From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 1/2] manualpages: Add path and file extension to the configuration Date: Wed, 06 Apr 2022 15:39:39 +0200 Message-ID: <20220406133940.803-1-hofmann@leo-andres.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1402546899139351791==" List-Id: --===============1402546899139351791== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This allows to correctly assign an URL to a file without relying on unique base names. A custom read function is required because General::readhash() doesn't allow paths as hash keys. Modifying the existing functions could affect other CGIs and was therefore dismissed. Fixes: #12806 Signed-off-by: Leo-Andres Hofmann --- config/cfgroot/header.pl | 33 ++++- config/cfgroot/manualpages | 144 +++++++++---------- html/html/themes/ipfire/include/functions.pl | 4 +- tools/check_manualpages.pl | 17 +-- 4 files changed, 110 insertions(+), 88 deletions(-) diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index e97f90d67..e6d2b7c78 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -93,7 +93,7 @@ if ( -d "/var/ipfire/langs/${language}/" ) { =20 ### Initialize user manual my %manualpages =3D (); -&General::readhash("${General::swroot}/main/manualpages", \%manualpages); +&_read_manualpage_hash("${General::swroot}/main/manualpages"); =20 ### Load selected language and theme functions require "${swroot}/langs/en.pl"; @@ -558,18 +558,41 @@ sub colorize { } } =20 -# Get user manual URL for the specified configuration page, returns empty if= no entry is configured +# Get user manual URL for a configuration page inside the "/cgi-bin/" +# (reads current page from the environment variables unless defined) +# Returns empty if no URL is available sub get_manualpage_url() { - my ($cgi_page) =3D @_; + my ($cgifile) =3D @_; + $cgifile //=3D substr($ENV{'SCRIPT_NAME'}, 9); # remove fixed "/cgi-bin/" p= ath =20 # Ensure base url is configured return unless($manualpages{'BASE_URL'}); =20 # Return URL - if($cgi_page && defined($manualpages{$cgi_page})) { - return "$manualpages{'BASE_URL'}/$manualpages{$cgi_page}"; + if($cgifile && defined($manualpages{$cgifile})) { + return "$manualpages{'BASE_URL'}/$manualpages{$cgifile}"; } =20 # No manual page configured, return nothing return; } + +# Private function to load a hash of configured user manual pages from file +# (run check_manualpages.pl to make sure the file is correct) +sub _read_manualpage_hash() { + my ($filename) =3D @_; + + open(my $file, "<", $filename) or return; # Fail silent + while(my $line =3D <$file>) { + chomp($line); + next if(substr($line, 0, 1) eq '#'); # Skip comments + next if(index($line, '=3D', 1) =3D=3D -1); # Skip incomplete lines + + my($left, $value) =3D split(/=3D/, $line, 2); + if($left =3D~ /^([[:alnum:]\/._-]+)$/) { + my $key =3D $1; + $manualpages{$key} =3D $value; + } + } + close($file); +} diff --git a/config/cfgroot/manualpages b/config/cfgroot/manualpages index 6c2e54b55..b92a81b56 100644 --- a/config/cfgroot/manualpages +++ b/config/cfgroot/manualpages @@ -1,88 +1,88 @@ -# Assign manual page URL path to CGI file ([cgi basename]=3D[path/to/page]) = +# Assign manual page URL path to CGI file ([cgi file]=3D[path/to/page]) +# The CGI files are referenced relative to the "/cgi-bin/" path =20 -# Base URL (without trailing slash) +# Fixed base URL (without trailing slash) BASE_URL=3Dhttps://wiki.ipfire.org -index=3Dconfiguration/system/startpage =20 # System menu -index=3Dconfiguration/system/startpage -mail=3Dconfiguration/system/mail_service -remote=3Dconfiguration/system/ssh -backup=3Dconfiguration/system/backup -gui=3Dconfiguration/system/userinterface -fireinfo=3Dfireinfo -vulnerabilities=3Dconfiguration/system/vulnerabilities -shutdown=3Dconfiguration/system/shutdown -credits=3Dconfiguration/system/credits +index.cgi=3Dconfiguration/system/startpage +mail.cgi=3Dconfiguration/system/mail_service +remote.cgi=3Dconfiguration/system/ssh +backup.cgi=3Dconfiguration/system/backup +gui.cgi=3Dconfiguration/system/userinterface +fireinfo.cgi=3Dfireinfo +vulnerabilities.cgi=3Dconfiguration/system/vulnerabilities +shutdown.cgi=3Dconfiguration/system/shutdown +credits.cgi=3Dconfiguration/system/credits =20 # Status menu -system=3Dconfiguration/status/system -memory=3Dconfiguration/status/memory -services=3Dconfiguration/status/services -media=3Dconfiguration/status/drives -netexternal=3Dconfiguration/status/network_ext -netinternal=3Dconfiguration/status/network_int -netother=3Dconfiguration/status/network_int -netovpnrw=3Dconfiguration/status/network_ovpnrw -#netovpnsrv=3D -wio=3Daddons/wio -hardwaregraphs=3Dconfiguration/status/hardware_diagrams -entropy=3Dconfiguration/status/entropy -connections=3Dconfiguration/status/connections -traffic=3Dconfiguration/status/nettraffic -#mdstat=3D +system.cgi=3Dconfiguration/status/system +memory.cgi=3Dconfiguration/status/memory +services.cgi=3Dconfiguration/status/services +media.cgi=3Dconfiguration/status/drives +netexternal.cgi=3Dconfiguration/status/network_ext +netinternal.cgi=3Dconfiguration/status/network_int +netother.cgi=3Dconfiguration/status/network_int +netovpnrw.cgi=3Dconfiguration/status/network_ovpnrw +#netovpnsrv.cgi=3D +wio.cgi=3Daddons/wio +hardwaregraphs.cgi=3Dconfiguration/status/hardware_diagrams +entropy.cgi=3Dconfiguration/status/entropy +connections.cgi=3Dconfiguration/status/connections +traffic.cgi=3Dconfiguration/status/nettraffic +#mdstat.cgi=3D =20 # Network menu -zoneconf=3Dconfiguration/network/zoneconf -dns=3Ddns -proxy=3Dconfiguration/network/proxy -urlfilter=3Dconfiguration/network/proxy/url-filter -#updatexlrator=3Dconfiguration/network/proxy/update_accelerator -dhcp=3Dconfiguration/network/dhcp -captive=3Dconfiguration/network/captive -connscheduler=3Dconfiguration/network/connectionscheduler -hosts=3Dconfiguration/network/hosts -dnsforward=3Dconfiguration/network/dnsforward -routing=3Dconfiguration/network/static -mac=3Dconfiguration/network/mac-address -wakeonlan=3Dconfiguration/network/wake-on-lan +zoneconf.cgi=3Dconfiguration/network/zoneconf +dns.cgi=3Ddns +proxy.cgi=3Dconfiguration/network/proxy +urlfilter.cgi=3Dconfiguration/network/proxy/url-filter +#updatexlrator.cgi=3Dconfiguration/network/proxy/update_accelerator +dhcp.cgi=3Dconfiguration/network/dhcp +captive.cgi=3Dconfiguration/network/captive +connscheduler.cgi=3Dconfiguration/network/connectionscheduler +hosts.cgi=3Dconfiguration/network/hosts +dnsforward.cgi=3Dconfiguration/network/dnsforward +routing.cgi=3Dconfiguration/network/static +mac.cgi=3Dconfiguration/network/mac-address +wakeonlan.cgi=3Dconfiguration/network/wake-on-lan =20 # Services menu -vpnmain=3Dconfiguration/services/ipsec -ovpnmain=3Dconfiguration/services/openvpn -ddns=3Dconfiguration/services/dyndns -time=3Dconfiguration/services/ntp -qos=3Dconfiguration/services/qos -guardian=3Daddons/guardian -extrahd=3Dconfiguration/services/extrahd +vpnmain.cgi=3Dconfiguration/services/ipsec +ovpnmain.cgi=3Dconfiguration/services/openvpn +ddns.cgi=3Dconfiguration/services/dyndns +time.cgi=3Dconfiguration/services/ntp +qos.cgi=3Dconfiguration/services/qos +guardian.cgi=3Daddons/guardian +extrahd.cgi=3Dconfiguration/services/extrahd =20 # Firewall menu -firewall=3Dconfiguration/firewall -fwhosts=3Dconfiguration/firewall/fwgroups -optionsfw=3Dconfiguration/firewall/options -ids=3Dconfiguration/firewall/ips -location-block=3Dconfiguration/firewall/geoip-block -wireless=3Dconfiguration/firewall/accesstoblue -iptables=3Dconfiguration/firewall/iptables +firewall.cgi=3Dconfiguration/firewall +fwhosts.cgi=3Dconfiguration/firewall/fwgroups +optionsfw.cgi=3Dconfiguration/firewall/options +ids.cgi=3Dconfiguration/firewall/ips +location-block.cgi=3Dconfiguration/firewall/geoip-block +wireless.cgi=3Dconfiguration/firewall/accesstoblue +iptables.cgi=3Dconfiguration/firewall/iptables =20 # IPfire menu -pakfire=3Dconfiguration/ipfire/pakfire -wlanap=3Daddons/wireless -tor=3Daddons/tor -mpfire=3Daddons/mpfire -samba=3Daddons/samba +pakfire.cgi=3Dconfiguration/ipfire/pakfire +wlanap.cgi=3Daddons/wireless +tor.cgi=3Daddons/tor +mpfire.cgi=3Daddons/mpfire +samba.cgi=3Daddons/samba =20 # Logs menu -summary=3Dconfiguration/logs/summary -config=3Dconfiguration/logs/logsettings -proxylog=3Dconfiguration/logs/proxy -calamaris=3Dconfiguration/logs/proxyreports -accounting=3Daddons/squid-accounting -firewalllog=3Dconfiguration/logs/firewall -firewalllogip=3Dconfiguration/logs/firewall-ip -firewalllogport=3Dconfiguration/logs/firewall-port -firewalllogcountry=3Dconfiguration/logs/firewall-country -ids=3Dconfiguration/logs/ips -#ovpnclients=3D -urlfilter=3Dconfiguration/logs/url-filter -log=3Dconfiguration/logs/system +logs.cgi/summary.dat=3Dconfiguration/logs/summary +logs.cgi/config.dat=3Dconfiguration/logs/logsettings +logs.cgi/proxylog.dat=3Dconfiguration/logs/proxy +logs.cgi/calamaris.dat=3Dconfiguration/logs/proxyreports +logs.cgi/accounting.dat=3Daddons/squid-accounting +logs.cgi/firewalllog.dat=3Dconfiguration/logs/firewall +logs.cgi/firewalllogip.dat=3Dconfiguration/logs/firewall-ip +logs.cgi/firewalllogport.dat=3Dconfiguration/logs/firewall-port +logs.cgi/firewalllogcountry.dat=3Dconfiguration/logs/firewall-country +logs.cgi/ids.dat=3Dconfiguration/logs/ips +#logs.cgi/ovpnclients.dat=3D +logs.cgi/urlfilter.dat=3Dconfiguration/logs/url-filter +logs.cgi/log.dat=3Dconfiguration/logs/system diff --git a/html/html/themes/ipfire/include/functions.pl b/html/html/themes/= ipfire/include/functions.pl index d74c962e4..40afb3ce3 100644 --- a/html/html/themes/ipfire/include/functions.pl +++ b/html/html/themes/ipfire/include/functions.pl @@ -102,8 +102,6 @@ sub openpage { my $boh =3D shift; my $extrahead =3D shift; my $suppressMenu =3D shift; - my @tmp =3D split(/\./, basename($0)); - my $scriptName =3D @tmp[0]; =20 @URI=3Dsplit ('\?', $ENV{'REQUEST_URI'} ); &General::readhash("${swroot}/main/settings", \%settings); @@ -176,7 +174,7 @@ END ; =20 # Print user manual link -my $manual_url =3D &Header::get_manualpage_url($scriptName); +my $manual_url =3D &Header::get_manualpage_url(); if($manual_url) { print <3D"$Lang::tr{'online diff --git a/tools/check_manualpages.pl b/tools/check_manualpages.pl index 75a560560..446e94649 100644 --- a/tools/check_manualpages.pl +++ b/tools/check_manualpages.pl @@ -25,18 +25,19 @@ use strict; # Import make.sh environment my $basedir =3D $ENV{'BASEDIR'}; =20 -# Load configuration file (General::readhash isn't available yet) +# Load configuration file (Header::_read_manualpage_hash() isn't available y= et) my $configfile =3D "${basedir}/config/cfgroot/manualpages"; my %manualpages =3D (); =20 open(my $file, "<", $configfile) or die "ERROR: Can't read from file '$confi= gfile'!\n"; while(my $line =3D <$file>) { - $line =3D~ s/\R//g; - next unless($line =3D~ /=3D/); + chomp($line); + next if(substr($line, 0, 1) eq '#'); # Skip comments + next if(index($line, '=3D', 1) =3D=3D -1); # Skip incomplete lines =20 my($left, $value) =3D split(/=3D/, $line, 2); - if($left =3D~ /(^[A-Za-z0-9_-]+$)/) { - my $key =3D $1; # Got alphanumeric key + if($left =3D~ /^([[:alnum:]\/._-]+)$/) { + my $key =3D $1; $manualpages{$key} =3D $value; } } @@ -55,11 +56,11 @@ if ($baseurl =3D~ /\/\s*$/) { =20 # Loop trough configured manual pages foreach my $page (keys %manualpages) { - # Build absolute path and URL - my $cgifile =3D "${basedir}/html/cgi-bin/${page}.cgi"; + # Build absolute path (inside cgi-bin) and URL + my $cgifile =3D "${basedir}/html/cgi-bin/${page}"; my $url =3D "${baseurl}/$manualpages{$page}"; =20 - print "${page}.cgi -> '$url'\n"; + print "cgi-bin/${page} -> '$url'\n"; =20 # Check CGI file exists if(! -f $cgifile) { --=20 2.27.0.windows.1 --===============1402546899139351791==--