]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
make.sh: Add check-manualpages function
authorLeo-Andres Hofmann <hofmann@leo-andres.de>
Tue, 28 Sep 2021 11:09:05 +0000 (13:09 +0200)
committerPeter Müller <peter.mueller@ipfire.org>
Fri, 19 Nov 2021 06:18:25 +0000 (07:18 +0100)
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>
Reviewed-by: Bernhard Bitsch <bbitsch@ipfire.org>
make.sh
tools/check_manualpages.pl [new file with mode: 0644]

diff --git a/make.sh b/make.sh
index e26753f4e006545227e9e053f223ac8e9fb1b138..1983024ae12d55074a462be5883c9830c9a0b988 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -1961,8 +1961,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 (file)
index 0000000..8eefc63
--- /dev/null
@@ -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;