]> git.ipfire.org Git - people/amarx/ipfire-2.x.git/commitdiff
Merge branch 'sendemail2' of ssh://git.ipfire.org/pub/git/people/amarx/ipfire-2.x... sendemail2
authorAlexander Marx <alexander.marx@ipfire.org>
Mon, 26 Jan 2015 03:45:07 +0000 (04:45 +0100)
committerAlexander Marx <alexander.marx@ipfire.org>
Mon, 26 Jan 2015 05:00:16 +0000 (06:00 +0100)
1  2 
src/sendemail/sendemail-lib.pl

index 0000000000000000000000000000000000000000,4568f63db1fe51d9878adece54f846dae6da4ff0..e1d85b30b4d6d70244ba74ade988057142d5a023
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,109 +1,112 @@@
+ #!/usr/bin/perl
+ ###############################################################################
+ #                                                                             #
+ # IPFire.org - A linux based firewall                                         #
+ # Copyright (C) 2013 Alexander Marx <amarx@ipfire.org>                        #
+ #                                                                             #
+ # 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 <http://www.gnu.org/licenses/>.       #
+ #                                                                             #
+ ###############################################################################
+ 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;