]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/index.cgi
65773244c5d67bed9ac7dc6abde32a58f09a94c0
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
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";
51 if ( ! -e
"/var/ipfire/main/gpl_accepted" ) {
52 print "Status: 302 Moved Temporarily\n";
53 print "Location: gpl.cgi\n\n";
57 &Header
::showhttpheaders
();
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);
71 my %mainsettings = ();
72 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
73 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
75 my $connstate = &Header
::connectionstatus
();
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;'>";
85 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial profile'})
87 my $profile = $cgiparams{'PROFILE'};
88 my %tempcgiparams = ();
89 $tempcgiparams{'PROFILE'} = '';
90 &General
::readhash
("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
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");
99 # read in the new params "early" so we can write secrets.
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'}",
107 # write secrets file.
108 open(FILE
, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
110 my $username = $cgiparams{'USERNAME'};
111 my $password = $cgiparams{'PASSWORD'};
112 print FILE
"'$username' * '$password'\n";
113 chmod 0600, "${General::swroot}/ppp/secrets";
116 &General
::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
117 $cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
120 if ($cgiparams{'ACTION'} eq $Lang::tr
{'dial'}) {
121 &General
::system('/usr/local/bin/redctrl', 'start') == 0
122 or &General
::log("Dial failed: $?"); sleep 1;
123 }elsif ($cgiparams{'ACTION'} eq $Lang::tr
{'hangup'}) {
124 &General
::system('/usr/local/bin/redctrl', 'stop') == 0
125 or &General
::log("Hangup failed: $?"); sleep 1;
130 my @profilenames = ();
132 for ($c = 1; $c <= $maxprofiles; $c++)
134 my %temppppsettings = ();
135 $temppppsettings{'PROFILENAME'} = '';
136 &General
::readhash
("${General::swroot}/ppp/settings-$c", \
%temppppsettings);
137 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
140 for ($c = 1; $c <= $maxprofiles; $c++) {
141 $selected{'PROFILE'}{$c} = '';
143 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
144 my $dialButtonDisabled = "disabled='disabled'";
146 &Header
::openpage
($Lang::tr
{'main page'}, 1, $refresh);
147 &Header
::openbigbox
('', 'center');
148 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
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")) {
161 if (open(IPADDR
,"${General::swroot}/red/local-ipaddress")) {
166 } elsif ($modemsettings{'VALID'} eq 'no') {
167 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
169 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
173 <!-- Table of networks -->
174 <table class='tbl' style='width:80%;'>
176 <th>$Lang::tr{'network'}</th>
177 <th>$Lang::tr{'ip address'}</th>
178 <th>$Lang::tr{'status'}</th>
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>
186 my $HOSTNAME = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
187 if ( "$HOSTNAME" ne "" ) {
189 <tr><td><b>$Lang::tr{'hostname'}:</b><td style='text-align:center;'>$HOSTNAME</td><td></td>
193 if ( -e
"${General::swroot}/red/remote-ipaddress" ) {
194 open (TMP
, "<${General::swroot}/red/remote-ipaddress");
199 <tr><td><b>$Lang::tr{'gateway'}:</b><td style='text-align:center;'>$GATEWAY</td><td></td></tr>
203 if (&General
::RedIsWireless
()) {
204 my $iface = $netsettings{"RED_DEV"} || "red0";
206 my $essid = &Network
::wifi_get_essid
($iface);
207 my $frequency = &Network
::wifi_get_frequency
($iface);
208 my $access_point = &Network
::wifi_get_access_point
($iface);
209 my $bit_rate = &Network
::wifi_get_bit_rate
($iface);
210 my $link_quality = &Network
::wifi_get_link_quality
($iface);
211 my $signal_level = &Network
::wifi_get_signal_level
($iface);
216 <strong>$Lang::tr{'wireless network'}:</strong>
218 <td style="text-align: center">
221 <td style="text-align: center">
222 $access_point @ $frequency
228 $Lang::tr{'uplink bit rate'}:
231 <td style="text-align: center">
234 <td style="text-align: center">
235 $link_quality% @ $signal_level
246 if ( $netsettings{'RED_TYPE'} ne "STATIC" && $netsettings{'RED_TYPE'} ne "DHCP" ){
247 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
250 <table style='width:80%;'>
252 <form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'profile'}:
253 <select name='PROFILE'>
255 for ($c = 1; $c <= $maxprofiles; $c++)
257 if ($profilenames[$c] ne '') {
258 $dialButtonDisabled = "";
259 print "<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>";
262 $dialButtonDisabled = "disabled='disabled'" if (-e
'/var/run/ppp-ipfire.pid' || -e
"${General::swroot}/red/active");
265 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
268 <td style='text-align:center;'>
269 <table style='width:100%;'>
271 <td style='width=50%; text-align:right;'>
272 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
273 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
276 <td style='width=50%; text-align:left;'>
277 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
278 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
288 print "<br/><span style='color:red;'>$Lang::tr{'profile has errors'}</span><br/>";
295 <table class='tbl' style='width:80%;'>
297 <th>$Lang::tr{'network'}</th>
298 <th>$Lang::tr{'ip address'}</th>
299 <th>$Lang::tr{'status'}</th>
303 if ( $netsettings{'GREEN_DEV'} ) {
304 my $sub=&General
::iporsubtocidr
($netsettings{'GREEN_NETMASK'});
307 <td style='width:25%; text-align:center; background-color:$Header::colourgreen;'>
308 <a href='/cgi-bin/dhcp.cgi' style='color:white'><b>$Lang::tr{'lan'}</b></a>
310 <td style='width:30%; text-align:center;'>$netsettings{'GREEN_ADDRESS'}/$sub</td>
311 <td style='width:45%; text-align:center;'>
313 if ( $proxysettings{'ENABLE'} eq 'on' ) {
314 print $Lang::tr
{'advproxy on'};
315 if ( $proxysettings{'TRANSPARENT'} eq 'on' ) { print " (transparent)"; }
316 } else { print $Lang::tr
{'advproxy off'}; }
320 if (&Header
::blue_used
()) {
321 my $sub=&General
::iporsubtocidr
($netsettings{'BLUE_NETMASK'});
324 <td style='width:25%; text-align:center; background-color:$Header::colourblue;'>
325 <a href='/cgi-bin/wireless.cgi' style='color:white'><b>$Lang::tr{'wireless'}</b></a>
327 <td style='width:30%; text-align:center;'>$netsettings{'BLUE_ADDRESS'}/$sub
328 <td style='width:45%; text-align:center;'>
330 if ( $proxysettings{'ENABLE_BLUE'} eq 'on' ) {
331 print $Lang::tr
{'advproxy on'};
332 if ( $proxysettings{'TRANSPARENT_BLUE'} eq 'on' ) { print " (transparent)"; }
333 } else { print $Lang::tr
{'advproxy off'}; }
337 if (&Header
::orange_used
()) {
338 my $sub=&General
::iporsubtocidr
($netsettings{'ORANGE_NETMASK'});
341 <td style='width:25%; text-align:center; background-color:$Header::colourorange;'>
342 <a href='/cgi-bin/firewall.cgi' style='color:white'><b>$Lang::tr{'dmz'}</b></a>
344 <td style='width:30%; text-align:center;'>$netsettings{'ORANGE_ADDRESS'}/$sub</td>
345 <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td>
349 #check if IPSEC is running
350 if ( $vpnsettings{'ENABLED'} eq 'on' || $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {
353 <td style='width:25%; text-align:center; background-color:$Header::colourvpn;'>
354 <a href='/cgi-bin/vpnmain.cgi' style='color:white'><b>$Lang::tr{'ipsec'}</b></a>
356 <td style='width:30%; text-align:center;'></td>
357 <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td>
362 #check if OpenVPN is running
364 &General
::readhash
("${General::swroot}/ovpn/settings", \
%confighash);
366 if (($confighash{'ENABLED'} eq "on") ||
367 ($confighash{'ENABLED_BLUE'} eq "on") ||
368 ($confighash{'ENABLED_ORANGE'} eq "on")) {
369 my ($ovpnip,$sub) = split("/",$confighash{'DOVPN_SUBNET'});
370 $sub=&General
::iporsubtocidr
($sub);
371 $ovpnip="$ovpnip/$sub";
374 <td style='width:25%; text-align:center; background-color:$Header::colourovpn;'>
375 <a href='/cgi-bin/ovpnmain.cgi' style='color:white'><b>OpenVPN</b></a>
377 <td style='width:30%; text-align:center;'>$ovpnip</td>
378 <td style='width:45%; text-align:center; color:$Header::colourgreen;'>Online</td>
385 #Check if there are any vpns configured (ipsec and openvpn)
386 &General
::readhasharray
("${General::swroot}/vpn/config", \
%vpnconfig);
387 foreach my $key (sort { ncmp
($vpnconfig{$a}[1],$vpnconfig{$b}[1]) } keys %vpnconfig) {
388 if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host'){
394 &General
::readhasharray
("${General::swroot}/ovpn/ovpnconfig", \
%ovpnconfig);
395 foreach my $dkey (sort { ncmp
($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
396 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e
"/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
404 # Start of Box wich contains all vpn connections
405 &Header
::openbox
('100%', 'center', $Lang::tr
{'vpn'});
407 #show ipsec connectiontable
409 my $ipsecip = $vpnsettings{'VPN_IP'};
410 my @status = `/usr/local/bin/ipsecctrl I`;
417 <table class='tbl' style='width:80%;'>
419 <th style='width:40%;'>$Lang::tr{'ipsec network'}</th>
420 <th style='width:30%;'>$Lang::tr{'ip address'}</th>
421 <th style='width:30%;'>$Lang::tr{'status'}</th>
424 foreach my $key (sort { uc($vpnconfig{$a}[1]) cmp uc($vpnconfig{$b}[1]) } keys %vpnconfig) {
425 if ($vpnconfig{$key}[0] eq 'on' && $vpnconfig{$key}[3] ne 'host') {
430 my @networks = split(/\|/, $vpnconfig{$key}[11]);
431 foreach my $network (@networks) {
432 my ($vpnip, $vpnsub) = split("/", $network);
433 $vpnsub = &Network
::convert_netmask2prefix
($vpnsub) || $vpnsub;
434 push(@n, "$vpnip/$vpnsub");
438 $col = $color{'color22'};
440 $col = $color{'color20'};
443 print "<td style='text-align:left; color:white; background-color:$Header::colourvpn;'>$vpnconfig{$key}[1]</td>";
444 print "<td style='text-align:center; background-color:$col'>" . join("<br>", @n) . "</td>";
446 my $activecolor = $Header::colourred
;
447 my $activestatus = $Lang::tr
{'capsclosed'};
448 if ($vpnconfig{$key}[33] eq "add") {
449 $activecolor = ${Header
::colourorange
};
450 $activestatus = $Lang::tr
{'vpn wait'};
452 if ($vpnconfig{$key}[0] eq 'off') {
453 $activecolor = $Header::colourblue
;
454 $activestatus = $Lang::tr
{'capsclosed'};
456 foreach my $line (@status) {
457 if (($line =~ /\"$vpnconfig{$key}[1]\".*IPsec SA established/) || ($line =~/$vpnconfig{$key}[1]\{.*INSTALLED/ )){
458 $activecolor = $Header::colourgreen
;
459 $activestatus = $Lang::tr
{'capsopen'};
461 } elsif ($line =~ /$vpnconfig{$key}[1]\[.*CONNECTING/) {
462 $activecolor = $Header::colourorange
;
463 $activestatus = $Lang::tr
{'vpn connecting'};
464 } elsif ($line =~ /$vpnconfig{$key}[1]\{.*ROUTED/) {
465 $activecolor = $Header::colourorange
;
466 $activestatus = $Lang::tr
{'vpn on-demand'};
470 print "<td style='text-align:center; color:white; background-color:$activecolor;'><b>$activestatus</b></td>";
477 # Check if there is any OpenVPN connection configured.
481 <table class='tbl' style='width:80%;'>
483 <th style='width:40%;'>$Lang::tr{'openvpn network'}</th>
484 <th style='width:30%;'>$Lang::tr{'ip address'}</th>
485 <th style='width:30%;'>$Lang::tr{'status'}</th>
488 # Check if the OpenVPN server for Road Warrior Connections is running and display status information.
491 # Print the OpenVPN N2N connection status.
492 if ( -d
"${General::swroot}/ovpn/n2nconf") {
494 foreach my $dkey (sort { ncmp
($ovpnconfig{$a}[1],$ovpnconfig{$b}[1])} keys %ovpnconfig) {
495 if (($ovpnconfig{$dkey}[3] eq 'net') && (-e
"/var/run/$ovpnconfig{$dkey}[1]n2n.pid")){
497 my $tport = $ovpnconfig{$dkey}[22];
498 next if ($tport eq '');
499 my $tnet = new Net
::Telnet
( Timeout
=>5, Errmode
=>'return', Port
=>$tport);
500 $tnet->open('127.0.0.1');
501 my @output = $tnet->cmd(String
=> 'state', Prompt
=> '/(END.*\n|ERROR:.*\n)/');
502 my @tustate = split(/\,/, $output[1]);
504 my $display_colour = $Header::colourred
;
505 if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) {
506 $display_colour = $Header::colourgreen
;
507 $display = $Lang::tr
{'capsopen'};
509 $display = $tustate[1];
512 $col = $color{'color22'};
514 $col = $color{'color20'};
518 my ($vpnip,$vpnsub) = split("/",$ovpnconfig{$dkey}[11]);
519 my $vpnsub=&General
::iporsubtocidr
($vpnsub);
520 my $vpnip="$vpnip/$vpnsub";
523 <td style='text-align:left; color:white; background-color:$Header::colourovpn;'>$ovpnconfig{$dkey}[1]</td>
524 <td style='text-align:center; background-color:$col'>$vpnip</td>
525 <td style='text-align:center; color:white; background-color:$display_colour' ><b>$display</b></td>
531 if ($active ne 'off'){
532 print "<tr><td colspan='3' style='text-align:center;'>$Lang::tr{'ovpn no connections'}</td></tr>";
540 if ( ! -e
"/var/ipfire/main/send_profile") {
541 $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'>$Lang::tr{'fireinfo please enable'}</a></li>";
545 my ($sysname, $nodename, $release, $version, $machine) = &POSIX
::uname
();
546 if ($machine =~ m/^arm/) {
547 $warnmessage .= "<li><a href='https://wiki.ipfire.org/hardware/requirements' style='color:white;'>$Lang::tr{'eol architecture warning'}</a></li>";
550 # Memory usage warning
551 my @free = `/usr/bin/free`;
552 $free[1] =~ m/(\d+)/;
554 $free[2] =~ m/(\d+)/;
556 my $pct = int 100 * ($mem - $used) / $mem;
557 if ($used / $mem > 90) {
558 $warnmessage .= "<li>$Lang::tr{'high memory usage'}: $pct% !</li>";
561 # Diskspace usage warning
564 my @df = `/bin/df -B M -P -x rootfs`;
565 foreach my $line (@df) {
566 next if $line =~ m/^Filesystem/;
567 if ($line =~ m/root/ ) {
568 $line =~ m/^.* (\d+)M.*$/;
569 @temp = split(/ +/,$line);
571 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
572 # and root size should not vary during time
573 $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>";
577 # $line =~ m/^.* (\d+)m.*$/;
578 $line =~ m/^.* (\d+)\%.*$/;
580 @temp = split(/ /,$line);
582 $warnmessage .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>";
587 # S.M.A.R.T. health warning
588 my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null`;
589 foreach my $file (@files) {
591 my $disk=`echo $file | cut -d"-" -f2`;
593 if (`/bin/grep "SAVE ALL DATA" $file`) {
594 $warnmessage .= "<li>$Lang::tr{'smartwarn1'} /dev/$disk $Lang::tr{'smartwarn2'} !</li>";
599 &Header
::openbox
('100%','center', );
600 print "<table class='tbl' style='width:80%;'>";
601 print "<tr><th>$Lang::tr{'fwhost hint'}</th></tr>";
602 print "<tr><td style='color:white; background-color:$Header::colourred;'>$warnmessage</td></tr>";
607 my %coredb = &Pakfire
::coredbinfo
();
608 if (defined $coredb{'AvailableRelease'}) {
609 print "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $coredb{'Release'} $Lang::tr{'core notice 2'} $coredb{'AvailableRelease'} $Lang::tr{'core notice 3'}</a>";
612 if ( -e
"/var/run/need_reboot" ) {
613 print "<div style='text-align:center; color:red;'>";
614 print "<br/><br/>$Lang::tr{'needreboot'}!";
618 if ( `/bin/grep -c "reiserfs" /proc/self/mounts` > 0 ) {
619 print "<div style='text-align:center; color:blue;'>";
620 print "<br/><br/>$Lang::tr{'reiserfs warning1'}";
621 print "<br/>$Lang::tr{'reiserfs warning2'}";
625 &Header
::closebigbox
();
626 &Header
::closepage
();