]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - tools/check_manualpages.pl
Merge branch 'master' into next
[people/pmueller/ipfire-2.x.git] / tools / check_manualpages.pl
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2021 IPFire Team #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23 #use warnings;
24
25 # Import make.sh environment
26 my $basedir = $ENV{'BASEDIR'};
27
28 # Load configuration file (General::readhash isn't available yet)
29 my $configfile = "${basedir}/config/cfgroot/manualpages";
30 my %manualpages = ();
31
32 open(my $file, "<", $configfile) or die "ERROR: Can't read from file '$configfile'!\n";
33 while(my $line = <$file>) {
34 $line =~ s/\R//g;
35 next unless($line =~ /=/);
36
37 my($left, $value) = split(/=/, $line, 2);
38 if($left =~ /(^[A-Za-z0-9_-]+$)/) {
39 my $key = $1; # Got alphanumeric key
40 $manualpages{$key} = $value;
41 }
42 }
43 close($file);
44
45 # Check configuration
46 if(! defined $manualpages{'BASE_URL'}) {
47 die "ERROR: User manual base URL not configured!\n";
48 }
49 my $baseurl = $manualpages{'BASE_URL'};
50 delete $manualpages{'BASE_URL'};
51
52 if ($baseurl =~ /\/\s*$/) {
53 die "ERROR: User manual base URL must not end with a slash!\n";
54 }
55
56 # Loop trough configured manual pages
57 foreach my $page (keys %manualpages) {
58 # Build absolute path and URL
59 my $cgifile = "${basedir}/html/cgi-bin/${page}.cgi";
60 my $url = "${baseurl}/$manualpages{$page}";
61
62 print "${page}.cgi -> '$url'\n";
63
64 # Check CGI file exists
65 if(! -f $cgifile) {
66 print "WARNING: Obsolete link, page '$cgifile' doesn't exist!\n";
67 }
68
69 # Check obvious invalid characters
70 if($url =~ /[^[:graph:]]/) {
71 die("ERROR: URL contains invalid characters!\n");
72 }
73
74 # Check HTTP 200 "OK" result, follow up to 1 redirect (e.g. HTTP -> HTTPS)
75 my $status = `curl --silent --show-error --output /dev/null --location --max-redirs 1 --max-time 10 --write-out "%{http_code}" --url "${url}"`;
76 if($status != 200) {
77 die("ERROR: Received unexpected HTTP '$status'!\n");
78 }
79
80 print "SUCCESS: Received HTTP '$status'.\n";
81 }
82
83 # Clean exit
84 exit 0;