From: Alexander Marx Date: Fri, 21 Aug 2015 08:46:26 +0000 (+0100) Subject: Add web UI for the system MTA X-Git-Tag: v2.17-core94~54^2~8 X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=commitdiff_plain;h=9c7b90207ed941175f4f906f038e1966fea1d362;hp=fb79f85b49d9304185463195d627d046672701c6 Add web UI for the system MTA Signed-off-by: Michael Tremer --- diff --git a/config/menu/40-services.menu b/config/menu/40-services.menu index 2f4d96e736..aaf1ad715f 100644 --- a/config/menu/40-services.menu +++ b/config/menu/40-services.menu @@ -20,6 +20,11 @@ 'title' => "$Lang::tr{'time server'}", 'enabled' => 1, }; + $subservices->{'41.dma'} = {'caption' => $Lang::tr{'email settings'}, + 'uri' => '/cgi-bin/mail.cgi', + 'title' => "$Lang::tr{'email settings'}", + 'enabled' => 1, + }; $subservices->{'50.qos'} = {'caption' => 'Quality of Service', 'uri' => '/cgi-bin/qos.cgi', 'title' => "Quality of Service", diff --git a/html/cgi-bin/mail.cgi b/html/cgi-bin/mail.cgi new file mode 100755 index 0000000000..d409a4c69d --- /dev/null +++ b/html/cgi-bin/mail.cgi @@ -0,0 +1,345 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2015 IPFire Team # +# # +# 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 MIME::Lite; + +#enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; + +#Initialize variables and hashes +my $dmafile="${General::swroot}/dma/dma.conf"; +my $authfile="${General::swroot}/dma/auth.conf"; +my $mailfile="${General::swroot}/dma/mail.conf"; +my %dma=(); +my %auth=(); +my %mail=(); +my %mainsettings=(); +my %cgiparams=(); +my $errormessage=''; + +#Read all parameters for site +&Header::getcgihash(\%cgiparams); +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + +#Show Headers +&Header::showhttpheaders(); + +#Check configfiles +if ( -f $dmafile){ + open (FILE, "<", $dmafile) or die $!; + foreach my $line () { + $line =~ m/^([A-Z]+)\s+?(.*)?$/; + my $key = $1; + my $val = $2; + $dma{$key}=$val; + } +}else{ + open(FILE, ">$dmafile") or die $!; +} +close FILE; + +if (exists $dma{'AUTHPATH'}){ + open (FILE, "<", $dma{'AUTHPATH'}) or die "$dma{'AUTHPATH'} nicht gefunden $! "; + my $authline; + foreach my $line () { + $authline = $line; + } + my @part1 = split(/\|/,$authline); + my @part2 = split(/\:/,$part1[1]); + $auth{'AUTHNAME'} = $part1[0]; + $auth{'AUTHHOST'} = $part2[0]; + $auth{'AUTHPASS'} = $part2[1]; +} + +if ( -f $mailfile){ + &General::readhash($mailfile, \%mail); +} + +#ACTIONS +if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveButton on configsite + #Check fields + if ($cgiparams{'USEMAIL'} eq 'on'){ + $errormessage=&checkmailsettings; + }else{ + $cgiparams{'txt_mailserver'}=''; + $cgiparams{'txt_mailport'}=''; + $cgiparams{'txt_mailuser'}=''; + $cgiparams{'txt_mailpass'}=''; + $cgiparams{'mail_tls'}=''; + $cgiparams{'txt_mailsender'}=''; + $cgiparams{'txt_recipient'}=''; + } + if(!$errormessage){ + #clear hashes + %auth=(); + %dma=(); + %mail=(); + + #clear configfiles + open (TXT, ">$dmafile") or die("Could not open /var/ipfire/dma/dma.conf: $!\n"); + open (TXT1, ">$authfile") or die("Could not open /var/ipfire/dma/dma.conf: $!\n"); + open (TXT2, ">$mailfile") or die("Could not open /var/ipfire/dma/dma.conf: $!\n"); + close TXT2; + + #Fill hashes with actual values + $mail{'USEMAIL'} = $cgiparams{'USEMAIL'}; + $mail{'SENDER'} = $cgiparams{'txt_mailsender'}; + $mail{'RECIPIENT'} = $cgiparams{'txt_recipient'}; + + $auth{'AUTHNAME'} = $cgiparams{'txt_mailuser'}; + $auth{'AUTHPASS'} = $cgiparams{'txt_mailpass'}; + $auth{'AUTHHOST'} = $cgiparams{'txt_mailserver'}; + + $dma{'SMARTHOST'} = $cgiparams{'txt_mailserver'}; + $dma{'PORT'} = $cgiparams{'txt_mailport'}; + $dma{'STARTTLS'} = '' if ($cgiparams{'mail_tls'}); + $dma{'SECURETRANSFER'} = '' if exists $dma{'STARTTLS'}; + $dma{'SPOOLDIR'} = "/var/spool/dma"; + $dma{'FULLBOUNCE'} = ''; + $dma{'MAILNAME'} = "$mainsettings{'HOSTNAME'}.$mainsettings{DOMAINNAME}"; + $dma{'AUTHPATH'} = "$authfile" if exists $auth{'AUTHNAME'}; + + #Create new configfiles + &General::writehash("$mailfile", \%mail); + while ( ($k,$v) = each %dma ) { + print TXT "$k $v\n"; + } + close TXT; + print TXT1 "$auth{'AUTHNAME'}|$auth{'AUTHHOST'}:$auth{'AUTHPASS'}\n"; + close TXT2; + + }else{ + $cgiparams{'update'}='on'; + &configsite; + } +} +if ($cgiparams{'ACTION'} eq "$Lang::tr{'email testmail'}"){ #Testmail button on configsite + &testmail; +} + +#Show site +&configsite; + +#FUNCTIONS +sub configsite{ + + + #If update set fieldvalues new + if($cgiparams{'update'} eq 'on'){ + $dma{'USEMAIL'}= 'on'; + $dma{'SMARTHOST'} = $cgiparams{'txt_mailserver'}; + $dma{'PORT'} = $cgiparams{'txt_mailport'}; + $auth{'AUTHUSER'} = $cgiparams{'txt_mailuser'}; + $auth{'AUTHHOST'} = $cgiparams{'txt_mailserver'}; + $auth{'AUTHPASS'} = $cgiparams{'txt_mailpass'}; + } + #find preselections + $checked{'usemail'}{$mail{'USEMAIL'}} = 'CHECKED'; + $checked{'mail_tls'}{'on'} = 'CHECKED' if exists $dma{'STARTTLS'}; + + #Open site + &Header::openpage($Lang::tr{'email settings'}, 1, ''); + &Header::openbigbox('100%', 'center'); + &error; + &info; + &Header::openbox('100%', 'left', $Lang::tr{'email config'}); + + #### JAVA SCRIPT #### + print< + \$(document).ready(function() { + // Show/Hide elements when USEMAIL checkbox is checked. + if (\$("#MAIL").attr("checked")) { + \$(".MAILSRV").show(); + } else { + \$(".MAILSRV").hide(); + } + + // Toggle MAIL elements when "USEMAIL" checkbox is clicked + \$("#MAIL").change(function() { + \$(".MAILSRV").toggle(); + }); + }); + +END + ##### JAVA SCRIPT END #### + my $col="style='background-color:$color{'color22'}'"; + print< + + + + + + + + + +
$Lang::tr{'email usemail'}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +END + if (! -z $dmafile && $mail{'USEMAIL'} eq 'on'){ + print ""; + print ""; + print ""; + print ""; + } + print< + + +
$Lang::tr{'email mailaddr'}
$Lang::tr{'email mailport'}
$Lang::tr{'email mailuser'}*
$Lang::tr{'email mailpass'}*
$Lang::tr{'email tls'}
$Lang::tr{'email mailsender'}
$Lang::tr{'email mailrcpt'}
 
+
+ + + + + +
+
+ +END + &Header::closebox(); + &Header::closebigbox(); + &Header::closepage(); + exit 0; +} + +sub checkmailsettings { + #Check if mailserver is an ip address or a domain + if ($cgiparams{'txt_mailserver'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){ + if (! &General::validip($cgiparams{'txt_mailserver'})){ + $errormessage.="$Lang::tr{'email invalid mailip'} $cgiparams{'txt_mailserver'}
"; + } + }elsif(! &General::validfqdn($cgiparams{'txt_mailserver'})){ + $errormessage.="$Lang::tr{'email invalid mailfqdn'} $cgiparams{'txt_mailserver'}
"; + } + #Check valid mailserverport + if($cgiparams{'txt_mailport'} < 1 || $cgiparams{'txt_mailport'} > 65535){ + $errormessage.="$Lang::tr{'email invalid mailport'} $cgiparams{'txt_mailport'}
"; + } + #Check valid sender + if(! $cgiparams{'txt_mailsender'}){ + $errormessage.="$Lang::tr{'email empty field'} $Lang::tr{'email mailsender'}
"; + }else{ + if (! &General::validemail($cgiparams{'txt_mailsender'})){ + $errormessage.="
$Lang::tr{'email invalid'} $Lang::tr{'email mailsender'}
"; + } + } + return $errormessage; +} + +sub testmail { + ### Create a new multipart message: + $msg = MIME::Lite->new( + From => $mail{'SENDER'}, + To => $mail{'RECIPIENT'}, + #Cc => 'some@other.com, some@more.com', + Subject => 'IPFire Testmail', + Type => 'multipart/mixed' + ); + + ### Add parts (each "attach" has same arguments as "new"): + $msg->attach( + Type => 'TEXT', + Data => "This is the IPFire test mail." + ); + + ### Add attachment for testing + #$msg->attach( + # Type => 'application/txt', + # Encoding => 'base64', + # Path => '/var/ipfire/dma/dma.conf', + # Filename => 'dma.conf', + # Disposition => 'attachment' + #); + + $msg->send_by_sendmail; +} + +sub info { + if ($infomessage) { + &Header::openbox('100%', 'left', $Lang::tr{'info messages'}); + print "$infomessage\n"; + print " \n"; + &Header::closebox(); + } +} + +sub error { + if ($errormessage) { + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage\n"; + print " \n"; + &Header::closebox(); + } +} + + + + + + + + + + + + + + + diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 48ade280a8..36b54b8a05 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -833,6 +833,26 @@ 'edit share' => 'Freigabe bearbeiten', 'editor' => 'Editor', 'eg' => 'z.B.:', +'email invalid mailip' => 'Ungültige IP-Adresse für Mailserver', +'email invalid mailfqdn' => 'Ungültiger FQDN für Mailserver', +'email invalid mailport' => 'Ungültiger Port für Mailserver', +'email empty field' => 'Leeres Feld', +'email mailaddr' => 'Mailserver-Adresse', +'email mailport' => 'Mailserver-Port', +'email mailuser' => 'Benutzername', +'email mailpass' => 'Passwort', +'email tls' => 'TLS aktivieren', +'email mailrcpt' => 'E-Mail-Empfänger', +'email mailsender' => 'E-Mail Absender', +'email usemail' => 'Mailversand aktivieren', +'email settings' => 'Mailversand', +'email config' => 'Konfiguration', +'email subject' => 'IPFire Testmail', +'email text' => 'Testnachricht vom IPFire Mailversand.', +'email testmail' => 'Testnachricht senden', +'email success' => 'Testmail erfolgreich versendet', +'email error' => 'ERROR: Testmail konnte nicht versendet werden', +'email invalid' => 'Ungültiges Feld', 'email server can not be empty' => 'Email-Server darf nicht leer sein', 'emailreportlevel' => 'Email-Reportlevel', 'empty' => 'Dieses Feld kann leer bleiben', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index af7fda947e..ef5f50b3e9 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -859,6 +859,26 @@ 'edit share' => 'Edit share', 'editor' => 'Editor', 'eg' => 'e.g.:', +'email invalid mailip' => 'Invalid mailserver IP address', +'email invalid mailfqdn' => 'Invalid mailserver fqdn', +'email invalid mailport' => 'Invalid mailserver port', +'email empty field' => 'Empty field', +'email mailaddr' => 'Mailserver address', +'email mailport' => 'Mailserver port', +'email mailuser' => 'Username', +'email mailpass' => 'Password', +'email tls' => 'Use TLS', +'email mailrcpt' => 'Mail recipient', +'email mailsender' => 'Mail sender', +'email usemail' => 'Activate Mailservice', +'email settings' => 'Mailservice', +'email config' => 'Configuration', +'email subject' => 'IPFire Testmail', +'email text' => 'Testmail from IPFire Mailservice.', +'email testmail' => 'Send testmail', +'email success' => 'Testmail successfully sent', +'email error' => 'ERROR: Testmail could not be sent', +'email invalid' => 'Invalid field', 'email server can not be empty' => 'E-mail server can not be empty', 'emailreportlevel' => 'E-mailreportlevel', 'emerging rules' => 'Emergingthreats.net Community Rules',