]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | use strict; | |
23 | use Net::Telnet; | |
24 | use Sort::Naturally; | |
25 | ||
26 | # enable only the following on debugging purpose | |
27 | #use warnings; | |
28 | #use CGI::Carp 'fatalsToBrowser'; | |
29 | ||
30 | require '/var/ipfire/general-functions.pl'; | |
31 | require "${General::swroot}/lang.pl"; | |
32 | require "${General::swroot}/header.pl"; | |
33 | require "/opt/pakfire/lib/functions.pl"; | |
34 | ||
35 | my %cgiparams=(); | |
36 | my %pppsettings=(); | |
37 | my %modemsettings=(); | |
38 | my %netsettings=(); | |
39 | my %ddnssettings=(); | |
40 | my %proxysettings=(); | |
41 | my %vpnsettings=(); | |
42 | my %vpnconfig=(); | |
43 | my %ovpnconfig=(); | |
44 | my $warnmessage = ''; | |
45 | my $refresh = ""; | |
46 | my $ipaddr=''; | |
47 | my $showbox=0; | |
48 | my $showipsec=0; | |
49 | my $showovpn=0; | |
50 | ||
51 | if ( ! -e "/var/ipfire/main/gpl_accepted" ) { | |
52 | print "Status: 302 Moved Temporarily\n"; | |
53 | print "Location: gpl.cgi\n\n"; | |
54 | exit (0); | |
55 | } | |
56 | ||
57 | &Header::showhttpheaders(); | |
58 | ||
59 | $cgiparams{'ACTION'} = ''; | |
60 | &Header::getcgihash(\%cgiparams); | |
61 | $pppsettings{'VALID'} = ''; | |
62 | $pppsettings{'PROFILENAME'} = 'None'; | |
63 | &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); | |
64 | &General::readhash("${General::swroot}/modem/settings", \%modemsettings); | |
65 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
66 | &General::readhash("${General::swroot}/ddns/settings", \%ddnssettings); | |
67 | &General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings); | |
68 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); | |
69 | ||
70 | my %color = (); | |
71 | my %mainsettings = (); | |
72 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
73 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
74 | ||
75 | my $connstate = &Header::connectionstatus(); | |
76 | ||
77 | if ( -e "/var/ipfire/main/gpl-accepted" ) { | |
78 | if ($connstate =~ /$Lang::tr{'connecting'}/ || /$Lang::tr{'connection closed'}/ ){ | |
79 | $refresh = "<meta http-equiv='refresh' content='5;'>"; | |
80 | }elsif ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e "${General::swroot}/main/refreshindex") { | |
81 | $refresh = "<meta http-equiv='refresh' content='30;'>"; | |
82 | } | |
83 | } | |
84 | ||
85 | if ($cgiparams{'ACTION'} eq $Lang::tr{'dial profile'}) | |
86 | { | |
87 | my $profile = $cgiparams{'PROFILE'}; | |
88 | my %tempcgiparams = (); | |
89 | $tempcgiparams{'PROFILE'} = ''; | |
90 | &General::readhash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
91 | \%tempcgiparams); | |
92 | ||
93 | # make a link from the selected profile to the "default" one. | |
94 | unlink("${General::swroot}/ppp/settings"); | |
95 | link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
96 | "${General::swroot}/ppp/settings"); | |
97 | open (TMP, ">${General::swroot}/ppp/updatesettings"); | |
98 | close TMP; | |
99 | # read in the new params "early" so we can write secrets. | |
100 | %cgiparams = (); | |
101 | &General::readhash("${General::swroot}/ppp/settings", \%cgiparams); | |
102 | $cgiparams{'PROFILE'} = $profile; | |
103 | $cgiparams{'BACKUPPROFILE'} = $profile; | |
104 | &General::writehash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}", | |
105 | \%cgiparams); | |
106 | ||
107 | # write secrets file. | |
108 | open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file."; | |
109 | flock(FILE, 2); | |
110 | my $username = $cgiparams{'USERNAME'}; | |
111 | my $password = $cgiparams{'PASSWORD'}; | |
112 | print FILE "'$username' * '$password'\n"; | |
113 | chmod 0600, "${General::swroot}/ppp/secrets"; | |
114 | close FILE; | |
115 | ||
116 | &General::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}"); | |
117 | $cgiparams{'ACTION'} = "$Lang::tr{'dial'}"; | |
118 | } | |
119 | ||
120 | if ($cgiparams{'ACTION'} eq $Lang::tr{'dial'}) { | |
121 | system('/usr/local/bin/redctrl start > /dev/null') == 0 | |
122 | or &General::log("Dial failed: $?"); sleep 1; | |
123 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'hangup'}) { | |
124 | system('/usr/local/bin/redctrl stop > /dev/null') == 0 | |
125 | or &General::log("Hangup failed: $?"); sleep 1; | |
126 | } | |
127 | ||
128 | my $c; | |
129 | my $maxprofiles = 5; | |
130 | my @profilenames = (); | |
131 | ||
132 | for ($c = 1; $c <= $maxprofiles; $c++) | |
133 | { | |
134 | my %temppppsettings = (); | |
135 | $temppppsettings{'PROFILENAME'} = ''; | |
136 | &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings); | |
137 | $profilenames[$c] = $temppppsettings{'PROFILENAME'}; | |
138 | } | |
139 | my %selected; | |
140 | for ($c = 1; $c <= $maxprofiles; $c++) { | |
141 | $selected{'PROFILE'}{$c} = ''; | |
142 | } | |
143 | $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'"; | |
144 | my $dialButtonDisabled = "disabled='disabled'"; | |
145 | ||
146 | &Header::openpage($Lang::tr{'main page'}, 1, $refresh); | |
147 | &Header::openbigbox('', 'center'); | |
148 | if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) { | |
149 | $ipaddr = <IPADDR>; | |
150 | close IPADDR; | |
151 | chomp ($ipaddr); | |
152 | } | |
153 | ||
154 | &Header::openbox('100%', 'center', ''); | |
155 | if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) { | |
156 | if (open(IPADDR,"${General::swroot}/ddns/ipcache")) { | |
157 | $ipaddr = <IPADDR>; | |
158 | close IPADDR; | |
159 | chomp ($ipaddr); | |
160 | } | |
161 | if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) { | |
162 | $ipaddr = <IPADDR>; | |
163 | close IPADDR; | |
164 | chomp ($ipaddr); | |
165 | } | |
166 | } elsif ($modemsettings{'VALID'} eq 'no') { | |
167 | print "$Lang::tr{'modem settings have errors'}\n </b></font>\n"; | |
168 | } else { | |
169 | print "$Lang::tr{'profile has errors'}\n </b></font>\n"; | |
170 | } | |
171 | ||
172 | print <<END; | |
173 | <!-- Table of networks --> | |
174 | <table class='tbl' style='width:80%;'> | |
175 | <tr> | |
176 | <th style='background-color:$color{'color20'};'>$Lang::tr{'network'}</th> | |
177 | <th style='background-color:$color{'color20'};'>$Lang::tr{'ip address'}</th> | |
178 | <th style='background-color:$color{'color20'};'>$Lang::tr{'status'}</th> | |
179 | </tr> | |
180 | <tr> | |
181 | <td style='width:25%; text-align:center; background-color:$Header::colourred;'><a href='/cgi-bin/pppsetup.cgi' style='color:white;'><b>$Lang::tr{'internet'}</b></a><br/></td> | |
182 | <td style='width:30%; text-align:center;'>$ipaddr </td> | |
183 | <td style='width:45%; text-align:center;'>$connstate </td> | |
184 | </tr> | |
185 | END | |
186 | my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
187 | if ( "$HOSTNAME" ne "" ) { | |
188 | print <<END; | |
189 | <tr><td><b>$Lang::tr{'hostname'}:</b><td style='text-align:center;'>$HOSTNAME</td><td></td> | |
190 | END | |
191 | } | |
192 | ||
193 | if ( -e "${General::swroot}/red/remote-ipaddress" ) { | |
194 | open (TMP, "<${General::swroot}/red/remote-ipaddress"); | |
195 | my $GATEWAY = <TMP>; | |
196 | chomp($GATEWAY); | |
197 | close TMP; | |
198 | print <<END; | |
199 | <tr><td><b>$Lang::tr{'gateway'}:</b><td style='text-align:center;'>$GATEWAY</td><td></td></tr> | |
200 | END | |
201 | } | |
202 | ||
203 | my @dns_servers = (); | |
204 | foreach my $f ("${General::swroot}/red/dns1", "${General::swroot}/red/dns2") { | |
205 | open(DNS, "<$f"); | |
206 | my $dns_server = <DNS>; | |
207 | close(DNS); | |
208 | ||
209 | chomp($dns_server); | |
210 | if ($dns_server) { | |
211 | push(@dns_servers, $dns_server); | |
212 | } | |
213 | } | |
214 | my $dns_servers_str = join(", ", @dns_servers); | |
215 | ||
216 | print <<END; | |
217 | <tr> | |
218 | <td> | |
219 | <b>$Lang::tr{'dns servers'}:</b> | |
220 | </td> | |
221 | <td style='text-align:center;'> | |
222 | $dns_servers_str | |
223 | </td> | |
224 | <td></td> | |
225 | </tr> | |
226 | </table> | |
227 | END | |
228 | ||
229 | #Dial profiles | |
230 | if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){ | |
231 | if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) { | |
232 | print <<END; | |
233 | <br/> | |
234 | <table style='width:80%;'> | |
235 | <tr><td> | |
236 | <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}: | |
237 | <select name='PROFILE'> | |
238 | END | |
239 | for ($c = 1; $c <= $maxprofiles; $c++) | |
240 | { | |
241 | if ($profilenames[$c] ne '') { | |
242 | $dialButtonDisabled = ""; | |
243 | print "<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>"; | |
244 | } | |
245 | } | |
246 | $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active"); | |
247 | print <<END; | |
248 | </select> | |
249 | <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled /> | |
250 | </form> | |
251 | </td> | |
252 | <td style='text-align:center;'> | |
253 | <table style='width:100%;'> | |
254 | <tr> | |
255 | <td style='width=50%; text-align:right;'> | |
256 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
257 | <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'> | |
258 | </form> | |
259 | </td> | |
260 | <td style='width=50%; text-align:left;'> | |
261 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
262 | <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'> | |
263 | </form> | |
264 | </td> | |
265 | </tr> | |
266 | </table> | |
267 | </td> | |
268 | </tr> | |
269 | </table> | |
270 | END | |
271 | } else { | |
272 | print "<br/><span style='color:red;'>$Lang::tr{'profile has errors'}</span><br/>"; | |
273 | } | |
274 | } | |
275 | ||
276 | ||
277 | print <<END; | |
278 | <br/> | |
279 | <table class='tbl' style='width:80%;'> | |
280 | <tr> | |
281 | <th>$Lang::tr{'network'}</th> | |
282 | <th>$Lang::tr{'ip address'}</th> | |
283 | <th>$Lang::tr{'status'}</th> | |
284 | </tr> | |
285 | END | |
286 | ||
287 | if ( $netsettings{'GREEN_DEV'} ) { | |
288 | my $sub=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'}); | |
289 | print <<END; | |
290 | <tr> | |
291 | <td style='width:25%; text-align:center; background-color:$Header::colourgreen;'> | |
292 | <a href='/cgi-bin/dhcp.cgi' style='color:white'><b>$Lang::tr{'lan'}</b></a> | |
293 | </td> | |
294 | <td style='width:30%; text-align:center;'>$netsettings{'GREEN_ADDRESS'}/$sub</td> | |
295 | <td style='width:45%; text-align:center;'> | |
296 | END | |
297 | if ( $proxysettings{'ENABLE'} eq 'on' ) { | |
298 | print $Lang::tr{'advproxy on'}; | |
299 | if ( $proxysettings{'TRANSPARENT'} eq 'on' ) { print " (transparent)"; } | |
300 | } else { print $Lang::tr{'advproxy off'}; } | |
301 | print '</td>'; | |
302 | print '</tr>'; | |
303 | } | |
304 | if ( $netsettings{'BLUE_DEV'} ) { | |
305 | my $sub=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'}); | |
306 | print <<END; | |
307 | <tr> | |
308 | <td style='width:25%; text-align:center; background-color:$Header::colourblue;'> | |
309 | <a href='/cgi-bin/wireless.cgi' style='color:white'><b>$Lang::tr{'wireless'}</b></a> | |
310 | </td> | |
311 | <td style='width:30%; text-align:center;'>$netsettings{'BLUE_ADDRESS'}/$sub | |
312 | <td style='width:45%; text-align:center;'> | |
313 | END | |
314 | if ( $proxysettings{'ENABLE_BLUE'} eq 'on' ) { | |
315 | print $Lang::tr{'advproxy on'}; | |
316 | if ( $proxysettings{'TRANSPARENT_BLUE'} eq 'on' ) { print " (transparent)"; } | |
317 | } else { print $Lang::tr{'advproxy off'}; } | |
318 | print '</td>'; | |
319 | print '</tr>'; | |
320 | } | |
321 | if ( $netsettings{'ORANGE_DEV'} ) { | |
322 | my $sub=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'}); | |
323 | print <<END; | |
324 | <tr> | |
325 | <td style='width:25%; text-align:center; background-color:$Header::colourorange;'> | |
326 | <a href='/cgi-bin/firewall.cgi' style='color:white'><b>$Lang::tr{'dmz'}</b></a> | |
327 | </td> | |
328 | <td style='width:30%; text-align:center;'>$netsettings{'ORANGE_ADDRESS'}/$sub</td> | |
329 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
330 | </tr> | |
331 | END | |
332 | } | |
333 | #check if IPSEC is running | |
334 | if ( $vpnsettings{'ENABLED'} eq 'on' || $vpnsettings{'ENABLED_BLUE'} eq 'on' ) { | |
335 | my $ipsecip = $vpnsettings{'VPN_IP'}; | |
336 | print<<END; | |
337 | <tr> | |
338 | <td style='width:25%; text-align:center; background-color:$Header::colourvpn;'> | |
339 | <a href='/cgi-bin/vpnmain.cgi' style='color:white'><b>$Lang::tr{'ipsec'}</b></a> | |
340 | </td> | |
341 | <td style='width:30%; text-align:center;'>$ipsecip</td> | |
342 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
343 | </tr> | |
344 | END | |
345 | } | |
346 | ||
347 | #check if OpenVPN is running | |
348 | my %confighash=(); | |
349 | &General::readhash("${General::swroot}/ovpn/settings", \%confighash); | |
350 | ||
351 | if (($confighash{'ENABLED'} eq "on") || | |
352 | ($confighash{'ENABLED_BLUE'} eq "on") || | |
353 | ($confighash{'ENABLED_ORANGE'} eq "on")) { | |
354 | my ($ovpnip,$sub) = split("/",$confighash{'DOVPN_SUBNET'}); | |
355 | $sub=&General::iporsubtocidr($sub); | |
356 | $ovpnip="$ovpnip/$sub"; | |
357 | print <<END; | |
358 | <tr> | |
359 | <td style='width:25%; text-align:center; background-color:$Header::colourovpn;'> | |
360 | <a href='/cgi-bin/ovpnmain.cgi' style='color:white'><b>OpenVPN</b></a> | |
361 | </td> | |
362 | <td style='width:30%; text-align:center;'>$ovpnip</td> | |
363 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
364 | </tr> | |
365 | END | |
366 | } | |
367 | print"</table>"; | |
368 | &Header::closebox(); | |
369 | ||
370 | #Check if there are any vpns configured (ipsec and openvpn) | |
371 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
372 | foreach my $key (sort { ncmp($vpnconfig{$a}[1],$vpnconfig{$b}[1]) } keys %vpnconfig) { | |
373 | if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host'){ | |
374 | $showipsec=1; | |
375 | $showbox=1; | |
376 | last; | |
377 | } | |
378 | } | |
379 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ovpnconfig); | |
380 | foreach my $dkey (sort { ncmp($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) { | |
381 | if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){ | |
382 | $showbox=1; | |
383 | $showovpn=1; | |
384 | last; | |
385 | } | |
386 | } | |
387 | ||
388 | if ($showbox){ | |
389 | # Start of Box wich contains all vpn connections | |
390 | &Header::openbox('100%', 'center', $Lang::tr{'vpn'}); | |
391 | ||
392 | #show ipsec connectiontable | |
393 | if ( $showipsec ) { | |
394 | my $ipsecip = $vpnsettings{'VPN_IP'}; | |
395 | my @status = `/usr/local/bin/ipsecctrl I`; | |
396 | my %confighash = (); | |
397 | my $id = 0; | |
398 | my $gif; | |
399 | my $col=""; | |
400 | my $count=0; | |
401 | print <<END; | |
402 | <table class='tbl' style='width:80%;'> | |
403 | <tr> | |
404 | <th style='width:40%;'>$Lang::tr{'ipsec network'}</th> | |
405 | <th style='width:30%;'>$Lang::tr{'ip address'}</th> | |
406 | <th style='width:30%;'>$Lang::tr{'status'}</th> | |
407 | </tr> | |
408 | END | |
409 | foreach my $key (sort { uc($vpnconfig{$a}[1]) cmp uc($vpnconfig{$b}[1]) } keys %vpnconfig) { | |
410 | if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host') { | |
411 | $count++; | |
412 | my ($vpnip,$vpnsub) = split("/",$vpnconfig{$key}[11]); | |
413 | $vpnsub=&General::iporsubtocidr($vpnsub); | |
414 | $vpnip="$vpnip/$vpnsub"; | |
415 | if ($count % 2){ | |
416 | $col = $color{'color22'}; | |
417 | }else{ | |
418 | $col = $color{'color20'}; | |
419 | } | |
420 | print "<tr>"; | |
421 | print "<td style='text-align:left; color:white; background-color:$Header::colourvpn;'>$vpnconfig{$key}[1]</td>"; | |
422 | print "<td style='text-align:center; background-color:$col'>$vpnip</td>"; | |
423 | ||
424 | my $activecolor = $Header::colourred; | |
425 | my $activestatus = $Lang::tr{'capsclosed'}; | |
426 | if ($vpnconfig{$key}[0] eq 'off') { | |
427 | $activecolor = $Header::colourblue; | |
428 | $activestatus = $Lang::tr{'capsclosed'}; | |
429 | } else { | |
430 | foreach my $line (@status) { | |
431 | if (($line =~ /\"$vpnconfig{$key}[1]\".*IPsec SA established/) || ($line =~/$vpnconfig{$key}[1]\{.*INSTALLED/ )){ | |
432 | $activecolor = $Header::colourgreen; | |
433 | $activestatus = $Lang::tr{'capsopen'}; | |
434 | } | |
435 | } | |
436 | } | |
437 | print "<td style='text-align:center; color:white; background-color:$activecolor;'><b>$activestatus</b></td>"; | |
438 | print "</tr>"; | |
439 | } | |
440 | } | |
441 | print "</table>"; | |
442 | } | |
443 | ||
444 | # Check if there is any OpenVPN connection configured. | |
445 | if ( $showovpn ){ | |
446 | print <<END; | |
447 | <br/> | |
448 | <table class='tbl' style='width:80%;'> | |
449 | <tr> | |
450 | <th style='width:40%;'>$Lang::tr{'openvpn network'}</th> | |
451 | <th style='width:30%;'>$Lang::tr{'ip address'}</th> | |
452 | <th style='width:30%;'>$Lang::tr{'status'}</th> | |
453 | END | |
454 | ||
455 | # Check if the OpenVPN server for Road Warrior Connections is running and display status information. | |
456 | my $active; | |
457 | my $count=0; | |
458 | # Print the OpenVPN N2N connection status. | |
459 | if ( -d "${General::swroot}/ovpn/n2nconf") { | |
460 | my $col=""; | |
461 | foreach my $dkey (sort { ncmp ($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) { | |
462 | if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){ | |
463 | $count++; | |
464 | my $tport = $ovpnconfig{$dkey}[22]; | |
465 | next if ($tport eq ''); | |
466 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
467 | $tnet->open('127.0.0.1'); | |
468 | my @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
469 | my @tustate = split(/\,/, $output[1]); | |
470 | my $display; | |
471 | my $display_colour = $Header::colourred; | |
472 | if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) { | |
473 | $display_colour = $Header::colourgreen; | |
474 | $display = $Lang::tr{'capsopen'}; | |
475 | } else { | |
476 | $display = $tustate[1]; | |
477 | } | |
478 | if ($count %2){ | |
479 | $col = $color{'color22'}; | |
480 | }else{ | |
481 | $col = $color{'color20'}; | |
482 | } | |
483 | $active='off'; | |
484 | #make cidr from ip | |
485 | my ($vpnip,$vpnsub) = split("/",$ovpnconfig{$dkey}[11]); | |
486 | my $vpnsub=&General::iporsubtocidr($vpnsub); | |
487 | my $vpnip="$vpnip/$vpnsub"; | |
488 | print <<END; | |
489 | <tr> | |
490 | <td style='text-align:left; color:white; background-color:$Header::colourovpn;'>$ovpnconfig{$dkey}[1]</td> | |
491 | <td style='text-align:center; background-color:$col'>$vpnip</td> | |
492 | <td style='text-align:center; color:white; background-color:$display_colour' ><b>$display</b></td> | |
493 | </tr> | |
494 | END | |
495 | } | |
496 | } | |
497 | } | |
498 | if ($active ne 'off'){ | |
499 | print "<tr><td colspan='3' style='text-align:center;'>$Lang::tr{'ovpn no connections'}</td></tr>"; | |
500 | } | |
501 | print"</table>"; | |
502 | } | |
503 | &Header::closebox(); | |
504 | } | |
505 | ||
506 | # Fireinfo | |
507 | if ( ! -e "/var/ipfire/main/send_profile") { | |
508 | $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>"; | |
509 | } | |
510 | ||
511 | # Memory usage warning | |
512 | my @free = `/usr/bin/free`; | |
513 | $free[1] =~ m/(\d+)/; | |
514 | my $mem = $1; | |
515 | $free[2] =~ m/(\d+)/; | |
516 | my $used = $1; | |
517 | my $pct = int 100 * ($mem - $used) / $mem; | |
518 | if ($used / $mem > 90) { | |
519 | $warnmessage .= "<li>$Lang::tr{'high memory usage'}: $pct% !</li>"; | |
520 | } | |
521 | ||
522 | # Diskspace usage warning | |
523 | my @temp=(); | |
524 | my $temp2=(); | |
525 | my @df = `/bin/df -B M -P -x rootfs`; | |
526 | foreach my $line (@df) { | |
527 | next if $line =~ m/^Filesystem/; | |
528 | if ($line =~ m/root/ ) { | |
529 | $line =~ m/^.* (\d+)M.*$/; | |
530 | @temp = split(/ +/,$line); | |
531 | if ($1<5) { | |
532 | # available:plain value in MB, and not %used as 10% is too much to waste on small disk | |
533 | # and root size should not vary during time | |
534 | $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>"; | |
535 | } | |
536 | ||
537 | } else { | |
538 | # $line =~ m/^.* (\d+)m.*$/; | |
539 | $line =~ m/^.* (\d+)\%.*$/; | |
540 | if ($1>90) { | |
541 | @temp = split(/ /,$line); | |
542 | $temp2=int(100-$1); | |
543 | $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>"; | |
544 | } | |
545 | } | |
546 | } | |
547 | ||
548 | # S.M.A.R.T. health warning | |
549 | my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`; | |
550 | foreach my $file (@files) { | |
551 | chomp ($file); | |
552 | my $disk=`echo $file | cut -d"-" -f2`; | |
553 | chomp ($disk); | |
554 | if (`/bin/grep "SAVE ALL DATA" $file`) { | |
555 | $warnmessage .= "<li>$Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>"; | |
556 | } | |
557 | } | |
558 | ||
559 | # Reiser4 warning | |
560 | my @files = `mount | grep " reiser4 (" 2>/dev/null`; | |
561 | foreach my $disk (@files) { | |
562 | chomp ($disk); | |
563 | $warnmessage .= "<li>$disk - $Lang::tr{'deprecated fs warn'}</li>"; | |
564 | } | |
565 | ||
566 | if ($warnmessage) { | |
567 | &Header::openbox('100%','center', ); | |
568 | print "<table class='tbl' style='width:80%;'>"; | |
569 | print "<tr><th>$Lang::tr{'fwhost hint'}</th></tr>"; | |
570 | print "<tr><td style='color:white; background-color:$Header::colourred;'>$warnmessage</td></tr>"; | |
571 | print "</table>"; | |
572 | &Header::closebox(); | |
573 | } | |
574 | ||
575 | &Pakfire::dblist("upgrade", "notice"); | |
576 | if ( -e "/var/run/need_reboot" ) { | |
577 | print "<div style='text-align:center; color:red;'>"; | |
578 | print "<br/><br/>$Lang::tr{'needreboot'}!"; | |
579 | print "</div>"; | |
580 | } | |
581 | ||
582 | &Header::closebigbox(); | |
583 | &Header::closepage(); | |
584 |