fix(cgi-bin): complete draft for clean up

main
Tsu-ba-me 3 years ago
parent df33c2d193
commit 9603974c24
  1. 85
      cgi-bin/manage_vnc_ports

@ -112,6 +112,21 @@ sub is_websockify_process
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
{
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
{
my $query = "
@ -268,34 +300,60 @@ INSERT INTO public.vnc_pipes (
sub get_vnc_pipe
{
my $parameters = shift;
my $server_uuid = $parameters->{server_uuid};
my $ssh_tunnel_host_uuid = $parameters->{ssh_tunnel_host_uuid};
my $parameters = shift;
my $server_uuid = $parameters->{server_uuid};
my $host_uuid = $parameters->{host_uuid};
my $vnc_pipe_info;
my $query = "
SELECT
ws_host_uuid, ws_pid, ssh_tunnel_pid
hos.host_name, vnc.ws_pid, vnc.ssh_tunnel_pid
FROM
public.vnc_pipes
public.vnc_pipes AS vnc
JOIN
public.hosts AS hos
ON
vnc.ws_host_uuid = hos.host_uuid
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
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
{
my $parameters = shift;
my $server_uuid = $parameters->{server_uuid};
my $ssh_tunnel_host_uuid = $parameters->{ssh_tunnel_host_uuid};
my $parameters = shift;
my $server_uuid = $parameters->{server_uuid};
my $host_uuid = $parameters->{host_uuid};
my $query = "
DELETE FROM public.vnc_pipes
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
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__ });
@ -364,7 +422,12 @@ if ($server_uuid)
}
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'})

Loading…
Cancel
Save