2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2011 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";
31 require "/opt/pakfire/lib/functions.pl";
43 &Header
::showhttpheaders
();
45 $cgiparams{'ACTION'} = '';
46 &Header
::getcgihash
(\
%cgiparams);
47 $pppsettings{'VALID'} = '';
48 $pppsettings{'PROFILENAME'} = 'None';
49 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
50 &General
::readhash
("${General::swroot}/modem/settings", \
%modemsettings);
51 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
52 &General
::readhash
("${General::swroot}/ddns/settings", \
%ddnssettings);
55 my %mainsettings = ();
56 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
57 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
59 my $connstate = &Header
::connectionstatus
();
61 if ( -e
"/var/ipfire/main/gpl-accepted" ) {
62 if ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown'} || $cgiparams{'ACTION'} eq $Lang::tr
{'reboot'}) {
63 $refresh = "<meta http-equiv='refresh' content='300;'>";
64 } elsif ($connstate =~ /$Lang::tr{'connecting'}/ || /$Lang::tr{'connection closed'}/ ){
65 $refresh = "<meta http-equiv='refresh' content='5;'>";
66 } elsif ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e
"${General::swroot}/main/refreshindex") {
67 $refresh = "<meta http-equiv='refresh' content='30;'>";
71 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial profile'})
73 my $profile = $cgiparams{'PROFILE'};
74 my %tempcgiparams = ();
75 $tempcgiparams{'PROFILE'} = '';
76 &General
::readhash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
79 # make a link from the selected profile to the "default" one.
80 unlink("${General::swroot}/ppp/settings");
81 link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
82 "${General::swroot}/ppp/settings");
83 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
85 # read in the new params "early" so we can write secrets.
87 &General
::readhash
("${General::swroot}/ppp/settings", \
%cgiparams);
88 $cgiparams{'PROFILE'} = $profile;
89 $cgiparams{'BACKUPPROFILE'} = $profile;
90 &General
::writehash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
94 open(FILE
, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
96 my $username = $cgiparams{'USERNAME'};
97 my $password = $cgiparams{'PASSWORD'};
98 print FILE
"'$username' * '$password'\n";
99 chmod 0600, "${General::swroot}/ppp/secrets";
102 &General
::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
103 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
106 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial'}) {
107 system('/usr/local/bin/redctrl start > /dev/null') == 0
108 or &General
::log("Dial failed: $?"); sleep 1;}
109 elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'hangup'}) {
110 system('/usr/local/bin/redctrl stop > /dev/null') == 0
111 or &General
::log("Hangup failed: $?"); sleep 1;}
115 my @profilenames = ();
117 for ($c = 1; $c <= $maxprofiles; $c++)
119 my %temppppsettings = ();
120 $temppppsettings{'PROFILENAME'} = '';
121 &General
::readhash
("${General::swroot}/ppp/settings-$c", \
%temppppsettings);
122 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
125 for ($c = 1; $c <= $maxprofiles; $c++) {
126 $selected{'PROFILE'}{$c} = '';
128 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
129 my $dialButtonDisabled = "disabled='disabled'";
132 &Header
::openpage
($Lang::tr
{'main page'}, 1, $refresh);
133 &Header
::openbigbox
('', 'center');
136 if ($cgiparams{'ACTION'} eq $Lang::tr
{'yes'} && $cgiparams{'gpl_accepted'} eq '1') {
137 system('touch /var/ipfire/main/gpl_accepted')
139 if ( -e
"/var/ipfire/main/gpl_accepted" ) {
140 &Header
::openbox
('100%', 'center', &Header
::cleanhtml
(`/bin/uname -n`,"y"));
143 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
144 if (open(IPADDR
,"${General::swroot}/ddns/ipcache")) {
149 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
154 } elsif ($modemsettings{'VALID'} eq 'no') {
155 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
157 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
160 #if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
161 # $ipaddr = $netsettings{'RED_ADDRESS'};
167 if ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown'}) {
169 &General
::log($Lang::tr
{'shutting down ipfire'});
170 system '/usr/local/bin/ipfirereboot down';
171 } elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'reboot'}) {
173 &General
::log($Lang::tr
{'rebooting ipfire'});
174 system '/usr/local/bin/ipfirereboot boot';
177 if ($death == 0 && $rebirth == 0) {
179 if ($mainsettings{'REBOOTQUESTION'} eq "off") {
181 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
184 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
185 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
186 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
193 if ($cgiparams{'ACTION'} eq $Lang::tr
{'reboot ask'}) {
195 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
198 <td colspan="3" align='left'><font color="red">$Lang::tr{'reboot sure'}</font></td>
201 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
202 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
203 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown ask'}' /></td>
209 } elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown ask'}) {
211 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
214 <td colspan="3" align='right'><font color="red">$Lang::tr{'shutdown sure'}</font></td>
217 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot ask'}' /></td>
218 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
219 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
227 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
230 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot ask'}' /></td>
231 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
232 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown ask'}' /></td>
243 <!-- Table of networks -->
244 <table border='0' width=80%>
245 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}
246 <th bgcolor='$color{'color20'}'>IP
247 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}
248 <tr> <td align='center' bgcolor='$Header::colourred' width='25%'><a href="/cgi-bin/pppsetup.cgi"><font size='2' color='white'><b>$Lang::tr{'internet'}</b></font></a><br>
249 <td width='30%' align='center'>$ipaddr
250 <td width='45%' align='center'>$connstate
252 if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
253 print `/usr/local/bin/dialctrl.pl show`;
256 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
257 <select name='PROFILE'>
259 for ($c = 1; $c <= $maxprofiles; $c++)
261 if ($profilenames[$c] ne '') {
262 $dialButtonDisabled = "";
263 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
266 $dialButtonDisabled = "disabled='disabled'" if (-e
'/var/run/ppp-ipfire.pid' || -e
"${General::swroot}/red/active");
267 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
270 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
273 <table width='100%' border='0'>
275 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
276 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
278 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
279 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
284 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
287 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
288 if ( "$HOSTNAME" ne "" ) {
290 <tr><td><b>Hostname:</b><td align='center'>$HOSTNAME<td>
294 if ( -e
"/var/ipfire/red/remote-ipaddress" ) {
295 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
298 <tr><td><b>Gateway:</b><td align='center'>$GATEWAY<td>
302 my $DNS1 = `cat /var/ipfire/red/dns1`;
303 my $DNS2 = `cat /var/ipfire/red/dns2`;
307 if ( $DNS1 ) { print <<END;
308 <tr><td><b>DNS-Server:</b><td align='center'>$DNS1
311 if ( $DNS2 ) { print <<END;
312 <td align='center'>$DNS2
314 } else { print <<END;
319 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
320 <tr><td align='center' bgcolor='$Header::colourgreen' width='25%'><a href="/cgi-bin/dhcp.cgi"><font size='2' color='white'><b>$Lang::tr{'lan'}</b></font></a>
321 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}
322 <td width='45%' align='center'>
324 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
325 print $Lang::tr
{'advproxy on'};
326 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
327 } else { print $Lang::tr
{'advproxy off'}; }
329 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
330 <tr><td align='center' bgcolor='$Header::colourblue' width='25%'><a href="/cgi-bin/wireless.cgi"><font size='2' color='white'><b>$Lang::tr{'wireless'}</b></font></a><br>
331 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}
332 <td width='45%' align='center'>
334 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
335 print $Lang::tr
{'advproxy on'};
336 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
337 } else { print $Lang::tr
{'advproxy off'}; }
339 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
340 <tr><td align='center' bgcolor='$Header::colourorange' width='25%'><a href="/cgi-bin/dmzholes.cgi"><font size='2' color='white'><b>$Lang::tr{'dmz'}</b></font></a><br>
341 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}
342 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
345 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
346 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
347 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
348 my @status = `/usr/local/bin/ipsecctrl I`;
350 &General
::readhasharray
("${General::swroot}/vpn/config", \
%confighash);
352 <tr><td align='center' bgcolor='$Header::colourvpn' width='25%'><a href="/cgi-bin/vpnmain.cgi"><font size='2' color='white'><b>$Lang::tr{'vpn'}</b></font></a><br>
353 <td width='30%' align='center'>$ipsecip
354 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
358 foreach my $key (keys %confighash) {
359 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
362 print "<tr><td align='left' nowrap='nowrap' bgcolor='$color{'color20'}'>$confighash{$key}[1] / " . $Lang::tr
{"$confighash{$key}[3]"} . " (" . $Lang::tr
{"$confighash{$key}[4]"} . ")</td><td align='center'>$confighash{$key}[11]</td>";
364 print "<tr></td><td align='left' nowrap='nowrap' bgcolor='$color{'color22'}'>$confighash{$key}[1] / " . $Lang::tr
{"$confighash{$key}[3]"} . " (" . $Lang::tr
{"$confighash{$key}[4]"} . ")</td><td align='center'>$confighash{$key}[11]</td>";
367 my $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td></tr></table>";
368 if ($confighash{$key}[0] eq 'off') {
369 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourblue}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td></tr></table>";
371 foreach my $line (@status) {
372 if (($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) ||
373 ($line =~/$confighash{$key}[1]\{.*INSTALLED/ ))
375 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b></td></tr></table>";
379 print "<td align='center'>$active</td>";
382 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
383 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
384 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
385 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
387 <tr><td align='center' bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN</b></font></a><br>
388 <td width='30%' align='center'>$ovpnip
389 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
397 if ( -d
"${General::swroot}/ovpn/n2nconf") {
399 &General
::readhasharray
("${General::swroot}/ovpn/ovpnconfig", \
%confighash);
400 foreach my $dkey (keys %confighash) {
401 if ($confighash{$dkey}[0] eq 'on' && $confighash{$dkey}[3] eq 'net') {
402 my @n2novpnet = split(/\//,$confighash{$dkey}[27]);
404 <tr><td align='center' bgcolor='$Header::colourvpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN n2n</b></font></a><br>
405 <td width='30%' align='center'> $n2novpnet[0]
406 <td width='45%' align='center'><font color=$Header::colourblue>$confighash{$dkey}[6]</font>
413 if ( ! -e
"/var/ipfire/main/send_profile") {
414 $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>";
417 # Memory usage warning
418 my @free = `/usr/bin/free`;
419 $free[1] =~ m/(\d+)/;
421 $free[2] =~ m/(\d+)/;
423 my $pct = int 100 * ($mem - $used) / $mem;
424 if ($used / $mem > 90) {
425 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
428 # Diskspace usage warning
431 my @df = `/bin/df -B M -P -x rootfs`;
432 foreach my $line (@df) {
433 next if $line =~ m/^Filesystem/;
434 if ($line =~ m/root/ ) {
435 $line =~ m/^.* (\d+)M.*$/;
436 @temp = split(/ +/,$line);
438 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
439 # and root size should not vary during time
440 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
444 # $line =~ m/^.* (\d+)m.*$/;
445 $line =~ m/^.* (\d+)\%.*$/;
447 @temp = split(/ /,$line);
449 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
454 # S.M.A.R.T. health warning
455 my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`;
456 foreach my $file (@files) {
458 my $disk=`echo $file | cut -d"-" -f2`;
460 if (`/bin/grep "SAVE ALL DATA" $file`) {
461 $warnmessage .= "<li> $Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>\n\n";
466 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
472 &Pakfire
::dblist
("upgrade", "notice");
475 if ( -e
"/var/run/need_reboot" ) {
476 print "<br /><br /><font color='red'>$Lang::tr{'needreboot'}!</font>";
481 $message = $Lang::tr
{'ipfire has now shutdown'};
483 $message = $Lang::tr
{'ipfire has now rebooted'};
487 <table width='100%' bgcolor='#ffffff'>
488 <tr><td align='center'>
489 <br /><br /><img src='/images/IPFire.png' /><br /><br /><br />
493 <font size='6'>$message</font>
504 &Header
::openbox
('100%', 'left', $Lang::tr
{'gpl license agreement'});
506 $Lang::tr{'gpl please read carefully the general public license and accept it below'}.
510 if ( -e
"/usr/share/doc/licenses/GPLv3" ) {
511 print '<textarea rows=\'25\' cols=\'75\' readonly=\'true\'>';
512 print `cat /usr/share/doc/licenses/GPLv3`;
516 print '<br /><a href=\'http://www.gnu.org/licenses/gpl-3.0.txt\' target=\'_blank\'>GNU GENERAL PUBLIC LICENSE</a><br />';
520 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
521 <input type='checkbox' name='gpl_accepted' value='1'/> $Lang::tr{'gpl i accept these terms and conditions'}.
523 <input type='submit' name='ACTION' value=$Lang::tr{'yes'} />
526 <a href='http://www.gnu.org/licenses/translations.html' target='_blank'>$Lang::tr{'gpl unofficial translation of the general public license v3'}</a>
533 &Header
::closebigbox
();
534 &Header
::closepage
();