UI: Handle app group periods

This commit is contained in:
Nodir Temirkhodjaev 2024-10-14 12:23:46 +05:00
parent bf4247b73d
commit f818c182a1
17 changed files with 210 additions and 223 deletions

View File

@ -64,7 +64,7 @@ TEST_F(ConfUtilTest, confWriteRead)
conf.addAppGroup(appGroup1); conf.addAppGroup(appGroup1);
conf.addAppGroup(appGroup2); conf.addAppGroup(appGroup2);
conf.resetEdited(true); conf.resetEdited(FirewallConf::AllEdited);
conf.prepareToSave(); conf.prepareToSave();
ConfUtil confUtil; ConfUtil confUtil;

View File

@ -165,6 +165,16 @@ void AppGroup::setPeriodTo(const QString &periodTo)
} }
} }
bool AppGroup::isTimeInPeriod(QTime time) const
{
if (m_periodFrom.isNull()) {
m_periodFromTime = DateUtil::parseTime(m_periodFrom);
m_periodToTime = DateUtil::parseTime(m_periodTo);
}
return DateUtil::isTimeInPeriod(time, m_periodFromTime, m_periodToTime);
}
QString AppGroup::menuLabel() const QString AppGroup::menuLabel() const
{ {
QString text = name(); QString text = name();

View File

@ -2,6 +2,7 @@
#define APPGROUP_H #define APPGROUP_H
#include <QObject> #include <QObject>
#include <QTime>
#include <QVariant> #include <QVariant>
#define MAX_APP_GROUP_COUNT 16 #define MAX_APP_GROUP_COUNT 16
@ -90,6 +91,8 @@ public:
QString periodTo() const { return m_periodTo; } QString periodTo() const { return m_periodTo; }
void setPeriodTo(const QString &periodTo); void setPeriodTo(const QString &periodTo);
bool isTimeInPeriod(QTime time) const;
QString menuLabel() const; QString menuLabel() const;
void copy(const AppGroup &o); void copy(const AppGroup &o);
@ -132,6 +135,9 @@ private:
// In format "hh:mm" // In format "hh:mm"
QString m_periodFrom; QString m_periodFrom;
QString m_periodTo; QString m_periodTo;
mutable QTime m_periodFromTime; // transient
mutable QTime m_periodToTime; // transient
}; };
#endif // APPGROUP_H #endif // APPGROUP_H

View File

@ -185,19 +185,18 @@ void ConfAppManager::setupAppEndTimer()
void ConfAppManager::updateAppEndTimer() void ConfAppManager::updateAppEndTimer()
{ {
const qint64 endTimeMsecs = DbQuery(sqliteDb()).sql(sqlSelectMinEndApp).execute().toLongLong(); m_appEndTimer.stop();
const qint64 endTimeMsecs = DbQuery(sqliteDb()).sql(sqlSelectMinEndApp).execute().toLongLong();
if (endTimeMsecs == 0)
return;
if (endTimeMsecs != 0) {
const qint64 currentMsecs = QDateTime::currentMSecsSinceEpoch(); const qint64 currentMsecs = QDateTime::currentMSecsSinceEpoch();
const qint64 deltaMsecs = endTimeMsecs - currentMsecs; const qint64 deltaMsecs = endTimeMsecs - currentMsecs;
const int interval = qMax( const int interval = qBound(
(deltaMsecs > 0 ? int(qMin(deltaMsecs, qint64(APP_END_TIMER_INTERVAL_MAX))) : 0), qint64(APP_END_TIMER_INTERVAL_MIN), deltaMsecs, qint64(APP_END_TIMER_INTERVAL_MAX));
APP_END_TIMER_INTERVAL_MIN);
m_appEndTimer.start(interval); m_appEndTimer.start(interval);
} else {
m_appEndTimer.stop();
}
} }
bool ConfAppManager::addAppPathBlocked(App &app) bool ConfAppManager::addAppPathBlocked(App &app)

View File

@ -36,6 +36,8 @@ const QLoggingCategory LC("conf");
constexpr int DATABASE_USER_VERSION = 45; constexpr int DATABASE_USER_VERSION = 45;
constexpr int CONF_PERIODS_UPDATE_INTERVAL = 60 * 1000; // 1 minute
const char *const sqlSelectAddressGroups = "SELECT addr_group_id, include_all, exclude_all," const char *const sqlSelectAddressGroups = "SELECT addr_group_id, include_all, exclude_all,"
" include_zones, exclude_zones," " include_zones, exclude_zones,"
" include_text, exclude_text" " include_text, exclude_text"
@ -457,6 +459,8 @@ bool importFile(const QString &filePath, const QString &path)
ConfManager::ConfManager(const QString &filePath, QObject *parent, quint32 openFlags) : ConfManager::ConfManager(const QString &filePath, QObject *parent, quint32 openFlags) :
QObject(parent), m_sqliteDb(new SqliteDb(filePath, openFlags)), m_conf(createConf()) QObject(parent), m_sqliteDb(new SqliteDb(filePath, openFlags)), m_conf(createConf())
{ {
m_confTimer.setSingleShot(true);
connect(&m_confTimer, &QTimer::timeout, this, &ConfManager::updateConfPeriods);
} }
IniUser &ConfManager::iniUser() const IniUser &ConfManager::iniUser() const
@ -532,6 +536,25 @@ FirewallConf *ConfManager::createConf()
return conf; return conf;
} }
bool ConfManager::applyConfPeriods(bool onlyFlags)
{
m_confTimer.stop();
if (!conf() || !conf()->updateGroupPeriods(onlyFlags))
return false;
m_confTimer.start(CONF_PERIODS_UPDATE_INTERVAL);
return true;
}
void ConfManager::updateConfPeriods()
{
if (applyConfPeriods(/*onlyFlags=*/false)) {
emit confChanged(/*onlyFlags=*/true, FirewallConf::FlagsEdited);
}
}
bool ConfManager::setupDb() bool ConfManager::setupDb()
{ {
if (!sqliteDb()->open()) { if (!sqliteDb()->open()) {
@ -623,7 +646,9 @@ void ConfManager::applySavedConf(FirewallConf *newConf)
} }
} }
emit confChanged(onlyFlags); applyConfPeriods(onlyFlags);
emit confChanged(onlyFlags, conf()->editedFlags());
if (conf()->iniEdited()) { if (conf()->iniEdited()) {
emit iniChanged(conf()->ini()); emit iniChanged(conf()->ini());
@ -669,11 +694,11 @@ void ConfManager::saveIniUser(bool edited, bool onlyFlags)
} }
} }
QVariant ConfManager::toPatchVariant(bool onlyFlags) const QVariant ConfManager::toPatchVariant(bool onlyFlags, uint editedFlags) const
{ {
return onlyFlags ? conf()->toVariant(/*onlyEdited=*/true) // send only flags to clients return onlyFlags ? conf()->toVariant(/*onlyEdited=*/true) // send only flags to clients
: FirewallConf::editedFlagsToVariant( : FirewallConf::editedFlagsToVariant(
FirewallConf::AllEdited); // clients have to reload all from storage editedFlags); // clients have to reload all from storage
} }
bool ConfManager::saveVariant(const QVariant &confVar) bool ConfManager::saveVariant(const QVariant &confVar)
@ -817,7 +842,7 @@ bool ConfManager::importMasterBackup(const QString &path)
if (ok) { if (ok) {
emit imported(); emit imported();
emit confChanged(/*onlyFlags=*/false); load(); // Reload conf
} else { } else {
qCWarning(LC) << "Import error:" << path; qCWarning(LC) << "Import error:" << path;
} }

View File

@ -2,6 +2,7 @@
#define CONFMANAGER_H #define CONFMANAGER_H
#include <QObject> #include <QObject>
#include <QTimer>
#include <sqlite/sqlite_types.h> #include <sqlite/sqlite_types.h>
@ -49,7 +50,7 @@ public:
void saveIni(); void saveIni();
void saveIniUser(bool edited = false, bool onlyFlags = false); void saveIniUser(bool edited = false, bool onlyFlags = false);
QVariant toPatchVariant(bool onlyFlags) const; QVariant toPatchVariant(bool onlyFlags, uint editedFlags) const;
bool saveVariant(const QVariant &confVar); bool saveVariant(const QVariant &confVar);
bool loadTasks(const QList<TaskInfo *> &taskInfos); bool loadTasks(const QList<TaskInfo *> &taskInfos);
@ -70,7 +71,7 @@ public:
signals: signals:
void imported(); void imported();
void confChanged(bool onlyFlags); void confChanged(bool onlyFlags, uint editedFlags);
void iniChanged(const IniOptions &ini); void iniChanged(const IniOptions &ini);
void iniUserChanged(const IniUser &ini, bool onlyFlags); void iniUserChanged(const IniUser &ini, bool onlyFlags);
@ -78,7 +79,11 @@ protected:
void setConf(FirewallConf *newConf); void setConf(FirewallConf *newConf);
FirewallConf *createConf(); FirewallConf *createConf();
virtual bool applyConfPeriods(bool onlyFlags);
private: private:
void updateConfPeriods();
bool setupDb(); bool setupDb();
void setupDefault(FirewallConf &conf) const; void setupDefault(FirewallConf &conf) const;
@ -103,6 +108,8 @@ private:
FirewallConf *m_confToEdit = nullptr; FirewallConf *m_confToEdit = nullptr;
IniUser *m_iniUserToEdit = nullptr; IniUser *m_iniUserToEdit = nullptr;
QTimer m_confTimer;
}; };
#endif // CONFMANAGER_H #endif // CONFMANAGER_H

View File

@ -1,6 +1,7 @@
#include "firewallconf.h" #include "firewallconf.h"
#include <manager/envmanager.h> #include <manager/envmanager.h>
#include <util/dateutil.h>
#include <util/net/netutil.h> #include <util/net/netutil.h>
#include "addressgroup.h" #include "addressgroup.h"
@ -11,11 +12,6 @@ FirewallConf::FirewallConf(Settings *settings, QObject *parent) : QObject(parent
setupAddressGroups(); setupAddressGroups();
} }
void FirewallConf::resetEdited(bool v)
{
m_editedFlags = v ? AllEdited : NoneEdited;
}
int FirewallConf::blockTrafficIndex() const int FirewallConf::blockTrafficIndex() const
{ {
return m_blockInetTraffic ? 2 : (m_blockTraffic ? 1 : 0); return m_blockInetTraffic ? 2 : (m_blockTraffic ? 1 : 0);
@ -90,29 +86,9 @@ QStringList FirewallConf::filterModeIconPaths()
":/icons/road_sign.png" }; ":/icons/road_sign.png" };
} }
void FirewallConf::setActivePeriodEnabled(bool activePeriodEnabled) void FirewallConf::setupAppGroupBits(quint32 v)
{ {
m_activePeriodEnabled = activePeriodEnabled; setAppGroupBits(v);
}
void FirewallConf::setActivePeriodFrom(const QString &activePeriodFrom)
{
m_activePeriodFrom = activePeriodFrom;
}
void FirewallConf::setActivePeriodTo(const QString &activePeriodTo)
{
m_activePeriodTo = activePeriodTo;
}
void FirewallConf::setAppGroupBits(quint32 groupBits)
{
m_appGroupBits = groupBits;
}
void FirewallConf::setupAppGroupBits(quint32 groupBits)
{
setAppGroupBits(groupBits);
applyAppGroupBits(); applyAppGroupBits();
} }
@ -214,6 +190,25 @@ void FirewallConf::clearRemovedAppGroupIdList() const
m_removedAppGroupIdList.clear(); m_removedAppGroupIdList.clear();
} }
void FirewallConf::loadGroupPeriodBits()
{
const QTime now = DateUtil::currentTime();
m_anyGroupPeriodEnabled = false;
m_groupActivePeriodBits = quint32(-1);
int groupIndex = 0;
for (AppGroup *appGroup : appGroups()) {
if (appGroup->periodEnabled()) {
m_anyGroupPeriodEnabled = true;
if (!appGroup->isTimeInPeriod(now)) {
m_groupActivePeriodBits ^= (1 << groupIndex);
}
}
++groupIndex;
}
}
void FirewallConf::loadAppGroupBits() void FirewallConf::loadAppGroupBits()
{ {
m_appGroupBits = 0; m_appGroupBits = 0;
@ -271,6 +266,15 @@ void FirewallConf::afterSaved()
ini().clear(); ini().clear();
} }
bool FirewallConf::updateGroupPeriods(bool onlyFlags)
{
if (!onlyFlags) {
loadGroupPeriodBits();
}
return m_anyGroupPeriodEnabled;
}
void FirewallConf::copyFlags(const FirewallConf &o) void FirewallConf::copyFlags(const FirewallConf &o)
{ {
m_editedFlags = o.editedFlags(); m_editedFlags = o.editedFlags();
@ -476,11 +480,8 @@ void FirewallConf::fromVariant(const QVariant &v, bool onlyEdited)
{ {
const QVariantMap map = v.toMap(); const QVariantMap map = v.toMap();
if (onlyEdited) { resetEdited(onlyEdited ? FirewallConf::EditedFlags(editedFlagsFromVariant(v))
m_editedFlags = editedFlagsFromVariant(v); : FirewallConf::AllEdited);
} else {
resetEdited(true);
}
if (optEdited()) { if (optEdited()) {
addressesFromVariant(map["addressGroups"]); addressesFromVariant(map["addressGroups"]);
@ -510,5 +511,6 @@ QVariant FirewallConf::editedFlagsToVariant(uint editedFlags)
uint FirewallConf::editedFlagsFromVariant(const QVariant &v) uint FirewallConf::editedFlagsFromVariant(const QVariant &v)
{ {
const QVariantMap map = v.toMap(); const QVariantMap map = v.toMap();
return map["editedFlags"].toUInt(); return map["editedFlags"].toUInt();
} }

View File

@ -41,55 +41,52 @@ public:
void setTaskEdited() { m_editedFlags |= TaskEdited; } void setTaskEdited() { m_editedFlags |= TaskEdited; }
bool anyEdited() const { return m_editedFlags != NoneEdited; } bool anyEdited() const { return m_editedFlags != NoneEdited; }
void resetEdited(bool v = false); void resetEdited(EditedFlags v = NoneEdited) { m_editedFlags = v; }
bool bootFilter() const { return m_bootFilter; } bool bootFilter() const { return m_bootFilter; }
void setBootFilter(bool bootFilter) { m_bootFilter = bootFilter; } void setBootFilter(bool v) { m_bootFilter = v; }
bool filterEnabled() const { return m_filterEnabled; } bool filterEnabled() const { return m_filterEnabled; }
void setFilterEnabled(bool filterEnabled) { m_filterEnabled = filterEnabled; } void setFilterEnabled(bool v) { m_filterEnabled = v; }
bool filterLocals() const { return m_filterLocals; } bool filterLocals() const { return m_filterLocals; }
void setFilterLocals(bool filterLocals) { m_filterLocals = filterLocals; } void setFilterLocals(bool v) { m_filterLocals = v; }
bool filterLocalNet() const { return m_filterLocalNet; } bool filterLocalNet() const { return m_filterLocalNet; }
void setFilterLocalNet(bool filterLocalNet) { m_filterLocalNet = filterLocalNet; } void setFilterLocalNet(bool v) { m_filterLocalNet = v; }
bool blockTraffic() const { return m_blockTraffic; } bool blockTraffic() const { return m_blockTraffic; }
void setBlockTraffic(bool blockTraffic) { m_blockTraffic = blockTraffic; } void setBlockTraffic(bool v) { m_blockTraffic = v; }
bool blockInetTraffic() const { return m_blockInetTraffic; } bool blockInetTraffic() const { return m_blockInetTraffic; }
void setBlockInetTraffic(bool blockInetTraffic) { m_blockInetTraffic = blockInetTraffic; } void setBlockInetTraffic(bool v) { m_blockInetTraffic = v; }
bool allowAllNew() const { return m_allowAllNew; } bool allowAllNew() const { return m_allowAllNew; }
void setAllowAllNew(bool allowAllNew) { m_allowAllNew = allowAllNew; } void setAllowAllNew(bool v) { m_allowAllNew = v; }
bool askToConnect() const { return m_askToConnect; } bool askToConnect() const { return m_askToConnect; }
void setAskToConnect(bool askToConnect) { m_askToConnect = askToConnect; } void setAskToConnect(bool v) { m_askToConnect = v; }
bool groupBlocked() const { return m_groupBlocked; } bool groupBlocked() const { return m_groupBlocked; }
void setGroupBlocked(bool groupBlocked) { m_groupBlocked = groupBlocked; } void setGroupBlocked(bool v) { m_groupBlocked = v; }
bool logStat() const { return m_logStat; } bool logStat() const { return m_logStat; }
void setLogStat(bool logStat) { m_logStat = logStat; } void setLogStat(bool v) { m_logStat = v; }
bool logStatNoFilter() const { return m_logStatNoFilter; } bool logStatNoFilter() const { return m_logStatNoFilter; }
void setLogStatNoFilter(bool logStatNoFilter) { m_logStatNoFilter = logStatNoFilter; } void setLogStatNoFilter(bool v) { m_logStatNoFilter = v; }
bool logBlocked() const { return m_logBlocked; } bool logBlocked() const { return m_logBlocked; }
void setLogBlocked(bool logBlocked) { m_logBlocked = logBlocked; } void setLogBlocked(bool v) { m_logBlocked = v; }
bool logAllowedIp() const { return m_logAllowedIp; } bool logAllowedIp() const { return m_logAllowedIp; }
void setLogAllowedIp(bool logAllowedIp) { m_logAllowedIp = logAllowedIp; } void setLogAllowedIp(bool v) { m_logAllowedIp = v; }
bool logBlockedIp() const { return m_logBlockedIp; } bool logBlockedIp() const { return m_logBlockedIp; }
void setLogBlockedIp(bool logBlockedIp) { m_logBlockedIp = logBlockedIp; } void setLogBlockedIp(bool v) { m_logBlockedIp = v; }
bool logAlertedBlockedIp() const { return m_logAlertedBlockedIp; } bool logAlertedBlockedIp() const { return m_logAlertedBlockedIp; }
void setLogAlertedBlockedIp(bool logAlertedBlockedIp) void setLogAlertedBlockedIp(bool v) { m_logAlertedBlockedIp = v; }
{
m_logAlertedBlockedIp = logAlertedBlockedIp;
}
bool appBlockAll() const { return m_appBlockAll; } bool appBlockAll() const { return m_appBlockAll; }
void setAppBlockAll(bool appBlockAll) { m_appBlockAll = appBlockAll; } void setAppBlockAll(bool appBlockAll) { m_appBlockAll = appBlockAll; }
@ -110,18 +107,20 @@ public:
static QStringList filterModeIconPaths(); static QStringList filterModeIconPaths();
bool activePeriodEnabled() const { return m_activePeriodEnabled; } bool activePeriodEnabled() const { return m_activePeriodEnabled; }
void setActivePeriodEnabled(bool activePeriodEnabled); void setActivePeriodEnabled(bool v) { m_activePeriodEnabled = v; }
QString activePeriodFrom() const { return m_activePeriodFrom; } QString activePeriodFrom() const { return m_activePeriodFrom; }
void setActivePeriodFrom(const QString &activePeriodFrom); void setActivePeriodFrom(const QString &v) { m_activePeriodFrom = v; }
QString activePeriodTo() const { return m_activePeriodTo; } QString activePeriodTo() const { return m_activePeriodTo; }
void setActivePeriodTo(const QString &activePeriodTo); void setActivePeriodTo(const QString &v) { m_activePeriodTo = v; }
quint32 appGroupBits() const { return m_appGroupBits; } quint32 appGroupBits() const { return m_appGroupBits; }
void setAppGroupBits(quint32 groupBits); void setAppGroupBits(quint32 v) { m_appGroupBits = v; }
void setupAppGroupBits(quint32 groupBits); quint32 activeGroupBits() const { return m_appGroupBits & m_groupActivePeriodBits; }
void setupAppGroupBits(quint32 v);
bool appGroupEnabled(int groupIndex) const; bool appGroupEnabled(int groupIndex) const;
@ -168,11 +167,15 @@ public slots:
void prepareToSave(); void prepareToSave();
void afterSaved(); void afterSaved();
bool updateGroupPeriods(bool onlyFlags);
private: private:
void setupAddressGroups(); void setupAddressGroups();
void setAppGroupsEdited(int from, int to); void setAppGroupsEdited(int from, int to);
void loadGroupPeriodBits();
void loadAppGroupBits(); void loadAppGroupBits();
void applyAppGroupBits(); void applyAppGroupBits();
@ -213,8 +216,10 @@ private:
uint m_appAllowAll : 1 = false; uint m_appAllowAll : 1 = false;
uint m_activePeriodEnabled : 1 = false; uint m_activePeriodEnabled : 1 = false;
uint m_anyGroupPeriodEnabled : 1 = false;
quint32 m_appGroupBits = 0; quint32 m_appGroupBits = 0;
quint32 m_groupActivePeriodBits = quint32(-1); // transient
QString m_activePeriodFrom; QString m_activePeriodFrom;
QString m_activePeriodTo; QString m_activePeriodTo;

View File

@ -3,7 +3,7 @@
#include <util/ini/mapsettings.h> #include <util/ini/mapsettings.h>
#define DEFAULT_APP_GROUP_BITS 0xFFFF #define DEFAULT_APP_GROUP_BITS quint32(-1)
#define DEFAULT_MONTH_START 1 #define DEFAULT_MONTH_START 1
#define DEFAULT_TRAF_HOUR_KEEP_DAYS 90 // ~3 months #define DEFAULT_TRAF_HOUR_KEEP_DAYS 90 // ~3 months
#define DEFAULT_TRAF_DAY_KEEP_DAYS 365 // ~1 year #define DEFAULT_TRAF_DAY_KEEP_DAYS 365 // ~1 year

View File

@ -216,10 +216,9 @@ void FortManager::setupLogger()
logger->setForceDebug(settings->forceDebug()); logger->setForceDebug(settings->forceDebug());
} }
void FortManager::updateLogger(const FirewallConf *conf) void FortManager::updateLogger()
{ {
if (!conf->iniEdited()) const FirewallConf *conf = IoC<ConfManager>()->conf();
return;
Logger *logger = Logger::instance(); Logger *logger = Logger::instance();
@ -333,22 +332,16 @@ bool FortManager::removeDriver()
bool FortManager::setupDriver() bool FortManager::setupDriver()
{ {
auto driverManager = IoC<DriverManager>(); auto driverManager = IoC<DriverManager>();
auto confManager = IoC<ConfManager>();
bool ok = driverManager->openDevice(); if (!driverManager->openDevice())
return false;
if (ok && !confManager->validateDriver()) { if (!setupDriverConf()) {
driverManager->closeDevice(); driverManager->closeDevice();
ok = false; return false;
} }
if (ok) { return true;
confManager->updateServices();
updateTaskManager();
}
return ok;
} }
void FortManager::closeDriver() void FortManager::closeDriver()
@ -415,12 +408,12 @@ void FortManager::setupConfManager()
connect(confManager, &ConfManager::imported, IoC<WindowManager>(), connect(confManager, &ConfManager::imported, IoC<WindowManager>(),
&WindowManager::closeAllWindows); &WindowManager::closeAllWindows);
connect(confManager, &ConfManager::confChanged, this, [&](bool onlyFlags) { connect(confManager, &ConfManager::confChanged, this, [&](bool onlyFlags, uint editedFlags) {
const FirewallConf *conf = IoC<ConfManager>()->conf(); if (!onlyFlags && (editedFlags & FirewallConf::IniEdited) != 0) {
updateLogger();
}
updateLogger(conf); if (!onlyFlags || (editedFlags & FirewallConf::FlagsEdited) != 0) {
if (!onlyFlags || conf->flagsEdited()) {
updateDriverConf(onlyFlags); updateDriverConf(onlyFlags);
} }
}); });
@ -491,7 +484,6 @@ void FortManager::processRestartRequired(const QString &info)
void FortManager::loadConf() void FortManager::loadConf()
{ {
const auto settings = IoC<FortSettings>(); const auto settings = IoC<FortSettings>();
const auto confManager = IoC<ConfManager>();
// Validate migration // Validate migration
QString viaVersion; QString viaVersion;
@ -501,14 +493,35 @@ void FortManager::loadConf()
exit(-1); // Exit the program exit(-1); // Exit the program
} }
if (!confManager->load()) {
showErrorMessage(tr("Cannot load Settings"));
}
qCDebug(LC) << "Started as" qCDebug(LC) << "Started as"
<< (settings->isService() ? "Service" << (settings->isService() ? "Service"
: settings->hasService() ? "Client" : settings->hasService() ? "Client"
: "Program"); : "Program");
if (!IoC<ConfManager>()->load()) {
showErrorMessage(tr("Cannot load Settings"));
}
}
bool FortManager::setupDriverConf()
{
auto confManager = IoC<ConfManager>();
if (!confManager->validateDriver())
return false;
// Services
confManager->updateServices();
// Zones
{
auto zd = IoC<TaskManager>()->taskInfoZoneDownloader();
IoC<ConfZoneManager>()->updateDriverZones(
zd->dataZonesMask(), zd->enabledMask(), zd->dataSize(), zd->zonesData());
}
return true;
} }
bool FortManager::updateDriverConf(bool onlyFlags) bool FortManager::updateDriverConf(bool onlyFlags)
@ -525,19 +538,6 @@ bool FortManager::updateDriverConf(bool onlyFlags)
return res; return res;
} }
void FortManager::updateTaskManager()
{
auto taskManager = IoC<TaskManager>();
// Zones
{
auto zd = taskManager->taskInfoZoneDownloader();
IoC<ConfZoneManager>()->updateDriverZones(
zd->dataZonesMask(), zd->enabledMask(), zd->dataSize(), zd->zonesData());
}
}
void FortManager::updateLogManager(bool active) void FortManager::updateLogManager(bool active)
{ {
IoC<LogManager>()->setActive(active); IoC<LogManager>()->setActive(active);

View File

@ -39,7 +39,7 @@ private:
void setupThreadPool(); void setupThreadPool();
void setupLogger(); void setupLogger();
void updateLogger(const FirewallConf *conf); void updateLogger();
void createManagers(); void createManagers();
void deleteManagers(); void deleteManagers();
@ -60,9 +60,9 @@ private:
void loadConf(); void loadConf();
bool setupDriverConf();
bool updateDriverConf(bool onlyFlags = false); bool updateDriverConf(bool onlyFlags = false);
void updateTaskManager();
void updateLogManager(bool active); void updateLogManager(bool active);
void updateStatManager(FirewallConf *conf); void updateStatManager(FirewallConf *conf);

View File

@ -7,7 +7,6 @@
#include <fortsettings.h> #include <fortsettings.h>
#include <manager/windowmanager.h> #include <manager/windowmanager.h>
#include <rpc/rpcmanager.h> #include <rpc/rpcmanager.h>
#include <task/taskmanager.h>
#include <util/ioc/ioccontainer.h> #include <util/ioc/ioccontainer.h>
#include <util/variantutil.h> #include <util/variantutil.h>
@ -76,21 +75,6 @@ ConfManagerRpc::ConfManagerRpc(const QString &filePath, QObject *parent) :
{ {
} }
bool ConfManagerRpc::exportMasterBackup(const QString &path)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_exportMasterBackup, { path });
}
bool ConfManagerRpc::importMasterBackup(const QString &path)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_importMasterBackup, { path });
}
bool ConfManagerRpc::checkPassword(const QString &password)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_checkPassword, { password });
}
bool ConfManagerRpc::saveConf(FirewallConf &newConf) bool ConfManagerRpc::saveConf(FirewallConf &newConf)
{ {
Q_ASSERT(&newConf == conf() || &newConf == confToEdit()); // else newConf.deleteLater() Q_ASSERT(&newConf == conf() || &newConf == confToEdit()); // else newConf.deleteLater()
@ -117,6 +101,21 @@ bool ConfManagerRpc::saveConf(FirewallConf &newConf)
return true; return true;
} }
bool ConfManagerRpc::exportMasterBackup(const QString &path)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_exportMasterBackup, { path });
}
bool ConfManagerRpc::importMasterBackup(const QString &path)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_importMasterBackup, { path });
}
bool ConfManagerRpc::checkPassword(const QString &password)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_checkPassword, { password });
}
void ConfManagerRpc::onConfChanged(const QVariant &confVar) void ConfManagerRpc::onConfChanged(const QVariant &confVar)
{ {
IoC<FortSettings>()->clearCache(); // FirewallConf::IniEdited is handled here IoC<FortSettings>()->clearCache(); // FirewallConf::IniEdited is handled here
@ -132,10 +131,6 @@ void ConfManagerRpc::onConfChanged(const QVariant &confVar)
conf()->fromVariant(confVar, /*onlyEdited=*/true); conf()->fromVariant(confVar, /*onlyEdited=*/true);
} }
if ((editedFlags & FirewallConf::TaskEdited) != 0) {
IoC<TaskManager>()->loadSettings();
}
applySavedConf(conf()); applySavedConf(conf());
if (!saving()) { if (!saving()) {
@ -168,8 +163,9 @@ void ConfManagerRpc::setupServerSignals(RpcManager *rpcManager)
{ {
auto confManager = IoC<ConfManager>(); auto confManager = IoC<ConfManager>();
connect(confManager, &ConfManager::confChanged, rpcManager, [=](bool onlyFlags) { connect(confManager, &ConfManager::confChanged, rpcManager,
const QVariant confVar = IoC<ConfManager>()->toPatchVariant(onlyFlags); [=](bool onlyFlags, uint editedFlags) {
const QVariant confVar = IoC<ConfManager>()->toPatchVariant(onlyFlags, editedFlags);
rpcManager->invokeOnClients(Control::Rpc_ConfManager_confChanged, { confVar }); rpcManager->invokeOnClients(Control::Rpc_ConfManager_confChanged, { confVar });
}); });
connect(confManager, &ConfManager::imported, rpcManager, connect(confManager, &ConfManager::imported, rpcManager,

View File

@ -15,6 +15,8 @@ class ConfManagerRpc : public ConfManager
public: public:
explicit ConfManagerRpc(const QString &filePath, QObject *parent = nullptr); explicit ConfManagerRpc(const QString &filePath, QObject *parent = nullptr);
bool saveConf(FirewallConf &newConf) override;
bool exportMasterBackup(const QString &path) override; bool exportMasterBackup(const QString &path) override;
bool importMasterBackup(const QString &path) override; bool importMasterBackup(const QString &path) override;
@ -28,7 +30,7 @@ public:
static void setupServerSignals(RpcManager *rpcManager); static void setupServerSignals(RpcManager *rpcManager);
protected: protected:
bool saveConf(FirewallConf &newConf) override; bool applyConfPeriods(bool /*onlyFlags*/) override { return false; }
private: private:
bool saving() const { return m_saving; } bool saving() const { return m_saving; }

View File

@ -22,38 +22,6 @@ TaskManager *TaskInfo::taskManager() const
return qobject_cast<TaskManager *>(parent()); return qobject_cast<TaskManager *>(parent());
} }
void TaskInfo::setEnabled(bool enabled)
{
if (m_enabled != enabled) {
m_enabled = enabled;
emit enabledChanged();
}
}
void TaskInfo::setRunOnStatup(bool runOnStatup)
{
if (m_runOnStatup != runOnStatup) {
m_runOnStatup = runOnStatup;
emit runOnStatupChanged();
}
}
void TaskInfo::setRunning(bool running)
{
if (m_running != running) {
m_running = running;
emit enabledChanged();
}
}
void TaskInfo::setIntervalHours(int intervalHours)
{
if (m_intervalHours != intervalHours) {
m_intervalHours = quint16(intervalHours);
emit intervalHoursChanged();
}
}
QString TaskInfo::title() const QString TaskInfo::title() const
{ {
return title(m_type); return title(m_type);
@ -74,43 +42,11 @@ QString TaskInfo::title(TaskType type)
} }
} }
void TaskInfo::setType(TaskInfo::TaskType type)
{
if (m_type != type) {
m_type = type;
emit typeChanged();
}
}
void TaskInfo::setLastRun(const QDateTime &lastRun)
{
if (m_lastRun != lastRun) {
m_lastRun = lastRun;
emit lastRunChanged();
}
}
QDateTime TaskInfo::plannedRun() const QDateTime TaskInfo::plannedRun() const
{ {
return m_lastRun.addSecs(m_intervalHours * 60 * 60); return m_lastRun.addSecs(m_intervalHours * 60 * 60);
} }
void TaskInfo::setLastSuccess(const QDateTime &lastSuccess)
{
if (m_lastSuccess != lastSuccess) {
m_lastSuccess = lastSuccess;
emit lastSuccessChanged();
}
}
void TaskInfo::setTaskWorker(TaskWorker *taskWorker)
{
if (m_taskWorker != taskWorker) {
m_taskWorker = taskWorker;
emit taskWorkerChanged();
}
}
void TaskInfo::editFromVariant(const QVariant &v) void TaskInfo::editFromVariant(const QVariant &v)
{ {
const TaskEditInfo info(v.toUInt()); const TaskEditInfo info(v.toUInt());

View File

@ -33,41 +33,41 @@ public:
QString name() const { return typeToString(type()); } QString name() const { return typeToString(type()); }
bool enabled() const { return m_enabled; } bool enabled() const { return m_enabled; }
void setEnabled(bool enabled); void setEnabled(bool v) { m_enabled = v; }
bool runOnStatup() const { return m_runOnStatup; } bool runOnStatup() const { return m_runOnStatup; }
void setRunOnStatup(bool runOnStatup); void setRunOnStatup(bool v) { m_runOnStatup = v; }
bool aborted() const { return m_aborted; } bool aborted() const { return m_aborted; }
bool running() const { return m_running; } bool running() const { return m_running; }
void setRunning(bool running); void setRunning(bool v) { m_running = v; }
int intervalHours() const { return m_intervalHours; } int intervalHours() const { return m_intervalHours; }
void setIntervalHours(int intervalHours); void setIntervalHours(int v) { m_intervalHours = quint16(v); }
QString title() const; QString title() const;
static QString title(TaskType type); static QString title(TaskType type);
TaskInfo::TaskType type() const { return m_type; } TaskInfo::TaskType type() const { return m_type; }
void setType(TaskInfo::TaskType type); void setType(TaskInfo::TaskType v) { m_type = v; }
qint64 id() const { return m_id; } qint64 id() const { return m_id; }
void setId(qint64 id) { m_id = id; } void setId(qint64 id) { m_id = id; }
QDateTime lastRun() const { return m_lastRun; } QDateTime lastRun() const { return m_lastRun; }
void setLastRun(const QDateTime &lastRun); void setLastRun(const QDateTime &v) { m_lastRun = v; }
QDateTime plannedRun() const; QDateTime plannedRun() const;
QDateTime lastSuccess() const { return m_lastSuccess; } QDateTime lastSuccess() const { return m_lastSuccess; }
void setLastSuccess(const QDateTime &lastSuccess); void setLastSuccess(const QDateTime &v) { m_lastSuccess = v; }
virtual QByteArray data() const { return QByteArray(); } virtual QByteArray data() const { return QByteArray(); }
virtual void setData(const QByteArray &data) { Q_UNUSED(data); } virtual void setData(const QByteArray &data) { Q_UNUSED(data); }
TaskWorker *taskWorker() const { return m_taskWorker; } TaskWorker *taskWorker() const { return m_taskWorker; }
void setTaskWorker(TaskWorker *taskWorker); void setTaskWorker(TaskWorker *v) { m_taskWorker = v; }
void editFromVariant(const QVariant &v); void editFromVariant(const QVariant &v);
@ -77,15 +77,6 @@ public:
static TaskInfo::TaskType stringToType(const QString &name); static TaskInfo::TaskType stringToType(const QString &name);
signals: signals:
void enabledChanged();
void runOnStatupChanged();
void runningChanged();
void intervalHoursChanged();
void typeChanged();
void lastRunChanged();
void lastSuccessChanged();
void taskWorkerChanged();
void workStarted(); void workStarted();
void workFinished(bool success); void workFinished(bool success);

View File

@ -1,6 +1,7 @@
#include "taskmanager.h" #include "taskmanager.h"
#include <conf/confmanager.h> #include <conf/confmanager.h>
#include <conf/firewallconf.h>
#include <util/dateutil.h> #include <util/dateutil.h>
#include <util/ioc/ioccontainer.h> #include <util/ioc/ioccontainer.h>
@ -38,10 +39,19 @@ TaskInfo *TaskManager::taskInfoAt(int row) const
void TaskManager::setUp() void TaskManager::setUp()
{ {
auto confManager = IoCDependency<ConfManager>();
loadSettings(); loadSettings();
initializeTasks(); initializeTasks();
setupTimer(); setupTimer();
connect(confManager, &ConfManager::confChanged, this, [&](bool onlyFlags, uint editedFlags) {
if (onlyFlags || (editedFlags & FirewallConf::TaskEdited) == 0)
return;
loadSettings();
});
} }
void TaskManager::initializeTasks() void TaskManager::initializeTasks()
@ -79,9 +89,7 @@ void TaskManager::appendTaskInfo(TaskInfo *taskInfo)
void TaskManager::loadSettings() void TaskManager::loadSettings()
{ {
auto confManager = IoCDependency<ConfManager>(); IoC<ConfManager>()->loadTasks(taskInfoList());
confManager->loadTasks(taskInfoList());
} }
bool TaskManager::saveSettings() bool TaskManager::saveSettings()

View File

@ -78,7 +78,7 @@ void writeConfFlags(const FirewallConf &conf, PFORT_CONF_FLAGS confFlags)
confFlags->log_blocked_ip = conf.logBlockedIp(); confFlags->log_blocked_ip = conf.logBlockedIp();
confFlags->log_alerted_blocked_ip = conf.logAlertedBlockedIp(); confFlags->log_alerted_blocked_ip = conf.logAlertedBlockedIp();
confFlags->group_bits = conf.appGroupBits(); confFlags->group_bits = conf.activeGroupBits();
} }
void writeAppGroupFlags(PFORT_CONF_GROUP out, const FirewallConf &conf) void writeAppGroupFlags(PFORT_CONF_GROUP out, const FirewallConf &conf)