initial commit
Benjamin Renard authored 12 years ago
|
1) #!/usr/bin/perl -w
2)
3) # # mail2gnokii
4) #
5) # Postfix transport to sending SMS by gnokii
6) #
7) # Usage :
8) #
9) # in master.cf :
10) #
11) # sms unix - n n - 1 pipe
|
add smsc option to script m...
Benjamin Renard authored 12 years ago
|
12) # flags=Rq user=gnokii:dialout argv=/usr/local/sbin/mail2gnokii ${user} [SMSC]
|
initial commit
Benjamin Renard authored 12 years ago
|
13) #
14) # in transport :
15) #
16) # sms.example.tld sms
17) #
18) # # arg1: phone number
19)
20) use Email::Simple;
21) use Encode qw/encode decode/;
22)
23) # Configuration
24) $smsc="+33609001390";
|
Add check_authorized_number...
Benjamin Renard authored 12 years ago
|
25) $check_authorized_number=undef;
|
initial commit
Benjamin Renard authored 12 years ago
|
26) @authorized_number=("0612345678","0033600000000");
27) $gnokii_config="/etc/gnokiirc";
28)
29) # constantes tirees de <sysexits.h>
30) use constant {
31) EX_OK => 0,
32) EX_USAGE => 64,
33) EX_DATAERR => 65,
34) EX_NOINPUT => 66,
35) EX_NOUSER => 67,
36) EX_NOHOST => 68,
37) EX_UNAVAILABLE => 69,
38) EX_SOFTWARE => 70
39) };
40)
41)
|
add smsc option to script m...
Benjamin Renard authored 12 years ago
|
42) if($#ARGV + 1 != 1 and $#ARGV + 1 != 2){
43) print "Usage : mail2gnokii [phone number] [SMSC phone number]";
|
initial commit
Benjamin Renard authored 12 years ago
|
44) exit EX_USAGE;
45) }
46)
47)
48)
49) # recuperation du mail
50)
51) my $text;
52)
53) while(<STDIN>){
54) $text .= $_;
55) }
56)
57)
58) if($text eq ''){
59) print "Mail is empty !";
60) exit EX_NOINPUT;
61) }
62)
63) my $email = Email::Simple->new($text);
64)
65)
66) # recuperation du sujet
67)
68) my $subject = $email->header("Subject");
69)
70) if($subject eq ''){
71) print "No text in Subject header !";
72) exit EX_NOINPUT;
73) }
74)
75) $subject = decode('MIME-Header', $subject);
76)
77)
78)
79) # recuperation du numero de mobile
80) my $mob=$ARGV[0];
81)
82) if (not $mob =~ m/^[0-9]*$/) {
83) print "Invalid phone number : $mob";
84) exit EX_DATAERR;
85) }
86)
|
add smsc option to script m...
Benjamin Renard authored 12 years ago
|
87) # recuperation du numero du SMSC (si present)
88) if (defined $ARGV[1]) {
89) if (not $ARGV[1]=~ m/^[0-9\+]*$/) {
90) print "Invalid SMSC phone number : "+$ARGV[1];
91) exit EX_DATAERR;
92) }
93) $smsc=$ARGV[1];
94) }
95)
|
initial commit
Benjamin Renard authored 12 years ago
|
96) sub in_array {
97) my ($arr,$search_for) = @_;
98) my %items = map {$_ => 1} @$arr; # create a hash out of the array values
99) return (exists($items{$search_for}))?1:0;
100) }
101)
102) # Envoie du SMS
|
Add check_authorized_number...
Benjamin Renard authored 12 years ago
|
103) if (not $check_authorized_number or $mob ne '' && in_array(\@authorized_number,$mob)){
|