mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:25:20 +00:00
UI: Connections: Add "Auto Scroll" option.
This commit is contained in:
parent
dd415e57bf
commit
ed942cc4d4
@ -74,6 +74,7 @@ void ConnectionsWindow::onRetranslateUi()
|
|||||||
m_btLogOptions->setText(tr("Options"));
|
m_btLogOptions->setText(tr("Options"));
|
||||||
m_cbLogAllowedIp->setText(tr("Collect allowed connections"));
|
m_cbLogAllowedIp->setText(tr("Collect allowed connections"));
|
||||||
m_cbLogBlockedIp->setText(tr("Collect blocked connections"));
|
m_cbLogBlockedIp->setText(tr("Collect blocked connections"));
|
||||||
|
m_cbAutoScroll->setText(tr("Auto Scroll"));
|
||||||
|
|
||||||
connListModel()->refresh();
|
connListModel()->refresh();
|
||||||
|
|
||||||
@ -153,9 +154,11 @@ void ConnectionsWindow::setupLogOptions()
|
|||||||
{
|
{
|
||||||
setupLogAllowedIp();
|
setupLogAllowedIp();
|
||||||
setupLogBlockedIp();
|
setupLogBlockedIp();
|
||||||
|
setupAutoScroll();
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
const QList<QWidget *> menuWidgets = { m_cbLogAllowedIp, m_cbLogBlockedIp };
|
const QList<QWidget *> menuWidgets = { m_cbLogAllowedIp, m_cbLogBlockedIp,
|
||||||
|
ControlUtil::createSeparator(), m_cbAutoScroll };
|
||||||
auto layout = ControlUtil::createLayoutByWidgets(menuWidgets);
|
auto layout = ControlUtil::createLayoutByWidgets(menuWidgets);
|
||||||
|
|
||||||
auto menu = ControlUtil::createMenuByLayout(layout, this);
|
auto menu = ControlUtil::createMenuByLayout(layout, this);
|
||||||
@ -188,6 +191,31 @@ void ConnectionsWindow::setupLogBlockedIp()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionsWindow::setupAutoScroll()
|
||||||
|
{
|
||||||
|
const auto syncAutoScroll = [&] {
|
||||||
|
if (settings()->connAutoScroll()) {
|
||||||
|
connect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView,
|
||||||
|
&QAbstractItemView::scrollToBottom);
|
||||||
|
} else {
|
||||||
|
disconnect(connListModel(), &QAbstractItemModel::rowsInserted, m_connListView,
|
||||||
|
&QAbstractItemView::scrollToBottom);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
syncAutoScroll();
|
||||||
|
|
||||||
|
m_cbAutoScroll = ControlUtil::createCheckBox(
|
||||||
|
settings()->connAutoScroll(), [&, syncAutoScroll](bool checked) {
|
||||||
|
if (settings()->connAutoScroll() == checked)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settings()->setConnAutoScroll(checked);
|
||||||
|
|
||||||
|
syncAutoScroll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionsWindow::setupTableConnList()
|
void ConnectionsWindow::setupTableConnList()
|
||||||
{
|
{
|
||||||
m_connListView = new TableView();
|
m_connListView = new TableView();
|
||||||
|
@ -36,6 +36,7 @@ private:
|
|||||||
void setupLogOptions();
|
void setupLogOptions();
|
||||||
void setupLogAllowedIp();
|
void setupLogAllowedIp();
|
||||||
void setupLogBlockedIp();
|
void setupLogBlockedIp();
|
||||||
|
void setupAutoScroll();
|
||||||
void setupTableConnList();
|
void setupTableConnList();
|
||||||
void setupTableConnListHeader();
|
void setupTableConnListHeader();
|
||||||
void setupAppInfoRow();
|
void setupAppInfoRow();
|
||||||
@ -64,6 +65,7 @@ private:
|
|||||||
QPushButton *m_btLogOptions = nullptr;
|
QPushButton *m_btLogOptions = nullptr;
|
||||||
QCheckBox *m_cbLogAllowedIp = nullptr;
|
QCheckBox *m_cbLogAllowedIp = nullptr;
|
||||||
QCheckBox *m_cbLogBlockedIp = nullptr;
|
QCheckBox *m_cbLogBlockedIp = nullptr;
|
||||||
|
QCheckBox *m_cbAutoScroll = nullptr;
|
||||||
TableView *m_connListView = nullptr;
|
TableView *m_connListView = nullptr;
|
||||||
AppInfoRow *m_appInfoRow = nullptr;
|
AppInfoRow *m_appInfoRow = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -220,6 +220,9 @@ public:
|
|||||||
QByteArray connListHeader() const { return iniByteArray("connWindow/connListHeader"); }
|
QByteArray connListHeader() const { return iniByteArray("connWindow/connListHeader"); }
|
||||||
void setConnListHeader(const QByteArray &v) { setIniValue("connWindow/connListHeader", v); }
|
void setConnListHeader(const QByteArray &v) { setIniValue("connWindow/connListHeader", v); }
|
||||||
|
|
||||||
|
bool connAutoScroll() const { return iniBool("connWindow/autoScroll"); }
|
||||||
|
void setConnAutoScroll(bool on) { setIniValue("connWindow/autoScroll", on); }
|
||||||
|
|
||||||
qint32 quotaDayAlerted() const { return iniInt("quota/dayAlerted"); }
|
qint32 quotaDayAlerted() const { return iniInt("quota/dayAlerted"); }
|
||||||
void setQuotaDayAlerted(qint32 v) { setIniValue("quota/dayAlerted", v); }
|
void setQuotaDayAlerted(qint32 v) { setIniValue("quota/dayAlerted", v); }
|
||||||
|
|
||||||
|
@ -32,10 +32,25 @@ void ConnListModel::setAppInfoCache(AppInfoCache *v)
|
|||||||
|
|
||||||
void ConnListModel::handleLogBlockedIp(const LogEntryBlockedIp &entry, qint64 unixTime)
|
void ConnListModel::handleLogBlockedIp(const LogEntryBlockedIp &entry, qint64 unixTime)
|
||||||
{
|
{
|
||||||
|
const int row = rowCount();
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
|
|
||||||
if (statManager()->logBlockedIp(entry.inbound(), entry.blockReason(), entry.ipProto(),
|
if (statManager()->logBlockedIp(entry.inbound(), entry.blockReason(), entry.ipProto(),
|
||||||
entry.localPort(), entry.remotePort(), entry.localIp(), entry.remoteIp(),
|
entry.localPort(), entry.remotePort(), entry.localIp(), entry.remoteIp(),
|
||||||
entry.pid(), entry.path(), unixTime)) {
|
entry.pid(), entry.path(), unixTime)) {
|
||||||
reset();
|
invalidateRowCache();
|
||||||
|
++m_connBlockInc;
|
||||||
|
}
|
||||||
|
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
constexpr int connBlockIncMax = 100;
|
||||||
|
if (m_connBlockInc >= connBlockIncMax) {
|
||||||
|
m_connBlockInc = 0;
|
||||||
|
if (statManager()->deleteOldConnBlock()) {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +159,6 @@ void ConnListModel::deleteConn(qint64 connId, bool blocked, int row)
|
|||||||
|
|
||||||
if (statManager()->deleteConn(connId, blocked)) {
|
if (statManager()->deleteConn(connId, blocked)) {
|
||||||
invalidateRowCache();
|
invalidateRowCache();
|
||||||
removeRow(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
@ -72,6 +72,8 @@ protected:
|
|||||||
QString sqlBase() const override;
|
QString sqlBase() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_connBlockInc = 999999999; // to trigger on first check
|
||||||
|
|
||||||
StatManager *m_statManager = nullptr;
|
StatManager *m_statManager = nullptr;
|
||||||
AppInfoCache *m_appInfoCache = nullptr;
|
AppInfoCache *m_appInfoCache = nullptr;
|
||||||
|
|
||||||
|
@ -363,11 +363,6 @@ bool StatManager::logBlockedIp(bool inbound, quint8 blockReason, quint8 ipProto,
|
|||||||
ok = (connId > 0);
|
ok = (connId > 0);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
ok = createConnBlock(connId, blockReason);
|
ok = createConnBlock(connId, blockReason);
|
||||||
constexpr int connBlockIncMax = 100;
|
|
||||||
if (ok && ++m_connBlockInc > connBlockIncMax) {
|
|
||||||
m_connBlockInc = 0;
|
|
||||||
deleteOldConnBlock(m_conf->blockedIpKeepCount());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,6 +384,18 @@ void StatManager::deleteStatApp(qint64 appId)
|
|||||||
m_sqliteDb->commitTransaction();
|
m_sqliteDb->commitTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StatManager::deleteOldConnBlock()
|
||||||
|
{
|
||||||
|
const int keepCount = m_conf->blockedIpKeepCount();
|
||||||
|
const qint64 connId =
|
||||||
|
m_sqliteDb->executeEx(StatSql::sqlSelectOldConnBlock, { keepCount }).toLongLong();
|
||||||
|
if (connId > 0) {
|
||||||
|
deleteRangeConnBlock(1, connId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool StatManager::deleteConn(qint64 connId, bool blocked)
|
bool StatManager::deleteConn(qint64 connId, bool blocked)
|
||||||
{
|
{
|
||||||
m_sqliteDb->beginTransaction();
|
m_sqliteDb->beginTransaction();
|
||||||
@ -562,15 +569,6 @@ bool StatManager::createConnBlock(qint64 connId, quint8 blockReason)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatManager::deleteOldConnBlock(int keepCount)
|
|
||||||
{
|
|
||||||
const qint64 connId =
|
|
||||||
m_sqliteDb->executeEx(StatSql::sqlSelectOldConnBlock, { keepCount }).toLongLong();
|
|
||||||
if (connId > 0) {
|
|
||||||
deleteRangeConnBlock(1, connId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StatManager::deleteRangeConnBlock(qint64 connIdFrom, qint64 connIdTo)
|
void StatManager::deleteRangeConnBlock(qint64 connIdFrom, qint64 connIdTo)
|
||||||
{
|
{
|
||||||
deleteAppStmtList(getId2Stmt(StatSql::sqlSelectDeletedRangeConnAppPaths, connIdFrom, connIdTo),
|
deleteAppStmtList(getId2Stmt(StatSql::sqlSelectDeletedRangeConnAppPaths, connIdFrom, connIdTo),
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
void deleteStatApp(qint64 appId);
|
void deleteStatApp(qint64 appId);
|
||||||
|
|
||||||
|
bool deleteOldConnBlock();
|
||||||
bool deleteConn(qint64 connId, bool blocked);
|
bool deleteConn(qint64 connId, bool blocked);
|
||||||
void deleteConns();
|
void deleteConns();
|
||||||
|
|
||||||
@ -87,7 +88,6 @@ private:
|
|||||||
qint64 createConn(bool inbound, quint8 ipProto, quint16 localPort, quint16 remotePort,
|
qint64 createConn(bool inbound, quint8 ipProto, quint16 localPort, quint16 remotePort,
|
||||||
quint32 localIp, quint32 remoteIp, quint32 pid, qint64 unixTime, qint64 appId);
|
quint32 localIp, quint32 remoteIp, quint32 pid, qint64 unixTime, qint64 appId);
|
||||||
bool createConnBlock(qint64 connId, quint8 blockReason);
|
bool createConnBlock(qint64 connId, quint8 blockReason);
|
||||||
void deleteOldConnBlock(int keepCount);
|
|
||||||
void deleteRangeConnBlock(qint64 connIdFrom, qint64 connIdTo);
|
void deleteRangeConnBlock(qint64 connIdFrom, qint64 connIdTo);
|
||||||
|
|
||||||
void deleteAppStmtList(SqliteStmt *stmtAppPaths, const QStmtList &stmtList);
|
void deleteAppStmtList(SqliteStmt *stmtAppPaths, const QStmtList &stmtList);
|
||||||
@ -114,8 +114,6 @@ private:
|
|||||||
qint32 m_lastTrafMonth = 0;
|
qint32 m_lastTrafMonth = 0;
|
||||||
qint32 m_lastTick = 0;
|
qint32 m_lastTick = 0;
|
||||||
|
|
||||||
int m_connBlockInc = 999999999; // to trigger on first check
|
|
||||||
|
|
||||||
QuotaManager *m_quotaManager = nullptr;
|
QuotaManager *m_quotaManager = nullptr;
|
||||||
const FirewallConf *m_conf = nullptr;
|
const FirewallConf *m_conf = nullptr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user