mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:46:03 +00:00
UI: StatManagerRpc: Fix connections handling.
This commit is contained in:
parent
fd9589a6ab
commit
bffc750465
@ -61,17 +61,9 @@ void ConnListModel::handleLogBlockedIp(const LogEntryBlockedIp &entry, qint64 un
|
||||
|
||||
doBeginInsertRows(row, row);
|
||||
|
||||
if (statManager()->logBlockedIp(entry, unixTime)) {
|
||||
++m_connBlockInc;
|
||||
}
|
||||
statManager()->logBlockedIp(entry, unixTime);
|
||||
|
||||
doEndInsertRows();
|
||||
|
||||
constexpr int connBlockIncMax = 100;
|
||||
if (m_connBlockInc >= connBlockIncMax) {
|
||||
m_connBlockInc = 0;
|
||||
statManager()->deleteOldConnBlock();
|
||||
}
|
||||
}
|
||||
|
||||
int ConnListModel::columnCount(const QModelIndex &parent) const
|
||||
|
@ -102,8 +102,6 @@ private:
|
||||
bool m_blockedMode = false;
|
||||
bool m_resolveAddress = false;
|
||||
|
||||
int m_connBlockInc = 999999999; // to trigger on first check
|
||||
|
||||
StatManager *m_statManager = nullptr;
|
||||
AppInfoCache *m_appInfoCache = nullptr;
|
||||
HostInfoCache *m_hostInfoCache = nullptr;
|
||||
|
@ -459,10 +459,14 @@ bool RpcManager::processStatManagerRpc(
|
||||
args.value(0).toLongLong(), args.value(1).toUInt(), args.value(2).toUInt());
|
||||
return true;
|
||||
case Control::Rpc_StatManager_connBlockAdded:
|
||||
emit statManager()->connBlockAdded();
|
||||
if (auto sm = qobject_cast<StatManagerRpc *>(statManager())) {
|
||||
sm->onConnBlockAdded();
|
||||
}
|
||||
return true;
|
||||
case Control::Rpc_StatManager_connRemoved:
|
||||
emit statManager()->connRemoved();
|
||||
if (auto sm = qobject_cast<StatManagerRpc *>(statManager())) {
|
||||
sm->onConnRemoved();
|
||||
}
|
||||
return true;
|
||||
case Control::Rpc_StatManager_appTrafTotalsResetted:
|
||||
emit statManager()->appTrafTotalsResetted();
|
||||
|
@ -6,7 +6,8 @@
|
||||
#include "../rpc/rpcmanager.h"
|
||||
|
||||
StatManagerRpc::StatManagerRpc(const QString &filePath, FortManager *fortManager, QObject *parent) :
|
||||
StatManager(filePath, fortManager->quotaManager(), parent, SqliteDb::OpenDefaultReadOnly)
|
||||
StatManager(filePath, fortManager->quotaManager(), parent, SqliteDb::OpenDefaultReadOnly),
|
||||
m_fortManager(fortManager)
|
||||
{
|
||||
}
|
||||
|
||||
@ -39,3 +40,15 @@ bool StatManagerRpc::clearTraffic()
|
||||
{
|
||||
return rpcManager()->doOnServer(Control::Rpc_StatManager_clearTraffic);
|
||||
}
|
||||
|
||||
void StatManagerRpc::onConnBlockAdded()
|
||||
{
|
||||
setupConnBlockId();
|
||||
emit connBlockAdded();
|
||||
}
|
||||
|
||||
void StatManagerRpc::onConnRemoved()
|
||||
{
|
||||
setupConnBlockId();
|
||||
emit connRemoved();
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ public:
|
||||
public slots:
|
||||
bool clearTraffic() override;
|
||||
|
||||
void onConnBlockAdded();
|
||||
void onConnRemoved();
|
||||
|
||||
private:
|
||||
FortManager *m_fortManager = nullptr;
|
||||
};
|
||||
|
@ -342,6 +342,12 @@ bool StatManager::logBlockedIp(const LogEntryBlockedIp &entry, qint64 unixTime)
|
||||
ok = (appId != INVALID_APP_ID);
|
||||
if (ok) {
|
||||
ok = createConnBlock(entry, unixTime, appId);
|
||||
|
||||
constexpr int connBlockIncMax = 100;
|
||||
if (++m_connBlockInc >= connBlockIncMax) {
|
||||
m_connBlockInc = 0;
|
||||
deleteOldConnBlock();
|
||||
}
|
||||
}
|
||||
|
||||
sqliteDb()->endTransaction(ok);
|
||||
@ -380,8 +386,6 @@ bool StatManager::deleteOldConnBlock()
|
||||
|
||||
deleteRangeConnBlock(m_connBlockIdMin, m_connBlockIdMin + oldCount);
|
||||
|
||||
emit connRemoved();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,6 @@ public:
|
||||
|
||||
virtual bool deleteStatApp(qint64 appId);
|
||||
|
||||
bool deleteOldConnBlock();
|
||||
virtual bool deleteConn(qint64 rowIdTo, bool blocked);
|
||||
virtual bool deleteConnAll();
|
||||
|
||||
@ -78,11 +77,13 @@ signals:
|
||||
public slots:
|
||||
virtual bool clearTraffic();
|
||||
|
||||
protected:
|
||||
void setupConnBlockId();
|
||||
|
||||
private:
|
||||
using QStmtList = QList<SqliteStmt *>;
|
||||
|
||||
void setupTrafDate();
|
||||
void setupConnBlockId();
|
||||
|
||||
void setupByConf();
|
||||
|
||||
@ -103,6 +104,8 @@ private:
|
||||
void clearCachedAppId(const QString &appPath);
|
||||
void clearAppIdCache();
|
||||
|
||||
bool deleteOldConnBlock();
|
||||
|
||||
qint64 getAppId(const QString &appPath);
|
||||
qint64 createAppId(const QString &appPath, qint64 unixTime);
|
||||
qint64 getOrCreateAppId(const QString &appPath, qint64 unixTime = 0, bool blocked = false);
|
||||
@ -142,6 +145,8 @@ private:
|
||||
quint8 m_activePeriodToHour = 0;
|
||||
quint8 m_activePeriodToMinute = 0;
|
||||
|
||||
int m_connBlockInc = 999999999; // to trigger on first check
|
||||
|
||||
qint32 m_trafHour = 0;
|
||||
qint32 m_trafDay = 0;
|
||||
qint32 m_trafMonth = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user