view release on metacpan or search on metacpan
lib/EMDIS/ECS.pm view on Meta::CPAN
if( $^O =~ /MSWin32/ )
{
# Win32 only modules
eval "require Win32::Process";
}
}
# module/package version
$VERSION = '0.44';
# file creation mode (octal, a la chmod)
$FILEMODE = 0660;
# subclass Exporter and define Exporter set up
require Exporter;
@ISA = qw(Exporter);
@EXPORT = (); # items exported by default
@EXPORT_OK = (); # items exported by request
%EXPORT_TAGS = ( # tags for groups of items
ALL => [ qw($ECS_CFG $ECS_NODE_TBL $FILEMODE $VERSION
load_ecs_config delete_old_files dequote ecs_is_configured
lib/EMDIS/ECS.pm view on Meta::CPAN
my $timestamp = localtime;
my $origin = $0;
my $setmode = not -e $cfg->LOG_FILE;
open LOG, ">>" . $cfg->LOG_FILE or do {
warn "Error within ECS library: $! " . $cfg->LOG_FILE;
return;
};
print LOG join("|",$timestamp,$origin,$LOG_LEVEL[$level],$text),"\n";
close LOG;
chmod $FILEMODE, $cfg->LOG_FILE if $setmode;
if ( $level >= $cfg->MAIL_LEVEL )
{
send_admin_email (join("|",$timestamp,$origin,$LOG_LEVEL[$level],$text));
}
return '';
}
# logging subroutines for specific logging levels
sub log_debug { return &log(0, @_); }
sub log_info { return &log(1, @_); }
sub log_warn { return &log(2, @_); }
lib/EMDIS/ECS.pm view on Meta::CPAN
$template .= '_XXXX';
}
my ($fh, $tempfilename) = tempfile($template,
DIR => $targetdir,
SUFFIX => $suffix);
return "unable to open tempfile in directory $targetdir: $!"
unless $fh;
$err = "unable to copy $filename to $tempfilename: $!"
unless copy($filename, $fh);
close $fh;
chmod $FILEMODE, $tempfilename;
return $err;
}
# ----------------------------------------------------------------------
# Move file to specified directory. If necessary, rename file to avoid
# filename collision.
# Returns empty string if successful or error message if error encountered.
sub move_to_dir {
my $filename = shift;
my $targetdir = shift;
lib/EMDIS/ECS.pm view on Meta::CPAN
if(not $err) {
my $template = format_datetime(time, '%04d%02d%02d_%02d%02d%02d_XXXX');
my ($fh, $filename) = tempfile($template,
DIR => $cfg->ECS_MBX_OUT_DIR,
SUFFIX => '.msg');
$err = "EMDIS::ECS::send_admin_email(): unable to create 'out' file"
unless $fh;
if($fh) {
print $fh @_;
close $fh;
chmod $FILEMODE, $filename;
}
}
if(not $err)
{
my @recipients = split /,/, $cfg->ADM_ADDR;
foreach my $recipient (@recipients)
{
$err = send_email($recipient, '[' . $cfg->MAIL_MRK . '] ECS Error',
undef, "Origin: $0\n", @_);
lib/EMDIS/ECS.pm view on Meta::CPAN
return "EMDIS::ECS::send_ecs_message(): unable to open file: " .
"$filename"
unless $fh->open("> $filename");
}
$fh->print("Subject: $subject\n");
$fh->print("To: $node->{addr}\n");
$fh->print("From: " . $cfg->SMTP_FROM . "\n\n");
$fh->print(@_);
$fh->close();
chmod $FILEMODE, $filename;
if ( $err ) {
$err = "EMDIS::ECS::send_ecs_message(): unable to update node $node_id: $err";
}
elsif ( not $seq_num and ($node->{encr_meta} !~ /true/i) ) {
# if indicated, don't encrypt meta-message
if(is_yes($cfg->ENABLE_AMQP) and exists $node->{amqp_addr_meta} and $node->{amqp_addr_meta}) {
# send meta-message via AMQP (if indicated by node config)
$err = send_amqp_message(
$node->{amqp_addr_meta},
lib/EMDIS/ECS.pm view on Meta::CPAN
my $template = format_datetime(time, '%04d%02d%02d_%02d%02d%02d_XXXX');
# write message body to temp file
my ($fh, $filename) = tempfile($template,
DIR => $cfg->ECS_TMP_DIR,
SUFFIX => '.tmp');
return "EMDIS::ECS::send_encrypted_message(): unable to create temporary file"
unless $fh;
print $fh @_;
close $fh;
chmod $FILEMODE, $filename;
# create file containing encrypted message
my $encr_filename = "$filename.pgp";
my $result = '';
for ($encr_typ) {
/PGP2/i and do {
$result = pgp2_encrypt($filename, $encr_filename, $encr_recip,
$encr_out_keyid, $encr_out_passphrase);
last;
};
lib/EMDIS/ECS.pm view on Meta::CPAN
# ----------------------------------------------------------------------
# Update PID file.
sub save_pid
{
die "EMDIS::ECS::save_pid(): ECS has not been configured."
unless ecs_is_configured();
open PIDFILE, ">$pidfile";
print PIDFILE "$$\n";
close PIDFILE;
chmod $FILEMODE, $pidfile;
$pid_saved = 1;
}
# ----------------------------------------------------------------------
# Select the Win32 or Unix version of timelimit_cmd
sub timelimit_cmd
{
$^O =~ /MSWin32/ ? timelimit_cmd_win32(@_) : timelimit_cmd_unix(@_);
}
lib/EMDIS/ECS/Config.pm view on Meta::CPAN
$this->{INBOX_USE_STARTTLS} = "NO";
$this->{INBOX_MAX_MSG_SIZE} = "1048576";
$this->{OPENPGP_CMD_ENCRYPT} = '/usr/local/bin/gpg --armor --batch ' .
'--charset ISO-8859-1 --force-mdc --logger-fd 1 --openpgp ' .
'--output __OUTPUT__ --passphrase-fd 0 --quiet ' .
'--recipient __RECIPIENT__ --recipient __SELF__ --yes ' .
'--sign --local-user __SELF__ --encrypt __INPUT__';
$this->{OPENPGP_CMD_DECRYPT} = '/usr/local/bin/gpg --batch ' .
'--charset ISO-8859-1 --logger-fd 1 --openpgp --output __OUTPUT__ ' .
'--passphrase-fd 0 --quiet --yes --decrypt __INPUT__';
$this->{PGP2_CMD_ENCRYPT} = '/usr/local/bin/pgp +batchmode +verbose=0 ' .
'+force +CharSet=latin1 +ArmorLines=0 -o __OUTPUT__ ' .
'-u __SELF__ -eats __INPUT__ __RECIPIENT__ __SELF__';
$this->{PGP2_CMD_DECRYPT} = '/usr/local/bin/pgp +batchmode +verbose=0 ' .
'+force +CharSet=latin1 -o __OUTPUT__ __INPUT__';
$this->{ENABLE_AMQP} = "NO";
$this->{AMQP_RECV_TIMEOUT} = 5;
$this->{AMQP_RECV_TIMELIMIT} = 300;
$this->{AMQP_SEND_TIMELIMIT} = 60;
$this->{AMQP_DEBUG_LEVEL} = 0;
$this->{AMQP_CMD_SEND} = 'ecs_amqp_send.py';
$this->{AMQP_CMD_RECV} = 'ecs_amqp_recv.py';
}
lib/EMDIS/ECS/FileBackedMessage.pm view on Meta::CPAN
last; # EOF
}
else
{
print $fh $buffer
or $err = "send_this_message(): Problem writing output " .
"file $filename: $!";
}
}
close $fh;
chmod $FILEMODE, $filename;
}
my $custom_headers = {};
$custom_headers->{'x-emdis-hub-rcv'} = $rcv_node_id;
$custom_headers->{'x-emdis-hub-snd'} = $cfg->THIS_NODE;
if($num_parts == 1)
{
# read all data, send single email message
$err = "send_this_message(): Unable to position file pointer for " .
lib/EMDIS/ECS/Message.pm view on Meta::CPAN
# invoked as class method
$filename = $arg1;
my $raw_text = shift;
$msg = new EMDIS::ECS::Message($raw_text);
}
open MSGFILE, ">$filename"
or return "Unable to create file $filename: $!";
print MSGFILE $msg->full_msg()
or $err = "Unable to write file $filename: $!";
close MSGFILE;
chmod $EMDIS::ECS::FILEMODE, $filename;
return $err; # return error message (if any)
}
# ----------------------------------------------------------------------
# read message from file
# returns object reference if successful, otherwise returns error message
sub read_from_file
{
my $err = '';
my $arg1 = shift;
script/ecs_scan_mail view on Meta::CPAN
my $msg = new EMDIS::ECS::Message($raw_msg);
if((not ref $msg) or (not $msg->is_ecs_message() and not $msg->is_document())) {
my $template = sprintf('%s_%d_%04d_XXXX',
$fname_dttm, $loopnum, $msgnum);
my ($fh, $filename) = tempfile($template,
DIR => catdir($ECS_CFG->ECS_DAT_DIR, 'mboxes', 'trash'),
SUFFIX => '.msg');
print $fh $raw_msg
or $err = "unable to write file $filename: $!";
close $fh;
chmod $EMDIS::ECS::FILEMODE, $filename;
log_info(
"scan_mail(): received non-ECS message: $filename\n");
mbox_delete_message(indexAdj($msgnum,$numDelMsg));
$numDelMsg++; # We just deleted a msg
$ignored_msgcount++;
next;
}
last if $interrupted; # exit msgnum loop if int'd
# write message to temp file in $ECS_DAT_DIR/tmp
my $template = sprintf('%s_%d_%04d_XXXX',
$fname_dttm, $loopnum, $msgnum);
my ($fh, $filename) = tempfile($template,
DIR => $ECS_CFG->ECS_TMP_DIR,
SUFFIX => '.msg');
print $fh $msg->full_msg()
or $err = "unable to write file $filename: $!";
close $fh;
chmod $EMDIS::ECS::FILEMODE, $filename;
if($err) {
log_error("scan_mail(): unable to create tempfile: $err");
next;
}
# check if sender is this_node
if ($msg->sender eq $ECS_CFG->THIS_NODE) {
# mailtoadmin - tell admin mail is in $filename
print "$DEBUG_LABEL processing recipient = sender file: $filename\n"
if $ECS_CFG->{ECS_DEBUG} > 0;
script/ecs_scan_mail view on Meta::CPAN
$template =~ s/_\w{4}(\.\w+)*$/_XXXX/o;
}
else {
$template .= '_XXXX';
}
my ($fh, $doc_fname) = tempfile($template, SUFFIX => '.doc.asc');
print $fh $dmsg->cleartext
or $err = "process_document: Unable to write file " .
"$doc_fname: $!";
close $fh;
chmod $EMDIS::ECS::FILEMODE, $doc_fname;
# if error encountered, remove temp file and return error
if($err)
{
unlink $doc_fname;
return $err;
}
# store copy of decrypted payload in $ECS_MBX_IN_FML_DIR
my $in_fml_filename = catfile($ECS_CFG->ECS_MBX_IN_FML_DIR,
sprintf("%s_%s_%010d.doc", $msg->sender, $ECS_CFG->THIS_NODE,
$msg->seq_num));
if(not copy($doc_fname, $in_fml_filename))
{
$err = "process_document(): could not copy $doc_fname " .
"to $in_fml_filename: $!";
unlink $doc_fname;
return $err;
}
chmod $EMDIS::ECS::FILEMODE, $in_fml_filename;
# copy payload file to from_XX directory (if ECS_FROM_DIR is configured)
my $from_dir = $ECS_CFG->ECS_FROM_DIR;
if ( defined $from_dir and $from_dir ne '' ) {
# create temporary file (without extension .doc!)
# to prevent a race condition on the interface
$from_dir = catdir( $from_dir, 'from_' . $msg->sender );
my $template = sprintf( "tmp_doc_d%010d.XXXXXX", $msg->seq_num );
my( $tmp_fh, $from_tmp_filename ) = tempfile( $template,
DIR => $from_dir,
script/ecs_scan_mail view on Meta::CPAN
# put the final filename together ...
my $from_filename = catfile( $from_dir,
sprintf("d%010d.doc", $msg->seq_num ) );
# ... and rename our temporary file in the same directory
if ( not rename( $from_tmp_filename, $from_filename ) )
{
$err = "process_document(): could not rename $from_tmp_filename "
. "to $from_filename: $!";
}
chmod $EMDIS::ECS::FILEMODE, $from_filename;
}
# remove temp file
unlink $doc_fname;
return $err if $err ne '';
unlink $filename; # remove input file after successful processing
# message was processed
script/ecs_scan_mail view on Meta::CPAN
}
# write FML message payload to temp file in $ECS_DAT_DIR/tmp
my $template = $filename;
$template =~ s/_\w{4}(\.\w+)*$/_XXXX/;
my ($fh, $mp_payload_fname) = tempfile($template, SUFFIX => '.fml');
print $fh $dmsg->cleartext
or $err = "process_message: Unable to write file " .
"$mp_payload_fname: $!";
close $fh;
chmod $EMDIS::ECS::FILEMODE, $mp_payload_fname;
push @mp_payload_filename, $mp_payload_fname;
if($err)
{
last;
}
}
# if error encountered, remove any partial payload files and return error
if($err)
{
script/ecs_scan_mail view on Meta::CPAN
my $in_fml_filename = catfile($ECS_CFG->ECS_MBX_IN_FML_DIR,
sprintf("%s_%s_%010d.fml", $msg->sender, $ECS_CFG->THIS_NODE,
$msg->seq_num));
if(not copy($payload_filename, $in_fml_filename))
{
$err = "process_message(): could not copy $payload_filename " .
"to $in_fml_filename: $!";
unlink $payload_filename;
return $err;
}
chmod $EMDIS::ECS::FILEMODE, $in_fml_filename;
# process file via ADAPTER_CMD (if ADAPTER_CMD is configured)
if( defined $ECS_CFG->ADAPTER_CMD and $ECS_CFG->ADAPTER_CMD ne '' )
{
# compose command
my $cmd = sprintf("%s %s %s %s",
$ECS_CFG->MSG_PROC,
$payload_filename,
$msg->sender,
$msg->seq_num);
script/ecs_scan_mail view on Meta::CPAN
# put the final filename together ...
my $from_filename = catfile( $from_dir,
sprintf("%010d.msg", $msg->seq_num ) );
# ... and rename our temporary file in the same directory
if ( not rename( $from_tmp_filename, $from_filename ) )
{
$err = "process_message(): could not rename $from_tmp_filename "
. "to $from_filename: $!";
}
chmod $EMDIS::ECS::FILEMODE, $from_filename;
}
# remove temp file
unlink $payload_filename;
return $err if $err ne '';
# message was processed
# if needed, update $node->{in_seq}
if(not $was_locked) {
script/ecs_setup view on Meta::CPAN
print CFG cfgline('PGP_HOMEDIR');
print CFG '#' if not exists $cfg->{CFG_PGP};
print CFG cfgline('PGP_KEYID');
print CFG '#' if not exists $cfg->{CFG_PGP};
print CFG cfgline('PGP_PASSPHRASE');
print CFG '#', cfgline('PGP2_CMD_ENCRYPT');
print CFG '#', cfgline('PGP2_CMD_DECRYPT');
close CFG;
chmod $EMDIS::ECS::FILEMODE, $opt_config;
}
__END__
# embedded POD documentation
=head1 NAME
ecs_setup - ECS setup wizard
script/ecstool view on Meta::CPAN
{
my $err = $!;
close $fh;
die "Unable to lock output file $tempfilename: $err";
}
my $err = '';
print $fh $msg_text
or $err = "Unable to write output file $tempfilename: $!";
flock($fh, LOCK_UN);
close $fh;
chmod $EMDIS::ECS::FILEMODE, $tempfilename;
print "Message copied to $targetdir directory.\n";
}
# meta
if($opt_meta) {
die "Invalid number of parameters specified for --meta command.\n$usage"
unless $#ARGV >= 1;
my ($node_id, $msg_type, $seq1, $seq2) = @ARGV;
$ECS_NODE_TBL->lock() # lock node_tbl
ok($cfg->INBOX_PORT == 110);
ok($cfg->INBOX_MAX_MSG_SIZE == 1048576);
ok($cfg->OPENPGP_CMD_ENCRYPT eq '/usr/local/bin/gpg --armor --batch ' .
'--charset ISO-8859-1 --force-mdc --logger-fd 1 --openpgp ' .
'--output __OUTPUT__ --passphrase-fd 0 --quiet ' .
'--recipient __RECIPIENT__ --recipient __SELF__ --yes ' .
'--sign --local-user __SELF__ --encrypt __INPUT__');
ok($cfg->OPENPGP_CMD_DECRYPT eq '/usr/local/bin/gpg --batch ' .
'--charset ISO-8859-1 --logger-fd 1 --openpgp --output __OUTPUT__ ' .
'--passphrase-fd 0 --quiet --yes --decrypt __INPUT__');
ok($cfg->PGP2_CMD_ENCRYPT eq '/usr/local/bin/pgp +batchmode +verbose=0 ' .
'+force +CharSet=latin1 +ArmorLines=0 -o __OUTPUT__ ' .
'-u __SELF__ -eats __INPUT__ __RECIPIENT__ __SELF__');
ok($cfg->PGP2_CMD_DECRYPT eq '/usr/local/bin/pgp +batchmode +verbose=0 ' .
'+force +CharSet=latin1 -o __OUTPUT__ __INPUT__');
# derived values
ok($cfg->ECS_TMP_DIR =~ /tmp$/);
ok($cfg->ECS_DRP_DIR =~ /maildrop$/);
ok($cfg->ECS_MBX_DIR =~ /mboxes$/);
ok($cfg->ECS_MBX_IN_DIR =~ /in$/);
ok($cfg->ECS_MBX_IN_FML_DIR =~ /in_fml$/);
ok($cfg->ECS_MBX_OUT_DIR =~ /out$/);
ok($cfg->ECS_MBX_TRASH_DIR =~ /trash$/);
ok($cfg->ECS_MBX_STORE_DIR =~ /store$/);
web_status/README view on Meta::CPAN
subdirectories contain graphical images used by the web based status
display.
The following example illustrates one possible method for installing and
configuring these scripts.
1. Copy script files to web server cgi-bin subdirectory.
> mkdir /www/dev/cgi-bin/ecs
> cp web_status/ecs_status* /www/dev/cgi-bin/ecs
> chmod 755 /www/dev/cgi-bin/ecs/ecs_status*
2. Copy image files to web server html subcirectory. Modify file
permissions and group ownership as needed.
> mkdir /www/dev/html/ecs/images
> mkdir /www/dev/html/ecs/images/22px
> mkdir /www/dev/html/ecs/images/60px
> cp web_status/images/*.ico /www/dev/html/ecs/images
> cp web_status/images/*.png /www/dev/html/ecs/images
> cp web_status/images/22px/*.png /www/dev/html/ecs/images/22px
> cp web_status/images/60px/*.png /www/dev/html/ecs/images/60px
> find /www/dev/html/ecs/images -type f -exec chmgrp web '{}' \;
> find /www/dev/html/ecs/images -type f -exec chmod 664 '{}' \;
3. If needed (depending on how system and web server permissions are
configured), create node_tbl files and set file permissions so the
files are writable by web server user.
> touch /www/dev/cgi-bin/ecs/node_tbl.dat.dir
> touch /www/dev/cgi-bin/ecs/node_tbl.dat.pag
> touch /www/dev/cgi-bin/ecs/node_tbl.lock
> chmod 666 /www/dev/cgi-bin/ecs/node_tbl*
4. Edit ecs_status environment variable values to further customize
setup.
> vi /www/dev/cgi-bin/ecs/ecs_status
...
5. Use web browser to view ECS status page.
> firefox http://myserver/ecs/ecs_status