Commit a09b9992 authored by joelalju's avatar joelalju
Browse files

[#404] "Set base picture" button implemented. The base doesn't have the screenshot buttons.

parent cc9ce163
......@@ -8,6 +8,7 @@ our $VERSION = '0.2.10';
use Carp qw(carp croak);
use Data::Dumper;
use DBIx::Connector;
use File::Copy;
use Hash::Util qw(lock_hash);
use Moose;
use POSIX qw(WNOHANG);
......@@ -1487,6 +1488,28 @@ sub _cmd_screenshot {
$request->error("No data received") if !$bytes;
}
sub _cmd_copy_screenshot {
my $self = shift;
my $request = shift;
my $id_domain = $request->args('id_domain');
my $domain = $self->search_domain_by_id($id_domain);
my $id_base = $domain->id_base;
my $base = $self->search_domain_by_id($id_base);
if (!$domain->file_screenshot) {
die "I don't have the screenshot of the domain ".$domain->name;
} else {
my $base_screenshot = $domain->file_screenshot();
$base_screenshot =~ s{(.*)/\d+\.(\w+)}{$1/$id_base.$2};
$base->_post_screenshot($base_screenshot);
copy($domain->file_screenshot, $base_screenshot);
}
}
sub _cmd_create{
my $self = shift;
......@@ -1896,6 +1919,7 @@ sub _req_method {
,set_driver => \&_cmd_set_driver
,domdisplay => \&_cmd_domdisplay
,screenshot => \&_cmd_screenshot
,copy_screenshot => \&_cmd_copy_screenshot
,remove_base => \&_cmd_remove_base
,ping_backend => \&_cmd_ping_backend
,prepare_base => \&_cmd_prepare_base
......
......@@ -55,6 +55,7 @@ our %VALID_ARG = (
,shutdown_domain => { name => 2, id_domain => 2, uid => 1, timeout => 2, at => 2 }
,force_shutdown_domain => { name => 1, uid => 1, at => 2 }
,screenshot_domain => { id_domain => 1, filename => 2 }
,copy_screenshot => { id_domain => 1, filename => 2 }
,start_domain => {%$args_manage, remote_ip => 1 }
,rename_domain => { uid => 1, name => 1, id_domain => 1}
,set_driver => {uid => 1, id_domain => 1, id_option => 1}
......@@ -685,6 +686,31 @@ sub screenshot_domain {
}
=head2 copy_screenshot
Request to copy a screenshot from a domain to another
=cut
sub copy_screenshot {
my $proto = shift;
my $class=ref($proto) || $proto;
my $args = _check_args('copy_screenshot', @_ );
$args->{filename} = '' if !exists $args->{filename};
my $self = {};
bless($self,$class);
return $self->_new_request(
command => 'copy_screenshot'
,id_domain => $args->{id_domain}
,args => $args
);
}
=head2 open_iptables
Request to open iptables for a remote client
......
......@@ -153,12 +153,38 @@
};
$scope.reload_page_msg = false;
$scope.action = function(target,action,machineId){
$scope.fail_page_msg = false;
$scope.screenshot = function(target,action,machineId, isActive){
if (isActive) {
$http.get('/'+target+'/'+action+'/'+machineId+'.json');
$scope.fail_page_msg = false;
$scope.reload_page_msg = true;
setTimeout(function () {
window.location.reload(false);
}, 5000);
}
else {
$scope.reload_page_msg = false;
$scope.fail_page_msg = true;
}
};
$scope.reload_page_copy_msg = false;
$scope.fail_page_copy_msg = false;
$scope.copy_done = false;
$scope.copy_screenshot = function(target, action, machineId, fileScreenshot){
if (fileScreenshot != '') {
$http.get('/'+target+'/'+action+'/'+machineId+'.json');
$scope.fail_page_copy_msg = false;
$scope.reload_page_copy_msg = true;
setTimeout(function () {
$scope.reload_page_copy_msg = false;
}, 2000);
}
else {
$scope.reload_page_copy_msg = false;
$scope.fail_page_copy_msg = true;
}
};
$scope.rename = function(machineId, old_name) {
......
......@@ -394,6 +394,12 @@ get '/machine/screenshot/(:id).(:type)' => sub {
return screenshot_machine($c);
};
get '/machine/copy_screenshot/(:id).(:type)' => sub {
my $c = shift;
return access_denied($c) if !$USER->is_admin();
return copy_screenshot($c);
};
get '/machine/pause/(:id).(:type)' => sub {
my $c = shift;
return pause_machine($c);
......@@ -1379,6 +1385,13 @@ sub settings_machine {
_enable_buttons($c, $domain);
my $file_screenshot = "$DOCUMENT_ROOT/img/screenshots/".$domain->id.".png";
my $req3 = Ravada::Request->copy_screenshot (
id_domain => $domain->id
,filename => $file_screenshot
) if $c->param('copy_screenshot');
$c->stash(message => '');
my @reqs = ();
for (qw(sound video network image jpeg zlib playback streaming)) {
......@@ -1402,8 +1415,6 @@ sub settings_machine {
}
}
for my $req (@reqs) {
$RAVADA->wait_request($req, 60)
}
......@@ -1538,6 +1549,20 @@ sub screenshot_machine {
$c->render(json => { request => $req->id});
}
sub copy_screenshot {
my $c = shift;
return login($c) if !_logged_in($c);
my $domain = _search_requested_machine($c);
my $file_screenshot = "$DOCUMENT_ROOT/img/screenshots/".$domain->id.".png";
my $req = Ravada::Request->copy_screenshot (
id_domain => $domain->id
,filename => $file_screenshot
);
$c->render(json => { request => $req->id});
}
sub prepare_machine {
my $c = shift;
return login($c) if !_logged_in($c);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment