Files
bpfire/tools/check_manualpages.pl
Peter Müller 66c3619872 Early spring clean: Remove trailing whitespaces, and correct licence headers
Bumping across one of our scripts with very long trailing whitespaces, I
thought it might be a good idea to clean these up. Doing so, some
missing or inconsistent licence headers were fixed.

There is no need in shipping all these files en bloc, as their
functionality won't change.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
2022-02-18 23:54:57 +00:00

85 lines
3.2 KiB
Perl

#!/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;