def createWorkspace(self, name, description=""): """Uses the instance of workspace manager passed into __init__ to get all the workspaces names and see if they don't clash with the one the user wrote. If everything's fine, it saves the new workspace and returns True. If something went wrong, return False""" if name in self.workspace_manager.getWorkspacesNames(): error_str = "A workspace with name %s already exists" % name model.api.log(error_str, "ERROR") errorDialog(self.window, error_str) creation_ok = False else: model.api.log("Creating workspace '%s'" % name) model.api.devlog("Looking for the delegation class") manager = self.getWorkspaceManager() try: w = manager.createWorkspace(name, description, manager.namedTypeToDbType('CouchDB')) self.change_workspace(w.name) creation_ok = True except Exception as e: model.guiapi.notification_center.showDialog(str(e)) creation_ok = False return creation_ok
def connect_to_couch(self, server_uri, parent=None): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ if parent is None: parent = self.window if not self.serverIO.test_server_url(server_uri): errorDialog(parent, "Could not connect to Faraday Server.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif server_uri.startswith("https://"): if not checkSSL(server_uri): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: CONF.setCouchUri(server_uri) CONF.saveConfig() self.reload_workspaces() self.open_last_workspace() success = True self.lost_connection_dialog_raised = False return success
def connect_to_couch(self, couch_uri, parent=None): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ if parent is None: parent = self.window if not CouchDbManager.testCouch(couch_uri): errorDialog(parent, "Could not connect to Faraday Server.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif couch_uri.startswith("https://"): if not checkSSL(couch_uri): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: CONF.setCouchUri(couch_uri) CONF.saveConfig() self.reload_workspaces() self.open_last_workspace() success = True self.lost_connection_dialog_raised = False return success
def createWorkspace(self, name, description=""): """Uses the instance of workspace manager passed into __init__ to get all the workspaces names and see if they don't clash with the one the user wrote. If everything's fine, it saves the new workspace and returns True. If something went wrong, return False""" if name in self.workspace_manager.getWorkspacesNames(): error_str = "A workspace with name %s already exists" % name model.api.log(error_str, "ERROR") errorDialog(self.window, error_str) creation_ok = False else: model.api.log("Creating workspace '%s'" % name) model.api.devlog("Looking for the delegation class") manager = self.getWorkspaceManager() try: w = manager.createWorkspace( name, description, manager.namedTypeToDbType('CouchDB')) self.change_workspace(w.name) creation_ok = True except Exception as e: model.guiapi.notification_center.showDialog(str(e)) creation_ok = False return creation_ok
def setPath(): path = questionDialog("Invalid setting: please specify the NetworkManager path for VPN-Connection-Settings on your system.", defaultPath) if not os.path.exists(path): errorDialog("Error: the path " + path + " doesn't exist. Please make sure you entered the right values, check the tool configuration (" + defaultFile + ") and rerun this tool!") exit("Error: Setup failed (invalid VPN config path)") print("Using " + path + " as NM path.") return path
def on_open_report_button(self, action, param): """What happens when the user clicks the open report button. A dialog will present itself with a combobox to select a plugin. Then a file chooser to select a report. The report will be processed with the selected plugin. """ def select_plugin(): """Creates a simple dialog with a combo box to select a plugin""" plugins_id = [_id for _id in self.plugin_manager.getPlugins()] plugins_id = sorted(plugins_id, key=lambda s: s.lower()) dialog = Gtk.Dialog("Select plugin", self.window, 0) combo_box = Gtk.ComboBoxText() combo_box.set_wrap_width(3) for plugin_id in plugins_id: combo_box.append_text(plugin_id) combo_box.show() dialog.vbox.pack_start(combo_box, False, True, 10) dialog.add_button("Cancel", Gtk.ResponseType.DELETE_EVENT) dialog.add_button("OK", Gtk.ResponseType.ACCEPT) response = dialog.run() selected = combo_box.get_active_text() dialog.destroy() return response, selected def on_file_selected(plugin_id, report): """Send the plugin_id and the report file to be processed""" try: self.report_manager.sendReportToPluginById(plugin_id, report) except Unauthorized: self.show_normal_error("You are not authorized to write data " "to this workspace.") plugin_response, plugin_id = select_plugin() while plugin_response == Gtk.ResponseType.ACCEPT and plugin_id is None: # force user to select a plugin if he did not do it errorDialog(self.window, "Please select a plugin to parse your report!") plugin_response, plugin_id = select_plugin() else: if plugin_response == Gtk.ResponseType.ACCEPT: dialog = Gtk.FileChooserDialog(title="Import a report", parent=self.window, action=Gtk.FileChooserAction.OPEN, buttons=("Open", Gtk.ResponseType.ACCEPT, "Cancel", Gtk.ResponseType.CANCEL) ) dialog.set_modal(True) res = dialog.run() if res == Gtk.ResponseType.ACCEPT: on_file_selected(plugin_id, dialog.get_filename()) dialog.destroy()
def checkPath(path, conID): if(os.path.exists(path)): print("Using " + path + " as vpn config path.") infoDialog("This Tool will look for your VPN Connection settings at " + path + ". If you need to change this, use the Tool Menu. (Connection -> Tool Settings)") else: print("Error: File not found at " + path) nmPath = questionDialog("No file found at " + path + "\nPlease specify the NetworkManager path for VPN-Connection-Settings on your system.", defaultPath) path = nmPath + conID if not os.path.exists(path): errorDialog("Error: no VPN configfile found at " + path + ". Please make sure you entered the right values and created the PP VPN connection in NetworkManager and rerun this tool!") exit("Error: Setup failed (invalid VPN config file)") return path
def on_open_report_button(self, action, param): """What happens when the user clicks the open report button. A dialog will present itself with a combobox to select a plugin. Then a file chooser to select a report. The report will be processed with the selected plugin. """ def select_plugin(): """Creates a simple dialog with a combo box to select a plugin""" plugins_id = [_id for _id in self.plugin_manager.getPlugins()] plugins_id = sorted(plugins_id) dialog = Gtk.Dialog("Select plugin", self.window, 0) combo_box = Gtk.ComboBoxText() for plugin_id in plugins_id: combo_box.append_text(plugin_id) combo_box.show() dialog.vbox.pack_start(combo_box, True, True, 10) dialog.add_button("Cancel", Gtk.ResponseType.DELETE_EVENT) dialog.add_button("OK", Gtk.ResponseType.ACCEPT) response = dialog.run() selected = combo_box.get_active_text() dialog.destroy() return response, selected def on_file_selected(plugin_id, report): """Send the plugin_id and the report file to be processed""" self.report_manager.sendReportToPluginById(plugin_id, report) plugin_response, plugin_id = select_plugin() while plugin_response == Gtk.ResponseType.ACCEPT and plugin_id is None: # force user to select a plugin if he did not do it errorDialog(self.window, "Please select a plugin to parse your report!") plugin_response, plugin_id = select_plugin() else: if plugin_response == Gtk.ResponseType.ACCEPT: dialog = Gtk.FileChooserNative() dialog.set_title("Import a report") dialog.set_modal(True) dialog.set_transient_for(self.window) dialog.set_action(Gtk.FileChooserAction.OPEN) res = dialog.run() if res == Gtk.ResponseType.ACCEPT: on_file_selected(plugin_id, dialog.get_filename()) dialog.destroy()
def _loadHelp( self, *args ): """ Shows the user manual. Arguments: - self: The main object pointer. - *args: The widget callback arguments. """ try: import gnome gnome.help_display_uri("ghelp:%s/docs/mousetrap.xml" % env.mTDataDir) except ImportError: dialogs.errorDialog( "mouseTrap needs <b>gnome</b> module to show the help. Please install gnome-python and try again.", None ) debug.exception( "mainGui", "The help load failed" )
def _loadHelp(self, *args): """ Shows the user manual. Arguments: - self: The main object pointer. - *args: The widget callback arguments. """ try: import gnome gnome.help_display_uri("ghelp:%s/docs/mousetrap.xml" % env.mTDataDir) except ImportError: dialogs.errorDialog( "mouseTrap needs <b>gnome</b> module to show the help. Please install gnome-python and try again.", None) debug.exception("mainGui", "The help load failed")
def connect_to_couch(self, server_uri, parent=None): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ if parent is None: parent = self.window if not self.serverIO.test_server_url(server_uri): errorDialog(parent, "Could not connect to Faraday Server.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif server_uri.startswith("https://"): if not checkSSL(server_uri): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: try: check_faraday_version() except RuntimeError: errorDialog(parent, "The server ir running a different Faraday version then the " "client you are runnung. Version numbers must match!") success = False return success CONF.setCouchUri(server_uri) CONF.saveConfig() self.reload_workspaces() self.open_last_workspace() success = True self.lost_connection_dialog_raised = False return success
def connect_to_couch(self, server_url, parent=None): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ if parent is None: parent = self.window if not self.serverIO.check_server_url(server_url): errorDialog(parent, "Could not connect to Faraday Server.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif server_url.startswith("https://"): if not checkSSL(server_url): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: try: check_faraday_version() except RuntimeError: errorDialog(parent, "The server ir running a different Faraday version then the " "client you are runnung. Version numbers must match!") success = False return success CONF.setAPIUrl(server_url) CONF.saveConfig() self.reload_workspaces() self.open_last_workspace() success = True self.lost_connection_dialog_raised = False return success
def connect_to_couch(self, couch_uri): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ if not CouchDbManager.testCouch(couch_uri): errorDialog(self.window, "Could not connect to CouchDB.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif couch_uri.startswith("https://"): if not checkSSL(couch_uri): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: CONF.setCouchUri(couch_uri) CONF.saveConfig() self.reloadWorkspaces() success = True return success
def setOvpnFolder(): path = questionDialog("You choose openvpn as connection type. PP Config Tool will use the openvpn configuration files from the PP member downloads. Please get that package (https://www.perfect-privacy.com/members/All.ovpn.ubuntu.zip), extract it and input the path of that folder below:", os.path.expanduser("~/Downloads/All.ovpn.ubuntu")) if not os.path.exists(path): errorDialog("Error: the path " + path + " doesn't exist. Please make sure you entered the right values, check the tool configuration (" + defaultFile + ") and rerun this tool!") exit("Error: Setup failed (invalid VPN config path)") return path