Handle hostnames with upper-case letters
[webmin.git] / cluster-useradmin / user_form.cgi
1 #!/usr/local/bin/perl
2 # user_form.cgi
3 # Display a form for creating a new user
4
5 require './cluster-useradmin-lib.pl';
6 require 'timelocal.pl';
7 &ReadParse();
8 &foreign_require("useradmin", "user-lib.pl");
9
10 &ui_print_header(undef, $text{'uedit_title2'}, "");
11 @hosts = &list_useradmin_hosts();
12 @servers = &list_servers();
13
14 # build list of used shells and uids
15 foreach $h (@hosts) {
16         foreach $u (@{$h->{'users'}}) {
17                 push(@shlist, $u->{'shell'}) if ($u->{'shell'});
18                 $used{$u->{'uid'}}++;
19                 }
20         foreach $g (@{$h->{'groups'}}) {
21                 push(@glist, $g) if (!$donegroup{$g->{'group'}}++);
22                 }
23         }
24 open(SHELLS, "/etc/shells");
25 while(<SHELLS>) {
26         s/\r|\n//g;
27         s/#.*$//;
28         push(@shlist, $_) if (/\S/);
29         }
30 close(SHELLS);
31
32 print "<form action=create_user.cgi method=post>\n";
33 print "<table border width=100%>\n";
34 print "<tr $tb> <td><b>$text{'uedit_details'}</b></td> </tr>\n";
35 print "<tr $cb> <td><table width=100%>\n";
36
37 print "<tr> <td><b>$text{'user'}</b></td>\n";
38 print "<td><input name=user size=10></td>\n";
39
40 # Find the first free UID above the base
41 print "<td><b>$text{'uid'}</b></td>\n";
42 $newuid = int($uconfig{'base_uid'});
43 while($used{$newuid}) {
44         $newuid++;
45         }
46 print "<td><input name=uid size=10 value='$newuid'></td> </tr>\n";
47
48 if ($uconfig{'extra_real'}) {
49         print "<tr> <td><b>$text{'real'}</b></td>\n";
50         print "<td><input name=real size=20></td>\n";
51
52         print "<td><b>$text{'office'}</b></td>\n";
53         print "<td><input name=office size=20 value=\"$real[1]\"></td> </tr>\n";
54
55         print "<tr> <td><b>$text{'workph'}</b></td>\n";
56         print "<td><input name=workph size=20></td>\n";
57
58         print "<td><b>$text{'homeph'}</b></td>\n";
59         print "<td><input name=homeph size=20></td> </tr>\n";
60
61         print "<tr> <td><b>$text{'extra'}</b></td>\n";
62         print "<td><input name=extra size=20></td>\n";
63         }
64 else {
65         print "<tr> <td><b>$text{'real'}</b></td>\n";
66         print "<td><input name=real size=20></td>\n";
67         }
68
69 print "<td><b>$text{'home'}</b></td>\n";
70 print "<td>\n";
71 if ($uconfig{'home_base'}) {
72         printf "<input type=radio name=home_base value=1 checked> %s\n",
73                 $text{'uedit_auto'};
74         printf "<input type=radio name=home_base value=0>\n";
75         printf "<input name=home size=25> %s\n",
76                 &file_chooser_button("home", 1);
77         }
78 else {
79         print "<input name=home size=25>\n",
80               &file_chooser_button("home", 1);
81         }
82 print "</td> </tr>\n";
83
84 print "<tr> <td valign=top><b>$text{'shell'}</b></td>\n";
85 print "<td valign=top><select name=shell>\n";
86 @shlist = &unique(@shlist);
87 foreach $s (@shlist) {
88         printf "<option value='%s'>%s\n", $s,
89                 $s eq "" ? "&lt;None&gt;" : $s;
90         }
91 print "<option value=*>$text{'uedit_other'}\n";
92 print "</select></td>\n";
93
94 &seed_random();
95 foreach (1 .. 15) {
96         $random_password .= $random_password_chars[
97                                 rand(scalar(@random_password_chars))];
98         }
99 print "<td valign=top rowspan=4><b>$text{'pass'}</b>",
100       "</td> <td rowspan=4 valign=top>\n";
101 printf "<input type=radio name=passmode value=0> %s<br>\n",
102         $uconfig{'empty_mode'} ? $text{'none1'} : $text{'none2'};
103 printf "<input type=radio name=passmode value=1 checked> %s<br>\n",
104         $text{'nologin'};
105 printf "<input type=radio name=passmode value=3> %s\n",
106         $text{'clear'};
107 printf "<input %s name=pass size=15 value='%s'><br>\n",
108         $uconfig{'passwd_stars'} ? "type=password" : "",
109         $uconfig{'random_password'} ? $random_password : "";
110 printf "<input type=radio name=passmode value=2> $text{'encrypted'}\n";
111 printf "<input name=encpass size=13>\n";
112 print "</td> </tr>\n";
113
114 print "<tr> <td valign=top>$text{'uedit_other'}</td>\n";
115 print "<td valign=top><input size=25 name=othersh>\n";
116 print &file_chooser_button("othersh", 0),"</td> </tr>\n";
117 print "<tr> <td colspan=2><br></td> </tr>\n";
118 print "</table></td></tr></table><p>\n";
119
120 $pft = &foreign_call("useradmin", "passfiles_type");
121 if ($pft == 1 || $pft == 6) {
122         # This is a BSD system.. a few extra password options are supported
123         print "<table border width=100%>\n";
124         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
125         print "<tr $cb> <td><table width=100%>\n";
126         print "<tr> <td><b>$text{'change2'}</b></td>\n";
127         print "<td>";
128         &date_input("", "", "", 'change');
129         print " &nbsp; <input name=changeh size=3>";
130         print ":<input name=changemi size=3></td>\n";
131
132         print "<td><b>$text{'expire2'}</b></td>\n";
133         print "<td>";
134         &date_input("", "", "", 'expire');
135         print " &nbsp; <input name=expireh size=3>";
136         print ":<input name=expiremi size=3></td> </tr>\n";
137
138         print "<tr> <td><b>$text{'class'}</b></td>\n";
139         print "<td><input name=class size=10></td>\n";
140         print "</tr>\n";
141         print "</table></td></tr></table><p>\n";
142         }
143 elsif ($pft == 2) {
144         # System has a shadow password file as well.. which means it supports
145         # password expiry and so on
146         print "<table border width=100%>\n";
147         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
148         print "<tr $cb> <td><table width=100%>\n";
149
150         print "<td><b>$text{'expire'}</b></td>\n";
151         print "<td>";
152         &date_input($eday, $emon, $eyear, 'expire');
153         print "</td> </tr>\n";
154
155         print "<tr> <td><b>$text{'min'}</b></td>\n";
156         print "<td><input size=5 name=min></td>\n";
157
158         print "<td><b>$text{'max'}</b></td>\n";
159         print "<td><input size=5 name=max></td></tr>\n";
160
161         print "<tr> <td><b>$text{'warn'}</b></td>\n";
162         print "<td><input size=5 name=warn></td>\n";
163
164         print "<td><b>$text{'inactive'}</b></td>\n";
165         print "<td><input size=5 name=inactive></td></tr>\n";
166
167         print "</table></td></tr></table><p>\n";
168         }
169 elsif ($pft == 4) {
170         # This is an AIX system
171         print "<table border width=100%>\n";
172         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
173         print "<tr $cb> <td><table width=100%>\n";
174
175         print "<tr> <td><b>$text{'expire'}</b></td>\n";
176         print "<td>";
177         &date_input("", "", "", 'expire');
178         print " &nbsp; <input name=expireh size=3>";
179         print "<b>:</b><input name=expiremi size=3></td> </tr>\n";
180
181         print "<tr> <td><b>$text{'min_weeks'}</b></td>\n";
182         print "<td><input size=5 name=min></td>\n";
183
184         print "<td><b>$text{'max_weeks'}</b></td>\n";
185         print "<td><input size=5 name=max></td></tr>\n";
186
187         print "<tr> <td valign=top><b>$text{'warn'}</b></td>\n";
188         print "<td valign=top><input size=5 name=warn></td>\n";
189
190         print "<td valign=top><b>$text{'flags'}</b></td> <td>\n";
191         printf "<input type=checkbox name=flags value=admin> %s<br>\n",
192                 $text{'uedit_admin'};
193         printf "<input type=checkbox name=flags value=admchg> %s<br>\n",
194                 $text{'uedit_admchg'};
195         printf "<input type=checkbox name=flags value=nocheck> %s\n",
196                 $text{'uedit_nocheck'};
197         print "</td> </tr>\n";
198
199         print "</table></td></tr></table><p>\n";
200         }
201
202 # Output group memberships
203 print "<table border width=100%>\n";
204 print "<tr $tb> <td><b>$text{'uedit_gmem'}</b></td> </tr>\n";
205 print "<tr $cb> <td><table width=100%>\n";
206 print "<tr> <td valign=top><b>$text{'group'}</b></td> <td valign=top>\n";
207 printf "<input name=gid size=8 value=\"%s\">\n",
208         $uconfig{'default_group'};
209 print "<input type=button onClick='ifield = document.forms[0].gid; chooser = window.open(\"/useradmin/my_group_chooser.cgi?multi=0&group=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=300,height=200\"); chooser.ifield = ifield' value=\"...\"></td>\n";
210
211 print "<td valign=top><b>$text{'uedit_2nd'}</b></td>\n";
212 print "<td><select name=sgid multiple size=5>\n";
213 @glist = sort { $a->{'group'} cmp $b->{'group'} } @glist
214         if ($uconfig{'sort_mode'});
215 foreach $g (@glist) {
216         @mems = split(/,/ , $g->{'members'});
217         print "<option value=\"$g->{'gid'}\">$g->{'group'} ($g->{'gid'})\n";
218         }
219 print "</select></td> </tr>\n";
220 print "</table></td></tr></table><p>\n";
221
222 print "<table border width=100%>\n";
223 print "<tr $tb> <td><b>$text{'uedit_oncreate'}</b></td> </tr>\n";
224 print "<tr $cb> <td><table>\n";
225
226 print "<tr> <td><b>$text{'uedit_makehome'}</b></td>\n";
227 print "<td><input type=radio name=makehome value=1 checked> $text{'yes'}</td>\n";
228 print "<td><input type=radio name=makehome value=0> $text{'no'}</td> </tr>\n";
229
230 if ($uconfig{'user_files'} =~ /\S/) {
231         print "<tr> <td><b>$text{'uedit_copy'}<b></td>\n";
232         print "<td><input type=radio name=copy_files ",
233               "value=1 checked> $text{'yes'}</td>\n";
234         print "<td><input type=radio name=copy_files ",
235               "value=0> $text{'no'}</td> </tr>\n";
236         }
237
238 # Show make home on all servers option
239 print "<tr> <td><b>$text{'uedit_servs'}</b></td>\n";
240 print "<td><input type=radio name=servs value=1> $text{'uedit_mall'}</td>\n";
241 print "<td><input type=radio name=servs value=0 checked> $text{'uedit_mthis'}</td> </tr>\n";
242
243 # Show other modules option
244 print "<tr> <td><b>$text{'uedit_others'}</b></td>\n";
245 print "<td><input type=radio name=others value=1 checked> $text{'yes'}</td>\n";
246 print "<td><input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
247
248 # Show selector for hosts to create on
249 &create_on_input($text{'uedit_servers'});
250
251 print "</table></td> </tr></table><p>\n";
252
253 print "<input type=submit value=\"$text{'create'}\"></form><p>\n";
254
255 &ui_print_footer("", $text{'index_return'});
256
257 # date_input(day, month, year, prefix)
258 sub date_input
259 {
260 print "<input name=$_[3]d size=3 value='$_[0]'>";
261 print "/<select name=$_[3]m>\n";
262 local $m;
263 foreach $m (1..12) {
264         printf "<option value=%d %s>%s\n",
265                 $m, $_[1] eq $m ? 'selected' : '', $text{"smonth_$m"};
266         }
267 print "</select>";
268 print "/<input name=$_[3]y size=5 value='$_[2]'>";
269 print &date_chooser_button("$_[3]d", "$_[3]m", "$_[3]y");
270 }
271