]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/index.cgi
Zeitanzeige fuer PPP-Verbindungen...
[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 END
108 print `/usr/local/bin/dialctrl.pl show`;
109 print <<END;
110 <tr><td colspan='2'>
111 <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}:
112 <select name='PROFILE'>
113 END
114 for ($c = 1; $c <= $maxprofiles; $c++)
115 {
116 if ($profilenames[$c] ne '') {
117 $dialButtonDisabled = "";
118 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
119 }
120 }
121 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active");
122 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
123 print <<END;
124 </select>
125 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
126 </form>
127 <td align='center'>
128 <table width='100%' border='0'>
129 <tr>
130 <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'>
131 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
132 </form>
133 <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'>
134 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
135 </form>
136 </table>
137 END
138 } else {
139 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
140 }
141
142 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
143 if ( "$HOSTNAME" ne "" ) {
144 print <<END;
145 <tr><td><b>Hostname:</b><td>$HOSTNAME<td>&nbsp;
146 END
147 }
148
149 if ( -e "/var/ipfire/red/remote-ipaddress" ) {
150 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress`;
151 chomp($GATEWAY);
152 print <<END;
153 <tr><td><b>Gateway:</b><td>$GATEWAY<td>&nbsp;
154 END
155 }
156
157 my $DNS1 = `cat /var/ipfire/red/dns1`;
158 my $DNS2 = `cat /var/ipfire/red/dns2`;
159 chomp($DNS1);
160 chomp($DNS1);
161
162 if ( $DNS1 ) { print <<END;
163 <tr><td><b>DNS-Server:</b><td>$DNS1
164 END
165 }
166 if ( $DNS2 ) { print <<END;
167 <td>$DNS2
168 END
169 } else { print <<END;
170 <td>&nbsp;
171 END
172 }
173
174 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
175 <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>
176 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
177 <td width='45%'>
178 END
179 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
180 print "Proxy an";
181 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
182 } else { print "Proxy aus"; }
183 }
184 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
185 <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>
186 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
187 <td width='45%'>
188 END
189 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
190 print "Proxy an";
191 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
192 } else { print "Proxy aus"; }
193 }
194 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
195 <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>
196 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
197 <td width='45%'><font color=$Header::colourgreen>Online</font>
198 END
199 }
200 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
201 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
202 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
203 my @status = `/usr/sbin/ipsec auto --status`;
204 my %confighash = ();
205 &General::readhasharray("${General::swroot}/vpn/config", \%confighash);
206 print <<END;
207 <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>
208 <td width='30%'>$ipsecip
209 <td width='45%'><font color=$Header::colourgreen>Online</font>
210 END
211 my $id = 0;
212 my $gif;
213 foreach my $key (keys %confighash) {
214 if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
215
216 if ($id % 2) {
217 print "<tr bgcolor='${Header::table1colour}'>\n";
218 } else {
219 print "<tr bgcolor='${Header::table2colour}'>\n";
220 }
221 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>";
222 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>";
223 if ($confighash{$key}[0] eq 'off') {
224 $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>";
225 } else {
226 foreach my $line (@status) {
227 if ($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) {
228 $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>";
229 }
230 }
231 }
232 print "<td align='center'>$active</td>";
233 }
234 }
235 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
236 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
237 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
238 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
239 print <<END;
240 <tr><td bgcolor='$Header::colourovpn' width='25%'><a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN:</b></font></a><br>
241 <td width='30%'>$ovpnip
242 <td width='45%'><font color=$Header::colourgreen>Online</font>
243 END
244 }
245
246 # Memory usage warning
247 my @free = `/usr/bin/free`;
248 $free[1] =~ m/(\d+)/;
249 my $mem = $1;
250 $free[2] =~ m/(\d+)/;
251 my $used = $1;
252 my $pct = int 100 * ($mem - $used) / $mem;
253 if ($used / $mem > 90) {
254 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
255 }
256
257 # Diskspace usage warning
258 my @temp=();
259 my $temp2=();
260 my @df = `/bin/df -B M -x rootfs`;
261 foreach my $line (@df) {
262 next if $line =~ m/^Filesystem/;
263 if ($line =~ m/root/ ) {
264 $line =~ m/^.* (\d+)M.*$/;
265 @temp = split(/ +/,$line);
266 if ($1<5) {
267 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
268 # and root size should not vary during time
269 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n";
270 }
271
272 } else {
273 # $line =~ m/^.* (\d+)m.*$/;
274 $line =~ m/^.* (\d+)\%.*$/;
275 if ($1>90) {
276 @temp = split(/ /,$line);
277 $temp2=int(100-$1);
278 $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n";
279 }
280 }
281 }
282
283 if ($warnmessage) {
284 print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>";
285 }
286 print <<END;
287 </table>
288
289 END
290
291 &Header::closebox();
292
293 &Header::closebigbox();
294
295 &Header::closepage();