[!
use strict;
use PVE::pvecfg;
use PVE::I18N;
use PVE::ConfigServer;
use PVE::HTMLTable;
use PVE::HTMLDropDown;
use PVE::HTMLForm;
use PVE::HTMLGrid;
use PVE::HTMLUtils;
!]
[-
use strict;
my $cinfo = $fdat{__cinfo};
my $cidlist = [];
if ($cinfo->{local}->{role} eq '-') {
my $ni = $cinfo->{local};
push @$cidlist, [0, "$ni->{name} ($ni->{ip})"];
} else {
foreach my $ni (@{$cinfo->{nodes}}) {
next if !$ni->{cid};
push @$cidlist, [$ni->{cid}, "$ni->{name} ($ni->{ip})"];
}
}
my $out = '';
my $conn = PVE::ConfigClient::connect ($udat{auth_cookie});
my $form = PVE::HTMLForm->new (\%fdat);
if ($udat{action} eq 'delete') {
my ($jid, $digest) = split (/:/, $fdat{aa});
eval {
check_write_mode ($udat{AM});
$conn->update_config_data ('vzdump', { $jid => undef , digest => $digest })->result;
};
if ($@) {
$udat{popup_error} = $@;
$udat{redirect} = $fdat{__uri};
return;
}
}
if ($form->action eq 'save') {
my ($jid, $digest) = split (/:/, $fdat{aa});
my $d = {};
eval {
check_write_mode ($udat{AM});
my ($hour, $minute) = split (/:/, $fdat{starttime});
$d->{node} = $fdat{hostcid} || 0;
$d->{hour} = $hour;
$d->{minute} = $minute;
$d->{mode} = $fdat{bkmode} || 'snapshot';
if ($fdat{incmode}) {
$d->{includeall} = 1;
} else {
$d->{vmlist} = $fdat{vmsel};
}
if ($fdat{storage}) {
$d->{storage} = $fdat{storage};
} elsif ($fdat{dumpdir}) {
$d->{dumpdir} = $fdat{dumpdir};
$d->{dumpdir} = "/$d->{dumpdir}" if $d->{dumpdir} !~ m|^/|;
if (! -d $d->{dumpdir}) {
die sprintf (__("Destination directory '%s' does not exist") . "\n", $d->{dumpdir});
}
}
$d->{compress} = $fdat{compress};
$d->{mailto} = $fdat{mailto};
$d->{maxfiles} = $fdat{maxfiles};
my $found = 0;
foreach my $day (split ('\s+', $fdat{dow})) {
$d->{$day} = 1;
$found = 1;
}
die __("Please select at least one day") . "\n" if !$found;
$conn->update_config_data ('vzdump', { $jid => $d, digest => $digest})->result;
};
if ($@) {
$udat{popup_error} = $@;
} else {
$fdat{edit} = undef;
}
}
my $jobs = $conn->get_config_data ('vzdump')->result;
my $stinfo = $conn->storage_user_info ()->result;
my $stcfg = $stinfo->{cfg};
my $def_storage = $stinfo->{backup_default};
if ($fdat{edit} == 2 && !$def_storage) {
$udat{popup_error} = __("no backup storage defined - please create a backup storage first");
} elsif ($fdat{edit} == 1 || ($fdat{edit} == 2 && $def_storage)) {
my $d;
my ($jid, $digest) = split (/:/, $fdat{aa});
if ($fdat{edit} == 2) {
$d = { hour => 2,
minute => 0,
mode => 'snapshot',
compress => 0,
dow => "mon tue wed thu fri sat sun",
node => $cinfo->{local}->{cid},
includeall => 0,
mailto => '',
maxfiles => '1',
};
$d->{storage} = $def_storage;
} else {
$d = $jobs->{$jid};
$d->{dow} =~ s/,/ /g;
$d->{node} = 0 if !defined ($d->{node});
}
my $vzlist = $conn->cluster_vzlist()->result;
if (!defined ($fdat{hostcid})) {
$fdat{hostcid} = $d->{node};
}
if (!defined ($fdat{storage})) {
$fdat{storage} = $d->{storage};
}
if (!defined ($fdat{dumpdir})) {
$fdat{dumpdir} = $d->{dumpdir};
}
if (!defined ($fdat{incmode})) {
$fdat{incmode} = $d->{includeall};
}
if (!defined ($fdat{compress})) {
$fdat{compress} = $d->{compress};
}
if (!defined ($fdat{mailto})) {
$fdat{mailto} = $d->{mailto};
}
if (!defined ($fdat{maxfiles})) {
$fdat{maxfiles} = $d->{maxfiles};
}
if (!defined ($fdat{bkmode})) {
$fdat{bkmode} = $d->{mode};
$fdat{dow} = $d->{dow};
}
if (!defined ($fdat{starttime})) {
$fdat{starttime} = sprintf ("%02d:%02d", $d->{hour}, $d->{minute});
}
if (!defined ($fdat{vmsel})) {
$fdat{vmsel} = $d->{vmlist} || '';
}
my $vzl;
if (!defined ($cinfo->{"CID_$fdat{hostcid}"})) {
push @$cidlist, [$fdat{hostcid}, "unknown"];
} else {
$vzl = $vzlist ? $vzlist->{"CID_$fdat{hostcid}"} : undef;
}
$out .= $form->create_header($fdat{__uri});
my $grid = PVE::HTMLGrid->new ('fw1', 'fw2', 'fw3:right', 'fw4');
$grid->add_row (__("Cluster Node") . ':',
$form->create_element ('hostcid', 'dynamicdropdown',$fdat{hostcid}, $cidlist),
__("Send email to") . ':',
$form->create_element ('mailto', 'text', $fdat{mailto}));
if ($def_storage && ($fdat{edit} == 2 || defined ($fdat{storage}))) {
my $backupstorelist = PVE::HTMLUtils::storage_format_storage_list ($stinfo, 'backup');
$grid->add_row (__("Storage") . ':',
$form->create_element ('storage', 'dropdown',
$fdat{storage}, $backupstorelist),
__("Include all VMs") . ':',
$form->create_element ('incmode', 'dynamicbool', $fdat{incmode}));
} else {
$grid->add_row (__("Destination") . ':',
$form->create_element ('dumpdir', 'text', $fdat{dumpdir}, ['default']),
__("Include all VMs") . ':',
$form->create_element ('incmode', 'dynamicbool', $fdat{incmode}));
}
$grid->add_row (__("Day of Week") . ':',
$form->create_element ('dow', 'dow', $fdat{dow}),
__("Max files") . ':',
$form->create_element ('maxfiles', 'text', $fdat{maxfiles}));
$grid->add_row (__("Start time") . ':',
$form->create_element ('starttime', 'time', $fdat{starttime}));
$grid->add_row (__("Mode") . ':',
$form->create_element ('bkmode', 'dropdown', $fdat{bkmode},
['snapshot', 'suspend', 'stop']));
$grid->add_row (__("Compress files") . ':',
$form->create_element ('compress', 'bool', $fdat{compress}));
my $html = $grid->html();
my $table = PVE::HTMLTable->new ([]);
my @header = ('1', '20px', ' ',
'1', '50px', __('VMID'),
'1', '100px', __('Status'),
'1', '400px', __('Name'),
'1', '100px', __('VM Type'),
'1', '100px', __('Disk size'),
);
$table->add_headline (\@header);
my $found;
if ($vzl) {
foreach my $vkey (sort keys %$vzl) {
next if $vkey !~ m/^VEID_(\d+)$/;
my $veid = $1;
my $d = $vzl->{$vkey};
my $checked = '';
foreach my $sel (split ('\s+', $fdat{vmsel})) {
$checked = 'checked' if $veid eq $sel;
}
my $selector;
if ($fdat{incmode}) {
$selector = "";
$html .= "" if $checked;
} else {
$selector = "";
}
my $vmtype = $d->{type};
$vmtype =~ s/qemu/kvm/;
$table->add_row ('', $selector, $veid, $d->{status}, $d->{name}, $vmtype,
sprintf ("%.2f GB", $d->{maxdisk}/1024));
$found = 1;
}
}
$html .= "
";
if (!$found) {
$html .= __("Node has no VMs") . "
";
} else {
$html .= $table->out_table ();
}
$html .= $form->create_element("edit", "hidden", $fdat{edit});
$html .= $form->create_element("aa", "hidden", $fdat{aa});
$html .= "
";
$html .= $form->create_cmdbutton ('save');
my $title = ($fdat{edit} == 2) ? __("Create new job") : __("Edit backup job");
$out .= PVE::HTMLUtils::create_statusframe (undef, $title,
undef, $html);
$out .= $form->create_footer();
print OUT $out;
return;
}
my @names = split (/\s+/, __("Mon Tue Wed Thu Fri Sat Sun"));
my @header = (
'1', '20px', ' ',
'1', '100px', __('Node'),
'1', '20px', $names[0],
'1', '20px', $names[1],
'1', '20px', $names[2],
'1', '20px', $names[3],
'1', '20px', $names[4],
'1', '20px', $names[5],
'1', '20px', $names[6],
'1', '70px', __('Start time'),
'1', '200px', __('Storage') . "/" . __('Destination'),
'1', '350px', __('Selection'));
my $table = PVE::HTMLTable->new ([]);
$table->add_headline (\@header);
my $ddown = PVE::HTMLDropDown->new ();
$ddown->add_item("menu0","?edit=2&aa=JOB0", __("Create new job") );
$ddown->add_item("menu1","?edit=1", __("Edit"));
$ddown->add_item("menu1","?action=delete", __("Delete"));
$out .= "