]>
Commit | Line | Data |
---|---|---|
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 | |
10 | use strict; | |
11 | ||
12 | # enable only the following on debugging purpose | |
786f2c8a MT |
13 | use warnings; |
14 | use CGI::Carp 'fatalsToBrowser'; | |
ac1cfefa | 15 | |
e383179b | 16 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
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 = ''; | |
e383179b | 27 | my $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 | ||
f2fdd0c1 CS |
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 | ||
ac1cfefa MT |
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 | ||
e383179b MT |
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 | ||
ac1cfefa MT |
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 | ||
a08a5f33 | 75 | if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) { |
986e08d9 MT |
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")) { | |
786f2c8a | 82 | $ipaddr = <IPADDR>; |
986e08d9 MT |
83 | close IPADDR; |
84 | chomp ($ipaddr); | |
85 | } | |
ac1cfefa MT |
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 | ||
e383179b MT |
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%> | |
f2fdd0c1 CS |
106 | <tr> <th bgcolor='$color{'color20'}'>$Lang::tr{'network'} |
107 | <th bgcolor='$color{'color20'}'>IP | |
108 | <th bgcolor='$color{'color20'}'>$Lang::tr{'status'} | |
e455cafe | 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> |
39a7cc11 MT |
110 | <td width='30%'>$ipaddr |
111 | <td width='45%'>$connstate | |
f3bbb213 MT |
112 | END |
113 | print `/usr/local/bin/dialctrl.pl show`; | |
114 | print <<END; | |
e383179b MT |
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 | } | |
c6aa4ac1 | 126 | $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active"); |
a08a5f33 | 127 | if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) { |
e383179b MT |
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 | ||
786f2c8a MT |
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> | |
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> | |
159 | END | |
160 | } | |
161 | ||
c6aa4ac1 MT |
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> | |
176 | END | |
177 | } | |
178 | ||
072cd997 | 179 | if ( $netsettings{'GREEN_DEV'} ) { print <<END; |
e455cafe | 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> |
072cd997 MT |
181 | <td width='30%'>$netsettings{'GREEN_ADDRESS'} |
182 | <td width='45%'> | |
e383179b | 183 | END |
072cd997 MT |
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; | |
e455cafe | 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> |
072cd997 MT |
191 | <td width='30%'>$netsettings{'BLUE_ADDRESS'} |
192 | <td width='45%'> | |
e383179b | 193 | END |
072cd997 MT |
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 | } | |
39a7cc11 | 199 | if ( $netsettings{'ORANGE_DEV'} ) { print <<END; |
e455cafe | 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> |
072cd997 MT |
201 | <td width='30%'>$netsettings{'ORANGE_ADDRESS'} |
202 | <td width='45%'><font color=$Header::colourgreen>Online</font> | |
e383179b | 203 | END |
072cd997 | 204 | } |
39a7cc11 MT |
205 | if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` || |
206 | `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) { | |
072cd997 | 207 | my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`; |
e455cafe MT |
208 | my @status = `/usr/sbin/ipsec auto --status`; |
209 | my %confighash = (); | |
210 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
072cd997 | 211 | print <<END; |
e455cafe | 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> |
072cd997 MT |
213 | <td width='30%'>$ipsecip |
214 | <td width='45%'><font color=$Header::colourgreen>Online</font> | |
e383179b | 215 | END |
e455cafe MT |
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'> </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/) { | |
f2fdd0c1 | 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>"; |
e455cafe MT |
234 | } |
235 | } | |
236 | } | |
237 | print "<td align='center'>$active</td>"; | |
238 | } | |
072cd997 MT |
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; | |
e455cafe | 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> |
072cd997 MT |
246 | <td width='30%'>$ovpnip |
247 | <td width='45%'><font color=$Header::colourgreen>Online</font> | |
248 | END | |
249 | } | |
ac1cfefa MT |
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 | |
02dc0a76 | 274 | $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !\n"; |
ac1cfefa MT |
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); | |
02dc0a76 | 283 | $warnmessage .= "$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !\n"; |
ac1cfefa MT |
284 | } |
285 | } | |
286 | } | |
287 | ||
ac1cfefa | 288 | if ($warnmessage) { |
02dc0a76 | 289 | print "<tr><td align='center' bgcolor=$Header::colourred colspan='3'><font color='white'>$warnmessage</font></table>"; |
ac1cfefa | 290 | } |
02dc0a76 MT |
291 | print <<END; |
292 | </table> | |
f3bbb213 | 293 | |
02dc0a76 | 294 | END |
f3bbb213 | 295 | |
d81292e0 CS |
296 | require "${General::swroot}/net-traffic/net-traffic-admin.pl"; |
297 | ||
298 | if($NETTRAFF::settings{'SHOW_AT_HOME'} eq 'on') | |
299 | { | |
300 | my %calc = (); | |
301 | $calc{'CALC_VOLUME_TOTAL'} = 0; | |
302 | $calc{'CALC_VOLUME_IN'} = 0; | |
303 | $calc{'CALC_VOLUME_OUT'} = 0; | |
304 | $calc{'CALC_WEEK_TOTAL'} = 0; | |
305 | $calc{'CALC_WEEK_IN'} = 0; | |
306 | $calc{'CALC_WEEK_OUT'} = 0; | |
307 | $calc{'CALC_LAST_RUN'} = 0; | |
308 | $calc{'CALC_PERCENT'} = 0; | |
309 | ||
310 | &General::readhash($NETTRAFF::logfile, \%calc); | |
311 | ||
312 | my $calctime = &NETTRAFF::getFormatedDate($calc{'CALC_LAST_RUN'}); | |
313 | ||
314 | print <<END; | |
315 | <hr /><br /> | |
316 | ||
317 | <table width='80%'> | |
318 | <tr> | |
319 | <td colspan='4' align='center' nowrap='nowrap' >$Lang::tr{'traffic monitor'} ($Lang::tr{'traffic calc time'} $calctime)</td> | |
320 | </tr> | |
321 | <tr> | |
322 | <td align='center' nowrap='nowrap' > </td> | |
323 | <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td> | |
324 | <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td> | |
325 | <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficsum'}</b></font></td> | |
326 | </tr> | |
327 | <tr> | |
328 | <td align='center' nowrap='nowrap' >$Lang::tr{'this weeks volume'} (MB):</td> | |
329 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_IN'}</td> | |
330 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_OUT'}</td> | |
331 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_TOTAL'}</td> | |
332 | </tr> | |
333 | <tr> | |
334 | <td align='center' nowrap='nowrap' >$Lang::tr{'this months volume'} (MB):</td> | |
335 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_IN'}</td> | |
336 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_OUT'}</td> | |
337 | <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_TOTAL'}</td> | |
338 | </tr> | |
339 | END | |
340 | ||
341 | if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on') | |
342 | { | |
343 | print "<tr><td align='center'>max. $NETTRAFF::settings{'MONTHLY_VOLUME'} MB</td><td align='left' colspan='3' nowrap='nowrap'>"; | |
344 | &NETTRAFF::traffPercentbar("$calc{'CALC_PERCENT'}%"); | |
345 | print "</td><td align='left' nowrap='nowrap'> $calc{'CALC_PERCENT'}%</td></tr>"; | |
346 | } | |
347 | print "</table>"; | |
348 | } | |
349 | ||
ac1cfefa MT |
350 | &Header::closebox(); |
351 | ||
ac1cfefa MT |
352 | &Header::closebigbox(); |
353 | ||
354 | &Header::closepage(); |