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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#!/usr/local/bin/perl
# Show a form for backing up a single virtual server, or a bunch
#
# XXX support use by domain owners?
require './virtual-server-lib.pl';
&ReadParse();
&master_admin() || &error($text{'backup_ecannot'});
if ($in{'sched'}) {
&ui_print_header(undef, $text{'backup_title2'}, "");
print "<form action=backup_sched.cgi method=post>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$text{'backup_header2'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
}
else {
&ui_print_header(undef, $text{'backup_title'}, "");
print "<form action=backup.cgi method=post>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$text{'backup_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
}
# Work out default backup selection
$dest = $config{'backup_dest'};
$backup_fmt = $config{'backup_fmt'};
$backup_errors = $config{'backup_errors'};
$backup_strftime = $config{'backup_strftime'};
print "<tr> <td valign=top><b>$text{'backup_doms'}</td> <td>\n";
if (defined($in{'dom'})) {
# Just one domain
$d = &get_domain($in{'dom'});
if (defined($d->{'backup_dest'})) {
$dest = $d->{'backup_dest'};
}
elsif ($config{'backup_fmt'} == 0 && $dest) {
$dest .= "/$d->{'dom'}.tar.gz";
}
$backup_fmt = $d->{'backup_fmt'}
if (defined($d->{'backup_fmt'}));
$backup_errors = $d->{'backup_errors'}
if (defined($d->{'backup_errors'}));
$backup_strftime = $d->{'backup_strftime'}
if (defined($d->{'backup_strftime'}));
print &ui_hidden("dom", $in{'dom'}),"\n";
print &ui_hidden("doms", $in{'dom'}),"\n";
print &ui_hidden("backup_all", 0),"\n";
print "<tt>$d->{'dom'}</tt>\n";
}
else {
# User can select which domains
$backup_all = $config{'backup_all'};
%bak = map { $_, 1 } split(/\s+/, $config{'backup_doms'});
@doms = &list_domains();
printf "<input type=radio name=all value=1 %s> %s\n",
$backup_all == 1 ? "checked" : "", $text{'backup_all'};
printf "<input type=radio name=all value=0 %s> %s\n",
$backup_all == 0 ? "checked" : "", $text{'backup_sel'};
printf "<input type=radio name=all value=2 %s> %s\n",
$backup_all == 2 ? "checked" : "", $text{'backup_exc'};
print "<br>\n";
$sz = scalar(@doms) > 10 ? 10 : scalar(@doms);
print "<select name=doms multiple size=$sz width=400>\n";
foreach $d (sort { $a->{'dom'} cmp $b->{'dom'} } @doms) {
printf "<option value=%s %s>%s\n",
$d->{'id'}, $bak{$d->{'id'}} ? "selected" : "", $d->{'dom'};
}
print "</select>\n";
}
print "</td> </tr>\n";
# Show feature selection boxes
print "<tr> <td valign=top><b>$text{'backup_features'}</td> <td>\n";
foreach $f (@backup_features) {
local $bfunc = "backup_$f";
if (defined(&$bfunc) &&
($config{$f} || $f eq "unix" || $f eq "virtualmin")) {
printf "<input type=checkbox name=feature value=%s %s> %s\n",
$f, $config{'backup_feature_'.$f} ? "checked" : "",
$text{'backup_feature_'.$f} || $text{'feature_'.$f};
local $ofunc = "show_backup_$f";
if (defined(&$ofunc)) {
local %opts = map { split(/=/, $_) }
split(/,/, $config{'backup_opts_'.$f});
local $ohtml = &$ofunc(\%opts);
print $ohtml;
}
print "<br>\n";
}
}
print "</td> </tr>\n";
# Show destination fields
print "<tr> <td valign=top><b>$text{'backup_dest'}</td>\n";
print "<td>",&show_backup_destination("dest", $dest),
"</td> </tr>\n";
print "<tr> <td></td>\n";
printf "<td><input type=checkbox name=strftime value=1 %s> %s</td> </tr>\n",
$backup_strftime ? "checked" : "", $text{'backup_strftime'};
print "<tr> <td><b>$text{'backup_fmt'}</td> <td>\n";
printf "<input type=radio name=fmt value=0 %s> %s\n",
$backup_fmt == 0 ? "checked" : "", $text{'backup_fmt0'};
printf "<input type=radio name=fmt value=1 %s> %s</td> </tr>\n",
$backup_fmt == 1 ? "checked" : "", $text{'backup_fmt1'};
# Show error mode
print "<tr> <td><b>$text{'backup_errors'}</td> <td>\n";
printf "<input type=radio name=errors value=0 %s> %s\n",
$backup_errors == 0 ? "checked" : "", $text{'backup_errors0'};
printf "<input type=radio name=errors value=1 %s> %s</td> </tr>\n",
$backup_errors == 1 ? "checked" : "", $text{'backup_errors1'};
if ($in{'sched'}) {
# Show schedule inputs
&foreign_require("cron", "cron-lib.pl");
local @jobs = &cron::list_cron_jobs();
local ($job) = grep { $_->{'user'} eq 'root' &&
$_->{'command'} eq $backup_cron_cmd } @jobs;
# Enabled/disabled input
print "<tr> <td><b>$text{'backup_enabled'}</b></td>\n";
printf "<td><input type=radio name=enabled value=0 %s> %s\n",
$job ? "" : "checked", $text{'no'};
printf "<input type=radio name=enabled value=1 %s> %s</td> </tr>\n",
$job ? "checked" : "", $text{'backup_enabledyes'};
# Email input
print "<tr> <td><b>$text{'backup_email'}</b></td>\n";
printf "<td><input name=email size=40 value='%s'></td> </tr>\n",
$config{'backup_email'};
# Times input
print "<tr> <td colspan=2><table border>\n";
$job ||= { 'special' => 'daily' };
&cron::show_times_input($job);
print "</table></td> </tr>\n";
print "</table></td></tr></table>\n";
print "<input type=submit value='$text{'backup_save'}'></form>\n";
}
else {
print "</table></td></tr></table>\n";
print "<input type=submit value='$text{'backup_now'}'></form>\n";
}
&ui_print_footer("", $text{'index_return'});
|