Handle hostnames with upper-case letters
[webmin.git] / file / save_share.cgi
1 #!/usr/local/bin/perl
2 # save_share.cgi
3 # Create, update or delete a samba share
4
5 require './file-lib.pl';
6 $disallowed_buttons{'sharing'} && &error($text{'ebutton'});
7 &ReadParse();
8 print "Content-type: text/plain\n\n";
9 if ($access{'ro'} || $access{'uid'}) {
10         # User has no access to samba
11         print "0\n";
12         exit;
13         }
14
15 %minfo = &get_module_info("samba");
16 &read_acl(\%acl, undef);
17 if (!%minfo || !&check_os_support(\%minfo) ||
18     !$acl{$base_remote_user,'samba'}) {
19         # Samba module not installed or supported
20         print "0\n";
21         exit;
22         }
23
24 &foreign_require("samba", "samba-lib.pl");
25 %sconfig = &foreign_config("samba");
26 &lock_file($sconfig{'smb_conf'});
27 @shares = &foreign_call("samba", "list_shares");
28
29 if ($in{'delete'}) {
30         # Deleting an old share
31         foreach $s (@shares) {
32                 &foreign_call("samba", "get_share", $s);
33                 if ($samba::share{'path'} &&
34                     $samba::share{'path'} eq $in{'path'}) {
35                         &foreign_call("samba", "delete_share", $s);
36                         last;
37                         }
38                 }
39         print "1\n";
40         }
41 elsif ($in{'new'}) {
42         # Creating a new share
43         map { $taken{$_}++ } @shares;
44         if ($in{'path'} =~ /\/([^\/]+)$/) {
45                 $base = $1;
46                 }
47         else {
48                 $base = "root";
49                 }
50         if ($taken{$base}) {
51                 for($i=2; $taken{$base.$i}; $i++) { }
52                 $base = $base.$i;
53                 }
54         $samba::share{'path'} = $in{'path'};
55         $samba::share{'available'} = $in{'available'} ? 'yes' : 'no';
56         $samba::share{'writeable'} = $in{'writable'} ? 'yes' : 'no';
57         $samba::share{'comment'} = $in{'comment'};
58         if ($in{'guest'} == 2) {
59                 $samba::share{'public'} = 'yes';
60                 $samba::share{'guest only'} = 'yes';
61                 }
62         elsif ($in{'guest'} == 1) {
63                 $samba::share{'public'} = 'yes';
64                 }
65         &foreign_call("samba", "create_share", $base);
66         print "1\n";
67         }
68 else {
69         # Updating an existing share
70         foreach $s (@shares) {
71                 &foreign_call("samba", "get_share", $s);
72                 if ($samba::share{'path'} &&
73                     $samba::share{'path'} eq $in{'path'}) {
74                         # found the share to update
75                         $samba::share{'available'} = $in{'available'} ? 'yes'
76                                                                       : 'no';
77                         $samba::share{'writeable'} = $in{'writable'} ? 'yes'
78                                                                     : 'no';
79                         $samba::share{'comment'} = $in{'comment'};
80                         if ($in{'guest'} == 2) {
81                                 $samba::share{'public'} = 'yes';
82                                 $samba::share{'guest only'} = 'yes';
83                                 }
84                         elsif ($in{'guest'} == 1) {
85                                 $samba::share{'public'} = 'yes';
86                                 delete($samba::share{'guest only'});
87                                 }
88                         else {
89                                 delete($samba::share{'public'});
90                                 delete($samba::share{'guest only'});
91                                 }
92                         &foreign_call("samba", "modify_share", $s, $s);
93                         last;
94                         }
95                 }
96         print "1\n";
97         }
98 &unlock_file($sconfig{'smb_conf'});
99 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
100             'share', $in{'path'});
101