mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2024-11-15 15:06:38 +01:00
114 lines
3.3 KiB
Perl
114 lines
3.3 KiB
Perl
|
#!/usr/bin/perl
|
||
|
#
|
||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||
|
#
|
||
|
# sudo su www-data -c "./src/scripts/sig_client.pl shareeapp-sx bikes_available"
|
||
|
#
|
||
|
# 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'"
|
||
|
#
|
||
|
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] || "";
|
||
|
my $sig_bike_id = $ARGV[3] || "";
|
||
|
|
||
|
open(FILE,">>$varenv{logdir}/APIsigclient.log");
|
||
|
print FILE "\n*** $now_dt 'sig_client fork with todo:$todo|user_id:$user_id|sig_bike_id:$sig_bike_id' \n";
|
||
|
|
||
|
#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);
|
||
|
|
||
|
my $ct_bike = { txt22 => "" };
|
||
|
|
||
|
my $posref = {
|
||
|
table => "contenttranspos",
|
||
|
fetch => "one",
|
||
|
ca_id => "$ctadr->{c_id}",
|
||
|
int10 => "IN::('3','2')",
|
||
|
txt22 => "$sig_bike_id",
|
||
|
};
|
||
|
my $ctpos = { c_id => 0 };
|
||
|
$ctpos = $dbt->fetch_tablerecord($dbh,$posref) if($user_id =~ /^\d+$/ && $user_id > 0 && $sig_bike_id);
|
||
|
|
||
|
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";
|
||
|
}
|
||
|
|
||
|
#only for tests
|
||
|
elsif($todo eq "reserve"){
|
||
|
#$ctadr = { c_id => 1842 };
|
||
|
#$ct_bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };
|
||
|
my $return = $si->sig_booking(\%varenv,$ctadr,$ct_bike,$ctpos,$todo);
|
||
|
#print $0 . Dumper($return) . "\n";
|
||
|
}
|
||
|
|
||
|
#used also live! to fork rental request with
|
||
|
elsif($todo eq "rental" && $ctadr->{c_id} > 0 && $ctpos->{txt22}){
|
||
|
#$ctadr = { c_id => 1842 };
|
||
|
#$ct_bike = { txt22 => "380116b5-0522-43da-ab66-477744a731a3" };
|
||
|
my $return = $si->sig_booking(\%varenv,$ctadr,$ct_bike,$ctpos,$todo);
|
||
|
#print $0 . Dumper($return) . "\n";
|
||
|
}
|
||
|
|
||
|
#used also live! to fork rental_end request with "rentalId"
|
||
|
elsif($todo eq "rental_end" && $ctadr->{c_id} > 0 && $ctpos->{txt11}){
|
||
|
my $return = $si->sig_booking(\%varenv,$ctadr,$ct_bike,$ctpos,$todo);
|
||
|
#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);
|
||
|
|