Handle hostnames with upper-case letters
[webmin.git] / samba / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a list of available samba shares. Special shares (like [homes] and
4 # [printers]) are included as well.
5
6 require './samba-lib.pl';
7
8 # Check for Samba executable
9 if (!-x $config{'samba_server'}) {
10         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
11                 &help_search_link("samba", "man", "doc", "google"));
12         print &text('error_nosamba', $config{'samba_server'}, "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13
14         &foreign_require("software", "software-lib.pl");
15         $lnk = &software::missing_install_link("samba", $text{'index_samba'},
16                         "../$module_name/", $text{'index_title'});
17         print $lnk,"<p>\n" if ($lnk);
18
19         &ui_print_footer("/", $text{'index'});
20         exit;
21         }
22
23 # Check the samba version
24 if ($samba_version = &get_samba_version(\$out, 0)) {
25         # Save version number
26         &open_tempfile(VERSION, ">$module_config_directory/version");
27         &print_tempfile(VERSION, $samba_version,"\n");
28         &close_tempfile(VERSION);
29         }
30 else {
31         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
32                 &help_search_link("samba", "man", "doc", "google"));
33         print &text('error_version', $config{'samba_server'},
34                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
35         print "<pre>$out</pre>\n";
36         &ui_print_footer("/", $text{'index'});
37         exit;
38         }
39 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
40         &help_search_link("samba", "man", "doc", "google"), undef, undef,
41         &text('index_version', &get_samba_version(\$out, 1)));
42
43 @empty = &list_shares();
44 if (!@empty && (-r $config{alt_smb_conf})) {
45         # Copy the sample smb.conf file to the real location
46         # This is a hack for slackware
47         system("cp $config{alt_smb_conf} $config{smb_conf} >/dev/null 2>&1");
48         }
49 if (!(-r $config{smb_conf})) {
50         print &text('error_config', $config{'smb_conf'}, "$gconfig{'webprefix'}/config.cgi?$module_name");
51         print "<p>\n";
52         &ui_print_footer("/", $text{'index'});
53         exit;
54         }
55
56 # Check for 'config' or 'include' directives
57 &get_share("global");
58 if (&getval("config") || &getval("include")) {
59         print &text('index_einclude',
60                     "<tt>$config{'smb_conf'}</tt>",
61                     "<tt>config</tt>", "<tt>include</tt>"),"<p>\n";
62         }
63
64 # Work out links for adding things
65 @links = ( );
66 push(@links, "<a href=edit_fshare.cgi>$text{'index_createfileshare'}</a>")
67         if ($access{'c_fs'});
68 push(@links, "<a href=edit_pshare.cgi>$text{'index_createprnshare'}</a>")
69         if ($access{'c_ps'});
70 push(@links, "<a href=create_copy.cgi>$text{'index_createcopy'}</a>")
71         if ($access{'copy'});
72 push(@links, "<a href=view_users.cgi>$text{'index_view'}</a>")
73         if ($access{'view_all_con'});
74
75 foreach $s (&list_shares()) {
76         next unless &can('r', \%access, $s) || !$access{'hide'};
77         $us = "share=".&urlize($s);
78         if ($s eq "global") { next; }
79         if (!$donefirst) {
80                 # Show headers
81                 @tds = ( "width=5" );
82                 print &ui_form_start("delete_shares.cgi", "post");
83                 unshift(@links, &select_all_link("d"),
84                                 &select_invert_link("d"));
85                 print &ui_links_row(\@links);
86                 print &ui_columns_start([
87                         "",
88                         $text{'index_sharename'},
89                         $text{'index_path'},
90                         $text{'index_security'} ], 100, 0, \@tds);
91                 $donefirst = 1;
92                 }
93
94         # Show share details
95         &get_share($s);
96         local @cols;
97         if ($cp = &getval("copy")) { $cp = "(copy of <i>$cp</i>)"; }
98         if (&istrue("printable")) {
99                 push(@cols, "<a href=\"edit_pshare.cgi?$us\">".
100                             &html_escape($s)."</a> $cp");
101                 }
102         else {
103                 push(@cols, "<a href=\"edit_fshare.cgi?$us\">".
104                             &html_escape($s)."</a> $cp");
105                 }
106
107         # Output location / path info
108         if ($s eq "homes") {
109                 $p = "<i>$text{'index_homedir'}</i>";
110                 }
111         elsif ($s eq "printers") {
112                 $p = "<i>$text{'index_allprinter'}</i>";
113                 }
114         elsif (&istrue("printable")) {
115                 $p = &getval("printer") ? $text{'index_printer'}." ".&html_escape(&getval("printer")) : $text{'index_defaultprn'};
116                 }
117         else {
118                 $p = &html_escape(&getval("path"));
119                 }
120         push(@cols, $p);
121
122         # Output security information
123         if (&istrue("printable")) {
124                 if (&getval("valid users")) {
125                         # Only accessible to some users..
126                         $sc = $text{'index_printableto'}." ".
127                                 &user_list(&getval("valid users"));
128                         }
129                 elsif (&istrue("public")) {
130                         # Accessible to everyone
131                         $sc = $text{'index_prneveryone'};
132                         }
133                 else {
134                         $sc = $text{'index_prnalluser'};
135                         }
136                 }
137         elsif (&istrue("writable")) {
138                 # Default is read/write access
139                 if (&istrue("public")) {
140                         # No password needed..
141                         $sc = $text{'index_rwpublic'};
142                         }
143                 else {
144                         # Password needed..
145                         if (&getval("read list")) {
146                                 $sc = &text('index_readonly', &user_list(&getval("read list")));
147                                 }
148                         else {
149                                 $sc = $text{'index_rwalluser'};
150                                 }
151                         }
152                 }
153         else {
154                 # Default is read-only access
155                 if (&istrue("public")) {
156                         # No password needed..
157                         $sc = $text{'index_roeveryone'};
158                         }
159                 else {
160                         # Password needed..
161                         if (&getval("write list")) {
162                                 $sc = &text('index_readwrite', &user_list(&getval("write list")));
163                                 }
164                         else {
165                                 $sc = $text{'index_roalluser'};
166                                 }
167                         }
168                 }
169         push(@cols, $sc);
170         print &ui_checked_columns_row(\@cols, \@tds, "d", $s);
171         }
172 if ($donefirst) {
173         print &ui_columns_end();
174         }
175 else {
176         print "<b>$text{'index_noshares'}</b>. <p>\n";
177         }
178 print &ui_links_row(\@links);
179 if ($donefirst) {
180         print &ui_form_end([ [ "delete", $text{'index_delete'} ] ]);
181         }
182
183 @gc_acl = qw(conf_net conf_smb conf_pass conf_print conf_misc conf_bind
184                           ACLfs_global ACLps_global manual swat winbind);
185 @gc_progs = ("conf_net.cgi", "conf_smb.cgi", "conf_pass.cgi",
186              "conf_print.cgi", "conf_misc.cgi", "conf_bind.cgi",
187              "edit_fshare.cgi?share=global", "edit_pshare.cgi?share=global",
188              "edit_manual.cgi");
189 @gc_names = ($text{'global_unixnetwork'}, $text{'global_winnetwork'},
190              $text{'global_auth'}, $text{'global_printing'},
191              $text{'global_misc'}, $text{'global_bind'},
192              $text{'global_filedefault'},
193              $text{'global_prndefault'},
194              $text{'manual_title'});
195 @gc_icons = ("images/icon_0.gif", "images/icon_1.gif", "images/icon_2.gif",
196              "images/icon_3.gif", "images/icon_4.gif",
197              "images/icon_10.gif", "images/icon_5.gif", "images/icon_6.gif",
198              "images/manual.gif");
199 if (&has_command($config{'swat_path'})) {
200         push(@gc_progs, "swat.cgi");
201         push(@gc_names, "SWAT");
202         push(@gc_icons, "images/icon_9.gif");
203         }
204
205 foreach $i (0..$#gc_acl) {
206         next unless ($access{$gc_acl[$i]} && $gc_progs[$i]);
207         next if ($gc_acl[$i] eq "conf_winbind" && $samba_version < 3);
208         push(@gc_progs1, $gc_progs[$i]);
209         push(@gc_names1, $gc_names[$i]);
210         push(@gc_icons1, $gc_icons[$i]);
211         $disp++;
212         }
213
214 if ($disp) {
215         print &ui_hr();
216         print &ui_subheading($text{'global_title'});
217         &icons_table(\@gc_progs1, \@gc_names1, \@gc_icons1, 4);
218         }
219
220 # Generate table of accessible user and group editing icons
221 if ($access{'view_users'}) {
222         push(@utitles, $text{'global_edit'});
223         push(@ulinks, "edit_epass.cgi");
224         push(@uicons, "images/editepass.gif");
225         }
226 if ($access{'maint_makepass'}) {
227         push(@utitles, $text{'global_convert'});
228         push(@ulinks, "ask_epass.cgi");
229         push(@uicons, "images/askepass.gif");
230         }
231 if ($access{'maint_sync'}) {
232         push(@utitles, $text{'global_sync'});
233         push(@ulinks, "edit_sync.cgi");
234         push(@uicons, "images/editsync.gif");
235         }
236 if ($samba_version >= 3) {
237         if ($access{'maint_groups'}) {
238                 push(@utitles, $text{'global_gedit'});
239                 push(@ulinks, "list_groups.cgi");
240                 push(@uicons, "images/listgroups.gif");
241                 }
242         if ($access{'maint_gsync'}) {
243                 push(@utitles, $text{'global_gsync'});
244                 push(@ulinks, "edit_gsync.cgi");
245                 push(@uicons, "images/editgsync.gif");
246                 }
247         if ($access{'winbind'} && $has_net) {
248                 push(@utitles, $text{'global_winbind'});
249                 push(@ulinks, "edit_winbind.cgi");
250                 push(@uicons, "images/winbind.gif");
251                 }
252         }
253
254 if (@utitles) {
255         # We have some icons to show
256         print &ui_hr();
257         print &ui_subheading($text{'global_users'});
258         &icons_table(\@ulinks, \@utitles, \@uicons, 3);
259         }
260
261 if ($access{'apply'}) {
262         $isrun = &is_samba_running();
263         print &ui_hr();
264         print &ui_buttons_start();
265         if ($isrun == 0) {
266                 # Start button
267                 print &ui_buttons_row("start.cgi", $text{'index_start'},
268                                       $text{'index_startmsg'});
269                 }
270         elsif ($isrun == 1) {
271                 # Restart / stop buttons
272                 print &ui_buttons_row("restart.cgi", $text{'index_restart'},
273                                       $text{'index_restartmsg'}."\n".
274                                       $text{'index_restartmsg2'});
275                 print &ui_buttons_row("stop.cgi", $text{'index_stop'},
276                                       $text{'index_stopmsg'});
277                 }
278         print &ui_buttons_end();
279         if (&has_command("winbindd")) {
280                 $isrun2 = &is_winbind_running();
281                 print &ui_hr();
282                 print &ui_buttons_start();
283                 if ($isrun2 == 0) {
284                  # Start button
285                  print &ui_buttons_row("start_wb.cgi", $text{'index_start_wb'},
286                                       $text{'index_startmsg_wb'});
287                  }
288                 elsif ($isrun2 == 1) {
289                  # Restart / stop buttons
290                  print &ui_buttons_row("restart_wb.cgi", $text{'index_restart_wb'},
291                                        $text{'index_restartmsg_wb'});
292                  print &ui_buttons_row("stop_wb.cgi", $text{'index_stop_wb'},
293                                        $text{'index_stopmsg_wb'});
294                  }
295                 }
296         print &ui_buttons_end();
297         }
298
299 &ui_print_footer("/", $text{'index'});
300