Handle hostnames with upper-case letters
[webmin.git] / exports / edit_export.cgi
1 #!/usr/local/bin/perl
2 # edit_export.cgi
3 # Allow editing of one export to a client
4
5 require './exports-lib.pl';
6 &ReadParse();
7 local $via_pfs = 0;
8 local $nfsv = nfs_max_version("localhost");
9 if ($in{'new'}) {
10         &ui_print_header(undef, $text{'create_title'}, "", "create_export");
11         $via_pfs = ($nfsv == 4) ? 1 : 0;
12         $exp->{"pfs"} = "/export";
13     }
14 else {
15         &ui_print_header(undef, $text{'edit_title'}, "", "edit_export");
16         @exps = &list_exports();
17         $exp = $exps[$in{'idx'}];
18         %opts = %{$exp->{'options'}};
19         }
20
21 # WebNFS doesn't exist on Linux
22 local $linux = ($gconfig{'os_type'} =~ /linux/i) ? 1 : 0;
23
24 print "<script type=\"text/javascript\">\n";
25 print "function enable_sec(level) {\n";
26 print " if (level) {\n";
27 print "   document.forms[0].sec[1].disabled=0;\n";
28 print "   document.forms[0].sec[2].disabled=0;\n";
29 print "   } else {\n";
30 print "   document.forms[0].sec[1].disabled=1;\n";
31 print "   document.forms[0].sec[2].disabled=1;\n";
32 print "   document.forms[0].sec[0].checked=1;\n";
33 print " }\n}\n";
34 print "function enable_pfs(enable) {\n";
35 print" set_pfs_dir();\n";
36 print "if (enable == 1) {\n";
37 print "   document.forms[0].pfs.disabled=0;\n";
38 print "   document.forms[0].pfs_button.disabled=0;\n";
39 print "   document.forms[0].pfs_dir.disabled=0;\n";
40 print "   } else {\n";
41 print "   document.forms[0].pfs.disabled=1;\n";
42 print "   document.forms[0].pfs_button.disabled=1;\n";
43 print "   document.forms[0].pfs_dir.disabled=1;\n";
44 print "   }\n";
45 print "}\n";
46 print "function set_pfs_dir() {\n";
47 print "   var pfs = document.forms[0].pfs.value;\n";
48 print "   var dir = document.forms[0].dir.value;\n";
49 print "   if (document.forms[0].via_pfs[0].checked == 0) {\n";
50 print "      document.forms[0].pfs_dir.value = dir; }\n";
51 print "   else {\n";
52 print "      var reg = /\\/\$/;\n";
53 print "      dir = dir.replace(reg, \"\");\n";
54 print "      dir = dir.substring(dir.lastIndexOf(\"/\"));\n";
55 print "      document.forms[0].pfs_dir.value = pfs + dir; }\n";
56 print "}\n";
57 print "window.onload = function() {\n";
58 print "   enable_pfs(document.forms[0].via_pfs[0].checked);\n";
59 print "   if (document.forms[0].auth[0].checked == 1) {\n";
60 print "      enable_sec(0); }\n";
61 print "   else {\n";
62 print "      enable_sec(1); }\n";
63 print "   set_pfs_dir();\n";
64 print "}\n";
65 print "</script>\n";
66
67 print "<form action=save_export.cgi>\n";
68 print "<input type=hidden name=new value='$in{'new'}'>\n";
69 print "<input type=hidden name=idx value='$in{'idx'}'>\n";
70
71 print "<table border width=100%>\n";
72 print "<tr $tb> <td><b>$text{'edit_details'}</b></td> </tr>\n";
73 print "<tr $cb> <td><table>\n";
74
75 # Show NFS pseudofilesystem (NFSv4)
76 if ($nfsv == 4) {
77     print "<tr> <td>",&hlink("<b>$text{'edit_nfs_vers'}</b>","vers"),"</td>\n";
78     printf "<td colspan=3><input type=radio name=via_pfs value=1 %s onclick=enable_pfs(1)> 4\n",
79     $via_pfs ? "checked" : "";
80     printf "<input type=radio name=via_pfs value=0 %s onclick=enable_pfs(0)> 3 (or lower)</td> </tr>\n",
81     $via_pfs ? "" : "checked";
82     
83     print "<tr> <td>",&hlink("<b>$text{'edit_pfs'}</b>","pfs"),"</td>\n";
84     printf "<td colspan=3><input name=pfs size=40 value=\"$exp->{'pfs'}\" onkeyup=set_pfs_dir()>";
85     print &file_chooser_button2("pfs", 1, "pfs_button", ($via_pfs == 0)),"</td> </tr>\n";
86 } else {
87     printf "<tr><td><input type=hidden name=via_pfs value=0></td></tr>\n";
88 }
89
90 # Show directory input
91 print "<tr> <td>",&hlink("<b>$text{'edit_dir'}</b>","dir"),"</td>\n";
92 print "<td colspan=3><input name=dir size=40 value=\"$exp->{'dir'}\" onkeyup=set_pfs_dir()>",
93     &file_chooser_button("dir", 1);
94 if ($nfsv == 4) {
95     print "$text{'edit_in'} <input style=\"background: rgb(238, 238, 238)\" name=pfs_dir size=40 readonly></td> </tr>\n";
96 }
97
98 # Show active input
99 print "<tr> <td>",&hlink("<b>$text{'edit_active'}</b>","active"),"</td>\n";
100 printf "<td colspan=3><input type=radio name=active value=1 %s> $text{'yes'}\n",
101     $in{'new'} || $exp->{'active'} ? 'checked' : '';
102 printf "<input type=radio name=active value=0 %s> $text{'no'}</td> </tr>\n",
103     $in{'new'} || $exp->{'active'} ? '' : 'checked';
104
105 # Show input for export to
106 local $h = $exp->{'host'};
107 if ($h eq "=public") { $mode = 0; }
108 elsif ($h =~ /^gss\//) {$mode = 5; }
109 elsif ($h =~ /^\@(.*)/) { $mode = 1; $netgroup = $1; }
110 elsif ($h =~ /^(\S+)\/(\S+)$/) { $mode = 2; $network = $1; $netmask = $2; }
111 elsif ($h eq "") { $mode = 3; }
112 else { $mode = 4; $host = $h; }
113 # and authentication input
114 local $auth = "", $sec = "";
115 if ($h =~ /^gss\/krb5/) {
116     $auth = "krb5";
117     if ($h =~ /i$/) { $sec = "i"; }
118     if ($h =~ /p$/) { $sec = "p"; }
119 }
120
121 print "<tr><td rowspan=8 valign=top>",&hlink("<b>$text{'edit_to'}</b>","client");
122 if ($nfsv == 4) {
123     print "<br>",&hlink("$text{'edit_auth'}","auth"),"</td>\n";
124     
125     printf "<td rowspan=5><input type=radio name=auth value=0 %s onclick=enable_sec(0)> sys</td>\n",
126     ($auth eq "") ? "checked" : "";
127 } else {
128     printf "<td><input type=hidden name=auth value=0></td>\n";
129 }
130 printf "<tr><td><input type=radio name=mode value=3 %s> $text{'edit_all'} </td>\n",
131         $mode == 3 ? "checked" : "";
132
133 printf "<td colspan=2><input type=radio name=mode value=4 %s> $text{'edit_host'}\n",
134         $mode == 4 ? "checked" : "";
135 print "<input name=host size=35 value='$host'></td> </tr>\n";
136
137 printf "<tr><td><input type=radio name=mode value=0 %s %s> $text{'edit_webnfs'}</td>\n",
138         $mode == 0 ? "checked" : "", $linux ? "disabled" : "";
139
140 printf "<td colspan=2><input type=radio name=mode value=1 %s> $text{'edit_netgroup'}\n",
141         $mode == 1 ? "checked" : "";
142 print "<input name=netgroup size=25 value='$netgroup'></td> </tr>\n";
143
144 printf "<tr><td colspan=3><input type=radio name=mode value=2 %s> IPv4 $text{'edit_network'}\n",
145         $mode == 2 ? "checked" : "";
146 print "<input name=network size=15 value='$network'>\n";
147 print "$text{'edit_netmask'} <input name=netmask size=15 value='$netmask'></td> </tr>\n";
148
149 printf "<tr><td colspan=3><input type=radio name=mode value=6 %s disabled> IPv6 $text{'edit_address'}\n",
150     $mode == 6 ? "checked" : "";
151 print "<input name=address size=39 value='$address' disabled>\n";
152 print "$text{'edit_prefix'}<input name=prefix size=2 value='$prefix' disabled></td> </tr>\n";
153
154 if ($nfsv == 4) {
155     printf "<tr><td colspan=3><input type=radio name=auth value=1 %s onclick=enable_sec(1)> krb5</td></tr>",
156     ($auth eq "krb5") ? "checked" : "";
157     printf "<tr><td colspan=3><input type=radio name=auth value=2 %s disabled> lipkey</td></tr>\n",
158     ($auth eq "lipkey") ? "checked" : "";
159     printf "<tr><td colspan=3><input type=radio name=auth value=3 %s disabled> spkm-3</td></tr>\n",
160     ($auth eq "spkm") ? "checked" : "";
161
162 # Show security level input
163 print "<tr> <td>", &hlink("<b>$text{'edit_sec'}</b>", "sec"), "</td>\n";
164 printf "<td nowrap colspan=3><input type=radio name=sec value=0 %s> $text{'config_none'}\n",
165     ($sec eq "") ? "checked" : "";
166 printf "<input type=radio name=sec value=1 %s> $text{'edit_integrity'}\n",
167     ($sec eq "i") ? "checked" : "";
168 printf "<input type=radio name=sec value=2 %s> $text{'edit_privacy'}</td></tr>\n",
169     ($sec eq "p") ? "checked" : "";
170 }
171
172 print "</table></td></tr></table><p>\n";
173 print "<table border width=100%>\n";
174 print "<tr $tb> <td><b>$text{'edit_security'}</b></td> </tr>\n";
175 print "<tr $cb> <td><table width=100%>\n";
176
177 # Show read-only input
178 print "<tr> <td>",&hlink("<b>$text{'edit_ro'}</b>","ro"),"</td>\n";
179 printf "<td><input type=radio name=ro value=1 %s> $text{'yes'}\n",
180         defined($opts{'rw'}) ? "" : "checked";
181 printf "<input type=radio name=ro value=0 %s> $text{'no'}</td>\n",
182         defined($opts{'rw'}) ? "checked" : "";
183
184 # Show input for secure port
185 print "<td>",&hlink("<b>$text{'edit_insecure'}</b>","insecure"),"</td>\n";
186 printf "<td><input type=radio name=insecure value=0 %s> $text{'yes'}\n",
187         defined($opts{'insecure'}) ? "" : "checked";
188 printf "<input type=radio name=insecure value=1 %s> $text{'no'}</td> </tr>\n",
189         defined($opts{'insecure'}) ? "checked" : "";
190
191 # Show subtree check input
192 print "<tr> <td>",&hlink("<b>$text{'edit_subtree_check'}</b>","subtree_check"),"</td>\n";
193 printf "<td><input type=radio name=no_subtree_check value=1 %s> $text{'yes'}\n",
194     defined($opts{'no_subtree_check'}) ? "checked" : "";
195 printf "<input type=radio name=no_subtree_check value=0 %s> $text{'no'}\n",
196     defined($opts{'no_subtree_check'}) ? "" : "checked";
197 print "</td>\n";
198
199 # Show nohide check input
200 print "<td>",&hlink("<b>$text{'edit_hide'}</b>","hide"),"</td>\n";
201 printf "<td><input type=radio name=nohide value=0 %s> $text{'yes'}\n",
202         defined($opts{'nohide'}) ? "" : "checked";
203 printf "<input type=radio name=nohide value=1 %s> $text{'no'}</td> </tr>\n",
204         defined($opts{'nohide'}) ? "checked" : "";
205
206 # Show sync input
207 my $sync = defined($opts{'sync'}) ? 1 : defined($opts{'async'}) ? 2 : 0;
208 print "<tr> <td>",&hlink("<b>$text{'edit_sync'}</b>","sync"),"</td>\n<td colspan=3>";
209 foreach $s (1, 2, 0) {
210         printf "<input type=radio name=sync value=%d %s> %s\n",
211                 $s, $sync == $s ? "checked" : "", $text{'edit_sync'.$s};
212         }
213 print "</td> </tr>\n";
214
215 # Show root trust input
216 print "<tr> <td>",&hlink("<b>$text{'edit_squash'}</b>","squash"),"</td> <td colspan=3>\n";
217 printf "<input type=radio name=squash value=0 %s> $text{'edit_everyone'}\n",
218         defined($opts{'no_root_squash'}) ? "checked" : "";
219 printf "<input type=radio name=squash value=1 %s> $text{'edit_except'}\n",
220         !defined($opts{'no_root_squash'}) &&
221         !defined($opts{'all_squash'}) ? "checked" : "";
222 printf "<input type=radio name=squash value=2 %s> $text{'edit_nobody'}\n";
223         defined($opts{'all_squash'}) ? "checked" : "";
224 print "</td> </tr>\n";
225
226 # Show untrusted user input
227 print "<tr> <td>",&hlink("<b>$text{'edit_anonuid'}</b>","anonuid"),"</td> <td>\n";
228 printf "<input type=radio name=anonuid_def value=1 %s> $text{'edit_default'}\n",
229     defined($opts{'anonuid'}) ? "" : "checked";
230 printf "<input type=radio name=anonuid_def value=0 %s>\n",
231     defined($opts{'anonuid'}) ? "checked" : "";
232 printf "<input name=anonuid size=8 value=\"%s\">\n",
233     $opts{'anonuid'} ? getpwuid($opts{'anonuid'}) : "";
234 print &user_chooser_button("anonuid", 0),"</td>\n";
235
236 # Show untrusted group input
237 print "<td>",&hlink("<b>$text{'edit_anongid'}</b>","anongid"),"</td> <td>\n";
238 printf "<input type=radio name=anongid_def value=1 %s> $text{'edit_default'}\n",
239     defined($opts{'anongid'}) ? "" : "checked";
240 printf "<input type=radio name=anongid_def value=0 %s>\n",
241     defined($opts{'anongid'}) ? "checked" : "";
242 printf "<input name=anongid size=8 value=\"%s\">\n",
243     $opts{'anongid'} ? getgrgid($opts{'anongid'}) : "";
244 print &group_chooser_button("anongid", 0),"</td> </tr>\n";
245
246 print "<tr $tb> <td colspan=4><b>$text{'edit_v2opts'}</b></td> </tr>\n";
247
248 # Show input for relative symlinks
249 print "<tr> <td>",&hlink("<b>$text{'edit_relative'}</b>","link_relative"),"</td>\n";
250 printf "<td><input type=radio name=link_relative value=1 %s> $text{'yes'}\n",
251     defined($opts{'link_relative'}) ? "checked" : "";
252 printf "<input type=radio name=link_relative value=0 %s> $text{'no'}</td>\n",
253     defined($opts{'link_relative'}) ? "" : "checked";
254
255 # Show deny access input
256 print "<td>",&hlink("<b>$text{'edit_noaccess'}</b>","noaccess"),"</td>\n";
257 printf "<td><input type=radio name=noaccess value=1 %s> $text{'yes'}\n",
258     defined($opts{'noaccess'}) ? "checked" : "";
259 printf "<input type=radio name=noaccess value=0 %s> $text{'no'}</td> </tr>\n",
260     defined($opts{'noaccess'}) ? "" : "checked";
261
262 # Show untrusted UIDs input
263 print "<tr> <td>",&hlink("<b>$text{'edit_uids'}</b>","squash_uids"),"</td> <td>\n";
264 printf "<input type=radio name=squash_uids_def value=1 %s> $text{'edit_none'}\n",
265     $opts{'squash_uids'} ? "" : "checked";
266 printf "<input type=radio name=squash_uids_def value=0 %s>\n",
267     $opts{'squash_uids'} ? "checked" : "";
268 printf "<input name=squash_uids size=15 value=\"%s\"></td>\n",
269     $opts{'squash_uids'};
270
271 # Show untrusted GIDs input
272 print "<td>",&hlink("<b>$text{'edit_gids'}</b>","squash_gids"),"</td> <td>\n";
273 printf "<input type=radio name=squash_gids_def value=1 %s> $text{'edit_none'}\n",
274     $opts{'squash_gids'} ? "" : "checked";
275 printf "<input type=radio name=squash_gids_def value=0 %s>\n",
276     $opts{'squash_gids'} ? "checked" : "";
277 printf "<input name=squash_gids size=15 value=\"%s\"></td> </tr>\n",
278     $opts{'squash_gids'};
279
280 print "</table></td></tr></table>\n";
281 if (!$in{'new'}) {
282         print "<table width=100%><tr>\n";
283         print "<td><input type=submit value=\"$text{'save'}\"></td>\n";
284         print "<td align=right><input type=submit name=delete ",
285               "value=\"$text{'delete'}\"></td>\n";
286         print "</tr></table>\n";
287         }
288 else {
289         print "<input type=hidden name=new value=1>\n";
290         print "<input type=submit value=\"$text{'create'}\">\n";
291         }
292
293 &ui_print_footer("", $text{'index_return'});