Reviewed-by: Bernhard Bitsch bbitsch@ipfire.org
Am 28.09.2021 um 13:09 schrieb Leo-Andres Hofmann:
This patch adds a function to verify the user manual links configuration file at build time. Run with "./make.sh check-manualpages"
Signed-off-by: Leo-Andres Hofmann hofmann@leo-andres.de
make.sh | 12 +++++- tools/check_manualpages.pl | 84 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tools/check_manualpages.pl
diff --git a/make.sh b/make.sh index 8b97b24df..370a19aa5 100755 --- a/make.sh +++ b/make.sh @@ -1958,8 +1958,18 @@ find-dependencies) shift exec "${BASEDIR}/tools/find-dependencies" "${BASEDIR}/build" "$@" ;; +check-manualpages)
- echo "Checking the manual pages for broken links..."
- chmod 755 $BASEDIR/tools/check_manualpages.pl
- if $BASEDIR/tools/check_manualpages.pl; then
print_status DONE
- else
print_status FAIL
- fi
- ;; *)
- echo "Usage: $0 {build|changelog|clean|gettoolchain|downloadsrc|shell|sync|toolchain|update-contributors|find-dependencies}"
- echo "Usage: $0 {build|changelog|clean|gettoolchain|downloadsrc|shell|sync|toolchain|update-contributors|find-dependencies|check-manualpages}" cat doc/make.sh-usage ;; esac
diff --git a/tools/check_manualpages.pl b/tools/check_manualpages.pl new file mode 100644 index 000000000..8eefc63e2 --- /dev/null +++ b/tools/check_manualpages.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2005-2021 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +###############################################################################
+use strict; +#use warnings;
+# Import make.sh environment +my $basedir = $ENV{'BASEDIR'};
+# Load configuration file (General::readhash isn't available yet) +my $configfile = "${basedir}/config/cfgroot/manualpages"; +my %manualpages = ();
+open(my $file, "<", $configfile) or die "ERROR: Can't read from file '$configfile'!\n"; +while(my $line = <$file>) {
- $line =~ s/\R//g;
- next unless($line =~ /=/);
- my($left, $value) = split(/=/, $line, 2);
- if($left =~ /(^[A-Za-z0-9_-]+$)/) {
my $key = $1; # Got alphanumeric key
$manualpages{$key} = $value;
- }
+} +close($file);
+# Check configuration +if(! defined $manualpages{'BASE_URL'}) {
- die "ERROR: User manual base URL not configured!\n";
+} +my $baseurl = $manualpages{'BASE_URL'}; +delete $manualpages{'BASE_URL'};
+if ($baseurl =~ //\s*$/) {
- die "ERROR: User manual base URL must not end with a slash!\n";
+}
+# Loop trough configured manual pages +foreach my $page (keys %manualpages) {
- # Build absolute path and URL
- my $cgifile = "${basedir}/html/cgi-bin/${page}.cgi";
- my $url = "${baseurl}/$manualpages{$page}";
- print "${page}.cgi -> '$url'\n";
- # Check CGI file exists
- if(! -f $cgifile) {
print "WARNING: Obsolete link, page '$cgifile' doesn't exist!\n";
- }
- # Check obvious invalid characters
- if($url =~ /[^[:graph:]]/) {
die("ERROR: URL contains invalid characters!\n");
- }
- # Check HTTP 200 "OK" result, follow up to 1 redirect (e.g. HTTP -> HTTPS)
- my $status = `curl --silent --show-error --output /dev/null --location --max-redirs 1 --max-time 10 --write-out "%{http_code}" --url "${url}"`;
- if($status != 200) {
die("ERROR: Received unexpected HTTP '$status'!\n");
- }
- print "SUCCESS: Received HTTP '$status'.\n";
+}
+# Clean exit +exit 0;