Unverified Commit d49cad69 authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Merge pull request #506 from UPC/404_screenshot

404 screenshot
parents 1f2b1cbe c07f9caf
......@@ -8,6 +8,7 @@ our $VERSION = '0.3.0';
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);
......@@ -1605,6 +1606,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;
......@@ -2031,6 +2054,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
......
......@@ -1744,6 +1744,10 @@ sub type {
return $type;
}
sub file_screenshot($self) {
return $self->_data('file_screenshot');
}
sub _pre_clone($self,%args) {
my $name = delete $args{name};
my $user = delete $args{user};
......
......@@ -55,6 +55,7 @@ our %VALID_ARG = (
,shutdown_domain => { name => 2, id_domain => 2, uid => 1, timeout => 2, at => 2 }
,force_shutdown_domain => { id_domain => 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}
......@@ -692,6 +693,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
......
......@@ -152,9 +152,41 @@
$http.get('/machine/remove_clones/'+machineId+'.json');
};
$scope.action = function(target,action,machineId){
$http.get('/'+target+'/'+action+'/'+machineId+'.json');
$scope.reload_page_msg = false;
$scope.fail_page_msg = false;
$scope.screenshot = function(machineId, isActive){
if (isActive) {
$http.get('/machine/screenshot/'+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(machineId, fileScreenshot){
if (fileScreenshot != '') {
$http.get('/machine/copy_screenshot/'+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) {
if ($scope.new_name_duplicated || $scope.new_name_invalid) return;
$scope.rename_requested=1;
......
......@@ -398,6 +398,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);
......@@ -1421,8 +1427,6 @@ sub settings_machine {
}
}
for my $req (@reqs) {
$RAVADA->wait_request($req, 60)
}
......@@ -1558,6 +1562,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);
......
......@@ -24,6 +24,11 @@
% }
</div>
% }
% if ($USER->can_change_settings) {
<div class="tab-pane fade" id="screenshot">
%= include 'main/vm_screenshot'
</div>
% }
% if ($domain->type eq 'KVM') {
<div class="tab-pane fade" id="graphics">
% if ($domain->is_base) {
......@@ -42,4 +47,3 @@
%= include 'main/vm_remove'
</div>
% }
......@@ -7,6 +7,9 @@
% if ($USER->can_change_settings && $domain->drivers) {
<li class="nav"><a href="#drivers" data-toggle="tab">Drivers</a></li>
% }
% if ($USER->can_change_settings) {
<li class="nav"><a href="#screenshot" data-toggle="tab">Screenshot</a></li>
% }
% if ($domain->drivers) {
<li class="nav"><a href="#graphics" data-toggle="tab">Graphics</a></li>
% }
......@@ -17,4 +20,3 @@
<li class="nav"><a href="#remove" data-toggle="tab">Remove Machine</a></li>
% }
</ul>
<div class="panel-body">
<div class="form-group">
<div ng-hide= "<%= $domain->is_base %>" class="row" ng-cloak>
<div class="col-lg-2">
<button ng-click="screenshot(<%= $domain->id %>, <%= $domain->is_active %>)">
<%=l "Take screenshot" %></a>
</div>
<div class="col-lg-2">
<button ng-click="copy_screenshot(<%= $domain->id %>, '<%= $domain->file_screenshot %>')">
<%=l "Set base picture" %></button>
</div>
<i ng-show="reload_page_msg" ng-cloak><font color="green">Saving the screenshot, please wait a moment...</font></i>
<i ng-show="fail_page_msg" ng-cloak><font color="red">You need to run the machine in order to take a screenshot.</font></i>
<i ng-show="reload_page_copy_msg" ng-cloak><font color="green">Copying the screenshot, please wait a moment...</font></i>
<i ng-show="fail_page_copy_msg" ng-cloak><font color="red">You need a screenshot in order to copy it to the base machine.</font></i>
</div>
<div class="row">
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
% my ($screenshot) = $domain->file_screenshot =~ m{/var/www(.*)};
<img src="<%= $screenshot %>" width="260">
</div>
</div>
</div>
</div>
</div>
</div>
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