Handle hostnames with upper-case letters
[webmin.git] / fsdump / solaris-lib.pl.bak
1 # solaris-lib.pl
2
3 # supported_filesystems()
4 # Returns a list of filesystem types on which dumping is supported
5 sub supported_filesystems
6 {
7 local @rv;
8 push(@rv, "ufs") if (&has_command("ufsdump"));
9 return @rv;
10 }
11
12 # dump_form(&dump)
13 sub dump_form
14 {
15 # Display common options
16 print "<tr> <td valign=top><b>",&hlink($text{'dump_dest'}, "dest"),
17       "</b></td> <td colspan=3>\n";
18 printf "<input type=radio name=mode value=0 %s> %s\n",
19         $_[0]->{'host'} ? '' : 'checked', $text{'dump_file'};
20 printf "<input name=file size=50 value='%s'> %s<br>\n",
21         $_[0]->{'host'} ? '' : $_[0]->{'file'},
22         &file_chooser_button("file");
23 printf "<input type=radio name=mode value=1 %s>\n",
24         $_[0]->{'host'} ? 'checked' : '';
25 print &text('dump_host',
26             "<input name=host size=15 value='$_[0]->{'host'}'>",
27             "<input name=huser size=8 value='$_[0]->{'huser'}'>",
28             "<input name=hfile size=20 value='$_[0]->{'hfile'}'>"),
29       "</td> </tr>\n";
30
31 print "<tr> <td><b>",&hlink($text{'dump_update'},"update"),
32       "</b></td>\n";
33 printf "<td><input name=update type=radio value=1 %s> %s\n",
34         $_[0]->{'update'} ? 'checked' : '', $text{'yes'};
35 printf "<input name=update type=radio value=0 %s> %s</td>\n",
36         $_[0]->{'update'} ? '' : 'checked', $text{'no'};
37
38 print "<td><b>",&hlink($text{'dump_verify'},"verify"),"</b></td>\n";
39 printf "<td><input name=verify type=radio value=1 %s> %s\n",
40         $_[0]->{'verify'} ? 'checked' : '', $text{'yes'};
41 printf "<input name=verify type=radio value=0 %s> %s</td> </tr>\n",
42         $_[0]->{'verify'} ? '' : 'checked', $text{'no'};
43
44 print "<tr> <td><b>",&hlink($text{'dump_level'},"level"),"</b></td>\n";
45 print "<td><select name=level>\n";
46 foreach $l (0 .. 9) {
47         printf "<option value=%d %s>%d %s\n",
48                 $l, $_[0]->{'level'} == $l ? "selected" : "", $l,
49                 $text{'dump_level_'.$l};
50         }
51 print "</select></td>\n";
52
53 print "<td><b>",&hlink($text{'dump_offline'},"offline"),"</b></td>\n";
54 printf "<td><input name=offline type=radio value=1 %s> %s\n",
55         $_[0]->{'offline'} ? 'checked' : '', $text{'yes'};
56 printf "<input name=offline type=radio value=0 %s> %s</td> </tr>\n",
57         $_[0]->{'offline'} ? '' : 'checked', $text{'no'};
58 }
59
60 # parse_dump(&dump)
61 sub parse_dump
62 {
63 # Parse common options
64 if ($in{'mode'} == 0) {
65         $in{'file'} =~ /\S/ || &error($text{'dump_efile'});
66         $_[0]->{'file'} = $in{'file'};
67         delete($_[0]->{'host'});
68         delete($_[0]->{'huser'});
69         delete($_[0]->{'hfile'});
70         }
71 else {
72         gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
73                 &error($text{'dump_ehost'});
74         $_[0]->{'host'} = $in{'host'};
75         $in{'huser'} =~ /^\S+$/ || &error($text{'dump_ehuser'});
76         $_[0]->{'huser'} = $in{'huser'};
77         $in{'hfile'} || &error($text{'dump_ehfile'});
78         $_[0]->{'hfile'} = $in{'hfile'};
79         delete($_[0]->{'file'});
80         }
81
82 $_[0]->{'update'} = $in{'update'};
83 $_[0]->{'verify'} = $in{'verify'};
84 $_[0]->{'level'} = $in{'level'};
85 $_[0]->{'offline'} = $in{'offline'};
86 }
87
88 # execute_dump(&dump, filehandle, escape)
89 # Executes a dump and displays the output
90 sub execute_dump
91 {
92 local $fh = $_[1];
93 local $cmd = "ufsdump $_[0]->{'level'}";
94 $cmd .= "u" if ($_[0]->{'update'});
95 $cmd .= "v" if ($_[0]->{'verify'});
96 $cmd .= "o" if ($_[0]->{'offline'});
97 if ($_[0]->{'huser'}) {
98         $cmd .= "f '$_[0]->{'huser'}@$_[0]->{'host'}:$_[0]->{'hfile'}'";
99         }
100 elsif ($_[0]->{'host'}) {
101         $cmd .= "f '$_[0]->{'host'}:$_[0]->{'hfile'}'";
102         }
103 else {
104         $cmd .= "f '$_[0]->{'file'}'";
105         }
106 $cmd .= " '$_[0]->{'dir'}'";
107
108 &system_logged("sync");
109 sleep(1);
110 &additional_log('exec', undef, $cmd);
111 open(CMD, "$cmd 2>&1 </dev/null |");
112 while(<CMD>) {
113         if ($_[2]) {
114                 print $fh &html_escape($_);
115                 }
116         else {
117                 print $fh $_;
118                 }
119         }
120 close(CMD);
121 }
122
123 # dump_dest(&dump)
124 sub dump_dest
125 {
126 if ($_[0]->{'file'}) {
127         return "<tt>".&html_escape($_[0]->{'file'})."</tt>";
128         }
129 elsif ($_[0]->{'huser'}) {
130         return "<tt>".&html_escape("$_[0]->{'huser'}@$_[0]->{'host'}:$_[0]->{'hfile'}")."</tt>";
131         }
132 else {
133         return "<tt>".&html_escape("$_[0]->{'host'}:$_[0]->{'hfile'}")."</tt>";
134         }
135 }
136
137 # missing_restore_command(filesystem)
138 sub missing_restore_command
139 {
140 return &has_command("ufsrestore") ? undef : "ufsrestore";
141 }
142
143 # restore_form(filesystem)
144 sub restore_form
145 {
146 # common options
147 print "<tr> <td valign=top><b>",&hlink($text{'restore_src'}, "rsrc"),
148       "</b></td>\n";
149 printf "<td colspan=3><input type=radio name=mode value=0 checked> %s\n",
150         $text{'dump_file'};
151 printf "<input name=file size=50> %s<br>\n",
152         &file_chooser_button("file");
153 printf "<input type=radio name=mode value=1>\n";
154 print &text('dump_host',
155             "<input name=host size=15>",
156             "<input name=huser size=8>",
157             "<input name=hfile size=20>"),
158       "</td> </tr>\n";
159
160 print "<tr> <td><b>",&hlink($text{'restore_files'},"rfiles"),
161       "</b></td>\n";
162 print "<td colspan=3><input type=radio name=files_def value=1 checked> ",
163       "$text{'restore_all'}\n";
164 print "<input type=radio name=files_def value=0> $text{'restore_sel'}\n";
165 print "<input name=files size=40></td> </tr>\n";
166
167 print "<tr> <td><b>",&hlink($text{'restore_dir'},"rdir"),"</td>\n";
168 print "<td><input name=dir size=40> ",&file_chooser_button("dir", 1),
169       "</td> </tr>\n";
170
171 print "<tr> <td><b>",&hlink($text{'restore_test'},"rtest"),"</td>\n";
172 print "<td><input type=radio name=test value=1> $text{'yes'}\n";
173 print "<input type=radio name=test value=0 checked> $text{'no'}</td> </tr>\n";
174 }
175
176 # parse_restore(filesystem)
177 # Parses inputs from restore_form() and returns a command to be passed to
178 # restore_backup()
179 sub parse_restore
180 {
181 local $cmd;
182 $cmd = "ufsrestore";
183 $cmd .= ($in{'test'} ? " t" : " x");
184 if ($in{'mode'} == 0) {
185         $in{'file'} || &error($text{'restore_efile'});
186         $cmd .= "f '$in{'file'}'";
187         }
188 else {
189         gethostbyname($in{'host'}) || &check_ipaddress($in{'host'}) ||
190                 &error($text{'restore_ehost'});
191         $in{'huser'} =~ /^\S*$/ || &error($text{'restore_ehuser'});
192         $in{'hfile'} || &error($text{'restore_ehfile'});
193         if ($in{'huser'}) {
194                 $cmd .= "f '$in{'huser'}@$in{'host'}:$in{'hfile'}'";
195                 }
196         else {
197                 $cmd .= "f '$in{'host'}:$in{'hfile'}'";
198                 }
199         }
200
201 if (!$in{'files_def'}) {
202         $in{'files'} || &error($text{'restore_efiles'});
203         $cmd .= " $in{'files'}";
204         }
205 -d $in{'dir'} || &error($text{'restore_edir'});
206
207 return $cmd;
208 }
209
210 # restore_backup(filesystem, command)
211 # Restores a backup based on inputs from restore_form(), and displays the results
212 sub restore_backup
213 {
214 &additional_log('exec', undef, $_[1]);
215
216 &foreign_require("proc", "proc-lib.pl");
217 local ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", "cd '$in{'dir'}' ; $_[1]");
218 local $donevolume;
219 while(1) {
220         local $rv = &wait_for($fh, "(next volume #)", "(set owner.mode for.*\\[yn\\])", "(Directories already exist, set modes anyway. \\[yn\\])", "((.*)\\[yn\\])", "(.*\\n)");
221         last if ($rv < 0);
222         print &html_escape($matches[1]);
223         if ($rv == 0) {
224                 if ($donevolume++) {
225                         return $text{'restore_evolume'};
226                         }
227                 else {
228                         syswrite($fh, "1\n");
229                         }
230                 }
231         elsif ($rv == 1 || $rv == 2) {
232                 syswrite($fh, "n\n");
233                 }
234         elsif ($rv == 3) {
235                 return &text('restore_equestion',
236                              "<tt>$matches[2]</tt>");
237                 }
238         }
239 close($fh);
240 return undef;
241 }
242
243 1;
244