sharee.bike/copri4/main/src/scripts/sig_client.pl

131 lines
3.8 KiB
Perl
Raw Normal View History

2022-05-11 08:05:35 +02:00
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
2022-06-02 10:34:03 +02:00
#On this forking script, nothing will saved on script, else by execute APIsigclient methodes
#
# command line syntax
# sudo su www-data -c "./src/scripts/sig_client.pl shareeapp-sx 'todo' 'user_id' 'bike_id' 'pos_id'"
#
2022-05-11 08:05:35 +02:00
# sudo su www-data -c "./src/scripts/sig_client.pl shareeapp-sx bikes_available"
#
2022-06-02 10:34:03 +02:00
# sudo su www-data -c "./src/scripts/sig_client.pl shareeapp-sx reserve 1842 '380116b5-0522-43da-ab66-477744a731a3' ''"
# sudo su www-data -c "./src/scripts/sig_client.pl shareeapp-sx rental 1842 '380116b5-0522-43da-ab66-477744a731a3' ''"
2022-05-11 08:05:35 +02:00
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die 'syshost not defined';
}
use lib "/var/www/copri-bike/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI;
use Scalar::Util qw(looks_like_number);
use Mod::DBtank;
use Mod::APIsigclient;
use Data::Dumper;
my $q = new CGI;
my $cf = new Config;
my $dbt = new DBtank;
my $si = new APIsigclient;
my $bw = new Basework;
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my %varenv = $cf->envonline();
my $dbh = "";
my $todo = $ARGV[1] || "";
my $user_id = $ARGV[2] || "";
2022-06-02 10:34:03 +02:00
my $bike_id = $ARGV[3] || "";
my $pos_id = $ARGV[4] || "";
2022-05-11 08:05:35 +02:00
open(FILE,">>$varenv{logdir}/APIsigclient.log");
2022-05-27 17:11:35 +02:00
print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|pos_id:$pos_id' \n";
2022-05-11 08:05:35 +02:00
#get user and bike in copri by id
my $apref = {
table => "contentadr",
fetch => "one",
template_id => "202",
c_id => "$user_id",
};
my $ctadr = { c_id => 0 };
$ctadr = $dbt->fetch_record($dbh,$apref) if($user_id =~ /^\d+$/ && $user_id > 0);
2022-06-02 10:34:03 +02:00
my $ct_bike = { txt22 => "$bike_id" };
2022-05-11 08:05:35 +02:00
my $posref = {
table => "contenttranspos",
fetch => "one",
ca_id => "$ctadr->{c_id}",
int10 => "IN::('3','2')",
2022-05-27 17:11:35 +02:00
c_id => "$pos_id",
2022-05-11 08:05:35 +02:00
};
my $ctpos = { c_id => 0 };
2022-06-02 10:34:03 +02:00
$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $pos_id && $pos_id =~ /^\d+$/);
2022-05-11 08:05:35 +02:00
print FILE "fetched from DB ctadr:$ctadr->{c_id}|ctpos:$ctpos->{c_id}\n";
#only for tests
if($todo eq "stations_available"){
$q->param(-name=>'request',-value=>"stations_available");
$ctadr = { c_id => 0 };
my $return = $si->sig_available($q,\%varenv,$ctadr);
#print $0 . Dumper($return) . "\n";
}
#only for tests
if($todo eq "bikes_available"){
$q->param(-name=>'request',-value=>"bikes_available");
#$ctadr = { c_id => 0 };
my $return = $si->sig_available($q,\%varenv,$ctadr);
#print $0 . Dumper($return) . "\n";
}
2022-06-02 10:34:03 +02:00
#sig => copri key mapping
#bike id => txt22
#reservationId => txt10
#renatlId => txt11
#only for tests. build in methode
2022-05-11 08:05:35 +02:00
elsif($todo eq "reserve"){
#$ctadr = { c_id => 1842 };
#$ct_bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };
2022-06-02 10:34:03 +02:00
my $return = $si->sig_booking(\%varenv,$todo,$ctadr,$ct_bike,$ctpos);
2022-05-11 08:05:35 +02:00
#print $0 . Dumper($return) . "\n";
}
2022-06-02 10:34:03 +02:00
#live! Fork rental request with bike "id"
2022-05-11 08:05:35 +02:00
elsif($todo eq "rental" && $ctadr->{c_id} > 0 && $ctpos->{txt22}){
#$ctadr = { c_id => 1842 };
#$ct_bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };
2022-06-02 10:34:03 +02:00
my $return = $si->sig_booking(\%varenv,$todo,$ctadr,$ct_bike,$ctpos);
2022-05-11 08:05:35 +02:00
#print $0 . Dumper($return) . "\n";
}
2022-06-02 10:34:03 +02:00
#live! Fork rental_end request with "rentalId"
2022-05-11 08:05:35 +02:00
elsif($todo eq "rental_end" && $ctadr->{c_id} > 0 && $ctpos->{txt11}){
2022-06-02 10:34:03 +02:00
my $return = $si->sig_booking(\%varenv,$todo,$ctadr,$ct_bike,$ctpos);
#print $0 . Dumper($return) . "\n";
}
#only for tests. build in methode
elsif($todo eq "rentals_running" && $ctadr->{c_id} > 0 && $ctpos->{txt22}){
my $return = $si->sig_booking(\%varenv,$todo,$ctadr,$ct_bike,$ctpos);
2022-05-11 08:05:35 +02:00
#print $0 . Dumper($return) . "\n";
}
else{
print FILE "failure::sig_client request not defined: $todo && $ctadr->{c_id} > 0 && $ctpos->{txt22}\n";
close(FILE);
exit 1;
}
close(FILE);