package SMSTransport; # # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # #SMS sender # #perl -cw do #use lib "/var/www/copri4/shareeapp-primary/src"; use strict; use warnings; use POSIX; use CGI; # only for debugging use LWP::UserAgent; use URI::Encode; use JSON; use Scalar::Util qw(looks_like_number); use Mod::DBtank; use Mod::Basework; use Data::Dumper; my $q = new CGI; my $dbt = new DBtank; my $bw = new Basework; sub new { my $class = shift; my $self = {}; bless($self,$class); return $self; } my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime; my $ua = LWP::UserAgent->new; $ua->agent("sharee smsclient"); my $uri_encode = URI::Encode->new( { encode_reserved => 1 } ); my $json = JSON->new->allow_nonref; my $response_in = {}; my $dbh = ""; my $owner = 181; sub sms_ack_digest { my $self = shift; my $ctadr = shift; #Ack digest my $ack_digest = $q->unescapeHTML($ctadr->{txt34}) || ""; my $email_ack_digest = $1 if($ack_digest =~ /^(.{5})/); my $sms_ack_digest = $1 if($ack_digest =~ /(.{5})$/); my $sms_from = "Mietradcode"; my $sms_to = $ctadr->{txt07};# || "+491799xxxx72"; my $sms_message = "Ihr Mietradsystem SMS-Bestätigungscode lautet: $sms_ack_digest"; my $message = Encode::encode('iso-8859-1', Encode::decode('utf-8',"$sms_message")); open(FILE,">>$dbt->{copri_conf}->{logdir}/sms_gtx.log"); print FILE "\n*** $now_dt 'sharee smsclient' \n"; my $request = { from => $sms_from, to => $sms_to, text => $message, }; print FILE "---> request:\n" . Dumper($request); my $ret_json = $self->get_sms_gtx($request); eval { $response_in = decode_json($ret_json); print FILE "<--- response_in:\n" . Dumper($response_in); }; if ($@){ print FILE "<--- failure raw response_in:\n" . Dumper($ret_json) . "\n"; warn $@; } close(FILE); return $ret_json; } #sms gtx http request sub get_sms_gtx { my $self = shift; my $request = shift || ""; my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg"; my $aconf = Config::General->new($api_file); my %apikeyconf = $aconf->getall; #print $apikeyconf{smsgtx}->{gtx_key}; my $endpoint = "https://rest.gtx-messaging.net/smsc/sendsms/$apikeyconf{smsgtx}->{gtx_key}/json"; my $rest; foreach (keys (%$request)){ my $encoded_val = $uri_encode->encode($request->{$_}); $rest .= "$_=$encoded_val&"; } $rest =~ s/\&$//; my $gtx_request = "$endpoint?$rest"; print FILE "===> GET2gtx >> " . $gtx_request . "\n"; my $req = HTTP::Request->new(GET => "$gtx_request"); $req->content_type('application/x-www-form-urlencoded'); 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"; } } # 1;