UI: Programs: Prepare Wildcard paths

This commit is contained in:
Nodir Temirkhodjaev 2023-12-03 12:06:43 +03:00
parent 5528bfd3b0
commit c6cb09a6d1
14 changed files with 140 additions and 97 deletions

View File

@ -2,9 +2,9 @@
bool App::isEqual(const App &o) const
{
return useGroupPerm == o.useGroupPerm && applyChild == o.applyChild && lanOnly == o.lanOnly
&& logBlocked == o.logBlocked && logConn == o.logConn && blocked == o.blocked
&& killProcess == o.killProcess && groupIndex == o.groupIndex
&& appOriginPath == o.appOriginPath && appPath == o.appPath
&& endTime == o.endTime;
return isWildcard == o.isWildcard && useGroupPerm == o.useGroupPerm
&& applyChild == o.applyChild && lanOnly == o.lanOnly && logBlocked == o.logBlocked
&& logConn == o.logConn && blocked == o.blocked && killProcess == o.killProcess
&& groupIndex == o.groupIndex && appOriginPath == o.appOriginPath
&& appPath == o.appPath && endTime == o.endTime;
}

View File

@ -10,14 +10,15 @@ public:
bool isEqual(const App &o) const;
public:
bool useGroupPerm = true;
bool applyChild = false;
bool lanOnly = false;
bool logBlocked = true;
bool logConn = true;
bool blocked = false;
bool killProcess = false;
bool alerted = false;
bool isWildcard : 1 = false;
bool useGroupPerm : 1 = true;
bool applyChild : 1 = false;
bool lanOnly : 1 = false;
bool logBlocked : 1 = true;
bool logConn : 1 = true;
bool blocked : 1 = false;
bool killProcess : 1 = false;
bool alerted : 1 = false;
int groupIndex = 0;

View File

@ -37,7 +37,7 @@ namespace {
const QLoggingCategory LC("conf");
constexpr int DATABASE_USER_VERSION = 24;
constexpr int DATABASE_USER_VERSION = 25;
constexpr int APP_END_TIMER_INTERVAL_MIN = 100;
constexpr int APP_END_TIMER_INTERVAL_MAX = 24 * 60 * 60 * 1000; // 1 day
@ -118,6 +118,7 @@ const char *const sqlSelectAppById = "SELECT"
" g.order_index as group_index,"
" t.origin_path,"
" t.path,"
" t.is_wildcard,"
" t.use_group_perm,"
" t.apply_child,"
" t.lan_only,"
@ -135,6 +136,7 @@ const char *const sqlSelectApps = "SELECT"
" g.order_index as group_index,"
" t.origin_path,"
" t.path,"
" t.is_wildcard,"
" t.use_group_perm,"
" t.apply_child,"
" t.lan_only,"
@ -151,7 +153,8 @@ const char *const sqlSelectMinEndApp = "SELECT MIN(end_time) FROM app"
" WHERE end_time != 0 AND blocked = 0;";
const char *const sqlSelectEndedApps = "SELECT t.app_id, g.order_index as group_index,"
" t.origin_path, t.path, t.name, t.use_group_perm,"
" t.origin_path, t.path, t.name,"
" t.is_wildcard, t.use_group_perm,"
" t.apply_child, t.lan_only, t.log_blocked, t.log_conn"
" FROM app t"
" JOIN app_group g ON g.app_group_id = t.app_group_id"
@ -160,15 +163,16 @@ const char *const sqlSelectEndedApps = "SELECT t.app_id, g.order_index as group_
const char *const sqlSelectAppIdByPath = "SELECT app_id FROM app WHERE path = ?1;";
const char *const sqlUpsertApp = "INSERT INTO app(app_group_id, origin_path, path, name,"
" use_group_perm, apply_child, lan_only,"
" is_wildcard, use_group_perm, apply_child, lan_only,"
" log_blocked, log_conn, blocked, kill_process,"
" end_time, creat_time)"
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)"
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9,"
" ?10, ?11, ?12, ?13, ?14)"
" ON CONFLICT(path) DO UPDATE"
" SET app_group_id = ?1, origin_path = ?2, name = ?4,"
" use_group_perm = ?5, apply_child = ?6,"
" lan_only = ?7, log_blocked = ?8, log_conn = ?9,"
" blocked = ?10, kill_process = ?11, end_time = ?12"
" is_wildcard = ?5, use_group_perm = ?6, apply_child = ?7,"
" lan_only = ?8, log_blocked = ?9, log_conn = ?10,"
" blocked = ?11, kill_process = ?12, end_time = ?13"
" RETURNING app_id;";
const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id) VALUES(?1);";
@ -179,9 +183,10 @@ const char *const sqlDeleteAppAlert = "DELETE FROM app_alert WHERE app_id = ?1;"
const char *const sqlUpdateApp = "UPDATE app"
" SET app_group_id = ?2, origin_path = ?3, name = ?4,"
" use_group_perm = ?5, apply_child = ?6, lan_only = ?7,"
" log_blocked = ?8, log_conn = ?9,"
" blocked = ?10, kill_process = ?11, end_time = ?12"
" is_wildcard = ?5, use_group_perm = ?6,"
" apply_child = ?7, lan_only = ?8,"
" log_blocked = ?9, log_conn = ?10,"
" blocked = ?11, kill_process = ?12, end_time = ?13"
" WHERE app_id = ?1;";
const char *const sqlUpdateAppName = "UPDATE app SET name = ?2 WHERE app_id = ?1;";
@ -966,9 +971,9 @@ bool ConfManager::updateApp(const App &app)
sqliteDb()->beginTransaction();
const auto vars = QVariantList()
<< app.appId << appGroup->id() << app.appOriginPath << app.appName << app.useGroupPerm
<< app.applyChild << app.lanOnly << app.logBlocked << app.logConn << app.blocked
<< app.killProcess << (!app.endTime.isNull() ? app.endTime : QVariant());
<< app.appId << appGroup->id() << app.appOriginPath << app.appName << app.isWildcard
<< app.useGroupPerm << app.applyChild << app.lanOnly << app.logBlocked << app.logConn
<< app.blocked << app.killProcess << (!app.endTime.isNull() ? app.endTime : QVariant());
sqliteDb()->executeEx(sqlUpdateApp, vars, 0, &ok);
if (ok) {
@ -1044,14 +1049,15 @@ bool ConfManager::walkApps(const std::function<walkAppsCallback> &func)
app.groupIndex = stmt.columnInt(0);
app.appOriginPath = stmt.columnText(1);
app.appPath = stmt.columnText(2);
app.useGroupPerm = stmt.columnBool(3);
app.applyChild = stmt.columnBool(4);
app.lanOnly = stmt.columnBool(5);
app.logBlocked = stmt.columnBool(6);
app.logConn = stmt.columnBool(7);
app.blocked = stmt.columnBool(8);
app.killProcess = stmt.columnBool(9);
app.alerted = stmt.columnBool(10);
app.isWildcard = stmt.columnBool(3);
app.useGroupPerm = stmt.columnBool(4);
app.applyChild = stmt.columnBool(5);
app.lanOnly = stmt.columnBool(6);
app.logBlocked = stmt.columnBool(7);
app.logConn = stmt.columnBool(8);
app.blocked = stmt.columnBool(9);
app.killProcess = stmt.columnBool(10);
app.alerted = stmt.columnBool(11);
if (!func(app))
return false;
@ -1075,11 +1081,12 @@ void ConfManager::updateAppEndTimes()
app.appOriginPath = stmt.columnText(2);
app.appPath = stmt.columnText(3);
app.appName = stmt.columnText(4);
app.useGroupPerm = stmt.columnBool(5);
app.applyChild = stmt.columnBool(6);
app.lanOnly = stmt.columnBool(7);
app.logBlocked = stmt.columnBool(8);
app.logConn = stmt.columnBool(9);
app.isWildcard = stmt.columnBool(5);
app.useGroupPerm = stmt.columnBool(6);
app.applyChild = stmt.columnBool(7);
app.lanOnly = stmt.columnBool(8);
app.logBlocked = stmt.columnBool(9);
app.logConn = stmt.columnBool(10);
app.blocked = true;
app.killProcess = false;
@ -1331,9 +1338,9 @@ bool ConfManager::addOrUpdateApp(const App &app)
sqliteDb()->beginTransaction();
const auto vars = QVariantList()
<< appGroup->id() << app.appOriginPath << app.appPath << app.appName << app.useGroupPerm
<< app.applyChild << app.lanOnly << app.logBlocked << app.logConn << app.blocked
<< app.killProcess << (!app.endTime.isNull() ? app.endTime : QVariant())
<< appGroup->id() << app.appOriginPath << app.appPath << app.appName << app.isWildcard
<< app.useGroupPerm << app.applyChild << app.lanOnly << app.logBlocked << app.logConn
<< app.blocked << app.killProcess << (!app.endTime.isNull() ? app.endTime : QVariant())
<< QDateTime::currentDateTime();
const auto appIdVar = sqliteDb()->executeEx(sqlUpsertApp, vars, 1, &ok);
@ -1372,14 +1379,15 @@ bool ConfManager::updateDriverAppBlocked(
app.groupIndex = stmt.columnInt(0);
app.appOriginPath = stmt.columnText(1);
app.appPath = stmt.columnText(2);
app.useGroupPerm = stmt.columnBool(3);
app.applyChild = stmt.columnBool(4);
app.lanOnly = stmt.columnBool(5);
app.logBlocked = stmt.columnBool(6);
app.logConn = stmt.columnBool(7);
app.blocked = stmt.columnBool(8);
app.killProcess = stmt.columnBool(9);
const bool wasAlerted = stmt.columnBool(10);
app.isWildcard = stmt.columnBool(3);
app.useGroupPerm = stmt.columnBool(4);
app.applyChild = stmt.columnBool(5);
app.lanOnly = stmt.columnBool(6);
app.logBlocked = stmt.columnBool(7);
app.logConn = stmt.columnBool(8);
app.blocked = stmt.columnBool(9);
app.killProcess = stmt.columnBool(10);
const bool wasAlerted = stmt.columnBool(11);
if (!updateDriverCheckUpdateApp(app, blocked, killProcess, /*force=*/wasAlerted))
return false;

View File

@ -196,7 +196,9 @@ const AppGroup *FirewallConf::appGroupAt(int index) const
static const AppGroup g_nullAppGroup;
return &g_nullAppGroup;
}
return appGroups().at(index);
const AppGroup *appGroup = appGroups().at(index);
return appGroup;
}
QStringList FirewallConf::appGroupNames() const

View File

@ -126,6 +126,7 @@ CREATE TABLE app(
origin_path TEXT,
path TEXT NOT NULL,
name TEXT,
is_wildcard BOOLEAN NOT NULL DEFAULT 0,
use_group_perm BOOLEAN NOT NULL DEFAULT 1,
apply_child BOOLEAN NOT NULL DEFAULT 0,
lan_only BOOLEAN NOT NULL DEFAULT 0,

View File

@ -66,7 +66,7 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector<qint64> &
m_appIdList = appIdList;
const bool isSingleSelection = (appIdList.size() <= 1);
const bool isPathEditable = isSingleSelection && appRow.appId == 0;
const bool isPathEditable = isSingleSelection && (appRow.appId == 0 || appRow.isWildcard);
m_editPath->setText(isSingleSelection ? appRow.appOriginPath : QString());
m_editPath->setReadOnly(!isPathEditable);

View File

@ -131,6 +131,7 @@ void ProgramsWindow::retranslateUi()
m_actBlockApp->setText(tr("Block"));
m_actKillApp->setText(tr("Kill Process"));
m_actAddApp->setText(tr("Add"));
m_actAddWildcard->setText(tr("Add Wildcard"));
m_actEditApp->setText(tr("Edit"));
m_actRemoveApp->setText(tr("Remove"));
m_actPurgeApps->setText(tr("Purge Obsolete"));
@ -257,6 +258,9 @@ void ProgramsWindow::setupEditMenu()
m_actAddApp = editMenu->addAction(IconCache::icon(":/icons/add.png"), QString());
m_actAddApp->setShortcut(Qt::Key_Plus);
m_actAddWildcard = editMenu->addAction(QString());
m_actAddWildcard->setShortcut(QKeyCombination(Qt::CTRL, Qt::Key_N));
m_actEditApp = editMenu->addAction(IconCache::icon(":/icons/pencil.png"), QString());
m_actEditApp->setShortcut(Qt::Key_Enter);
@ -277,6 +281,7 @@ void ProgramsWindow::setupEditMenu()
connect(m_actKillApp, &QAction::triggered, this,
[&] { updateSelectedApps(/*blocked=*/true, /*killProcess=*/true); });
connect(m_actAddApp, &QAction::triggered, this, &ProgramsWindow::addNewProgram);
connect(m_actAddWildcard, &QAction::triggered, this, &ProgramsWindow::addNewWildcard);
connect(m_actEditApp, &QAction::triggered, this, &ProgramsWindow::editSelectedPrograms);
connect(m_actRemoveApp, &QAction::triggered, this, [&] {
windowManager()->showConfirmBox(
@ -419,6 +424,14 @@ void ProgramsWindow::addNewProgram()
openAppEditForm({});
}
void ProgramsWindow::addNewWildcard()
{
AppRow appRow;
appRow.isWildcard = true;
openAppEditForm(appRow);
}
void ProgramsWindow::editSelectedPrograms()
{
const QVector<qint64> appIdList = selectedAppIdList();

View File

@ -71,6 +71,7 @@ private:
void setupAppEditForm();
void addNewProgram();
void addNewWildcard();
void editSelectedPrograms();
void openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList = {});
@ -91,6 +92,7 @@ private:
QAction *m_actBlockApp = nullptr;
QAction *m_actKillApp = nullptr;
QAction *m_actAddApp = nullptr;
QAction *m_actAddWildcard = nullptr;
QAction *m_actEditApp = nullptr;
QAction *m_actRemoveApp = nullptr;
QAction *m_actPurgeApps = nullptr;

View File

@ -7,6 +7,7 @@
<file>icons/application-window-96.png</file>
<file>icons/application_double.png</file>
<file>icons/arrow_refresh_small.png</file>
<file>icons/asterisk_orange.png</file>
<file>icons/bin_closed.png</file>
<file>icons/cancel.png</file>
<file>icons/chart_bar.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -212,7 +212,7 @@ QVariant AppListModel::dataDecoration(const QModelIndex &index) const
switch (column) {
case 0:
return appInfoCache()->appIcon(appRow.appPath);
return appIcon(appRow);
case 1:
return appStateIcon(appRow);
}
@ -270,6 +270,15 @@ QVariant AppListModel::appGroupColor(const AppRow &appRow) const
return {};
}
QIcon AppListModel::appIcon(const AppRow &appRow) const
{
if (appRow.isWildcard) {
return IconCache::icon(":/icons/asterisk_orange.png");
}
return appInfoCache()->appIcon(appRow.appPath);
}
QString AppListModel::appStateText(const AppRow &appRow)
{
if (appRow.killProcess)
@ -310,16 +319,17 @@ bool AppListModel::updateAppRow(const QString &sql, const QVariantList &vars, Ap
appRow.appOriginPath = stmt.columnText(2);
appRow.appPath = stmt.columnText(3);
appRow.appName = stmt.columnText(4);
appRow.useGroupPerm = stmt.columnBool(5);
appRow.applyChild = stmt.columnBool(6);
appRow.lanOnly = stmt.columnBool(7);
appRow.logBlocked = stmt.columnBool(8);
appRow.logConn = stmt.columnBool(9);
appRow.blocked = stmt.columnBool(10);
appRow.killProcess = stmt.columnBool(11);
appRow.alerted = stmt.columnBool(12);
appRow.endTime = stmt.columnDateTime(13);
appRow.creatTime = stmt.columnDateTime(14);
appRow.isWildcard = stmt.columnBool(5);
appRow.useGroupPerm = stmt.columnBool(6);
appRow.applyChild = stmt.columnBool(7);
appRow.lanOnly = stmt.columnBool(8);
appRow.logBlocked = stmt.columnBool(9);
appRow.logConn = stmt.columnBool(10);
appRow.blocked = stmt.columnBool(11);
appRow.killProcess = stmt.columnBool(12);
appRow.alerted = stmt.columnBool(13);
appRow.endTime = stmt.columnDateTime(14);
appRow.creatTime = stmt.columnDateTime(15);
return true;
}
@ -374,6 +384,7 @@ QString AppListModel::sqlBase() const
" t.origin_path,"
" t.path,"
" t.name,"
" t.is_wildcard,"
" t.use_group_perm,"
" t.apply_child,"
" t.lan_only,"
@ -404,7 +415,7 @@ QString AppListModel::sqlOrderColumn() const
case 0: // Name
columnsStr = "t.name " + sqlOrderAsc() + ", t.path";
break;
case 1: // State
case 1: // Action
columnsStr = "alerted DESC, t.kill_process, t.blocked " + sqlOrderAsc() + ", t.app_id";
break;
case 2: // Group
@ -413,8 +424,8 @@ QString AppListModel::sqlOrderColumn() const
case 3: // File Path
columnsStr = "t.path";
break;
default: // Creation Time
columnsStr = "t.app_id"; // App ID
default: // Creation Time ~ App ID
columnsStr = "t.app_id";
break;
}

View File

@ -67,6 +67,8 @@ private:
QVariant appGroupName(const AppRow &appRow) const;
QVariant appGroupColor(const AppRow &appRow) const;
QIcon appIcon(const AppRow &appRow) const;
static QString appStateText(const AppRow &appRow);
static QColor appStateColor(const AppRow &appRow);
static QIcon appStateIcon(const AppRow &appRow);

View File

@ -18,9 +18,9 @@ ConfManagerRpc::ConfManagerRpc(const QString &filePath, QObject *parent) :
bool ConfManagerRpc::addApp(const App &app)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_addApp,
{ app.useGroupPerm, app.applyChild, app.lanOnly, app.logBlocked, app.logConn,
app.blocked, app.killProcess, app.groupIndex, app.appOriginPath, app.appPath,
app.appName, app.endTime });
{ app.isWildcard, app.useGroupPerm, app.applyChild, app.lanOnly, app.logBlocked,
app.logConn, app.blocked, app.killProcess, app.groupIndex, app.appOriginPath,
app.appPath, app.appName, app.endTime });
}
bool ConfManagerRpc::deleteApp(qint64 appId)
@ -36,9 +36,9 @@ bool ConfManagerRpc::purgeApps()
bool ConfManagerRpc::updateApp(const App &app)
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfManager_updateApp,
{ app.useGroupPerm, app.applyChild, app.lanOnly, app.logBlocked, app.logConn,
app.blocked, app.killProcess, app.groupIndex, app.appId, app.appOriginPath,
app.appPath, app.appName, app.endTime });
{ app.isWildcard, app.useGroupPerm, app.applyChild, app.lanOnly, app.logBlocked,
app.logConn, app.blocked, app.killProcess, app.groupIndex, app.appId,
app.appOriginPath, app.appPath, app.appName, app.endTime });
}
bool ConfManagerRpc::updateAppBlocked(qint64 appId, bool blocked, bool killProcess)

View File

@ -71,18 +71,19 @@ bool processConfManager_addApp(
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
{
App app;
app.useGroupPerm = p.args.value(0).toBool();
app.applyChild = p.args.value(1).toBool();
app.lanOnly = p.args.value(2).toBool();
app.logBlocked = p.args.value(3).toBool();
app.logConn = p.args.value(4).toBool();
app.blocked = p.args.value(5).toBool();
app.killProcess = p.args.value(6).toBool();
app.groupIndex = p.args.value(7).toInt();
app.appOriginPath = p.args.value(8).toString();
app.appPath = p.args.value(9).toString();
app.appName = p.args.value(10).toString();
app.endTime = p.args.value(11).toDateTime();
app.isWildcard = p.args.value(0).toBool();
app.useGroupPerm = p.args.value(1).toBool();
app.applyChild = p.args.value(2).toBool();
app.lanOnly = p.args.value(3).toBool();
app.logBlocked = p.args.value(4).toBool();
app.logConn = p.args.value(5).toBool();
app.blocked = p.args.value(6).toBool();
app.killProcess = p.args.value(7).toBool();
app.groupIndex = p.args.value(8).toInt();
app.appOriginPath = p.args.value(9).toString();
app.appPath = p.args.value(10).toString();
app.appName = p.args.value(11).toString();
app.endTime = p.args.value(12).toDateTime();
return confManager->addApp(app);
}
@ -103,19 +104,20 @@ bool processConfManager_updateApp(
ConfManager *confManager, const ProcessCommandArgs &p, QVariantList & /*resArgs*/)
{
App app;
app.useGroupPerm = p.args.value(0).toBool();
app.applyChild = p.args.value(1).toBool();
app.lanOnly = p.args.value(2).toBool();
app.logBlocked = p.args.value(3).toBool();
app.logConn = p.args.value(4).toBool();
app.blocked = p.args.value(5).toBool();
app.killProcess = p.args.value(6).toBool();
app.groupIndex = p.args.value(7).toInt();
app.appId = p.args.value(8).toLongLong();
app.appOriginPath = p.args.value(9).toString();
app.appPath = p.args.value(10).toString();
app.appName = p.args.value(11).toString();
app.endTime = p.args.value(12).toDateTime();
app.isWildcard = p.args.value(0).toBool();
app.useGroupPerm = p.args.value(1).toBool();
app.applyChild = p.args.value(2).toBool();
app.lanOnly = p.args.value(3).toBool();
app.logBlocked = p.args.value(4).toBool();
app.logConn = p.args.value(5).toBool();
app.blocked = p.args.value(6).toBool();
app.killProcess = p.args.value(7).toBool();
app.groupIndex = p.args.value(8).toInt();
app.appId = p.args.value(9).toLongLong();
app.appOriginPath = p.args.value(10).toString();
app.appPath = p.args.value(11).toString();
app.appName = p.args.value(12).toString();
app.endTime = p.args.value(13).toDateTime();
return confManager->updateApp(app);
}