Initial commit

This commit is contained in:
Rainer Gümpelein 2021-12-30 12:05:56 +01:00
parent b686656e88
commit 5e91fe947d
177 changed files with 41037 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,47 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Arrays;
public class Ilockauth {
public static void main( String args[] ) {
String db_id = args[0];
String bike_id = args[1];
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/" + db_id,
"postgres", "");
c.setAutoCommit(false);
//System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM content where barcode=" + bike_id + ";" );
while ( rs.next() ) {
byte[] randomNum = new byte[16];
byte[] K_int = rs.getBytes("byte01");
//example by byte[]
//byte[] K_int = {(byte) 0xA7, (byte) 0x99, (byte) 0x91, 0x12, 0x49, (byte) 0xE0, (byte) 0xBA, (byte) 0xD5, (byte) 0xF2, 0x48, (byte) 0x8D, (byte) 0xC1, 0x7E, 0x28, 0x2D, (byte) 0xD0};
System.out.println( "K_int = " + Arrays.toString(K_int));
Ilockkeygen.generateKey(randomNum, K_int);
}
rs.close();
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
//System.out.println("Operation done successfully");
}
}

View file

@ -0,0 +1,143 @@
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#For pdf pw files
#"pdftotext -upw FksjxxxxxxfmC1h Teilrad_ISI_PLUS_BB01207.pdf"
#:1,$ s/^\n//g
#:1,$ s/\n/;/g
#:1,$ s/;C2-/\rC2-/g
#:1,$ s/;QR-/\rQR-/g
#
#
#check if UTF-8
#file Teilrad_ISI_PLUS_BB01207.txt
#iconv -t utf-8 -f iso-8859-1 Ilockitkeys_110520.csv -o Ilockitkeys_110520_utf8.cs
#
#sudo su www-data -c "./src/scripts/Ilockit_CSV2DB.pl shareedms-fr01 Teilrad_ISI_GPS_BB01328.txt"
#
#do it twice to set hex-key and bike-nr!
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || exit 1;
}
use lib "/var/www/copri4/$syshost/src";
my $csv_file = $ARGV[1] || "";
use strict;
use warnings;
use POSIX;
use DBI;
use CGI ':standard';
use Lib::Config;
use Mod::DBtank;
use Scalar::Util qw(looks_like_number);
use Data::Dumper;
my $q = new CGI;
my $cf = new Config;
my %varenv = $cf->envonline("$syshost");
print "$varenv{wwwhost}\n";
my $dbt = new DBtank;
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $dbh = "";
my $main_id = 300001;#TODO Mietrad Flotten ID
my $template_id = 205;
###
#Start loop payone log and update userid ##################################
####
#reading CSV
my $dbh_csv = DBI->connect("DBI:CSV:");
$dbh_csv->{'csv_tables'}->{'ilockitcsv'} = {
'eol' => "\n",
'sep_char' => ";",
'quote_char' => undef,
#'quote_char' => "\"",
'escape_char' => undef,
'file' => $csv_file,
'col_names' => ["serialnr","ilockit_id","ilockit_key","c1","c2","c3","c4","c5","c6"]
};
my $sth = $dbh_csv->prepare("SELECT * FROM ilockitcsv where serialnr like 'C2-%'");
my $rc = $sth->execute();
my $csv = $sth->fetchall_hashref("serialnr");
my $i=0;
foreach my $id (sort { $csv->{$a}->{serialnr} cmp $csv->{$b}->{serialnr} } keys (%$csv)){
$i++;
if($csv->{$id}->{serialnr}){
$csv->{$id}->{ilockit_id} =~ s/\+/\-/;
$csv->{$id}->{c1} =~ s/Rot/red/;$csv->{$id}->{c1} =~ s/Blau/blue/;$csv->{$id}->{c1} =~ s/Gr.+n/green/;
$csv->{$id}->{c2} =~ s/Rot/red/;$csv->{$id}->{c2} =~ s/Blau/blue/;$csv->{$id}->{c2} =~ s/Gr.+n/green/;
$csv->{$id}->{c3} =~ s/Rot/red/;$csv->{$id}->{c3} =~ s/Blau/blue/;$csv->{$id}->{c3} =~ s/Gr.+n/green/;
$csv->{$id}->{c4} =~ s/Rot/red/;$csv->{$id}->{c4} =~ s/Blau/blue/;$csv->{$id}->{c4} =~ s/Gr.+n/green/;
$csv->{$id}->{c5} =~ s/Rot/red/;$csv->{$id}->{c5} =~ s/Blau/blue/;$csv->{$id}->{c5} =~ s/Gr.+n/green/;
$csv->{$id}->{c6} =~ s/Rot/red/;$csv->{$id}->{c6} =~ s/Blau/blue/;$csv->{$id}->{c6} =~ s/Gr.+n/green/;
print "$i) $csv->{$id}->{serialnr}|\n";
my $ct = &select_content($csv->{$id});
my $data = {
table => "content",
main_id => "$main_id",
template_id => "$template_id",
txt22 => "$csv->{$id}->{serialnr}",
txt18 => "$csv->{$id}->{ilockit_id}",
byte01 => "\\x$csv->{$id}->{ilockit_key}",
int04 => "0",#station Werkstatt
int10 => "5",#defect
int11 => "2",#Ilockit
int20 => "1",#locked
txt01 => "unverbaut", #Bezeichnung #TODO
txt04 => "aus Lieferung vom 29.11.2021", #Besonderheiten
txt15 => "", #Firmware
txt17 => "", #GUID from APP
txt23 => "$csv->{$id}->{c1} $csv->{$id}->{c2} $csv->{$id}->{c3} $csv->{$id}->{c4} $csv->{$id}->{c5} $csv->{$id}->{c6}",
mtime => "now()",
owner => "1842",
};
if(ref($ct) eq "HASH" && $ct->{c_id} && ref($data) eq "HASH" && $csv->{$id}->{serialnr}){
print "UPDATE $csv->{$id}->{serialnr} (c_id:$ct->{c_id})\n";
$data->{barcode} = $ct->{c_id} if(!$ct->{barcode});
$dbt->update_record($dbh,$data, { c_id => $ct->{c_id} });
print Dumper($data) . "\n";
}elsif(ref($data) eq "HASH" && $csv->{$id}->{serialnr}){
print "INSERT $csv->{$id}->{serialnr}\n";
$dbt->insert_contentoid($dbh,$data);
print Dumper($data) . "\n";
}else{
print "nothing todo\n";
}
}
}
#content check if still exists
sub select_content{
my $ct_hash = shift;
my $fetch = {
table => "content",
main_id => "$main_id",
template_id => "$template_id",
fetch => "one",
};
if(ref($ct_hash) eq "HASH" && $ct_hash->{serialnr}){
$fetch = { %$fetch , txt22 => "=::$ct_hash->{serialnr}" };
#$fetch = { %$fetch , barcode => "<::100" };
#$fetch = { %$fetch , int10 => "!=::3" };
#$fetch = { %$fetch , int11 => "!=::2" };
}
my $ct = $dbt->fetch_record($dbh,$fetch);
return $ct;
}

View file

@ -0,0 +1,377 @@
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#get lock event for last 20 minutes
#cronjob interval 15 minutes
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events"
#
#Ilockit GPS cloud
#
#4. Get a list of positions
#fetch_ >> https://tracking.ilockit.bike/api/positions?from=2021-05-31T07:44:10Z&to=2021-06-06T07:44:10Z&deviceId=4272
#5. Get a list of Events
#fetch_ >> https://tracking.ilockit.bike/api/reports/events?from=2021-05-31T07:44:10Z&to=2021-06-06T07:44:10Z&deviceId=4272
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die;
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI;
use Lib::Config;
use JSON;
use LWP::UserAgent;
use DateTime;
use Time::Piece;
my $cf = new Config;
use Mod::DBtank;
use Data::Dumper;
my $q = new CGI;
my $dbt = new DBtank;
my %varenv = $cf->envonline($syshost);
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg";
my $aconf = Config::General->new($api_file);
my %apikeyconf = $aconf->getall;
#print "---> " . $apikeyconf{Ilockitcloud}->{username} . "\n";
my $ua = LWP::UserAgent->new;
$ua->agent("sharee APIclient");
$ua->credentials( 'tracking.ilockit.bike:443', 'api', "$apikeyconf{Ilockitcloud}->{username}", "$apikeyconf{Ilockitcloud}->{passwd}");
my $json = JSON->new->allow_nonref;
my $response_in = {};
my $dbh = "";
my $owner = 183;
my $todo = $ARGV[1];
my $deviceId = $ARGV[2] || "";
open(FILE,">>$varenv{logdir}/Ilockit_cloud.log");
print FILE "\n\n*** $now_dt\n";
#my $endpoint = "https://tracking.ilockit.bike/api/commands";
#utc to localtime
sub localizedtime {
my $date = shift;
$date =~ s/\..*$//;
my $time = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%S");
print FILE "localizedtime GMT alias Zulu: " . $time->datetime . "\n";#GMT alias Zulu
$time = localtime($time->epoch);#epoch
print FILE "localizedtime localized date time: " . $time->datetime . "\n";#localized date time
return $time->datetime;
}
#print localizedtime("2021-06-11T11:58:09.000+0000") . " example\n";
#localtime to utc
#my $now = strftime "%Y-%m-%dT%H:%M:%S", localtime;
#utctime($now);
sub utctime {
my $date = shift;
my $latency = shift || 0;
$date =~ s/\..*$//;
$date =~ s/\+\d+$//;
print FILE "requested datetime: " . $date . "\n";
my $time = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%S");
print FILE "localtime: " . $time->datetime . "\n";#localtime
my $utc_epoch = $time->epoch;
#$utc_epoch -= 2*60*60;# -2 std
#
#only -1 hour, because of deviceTime and serverTime differs
#'deviceTime' => '2021-10-14T08:19:35.000+0000',
#'serverTime' => '2021-10-14T07:19:37.000+0000',
$utc_epoch -= 1*60*60;# -1 std
$utc_epoch += $latency;
$time = gmtime($utc_epoch);#epoch
print FILE "utctime: " . $time->datetime . "\n";#utc zulu date time
#
return $time->datetime;
}
#get all device localy
sub get_devicesONcontent_all {
my $deviceId = shift;
my $pref = {
table => "content",
fetch => "all",
keyfield => "int13",
template_id => "205",
int13 => ">::0",
};
my $record = $dbt->fetch_record($dbh,$pref);
return $record;
}
#get one device localy in contenttranspos to check if bike is locked
sub get_devicesONcontenttranspos {
my $deviceId = shift;
my $pref = {
table => "contenttranspos",
fetch => "one",
int13 => "$deviceId",
#int20 => "1",#locked
};
my $record = $dbt->fetch_tablerecord($dbh,$pref);
return $record;
}
#get one device localy
sub get_devicesONcontent {
my $deviceId = shift;
my $pref = {
table => "content",
fetch => "one",
template_id => "205",
int13 => "$deviceId",
};
my $record = $dbt->fetch_record($dbh,$pref);
return $record;
}
#get and check if theft exist in contenttranspos not older than 1 day
sub get_devicesONcontenttheftpos {
my $key = shift;
my $id = shift;
my $pref = {
table => "contenttheftpos",
fetch => "one",
#mtime => ">::(now() - interval '1 day')",
$key => "$id",
};
my $record = $dbt->fetch_tablerecord($dbh,$pref);
return $record;
}
#per cronjob once a day to get and update content with cloud device id
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
&get_devices if($todo eq "get_devices");
sub get_devices {
my $endpoint = "https://tracking.ilockit.bike/api/devices";
my $rest = "";
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
$response_in = decode_json($ret_json);
print FILE "ilockit get_devices response_in:" . Dumper($response_in);
#foreach my $result (@{ $response_in }) {
# if($result->{id}){
# print $result->{id} . "\n";
# print $result->{name} . "\n";
# }
#}
my $pref = {
table => "content",
fetch => "all",
keyfield => "barcode",
template_id => "205",
#int10 => "1",#1 = "available"
};
my $record = $dbt->fetch_record($dbh,$pref);
my $rows = 0;
if(1==1 && ref($response_in) eq "ARRAY"){
foreach my $id (sort { $record->{$a}->{barcode} <=> $record->{$b}->{barcode} } keys (%$record)){
foreach my $resp (@{ $response_in }) {
#print "if($resp->{name} eq $record->{$id}->{txt18} && ($resp->{id} && $resp->{id} ne $record->{$id}->{int13}))\n";
if($resp->{name} eq $record->{$id}->{txt18} && ($resp->{id} && $resp->{id} ne $record->{$id}->{int13})){
my $update = {
table => "content",
mtime => "now()",
owner => "$owner",
int13 => "$resp->{id}",
};
$rows = $dbt->update_record($dbh,$update,$record->{$id});
print FILE "update_record content.int13=$resp->{id}" . $rows . "\n";
}
}
}
}
}#end if($todo eq "get_devices"){
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 6572 20"
&get_events if($todo eq "get_events");
sub get_events {
#1. select all devices on content
my $record_cc = get_devicesONcontent_all();
my $today = DateTime->now( time_zone => "Europe/Berlin" );
$today .= "Z";
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
$from_datetime->subtract( days => 1 );
$from_datetime .= "Z";
my $endpoint = "https://tracking.ilockit.bike/api/reports/events";
#my $rest = "from=2021-05-31T07:44:10Z\&to=2021-06-06T07:44:10Z\&deviceId=4272";
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId";
#
#2. loope cloud
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
$response_in = decode_json($ret_json);
print FILE "ilockit get_events response_in:" . Dumper($response_in);
foreach my $resp (@{ $response_in }) {
#if($record_cc->{$id}->{int13} eq $resp->{deviceId} && $resp->{type} eq "deviceOnline"){
if($record_cc->{$id}->{int13} && $record_cc->{$id}->{int13} eq $resp->{deviceId} && ref($resp->{attributes}) eq "HASH" && $resp->{attributes}->{statusCode} && $resp->{attributes}->{statusCode} eq "alarm"){
my $theft_record = get_devicesONcontenttheftpos("int01",$resp->{id});
print FILE "id: $resp->{id}\n";
print FILE "deviceId: $resp->{deviceId}\n";
print FILE "type: $resp->{type}\n";
print FILE "statusCode: $resp->{attributes}->{statusCode}\n";
print FILE "serverTime: $resp->{serverTime}\n\n";
if(!$theft_record->{c_id}){
my $serverTime = localizedtime($resp->{serverTime});
my $insert = {
table => "contenttheftpos",
cc_id => "$record_cc->{$id}->{c_id}",
barcode => "$record_cc->{$id}->{barcode}",
int04 => "$record_cc->{$id}->{int04}",#end station
txt06 => "$record_cc->{$id}->{txt06}",#end gps
txt18 => "$record_cc->{$id}->{txt18}",
owner => $owner,
mtime => "now()",
int10 => "7",#theft alarm
int01 => "$resp->{id}",#keeps id for event_type
int13 => "$resp->{deviceId}",
start_time => "$serverTime",
end_time => "$serverTime",
};
my $c_id = $dbt->insert_contentoid($dbh,$insert);
print FILE "insert sub get_events:" . Dumper($insert);
}
}
}
}
}#end if($todo eq "get_events"){
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
#2021-10-27, cron disabled, unspecific and not only alarm
&get_positions if($todo eq "get_positions");
sub get_positions {
#1. select all devices on content
my $record_cc = get_devicesONcontent_all();
my $today = DateTime->now( time_zone => "Europe/Berlin" );
$today .= "Z";
my $from_datetime = DateTime->now( time_zone => "Europe/Berlin" );
$from_datetime->subtract( days => 1 );
$from_datetime .= "Z";
my $endpoint = "https://tracking.ilockit.bike/api/positions";
#my $rest = "from=2021-06-11T07:44:10Z\&to=2021-06-11T12:44:10Z\&deviceId=$deviceId" if($deviceId);
#my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
#$response_in = decode_json($ret_json);
#print Dumper($response_in);
#2. loope cloud
foreach my $id (sort { $record_cc->{$a}->{barcode} <=> $record_cc->{$b}->{barcode} } keys (%$record_cc)){
my $ctpos = get_devicesONcontenttranspos("$record_cc->{$id}->{int13}");
if($ctpos->{int20} == 1){#if locked then get position in range of end_time to now
print FILE "record_pos.int13: $ctpos->{int13} --> lock_state:$ctpos->{int20}| end_time:$ctpos->{end_time}\n";
#get only positions until smartlock end_time is locked
if($ctpos->{int13} && $ctpos->{end_time} =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/){
$ctpos->{end_time} =~ s/\..*$//;
my $end_time = $ctpos->{end_time};
$end_time =~ s/\s/T/;
$from_datetime = utctime($end_time,"0");
$from_datetime .= "Z";
#keep in mind, api-from maybe deviceTime (end_time-1) and position timestamp is serverTime+2
my $rest = "from=$from_datetime\&to=$today\&deviceId=$record_cc->{$id}->{int13}";
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
$response_in = decode_json($ret_json);
print FILE "ilockit get_positions response_in:" . Dumper($response_in);
foreach my $resp (@{ $response_in }) {
if($record_cc->{$id}->{int13} eq $resp->{deviceId}){
my $theft_record = get_devicesONcontenttheftpos("int02",$resp->{id});
print FILE "id: $resp->{id}\n";
print FILE "deviceId: $resp->{deviceId}\n";
print FILE "serverTime: $resp->{serverTime}\n\n";
if(!$theft_record->{c_id}){
my $serverTime = localizedtime($resp->{serverTime});
my $insert = {
table => "contenttheftpos",
cc_id => "$record_cc->{$id}->{c_id}",
barcode => "$record_cc->{$id}->{barcode}",
txt06 => "$resp->{latitude}, $resp->{longitude}",
owner => $owner,
mtime => "now()",
int10 => "8",#gps position
int02 => "$resp->{id}",#keeps id for event_type
int07 => "$resp->{speed}",
int08 => "$resp->{attributes}->{distance}",
int09 => "$resp->{attributes}->{totalDistance}",
int13 => "$resp->{deviceId}",
start_time => "$serverTime",
end_time => "$serverTime",
};
my $c_id = $dbt->insert_contentoid($dbh,$insert);
print FILE "insert sub get_positions:" . Dumper($insert);
}
}
}
}
}
}
}#end if($todo eq "get_positions"){
#ilockit http request
sub fetch_ilockit_cloud {
my $self = shift;
my $ilockitserver = shift || "";
my $rest = shift || "";
my $ilockit_request = "$ilockitserver?$rest";
print FILE "fetch_ >> " . $ilockit_request . "\n";
my $req = HTTP::Request->new(GET => "$ilockit_request");
#$req->content_type('application/x-www-form-urlencoded');
$req->content_type('application/json');
$req->content($rest);
my $res = $ua->request($req);
if ($res->is_success) {
#print $res->content;
return $res->content;
print $res->status_line, "\n";
}else {
print $res->status_line, "\n";
}
}
close(FILE);

View file

@ -0,0 +1,214 @@
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#get tracking by
#Ilockit trips by Ilockit cloud
#
#sudo su www-data -c "./src/scripts/Ilockit_trackingcloud.pl shareedms-fr01 get_tripsum 155884"
#
#2021-07-20
#GPS tracking
#Unser System bieten für die Auswertung von Fahrtstrecken bereits Zusammenfassungen an. Hierfür können Sie einfach die folgenden Calls benutzen:
#
#GET /api/reports/summary?groupId=95&amp; from=2021-07-17T18:30:00Z&amp; to=2021-07-20T18:30:00Z - Gibt Ihnen eine Zusammenfassung aller Fahrstrecken für die Schlösser in der Gruppe zurück.
#
#GET /api/reports/trips?groupId=95&amp; from=2020-07-17T18:30:00Z&amp; to=2021-07-20T18:30:00Z - Gibt Ihnen einzelne Fahrtstrecken für die Schlösser in der Gruppe zurück.
#
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die;
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI;
use Lib::Config;
use JSON;
use LWP::UserAgent;
use DateTime;
use Time::Piece;
use Mod::DBtank;
use Data::Dumper;
my $q = new CGI;
my $dbt = new DBtank;
my $cf = new Config;
my %varenv = $cf->envonline($syshost);
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $ua = LWP::UserAgent->new;
$ua->agent("sharee APIclient");
$ua->credentials( 'tracking.ilockit.bike:443', 'api', 'r.guempelein@sharee.bike', 'mohj2ooN');
my $json = JSON->new->allow_nonref;
my $response_in = {};
my $dbh = "";
my $owner = 183;
my $todo = $ARGV[1];
#my $deviceId = $ARGV[2] || "";
my $pos_id = $ARGV[2] || "";
open(FILE,">>$varenv{logdir}/Ilockit_tracking.log");
print FILE "\n\n*** $now_dt\n";
#utc to localtime
sub localizedtime {
my $date = shift;
$date =~ s/\..*$//;
my $time = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%S");
#print $time->datetime . "\n";#GMT alias Zulu
$time = localtime($time->epoch);#epoch
#print $time->datetime . "\n";#localized date time
#
return $time->datetime;
}
#localtime to utc
#my $now = strftime "%Y-%m-%dT%H:%M:%S", localtime;
#utctime($now);
#exit;
#
sub utctime {
my $date = shift;
my $latency = shift || 0;
$date =~ s/\..*$//;
$date =~ s/\+\d+$//;
print FILE "requested datetime: " . $date . "\n";
my $time = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%S");
print FILE "localtime: " . $time->datetime . "\n";#localtime
my $utc_epoch = $time->epoch;
#$utc_epoch -= 2*60*60;# -2 std (Sommerzeit)
$utc_epoch -= 1*60*60;# -1 std (Winterzeit)
$utc_epoch += $latency;
$time = gmtime($utc_epoch);#epoch
print FILE "utctime: " . $time->datetime . "\n";#utc zulu date time
#
return $time->datetime;
}
#get pos in contenttranspo
sub get_pos {
my $id = shift;
my $pref = {
table => "contenttranspos",
fetch => "one",
c_id => "$id",
};
my $record = $dbt->fetch_tablerecord($dbh,$pref);
return $record;
}
if($todo eq "get_tripsum" && $pos_id){
print FILE "trying $todo && $pos_id" . "\n";
my $rows = &get_tripsum($pos_id);
print FILE "got rows $rows" . "\n";
}else{
print FILE "failure: $todo && $pos_id" . "\n";
}
sub get_tripsum {
my $pos_id = shift;
my $ctpos = get_pos($pos_id);
#TEST
#$ctpos->{int13} = 8385;
#$ctpos->{start_time} = "2021-10-04 08:12:29";
#$ctpos->{end_time} = "2021-10-04 17:35:49";
#GET /api/reports/summary?groupId=95&amp; from=2021-07-17T18:30:00Z&amp; to=2021-07-20T18:30:00Z
my $endpoint = "https://tracking.ilockit.bike/api/reports/summary";
#GET /api/reports/trips?groupId=95&amp; from=2020-07-17T18:30:00Z&amp; to=2021-07-20T18:30:00Z
#my $endpoint = "https://tracking.ilockit.bike/api/reports/trips";
#my $rest = "groupId=95\&from=$oneday\&to=$today";
#my $rest = "deviceId=6574\&from=$oneday\&to=$today";
#
my $rows = 0;
if($ctpos->{int13}){
#start_time
$ctpos->{start_time} =~ s/\..*$//;
my $start_time = $ctpos->{start_time};
$start_time =~ s/\s/T/;
my $utc_start_time = utctime($start_time,"0");
$utc_start_time .= "Z";
#end_time
#my $end_time = strftime "%Y-%m-%dT%H:%M:%S", localtime;
$ctpos->{end_time} =~ s/\..*$//;
my $end_time = $ctpos->{end_time};
$end_time =~ s/\s/T/;
my $utc_end_time = utctime($end_time,"+300");#add 5 minutes, 300sec for latency
$utc_end_time .= "Z";
my $rest = "deviceId=$ctpos->{int13}\&from=$utc_start_time\&to=$utc_end_time";
#my $rest = "deviceId=$ctpos->{int13}\&from=2021-11-03T07:50:00Z\&to=2021-11-03T11:00:00Z";
my $ret_json = fetch_ilockit_cloud("","$endpoint",$rest);
$response_in = decode_json($ret_json);
print FILE "ilockit get_tripsum response_in:" . Dumper($response_in) . "\n";
if(1==1){
my $update_pos = {
table => "contenttranspos",
owner => $owner,
mtime => "now()",
int26 => 0,
};
foreach my $resp (@{ $response_in }) {
if($ctpos->{int13} eq $resp->{deviceId}){
print FILE "device Id: $resp->{deviceId}" . "\n";
print FILE "distance: $resp->{distance}" . "\n";
if($resp->{distance}){
#my $distance = $resp->{distance} / 1000 * 1.60934; #distance in Meilen
my $distance = $resp->{distance} / 1000;
$distance = sprintf('%.2f', $distance);
$update_pos->{int26} = $distance;
}
}
}
$rows = $dbt->update_record($dbh,$update_pos,$ctpos) if($ctpos->{c_id} && $update_pos->{int26});
}
}else{
print FILE "failure: There is no contenttranspo deviceId int13: $ctpos->{int13}" . "\n";
}
return $rows;
}#end if($todo eq "get_tripsum"){
#ilockit http request
sub fetch_ilockit_cloud {
my $self = shift;
my $ilockitserver = shift || "";
my $rest = shift || "";
my $ilockit_request = "$ilockitserver?$rest";
print FILE "fetch_ >> " . $ilockit_request . "\n";
my $req = HTTP::Request->new(GET => "$ilockit_request");
$req->content_type('application/json');
$req->content($rest);
my $res = $ua->request($req);
if ($res->is_success) {
#print $res->content;
return $res->content;
print $res->status_line, "\n";
}else {
print $res->status_line, "\n";
}
}
close(FILE);
1;

Binary file not shown.

View file

@ -0,0 +1,102 @@
/*
import android.util.Log;
*/
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
/**
* Created by Bjoern Kinberger on 04.10.18.
*
* This is a test class for the authentication process without a server
*
* Only use this for the development process, the key generation should be done on the server!
*/
public class Ilockkeygen {
//private static final String LOG_TAG = Ilockkeygen.class.getName();
public static byte[] sha1Value;
public static void generateKey(byte[] randomNum, byte[] internKey) {
//System.out.println( "K_int_byte = " + internKey );
//System.out.println("K_int_string = " + new String(internKey));
System.out.println("K_int = " + Arrays.toString(internKey));
byte[] filler = {0, 0, 0, 0};
Random random = new Random();
for (int i = 0; i < 16; i++) {
randomNum[i] = (byte) random.nextInt(255);
}
System.out.println("K_seed = " + Arrays.toString(randomNum));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
outputStream = new ByteArrayOutputStream();
outputStream.write(randomNum);
outputStream.write(internKey);
} catch (IOException e) {
e.printStackTrace();
}
byte tempoKey[] = outputStream.toByteArray();
System.out.println("K_temp = " + Arrays.toString(tempoKey));
/*
Log.d(LOG_TAG, "onCreate: temp key " + Arrays.toString(tempoKey));
*/
try {
sha1Value = SHA1(tempoKey);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
outputStream = new ByteArrayOutputStream();
outputStream.write(sha1Value);
outputStream.write(filler);
sha1Value = outputStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("K_a = " + Arrays.toString(sha1Value));
/*
Log.d(LOG_TAG, "onCreate: 1. " + Arrays.toString(sha1Value));
*/
try {
sha1Value = SHA1(sha1Value);
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
outputStream = new ByteArrayOutputStream();
outputStream.write(sha1Value);
outputStream.write(filler);
sha1Value = outputStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("K_u = " + Arrays.toString(sha1Value));
/*
Log.d(LOG_TAG, "onCreate: 2. " + Arrays.toString(sha1Value));
*/
}
private static byte[] SHA1(byte[] tempoKey) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(tempoKey);
return md.digest();
}
}

View file

@ -0,0 +1,50 @@
#!/usr/bin/perl
#
#Autor ragu@gnu-systems.de
#
#Ilockit authentify test
#
#sudo su www-data -c "./src/scripts/Ilocktestauth.pl shareeapp_operator 1003"
#
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || exit 1;
}
use lib "/var/www/copri4/$syshost/src";
my $dbname = $ARGV[1] || "";
my $bike = $ARGV[2] || "";
use strict;
use warnings;
use POSIX;
use CGI ':standard';
use Lib::Config;
use Data::Dumper;
my $q = new CGI;
my $cf = new Config;
my %varenv = $cf->envonline("$syshost");
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my @K_select = `cd /var/www/copri4/$varenv{syshost}/src/scripts && export CLASSPATH='.:/usr/share/java:/usr/share/java/postgresql.jar' && java Ilockauth $dbname $bike`;
foreach(@K_select){
my ($K_key,$K_val) = split(/ = /, $_);
$K_val =~ s/\n//g;
print "$K_key: $K_val\n";
}
my $receiver_usb = "abcd";
if($receiver_usb =~ /(\w)(\w)$/){
my $a = ord($1);
my $b = ord($2);
print "$1|$2" . "\n";
print "$a|$b" . "\n";
my $receiver_id = sprintf( "%x", $a ) . sprintf( "%x", $b );
print $receiver_id . "\n";
}

View file

@ -0,0 +1,133 @@
#!/usr/bin/perl -w
#2021-03-17
#redisgn because of BEGIN, use Net::SMTP; and executed in src/scripts
#
#sudo su www-data -c "./src/scripts/newsletter_post.pl 'shareedms-primary' 'send_cardexpire'"
#
#TODO, migrate it all to MailTransport.pm
#
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || exit 1;
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use utf8;
use Encode;
use CGI ':standard';
use DBI;
use POSIX;
use Email::MIME;
use IO::All;
use Email::MIME::CreateHTML;
use Email::Sender::Simple qw(sendmail);
use Net::SMTP;
use Try::Tiny;
use URI::Encode;
my $uri_encode = URI::Encode->new( { encode_reserved => 1 } );
use Data::Dumper;
use Sys::Hostname;
my $hostname = hostname;
use Lib::Config;
my $q = new CGI;
my $cf = new Config;
my %varenv = $cf->envonline("","$syshost");
my $today = strftime("%d.%m.%Y %H:%M:%S",localtime(time));
my $todo = $ARGV[1];
open(EMA, ">> $varenv{logdir}/newsletter_post.log");
print EMA "\n$today, start mailing\n";
print EMA "'$todo\n";
my $smtp_return = "";
if($todo eq "send_cardexpire"){
my ($mail_to,$subject,$body,$signature) = send_cardexpire(\%varenv);
$smtp_return = transport(\%varenv,$mail_to,$subject,$body,$signature);
}
#----------------------------------------------------
sub send_cardexpire {
my $varenv = shift;
my $mail_to = "ragu\@gnu-systems.de";
my $name = "test";
my $subject = "Fahrradmietsystem Konstanz";
my $body = <<EOF
Guten Tag $name,
wir mussten Ihren Fahrradmietsystem Account sperren weil der letzte Mietbetrag nicht eingezogen werden konnte.
Sie können Ihren Account selbst wieder freischalten, indem Sie die Zahlungsdaten erneuern. Dies kann aus Sicherheitsgründen von Seiten Ihrer Bank nötig sein oder es gab einen Fehler in Ihren Eingaben.
Nach der Anmeldung im Fahrradmietsystem Konstanz ( <a href='https://www.stadtwerke-konstanz.de/mobilitaet/rad-mietsystem?konrad_goto=Anmelden'>https://www.stadtwerke-konstanz.de/mobilitaet/rad-mietsystem</a> ) haben Sie die Möglichkeit Ihre Daten zu überprüfen und ggf. zu erneuern.
Kontaktieren Sie uns bitte falls Ihr Account für den Verleih nicht automatisch freigeschaltet wurde.
Für weitere Fragen wenden Sie sich bitte an unsere Buchhaltung unter: buchhaltung\@fahrradspezialitaeten.com oder telefonisch 0761/5158912 (Mo, Mi, Fr 9-12 Uhr)
EOF
;
$body =~ s/\n/\<br \/>/g;
my $signature = "";
return ($mail_to,$subject,$body,$signature);
}
#---------------------------------------------------
#
sub transport {
my $varenv = shift;
my $mail_to = shift;
my $subject = shift;
my $body = shift;
my $signature = shift;
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>$body</div>\n";
$html .= "<div>$signature</div>\n";
$html .= "</body></html>";
my $smtp = Net::SMTP->new($varenv->{mail_gateway},
Port => 465,
Hello => 'TeilRad',
Timeout => 30,
Debug => 0,
SSL => 1,
);
$smtp->auth($varenv->{sasl_username},$varenv->{sasl_password});
$smtp->mail($varenv->{mail_from});
if($hostname ne "$varenv->{live_hostname}"){
$mail_to = $varenv->{mail_testto};
$subject .= "* offline Test *";
}
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();
print EMA "$?\n";
} else {
print EMA $smtp->message();
}
sleep 1;
return $?;
}
#----------------------------------------------------
print EMA "done mailing: $?\n";
print EMA "\n\n";
close EMA;
1;

View file

@ -0,0 +1,245 @@
#!/usr/bin/perl
#
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#Capture payone payment by cron
#
#> 1. auto-fixed RadBuchungen (bei service-fixed hat schon jemand die Buchung manuell bearbeitet, oder?)
#--> service fixed wird gesetzt wenn das Rad via COPRI terminiert wurde. D.h. das hat keine Aussage ob auch der RadBuchungs Datensatz bearbeitet wurde. Deshalb gilt hier die userid des Datensatz Bearbeiters als key ob Automatik angewandt werden kann.-->ok
#> 2. mit defect -->ok
#> 3. RadBuchungen länger als 1 Tag oder bei konrad > 9,- € und bei TINK > 15,- € -->ok if int03 <= 5
#> 4. Gesamtbetrag > 50,- € -->ok
#> 5. OPOS, also bereits fehlgeschlagene Einzüge -->ok
# 6. "Internas und Bearbeitungstatus" wenn definiert und nicht Buchungsfreigabe, txid renew
#
#payone_cron cron Intervall 0=disabled, 1=weekly, 2=monthly
#
#All with coded conditions
#sudo su www-data -c "./src/scripts/payone_cron.pl tinkdms '' 1"
#One invoice
#sudo su www-data -c "./src/scripts/payone_cron.pl tinkdms ctt_id 1"
#
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || exit 1;
}
use lib "/var/www/copri4/$syshost/src";
my $ctt_id = $ARGV[1] || "";
my $intervall = $ARGV[2] || "1";
use strict;
use warnings;
use POSIX;
use Lib::Config;
use Mod::Libenz;
use Mod::DBtank;
use Mod::Payment;
use Data::Dumper;
use Scalar::Util qw(looks_like_number);
my $cf = new Config;
my %varenv = $cf->envonline("$syshost");
my $lb = new Libenz;
my $dbt = new DBtank;
my $pay = new Payment;
my $now_dt = strftime("%Y-%m-%d %H:%M:%S",localtime(time));
my $owner = 179;#179=cron
my $dbh = $dbt->dbconnect();
#get Firma in contentuser
my $fetchuser = {
table => "contentuser",
fetch => "one",
c_id => 100002,
};
my $ctf = $dbt->fetch_tablerecord($dbh,$fetchuser);
#collect open invoices
my $fetchtrans = {
table => "contenttrans",
fetch => "all",
keyfield => "c_id",
main_id => "300008",#Rechnung
template_id => "218",#Rechnung
state => "is::null",#never tried buchen
close_time => "",#invoice isn't closed
int14 => "is::null",#OPOS
owner => "!=::$owner",#not 179=cron, not still tried by payone_cron
};
$fetchtrans = { %$fetchtrans , c_id => $ctt_id } if($ctt_id && $ctt_id =~ /^\d+$/);
my $ct4rel = $dbt->fetch_record($dbh,$fetchtrans);
open(FILE,">>$varenv{logdir}/payone_cron.log");
print FILE "\n\n*** $now_dt\n";
my $max_sum = $ctf->{int03} || "10000";
my $max_timestamp = "210001012359";
my $scol = "mtime";
my $i=0;
#loop invoices
#foreach my $id (sort { $ct4rel->{$a}->{$scol} cmp $ct4rel->{$b}->{$scol} }keys (%$ct4rel)){
foreach my $id (sort { $ct4rel->{$b}->{$scol} cmp $ct4rel->{$a}->{$scol} }keys (%$ct4rel)){
$i++;
print FILE "\n$i)** loop $now_dt ---> payone_cron select invoice ct.c_id:$ct4rel->{$id}->{c_id}| ca.c_id:$ct4rel->{$id}->{int10}| ct.ct_name:$ct4rel->{$id}->{ct_name}| ct.mtime:$ct4rel->{$id}->{mtime}\n";
if($ct4rel->{$id}->{int10} && !$ct4rel->{$id}->{txt22} && $ct4rel->{$id}->{ct_name} =~ /---|^\d+$/){
my $umst1619 = $lb->umst_breaking($ct4rel->{$id},$now_dt);
#get Adresse from contentadr
my $fetchadr = {
table => "contentadr",
fetch => "one",
int16 => $intervall,
c_id => $ct4rel->{$id}->{int10},
};
my $ctadr = $dbt->fetch_tablerecord($dbh,$fetchadr);
#payone_cron cron Intervall 0=disabled, 1=weekly, 2=monthly
if($ctadr->{int16}){
#collect invoice positions
my $fetchpos = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
ct_id => $ct4rel->{$id}->{c_id},
};
my $cttpos = $dbt->fetch_tablerecord($dbh,$fetchpos);
my $scol = "itime";
my $sum_parts0=0;
my $sum_parts7=0;
my $sum_parts19=0;
my $sum_kaution=0;
my $diff7 = 100 + 7;
my $diff19 = 100 + $umst1619;
my $sum_umst7=0;
my $sum_umst19=0;
my $j=0;
my $accounting_start = "";
my $accounting_end = "";
my $k=0;
my $m=0;
my $capture_condition=1;#1=false
#loop invoice positions
foreach my $id (sort { $cttpos->{$b}->{$scol} cmp $cttpos->{$a}->{$scol} } keys(%$cttpos)){
if(($cttpos->{$id}->{int12} && $cttpos->{$id}->{int12} !~ /300005|300024/) || (($cttpos->{$id}->{int10} && $cttpos->{$id}->{int10} == 1) && ($cttpos->{$id}->{int03} && $cttpos->{$id}->{int03} <= 5) && ($cttpos->{$id}->{txt01} && $cttpos->{$id}->{txt01} !~ /fixed|defect/ || ($cttpos->{$id}->{owner_end} && $cttpos->{$id}->{owner_end} > 1000)))){
$j++;
my $cttpos_timestamp = $1 . $2 . $3 . "0000" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
#max. Rechnungspositionen
if(($cttpos_timestamp <= $max_timestamp) && ($sum_parts19 <= $max_sum)){
$k++;
#print "$i (($id: $cttpos_timestamp <= $max_timestamp) && ($sum_parts19 <= $max_sum))<br>";
if($k==1){
$accounting_end = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
$accounting_start = $accounting_end;
}else{
$accounting_start = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
}
$capture_condition=0;
my $gesamt = 0;
my $einzel = $cttpos->{$id}->{int02};
my $menge = $cttpos->{$id}->{int03};
$gesamt = $einzel * $menge;
my $rabatt_val = $cttpos->{$id}->{int07} || 0;
my $rabatt_eur = 0;
my $proz_eur = $cttpos->{$id}->{int08} || 0;
if($rabatt_val != 0){
$rabatt_eur = $rabatt_val;
if($proz_eur != 1){#wenn int08 != 1 alias €
$rabatt_eur = $einzel * $menge * $rabatt_val/100;
}
$gesamt = $einzel * $menge - $rabatt_eur;
}
$m++ if($gesamt != 0);
print FILE "pos gesamt: $gesamt = $einzel * $menge - $rabatt_eur ($rabatt_val|$rabatt_eur)\n";
$gesamt = $lb->round($gesamt);
$gesamt = $lb->cashme($gesamt);
$ctf->{txt13} = $1 if($ctf->{txt13} =~ /(\d+)/);
if($ct4rel->{$id}->{node_name} && $ct4rel->{$id}->{node_name} =~ /steuerfrei/){
$sum_parts0 += $gesamt;
}elsif($cttpos->{$id}->{int05} && $cttpos->{$id}->{int05} =~ /\d/){
$sum_parts0 += $gesamt if($cttpos->{$id}->{int05} == 0);
$sum_parts7 += $gesamt if($cttpos->{$id}->{int05} == 7);
$sum_parts19 += $gesamt if($cttpos->{$id}->{int05} >= 16);
}else{
$sum_parts0 += $gesamt if($ctf->{txt13} == 0);
$sum_parts7 += $gesamt if($ctf->{txt13} == 7);
$sum_parts19 += $gesamt if($ctf->{txt13} >= 16);
}
}#end timestamp
}else{#end conditons
$capture_condition=1;
#print "LAST LINE\n";
last;
}
}#end loop invoice positions
my $sum_paid = $sum_parts0 + $sum_parts7 + $sum_parts19;
$sum_paid = $lb->round($sum_paid);
my $sum_preauth = $sum_paid || 0;
$sum_paid = $lb->cashme($sum_paid,"");
my $line_count2 = $m+4;
print FILE "---> payone_cron capture conditions c_id:$ct4rel->{$id}->{c_id}, capture_condition:$capture_condition, sum_paid:$sum_paid, sum_preauth:$sum_preauth, ($accounting_start - $accounting_end)\n";
if($capture_condition==0 && $sum_paid > 0 && $sum_paid <= 50){
my $update = {
table => "contenttrans",
int15 => "$sum_preauth",
txt20 => "$accounting_start - $accounting_end",
owner => "$owner",#cron
int04 => "14.$line_count2",
mtime => "now()",
};
my $record = { c_id => $ct4rel->{$id}->{c_id} };
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
my ($return,$return_text) = $pay->payone_capture(\%varenv,$ctf,$ctadr,$ct4rel->{$id},$sum_paid,$owner);
print FILE "---> Payment.pm Modul things: $return_text\nFinally log payone-return-post.log\n";
sleep 20;
}elsif($sum_paid > 0){
my $update = {
table => "contenttrans",
txt22 => "cronjob fail",#also defined in Config.pm
owner => "$owner",#cron
mtime => "now()",
};
my $record = { c_id => $ct4rel->{$id}->{c_id} };
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} conditions fails\n";
}else{
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} conditions fails at all, sum_paid: $sum_paid > 0\n";
}
}#end if $ctadr->{int16}
}else{
my $update = {
table => "contenttrans",
#txt22 => "cronjob fail",#disabled to keep fibu saved Bearbeitsungsstatus
owner => "$owner",#cron
mtime => "now()",
};
my $record = { c_id => $ct4rel->{$id}->{c_id} };
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} Failure: no ct.int10 or order_stat ct.txt22:$ct4rel->{$id}->{txt22}\n";
}
}#end loop invoices
close(FILE);

View file

@ -0,0 +1,35 @@
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#loops sharee operators for payone capture
#only primary should do this
#
#sudo su www-data -c "./src/scripts/payone_operatorsloop.pl 1"
#
#defined by cronjob
#weekly for $ARGV[0]=1
#nonthly for $ARGV[0]=2
#
use lib "/var/www/copri4/shareedms-primary/src";
use strict;
use warnings;
use POSIX;
use Config::General;
die if(!$ARGV[0] || ($ARGV[0] != 1 && $ARGV[0] != 2));
my $globalconf_file = "/var/www/copri4/shareeconf/global.cfg";
my $conf = Config::General->new($globalconf_file);
my %globalconf = $conf->getall;
while (my ($key, $value) = each %{ $globalconf{"operator"} }) {
if(-d "/var/www/copri4/$value->{syshost}"){
`/var/www/copri4/shareedms-primary/src/scripts/payone_cron.pl $value->{syshost} '' $ARGV[0]`;
die if($? != 0);
}else{
print "/var/www/copri4/$value->{syshost} not available\n";
}
}

View file

@ -0,0 +1,97 @@
#!/usr/bin/perl
#
#Autor ragu@gnu-systems.de
#sharee payone POST
#
#managemandate
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 managemandate contentadr 21250"
#
#captureSEPA
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 preauthorizationSEPA contentadr 22027 28845"
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 captureSEPA contenttrans '' 28845"
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die 'syshost not defined';
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI ':standard';
use Lib::Config;
use Mod::Libenzdb;
use Mod::Payment;
use Config::General;
use Data::Dumper;
use Sys::Hostname;
my $hostname = hostname;
my $q = new CGI;
my $cf = new Config;
my %varenv = $cf->envonline("$syshost");
print "$varenv{dbname}\n";
my $db = new Libenzdb;
my $pay = new Payment;
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $owner = 178;#payone API
my $todo = $ARGV[1];
my $table = $ARGV[2];
my $ctadr_id = $ARGV[3];
my $ctt_id = $ARGV[4];
my $sequenz = $ARGV[5] || 0;
my $set_time = $ARGV[6] || "";#no_time
my $renewed = $ARGV[7] || "";#for requesting new txid via script loop_payone_capture.pl
my $request_state = $ARGV[8] || "";#if request state=occupied , then never delete adr4xml
my $globalconf_file = "/var/www/copri4/shareeconf/global.cfg";
my $conf = Config::General->new($globalconf_file);
my %globalconf = $conf->getall;
#print Dumper(\%globalconf);
my $refpre = $globalconf{operator}{$varenv{dbname}}->{oprefix};#FR KN ...
my $payone_conf = $globalconf{operator}{$varenv{dbname}}{payone_conf} || $globalconf{payone_conf};
my $ctadr = { c_id => 0 };
my $ctt = { c_id => 0 };
$ctadr = $db->get_contentrow("contentadr",$ctadr_id,"","","","","","") if($ctadr_id);
$ctt = $db->get_contentrow("contenttrans",$ctt_id,"","","","","","") if($ctt_id);
#managemandate SEPA
#1.
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} managemandate contentadr $ctadr_id"
if($todo eq "managemandate" && $table eq "contentadr" && $ctadr->{c_id} > 0){
$pay->managemandate_main(\%varenv,$ctadr,$ctt,$owner);
}
#preauthorizationSEPA
#2.
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} preauthorizationSEPA contentadr $ctadr_id $ctt_id"
if($todo eq "preauthorizationSEPA" && $table eq "contentadr" && $ctadr->{c_id} > 0 && $ctt->{c_id} > 0){
$pay->preauthorizationSEPA_main(\%varenv,$ctadr,$ctt,$owner);
}
#captureSEPA
#3.
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} captureSEPA contenttrans '' $ctt_id"
if($todo eq "captureSEPA" && $table eq "contenttrans" && $ctt->{c_id} > 0){
$pay->captureSEPA_main(\%varenv,$ctadr,$ctt,$owner);
}
#preauthorizationCC
#1.PayoneCC creditcardcheck ajaxCall
#2.
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} preauthorizationCC contentadr $ctadr_id $ctt_id"
if($todo eq "preauthorizationCC" && $table eq "contentadr" && $ctadr->{c_id} > 0 && $ctt->{c_id} > 0){
$pay->preauthorizationCC_main(\%varenv,$ctadr,$ctt,$owner);
}
#captureCC
#3.
#
if($todo eq "captureCC" && $table eq "contenttrans" && $ctt->{c_id} > 0){
$pay->captureCC_main(\%varenv,$ctadr,$ctt,$owner);
}

View file

@ -0,0 +1,70 @@
#!/usr/bin/perl
#
#Autor ragu@gnu-systems.de
#
#set availabel if requested > 15min
#
#sudo su www-data -c "./src/scripts/requested_timeout.pl shareedms-fr01"
#
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die;
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI ':standard';
use Lib::Config;
use Mod::DBtank;
use Data::Dumper;
my $q = new CGI;
my $cf = new Config;
my %varenv = $cf->envonline("$syshost");
my $dbt = new DBtank;
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $dbh = "";
#set available if requestes older than 15 minute
my $return={};
my $pref = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
#txt10 => "requested",
int10 => "2",
owner => "!=::199",#don't select LV api requested bikes
start_time => "<=::(now() - interval '15 minutes')",
};
my $record_cp = $dbt->fetch_tablerecord($dbh,$pref);
my $update_cp = {
table => "contenttranspos",
#txt10 => "available",
int10 => "1",
};
my $update_cc = {
table => "content",
int10 => "1",
};
my $rows = 0;
foreach my $id (sort { $record_cp->{$a}->{c_id} <=> $record_cp->{$b}->{c_id} } keys (%$record_cp)){
my $record = { c_id => 0 };
$record->{c_id} = $record_cp->{$id}->{c_id};
#contenttranspos
$rows = $dbt->update_record($dbh,$update_cp,$record);
if($rows > 0 && $record_cp->{$id}->{cc_id}){
$record->{c_id} = $record_cp->{$id}->{cc_id};
#content
$dbt->update_record($dbh,$update_cc,$record);
}
}
1;

View file

@ -0,0 +1,26 @@
#!/usr/bin/perl
#
#sudo su www-data -c "./src/scripts/sms_gtx_SMSTransport.pl shareeapp-operator '+491799xxxx72'"
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die 'syshost not defined';
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use Mod::SMSTransport;
my $smstrans = new SMSTransport;
my $phone = $ARGV[1] || die 'phone not defined';
my $adrhash = {
txt07 => $phone,
txt34 => "nureinlangertestdigest",
};
my $ret_json = $smstrans->sms_ack_digest($adrhash);

View file

@ -0,0 +1,184 @@
#!/usr/bin/perl
#
## SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
use lib "/var/www/copri4/shareeweb-project/src";
use strict;
use warnings;
use POSIX;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie ();
use DBI;
use Lib::Config;
use Mod::DBtank;
my $q = new CGI();
$q->import_names('R');
my $cf = new Config;
my $dbt = new DBtank;
my %varenv = $cf->envonline();
my $coo = $q->cookie('domcookie') || $q->param('sessionid') || "";
if($q->param('sessionid') && $q->param('sessionid') ne $q->cookie('domcookie')){
$coo = $q->param('sessionid');
my $cookie = CGI::Cookie->new(-name => 'domcookie',-value => $coo);
print $q->header(-charset=>"utf-8", -cookie=>$cookie);
}else{
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 $lang = "de";
my $dyn_js = "
function onLoad() {
console.log('hallo');
if ('geolocation' in navigator) {
console.log('geon');
/* geolocation funktioniert */
} else {
console.log('geoff');
/* geolocation funktioniert NICHT */
}
\$( '#no_javascript' ).hide();
}
\n";
my $dyn_css = "";
my $local_style = "$varenv{metahost}/$dbt->{shareeapp_conf}->{local_style}";
my $jquery = "$varenv{metahost}/$dbt->{shareeapp_conf}->{jquery}";
my $js_bootstrap = "$varenv{metahost}/$dbt->{shareeapp_conf}->{js_bootstrap}";
my $style_bootstrap = "$varenv{metahost}/$dbt->{shareeapp_conf}->{style_bootstrap}";
if($varenv{wwwhost} =~ /shareedms/){
$local_style = "$varenv{metahost}/$dbt->{shareedms_conf}->{local_style}";
$jquery = "$varenv{metahost}/$dbt->{shareedms_conf}->{jquery}";
$js_bootstrap = "$varenv{metahost}/$dbt->{shareedms_conf}->{js_bootstrap}";
$style_bootstrap = "$varenv{metahost}/$dbt->{shareedms_conf}->{style_bootstrap}";
}
my $html5 = $q->start_html(
-title => "shareetest",
-lang => '',
-onload => "onLoad();",
-encoding => "utf-8",
-base => 'true',
-head => Link(
{
-rel => 'shortcut icon',
-type => 'image/x-icon',
-href => "/css/favicon.ico"
}
),
-meta => {
'viewport'=>"width=device-width,initial-scale=1,user-scalable=yes",
'author' => "rainer guempelein",
'publisher' => "",
'copyright' => "",
},
-script=>[
{-language=>'JAVASCRIPT',
-src=>"$jquery"},
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/$dbt->{copri_conf}->{jquery_ui}"},
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/$dbt->{copri_conf}->{jquery_resize}"},
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/$dbt->{copri_conf}->{jsscript}"},
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/js/shareespecial.js"},
{-language=>'JAVASCRIPT',
-code=>"$dyn_js"}
],
-STYLE=>{
-code=>"$dyn_css",
-src=>[
"$local_style",
"$style_bootstrap",
"$varenv{metahost}/$dbt->{copri_conf}->{style_bootstrap_icons}",
"$varenv{metahost}/$dbt->{copri_conf}->{style_jquery_ui}"
],
-verbatim=>"\@import url(\"$local_style\");",
-media=>'screen'
}
);
$html5 =~ s{<!DOCTYPE.*?>}{<!DOCTYPE html>}s;
$html5 =~ s{<html.*?>}{<html lang='de'>}s;
print $html5;
##
my $uri = "$dbt->{primary}->{sharee_primary}->{primaryApp}/APIjsonserver";
print $q->div({-style=>'margin:15px;'},$q->a({-href=>"/src/scripts/tests/index.pl"},"[ index ]")),"\n";
print $q->div({-style=>'margin:15px;'},"&nbsp;"),"\n";
print $q->div({-style=>'margin:15px;'},"-------------- $uri --------------------"),"\n";
my $authorization = "$uri?request=authorization&user_id=ragu\@gnu-systems.de&user_pw=mabel321&merchant_id=oiF2kahH&hw_id=g89g8o7goguzuzug";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$authorization"},"[ authorization ]---> $authorization")),"\n";
my $authout = "$uri?request=authout&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$authout"},"[ authout ]---> $authout")),"\n";
my $bikes_all = "$uri?request=bikes_all&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$bikes_all"},"[ bikes_all ]---> $bikes_all")),"\n";
my $bikes_available = "$uri?request=bikes_available&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$bikes_available"},"[ bikes_available ]---> $bikes_available")),"\n";
my $stations_all = "$uri?request=stations_all&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$stations_all"},"[ stations_all ]---> $stations_all")),"\n";
my $stations_available = "$uri?request=stations_available&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$stations_available"},"[ stations_available ]---> $stations_available")),"\n";
my $user_bikes_occupied = "$uri?request=user_bikes_occupied&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_bikes_occupied"},"[ user_bikes_occupied ]---> $user_bikes_occupied")),"\n";
my $user_rentals_history = "$uri?request=user_rentals_history&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_rentals_history"},"[ user_rentals_history ]---> $user_rentals_history")),"\n";
my $user_minianswer = "$uri?request=user_minianswer&q1=opt5&q2=opt4&q3=iuwehfiolbev&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_minianswer"},"[ user_minianswer ]---> $user_minianswer")),"\n";
###
print $q->div({-style=>'margin:15px;'},"&nbsp;"),"\n";
my $uriop = "$dbt->{operator}->{sharee_operator}->{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";
my $booking_update_cancel = "$uriop?request=booking_update&bike=FR1003&state=canceled&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_cancel"},"[ booking_update_cancel ]---> $booking_update_cancel")),"\n";
my $booking_update_locking = "$uriop?request=booking_update&bike=FR1003&lock_state=locking&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_locking"},"[ booking_update_locking ]---> $booking_update_locking")),"\n";
my $booking_update_locked = "$uriop?request=booking_update&bike=FR1003&lock_state=locked&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_locked"},"[ booking_update_locked ]---> $booking_update_locked")),"\n";
my $booking_update_unlocked = "$uriop?request=booking_update&bike=FR1003&lock_state=unlocked&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_unlocked"},"[ booking_update_unlocked ]---> $booking_update_unlocked")),"\n";
my $booking_update_oc_ul = "$uriop?request=booking_update&bike=FR1003&state=occupied&lock_state=unlocked&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_oc_ul"},"[ booking_update_oc_ul ]---> $booking_update_oc_ul")),"\n";
my $booking_request_oc_ul = "$uriop?request=booking_request&bike=FR1003&state=occupied&lock_state=unlocked&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_request_oc_ul"},"[ booking_request_oc_ul ]---> $booking_request_oc_ul")),"\n";
my $booking_update_av_lo = "$uriop?request=booking_update&bike=FR1003&state=available&lock_state=locked&latitude=47.927738&longitude=7.973855&gps_age=300&user_device_manufaturer=samsung)&user_device_model=SM-G398FN&user_device_platform=Android&user_device_version=10&user_device_id=90af86831c10374d&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$booking_update_av_lo"},"[ booking_update_av_lo ]---> $booking_update_av_lo")),"\n";
my $user_feedback = "$uriop?request=user_feedback&bike=FR1003&bike_broken=1&message=testnachricht äöü&authcookie=$coo";
print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_feedback"},"[ user_feedback ]---> $user_feedback")),"\n";
print "<div style='text-align:center;'>";
print "<iframe width='750' height='500' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://www.openstreetmap.org/export/embed.html?bbox=7.604942321777345%2C47.923934784536236%2C7.979164123535157%2C48.07005002188767&amp;layer=mapnik' style='border: 1px solid black'></iframe><br/><small><a href='https://www.openstreetmap.org/#map=12/47.9970/7.7921'>Größere Karte anzeigen</a></small>\n";
print "</div>\n";
print $q->end_html;
1;

View file

@ -0,0 +1,220 @@
#!/usr/bin/perl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
# velofaktur per REST JSON Payload with Bearer Token
#
# Abrufen einer Liste mit Stationen, Anzahl Slots + Name
# sudo su www-data -c "./src/scripts/velofaktur_client.pl shareedms-fr01 get_velo"
#
# bike ID Statusabfrage | Freigeben
# sudo su www-data -c "./src/scripts/velofaktur_client.pl shareedms-fr01 post_velo 8 1 200008 Statusabfrage"
# will be sent by booking_update $lock_state eq "unlocked"
# sudo su www-data -c "./src/scripts/velofaktur_client.pl shareedms-fr01 post_velo 8 1 200008 Freigeben "$record_pos->{c_id}""
#
use vars qw($syshost);
BEGIN {
$syshost = $ARGV[0] || die;
}
use lib "/var/www/copri4/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI;
use JSON;
use LWP::UserAgent;
use DateTime;
use Time::Piece;
use Lib::Config;
use Mod::DBtank;
use Mod::Basework;
use Data::Dumper;
my $q = new CGI;
my $cf = new Config;
my $dbt = new DBtank;
my $bw = new Basework;
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg";
my $aconf = Config::General->new($api_file);
my %apikeyconf = $aconf->getall;
#print $apikeyconf{velofaktur}->{bearer};
my $ua = LWP::UserAgent->new;
$ua->agent("sharee veloclient");
my $size = $ua->max_size;
my $bytes = 1000;
$ua->max_size( $bytes );
$ua->default_header( 'Authorization' => $apikeyconf{velofaktur}->{bearer} );
my $json = JSON->new->allow_nonref;
my %varenv = $cf->envonline($syshost);
my $response_in = {};
my $dbh = "";
my $owner = 182;
my $todo = $ARGV[1];
my $Station = $ARGV[2] || "";
my $Slot = $ARGV[3] || "";
my $velo_id = $ARGV[4] || "";
my $Befehl = $ARGV[5] || "";
my $posc_id = $ARGV[6] || "";
open(FILE,">>$varenv{logdir}/APIvelo.log");
print FILE "\n*** $now_dt 'sharee veloclient' \n";
&get_velo if($todo eq "get_velo");
sub get_velo {
#my $endpoint = "https://shareeapp-primary.copri-bike.de/APIvelo";
my $endpoint = "https://cockpit.velofactur.de/api/portal/station";
my $rest_json = "";
my $ret_json = getvelo_cloud("","$endpoint",$rest_json);
eval {
$response_in = decode_json($ret_json);
print FILE "<--- velofactur response_in:\n" . Dumper($response_in);
};
if ($@){
print FILE "<--- failure get_velo raw response_in:\n" . Dumper($ret_json) . "\n";
warn $@;
}
}
#velofaktur http request
sub getvelo_cloud {
my $self = shift;
my $veloserver = shift || "";
my $rest_json = shift || "";
my $velo_request = "$veloserver";
print FILE "===> GET2velo >> " . $velo_request . "\n" . $rest_json . "\n";
my $req = HTTP::Request->new(GET => "$velo_request");
$req->content_type('application/json');
$req->content($rest_json);
my $res = $ua->request($req);
if ($res->is_success) {
#print $res->content;
return $res->content;
print $res->status_line, "\n";
}else {
print $res->status_line, "\n";
}
}
#end if($todo eq "get_velo"){
&post_velo($Station,$Slot,$velo_id,$Befehl,$posc_id) if($todo eq "post_velo");
sub post_velo {
my $Station = shift;
my $Slot = shift;
my $velo_id = shift;
my $Befehl = shift;
#local TEST
#my $endpoint = "https://shareeapp-primary.copri-bike.de/APIvelo";
#LIVE
my $endpoint = "https://cockpit.velofactur.de/api/portal/befehl";
my %json;
$json{Station} = "$Station";
$json{Slot} = "$Slot";
$json{Id} = "$velo_id";
$json{Befehl} = "$Befehl";
my $rest_json = encode_json(\%json);
my $ret_json = post2velo_cloud("","$endpoint",$rest_json);
#
eval {
$response_in = decode_json($ret_json);
print FILE "<--- velofaktur response_in:\n" . Dumper($response_in);
print $ret_json . "\n";
my $record_cc = { c_id => 0 };
if($velo_id && $velo_id > 0){
my $pref_cc = {
table => "content",
fetch => "one",
template_id => "205",
int27 => $velo_id,
};
$record_cc = $dbt->fetch_record($dbh,$pref_cc);
my $update_cc = {
table => "content",
mtime => "now()",
owner => "$owner",
};
$update_cc->{txt25} = $response_in->{status} if($response_in->{status});
$dbt->update_record($dbh,$update_cc,$record_cc) if($record_cc->{c_id});
$bw->log("update content velofactur response Status for bike $velo_id $record_cc->{barcode} $response_in->{status}",$update_cc,"");
}
my $record_pos = { c_id => 0 };
if($posc_id && $posc_id > 0){
my $pref_pos = {
table => "contenttranspos",
fetch => "one",
c_id => $posc_id,
};
$record_pos = $dbt->fetch_record($dbh,$pref_pos);
my $update_pos = {
table => "contenttranspos",
mtime => "now()",
owner => "$owner",
};
$update_pos->{int27} = $velo_id if($velo_id);
$update_pos->{30} = $Station if($Station);
$update_pos->{31} = $Slot if($Slot);
$update_pos->{txt25} = $response_in->{status} if($response_in->{status});
$dbt->update_record($dbh,$update_pos,$record_pos) if($record_pos->{c_id});
$bw->log("update contenttranspos velofactur response Status for bike $velo_id $record_pos->{barcode} $response_in->{status}",$update_pos,"");
}
};
if ($@){
print FILE "<--- failure post_velo raw response_in:\n" . Dumper($ret_json) . "\n";
warn $@;
}
}#end if($todo eq "post_velo"){
#velofaktur http POST request
sub post2velo_cloud {
my $self = shift;
my $veloserver = shift || "";
my $rest_json = shift || "";
my $velo_request = "$veloserver";
print FILE "===> POST2velo >> " . $velo_request . "\n" . $rest_json . "\n";
my $req = HTTP::Request->new(POST => "$velo_request");
$req->content_type('application/json');
$req->content($rest_json);
my $res = $ua->request($req);
if ($res->is_success) {
#print $res->content;
return $res->content;
print $res->status_line, "\n";
}else {
print $res->status_line, "\n";
}
}
close(FILE);