Handle hostnames with upper-case letters
[webmin.git] / useradmin / acl_security.pl
1
2 require 'user-lib.pl';
3
4 # acl_security_form(&options)
5 # Output HTML for editing security options for the useradmin module
6 sub acl_security_form
7 {
8 local $o = $_[0];
9
10 print "<tr> <td valign=top><b>$text{'acl_uedit'}</b></td> <td colspan=3>\n";
11 printf "<input type=radio name=uedit_mode value=0 %s> $text{'acl_uedit_all'}&nbsp;&nbsp;\n",
12         $o->{'uedit_mode'} == 0 ? "checked" : "";
13 printf "<input type=radio name=uedit_mode value=1 %s> $text{'acl_uedit_none'}&nbsp;\n",
14         $o->{'uedit_mode'} == 1 ? "checked" : "";
15 printf "<input type=radio name=uedit_mode value=6 %s> $text{'acl_uedit_this'}<br>\n",
16         $o->{'uedit_mode'} == 6 ? "checked" : "";
17 printf "<input type=radio name=uedit_mode value=2 %s> $text{'acl_uedit_only'}\n",
18         $o->{'uedit_mode'} == 2 ? "checked" : "";
19 printf "<input name=uedit_can size=40 value='%s'> %s<br>\n",
20         $o->{'uedit_mode'} == 2 ? $o->{'uedit'} : "",
21         &user_chooser_button("uedit_can", 1);
22 printf "<input type=radio name=uedit_mode value=3 %s> $text{'acl_uedit_except'}\n",
23         $o->{'uedit_mode'} == 3 ? "checked" : "";
24 printf "<input name=uedit_cannot size=40 value='%s'> %s<br>\n",
25         $o->{'uedit_mode'} == 3 ? $o->{'uedit'} : "",
26         &user_chooser_button("uedit_cannot", 1);
27 printf "<input type=radio name=uedit_mode value=4 %s> $text{'acl_uedit_uid'}\n",
28         $o->{'uedit_mode'} == 4 ? "checked" : "";
29 printf "<input name=uedit_uid size=6 value='%s'> - \n",
30         $o->{'uedit_mode'} == 4 ? $o->{'uedit'} : "";
31 printf "<input name=uedit_uid2 size=6 value='%s'><br>\n",
32         $o->{'uedit_mode'} == 4 ? $o->{'uedit2'} : "";
33 printf "<input type=radio name=uedit_mode value=5 %s> $text{'acl_uedit_group'}\n",
34         $o->{'uedit_mode'} == 5 ? "checked" : "";
35 printf "<input name=uedit_group size=40 value='%s'> %s<br>\n",
36         $o->{'uedit_mode'} == 5 ?
37          join(" ", map { "".&my_getgrgid($_) } split(/\s+/, $o->{'uedit'})) :"",
38         &group_chooser_button("uedit_group", 1);
39 printf "%s <input type=checkbox name=uedit_sec value=1 %s> %s<br>\n",
40         "&nbsp;" x 5, $o->{'uedit_sec'} ? 'checked' : '',$text{'acl_uedit_sec'};
41 printf "<input type=radio name=uedit_mode value=7 %s> $text{'acl_uedit_re'}\n",
42         $o->{'uedit_mode'} == 7 ? "checked" : "";
43 printf "<input name=uedit_re size=40 value='%s'> %s<br>\n",
44         $o->{'uedit_mode'} == 7 ? $o->{'uedit_re'} : "";
45 print "</td> </tr>\n";
46
47 print "<tr> <td><b>$text{'acl_ucreate'}</b></td> <td>\n";
48 printf "<input type=radio name=ucreate value=1 %s> $text{'yes'}\n",
49         $o->{'ucreate'} ? "checked" : "";
50 printf "<input type=radio name=ucreate value=0 %s> $text{'no'}</td> </tr>\n",
51         $o->{'ucreate'} ? "" : "checked";
52
53 print "<tr> <td><b>$text{'acl_batch'}</b></td> <td>\n";
54 printf "<input type=radio name=batch value=1 %s> $text{'yes'}\n",
55         $o->{'batch'} ? "checked" : "";
56 printf "<input type=radio name=batch value=0 %s> $text{'no'}</td> </tr>\n",
57         $o->{'batch'} ? "" : "checked";
58
59 print "<tr> <td><b>$text{'acl_export'}</b></td> <td colspan=3>\n";
60 printf "<input type=radio name=export value=2 %s> $text{'yes'}\n",
61         $o->{'export'} == 2 ? "checked" : "";
62 printf "<input type=radio name=export value=1 %s> $text{'acl_export1'}\n",
63         $o->{'export'} == 1 ? "checked" : "";
64 printf "<input type=radio name=export value=0 %s> $text{'no'}</td> </tr>\n",
65         $o->{'export'} == 0 ? "checked" : "";
66
67 print "<tr> <td valign=top><b>$text{'acl_uid'}</b></td>\n";
68 print "<td colspan=3><input name=lowuid size=6 value='$o->{'lowuid'}'> -\n";
69 print "<input name=hiuid size=6 value='$o->{'hiuid'}'><br>\n";
70 printf "<input type=checkbox name=autouid value=1 %s> %s<br>\n",
71         $o->{'autouid'} ? "checked" : "", $text{'acl_autouid'};
72 printf "<input type=checkbox name=calcuid value=1 %s> %s<br>\n",
73         $o->{'calcuid'} ? "checked" : "", $text{'acl_calcuid'};
74 printf "<input type=checkbox name=useruid value=1 %s> %s<br>\n",
75         $o->{'useruid'} ? "checked" : "", $text{'acl_useruid'};
76 printf "<input type=checkbox name=umultiple value=1 %s> %s<br>\n",
77         $o->{'umultiple'} ? "checked" : "", $text{'acl_umultiple'};
78 printf "<input type=checkbox name=uuid value=1 %s> %s</td> </tr>\n",
79         $o->{'uuid'} ? "checked" : "", $text{'acl_uuid'};
80
81 local $uedit_gmode = defined($o->{'uedit_gmode'}) ? $o->{'uedit_gmode'} :
82                      $o->{'ugroups'} eq '*' ? 0 : 2;
83 print "<tr> <td valign=top><b>$text{'acl_ugroups'}</b></td> <td colspan=3>\n";
84 printf "<input type=radio name=uedit_gmode value=0 %s> $text{'acl_gedit_all'}<br>\n",
85         $uedit_gmode == 0 ? "checked" : "";
86 printf "<input type=radio name=uedit_gmode value=2 %s> $text{'acl_gedit_only'}\n",
87         $uedit_gmode == 2 ? "checked" : "";
88 printf "<input name=uedit_gcan size=40 value='%s'> %s<br>\n",
89         $uedit_gmode == 2 ? $o->{'ugroups'} : "",
90         &group_chooser_button("uedit_gcan", 1);
91 printf "<input type=radio name=uedit_gmode value=3 %s> $text{'acl_gedit_except'}\n",
92         $uedit_gmode == 3 ? "checked" : "";
93 printf "<input name=uedit_gcannot size=40 value='%s'> %s<br>\n",
94         $uedit_gmode == 3 ? $o->{'ugroups'} : "",
95         &group_chooser_button("uedit_gcannot", 1);
96 printf "<input type=radio name=uedit_gmode value=4 %s> $text{'acl_gedit_gid'}\n",
97         $uedit_gmode == 4 ? "checked" : "";
98 printf "<input name=uedit_gid size=6 value='%s'> -\n",
99         $uedit_gmode == 4 ? $o->{'ugroups'} : "";
100 printf "<input name=uedit_gid2 size=6 value='%s'></td> </tr>\n",
101         $uedit_gmode == 4 ? $o->{'ugroups2'} : "";
102
103 print "<tr> <td valign=top><b>$text{'acl_shells'}</b></td> <td colspan=3>\n";
104 printf "<input type=radio name=shells_def value=1 %s> $text{'acl_any'}\n",
105         $o->{'shells'} eq "*" ? "checked" : "";
106 printf "<input type=radio name=shells_def value=0 %s> $text{'acl_listed'}<br>\n",
107         $o->{'shells'} eq "*" ? "" : "checked";
108 print "<textarea name=shells rows=3 cols=40>",
109         $o->{'shells'} eq "*" ? "" : join("\n", split(/\s+/, $o->{'shells'})),
110         "</textarea></td> </tr>\n";
111
112 print "<tr> <td><b>$text{'acl_epeopt'}</b></td> <td>\n";
113 printf "<input type=radio name=peopt value=1 %s> $text{'yes'}\n",
114         $o->{'peopt'} ? "checked" : "";
115 printf "<input type=radio name=peopt value=0 %s> $text{'no'}</td> </tr>\n",
116         $o->{'peopt'} ? "" : "checked";
117
118 print "<tr> <td valign=top><b>$text{'acl_home'}</b></td>\n";
119 printf "<td colspan=3><input name=home size=40 value='%s'> %s<br>\n",
120         $o->{'home'}, &file_chooser_button("home", 1);
121 printf "<input type=checkbox name=autohome value=1 %s> %s</td> </tr>\n",
122         $o->{'autohome'} ? "checked" : "",
123         $text{'acl_autohome'};
124
125 print "<tr> <td><b>$text{'acl_udelete'}</b></td> <td>\n";
126 printf "<input type=radio name=udelete value=1 %s> $text{'yes'}\n",
127         $o->{'udelete'} ? "checked" : "";
128 printf "<input type=radio name=udelete value=0 %s> $text{'no'}</td> </tr>\n",
129         $o->{'udelete'} ? "" : "checked";
130
131 print "<tr> <td><b>$text{'acl_urename'}</b></td> <td>\n";
132 printf "<input type=radio name=urename value=1 %s> $text{'yes'}\n",
133         $o->{'urename'} ? "checked" : "";
134 printf "<input type=radio name=urename value=0 %s> $text{'no'}</td> </tr>\n",
135         $o->{'urename'} ? "" : "checked";
136
137 print "<tr> <td valign=top><b>$text{'acl_delhome'}</b></td>\n";
138 print "<td colspan=3>",&ui_radio("delhome", $o->{'delhome'},
139                           [ [ 2, $text{'acl_option'} ],
140                             [ 1, $text{'acl_always'} ],
141                             [ 0, $text{'acl_never'} ] ]),"</td> </tr>\n";
142
143 # 0 = always on, 1 = can edit, 2 = always off
144 print "<tr> <td valign=top><b>$text{'acl_saveopts'}</b></td> ",
145       "<td colspan=3><table>\n";
146 foreach $opt ('chuid', 'chgid', 'movehome', 'mothers',
147               'makehome', 'copy', 'cothers', 'dothers') {
148         print "<tr> <td>",$text{"uedit_$opt"},"</td>\n";
149         printf "<td><input type=radio name=$opt value=1 %s> %s\n",
150                 $o->{$opt} == 1 ? "checked" : "", $text{'acl_canedit'};
151         printf "<input type=radio name=$opt value=0 %s> %s\n",
152                 $o->{$opt} == 0 ? "checked" : "", $text{'acl_on'};
153         printf "<input type=radio name=$opt value=2 %s> %s</td> </tr>\n",
154                 $o->{$opt} == 2 ? "checked" : "", $text{'acl_off'};
155         }
156 print "</table></td> </tr>\n";
157
158 print "<tr> <td colspan=4><hr></td> </tr>\n";
159
160 print "<tr> <td valign=top><b>$text{'acl_gedit'}</b></td> <td colspan=3>\n";
161 printf "<input type=radio name=gedit_mode value=0 %s> $text{'acl_gedit_all'}&nbsp;&nbsp;\n",
162         $o->{'gedit_mode'} == 0 ? "checked" : "";
163 printf "<input type=radio name=gedit_mode value=1 %s> $text{'acl_gedit_none'}<br>\n",
164         $o->{'gedit_mode'} == 1 ? "checked" : "";
165 printf "<input type=radio name=gedit_mode value=2 %s> $text{'acl_gedit_only'}\n",
166         $o->{'gedit_mode'} == 2 ? "checked" : "";
167 printf "<input name=gedit_can size=40 value='%s'> %s<br>\n",
168         $o->{'gedit_mode'} == 2 ? $o->{'gedit'} : "",
169         &group_chooser_button("gedit_can", 1);
170 printf "<input type=radio name=gedit_mode value=3 %s> $text{'acl_gedit_except'}\n",
171         $o->{'gedit_mode'} == 3 ? "checked" : "";
172 printf "<input name=gedit_cannot size=40 value='%s'> %s<br>\n",
173         $o->{'gedit_mode'} == 3 ? $o->{'gedit'} : "",
174         &group_chooser_button("gedit_cannot", 1);
175 printf "<input type=radio name=gedit_mode value=4 %s> $text{'acl_gedit_gid'}\n",
176         $o->{'gedit_mode'} == 4 ? "checked" : "";
177 printf "<input name=gedit_gid size=6 value='%s'> -\n",
178         $o->{'gedit_mode'} == 4 ? $o->{'gedit'} : "";
179 printf "<input name=gedit_gid2 size=6 value='%s'></td> </tr>\n",
180         $o->{'gedit_mode'} == 4 ? $o->{'gedit2'} : "";
181
182 print "<tr> <td><b>$text{'acl_gcreate'}</b></td> <td colspan=3>\n";
183 printf "<input type=radio name=gcreate value=1 %s> $text{'yes'}\n",
184         $o->{'gcreate'}==1 ? "checked" : "";
185 printf "<input type=radio name=gcreate value=2 %s> $text{'acl_gnew'}\n",
186         $o->{'gcreate'}==2 ? "checked" : "";
187 printf "<input type=radio name=gcreate value=0 %s> $text{'no'}</td> </tr>\n",
188         $o->{'gcreate'}==0 ? "checked" : "";
189
190 print "<tr> <td valign=top><b>$text{'acl_gid'}</b></td>\n";
191 print "<td colspan=3><input name=lowgid size=6 value='$o->{'lowgid'}'> -\n";
192 print "<input name=higid size=6 value='$o->{'higid'}'><br>\n";
193 printf "<input type=checkbox name=autogid value=1 %s> %s<br>\n",
194         $o->{'autogid'} ? "checked" : "", $text{'acl_autogid'};
195 printf "<input type=checkbox name=calcgid value=1 %s> %s<br>\n",
196         $o->{'calcgid'} ? "checked" : "", $text{'acl_calcgid'};
197 printf "<input type=checkbox name=usergid value=1 %s> %s<br>\n",
198         $o->{'usergid'} ? "checked" : "", $text{'acl_usergid'};
199 printf "<input type=checkbox name=gmultiple value=1 %s> %s<br>\n",
200         $o->{'gmultiple'} ? "checked" : "", $text{'acl_gmultiple'};
201 printf "<input type=checkbox name=ggid value=1 %s> %s</td> </tr>\n",
202         $o->{'ggid'} ? "checked" : "", $text{'acl_ggid'};
203
204 print "<tr> <td><b>$text{'acl_gdelete'}</b></td> <td>\n";
205 printf "<input type=radio name=gdelete value=1 %s> $text{'yes'}\n",
206         $o->{'gdelete'} ? "checked" : "";
207 printf "<input type=radio name=gdelete value=0 %s> $text{'no'}</td> </tr>\n",
208         $o->{'gdelete'} ? "" : "checked";
209
210 print "<tr> <td colspan=4><hr></td> </tr>\n";
211
212 print "<tr><td valign=top><b>$text{'acl_logins'}</b></td> <td colspan=3>\n";
213 printf "<input type=radio name=logins_mode value=0 %s> $text{'acl_lnone'}<br>\n",
214         $o->{'logins'} ? "" : "checked";
215 printf "<input type=radio name=logins_mode value=1 %s> $text{'acl_lall'}<br>\n",
216         $o->{'logins'} eq "*" ? "checked" : "";
217 printf "<input type=radio name=logins_mode value=2 %s>\n",
218         $o->{'logins'} =~ /[^\*]/ ? "checked" : "";
219 printf "<input name=logins size=40 value='%s'> %s</td> </tr>\n",
220         $o->{'logins'} =~ /[^\*]/ ? $o->{'logins'} : "",
221         &user_chooser_button("logins", 1);
222 }
223
224 # acl_security_save(&options)
225 # Parse the form for security options for the useradmin module
226 sub acl_security_save
227 {
228 $_[0]->{'lowuid'} = $in{'lowuid'};
229 $_[0]->{'hiuid'} = $in{'hiuid'};
230 $_[0]->{'autouid'} = $in{'autouid'};
231 $_[0]->{'autogid'} = $in{'autogid'};
232 $_[0]->{'calcuid'} = $in{'calcuid'};
233 $_[0]->{'calcgid'} = $in{'calcgid'};
234 $_[0]->{'useruid'} = $in{'useruid'};
235 $_[0]->{'usergid'} = $in{'usergid'};
236 $_[0]->{'lowgid'} = $in{'lowgid'};
237 $_[0]->{'higid'} = $in{'higid'};
238 $_[0]->{'uedit_mode'} = $in{'uedit_mode'};
239 $_[0]->{'uedit'} = $in{'uedit_mode'} == 2 ? $in{'uedit_can'} :
240                    $in{'uedit_mode'} == 3 ? $in{'uedit_cannot'} :
241                    $in{'uedit_mode'} == 4 ? $in{'uedit_uid'} :
242                    $in{'uedit_mode'} == 5 ?
243                         join(" ", map { "".&my_getgrnam($_) }
244                              split(/\s+/, $in{'uedit_group'})) : "";
245 $_[0]->{'uedit2'} = $in{'uedit_mode'} == 4 ? $in{'uedit_uid2'} : undef;
246 $_[0]->{'uedit_sec'} = $in{'uedit_mode'} == 5 ? $in{'uedit_sec'} : undef;
247 $_[0]->{'uedit_re'} = $in{'uedit_mode'} == 7 ? $in{'uedit_re'} : undef;
248 $_[0]->{'gedit_mode'} = $in{'gedit_mode'};
249 $_[0]->{'gedit'} = $in{'gedit_mode'} == 2 ? $in{'gedit_can'} :
250                    $in{'gedit_mode'} == 3 ? $in{'gedit_cannot'} :
251                    $in{'gedit_mode'} == 4 ? $in{'gedit_gid'} : "";
252 $_[0]->{'gedit2'} = $in{'gedit_mode'} == 4 ? $in{'gedit_gid2'} : undef;
253 $_[0]->{'ucreate'} = $in{'ucreate'};
254 $_[0]->{'gcreate'} = $in{'gcreate'};
255 if ($in{'uedit_gmode'} == 0) {
256         delete($_[0]->{'uedit_gmode'});
257         $_[0]->{'ugroups'} = "*";
258         }
259 elsif ($in{'uedit_gmode'} == 2) {
260         delete($_[0]->{'uedit_gmode'});
261         $_[0]->{'ugroups'} = $in{'uedit_gcan'};
262         }
263 else {
264         $_[0]->{'uedit_gmode'} = $in{'uedit_gmode'};
265         $_[0]->{'ugroups'} = $in{'uedit_gmode'} == 3 ? $in{'uedit_gcannot'} :
266                              $in{'uedit_gmode'} == 4 ? $in{'uedit_gid'} : "";
267         }
268 $_[0]->{'ugroups2'} = $in{'uedit_gmode'} == 4 ? $in{'uedit_gid2'} : undef;
269
270 $_[0]->{'logins'} = $in{'logins_mode'} == 0 ? "" :
271                     $in{'logins_mode'} == 1 ? "*" : $in{'logins'};
272 $_[0]->{'shells'} = $in{'shells_def'} ? "*"
273                                       : join(" ", split(/\s+/, $in{'shells'}));
274 $_[0]->{'peopt'} = $in{'peopt'};
275 $_[0]->{'batch'} = $in{'batch'};
276 $_[0]->{'export'} = $in{'export'};
277 $_[0]->{'home'} = $in{'home'};
278 $_[0]->{'delhome'} = $in{'delhome'};
279 $_[0]->{'autohome'} = $in{'autohome'};
280 $_[0]->{'umultiple'} = $in{'umultiple'};
281 $_[0]->{'uuid'} = $in{'uuid'};
282 $_[0]->{'gmultiple'} = $in{'gmultiple'};
283 $_[0]->{'ggid'} = $in{'ggid'};
284 foreach $o ('chuid', 'chgid', 'movehome', 'mothers',
285             'makehome', 'copy', 'cothers', 'dothers') {
286         $_[0]->{$o} = $in{$o};
287         }
288 $_[0]->{'udelete'} = $in{'udelete'};
289 $_[0]->{'urename'} = $in{'urename'};
290 $_[0]->{'gdelete'} = $in{'gdelete'};
291 }
292