|
|
@ -112,6 +112,21 @@ sub is_websockify_process |
|
|
|
return $shell_output eq "websockify" ? 1 : 0; |
|
|
|
return $shell_output eq "websockify" ? 1 : 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub is_ssh_process |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my $parameters = shift; |
|
|
|
|
|
|
|
my $ssh_tunnel_pid = $parameters->{ssh_tunnel_pid}; |
|
|
|
|
|
|
|
my $shell_call = "ps -o comm -h -p ".$ssh_tunnel_pid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my ($shell_output, $shell_return_code) = $anvil->System->call({ shell_call => $shell_call }); |
|
|
|
|
|
|
|
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
|
|
|
shell_output => $shell_output, |
|
|
|
|
|
|
|
shell_return_code => $shell_return_code |
|
|
|
|
|
|
|
} }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $shell_output eq "ssh" ? 1 : 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub is_websockify_exists |
|
|
|
sub is_websockify_exists |
|
|
|
{ |
|
|
|
{ |
|
|
|
my $parameters = shift; |
|
|
|
my $parameters = shift; |
|
|
@ -218,6 +233,23 @@ sub stop_websockify |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub stop_ssh_tunnel |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my $parameters = shift; |
|
|
|
|
|
|
|
my $ssh_tunnel_pid = $parameters->{ssh_tunnel_pid}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_ssh_process($parameters)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my $shell_call = "kill -9 ".$ssh_tunnel_pid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my ($shell_output, $shell_return_code) = $anvil->System->call({ shell_call => $shell_call }); |
|
|
|
|
|
|
|
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
|
|
|
shell_output => $shell_output, |
|
|
|
|
|
|
|
shell_return_code => $shell_return_code |
|
|
|
|
|
|
|
} }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub create_vnc_pipes_table |
|
|
|
sub create_vnc_pipes_table |
|
|
|
{ |
|
|
|
{ |
|
|
|
my $query = " |
|
|
|
my $query = " |
|
|
@ -268,34 +300,60 @@ INSERT INTO public.vnc_pipes ( |
|
|
|
|
|
|
|
|
|
|
|
sub get_vnc_pipe |
|
|
|
sub get_vnc_pipe |
|
|
|
{ |
|
|
|
{ |
|
|
|
my $parameters = shift; |
|
|
|
my $parameters = shift; |
|
|
|
my $server_uuid = $parameters->{server_uuid}; |
|
|
|
my $server_uuid = $parameters->{server_uuid}; |
|
|
|
my $ssh_tunnel_host_uuid = $parameters->{ssh_tunnel_host_uuid}; |
|
|
|
my $host_uuid = $parameters->{host_uuid}; |
|
|
|
|
|
|
|
my $vnc_pipe_info; |
|
|
|
|
|
|
|
|
|
|
|
my $query = " |
|
|
|
my $query = " |
|
|
|
SELECT |
|
|
|
SELECT |
|
|
|
ws_host_uuid, ws_pid, ssh_tunnel_pid |
|
|
|
hos.host_name, vnc.ws_pid, vnc.ssh_tunnel_pid |
|
|
|
FROM |
|
|
|
FROM |
|
|
|
public.vnc_pipes |
|
|
|
public.vnc_pipes AS vnc |
|
|
|
|
|
|
|
JOIN |
|
|
|
|
|
|
|
public.hosts AS hos |
|
|
|
|
|
|
|
ON |
|
|
|
|
|
|
|
vnc.ws_host_uuid = hos.host_uuid |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
server_uuid = ".$anvil->Database->quote($server_uuid)." |
|
|
|
server_uuid = ".$anvil->Database->quote($server_uuid)." |
|
|
|
AND |
|
|
|
AND |
|
|
|
ssh_tunnel_host_uuid = ".$anvil->Database->quote($ssh_tunnel_host_uuid)." |
|
|
|
ssh_tunnel_host_uuid = ".$anvil->Database->quote($host_uuid)." |
|
|
|
;"; |
|
|
|
;"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ }); |
|
|
|
|
|
|
|
my $count = @{$results}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($count == 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my $row = $results->[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$vnc_pipe_info = {}; |
|
|
|
|
|
|
|
$vnc_pipe_info->{host_name} = $row->[0]; |
|
|
|
|
|
|
|
$vnc_pipe_info->{ws_pid} = $row->[1]; |
|
|
|
|
|
|
|
$vnc_pipe_info->{ssh_tunnel_pid} = $row->[2]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
|
|
|
host_name => $vnc_pipe_info->{host_name}, |
|
|
|
|
|
|
|
ws_pid => $vnc_pipe_info->{ws_pid}, |
|
|
|
|
|
|
|
ssh_tunnel_pid => $vnc_pipe_info->{ssh_tunnel_pid} |
|
|
|
|
|
|
|
} }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $vnc_pipe_info; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub delete_vnc_pipe |
|
|
|
sub delete_vnc_pipe |
|
|
|
{ |
|
|
|
{ |
|
|
|
my $parameters = shift; |
|
|
|
my $parameters = shift; |
|
|
|
my $server_uuid = $parameters->{server_uuid}; |
|
|
|
my $server_uuid = $parameters->{server_uuid}; |
|
|
|
my $ssh_tunnel_host_uuid = $parameters->{ssh_tunnel_host_uuid}; |
|
|
|
my $host_uuid = $parameters->{host_uuid}; |
|
|
|
|
|
|
|
|
|
|
|
my $query = " |
|
|
|
my $query = " |
|
|
|
DELETE FROM public.vnc_pipes |
|
|
|
DELETE FROM public.vnc_pipes |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
server_uuid = ".$anvil->Database->quote($server_uuid)." |
|
|
|
server_uuid = ".$anvil->Database->quote($server_uuid)." |
|
|
|
AND |
|
|
|
AND |
|
|
|
ssh_tunnel_host_uuid = ".$anvil->Database->quote($ssh_tunnel_host_uuid)." |
|
|
|
ssh_tunnel_host_uuid = ".$anvil->Database->quote($host_uuid)." |
|
|
|
;"; |
|
|
|
;"; |
|
|
|
|
|
|
|
|
|
|
|
$anvil->Database->write({ query => $query, source => $THIS_FILE, line => __LINE__ }); |
|
|
|
$anvil->Database->write({ query => $query, source => $THIS_FILE, line => __LINE__ }); |
|
|
@ -364,7 +422,12 @@ if ($server_uuid) |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
# TODO: fill-in clean up section. |
|
|
|
my $vnc_pipe_parameters = { server_uuid => $server_uuid, host_uuid => $anvil->Get->host_uuid() }; |
|
|
|
|
|
|
|
my $vnc_pipe_info = get_vnc_pipe($vnc_pipe_parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stop_websockify({ host_name => $vnc_pipe_info->{host_name}, ws_pid => $vnc_pipe_info->{ws_pid} }); |
|
|
|
|
|
|
|
stop_ssh_tunnel({ ssh_tunnel_pid => $vnc_pipe_info->{ssh_tunnel_pid} }); |
|
|
|
|
|
|
|
delete_vnc_pipe($vnc_pipe_parameters); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
elsif ($anvil->data->{switches}{'drop-table'}) |
|
|
|
elsif ($anvil->data->{switches}{'drop-table'}) |
|
|
|