HinzugefĆ¼gt:
[people/pmueller/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
13#use warnings;
14#use CGI::Carp 'fatalsToBrowser';
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
e383179b 70if ( ( $pppsettings{'VALID'} eq 'yes'&& $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
ac1cfefa 71 if ($connstate =~ /$Lang::tr{'connected'}/) {
ac1cfefa
MT
72 if ($ddnssettings{'BEHINDROUTER'} eq 'FETCH_IP') {
73 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
e383179b 74 $ipaddr = <IPADDR>;
ac1cfefa 75 close IPADDR;
e383179b 76 chomp ($ipaddr);
ac1cfefa
MT
77 }
78 }
79 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
80 my $ipaddr = <IPADDR>;
81 close IPADDR;
82 chomp ($ipaddr);
ac1cfefa
MT
83 }
84 }
ac1cfefa
MT
85} elsif ($modemsettings{'VALID'} eq 'no') {
86 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
87} else {
88 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
89}
90
e383179b
MT
91if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
92 $ipaddr = $netsettings{'RED_ADDRESS'};
93}
94
95print <<END;
96<table border='0'>
97<tr>
98 <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}">
99 <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' />
100 </form></td>
101</tr></table>
102
103<!-- Table of networks -->
104<table border='0' width=80%>
e383179b
MT
105 <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'}
106 <th bgcolor='lightgrey'>IP
107 <th bgcolor='lightgrey'>$Lang::tr{'status'}
e383179b 108 <tr> <td bgcolor='$Header::colourred' width='25%'><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font><br>
39a7cc11
MT
109 <td width='30%'>$ipaddr
110 <td width='45%'>$connstate
e383179b
MT
111 <tr><td colspan='2'>
112 <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}:
113 <select name='PROFILE'>
114END
115 for ($c = 1; $c <= $maxprofiles; $c++)
116 {
117 if ($profilenames[$c] ne '') {
118 $dialButtonDisabled = "";
119 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
120 }
121 }
122 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active");
123 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
124 print <<END;
125 </select>
126 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
127 </form>
128 <td align='center'>
129 <table width='100%' border='0'>
130 <tr>
131 <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'>
132 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
133 </form>
134 <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'>
135 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
136 </form>
137 </table>
138END
139 } else {
140 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
141 }
142
072cd997
MT
143 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
144 <tr><td bgcolor='$Header::colourgreen' width='25%'><font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font>
145 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
146 <td width='45%'>
e383179b 147END
072cd997
MT
148 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
149 print "Proxy an";
150 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
151 } else { print "Proxy aus"; }
152 }
153 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
154 <tr><td bgcolor='$Header::colourblue' width='25%'><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font><br>
155 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
156 <td width='45%'>
e383179b 157END
072cd997
MT
158 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
159 print "Proxy an";
160 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
161 } else { print "Proxy aus"; }
162 }
39a7cc11 163 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
072cd997
MT
164 <tr><td bgcolor='$Header::colourorange' width='25%'><font size='2' color='white'><b>$Lang::tr{'dmz'}:</b></font><br>
165 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
166 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 167END
072cd997 168 }
39a7cc11
MT
169 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
170 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
072cd997
MT
171 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
172 print <<END;
173 <tr><td bgcolor='$Header::colourvpn' width='25%'><font size='2' color='white'><b>$Lang::tr{'vpn'}:</b></font><br>
174 <td width='30%'>$ipsecip
175 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 176END
072cd997
MT
177 }
178 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
179 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
180 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
181 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
182 print <<END;
183 <tr><td bgcolor='$Header::colourovpn' width='25%'><font size='2' color='white'><b>OpenVPN:</b></font><br>
184 <td width='30%'>$ovpnip
185 <td width='45%'><font color=$Header::colourgreen>Online</font>
186END
187 }
188 if ( $netsettings{'DNS1'} ) { print <<END;
189 <tr><td>DNS-Server: <td>$netsettings{'DNS1'}
e383179b 190END
072cd997
MT
191 }
192 if ( $netsettings{'DNS2'} ) { print <<END;
193 <td>$netsettings{'DNS2'}
194END
195 }
e383179b
MT
196print <<END;
197</table>
198END
ac1cfefa
MT
199
200# Memory usage warning
201my @free = `/usr/bin/free`;
202$free[1] =~ m/(\d+)/;
203my $mem = $1;
204$free[2] =~ m/(\d+)/;
205my $used = $1;
206my $pct = int 100 * ($mem - $used) / $mem;
207if ($used / $mem > 90) {
208 $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n";
209}
210
211# Diskspace usage warning
212my @temp=();
213my $temp2=();
214my @df = `/bin/df -B M -x rootfs`;
215foreach my $line (@df) {
216 next if $line =~ m/^Filesystem/;
217 if ($line =~ m/root/ ) {
218 $line =~ m/^.* (\d+)M.*$/;
219 @temp = split(/ +/,$line);
220 if ($1<5) {
221 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
222 # and root size should not vary during time
223 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n";
224 }
225
226 } else {
227 # $line =~ m/^.* (\d+)m.*$/;
228 $line =~ m/^.* (\d+)\%.*$/;
229 if ($1>90) {
230 @temp = split(/ /,$line);
231 $temp2=int(100-$1);
232 $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n";
233 }
234 }
235}
236
ac1cfefa 237if ($warnmessage) {
072cd997 238 print "<table border='0'><tr><td align='center' bgcolor=$Header::colourred>$warnmessage</table>";
ac1cfefa
MT
239}
240
ac1cfefa
MT
241&Header::closebox();
242
ac1cfefa
MT
243&Header::closebigbox();
244
245&Header::closepage();