mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:36:09 +00:00
UI: Extract ConfZoneManager from ConfManager
This commit is contained in:
parent
b1fae5aaf7
commit
6e10a8b0af
@ -22,6 +22,7 @@ SOURCES += \
|
||||
conf/appgroup.cpp \
|
||||
conf/confappmanager.cpp \
|
||||
conf/confmanager.cpp \
|
||||
conf/confzonemanager.cpp \
|
||||
conf/firewallconf.cpp \
|
||||
conf/inioptions.cpp \
|
||||
conf/rules/policy.cpp \
|
||||
@ -136,6 +137,7 @@ SOURCES += \
|
||||
rpc/askpendingmanagerrpc.cpp \
|
||||
rpc/confappmanagerrpc.cpp \
|
||||
rpc/confmanagerrpc.cpp \
|
||||
rpc/confzonemanagerrpc.cpp \
|
||||
rpc/drivermanagerrpc.cpp \
|
||||
rpc/logmanagerrpc.cpp \
|
||||
rpc/quotamanagerrpc.cpp \
|
||||
@ -220,6 +222,7 @@ HEADERS += \
|
||||
conf/appgroup.h \
|
||||
conf/confappmanager.h \
|
||||
conf/confmanager.h \
|
||||
conf/confzonemanager.h \
|
||||
conf/firewallconf.h \
|
||||
conf/inioptions.h \
|
||||
conf/rules/policy.h \
|
||||
@ -336,6 +339,7 @@ HEADERS += \
|
||||
rpc/askpendingmanagerrpc.h \
|
||||
rpc/confappmanagerrpc.h \
|
||||
rpc/confmanagerrpc.h \
|
||||
rpc/confzonemanagerrpc.h \
|
||||
rpc/drivermanagerrpc.h \
|
||||
rpc/logmanagerrpc.h \
|
||||
rpc/quotamanagerrpc.h \
|
||||
|
@ -13,8 +13,6 @@
|
||||
class App;
|
||||
class ConfManager;
|
||||
class FirewallConf;
|
||||
class IniOptions;
|
||||
class IniUser;
|
||||
class LogEntryBlocked;
|
||||
|
||||
class ConfAppManager : public QObject, public ConfAppsWalker, public IocService
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <appinfo/appinfocache.h>
|
||||
#include <appinfo/appinfoutil.h>
|
||||
#include <conf/zone.h>
|
||||
#include <driver/drivermanager.h>
|
||||
#include <fortsettings.h>
|
||||
#include <log/logmanager.h>
|
||||
@ -109,38 +108,6 @@ const char *const sqlUpdateTask = "UPDATE task"
|
||||
" last_run = ?5, last_success = ?6, data = ?7"
|
||||
" WHERE task_id = ?1;";
|
||||
|
||||
const char *const sqlInsertZone = "INSERT INTO zone(zone_id, name, enabled, custom_url,"
|
||||
" source_code, url, form_data, text_inline)"
|
||||
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);";
|
||||
|
||||
const char *const sqlSelectZoneIds = "SELECT zone_id FROM zone ORDER BY zone_id;";
|
||||
|
||||
const char *const sqlDeleteZone = "DELETE FROM zone WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlDeleteAddressGroupZone = "UPDATE address_group"
|
||||
" SET include_zones = include_zones & ?1,"
|
||||
" exclude_zones = exclude_zones & ?1;";
|
||||
|
||||
const char *const sqlDeleteAppZone = "UPDATE app"
|
||||
" SET accept_zones = accept_zones & ?1,"
|
||||
" reject_zones = reject_zones & ?1;";
|
||||
|
||||
const char *const sqlUpdateZone = "UPDATE zone"
|
||||
" SET name = ?2, enabled = ?3, custom_url = ?4,"
|
||||
" source_code = ?5, url = ?6,"
|
||||
" form_data = ?7, text_inline = ?8"
|
||||
" WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneName = "UPDATE zone SET name = ?2 WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneResult =
|
||||
"UPDATE zone"
|
||||
" SET address_count = ?2, text_checksum = ?3, bin_checksum = ?4,"
|
||||
" source_modtime = ?5, last_run = ?6, last_success = ?7"
|
||||
" WHERE zone_id = ?1;";
|
||||
|
||||
using AppsMap = QHash<qint64, QString>;
|
||||
using AppIdsArray = QVector<qint64>;
|
||||
|
||||
@ -770,149 +737,6 @@ bool ConfManager::importBackup(const QString &path)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfManager::addZone(Zone &zone)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
zone.zoneId = getFreeZoneId();
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode
|
||||
<< zone.url << zone.formData << zone.textInline;
|
||||
|
||||
sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneAdded();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
int ConfManager::getFreeZoneId()
|
||||
{
|
||||
int zoneId = 1;
|
||||
|
||||
SqliteStmt stmt;
|
||||
if (stmt.prepare(sqliteDb()->db(), sqlSelectZoneIds)) {
|
||||
while (stmt.step() == SqliteStmt::StepRow) {
|
||||
const int id = stmt.columnInt(0);
|
||||
if (id > zoneId)
|
||||
break;
|
||||
|
||||
zoneId = id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
bool ConfManager::deleteZone(int zoneId)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
beginTransaction();
|
||||
|
||||
sqliteDb()->executeEx(sqlDeleteZone, { zoneId }, 0, &ok);
|
||||
if (ok) {
|
||||
const quint32 zoneUnMask = ~(quint32(1) << (zoneId - 1));
|
||||
|
||||
// Delete the Zone from Address Groups
|
||||
sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok);
|
||||
|
||||
// Delete the Zone from Programs
|
||||
sqliteDb()->executeEx(sqlDeleteAppZone, { qint64(zoneUnMask) }, 0, &ok);
|
||||
}
|
||||
|
||||
commitTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneRemoved(zoneId);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZone(const Zone &zone)
|
||||
{
|
||||
if (!updateDriverZoneFlag(zone.zoneId, zone.enabled))
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode
|
||||
<< zone.url << zone.formData << zone.textInline;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneName(int zoneId, const QString &zoneName)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList() << zoneId << zoneName;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneEnabled(int zoneId, bool enabled)
|
||||
{
|
||||
if (!updateDriverZoneFlag(zoneId, enabled))
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList() << zoneId << enabled;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneResult(const Zone &zone)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.addressCount << zone.textChecksum << zone.binChecksum
|
||||
<< zone.sourceModTime << zone.lastRun << zone.lastSuccess;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::checkPassword(const QString &password)
|
||||
{
|
||||
return IoC<FortSettings>()->checkPassword(password);
|
||||
@ -974,27 +798,6 @@ void ConfManager::updateDriverServices(
|
||||
driverManager->writeServices(buf, outSize);
|
||||
}
|
||||
|
||||
void ConfManager::updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData)
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
QByteArray buf;
|
||||
|
||||
const int entrySize = confUtil.writeZones(zonesMask, enabledMask, dataSize, zonesData, buf);
|
||||
|
||||
driverWriteZones(confUtil, buf, entrySize);
|
||||
}
|
||||
|
||||
bool ConfManager::updateDriverZoneFlag(int zoneId, bool enabled)
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
QByteArray buf;
|
||||
|
||||
const int entrySize = confUtil.writeZoneFlag(zoneId, enabled, buf);
|
||||
|
||||
return driverWriteZones(confUtil, buf, entrySize, /*onlyFlags=*/true);
|
||||
}
|
||||
|
||||
bool ConfManager::loadFromDb(FirewallConf &conf, bool &isNew)
|
||||
{
|
||||
// Load Address Groups
|
||||
|
@ -13,7 +13,6 @@ class FirewallConf;
|
||||
class IniOptions;
|
||||
class IniUser;
|
||||
class TaskInfo;
|
||||
class Zone;
|
||||
|
||||
class ConfManager : public QObject, public IocService
|
||||
{
|
||||
@ -59,14 +58,6 @@ public:
|
||||
virtual bool exportBackup(const QString &path);
|
||||
virtual bool importBackup(const QString &path);
|
||||
|
||||
virtual bool addZone(Zone &zone);
|
||||
int getFreeZoneId();
|
||||
virtual bool deleteZone(int zoneId);
|
||||
virtual bool updateZone(const Zone &zone);
|
||||
virtual bool updateZoneName(int zoneId, const QString &zoneName);
|
||||
virtual bool updateZoneEnabled(int zoneId, bool enabled);
|
||||
bool updateZoneResult(const Zone &zone);
|
||||
|
||||
virtual bool checkPassword(const QString &password);
|
||||
|
||||
bool validateDriver();
|
||||
@ -74,18 +65,11 @@ public:
|
||||
void updateServices();
|
||||
void updateDriverServices(const QVector<ServiceInfo> &services, int runningServicesCount);
|
||||
|
||||
void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData);
|
||||
|
||||
signals:
|
||||
void confChanged(bool onlyFlags);
|
||||
void iniChanged(const IniOptions &ini);
|
||||
void iniUserChanged(const IniUser &ini, bool onlyFlags);
|
||||
|
||||
void zoneAdded();
|
||||
void zoneRemoved(int zoneId);
|
||||
void zoneUpdated();
|
||||
|
||||
protected:
|
||||
void setConf(FirewallConf *newConf);
|
||||
FirewallConf *createConf();
|
||||
@ -95,8 +79,6 @@ private:
|
||||
|
||||
bool validateConf(const FirewallConf &newConf);
|
||||
|
||||
bool updateDriverZoneFlag(int zoneId, bool enabled);
|
||||
|
||||
bool loadFromDb(FirewallConf &conf, bool &isNew);
|
||||
bool saveToDb(const FirewallConf &conf);
|
||||
|
||||
|
276
src/ui/conf/confzonemanager.cpp
Normal file
276
src/ui/conf/confzonemanager.cpp
Normal file
@ -0,0 +1,276 @@
|
||||
#include "confzonemanager.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
#include <conf/zone.h>
|
||||
#include <driver/drivermanager.h>
|
||||
#include <manager/windowmanager.h>
|
||||
#include <util/conf/confutil.h>
|
||||
#include <util/ioc/ioccontainer.h>
|
||||
|
||||
#include "confmanager.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const QLoggingCategory LC("confZone");
|
||||
|
||||
const char *const sqlInsertZone = "INSERT INTO zone(zone_id, name, enabled, custom_url,"
|
||||
" source_code, url, form_data, text_inline)"
|
||||
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);";
|
||||
|
||||
const char *const sqlSelectZoneIds = "SELECT zone_id FROM zone ORDER BY zone_id;";
|
||||
|
||||
const char *const sqlDeleteZone = "DELETE FROM zone WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlDeleteAddressGroupZone = "UPDATE address_group"
|
||||
" SET include_zones = include_zones & ?1,"
|
||||
" exclude_zones = exclude_zones & ?1;";
|
||||
|
||||
const char *const sqlDeleteAppZone = "UPDATE app"
|
||||
" SET accept_zones = accept_zones & ?1,"
|
||||
" reject_zones = reject_zones & ?1;";
|
||||
|
||||
const char *const sqlUpdateZone = "UPDATE zone"
|
||||
" SET name = ?2, enabled = ?3, custom_url = ?4,"
|
||||
" source_code = ?5, url = ?6,"
|
||||
" form_data = ?7, text_inline = ?8"
|
||||
" WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneName = "UPDATE zone SET name = ?2 WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneResult =
|
||||
"UPDATE zone"
|
||||
" SET address_count = ?2, text_checksum = ?3, bin_checksum = ?4,"
|
||||
" source_modtime = ?5, last_run = ?6, last_success = ?7"
|
||||
" WHERE zone_id = ?1;";
|
||||
|
||||
void showErrorMessage(const QString &errorMessage)
|
||||
{
|
||||
IoC<WindowManager>()->showErrorBox(
|
||||
errorMessage, ConfZoneManager::tr("Zone Configuration Error"));
|
||||
}
|
||||
|
||||
bool driverWriteZones(ConfUtil &confUtil, QByteArray &buf, int entrySize, bool onlyFlags = false)
|
||||
{
|
||||
if (entrySize == 0) {
|
||||
showErrorMessage(confUtil.errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto driverManager = IoC<DriverManager>();
|
||||
if (!driverManager->writeZones(buf, entrySize, onlyFlags)) {
|
||||
showErrorMessage(driverManager->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ConfZoneManager::ConfZoneManager(QObject *parent) : QObject(parent) { }
|
||||
|
||||
ConfManager *ConfZoneManager::confManager() const
|
||||
{
|
||||
return m_confManager;
|
||||
}
|
||||
|
||||
SqliteDb *ConfZoneManager::sqliteDb() const
|
||||
{
|
||||
return confManager()->sqliteDb();
|
||||
}
|
||||
|
||||
void ConfZoneManager::setUp()
|
||||
{
|
||||
m_confManager = IoC()->setUpDependency<ConfManager>();
|
||||
}
|
||||
|
||||
bool ConfZoneManager::addZone(Zone &zone)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
zone.zoneId = getFreeZoneId();
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode
|
||||
<< zone.url << zone.formData << zone.textInline;
|
||||
|
||||
sqliteDb()->executeEx(sqlInsertZone, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneAdded();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
int ConfZoneManager::getFreeZoneId()
|
||||
{
|
||||
int zoneId = 1;
|
||||
|
||||
SqliteStmt stmt;
|
||||
if (stmt.prepare(sqliteDb()->db(), sqlSelectZoneIds)) {
|
||||
while (stmt.step() == SqliteStmt::StepRow) {
|
||||
const int id = stmt.columnInt(0);
|
||||
if (id > zoneId)
|
||||
break;
|
||||
|
||||
zoneId = id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
bool ConfZoneManager::deleteZone(int zoneId)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
beginTransaction();
|
||||
|
||||
sqliteDb()->executeEx(sqlDeleteZone, { zoneId }, 0, &ok);
|
||||
if (ok) {
|
||||
const quint32 zoneUnMask = ~(quint32(1) << (zoneId - 1));
|
||||
|
||||
// Delete the Zone from Address Groups
|
||||
sqliteDb()->executeEx(sqlDeleteAddressGroupZone, { qint64(zoneUnMask) }, 0, &ok);
|
||||
|
||||
// Delete the Zone from Programs
|
||||
sqliteDb()->executeEx(sqlDeleteAppZone, { qint64(zoneUnMask) }, 0, &ok);
|
||||
}
|
||||
|
||||
commitTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneRemoved(zoneId);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfZoneManager::updateZone(const Zone &zone)
|
||||
{
|
||||
if (!updateDriverZoneFlag(zone.zoneId, zone.enabled))
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.zoneName << zone.enabled << zone.customUrl << zone.sourceCode
|
||||
<< zone.url << zone.formData << zone.textInline;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZone, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfZoneManager::updateZoneName(int zoneId, const QString &zoneName)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList() << zoneId << zoneName;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneName, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfZoneManager::updateZoneEnabled(int zoneId, bool enabled)
|
||||
{
|
||||
if (!updateDriverZoneFlag(zoneId, enabled))
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList() << zoneId << enabled;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfZoneManager::updateZoneResult(const Zone &zone)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zone.zoneId << zone.addressCount << zone.textChecksum << zone.binChecksum
|
||||
<< zone.sourceModTime << zone.lastRun << zone.lastSuccess;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
||||
|
||||
checkEndTransaction(ok);
|
||||
|
||||
if (ok) {
|
||||
emit zoneUpdated();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void ConfZoneManager::updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData)
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
QByteArray buf;
|
||||
|
||||
const int entrySize = confUtil.writeZones(zonesMask, enabledMask, dataSize, zonesData, buf);
|
||||
|
||||
driverWriteZones(confUtil, buf, entrySize);
|
||||
}
|
||||
|
||||
bool ConfZoneManager::updateDriverZoneFlag(int zoneId, bool enabled)
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
QByteArray buf;
|
||||
|
||||
const int entrySize = confUtil.writeZoneFlag(zoneId, enabled, buf);
|
||||
|
||||
return driverWriteZones(confUtil, buf, entrySize, /*onlyFlags=*/true);
|
||||
}
|
||||
|
||||
bool ConfZoneManager::beginTransaction()
|
||||
{
|
||||
return sqliteDb()->beginTransaction();
|
||||
}
|
||||
|
||||
bool ConfZoneManager::commitTransaction(bool ok)
|
||||
{
|
||||
ok = sqliteDb()->endTransaction(ok);
|
||||
|
||||
return checkEndTransaction(ok);
|
||||
}
|
||||
|
||||
bool ConfZoneManager::checkEndTransaction(bool ok)
|
||||
{
|
||||
if (!ok) {
|
||||
showErrorMessage(sqliteDb()->errorMessage());
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
55
src/ui/conf/confzonemanager.h
Normal file
55
src/ui/conf/confzonemanager.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef CONFZONEMANAGER_H
|
||||
#define CONFZONEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <sqlite/sqlitetypes.h>
|
||||
|
||||
#include <util/classhelpers.h>
|
||||
#include <util/ioc/iocservice.h>
|
||||
#include <util/service/serviceinfo.h>
|
||||
|
||||
class ConfManager;
|
||||
class Zone;
|
||||
|
||||
class ConfZoneManager : public QObject, public IocService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfZoneManager(QObject *parent = nullptr);
|
||||
CLASS_DELETE_COPY_MOVE(ConfZoneManager)
|
||||
|
||||
ConfManager *confManager() const;
|
||||
SqliteDb *sqliteDb() const;
|
||||
|
||||
void setUp() override;
|
||||
|
||||
virtual bool addZone(Zone &zone);
|
||||
int getFreeZoneId();
|
||||
virtual bool deleteZone(int zoneId);
|
||||
virtual bool updateZone(const Zone &zone);
|
||||
virtual bool updateZoneName(int zoneId, const QString &zoneName);
|
||||
virtual bool updateZoneEnabled(int zoneId, bool enabled);
|
||||
bool updateZoneResult(const Zone &zone);
|
||||
|
||||
void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData);
|
||||
|
||||
signals:
|
||||
void zoneAdded();
|
||||
void zoneRemoved(int zoneId);
|
||||
void zoneUpdated();
|
||||
|
||||
private:
|
||||
bool updateDriverZoneFlag(int zoneId, bool enabled);
|
||||
|
||||
bool beginTransaction();
|
||||
bool commitTransaction(bool ok);
|
||||
bool checkEndTransaction(bool ok);
|
||||
|
||||
private:
|
||||
ConfManager *m_confManager = nullptr;
|
||||
};
|
||||
|
||||
#endif // CONFZONEMANAGER_H
|
@ -23,16 +23,17 @@ const char *const commandString(Command cmd)
|
||||
CASE_STRING(Rpc_ConfManager_saveVariant)
|
||||
CASE_STRING(Rpc_ConfManager_exportBackup)
|
||||
CASE_STRING(Rpc_ConfManager_importBackup)
|
||||
CASE_STRING(Rpc_ConfManager_addZone)
|
||||
CASE_STRING(Rpc_ConfManager_deleteZone)
|
||||
CASE_STRING(Rpc_ConfManager_updateZone)
|
||||
CASE_STRING(Rpc_ConfManager_updateZoneName)
|
||||
CASE_STRING(Rpc_ConfManager_updateZoneEnabled)
|
||||
CASE_STRING(Rpc_ConfManager_checkPassword)
|
||||
CASE_STRING(Rpc_ConfManager_confChanged)
|
||||
CASE_STRING(Rpc_ConfManager_zoneAdded)
|
||||
CASE_STRING(Rpc_ConfManager_zoneRemoved)
|
||||
CASE_STRING(Rpc_ConfManager_zoneUpdated)
|
||||
|
||||
CASE_STRING(Rpc_ConfZoneManager_addZone)
|
||||
CASE_STRING(Rpc_ConfZoneManager_deleteZone)
|
||||
CASE_STRING(Rpc_ConfZoneManager_updateZone)
|
||||
CASE_STRING(Rpc_ConfZoneManager_updateZoneName)
|
||||
CASE_STRING(Rpc_ConfZoneManager_updateZoneEnabled)
|
||||
CASE_STRING(Rpc_ConfZoneManager_zoneAdded)
|
||||
CASE_STRING(Rpc_ConfZoneManager_zoneRemoved)
|
||||
CASE_STRING(Rpc_ConfZoneManager_zoneUpdated)
|
||||
|
||||
CASE_STRING(Rpc_ConfAppManager_addApp)
|
||||
CASE_STRING(Rpc_ConfAppManager_deleteApps)
|
||||
@ -82,6 +83,7 @@ const char *const rpcManagerString(RpcManager rpcManager)
|
||||
CASE_STRING(Rpc_AppInfoManager)
|
||||
CASE_STRING(Rpc_ConfManager)
|
||||
CASE_STRING(Rpc_ConfAppManager)
|
||||
CASE_STRING(Rpc_ConfZoneManager)
|
||||
CASE_STRING(Rpc_DriverManager)
|
||||
CASE_STRING(Rpc_QuotaManager)
|
||||
CASE_STRING(Rpc_StatManager)
|
||||
@ -111,16 +113,17 @@ RpcManager managerByCommand(Command cmd)
|
||||
Rpc_ConfManager, // Rpc_ConfManager_saveVariant,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_exportBackup,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_importBackup,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_addZone,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_deleteZone,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_updateZone,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_updateZoneName,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_updateZoneEnabled,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_checkPassword,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_confChanged,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_zoneAdded,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_zoneRemoved,
|
||||
Rpc_ConfManager, // Rpc_ConfManager_zoneUpdated,
|
||||
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_addZone,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_deleteZone,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZone,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZoneName,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_updateZoneEnabled,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneAdded,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneRemoved,
|
||||
Rpc_ConfZoneManager, // Rpc_ConfZoneManager_zoneUpdated,
|
||||
|
||||
Rpc_ConfAppManager, // Rpc_ConfAppManager_addApp,
|
||||
Rpc_ConfAppManager, // Rpc_ConfAppManager_deleteApps,
|
||||
@ -181,16 +184,17 @@ bool commandRequiresValidation(Command cmd)
|
||||
true, // Rpc_ConfManager_saveVariant,
|
||||
true, // Rpc_ConfManager_exportBackup,
|
||||
true, // Rpc_ConfManager_importBackup,
|
||||
true, // Rpc_ConfManager_addZone,
|
||||
true, // Rpc_ConfManager_deleteZone,
|
||||
true, // Rpc_ConfManager_updateZone,
|
||||
true, // Rpc_ConfManager_updateZoneName,
|
||||
true, // Rpc_ConfManager_updateZoneEnabled,
|
||||
0, // Rpc_ConfManager_checkPassword,
|
||||
0, // Rpc_ConfManager_confChanged,
|
||||
0, // Rpc_ConfManager_zoneAdded,
|
||||
0, // Rpc_ConfManager_zoneRemoved,
|
||||
0, // Rpc_ConfManager_zoneUpdated,
|
||||
|
||||
true, // Rpc_ConfZoneManager_addZone,
|
||||
true, // Rpc_ConfZoneManager_deleteZone,
|
||||
true, // Rpc_ConfZoneManager_updateZone,
|
||||
true, // Rpc_ConfZoneManager_updateZoneName,
|
||||
true, // Rpc_ConfZoneManager_updateZoneEnabled,
|
||||
0, // Rpc_ConfZoneManager_zoneAdded,
|
||||
0, // Rpc_ConfZoneManager_zoneRemoved,
|
||||
0, // Rpc_ConfZoneManager_zoneUpdated,
|
||||
|
||||
true, // Rpc_ConfAppManager_addApp,
|
||||
true, // Rpc_ConfAppManager_deleteApps,
|
||||
|
@ -22,16 +22,17 @@ enum Command : qint8 {
|
||||
Rpc_ConfManager_saveVariant,
|
||||
Rpc_ConfManager_exportBackup,
|
||||
Rpc_ConfManager_importBackup,
|
||||
Rpc_ConfManager_addZone,
|
||||
Rpc_ConfManager_deleteZone,
|
||||
Rpc_ConfManager_updateZone,
|
||||
Rpc_ConfManager_updateZoneName,
|
||||
Rpc_ConfManager_updateZoneEnabled,
|
||||
Rpc_ConfManager_checkPassword,
|
||||
Rpc_ConfManager_confChanged,
|
||||
Rpc_ConfManager_zoneAdded,
|
||||
Rpc_ConfManager_zoneRemoved,
|
||||
Rpc_ConfManager_zoneUpdated,
|
||||
|
||||
Rpc_ConfZoneManager_addZone,
|
||||
Rpc_ConfZoneManager_deleteZone,
|
||||
Rpc_ConfZoneManager_updateZone,
|
||||
Rpc_ConfZoneManager_updateZoneName,
|
||||
Rpc_ConfZoneManager_updateZoneEnabled,
|
||||
Rpc_ConfZoneManager_zoneAdded,
|
||||
Rpc_ConfZoneManager_zoneRemoved,
|
||||
Rpc_ConfZoneManager_zoneUpdated,
|
||||
|
||||
Rpc_ConfAppManager_addApp,
|
||||
Rpc_ConfAppManager_deleteApps,
|
||||
@ -76,6 +77,7 @@ enum RpcManager : qint8 {
|
||||
Rpc_AppInfoManager,
|
||||
Rpc_ConfManager,
|
||||
Rpc_ConfAppManager,
|
||||
Rpc_ConfZoneManager,
|
||||
Rpc_DriverManager,
|
||||
Rpc_QuotaManager,
|
||||
Rpc_StatManager,
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <conf/confappmanager.h>
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/confzonemanager.h>
|
||||
#include <conf/firewallconf.h>
|
||||
#include <driver/drivermanager.h>
|
||||
#include <fortmanager.h>
|
||||
@ -41,6 +42,11 @@ ConfAppManager *BaseController::confAppManager() const
|
||||
return IoC<ConfAppManager>();
|
||||
}
|
||||
|
||||
ConfZoneManager *BaseController::confZoneManager() const
|
||||
{
|
||||
return IoC<ConfZoneManager>();
|
||||
}
|
||||
|
||||
FirewallConf *BaseController::conf() const
|
||||
{
|
||||
return confManager()->conf();
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
class ConfAppManager;
|
||||
class ConfManager;
|
||||
class ConfZoneManager;
|
||||
class DriverManager;
|
||||
class FirewallConf;
|
||||
class FortManager;
|
||||
@ -27,6 +28,7 @@ public:
|
||||
FortSettings *settings() const;
|
||||
ConfManager *confManager() const;
|
||||
ConfAppManager *confAppManager() const;
|
||||
ConfZoneManager *confZoneManager() const;
|
||||
FirewallConf *conf() const;
|
||||
IniOptions *ini() const;
|
||||
IniUser *iniUser() const;
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QMenu>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/confzonemanager.h>
|
||||
#include <driver/drivercommon.h>
|
||||
#include <form/controls/controlutil.h>
|
||||
#include <model/zonelistmodel.h>
|
||||
@ -107,9 +107,9 @@ void ZonesSelector::setupZones()
|
||||
|
||||
connect(m_menuZones, &QMenu::aboutToShow, this, &ZonesSelector::updateZonesMenu);
|
||||
|
||||
auto confManager = IoC<ConfManager>();
|
||||
auto confZoneManager = IoC<ConfZoneManager>();
|
||||
|
||||
connect(confManager, &ConfManager::zoneRemoved, this, [&](int zoneId) {
|
||||
connect(confZoneManager, &ConfZoneManager::zoneRemoved, this, [&](int zoneId) {
|
||||
removeZone(zoneId);
|
||||
retranslateZonesText();
|
||||
});
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/confzonemanager.h>
|
||||
#include <conf/firewallconf.h>
|
||||
#include <form/controls/controlutil.h>
|
||||
#include <form/controls/plaintextedit.h>
|
||||
@ -64,6 +65,11 @@ ConfManager *ZonesWindow::confManager() const
|
||||
return ctrl()->confManager();
|
||||
}
|
||||
|
||||
ConfZoneManager *ZonesWindow::confZoneManager() const
|
||||
{
|
||||
return ctrl()->confZoneManager();
|
||||
}
|
||||
|
||||
IniOptions *ZonesWindow::ini() const
|
||||
{
|
||||
return ctrl()->ini();
|
||||
@ -562,7 +568,7 @@ bool ZonesWindow::saveZoneEditFormValidate(const Zone &zone, const ZoneSourceWra
|
||||
|
||||
bool ZonesWindow::saveZoneEditFormNew(Zone &zone)
|
||||
{
|
||||
if (confManager()->addZone(zone)) {
|
||||
if (confZoneManager()->addZone(zone)) {
|
||||
m_zoneListView->selectCell(zone.zoneId - 1);
|
||||
return true;
|
||||
}
|
||||
@ -577,14 +583,14 @@ bool ZonesWindow::saveZoneEditFormEdit(Zone &zone)
|
||||
|
||||
if (zone.isOptionsEqual(zoneRow)) {
|
||||
if (!zone.isNameEqual(zoneRow)) {
|
||||
return confManager()->updateZoneName(zoneRow.zoneId, zone.zoneName);
|
||||
return confZoneManager()->updateZoneName(zoneRow.zoneId, zone.zoneName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
zone.zoneId = zoneRow.zoneId;
|
||||
|
||||
return confManager()->updateZone(zone);
|
||||
return confZoneManager()->updateZone(zone);
|
||||
}
|
||||
|
||||
void ZonesWindow::updateZone(int row, bool enabled)
|
||||
@ -596,7 +602,7 @@ void ZonesWindow::updateZone(int row, bool enabled)
|
||||
Zone zone = zoneRow;
|
||||
zone.enabled = enabled;
|
||||
|
||||
confManager()->updateZone(zone);
|
||||
confZoneManager()->updateZone(zone);
|
||||
}
|
||||
|
||||
void ZonesWindow::deleteZone(int row)
|
||||
@ -605,7 +611,7 @@ void ZonesWindow::deleteZone(int row)
|
||||
if (zoneRow.isNull())
|
||||
return;
|
||||
|
||||
confManager()->deleteZone(zoneRow.zoneId);
|
||||
confZoneManager()->deleteZone(zoneRow.zoneId);
|
||||
}
|
||||
|
||||
void ZonesWindow::updateSelectedZone(bool enabled)
|
||||
|
@ -13,6 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||
QT_FORWARD_DECLARE_CLASS(QStackedLayout)
|
||||
|
||||
class ConfManager;
|
||||
class ConfZoneManager;
|
||||
class IniOptions;
|
||||
class IniUser;
|
||||
class PlainTextEdit;
|
||||
@ -36,6 +37,7 @@ public:
|
||||
|
||||
ZonesController *ctrl() const { return m_ctrl; }
|
||||
ConfManager *confManager() const;
|
||||
ConfZoneManager *confZoneManager() const;
|
||||
IniOptions *ini() const;
|
||||
IniUser *iniUser() const;
|
||||
WindowManager *windowManager() const;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <rpc/askpendingmanagerrpc.h>
|
||||
#include <rpc/confappmanagerrpc.h>
|
||||
#include <rpc/confmanagerrpc.h>
|
||||
#include <rpc/confzonemanagerrpc.h>
|
||||
#include <rpc/drivermanagerrpc.h>
|
||||
#include <rpc/logmanagerrpc.h>
|
||||
#include <rpc/quotamanagerrpc.h>
|
||||
@ -138,6 +139,7 @@ void FortManager::createManagers()
|
||||
|
||||
ConfManager *confManager;
|
||||
ConfAppManager *confAppManager;
|
||||
ConfZoneManager *confZoneManager;
|
||||
QuotaManager *quotaManager;
|
||||
StatManager *statManager;
|
||||
StatBlockManager *statBlockManager;
|
||||
@ -155,6 +157,7 @@ void FortManager::createManagers()
|
||||
|
||||
confManager = new ConfManager(settings->confFilePath());
|
||||
confAppManager = new ConfAppManager();
|
||||
confZoneManager = new ConfZoneManager();
|
||||
quotaManager = new QuotaManager();
|
||||
statManager = new StatManager(settings->statFilePath());
|
||||
statBlockManager = new StatBlockManager(settings->statBlockFilePath());
|
||||
@ -170,6 +173,7 @@ void FortManager::createManagers()
|
||||
} else {
|
||||
confManager = new ConfManagerRpc(settings->confFilePath());
|
||||
confAppManager = new ConfAppManagerRpc();
|
||||
confZoneManager = new ConfZoneManagerRpc();
|
||||
quotaManager = new QuotaManagerRpc();
|
||||
statManager = new StatManagerRpc(settings->statFilePath());
|
||||
statBlockManager = new StatBlockManagerRpc(settings->statBlockFilePath());
|
||||
@ -197,6 +201,7 @@ void FortManager::createManagers()
|
||||
|
||||
ioc->setService(confManager);
|
||||
ioc->setService(confAppManager);
|
||||
ioc->setService(confZoneManager);
|
||||
ioc->setService(quotaManager);
|
||||
ioc->setService(statManager);
|
||||
ioc->setService(statBlockManager);
|
||||
@ -374,8 +379,8 @@ void FortManager::setupTaskManager()
|
||||
WindowManager::MessageZones);
|
||||
});
|
||||
|
||||
connect(taskManager, &TaskManager::zonesUpdated, IoC<ConfManager>(),
|
||||
&ConfManager::updateDriverZones);
|
||||
connect(taskManager, &TaskManager::zonesUpdated, IoC<ConfZoneManager>(),
|
||||
&ConfZoneManager::updateDriverZones);
|
||||
|
||||
connect(taskManager, &TaskManager::taskDoubleClicked, this, [&](qint8 taskType) {
|
||||
switch (taskType) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/confzonemanager.h>
|
||||
#include <util/conf/confutil.h>
|
||||
#include <util/fileutil.h>
|
||||
#include <util/ioc/ioccontainer.h>
|
||||
@ -26,6 +27,11 @@ ConfManager *ZoneListModel::confManager() const
|
||||
return IoC<ConfManager>();
|
||||
}
|
||||
|
||||
ConfZoneManager *ZoneListModel::confZoneManager() const
|
||||
{
|
||||
return IoC<ConfZoneManager>();
|
||||
}
|
||||
|
||||
SqliteDb *ZoneListModel::sqliteDb() const
|
||||
{
|
||||
return confManager()->sqliteDb();
|
||||
@ -36,9 +42,9 @@ void ZoneListModel::setUp()
|
||||
setupZoneTypes();
|
||||
setupZoneSources();
|
||||
|
||||
connect(confManager(), &ConfManager::zoneAdded, this, &TableSqlModel::reset);
|
||||
connect(confManager(), &ConfManager::zoneRemoved, this, &ZoneListModel::reset);
|
||||
connect(confManager(), &ConfManager::zoneUpdated, this, &TableSqlModel::refresh);
|
||||
connect(confZoneManager(), &ConfZoneManager::zoneAdded, this, &TableSqlModel::reset);
|
||||
connect(confZoneManager(), &ConfZoneManager::zoneRemoved, this, &ZoneListModel::reset);
|
||||
connect(confZoneManager(), &ConfZoneManager::zoneUpdated, this, &TableSqlModel::refresh);
|
||||
}
|
||||
|
||||
int ZoneListModel::columnCount(const QModelIndex &parent) const
|
||||
@ -135,7 +141,7 @@ bool ZoneListModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||
switch (role) {
|
||||
case Qt::CheckStateRole:
|
||||
const auto zoneRow = zoneRowAt(index.row());
|
||||
return confManager()->updateZoneEnabled(zoneRow.zoneId, !zoneRow.enabled);
|
||||
return confZoneManager()->updateZoneEnabled(zoneRow.zoneId, !zoneRow.enabled);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <util/model/tablesqlmodel.h>
|
||||
|
||||
class ConfManager;
|
||||
class ConfZoneManager;
|
||||
class ZoneSourceWrapper;
|
||||
|
||||
struct ZoneRow : TableRow, public Zone
|
||||
@ -24,6 +25,7 @@ public:
|
||||
explicit ZoneListModel(QObject *parent = nullptr);
|
||||
|
||||
ConfManager *confManager() const;
|
||||
ConfZoneManager *confZoneManager() const;
|
||||
SqliteDb *sqliteDb() const override;
|
||||
|
||||
void setUp() override;
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <sqlite/sqlitedb.h>
|
||||
|
||||
#include <conf/firewallconf.h>
|
||||
#include <conf/zone.h>
|
||||
#include <fortsettings.h>
|
||||
#include <manager/windowmanager.h>
|
||||
#include <rpc/rpcmanager.h>
|
||||
@ -26,45 +25,6 @@ bool ConfManagerRpc::importBackup(const QString &path)
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_importBackup, { path });
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::addZone(Zone &zone)
|
||||
{
|
||||
QVariantList resArgs;
|
||||
|
||||
if (!IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_addZone,
|
||||
{ zone.enabled, zone.customUrl, zone.zoneName, zone.sourceCode, zone.url,
|
||||
zone.formData, zone.textInline },
|
||||
&resArgs))
|
||||
return false;
|
||||
|
||||
zone.zoneId = resArgs.value(0).toInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::deleteZone(int zoneId)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_deleteZone, { zoneId });
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::updateZone(const Zone &zone)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_updateZone,
|
||||
{ zone.enabled, zone.customUrl, zone.zoneId, zone.zoneName, zone.sourceCode, zone.url,
|
||||
zone.formData, zone.textInline });
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::updateZoneName(int zoneId, const QString &zoneName)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(
|
||||
Control::Rpc_ConfManager_updateZoneName, { zoneId, zoneName });
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::updateZoneEnabled(int zoneId, bool enabled)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(
|
||||
Control::Rpc_ConfManager_updateZoneEnabled, { zoneId, enabled });
|
||||
}
|
||||
|
||||
bool ConfManagerRpc::checkPassword(const QString &password)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_checkPassword, { password });
|
||||
|
@ -16,12 +16,6 @@ public:
|
||||
bool exportBackup(const QString &path) override;
|
||||
bool importBackup(const QString &path) override;
|
||||
|
||||
bool addZone(Zone &zone) override;
|
||||
bool deleteZone(int zoneId) override;
|
||||
bool updateZone(const Zone &zone) override;
|
||||
bool updateZoneName(int zoneId, const QString &zoneName) override;
|
||||
bool updateZoneEnabled(int zoneId, bool enabled) override;
|
||||
|
||||
bool checkPassword(const QString &password) override;
|
||||
|
||||
void onConfChanged(const QVariant &confVar);
|
||||
|
48
src/ui/rpc/confzonemanagerrpc.cpp
Normal file
48
src/ui/rpc/confzonemanagerrpc.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "confzonemanagerrpc.h"
|
||||
|
||||
#include <sqlite/sqlitedb.h>
|
||||
|
||||
#include <conf/zone.h>
|
||||
#include <rpc/rpcmanager.h>
|
||||
#include <util/ioc/ioccontainer.h>
|
||||
|
||||
ConfZoneManagerRpc::ConfZoneManagerRpc(QObject *parent) : ConfZoneManager(parent) { }
|
||||
|
||||
bool ConfZoneManagerRpc::addZone(Zone &zone)
|
||||
{
|
||||
QVariantList resArgs;
|
||||
|
||||
if (!IoC<RpcManager>()->doOnServer(Control::Rpc_ConfZoneManager_addZone,
|
||||
{ zone.enabled, zone.customUrl, zone.zoneName, zone.sourceCode, zone.url,
|
||||
zone.formData, zone.textInline },
|
||||
&resArgs))
|
||||
return false;
|
||||
|
||||
zone.zoneId = resArgs.value(0).toInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfZoneManagerRpc::deleteZone(int zoneId)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfZoneManager_deleteZone, { zoneId });
|
||||
}
|
||||
|
||||
bool ConfZoneManagerRpc::updateZone(const Zone &zone)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfZoneManager_updateZone,
|
||||
{ zone.enabled, zone.customUrl, zone.zoneId, zone.zoneName, zone.sourceCode, zone.url,
|
||||
zone.formData, zone.textInline });
|
||||
}
|
||||
|
||||
bool ConfZoneManagerRpc::updateZoneName(int zoneId, const QString &zoneName)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(
|
||||
Control::Rpc_ConfZoneManager_updateZoneName, { zoneId, zoneName });
|
||||
}
|
||||
|
||||
bool ConfZoneManagerRpc::updateZoneEnabled(int zoneId, bool enabled)
|
||||
{
|
||||
return IoC<RpcManager>()->doOnServer(
|
||||
Control::Rpc_ConfZoneManager_updateZoneEnabled, { zoneId, enabled });
|
||||
}
|
22
src/ui/rpc/confzonemanagerrpc.h
Normal file
22
src/ui/rpc/confzonemanagerrpc.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef CONFZONEMANAGERRPC_H
|
||||
#define CONFZONEMANAGERRPC_H
|
||||
|
||||
#include <conf/confzonemanager.h>
|
||||
|
||||
class RpcManager;
|
||||
|
||||
class ConfZoneManagerRpc : public ConfZoneManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfZoneManagerRpc(QObject *parent = nullptr);
|
||||
|
||||
bool addZone(Zone &zone) override;
|
||||
bool deleteZone(int zoneId) override;
|
||||
bool updateZone(const Zone &zone) override;
|
||||
bool updateZoneName(int zoneId, const QString &zoneName) override;
|
||||
bool updateZoneEnabled(int zoneId, bool enabled) override;
|
||||
};
|
||||
|
||||
#endif // CONFZONEMANAGERRPC_H
|
@ -11,6 +11,7 @@
|
||||
#include <rpc/appinfomanagerrpc.h>
|
||||
#include <rpc/confappmanagerrpc.h>
|
||||
#include <rpc/confmanagerrpc.h>
|
||||
#include <rpc/confzonemanagerrpc.h>
|
||||
#include <rpc/drivermanagerrpc.h>
|
||||
#include <rpc/quotamanagerrpc.h>
|
||||
#include <rpc/serviceinfomanagerrpc.h>
|
||||
@ -81,57 +82,6 @@ bool processConfManager_importBackup(
|
||||
return confManager->importBackup(p.args.value(0).toString());
|
||||
}
|
||||
|
||||
bool processConfManager_addZone(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList &resArgs)
|
||||
{
|
||||
Zone zone;
|
||||
zone.enabled = p.args.value(0).toBool();
|
||||
zone.customUrl = p.args.value(1).toBool();
|
||||
zone.zoneName = p.args.value(2).toString();
|
||||
zone.sourceCode = p.args.value(3).toString();
|
||||
zone.url = p.args.value(4).toString();
|
||||
zone.formData = p.args.value(5).toString();
|
||||
zone.textInline = p.args.value(6).toString();
|
||||
|
||||
const bool ok = confManager->addZone(zone);
|
||||
resArgs = { zone.zoneId };
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool processConfManager_deleteZone(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confManager->deleteZone(p.args.value(0).toLongLong());
|
||||
}
|
||||
|
||||
bool processConfManager_updateZone(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
Zone zone;
|
||||
zone.enabled = p.args.value(0).toBool();
|
||||
zone.customUrl = p.args.value(1).toBool();
|
||||
zone.zoneId = p.args.value(2).toInt();
|
||||
zone.zoneName = p.args.value(3).toString();
|
||||
zone.sourceCode = p.args.value(4).toString();
|
||||
zone.url = p.args.value(5).toString();
|
||||
zone.formData = p.args.value(6).toString();
|
||||
zone.textInline = p.args.value(7).toString();
|
||||
|
||||
return confManager->updateZone(zone);
|
||||
}
|
||||
|
||||
bool processConfManager_updateZoneName(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confManager->updateZoneName(p.args.value(0).toLongLong(), p.args.value(1).toString());
|
||||
}
|
||||
|
||||
bool processConfManager_updateZoneEnabled(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confManager->updateZoneEnabled(p.args.value(0).toLongLong(), p.args.value(1).toBool());
|
||||
}
|
||||
|
||||
bool processConfManager_checkPassword(
|
||||
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
@ -149,11 +99,6 @@ static processConfManager_func processConfManager_funcList[] = {
|
||||
&processConfManager_saveVariant, // Rpc_ConfManager_saveVariant,
|
||||
&processConfManager_exportBackup, // Rpc_ConfManager_exportBackup,
|
||||
&processConfManager_importBackup, // Rpc_ConfManager_importBackup,
|
||||
&processConfManager_addZone, // Rpc_ConfManager_addZone,
|
||||
&processConfManager_deleteZone, // Rpc_ConfManager_deleteZone,
|
||||
&processConfManager_updateZone, // Rpc_ConfManager_updateZone,
|
||||
&processConfManager_updateZoneName, // Rpc_ConfManager_updateZoneName,
|
||||
&processConfManager_updateZoneEnabled, // Rpc_ConfManager_updateZoneEnabled,
|
||||
&processConfManager_checkPassword, // Rpc_ConfManager_checkPassword,
|
||||
};
|
||||
|
||||
@ -238,6 +183,85 @@ inline bool processConfAppManagerRpcResult(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processConfZoneManager_addZone(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs)
|
||||
{
|
||||
Zone zone;
|
||||
zone.enabled = p.args.value(0).toBool();
|
||||
zone.customUrl = p.args.value(1).toBool();
|
||||
zone.zoneName = p.args.value(2).toString();
|
||||
zone.sourceCode = p.args.value(3).toString();
|
||||
zone.url = p.args.value(4).toString();
|
||||
zone.formData = p.args.value(5).toString();
|
||||
zone.textInline = p.args.value(6).toString();
|
||||
|
||||
const bool ok = confZoneManager->addZone(zone);
|
||||
resArgs = { zone.zoneId };
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool processConfZoneManager_deleteZone(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confZoneManager->deleteZone(p.args.value(0).toLongLong());
|
||||
}
|
||||
|
||||
bool processConfZoneManager_updateZone(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
Zone zone;
|
||||
zone.enabled = p.args.value(0).toBool();
|
||||
zone.customUrl = p.args.value(1).toBool();
|
||||
zone.zoneId = p.args.value(2).toInt();
|
||||
zone.zoneName = p.args.value(3).toString();
|
||||
zone.sourceCode = p.args.value(4).toString();
|
||||
zone.url = p.args.value(5).toString();
|
||||
zone.formData = p.args.value(6).toString();
|
||||
zone.textInline = p.args.value(7).toString();
|
||||
|
||||
return confZoneManager->updateZone(zone);
|
||||
}
|
||||
|
||||
bool processConfZoneManager_updateZoneName(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confZoneManager->updateZoneName(
|
||||
p.args.value(0).toLongLong(), p.args.value(1).toString());
|
||||
}
|
||||
|
||||
bool processConfZoneManager_updateZoneEnabled(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
|
||||
{
|
||||
return confZoneManager->updateZoneEnabled(
|
||||
p.args.value(0).toLongLong(), p.args.value(1).toBool());
|
||||
}
|
||||
|
||||
using processConfZoneManager_func = bool (*)(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs);
|
||||
|
||||
static processConfZoneManager_func processConfZoneManager_funcList[] = {
|
||||
&processConfZoneManager_addZone, // Rpc_ConfZoneManager_addZone,
|
||||
&processConfZoneManager_deleteZone, // Rpc_ConfZoneManager_deleteZone,
|
||||
&processConfZoneManager_updateZone, // Rpc_ConfZoneManager_updateZone,
|
||||
&processConfZoneManager_updateZoneName, // Rpc_ConfZoneManager_updateZoneName,
|
||||
&processConfZoneManager_updateZoneEnabled, // Rpc_ConfZoneManager_updateZoneEnabled,
|
||||
};
|
||||
|
||||
inline bool processConfZoneManagerRpcResult(
|
||||
ConfZoneManager *confZoneManager, const ProcessCommandArgs &p, QVariantList &resArgs)
|
||||
{
|
||||
if (p.command >= Control::Rpc_ConfZoneManager_addZone
|
||||
&& p.command <= Control::Rpc_ConfZoneManager_updateZoneEnabled) {
|
||||
|
||||
const int funcIndex = p.command - Control::Rpc_ConfZoneManager_addZone;
|
||||
const processConfZoneManager_func func = processConfZoneManager_funcList[funcIndex];
|
||||
|
||||
return func(confZoneManager, p, resArgs);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processStatManager_trafficCleared(StatManager *statManager, const ProcessCommandArgs & /*p*/)
|
||||
{
|
||||
emit statManager->trafficCleared();
|
||||
@ -382,15 +406,6 @@ bool processConfManagerRpc(
|
||||
switch (p.command) {
|
||||
case Control::Rpc_ConfManager_confChanged:
|
||||
return processConfManager_confChanged(confManager, p);
|
||||
case Control::Rpc_ConfManager_zoneAdded:
|
||||
emit confManager->zoneAdded();
|
||||
return true;
|
||||
case Control::Rpc_ConfManager_zoneRemoved:
|
||||
emit confManager->zoneRemoved(p.args.value(0).toInt());
|
||||
return true;
|
||||
case Control::Rpc_ConfManager_zoneUpdated:
|
||||
emit confManager->zoneUpdated();
|
||||
return true;
|
||||
default: {
|
||||
ok = processConfManagerRpcResult(confManager, p, resArgs);
|
||||
isSendResult = true;
|
||||
@ -422,6 +437,29 @@ bool processConfAppManagerRpc(
|
||||
}
|
||||
}
|
||||
|
||||
bool processConfZoneManagerRpc(
|
||||
const ProcessCommandArgs &p, QVariantList &resArgs, bool &ok, bool &isSendResult)
|
||||
{
|
||||
auto confZoneManager = IoC<ConfZoneManager>();
|
||||
|
||||
switch (p.command) {
|
||||
case Control::Rpc_ConfZoneManager_zoneAdded:
|
||||
emit confZoneManager->zoneAdded();
|
||||
return true;
|
||||
case Control::Rpc_ConfZoneManager_zoneRemoved:
|
||||
emit confZoneManager->zoneRemoved(p.args.value(0).toInt());
|
||||
return true;
|
||||
case Control::Rpc_ConfZoneManager_zoneUpdated:
|
||||
emit confZoneManager->zoneUpdated();
|
||||
return true;
|
||||
default: {
|
||||
ok = processConfZoneManagerRpcResult(confZoneManager, p, resArgs);
|
||||
isSendResult = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool processDriverManagerRpc(const ProcessCommandArgs &p, QVariantList & /*resArgs*/, bool & /*ok*/,
|
||||
bool & /*isSendResult*/)
|
||||
{
|
||||
@ -553,6 +591,7 @@ void RpcManager::setupServerSignals()
|
||||
setupAppInfoManagerSignals();
|
||||
setupConfManagerSignals();
|
||||
setupConfAppManagerSignals();
|
||||
setupConfZoneManagerSignals();
|
||||
setupDriverManagerSignals();
|
||||
setupQuotaManagerSignals();
|
||||
setupStatManagerSignals();
|
||||
@ -578,13 +617,6 @@ void RpcManager::setupConfManagerSignals()
|
||||
const QVariant confVar = IoC<ConfManager>()->toPatchVariant(onlyFlags);
|
||||
invokeOnClients(Control::Rpc_ConfManager_confChanged, { confVar });
|
||||
});
|
||||
|
||||
connect(confManager, &ConfManager::zoneAdded, this,
|
||||
[&] { invokeOnClients(Control::Rpc_ConfManager_zoneAdded); });
|
||||
connect(confManager, &ConfManager::zoneRemoved, this,
|
||||
[&](int zoneId) { invokeOnClients(Control::Rpc_ConfManager_zoneRemoved, { zoneId }); });
|
||||
connect(confManager, &ConfManager::zoneUpdated, this,
|
||||
[&] { invokeOnClients(Control::Rpc_ConfManager_zoneUpdated); });
|
||||
}
|
||||
|
||||
void RpcManager::setupConfAppManagerSignals()
|
||||
@ -599,6 +631,19 @@ void RpcManager::setupConfAppManagerSignals()
|
||||
[&] { invokeOnClients(Control::Rpc_ConfAppManager_appUpdated); });
|
||||
}
|
||||
|
||||
void RpcManager::setupConfZoneManagerSignals()
|
||||
{
|
||||
auto confZoneManager = IoC<ConfZoneManager>();
|
||||
|
||||
connect(confZoneManager, &ConfZoneManager::zoneAdded, this,
|
||||
[&] { invokeOnClients(Control::Rpc_ConfZoneManager_zoneAdded); });
|
||||
connect(confZoneManager, &ConfZoneManager::zoneRemoved, this, [&](int zoneId) {
|
||||
invokeOnClients(Control::Rpc_ConfZoneManager_zoneRemoved, { zoneId });
|
||||
});
|
||||
connect(confZoneManager, &ConfZoneManager::zoneUpdated, this,
|
||||
[&] { invokeOnClients(Control::Rpc_ConfZoneManager_zoneUpdated); });
|
||||
}
|
||||
|
||||
void RpcManager::setupDriverManagerSignals()
|
||||
{
|
||||
auto driverManager = IoC<DriverManager>();
|
||||
@ -804,6 +849,7 @@ static processManager_func processManager_funcList[] = {
|
||||
&processAppInfoManagerRpc, // Control::Rpc_AppInfoManager,
|
||||
&processConfManagerRpc, // Control::Rpc_ConfManager,
|
||||
&processConfAppManagerRpc, // Control::Rpc_ConfAppManager,
|
||||
&processConfZoneManagerRpc, // Control::Rpc_ConfZoneManager,
|
||||
&processDriverManagerRpc, // Control::Rpc_DriverManager,
|
||||
&processQuotaManagerRpc, // Control::Rpc_QuotaManager,
|
||||
&processStatManagerRpc, // Control::Rpc_StatManager,
|
||||
|
@ -39,6 +39,7 @@ private:
|
||||
void setupAppInfoManagerSignals();
|
||||
void setupConfManagerSignals();
|
||||
void setupConfAppManagerSignals();
|
||||
void setupConfZoneManagerSignals();
|
||||
void setupDriverManagerSignals();
|
||||
void setupQuotaManagerSignals();
|
||||
void setupStatManagerSignals();
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <conf/confmanager.h>
|
||||
#include <conf/confzonemanager.h>
|
||||
#include <fortsettings.h>
|
||||
#include <model/zonelistmodel.h>
|
||||
#include <model/zonesourcewrapper.h>
|
||||
@ -153,7 +153,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
|
||||
zone.lastRun = QDateTime::currentDateTime();
|
||||
zone.lastSuccess = success ? zone.lastRun : worker->lastSuccess();
|
||||
|
||||
IoC<ConfManager>()->updateZoneResult(zone);
|
||||
IoC<ConfZoneManager>()->updateZoneResult(zone);
|
||||
|
||||
addSubResult(worker, success);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user