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