apps / sms / bot /
Newer Older
508 lines | 17.843kb
initial commit
admin cloud-section (root) authored on 2016-12-10
1
#!/usr/bin/perl
2

            
3
use strict;
4
use warnings;
5

            
6
use Net::XMPP;
7
use DBI;
8
use POSIX qw/ceil strftime/;
9

            
10
use open ':utf8';
11
use open ':std';
12
use utf8;
13
#use Data::Dumper;
14

            
15
use threads;
16
use threads::shared;
17
use Thread::Queue;
18

            
remplacement de nom de varia...
admin cloud-section (root) authored on 2016-12-13
19
$ENV{PWD} = "" if not defined $ENV{PWD};
initial commit
admin cloud-section (root) authored on 2016-12-10
20
my $scriptconf = $ENV{PWD} . "/$0";
21
$scriptconf =~ s/\.pl$//;
22
$scriptconf =~ s/$/.conf/;
23
if (-r $scriptconf) {
24
    package cfg;
25
    unless (my $return = do $scriptconf) {
26
        warn "couldn't parse $scriptconf: $@" if $@;
27
        warn "couldn't do $scriptconf: $!"    unless defined $return;
28
        warn "couldn't run $scriptconf"       unless $return;
29
    }
30
}
31
else {
32
    print "pas de config\n";
33
    exit;
34
}
35

            
36
$SIG{INT}=\&terminate;
37
#my $next_sms :shared; # utilisé pour le top du procahin envoi
38
my $debugLevel = 0;
39

            
remplacement de nom de varia...
admin cloud-section (root) authored on 2016-12-13
40
my $phone_status : shared = "";
initial commit
admin cloud-section (root) authored on 2016-12-10
41

            
42
my $from_gtalksms_queue = Thread::Queue->new;
43
my $to_gtalksms_queue = Thread::Queue->new;
44
my $mail_queue = Thread::Queue->new;
45

            
46
my $bot = &xmpp_login($cfg::config{xmpp}->{hostName}, 
47
                      $cfg::config{xmpp}->{portNumber}, 
48
                      $cfg::config{xmpp}->{userName}, 
49
                      $cfg::config{xmpp}->{passWord}, 
50
                      $cfg::config{xmpp}->{componentName}, 
51
                      $cfg::config{xmpp}->{resource}, 
52
                      $cfg::config{xmpp}->{tls}, 
53
                      1, "", 0, 
54
                      $cfg::config{DEBUG});
55

            
56
$SIG{INT} = sub { $bot->Disconnect; };
57

            
58
my $mail = threads->new(\&ssmtp_send_mail);
59

            
60
my $from_gtalksms = threads->new(\&from_gtalksms_parse);
61

            
62
my $to_gtalksms = threads->new(\&xmpp_send_sms);
63

            
64
sub debug_print {
65
    print STDERR "sendxmpp: " . (join ' ', @_) . "\n"
66
	if (@_ && ($cfg::config{DEBUG} ||$cfg::config{VERBOSE}));
67
}
68

            
69
sub log_bot {
70
#    open(LOGFILE,'>>', 'bot.log');
71
#    print LOGFILE sprintf("[%s] %s\n",strftime("%Y-%m-%d %H:%M:%S", localtime), shift);
72
    print  sprintf("[%s] %s\n",strftime("%Y-%m-%d %H:%M:%S", localtime), shift);
73
#    close LOGFILE;
74
}
75

            
76
sub xmpp_logout($) {
77
    # HACK
78
    # messages may not be received if we log out too quickly...
79
    sleep 1;
80

            
81
    my $cnx = shift;
82
    $cnx->Disconnect();
83
    xmpp_check_result ('Disconnect',0); # well, nothing to check, really
84
}
85

            
86
sub terminate () {
87
    my $cnx = shift;
88
    debug_print "caught TERM";
89
    xmpp_logout($cnx);
90
    exit 0;
91
}
92

            
93
sub error_exit {
94
    my ($err,$cnx) = @_;
95
    print STDERR "$err\n";
96
    xmpp_logout ($cnx)
97
	if ($cnx);
98
    exit 1;
99
}
100

            
101
sub xmpp_check_result {
102
    my ($txt, $res, $cnx)=@_;
103

            
104
    error_exit ("Error '$txt': result undefined")
105
	unless (defined $res);
106

            
107
    # res may be 0
108
	if ($res == 0) {
109
		debug_print "$txt";
110
		# result can be true or 'ok'
111
	}
112
	elsif ((@$res == 1 && $$res[0]) || $$res[0] eq 'ok') {
113
		debug_print "$txt: " .  $$res[0];
114
		# otherwise, there is some error
115
	}
116
	else {
117
		my $errmsg = $cnx->GetErrorCode() || '?';
118
		error_exit ("Error '$txt': " . join (': ',@$res) . "[$errmsg]", $cnx);
119
	}
120
}
121

            
122
sub xmpp_login ($$$$$$$$$$$) {
123
    my ($host, $port, $user, $pw, $comp, $res, $tls, $no_tls_verify, $tls_ca_path, $ssl, $debug) = @_;
124
    my $cnx = new Net::XMPP::Client(debuglevel=>0);
125
    error_exit "could not create XMPP client object: $!" unless ($cnx);
126

            
127
	my $ssl_verify = 0x01;
128
	if ($no_tls_verify) { $ssl_verify = 0x00; }
129
	debug_print "ssl_verify: $ssl_verify";
130

            
131
	debug_print "tls_ca_path: $tls_ca_path";
132

            
133
    my @res;
134
	my $arghash = {
135
		hostname		=> $host,
136
		port            => $port,
137
		tls				=> $tls,
138
		ssl_verify		=> $ssl_verify,
139
		ssl_ca_path		=> $tls_ca_path,
140
		ssl             => $ssl,
141
		connectiontype	=> 'tcpip',
142
		componentname	=> $comp
143
	};
144

            
145
	delete $arghash->{port} unless $port; 
146
	if ($arghash->{port}) {
147
		@res = $cnx->Connect(%$arghash);
148
		error_exit ("Could not connect to '$host' on port $port: $@") unless @res;
149
	} else {
150
		@res = $cnx->Connect(%$arghash);
151
		error_exit ("Could not connect to server '$host': $@") unless @res;
152
	}
153

            
154
    xmpp_check_result("Connect",\@res,$cnx);
155

            
156
	if ($comp) {
157
		my $sid = $cnx->{SESSION}->{id};
158
		$cnx->{STREAM}->{SIDS}->{$sid}->{hostname} = $comp
159
	}
160

            
161
    @res = $cnx->AuthSend(#'hostname' => $host,
162
			  'username' => $user,
163
			  'password' => $pw,
164
			  'resource' => $res);
165
    xmpp_check_result('AuthSend',\@res,$cnx);
166

            
167
    return $cnx;
168
}
169

            
170
sub sql_request ($) {
171
    my $request = shift;
172
    my @result;
173
    my $dbh = DBI->connect($cfg::config{db}->{driver}, $cfg::config{db}->{user}, $cfg::config{db}->{password}, {'RaiseError' => 1});
174
    $dbh->{'mysql_enable_utf8'} = 1;
175
    $dbh->do(qq{SET NAMES "utf8"});
176
    my $sth = $dbh->prepare($request);
177
    $sth->execute();
178
    if (defined($sth->{NUM_OF_FIELDS})) {
179
        while (my $ref = $sth->fetchrow_hashref()) {
180
            push @result, $ref;
181
        }
182
    }
183
    $sth->finish();
184
    $dbh->disconnect();
185
    return @result;
186
}
187

            
188
sub massive_send_sms {
189
    my $request = shift;
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
190
    if ($to_gtalksms_queue->pending() > 0) {
191
        $to_gtalksms_queue->insert(0, [$request->{phone}, "un envoi massif est déjà en cours, lancé par " . $cfg::config{last_sender} . ", reste " . $to_gtalksms_queue->pending() . ", annulation"]);
192
        return;
193
    }
194
    $cfg::config{last_sender} = $request->{phone_owner};
195
    my @results = sql_request("SELECT phone, firstname, gender FROM " . $cfg::config{table} . " WHERE " . $cfg::config{group_prefix} . $request->{table} . " > '0'");
196
    my $qty = scalar(@results);
197
    my $start_msg = "envoi de " . $qty . " SMS (fin prévue entre ". strftime("%H:%M", localtime(time() + $qty * 60)) . " et " . strftime("%H:%M", localtime(time() + $qty * 90)) . ")";
198
    $to_gtalksms_queue->enqueue([$request->{phone}, $start_msg]);
199
    foreach my $contact (@results) {
200
        $contact->{phone} =~ s/[\s\.]//g;
201
        $_ = $request->{body};
202
        s/\@prénom/$contact->{firstname}/g;
203
        if ($contact->{gender} eq 'F') {
204
            s/\@\(\s*(\w+)\s*,\s*\w+\s*\)/$1/g;
réponse prioritaire au ping ...
admin cloud-section (root) authored on 2018-11-25
205
        }
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
206
        else {
207
            s/\@\(\s*\w+\s*,\s*(\w+)\s*\)/$1/g;
initial commit
admin cloud-section (root) authored on 2016-12-10
208
        }
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
209
        $to_gtalksms_queue->enqueue([$contact->{phone}, $_])
initial commit
admin cloud-section (root) authored on 2016-12-10
210
    }
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
211
    $to_gtalksms_queue->enqueue([$request->{phone}, "envoi des SMS terminé !"]);
initial commit
admin cloud-section (root) authored on 2016-12-10
212
}
213

            
214
sub control_sms_flow {
215
    my ($body, $max, $interval) = @_;
216
    my $flow_control="/home/sms/flow.control";
217
#    use bytes; # les caractères UTF-8 peuvent être codés sur plus d'un octet
218
#    my $nbr = ceil(length($$body)/140); # taille d'un SMS 140 octets
219
     my $nbr = 1;
220
#    no bytes;
221
    while (1) {
222
        my $left = $max;
223
        my $t = time;
224
        open (FILE, "<", $flow_control);
225
        my @lines = <FILE>;
226
        close FILE;
227
        open(FILE, ">", $flow_control);
228
        foreach my $line (@lines) {
229
            $line =~ /(\d+)/;
230
            my $ts = $1;
231
            if ($ts + $interval > $t) {
232
                $left--;
233
                print FILE $line;
234
            }
235
        }
236
        close FILE;
237
        log_bot("  ---> to send: $nbr; left: $left");
238
        last if $nbr < $left;
temps d'attente aléatoire en...
admin cloud-section (root) authored on 2018-04-02
239
        sleep 60;
initial commit
admin cloud-section (root) authored on 2016-12-10
240
    }
241
    open (FILE,">>", $flow_control);
242
    for (my $i = 0; $i < $nbr; $i++) { print FILE time, "\n"; }
243
    close FILE;
244
}
245

            
246
sub xmpp_send {
247
    my $msg = shift;
248
    $bot->MessageSend(
remplacement de nom de varia...
admin cloud-section (root) authored on 2016-12-13
249
            to => $cfg::config{xmpp}->{phoneBuddy}, 
initial commit
admin cloud-section (root) authored on 2016-12-10
250
            from => $cfg::config{xmpp}->{userName} . "@" . $cfg::config{xmpp}->{hostName}, 
251
            resource => $cfg::config{xmpp}->{resource}, 
252
            type => 'chat', 
253
            body => $$msg
254
    );
255
}
256

            
257
sub ssmtp_send_mail {
258
    while (my $request = $mail_queue->dequeue) {
259
        defined($request->{to}) or $request->{to} = $cfg::config{mail};
260
        open(MAIL, "|/usr/lib/sendmail -t");
261
        print MAIL "Subject: $request->{subject}\n"; 
262
        print MAIL "To: $request->{to}\n";
possibilité de répondre par ...
admin cloud-section (root) authored on 2018-04-02
263
        print MAIL "Reply-To: $request->{email}\n" if ($request->{email} ne '');
initial commit
admin cloud-section (root) authored on 2016-12-10
264
        print MAIL "$request->{body}\n";
265
        close(MAIL);
266
        log_bot("mail envoyé à $request->{to}");
267
    }
268
}
269

            
270
sub wait_open_time ($$) {
271
    my ($close_hour, $open_hour) = @_;
fix: heures silencieuses
admin cloud-section (root) authored on 2018-11-25
272
    my @lt = localtime;
273
    while ($lt[2] >= $close_hour or $lt[2] <= $open_hour) {
initial commit
admin cloud-section (root) authored on 2016-12-10
274
        sleep 1800;
275
    }
276
}
277

            
278
sub xmpp_send_sms {
279
    while (my $ref = $to_gtalksms_queue->dequeue) {
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
280
        wait_open_time($cfg::config{close_hour}, $cfg::config{begin_hour}); # pas d'envoi entre 21h et 8h
initial commit
admin cloud-section (root) authored on 2016-12-10
281
#        TODO lock($next_sms);
282
#        TODO $next_sms = $$ref[0];
283
        xmpp_send(\"sms:$$ref[0]:$$ref[1]");
284
        log_bot("envoi à $$ref[0] : $$ref[1]");
temps d'attente aléatoire en...
admin cloud-section (root) authored on 2018-04-02
285
        sleep 60 + int(rand(30)); # en attendant la maîtrise de cond_wait et cond_signal: cond_signal() called on unlocked variable at ./bot line 348
initial commit
admin cloud-section (root) authored on 2016-12-10
286
#        TODO cond_wait($next_sms); # attend le top 
287
    }
288
}
289

            
290
sub is_authorized {
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
291
    my ($request) = @_;
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
292
    my @results = sql_request("SELECT * FROM $cfg::config{table} WHERE phone = '$request->{phone}'");
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
293
    if (scalar(@results) == 1) {
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
294
        my $_results = $results[0];
295
        foreach my $column (keys(%$_results)) {
296
            if ($column =~ /^$cfg::config{group_prefix}/) {
297
                if ($results[0]->{$column} == 2) {
298
                    $request->{address} = $results[0]->{address};
299
                    return 1; # true
300
                }
301
            }
302
        }
303
        return 0; # false
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
304
    }
305
    else {
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
306
        return 0; # false
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
307
    }
initial commit
admin cloud-section (root) authored on 2016-12-10
308
}
309

            
310
sub authorized_on_table {
311
    my %request = @_;
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
312
    my $table_name = $cfg::config{group_prefix} . $request{groupe};
313
    my @results = sql_request("SELECT * FROM $cfg::config{table} WHERE phone = '$request{id}'");
314
    if (scalar(@results) == 1) {
315
        if (! defined($results[0]->{$table_name})) {
316
            $request{error} = "le groupe $request{groupe} n'existe pas";
317
            $to_gtalksms_queue->insert(0, [$request{id}, $request{error}]);
318
            return 0; # false
initial commit
admin cloud-section (root) authored on 2016-12-10
319
        }
320
    }
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
321
    @results = sql_request("SELECT $table_name FROM $cfg::config{table} WHERE phone = '$request{id}'");
322
    if (scalar(@results) == 1) {
323
        if ($results[0]->{$table_name} != 2) {
324
            $request{error} = "désolé, écrire au groupe $request{groupe} n'est pas autorisé pour toi";
325
            $to_gtalksms_queue->insert(0, [$request{id}, $request{error}]);
326
            return 0; # false
initial commit
admin cloud-section (root) authored on 2016-12-10
327
        }
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
328
        else {
329
            return 1; # true
initial commit
admin cloud-section (root) authored on 2016-12-10
330
        }
331
    }
332
}
333

            
334
sub react_on_message {
335
    my ($hashref , $request) = @_;
336
    for my $regex (keys(%$hashref)) {
337
        if ($request->{body} =~ m/$regex/i) {
338
            $request->{body} =~ s/$regex//i;
339
            $hashref->{$regex}();
340
            return 1; # true
341
        }
342
    }
343
    return 0; # false
344
}
345

            
346
sub messageCB {
347
    my ($sid, $msg) = @_;
348
    $from_gtalksms_queue->enqueue($msg) if $msg->DefinedBody();
349
}
350

            
351
sub from_gtalksms_parse {
352
    while (my $msg = $from_gtalksms_queue->dequeue) {
353
        my %request = (body => $msg->GetBody);
354
        my %part_from_gtalksms = (
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
355
            $cfg::gtalksms{from} => sub { # Message de +33612345678 :
initial commit
admin cloud-section (root) authored on 2016-12-10
356
                $request{phone} = "0" . $1;
357
                $request{phone_owner} = '';
possibilité de répondre par ...
admin cloud-section (root) authored on 2018-04-02
358
                $request{email} = '';
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
359
                my @results = sql_request("SELECT * FROM " . $cfg::config{table} . " WHERE phone = '$request{phone}'");
initial commit
admin cloud-section (root) authored on 2016-12-10
360
                my $number_of_candidates = @results;
361
                $number_of_candidates == 0 and return;
362
                $request{phone_owner} .= '(';
363
                foreach (@results) {
364
                    $request{phone_owner} .= "$_->{firstname} $_->{lastname}";
365
                    --$number_of_candidates > 0 and $request{phone_owner} .= ' ou ';
possibilité de répondre par ...
admin cloud-section (root) authored on 2018-04-02
366
                    $request{email} = $_->{email};
initial commit
admin cloud-section (root) authored on 2016-12-10
367
                } 
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
368
                $request{phone_owner} .= ')';
initial commit
admin cloud-section (root) authored on 2016-12-10
369
                log_bot("message de $request{phone} $request{phone_owner}");
370
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
371
            $cfg::gtalksms{"delivered"} => sub { # SMS "un contenu de SMS" pour 0612345678 délivré.
initial commit
admin cloud-section (root) authored on 2016-12-10
372
                log_bot("message $1 délivré pour $2");
373
# TODO cond_signal($next_sms);
374
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
375
            $cfg::gtalksms{forget} => sub { # Le destinataire par défaut est 0612345678: inutile
initial commit
admin cloud-section (root) authored on 2016-12-10
376
                return;
377
            },
378
        );
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
379

            
380
        my %sms_action = (
381
            "create flag" => sub {
382
                my ($flag) = @_;
383
                my $gid = getgrnam("sms-action");
384
                mkdir $cfg::sms_action{flagdir};
385
                chmod 0770, $cfg::sms_action{flagdir};
386
                chown $>, $gid, $cfg::sms_action{flagdir};
387

            
388
                open(FLAG, ">" . $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag});
389
                chmod 0660, $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag};
390
                chown $>, $gid, $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag};
391

            
392
                print FLAG $$flag if defined $flag;
393
                close FLAG;
394
            },
395
            "start action" => sub {
396
                # 0 = false
397
                return ! system("sudo /bin/systemctl start action.service");
398
            },
399
            "get locker" => sub {
400
                open FLAG, $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag};
401
                my $locker = '';
402
                my $intro_ = '';
403
                while (<FLAG>) {
404
                    if (/^firstname:(.+)$/) {
405
                        $locker = " par " . $1;
406
                    }
407
                    if (/^intro:(.+)$/) {
408
                        $intro_ = " de test ($1)";
409
                    }
410
                }
411
                close FLAG;
412
                return "l'envoi " . $intro_ . " est déjà prévu" . $locker . ", abandon";
413
            },
414
        );
415

            
initial commit
admin cloud-section (root) authored on 2016-12-10
416
        my %part_from_user = (
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
417
            $cfg::user{"stop"} => sub {
initial commit
admin cloud-section (root) authored on 2016-12-10
418
                log_bot("arrêt demandé par $request{phone} $request{phone_owner}");
419
                $bot->Disconnect();
420
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
421
            $cfg::user{"message de groupe"} => sub {
initial commit
admin cloud-section (root) authored on 2016-12-10
422
                $request{table} = lc $1;
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
423
                if (authorized_on_table(groupe => $request{table}, id => $request{phone})) {
424
                    &massive_send_sms(\%request);
425
                }
initial commit
admin cloud-section (root) authored on 2016-12-10
426
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
427
            $cfg::user{"message pour un destinataire"} => sub {
initial commit
admin cloud-section (root) authored on 2016-12-10
428
                $to_gtalksms_queue->enqueue([$1, $2]);
429
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
430
            $cfg::user{"ping"} => sub {
réponse prioritaire au ping ...
admin cloud-section (root) authored on 2018-11-25
431
                my $envoi_en_cours = "";
432
                if ($to_gtalksms_queue->pending() > 0) {
433
                    $envoi_en_cours = "\nenvoi en cours de traitement " . $cfg::config{last_sender};
434
                }
initial commit
admin cloud-section (root) authored on 2016-12-10
435
                log_bot("envoi d'un pong à $request{phone} $request{phone_owner}");
réponse prioritaire au ping ...
admin cloud-section (root) authored on 2018-11-25
436
                $to_gtalksms_queue->insert(0, [$request{phone}, "pong ($phone_status)" . $envoi_en_cours]);
initial commit
admin cloud-section (root) authored on 2016-12-10
437
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
438
            $cfg::user{"test intro pour action"} => sub {
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
439
                my $intro = $1;
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
440
                if (! -r $cfg::sms_action{flag_prefix} . $intro . $cfg::sms_action{flag_suffix}) {
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
441
                    $to_gtalksms_queue->enqueue([$request{phone}, "l'intro $intro n'existe pas, abandon"]);
442
                    return;
443
                }
séparation de la configurati...
admin cloud-section (root) authored on 2017-02-17
444
                if (-r $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag}) {
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
445
                    $to_gtalksms_queue->enqueue([$request{phone}, $sms_action{"get locker"}()]);
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
446
                }
447
                else {
448
                    log_bot("demande envoi du mail des actions avec intro $intro depuis $request{phone} $request{phone_owner} à $request{address}");
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
449
                    my $flag_content = "to:" . $request{address} . "\nintro:" . $intro . "\nfirstname:" . $request{phone} . " " . $request{phone_owner};
450
                    $sms_action{"create flag"}(\$flag_content);
451
                    if ($sms_action{"start action"}()) {
452
                        $to_gtalksms_queue->enqueue([$request{phone}, "le mail de test des actions avec intro $intro envoyé à $request{address}"]);
453
                    }
454
                    else {
455
                        $to_gtalksms_queue->enqueue([$request{phone}, "problème: le mail de test des actions avec intro $intro pour $request{address}, n'est probablement pas parti"]);
456
                    }
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
457
                }
458
            },
passage des regex dans le fi...
admin cloud-section (root) authored on 2017-02-17
459
            $cfg::user{"envoi normal pour action"} => sub {
séparation de la configurati...
admin cloud-section (root) authored on 2017-02-17
460
                if (-r $cfg::sms_action{flagdir} . "/" . $cfg::sms_action{flag}) {
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
461
                    $to_gtalksms_queue->enqueue([$request{phone}, $sms_action{"get locker"}()]);
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
462
                }
463
                else {
464
                    log_bot("demande envoi du mail des actions depuis $request{phone} $request{phone_owner}");
signal d'envoi immédiat du m...
admin cloud-section (root) authored on 2017-02-18
465
                    $sms_action{"create flag"}();
466
                    if ($sms_action{"start action"}()) {
467
                        $to_gtalksms_queue->enqueue([$request{phone}, "le mail des actions est parti"]);
468
                    }
469
                    else {
470
                        $to_gtalksms_queue->enqueue([$request{phone}, "problème: le mail des actions n'est probablement pas parti"]);
471
                    }
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
472
                }
473
            },
initial commit
admin cloud-section (root) authored on 2016-12-10
474
        );
475

            
476
        if (react_on_message(\%part_from_gtalksms, \%request)) {
sms/action: envoi du mail de...
admin cloud-section (root) authored on 2017-02-17
477
            if (defined $request{phone} and !(is_authorized(\%request) and react_on_message(\%part_from_user, \%request))) {
initial commit
admin cloud-section (root) authored on 2016-12-10
478
                $request{subject} = "SMS recu de $request{phone} $request{phone_owner}";
479
                $mail_queue->enqueue(\%request);
480
            }
481
        }
482
        else {
483
            log_bot("message de type inconnu: $request{body}") unless $request{body} eq "";
484
        }
485

            
486
        undef %request;
487
    }
488
}
489

            
490
$from_gtalksms->detach; # gère la file des événements produits par GTalkSMS
491
$to_gtalksms->detach;   # gère la file des envois de SMS par GTalkSMS
492
$mail->detach;          # gère la file des mails
changement d'API Perl XMPP
admin cloud-section (root) authored on 2018-04-02
493
$bot->SetMessageCallBacks(message => \&messageCB);
initial commit
admin cloud-section (root) authored on 2016-12-10
494

            
495
$bot->PresenceSend();
496
my $roster = $bot->Roster;
remplacement de nom de varia...
admin cloud-section (root) authored on 2016-12-13
497
$roster->add($cfg::config{xmpp}->{phoneBuddy});
initial commit
admin cloud-section (root) authored on 2016-12-10
498

            
499
while(defined($bot->Process())) { 
500
    $bot->RosterGet();
remplacement de nom de varia...
admin cloud-section (root) authored on 2016-12-13
501
    my $status = $roster->query($cfg::config{xmpp}->{phoneBuddy},'resources');
simplification table + répon...
admin cloud-section (root) authored on 2019-03-17
502
    if ($status) {
503
        $phone_status = $status->{GTalkSMS}->{status} =~ s/^GTalkSMS - //r;
504
    }
505
    else {
506
        $phone_status = "";
507
    }
initial commit
admin cloud-section (root) authored on 2016-12-10
508
}