File indexing completed on 2024-04-28 16:52:16
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 /* 0007 * UFW KControl Module 0008 */ 0009 0010 #ifndef IFIREWALLCLIENTBACKEND_H 0011 #define IFIREWALLCLIENTBACKEND_H 0012 0013 #include "appprofiles.h" 0014 #include "firewallclient.h" 0015 0016 #include <QString> 0017 #include <QVector> 0018 0019 class KJob; 0020 class LogListModel; 0021 class Rule; 0022 class RuleListModel; 0023 class FirewallClient; 0024 0025 class Q_DECL_EXPORT IFirewallClientBackend : public QObject 0026 { 0027 Q_OBJECT 0028 public: 0029 IFirewallClientBackend(QObject *parent, const QVariantList &args); 0030 ~IFirewallClientBackend() = default; 0031 0032 virtual QString name() const = 0; 0033 virtual void refresh() = 0; 0034 virtual RuleListModel *rules() const = 0; 0035 virtual bool isTcpAndUdp(int protocolIdx) = 0; 0036 virtual Rule *ruleAt(int index) = 0; 0037 0038 Q_INVOKABLE virtual KJob *addRule(Rule *rule) = 0; 0039 Q_INVOKABLE virtual KJob *removeRule(int index) = 0; 0040 Q_INVOKABLE virtual KJob *updateRule(Rule *rule) = 0; 0041 Q_INVOKABLE virtual KJob *moveRule(int from, int to) = 0; 0042 0043 Q_INVOKABLE virtual KJob *setEnabled(bool enabled) = 0; 0044 Q_INVOKABLE virtual KJob *queryStatus(FirewallClient::DefaultDataBehavior defaultsBehavior, FirewallClient::ProfilesBehavior profilesBehavior) = 0; 0045 Q_INVOKABLE virtual KJob *setDefaultIncomingPolicy(QString defaultIncomingPolicy) = 0; 0046 Q_INVOKABLE virtual KJob *setDefaultOutgoingPolicy(QString defaultOutgoingPolicy) = 0; 0047 Q_INVOKABLE virtual KJob *save(); 0048 0049 Q_INVOKABLE virtual bool supportsRuleUpdate() const = 0; 0050 0051 /* returns the --version of the software 0052 * the base runs `firewallbackend --help` 0053 * firewalld does not have --help. :| 0054 */ 0055 virtual QString version() const = 0; 0056 0057 virtual void setLogsAutoRefresh(bool logsAutoRefresh) = 0; 0058 0059 /* Creates a new Rule and returns it to the Qml side, passing arguments based on the Connection Table. */ 0060 virtual Rule *createRuleFromConnection(const QString &protocol, const QString &localAddress, const QString &foreignAddres, const QString &status) = 0; 0061 0062 virtual Rule *createRuleFromLog(const QString &protocol, 0063 const QString &sourceAddress, 0064 const QString &sourcePort, 0065 const QString &destinationAddress, 0066 const QString &destinationPort, 0067 const QString &inn) = 0; 0068 0069 virtual bool enabled() const = 0; 0070 virtual QString defaultIncomingPolicy() const = 0; 0071 virtual QString defaultOutgoingPolicy() const = 0; 0072 virtual LogListModel *logs() = 0; 0073 0074 /* TODO: Move it away from here. This asks the 0075 * Logs model to refresh after a few seconds 0076 */ 0077 virtual bool logsAutoRefresh() const = 0; 0078 0079 /* Returns true if the firewall represented 0080 * by this backend is running right now */ 0081 virtual bool isCurrentlyLoaded() const = 0; 0082 0083 virtual void refreshProfiles() = 0; 0084 virtual FirewallClient::Capabilities capabilities() const; 0085 virtual QStringList knownProtocols() = 0; 0086 virtual QStringList knownApplications() = 0; 0087 0088 void setProfiles(const QVector<Entry> &profiles); 0089 QVector<Entry> profiles(); 0090 Entry profileByName(const QString &profileName); 0091 0092 void queryExecutable(const QString &executableName); 0093 bool hasExecutable() const; 0094 QString executablePath() const; 0095 Q_SIGNALS: 0096 void enabledChanged(bool enabled); 0097 void defaultIncomingPolicyChanged(const QString &defaultIncomingPolicy); 0098 void defaultOutgoingPolicyChanged(const QString &defaultOutgoingPolicy); 0099 void logsAutoRefreshChanged(bool logsAutoRefresh); 0100 // Is this even used? 0101 void hasExecutableChanged(bool changed); 0102 0103 // TODO is this needed? 0104 void showErrorMessage(const QString &message); 0105 0106 private: 0107 QVector<Entry> m_profiles; 0108 QString m_executablePath; 0109 }; 0110 0111 #endif