]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/index.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
12 # enable only the following on debugging purpose
14 use CGI
::Carp
'fatalsToBrowser';
16 require '/var/ipfire/general-functions.pl';
17 require "${General::swroot}/lang.pl";
18 require "${General::swroot}/header.pl";
29 &Header
::showhttpheaders
();
31 $cgiparams{'ACTION'} = '';
32 &Header
::getcgihash
(\
%cgiparams);
33 $pppsettings{'VALID'} = '';
34 $pppsettings{'PROFILENAME'} = 'None';
35 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
36 &General
::readhash
("${General::swroot}/modem/settings", \
%modemsettings);
37 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
38 &General
::readhash
("${General::swroot}/ddns/settings", \
%ddnssettings);
41 my %mainsettings = ();
42 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
43 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
45 my $connstate = &Header
::connectionstatus
();
46 if ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e
"${General::swroot}/main/refreshindex") {
47 $refresh = "<meta http-equiv='refresh' content='30;'>";
48 } elsif ($connstate =~ /$Lang::tr{'connecting'}/) {
49 $refresh = "<meta http-equiv='refresh' content='5;'>";
52 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial profile'})
54 my $profile = $cgiparams{'PROFILE'};
55 my %tempcgiparams = ();
56 $tempcgiparams{'PROFILE'} = '';
57 &General
::readhash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
60 # make a link from the selected profile to the "default" one.
61 unlink("${General::swroot}/ppp/settings");
62 link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
63 "${General::swroot}/ppp/settings");
64 system ("/usr/bin/touch", "${General::swroot}/ppp/updatesettings");
66 # read in the new params "early" so we can write secrets.
68 &General
::readhash
("${General::swroot}/ppp/settings", \
%cgiparams);
69 $cgiparams{'PROFILE'} = $profile;
70 $cgiparams{'BACKUPPROFILE'} = $profile;
71 &General
::writehash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
75 open(FILE
, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
77 my $username = $cgiparams{'USERNAME'};
78 my $password = $cgiparams{'PASSWORD'};
79 print FILE
"'$username' * '$password'\n";
80 chmod 0600, "${General::swroot}/ppp/secrets";
83 &General
::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
84 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
87 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial'}) {
88 system('/usr/local/bin/redctrl start > /dev/null') == 0
89 or &General
::log("Dial failed: $?"); sleep 1;}
90 elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'hangup'}) {
91 system('/usr/local/bin/redctrl stop > /dev/null') == 0
92 or &General
::log("Hangup failed: $?"); sleep 1;}
96 my @profilenames = ();
98 for ($c = 1; $c <= $maxprofiles; $c++)
100 my %temppppsettings = ();
101 $temppppsettings{'PROFILENAME'} = '';
102 &General
::readhash
("${General::swroot}/ppp/settings-$c", \
%temppppsettings);
103 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
106 for ($c = 1; $c <= $maxprofiles; $c++) {
107 $selected{'PROFILE'}{$c} = '';
109 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
110 my $dialButtonDisabled = "disabled='disabled'";
113 &Header
::openpage
($Lang::tr
{'main page'}, 1, $refresh);
114 &Header
::openbigbox
('', 'center');
115 &Header
::openbox
('100%', 'center', &Header
::cleanhtml
(`/bin/uname -n`,"y"));
117 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
118 if (open(IPADDR
,"${General::swroot}/ddns/ipcache")) {
123 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
128 } elsif ($modemsettings{'VALID'} eq 'no') {
129 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
131 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
134 if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
135 $ipaddr = $netsettings{'RED_ADDRESS'};
141 if ($cgiparams{'ACTION'} eq $Lang::tr
{'shutdown'}) {
143 &General
::log($Lang::tr
{'shutting down ipfire'});
144 system '/usr/local/bin/ipfirereboot down';
145 } elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'reboot'}) {
147 &General
::log($Lang::tr
{'rebooting ipfire'});
148 system '/usr/local/bin/ipfirereboot boot';
151 if ($death == 0 && $rebirth == 0) {
154 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
157 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
158 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
159 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
166 <!-- Table of networks -->
167 <table border='0' width=80%>
168 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}
169 <th bgcolor='$color{'color20'}'>IP
170 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}
171 <tr> <td bgcolor='$Header::colourred' width='25%'><a href="/cgi-bin/pppsetup.cgi"><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font></a><br>
172 <td width='30%' align='center'>$ipaddr
173 <td width='45%' align='center'>$connstate
175 if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
176 print `/usr/local/bin/dialctrl.pl show`;
179 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
180 <select name='PROFILE'>
182 for ($c = 1; $c <= $maxprofiles; $c++)
184 if ($profilenames[$c] ne '') {
185 $dialButtonDisabled = "";
186 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
189 $dialButtonDisabled = "disabled='disabled'" if (-e
'/var/run/ppp-ipfire.pid' || -e
"${General::swroot}/red/active");
190 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
193 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
196 <table width='100%' border='0'>
198 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
199 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
201 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
202 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
207 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
210 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
211 if ( "$HOSTNAME" ne "" ) {
213 <tr><td><b>Hostname:</b><td align='center'>$HOSTNAME<td>
217 if ( -e
"/var/ipfire/red/remote-ipaddress" ) {
218 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
221 <tr><td><b>Gateway:</b><td align='center'>$GATEWAY<td>
225 my $DNS1 = `cat /var/ipfire/red/dns1`;
226 my $DNS2 = `cat /var/ipfire/red/dns2`;
230 if ( $DNS1 ) { print <<END;
231 <tr><td><b>DNS-Server:</b><td align='center'>$DNS1
234 if ( $DNS2 ) { print <<END;
235 <td align='center'>$DNS2
237 } else { print <<END;
242 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
243 <tr><td bgcolor='$Header::colourgreen' width='25%'><a href="/cgi-bin/dhcp.cgi"><font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font></a>
244 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}
245 <td width='45%' align='center'>
247 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
249 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
250 } else { print "Proxy aus"; }
252 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
253 <tr><td bgcolor='$Header::colourblue' width='25%'><a href="/cgi-bin/wireless.cgi"><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font></a><br>
254 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}
255 <td width='45%' align='center'>
257 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
259 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
260 } else { print "Proxy aus"; }
262 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
263 <tr><td bgcolor='$Header::colourorange' width='25%'><a href="/cgi-bin/dmzholes.cgi"><font size='2' color='white'><b>$Lang::tr{'dmz'}:</b></font></a><br>
264 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}
265 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
268 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
269 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
270 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
271 my @status = `/usr/sbin/ipsec auto --status`;
273 &General
::readhasharray
("${General::swroot}/vpn/config", \
%confighash);
275 <tr><td bgcolor='$Header::colourvpn' width='25%'><a href="/cgi-bin/vpnmain.cgi"><font size='2' color='white'><b>$Lang::tr{'vpn'}:</b></font></a><br>
276 <td width='30%' align='center'>$ipsecip
277 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
281 foreach my $key (keys %confighash) {
282 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
285 print "<tr><td align='center'> </td><td align='center' nowrap='nowrap' bgcolor='$color{'color20'}'>$confighash{$key}[1] / " . $Lang::tr
{"$confighash{$key}[3]"} . " (" . $Lang::tr
{"$confighash{$key}[4]"} . ")</td>";
287 print "<tr><td align='center'> </td><td align='center' nowrap='nowrap' bgcolor='$color{'color22'}'>$confighash{$key}[1] / " . $Lang::tr
{"$confighash{$key}[3]"} . " (" . $Lang::tr
{"$confighash{$key}[4]"} . ")</td>";
290 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>";
291 if ($confighash{$key}[0] eq 'off') {
292 $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>";
294 foreach my $line (@status) {
295 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
296 $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>";
300 print "<td align='center'>$active</td>";
303 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
304 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
305 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
306 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
308 <tr><td bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN:</b></font></a><br>
309 <td width='30%' align='center'>$ovpnip
310 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
314 # Memory usage warning
315 my @free = `/usr/bin/free`;
316 $free[1] =~ m/(\d+)/;
318 $free[2] =~ m/(\d+)/;
320 my $pct = int 100 * ($mem - $used) / $mem;
321 if ($used / $mem > 90) {
322 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
325 # Diskspace usage warning
328 my @df = `/bin/df -B M -x rootfs`;
329 foreach my $line (@df) {
330 next if $line =~ m/^Filesystem/;
331 if ($line =~ m/root/ ) {
332 $line =~ m/^.* (\d+)M.*$/;
333 @temp = split(/ +/,$line);
335 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
336 # and root size should not vary during time
337 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
341 # $line =~ m/^.* (\d+)m.*$/;
342 $line =~ m/^.* (\d+)\%.*$/;
344 @temp = split(/ /,$line);
346 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
352 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
361 $message = $Lang::tr
{'ipfire has now shutdown'};
363 $message = $Lang::tr
{'ipfire has now rebooted'};
367 <table width='100%' bgcolor='#ffffff'>
368 <tr><td align='center'>
369 <br /><br /><img src='/images/IPFire.png' /><br /><br /><br />
373 <font size='6'>$message</font>
379 &Header
::closebigbox
();
380 &Header
::closepage
();