Handle hostnames with upper-case letters
[webmin.git] / hpuxexports / hpux-lib.pl
1 # hpux-lib.pl
2 # Functions for HPUX exports files
3
4 # list_exports()
5 # Return a list of all the directories currently being exported
6 sub list_exports
7 {
8 local (@rv, $pos, $lnum, $h, $o, $line);
9 return @list_exports_cache if (@list_exports_cache);
10 open(EXP, $config{'exports_file'});
11 $lnum = 0;
12 while($line = <EXP>) {
13         local $slnum = $lnum;
14         $line =~ s/\s+$//g;
15         while($line =~ /\\$/) {
16                 # continuation character!
17                 $line =~ s/\\$//;
18                 $line .= <EXP>;
19                 $line =~ s/\s+$//g;
20                 $lnum++;
21                 }
22         if ($line =~ /^(#*)\s*(\/\S*)\s+-(.*)$/) {
23                 local %exp;
24                 $exp{'active'} = !$1;
25                 $exp{'dir'} = $2;
26                 # 'host' includes the hole option string!
27                 # for describe_host needed, only
28                 $exp{'host'} = $3;
29                 parse_options($3, $exp{'options'});
30                 $exp{'line'} = $slnum;
31                 $exp{'eline'} = $lnum;
32                 $exp{'pos'} = $pos++;
33                 $exp{'index'} = scalar(@rv);
34                 push(@rv, \%exp);
35                 }
36         $lnum++;
37         }
38 close(EXP);
39 @list_exports_cache = @rv;
40 return @list_exports_cache;
41 }
42
43
44 # make_exports_line([&export]+)
45 sub make_exports_line
46 {
47 local ($options, $line);
48 $options = join_options($_[0]->{'options'});
49 $line = ($_[0]->{'active'} ? "" : "#").$_[0]->{'dir'};
50 $line .= ($options ? " -".$options : "");
51 return $line;
52 }
53
54
55 # describe_host(host)
56 # Given a host option string return a human-readable version
57 sub describe_host
58 {
59 local ($desc, %options);
60 &parse_options($_[0], \%options);
61 if (defined($options{"ro"}) && $options{"access"} ne "") {
62         $desc = $text{'index_sel_ro'};
63         }
64 elsif (defined($options{"ro"}) && !defined($options{"access"})) {
65         $desc = $text{'index_all_ro'};
66         }
67 elsif ($options{"rw"} ne "") {
68         $desc = $text{'index_ro_rw'};
69         }
70 elsif (!defined($options{"ro"}) && $options{"access"} ne "") {
71         $desc = $text{'index_sel_rw'};
72         }
73 elsif (!defined($options{"ro"}) && !defined($options{"rw"}) && !defined($options{"access"})) {
74         $desc = $text{'index_all_rw'};
75         }
76 if ($options{"root"} ne "") {
77         $desc .= ", ";
78         $desc .= $text{'index_sel_root'};
79         }
80 return $desc;
81 }
82
83 # more_detail_fields()
84 sub more_detail_fields
85 {
86 print " <td><b>", &hlink($text{'edit_async'}, "async"), "</b></td>\n";
87 printf "<td nowrap><input type=radio name=async value=1 %s> %s\n",
88         defined($opts{"async"}) ? "checked" : "", $text{'yes'};
89 printf "<input type=radio name=nfs_bg value=0 %s> %s</td> </tr>\n",
90         defined($opts{"async"}) ? "" : "checked", $text{'no'};
91 }
92
93 # security_fields()
94 sub security_fields
95 {
96 print "<tr $cb>\n";
97 print " <td><b>", &hlink($text{'edit_user_access'}, "user_access"), "</b></td>\n";
98 print " <td><b>", &hlink($text{'edit_root_access'}, "root_access"), "</b></td>\n";
99 print " <td><b>", &hlink($text{'edit_anon_access'}, "anon"), "</b></td>\n";
100 print "</tr>\n";
101
102 $fn = "<font size=-1>"; $efn = "</font>";
103 print "<tr $cb>\n";
104 printf " <td><input type=radio name=user value=1 %s> $text{'edit_sel_ro'}<br>\n",
105         defined($opts{"ro"}) && $opts{"access"} ne "" ? "checked" : "";
106 printf "<input type=radio name=user value=2 %s> $text{'edit_all_ro'}<br>\n",
107         defined($opts{"ro"}) && !defined($opts{"access"}) ? "checked" : "";
108 printf "<input type=radio name=user value=3 %s> $text{'edit_ro_rw'}<br>\n",
109         $opts{"rw"} ne "" ? "checked" : "";
110 printf "<input type=radio name=user value=4 %s> $text{'edit_sel_rw'}<br>\n",
111         !defined($opts{"ro"}) && $opts{"access"} ne "" ? "checked" : "";
112 printf "<input type=radio name=user value=5 %s> $text{'edit_all_rw'}<br>\n",
113         !defined($opts{"ro"}) && !defined($opts{"rw"}) && !defined($opts{"access"}) ? "checked" : "";
114 print " </td>\n";
115 printf " <td><input type=radio name=root value=1 %s> $text{'edit_none'}<br>\n",
116         defined($opts{"root"}) ? "" : "checked";
117 print "<br>";
118 print "<br>";
119 print "<br>";
120 printf "<input type=radio name=root value=2 %s> $text{'edit_sel_hosts'}<br>\n",
121         $opts{"root"} ne "" ? "checked" : "";
122 print " </td>\n";
123 print " <td>\n";
124 if ($in{'new'}) { $opts{"anon"} = getpwnam("nobody"); }
125 printf "<input type=radio name=anon value=1 %s> $text{'edit_anon_noaccess'}<br>\n",
126         $opts{"anon"} == -1 ? "checked" : "";
127 if (defined($opts{"anon"}) && $opts{"anon"} != -1) {
128         $anonuser = getpwuid($opts{'anon'}) ?
129                 getpwuid($opts{'anon'}) : $opts{'anon'};
130         }
131 printf "<input type=radio name=anon value=2 %s>\n",
132         $opts{"anon"} != -1 ? "checked" : "";
133 print "<input name=anonnam size=8 value=\"$anonuser\"> ",
134         &user_chooser_button("anonnam", 0),"\n";   
135 print "<br>";
136 print "<br>";
137 print "<br>";
138 print "<br>";
139 print " </td>\n";
140 print "</tr>\n";
141
142 print "<tr $cb>\n";
143 print " <td>$fn<textarea name=ualist rows=6 cols=40 >";
144         if ($opts{"rw"} ne "") {
145                 $list = join("\n", split(/:/, $opts{"rw"}));
146                 }
147         if ($opts{"access"} ne "") {
148                 $list = join("\n", split(/:/, $opts{"access"}));
149                 }
150         print $list;
151 print "</textarea>$efn</td>\n";
152 printf " <td>$fn<textarea name=rtlist rows=6 cols=40 >%s</textarea>$efn</td>\n",
153         join("\n", split(/:/, $opts{"root"}));
154 print "</tr>\n";
155 }
156
157 # check_inputs()
158 sub check_inputs
159 {
160 if ($in{user} == 1 || $in{user} == 3 || $in{user} == 4) {
161         &check_hosts($text{'edit_user_access'}, $in{ualist});
162         @ualist = split(/\s+/, $in{ualist});
163         }
164 if ($in{root} == 2) {
165         &check_hosts($text{'edit_root_access'}, $in{rtlist});
166         @rtlist = split(/\s+/, $in{rtlist});
167         }
168
169 # Remove from the root list any hosts which not in the user list as well
170 if (($in{user} == 1 || $in{user} == 3 || $in{user} == 4) && $in{root} == 2) {
171         @tmplist = @rtlist;
172         foreach $rth (@tmplist) {
173                 if (($idx = &indexof($rth, @ualist)) == -1) {
174                         splice(@rtlist, &indexof($rth, @rtlist), 1);
175                         }
176                 }
177         if (@rtlist == 0) {
178                 $in{root} = 1;
179                 }
180         }
181 }
182
183
184 # set_options()
185 # Fill in the options associative array
186 sub set_options
187 {
188 delete($opts{"ro"});
189 delete($opts{"rw"});
190 delete($opts{"access"});
191 if ($in{user} == 1) { $opts{"ro"} = ""; $opts{"access"} = join(':', @ualist); }
192 elsif ($in{user} == 2) { $opts{"ro"} = ""; }
193 elsif ($in{user} == 3) { $opts{"rw"} = join(':', @ualist); }
194 elsif ($in{user} == 4) { $opts{"access"} = join(':', @ualist); }
195 elsif ($in{user} == 5) { ; }
196
197 if ($in{root} == 1) { delete($opts{"root"}); }
198 elsif ($in{root} == 2) { $opts{"root"} = join(':', @rtlist); }
199
200 if ($in{async} == 1) { $opts{"async"} = ""; }
201 else { delete($opts{"async"}); }
202
203 if ($in{'anon'} == 1) { $opts{"anon"} = -1; }
204 elsif ($in{'anonnam'} =~ /^[0-9\-]+$/)
205         { $opts{"anon"} = $in{"anonnam"}; }
206 elsif (getpwnam($in{"anonnam"})) 
207         { $opts{"anon"} = getpwnam($in{"anonnam"}); }
208 else { $opts{"anon"} = -1; }
209 }
210
211 1;
212