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