File indexing completed on 2024-05-12 09:38:25

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