Skip to content

Commit f91f1a9

Browse files
ui: allow to use multiple protobuffer versions
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
1 parent 4282fe4 commit f91f1a9

File tree

22 files changed

+2769
-30
lines changed

22 files changed

+2769
-30
lines changed

ui/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
recursive-include opensnitch/proto *
12
recursive-include opensnitch/res *
23
recursive-include opensnitch/i18n *.qm
34
recursive-include opensnitch/database/migrations *.sql

ui/bin/opensnitch-ui

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ from opensnitch.service import UIService
4242
from opensnitch.config import Config
4343
from opensnitch.utils import Themes, Utils, Versions, Message
4444
from opensnitch.utils.xdg import xdg_opensnitch_dir, xdg_current_session
45-
import opensnitch.ui_pb2
46-
from opensnitch.ui_pb2_grpc import add_UIServicer_to_server
45+
4746
from opensnitch import auth
47+
import opensnitch.proto as proto
48+
ui_pb2, ui_pb2_grpc = proto.import_()
4849

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

@@ -203,7 +204,7 @@ Examples:
203204
('grpc.max_receive_message_length', maxmsglen),
204205
))
205206

206-
add_UIServicer_to_server(service, server)
207+
ui_pb2_grpc.add_UIServicer_to_server(service, server)
207208

208209
auth_type = auth.Simple
209210
if args.socket_auth != None:

ui/opensnitch/dialogs/firewall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from opensnitch.config import Config
1212
from opensnitch.nodes import Nodes
1313
from opensnitch.dialogs.firewall_rule import FwRuleDialog
14-
from opensnitch import ui_pb2
1514
import opensnitch.firewall as Fw
1615
import opensnitch.firewall.profiles as FwProfiles
1716

17+
import opensnitch.proto as proto
18+
ui_pb2, ui_pb2_grpc = proto.import_()
1819

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

ui/opensnitch/dialogs/firewall_rule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from opensnitch.config import Config
1010
from opensnitch.nodes import Nodes
1111
from opensnitch.utils import NetworkServices, NetworkInterfaces, QuickHelp, Icons, Utils
12-
from opensnitch import ui_pb2
1312
import opensnitch.firewall as Fw
1413
from opensnitch.firewall.utils import Utils as FwUtils
1514

15+
import opensnitch.proto as proto
16+
ui_pb2, ui_pb2_grpc = proto.import_()
1617

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

ui/opensnitch/dialogs/preferences.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
from opensnitch.utils.xdg import Autostart
1515
from opensnitch.notifications import DesktopNotifications
1616

17-
from opensnitch import ui_pb2, auth
17+
from opensnitch import auth
18+
import opensnitch.proto as proto
19+
ui_pb2, ui_pb2_grpc = proto.import_()
1820

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

ui/opensnitch/dialogs/processdetails.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
from PyQt5 import QtCore, QtGui, uic, QtWidgets
66

7-
from opensnitch import ui_pb2
7+
import opensnitch.proto as proto
8+
ui_pb2, ui_pb2_grpc = proto.import_()
9+
810
from opensnitch.nodes import Nodes
911
from opensnitch.desktop_parser import LinuxDesktopParser
1012
from opensnitch.utils import Message, Icons

ui/opensnitch/dialogs/prompt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from opensnitch.actions import Actions
2121
from opensnitch.rules import Rules, Rule
2222

23-
from opensnitch import ui_pb2
23+
import opensnitch.proto as proto
24+
ui_pb2, ui_pb2_grpc = proto.import_()
2425

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

ui/opensnitch/dialogs/ruleseditor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import sys
88
import os
99
import pwd
10-
from opensnitch import ui_pb2
1110
import time
1211
import ipaddress
1312

13+
import opensnitch.proto as proto
14+
ui_pb2, ui_pb2_grpc = proto.import_()
15+
1416
from opensnitch.config import Config
1517
from opensnitch.nodes import Nodes
1618
from opensnitch.database import Database

ui/opensnitch/dialogs/stats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from PyQt5 import QtCore, QtGui, uic, QtWidgets
99
from PyQt5.QtCore import QCoreApplication as QC
1010

11-
from opensnitch import ui_pb2
1211
from opensnitch.config import Config
1312
from opensnitch.version import version
1413
from opensnitch.nodes import Nodes
@@ -27,6 +26,9 @@
2726
from opensnitch.actions import Actions
2827
from opensnitch.rules import Rule, Rules
2928

29+
import opensnitch.proto as proto
30+
ui_pb2, ui_pb2_grpc = proto.import_()
31+
3032
DIALOG_UI_PATH = "%s/../res/stats.ui" % os.path.dirname(sys.modules[__name__].__file__)
3133
class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
3234

ui/opensnitch/firewall/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from PyQt5.QtCore import QObject, QCoreApplication as QC
22
from google.protobuf import json_format
3-
from opensnitch import ui_pb2
3+
import opensnitch.proto as proto
4+
ui_pb2, ui_pb2_grpc = proto.import_()
45

56
from opensnitch.nodes import Nodes
67
from .enums import *

0 commit comments

Comments
 (0)