1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#!/usr/local/bin/perl
# Actually restore some servers, after asking for confirmation
require './virtual-server-lib.pl';
&master_admin() || &error($text{'restore_ecannot'});
&ReadParse();
# Validate inputs
&error_setup($text{'restore_err'});
if ($in{'src'}) {
$src = $in{'src'};
}
else {
$src = &parse_backup_destination("src", \%in);
}
($mode) = &parse_backup_url($src);
$mode > 0 || -r $src || -d $src || &error($text{'restore_esrc'});
@do_features = split(/\0/, $in{'feature'});
@do_features || &error($text{'restore_efeatures'});
%do_features = map { $_, 1 } @do_features;
# Parse option inputs
foreach $f (@do_features) {
local $ofunc = "parse_restore_$f";
if (defined(&$ofunc)) {
$options{$f} = &$ofunc(\%in);
}
}
$cont = &backup_contents($src);
if (!$in{'confirm'}) {
# See what is in the tar file or directory
ref($cont) || &error(&text('restore_efile', $cont));
(keys %$cont) || &error($text{'restore_enone'});
}
else {
# Find the selected domains
foreach $d (split(/\0/, $in{'dom'})) {
local $dinfo = &get_domain_by("dom", $d);
if ($dinfo) {
push(@doms, $dinfo);
}
else {
push(@doms, { 'dom' => $d,
'missing' => 1 });
}
}
@doms || &error($text{'restore_edoms'});
}
if ($in{'confirm'}) {
&ui_print_unbuffered_header(undef, $text{'restore_title'}, "");
}
else {
&ui_print_header(undef, $text{'restore_title'}, "");
}
if (!$in{'confirm'}) {
# Tell the user what will be done
print "<form action=restore.cgi method=post>\n";
print &text('restore_from', "<tt>$src</tt>"),"<p>\n";
print "<dl>\n";
foreach $d (sort { $a cmp $b } keys %$cont) {
print "<dt><input type=checkbox name=dom ",
"value='$d' checked><b>$d</b>\n";
if (!&get_domain_by("dom", $d)) {
print "($text{'restore_create'})\n";
}
@dfeats = grep { $do_features{$_} } @{$cont->{$d}};
if (!@dfeats) {
print "<dd><i>$text{'restore_nofeat'}</i>\n";
}
else {
print "<dd>",join("<br>",
map { $text{'backup_feature_'.$_} ||
$text{'feature_'.$_} } @dfeats),"\n";
$any++;
}
}
print "</dl>\n";
if ($any) {
# Pass all HTML inputs to program again, and show OK button
print "<input type=hidden name=src value='",
&html_escape($src),"'>\n";
foreach $i (keys %in) {
next if ($i =~ /^src_/);
foreach $v (split(/\0/, $in{$i})) {
print "<input type=hidden name='$i' value='$v'>\n";
}
}
print "<center><input type=submit name=confirm value='$text{'restore_now2'}'></center>\n";
}
else {
print "$text{'restore_notany'}<p>\n";
}
print "</form>\n";
}
else {
# Actually execute the restore
print "<p>",&text('restore_doing', scalar(@doms), "<tt>$src</tt>"),"<p>\n";
$ok = &restore_domains($src, \@doms, \@do_features, \%options);
&run_post_actions();
if ($ok) {
print &text('restore_done'),"<p>\n";
}
else {
print &text('restore_failed'),"<p>\n";
}
&webmin_log("restore", $src, undef,
{ 'doms' => [ map { $_->{'dom'} } @doms ] });
}
&ui_print_footer("", $text{'index_return'});
|