MailTransport reafctoring

This commit is contained in:
Rainer Gümpelein 2022-01-14 10:49:45 +01:00
parent 9082b161de
commit 4262462fc8
8 changed files with 71 additions and 50 deletions

View file

@ -75,7 +75,7 @@ my $response = {
response_state => "OK, nothing todo",
privacy_html => "site/privacy_1.html",
agb_html => "site/agb.html",
impress_html => "site/impress.html",
impress_html => "site/impress_1.html",
tariff_info_html => "site/tariff_info_1.html",
bike_info_html => "site/bike_info.html",
lang => "DE",

View file

@ -292,7 +292,7 @@ sub channel_map(){
192 => "Web Bayern",
193 => "Web Demo",#mig
194 => "Web Example",#mig
195 => "Web KN",#mig
195 => "Web KN",#mig and import
196 => "DMS Form std",#mig
197 => "Web Form std",#mig
198 => "primary",#mig

View file

@ -615,7 +615,7 @@ sub update_users4trans(){
c_id4trans='$c_id4trans',
tpl_id4trans='$tpl_id4trans',
ctpos_activ='0',
kind_of_trans='$kind_of_trans'
kind_of_trans='Faktura'
where u_id=$u_id");
my $rows = $sth->execute();
return $rows;

View file

@ -1,4 +1,4 @@
package Mod::MailTransport;
package MailTransport;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
@ -33,34 +33,15 @@ my $q = new CGI;
my $bw = new Basework;
my $dbt = new DBtank;
my $mailx_file = "/var/www/copri4/shareeconf/mailx.cfg";
my $conf = Config::General->new($mailx_file);
my %mailxconf = $conf->getall;
sub mail_connect {
my $self = shift;
my $sendref = shift;
sub send_mail(){
my $self = shift;
my $sendref = shift;
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $mailx_file = "/var/www/copri4/shareeconf/mailx.cfg";
my $conf = Config::General->new($mailx_file);
my %mailxconf = $conf->getall;
open(EMA, ">> $dbt->{copri_conf}->{logdir}/mailtransport.log");
my $mail_from = $sendref->{mail_from} || $mailxconf{$sendref->{mailxcfg}}->{mail_from};
my $mail_to = $sendref->{mail_to} || $mailxconf{$sendref->{mailxcfg}}->{mail_to};
my $filename = $sendref->{filename} || "";
print EMA "\n$now_dt, start mailing to: $mail_to | subject: $sendref->{subject}\n";
my $html = "<html><head><title>$sendref->{subject}</title></head><body style='text-align:left;border:0px solid silver;padding:15px;margin:2%;width:90%;'>\n";
$html .= "<div>$sendref->{message}</div>\n";
$html .= "<div>$sendref->{signature}</div>\n" if($sendref->{signature});
$html .= "</body></html>";
$bw->log("Trying send_mail:$0",$sendref,"");
if(ref($sendref) eq "HASH"){
my $smtp = Net::SMTP->new($mailxconf{$sendref->{mailxcfg}}->{mail_gateway},
my $smtp = Net::SMTP->new($mailxconf{$sendref->{mailxcfg}}->{mail_gateway},
Port => 465,
Hello => 'sharee.bike',
Timeout => 30,
@ -68,18 +49,49 @@ sub send_mail(){
SSL => 1,
);
$smtp->auth($mailxconf{$sendref->{mailxcfg}}->{sasl_username},$mailxconf{$sendref->{mailxcfg}}->{sasl_password});
$smtp->mail($mailxconf{$sendref->{mailxcfg}}->{mail_from});
$smtp->auth($mailxconf{$sendref->{mailxcfg}}->{sasl_username},$mailxconf{$sendref->{mailxcfg}}->{sasl_password});
$smtp->mail($mailxconf{$sendref->{mailxcfg}}->{mail_from});
if($dbt->{copri_conf}->{stage} eq "test"){
$mail_to = $mailxconf{$sendref->{mailxcfg}}->{mail_to};
$sendref->{subject} .= "* offline Test *";
}
return ($smtp,\%mailxconf);
}
sub mail_transport(){
my $self = shift;
my $smtp = shift;
my $mailxconf = shift;
my $sendref = shift;
#print Dumper($smtp);
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
open(EMA, ">> $dbt->{copri_conf}->{logdir}/mailtransport.log");
my $mail_from = $sendref->{mail_from} || $mailxconf->{$sendref->{mailxcfg}}->{mail_from};
my $mail_to = $sendref->{mail_to} || $mailxconf->{$sendref->{mailxcfg}}->{mail_to};
my $subject = $sendref->{subject};
if($dbt->{copri_conf}->{stage} eq "test"){
$mail_to = $mailxconf->{$sendref->{mailxcfg}}->{mail_to};
$subject = "* offline Test * " . $sendref->{subject};
}
print EMA "\n$now_dt, start mailing to: $mail_to | subject: $subject\n";
my $html = "<html><head><title>$subject</title></head><body style='text-align:left;border:0px solid silver;padding:15px;margin:2%;width:90%;'>\n";
$html .= "<div>$sendref->{message}</div>\n";
$html .= "<div>$sendref->{signature}</div>\n" if($sendref->{signature});
$html .= "</body></html>";
$bw->log("Trying send_mail by $0",$mail_to,"");
if(ref($sendref) eq "HASH"){
if ($smtp->to($mail_to)) {
$smtp->data();
$smtp->datasend("To: $mail_to\n");
$smtp->datasend("Subject: $sendref->{subject}\nMIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend("Subject: $subject\nMIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend($html);
$smtp->dataend();
} else {

View file

@ -55,13 +55,20 @@ sub sms_ack_digest {
my $sms_from = "Mietradcode";
my $sms_to = $ctadr->{txt07};# || "+491799xxxx72";
my $sms_message = "";
#goes to test if devel or joke bsp nr
if($dbt->{copri_conf}->{stage} eq "test" || $ctadr->{txt07} =~ /17012345678/){
$ctadr->{txt07} = "$dbt->{copri_conf}->{sms_to}";
$sms_message = "* offline Test *";
}
if($ctadr->{txt07} =~ /^0/ || $ctadr->{txt07} !~ /\+[1-9]/){
my $sms_tosub = $ctadr->{txt07};
$sms_tosub =~ s/^00/\+/g;
$sms_tosub =~ s/^0/\+49/g;
$sms_to = $sms_tosub;
}
my $sms_message = "Ihr Mietradsystem SMS-Bestätigungscode lautet: $sms_ack_digest";
$sms_message .= "Ihr Mietradsystem SMS-Bestätigungscode lautet: $sms_ack_digest";
my $message = Encode::encode('iso-8859-1', Encode::decode('utf-8',"$sms_message"));
open(FILE,">>$dbt->{copri_conf}->{logdir}/sms_gtx.log");

View file

@ -30,8 +30,10 @@ my %varenv = $cf->envonline();
my $cookie = CGI::Cookie->new(-name => 'domcookie',-value => $coo);
print $q->header(-charset=>"utf-8", -cookie=>$cookie);
}
die "no configuration available" if(!$varenv{wwwhost});
my $operator_key = $q->param('api_test');
my $lang = "de";
my $dyn_js = "
function onLoad() {
@ -149,7 +151,7 @@ print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_m
###
print $q->div({-style=>'margin:15px;'},"&nbsp;"),"\n";
my $uriop = "$dbt->{operator}->{sharee_operator}->{operatorApp}/APIjsonserver";
my $uriop = "$dbt->{operator}->{$operator_key}->{operatorApp}/APIjsonserver";
print $q->div({-style=>'margin:15px;'},"-------------- $uriop --------------------"),"\n";
my $booking_request = "$uriop?request=booking_request&bike=FR1003&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_request"},"[ booking_request ]---> $booking_request")),"\n";