Handle hostnames with upper-case letters
[webmin.git] / mount / smb_server.cgi
1 #!/usr/local/bin/perl
2 # smb_server.cgi
3 # Called in a pop-up javascript window to display a list of known SMB
4 # servers, by calling smbclient to request the browse list from some server
5
6 $trust_unknown_referers = 1;
7 require './mount-lib.pl';
8 use Socket;
9 &popup_header($text{'smb_choose'});
10 print <<EOF;
11 <script>
12 function choose(f)
13 {
14 top.opener.ifield.value = f;
15 window.close();
16 }
17 </script>
18 EOF
19
20 # call smbclient
21 $host = $config{'browse_server'} ? $config{'browse_server'} : "localhost";
22 &execute_command("$config{'smbclient_path'} -d 0 -L $host -N",
23                  undef, \$out, \$out);
24 if ($?) {
25         print "<b>",&text('smb_elist', $host),"</b>\n";
26         exit;
27         }
28 elsif ($out =~ /Unknown host/) {
29         print "<b>",&text('smb_ehost', $host),"</b>\n";
30         exit;
31         }
32 elsif ($out =~ /error connecting|connect error/) {
33         print "<b>",&text('smb_edown', $host),"</b>\n";
34         exit;
35         }
36
37 # parse server list
38 if ($out =~ /Server\s+Comment\n.*\n((.+\n)+)/) {
39         @svlist = split(/\n/, $1);
40         foreach $sv (@svlist) {
41                 if ($sv =~ /^\s+(\S+)\s*(.*)$/) {
42                         push(@names, $1); push(@comms, $2);
43                         }
44                 }
45         }
46
47 if (@names) {
48         print "<b>$text{'smb_sel'}</b><br>\n";
49         print "<table border width=100%>\n";
50         print "<tr $tb> <td><b>$text{'smb_name'}</b></td> ",
51               "<td><b>$text{'smb_desc'}</b></td> </tr>\n";
52         for($i=0; $i<@names; $i++) {
53                 print "<tr $cb>\n";
54                 print "<td><a href=\"\" onClick='choose(\"$names[$i]\"); ",
55                       "return false'>$names[$i]</a></td>\n";
56                 print "<td>$comms[$i]</td> </tr>\n";
57                 }
58         print "</table>\n";
59         }
60 else {
61         print "<b>$text{'smb_none'}</b>.<p>\n";
62         }
63
64 &popup_footer();
65
66