]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/mail.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 #enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
32 #Initialize variables and hashes
33 my $dmafile="${General::swroot}/dma/dma.conf";
34 my $authfile="${General::swroot}/dma/auth.conf";
35 my $mailfile="${General::swroot}/dma/mail.conf";
43 #Read all parameters for site
44 &Header
::getcgihash
(\
%cgiparams);
45 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
46 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
49 &Header
::showhttpheaders
();
53 open (FILE
, "<", $dmafile) or die $!;
54 foreach my $line (<FILE
>) {
55 $line =~ m/^([A-Z]+)\s+?(.*)?$/;
61 open(FILE
, ">$dmafile") or die $!;
65 if (exists $dma{'AUTHPATH'}){
66 open (FILE
, "<", $dma{'AUTHPATH'}) or die "$dma{'AUTHPATH'} nicht gefunden $! ";
68 foreach my $line (<FILE
>) {
71 my @part1 = split(/\|/,$authline);
72 my @part2 = split(/\:/,$part1[1]);
73 $auth{'AUTHNAME'} = $part1[0];
74 $auth{'AUTHHOST'} = $part2[0];
75 $auth{'AUTHPASS'} = $part2[1];
79 &General
::readhash
($mailfile, \
%mail);
83 if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveButton on configsite
85 $errormessage = &checkmailsettings
();
94 open (TXT
, ">$dmafile") or die("Could not open /var/ipfire/dma/dma.conf: $!\n");
95 open (TXT1
, ">$authfile") or die("Could not open /var/ipfire/dma/auth.conf: $!\n");
96 open (TXT2
, ">$mailfile") or die("Could not open /var/ipfire/dma/mail.conf: $!\n");
99 #Fill hashes with actual values
100 $mail{'USEMAIL'} = $cgiparams{'USEMAIL'};
101 $mail{'SENDER'} = $cgiparams{'txt_mailsender'};
102 $mail{'RECIPIENT'} = $cgiparams{'txt_recipient'};
104 if ($cgiparams{'txt_mailuser'} && $cgiparams{'txt_mailpass'}) {
105 $auth{'AUTHNAME'} = $cgiparams{'txt_mailuser'};
106 $auth{'AUTHPASS'} = $cgiparams{'txt_mailpass'};
107 $auth{'AUTHHOST'} = $cgiparams{'txt_mailserver'};
108 print TXT1
"$auth{'AUTHNAME'}|$auth{'AUTHHOST'}:$auth{'AUTHPASS'}\n";
111 $dma{'SMARTHOST'} = $cgiparams{'txt_mailserver'};
112 $dma{'PORT'} = $cgiparams{'txt_mailport'};
113 $dma{'STARTTLS'} = '' if ($cgiparams{'mail_tls'} eq 'explicit');
114 $dma{'SECURETRANSFER'} = '' if ($cgiparams{'mail_tls'} eq 'explicit' || $cgiparams{'mail_tls'} eq 'implicit');
115 $dma{'SPOOLDIR'} = "/var/spool/dma";
116 $dma{'FULLBOUNCE'} = '';
117 $dma{'MAILNAME'} = "$mainsettings{'HOSTNAME'}.$mainsettings{DOMAINNAME}";
118 $dma{'AUTHPATH'} = "$authfile" if exists $auth{'AUTHNAME'};
120 #Create new configfiles
121 &General
::writehash
("$mailfile", \
%mail);
122 while ( ($k,$v) = each %dma ) {
130 $cgiparams{'update'}='on';
134 if ($cgiparams{'ACTION'} eq "$Lang::tr{'email testmail'}"){ #Testmail button on configsite
143 #If update set fieldvalues new
144 if($cgiparams{'update'} eq 'on'){
145 $mail{'USEMAIL'} = 'on';
146 $mail{'SENDER'} = $cgiparams{'txt_mailsender'};
147 $mail{'RECIPIENT'} = $cgiparams{'txt_recipient'};
148 $dma{'SMARTHOST'} = $cgiparams{'txt_mailserver'};
149 $dma{'PORT'} = $cgiparams{'txt_mailport'};
150 $auth{'AUTHNAME'} = $cgiparams{'txt_mailuser'};
151 $auth{'AUTHHOST'} = $cgiparams{'txt_mailserver'};
152 $auth{'AUTHPASS'} = $cgiparams{'txt_mailpass'};
153 $dma{'STARTTLS'} = $cgiparams{'mail_tls'};
156 $checked{'usemail'}{$mail{'USEMAIL'}} = 'CHECKED';
157 $selected{'mail_tls'}{'explicit'} = 'selected' if exists $dma{'STARTTLS'};
158 $selected{'mail_tls'}{'implicit'} = 'selected' if (exists $dma{'SECURETRANSFER'}) and (not exists $dma{'STARTTLS'});
159 $selected{'mail_tls'}{'disabled'} = 'selected' if (not exists $dma{'SECURETRANSFER'}) and (not exists $dma{'STARTTLS'});
162 &Header
::openpage
($Lang::tr
{'email settings'}, 1, '');
163 &Header
::openbigbox
('100%', 'center');
166 &Header
::openbox
('100%', 'left', $Lang::tr
{'email config'});
168 #### JAVA SCRIPT ####
171 \$(document).ready(function() {
172 // Show/Hide elements when USEMAIL checkbox is checked.
173 if (\$("#MAIL").attr("checked")) {
174 \$(".MAILSRV").show();
176 \$(".MAILSRV").hide();
179 // Toggle MAIL elements when "USEMAIL" checkbox is clicked
180 \$("#MAIL").change(function() {
181 \$(".MAILSRV").toggle();
186 ##### JAVA SCRIPT END ####
187 my $col="style='background-color:$color{'color22'}'";
189 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
190 <table style='width:100%' border='0'>
192 <th colspan='3'></th>
195 <td style='width:24em'>$Lang::tr{'email usemail'}</td>
196 <td><label><input type='checkbox' name='USEMAIL' id='MAIL' $checked{'usemail'}{'on'}></label></td>
201 <div class="MAILSRV">
202 <table style='width:100%;'>
204 <td>$Lang::tr{'email mailsender'}<img src='/blob.gif' alt='*' /></td>
205 <td><input type='text' name='txt_mailsender' value='$mail{'SENDER'}' style='width:22em;'></td>
208 <td>$Lang::tr{'email mailrcpt'}<img src='/blob.gif' alt='*' /></td>
209 <td><input type='text' name='txt_recipient' value='$mail{'RECIPIENT'}' style='width:22em;'></td>
212 <td style='width:24em'>$Lang::tr{'email mailaddr'}<img src='/blob.gif' alt='*' /></td>
213 <td><input type='text' name='txt_mailserver' value='$dma{'SMARTHOST'}' style='width:22em;'></td>
216 <td>$Lang::tr{'email mailport'}<img src='/blob.gif' alt='*' /></td>
217 <td><input type='text' name='txt_mailport' value='$dma{'PORT'}' size='3'></td>
220 <td>$Lang::tr{'email mailuser'}</td>
221 <td><input type='text' name='txt_mailuser' value='$auth{'AUTHNAME'}' style='width:22em;'></td>
224 <td>$Lang::tr{'email mailpass'}</td>
225 <td><input type='password' name='txt_mailpass' value='$auth{'AUTHPASS'}' style='width:22em;' ></td>
228 <td>$Lang::tr{'email tls'}</td>
230 <select name='mail_tls'>
231 <option value='implicit' $selected{'mail_tls'}{'implicit'}>$Lang::tr{'email tls implicit'}</option>
232 <option value='explicit' $selected{'mail_tls'}{'explicit'}>$Lang::tr{'email tls explicit'}</option>
233 <option value='disabled' $selected{'mail_tls'}{'disabled'}>$Lang::tr{'disabled'}</option>
238 if (! -z
$dmafile && $mail{'USEMAIL'} eq 'on' && !$errormessage){
241 print "<td><input type='submit' name='ACTION' value='$Lang::tr{'email testmail'}'></td>";
246 <td colspan='2'> </td>
251 <table style='width:100%;'>
253 <td colspan='3' display:inline align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
260 &Header
::closebigbox
();
261 &Header
::closepage
();
265 sub checkmailsettings
{
266 #Check if mailserver is an ip address or a domain
267 if ($cgiparams{'txt_mailserver'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){
268 if (! &General
::validip
($cgiparams{'txt_mailserver'})){
269 $errormessage .= $Lang::tr
{'email invalid mailip'} . "<br>";
271 }elsif(! &General
::validfqdn
($cgiparams{'txt_mailserver'})){
272 $errormessage .= $Lang::tr
{'email invalid mailfqdn'} . "<br>";
274 #Check valid mailserverport
275 if($cgiparams{'txt_mailport'} < 1 || $cgiparams{'txt_mailport'} > 65535){
276 $errormessage .= $Lang::tr
{'email invalid mailport'} . "<br>";
279 if(! $cgiparams{'txt_mailsender'}){
280 $errormessage .= $Lang::tr
{'email empty field'} . "<br>";
282 if (! &General
::validemail
($cgiparams{'txt_mailsender'})){
283 $errormessage .= "$Lang::tr{'email invalid'} $Lang::tr{'email mailsender'}<br>";
286 return $errormessage;
290 ### Create a new multipart message:
291 $msg = MIME
::Lite
->new(
292 From
=> $mail{'SENDER'},
293 To
=> $mail{'RECIPIENT'},
294 #Cc => 'some@other.com, some@more.com',
295 Subject
=> 'IPFire Testmail',
296 Type
=> 'multipart/mixed'
299 ### Add parts (each "attach" has same arguments as "new"):
302 Data
=> "This is the IPFire test mail."
305 ### Add attachment for testing
307 # Type => 'application/txt',
308 # Encoding => 'base64',
309 # Path => '/var/ipfire/dma/dma.conf',
310 # Filename => 'dma.conf',
311 # Disposition => 'attachment'
314 $msg->send_by_sendmail;
319 &Header
::openbox
('100%', 'left', $Lang::tr
{'info messages'});
320 print "<class name='base'>$infomessage\n";
321 print " </class>\n";
328 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
329 print "<class name='base'>$errormessage\n";
330 print " </class>\n";