ui,popups: new button to update the checksum of all rules

When filtering by checksum and the checksum of a rule changes, we
display a warning on the popup, indicating that something happened.

The user had the option to update the checksum of one rule, directly
from the popup.

Now there's a new button to update all the rules that have a checksum as
filtering parameter.
This commit is contained in:
Gustavo Iñiguez Goia 2024-09-20 22:48:32 +02:00
parent 61727af788
commit c832accf5d
Failed to generate hash of commit
3 changed files with 102 additions and 67 deletions

View file

@ -92,7 +92,8 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
self.cmdInfo.clicked.connect(self._cb_cmdinfo_clicked)
self.cmdBack.clicked.connect(self._cb_cmdback_clicked)
self.cmdUpdateRule.clicked.connect(self._cb_update_rule_clicked)
self.cmdUpdateRule.clicked.connect(lambda: self._cb_update_rule_clicked(updateAll=False))
self.cmdUpdateRuleAll.clicked.connect(lambda: self._cb_update_rule_clicked(updateAll=True))
self.cmdBackChecksums.clicked.connect(self._cb_cmdback_clicked)
self.messageLabel.linkActivated.connect(self._cb_warninglbl_clicked)
@ -235,29 +236,35 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
self.stackedWidget.setCurrentIndex(_constants.PAGE_DETAILS)
self._stop_countdown()
def _cb_update_rule_clicked(self):
def _cb_update_rule_clicked(self, updateAll=False):
self.labelChecksumStatus.setStyleSheet('')
curRule = self.comboChecksumRule.currentText()
if curRule == "":
return
rule, error = _checksums.update_rule(self._peer, self._rules, curRule, self._con)
if rule == None:
self.labelChecksumStatus.setStyleSheet('color: red')
self.labelChecksumStatus.setText("" + error)
return
for idx in range(0, self.comboChecksumRule.count()):
curRule = self.comboChecksumRule.itemText(idx)
self._nodes.send_notification(
self._peer,
ui_pb2.Notification(
id=int(str(time.time()).replace(".", "")),
type=ui_pb2.CHANGE_RULE,
data="",
rules=[rule]
rule, error = _checksums.update_rule(self._peer, self._rules, curRule, self._con)
if rule == None:
self.labelChecksumStatus.setStyleSheet('color: red')
self.labelChecksumStatus.setText("" + error)
return
self._nodes.send_notification(
self._peer,
ui_pb2.Notification(
id=int(str(time.time()).replace(".", "")),
type=ui_pb2.CHANGE_RULE,
data="",
rules=[rule]
)
)
)
self.labelChecksumStatus.setStyleSheet('color: green')
self.labelChecksumStatus.setText("" + QC.translate("popups", "Rule updated."))
self.labelChecksumStatus.setStyleSheet('color: green')
self.labelChecksumStatus.setText("" + QC.translate("popups", "Rule updated."))
if not updateAll:
break
def _cb_cmdback_clicked(self):
self.stackedWidget.setCurrentIndex(_constants.PAGE_MAIN)

View file

@ -6,9 +6,13 @@ def verify(con, rule):
"""return true if the checksum of a rule matches the one of the process
opening a connection.
"""
# when verifying checksums, we'll always have a rule type List, with at
# least: path of the process + checksum
if rule.operator.type != Config.RULE_TYPE_LIST:
return True, ""
# checksum will be empty if the daemon failed to calculate it.
# in this case assume that it's ok (ignore it).
if con.process_checksums[Config.OPERAND_PROCESS_HASH_MD5] == "":
return True, ""
@ -27,7 +31,7 @@ def update_rule(node, rules, rule_name, con):
# get rule from the db
records = rules.get_by_name(node, rule_name)
if records == None or records.first() == False:
return None, QC.translate("popups", "Rule not updated, not found by name")
return None, QC.translate("popups", "Rule not updated, not found by name ({0})".format(rule_name))
# transform it to proto rule
rule_obj = Rule.new_from_records(records)
@ -42,6 +46,6 @@ def update_rule(node, rules, rule_name, con):
# add it back again to the db
added = rules.add_rules(node, [rule_obj])
if not added:
return None, QC.translate("popups", "Rule not updated.")
return None, QC.translate("popups", "Rule not updated ({0}).".format(rule_name))
return rule_obj, ""

View file

@ -342,6 +342,39 @@
<property name="bottomMargin">
<number>2</number>
</property>
<item row="5" column="0">
<widget class="QComboBox" name="comboChecksumRule"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelChecksumStatus">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelChecksumNote">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
@ -373,55 +406,46 @@
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="cmdUpdateRule">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Update rule</string>
</property>
<property name="icon">
<iconset theme="reload">
<normaloff>../../../../../../.designer/backup</normaloff>../../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelChecksumNote">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QComboBox" name="comboChecksumRule"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelChecksumStatus">
<property name="text">
<string/>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="cmdUpdateRule">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Update rule</string>
</property>
<property name="icon">
<iconset theme="reload">
<normaloff>../../../../../../../../../../../../../../.designer/backup</normaloff>../../../../../../../../../../../../../../.designer/backup</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdUpdateRuleAll">
<property name="text">
<string>Update All</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>