Skip to content

Commit

Permalink
ui: allow to use multiple protobuffer versions
Browse files Browse the repository at this point in the history
Protobuffers compiled with protobuf < 3.20.0 are incompatible with
protobuf >= 4.0.0:
https://github.com/evilsocket/opensnitch/wiki/GUI-known-problems#gui-does-not-show-up

This has been a source of problems for some users (#1214, #647), and
in some distributions, previous protobuffer does no longer work due to
incompatibility with the protobuf package version installed
(OpenSuse Tumbleweed).

So in order to solve this issue, we provide several protobuffers,
for old and new protobuf versions:
proto/ui_pb2* for protobuf >= 4.0.0
proto/pre3200/ui_pb2* for protobuf >= 3.6.0 and < 3.20.0

To avoid import errors, each protobuffer must be placed in its own
directory, and the name of the protobuffer files must be named with
the syntax <prefix>_pb2.py/<prefix>_pb2_grpc.py:
  ui_pb2.py and ui_pb2_grpc.py

The default compiled protobuffer will be opensnitch/proto/ui_*.py
instead of opensnitch/ui_*.py
  • Loading branch information
gustavo-iniguez-goya committed Jan 3, 2025
1 parent 24a5105 commit 5dd4ef0
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 34 deletions.
6 changes: 3 additions & 3 deletions proto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ all: ../daemon/ui/protocol/ui.pb.go ../ui/opensnitch/ui_pb2.py
protoc -I. ui.proto --go_out=../daemon/ui/protocol/ --go-grpc_out=../daemon/ui/protocol/ --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative

../ui/opensnitch/ui_pb2.py: ui.proto
python3 -m grpc_tools.protoc -I. --python_out=../ui/opensnitch/ --grpc_python_out=../ui/opensnitch/ ui.proto
python3 -m grpc_tools.protoc -I. --python_out=../ui/opensnitch/proto/ --grpc_python_out=../ui/opensnitch/proto/ ui.proto

clean:
@rm -rf ../daemon/ui/protocol/ui.pb.go
@rm -rf ../ui/opensnitch/ui_pb2.py
@rm -rf ../ui/opensnitch/ui_pb2_grpc.py
@rm -rf ../ui/opensnitch/proto/ui_pb2.py
@rm -rf ../ui/opensnitch/proto/ui_pb2_grpc.py
1 change: 1 addition & 0 deletions ui/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
recursive-include opensnitch/proto *
recursive-include opensnitch/res *
recursive-include opensnitch/i18n *.qm
recursive-include opensnitch/database/migrations *.sql
Expand Down
2 changes: 1 addition & 1 deletion ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install:

opensnitch/resources_rc.py: translations deps
@pyrcc5 -o opensnitch/resources_rc.py opensnitch/res/resources.qrc
sed -i 's/^import ui_pb2/from . import ui_pb2/' opensnitch/ui_pb2*
@find opensnitch/proto/ -name 'ui_pb2_grpc.py' -exec sed -i 's/^import ui_pb2/from . import ui_pb2/' {} \;

translations:
@cd i18n ; make
Expand Down
6 changes: 4 additions & 2 deletions ui/bin/opensnitch-ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ from opensnitch.service import UIService
from opensnitch.config import Config
from opensnitch.utils import Themes, Utils, Versions, Message
from opensnitch.utils.xdg import xdg_opensnitch_dir, xdg_current_session
from opensnitch.ui_pb2_grpc import add_UIServicer_to_server
from opensnitch import auth

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

app_id = os.path.join(xdg_opensnitch_dir, "io.github.evilsocket.opensnitch")

def on_exit():
Expand Down Expand Up @@ -202,7 +204,7 @@ Examples:
('grpc.max_receive_message_length', maxmsglen),
))

add_UIServicer_to_server(service, server)
ui_pb2_grpc.add_UIServicer_to_server(service, server)

auth_type = auth.Simple
if args.socket_auth != None:
Expand Down
3 changes: 2 additions & 1 deletion ui/opensnitch/dialogs/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
from opensnitch.config import Config
from opensnitch.nodes import Nodes
from opensnitch.dialogs.firewall_rule import FwRuleDialog
from opensnitch import ui_pb2
import opensnitch.firewall as Fw
import opensnitch.firewall.profiles as FwProfiles

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

DIALOG_UI_PATH = "%s/../res/firewall.ui" % os.path.dirname(sys.modules[__name__].__file__)
class FirewallDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
Expand Down
3 changes: 2 additions & 1 deletion ui/opensnitch/dialogs/firewall_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from opensnitch.config import Config
from opensnitch.nodes import Nodes
from opensnitch.utils import NetworkServices, NetworkInterfaces, QuickHelp, Icons, Utils
from opensnitch import ui_pb2
import opensnitch.firewall as Fw
from opensnitch.firewall.utils import Utils as FwUtils

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

DIALOG_UI_PATH = "%s/../res/firewall_rule.ui" % os.path.dirname(sys.modules[__name__].__file__)
class FwRuleDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from opensnitch.notifications import DesktopNotifications
from opensnitch.rules import DefaultRulesPath

from opensnitch import ui_pb2, auth
from opensnitch import auth
import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

DIALOG_UI_PATH = "%s/../res/preferences.ui" % os.path.dirname(sys.modules[__name__].__file__)
class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/dialogs/processdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

from PyQt5 import QtCore, QtGui, uic, QtWidgets

from opensnitch import ui_pb2
import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

from opensnitch.nodes import Nodes
from opensnitch.desktop_parser import LinuxDesktopParser
from opensnitch.utils import Message, Icons
Expand Down
5 changes: 3 additions & 2 deletions ui/opensnitch/dialogs/prompt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
from opensnitch.rules import Rules, Rule
from opensnitch.nodes import Nodes

from opensnitch import ui_pb2
from opensnitch.dialogs.prompt import _utils, _constants, _checksums, _details
import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

from network_aliases import NetworkAliases

Expand Down Expand Up @@ -589,7 +590,7 @@ def _send_rule(self):
self._rule.operator.type, self._rule.operator.operand, self._rule.operator.data = _utils.get_combo_operator(
self.whatCombo.itemData(what_idx),
self.whatCombo.currentText(),
self._con)
self._con)
if self._rule.operator.data == "":
print("popups: Invalid rule, discarding: ", self._rule)
self._rule = None
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/dialogs/ruleseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import sys
import os
import pwd
from opensnitch import ui_pb2
import time
import ipaddress

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

from opensnitch.config import Config
from opensnitch.nodes import Nodes
from opensnitch.database import Database
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/dialogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from PyQt5 import QtCore, QtGui, uic, QtWidgets
from PyQt5.QtCore import QCoreApplication as QC

from opensnitch import ui_pb2
from opensnitch.config import Config
from opensnitch.version import version
from opensnitch.nodes import Nodes
Expand All @@ -32,6 +31,9 @@
from opensnitch.plugins import PluginBase
from opensnitch.rules import Rule, Rules

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

DIALOG_UI_PATH = "%s/../res/stats.ui" % os.path.dirname(sys.modules[__name__].__file__)
class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):

Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/firewall/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from PyQt5.QtCore import QObject, QCoreApplication as QC
from google.protobuf import json_format
from opensnitch import ui_pb2

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

from opensnitch.nodes import Nodes
from .enums import *
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/firewall/chains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from opensnitch import ui_pb2
from .enums import *

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

class Chains():

def __init__(self, nodes):
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/firewall/exprs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

from opensnitch import ui_pb2
from .enums import *

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

class Expr():
"""
Expr returns a new nftables expression that defines a match or an action:
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/firewall/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from google.protobuf.json_format import MessageToJson
import uuid

from opensnitch import ui_pb2
from .enums import Operator
from .exprs import ExprLog

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

class Rules(QObject):
rulesUpdated = pyqtSignal()

Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import time
import json

from opensnitch import ui_pb2
from opensnitch.database import Database
from opensnitch.config import Config
from opensnitch.utils import NetworkInterfaces
from opensnitch.rules import Rules

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

class Nodes(QObject):
__instance = None
nodesUpdated = pyqtSignal(int) # total
Expand Down
4 changes: 3 additions & 1 deletion ui/opensnitch/rules.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from PyQt5.QtCore import QObject, pyqtSignal

from opensnitch import ui_pb2
from opensnitch.database import Database
from opensnitch.database.enums import RuleFields
from opensnitch.config import Config

import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

import os
import json
from slugify import slugify
Expand Down
4 changes: 2 additions & 2 deletions ui/opensnitch/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(path)

from opensnitch import ui_pb2
from opensnitch import ui_pb2_grpc
import opensnitch.proto as proto
ui_pb2, ui_pb2_grpc = proto.import_()

from opensnitch.dialogs.prompt import PromptDialog
from opensnitch.dialogs.stats import StatsDialog
Expand Down
12 changes: 1 addition & 11 deletions utils/packaging/ui/deb/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,15 @@ override_dh_auto_clean:
python3 setup.py clean -a
find . -name \*.pyc -exec rm {} \;



override_dh_auto_build:
python3 setup.py build --force



override_dh_auto_install:
cd i18n; make
cp -r i18n/locales/ opensnitch/i18n/
pyrcc5 -o opensnitch/resources_rc.py opensnitch/res/resources.qrc
sed -i 's/^import ui_pb2/from . import ui_pb2/' opensnitch/ui_pb2*
find opensnitch/proto/ -name 'ui_pb2_grpc.py' -exec sed -i 's/^import ui_pb2/from . import ui_pb2/' {} \;
python3 setup.py install --force --root=debian/python3-opensnitch-ui --no-compile -O0 --install-layout=deb



override_dh_python2:
dh_python2 --no-guessing-versions




2 changes: 1 addition & 1 deletion utils/packaging/ui/rpm/opensnitch-ui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fi
cd i18n; make; cd ..
cp -r i18n/locales/ opensnitch/i18n
pyrcc5 -o opensnitch/resources_rc.py opensnitch/res/resources.qrc
sed -i 's/^import ui_pb2/from . import ui_pb2/' opensnitch/ui_pb2*
find opensnitch/proto/ -name 'ui_pb2_grpc.py' -exec sed -i 's/^import ui_pb2/from . import ui_pb2/' {} \;
python3 setup.py build

%install
Expand Down

0 comments on commit 5dd4ef0

Please sign in to comment.