--- /dev/null
+ #!/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;