Merge remote-tracking branch 'origin/v3.6'

This commit is contained in:
Adolfo Gómez García 2022-10-16 18:47:51 +02:00
commit daf4bbcc37
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
8 changed files with 38 additions and 7 deletions

View File

@ -30,6 +30,8 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import os
import sys
import codecs
import logging
import json
@ -275,6 +277,33 @@ class Transport(Module):
parameters=transport_script.parameters,
)
def getRelativeScript(
self, scriptName: str, params: typing.Mapping[str, typing.Any]
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
"""Returns a script that will be executed on client, but will be downloaded from server
Args:
scriptName: Name of the script to be downloaded, relative path (i.e. 'scripts/direct/transport.py')
params: Parameters for the return tuple
"""
# Reads script and signature
basePath = os.path.dirname(sys.modules[self.__module__].__file__ or 'not_found') # Will raise if not found
script = open(os.path.join(basePath, scriptName), 'r').read()
signature = open(os.path.join(basePath, scriptName + '.signature'), 'r').read()
return script, signature, params
def getScript(
self, osName: str, type: typing.Literal['tunnel', 'direct'], params: typing.Mapping[str, typing.Any]
) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]:
"""
Returns a script for the given os and type
"""
return self.getRelativeScript(
'scripts/{os}/{type}.py'.format(os=osName, type=type), params
)
def getLink(
self,
userService: 'models.UserService',

View File

@ -130,7 +130,7 @@ def packageRelativeFile(moduleName: str, fileName: str) -> str:
This allows to keep images alongside report
"""
mod = sys.modules[moduleName]
if mod and mod.__file__:
if mod and hasattr(mod, '__file__') and mod.__file__:
pkgpath = os.path.dirname(mod.__file__)
return os.path.join(pkgpath, fileName)
# Not found, return fileName

View File

@ -196,4 +196,4 @@ class RDPTransport(BaseRDPTransport):
}
)
return self.getScript('scripts/{}/direct.py', osName, sp)
return self.getScript(osName, 'direct', sp)

View File

@ -243,4 +243,4 @@ class TRDPTransport(BaseRDPTransport):
}
)
return self.getScript('scripts/{}/tunnel.py', osName, sp)
return self.getScript(osName, 'tunnel', sp)

View File

@ -97,6 +97,8 @@ class SPICETransport(BaseSpiceTransport):
con['cert_subject'],
fullscreen=self.fullScreen.isTrue(),
)
r.proxy = con.get('proxy', None)
r.usb_auto_share = self.usbShare.isTrue()
r.new_usb_auto_share = self.autoNewUsbShare.isTrue()
r.smartcard = self.smartCardRedirect.isTrue()
@ -119,4 +121,4 @@ class SPICETransport(BaseSpiceTransport):
'as_file': r.as_file,
}
return self.getScript('scripts/{}/direct.py', osName, sp)
return self.getScript(osName, 'direct', sp)

View File

@ -201,4 +201,4 @@ class TSPICETransport(BaseSpiceTransport):
'ticket_secure': ticket_secure,
}
return self.getScript('scripts/{}/tunnel.py', osName, sp)
return self.getScript(osName, 'tunnel', sp)

View File

@ -120,4 +120,4 @@ class X2GOTransport(BaseX2GOTransport):
sp = {'ip': ip, 'port': '22', 'key': priv, 'xf': xf}
return self.getScript('scripts/{}/direct.py', osName, sp)
return self.getScript(osName, 'direct', sp)

View File

@ -197,4 +197,4 @@ class TX2GOTransport(BaseX2GOTransport):
'xf': xf,
}
return self.getScript('scripts/{}/tunnel.py', osName, sp)
return self.getScript(osName, 'tunnel', sp)