def _stop_monitoring(self): if self._pid == "": return self._set_button_running(False) noti = ui_pb2.Notification(clientName="", serverName="", type=ui_pb2.STOP_MONITOR_PROCESS, data=str(self._pid), rules=[]) self._nid = self._nodes.send_notification(self._pids[self._pid], noti, self._notification_callback) self._notifications_sent[self._nid] = noti self._pid = "" self._app_icon = None
def firewall(self, not_type=ui_pb2.LOAD_FIREWALL, addr=None, callback=None): noti = ui_pb2.Notification(clientName="", serverName="", type=not_type, data="", rules=[]) if addr == None: nid = self.send_notifications(noti, callback) else: nid = self.send_notification(addr, noti, callback) return nid, noti
def _cb_enable_rule_toggled(self, state): rule = ui_pb2.Rule(name=self.TABLES[self.tabWidget.currentIndex()]['label'].text()) rule.enabled = False rule.action = "" rule.duration = "" rule.operator.type = "" rule.operator.operand = "" rule.operator.data = "" notType = ui_pb2.DISABLE_RULE if state == True: notType = ui_pb2.ENABLE_RULE rule.enabled = state noti = ui_pb2.Notification(type=notType, rules=[rule]) self._notification_trigger.emit(noti)
def _del_rule(self, rule_name, node_addr): rule = ui_pb2.Rule(name=rule_name) rule.enabled = False rule.action = "" rule.duration = "" rule.operator.type = "" rule.operator.operand = "" rule.operator.data = "" noti = ui_pb2.Notification(type=ui_pb2.DELETE_RULE, rules=[rule]) nid = self._nodes.send_notification(node_addr, noti, self._notification_callback) self._notifications_sent[nid] = noti self._db.remove("DELETE FROM rules WHERE name='%s' AND node='%s'" % (rule.name, node_addr)) self._refresh_active_table()
def _save_settings(self): if self.tabWidget.currentIndex() == 0: self._cfg.setSettings(self.CFG_DEFAULT_ACTION, self.comboUIAction.currentIndex()) self._cfg.setSettings(self.CFG_DEFAULT_DURATION, int(self.comboUIDuration.currentIndex())) self._cfg.setSettings(self.CFG_DEFAULT_TARGET, self.comboUITarget.currentIndex()) self._cfg.setSettings(self.CFG_DEFAULT_TIMEOUT, self.spinUITimeout.value()) self._cfg.setSettings(self.CFG_DISABLE_POPUPS, bool(self.popupsCheck.isChecked())) # this is a workaround for not display pop-ups. # see #79 for more information. if self.popupsCheck.isChecked(): self._cfg.setSettings(self.CFG_DEFAULT_TIMEOUT, 0) elif self.tabWidget.currentIndex() == 1: self._show_status_label() addr = self.comboNodes.currentText() if (self._node_needs_update or self.checkApplyToNodes.isChecked()) and addr != "": try: notif = ui_pb2.Notification(id=int( str(time.time()).replace(".", "")), type=ui_pb2.CHANGE_CONFIG, data="", rules=[]) if self.checkApplyToNodes.isChecked(): for addr in self._nodes.get_nodes(): error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return else: error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return except Exception as e: print(self.LOG_TAG + "exception saving config: ", e) self._set_status_error( QtCore.QCoreApplication.translate( "preferences", "Exception saving config: {0}").format(str(e))) self._node_needs_update = False
def _start_monitoring(self): try: # avoid to send notifications without a pid if self._pid != "": return self._pid = self.comboPids.currentText() if self._pid == "": return self._set_button_running(True) noti = ui_pb2.Notification(clientName="", serverName="", type=ui_pb2.MONITOR_PROCESS, data=self._pid, rules=[]) self._nid = self._nodes.send_notification(self._pids[self._pid], noti, self._notification_callback) self._notifications_sent[self._nid] = noti except Exception as e: print(self.LOG_TAG + "exception starting monitoring: ", e)
def _cb_start_clicked(self): if self.daemon_connected == False: self.startButton.setChecked(False) return self.statusLabel.setStyleSheet('color: green') # TODO: move to a new method: node.load_firewall(), unload_firewall() notType = ui_pb2.UNLOAD_FIREWALL if self.startButton.isChecked(): self.statusLabel.setText("running") notType = ui_pb2.LOAD_FIREWALL else: self.statusLabel.setText("running/disabled") noti = ui_pb2.Notification(clientName="", serverName="", type=notType, data="", rules=[]) nid = self._nodes.send_notifications(noti, self._notification_callback) self._notifications_sent[nid] = noti
def _save_settings(self): if self.tabWidget.currentIndex() == 0: self._save_ui_config() elif self.tabWidget.currentIndex() == 1: self._show_status_label() addr = self.comboNodes.currentText() if (self._node_needs_update or self.checkApplyToNodes.isChecked()) and addr != "": try: notif = ui_pb2.Notification(id=int( str(time.time()).replace(".", "")), type=ui_pb2.CHANGE_CONFIG, data="", rules=[]) if self.checkApplyToNodes.isChecked(): for addr in self._nodes.get_nodes(): error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return else: error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return except Exception as e: print(self.LOG_TAG + "exception saving config: ", e) self._set_status_error( QC.translate("preferences", "Exception saving config: {0}").format( str(e))) self._node_needs_update = False elif self.tabWidget.currentIndex() == 2: self._save_db_config()
def _delete_rule(self): try: if self._old_rule_name != None: # if the rule name has changed, we need to remove the old one if self._old_rule_name != self.rule.name: self._db.remove("DELETE FROM rules WHERE name='%s'" % self._old_rule_name) old_rule = self.rule old_rule.name = self._old_rule_name notif_delete = ui_pb2.Notification(type=ui_pb2.DELETE_RULE, rules=[old_rule]) if self.nodeApplyAllCheck.isChecked(): nid = self._nodes.send_notifications( notif_delete, self._notification_callback) else: nid = self._nodes.send_notification( self.nodesCombo.currentText(), notif_delete, self._notification_callback) self._old_rule_name = None except Exception as e: print(self.LOG_TAG, "delete_rule() exception: ", e)
def _add_rule(self): try: if self.nodeApplyAllCheck.isChecked(): for pos in range(self.nodesCombo.count()): self._insert_rule_to_db(self.nodesCombo.itemText(pos)) else: self._insert_rule_to_db(self.nodesCombo.currentText()) notif = ui_pb2.Notification(id=int( str(time.time()).replace(".", "")), type=ui_pb2.CHANGE_RULE, data="", rules=[self.rule]) if self.nodeApplyAllCheck.isChecked(): nid = self._nodes.send_notifications( notif, self._notification_callback) else: nid = self._nodes.send_notification( self.nodesCombo.currentText(), notif, self._notification_callback) self._notifications_sent[nid] = notif except Exception as e: print(self.LOG_TAG, "add_rule() exception: ", e)
def _save_settings(self): if self.tabWidget.currentIndex() == 0: self._cfg.setSettings(self._cfg.DEFAULT_ACTION_KEY, self.comboUIAction.currentIndex()) self._cfg.setSettings(self._cfg.DEFAULT_DURATION_KEY, int(self.comboUIDuration.currentIndex())) self._cfg.setSettings(self._cfg.DEFAULT_TARGET_KEY, self.comboUITarget.currentIndex()) self._cfg.setSettings(self._cfg.DEFAULT_TIMEOUT_KEY, self.spinUITimeout.value()) self._cfg.setSettings(self.CFG_DISABLE_POPUPS, bool(self.popupsCheck.isChecked())) # this is a workaround for not display pop-ups. # see #79 for more information. if self.popupsCheck.isChecked(): self._cfg.setSettings(self._cfg.DEFAULT_TIMEOUT_KEY, 0) elif self.tabWidget.currentIndex() == 1: self._show_status_label() addr = self.comboNodes.currentText() if (self._node_needs_update or self.checkApplyToNodes.isChecked()) and addr != "": try: notif = ui_pb2.Notification(id=int( str(time.time()).replace(".", "")), type=ui_pb2.CHANGE_CONFIG, data="", rules=[]) if self.checkApplyToNodes.isChecked(): for addr in self._nodes.get_nodes(): error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return else: error = self._save_node_config(notif, addr) if error != None: self._set_status_error(error) return except Exception as e: print(self.LOG_TAG + "exception saving config: ", e) self._set_status_error( QC.translate("preferences", "Exception saving config: {0}").format( str(e))) self._node_needs_update = False elif self.tabWidget.currentIndex() == 2: dbtype = self.comboDBType.currentIndex() self._cfg.setSettings(Config.DEFAULT_DB_TYPE_KEY, dbtype) if dbtype == self._db.get_db_file(): return if self.comboDBType.currentIndex() != Database.DB_TYPE_MEMORY: if self.dbLabel.text() != "": self._cfg.setSettings(Config.DEFAULT_DB_FILE_KEY, self.dbLabel.text()) else: Message.ok( QC.translate("preferences", "Warning"), QC.translate( "preferences", "You must select a file for the database<br>or choose \"In memory\" type." ), QtWidgets.QMessageBox.Warning) return Message.ok( QC.translate("preferences", "DB type changed"), QC.translate( "preferences", "Restart the GUI in order effects to take effect"), QtWidgets.QMessageBox.Warning)