forked from shaba/openuds
fixes from 2.2
This commit is contained in:
commit
436fe43098
@ -31,6 +31,11 @@
|
|||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from udsactor import operations
|
from udsactor import operations
|
||||||
|
|
||||||
from udsactor.service import CommonService
|
from udsactor.service import CommonService
|
||||||
@ -38,23 +43,18 @@ from udsactor.service import initCfg
|
|||||||
from udsactor.service import IPC_PORT
|
from udsactor.service import IPC_PORT
|
||||||
|
|
||||||
from udsactor import ipc
|
from udsactor import ipc
|
||||||
|
from udsactor import store
|
||||||
from udsactor.log import logger
|
from udsactor.log import logger
|
||||||
|
|
||||||
from udsactor.linux.daemon import Daemon
|
from udsactor.linux.daemon import Daemon
|
||||||
from udsactor.linux import renamer
|
from udsactor.linux import renamer
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import stat
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
POST_CMD = '/etc/udsactor/post'
|
POST_CMD = '/etc/udsactor/post'
|
||||||
PRECONNECT_CMD = '/etc/udsactor/pre'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from prctl import set_proctitle # @UnresolvedImport
|
from prctl import set_proctitle # @UnresolvedImport
|
||||||
except Exception: # Platform may not include prctl, so in case it's not available, we let the "name" as is
|
except Exception: # Platform may not include prctl, so in case it's not available, we let the "name" as is
|
||||||
|
|
||||||
def set_proctitle(_):
|
def set_proctitle(_):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -97,7 +97,6 @@ class UDSActorSvc(Daemon, CommonService):
|
|||||||
logger.info('Rebooting computer to activate new name {}'.format(name))
|
logger.info('Rebooting computer to activate new name {}'.format(name))
|
||||||
self.reboot()
|
self.reboot()
|
||||||
|
|
||||||
|
|
||||||
def joinDomain(self, name, domain, ou, account, password):
|
def joinDomain(self, name, domain, ou, account, password):
|
||||||
logger.fatal('Join domain is not supported on linux platforms right now')
|
logger.fatal('Join domain is not supported on linux platforms right now')
|
||||||
|
|
||||||
@ -108,18 +107,19 @@ class UDSActorSvc(Daemon, CommonService):
|
|||||||
# Execute script in /etc/udsactor/post after interacting with broker, if no reboot is requested ofc
|
# Execute script in /etc/udsactor/post after interacting with broker, if no reboot is requested ofc
|
||||||
# This will be executed only when machine gets "ready"
|
# This will be executed only when machine gets "ready"
|
||||||
try:
|
try:
|
||||||
|
pre_cmd = store.preApplication()
|
||||||
if os.path.isfile(PRECONNECT_CMD):
|
if os.path.isfile(pre_cmd):
|
||||||
if (os.stat(PRECONNECT_CMD).st_mode & stat.S_IXUSR) != 0:
|
if (os.stat(pre_cmd).st_mode & stat.S_IXUSR) != 0:
|
||||||
subprocess.call([PRECONNECT_CMD, user, protocol])
|
subprocess.call([pre_cmd, user, protocol])
|
||||||
else:
|
else:
|
||||||
logger.info('PRECONNECT file exists but it it is not executable (needs execution permission by root)')
|
logger.info('PRECONNECT file exists but it it is not executable (needs execution permission by root)')
|
||||||
else:
|
else:
|
||||||
logger.info('PRECONNECT file not found & not executed')
|
logger.info('PRECONNECT file not found & not executed')
|
||||||
except Exception as e:
|
except Exception:
|
||||||
# Ignore output of execution command
|
# Ignore output of execution command
|
||||||
logger.error('Executing preconnect command give')
|
logger.error('Executing preconnect command give')
|
||||||
|
|
||||||
|
return 'ok'
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
cfg = initCfg() # Gets a local copy of config to get "reboot"
|
cfg = initCfg() # Gets a local copy of config to get "reboot"
|
||||||
@ -196,6 +196,7 @@ def usage():
|
|||||||
sys.stderr.write("usage: {} start|stop|restart|login 'username'|logout 'username'\n".format(sys.argv[0]))
|
sys.stderr.write("usage: {} start|stop|restart|login 'username'|logout 'username'\n".format(sys.argv[0]))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.setLevel(20000)
|
logger.setLevel(20000)
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import os
|
import os
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
CONFIGFILE = '/etc/udsactor/udsactor.cfg' if DEBUG is False else '/tmp/udsactor.cfg'
|
CONFIGFILE = '/etc/udsactor/udsactor.cfg' if DEBUG is False else '/tmp/udsactor.cfg'
|
||||||
|
PRECONNECT_CMD = '/etc/udsactor/pre'
|
||||||
|
|
||||||
|
|
||||||
def checkPermissions():
|
def checkPermissions():
|
||||||
@ -79,10 +79,15 @@ def writeConfig(data):
|
|||||||
|
|
||||||
os.chmod(CONFIGFILE, 0o0600)
|
os.chmod(CONFIGFILE, 0o0600)
|
||||||
|
|
||||||
|
|
||||||
def useOldJoinSystem():
|
def useOldJoinSystem():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Right now, we do not really need an application to be run on "startup" as could ocur with windows
|
# Right now, we do not really need an application to be run on "startup" as could ocur with windows
|
||||||
def runApplication():
|
def runApplication():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def preApplication():
|
||||||
|
return PRECONNECT_CMD
|
||||||
|
@ -93,7 +93,7 @@ class CommonService(object):
|
|||||||
def reboot(self):
|
def reboot(self):
|
||||||
self.rebootRequested = True
|
self.rebootRequested = True
|
||||||
|
|
||||||
def execute(self, cmdLine, section):
|
def execute(self, cmdLine, section): # pylint: disable=no-self-use
|
||||||
cmd = shlex.split(cmdLine, posix=False)
|
cmd = shlex.split(cmdLine, posix=False)
|
||||||
|
|
||||||
if os.path.isfile(cmd[0]):
|
if os.path.isfile(cmd[0]):
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
# pylint: disable=unused-wildcard-import, wildcard-import
|
# pylint: disable=unused-wildcard-import, wildcard-import
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
import win32serviceutil # @UnresolvedImport, pylint: disable=import-error
|
import win32serviceutil # @UnresolvedImport, pylint: disable=import-error
|
||||||
import win32service # @UnresolvedImport, pylint: disable=import-error
|
import win32service # @UnresolvedImport, pylint: disable=import-error
|
||||||
import win32security # @UnresolvedImport, pylint: disable=import-error
|
import win32security # @UnresolvedImport, pylint: disable=import-error
|
||||||
@ -40,8 +44,6 @@ import win32event # @UnresolvedImport, pylint: disable=import-error
|
|||||||
import win32com.client # @UnresolvedImport, @UnusedImport, pylint: disable=import-error
|
import win32com.client # @UnresolvedImport, @UnusedImport, pylint: disable=import-error
|
||||||
import pythoncom # @UnresolvedImport, pylint: disable=import-error
|
import pythoncom # @UnresolvedImport, pylint: disable=import-error
|
||||||
import servicemanager # @UnresolvedImport, pylint: disable=import-error
|
import servicemanager # @UnresolvedImport, pylint: disable=import-error
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
|
|
||||||
from udsactor import operations
|
from udsactor import operations
|
||||||
from udsactor import store
|
from udsactor import store
|
||||||
@ -205,6 +207,20 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
|||||||
self._user = None
|
self._user = None
|
||||||
logger.debug('User {} already in group'.format(user))
|
logger.debug('User {} already in group'.format(user))
|
||||||
|
|
||||||
|
# Now try to run pre connect command
|
||||||
|
try:
|
||||||
|
pre_cmd = store.preApplication()
|
||||||
|
if os.path.isfile(pre_cmd):
|
||||||
|
if (os.stat(pre_cmd).st_mode & stat.S_IXUSR) != 0:
|
||||||
|
subprocess.call([pre_cmd, user, protocol])
|
||||||
|
else:
|
||||||
|
logger.info('PRECONNECT file exists but it it is not executable (needs execution permission by root)')
|
||||||
|
else:
|
||||||
|
logger.info('PRECONNECT file not found & not executed')
|
||||||
|
except Exception as e:
|
||||||
|
# Ignore output of execution command
|
||||||
|
logger.error('Executing preconnect command give')
|
||||||
|
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
def onLogout(self, user):
|
def onLogout(self, user):
|
||||||
@ -223,7 +239,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Exception removing user from Remote Desktop Users: {}'.format(e))
|
logger.error('Exception removing user from Remote Desktop Users: {}'.format(e))
|
||||||
|
|
||||||
def SvcDoRun(self):
|
def SvcDoRun(self): # pylint: disable=too-many-statements, too-many-branches
|
||||||
'''
|
'''
|
||||||
Main service loop
|
Main service loop
|
||||||
'''
|
'''
|
||||||
|
@ -35,7 +35,7 @@ import pickle
|
|||||||
from win32com.shell import shell # @UnresolvedImport, pylint: disable=import-error
|
from win32com.shell import shell # @UnresolvedImport, pylint: disable=import-error
|
||||||
try:
|
try:
|
||||||
import winreg as wreg
|
import winreg as wreg
|
||||||
except ImportError: # Python 2.7 fallback
|
except ImportError: # Python 2.7 fallback
|
||||||
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
|
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
|
||||||
import win32security # @UnresolvedImport, pylint: disable=import-error
|
import win32security # @UnresolvedImport, pylint: disable=import-error
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ def encoder(data):
|
|||||||
def decoder(data):
|
def decoder(data):
|
||||||
return data.decode('bz2')
|
return data.decode('bz2')
|
||||||
|
|
||||||
|
|
||||||
path = 'Software\\UDSActor'
|
path = 'Software\\UDSActor'
|
||||||
baseKey = wreg.HKEY_CURRENT_USER if DEBUG is True else wreg.HKEY_LOCAL_MACHINE # @UndefinedVariable
|
baseKey = wreg.HKEY_CURRENT_USER if DEBUG is True else wreg.HKEY_LOCAL_MACHINE # @UndefinedVariable
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ def readConfig():
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def writeConfig(data, fixPermissions=True):
|
def writeConfig(data, fixPermissions=True):
|
||||||
try:
|
try:
|
||||||
key = wreg.OpenKey(baseKey, path, 0, wreg.KEY_ALL_ACCESS) # @UndefinedVariable
|
key = wreg.OpenKey(baseKey, path, 0, wreg.KEY_ALL_ACCESS) # @UndefinedVariable
|
||||||
@ -96,6 +98,7 @@ def writeConfig(data, fixPermissions=True):
|
|||||||
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, encoder(pickle.dumps(data))) # @UndefinedVariable
|
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, encoder(pickle.dumps(data))) # @UndefinedVariable
|
||||||
wreg.CloseKey(key) # @UndefinedVariable
|
wreg.CloseKey(key) # @UndefinedVariable
|
||||||
|
|
||||||
|
|
||||||
def useOldJoinSystem():
|
def useOldJoinSystem():
|
||||||
try:
|
try:
|
||||||
key = wreg.OpenKey(baseKey, 'Software\\UDSEnterpriseActor', 0, wreg.KEY_QUERY_VALUE) # @UndefinedVariable
|
key = wreg.OpenKey(baseKey, 'Software\\UDSEnterpriseActor', 0, wreg.KEY_QUERY_VALUE) # @UndefinedVariable
|
||||||
@ -109,6 +112,7 @@ def useOldJoinSystem():
|
|||||||
|
|
||||||
return data == 'old'
|
return data == 'old'
|
||||||
|
|
||||||
|
|
||||||
# Gives the oportunity to run an application ONE TIME (because, the registry key "run" will be deleted after read)
|
# Gives the oportunity to run an application ONE TIME (because, the registry key "run" will be deleted after read)
|
||||||
def runApplication():
|
def runApplication():
|
||||||
try:
|
try:
|
||||||
@ -119,8 +123,21 @@ def runApplication():
|
|||||||
except Exception:
|
except Exception:
|
||||||
data = None
|
data = None
|
||||||
wreg.CloseKey(key) # @UndefinedVariable
|
wreg.CloseKey(key) # @UndefinedVariable
|
||||||
except:
|
except Exception:
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def preApplication():
|
||||||
|
try:
|
||||||
|
key = wreg.OpenKey(baseKey, 'Software\\UDSEnterpriseActor', 0, wreg.KEY_ALL_ACCESS) # @UndefinedVariable
|
||||||
|
try:
|
||||||
|
data, _ = wreg.QueryValueEx(key, 'pre') # @UndefinedVariable
|
||||||
|
except Exception:
|
||||||
|
data = None
|
||||||
|
wreg.CloseKey(key) # @UndefinedVariable
|
||||||
|
except Exception:
|
||||||
|
data = None
|
||||||
|
|
||||||
|
return data
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
"""
|
"""
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
Loading…
Reference in New Issue
Block a user