Firewallhitgraphs gefixt.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / index.cgi
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
10 use strict;
11
12 # enable only the following on debugging purpose
13 use warnings;
14 use CGI::Carp 'fatalsToBrowser';
15
16 require '/var/ipfire/general-functions.pl';
17 require "${General::swroot}/lang.pl";
18 require "${General::swroot}/header.pl";
19
20 my %cgiparams=();
21 my %pppsettings=();
22 my %modemsettings=();
23 my %netsettings=();
24 my %ddnssettings=();
25 my $warnmessage = '';
26 my $refresh = '';
27 my $ipaddr='';
28
29 &Header::showhttpheaders();
30
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);
39
40 my $connstate = &Header::connectionstatus();
41 if ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e "${General::swroot}/main/refreshindex") {
42 $refresh = "<meta http-equiv='refresh' content='30;'>";
43 } elsif ($connstate =~ /$Lang::tr{'connecting'}/) {
44 $refresh = "<meta http-equiv='refresh' content='5;'>";
45 }
46
47 my $c;
48 my $maxprofiles = 5;
49 my @profilenames = ();
50
51 for ($c = 1; $c <= $maxprofiles; $c++)
52 {
53 my %temppppsettings = ();
54 $temppppsettings{'PROFILENAME'} = '';
55 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
56 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
57 }
58 my %selected;
59 for ($c = 1; $c <= $maxprofiles; $c++) {
60 $selected{'PROFILE'}{$c} = '';
61 }
62 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
63 my $dialButtonDisabled = "disabled='disabled'";
64
65
66 &Header::openpage($Lang::tr{'main page'}, 1, $refresh);
67 &Header::openbigbox('', 'center');
68 &Header::openbox('100%', 'center', &Header::cleanhtml(`/bin/uname -n`,"y"));
69
70 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
71 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
72 $ipaddr = <IPADDR>;
73 close IPADDR;
74 chomp ($ipaddr);
75 }
76 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
77 $ipaddr = <IPADDR>;
78 close IPADDR;
79 chomp ($ipaddr);
80 }
81 } elsif ($modemsettings{'VALID'} eq 'no') {
82 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
83 } else {
84 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
85 }
86
87 if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
88 $ipaddr = $netsettings{'RED_ADDRESS'};
89 }
90
91 print <<END;
92 <table border='0'>
93 <tr>
94 <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}">
95 <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' />
96 </form></td>
97 </tr></table>
98
99 <!-- Table of networks -->
100 <table border='0' width=80%>
101 <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'}
102 <th bgcolor='lightgrey'>IP
103 <th bgcolor='lightgrey'>$Lang::tr{'status'}
104 <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>
105 <td width='30%'>$ipaddr
106 <td width='45%'>$connstate
107 <tr><td colspan='2'>
108 <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}:
109 <select name='PROFILE'>
110 END
111 for ($c = 1; $c <= $maxprofiles; $c++)
112 {
113 if ($profilenames[$c] ne '') {
114 $dialButtonDisabled = "";
115 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
116 }
117 }
118 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
119 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
120 print <<END;
121 </select>
122 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
123 </form>
124 <td align='center'>
125 <table width='100%' border='0'>
126 <tr>
127 <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'>
128 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
129 </form>
130 <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'>
131 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
132 </form>
133 </table>
134 END
135 } else {
136 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
137 }
138
139 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
140 if ( "$HOSTNAME" ne "" ) {
141 print <<END;
142 <tr><td><b>Hostname:</b><td>$HOSTNAME<td>&nbsp;
143 END
144 }
145
146 if ( -e "/var/ipfire/red/remote-ipaddress" ) {
147 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
148 chomp($GATEWAY);
149 print <<END;
150 <tr><td><b>Gateway:</b><td>$GATEWAY<td>&nbsp;
151 END
152 }
153
154 my $DNS1 = `cat /var/ipfire/red/dns1`;
155 my $DNS2 = `cat /var/ipfire/red/dns2`;
156 chomp($DNS1);
157 chomp($DNS1);
158
159 if ( $DNS1 ) { print <<END;
160 <tr><td><b>DNS-Server:</b><td>$DNS1
161 END
162 }
163 if ( $DNS2 ) { print <<END;
164 <td>$DNS2
165 END
166 } else { print <<END;
167 <td>&nbsp;
168 END
169 }
170
171 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
172 <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>
173 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
174 <td width='45%'>
175 END
176 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
177 print "Proxy an";
178 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
179 } else { print "Proxy aus"; }
180 }
181 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
182 <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>
183 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
184 <td width='45%'>
185 END
186 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
187 print "Proxy an";
188 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
189 } else { print "Proxy aus"; }
190 }
191 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
192 <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>
193 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
194 <td width='45%'><font color=$Header::colourgreen>Online</font>
195 END
196 }
197 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
198 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
199 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
200 my @status = `/usr/sbin/ipsec auto --status`;
201 my %confighash = ();
202 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
203 print <<END;
204 <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>
205 <td width='30%'>$ipsecip
206 <td width='45%'><font color=$Header::colourgreen>Online</font>
207 END
208 my $id = 0;
209 my $gif;
210 foreach my $key (keys %confighash) {
211 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
212
213 if ($id % 2) {
214 print "<tr bgcolor='${Header::table1colour}'>\n";
215 } else {
216 print "<tr bgcolor='${Header::table2colour}'>\n";
217 }
218 print "<td bgcolor='#ffffff'>&nbsp;</td><td align='center' nowrap='nowrap'>$confighash{$key}[1] / " . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>";
219 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>";
220 if ($confighash{$key}[0] eq 'off') {
221 $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>";
222 } else {
223 foreach my $line (@status) {
224 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
225 $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>";
226 }
227 }
228 }
229 print "<td align='center'>$active</td>";
230 }
231 }
232 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
233 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
234 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
235 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
236 print <<END;
237 <tr><td bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN:</b></font></a><br>
238 <td width='30%'>$ovpnip
239 <td width='45%'><font color=$Header::colourgreen>Online</font>
240 END
241 }
242
243 # Memory usage warning
244 my @free = `/usr/bin/free`;
245 $free[1] =~ m/(\d+)/;
246 my $mem = $1;
247 $free[2] =~ m/(\d+)/;
248 my $used = $1;
249 my $pct = int 100 * ($mem - $used) / $mem;
250 if ($used / $mem > 90) {
251 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
252 }
253
254 # Diskspace usage warning
255 my @temp=();
256 my $temp2=();
257 my @df = `/bin/df -B M -x rootfs`;
258 foreach my $line (@df) {
259 next if $line =~ m/^Filesystem/;
260 if ($line =~ m/root/ ) {
261 $line =~ m/^.* (\d+)M.*$/;
262 @temp = split(/ +/,$line);
263 if ($1<5) {
264 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
265 # and root size should not vary during time
266 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
267 }
268
269 } else {
270 # $line =~ m/^.* (\d+)m.*$/;
271 $line =~ m/^.* (\d+)\%.*$/;
272 if ($1>90) {
273 @temp = split(/ /,$line);
274 $temp2=int(100-$1);
275 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
276 }
277 }
278 }
279
280 if ($warnmessage) {
281 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
282 }
283 print <<END;
284 </table>
285 END
286 &Header::closebox();
287
288 &Header::closebigbox();
289
290 &Header::closepage();