connections.cgi: Make the html pass html validation
[people/teissler/ipfire-2.x.git] / html / cgi-bin / index.cgi
CommitLineData
ac1cfefa 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
b81b96d2 5# Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
ac1cfefa
MT
21
22use strict;
54fd0535 23use Net::Telnet;
9d386698 24use Sort::Naturally;
ac1cfefa
MT
25
26# enable only the following on debugging purpose
cb5e9c6c
CS
27#use warnings;
28#use CGI::Carp 'fatalsToBrowser';
ac1cfefa 29
e383179b 30require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
31require "${General::swroot}/lang.pl";
32require "${General::swroot}/header.pl";
2b38ab5c 33require "/opt/pakfire/lib/functions.pl";
ac1cfefa
MT
34
35my %cgiparams=();
36my %pppsettings=();
37my %modemsettings=();
38my %netsettings=();
39my %ddnssettings=();
9d386698
AM
40my %proxysettings=();
41my %vpnsettings=();
42my %vpnconfig=();
43my %ovpnconfig=();
ac1cfefa 44my $warnmessage = '';
c85ec3b4 45my $refresh = "";
e383179b 46my $ipaddr='';
9d386698
AM
47my $showbox=0;
48my $showipsec=0;
49my $showovpn=0;
50
51if ( ! -e "/var/ipfire/main/gpl_accepted" ) {
52 print "Status: 302 Moved Temporarily\n";
53 print "Location: gpl.cgi\n\n";
54 exit (0);
55}
337305ef 56
ac1cfefa
MT
57&Header::showhttpheaders();
58
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);
9d386698
AM
67&General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
68&General::readhash("${General::swroot}/vpn/settings", \%vpnsettings);
ac1cfefa 69
f2fdd0c1
CS
70my %color = ();
71my %mainsettings = ();
72&General::readhash("${General::swroot}/main/settings", \%mainsettings);
73&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
74
ac1cfefa 75my $connstate = &Header::connectionstatus();
56b7a3e2 76
9d386698
AM
77if ( -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;'>";
82 }
f341a168 83}
ac1cfefa 84
957363eb
CS
85if ($cgiparams{'ACTION'} eq $Lang::tr{'dial profile'})
86{
87 my $profile = $cgiparams{'PROFILE'};
88 my %tempcgiparams = ();
89 $tempcgiparams{'PROFILE'} = '';
90 &General::readhash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
91 \%tempcgiparams);
92
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");
9d386698
AM
97 open (TMP, ">${General::swroot}/ppp/updatesettings");
98 close TMP;
957363eb
CS
99 # read in the new params "early" so we can write secrets.
100 %cgiparams = ();
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'}",
105 \%cgiparams);
106
107 # write secrets file.
108 open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
109 flock(FILE, 2);
110 my $username = $cgiparams{'USERNAME'};
111 my $password = $cgiparams{'PASSWORD'};
112 print FILE "'$username' * '$password'\n";
113 chmod 0600, "${General::swroot}/ppp/secrets";
114 close FILE;
115
116 &General::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
117 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
118}
119
120if ($cgiparams{'ACTION'} eq $Lang::tr{'dial'}) {
a56b5be4 121 system('/usr/local/bin/redctrl start > /dev/null') == 0
9d386698
AM
122 or &General::log("Dial failed: $?"); sleep 1;
123}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'hangup'}) {
a56b5be4 124 system('/usr/local/bin/redctrl stop > /dev/null') == 0
9d386698
AM
125 or &General::log("Hangup failed: $?"); sleep 1;
126}
957363eb 127
e383179b
MT
128my $c;
129my $maxprofiles = 5;
130my @profilenames = ();
131
132for ($c = 1; $c <= $maxprofiles; $c++)
133{
134 my %temppppsettings = ();
135 $temppppsettings{'PROFILENAME'} = '';
136 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
137 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
138}
139my %selected;
140for ($c = 1; $c <= $maxprofiles; $c++) {
141 $selected{'PROFILE'}{$c} = '';
142}
143$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
144my $dialButtonDisabled = "disabled='disabled'";
145
ac1cfefa
MT
146&Header::openpage($Lang::tr{'main page'}, 1, $refresh);
147&Header::openbigbox('', 'center');
9d386698
AM
148if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
149 $ipaddr = <IPADDR>;
150 close IPADDR;
151 chomp ($ipaddr);
152 }
ac1cfefa 153
043cfbc0 154&Header::openbox('100%', 'center', '');
a08a5f33 155if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
986e08d9
MT
156 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
157 $ipaddr = <IPADDR>;
158 close IPADDR;
159 chomp ($ipaddr);
160 }
ac1cfefa
MT
161} elsif ($modemsettings{'VALID'} eq 'no') {
162 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
163} else {
164 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
165}
166
a56b5be4 167print <<END;
e383179b 168<!-- Table of networks -->
9d386698 169<table width=80% class='tbl' >
e5d406ab 170 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}</th>
4bf6a597 171 <th bgcolor='$color{'color20'}'>$Lang::tr{'ip address'}</th>
e5d406ab
EK
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>
9d386698 175 <td width='45%' align='center'>$connstate </td></tr>
f3bbb213 176END
043cfbc0
AM
177 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
178 if ( "$HOSTNAME" ne "" ) {
179 print <<END;
2d26c575 180 <tr><td><b>$Lang::tr{'hostname'}:</b><td align='center'>$HOSTNAME</td><td></td>
043cfbc0
AM
181END
182 }
183
9d386698
AM
184 if ( -e "${General::swroot}/red/remote-ipaddress" ) {
185 open (TMP, "<${General::swroot}/red/remote-ipaddress");
186 my $GATEWAY = <TMP>;
043cfbc0 187 chomp($GATEWAY);
9d386698 188 close TMP;
043cfbc0 189 print <<END;
2d26c575 190 <tr><td><b>$Lang::tr{'gateway'}:</b><td align='center'>$GATEWAY</td><td></td></tr>
043cfbc0
AM
191END
192 }
317638e7
MT
193
194 my @dns_servers = ();
195 foreach my $f ("${General::swroot}/red/dns1", "${General::swroot}/red/dns2") {
196 open(DNS, "<$f");
197 my $dns_server = <DNS>;
198 close(DNS);
199
200 chomp($dns_server);
201 if ($dns_server) {
202 push(@dns_servers, $dns_server);
203 }
204 }
205 my $dns_servers_str = join(", ", @dns_servers);
043cfbc0 206
125b6fcd
MT
207 print <<END;
208 <tr>
209 <td>
317638e7 210 <b>$Lang::tr{'dns servers'}:</b>
125b6fcd
MT
211 </td>
212 <td align="center">
317638e7 213 $dns_servers_str
125b6fcd 214 </td>
317638e7 215 <td align="center"></td>
125b6fcd 216 </tr>
043cfbc0
AM
217 </table>
218END
043cfbc0
AM
219
220#Dial profiles
c85ec3b4 221if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
f3bbb213
MT
222print `/usr/local/bin/dialctrl.pl show`;
223print <<END;
043cfbc0
AM
224<br>
225 <table width='80%'>
226 <tr><td>
957363eb 227 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
e383179b
MT
228 <select name='PROFILE'>
229END
230 for ($c = 1; $c <= $maxprofiles; $c++)
231 {
232 if ($profilenames[$c] ne '') {
233 $dialButtonDisabled = "";
234 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
235 }
236 }
c6aa4ac1 237 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
a08a5f33 238 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
e383179b
MT
239 print <<END;
240 </select>
241 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
242 </form>
243 <td align='center'>
244 <table width='100%' border='0'>
245 <tr>
957363eb 246 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
e383179b
MT
247 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
248 </form>
957363eb 249 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
e383179b
MT
250 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
251 </form>
252 </table>
253END
254 } else {
255 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
256 }
043cfbc0 257 print"</tr></table>";
c85ec3b4 258}
043cfbc0
AM
259 if ( $netsettings{'GREEN_DEV'} ) {
260 my $sub=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'});
786f2c8a 261 print <<END;
043cfbc0
AM
262 <br>
263 <table width='80%' class='tbl'>
264 <tr>
265 <th>$Lang::tr{'network'}</th>
4bf6a597 266 <th>$Lang::tr{'ip address'}</th>
043cfbc0
AM
267 <th>$Lang::tr{'status'}</th>
268 </tr>
33e1f48c 269 <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>
043cfbc0
AM
270 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}/$sub
271 <td width='45%' align='center'>
e383179b 272END
9d386698
AM
273 if ( $proxysettings{'ENABLE'} eq 'on' ) {
274 print $Lang::tr{'advproxy on'};
275 if ( $proxysettings{'TRANSPARENT'} eq 'on' ) { print " (transparent)"; }
ef482d53 276 } else { print $Lang::tr{'advproxy off'}; }
072cd997 277 }
043cfbc0
AM
278 if ( $netsettings{'BLUE_DEV'} ) {
279 my $sub=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'});
280 print <<END;
33e1f48c 281 <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>
043cfbc0
AM
282 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}/$sub
283 <td width='45%' align='center'>
e383179b 284END
9d386698
AM
285 if ( $proxysettings{'ENABLE_BLUE'} eq 'on' ) {
286 print $Lang::tr{'advproxy on'};
287 if ( $proxysettings{'TRANSPARENT_BLUE'} eq 'on' ) { print " (transparent)"; }
ef482d53 288 } else { print $Lang::tr{'advproxy off'}; }
072cd997 289 }
043cfbc0
AM
290 if ( $netsettings{'ORANGE_DEV'} ) {
291 my $sub=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'});
292 print <<END;
b161bfa8 293 <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>
043cfbc0
AM
294 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}/$sub
295 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
296END
297 }
298#check if IPSEC is running
9d386698
AM
299if ( $vpnsettings{'ENABLED'} eq 'on' || $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {
300 my $ipsecip = $vpnsettings{'VPN_IP'};
043cfbc0 301print<<END;
f536ab26 302 <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>
043cfbc0
AM
303 <td width='30%' align='center'>$ipsecip
304 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
305END
306}
307
308#check if OpenVPN is running
309my %confighash=();
310&General::readhash("${General::swroot}/ovpn/settings", \%confighash);
311
312if (($confighash{'ENABLED'} eq "on") ||
313 ($confighash{'ENABLED_BLUE'} eq "on") ||
314 ($confighash{'ENABLED_ORANGE'} eq "on")) {
315 my ($ovpnip,$sub) = split("/",$confighash{'DOVPN_SUBNET'});
316 $sub=&General::iporsubtocidr($sub);
317 $ovpnip="$ovpnip/$sub";
043cfbc0
AM
318print <<END;
319 <tr>
320 <td align='center' bgcolor='$Header::colourovpn' width='25%'>
321 <a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN</b></font></a><br>
322 </td>
323 <td width='30%' align='center'>$ovpnip
324 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
e383179b 325END
072cd997 326 }
043cfbc0
AM
327print"</td></tr></table>";
328&Header::closebox();
329
9d386698
AM
330#Check if there are any vpns configured (ipsec and openvpn)
331&General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig);
332foreach my $key (sort { ncmp($vpnconfig{$a}[1],$vpnconfig{$b}[1]) } keys %vpnconfig) {
333 if ($vpnconfig{$key}[0] eq 'on'){
334 $showipsec=1;
335 $showbox=1;
336 last;
337 }
338}
339&General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ovpnconfig);
340foreach my $dkey (sort { ncmp($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
341 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
342 $showbox=1;
343 $showovpn=1;
344 last;
345 }
346}
043cfbc0 347
9d386698
AM
348if ($showbox){
349# Start of Box wich contains all vpn connections
350 &Header::openbox('100%', 'center', $Lang::tr{'vpn'});
043cfbc0 351#show ipsec connectiontable
9d386698
AM
352 if ( $showipsec ) {
353 my $ipsecip = $vpnsettings{'VPN_IP'};
db073a10 354 my @status = `/usr/local/bin/ipsecctrl I`;
e455cafe 355 my %confighash = ();
9d386698
AM
356 my $id = 0;
357 my $gif;
358 my $col="";
359 my $count=0;
072cd997 360 print <<END;
043cfbc0
AM
361 <br>
362 <table width='80%' class='tbl'>
363 <tr>
9d386698
AM
364 <th width='40%'>$Lang::tr{'ipsec network'}</th>
365 <th width='30%'>$Lang::tr{'ip address'}</th>
366 <th width='30%'>$Lang::tr{'status'}</th>
043cfbc0 367 </tr>
e383179b 368END
9d386698
AM
369 foreach my $key (sort { uc($vpnconfig{$a}[1]) cmp uc($vpnconfig{$b}[1]) } keys %vpnconfig) {
370 if ($vpnconfig{$key}[0] eq 'on') {
371 $count++;
372 my ($vpnip,$vpnsub) = split("/",$vpnconfig{$key}[11]);
373 $vpnsub=&General::iporsubtocidr($vpnsub);
374 $vpnip="$vpnip/$vpnsub";
375 if ($count % 2){
376 $col="bgcolor='$color{'color22'}'";
377 }else{
378 $col="bgcolor='$color{'color20'}'";
379 }
380 if ($id % 2) {
381 print "<tr><td align='left' nowrap='nowrap' bgcolor='$Header::colourvpn'><font color=white>$vpnconfig{$key}[1]</td><td align='center' $col>$vpnip</td>";
382 } else {
383 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 }
385 my $active = "<td bgcolor='${Header::colourred}' align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td>";
386 if ($vpnconfig{$key}[0] eq 'off') {
387 $active = "<td bgcolor='${Header::colourblue}' align='center'><b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b></td>";
388 } else {
389 foreach my $line (@status) {
390 if (($line =~ /\"$vpnconfig{$key}[1]\".*IPsec SA established/) || ($line =~/$vpnconfig{$key}[1]\{.*INSTALLED/ )){
391 $active = "<td align='center' bgcolor='${Header::colourgreen}'><b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b></td>";
392 }
393 }
e455cafe 394 }
9d386698 395 print "$active</td>";
e455cafe 396 }
e455cafe 397 }
043cfbc0 398 print "</tr></table>";
072cd997 399 }
4715ddb3
SS
400
401###
402# Check if there is any OpenVPN connection configured.
403###
404
9d386698
AM
405 if ( $showovpn ){
406 print <<END;
407 <br>
408 <table width='80%' class='tbl'>
409 <tr>
410 <th width='40%'>$Lang::tr{'openvpn network'}</th>
411 <th width='30%'>$Lang::tr{'ip address'}</th>
412 <th width='30%'>$Lang::tr{'status'}</th>
4715ddb3 413END
4715ddb3 414
9d386698
AM
415 # Check if the OpenVPN server for Road Warrior Connections is running and display status information.
416 my $active;
417 my $count=0;
418 # Print the OpenVPN N2N connection status.
419 if ( -d "${General::swroot}/ovpn/n2nconf") {
420 my $col="";
421 foreach my $dkey (sort { ncmp ($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
422 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
423 $count++;
424 my $tport = $ovpnconfig{$dkey}[22];
425 next if ($tport eq '');
426 my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport);
427 $tnet->open('127.0.0.1');
428 my @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/');
429 my @tustate = split(/\,/, $output[1]);
430 my $display;
431 my $display_colour = $Header::colourred;
432 if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) {
433 $display_colour = $Header::colourgreen;
434 $display = $Lang::tr{'capsopen'};
435 } else {
436 $display = $tustate[1];
437 }
438 if ($count %2){
439 $col="bgcolor='$color{'color22'}'";
440 }else{
441 $col="bgcolor='$color{'color20'}'";
442 }
443 $active='off';
444 #make cidr from ip
445 my ($vpnip,$vpnsub) = split("/",$ovpnconfig{$dkey}[11]);
446 my $vpnsub=&General::iporsubtocidr($vpnsub);
447 my $vpnip="$vpnip/$vpnsub";
448 print <<END;
449 <tr>
450 <td align='left' nowrap='nowrap' bgcolor='$Header::colourovpn'><font color='white'>$ovpnconfig{$dkey}[1]</font></td>
451 <td align='center' $col>$vpnip</td>
452 <td align='center' bgcolor='$display_colour' ><b><font color='#FFFFFF'>$display</font></b></td>
453 </tr>
54fd0535 454END
9d386698 455 }
4715ddb3 456 }
acb305f5 457 }
9d386698
AM
458 if ($active ne 'off'){
459 print "<tr><td colspan='3' align='center'>$Lang::tr{'ovpn no connections'}</td></tr>";
460 }
461 print"</table>";
acb305f5 462 }
043cfbc0 463&Header::closebox();
9d386698
AM
464}
465
579a39d0
MT
466# Fireinfo
467if ( ! -e "/var/ipfire/main/send_profile") {
468 $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>";
469}
470
ac1cfefa
MT
471# Memory usage warning
472my @free = `/usr/bin/free`;
473$free[1] =~ m/(\d+)/;
474my $mem = $1;
475$free[2] =~ m/(\d+)/;
476my $used = $1;
477my $pct = int 100 * ($mem - $used) / $mem;
478if ($used / $mem > 90) {
479 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
480}
481
482# Diskspace usage warning
483my @temp=();
484my $temp2=();
8955b5a7 485my @df = `/bin/df -B M -P -x rootfs`;
ac1cfefa
MT
486foreach my $line (@df) {
487 next if $line =~ m/^Filesystem/;
488 if ($line =~ m/root/ ) {
489 $line =~ m/^.* (\d+)M.*$/;
490 @temp = split(/ +/,$line);
491 if ($1<5) {
492 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
493 # and root size should not vary during time
62f1526a 494 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
ac1cfefa
MT
495 }
496
497 } else {
498 # $line =~ m/^.* (\d+)m.*$/;
499 $line =~ m/^.* (\d+)\%.*$/;
500 if ($1>90) {
501 @temp = split(/ /,$line);
502 $temp2=int(100-$1);
62f1526a 503 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
ac1cfefa
MT
504 }
505 }
506}
507
c1712013 508# S.M.A.R.T. health warning
73c7eff8 509my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`;
c1712013
AF
510foreach my $file (@files) {
511 chomp ($file);
512 my $disk=`echo $file | cut -d"-" -f2`;
513 chomp ($disk);
514 if (`/bin/grep "SAVE ALL DATA" $file`) {
62f1526a 515 $warnmessage .= "<li> $Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>\n\n";
c1712013
AF
516 }
517}
518
b81b96d2
AF
519# Reiser4 warning
520my @files = `mount | grep " reiser4 (" 2>/dev/null`;
521foreach my $disk (@files) {
522 chomp ($disk);
523 $warnmessage .= "<li>$disk - $Lang::tr{'deprecated fs warn'}</li>\n\n";
524}
525
ac1cfefa 526if ($warnmessage) {
9d386698
AM
527 &Header::openbox('100%','center', );
528 print "<table width='80%' class='tbl'>";
529 print "<tr><th>$Lang::tr{'fwhost hint'}</th></tr>";
02dc0a76 530 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
9d386698 531 &Header::closebox();
ac1cfefa 532}
9d386698
AM
533
534print "<div align='center'>";
2b38ab5c 535&Pakfire::dblist("upgrade", "notice");
f341a168 536if ( -e "/var/run/need_reboot" ) {
7274a673 537 print "<br /><br /><font color='red'>$Lang::tr{'needreboot'}!</font>";
337305ef 538}
7fa7c7dd 539
9d386698 540print "</div>";
7fa7c7dd 541
ac1cfefa 542&Header::closebigbox();
ac1cfefa 543&Header::closepage();