Zionetrix::Git
Repositories
Help
Report an Issue
gnokii-admin-scripts
Code
Commits
Branches
Tags
Search
Tree:
b5e826d
Branches
Tags
master
gnokii-admin-scripts
mail2gnokii
initial commit
Benjamin Renard
commited
b5e826d
at 2012-07-25 17:04:50
mail2gnokii
Blame
History
Raw
#!/usr/bin/perl -w # # mail2gnokii # # Postfix transport to sending SMS by gnokii # # Usage : # # in master.cf : # # sms unix - n n - 1 pipe # flags=Rq user=gnokii:dialout argv=/usr/local/sbin/mail2gnokii ${user} # # in transport : # # sms.example.tld sms # # # arg1: phone number use Email::Simple; use Encode qw/encode decode/; # Configuration $smsc="+33609001390"; @authorized_number=("0612345678","0033600000000"); $gnokii_config="/etc/gnokiirc"; # constantes tirees de <sysexits.h> use constant { EX_OK => 0, EX_USAGE => 64, EX_DATAERR => 65, EX_NOINPUT => 66, EX_NOUSER => 67, EX_NOHOST => 68, EX_UNAVAILABLE => 69, EX_SOFTWARE => 70 }; if($#ARGV + 1 != 1){ print "Usage : mail2gnokii [phone number]"; exit EX_USAGE; } # recuperation du mail my $text; while(<STDIN>){ $text .= $_; } if($text eq ''){ print "Mail is empty !"; exit EX_NOINPUT; } my $email = Email::Simple->new($text); # recuperation du sujet my $subject = $email->header("Subject"); if($subject eq ''){ print "No text in Subject header !"; exit EX_NOINPUT; } $subject = decode('MIME-Header', $subject); # recuperation du numero de mobile my $mob=$ARGV[0]; if (not $mob =~ m/^[0-9]*$/) { print "Invalid phone number : $mob"; exit EX_DATAERR; } sub in_array { my ($arr,$search_for) = @_; my %items = map {$_ => 1} @$arr; # create a hash out of the array values return (exists($items{$search_for}))?1:0; } # Envoie du SMS if ($mob ne '' && in_array(\@authorized_number,$mob)){ `echo "$subject" | gnokii --config $gnokii_config --sendsms $mob --smsc $smsc`; if($? != 0){ print "Error sending SMS"; exit EX_SOFTWARE; } } else{ print "Phone number $mob not in authorized list"; exit EX_DATAERR; } exit EX_OK;