From: Alexander Marx Date: Mon, 26 Jan 2015 03:45:07 +0000 (+0100) Subject: Merge branch 'sendemail2' of ssh://git.ipfire.org/pub/git/people/amarx/ipfire-2.x... X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fsendemail2;p=people%2Famarx%2Fipfire-2.x.git Merge branch 'sendemail2' of ssh://git.ipfire.org/pub/git/people/amarx/ipfire-2.x into sendemail2 --- dd70092728e81d3195d0cd07702a92faeacff870 diff --cc src/sendemail/sendemail-lib.pl index 000000000,4568f63db..e1d85b30b mode 000000,100644..100644 --- a/src/sendemail/sendemail-lib.pl +++ b/src/sendemail/sendemail-lib.pl @@@ -1,0 -1,109 +1,112 @@@ + #!/usr/bin/perl + ############################################################################### + # # + # IPFire.org - A linux based firewall # + # Copyright (C) 2013 Alexander Marx # + # # + # This program is free software: you can redistribute it and/or modify # + # it under the terms of the GNU General Public License as published by # + # the Free Software Foundation, either version 3 of the License, or # + # (at your option) any later version. # + # # + # This program is distributed in the hope that it will be useful, # + # but WITHOUT ANY WARRANTY; without even the implied warranty of # + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # + # GNU General Public License for more details. # + # # + # You should have received a copy of the GNU General Public License # + # along with this program. If not, see . # + # # + ############################################################################### + + use strict; + no warnings 'uninitialized'; + + package mail; + + require '/var/ipfire/general-functions.pl'; + + my $configmail = "${General::swroot}/sendemail/settings"; + my %mailsettings = (); + + &General::readhash("${General::swroot}/sendemail/settings", \%mailsettings); + + #functions: get single values + sub check_config{ + if (! -z $configmail){ + return 1; + } + return 0; + } + sub get_recipient{ + if(&check_config()){ + return $mailsettings{'RECIPIENT'}; + } + return 0; + } + sub get_sender{ + if(&check_config()){ + return $mailsettings{'SENDER'}; + } + return 0; + } + sub get_server{ + if(&check_config()){ + return $mailsettings{'SERVER'}; + } + return 0; + } + sub get_port{ + if(&check_config()){ + return $mailsettings{'PORT'}; + } + return 0; + } + sub get_tls{ + if(&check_config()){ + return $mailsettings{'TLS'}; + } + return 0; + } + sub get_user{ + if(&check_config()){ + return $mailsettings{'USER'}; + } + return 0; + } + + #functions: send mail + sub send_mail(){ + # 1st parameter: subject + # 2nd parameter: mailtext + # 3rd parameter: attachment (optional) + # 4rd parameter: sender (instead of configured one - optional) + # 5th parameter: recipients (instead of configured one - optional) ++ # 6th parameter: CC if needed. ++ # TAKE CARE! Not used parameters must be given with '' if the following parameters are set-> e.g. &mail::send_mail('SUBJECTTEXT','MAILTEXT','','','','ccmail@nowhere.de') + + if(&check_config() && $mailsettings{'USEMAIL'} eq 'on' && @_ ge 2){ + my $cmd = "/usr/local/bin/sendEmail "; + $cmd .= " -u ".$_[0]; + $cmd .= " -m ".$_[1]; + $cmd .= " -a ".$_[2] if $_[2]; + $mailsettings{'SENDER'} = $_[3] if $_[3]; + $cmd .= " -f $mailsettings{'SENDER'}"; + $mailsettings{'RECIPIENT'} = $_[4] if $_[4]; + $cmd .= " -t $mailsettings{'RECIPIENT'}"; ++ $cmd .= " -cc ".$_[5] if $_[5]; + $cmd .= " -s $mailsettings{'SERVER'}:$mailsettings{'PORT'}"; + $cmd .= " -xu $mailsettings{'USER'}" if $mailsettings{'USER'}; + $cmd .= " -xp $mailsettings{'PASS'}" if $mailsettings{'PASS'}; + $cmd .= " -q "; + #Send Mail via TLS? + if ($mailsettings{'TLS'} eq 'on'){ + $cmd .= " -o tls=yes"; + } + my $res=system ($cmd); + return $res; + } + return 1; + } + + return 1;