get display number to remote access

This commit is contained in:
Tuncay ÇOLAK 2023-03-14 14:54:05 +03:00
parent f029e916ef
commit 1746d98172
3 changed files with 22 additions and 6 deletions

View file

@ -292,12 +292,15 @@ class System:
@staticmethod
def display(username):
try:
system = System()
if "\\" in username:
user_parser = username.split("\\")
username = user_parser[1]
display = system.db_service.select_one_result('session', 'display', " username='{0}'".format(username))
return display
except Exception as e:
return None
@staticmethod
def desktop(username):

View file

@ -498,3 +498,10 @@ class Util:
return version
else:
return None
# return active user in sessions list
@staticmethod
def get_active_user():
result_code, p_out, p_err = Util.execute("for sessionid in $(loginctl list-sessions --no-legend | awk '{ print $1 }'); do loginctl show-session -p Id -p Name -p User -p State -p Type -p Remote $sessionid | sort; done | awk -F= '/Name/ { name = $2 } /User/ { user = $2 } /State/ { state = $2 } /Type/ { type = $2 } /Remote/ { remote = $2 } /User/ && remote == \"no\" && state == \"active\" && (type == \"x11\" || type == \"wayland\") { print name }\'")
p_out = str(p_out).rstrip()
return p_out

View file

@ -51,6 +51,8 @@ class SetupVnc(AbstractPlugin):
def run_vnc_server(self):
# user_name = self.db_service.select_one_result('session', 'username', " 1=1 order by id desc ")
user_name = self.get_username()
if user_name is None:
user_name = self.get_active_user()
self.logger.info('get logon username is {0}'.format(user_name))
self.logger.debug('Is VNC server installed?')
if self.is_installed('x11vnc') is False:
@ -65,6 +67,8 @@ class SetupVnc(AbstractPlugin):
self.logger.debug('Getting display and username...')
# display_number = self.get_username_display(user_name)
display_number = self.Sessions.display(user_name)
if display_number is None:
display_number = self.get_username_display()
desktop_env = self.get_desktop_env()
if desktop_env == "gnome":
display_number = self.get_username_display_gnome(user_name)
@ -73,6 +77,8 @@ class SetupVnc(AbstractPlugin):
#self.logger.info("Get home directory of {0} is {1}".format(user_name, homedir))
# this user_name for execute method
user_name = self.get_as_user()
if user_name is None:
user_name = self.get_active_user()
self.logger.debug('Username:{0} Display:{1}'.format(user_name, display_number))
#if self.is_exist('{0}/.vncahenk{1}'.format(homedir, user_name)) is True:
# self.delete_folder('{0}/.vncahenk{1}'.format(homedir, user_name))