
| Current Path : /var/www/web-klick.de/dsh/90_akt/old/utility/Process/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/90_akt/old/utility/Process/msend.pm |
package Process::msend;
use strict;
use Time::ParseDate;
use Date::Format;
sub new {
my $class = shift;
my $self = {};
$self->{'MTYPE'} = shift;
$self->{'ECOTEXT'} = shift; # Masquerading-Informationen
my $time = shift; # fuer die Versende-Arten
if ($time) {
$time = time() - parsedate($time,UK=>1);
}
$self->{'CTIME'} = $time;
bless($self,$class);
$self->read_ecosend();
return($self);
}
#************************************************************************
# Aufbereitung der Masquerading-Informationen
sub read_ecosend {
my $self = shift;
my $modes = $self->{'MTYPE'};
my $mode; my $o; my $ecoentry;
$self->{'ECOSEND'} = {};
$self->{'ECOCHANGEPRE1'} = {};
$self->{'ECOCHANGEPRE2'} = {};
$self->{'ECOCHANGEPOST1'} = {};
$self->{'ECOCHANGEPOST2'} = {};
$self->{'FEIERTAGE'} = {};
while ($modes) {
$mode = substr($modes,0,1);
$modes = substr($modes,1);
$self->{'ECOSEND'}->{$mode} = [];
$self->{'ECOCHANGEPRE1'}->{$mode} = "";
$self->{'ECOCHANGEPRE2'}->{$mode} = "";
$self->{'ECOCHANGEPOST1'}->{$mode} = "";
$self->{'ECOCHANGEPOST2'}->{$mode} = "";
$self->{'FEIERTAGE'}->{$mode} = [];
foreach $o (split(/\n/,$self->{'ECOTEXT'}->{$mode})) {
if ($o =~ /(.*)\#(.*)/) {
$o = $1;
}
if ($o =~ /^pre +(\S+) +(\S+)/) {
$self->{'ECOCHANGEPRE1'}->{$mode} = $1;
$self->{'ECOCHANGEPRE2'}->{$mode} = $2;
}
elsif ($o =~ /^post +(\S+) +(\S+)/) {
$self->{'ECOCHANGEPOST1'}->{$mode} = $1;
$self->{'ECOCHANGEPOST2'}->{$mode} = $2;
}
elsif ($o =~ /^fei +(.*?) */) {
foreach $o (split(/\s/,$1)) {
if ($o =~ /^\d(\S+)$/) {
push(@{$self->{'FEIERTAGE'}->{$mode}},$o);
}
}
}
elsif ($o =~ /(\S+) +(\S+) +(\S+) +(\S+) +(\S+) (.*)/) {
$ecoentry = [$1,$2,$3,$4,$5,"",""];
$o = $6;
if ($o =~ /(\S+) +(\S+)/) {
$ecoentry->[5] = $1;
$ecoentry->[6] = $2;
}
if ($o =~ /(\S+)/) {
$ecoentry->[5] = $1;
}
push(@{$self->{'ECOSEND'}->{$mode}},$ecoentry);
}
}
}
}
#************************************************************************
sub test { my $self = shift; $self->{'___TEST___'} = 1; }
#************************************************************************
sub run {
my $self = shift;
my $file = shift;
my $cmd; my $cmd1; my $o; my $o1; my $o2;
if ($file =~ /^(.*)\.\.do$/) {
push(@$cmd,"");
}
elsif ($file =~ /^(.*)\.\.(.*)$/) { # Externe Kanal-Angabe (per Datei-Suffix)
$o = $2; # Kommando-Position 0
if ($o =~ /^(.*)\=\=(.*)$/) {
$o = $1 . " (" . $2 . ")";
}
$o = "CHANNEL 999: $o";
$o1 = "PACKAGE Z: this\n";
opendir(DDIR,".");
while ($o2 = readdir(DDIR)) {
if ($o =~ /^\d/) {
if ($o2 =~ /\.g3$/) {
$o1 = $o1 . $o2 . "\n";
}
}
elsif ($o =~ /\@/) {
if ($o2 =~ /(.*)--(.*)--(.*)/) {
$o1 = $o1 . $o2 . "\n";
}
}
}
$o = $o . "\n" . $o1 . "SEND: Z999\nPROTOCOL:\n";
push(@$cmd,$o);
} else {
push(@$cmd,"");
}
open(FFILE,"<".$file);
my $text = join("",<FFILE>);
close(FFILE);
$self->{'TEXT'} = $text;
$self->{'FILE'} = $file;
my $text1 = $text;
$o = 1;
while ($text1 =~ s/(CHANNEL .*?\n) *\n/--$o--\n/s) {
push(@$cmd,$1);
$o = $o + 1;
}
# Hauptschleife: Alle Sendeanweisungen werden durchgegangen
my $ready = 1; # Annahme: Alle Auftraege abgearbeitet
my $zaehler = -1;
foreach $cmd1 (@$cmd) {
$zaehler = $zaehler + 1;
next if (!$cmd1);
next if ($cmd1 =~ /PROTOCOL(.*)\nSUCCEED/s);
my $channels = {};
my $packages = {};
my $send = "";
my $cmd2 = $cmd1;
while ($cmd2 =~ s/(CHANNEL|PACKAGE|SEND|PROTOCOL)(.*?)(CHANNEL|PACKAGE|SEND|PROTOCOL|END)/$3/s) {
$o = $1;
$o1 = $2;
if ($o eq "CHANNEL") {
$o1 =~ s/\n/ /gs;
if ($o1 =~ /^ *(\S+)\: *(.*?)\s*$/) { $channels->{$1} = $2; }
}
elsif ($o eq "PACKAGE") {
$o1 =~ s/\n/ /gs;
if ($o1 =~ /^ *(\S+)\: *(.*?)\s*$/) { $packages->{$1} = $2; }
}
elsif ($o eq "SEND") {
$o1 =~ s/\n/ /gs;
if ($o1 =~ /^ *\: *(.*?)\s*$/) { $send = $1; }
}
}
#-------- Durchgang durch alle Sende-Alternativen
my $succeed;
foreach $o (split(/,/,$send)) {
$succeed = 1; # Annahme: Pakete erfolgreich gesendet
foreach $o1 (split(/ +/,$o)) { # zu sendende Pakete
next if (!$o1);
next if ($cmd1 =~ /PROTOCOL(.*) $o1 OK/s); # schon versendet
$o2 = "";
if ( $o1 =~ /^([A-Z])(.*)$/ ) {
$o2 = $self->send($o1,$packages->{$1},$channels->{$2},$cmd1);
}
if ($o2 eq "skip") {
$succeed = 0;
} else {
$cmd1 = $cmd1 . $o2;
$self->write_protocol($text1,$cmd,$file);
next if ($cmd1 =~ /PROTOCOL(.*) $o1 OK/s);
$succeed = 0;
}
}
last if ($succeed);
}
if ($succeed) {
if ($zaehler == 0) { # Externe Datei-Angabe
$o = $file;
if ($file =~ /^(.*)\.\.(.*)$/) {
$file = $1 . "__" . $2 . "..do";
$self->c("mv $o $file");
}
} else {
$cmd1 = $cmd1 . "SUCCEED\n";
$self->write_protocol($text1,$cmd,$file);
}
} else {
$ready = 0;
}
}
$o = 0;
foreach $cmd1 (@$cmd) {
$text1 =~ s/--$o--\n/$cmd1\n/s;
$o = $o + 1;
}
if ($text1 ne $text) {
open(FFILE,">".$file."__");
print FFILE $text1;
close(FFILE);
system("mv ". $file . "__ " . $file);
}
if ($ready) { # Wenn alles abgearbeitet wurde,
print "READY\n";
$o = $file; # wird ein eventuelles ..do als Dateiendung entfernt
$o1 = time() - $self->{'CTIME'};
$o1 = sprintf("%04u",(localtime($o1))[5]+1900) .
sprintf("%02u",(localtime($o1))[4]) .
sprintf("%02u",(localtime($o1))[3]) . "_" .
sprintf("%02u",(localtime($o1))[2]) .
sprintf("%02u",(localtime($o1))[1]);
if ($file =~ /^(.*?)\.\.do$/) {
$o = $1 . "__" . $o1;
system("mv $file $o");
}
}
}
#*********************************************************************
sub write_protocol {
my $self = shift;
my $text1 = shift;
my $cmd = shift;
my $file = shift;
my $o = 1;
my $cmd1;
foreach $cmd1 (@$cmd) {
$text1 =~ s/--$o--\n/$cmd1\n/s;
$o = $o + 1;
}
open(FFILE,">".$file."__");
print FFILE $text1;
close(FFILE);
system("mv ". $file . "__ " . $file);
}
#*************************************************************************
sub send {
my $self = shift;
my $chpkg = shift;
my $package = shift;
my $channel = shift;
my $cmd1 = shift;
my $o;
my $time_constraints = ""; # Zeitbeschraenktes Senden
if ($channel =~ /^(.*) *\((.*)\) *$/) {
$channel = $1;
$time_constraints = $2;
}
my $channeltype = "p";
if ($channel =~ /\@/) { $channeltype = "m"; }
elsif ($channel =~ /^010/) { $channeltype = "s"; }
elsif ($channel =~ /^\d/) { $channeltype = "f"; }
if ($self->{'MTYPE'} !~ /$channeltype/) {
return("skip");
}
if ($channeltype eq "m") {
$o = $self->sendmail($channel,$package,$time_constraints); }
elsif ($channeltype eq "s") {
$o = $self->sendsms($channel,$package,$time_constraints); }
elsif ($channeltype eq "f") {
$o = $self->sendfax($channel,$package,$time_constraints); }
elsif ($channeltype eq "p") {
$o = $self->sendpost($channel,$package,$time_constraints); }
if ($o eq "___NO_PROTOCOL___") { return(""); }
$o = Date::Format::time2str("%d.%m.%Y %T",time() - $self->{'CTIME'})
. " " . $chpkg . " " . $o . "\n";
return($o);
}
#**********************************************************************
sub sendmail {
my $self = shift;
my $channel = shift;
my $package = shift;
my $time_constraints = shift;
my $file; my $o; my $o1;
my $mailfiles = [];
my $zaehler = 0;
my $mime;
my ($email_address,$amount) = $self->qqdelay(time()-$self->{'CTIME'},
"m",$channel,$time_constraints);
if (!$email_address) { return("not sent per MAIL: time constraints"); }
foreach $file (split(/,/,$package)) {
$zaehler = $zaehler + 1;
$file =~ /^ *(.*?) *$/;
$file = $1;
my $filetype = "";
next if (!$file);
if ($file =~ /^(.*?)\;(.*?) (.*)$/) {
$mime = $2;
$file = $1 . " " . $3;
}
elsif ($file =~ /^(.*?)\;(.*?)$/) {
$mime = $2;
$file = $1;
}
$mime = [split(/;/,$mime)];
if (!($mime->[0])) { $mime->[0] = ""; }
if (!($mime->[1])) { $mime->[1] = ""; }
if (!($mime->[2])) { $mime->[2] = ""; }
if ($file eq "this") { $file = "this "; }
if ($file =~ /^this (.*)/) {
$file = $self->{'FILE'} . " " . $1;
$self->{'AKTTEXT'} = $self->{'TEXT'};
$self->{'AKTFILE'} = $self->{'FILE'};
}
if ($file =~ / /) {
$file = $self->substitute($file,$zaehler);
}
if ($file =~ /\.tex/) {
if ($file =~ /\.tex\.\./ or $file =~ /\.tex$/) {
$filetype = "tex";
} else {
$self->filetype($file);
if ($self->{'AKTFILE'} =~ /documentclass/) {
$filetype = "tex";
}
}
}
if ($filetype eq "tex" and $mime->[0] =~ /\.txt$/) {
system("latex " . $file);
system("latex " . $file);
my $root = $file;
if ($file =~ /(.*)\.(.*)/) { $root = $1; }
my $file1 = $root;
if ($file1 !~ /^\_\_tmpfile/) {
$file1 = "__tmpfile.".$$.".".$zaehler;
}
system("dvi2tty -w 132 -e-21 -l -t -o$file1.txt $root.dvi");
push(@$mailfiles,["$file1.txt",$mime,
["$file1.txt","text/plain","base64"]]);
}
elsif ($filetype eq "tex" and $mime->[0] =~ /\.pdf$/) {
system("pdflatex " . $file);
system("pdflatex " . $file);
my $root = $file;
if ($file =~ /(.*)\.(.*)/) { $root = $1; }
my $file1 = $root;
if ($file1 !~ /^\_\_tmpfile/) {
$file1 = "__tmpfile.".$$.".".$zaehler;
}
system("mv $root.pdf $file1.pdf");
push(@$mailfiles,["$file1.pdf",$mime,
["$file1.pdf","application/postscript","base64"]]);
}
elsif ($file =~ /\.gif$/) {
push(@$mailfiles,[$file,$mime,[$file,"image/gif","base64"]]);
}
elsif ($file =~ /\.(jpg|jpeg)$/) {
push(@$mailfiles,[$file,$mime,[$file,"image/jpeg","base64"]]);
}
elsif ($file =~ /\.(txt|mai)$/) {
push(@$mailfiles,[$file,$mime,[$file,"text/plain","quoted-printable"]]);
}
}
$email_address =~ s/ +(-[A-Za-z]) / $1 /g;
$email_address =~ s/, +/,/gs;
$email_address =~ /(\S*) *(.*)/;
my $cmd = "metasend -S 99000000 -b " . $2 . " -t " . $1 . " ";
foreach $o (@$mailfiles) {
if ($o->[1]->[0]) { $o->[2]->[0] = $o->[1]->[0]; }
if ($o->[1]->[1]) { $o->[2]->[1] = $o->[1]->[1]; }
if ($o->[1]->[2]) { $o->[2]->[2] = $o->[1]->[2]; }
$mime = $o->[2];
$cmd = $cmd . " \\\n";
if ($cmd =~ / -f /) {
$cmd = $cmd . "-n";
}
if ($#{$mailfiles}) {
if ($mime->[0] and $mime->[1]) {
$mime->[1] = "\"" . $mime->[1] . "\; name=" .
$mime->[0] . "\"";
}
}
if ($mime->[1]) {
$cmd = $cmd . " -m " . $mime->[1];
}
if ($mime->[2]) {
$cmd = $cmd . " -e " . $mime->[2];
}
$cmd = $cmd . " -f " . $o->[0];
}
$self->c($cmd,$self->{'___TEST___'});
$self->c("rm __tmpfile.".$$.".\*.\*",$self->{'___TEST___'});
return("OK per MAIL");
}
#**********************************************************************
sub sendsms {
my $self = shift;
my $channel = shift;
my $package = shift;
my $time_constraints = shift;
return("SMS NOT IMPLEMENTED");
}
#**********************************************************************
sub sendfax {
my $self = shift;
my $channel = shift;
my $package = shift;
my $time_constraints = shift;
my $file; my $o; my $o1; my $z1;
my $g3files = [];
my $zaehler = 0;
my ($faxnr,$amount) = $self->qqdelay(time()-$self->{'CTIME'},
"f",$channel,$time_constraints);
if (!$faxnr) { return("not sent per FAX: time constraints"); }
$faxnr =~ s/\///g;
$faxnr =~ s/\-//g;
foreach $file (split(/,/,$package)) {
$zaehler = $zaehler + 1;
$file =~ /^ *(.*?) *$/;
$file = $1;
my $filetype = "";
next if (!$file);
if ($file =~ /^(.*?)\;(.*?) (.*)$/) {
$file = $1 . " " . $3;
}
elsif ($file =~ /^(.*?)\;(.*?)$/) {
$file = $1;
}
if ($file eq "this") { $file = "this "; }
if ($file =~ /^this (.*)/) {
$file = $self->{'FILE'} . $1;
$self->{'AKTTEXT'} = $self->{'TEXT'};
$self->{'AKTFILE'} = $self->{'FILE'};
}
if ($file =~ / /) {
$file = $self->substitute($file,$zaehler);
}
if ($file =~ /\.tex/) {
if ($file =~ /\.tex\.\./ or $file =~ /\.tex$/) {
$filetype = "tex";
} else {
$self->filetext($file);
if ($self->{'AKTTEXT'} =~ /documentclass/) {
$filetype = "tex";
}
}
}
elsif ($file =~ /\.g3$/) {
$filetype = "g3";
}
if ($filetype eq "tex") {
system("latex " . $file);
system("latex " . $file);
my $root = $file;
if ($file =~ /(.*)\.(.*)/) { $root = $1; }
my $file1 = $root;
if ($file1 !~ /^\_\_tmpfile/) {
$file1 = "__tmpfile.".$$.".".$zaehler;
}
$self->c("dvips -O -1in,-1in -o $file1.ps $root.dvi");
$self->c("gs -sDEVICE=faxg3 -dBATCH -dNOPAUSE " .
" -sOutputFile=$file1.%03d.g3 -r204x196 $file1.ps");
$self->c("rm $file1.ps; rm $root.dvi; rm $root.aux; rm $root.log");
push(@$g3files,"$file1.\*.g3");
}
elsif ($filetype eq "g3") {
push(@$g3files,$file);
}
}
my $ok = 0;
$self->c("sendfax -r " . $faxnr . " " . join(" ",@$g3files),
$self->{'___TEST___'});
foreach $file (@$g3files) {
if ($file =~ /\*/) {
$o = 0;
while (0 == 0) {
$o = sprintf("%03u",$o+1);
$o1 = $file;
$o1 =~ s/\*/$o/;
last if (!(-f $o1) and !(-f "$o1.done"));
if (-f "$o1.done") {
$self->c("rm $o1.done",$self->{'___TEST___'});
} else {
$self->c("rm $o1",$self->{'___TEST___'});
$ok = 1;
}
}
} else {
if (-f "$file.done") {
$self->c("mv $file.done $o1",$self->{'___TEST___'});
} else {
$ok = 1;
}
}
}
if ($self->{'___TEST___'}) { $ok = 0; }
$self->c("rm __tmpfile.".$$.".\*.\*",$self->{'___TEST___'});
if ($ok == 1) { return("not sent per FAX: send error".$amount); }
return("OK per FAX".$amount);
}
#**********************************************************************
sub sendpost {
my $self = shift;
my $channel = shift;
my $package = shift;
my $time_constraints = shift;
my $file; my $o; my $o1; my $z1;
my $printfiles = [];
my $zaehler = 0;
my ($print,$amount) = $self->qqdelay(time()-$self->{'CTIME'},
"f",$channel,$time_constraints);
if (!$print) { return("not sent per POST: time constraints"); }
foreach $file (split(/,/,$package)) {
$zaehler = $zaehler + 1;
$file =~ /^ *(.*?) *$/;
$file = $1;
my $filetype = "";
next if (!$file);
if ($file =~ /^(.*?)\;(.*?) (.*)$/) {
$file = $1 . " " . $3;
}
elsif ($file =~ /^(.*?)\;(.*?)$/) {
$file = $1;
}
if ($file eq "this") { $file = "this "; }
if ($file =~ /^this (.*)/) {
$file = $self->{'FILE'} . $1;
$self->{'AKTTEXT'} = $self->{'TEXT'};
$self->{'AKTFILE'} = $self->{'FILE'};
}
if ($file =~ / /) {
$file = $self->substitute($file,$zaehler);
}
if ($file =~ /\.tex/) {
if ($file =~ /\.tex\.\./ or $file =~ /\.tex$/) {
$filetype = "tex";
} else {
$self->filetext($file);
if ($self->{'AKTTEXT'} =~ /documentclass/) {
$filetype = "tex";
}
}
}
if ($file =~ /\.txt$/ or $file =~ /\.mai$/) {
$filetype = "txt";
}
if ($file =~ /\.gif$/ or $file =~ /\.jpg$/) {
$filetype = "gif";
}
if ($filetype eq "tex") {
system("latex " . $file);
system("latex " . $file);
my $root = $file;
if ($file =~ /(.*)\.(.*)/) { $root = $1; }
my $file1 = $root;
if ($file1 !~ /^\_\_tmpfile/) {
$file1 = "__tmpfile.".$$.".".$zaehler;
}
$self->c("dvips -O -1in,-1in -o $file1.ps $root.dvi");
push(@$printfiles,"lpr $file1.ps");
}
elsif ($filetype eq "txt") {
push(@$printfiles,"a2ps -B -1 -l 100 -L 100 $file");
}
elsif ($filetype eq "gif") {
push(@$printfiles,"cv print $file");
}
}
my $ok = 0;
foreach $file (@$printfiles) {
$self->c($file,$self->{'___TEST___'});
}
$self->c("rm __tmpfile.".$$.".\*.\*",$self->{'___TEST___'});
return("OK per POST");
}
#**********************************************************************
sub qqdelay {
my $self = shift;
my $zeit = shift;
my $mode = shift;
my $fax = shift; # Zugangsnummer
my $constraints = shift; # Sendezeiteinschraenkungen
my $o; my $o1; my $o2; my $o3;
# Auf Minuten runden:
$zeit = (localtime($zeit))[3] . "." .
((localtime($zeit))[4]+1) . "." .
((localtime($zeit))[5]+1900) . " " .
sprintf("%02u",(localtime($zeit))[2]) . ":" .
sprintf("%02u",(localtime($zeit))[1]);
# Bestimmung des Sendeintervalls [$sendtime,$lasttime]
my @xtimex = ();
my $sendtime = 0;
my $lasttime = 0;
if ($constraints) {
@xtimex = split(/,/,$constraints);
$o = shift(@xtimex);
$o1 = 0;
if ($o =~ /(.*)-(.*)/) {
$o1 = 1;
$o2 = $1;
$o3 = $2;
if ($o2) {
if ($o2 == 0) {
$o1 = 0;
} else {
$sendtime = $o2;
if ($o3 == 0) {
$o1 = 0;
} else {
$lasttime = $o3;
}
}
}
}
if (!$o1) {
unshift(@xtimex,$o);
$sendtime = 0;
$lasttime = 0;
}
}
if (!$sendtime) { $sendtime = $zeit; }
if (!$lasttime) { $lasttime = $zeit; }
if (parsedate($sendtime,UK=>1) < parsedate($zeit,UK=>1)) {
$sendtime = $zeit;
}
$sendtime = parsedate($sendtime,UK=>1);
if ($lasttime !~ / /) {
$lasttime = $lasttime . " 23:59";
}
$lasttime = parsedate($lasttime,UK=>1);
foreach $o (@xtimex) {
next if ($o =~ /(.*) (.*)/);
if ($o =~ /\D/) {
$o = $o . " 0-24";
} else {
$o = "Mo-So " . $o;
}
}
# Erstellung einer Liste mit allen relevanten Tages-Zeitpunkten
my @xtimex1 = ();
foreach $o (@{$self->{'ECOSEND'}->{$mode}}) {
if ($o->[1] =~ /(.*)-(.*)/) {
push(@xtimex1,"xx ".$o->[1]);
}
}
my $timep = {};
$timep->{"00:00"} = 1;
$timep->{sprintf("%02u",(localtime($sendtime))[2]).":".
sprintf("%02u",(localtime($sendtime))[1])} = 1;
$timep->{sprintf("%02u",(localtime($lasttime))[2]).":".
sprintf("%02u",(localtime($lasttime))[1])} = 1;
foreach $o (@xtimex,@xtimex1) {
if ($o =~ /(.*) +(.*)-(.*)/) {
my $x1 = $2;
my $x2 = $3;
foreach $o1 ($x1,$x2) {
$o2 = $o1;
if ($o2 !~ /:/) {
$o2 = $o2 . ":00";
}
if ($o2 =~ /^\d:/) {
$o2 = "0" . $o2;
}
next if ($o2 eq "24:00");
$timep->{$o2} = 1;
}
}
}
my @timepoints = sort keys %$timep;
# Bestimmung der guenstigsten moeglichen Sendezeit im gegebenen Zeitintervall
# Wenn es keine guenstigere Sendezeit als die aktuelle gibt, wird gesendet.
my $akttime = parsedate($zeit,UK=>1);
$akttime = (localtime($akttime))[3] . "." .
((localtime($akttime))[4]+1) . "." .
((localtime($akttime))[5]+1900) . " 00:00";
my $mincost = 999999; # Aktuelle minimale Kosten
my $mincosttime = $sendtime; # Zugehoerige Sendezeit
my $mineco = 0; # Zugehoerige ecosend-Zeile
my $zaehler = 0;
if ($self->{'ECOCHANGEPRE1'}->{$mode}) {
$o1 = $self->{'ECOCHANGEPRE1'}->{$mode};
$o2 = $self->{'ECOCHANGEPRE2'}->{$mode};
print("\$fax =~ s/".$o1."/".$o2."/\n");
eval("\$fax =~ s/".$o1."/".$o2."/");
}
while (0 == 0) {
last if (parsedate($akttime,UK=>1) > $lasttime);
if (parsedate($akttime,UK=>1) >= $sendtime) {
print "TIME: $akttime\n";
$o1 = 1;
if (@xtimex) {
$o1 = 0;
foreach $o (@xtimex) {
next if ($o !~ /(.*) +(.*)-(.*)/);
$o1 = $self->time_allowed($akttime,$o);
last if ($o1);
}
}
if ($o1) { # Wenn erlaubte Sendezeit
my $faxid = "";
if (!(@{$self->{'ECOSEND'}->{$mode}})) { # keine
$mincost = 0; # Masquerading-
$mincosttime = parsedate($akttime,UK=>1); # Angabe
$mineco = 0;
} else { # Masquerading-Angabe beruecksichtigen
foreach $o (@{$self->{'ECOSEND'}->{$mode}}) {
$o1 = $o->[3];
next if ($faxid and $o1 ne $faxid);
if ($fax =~ /$o1/) {
$faxid = $o1;
if ($o->[2] < $mincost) {
if ($self->time_allowed($akttime,$o->[0] . " " . $o->[1])) {
$mincost = $o->[2];
$mincosttime = parsedate($akttime,UK=>1);
$mineco = $o;
}
}
}
}
}
}
}
if (!($timepoints[$zaehler])) {
$akttime =~ /(.*) (.*)/;
$akttime = parsedate($1,UK=>1) + 86400;
$akttime = (localtime($akttime))[3] . "." .
((localtime($akttime))[4]+1) . "." .
((localtime($akttime))[5]+1900) . " 00:00";
$zaehler = 0;
}
$akttime =~ /(.*) (.*)/;
$akttime = $1 ." " . $timepoints[$zaehler];
$zaehler = $zaehler + 1;
}
# Guenstigste Sendezeit: $mincosttime
$o1 = (localtime($mincosttime))[3] . "." .
((localtime($mincosttime))[4]+1) . "." .
((localtime($mincosttime))[5]+1900) . " " .
sprintf("%02u",(localtime($mincosttime))[2]) . ":" .
sprintf("%02u",(localtime($mincosttime))[1]);
my $delay = $mincosttime - parsedate($zeit,UK=>1);
print "Cheaptime: $o1 (for $mincost), Acttime: $zeit, DELAY: $delay\n";
if ($delay < 20 and $mincost < 999999) {
if ($mineco) {
$o1 = $mineco->[3];
$o2 = $mineco->[4];
print("\$fax =~ s/".$o1."/".$o2."/\n");
eval("\$fax =~ s/".$o1."/".$o2."/");
}
if ($self->{'ECOCHANGEPOST1'}->{$mode}) {
$o1 = $self->{'ECOCHANGEPOST1'}->{$mode};
$o2 = $self->{'ECOCHANGEPOST2'}->{$mode};
print("\$fax =~ s/".$o1."/".$o2."/\n");
eval("\$fax =~ s/".$o1."/".$o2."/");
}
return($fax," (".$mincost.")");
}
return(0,0); # Fax noch nicht sendebereit
}
#***************************************************************
sub time_allowed {
my $self = shift;
my $xtime = shift;
my $interval = shift;
$xtime =~ /(.*)\.(.*)\.(.*) (.*):(.*)/;
my $xday = $1;
my $xmonth = $2;
my $xyear = $3;
my $xhour = $4 * 60 + $5;
my $wday = (localtime(parsedate($xtime,UK=>1)))[6];
$interval =~ /(.*) (.*)/;
my $days = $1;
my $hours = $2;
$days =~ s/So/0/g;
$days =~ s/Mo/1/g;
$days =~ s/Di/2/g;
$days =~ s/Mi/3/g;
$days =~ s/Do/4/g;
$days =~ s/Fr/5/g;
$days =~ s/Sa/6/g;
my @dd = split(/\+/,$days);
my @hh = split(/\+/,$hours);
my $o; my $o1; my $o2; my $o3; my $o4; my $day; my $hour;
foreach $day (@dd) {
if ($day =~ /(\d)-(\d)/) {
$o1 = $1;
$o2 = $2;
$day = $o1;
$o3 = $o1;
while ($o3 != $o2) {
$o3 = $o3 + 1;
if ($o3 == 7) { $o3 = $o3 - 7; }
$day = $day . $o3;
}
}
}
foreach $hour (@hh) {
$o1 = 1; # Leeres Intervall
$o2 = 0;
if ($hour =~ /(.*)-(.*)/) {
$o1 = $1;
$o2 = $2;
foreach $o ($o1,$o2) {
if ($o =~ /(.*):(.*)/) {
$o = $1 * 60 + $2;
} else {
$o = $o * 60;
}
}
}
$hour = [$o1,$o2];
}
foreach $day (@dd) {
foreach $hour (@hh) {
if ($day eq "Fei") {
if ($self->feiertag("$xday.$xmonth.$xyear")) {
if ($hour->[0] <= $xhour and $xhour <= $hour->[1]) {
return(1);
}
}
} else {
if ($day =~ /$wday/) {
if ($hour->[0] <= $xhour and $xhour <= $hour->[1]) {
return(1);
}
}
}
}
}
return(0);
}
#***************************************************************
sub feiertag { # Ueberprueft, ob $day ein Feiertag ist.
my $self = shift;
my $mode = shift;
my $day = shift;
my $o;
foreach $o (@{$self->{'FEIERTAGE'}->{$mode}}) {
next if ($day !~ /$o/);
return(1);
}
return(0);
}
#***************************************************************
sub c {
my $self = shift;
my $cmd = shift;
my $cmd1 = shift; # Wenn ja, nur dummy-Ausfuehrung
if (!$cmd) {
$cmd = $cmd1;
}
print $cmd . "\n";
if (!$cmd1) {
system($cmd);
}
}
#**********************************************************************
# Substitution in zu versendenden Files
sub substitute {
my $self = shift;
my $file = shift;
my $zaehler = shift;
$file =~ /^(.*?) +(.*)$/;
my $pars = $2 . " ";
$file = $1;
my $o; my $o1;
my $parameters = {};
while ($pars =~ s/(\S+?)\=\"(.*?)\"//) {
$parameters->{$1} = $2;
}
while ($pars =~ s/(\S+?)\=(.*?) / /) {
$parameters->{$1} = $2;
}
my $file1 = $parameters->{"file"};
if (!$file1) { $file1 = $file; }
foreach $o (keys %$parameters) {
$o1 = $parameters->{$o};
$o = "\%" . lc($o) . "\%";
$file1 =~ s/$o/$o1/g;
}
$pars = 0;
if ($file eq $file1) {
if ($file =~ /(.*)\.(.*)/) {
$file1 = "__tmpfile.".$$.".".$zaehler.".".$2;
} else {
$file1 = "__tmpfile.".$$.".".$zaehler;
}
} else {
$pars = 1;
}
$self->filetext($file);
$self->{'AKTFILE'} = $file1;
foreach $o (keys %$parameters) {
$o1 = $parameters->{$o};
$o = "-" . uc($o) . "-";
if ($self->{'AKTTEXT'} =~ s/$o/$o1/g) { $pars = 1; }
}
if ($pars) {
open(FFILE,">".$file1);
print FFILE $self->{'AKTTEXT'};
close(FFILE);
}
return($file1);
}
#******************************************************************
sub filetext {
my $self = shift;
my $file = shift;
if ($self->{'AKTFILE'} ne $file) {
open(FFILE,"<".$file);
$self->{'AKTTEXT'} = join("",<FFILE>);
close(FFILE);
$self->{'AKTFILE'} = $file;
}
return($self->{'AKTTEXT'});
}
1;