2 # Defines editors for host restriction directives
4 sub mod_access_directives
7 $rv = [ [ 'allow deny order', 1, 4, 'directory htaccess' ] ];
8 return &make_directives($rv, $_[0], "mod_access");
11 sub edit_allow_deny_order
13 local($d, @w, $i, @type, @mode, @what, $rv);
14 foreach $d (@{$_[0]}, @{$_[1]}) {
15 @w = split(/\s+/, $d->{'value'});
16 for($i=1; $i<@w; $i++) {
17 push(@type, lc($d->{'name'}) eq "allow" ? 1 : 2);
19 if ($w[$i] =~ /^env=(\S+)$/) {
23 elsif ($w[$i] =~ /^[0-9\.]+\/[0-9]+$/) { push(@mode, 5); }
24 elsif ($w[$i] =~ /^[0-9\.]+\/[0-9\.]+$/) { push(@mode, 4); }
25 elsif ($w[$i] =~ /^\d+\.\d+\.\d+\.\d+$/) { push(@mode, 2); }
26 elsif ($w[$i] =~ /^[0-9\.]+$/) { push(@mode, 3); }
27 elsif ($w[$i] eq "all") { push(@mode, 0); }
28 else { push(@mode, 1); }
31 push(@type, ""); push(@what, ""); push(@mode, 0);
32 $rv = "<i>$text{'mod_access_order'}</i>\n".
33 &choice_input($_[2]->[0]->{'value'}, "order", "",
34 "$text{'mod_access_denyallow'},deny,allow", "$text{'mod_access_allowdeny'},allow,deny",
35 "$text{'mod_access_mutual'},mutual-failure", "$text{'mod_access_default'},")."<br>\n";
36 $rv .= "<table border>\n".
37 "<tr $tb> <td><b>$text{'mod_access_action'}</b></td> <td><b>$text{'mod_access_cond'}</b></td> </tr>\n";
38 @sels = ("$text{'mod_access_all'},0", "$text{'mod_access_host'},1",
39 "$text{'mod_access_ip'},2", "$text{'mod_access_pip'},3");
40 if ($_[3]->{'version'} >= 1.3) {
41 push(@sels, "$text{'mod_access_mask'},4",
42 "$text{'mod_access_cidr'},5");
44 if ($_[3]->{'version'} >= 1.2) {
45 push(@sels, "$text{'mod_access_var'},6");
47 for($i=0; $i<@type; $i++) {
48 $rv .= "<tr $cb> <td>".&select_input($type[$i], "allow_type_$i", "",
49 ",0", "$text{'mod_access_allow'},1", "$text{'mod_access_deny'},2")."</td>\n";
50 $rv .= "<td>".&select_input($mode[$i], "allow_mode_$i", "0", @sels);
51 $rv .= sprintf "<input name=allow_what_$i size=20 value=\"%s\"></td>\n",
52 $mode[$i] ? $what[$i] : "";
56 return (2, "$text{'mod_access_restr'}", $rv);
58 sub save_allow_deny_order
60 local($i, $type, $mode, $what, @allow, @deny);
61 for($i=0; defined($type = $in{"allow_type_$i"}); $i++) {
62 $mode = $in{"allow_mode_$i"}; $what = $in{"allow_what_$i"};
64 if ($mode == 0) { $what = "all"; }
65 elsif ($mode == 2 && !&check_ipaddress($what) &&
66 !&check_ip6address($what)) {
67 &error(&text('mod_access_eip', $what));
69 elsif ($mode == 3 && $what !~ /^[0-9\.]+$/) {
70 &error(&text('mod_access_epip', $what));
72 elsif ($mode == 4 && ($what !~ /^([0-9\.:]+)\/([0-9\.:]+)$/ ||
73 (!&check_ipaddress($1) && !&check_ip6address($1)) ||
74 (!&check_ipaddress($2) && !&check_ip6address($2)))) {
75 &error(&text('mod_access_emask', $what));
77 elsif ($mode == 5 && ($what !~ /^([0-9\.:]+)\/([0-9]+)$/ ||
78 !&check_ipaddress($1) || $2 > 32)) {
79 &error(&text('mod_access_ecidr', $what));
83 &error(&text('mod_access_evar', $what));
86 if ($type == 1) { push(@allow, "from $what"); }
87 else { push(@deny, "from $what"); }
89 return ( \@allow, \@deny, &parse_choice("order", ""));