]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/index.cgi
Kernel-Config gefixt.
[people/pmueller/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#
ac1cfefa
MT
9
10use strict;
11
12# enable only the following on debugging purpose
786f2c8a
MT
13use warnings;
14use CGI::Carp 'fatalsToBrowser';
ac1cfefa 15
e383179b 16require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
17require "${General::swroot}/lang.pl";
18require "${General::swroot}/header.pl";
19
20my %cgiparams=();
21my %pppsettings=();
22my %modemsettings=();
23my %netsettings=();
24my %ddnssettings=();
25my $warnmessage = '';
26my $refresh = '';
e383179b 27my $ipaddr='';
ac1cfefa
MT
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
f2fdd0c1
CS
40my %color = ();
41my %mainsettings = ();
42&General::readhash("${General::swroot}/main/settings", \%mainsettings);
43&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
44
ac1cfefa
MT
45my $connstate = &Header::connectionstatus();
46if ($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;'>";
50}
51
957363eb
CS
52if ($cgiparams{'ACTION'} eq $Lang::tr{'dial profile'})
53{
54 my $profile = $cgiparams{'PROFILE'};
55 my %tempcgiparams = ();
56 $tempcgiparams{'PROFILE'} = '';
57 &General::readhash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
58 \%tempcgiparams);
59
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");
65
66 # read in the new params "early" so we can write secrets.
67 %cgiparams = ();
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'}",
72 \%cgiparams);
73
74 # write secrets file.
75 open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
76 flock(FILE, 2);
77 my $username = $cgiparams{'USERNAME'};
78 my $password = $cgiparams{'PASSWORD'};
79 print FILE "'$username' * '$password'\n";
80 chmod 0600, "${General::swroot}/ppp/secrets";
81 close FILE;
82
83 &General::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
84 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
85}
86
87if ($cgiparams{'ACTION'} eq $Lang::tr{'dial'}) {
88 system('/usr/local/bin/redctrl','start') == 0
89 or &General::log("Dial failed: $?"); sleep 1;}
90elsif ($cgiparams{'ACTION'} eq $Lang::tr{'hangup'}) {
91 system('/usr/local/bin/redctrl','stop') == 0
92 or &General::log("Hangup failed: $?"); sleep 1;}
93
e383179b
MT
94my $c;
95my $maxprofiles = 5;
96my @profilenames = ();
97
98for ($c = 1; $c <= $maxprofiles; $c++)
99{
100 my %temppppsettings = ();
101 $temppppsettings{'PROFILENAME'} = '';
102 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
103 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
104}
105my %selected;
106for ($c = 1; $c <= $maxprofiles; $c++) {
107 $selected{'PROFILE'}{$c} = '';
108}
109$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
110my $dialButtonDisabled = "disabled='disabled'";
111
112
ac1cfefa
MT
113&Header::openpage($Lang::tr{'main page'}, 1, $refresh);
114&Header::openbigbox('', 'center');
115&Header::openbox('100%', 'center', &Header::cleanhtml(`/bin/uname -n`,"y"));
116
a08a5f33 117if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
986e08d9
MT
118 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
119 $ipaddr = <IPADDR>;
120 close IPADDR;
121 chomp ($ipaddr);
122 }
123 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
786f2c8a 124 $ipaddr = <IPADDR>;
986e08d9
MT
125 close IPADDR;
126 chomp ($ipaddr);
127 }
ac1cfefa
MT
128} elsif ($modemsettings{'VALID'} eq 'no') {
129 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
130} else {
131 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
132}
133
e383179b
MT
134if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
135 $ipaddr = $netsettings{'RED_ADDRESS'};
136}
137
138print <<END;
139<table border='0'>
140<tr>
141 <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}">
142 <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' />
143 </form></td>
144</tr></table>
145
146<!-- Table of networks -->
147<table border='0' width=80%>
f2fdd0c1
CS
148 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}
149 <th bgcolor='$color{'color20'}'>IP
150 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}
e455cafe 151 <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>
39a7cc11
MT
152 <td width='30%'>$ipaddr
153 <td width='45%'>$connstate
f3bbb213
MT
154END
155print `/usr/local/bin/dialctrl.pl show`;
156print <<END;
e383179b 157 <tr><td colspan='2'>
957363eb 158 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
e383179b
MT
159 <select name='PROFILE'>
160END
161 for ($c = 1; $c <= $maxprofiles; $c++)
162 {
163 if ($profilenames[$c] ne '') {
164 $dialButtonDisabled = "";
165 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
166 }
167 }
c6aa4ac1 168 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
a08a5f33 169 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
e383179b
MT
170 print <<END;
171 </select>
172 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
173 </form>
174 <td align='center'>
175 <table width='100%' border='0'>
176 <tr>
957363eb 177 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
e383179b
MT
178 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
179 </form>
957363eb 180 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
e383179b
MT
181 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
182 </form>
183 </table>
184END
185 } else {
186 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
187 }
188
786f2c8a
MT
189 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
190 if ( "$HOSTNAME" ne "" ) {
191 print <<END;
192 <tr><td><b>Hostname:</b><td>$HOSTNAME<td>&nbsp;
193END
194 }
195
196 if ( -e "/var/ipfire/red/remote-ipaddress" ) {
197 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
198 chomp($GATEWAY);
199 print <<END;
200 <tr><td><b>Gateway:</b><td>$GATEWAY<td>&nbsp;
201END
202 }
203
c6aa4ac1
MT
204 my $DNS1 = `cat /var/ipfire/red/dns1`;
205 my $DNS2 = `cat /var/ipfire/red/dns2`;
206 chomp($DNS1);
207 chomp($DNS1);
208
209 if ( $DNS1 ) { print <<END;
210 <tr><td><b>DNS-Server:</b><td>$DNS1
211END
212 }
213 if ( $DNS2 ) { print <<END;
214 <td>$DNS2
215END
216 } else { print <<END;
217 <td>&nbsp;
218END
219 }
220
072cd997 221 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
e455cafe 222 <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>
072cd997
MT
223 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
224 <td width='45%'>
e383179b 225END
072cd997
MT
226 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
227 print "Proxy an";
228 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
229 } else { print "Proxy aus"; }
230 }
231 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
e455cafe 232 <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>
072cd997
MT
233 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
234 <td width='45%'>
e383179b 235END
072cd997
MT
236 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
237 print "Proxy an";
238 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
239 } else { print "Proxy aus"; }
240 }
39a7cc11 241 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
e455cafe 242 <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>
072cd997
MT
243 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
244 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 245END
072cd997 246 }
39a7cc11
MT
247 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
248 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
072cd997 249 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
e455cafe
MT
250 my @status = `/usr/sbin/ipsec auto --status`;
251 my %confighash = ();
252 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
072cd997 253 print <<END;
e455cafe 254 <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>
072cd997
MT
255 <td width='30%'>$ipsecip
256 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 257END
e455cafe
MT
258 my $id = 0;
259 my $gif;
260 foreach my $key (keys %confighash) {
261 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
262
263 if ($id % 2) {
264 print "<tr bgcolor='${Header::table1colour}'>\n";
265 } else {
266 print "<tr bgcolor='${Header::table2colour}'>\n";
267 }
268 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>";
269 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>";
270 if ($confighash{$key}[0] eq 'off') {
271 $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>";
272 } else {
273 foreach my $line (@status) {
274 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
f2fdd0c1 275 $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>";
e455cafe
MT
276 }
277 }
278 }
279 print "<td align='center'>$active</td>";
280 }
072cd997
MT
281 }
282 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
283 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
284 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
285 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
286 print <<END;
e455cafe 287 <tr><td bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN:</b></font></a><br>
072cd997
MT
288 <td width='30%'>$ovpnip
289 <td width='45%'><font color=$Header::colourgreen>Online</font>
290END
291 }
ac1cfefa
MT
292
293# Memory usage warning
294my @free = `/usr/bin/free`;
295$free[1] =~ m/(\d+)/;
296my $mem = $1;
297$free[2] =~ m/(\d+)/;
298my $used = $1;
299my $pct = int 100 * ($mem - $used) / $mem;
300if ($used / $mem > 90) {
301 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
302}
303
304# Diskspace usage warning
305my @temp=();
306my $temp2=();
307my @df = `/bin/df -B M -x rootfs`;
308foreach my $line (@df) {
309 next if $line =~ m/^Filesystem/;
310 if ($line =~ m/root/ ) {
311 $line =~ m/^.* (\d+)M.*$/;
312 @temp = split(/ +/,$line);
313 if ($1<5) {
314 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
315 # and root size should not vary during time
02dc0a76 316 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
ac1cfefa
MT
317 }
318
319 } else {
320 # $line =~ m/^.* (\d+)m.*$/;
321 $line =~ m/^.* (\d+)\%.*$/;
322 if ($1>90) {
323 @temp = split(/ /,$line);
324 $temp2=int(100-$1);
02dc0a76 325 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
ac1cfefa
MT
326 }
327 }
328}
329
ac1cfefa 330if ($warnmessage) {
02dc0a76 331 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
ac1cfefa 332}
02dc0a76
MT
333print <<END;
334</table>
f3bbb213 335
02dc0a76 336END
f3bbb213 337
d81292e0
CS
338require "${General::swroot}/net-traffic/net-traffic-admin.pl";
339
340if($NETTRAFF::settings{'SHOW_AT_HOME'} eq 'on')
341{
342 my %calc = ();
343 $calc{'CALC_VOLUME_TOTAL'} = 0;
344 $calc{'CALC_VOLUME_IN'} = 0;
345 $calc{'CALC_VOLUME_OUT'} = 0;
346 $calc{'CALC_WEEK_TOTAL'} = 0;
347 $calc{'CALC_WEEK_IN'} = 0;
348 $calc{'CALC_WEEK_OUT'} = 0;
349 $calc{'CALC_LAST_RUN'} = 0;
350 $calc{'CALC_PERCENT'} = 0;
351
352 &General::readhash($NETTRAFF::logfile, \%calc);
353
354 my $calctime = &NETTRAFF::getFormatedDate($calc{'CALC_LAST_RUN'});
355
356 print <<END;
357 <hr /><br />
358
359 <table width='80%'>
360 <tr>
361 <td colspan='4' align='center' nowrap='nowrap' >$Lang::tr{'traffic monitor'} ($Lang::tr{'traffic calc time'} $calctime)</td>
362 </tr>
363 <tr>
364 <td align='center' nowrap='nowrap' > </td>
365 <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>
366 <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>
367 <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficsum'}</b></font></td>
368 </tr>
369 <tr>
370 <td align='center' nowrap='nowrap' >$Lang::tr{'this weeks volume'} (MB):</td>
371 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_IN'}</td>
372 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_OUT'}</td>
373 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_TOTAL'}</td>
374 </tr>
375 <tr>
376 <td align='center' nowrap='nowrap' >$Lang::tr{'this months volume'} (MB):</td>
377 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_IN'}</td>
378 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_OUT'}</td>
379 <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_TOTAL'}</td>
380 </tr>
381END
382
383 if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
384 {
385print "<tr><td align='center'>max. $NETTRAFF::settings{'MONTHLY_VOLUME'} MB</td><td align='left' colspan='3' nowrap='nowrap'>";
386&NETTRAFF::traffPercentbar("$calc{'CALC_PERCENT'}%");
387print "</td><td align='left' nowrap='nowrap'>&nbsp; $calc{'CALC_PERCENT'}%</td></tr>";
388 }
389 print "</table>";
390}
391
ac1cfefa
MT
392&Header::closebox();
393
ac1cfefa
MT
394&Header::closebigbox();
395
396&Header::closepage();