]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/index.cgi
Festplattenerkennung ueberarbeitet.
[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
40my $connstate = &Header::connectionstatus();
41if ($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
e383179b
MT
47my $c;
48my $maxprofiles = 5;
49my @profilenames = ();
50
51for ($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}
58my %selected;
59for ($c = 1; $c <= $maxprofiles; $c++) {
60 $selected{'PROFILE'}{$c} = '';
61}
62$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
63my $dialButtonDisabled = "disabled='disabled'";
64
65
ac1cfefa
MT
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
986e08d9
MT
70if ( ( $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")) {
786f2c8a 77 $ipaddr = <IPADDR>;
986e08d9
MT
78 close IPADDR;
79 chomp ($ipaddr);
80 }
ac1cfefa
MT
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
e383179b
MT
87if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
88 $ipaddr = $netsettings{'RED_ADDRESS'};
89}
90
91print <<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%>
e383179b
MT
101 <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'}
102 <th bgcolor='lightgrey'>IP
103 <th bgcolor='lightgrey'>$Lang::tr{'status'}
e455cafe 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>
39a7cc11
MT
105 <td width='30%'>$ipaddr
106 <td width='45%'>$connstate
e383179b
MT
107 <tr><td colspan='2'>
108 <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}:
109 <select name='PROFILE'>
110END
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 }
c6aa4ac1 118 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
e383179b
MT
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>
134END
135 } else {
136 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
137 }
138
786f2c8a
MT
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;
143END
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;
151END
152 }
153
c6aa4ac1
MT
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
161END
162 }
163 if ( $DNS2 ) { print <<END;
164 <td>$DNS2
165END
166 } else { print <<END;
167 <td>&nbsp;
168END
169 }
170
072cd997 171 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
e455cafe 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>
072cd997
MT
173 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
174 <td width='45%'>
e383179b 175END
072cd997
MT
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;
e455cafe 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>
072cd997
MT
183 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
184 <td width='45%'>
e383179b 185END
072cd997
MT
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 }
39a7cc11 191 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
e455cafe 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>
072cd997
MT
193 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
194 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 195END
072cd997 196 }
39a7cc11
MT
197 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
198 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
072cd997 199 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
e455cafe
MT
200 my @status = `/usr/sbin/ipsec auto --status`;
201 my %confighash = ();
202 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
072cd997 203 print <<END;
e455cafe 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>
072cd997
MT
205 <td width='30%'>$ipsecip
206 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 207END
e455cafe
MT
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 }
072cd997
MT
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;
e455cafe 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>
072cd997
MT
238 <td width='30%'>$ovpnip
239 <td width='45%'><font color=$Header::colourgreen>Online</font>
240END
241 }
ac1cfefa
MT
242
243# Memory usage warning
244my @free = `/usr/bin/free`;
245$free[1] =~ m/(\d+)/;
246my $mem = $1;
247$free[2] =~ m/(\d+)/;
248my $used = $1;
249my $pct = int 100 * ($mem - $used) / $mem;
250if ($used / $mem > 90) {
251 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
252}
253
254# Diskspace usage warning
255my @temp=();
256my $temp2=();
257my @df = `/bin/df -B M -x rootfs`;
258foreach 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
02dc0a76 266 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
ac1cfefa
MT
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);
02dc0a76 275 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
ac1cfefa
MT
276 }
277 }
278}
279
ac1cfefa 280if ($warnmessage) {
02dc0a76 281 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
ac1cfefa 282}
02dc0a76
MT
283print <<END;
284</table>
285END
ac1cfefa
MT
286&Header::closebox();
287
ac1cfefa
MT
288&Header::closebigbox();
289
290&Header::closepage();