Handle hostnames with upper-case letters
[webmin.git] / lpadmin / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a list of all known printers
4
5 require './lpadmin-lib.pl';
6 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
7                  undef, undef, undef,
8                  &text('index_style',
9                         $text{'style_'.$config{'print_style'}} ||
10                         uc($config{'print_style'})));
11 @plist = &list_printers();
12
13 # Check the print system (if possible)
14 if (defined(&check_print_system)) {
15         $pserr = &check_print_system();
16         if ($pserr) {
17                 print $pserr,"\n";
18                 print &text('index_esystem',
19                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
20                 &ui_print_footer("/", $text{'index'});
21                 exit;
22                 }
23         }
24
25 # Create links to select / add
26 @links = ( );
27 if (@plist && !$config{'display_mode'}) {
28         push(@links, &select_all_link("d"),
29                      &select_invert_link("d") );
30         }
31 push(@links, "<a href=edit_printer.cgi?new=1>$text{'index_add'}</a>")
32         if ($access{'add'});
33
34 if ($config{'sort_mode'}) {
35         @plist = sort { $a cmp $b } @plist;
36         }
37 if (@plist) {
38         if ($config{'display_mode'}) {
39                 # Just show printer names
40                 print &ui_links_row(\@links);
41                 @grid = ( );
42                 $i = 0;
43                 foreach $p (@plist) {
44                         local $ed = &can_edit_printer($p);
45                         local $jb = &can_edit_jobs($p);
46                         next if (!$ed && !$jb && !$access{'view'});
47                         local $l;
48                         if ($ed) {
49                                 $l = "<a href='edit_printer.cgi?name=$p'>".
50                                      "$p</a>\n";
51                                 }
52                         else {
53                                 $l = $p."\n";
54                                 }
55                         if ($config{'show_jobs'}) {
56                                 local @jobs = &get_jobs($p->{'name'});
57                                 $l .= "&nbsp;<a href='list_jobs.cgi?name=$p'>".
58                                       "(".&text('index_jcount', scalar(@jobs)).
59                                       ")</a>";
60                                 }
61                         else {
62                                 $l .= "&nbsp;<a href='list_jobs.cgi?name=$p'>".
63                                       "($text{'index_jlist'})</a>";
64                                 }
65                         push(@grid, $l);
66                         }
67                 print &ui_grid_table(\@grid, 4, 100,
68                         [ "width=25%", "width=25%", "width=25%", "width=25%" ],
69                         undef,
70                         $text{'index_header'});
71                 print &ui_links_row(\@links);
72                 }
73         else {
74                 # Show full printer details .. table heading first
75                 if ($access{'delete'}) {
76                         print &ui_form_start("delete_printers.cgi", "post");
77                         @tds = ( "width=5" );
78                         print &ui_links_row(\@links);
79                         }
80                 print &ui_columns_start([
81                         $access{'delete'} ? ( "" ) : ( ),
82                         $text{'index_name'},
83                         $text{'index_desc'},
84                         $text{'index_to'},
85                         $config{'show_status'} ? ( $text{'index_enabled'},
86                                                    $text{'index_accepting'} )
87                                                : ( $text{'index_driver'} ),
88                         $text{'index_jobs'} ], 100, 0, \@tds);
89
90                 # One row per printer
91                 for($i=0; $i<@plist; $i++) {
92                         local ($wdrv, $hdrv, $drv);
93                         local $ed = &can_edit_printer($plist[$i]);
94                         local $jb = &can_edit_jobs($plist[$i]);
95                         next if (!$ed && !$jb && !$access{'view'});
96                         $p = &get_printer($plist[$i], !$config{'show_status'});
97                         $ed = 0 if ($p->{'ro'});
98
99                         local @cols;
100                         if ($ed) {
101                                 push(@cols, "<a href=\"edit_printer.cgi?".
102                                             "name=$p->{'name'}\">".
103                                             &html_escape($p->{'name'})."</a>");
104                                 }
105                         else {
106                                 push(@cols, &html_escape($p->{'name'}));
107                                 }
108                         push(@cols, &html_escape($p->{'desc'}));
109                         if (!$webmin_windows_driver) {
110                                 $wdrv = &is_webmin_windows_driver($p->{'iface'}, $p);
111                                 }
112                         $wdrv = &is_windows_driver($p->{'iface'}, $p) if (!$wdrv);
113                         $hdrv = &is_hpnp_driver($p->{'iface'}, $p);
114                         if ($wdrv) {
115                                 push(@cols, "<tt>\\\\$wdrv->{'server'}".
116                                             "\\$wdrv->{'share'}</tt>");
117                                 $p->{'iface'} = $wdrv->{'program'};
118                                 }
119                         elsif ($hdrv) {
120                                 push(@cols, "<tt>HPNP $hdrv->{'server'}:".
121                                             "$hdrv->{'port'}</tt>");
122                                 $p->{'iface'} = $hdrv->{'program'};
123                                 }
124                         elsif ($p->{'rhost'}) {
125                                 local $qu = $p->{'rqueue'} ? $p->{'rqueue'}
126                                                            : $p->{'name'};
127                                 push(@cols, "<tt>$p->{'rhost'}:$qu</tt>");
128                                 }
129                         elsif ($p->{'dhost'}) {
130                                 push(@cols, "<tt>$p->{'dhost'}:$p->{'dport'}</tt>");
131                                 }
132                         else {
133                                 push(@cols, &dev_name($p->{'dev'}));
134                                 }
135                         if (!$webmin_print_driver) {
136                                 $drv = &is_webmin_driver($p->{'iface'}, $p);
137                                 }
138                         $drv = &is_driver($p->{'iface'}, $p)
139                                 if ($drv->{'mode'} == 0 || $drv->{'mode'} == 2);
140                         if ($config{'show_status'}) {
141                                 push(@cols, $p->{'enabled'} ? $text{'yes'}
142                                                             : $text{'no'});
143                                 push(@cols, $p->{'accepting'} ? $text{'yes'}
144                                                               : $text{'no'});
145                                 }
146                         else {
147                                 push(@cols, &html_escape($drv->{'desc'}));
148                                 }
149                         $jlink = "<a href=\"list_jobs.cgi?name=$p->{'name'}\">";
150                         if ($config{'show_jobs'}) {
151                                 local @jobs = &get_jobs($p->{'name'});
152                                 $jlink .= scalar(@jobs);
153                                 }
154                         else {
155                                 $jlink .= $text{'index_list'};
156                                 }
157                         $jlink .= "</a>";
158                         push(@cols, $jlink);
159                         if (!$access{'delete'}) {
160                                 # Cannot delete
161                                 print &ui_columns_row(\@cols, \@tds);
162                                 }
163                         elsif ($ed) {
164                                 # Can delete
165                                 print &ui_checked_columns_row(\@cols, \@tds,
166                                                               "d",$p->{'name'});
167                                 }
168                         else {
169                                 # Cannot delete this one
170                                 print &ui_columns_row([ "", @cols ], \@tds);
171                                 }
172                         }
173                 print &ui_columns_end();
174                 if ($access{'delete'}) {
175                         print &ui_links_row(\@links);
176                         print &ui_form_end([ [ "delete", $text{'index_delete'} ] ]);
177                         }
178                 }
179         }
180 else {
181         print "<b>$text{'index_none'}</b><p>\n";
182         print &ui_links_row(\@links);
183         }
184
185 # display button to start or stop the scheduler (lpd, lpsched, etc..)
186 print &ui_hr();
187 print &ui_buttons_start();
188 $pid = &sched_running();
189 if ($pid < 0 || !$access{'stop'}) {
190         # cannot stop or start..
191         }
192 elsif ($pid && $access{'stop'} == 2) {
193         # can only restart
194         print &ui_buttons_row("restart.cgi",
195                               $text{'index_restart'}, $text{'index_restartmsg'});
196         }
197 elsif ($pid) {
198         print &ui_buttons_row("stop.cgi",
199                               $text{'index_stop'}, $text{'index_stopmsg'});
200         }
201 else {
202         print &ui_buttons_row("start.cgi",
203                               $text{'index_start'}, $text{'index_startmsg'});
204         }
205
206 # Show cluster button, if possible
207 if (&foreign_check("servers")) {
208         &foreign_require("servers", "servers-lib.pl");
209         @allservers = grep { $_->{'user'} }
210                         &servers::list_servers();
211         }
212 if ($access{'cluster'} && @allservers) {
213         print &ui_buttons_row("cluster.cgi",
214                       $text{'index_cluster'}, $text{'index_clusterdesc'});
215         }
216
217 print &ui_buttons_end();
218
219 &ui_print_footer("/", $text{'index'});
220
221