コード例 #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))
        startup.start_process(command, wait=False)
        return
コード例 #2
0
ファイル: utilities.py プロジェクト: securestate/king-phisher
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(smoke_zephyr.utilities.which('cmd.exe'))
		proc_args.append('/c')
		proc_args.append('start')
	elif smoke_zephyr.utilities.which('gvfs-open'):
		proc_args.append(smoke_zephyr.utilities.which('gvfs-open'))
	elif smoke_zephyr.utilities.which('xdg-open'):
		proc_args.append(smoke_zephyr.utilities.which('xdg-open'))
	else:
		raise RuntimeError('could not find suitable application to open uri')
	proc_args.append(uri)
	return startup.start_process(proc_args)
コード例 #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(smoke_zephyr.utilities.which('cmd.exe'))
        proc_args.append('/c')
        proc_args.append('start')
    elif smoke_zephyr.utilities.which('gvfs-open'):
        proc_args.append(smoke_zephyr.utilities.which('gvfs-open'))
    elif smoke_zephyr.utilities.which('xdg-open'):
        proc_args.append(smoke_zephyr.utilities.which('xdg-open'))
    else:
        raise RuntimeError('could not find suitable application to open uri')
    proc_args.append(uri)
    return startup.start_process(proc_args)