]>
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-2012 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 ###############################################################################
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33 require "/opt/pakfire/lib/functions.pl";
51 if ( ! -e
"/var/ipfire/main/gpl_accepted" ) {
52 print "Status: 302 Moved Temporarily\n";
53 print "Location: gpl.cgi\n\n";
57 &Header
::showhttpheaders
();
59 $cgiparams{'ACTION'} = '';
60 &Header
::getcgihash
(\
%cgiparams);
61 $pppsettings{'VALID'} = '';
62 $pppsettings{'PROFILENAME'} = 'None';
63 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
64 &General
::readhash
("${General::swroot}/modem/settings", \
%modemsettings);
65 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
66 &General
::readhash
("${General::swroot}/ddns/settings", \
%ddnssettings);
67 &General
::readhash
("${General::swroot}/proxy/advanced/settings", \
%proxysettings);
68 &General
::readhash
("${General::swroot}/vpn/settings", \
%vpnsettings);
71 my %mainsettings = ();
72 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
73 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
75 my $connstate = &Header
::connectionstatus
();
77 if ( -e
"/var/ipfire/main/gpl-accepted" ) {
78 if ($connstate =~ /$Lang::tr{'connecting'}/ || /$Lang::tr{'connection closed'}/ ){
79 $refresh = "<meta http-equiv='refresh' content='5;'>";
80 }elsif ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e
"${General::swroot}/main/refreshindex") {
81 $refresh = "<meta http-equiv='refresh' content='30;'>";
85 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial profile'})
87 my $profile = $cgiparams{'PROFILE'};
88 my %tempcgiparams = ();
89 $tempcgiparams{'PROFILE'} = '';
90 &General
::readhash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
93 # make a link from the selected profile to the "default" one.
94 unlink("${General::swroot}/ppp/settings");
95 link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
96 "${General::swroot}/ppp/settings");
97 open (TMP
, ">${General::swroot}/ppp/updatesettings");
99 # read in the new params "early" so we can write secrets.
101 &General
::readhash
("${General::swroot}/ppp/settings", \
%cgiparams);
102 $cgiparams{'PROFILE'} = $profile;
103 $cgiparams{'BACKUPPROFILE'} = $profile;
104 &General
::writehash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
107 # write secrets file.
108 open(FILE
, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
110 my $username = $cgiparams{'USERNAME'};
111 my $password = $cgiparams{'PASSWORD'};
112 print FILE
"'$username' * '$password'\n";
113 chmod 0600, "${General::swroot}/ppp/secrets";
116 &General
::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
117 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
120 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial'}) {
121 system('/usr/local/bin/redctrl start > /dev/null') == 0
122 or &General
::log("Dial failed: $?"); sleep 1;
123 }elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'hangup'}) {
124 system('/usr/local/bin/redctrl stop > /dev/null') == 0
125 or &General
::log("Hangup failed: $?"); sleep 1;
130 my @profilenames = ();
132 for ($c = 1; $c <= $maxprofiles; $c++)
134 my %temppppsettings = ();
135 $temppppsettings{'PROFILENAME'} = '';
136 &General
::readhash
("${General::swroot}/ppp/settings-$c", \
%temppppsettings);
137 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
140 for ($c = 1; $c <= $maxprofiles; $c++) {
141 $selected{'PROFILE'}{$c} = '';
143 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
144 my $dialButtonDisabled = "disabled='disabled'";
146 &Header
::openpage
($Lang::tr
{'main page'}, 1, $refresh);
147 &Header
::openbigbox
('', 'center');
148 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
154 &Header
::openbox
('100%', 'center', '');
155 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
156 if (open(IPADDR
,"${General::swroot}/ddns/ipcache")) {
161 } elsif ($modemsettings{'VALID'} eq 'no') {
162 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
164 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
168 <!-- Table of networks -->
169 <table width=80% class='tbl' >
170 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}</th>
171 <th bgcolor='$color{'color20'}'>$Lang::tr{'ip address'}</th>
172 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}</th></tr>
173 <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></td>
174 <td width='30%' align='center'>$ipaddr </td>
175 <td width='45%' align='center'>$connstate </td></tr>
177 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
178 if ( "$HOSTNAME" ne "" ) {
180 <tr><td><b>Hostname:</b><td align='center'>$HOSTNAME</td><td></td>
184 if ( -e
"${General::swroot}/red/remote-ipaddress" ) {
185 open (TMP
, "<${General::swroot}/red/remote-ipaddress");
190 <tr><td><b>Gateway:</b><td align='center'>$GATEWAY</td><td></td></tr>
194 open (DNS1
, "<${General::swroot}/red/dns1");
199 open (DNS2
, "<${General::swroot}/red/dns2");
207 <b>$Lang::tr{'dns server'}</b>
220 if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
221 print `/usr/local/bin/dialctrl.pl show`;
226 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
227 <select name='PROFILE'>
229 for ($c = 1; $c <= $maxprofiles; $c++)
231 if ($profilenames[$c] ne '') {
232 $dialButtonDisabled = "";
233 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
236 $dialButtonDisabled = "disabled='disabled'" if (-e
'/var/run/ppp-ipfire.pid' || -e
"${General::swroot}/red/active");
237 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
240 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
243 <table width='100%' border='0'>
245 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
246 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
248 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
249 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
254 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
256 print"</tr></table>";
258 if ( $netsettings{'GREEN_DEV'} ) {
259 my $sub=&General
::iporsubtocidr
($netsettings{'GREEN_NETMASK'});
262 <table width='80%' class='tbl'>
264 <th>$Lang::tr{'network'}</th>
265 <th>$Lang::tr{'ip address'}</th>
266 <th>$Lang::tr{'status'}</th>
268 <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>
269 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}/$sub
270 <td width='45%' align='center'>
272 if ( $proxysettings{'ENABLE'} eq 'on' ) {
273 print $Lang::tr
{'advproxy on'};
274 if ( $proxysettings{'TRANSPARENT'} eq 'on' ) { print " (transparent)"; }
275 } else { print $Lang::tr
{'advproxy off'}; }
277 if ( $netsettings{'BLUE_DEV'} ) {
278 my $sub=&General
::iporsubtocidr
($netsettings{'BLUE_NETMASK'});
280 <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>
281 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}/$sub
282 <td width='45%' align='center'>
284 if ( $proxysettings{'ENABLE_BLUE'} eq 'on' ) {
285 print $Lang::tr
{'advproxy on'};
286 if ( $proxysettings{'TRANSPARENT_BLUE'} eq 'on' ) { print " (transparent)"; }
287 } else { print $Lang::tr
{'advproxy off'}; }
289 if ( $netsettings{'ORANGE_DEV'} ) {
290 my $sub=&General
::iporsubtocidr
($netsettings{'ORANGE_NETMASK'});
292 <tr><td align='center' bgcolor='$Header::colourorange' width='25%'><a href="/cgi-bin/firewall.cgi"><font size='2' color='white'><b>$Lang::tr{'dmz'}</b></font></a><br>
293 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}/$sub
294 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
297 #check if IPSEC is running
298 if ( $vpnsettings{'ENABLED'} eq 'on' || $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {
299 my $ipsecip = $vpnsettings{'VPN_IP'};
301 <tr><td align='center' bgcolor='$Header::colourvpn' width='25%'><a href="/cgi-bin/vpnmain.cgi"><font size='2' color='white'><b>$Lang::tr{'ipsec'}</b></font></a><br>
302 <td width='30%' align='center'>$ipsecip
303 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
307 #check if OpenVPN is running
309 &General
::readhash
("${General::swroot}/ovpn/settings", \
%confighash);
311 if (($confighash{'ENABLED'} eq "on") ||
312 ($confighash{'ENABLED_BLUE'} eq "on") ||
313 ($confighash{'ENABLED_ORANGE'} eq "on")) {
314 my ($ovpnip,$sub) = split("/",$confighash{'DOVPN_SUBNET'});
315 $sub=&General
::iporsubtocidr
($sub);
316 $ovpnip="$ovpnip/$sub";
319 <td align='center' bgcolor='$Header::colourovpn' width='25%'>
320 <a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN</b></font></a><br>
322 <td width='30%' align='center'>$ovpnip
323 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
326 print"</td></tr></table>";
329 #Check if there are any vpns configured (ipsec and openvpn)
330 &General
::readhasharray
("${General::swroot}/vpn/config", \
%vpnconfig);
331 foreach my $key (sort { ncmp
($vpnconfig{$a}[1],$vpnconfig{$b}[1]) } keys %vpnconfig) {
332 if ($vpnconfig{$key}[0] eq 'on'){
338 &General
::readhasharray
("${General::swroot}/ovpn/ovpnconfig", \
%ovpnconfig);
339 foreach my $dkey (sort { ncmp
($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
340 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e
"/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
348 # Start of Box wich contains all vpn connections
349 &Header
::openbox
('100%', 'center', $Lang::tr
{'vpn'});
350 #show ipsec connectiontable
352 my $ipsecip = $vpnsettings{'VPN_IP'};
353 my @status = `/usr/local/bin/ipsecctrl I`;
361 <table width='80%' class='tbl'>
363 <th width='40%'>$Lang::tr{'ipsec network'}</th>
364 <th width='30%'>$Lang::tr{'ip address'}</th>
365 <th width='30%'>$Lang::tr{'status'}</th>
368 foreach my $key (sort { uc($vpnconfig{$a}[1]) cmp uc($vpnconfig{$b}[1]) } keys %vpnconfig) {
369 if ($vpnconfig{$key}[0] eq 'on') {
371 my ($vpnip,$vpnsub) = split("/",$vpnconfig{$key}[11]);
372 $vpnsub=&General
::iporsubtocidr
($vpnsub);
373 $vpnip="$vpnip/$vpnsub";
375 $col="bgcolor='$color{'color22'}'";
377 $col="bgcolor='$color{'color20'}'";
380 print "<tr><td align='left' nowrap='nowrap' bgcolor='$Header::colourvpn'><font color=white>$vpnconfig{$key}[1]</td><td align='center' $col>$vpnip</td>";
382 print "<tr></td><td align='left' nowrap='nowrap' bgcolor='$Header::colourvpn'><font color=white>$vpnconfig{$key}[1]</td><td align='center' $col>$vpnip</td>";
384 my $active = "<td bgcolor='${Header::colourred}' align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td>";
385 if ($vpnconfig{$key}[0] eq 'off') {
386 $active = "<td bgcolor='${Header::colourblue}' align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td>";
388 foreach my $line (@status) {
389 if (($line =~ /\"$vpnconfig{$key}[1]\".*IPsec SA established/) || ($line =~/$vpnconfig{$key}[1]\{.*INSTALLED/ )){
390 $active = "<td align='center' bgcolor='${Header::colourgreen}'><b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b></td>";
394 print "$active</td>";
397 print "</tr></table>";
401 # Check if there is any OpenVPN connection configured.
407 <table width='80%' class='tbl'>
409 <th width='40%'>$Lang::tr{'openvpn network'}</th>
410 <th width='30%'>$Lang::tr{'ip address'}</th>
411 <th width='30%'>$Lang::tr{'status'}</th>
414 # Check if the OpenVPN server for Road Warrior Connections is running and display status information.
417 # Print the OpenVPN N2N connection status.
418 if ( -d
"${General::swroot}/ovpn/n2nconf") {
420 foreach my $dkey (sort { ncmp
($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
421 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e
"/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
423 my $tport = $ovpnconfig{$dkey}[22];
424 next if ($tport eq '');
425 my $tnet = new Net
::Telnet
( Timeout
=>5, Errmode
=>'return', Port
=>$tport);
426 $tnet->open('127.0.0.1');
427 my @output = $tnet->cmd(String
=> 'state', Prompt
=> '/(END.*\n|ERROR:.*\n)/');
428 my @tustate = split(/\,/, $output[1]);
430 my $display_colour = $Header::colourred
;
431 if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) {
432 $display_colour = $Header::colourgreen
;
433 $display = $Lang::tr
{'capsopen'};
435 $display = $tustate[1];
438 $col="bgcolor='$color{'color22'}'";
440 $col="bgcolor='$color{'color20'}'";
444 my ($vpnip,$vpnsub) = split("/",$ovpnconfig{$dkey}[11]);
445 my $vpnsub=&General
::iporsubtocidr
($vpnsub);
446 my $vpnip="$vpnip/$vpnsub";
449 <td align='left' nowrap='nowrap' bgcolor='$Header::colourovpn'><font color='white'>$ovpnconfig{$dkey}[1]</font></td>
450 <td align='center' $col>$vpnip</td>
451 <td align='center' bgcolor='$display_colour' ><b><font color='#FFFFFF'>$display</font></b></td>
457 if ($active ne 'off'){
458 print "<tr><td colspan='3' align='center'>$Lang::tr{'ovpn no connections'}</td></tr>";
466 if ( ! -e
"/var/ipfire/main/send_profile") {
467 $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>";
470 # Memory usage warning
471 my @free = `/usr/bin/free`;
472 $free[1] =~ m/(\d+)/;
474 $free[2] =~ m/(\d+)/;
476 my $pct = int 100 * ($mem - $used) / $mem;
477 if ($used / $mem > 90) {
478 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
481 # Diskspace usage warning
484 my @df = `/bin/df -B M -P -x rootfs`;
485 foreach my $line (@df) {
486 next if $line =~ m/^Filesystem/;
487 if ($line =~ m/root/ ) {
488 $line =~ m/^.* (\d+)M.*$/;
489 @temp = split(/ +/,$line);
491 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
492 # and root size should not vary during time
493 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
497 # $line =~ m/^.* (\d+)m.*$/;
498 $line =~ m/^.* (\d+)\%.*$/;
500 @temp = split(/ /,$line);
502 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
507 # S.M.A.R.T. health warning
508 my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`;
509 foreach my $file (@files) {
511 my $disk=`echo $file | cut -d"-" -f2`;
513 if (`/bin/grep "SAVE ALL DATA" $file`) {
514 $warnmessage .= "<li> $Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>\n\n";
519 my @files = `mount | grep " reiser4 (" 2>/dev/null`;
520 foreach my $disk (@files) {
522 $warnmessage .= "<li>$disk - $Lang::tr{'deprecated fs warn'}</li>\n\n";
526 &Header
::openbox
('100%','center', );
527 print "<table width='80%' class='tbl'>";
528 print "<tr><th>$Lang::tr{'fwhost hint'}</th></tr>";
529 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
533 print "<div align='center'>";
534 &Pakfire
::dblist
("upgrade", "notice");
535 if ( -e
"/var/run/need_reboot" ) {
536 print "<br /><br /><font color='red'>$Lang::tr{'needreboot'}!</font>";
541 &Header
::closebigbox
();
542 &Header
::closepage
();