File indexing completed on 2024-07-21 13:11:44

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
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 #include "kcm.h"
0010 
0011 #include <KAboutData>
0012 #include <KJob>
0013 #include <KLocalizedString>
0014 #include <KPluginFactory>
0015 
0016 #include "core/ipvalidator.h"
0017 #include "core/loglistmodel.h"
0018 #include "core/rulelistmodel.h"
0019 #include "version.h"
0020 
0021 #include "backends/netstat/conectionsmodel.h"
0022 #include "backends/netstat/netstatclient.h"
0023 
0024 K_PLUGIN_FACTORY_WITH_JSON(KCMFirewallFactory, "kcm_firewall.json", registerPlugin<KCMFirewall>();)
0025 
0026 KCMFirewall::KCMFirewall(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
0027     : KQuickAddons::ConfigModule(parent, metaData, args)
0028     , m_client(new FirewallClient(this))
0029 {
0030     qmlRegisterAnonymousType<KJob>("org.kcm.firewall", 1);
0031     qmlRegisterType<RuleListModel>("org.kcm.firewall", 1, 0, "RuleListModel");
0032     qmlRegisterType<Rule>("org.kcm.firewall", 1, 0, "Rule");
0033     qmlRegisterUncreatableType<FirewallClient>("org.kcm.firewall", 1, 0, "FirewallClient", "FirewallClient is created by the KCM.");
0034     qmlRegisterUncreatableType<LogListModel>("org.kcm.firewall", 1, 0, "LogListModel", "Only created from the UfwClient.");
0035     qmlRegisterType<NetstatClient>("org.kcm.firewall", 1, 0, "NetstatClient");
0036     qmlRegisterUncreatableType<ConnectionsModel>("org.kcm.firewall", 1, 0, "ConnectionsModel", "Use the NetstatClient");
0037     qmlRegisterType<IPValidator>("org.kcm.firewall", 1, 0, "IPValidator");
0038 
0039     // TODO: Make this configurable.
0040     m_client->setBackend({"ufw", "firewalld"});
0041 
0042     if (m_client->capabilities() & FirewallClient::SaveCapability) {
0043         setButtons(Help | Apply);
0044     } else {
0045         setButtons(Help);
0046     }
0047 }
0048 
0049 KCMFirewall::~KCMFirewall()
0050 {
0051 }
0052 
0053 void KCMFirewall::save()
0054 {
0055     m_client->save();
0056 }
0057 
0058 FirewallClient *KCMFirewall::client() const
0059 {
0060     return m_client;
0061 }
0062 
0063 #include "kcm.moc"