]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/index.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 # check if reboot is necessary
63 if (`find /var/run/need_reboot 2>/dev/null`) {
67 if ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown'} || $cgiparams{'ACTION'} eq $Lang::tr
{'reboot'}) {
68 $refresh = "<meta http-equiv='refresh' content='300;'>";
69 } elsif ($connstate =~ /$Lang::tr{'connecting'}/ || /$Lang::tr{'connection closed'}/ ){
70 $refresh = "<meta http-equiv='refresh' content='5;'>";
71 } elsif ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e
"${General::swroot}/main/refreshindex") {
72 $refresh = "<meta http-equiv='refresh' content='30;'>";
75 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial profile'})
77 my $profile = $cgiparams{'PROFILE'};
78 my %tempcgiparams = ();
79 $tempcgiparams{'PROFILE'} = '';
80 &General
::readhash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
83 # make a link from the selected profile to the "default" one.
84 unlink("${General::swroot}/ppp/settings");
85 link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
86 "${General::swroot}/ppp/settings");
87 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
89 # read in the new params "early" so we can write secrets.
91 &General
::readhash
("${General::swroot}/ppp/settings", \
%cgiparams);
92 $cgiparams{'PROFILE'} = $profile;
93 $cgiparams{'BACKUPPROFILE'} = $profile;
94 &General
::writehash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
98 open(FILE
, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
100 my $username = $cgiparams{'USERNAME'};
101 my $password = $cgiparams{'PASSWORD'};
102 print FILE
"'$username' * '$password'\n";
103 chmod 0600, "${General::swroot}/ppp/secrets";
106 &General
::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
107 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
110 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial'}) {
111 system('/usr/local/bin/redctrl start > /dev/null') == 0
112 or &General
::log("Dial failed: $?"); sleep 1;}
113 elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'hangup'}) {
114 system('/usr/local/bin/redctrl stop > /dev/null') == 0
115 or &General
::log("Hangup failed: $?"); sleep 1;}
119 my @profilenames = ();
121 for ($c = 1; $c <= $maxprofiles; $c++)
123 my %temppppsettings = ();
124 $temppppsettings{'PROFILENAME'} = '';
125 &General
::readhash
("${General::swroot}/ppp/settings-$c", \
%temppppsettings);
126 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
129 for ($c = 1; $c <= $maxprofiles; $c++) {
130 $selected{'PROFILE'}{$c} = '';
132 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
133 my $dialButtonDisabled = "disabled='disabled'";
136 &Header
::openpage
($Lang::tr
{'main page'}, 1, $refresh);
137 &Header
::openbigbox
('', 'center');
138 &Header
::openbox
('100%', 'center', &Header
::cleanhtml
(`/bin/uname -n`,"y"));
142 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
143 if (open(IPADDR
,"${General::swroot}/ddns/ipcache")) {
148 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
153 } elsif ($modemsettings{'VALID'} eq 'no') {
154 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
156 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
159 #if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
160 # $ipaddr = $netsettings{'RED_ADDRESS'};
166 if ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown'}) {
168 &General
::log($Lang::tr
{'shutting down ipfire'});
169 system '/usr/local/bin/ipfirereboot down';
170 } elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'reboot'}) {
172 &General
::log($Lang::tr
{'rebooting ipfire'});
173 system '/usr/local/bin/ipfirereboot boot';
176 if ($death == 0 && $rebirth == 0) {
178 if ($mainsettings{'REBOOTQUESTION'} eq "off") {
180 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
183 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
184 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
185 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
192 if ($cgiparams{'ACTION'} eq $Lang::tr
{'reboot ask'}) {
194 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
197 <td colspan="3" align='left'><font color="red">$Lang::tr{'reboot sure'}</font></td>
200 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
201 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
202 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown ask'}' /></td>
208 } elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown ask'}) {
210 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
213 <td colspan="3" align='right'><font color="red">$Lang::tr{'shutdown sure'}</font></td>
216 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot ask'}' /></td>
217 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
218 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
226 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
229 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot ask'}' /></td>
230 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
231 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown ask'}' /></td>
242 <!-- Table of networks -->
243 <table border='0' width=80%>
244 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}
245 <th bgcolor='$color{'color20'}'>IP
246 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}
247 <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>
248 <td width='30%' align='center'>$ipaddr
249 <td width='45%' align='center'>$connstate
251 if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
252 print `/usr/local/bin/dialctrl.pl show`;
255 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
256 <select name='PROFILE'>
258 for ($c = 1; $c <= $maxprofiles; $c++)
260 if ($profilenames[$c] ne '') {
261 $dialButtonDisabled = "";
262 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
265 $dialButtonDisabled = "disabled='disabled'" if (-e
'/var/run/ppp-ipfire.pid' || -e
"${General::swroot}/red/active");
266 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
269 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
272 <table width='100%' border='0'>
274 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
275 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
277 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
278 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
283 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
286 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
287 if ( "$HOSTNAME" ne "" ) {
289 <tr><td><b>Hostname:</b><td align='center'>$HOSTNAME<td>
293 if ( -e
"/var/ipfire/red/remote-ipaddress" ) {
294 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
297 <tr><td><b>Gateway:</b><td align='center'>$GATEWAY<td>
301 my $DNS1 = `cat /var/ipfire/red/dns1`;
302 my $DNS2 = `cat /var/ipfire/red/dns2`;
306 if ( $DNS1 ) { print <<END;
307 <tr><td><b>DNS-Server:</b><td align='center'>$DNS1
310 if ( $DNS2 ) { print <<END;
311 <td align='center'>$DNS2
313 } else { print <<END;
318 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
319 <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>
320 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}
321 <td width='45%' align='center'>
323 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
324 print $Lang::tr
{'advproxy on'};
325 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
326 } else { print $Lang::tr
{'advproxy off'}; }
328 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
329 <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>
330 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}
331 <td width='45%' align='center'>
333 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
334 print $Lang::tr
{'advproxy on'};
335 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
336 } else { print $Lang::tr
{'advproxy off'}; }
338 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
339 <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>
340 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}
341 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
344 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
345 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
346 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
347 my @status = `/usr/local/bin/ipsecctrl I`;
349 &General
::readhasharray
("${General::swroot}/vpn/config", \
%confighash);
351 <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>
352 <td width='30%' align='center'>$ipsecip
353 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
357 foreach my $key (keys %confighash) {
358 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
361 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>";
363 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>";
366 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>";
367 if ($confighash{$key}[0] eq 'off') {
368 $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>";
370 foreach my $line (@status) {
371 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
372 $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>";
376 print "<td align='center'>$active</td>";
379 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
380 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
381 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
382 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
384 <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>
385 <td width='30%' align='center'>$ovpnip
386 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
390 # Memory usage warning
391 my @free = `/usr/bin/free`;
392 $free[1] =~ m/(\d+)/;
394 $free[2] =~ m/(\d+)/;
396 my $pct = int 100 * ($mem - $used) / $mem;
397 if ($used / $mem > 90) {
398 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
401 # Diskspace usage warning
404 my @df = `/bin/df -B M -x rootfs`;
405 foreach my $line (@df) {
406 next if $line =~ m/^Filesystem/;
407 if ($line =~ m/root/ ) {
408 $line =~ m/^.* (\d+)M.*$/;
409 @temp = split(/ +/,$line);
411 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
412 # and root size should not vary during time
413 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
417 # $line =~ m/^.* (\d+)m.*$/;
418 $line =~ m/^.* (\d+)\%.*$/;
420 @temp = split(/ /,$line);
422 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
427 # S.M.A.R.T. health warning
428 my @files = `/bin/ls /var/run/smartctl_out_hddtemp-*`;
429 foreach my $file (@files) {
431 my $disk=`echo $file | cut -d"-" -f2`;
433 if (`/bin/grep "SAVE ALL DATA" $file`) {
434 $warnmessage .= "<li> $Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>\n\n";
440 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
446 &Pakfire
::dblist
("upgrade", "notice");
450 print "<br /><font color='red'>$Lang::tr{'needreboot'}!</font>";
455 $message = $Lang::tr
{'ipfire has now shutdown'};
457 $message = $Lang::tr
{'ipfire has now rebooted'};
461 <table width='100%' bgcolor='#ffffff'>
462 <tr><td align='center'>
463 <br /><br /><img src='/images/IPFire.png' /><br /><br /><br />
467 <font size='6'>$message</font>
475 &Header
::closebigbox
();
476 &Header
::closepage
();