Beispiel #1
0
    def __init__(self, config_file=None, use_plugins=True, use_style=True):
        super(KingPhisherClientApplication, self).__init__()
        if use_style:
            gtk_version = (Gtk.get_major_version(), Gtk.get_minor_version())
            if gtk_version > (3, 18):
                self._theme_file = 'theme.v2.css'
            else:
                self._theme_file = 'theme.v1.css'
        else:
            self._theme_file = DISABLED
        self.logger = logging.getLogger('KingPhisher.Client.Application')
        # log version information for debugging purposes
        self.logger.debug("gi.repository GLib version: {0}".format('.'.join(
            map(str, GLib.glib_version))))
        self.logger.debug("gi.repository GObject version: {0}".format('.'.join(
            map(str, GObject.pygobject_version))))
        self.logger.debug("gi.repository Gtk version: {0}.{1}.{2}".format(
            Gtk.get_major_version(), Gtk.get_minor_version(),
            Gtk.get_micro_version()))
        if rpc_terminal.has_vte:
            self.logger.debug("gi.repository VTE version: {0}".format(
                rpc_terminal.Vte._version))
        if graphs.has_matplotlib:
            self.logger.debug("matplotlib version: {0}".format(
                graphs.matplotlib.__version__))
        self.set_property('application-id', 'org.king-phisher.client')
        self.set_property('register-session', True)
        self.config_file = config_file or os.path.join(USER_DATA_PATH,
                                                       'config.json')
        """The file containing the King Phisher client configuration."""
        if not os.path.isfile(self.config_file):
            self._create_config()
        self.config = None
        """The primary King Phisher client configuration."""
        self.main_window = None
        """The primary top-level :py:class:`~.MainAppWindow` instance."""
        self.rpc = None
        """The :py:class:`~.KingPhisherRPCClient` instance for the application."""
        self._ssh_forwarder = None
        """The SSH forwarder responsible for tunneling RPC communications."""
        self.style_provider = None
        try:
            self.emit('config-load', True)
        except IOError:
            self.logger.critical('failed to load the client configuration')
            raise

        self.connect('window-added', self.signal_window_added)
        self.actions = {}
        self._create_actions()

        if not use_plugins:
            self.logger.info('disabling all plugins')
            self.config['plugins.enabled'] = []
        self.plugin_manager = plugins.ClientPluginManager([
            os.path.join(USER_DATA_PATH, 'plugins'),
            find.find_data_directory('plugins')
        ], self)
        if use_plugins:
            self.plugin_manager.load_all()
Beispiel #2
0
    def __init__(self, config_file=None, use_plugins=True, use_style=True):
        super(KingPhisherClientApplication, self).__init__()
        if use_style:
            # 3.20+ use theme.v2.css
            if Gtk.check_version(3, 20, 0) or its.on_windows:
                self._theme_file = 'theme.v1.css'
            else:
                self._theme_file = 'theme.v2.css'
        else:
            self._theme_file = DISABLED
        self.user_data_path = os.path.join(GLib.get_user_config_dir(),
                                           USER_DATA_PATH)
        """
		The path to a directory where user data files can be stored. This path
		must be writable by the current user.

		The default value is platform dependant:

		:Linux:
			``~/.config/king-phisher``

		:Windows:
			``%LOCALAPPDATA%\\king-phisher``
		"""
        self.logger = logging.getLogger('KingPhisher.Client.Application')
        # log version information for debugging purposes
        self.logger.debug("gi.repository GLib version: {0}".format('.'.join(
            map(str, GLib.glib_version))))
        self.logger.debug("gi.repository GObject version: {0}".format('.'.join(
            map(str, GObject.pygobject_version))))
        self.logger.debug("gi.repository Gtk version: {0}.{1}.{2}".format(
            Gtk.get_major_version(), Gtk.get_minor_version(),
            Gtk.get_micro_version()))
        if rpc_terminal.has_vte:
            self.logger.debug("gi.repository VTE version: {0}".format(
                rpc_terminal.Vte._version))
        if graphs.has_matplotlib:
            self.logger.debug("matplotlib version: {0}".format(
                graphs.matplotlib.__version__))
        # do not negotiate a single instance application
        # https://developer.gnome.org/gio/unstable/GApplication.html#G-APPLICATION-NON-UNIQUE:CAPS
        self.set_flags(Gio.ApplicationFlags.NON_UNIQUE)
        self.set_property('application-id', 'org.king-phisher.client')
        self.set_property('register-session', True)
        self.config_file = config_file or os.path.join(self.user_data_path,
                                                       'config.json')
        """The file containing the King Phisher client configuration."""
        if not os.path.isfile(self.config_file):
            self._create_config()
        self.config = None
        """The primary King Phisher client configuration."""
        self.main_window = None
        """The primary top-level :py:class:`~.MainAppWindow` instance."""
        self.references = []
        """A list to store references to arbitrary objects in for avoiding garbage collection."""
        self.rpc = None
        """The :py:class:`~.KingPhisherRPCClient` instance for the application."""
        self._rpc_ping_event = None
        # this will be populated when the RPC object is authenticated to ping
        # the server periodically and keep the session alive
        self.server_events = None
        """The :py:class:`~.ServerEventSubscriber` instance for the application to receive server events."""
        self.server_user = None
        """The :py:class:`~.ServerUser` instance for the authenticated user."""
        self._ssh_forwarder = None
        """The SSH forwarder responsible for tunneling RPC communications."""
        self.style_provider = None
        try:
            self.emit('config-load', True)
        except IOError:
            self.logger.critical('failed to load the client configuration')
            raise

        self.connect('window-added', self.signal_window_added)
        self.actions = {}
        self._create_actions()

        if not use_plugins:
            self.logger.info('disabling all plugins')
            self.config['plugins.enabled'] = []

        if not os.path.exists(os.path.join(self.user_data_path, 'plugins')):
            try:
                os.mkdir(os.path.join(self.user_data_path, 'plugins'))
            except OSError:
                self.logger.warning('Failed to create user plugins folder')

        self.plugin_manager = plugins.ClientPluginManager([
            os.path.join(self.user_data_path, 'plugins'),
            find.data_directory('plugins')
        ] + self.config.get('plugins.path', []), self)
        """The :py:class:`~king_phisher.client.plugins.ClientPluginManager` instance to manage the installed client plugins."""
        if use_plugins:
            self.plugin_manager.load_all()