refs #527 remove unused code
parent
2c3bbe82a8
commit
25cfb31725
|
@ -48,7 +48,6 @@ import urllib.request
|
||||||
from configparser import NoOptionError
|
from configparser import NoOptionError
|
||||||
from opengnsys import REST, operations, VERSION
|
from opengnsys import REST, operations, VERSION
|
||||||
from opengnsys.log import logger
|
from opengnsys.log import logger
|
||||||
from opengnsys.scriptThread import ScriptExecutorThread
|
|
||||||
from opengnsys.workers import ServerWorker
|
from opengnsys.workers import ServerWorker
|
||||||
|
|
||||||
# Check authorization header decorator
|
# Check authorization header decorator
|
||||||
|
@ -173,44 +172,6 @@ class ogAdmClientWorker(ServerWorker):
|
||||||
threading.Thread(target=pwoff).start()
|
threading.Thread(target=pwoff).start()
|
||||||
return {'op': 'launched'}
|
return {'op': 'launched'}
|
||||||
|
|
||||||
@check_secret
|
|
||||||
def process_script(self, path, get_params, post_params, server):
|
|
||||||
"""
|
|
||||||
Processes an script execution (script should be encoded in base64)
|
|
||||||
:param path:
|
|
||||||
:param get_params:
|
|
||||||
:param post_params: JSON object {"script": "commands"}
|
|
||||||
:param server: authorization header
|
|
||||||
:return: JSON object {"op": "launched"}
|
|
||||||
"""
|
|
||||||
logger.debug('Processing script request')
|
|
||||||
# Decoding script
|
|
||||||
script = urllib.parse.unquote(base64.b64decode(post_params.get('script')).decode('utf-8'))
|
|
||||||
logger.debug('received script {}'.format(script))
|
|
||||||
if operations.os_type == 'Windows':
|
|
||||||
## for windows, we turn the script into utf16le, then to b64 again, and feed the blob to powershell
|
|
||||||
u16 = script.encode ('utf-16le') ## utf16
|
|
||||||
b64 = base64.b64encode (u16).decode ('utf-8') ## b64 (which returns bytes, so we need an additional decode(utf8))
|
|
||||||
script = """
|
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
import subprocess
|
|
||||||
cp = subprocess.run ("powershell -WindowStyle Hidden -EncodedCommand {}", capture_output=True)
|
|
||||||
subprocs_log = os.path.join (tempfile.gettempdir(), 'opengnsys-subprocs.log')
|
|
||||||
with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
|
||||||
fd.write (cp.stdout)
|
|
||||||
fd.write (cp.stderr)
|
|
||||||
""".format (b64)
|
|
||||||
else:
|
|
||||||
script = 'import subprocess; subprocess.check_output("""{0}""",shell=True)'.format(script)
|
|
||||||
# Executing script.
|
|
||||||
if post_params.get('client', 'false') == 'false':
|
|
||||||
thr = ScriptExecutorThread(script)
|
|
||||||
thr.start()
|
|
||||||
else:
|
|
||||||
self.sendClientMessage('script', {'code': script})
|
|
||||||
return {'op': 'launched'}
|
|
||||||
|
|
||||||
@check_secret
|
@check_secret
|
||||||
def process_logoff(self, path, get_params, post_params, server):
|
def process_logoff(self, path, get_params, post_params, server):
|
||||||
logger.warn('in process_logoff, should not happen')
|
logger.warn('in process_logoff, should not happen')
|
||||||
|
@ -223,6 +184,13 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
||||||
## type(post_params) "<class 'dict'>"
|
## type(post_params) "<class 'dict'>"
|
||||||
return {'debug':'test'}
|
return {'debug':'test'}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#def process_client_popup(self, params):
|
#def process_client_popup(self, params):
|
||||||
# logger.warn('in process_client_popup')
|
# logger.warn('in process_client_popup')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue