Handle hostnames with upper-case letters
[webmin.git] / lpadmin / edit_printer.cgi
1 #!/usr/local/bin/perl
2 # edit_printer.cgi
3 # Edit or create a printer
4
5 require './lpadmin-lib.pl';
6 &ReadParse();
7
8 if ($in{'new'}) {
9         $access{'add'} || &error($text{'edit_eadd'});
10         &ui_print_header(undef, $text{'edit_add'}, "");
11         $prn{'accepting'}++;
12         $prn{'enabled'}++;
13         $prn{'allow_all'}++;
14         $prn{'dev'} = $device_files[0];
15         $prn{'ctype'} = [ "postscript" ];
16         }
17 else {
18         &can_edit_printer($in{'name'}) || &error($text{'edit_eedit'});
19         &ui_print_header(undef, $text{'edit_edit'}, "");
20         local $prn = &get_printer($in{'name'});
21         $prn || &error(&text('save_egone', $in{'name'}));
22         %prn = %$prn;
23         }
24
25 print "<form action=save_printer.cgi method=post>\n";
26 print "<table border width=100%>\n";
27 print "<tr $tb> <td><b>$text{'edit_conf'}</b></td> </tr>\n";
28 print "<tr $cb> <td><table width=100%>\n";
29
30 print "<tr> <td><b>$text{'edit_name'}</b></td>\n";
31 if ($in{'new'}) {
32         print "<td><input name=name size=15></td>\n";
33         print "<input type=hidden name=new value=1>\n";
34         }
35 else {
36         print "<td>$prn{'name'}</td>\n";
37         print "<input type=hidden name=name value=\"$prn{'name'}\">\n";
38         }
39
40 print "<td align=right><b>$text{'edit_acc'}</b></td>\n";
41 printf "<td><input type=radio name=accepting value=1 %s> $text{'yes'}\n",
42         $prn{'accepting'} ? "checked" : "";
43 if (&printer_support('why')) {
44         printf "<input type=radio name=accepting value=0 %s> %s\n",
45                 $prn{'accepting'} ? "" : "checked", $text{'edit_why'};
46         printf "<input name=accepting_why size=15 value=\"%s\"></td> </tr>\n",
47                 $prn{'accepting_why'};
48         }
49 else {
50         printf "<input type=radio name=accepting value=0 %s> $text{'no'}\n",
51                 $prn{'accepting'} ? "" : "checked";
52         }
53
54 if (&printer_support('desc')) {
55         print "<tr> <td><b>$text{'edit_desc'}</b></td>\n";
56         print "<td><input name=desc size=20 value=\"",
57                 &html_escape($prn{'desc'}),"\"></td>\n";
58         }
59 else { print "<tr> <td colspan=2></td>\n"; }
60
61 print "<td align=right><b>$text{'edit_ena'}</b></td>\n";
62 printf "<td><input type=radio name=enabled value=1 %s> $text{'yes'}\n",
63         $prn{'enabled'} ? "checked" : "";
64 if (&printer_support('why')) {
65         printf "<input type=radio name=enabled value=0 %s> %s\n",
66                 $prn{'enabled'} ? "" : "checked", $text{'edit_why'};
67         printf "<input name=enabled_why size=15 value=\"%s\"></td> </tr>\n",
68                 $prn{'enabled_why'};
69         }
70 else {
71         printf "<input type=radio name=enabled value=0 %s> $text{'no'}\n",
72                 $prn{'enabled'} ? "" : "checked";
73         }
74
75 if (&printer_support('allow')) {
76         print "<tr> <td valign=top><b>$text{'edit_acl'}</b></td>\n";
77         print "<td colspan=3><table><tr><td valign=top>\n";
78         printf "<input type=radio name=access value=0 %s> %s<br>\n",
79                 $prn{'allow_all'} ? "checked" : "", $text{'edit_allow'};
80         printf "<input type=radio name=access value=1 %s> %s<br>\n",
81                 $prn{'deny_all'} ? "checked" : "", $text{'edit_deny'};
82         printf "<input type=radio name=access value=2 %s> %s<br>\n",
83                 $prn{'allow'} ? "checked" : "", $text{'edit_allowu'};
84         printf "<input type=radio name=access value=3 %s> %s\n",
85                 $prn{'deny'} ? "checked" : "", $text{'edit_denyu'};
86         print "</td> <td valign=top>\n";
87         print "<textarea wrap=auto name=users rows=5 cols=30>",
88               join(" ", (@{$prn{'allow'}}, @{$prn{'deny'}})),
89               "</textarea></td>\n";
90         print "<td valign=top>",&user_chooser_button("users",1),"</td>\n";
91         print "</tr></table></td> </tr>\n";
92         }
93
94 if (&printer_support('banner')) {
95         print "<tr> <td valign=top><b>$text{'edit_banner'}</b></td> ",
96               "<td valign=top>\n";
97         printf "<input type=radio name=prbanner value=1 %s> $text{'yes'}\n",
98                 $prn{'banner'} ? "checked" : "";
99         printf "<input type=radio name=prbanner value=0 %s> %s</td>\n",
100                 $prn{'banner'} ? "" : "checked", $text{'edit_opt'};
101         }
102 else { print "<tr>\n"; }
103
104 if (&printer_support('default')) {
105         print "<td align=right><b>$text{'edit_default'}</b></td> <td>\n";
106         if (!$prn{'default'}) {
107                 printf "<input type=radio name=default value=1 %s> $text{'yes'}\n", $prn{'default'} ? "checked" : "";
108                 printf "<input type=radio name=default value=0 %s> $text{'no'}</td></tr>\n", $prn{'default'} ? "" : "checked";
109                 }
110         else {
111                 print "<i>$text{'edit_already'}</i> </td> </tr>\n";
112                 }
113         }
114 elsif (&printer_support('msize')) {
115         print "<td align=right><b>$text{'edit_max'}</b></td> <td>\n";
116         printf "<input type=radio name=msize_def value=1 %s> %s\n",
117                 defined($prn{'msize'}) ? "" : "checked", $text{'default'};
118         printf "<input type=radio name=msize_def value=2 %s> %s\n",
119                 $prn{'msize'} eq '0' ? "checked" : "", $text{'edit_unlimited'};
120         printf "<input type=radio name=msize_def value=0 %s>\n",
121                 $prn{'msize'} ? "checked" : "";
122         printf "<input name=msize size=6 value=\"%s\"> %s</td> </tr>\n",
123                 $prn{'msize'} ? $prn{'msize'} : "", $text{'blocks'};
124         }
125 else { print "<td colspan=2></tr>\n"; }
126
127 if (&printer_support('ctype')) {
128         @ctype = @{$prn{'ctype'}};
129         print "<tr> <td><b>$text{'edit_dacc'}</b></td> <td colspan=3>\n";
130         printf "<input type=checkbox name=ctype_simple %s> %s &nbsp;\n",
131                 &indexof("simple", @ctype) < 0 ? "" : "checked",
132                 $text{'edit_dtext'};
133         printf "<input type=checkbox name=ctype_postscript %s> %s &nbsp;\n",
134                 &indexof("postscript", @ctype) < 0 ? "" : "checked",
135                 $text{'edit_dpost'};
136         @ctypeo = grep { !/^(simple|postscript)$/ } @ctype;
137         printf "<input type=checkbox name=ctype_other %s> %s\n",
138                 @ctypeo ? "checked" : "", $text{'edit_dother'};
139         printf "<input name=ctype_olist size=20 value=\"%s\">\n",
140                 join(' ', @ctypeo);
141         print "</td> </tr>\n";
142         }
143
144 if (&printer_support('alias')) {
145         @alias = @{$prn{'alias'}};
146         print "<tr> <td><b>$text{'edit_alt'}</b></td> <td colspan=3>\n";
147         printf "<input name=alias size=40 value=\"%s\"></td> </tr>\n",
148                 join(' ', @alias);
149         }
150
151 print "</table></td></tr></table><p>\n";
152
153 if ($in{'new'} || &printer_support('editdest')) {
154         print "<table border width=100%>\n";
155         print "<tr $tb> <td><b>$text{'edit_dest'}</b></td> </tr>\n";
156         print "<tr $cb> <td><table>\n";
157
158         $isdev = &indexof($prn{'dev'}, @device_files) >= 0;
159         if (!$webmin_windows_driver) {
160                 $wdrv = &is_webmin_windows_driver($prn{'iface'}, \%prn);
161                 $webmin++ if ($wdrv);
162                 }
163         $wdrv = &is_windows_driver($prn{'iface'}, \%prn) if (!$wdrv);
164         $hdrv = &is_hpnp_driver($prn{'iface'}, \%prn);
165         if ($wdrv) { $prn{'iface'} = $wdrv->{'program'}; }
166         elsif ($hdrv) { $prn{'iface'} = $hdrv->{'program'}; }
167
168         printf "<tr> <td><input type=radio name=dest value=0 %s> %s</td>\n",
169                 $prn{'dev'} && $isdev && !$wdrv && !$hdrv ? "checked" : "",
170                 $text{'edit_dev'};
171         print "<td><select name=dev>\n";
172         for($i=0; $i<@device_files; $i++) {
173                 $d = $device_files[$i];
174                 printf "<option value=\"$d\" %s>$device_names[$i]\n",
175                         $d eq $prn{'dev'} ? "selected" : "";
176                 }
177         print "</select></td> </tr>\n";
178
179         printf "<tr> <td><input type=radio name=dest value=1 %s> %s</td>\n",
180                 $prn{'dev'} && !$isdev && !$wdrv && !$hdrv ? "checked" : "",
181                 $text{'edit_file'};
182         printf "<td><input name=file size=25 value=\"%s\"></td> </tr>\n",
183                 $isdev || $wdrv || $hdrv ? "" : $prn{'dev'};
184
185         printf "<tr> <td><input type=radio name=dest value=2 %s>\n",
186                 $prn{'rhost'} ? "checked" : "";
187         print "$text{'edit_remote'}</td>\n";
188         print "<td><input name=rhost size=25 value=\"$prn{'rhost'}\"></td>\n";
189         print "<td>$text{'edit_rqueue'} ",
190               "<input name=rqueue size=15 value=\"$prn{'rqueue'}\">\n";
191         if (defined(&remote_printer_types)) {
192                 @rtypes = &remote_printer_types();
193                 }
194         elsif (&printer_support('sysv')) {
195                 @rtypes = ( [ 'bsd', 'BSD' ], [ 's5', 'SysV' ] );
196                 }
197         elsif (&printer_support('ipp')) {
198                 @rtypes = ( [ 'bsd', 'BSD' ], [ 'ipp', 'IPP' ] );
199                 }
200         if (@rtypes) {
201                 print "$text{'edit_type'} <select name=rtype>\n";
202                 foreach $t (@rtypes) {
203                         printf "<option value=%s %s>%s\n",
204                                 $t->[0],
205                                 $prn{'rtype'} eq $t->[0] ? "selected" : "",
206                                 $t->[1];
207                         }
208                 print "</select>\n";
209                 }
210         print "</td> </tr>\n";
211
212         if (&printer_support("direct")) {
213                 printf "<tr> <td><input type=radio name=dest value=5 %s>\n",
214                         $prn{'dhost'} ? "checked" : "";
215                 print "$text{'edit_direct'}</td>\n";
216                 print "<td><input name=dhost size=25 ",
217                       "value=\"$prn{'dhost'}\"></td>\n";
218                 print "<td>$text{'edit_dport'} ",
219                       "<input name=dport size=5 value=\"$prn{'dport'}\">\n";
220                 print "</td> </tr>\n";
221                 }
222
223         if (&has_smbclient()) {
224                 printf "<tr> <td><input type=radio name=dest value=3 %s>\n",
225                         $wdrv ? "checked" : "";
226                 printf "$text{'edit_smb'}</td> ".
227                       "<td><input name=server size=25 value=\"%s\"></td>\n",
228                         $wdrv->{'server'};
229                 printf "<td>$text{'edit_share'} ".
230                        "<input name=share size=15 value=\"%s\"></td>\n",
231                         $wdrv->{'share'};
232                 print "</tr><tr> <td align=right>$text{'edit_user'}</td>\n";
233                 printf "<td colspan=2><input name=suser size=10 value='%s'>\n",
234                         $wdrv->{'user'};
235                 printf "$text{'edit_pass'} ".
236                        "<input type=password name=spass size=10 value='%s'>\n",
237                         $wdrv->{'pass'};
238                 printf "$text{'edit_wgroup'} ".
239                        "<input name=wgroup size=10 value=\"%s\">\n",
240                         $wdrv->{'workgroup'};
241                 print "</td> </tr>\n";
242                 }
243
244         if (&has_hpnp()) {
245                 printf "<tr> <td><input type=radio name=dest value=4 %s>\n",
246                         $hdrv ? "checked" : "";
247                 print "$text{'edit_hpnp'}</td>\n";
248                 printf "<td><input name=hpnp size=25 value=\"%s\"></td>\n",
249                         $hdrv->{'server'};
250                 printf "<td>$text{'edit_port'} ".
251                        "<input name=port size=15 value=\"%s\"></td> </tr>\n",
252                         $hdrv->{'port'};
253                 }
254
255         print "<tr> <td>&nbsp;&nbsp;&nbsp;&nbsp;",
256               "<input type=checkbox name=check value=1> ",
257               "$text{'edit_check'}</td> </tr>\n";
258
259         print "</table></td></tr></table><p>\n";
260
261         print "<table border width=100%>\n";
262         print "<tr $tb> <td><b>$text{'edit_driver'}</b></td> </tr>\n";
263         print "<tr $cb> <td><table width=100%>\n";
264         if (!$webmin_print_driver) {
265                 $drv = &is_webmin_driver($prn{'iface'}, \%prn);
266                 }
267         if ($drv->{'mode'} != 0 && $drv->{'mode'} != 2 || $webmin) {
268                 $webmin++;
269                 $after = &webmin_driver_input(\%prn, $drv);
270                 }
271         else {
272                 $drv = &is_driver($prn{'iface'}, \%prn);
273                 $after = &driver_input(\%prn, $drv);
274                 }
275         print "</table></td></tr></table><p>\n";
276         }
277 print "<input type=hidden name=webmin value=\"$webmin\">\n";
278
279 if ($in{'new'}) {
280         print "<input type=submit value=\"$text{'create'}\"></form><p>\n";
281         }
282 else {
283         print "<table width=100%>\n";
284         print "<tr> <td><input type=submit value=\"$text{'save'}\"></td>\n";
285         if ($access{'delete'}) {
286                 print "</form><form action=\"delete_printer.cgi\">\n";
287                 print "<input type=hidden name=name value=\"$in{'name'}\">\n";
288                 print "<td align=right><input type=submit ",
289                       "value=\"$text{'delete'}\"></td> </tr>\n";
290                 }
291         print "</form></table>\n";
292         }
293 print $after;
294
295 &ui_print_footer("", $text{'index_return'});
296