]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/index.cgi
BUILDFIXES:
[ipfire-2.x.git] / html / cgi-bin / index.cgi
CommitLineData
ac1cfefa
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9# $Id: index.cgi,v 1.15.2.18 2005/09/17 13:51:47 gespinasse Exp $
10#
11
12use strict;
13
14# enable only the following on debugging purpose
15#use warnings;
16#use CGI::Carp 'fatalsToBrowser';
17
18require 'CONFIG_ROOT/general-functions.pl';
19require "${General::swroot}/lang.pl";
20require "${General::swroot}/header.pl";
21
22my %cgiparams=();
23my %pppsettings=();
24my %modemsettings=();
25my %netsettings=();
26my %ddnssettings=();
27my $warnmessage = '';
28my $refresh = '';
29
30&Header::showhttpheaders();
31
32$cgiparams{'ACTION'} = '';
33&Header::getcgihash(\%cgiparams);
34$pppsettings{'VALID'} = '';
35$pppsettings{'PROFILENAME'} = 'None';
36&General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
37&General::readhash("${General::swroot}/modem/settings", \%modemsettings);
38&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
39&General::readhash("${General::swroot}/ddns/settings", \%ddnssettings);
40
41my $connstate = &Header::connectionstatus();
42if ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e "${General::swroot}/main/refreshindex") {
43 $refresh = "<meta http-equiv='refresh' content='30;'>";
44} elsif ($connstate =~ /$Lang::tr{'connecting'}/) {
45 $refresh = "<meta http-equiv='refresh' content='5;'>";
46}
47
48&Header::openpage($Lang::tr{'main page'}, 1, $refresh);
49&Header::openbigbox('', 'center');
50&Header::openbox('100%', 'center', &Header::cleanhtml(`/bin/uname -n`,"y"));
51
52# hide buttons only when pppsettings mandatory used and not valid
53if ( ( $pppsettings{'VALID'} eq 'yes' ) ||
54 ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
55 print <<END
56 <table border='0'>
57 <tr>
58 <td align='center'><form method='post' action='/cgi-bin/dial.cgi'>
59 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}' />
60 </form></td>
61 <td>&nbsp;&nbsp;</td>
62 <td align='center'><form method='post' action='/cgi-bin/dial.cgi'>
63 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}' />
64 </form></td>
65 <td>&nbsp;&nbsp;</td>
66 <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}">
67 <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' />
68 </form></td>
69 </tr></table>
70END
71 ;
72}
73
74print "<font face='Helvetica' size='4'><b>";
75if ( !( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
76 print "<u>$Lang::tr{'current profile'} $pppsettings{'PROFILENAME'}</u><br />\n";
77}
78
79if ( ( $pppsettings{'VALID'} eq 'yes'&& $modemsettings{'VALID'} eq 'yes' ) ||
80 ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
81 print $connstate;
82 print "</b></font>\n";
83 if ($connstate =~ /$Lang::tr{'connected'}/) {
84 my $fetch_ip='nothing';
85 if ($ddnssettings{'BEHINDROUTER'} eq 'FETCH_IP') {
86 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
87 $fetch_ip = <IPADDR>;
88 close IPADDR;
89 chomp ($fetch_ip);
90 my $host_name = (gethostbyaddr(pack("C4", split(/\./, $fetch_ip)), 2))[0];
91 print "<br />$Lang::tr{'ip address'} (internet): $fetch_ip <br /> $Lang::tr{'ipcops hostname'} (internet): $host_name <br />";
92 }
93 }
94 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
95 my $ipaddr = <IPADDR>;
96 close IPADDR;
97 chomp ($ipaddr);
98 if ($ipaddr ne $fetch_ip){ #do not show info twice
99 my $host_name = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
100 print "<br />$Lang::tr{'ip address'}: $ipaddr <br /> $Lang::tr{'ipcops hostname'}: $host_name <br />";
101 }
102 }
103 }
104
105} elsif ($modemsettings{'VALID'} eq 'no') {
106 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
107} else {
108 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
109}
110
111
112# Memory usage warning
113my @free = `/usr/bin/free`;
114$free[1] =~ m/(\d+)/;
115my $mem = $1;
116$free[2] =~ m/(\d+)/;
117my $used = $1;
118my $pct = int 100 * ($mem - $used) / $mem;
119if ($used / $mem > 90) {
120 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
121}
122
123# Diskspace usage warning
124my @temp=();
125my $temp2=();
126my @df = `/bin/df -B M -x rootfs`;
127foreach my $line (@df) {
128 next if $line =~ m/^Filesystem/;
129 if ($line =~ m/root/ ) {
130 $line =~ m/^.* (\d+)M.*$/;
131 @temp = split(/ +/,$line);
132 if ($1<5) {
133 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
134 # and root size should not vary during time
135 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
136 }
137
138 } else {
139 # $line =~ m/^.* (\d+)m.*$/;
140 $line =~ m/^.* (\d+)\%.*$/;
141 if ($1>90) {
142 @temp = split(/ /,$line);
143 $temp2=int(100-$1);
144 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
145 }
146 }
147}
148
149# Patches warning
150open(AV, "<${General::swroot}/patches/available") or die "Could not open available patches database ($!)";
151my @av = <AV>;
152close(AV);
153open(PF, "<${General::swroot}/patches/installed") or die "Could not open installed patches file. ($!)<br />";
154while(<PF>)
155{
156 next if $_ =~ m/^#/;
157 @temp = split(/\|/,$_);
158 @av = grep(!/^$temp[0]/, @av);
159}
160close(PF);
161
162if ($#av != -1)
163{
164 $warnmessage .= "<li> $Lang::tr{'there are updates'}</li>";
165}
166my $age = &General::age("/${General::swroot}/patches/available");
167if ($age =~ m/(\d{1,3})d/) {
168 if ($1 >= 7) {
169 $warnmessage .= "<li>$Lang::tr{'updates is old1'} $age $Lang::tr{'updates is old2'}</li>\n";
170 }
171}
172
173if ($warnmessage) {
174 print "<ol>$warnmessage</ol>";
175}
176
177print "<p>";
178system('/usr/bin/uptime');
179print "</p>\n";
180
181&Header::closebox();
182
10a04d70
MT
183&Header::openbox('100%', 'left', $Lang::tr{'quick control'});
184# read in the profile names into @profilenames.
185my $c;
186my $maxprofiles = 5;
187my @profilenames = ();
188
189for ($c = 1; $c <= $maxprofiles; $c++)
190{
191 my %temppppsettings = ();
192 $temppppsettings{'PROFILENAME'} = '';
193 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
194 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
195}
196my %selected;
197for ($c = 1; $c <= $maxprofiles; $c++) {
198 $selected{'PROFILE'}{$c} = '';
ac1cfefa 199}
10a04d70
MT
200$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
201
202print <<END;
203 <table width='100%'>
204 <tr>
205 <td align='left'>
206 <form method='post' action='/cgi-bin/dial.cgi'>
207 $Lang::tr{'profile'}:
208 <select name='PROFILE'>
ac1cfefa 209END
10a04d70
MT
210my $dialButtonDisabled = "disabled='disabled'";
211for ($c = 1; $c <= $maxprofiles; $c++)
212{
213 if ($profilenames[$c] ne '') {
214 $dialButtonDisabled = "";
215 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
216 }
ac1cfefa 217}
10a04d70
MT
218$dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active");
219
220print <<END;
221 </select>
222 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
223 </form>
224 </td>
225 <td align='right'>
226 <form method='post' action='/cgi-bin/shutdown.cgi'>
227 <input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' />
228 </form>
229 </td>
230 </tr>
231 </table>
232END
233&Header::closebox();
ac1cfefa
MT
234
235&Header::closebigbox();
236
237&Header::closepage();