Handle hostnames with upper-case letters
[webmin.git] / apache / mod_actions.pl
1 # mod_actions.pl
2 # Defines editors for CGI actions
3
4 sub mod_actions_directives
5 {
6 $rv = [ [ 'Action', 1, 11, 'virtual directory htaccess', undef, 5 ],
7         [ 'Script', 1, 11, 'virtual directory' ] ];
8 return &make_directives($rv, $_[0], "mod_actions");
9 }
10
11 sub mod_actions_handlers
12 {
13 local($d, @rv);
14 foreach $d (&find_all_directives($_[0], "Action")) {
15         if ($d->{'words'}->[0] =~ /^[A-z0-9\-\_]+$/) {
16                 push(@rv, $d->{'words'}->[0]);
17                 }
18         }
19 return @rv;
20 }
21
22 sub edit_Action
23 {
24 local($rv, $len, $i, $type, $cgi);
25 $rv = "<table border>\n".
26       "<tr $tb> <td><b>$text{'mod_actions_mime'}</b></td> <td><b>$text{'mod_actions_cgiurl'}</b></td> </tr>";
27 $len = @{$_[0]}+1;
28 for($i=0; $i<$len; $i++) {
29         if ($_[0]->[$i]->{'value'} =~ /^(\S+)\s+(\S+)$/) {
30                 $type = $1; $cgi = $2;
31                 }
32         else { $type = $cgi = ""; }
33         $rv .= "<tr $cb>\n";
34         $rv .= "<td><input name=Action_type_$i size=20 value=\"$type\"></td>\n";
35         $rv .= "<td><input name=Action_cgi_$i size=40 value=\"$cgi\"></td>\n";
36         $rv .= "</tr>\n";
37         }
38 $rv .= "</table>\n";
39 return (2, "$text{'mod_actions_mimecgi'}", $rv);
40 }
41 sub save_Action
42 {
43 local($i, $cgi, $type, @rv);
44 for($i=0; defined($in{"Action_type_$i"}); $i++) {
45         $type = $in{"Action_type_$i"}; $cgi = $in{"Action_cgi_$i"};
46         if ($type !~ /\S/ && $cgi !~ /\S/) { next; }
47         $type =~ /^(\S+)$/ || &error(&text('mod_actions_emime', $type));
48         $cgi =~ /^\/(\S+)$/ || &error(&text('mod_actions_ecgi', $cgi));
49         push(@rv, "$type $cgi");
50         }
51 return ( \@rv );
52 }
53
54 sub edit_Script
55 {
56 local($rv, $len, $i, $meth, $cgi, $m, $found);
57 $rv = "<table border>\n".
58       "<tr $tb> <td><b>$text{'mod_actions_http'}</b></td> <td><b>$text{'mod_actions_cgi'}</b></td> </tr>";
59 $len = @{$_[0]}+1;
60 for($i=0; $i<$len; $i++) {
61         if ($_[0]->[$i]->{'value'} =~ /^(\S+)\s+(\S+)$/) {
62                 $meth = $1; $cgi = $2;
63                 }
64         else { $meth = $cgi = ""; }
65         $rv .= "<tr $cb><td><select name=Script_meth_$i>\n";
66         foreach $m ("", "GET", "POST", "PUT", "DELETE") {
67                 $rv .= sprintf "<option %s>$m\n", $meth eq $m ? "selected" : "";
68                 $found++ if ($meth eq $m);
69                 }
70         printf "<option selected>$meth\n" if (!$found);
71         $rv .= "</select></td>\n";
72         $rv .= "<td><input name=Script_cgi_$i size=40 value=\"$cgi\"></td>\n";
73         $rv .= "</tr>\n";
74         }
75 $rv .= "</table>\n";
76 return (2, "$text{'mod_actions_httpcgi'}", $rv);
77 }
78 sub save_Script
79 {
80 local($i, @rv, $meth, $cgi);
81 for($i=0; defined($in{"Script_meth_$i"}); $i++) {
82         $meth = $in{"Script_meth_$i"}; $cgi = $in{"Script_cgi_$i"};
83         if (!$meth && $cgi !~ /\S/) { next; }
84         $meth || &error(&text('mod_actions_enometh', $cgi));
85         $cgi =~ /^\/(\S+)$/ || &error(&text('mod_actions_ecgi', $cgi));
86         push(@rv, "$meth $cgi");
87         }
88 return ( \@rv );
89 }
90
91 1;
92