]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - html/cgi-bin/index.cgi
Pakfire laedt die Listen jetzt besser und hat eine veraenderte Oberflaeche bekommen.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / index.cgi
... / ...
CommitLineData
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
10use strict;
11
12# enable only the following on debugging purpose
13#use warnings;
14#use CGI::Carp 'fatalsToBrowser';
15
16require '/var/ipfire/general-functions.pl';
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 = "";
27my $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
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
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
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 > /dev/null') == 0
89 or &General::log("Dial failed: $?"); sleep 1;}
90elsif ($cgiparams{'ACTION'} eq $Lang::tr{'hangup'}) {
91 system('/usr/local/bin/redctrl stop > /dev/null') == 0
92 or &General::log("Hangup failed: $?"); sleep 1;}
93
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
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
117
118
119if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
120 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
121 $ipaddr = <IPADDR>;
122 close IPADDR;
123 chomp ($ipaddr);
124 }
125 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
126 $ipaddr = <IPADDR>;
127 close IPADDR;
128 chomp ($ipaddr);
129 }
130} elsif ($modemsettings{'VALID'} eq 'no') {
131 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
132} else {
133 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
134}
135
136#if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
137# $ipaddr = $netsettings{'RED_ADDRESS'};
138#}
139
140my $death = 0;
141my $rebirth = 0;
142
143if ($cgiparams{'ACTION'} eq $Lang::tr{'shutdown'}) {
144 $death = 1;
145 &General::log($Lang::tr{'shutting down ipfire'});
146 system '/usr/local/bin/ipfirereboot down';
147} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reboot'}) {
148 $rebirth = 1;
149 &General::log($Lang::tr{'rebooting ipfire'});
150 system '/usr/local/bin/ipfirereboot boot';
151}
152
153if ($death == 0 && $rebirth == 0) {
154
155print <<END
156<form method='post' action='$ENV{'SCRIPT_NAME'}'>
157<table width='100%'>
158<tr>
159 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
160 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /></td>
161 <td width='33%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
162</tr>
163</table>
164END
165;
166print <<END;
167
168<!-- Table of networks -->
169<table border='0' width=80%>
170 <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'}
171 <th bgcolor='$color{'color20'}'>IP
172 <th bgcolor='$color{'color20'}'>$Lang::tr{'status'}
173 <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>
174 <td width='30%' align='center'>$ipaddr
175 <td width='45%' align='center'>$connstate
176END
177if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
178print `/usr/local/bin/dialctrl.pl show`;
179print <<END;
180 <tr><td colspan='2'>
181 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
182 <select name='PROFILE'>
183END
184 for ($c = 1; $c <= $maxprofiles; $c++)
185 {
186 if ($profilenames[$c] ne '') {
187 $dialButtonDisabled = "";
188 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
189 }
190 }
191 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
192 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
193 print <<END;
194 </select>
195 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
196 </form>
197 <td align='center'>
198 <table width='100%' border='0'>
199 <tr>
200 <td width='50%' align='right'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
201 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
202 </form>
203 <td width='50%' align='left'> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
204 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
205 </form>
206 </table>
207END
208 } else {
209 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
210 }
211}
212 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
213 if ( "$HOSTNAME" ne "" ) {
214 print <<END;
215 <tr><td><b>Hostname:</b><td align='center'>$HOSTNAME<td>&nbsp;
216END
217 }
218
219 if ( -e "/var/ipfire/red/remote-ipaddress" ) {
220 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
221 chomp($GATEWAY);
222 print <<END;
223 <tr><td><b>Gateway:</b><td align='center'>$GATEWAY<td>&nbsp;
224END
225 }
226
227 my $DNS1 = `cat /var/ipfire/red/dns1`;
228 my $DNS2 = `cat /var/ipfire/red/dns2`;
229 chomp($DNS1);
230 chomp($DNS1);
231
232 if ( $DNS1 ) { print <<END;
233 <tr><td><b>DNS-Server:</b><td align='center'>$DNS1
234END
235 }
236 if ( $DNS2 ) { print <<END;
237 <td align='center'>$DNS2
238END
239 } else { print <<END;
240 <td>&nbsp;
241END
242 }
243
244 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
245 <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>
246 <td width='30%' align='center'>$netsettings{'GREEN_ADDRESS'}
247 <td width='45%' align='center'>
248END
249 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
250 print "Proxy an";
251 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
252 } else { print "Proxy aus"; }
253 }
254 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
255 <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>
256 <td width='30%' align='center'>$netsettings{'BLUE_ADDRESS'}
257 <td width='45%' align='center'>
258END
259 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
260 print "Proxy an";
261 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
262 } else { print "Proxy aus"; }
263 }
264 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
265 <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>
266 <td width='30%' align='center'>$netsettings{'ORANGE_ADDRESS'}
267 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
268END
269 }
270 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
271 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
272 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
273 my @status = `/usr/sbin/ipsec auto --status`;
274 my %confighash = ();
275 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
276 print <<END;
277 <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>
278 <td width='30%' align='center'>$ipsecip
279 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
280END
281 my $id = 0;
282 my $gif;
283 foreach my $key (keys %confighash) {
284 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
285
286 if ($id % 2) {
287 print "<tr><td align='center'>&nbsp;</td><td align='center' nowrap='nowrap' bgcolor='$color{'color20'}'>$confighash{$key}[1] / " . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>";
288 } else {
289 print "<tr><td align='center'>&nbsp;</td><td align='center' nowrap='nowrap' bgcolor='$color{'color22'}'>$confighash{$key}[1] / " . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>";
290 }
291
292 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>";
293 if ($confighash{$key}[0] eq 'off') {
294 $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>";
295 } else {
296 foreach my $line (@status) {
297 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
298 $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>";
299 }
300 }
301 }
302 print "<td align='center'>$active</td>";
303 }
304 }
305 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
306 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
307 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
308 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
309 print <<END;
310 <tr><td bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN:</b></font></a><br>
311 <td width='30%' align='center'>$ovpnip
312 <td width='45%' align='center'><font color=$Header::colourgreen>Online</font>
313END
314 }
315
316# Memory usage warning
317my @free = `/usr/bin/free`;
318$free[1] =~ m/(\d+)/;
319my $mem = $1;
320$free[2] =~ m/(\d+)/;
321my $used = $1;
322my $pct = int 100 * ($mem - $used) / $mem;
323if ($used / $mem > 90) {
324 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
325}
326
327# Diskspace usage warning
328my @temp=();
329my $temp2=();
330my @df = `/bin/df -B M -x rootfs`;
331foreach my $line (@df) {
332 next if $line =~ m/^Filesystem/;
333 if ($line =~ m/root/ ) {
334 $line =~ m/^.* (\d+)M.*$/;
335 @temp = split(/ +/,$line);
336 if ($1<5) {
337 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
338 # and root size should not vary during time
339 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
340 }
341
342 } else {
343 # $line =~ m/^.* (\d+)m.*$/;
344 $line =~ m/^.* (\d+)\%.*$/;
345 if ($1>90) {
346 @temp = split(/ /,$line);
347 $temp2=int(100-$1);
348 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
349 }
350 }
351}
352
353if ($warnmessage) {
354 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
355}
356print <<END;
357</table>
358
359END
360} else {
361 my $message='';
362 if ($death) {
363 $message = $Lang::tr{'ipfire has now shutdown'};
364 } else {
365 $message = $Lang::tr{'ipfire has now rebooted'};
366 }
367 print <<END
368<div align='center'>
369<table width='100%' bgcolor='#ffffff'>
370<tr><td align='center'>
371<br /><br /><img src='/images/IPFire.png' /><br /><br /><br />
372</td></tr>
373</table>
374<br />
375<font size='6'>$message</font>
376</div>
377END
378;
379}
380&Header::closebox();
381&Header::closebigbox();
382&Header::closepage();