File: NX.pm

package info (click to toggle)
x2goserver 4.1.0.3-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,492 kB
  • sloc: perl: 5,593; sh: 2,173; makefile: 811; xml: 21; ansic: 19
file content (123 lines) | stat: -rw-r--r-- 2,664 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright (C) 2007-2018 X2Go Project - https://wiki.x2go.org
# Copyright (C) 2007-2018 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>
# Copyright (C) 2007-2018 Heinz-Markus Graesing <heinz-m.graesing@obviously-nice.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

package X2Go::Server::Agent::NX;

=head1 NAME

X2Go::Server::Agent::NX - X2Go Server NX Agent package for Perl

=head1 DESCRIPTION

X2Go::Server::Agent::NX Perl package for X2Go::Server.

=cut

use strict;
use POSIX;
use Sys::Syslog qw( :standard :macros );

use X2Go::Log qw( loglevel );

setlogmask( LOG_UPTO(loglevel()) );


sub session_has_terminated
{
	my $state=get_agent_state(@_);
	if(($state eq 'TERMINATING')||($state eq 'TERMINATED'))
	{
		return 1;
	}
	return 0;
}


sub session_is_suspended
{
	my $state=get_agent_state(@_);
	if(($state eq 'SUSPENDING')||($state eq 'SUSPENDED'))
	{
		return 1;
	}
	return 0;
}


sub session_is_running
{
	my $state=get_agent_state(@_);
	if(($state eq 'STARTING')||($state eq 'RESUMING')||($state eq 'RUNNING'))
	{
		return 1;
	}
	return 0;
}

sub get_agent_state_file
{
	my $sess=@_[1];
	my $user;

	if ( $sess =~ m/.*-[0-9]{2,}-[0-9]{10,}_stS(0|1)XSHAD.*XSHADPP.*/ ) {
		my $shadow_user = $sess;
		$shadow_user =~ s/.*XSHAD(.*)XSHADPP.*/$1/;
		$user = $shadow_user;
	} else {
		$user=@_[2];
	}

	my $stateFile;
	if ( -d "/tmp-inst/${user}/.x2go-${user}" ) {
		$stateFile="/tmp-inst/${user}/.x2go-".$user."/C-".$sess."/state";
	} else {
		$stateFile = "/tmp/.x2go-".$user."/C-".$sess."/state";
	}
	return $stateFile;
}

sub has_agent_state_file
{
	my $stateFile = get_agent_state_file(@_);
	if ( -e "$stateFile" )
	{
		return 1;
	}
	return 0;
}

sub get_agent_state
{
	my $state;
	my $stateFile = get_agent_state_file(@_);
	if (! -e "$stateFile" )
	{
		syslog('warning', "@_[1]: state file for this session does not exist: $stateFile (this can be ignored during session startups)");
		$state="UNKNOWN";
	}
	else
	{
		open(F,"<$stateFile");
		$state=<F>;
		close(F);
	}
	return $state;
}

1;