APIshareeio for push notify

This commit is contained in:
ragu 2022-06-07 06:53:15 +02:00
parent 782bf6a153
commit 57515256a5
10 changed files with 189 additions and 61 deletions

View file

@ -1030,7 +1030,7 @@ sub booking_update(){
bike => "$bike",
state => "",
lock_state => "",
station_state => "",
#station_state => "",
co2saving => "",
response_state => "OK 1017: No update",
response_text => "Der Mietstatus wurde nicht geändert.",
@ -1167,7 +1167,7 @@ sub booking_update(){
#return after booking_update
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"");
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
@ -1227,7 +1227,7 @@ sub booking_update(){
#return after booking_update
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"");
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
@ -1264,7 +1264,7 @@ sub booking_update(){
#return after booking_update
#my $pricing = $pri->sharee_pricing($record_pos,"calc_price");
#new sharee_pricing
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"");
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
@ -1680,7 +1680,7 @@ sub rentals(){
#$return->{$id} = $pri->sharee_pricing($record->{$id},"readonly");
#new sharee_pricing
(my $return_counting->{$id}, my $counting) = $pri->counting_rental(\%varenv,$record->{$id},"readonly");
(my $return_counting->{$id}, my $counting) = $pri->counting_rental(\%varenv,$record->{$id},"");
my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id},$return_counting->{$id});
$return->{$id} = { %{ $return_counting->{$id} }, %{ $return_feed->{$id} } };

View file

@ -27,13 +27,10 @@ use Mod::APIfunc;
use Mod::APIjsonclient;
use Mod::APIsigclient;
use Data::Dumper;
use Sys::Hostname;
my $hostname = hostname;
sub handler {
my ($r) = @_;
my $q = new CGI;
my $netloc = $q->url(-base=>1);
$q->import_names('R');
my $json = JSON->new->allow_nonref;
my $cf = new Config;
@ -70,7 +67,7 @@ my $response = {
apiserver => "$apiserver",
response => "$respreq",
uri_primary => "$dbt->{primary}->{sharee_primary}->{primaryApp}",
copri_version => "4.1.11.3",
copri_version => "4.1.12.5",
user_id => "",
authcookie => "",
new_authcoo => "0",
@ -79,11 +76,11 @@ my $response = {
user_group => [],
user_tour => [],
response_state => "OK, nothing todo",
agb_html => "site/agb_sharee_1.html",
privacy_html => "site/privacy_2.html",
agb_html => "site/agb.html",
impress_html => "site/impress_1.html",
tariff_info_html => "site/tariff_info.html",
bike_info_html => "site/bike_info.html",
bike_info_html => "site/bike_info_sharee_1.html",
lang => "DE",
last_used_operator => {
operator_name => "sharee.bike | TeilRad GmbH",
@ -257,7 +254,7 @@ elsif($q->param('request') eq "booking_request"){
#sig booking_request
my $sig_book = {
bikeId => "$ct_bike->{txt22}",
bikeId => "",
rentalId => "",
reservationId => ""
};
@ -267,6 +264,7 @@ elsif($q->param('request') eq "booking_request"){
if($ct_bike->{int11} == 3){
$sig_book = $si->sig_booking(\%varenv,"reserve",$authraw,$ct_bike,"");
$sig_book->{bikeId} = "$ct_bike->{txt22}";
$sig_book->{reservationId} = "$R::reservationId" if($R::reservationId);#only for cmd tests
}
$response_book = $apif->booking_request($q,\%varenv,$authraw,$bike,$ct_bike,$ct_tariff,$aowner,$gps,$sig_book);
}elsif(!$ct_tariff->{barcode}){
@ -295,6 +293,7 @@ elsif($q->param('request') eq "booking_request"){
#usecase with reservationId (in ctpos) is in sig not defined, thats because using ct_bike.txt22
#$sig_book = $si->sig_booking(\%varenv,"rental",$authraw,$ct_bike,$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} '' $ctpos->{c_id} &");
$sig_book->{rentalId} = "$R::rentalId" if($R::rentalId);#only for cmd tests
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
$response = {%$response, %$booking_values};
}else{
@ -375,30 +374,32 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
}elsif($q->param('request') eq "booking_update" && (($q->param('state') && $q->param('state') =~ /occupied|available/) || ($q->param('lock_state') && $q->param('lock_state') =~ /locking|locked|unlocking|unlocked/))){
my $booking_values = {};
#update on sig
if($ctpos->{int11} == 3){
if($q->param('state') eq "occupied"){
#$sig_book = $si->sig_booking(\%varenv,"rental",$authraw,"",$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental' $authraw->{c_id} '' $ctpos->{c_id} &");
}
if($q->param('state') eq "available"){
#$sig_book = $si->sig_booking(\%varenv,"rental_end",$authraw,"",$ctpos);
system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental_end' $authraw->{c_id} '' $ctpos->{c_id} &");
#rental/end will be done by sig push-notification
#system("$varenv{basedir}/src/scripts/sig_client.pl $varenv{syshost} 'rental_end' $authraw->{c_id} '' $ctpos->{c_id} &");
}
#TODO, check if booking_values in both cases: push-notify and/or app trigger works
$sig_book->{rentalId} = "$R::rentalId" if($R::rentalId);#only for cmd tests
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
$response = {%$response, %$booking_values};
#update on Ilockit
}else{
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book);
$response = {%$response, %$booking_values};
}
#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 || $authraw->{c_id} == 38883))){
#TODO $ user_miniquery have to be in db table on primary
$bw->log("user_miniquery communicated to user ID",$authraw->{c_id},"");
$bw->log("user_miniquery via $varenv{dbname} user ID $authraw->{c_id} exist count:",$authraw->{int23},"");
my $user_miniquery = {
title => "Bitte unterstützen Sie unsere Begleitforschung",
subtitle => "Ihre drei Antworten werden anonym gespeichert.",
@ -440,21 +441,22 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
};
$response->{user_miniquery} = $user_miniquery;
}#end mini_quest
#user_miniquest_count
my $user_miniquest_count = $authraw->{int23} || 0;
if($q->param('request') && $q->param('request') eq "booking_update" && $q->param('state') eq "available" && $user_miniquest_count <= 4){
$user_miniquest_count++;
my $update_op = {
#user_miniquest_count
my $user_miniquest_count = $authraw->{int23} || 0;
if($user_miniquest_count <= 4){
$user_miniquest_count++;
my $update_op = {
table => "contentadr",
int23 => $user_miniquest_count,
atime => "now()",
owner => "198",
};
my $rows = $dbt->update_record($dbh,$update_op,$authraw);
}
}
my $rows = $dbt->update_record($dbh,$update_op,$authraw);
}
}#end mini_quest
}#end occupied|available
my $record = $apif->user_bikes_occupied($q,$authraw);
$response->{bikes_occupied} = $apif->rentals($record,$authraw,"1");

View file

@ -0,0 +1,136 @@
package Mod::APIshareeio;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
use warnings;
use strict;
use Exporter;
our @ISA = qw (Exporter);
use POSIX;
use CGI;
use Apache2::Const -compile => qw(OK );
use JSON;
use Scalar::Util qw(looks_like_number);
use Config::General;
use Lib::Config;
use Mod::DBtank;
use Mod::Basework;
use Mod::Shareework;
use Mod::APIfunc;
use Data::Dumper;
sub handler {
my ($r) = @_;
my $q = new CGI;
my $netloc = $q->url(-base=>1);
$q->import_names('R');
my $json = JSON->new->allow_nonref;
my $cf = new Config;
my $dbt = new DBtank;
my $bw = new Basework;
my $tk = new Shareework;
my $apif = new APIfunc;
my $dbh = "";
my %varenv = $cf->envonline();
my $oprefix = $dbt->{operator}->{$varenv{dbname}}->{oprefix};
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my @keywords = $q->param;
my $user_agent = $q->user_agent();
my $aowner = 168;
my $dbh = "";
my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg";
my $aconf = Config::General->new($api_file);
my %apikeyconf = $aconf->getall;
my %headers = map { $_ => $q->http($_) } $q->http();
$bw->log("APIshareeio request:\n--> user-agent '$user_agent' ",$q,"");
$bw->log("headers:",\%headers,"");
#for my $header ( keys %headers ) {
# print "$header: $headers{$header}\n";
#}
print $q->header(-type => "application/json", -charset => "utf-8", -'Access-Control-Allow-Origin' => "*");
my $response = {
response_state => "OK, nothing todo",
};
my $http_sharee_api_key = $headers{HTTP_SHAREE_API_KEY} || $R::HTTP_SHAREE_API_KEY || "";
if(!$apikeyconf{shareeio}->{sharee_api_key} || !$http_sharee_api_key || $apikeyconf{shareeio}->{sharee_api_key} ne $http_sharee_api_key){
$response->{response_state} = "Failure: access denied, api-key doesn't match";
$bw->log("Failure: access denied, api-key doesn't match",$q,"");
my $jrout = $json->pretty->encode({shareeio => $response});
print $jrout;
return Apache2::Const::OK;
exit 0;
}
foreach(@keywords){
if(length($_) > 20 || length($q->param($_)) > 40){
$response->{response_state} = "Failure 9000: amount of characters in $_ exceeds";
$bw->log("Failure 9000: amount of characters in $_ exceeds",$q,"");
my $jrout = $json->pretty->encode({shareeio => $response});
print $jrout;
return Apache2::Const::OK;
exit 0;
}
}
#sig booking_update
if($R::request && $R::request eq "booking_update"){
my $rentalId = $q->escapeHTML($R::rentalId) || "";
my $rows = 0;
my $booking_values = {};
if($rentalId){
if($R::state && $R::lock_state && $R::state eq "available" && $R::lock_state eq "locked"){
my $ctpos = {};
my $booking_pos = {
table => "contenttranspos",
fetch => "one",
txt11 => "$rentalId",
int10 => "IN::('2','3')",
#ca_id => "$authraw->{c_id}",#sig doesn't know uid
};
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos);
if(ref($ctpos) eq "HASH" && $ctpos->{txt22} && $ctpos->{txt11}){
my $sig_book = {
bikeId => $ctpos->{txt22},
rentalId => $ctpos->{txt11},
reservationId => ""
};
my $authraw = { c_id => "" };
$authraw->{c_id} = $ctpos->{ca_id} if($ctpos->{ca_id});
$q->param(-name=>'bike',-value=>"$ctpos->{ct_name}") if($ctpos->{ct_name});
($rows, $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$sig_book) if($authraw->{c_id});
$response = {%$response, %$booking_values};
}else{
$response->{response_state} = "Failure: there is no rental with rentalID=$rentalId";
}
}else{
$response->{response_state} = "Failure: syntax failure";
}
}else{
$response->{response_state} = "Failure: no rentalId defined";
}
}#end sig booking_update
#end RESTful ------------------------------------------------------------
#FINAL JSON response OUTPUT ----------------------------------------------------------
my $jrout = $json->pretty->encode({shareeio => $response});
print $jrout;
$bw->log("APIjsonserver response by $user_agent mapped aowner:$aowner",$jrout,"");
#end JSON ----------------------------------------------------------------------------
return Apache2::Const::OK;
}#end handler
1;

View file

@ -276,31 +276,33 @@ sub users_map(){
sub channel_map(){
my $self = shift;
my $channel = {
167 => "sig cmd",
168 => "shareeio",
169 => "sig connector",
172 => "cron timeout",
173 => "merchant fallback",#mig
175 => "example App",#mig
#173 => "merchant fallback",#mig
#175 => "example App",#mig
176 => "Mein konrad App",#mig
177 => "LastenradBay App",#mig
179 => "cronjob",
178 => "payone API",
181 => "SMS API",
182 => "velofactur API",
#181 => "SMS API",
#182 => "velofactur API",
183 => "Ilockit API",
184 => "web App",#mig
185 => "konstanz App",#mig
186 => "sharee App",#mig
#184 => "web App",#mig
#185 => "konstanz App",#mig
186 => "sharee.bike App",#mig
187 => "shareetool",#mig
188 => "sys API",
192 => "web Bayern",
193 => "web demo",#mig
194 => "web example",#mig
#193 => "web demo",#mig
#194 => "web example",#mig
195 => "web konrad",#mig and import
196 => "DMS Form std",#mig
196 => "copri",#mig
197 => "web sharee.bike",#mig
198 => "primary",#mig
199 => "LV API",#mig
201 => "web Rentamania",#mig
201 => "web Renta",#mig
};
return $channel;
}

View file

@ -266,20 +266,15 @@ sub handler {
#Menu & node_path handling
my ($view,$view_post);
my @viewsel = ("shareestart");
if($path =~ /^\/(.*)/){
my $view = "";
my @viewsel = ("app","shareestart");
if($path && $path =~ /^\/\w/ && $path =~ /^\/(.*)/){
@viewsel = split /\//,$1;
if("$path" =~ /\/($modes)$/){
if("$path" =~ /\/$modes$/){
pop @viewsel;
}
$view_post = $viewsel[-1] || "root";
#$view_post = encode('iso-8859-1',decode('utf-8', $view_post));
$view = $viewsel[0];
}
my $depth = scalar(@viewsel);
$view = "root" if(!$view);
my $node_meta = $dbt->get_node_meta($dbh,\@viewsel);
#DMS & Tools

View file

@ -153,15 +153,8 @@ sub counting_rental {
my $used_max_fee = "off";
my $used_methode = "";
#readonly if bike available then take saved $total_price
if($ctpos->{int10} && $ctpos->{int10} == 1 && $todo eq "readonly"){
#if($ctpos->{int38} && $ctpos->{int38} > 0 && $ctpos->{int35} && $ctpos->{int35} > 0){
# $total_price = $ctpos->{int38} * $ctpos->{int35};
# $used_methode = "readonly $ctpos->{int38} pos.int38 * $ctpos->{int35} pos.int35";
#}
}
#on time unit (int35 keeps unit_price1)
elsif($rental_minute && $rental_minute > 0 && $ctpos->{int35} && $ctpos->{int35} > 0){
if($rental_minute && $rental_minute > 0 && $ctpos->{int35} && $ctpos->{int35} > 0){
$rental_unit = $rental_minute / $tariff_unitbyminute;
$price_by_allunit = $rental_unit * $ctpos->{int35};

View file

@ -121,7 +121,7 @@ sub tpl(){
print $q->end_form;
print $q->start_form();
print "<div id='Content4list' style='font-size:0.91em;min-width:1300px;'>\n";
print "<div id='Content4list' style='font-size:0.91em;min-width:1400px;'>\n";
my $start_date_time = $R::start_date_time;
my $end_date_time = $R::end_date_time;

View file

@ -45,8 +45,8 @@ sub tpl(){
#my $api_test = "sharee_fr01"; my $bike="FR1538";
#my $api_test = "sharee_fr01"; my $bike="FR4781";#Tracking and BVB test
#my $api_test = "sharee_kn"; my $bike="KN205";
#my $api_test = "sharee_wue"; my $bike="WUE5524";
my $api_test = "sharee_sx"; my $bike="S3X1001";
my $api_test = "sharee_wue"; my $bike="WUE5524";
#my $api_test = "sharee_sx"; my $bike="S3X1001";
#my $api_test = "sharee_ren"; my $bike="REN2";
print $q->div({-style=>'float:right;text-align:right;height:25px;padding:6px 15px;background-color:white'},$q->a({-style=>"background-color:#ffffff;color:#$bgcolor1;", -href=>"$varenv->{metahost}/src/scripts/tests/index.pl?sessionid=$coo\&api_test=$api_test\&bike=$bike", -target=>'_blank'}," [ tests --> $api_test ] "),"$users_sharee->{txt08}",$q->a({-style=>"color:#$bgcolor1;", -href=>"logout_sharee$session"},"logout")),"\n";

View file

@ -166,7 +166,7 @@ Weitere Personen aus Ihrem Haushalt profitieren jedoch ebenfalls, falls Sie weit
my $sharee_agb_text = {};
$sharee_agb_text->{ct_name} = "AGB";
$sharee_agb_text->{txt01} = "<iframe src='$varenv->{wwwhost}/site/agb.html' style='width:100%;height:10000px;border:none;' scrolling='auto'></iframe>";
$sharee_agb_text->{txt01} = "<iframe src='$varenv->{wwwhost}/site/agb_sharee_1.html' style='width:100%;height:10000px;border:none;' scrolling='auto'></iframe>";
my $sharee_privacy_text = {};
$sharee_privacy_text->{ct_name} = "Datenschutzhinweise";
$sharee_privacy_text->{txt01} = "<iframe src='$varenv->{wwwhost}/site/privacy_2.html' style='width:100%;height:8000px;border:none;' scrolling='auto'></iframe>";

View file

@ -204,7 +204,7 @@ sub tpl(){
my $sharee_privacy_text = {};
$sharee_privacy_text->{ct_name} = "Datenschutzhinweise";
$sharee_privacy_text->{txt01} = "<iframe src='$varenv->{wwwhost}/site/privacy_2.html' style='width:100%;height:6000px;border:none;' scrolling='auto'></iframe>";
$sharee_privacy_text->{txt01} = "<iframe src='$varenv->{wwwhost}/site/privacy_lastenradbayern.html' style='width:100%;height:8000px;border:none;' scrolling='auto'></iframe>";
print <<EOF
<!-- Modal -->