]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - tools/check_manualpages.pl
suricata: Change midstream policy to "pass-flow"
[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 (Header::_read_manualpage_hash() 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 chomp($line);
35 next if(substr($line, 0, 1) eq '#'); # Skip comments
36 next if(index($line, '=', 1) == -1); # Skip incomplete lines
37
38 my($left, $value) = split(/=/, $line, 2);
39 if($left =~ /^([[:alnum:]\/._-]+)$/) {
40 my $key = $1;
41 $manualpages{$key} = $value;
42 }
43 }
44 close($file);
45
46 # Check configuration
47 if(! defined $manualpages{'BASE_URL'}) {
48 die "ERROR: User manual base URL not configured!\n";
49 }
50 my $baseurl = $manualpages{'BASE_URL'};
51 delete $manualpages{'BASE_URL'};
52
53 if ($baseurl =~ /\/\s*$/) {
54 die "ERROR: User manual base URL must not end with a slash!\n";
55 }
56
57 # Loop trough configured manual pages
58 foreach my $page (keys %manualpages) {
59 # Build absolute path (inside cgi-bin) and URL
60 my $cgifile = "${basedir}/html/cgi-bin/${page}";
61 my $url = "${baseurl}/$manualpages{$page}";
62
63 print "cgi-bin/${page} -> '$url'\n";
64
65 # Check CGI file exists
66 if(! -f $cgifile) {
67 print "WARNING: Obsolete link, page '$cgifile' doesn't exist!\n";
68 }
69
70 # Check obvious invalid characters
71 if($url =~ /[^[:graph:]]/) {
72 die("ERROR: URL contains invalid characters!\n");
73 }
74
75 # Check HTTP 200 "OK" result, follow up to 1 redirect (e.g. HTTP -> HTTPS)
76 my $status = `curl --silent --show-error --output /dev/null --location --max-redirs 1 --max-time 10 --write-out "%{http_code}" --url "${url}"`;
77 if($status != 200) {
78 die("ERROR: Received unexpected HTTP '$status'!\n");
79 }
80
81 print "SUCCESS: Received HTTP '$status'.\n";
82 }
83
84 # Clean exit
85 exit 0;