From d497235eeb4c5eb6aa4f34962a2fb105be69cfed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Tue, 13 Jul 2021 11:53:22 +0200 Subject: [PATCH] * Added config parameter for "check removal processes hanged" and removed six from RDP client scripts (and regenerated signatures) --- server/src/uds/core/util/config.py | 1 + .../workers/hanged_userservice_cleaner.py | 43 ++++++++++++------- .../transports/RDP/scripts/windows/direct.py | 9 +--- .../RDP/scripts/windows/direct.py.signature | 2 +- .../transports/RDP/scripts/windows/tunnel.py | 10 +---- .../RDP/scripts/windows/tunnel.py.signature | 2 +- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/server/src/uds/core/util/config.py b/server/src/uds/core/util/config.py index 8f1c9a58..d0e85605 100644 --- a/server/src/uds/core/util/config.py +++ b/server/src/uds/core/util/config.py @@ -288,6 +288,7 @@ class GlobalConfig: # Max time needed to get a service "fully functional" before it's considered "failed" and removed # The time is in seconds MAX_INITIALIZING_TIME: Config.Value = Config.section(GLOBAL_SECTION).value('maxInitTime', '3601', type=Config.NUMERIC_FIELD) + MAX_REMOVAL_TIME: Config.Value = Config.section(GLOBAL_SECTION).value('maxRemovalTime', '86400', type=Config.NUMERIC_FIELD) # Maximum logs per user service MAX_LOGS_PER_ELEMENT: Config.Value = Config.section(GLOBAL_SECTION).value('maxLogPerElement', '100', type=Config.NUMERIC_FIELD) # Time to restrain a deployed service in case it gives some errors at some point diff --git a/server/src/uds/core/workers/hanged_userservice_cleaner.py b/server/src/uds/core/workers/hanged_userservice_cleaner.py index 3beb4a09..67822bf3 100644 --- a/server/src/uds/core/workers/hanged_userservice_cleaner.py +++ b/server/src/uds/core/workers/hanged_userservice_cleaner.py @@ -41,8 +41,6 @@ from uds.core.util import log logger = logging.getLogger(__name__) -MAX_REMOVAL_TIME = 24*60*60 - class HangedCleaner(Job): frecuency = 3601 frecuency_cfg = GlobalConfig.MAX_INITIALIZING_TIME @@ -54,7 +52,7 @@ class HangedCleaner(Job): seconds=GlobalConfig.MAX_INITIALIZING_TIME.getInt() ) since_removing = now -timedelta( - seconds=MAX_REMOVAL_TIME + seconds=GlobalConfig.MAX_REMOVAL_TIME.getInt() ) # Filter for locating machine not ready flt = Q(state_date__lt=since_state, state=State.PREPARING) | Q( @@ -97,20 +95,33 @@ class HangedCleaner(Job): ): # It's waiting for removal, skip this very specific case continue logger.debug('Found hanged service %s', us) - log.doLog( - us, - log.ERROR, - 'User Service seems to be hanged. Removing it.', - log.INTERNAL, - ) - log.doLog( - servicePool, - log.ERROR, - 'Removing user service {} because it seems to be hanged'.format( - us.friendly_name - ), - ) if us.state == State.REMOVING: # Removing too long, remark it as removable + log.doLog( + us, + log.ERROR, + 'User Service hanged on removal process. Restarting removal.', + log.INTERNAL, + ) + log.doLog( + servicePool, + log.ERROR, + 'User service {} hanged on removal. Restarting removal.'.format( + us.friendly_name + ), + ) us.remove() # Mark it again as removable, and let's see else: + log.doLog( + us, + log.ERROR, + 'User Service seems to be hanged. Removing it.', + log.INTERNAL, + ) + log.doLog( + servicePool, + log.ERROR, + 'Removing user service {} because it seems to be hanged'.format( + us.friendly_name + ), + ) us.removeOrCancel() diff --git a/server/src/uds/transports/RDP/scripts/windows/direct.py b/server/src/uds/transports/RDP/scripts/windows/direct.py index 17211194..ff511ebe 100644 --- a/server/src/uds/transports/RDP/scripts/windows/direct.py +++ b/server/src/uds/transports/RDP/scripts/windows/direct.py @@ -1,8 +1,3 @@ -# This is a template -# Saved as .py for easier editing -from __future__ import unicode_literals - -# pylint: disable=import-error, no-name-in-module import subprocess import win32crypt # type: ignore import codecs @@ -15,9 +10,7 @@ except ImportError: # Python 2.7 fallback from uds.log import logger # type: ignore from uds import tools # type: ignore -import six - -thePass = six.binary_type(sp['password'].encode('UTF-16LE')) # type: ignore +thePass = sp['password'].encode('UTF-16LE') # type: ignore try: password = codecs.encode(win32crypt.CryptProtectData(thePass, None, None, None, None, 0x01), 'hex').decode() diff --git a/server/src/uds/transports/RDP/scripts/windows/direct.py.signature b/server/src/uds/transports/RDP/scripts/windows/direct.py.signature index 00d44bf3..55fcdb42 100644 --- a/server/src/uds/transports/RDP/scripts/windows/direct.py.signature +++ b/server/src/uds/transports/RDP/scripts/windows/direct.py.signature @@ -1 +1 @@ -EbLkCRb09VB7luaOpj43/F1tiPfnw8TPO3bCRqasEwWEi1S9BvK/hgpfTuCKFsKJ4q8+X1lGwPbIGquryzBaa+g+Q9o74ZMaP7hLZH2ko9G32Zd56B6XisHg7qfJC46pjwrHEI7jBec8Du6cBEfi3FCg3i1lHxUXPgZeLWrmuSv4x/HZKYGtXTSMI77ZL6zi8ZFkUk1pceyo9aNj9Zr3uok4Ddg/z/OSU+tD49tkJvIj8GTbpl0Wf4gu02ikrN+nF5+Yu5zac2nz26yPnAXJh1PecoKw/uuwDW5hpvSAwMfBIACezD1r5wfzjpMLqfbIq8VKca57USsi+1R4kwbV1dewTotwh6pHOj8bcVk78LTPqshdVud56390D3jV4C7fQtdA3+CWe6M6SScAwu7a0zDo2CNagmQJuBmlbmxjYgKFsUfjQTZehESCHBLpGiXPuIipU7A+F0iWYLUMKtrT1twfWDaxkCDSO5PGt+hNbt1Jie4qCQ97SvDx4cReaQomkVm4hAaAphS+/HOhZSTQ/+jfGmOYX8MgrM43c3o7r3Avg7heDn2r7CCMMeC5Kh8Clh3nzvM/F0QjvY9TibvlzO1qzyylt5U2OXrJ8agZ8Rpu4IJJQFL6DubVZAlPjlHAJ2d+8Vv8QNi42HEc967RDToaStoeofS6d4eft2SOUP4= \ No newline at end of file +kCBE6foYTr5Q55ma0dSm8jlWJg2S/CywReGILq7IjqTkr7PQLVPIVPlxO5XH5ApoRKDHG8Tgd9ObuTGy5NQ6nJXsX6gk3ZTRcm0MwGeMfOM2p0Jz8v4dcpL8eorAam07/BH8HtO+9aWW18oqwO7jzqsSdSQeSEnSxPBXLRRRG83wYABKwWajH8pTswNEZ1MT5sb9dcT2EYRpaDZdH0WeUYvoL9ikn6MfpvpCcAvY7PwiHHPZs6cTFksFcwm6578AlQGGluP7Zby6lB8a2tiZFJTAsJpMJorl0p7wSV4mDYXY5d1zLacIeuMHf/UMUfoZubr02WqcmdkOy8PT4IDLToav+xIUKBnbxXwqdyrmbGohY5jJmr3RWSvlNFv1jRnfHv2ayjzJ0gRip8x6OW0pwKNn4caai9QA0qGpO34MM1d4nnbhcRjHDOp2xWhQtbCjFnSrJz612hqT33DAUcJsqQhF88J1Xgjg0bEVs2Bb3hBfl1pPqevnswUfo0VWT8MlfPau54OC/VegrVjwu47t7MrwISYEzgFzkgSInC5xLw5wNg8zBhUx58TDH0O6UBcChfrcwjW4fZqi5N+0bzoTWqlwzzXjSvFTuWNfOrL++tdg0WLa9P/Jj0JOjjT4Boiz6zAdhTm2ZK8UN/qrlItsZ1Ud0a+jTj4yHbtK24ilUKU= \ No newline at end of file diff --git a/server/src/uds/transports/RDP/scripts/windows/tunnel.py b/server/src/uds/transports/RDP/scripts/windows/tunnel.py index 7bbac272..a71f821c 100644 --- a/server/src/uds/transports/RDP/scripts/windows/tunnel.py +++ b/server/src/uds/transports/RDP/scripts/windows/tunnel.py @@ -1,9 +1,3 @@ -# This is a template -# Saved as .py for easier editing -from __future__ import unicode_literals - -# pylint: disable=import-error, no-name-in-module, too-many-format-args, undefined-variable - import subprocess import win32crypt # type: ignore import codecs @@ -17,8 +11,6 @@ from uds.log import logger # type: ignore from uds import tools # type: ignore -import six - # Open tunnel fs = forward(remote=(sp['tunHost'], int(sp['tunPort'])), ticket=sp['ticket'], timeout=sp['tunWait'], check_certificate=sp['tunChk']) # type: ignore @@ -26,7 +18,7 @@ fs = forward(remote=(sp['tunHost'], int(sp['tunPort'])), ticket=sp['ticket'], ti if fs.check() is False: raise Exception('

Could not connect to tunnel server.

Please, check your network settings.

') -thePass = six.binary_type(sp['password'].encode('UTF-16LE')) # type: ignore +thePass = sp['password'].encode('UTF-16LE') # type: ignore try: password = codecs.encode(win32crypt.CryptProtectData(thePass, None, None, None, None, 0x01), 'hex').decode() diff --git a/server/src/uds/transports/RDP/scripts/windows/tunnel.py.signature b/server/src/uds/transports/RDP/scripts/windows/tunnel.py.signature index 78e20320..20b54d3a 100644 --- a/server/src/uds/transports/RDP/scripts/windows/tunnel.py.signature +++ b/server/src/uds/transports/RDP/scripts/windows/tunnel.py.signature @@ -1 +1 @@ -PxgUpszz7f/yliXrWhEzYUPd8D4bTMhI2Wq94xh8ZszcHVWwkwudtv7M9on3QJ9vDQ/E7YF9bFsuM+Vql4Fjcnk8sJMHiToXXJADIvNPUOWB24inPUxSkJGiZVITpfMhyNFzcykxcQ7U8U/UepK7ZRdIVQWJpR23XGTARmBDzxgYITS3LrIhpgtJ3jiQZov1K3Ub0oY3GUUK6UxidtRov70e/S1btHi7U6OvjT0Q/PhJBpxMBm0+xf7IF1t//dcGg591SOn1s97wjWhvSTVVFm/P1+7Xso6ZJuWVd5P+yTSH5v9xVTLcARkKRou+0I2syrSb6+zn2FyJgthp3PWYoepFJ+t946qDj//ew6fEBP4p4PcFeQ4Uuc/1F7/bKbNdHj6UzE06qmzbMpYl8QD2DXlL0zrUTlKFEUIKGSdmVmeWFgMrp/yJyUJaFceX0WMSC88Wj3MUW8qO0eTG/KtwgFRYldNt+l9xXl46pp/CsyIRnZQmWf2Lv3+YBU4okn6EPdS9V23Oy+jC4WkgOdHGwaP9weL8BLEIbvpPwgtAGJm9v6MuLT/VXf9sx5PidA+e1XUuvkR7yq7LtfbjdjTKvWtKtaPUiBnCQMc0uYGB0YnpaEj6WU/7yiahbEBZzbShbWMFXbV4RuV+lQsfHYwBNbAxbckhgEK2+ASpNb/7au8= \ No newline at end of file +Zqq4IZrBzD/r4lBO+Muvs7YaQGhl8D/6TR6GzKOOLu0zwDrvqnfQ9Xwjv9vsgI19mljiipyKjAYNLd4PQPwq+oSdD3DTvusaubDZ1es2ACRpC8dMwl6vT61W1xl7FKeZJP47h+i2o2cvyJeEyteU2HJ9xGmx2LQyss4OQqGb2C4WIixG1MkYRWbgfxRETD2kF/RrwevE52lRYs4Uf9bjKgFQ59tl1rn8JR1SYxbBb19I4ycJWh1K5kSja/XlFL9fU4W++L2nSMxIMz83YWi0cTlbno8AH91xGrsfqasoDTz9xVQ+6gRlkppxp5fTS08K4B8QAnXK330J+bxBtwAkjX+/E5zb09iEy5pDzFJW0xFA0poDfi1hvltBlaIpAivhcdhG+D36LH4mODGlkdcQykaI5ccPkPZZOq1fNCDS/n+YEzm1WHuVeOwKfbkbPtE095pP10KnCu1UPk/Xak39csMj/2FjDPEQ6H1F3VVoxnyfihGe6XmsKInMmCOI5LcItiemcJkT2mNkZU9KprweXfvB5TU/yPgLGvlnSRidhqyTk2AZRLWRirk0UuR44a2wP5BB2ExnKU1fjW1b6SXPEBvZ4XNfil3pgVWxkEDJq2M8MztGeOugm6gDnNbYjybnQC2BAjtj2VCqJ3WpSTtej1vnxg8lafOUYKAQywpzaso= \ No newline at end of file