]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - tools/check_manualpages.pl
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / tools / check_manualpages.pl
CommitLineData
4edcd4b2
LAH
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
22use strict;
23#use warnings;
24
25# Import make.sh environment
26my $basedir = $ENV{'BASEDIR'};
27
64db1faf 28# Load configuration file (Header::_read_manualpage_hash() isn't available yet)
4edcd4b2
LAH
29my $configfile = "${basedir}/config/cfgroot/manualpages";
30my %manualpages = ();
31
32open(my $file, "<", $configfile) or die "ERROR: Can't read from file '$configfile'!\n";
33while(my $line = <$file>) {
64db1faf
LAH
34 chomp($line);
35 next if(substr($line, 0, 1) eq '#'); # Skip comments
36 next if(index($line, '=', 1) == -1); # Skip incomplete lines
4edcd4b2
LAH
37
38 my($left, $value) = split(/=/, $line, 2);
64db1faf
LAH
39 if($left =~ /^([[:alnum:]\/._-]+)$/) {
40 my $key = $1;
4edcd4b2
LAH
41 $manualpages{$key} = $value;
42 }
43}
44close($file);
45
46# Check configuration
47if(! defined $manualpages{'BASE_URL'}) {
48 die "ERROR: User manual base URL not configured!\n";
49}
50my $baseurl = $manualpages{'BASE_URL'};
51delete $manualpages{'BASE_URL'};
52
53if ($baseurl =~ /\/\s*$/) {
54 die "ERROR: User manual base URL must not end with a slash!\n";
55}
56
57# Loop trough configured manual pages
58foreach my $page (keys %manualpages) {
64db1faf
LAH
59 # Build absolute path (inside cgi-bin) and URL
60 my $cgifile = "${basedir}/html/cgi-bin/${page}";
4edcd4b2 61 my $url = "${baseurl}/$manualpages{$page}";
66c36198 62
64db1faf 63 print "cgi-bin/${page} -> '$url'\n";
4edcd4b2
LAH
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 }
66c36198 80
4edcd4b2
LAH
81 print "SUCCESS: Received HTTP '$status'.\n";
82}
83
84# Clean exit
85exit 0;