File indexing completed on 2025-01-05 05:07:03
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2011 Craig Drummond <craig.p.drummond@gmail.com> 0003 // SPDX-FileCopyrightText: 2018 Alexis Lopes Zubeta <contact@azubieta.net> 0004 // SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@kde.org> 0005 /* 0006 * UFW KControl Module 0007 */ 0008 0009 #pragma once 0010 0011 #include <QString> 0012 #include <QTimer> 0013 0014 #include <KAuth/Action> 0015 0016 #include <QXmlStreamWriter> 0017 #include <ifirewallclientbackend.h> 0018 #include <profile.h> 0019 0020 class RuleListModel; 0021 class LogListModel; 0022 0023 class Q_DECL_EXPORT UfwClient : public IFirewallClientBackend 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit UfwClient(QObject *parent, const QVariantList &args); 0028 0029 void refresh() override; 0030 RuleListModel *rules() const override; 0031 Rule *ruleAt(int index) override; 0032 KJob *addRule(Rule *r) override; 0033 KJob *removeRule(int index) override; 0034 KJob *updateRule(Rule *r) override; 0035 KJob *moveRule(int from, int to) override; 0036 bool isTcpAndUdp(int protocolIdx) override; 0037 0038 KJob *queryStatus(FirewallClient::DefaultDataBehavior defaultsBehavior, FirewallClient::ProfilesBehavior profilesBehavior) override; 0039 KJob *setDefaultIncomingPolicy(QString defaultIncomingPolicy) override; 0040 KJob *setDefaultOutgoingPolicy(QString defaultOutgoingPolicy) override; 0041 0042 KJob *setEnabled(bool enabled) override; 0043 0044 /* Creates a new Rule and returns it to the Qml side, passing arguments based on the Connection Table. */ 0045 Rule *createRuleFromConnection(const QString &protocol, const QString &localAddress, const QString &foreignAddres, const QString &status) override; 0046 0047 Rule *createRuleFromLog(const QString &protocol, 0048 const QString &sourceAddress, 0049 const QString &sourcePort, 0050 const QString &destinationAddress, 0051 const QString &destinationPort, 0052 const QString &inn) override; 0053 0054 bool enabled() const override; 0055 QString defaultIncomingPolicy() const override; 0056 QString defaultOutgoingPolicy() const override; 0057 QString name() const override; 0058 0059 LogListModel *logs() override; 0060 bool logsAutoRefresh() const override; 0061 void setLogsAutoRefresh(bool logsAutoRefresh) override; 0062 static IFirewallClientBackend *createMethod(FirewallClient *parent); 0063 void refreshProfiles() override; 0064 bool isCurrentlyLoaded() const override; 0065 bool supportsRuleUpdate() const override; 0066 0067 QString version() const override; 0068 QStringList knownApplications() override; 0069 0070 protected slots: 0071 void refreshLogs(); 0072 QStringList knownProtocols() override; 0073 0074 protected: 0075 void setProfile(Profile profile); 0076 void queryKnownApplications(); 0077 KAuth::Action buildQueryAction(const QVariantMap &arguments); 0078 KAuth::Action buildModifyAction(const QVariantMap &arguments); 0079 0080 private: 0081 void enableService(bool value); 0082 QString toXml(Rule *r) const; 0083 QStringList m_rawLogs; 0084 Profile m_currentProfile; 0085 RuleListModel *const m_rulesModel; 0086 LogListModel *m_logs = nullptr; 0087 QTimer m_logsRefreshTimer; 0088 bool m_logsAutoRefresh; 0089 KAuth::Action m_queryAction; 0090 bool m_busy = false; 0091 QStringList m_knownApplications; 0092 };