1#! /usr/bin/perl -w
2
3use strict;
4
5my $conf__num_max = (256 * 256 * 256) - 2;
6
7use Getopt::Long;
8use Pod::Usage;
9
10my $man = 0;
11my $help = 0;
12
13my $conf_num = 10_000;
14my $conf_policy = 0;
15my $conf_reverse = 0;
16
17GetOptions ("number=i" => \$conf_num,
18	    "policy!"  => \$conf_policy,
19	    "reverse!" => \$conf_reverse,
20            "help|?"   => \$help,
21            "man"      => \$man);
22pod2usage(-exitstatus => 0, -verbose => 1) if $help;
23pod2usage(-exitstatus => 0, -verbose => 2) if $man;
24
25if (($conf_num < 0) || ($conf_num > $conf__num_max))
26  { die "Invalid number of statements."; }
27
28print <<EOL;
29(org.and.jhttpd-conf-main-1.0
30
31  (org.and.daemon-conf-1.0
32; Listen on test port/address
33    (listen
34      (port 8008))
35
36    (cntl-file jhttpd_cntl) ; Allow simple shutdown
37
38    (idle-timeout 32)
39    (procs 4))
40
41  (policy <default>
42    (document-root html)
43    (request-configuration-directory conf))
44  (policy foo [(inherit <default>)]
45    (server-name "Default/1 (jhttpd)"))
46
47EOL
48
49my @nums = (1..$conf_num);
50if ($conf_reverse)
51{ @nums = reverse @nums; }
52
53for (@nums)
54  {
55    my $num = int($_);
56    # convert num to 127.* ip
57    my @ips = ();
58    push @ips, int($num % 256); $num /= 256;
59    push @ips, int($num % 256); $num /= 256;
60    push @ips, int($num % 256); $num /= 256;
61
62    if ($conf_policy)
63      {
64print <<EOL;
65  (policy foo$_ [(inherit <default>)]
66    (server-name "Huge/$_ (jhttpd)"))
67  (match-connection [(client-ipv4-cidr-eq 127.$ips[2].$ips[1].$ips[0])]
68    (policy foo$_))
69
70EOL
71     }
72    else
73      {
74print <<EOL;
75  (match-connection [(client-ipv4-cidr-eq 127.$ips[2].$ips[1].$ips[0])]
76    (policy foo))
77EOL
78     }
79}
80
81print <<EOL;
82 ; Close the rest...
83  (match-connection [(policy-eq <default>)] <close>))
84EOL
85
86__END__
87
88=head1 NAME
89
90gen_huge_httpd_conf.pl - Generates huge config. files for jhttpd
91
92=head1 SYNOPSIS
93
94gen_huge_httpd_conf.pl [options]
95
96 Options:
97  --help -?         brief help message
98  --man             full documentation
99  --policy          Create a new policy for each match-request
100  --number          Number of match-requests to make
101
102
103=cut
104