3 # Save changes to a shared directory
5 require './dfs-lib.pl';
6 &error_setup($text{'save_err'});
9 @shlist = &list_shares();
12 # Redirect to deletion CGI
13 &redirect("delete_share.cgi?idx=$in{'idx'}");
18 if ($in{directory} !~ /^\/.*/) {
19 &error(&text('save_edirectory', $in{'directory'}));
21 if (!(-d $in{directory})) {
22 &error(&text('save_edirectory2', $in{'directory'}));
24 @rolist = split(/\s+/, $in{rolist}); &check_hosts(@rolist);
25 @rwlist = split(/\s+/, $in{rwlist}); &check_hosts(@rwlist);
26 @rtlist = split(/\s+/, $in{rtlist}); &check_hosts(@rtlist);
27 if ($in{readwrite} == 2 && !@rwlist) {
28 &error($text{'save_erw'});
30 if ($in{readonly} == 2 && !@rolist) {
31 &error($text{'save_ero'});
33 if ($in{root} == 2 && !@rtlist) {
34 &error($text{'save_eroot'});
37 # Remove from the read-only list any hosts shared read-write as well
38 if ($in{readwrite} == 1) {
41 elsif ($in{readwrite} == 2) {
42 foreach $rwh (@rwlist) {
43 if (($idx = &indexof($rwh, @rolist)) != -1) {
44 splice(@rolist, $idx, 1);
47 if (@rolist == 0 && $in{readonly} == 2) {
52 &lock_file($config{dfstab_file});
53 foreach $s (@shlist) {
54 $taken = $s if ($s->{'dir'} eq $in{directory});
57 if (defined($in{'idx'})) {
58 $share = $shlist[$in{'idx'}];
59 $olddir = $share->{'dir'};
61 $share->{'dir'} = $in{'directory'};
62 $share->{'desc'} = $in{'desc'};
63 $share->{'type'} = 'nfs';
65 if (defined($in{'idx'})) {
66 # Changing an existing share
67 if ($taken && $taken->{'index'} != $in{'idx'}) {
68 &error(&text('save_ealready', $in{'directory'}));
70 &parse_options($share->{'opts'});
72 $share->{'opts'} = &join_options();
73 &modify_share($share);
76 # Creating a new share
78 &error(&text('save_ealready', $in{'directory'}));
81 $share->{'opts'} = &join_options();
82 &create_share($share);
84 &unlock_file($config{dfstab_file});
85 if (defined($in{'idx'})) {
86 &webmin_log('modify', 'share', $olddir, \%in);
89 &webmin_log('create', 'share', $share->{'dir'}, \%in);
94 # Fill in the options associative array
97 if ($in{readonly} == 0) { delete($options{"ro"}); }
98 elsif ($in{readonly} == 1) { $options{"ro"} = ""; }
99 elsif ($in{readonly} == 2) { $options{"ro"} = join(':', @rolist); }
101 if ($in{readwrite} == 0) { delete($options{"rw"}); }
102 elsif ($in{readwrite} == 1) { $options{"rw"} = ""; }
103 elsif ($in{readwrite} == 2) { $options{"rw"} = join(':', @rwlist); }
105 if ($in{root} == 0) { delete($options{"root"}); }
106 elsif ($in{root} == 2) { $options{"root"} = join(':', @rtlist); }
108 if (!$access{'simple'}) {
109 if ($in{nosub}) { $options{"nosub"} = ""; }
110 else { delete($options{"nosub"}); }
112 if ($in{nosuid}) { $options{"nosuid"} = ""; }
113 else { delete($options{"nosuid"}); }
115 if ($in{secure}) { $options{"secure"} = ""; }
116 else { delete($options{"secure"}); }
118 if ($in{kerberos}) { $options{"kerberos"} = ""; }
119 else { delete($options{"kerberos"}); }
121 if ($in{'anon_m'} == 0) { delete($options{"anon"}); }
122 elsif ($in{'anon_m'} == 1) { $options{"anon"} = -1; }
123 else { $options{"anon"} = getpwnam($in{"anon"}); }
125 if ($in{aclok}) { $options{"aclok"} = ""; }
126 else { delete($options{"aclok"}); }
128 if ($gconfig{'os_version'} >= 7) {
129 if ($in{'public'}) { $options{'public'} = ""; }
130 else { delete($options{'public'}); }
131 if (!$in{'index_def'}) { $options{'index'} = $in{'index'}; }
132 else { delete($options{'index'}); }
137 # check_hosts(host, host, ...)
138 # Die if any of the listed hosts does not exist
142 if ($gconfig{'os_version'} < 7) {
144 &to_ipaddress($h) || &to_ip6address($h) ||
145 &error(&text('save_ehost', $h));