shareetool operator fix

This commit is contained in:
Rainer Gümpelein 2022-01-31 14:55:05 +01:00
parent fe9ae91ff8
commit c7c9e0e699
5 changed files with 80 additions and 34 deletions

View file

@ -57,7 +57,11 @@ sub fetch_merchant {
my $req_coo = shift || "";
my $req_merchant_id = shift || "";
my $return = { merchant_id => "" };
my $return = {
aowner => "",
merchant_id => "",
project_id => ""
};
my $merchanized = 0;
my $aowner = 0;
@ -65,8 +69,9 @@ sub fetch_merchant {
#$bw->log("---> trying merchant select by session-cookie OR authcookie OR merchant_id: if($merchant_conf && (($req_coo && $req_coo =~ /$merchant_conf/) || ($req_merchant_id && $req_merchant_id eq $merchant_conf))){",$merchant_conf,"");
if($merchant_conf && (($req_coo && $req_coo =~ /$merchant_conf$/) || ($req_merchant_id && $req_merchant_id eq $merchant_conf))){
$aowner = $value->{id};
$merchanized = 1;
$aowner = $value->{id};
$return->{aowner} = $value->{id};
$return->{merchant_id} = $merchant_conf;
$return->{project_id} = $value->{project};
my $lat = "";
@ -87,6 +92,7 @@ sub fetch_merchant {
if(!$merchanized){
if($varenv->{syshost} eq "shareeapp-primary" || $varenv->{syshost} eq "shareedms-primary"){
$aowner = $dbt->{primary}->{sharee_primary}->{owner};
$return->{aowner} = $dbt->{primary}->{sharee_primary}->{owner};
$return->{merchant_id} = $dbt->{primary}->{sharee_primary}->{merchant_id};
$return->{project_id} = $dbt->{primary}->{sharee_primary}->{project};
$merchanized = 1;
@ -94,6 +100,7 @@ sub fetch_merchant {
}
elsif($varenv->{syshost} =~ /shareeapp-(\w+)/ || $varenv->{syshost} =~ /shareedms-(\w+)/){
$aowner = $dbt->{operator}->{$varenv->{dbname}}->{owner};
$return->{aowner} = $dbt->{operator}->{$varenv->{dbname}}->{owner};
$return->{merchant_id} = $dbt->{operator}->{$varenv->{dbname}}->{merchant_id};
$return->{project_id} = $dbt->{operator}->{$varenv->{dbname}}->{project};
$merchanized = 1;
@ -101,6 +108,7 @@ sub fetch_merchant {
}
elsif($varenv->{syshost} =~ /shareeweb-/){
$aowner = $dbt->{website}->{$varenv->{syshost}}->{owner};
$return->{aowner} = $dbt->{website}->{$varenv->{syshost}}->{owner};
$return->{merchant_id} = $dbt->{website}->{$varenv->{syshost}}->{merchant_id};
$return->{project_id} = $dbt->{website}->{$varenv->{syshost}}->{project};
$merchanized = 1;

View file

@ -14,6 +14,7 @@ use LWP::UserAgent;
use URI::Encode;
use Config::General;
use Mod::Basework;
use Mod::DBtank;
use Data::Dumper;
@ -31,17 +32,17 @@ my $ua = LWP::UserAgent->new;
my $uri_encode = URI::Encode->new( { encode_reserved => 1 } );
$ua->agent("APIclient $netloc");
my $bw = new Basework;
my $dbt = new DBtank;
my $json = JSON->new->allow_nonref;
sub loop_sharees {
my $self = shift;
my $q = shift || "";
my $auth = shift;
my $authraw = shift;
my $return_merchant = shift || "";
my @keywords = $q->param;
#my $project = "all";
my $project = $return_merchant->{project_id} || "all";
#my $project = $return_merchant->{project_id} || "all";
#only request keys which initated by sharee primary requests to operator
my $rest = "";
@ -50,12 +51,6 @@ sub loop_sharees {
my $val = $q->param($_);
my $encoded_val = $uri_encode->encode($val);
$rest .= "$_=$encoded_val&";
#}elsif($_ eq "project"){
#my $val = $q->param($_);
#$project = $val if($val eq "Bayern");#restricted map view only on lastenrad bayern iframe
#$project = $val if($val eq "Konstanz");
#$project = $val if($val eq "Demo");
#$project = $val if($val eq "LastenVelo");
}
}
$rest =~ s/\&$//;
@ -72,10 +67,18 @@ sub loop_sharees {
my $fetch_hash = {};
while (my ($key, $value) = each %{ $globalconf{operator} }) {
my $ret_json = "";
#print $key;# like sharee_fr01
if($value->{operatorApp} && ($project eq $value->{project} || $project eq "all")){
$bw->log("--> LOOP-start ($return_merchant->{merchant_id}) jsonclient loop_sharees $key by operatorApp: $value->{operatorApp}, netloc: $netloc if($project eq $value->{project} || $project eq \"all\")\n","","");
#shareetool, to loop only operators who is the shareetool by usersconf enabled
my $users_serviceapp = { u_id => 0 };
if($return_merchant->{aowner} && $return_merchant->{aowner} == 187 && $value->{database}->{dbname} && $authraw->{txt17} =~ /$value->{database}->{dbname}/){
my $dbh_operator = $dbt->dbconnect_extern($value->{database}->{dbname});
$users_serviceapp = $dbt->select_users($dbh_operator,$authraw->{c_id},"and int09=1");
$bw->log("shareetool select_users $return_merchant->{aowner} on $value->{database}->{dbname} $authraw->{c_id} $authraw->{txt17}",$users_serviceapp->{u_id},"");
}
if($value->{operatorApp} && ($return_merchant->{project_id} eq $value->{project} || $users_serviceapp->{u_id})){
$bw->log("--> LOOP-start ($return_merchant->{merchant_id}) jsonclient loop_sharees $key by operatorApp: $value->{operatorApp}, netloc: $netloc if($return_merchant->{project_id} eq $value->{project} || $users_serviceapp->{u_id} > 0)\n","","");
$ret_json = $self->fetch_operator_json($value->{operatorApp},$rest);
if($ret_json){
push(@uri_operator_array, $value->{operatorApp});

View file

@ -64,7 +64,7 @@ my $response = {
apiserver => "$apiserver",
response => "$respreq",
uri_primary => "$dbt->{primary}->{sharee_primary}->{primaryApp}",
copri_version => "4.1.9.6",
copri_version => "4.1.10.2",
user_id => "",
authcookie => "",
new_authcoo => "0",
@ -289,7 +289,7 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
#keep in mind, it works on operator dependency
$bw->log("user_miniquery via $varenv{dbname} exist count:",$authraw->{int23},"");
#Nur für project=Bayern und für Entwickler aktiviert
if($booking_values->{state} eq "available" && $dbt->{operator}->{$varenv{dbname}}->{project} eq "Bayern" && (($authraw->{int23} >= 1 && $authraw->{int23} < 4) || ($authraw->{c_id} == 1842 || $authraw->{c_id} == 5781 || $authraw->{c_id} == 11765 || $authraw->{c_id} == 1843))){
if($booking_values->{state} eq "available" && (($dbt->{operator}->{$varenv{dbname}}->{project} eq "Bayern" && $authraw->{int23} >= 1 && $authraw->{int23} < 4) || ($authraw->{c_id} == 1842 || $authraw->{c_id} == 5781 || $authraw->{c_id} == 11765 || $authraw->{c_id} == 1843))){
#TODO $ user_miniquery have to be in db table on primary
$bw->log("user_miniquery communicated to user ID",$authraw->{c_id},"");
@ -393,7 +393,7 @@ elsif($q->param('request') eq "user_bikes_occupied"){
my ($auth,$authraw) = $apif->auth_verify($q);
if(ref($auth) eq "HASH" && $auth->{authcookie}){
$response = { %$response, %$auth };
($response->{bikes_occupied},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$return_merchant);
($response->{bikes_occupied},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$authraw,$return_merchant);
}else{
$response->{response_state} = "Failure 1001: authcookie on primary not defined";
$response->{response_text} = "Entschuldigung, die Session wurde unterbrochen";
@ -424,7 +424,7 @@ elsif($q->param('request') eq "bikes_available"){
my ($auth,$authraw) = $apif->auth_verify($q);
$response = { %$response, %$auth };
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$return_merchant);
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$authraw,$return_merchant);
#my $stamp = gettimeofday;
#$bw->log("X bikes_available $varenv{syshost} $stamp: $response->{user_group}",$response,"");
}else{
@ -452,7 +452,7 @@ elsif($q->param('request') eq "bikes_all"){
my ($auth,$authraw) = $apif->auth_verify($q);
$response = { %$response, %$auth };
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$return_merchant);
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$authraw,$return_merchant);
}else{
($aowner,my $return_merchant) = $apif->fetch_merchant($q,\%varenv,$coo,$q->param('merchant_id'));
$varenv{merchant_id} = $return_merchant->{merchant_id};
@ -461,7 +461,7 @@ elsif($q->param('request') eq "bikes_all"){
$response = { %$response, %$auth };
$response->{response_text} = "Vorsicht, das ist die Liste aller Leihräder unabhängig von der Verfügbarkeit";
#on servicetool only stations on user_tour
#on shareetool only stations on user_tour
my $stations_allraw = {};
(my $stations_not_used,$stations_allraw) = $apif->stations_all($q,\%varenv,"",$authraw) if($aowner && $aowner eq "187");#shareetool
@ -603,7 +603,7 @@ elsif($q->param('request') eq "stations_all"){
my ($auth,$authraw) = $apif->auth_verify($q);
$response = { %$response, %$auth };
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$return_merchant);
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$authraw,$return_merchant);
}else{
($aowner,my $return_merchant) = $apif->fetch_merchant($q,\%varenv,$coo,$q->param('merchant_id'));
$varenv{merchant_id} = $return_merchant->{merchant_id};
@ -629,7 +629,7 @@ elsif($q->param('request') eq "stations_available"){
#$response->{merchant_message} = "Herzlich Willkommen bei der neuen konrad App! Die App ist zwar schon installierbar, bis zur vollständigen Umstellung des Systems sind aber noch keine Räder ausleihbar. Das ist erst voraussichtlich Ende Januar der Fall und wird den Nutzern noch mitgeteilt. Danke für Ihr Verständnis! Ihr konrad-Team";
#}
$response = { %$response, %$auth };
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$return_merchant);
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$authraw,$return_merchant);
}else{
($aowner,my $return_merchant) = $apif->fetch_merchant($q,\%varenv,$coo,$q->param('merchant_id'));
$varenv{merchant_id} = $return_merchant->{merchant_id};

View file

@ -12,9 +12,9 @@ use strict;
use warnings;
use POSIX;
use CGI ':standard';
use Email::MIME;
use IO::All;
use Net::SMTP;
use MIME::Base64 qw( encode_base64 );
use Try::Tiny;
use Config::General;
@ -45,7 +45,7 @@ sub mail_connect {
Port => 465,
Hello => 'sharee.bike',
Timeout => 30,
Debug => 0,
Debug => 1,
SSL => 1,
);
@ -70,6 +70,14 @@ sub mail_transport(){
my $mail_to = $sendref->{mail_to} || $mailxconf->{$sendref->{mailxcfg}}->{mail_to};
my $subject = $sendref->{subject};
my ($buf, $picture);
my $boundary = 'frontier';
my $pdfpath = "$dbt->{copri_conf}->{basedir}/$sendref->{syshost}/pdf";
my $attachBinaryFile = "sharee.pdf";
if(-f "$pdfpath/Rechnung-sharee_fr01-21084-4.pdf"){
$attachBinaryFile = "Rechnung-sharee_fr01-21084-4.pdf";
}
if($dbt->{copri_conf}->{stage} eq "test"){
$mail_to = $mailxconf->{$sendref->{mailxcfg}}->{mail_to};
$subject = "* offline Test * " . $sendref->{subject};
@ -91,9 +99,43 @@ sub mail_transport(){
if ($smtp->to($mail_to)) {
$smtp->data();
$smtp->datasend("To: $mail_to\n");
$smtp->datasend("Subject: $subject\nMIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend($html);
$smtp->dataend();
#$smtp->datasend("Subject: $subject\nMIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("MIME-Version: 1.0\n");
#$smtp->datasend("Content-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n");
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
#$smtp->datasend("Content-type: text/plain\n");
#$smtp->datasend("\nToday\'s files are attached:\n\nHave a nice day! :)\n");
$smtp->datasend("Content-Type: text/html; charset=UTF-8 \n\n");
$smtp->datasend($html);
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
#$smtp->datasend("Content-Type: image/jpeg; name=\"$attachBinaryFile\"\n");
$smtp->datasend("Content-Type: application/pdf; name=\"$attachBinaryFile\"\n");
$smtp->datasend("Content-Transfer-Encoding: base64\n");
$smtp->datasend("Content-Disposition: attachment; filename=\"$attachBinaryFile\"\n");
$smtp->datasend("\n");
if(1==1){
open(DAT, "$pdfpath/$attachBinaryFile") || die("Could not open $pdfpath/$attachBinaryFile");
binmode(DAT);
local $/=undef;
while (read(DAT, $picture, 4104)) {
$buf = &encode_base64( $picture );
$smtp->datasend($buf);
}
$smtp->datasend("\n");
close(DAT);
}
$smtp->datasend("--$boundary\r\n\r");
$smtp->dataend();#doesn't exit
$smtp->quit;
} else {
print EMA $smtp->message();
}

View file

@ -393,13 +393,6 @@ sub save_account(){
if($valxx !~ /\d{9}/ || length($valxx) > 16){
$ret = "failure::$_#top";
}else{
my $lastnum = $valxx;
$lastnum = $1 if($valxx =~ /(\d{9})$/);
my $phone_check = &check_account("","txt07","~",$lastnum,"c_id","!=",$c_id);
if($phone_check->{c_id} && $phone_check->{c_id} != $c_id){
my $encoded_val = $uri_encode->encode($valxx);
$ret_conflict = "failure::conflict_$_=$encoded_val#top";
}
#smsAck reset
if($valxx ne $ctadr->{txt07}){
$u_rows = $dbt->update_one($dbh,$update_primary,"int13=0");