3 # Create, update or delete a samba share
5 require './file-lib.pl';
6 $disallowed_buttons{'sharing'} && &error($text{'ebutton'});
8 print "Content-type: text/plain\n\n";
9 if ($access{'ro'} || $access{'uid'}) {
10 # User has no access to samba
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
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");
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);
42 # Creating a new share
43 map { $taken{$_}++ } @shares;
44 if ($in{'path'} =~ /\/([^\/]+)$/) {
51 for($i=2; $taken{$base.$i}; $i++) { }
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';
62 elsif ($in{'guest'} == 1) {
63 $samba::share{'public'} = 'yes';
65 &foreign_call("samba", "create_share", $base);
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'
77 $samba::share{'writeable'} = $in{'writable'} ? 'yes'
79 $samba::share{'comment'} = $in{'comment'};
80 if ($in{'guest'} == 2) {
81 $samba::share{'public'} = 'yes';
82 $samba::share{'guest only'} = 'yes';
84 elsif ($in{'guest'} == 1) {
85 $samba::share{'public'} = 'yes';
86 delete($samba::share{'guest only'});
89 delete($samba::share{'public'});
90 delete($samba::share{'guest only'});
92 &foreign_call("samba", "modify_share", $s, $s);
98 &unlock_file($sconfig{'smb_conf'});
99 &webmin_log($in{'delete'} ? 'delete' : $in{'new'} ? 'create' : 'modify',
100 'share', $in{'path'});