def _save_settings(self): self._save_ui_config() self._save_db_config() if self.tabWidget.currentIndex() == self.TAB_NODES: 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 self.saved.emit() self._settingsSaved = True
def reload_fw(self, addr, fw_config, callback): notif = ui_pb2.Notification( id=int(str(time.time()).replace(".", "")), type=ui_pb2.RELOAD_FW_RULES, sysFirewall=fw_config ) nid = self.send_notification(addr, notif, callback) return nid, notif
def firewall(self, not_type=ui_pb2.ENABLE_INTERCEPTION, 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 stop_notifications(self): """Send a dummy notification to force Notifications class to exit. """ exit_noti = ui_pb2.Notification(clientName="", serverName="", type=0, data="", rules=[]) self.send_notifications(exit_noti)
def delete_rule(self, rule_name, addr, callback): 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.send_notification(addr, noti, None) self._db.delete_rule(rule.name, addr) return nid, noti
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 _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 _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 _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)