Compare commits

..

No commits in common. "10a4c28ea68e2b4e2a72e3218c3e80b57aaeb562" and "64dea9f846425564693fdf7e638bf22f31cdf6ee" have entirely different histories.

3 changed files with 4 additions and 17 deletions

0
src/OGAgentUser.py 100755 → 100644
View File

View File

@ -1 +1 @@
1.3.3
1.3.2

View File

@ -149,7 +149,6 @@ class OpenGnSysWorker(ServerWorker):
break
# Raise error after timeout
if not self.interface:
## UnboundLocalError: cannot access local variable 'e' where it is not associated with a value
raise e
# Loop to send initialization message
@ -333,23 +332,11 @@ class OpenGnSysWorker(ServerWorker):
:return: JSON object {"op": "launched"}
"""
logger.debug('Processing script request')
# Decoding script
# Decoding script (Windows scripts need a subprocess call per line)
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)
script = 'import subprocess; {0}'.format(
';'.join(['subprocess.check_output({0},shell=True)'.format(repr(c)) for c in script.split('\n')]))
else:
script = 'import subprocess; subprocess.check_output("""{0}""",shell=True)'.format(script)
# Executing script.