]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/index.cgi
HinzugefĆ¼gt:
[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%>
105 <!-- Headline -->
106 <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'}
107 <th bgcolor='lightgrey'>IP
108 <th bgcolor='lightgrey'>$Lang::tr{'status'}
109 <!-- RED -->
110 <tr> <td bgcolor='$Header::colourred' width='25%'><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font><br>
111 <td width='30%'>$ipaddr <td width='45%'>$connstate
112 <tr><td colspan='2'>
113 <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}:
114 <select name='PROFILE'>
115END
116 for ($c = 1; $c <= $maxprofiles; $c++)
117 {
118 if ($profilenames[$c] ne '') {
119 $dialButtonDisabled = "";
120 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
121 }
122 }
123 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active");
124 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
125 print <<END;
126 </select>
127 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
128 </form>
129 <td align='center'>
130 <table width='100%' border='0'>
131 <tr>
132 <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'>
133 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
134 </form>
135 <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'>
136 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
137 </form>
138 </table>
139END
140 } else {
141 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
142 }
143
072cd997
MT
144 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
145 <tr><td bgcolor='$Header::colourgreen' width='25%'><font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font>
146 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
147 <td width='45%'>
e383179b 148END
072cd997
MT
149 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
150 print "Proxy an";
151 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
152 } else { print "Proxy aus"; }
153 }
154 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
155 <tr><td bgcolor='$Header::colourblue' width='25%'><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font><br>
156 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
157 <td width='45%'>
e383179b 158END
072cd997
MT
159 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
160 print "Proxy an";
161 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
162 } else { print "Proxy aus"; }
163 }
164 if (`ifconfig | grep $netsettings{'ORANGE_DEV'}`) { print <<END;
165 <tr><td bgcolor='$Header::colourorange' width='25%'><font size='2' color='white'><b>$Lang::tr{'dmz'}:</b></font><br>
166 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
167 <td width='45%'><font color=$Header::colourgreen>Online</font>
e383179b 168END
072cd997
MT
169 }
170 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ) {
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();