2 # Functions for printer drivers as generated by COAS
4 %paper_sizes = ( 'a4', 'A4',
10 $driver_dir = "/etc/sysconfig/printers";
11 $base_driver = "$module_root_directory/base_coas_driver";
12 $webmin_windows_driver = 1;
14 # is_windows_driver(path)
15 # Returns the server, share, username, password, workgroup, program
16 # if path is a webmin windows driver
19 return &is_webmin_windows_driver(@_);
23 # Returns the driver name and dpi if some path is a webmin driver, or undef
33 if ($lines[1] =~ /^source ($driver_dir\/\S+)/) {
34 # Looks like a caldera driver! Read the sysconfig file
36 &read_env_file($1, \%conf);
37 if ($conf{'GSDEVICE'} eq 'NET' || $conf{'GSDEVICE'} eq 'RAW') {
38 # Driver isn't even used
42 elsif ($conf{'GSDEVICE'} eq 'uniprint') {
44 foreach $u (&list_uniprint()) {
45 $desc = $u->[1] if ($u->[0] eq $conf{'UPP'});
49 'upp' => $conf{'UPP'},
50 'paper' => $conf{'PAPERSIZE'},
51 'double' => lc($conf{'DOUBLEPAGE'}),
52 'eof' => lc($conf{'SENDEOF'}),
53 'desc' => $desc ? $desc : $conf{'UPP'} };
56 # A caldera printer driver
57 open(COAS, $config{'coas_printers'});
58 local $plist = &parse_coas(COAS);
61 foreach $p (values %$plist) {
62 $desc = $p->{'description'}
63 if ($p->{'type'}->{'0'} eq $conf{'GSDEVICE'} &&
67 'gsdevice' => $conf{'GSDEVICE'},
68 'gsname' => $conf{'GSNAME'},
69 'res' => $conf{'RESOLUTION'},
70 'paper' => $conf{'PAPERSIZE'},
71 'eof' => lc($conf{'SENDEOF'}),
72 'double' => lc($conf{'DOUBLEPAGE'}),
73 'gsopts' => $conf{'GSOPTS'},
74 'desc' => $conf{'GSNAME'} ? $conf{'GSNAME'} : $desc };
78 # A driver of some kind, but not caldera's
85 # create_windows_driver(&printer, &driver)
86 sub create_windows_driver
88 return &create_webmin_windows_driver(@_);
91 # create_driver(&printer, &driver)
94 if ($_[1]->{'mode'} == 0) {
97 elsif ($_[1]->{'mode'} == 2) {
98 return $_[1]->{'file'};
101 # Create or update the parameters file
103 &read_env_file("$driver_dir/$_[0]->{'name'}", \%conf);
104 $conf{'GSDEVICE'} = $_[1]->{'gsdevice'};
105 $conf{'GSNAME'} = $_[1]->{'gsname'};
106 $conf{'NAME'} = $_[0]->{'name'};
107 $conf{'RESOLUTION'} = $_[1]->{'res'};
108 $conf{'PAPERSIZE'} = $_[1]->{'paper'};
109 $conf{'DESC'} = $_[0]->{'desc'};
110 $conf{'SENDEOF'} = $_[1]->{'eof'};
111 $conf{'DOUBLEPAGE'} = $_[1]->{'double'};
112 $conf{'GSOPTS'} = $_[1]->{'gsopts'};
113 $conf{'UPP'} = $_[1]->{'upp'};
114 &write_env_file("$driver_dir/$_[0]->{'name'}", \%conf);
116 # Create the standard driver program
117 open(DRIVER, $base_driver);
118 local @lines = <DRIVER>;
120 $lines[1] = "source $driver_dir/$_[0]->{'name'}\n";
121 mkdir("$config{'spool_dir'}/$_[0]->{'name'}", 0755);
122 local $drv = "$config{'spool_dir'}/$_[0]->{'name'}/printfilter";
130 # delete_driver(name)
133 &delete_webmin_driver($_[0]);
134 unlink("$driver_dir/$_[0]");
137 # driver_input(&printer, &driver)
140 local $mode = $_[0]->{'rhost'} ? 0 : $_[1]->{'mode'};
141 printf "<tr> <td><input type=radio name=mode value=0 %s> %s</td>\n",
142 $mode == 0 ? 'checked' : '', $text{'caldera_none'};
143 print "<td>($text{'caldera_nonemsg'})</td> </tr>\n";
144 printf "<tr> <td><input type=radio name=mode value=2 %s> %s</td>",
145 $mode == 2 ? 'checked' : '', $text{'caldera_prog'};
146 printf "<td><input name=program size=40 value='%s'></td> </tr>\n",
147 $mode == 2 ? $_[0]->{'iface'} : '';
149 # Normal driver options
150 printf "<tr> <td valign=top><input type=radio name=mode value=1 %s> %s</td>\n",
151 $mode == 1 ? 'checked' : '', $text{'caldera_coas'};
152 print "<td><table width=100%>\n";
154 print "<tr> <td valign=top><b>$text{'caldera_printer'}</b></td>\n";
155 print "<td colspan=3><select size=5 name=gsdevice onChange='setres(0)'>\n";
156 open(COAS, $config{'coas_printers'});
157 local $plist = &parse_coas(COAS);
159 local ($i, $j, $p, $k, $found, $select_res);
160 foreach $p (values %$plist) {
161 if ($p->{'description'} eq $_[1]->{'gsname'} &&
162 $p->{'type'}->{'0'} ne $_[1]->{'gsdevice'}) {
163 # COAS has changed the device
164 $_[1]->{'gsname'} = undef;
167 foreach $k (sort { $a <=> $b } keys %$plist) {
169 next if ($p->{'type'}->{'0'} =~ /NET|RAW/);
170 local @thisres = values %{$p->{'resolution'}};
171 local $got = ($_[1]->{'gsname'} eq $p->{'description'} &&
172 $_[1]->{'gsdevice'} eq $p->{'type'}->{'0'}) ||
173 (!$_[1]->{'gsname'} && !$found &&
174 $_[1]->{'gsdevice'} eq $p->{'type'}->{'0'});
175 printf "<option %s value='%s'>%s\n",
176 $got ? 'selected' : '',
177 $p->{'description'}.";".join(";", @thisres),
180 $select_res = &indexof($_[1]->{'res'}, @thisres) if ($got);
181 map { $gotres{$_}++ } @thisres;
183 print "</select><select name=res size=5>\n";
184 foreach $r (sort { $a <=> $b} keys %gotres) {
185 printf "<option %s>%s\n",
186 $_[1]->{'res'} eq $r ? 'selected' : '', $r;
188 print "</select></td> </tr>\n";
190 print "<tr> <td><b>$text{'caldera_eof'}</b></td>\n";
191 printf "<td><input type=radio name=eof value=true %s> $text{'yes'}\n",
192 $_[1]->{'eof'} eq 'true' ? 'checked' : '';
193 printf "<input type=radio name=eof value=false %s> $text{'no'}</td>\n",
194 $_[1]->{'eof'} eq 'true' ? '' : 'checked';
196 print "<td><b>$text{'caldera_paper'}</b></td> <td><select name=paper>\n";
197 foreach $p (sort { $a cmp $b } keys %paper_sizes) {
198 printf "<option value='%s' %s>%s\n",
199 $p, $_[1]->{'paper'} eq $p ? 'selected' : '',
202 print "</select></td> </tr>\n";
204 print "<tr> <td><b>$text{'caldera_double'}</b></td>\n";
205 printf "<td><input type=radio name=double value=true %s> $text{'yes'}\n",
206 $_[1]->{'double'} eq 'true' ? 'checked' : '';
207 printf "<input type=radio name=double value=false %s> $text{'no'}</td>\n",
208 $_[1]->{'double'} eq 'true' ? '' : 'checked';
210 print "<td><b>$text{'caldera_gsopts'}</b></td>\n";
211 printf "<td><input name=gsopts size=30 value='%s'></td> </tr>\n",
214 print "</table></td></tr>\n";
216 # Uniprint driver options
217 printf "<tr> <td valign=top><input type=radio name=mode value=3 %s> %s</td>\n",
218 $mode == 3 ? 'checked' : '', $text{'caldera_uniprint'};
219 print "<td><table width=100%>\n";
221 print "<tr> <td valign=top><b>$text{'caldera_printer'}</b></td>\n";
222 print "<td colspan=3><select name=uniprint size=5>\n";
223 foreach $u (&list_uniprint()) {
224 printf "<option value=%s %s>%s\n",
225 $u->[0], $u->[0] eq $_[1]->{'upp'} ? 'selected' : '', $u->[1];
228 print "</select></td> </tr>\n";
230 print "<tr> <td><b>$text{'caldera_eof'}</b></td>\n";
231 printf "<td><input type=radio name=ueof value=true %s> $text{'yes'}\n",
232 $_[1]->{'eof'} eq 'true' ? 'checked' : '';
233 printf "<input type=radio name=ueof value=false %s> $text{'no'}</td>\n",
234 $_[1]->{'eof'} eq 'true' ? '' : 'checked';
236 print "<td><b>$text{'caldera_paper'}</b></td> <td><select name=upaper>\n";
237 foreach $p (sort { $a cmp $b } keys %paper_sizes) {
238 printf "<option value='%s' %s>%s\n",
239 $p, $_[1]->{'paper'} eq $p ? 'selected' : '',
242 print "</select></td> </tr>\n";
244 print "<tr> <td><b>$text{'caldera_double'}</b></td>\n";
245 printf "<td><input type=radio name=udouble value=true %s> $text{'yes'}\n",
246 $_[1]->{'double'} eq 'true' ? 'checked' : '';
247 printf "<input type=radio name=udouble value=false %s> $text{'no'}</td>\n",
248 $_[1]->{'double'} eq 'true' ? '' : 'checked';
250 print "</table></td></tr>\n";
256 var idx = document.forms[0].gsdevice.selectedIndex;
257 var v = new String(document.forms[0].gsdevice.options[idx].value);
258 var vv = v.split(";");
259 var res = document.forms[0].res;
261 for(var i=1; i<vv.length; i++) {
262 res.options[i-1] = new Option(vv[i], vv[i]);
264 if (res.length > 0) {
265 res.options[sel].selected = true;
274 # Parse driver selection from %in and return a driver structure
277 if ($in{'mode'} == 0) {
278 return { 'mode' => 0 };
280 elsif ($in{'mode'} == 2) {
281 $in{'program'} =~ /^(\S+)/ && -x $1 ||
282 &error(&text('caldera_eprog', $in{'program'}));
283 return { 'mode' => 2,
284 'file' => $in{'program'} };
286 elsif ($in{'mode'} == 1) {
287 # Normal ghostscript driver
288 open(COAS, $config{'coas_printers'});
289 local $plist = &parse_coas(COAS);
291 $in{'gsdevice'} || &error($text{'caldera_edriver'});
292 $in{'gsdevice'} =~ s/;(.*)$//;
293 local ($p, $gsdevice);
294 foreach $p (values %$plist) {
295 $gsdevice = $p->{'type'}->{'0'}
296 if ($p->{'description'} eq $in{'gsdevice'});
298 $gsdevice eq 'PostScript' || $in{'res'} ||
299 &error($text{'caldera_eres'});
300 return { 'mode' => 1,
301 'gsdevice' => $gsdevice,
302 'gsname' => $in{'gsdevice'},
304 'paper' => $in{'paper'},
306 'double' => $in{'double'},
307 'gsopts' => $in{'gsopts'} };
310 # Uniprint ghostscript driver
311 $in{'uniprint'} || &error($text{'caldera_edriver'});
312 return { 'mode' => 3,
313 'gsdevice' => 'uniprint',
314 'upp' => $in{'uniprint'},
315 'paper' => $in{'upaper'},
316 'eof' => $in{'ueof'},
317 'double' => $in{'udouble'} };
329 if (/^\s*(\S+)\s+{/) {
332 $rv{$k} = &parse_coas($h);
338 elsif (/^\s*(\S+)\s+(.*)/) {
339 # a value in a section