Пример #1
0
    def do_sftp_client_start(self):
        """
		Start the client's preferred sftp client application in a new process.
		"""
        if not self.config['sftp_client']:
            gui_utilities.show_dialog_error(
                'Invalid SFTP Configuration', self.get_active_window(),
                'An SFTP client is not configured.\nOne can be configured in the Client Preferences.'
            )
            return False
        command = str(self.config['sftp_client'])
        sftp_bin = shlex.split(command)[0]
        if not which(sftp_bin):
            self.logger.error('could not locate the sftp binary: ' + sftp_bin)
            gui_utilities.show_dialog_error(
                'Invalid SFTP Configuration', self.get_active_window(),
                "Could not find the SFTP binary '{0}'".format(sftp_bin))
            return False
        try:
            command = command.format(
                server=self.config['server'],
                username=self.config['server_username'],
                web_root=self.config['server_config']['server.web_root'])
        except KeyError as error:
            self.logger.error(
                "key error while parsing the sftp command for token: {0}".
                format(error.args[0]))
            gui_utilities.show_dialog_error(
                'Invalid SFTP Configuration', self.get_active_window(),
                "Invalid token '{0}' in the SFTP command.".format(
                    error.args[0]))
            return False
        self.logger.debug("starting sftp client command: {0}".format(command))
        utilities.start_process(command, wait=False)
        return
Пример #2
0
	def do_sftp_client_start(self):
		"""
		Start the client's preferred sftp client application in a new process.
		"""
		if not self.config['sftp_client']:
			gui_utilities.show_dialog_error('Invalid SFTP Configuration', self.get_active_window(), 'An SFTP client is not configured.\nOne can be configured in the Client Preferences.')
			return False
		command = str(self.config['sftp_client'])
		sftp_bin = shlex.split(command)[0]
		if not which(sftp_bin):
			self.logger.error('could not locate the sftp binary: ' + sftp_bin)
			gui_utilities.show_dialog_error('Invalid SFTP Configuration', self.get_active_window(), "Could not find the SFTP binary '{0}'".format(sftp_bin))
			return False
		try:
			command = command.format(
				server=self.config['server'],
				username=self.config['server_username'],
				web_root=self.config['server_config']['server.web_root']
			)
		except KeyError as error:
			self.logger.error("key error while parsing the sftp command for token: {0}".format(error.args[0]))
			gui_utilities.show_dialog_error('Invalid SFTP Configuration', self.get_active_window(), "Invalid token '{0}' in the SFTP command.".format(error.args[0]))
			return False
		self.logger.debug("starting sftp client command: {0}".format(command))
		utilities.start_process(command, wait=False)
		return
Пример #3
0
def open_uri(uri):
	"""
	Open a URI in a platform intelligent way. On Windows this will use
	'cmd.exe /c start' and on Linux this will use gvfs-open or xdg-open
	depending on which is available. If no suitable application can be
	found to open the URI, a RuntimeError will be raised.

	:param str uri: The URI to open.
	"""
	proc_args = []
	if sys.platform.startswith('win'):
		proc_args.append(which('cmd.exe'))
		proc_args.append('/c')
		proc_args.append('start')
	elif which('gvfs-open'):
		proc_args.append(which('gvfs-open'))
	elif which('xdg-open'):
		proc_args.append(which('xdg-open'))
	else:
		raise RuntimeError('could not find suitable application to open uri')
	proc_args.append(uri)
	return start_process(proc_args)
Пример #4
0
def open_uri(uri):
    """
	Open a URI in a platform intelligent way. On Windows this will use
	'cmd.exe /c start' and on Linux this will use gvfs-open or xdg-open
	depending on which is available. If no suitable application can be
	found to open the URI, a RuntimeError will be raised.

	:param str uri: The URI to open.
	"""
    proc_args = []
    if sys.platform.startswith('win'):
        proc_args.append(which('cmd.exe'))
        proc_args.append('/c')
        proc_args.append('start')
    elif which('gvfs-open'):
        proc_args.append(which('gvfs-open'))
    elif which('xdg-open'):
        proc_args.append(which('xdg-open'))
    else:
        raise RuntimeError('could not find suitable application to open uri')
    proc_args.append(uri)
    return start_process(proc_args)
Пример #5
0
	def __init__(self, application):
		"""
		:param application: The application instance to which this window belongs.
		:type application: :py:class:`.KingPhisherClientApplication`
		"""
		assert isinstance(application, Gtk.Application)
		self.application = application
		self.logger = logging.getLogger('KingPhisher.Client.' + self.__class__.__name__)
		if not has_vte:
			gui_utilities.show_dialog_error('RPC Terminal Is Unavailable', self.application.get_active_window(), 'VTE is not installed')
			return
		config = application.config

		self.terminal = Vte.Terminal()
		self.rpc_window = RPCTerminalWindow(self.terminal, self.application)

		rpc = self.application.rpc
		config = {
			'campaign_id': config['campaign_id'],
			'campaign_name': config['campaign_name'],
			'rpc_data': {
				'address': (rpc.host, rpc.port),
				'use_ssl': rpc.use_ssl,
				'username': rpc.username,
				'uri_base': rpc.uri_base,
				'hmac_key': rpc.hmac_key
			}
		}

		module_path = os.path.dirname(client_rpc.__file__) + ((os.path.sep + '..') * client_rpc.__name__.count('.'))
		module_path = os.path.normpath(module_path)

		python_command = [
			"import {0}".format(client_rpc.__name__),
			"{0}.vte_child_routine('{1}')".format(client_rpc.__name__, json.dumps(config))
		]
		python_command = '; '.join(python_command)

		if hasattr(self.terminal, 'pty_new_sync'):
			# Vte._version >= 2.91
			vte_pty = self.terminal.pty_new_sync(Vte.PtyFlags.DEFAULT)
			self.terminal.set_pty(vte_pty)
			self.terminal.connect('child-exited', lambda vt, status: self.rpc_window.window.destroy())
		else:
			# Vte._version <= 2.90
			vte_pty = self.terminal.pty_new(Vte.PtyFlags.DEFAULT)
			self.terminal.set_pty_object(vte_pty)
			self.terminal.connect('child-exited', lambda vt: self.rpc_window.window.destroy())

		child_pid, _, _, _ = GLib.spawn_async(
			working_directory=os.getcwd(),
			argv=[which('python'), '-c', python_command],
			envp=['PYTHONPATH=' + module_path],
			flags=(GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD),
			child_setup=self._child_setup,
			user_data=vte_pty
		)

		self.logger.info("vte spawned child process with pid: {0}".format(child_pid))
		self.child_pid = child_pid
		self.terminal.watch_child(child_pid)
		GLib.spawn_close_pid(child_pid)
		self.rpc_window.window.show_all()
		self.rpc_window.child_pid = child_pid

		# automatically enter the password
		vte_pty_fd = vte_pty.get_fd()
		if len(select.select([vte_pty_fd], [], [], 1)[0]):
			os.write(vte_pty_fd, rpc.password + '\n')
		return
Пример #6
0
    def __init__(self, application):
        """
		:param application: The application instance to which this window belongs.
		:type application: :py:class:`.KingPhisherClientApplication`
		"""
        assert isinstance(application, Gtk.Application)
        self.application = application
        self.logger = logging.getLogger('KingPhisher.Client.' +
                                        self.__class__.__name__)
        if not has_vte:
            gui_utilities.show_dialog_error(
                'RPC Terminal Is Unavailable',
                self.application.get_active_window(), 'VTE is not installed')
            return
        config = application.config

        self.terminal = Vte.Terminal()
        self.rpc_window = RPCTerminalAppWindow(self.terminal, self.application)

        rpc = self.application.rpc
        config = {
            'campaign_id': config['campaign_id'],
            'campaign_name': config['campaign_name'],
            'rpc_data': {
                'address': (rpc.host, rpc.port),
                'use_ssl': rpc.use_ssl,
                'username': rpc.username,
                'uri_base': rpc.uri_base,
                'headers': rpc.headers,
                'hmac_key': rpc.hmac_key
            }
        }

        module_path = os.path.dirname(client_rpc.__file__) + (
            (os.path.sep + '..') * client_rpc.__name__.count('.'))
        module_path = os.path.normpath(module_path)

        python_command = [
            "import {0}".format(client_rpc.__name__),
            "{0}.vte_child_routine('{1}')".format(
                client_rpc.__name__, json_ex.dumps(config, pretty=False))
        ]
        python_command = '; '.join(python_command)

        if hasattr(self.terminal, 'pty_new_sync'):
            # Vte._version >= 2.91
            vte_pty = self.terminal.pty_new_sync(Vte.PtyFlags.DEFAULT)
            self.terminal.set_pty(vte_pty)
            self.terminal.connect(
                'child-exited',
                lambda vt, status: self.rpc_window.window.destroy())
        else:
            # Vte._version <= 2.90
            vte_pty = self.terminal.pty_new(Vte.PtyFlags.DEFAULT)
            self.terminal.set_pty_object(vte_pty)
            self.terminal.connect('child-exited',
                                  lambda vt: self.rpc_window.window.destroy())

        child_pid, _, _, _ = GLib.spawn_async(
            working_directory=os.getcwd(),
            argv=[which('python'), '-c', python_command],
            envp=[
                'PYTHONPATH=' + module_path,
                find.ENV_VAR + '=' + os.environ[find.ENV_VAR]
            ],
            flags=(GLib.SpawnFlags.SEARCH_PATH
                   | GLib.SpawnFlags.DO_NOT_REAP_CHILD),
            child_setup=self._child_setup,
            user_data=vte_pty)

        self.logger.info(
            "vte spawned child process with pid: {0}".format(child_pid))
        self.child_pid = child_pid
        self.terminal.watch_child(child_pid)
        GLib.spawn_close_pid(child_pid)
        self.rpc_window.window.show_all()
        self.rpc_window.child_pid = child_pid
        return