]>
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 | if ( -e "${General::swroot}/red/dns" ) { | |
205 | open (TMP, "<${General::swroot}/red/dns"); | |
206 | $dns_servers = <TMP>; | |
207 | chomp($dns_servers); | |
208 | close TMP; | |
209 | } | |
210 | print <<END; | |
211 | <tr> | |
212 | <td> | |
213 | <b>$Lang::tr{'dns servers'}:</b> | |
214 | </td> | |
215 | <td style='text-align:center;'> | |
216 | $dns_servers | |
217 | </td> | |
218 | <td></td> | |
219 | </tr> | |
220 | END | |
221 | ||
222 | if (&General::RedIsWireless()) { | |
223 | my $iface = $netsettings{"RED_DEV"} || "red0"; | |
224 | ||
225 | my $essid = &Network::wifi_get_essid($iface); | |
226 | my $frequency = &Network::wifi_get_frequency($iface); | |
227 | my $access_point = &Network::wifi_get_access_point($iface); | |
228 | my $bit_rate = &Network::wifi_get_bit_rate($iface); | |
229 | my $link_quality = &Network::wifi_get_link_quality($iface); | |
230 | my $signal_level = &Network::wifi_get_signal_level($iface); | |
231 | ||
232 | print <<END; | |
233 | <tr> | |
234 | <td> | |
235 | <strong>$Lang::tr{'wireless network'}:</strong> | |
236 | </td> | |
237 | <td style="text-align: center"> | |
238 | $essid | |
239 | </td> | |
240 | <td style="text-align: center"> | |
241 | $access_point @ $frequency | |
242 | </td> | |
243 | </tr> | |
244 | <tr> | |
245 | <td> | |
246 | <strong> | |
247 | $Lang::tr{'uplink bit rate'}: | |
248 | </strong> | |
249 | </td> | |
250 | <td style="text-align: center"> | |
251 | $bit_rate | |
252 | </td> | |
253 | <td style="text-align: center"> | |
254 | $link_quality% @ $signal_level | |
255 | </td> | |
256 | </tr> | |
257 | END | |
258 | } | |
259 | ||
260 | print <<END; | |
261 | </table> | |
262 | END | |
263 | ||
264 | #Dial profiles | |
265 | if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){ | |
266 | if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) { | |
267 | print <<END; | |
268 | <br/> | |
269 | <table style='width:80%;'> | |
270 | <tr><td> | |
271 | <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}: | |
272 | <select name='PROFILE'> | |
273 | END | |
274 | for ($c = 1; $c <= $maxprofiles; $c++) | |
275 | { | |
276 | if ($profilenames[$c] ne '') { | |
277 | $dialButtonDisabled = ""; | |
278 | print "<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>"; | |
279 | } | |
280 | } | |
281 | $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipfire.pid' || -e "${General::swroot}/red/active"); | |
282 | print <<END; | |
283 | </select> | |
284 | <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled /> | |
285 | </form> | |
286 | </td> | |
287 | <td style='text-align:center;'> | |
288 | <table style='width:100%;'> | |
289 | <tr> | |
290 | <td style='width=50%; text-align:right;'> | |
291 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
292 | <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'> | |
293 | </form> | |
294 | </td> | |
295 | <td style='width=50%; text-align:left;'> | |
296 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
297 | <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'> | |
298 | </form> | |
299 | </td> | |
300 | </tr> | |
301 | </table> | |
302 | </td> | |
303 | </tr> | |
304 | </table> | |
305 | END | |
306 | } else { | |
307 | print "<br/><span style='color:red;'>$Lang::tr{'profile has errors'}</span><br/>"; | |
308 | } | |
309 | } | |
310 | ||
311 | ||
312 | print <<END; | |
313 | <br/> | |
314 | <table class='tbl' style='width:80%;'> | |
315 | <tr> | |
316 | <th>$Lang::tr{'network'}</th> | |
317 | <th>$Lang::tr{'ip address'}</th> | |
318 | <th>$Lang::tr{'status'}</th> | |
319 | </tr> | |
320 | END | |
321 | ||
322 | if ( $netsettings{'GREEN_DEV'} ) { | |
323 | my $sub=&General::iporsubtocidr($netsettings{'GREEN_NETMASK'}); | |
324 | print <<END; | |
325 | <tr> | |
326 | <td style='width:25%; text-align:center; background-color:$Header::colourgreen;'> | |
327 | <a href='/cgi-bin/dhcp.cgi' style='color:white'><b>$Lang::tr{'lan'}</b></a> | |
328 | </td> | |
329 | <td style='width:30%; text-align:center;'>$netsettings{'GREEN_ADDRESS'}/$sub</td> | |
330 | <td style='width:45%; text-align:center;'> | |
331 | END | |
332 | if ( $proxysettings{'ENABLE'} eq 'on' ) { | |
333 | print $Lang::tr{'advproxy on'}; | |
334 | if ( $proxysettings{'TRANSPARENT'} eq 'on' ) { print " (transparent)"; } | |
335 | } else { print $Lang::tr{'advproxy off'}; } | |
336 | print '</td>'; | |
337 | print '</tr>'; | |
338 | } | |
339 | if (&Header::blue_used()) { | |
340 | my $sub=&General::iporsubtocidr($netsettings{'BLUE_NETMASK'}); | |
341 | print <<END; | |
342 | <tr> | |
343 | <td style='width:25%; text-align:center; background-color:$Header::colourblue;'> | |
344 | <a href='/cgi-bin/wireless.cgi' style='color:white'><b>$Lang::tr{'wireless'}</b></a> | |
345 | </td> | |
346 | <td style='width:30%; text-align:center;'>$netsettings{'BLUE_ADDRESS'}/$sub | |
347 | <td style='width:45%; text-align:center;'> | |
348 | END | |
349 | if ( $proxysettings{'ENABLE_BLUE'} eq 'on' ) { | |
350 | print $Lang::tr{'advproxy on'}; | |
351 | if ( $proxysettings{'TRANSPARENT_BLUE'} eq 'on' ) { print " (transparent)"; } | |
352 | } else { print $Lang::tr{'advproxy off'}; } | |
353 | print '</td>'; | |
354 | print '</tr>'; | |
355 | } | |
356 | if (&Header::orange_used()) { | |
357 | my $sub=&General::iporsubtocidr($netsettings{'ORANGE_NETMASK'}); | |
358 | print <<END; | |
359 | <tr> | |
360 | <td style='width:25%; text-align:center; background-color:$Header::colourorange;'> | |
361 | <a href='/cgi-bin/firewall.cgi' style='color:white'><b>$Lang::tr{'dmz'}</b></a> | |
362 | </td> | |
363 | <td style='width:30%; text-align:center;'>$netsettings{'ORANGE_ADDRESS'}/$sub</td> | |
364 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
365 | </tr> | |
366 | END | |
367 | } | |
368 | #check if IPSEC is running | |
369 | if ( $vpnsettings{'ENABLED'} eq 'on' || $vpnsettings{'ENABLED_BLUE'} eq 'on' ) { | |
370 | my $ipsecip = $vpnsettings{'VPN_IP'}; | |
371 | print<<END; | |
372 | <tr> | |
373 | <td style='width:25%; text-align:center; background-color:$Header::colourvpn;'> | |
374 | <a href='/cgi-bin/vpnmain.cgi' style='color:white'><b>$Lang::tr{'ipsec'}</b></a> | |
375 | </td> | |
376 | <td style='width:30%; text-align:center;'>$ipsecip</td> | |
377 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
378 | </tr> | |
379 | END | |
380 | } | |
381 | ||
382 | #check if OpenVPN is running | |
383 | my %confighash=(); | |
384 | &General::readhash("${General::swroot}/ovpn/settings", \%confighash); | |
385 | ||
386 | if (($confighash{'ENABLED'} eq "on") || | |
387 | ($confighash{'ENABLED_BLUE'} eq "on") || | |
388 | ($confighash{'ENABLED_ORANGE'} eq "on")) { | |
389 | my ($ovpnip,$sub) = split("/",$confighash{'DOVPN_SUBNET'}); | |
390 | $sub=&General::iporsubtocidr($sub); | |
391 | $ovpnip="$ovpnip/$sub"; | |
392 | print <<END; | |
393 | <tr> | |
394 | <td style='width:25%; text-align:center; background-color:$Header::colourovpn;'> | |
395 | <a href='/cgi-bin/ovpnmain.cgi' style='color:white'><b>OpenVPN</b></a> | |
396 | </td> | |
397 | <td style='width:30%; text-align:center;'>$ovpnip</td> | |
398 | <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td> | |
399 | </tr> | |
400 | END | |
401 | } | |
402 | print"</table>"; | |
403 | &Header::closebox(); | |
404 | ||
405 | #Check if there are any vpns configured (ipsec and openvpn) | |
406 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
407 | foreach my $key (sort { ncmp($vpnconfig{$a}[1],$vpnconfig{$b}[1]) } keys %vpnconfig) { | |
408 | if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host'){ | |
409 | $showipsec=1; | |
410 | $showbox=1; | |
411 | last; | |
412 | } | |
413 | } | |
414 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ovpnconfig); | |
415 | foreach my $dkey (sort { ncmp($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) { | |
416 | if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){ | |
417 | $showbox=1; | |
418 | $showovpn=1; | |
419 | last; | |
420 | } | |
421 | } | |
422 | ||
423 | if ($showbox){ | |
424 | # Start of Box wich contains all vpn connections | |
425 | &Header::openbox('100%', 'center', $Lang::tr{'vpn'}); | |
426 | ||
427 | #show ipsec connectiontable | |
428 | if ( $showipsec ) { | |
429 | my $ipsecip = $vpnsettings{'VPN_IP'}; | |
430 | my @status = `/usr/local/bin/ipsecctrl I`; | |
431 | my %confighash = (); | |
432 | my $id = 0; | |
433 | my $gif; | |
434 | my $col=""; | |
435 | my $count=0; | |
436 | print <<END; | |
437 | <table class='tbl' style='width:80%;'> | |
438 | <tr> | |
439 | <th style='width:40%;'>$Lang::tr{'ipsec network'}</th> | |
440 | <th style='width:30%;'>$Lang::tr{'ip address'}</th> | |
441 | <th style='width:30%;'>$Lang::tr{'status'}</th> | |
442 | </tr> | |
443 | END | |
444 | foreach my $key (sort { uc($vpnconfig{$a}[1]) cmp uc($vpnconfig{$b}[1]) } keys %vpnconfig) { | |
445 | if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host') { | |
446 | $count++; | |
447 | my ($vpnip,$vpnsub) = split("/",$vpnconfig{$key}[11]); | |
448 | $vpnsub=&General::iporsubtocidr($vpnsub); | |
449 | $vpnip="$vpnip/$vpnsub"; | |
450 | if ($count % 2){ | |
451 | $col = $color{'color22'}; | |
452 | }else{ | |
453 | $col = $color{'color20'}; | |
454 | } | |
455 | print "<tr>"; | |
456 | print "<td style='text-align:left; color:white; background-color:$Header::colourvpn;'>$vpnconfig{$key}[1]</td>"; | |
457 | print "<td style='text-align:center; background-color:$col'>$vpnip</td>"; | |
458 | ||
459 | my $activecolor = $Header::colourred; | |
460 | my $activestatus = $Lang::tr{'capsclosed'}; | |
461 | if ($vpnconfig{$key}[0] eq 'off') { | |
462 | $activecolor = $Header::colourblue; | |
463 | $activestatus = $Lang::tr{'capsclosed'}; | |
464 | } else { | |
465 | foreach my $line (@status) { | |
466 | if (($line =~ /\"$vpnconfig{$key}[1]\".*IPsec SA established/) || ($line =~/$vpnconfig{$key}[1]\{.*INSTALLED/ )){ | |
467 | $activecolor = $Header::colourgreen; | |
468 | $activestatus = $Lang::tr{'capsopen'}; | |
469 | } elsif ($line =~ /$vpnconfig{$key}[1]\[.*CONNECTING/) { | |
470 | $activecolor = $Header::colourorange; | |
471 | $activestatus = $Lang::tr{'vpn connecting'}; | |
472 | } elsif ($line =~ /$vpnconfig{$key}[1]\{.*ROUTED/) { | |
473 | $activecolor = $Header::colourorange; | |
474 | $activestatus = $Lang::tr{'vpn on-demand'}; | |
475 | } | |
476 | } | |
477 | } | |
478 | print "<td style='text-align:center; color:white; background-color:$activecolor;'><b>$activestatus</b></td>"; | |
479 | print "</tr>"; | |
480 | } | |
481 | } | |
482 | print "</table>"; | |
483 | } | |
484 | ||
485 | # Check if there is any OpenVPN connection configured. | |
486 | if ( $showovpn ){ | |
487 | print <<END; | |
488 | <br/> | |
489 | <table class='tbl' style='width:80%;'> | |
490 | <tr> | |
491 | <th style='width:40%;'>$Lang::tr{'openvpn network'}</th> | |
492 | <th style='width:30%;'>$Lang::tr{'ip address'}</th> | |
493 | <th style='width:30%;'>$Lang::tr{'status'}</th> | |
494 | END | |
495 | ||
496 | # Check if the OpenVPN server for Road Warrior Connections is running and display status information. | |
497 | my $active; | |
498 | my $count=0; | |
499 | # Print the OpenVPN N2N connection status. | |
500 | if ( -d "${General::swroot}/ovpn/n2nconf") { | |
501 | my $col=""; | |
502 | foreach my $dkey (sort { ncmp ($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) { | |
503 | if (($ovpnconfig{$dkey}[3] eq 'net') && (-e "/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){ | |
504 | $count++; | |
505 | my $tport = $ovpnconfig{$dkey}[22]; | |
506 | next if ($tport eq ''); | |
507 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
508 | $tnet->open('127.0.0.1'); | |
509 | my @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
510 | my @tustate = split(/\,/, $output[1]); | |
511 | my $display; | |
512 | my $display_colour = $Header::colourred; | |
513 | if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) { | |
514 | $display_colour = $Header::colourgreen; | |
515 | $display = $Lang::tr{'capsopen'}; | |
516 | } else { | |
517 | $display = $tustate[1]; | |
518 | } | |
519 | if ($count %2){ | |
520 | $col = $color{'color22'}; | |
521 | }else{ | |
522 | $col = $color{'color20'}; | |
523 | } | |
524 | $active='off'; | |
525 | #make cidr from ip | |
526 | my ($vpnip,$vpnsub) = split("/",$ovpnconfig{$dkey}[11]); | |
527 | my $vpnsub=&General::iporsubtocidr($vpnsub); | |
528 | my $vpnip="$vpnip/$vpnsub"; | |
529 | print <<END; | |
530 | <tr> | |
531 | <td style='text-align:left; color:white; background-color:$Header::colourovpn;'>$ovpnconfig{$dkey}[1]</td> | |
532 | <td style='text-align:center; background-color:$col'>$vpnip</td> | |
533 | <td style='text-align:center; color:white; background-color:$display_colour' ><b>$display</b></td> | |
534 | </tr> | |
535 | END | |
536 | } | |
537 | } | |
538 | } | |
539 | if ($active ne 'off'){ | |
540 | print "<tr><td colspan='3' style='text-align:center;'>$Lang::tr{'ovpn no connections'}</td></tr>"; | |
541 | } | |
542 | print"</table>"; | |
543 | } | |
544 | &Header::closebox(); | |
545 | } | |
546 | ||
547 | my $dnssec_status = &General::dnssec_status(); | |
548 | if ($dnssec_status eq "off") { | |
549 | $warnmessage .= "<li>$Lang::tr{'dnssec disabled warning'}</li>"; | |
550 | } | |
551 | ||
552 | # Fireinfo | |
553 | if ( ! -e "/var/ipfire/main/send_profile") { | |
554 | $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>"; | |
555 | } | |
556 | ||
557 | # Memory usage warning | |
558 | my @free = `/usr/bin/free`; | |
559 | $free[1] =~ m/(\d+)/; | |
560 | my $mem = $1; | |
561 | $free[2] =~ m/(\d+)/; | |
562 | my $used = $1; | |
563 | my $pct = int 100 * ($mem - $used) / $mem; | |
564 | if ($used / $mem > 90) { | |
565 | $warnmessage .= "<li>$Lang::tr{'high memory usage'}: $pct% !</li>"; | |
566 | } | |
567 | ||
568 | # Diskspace usage warning | |
569 | my @temp=(); | |
570 | my $temp2=(); | |
571 | my @df = `/bin/df -B M -P -x rootfs`; | |
572 | foreach my $line (@df) { | |
573 | next if $line =~ m/^Filesystem/; | |
574 | if ($line =~ m/root/ ) { | |
575 | $line =~ m/^.* (\d+)M.*$/; | |
576 | @temp = split(/ +/,$line); | |
577 | if ($1<5) { | |
578 | # available:plain value in MB, and not %used as 10% is too much to waste on small disk | |
579 | # and root size should not vary during time | |
580 | $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>"; | |
581 | } | |
582 | ||
583 | } else { | |
584 | # $line =~ m/^.* (\d+)m.*$/; | |
585 | $line =~ m/^.* (\d+)\%.*$/; | |
586 | if ($1>90) { | |
587 | @temp = split(/ /,$line); | |
588 | $temp2=int(100-$1); | |
589 | $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>"; | |
590 | } | |
591 | } | |
592 | } | |
593 | ||
594 | # S.M.A.R.T. health warning | |
595 | my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`; | |
596 | foreach my $file (@files) { | |
597 | chomp ($file); | |
598 | my $disk=`echo $file | cut -d"-" -f2`; | |
599 | chomp ($disk); | |
600 | if (`/bin/grep "SAVE ALL DATA" $file`) { | |
601 | $warnmessage .= "<li>$Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>"; | |
602 | } | |
603 | } | |
604 | ||
605 | # Reiser4 warning | |
606 | my @files = `mount | grep " reiser4 (" 2>/dev/null`; | |
607 | foreach my $disk (@files) { | |
608 | chomp ($disk); | |
609 | $warnmessage .= "<li>$disk - $Lang::tr{'deprecated fs warn'}</li>"; | |
610 | } | |
611 | ||
612 | if ($warnmessage) { | |
613 | &Header::openbox('100%','center', ); | |
614 | print "<table class='tbl' style='width:80%;'>"; | |
615 | print "<tr><th>$Lang::tr{'fwhost hint'}</th></tr>"; | |
616 | print "<tr><td style='color:white; background-color:$Header::colourred;'>$warnmessage</td></tr>"; | |
617 | print "</table>"; | |
618 | &Header::closebox(); | |
619 | } | |
620 | ||
621 | &Pakfire::dblist("upgrade", "notice"); | |
622 | if ( -e "/var/run/need_reboot" ) { | |
623 | print "<div style='text-align:center; color:red;'>"; | |
624 | print "<br/><br/>$Lang::tr{'needreboot'}!"; | |
625 | print "</div>"; | |
626 | } | |
627 | ||
628 | &Header::closebigbox(); | |
629 | &Header::closepage(); | |
630 |