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 #ifndef UFW_PROFILE_H 0007 #define UFW_PROFILE_H 0008 0009 /* 0010 * UFW KControl Module 0011 */ 0012 0013 #include <kcm_firewall_core_export.h> 0014 0015 #include <QByteArray> 0016 #include <QList> 0017 #include <QSet> 0018 0019 #include "rule.h" 0020 #include "types.h" 0021 0022 class QFile; 0023 class QIODevice; 0024 0025 class KCM_FIREWALL_CORE_EXPORT Profile 0026 { 0027 public: 0028 enum Fields { FIELD_RULES = 0x01, FIELD_DEFAULTS = 0x02, FIELD_MODULES = 0x04, FIELD_STATUS = 0x08 }; 0029 0030 explicit Profile(QByteArray &xml, bool isSys = false); 0031 explicit Profile(QFile &file, bool isSys = false); 0032 0033 Profile() 0034 : m_fields(0) 0035 , m_enabled(false) 0036 , m_ipv6Enabled(false) 0037 , m_logLevel(Types::LOG_OFF) 0038 , m_defaultIncomingPolicy(Types::POLICY_ALLOW) 0039 , m_defaultOutgoingPolicy(Types::POLICY_ALLOW) 0040 , m_rules({}) 0041 , m_modules({}) 0042 , m_isSystem(false) 0043 { 0044 } 0045 0046 Profile(const QVector<Rule *> &rules, const QVariantMap &args, bool isSys = false); 0047 Profile(bool ipv6, Types::LogLevel ll, Types::Policy dip, Types::Policy dop, const QVector<Rule *> &r, const QSet<QString> &m) 0048 : m_fields(0xFF) 0049 , m_enabled(true) 0050 , m_ipv6Enabled(ipv6) 0051 , m_logLevel(ll) 0052 , m_defaultIncomingPolicy(dip) 0053 , m_defaultOutgoingPolicy(dop) 0054 , m_rules(r) 0055 , m_modules(m) 0056 , m_isSystem(false) 0057 { 0058 } 0059 0060 bool operator==(const Profile &o) const 0061 { 0062 return m_ipv6Enabled == o.m_ipv6Enabled && m_logLevel == o.m_logLevel && m_defaultIncomingPolicy == o.m_defaultIncomingPolicy 0063 && m_defaultOutgoingPolicy == o.m_defaultOutgoingPolicy && m_rules == o.m_rules && m_modules == o.m_modules; 0064 } 0065 0066 QString toXml() const; 0067 QString defaultsXml() const; 0068 QString modulesXml() const; 0069 0070 bool hasRules() const 0071 { 0072 return m_fields & FIELD_RULES; 0073 } 0074 bool hasDefaults() const 0075 { 0076 return m_fields & FIELD_DEFAULTS; 0077 } 0078 bool hasModules() const 0079 { 0080 return m_fields & FIELD_MODULES; 0081 } 0082 bool hasStatus() const 0083 { 0084 return m_fields & FIELD_STATUS; 0085 } 0086 0087 int fields() const 0088 { 0089 return m_fields; 0090 } 0091 bool enabled() const 0092 { 0093 return m_enabled; 0094 } 0095 bool ipv6Enabled() const 0096 { 0097 return m_ipv6Enabled; 0098 } 0099 Types::LogLevel logLevel() const 0100 { 0101 return m_logLevel; 0102 } 0103 Types::Policy defaultIncomingPolicy() const 0104 { 0105 return m_defaultIncomingPolicy; 0106 } 0107 Types::Policy defaultOutgoingPolicy() const 0108 { 0109 return m_defaultOutgoingPolicy; 0110 } 0111 const QVector<Rule *> rules() const 0112 { 0113 return m_rules; 0114 } 0115 const QSet<QString> modules() const 0116 { 0117 return m_modules; 0118 } 0119 const QString fileName() const 0120 { 0121 return m_fileName; 0122 } 0123 bool isSystem() const 0124 { 0125 return m_isSystem; 0126 } 0127 0128 void setRules(const QVector<Rule *> &newrules); 0129 void setArgs(const QVariantMap &args); 0130 void setEnabled(bool value); 0131 void setDefaultIncomingPolicy(const QString &policy); 0132 void setDefaultOutgoingPolicy(const QString &policy); 0133 0134 private: 0135 void load(QIODevice *device); 0136 0137 private: 0138 int m_fields; 0139 bool m_enabled, m_ipv6Enabled; 0140 Types::LogLevel m_logLevel; 0141 Types::Policy m_defaultIncomingPolicy, m_defaultOutgoingPolicy; 0142 QVector<Rule *> m_rules; 0143 QSet<QString> m_modules; 0144 QString m_fileName; 0145 bool m_isSystem; 0146 }; 0147 0148 #endif