mirror of
https://github.com/tnodir/fort
synced 2024-11-15 14:35:10 +00:00
UI: Zones: Add "Addresses" column.
This commit is contained in:
parent
9f7adf79e8
commit
273cbb5bea
@ -27,7 +27,7 @@ Q_LOGGING_CATEGORY(CLOG_CONF_MANAGER, "conf")
|
||||
#define logWarning() qCWarning(CLOG_CONF_MANAGER, )
|
||||
#define logCritical() qCCritical(CLOG_CONF_MANAGER, )
|
||||
|
||||
#define DATABASE_USER_VERSION 9
|
||||
#define DATABASE_USER_VERSION 10
|
||||
|
||||
namespace {
|
||||
|
||||
@ -130,8 +130,7 @@ const char *const sqlUpsertApp =
|
||||
" creat_time = ?6, end_time = ?7"
|
||||
" RETURNING app_id;";
|
||||
|
||||
const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id)"
|
||||
" VALUES(?1);";
|
||||
const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id) VALUES(?1);";
|
||||
|
||||
const char *const sqlDeleteApp = "DELETE FROM app WHERE app_id = ?1;";
|
||||
|
||||
@ -142,9 +141,7 @@ const char *const sqlUpdateApp = "UPDATE app"
|
||||
" blocked = ?5, end_time = ?6"
|
||||
" WHERE app_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateAppName = "UPDATE app"
|
||||
" SET name = ?2"
|
||||
" WHERE app_id = ?1;";
|
||||
const char *const sqlUpdateAppName = "UPDATE app SET name = ?2 WHERE app_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateAppResetGroup = "UPDATE app"
|
||||
" SET app_group_id = ?2"
|
||||
@ -167,18 +164,15 @@ const char *const sqlUpdateZone = "UPDATE zone"
|
||||
" source_code = ?5, url = ?6, form_data = ?7"
|
||||
" WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneName = "UPDATE zone"
|
||||
" SET name = ?2"
|
||||
" 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 sqlUpdateZoneEnabled = "UPDATE zone SET enabled = ?2 WHERE zone_id = ?1;";
|
||||
|
||||
const char *const sqlUpdateZoneResult = "UPDATE zone"
|
||||
" SET text_checksum = ?2, bin_checksum = ?3,"
|
||||
" source_modtime = ?4, last_run = ?5, last_success = ?6"
|
||||
" 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;";
|
||||
|
||||
bool migrateFunc(SqliteDb *db, int version, bool isNewDb, void *ctx)
|
||||
{
|
||||
@ -954,14 +948,14 @@ bool ConfManager::updateZoneEnabled(int zoneId, bool enabled)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||
bool ConfManager::updateZoneResult(int zoneId, int addressCount, const QString &textChecksum,
|
||||
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zoneId << textChecksum << binChecksum << sourceModTime << lastRun << lastSuccess;
|
||||
const auto vars = QVariantList() << zoneId << addressCount << textChecksum << binChecksum
|
||||
<< sourceModTime << lastRun << lastSuccess;
|
||||
|
||||
sqliteDb()->executeEx(sqlUpdateZoneResult, vars, 0, &ok);
|
||||
|
||||
|
@ -86,8 +86,9 @@ public:
|
||||
const QString &url, const QString &formData, bool enabled, bool customUrl);
|
||||
virtual bool updateZoneName(int zoneId, const QString &zoneName);
|
||||
virtual bool updateZoneEnabled(int zoneId, bool enabled);
|
||||
bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum,
|
||||
const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess);
|
||||
bool updateZoneResult(int zoneId, int addressCount, const QString &textChecksum,
|
||||
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess);
|
||||
|
||||
virtual bool checkPassword(const QString &password);
|
||||
|
||||
|
@ -6,6 +6,7 @@ CREATE TABLE zone(
|
||||
source_code TEXT NOT NULL,
|
||||
url TEXT,
|
||||
form_data TEXT,
|
||||
address_count INTEGER,
|
||||
text_checksum TEXT,
|
||||
bin_checksum TEXT,
|
||||
source_modtime INTEGER,
|
||||
|
@ -10,7 +10,7 @@
|
||||
"code": "winspyblock",
|
||||
"title": "WindowsSpyBlocker",
|
||||
"zoneType": "gen",
|
||||
"url": "https://github.com/crazy-max/WindowsSpyBlocker/blob/master/data/firewall/spy.txt",
|
||||
"url": "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/firewall/spy.txt",
|
||||
"formData": ""
|
||||
},
|
||||
{
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
#define ZONES_HEADER_VERSION 1
|
||||
#define ZONES_HEADER_VERSION 2
|
||||
|
||||
}
|
||||
|
||||
@ -335,11 +335,13 @@ void ZonesWindow::setupTableZonesHeader()
|
||||
|
||||
header->setSectionResizeMode(0, QHeaderView::Interactive);
|
||||
header->setSectionResizeMode(1, QHeaderView::Interactive);
|
||||
header->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||
header->setSectionResizeMode(2, QHeaderView::Interactive);
|
||||
header->setSectionResizeMode(3, QHeaderView::Stretch);
|
||||
header->setSectionResizeMode(4, QHeaderView::Stretch);
|
||||
|
||||
header->resizeSection(0, 350);
|
||||
header->resizeSection(1, 290);
|
||||
header->resizeSection(0, 300);
|
||||
header->resizeSection(1, 300);
|
||||
header->resizeSection(2, 90);
|
||||
}
|
||||
|
||||
void ZonesWindow::setupTableZonesChanged()
|
||||
|
@ -34,7 +34,7 @@ void ZoneListModel::initialize()
|
||||
|
||||
int ZoneListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 4;
|
||||
return parent.isValid() ? 0 : 5;
|
||||
}
|
||||
|
||||
QVariant ZoneListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
@ -46,8 +46,10 @@ QVariant ZoneListModel::headerData(int section, Qt::Orientation orientation, int
|
||||
case 1:
|
||||
return tr("Source");
|
||||
case 2:
|
||||
return tr("Last Run");
|
||||
return tr("Addresses");
|
||||
case 3:
|
||||
return tr("Last Run");
|
||||
case 4:
|
||||
return tr("Last Success");
|
||||
}
|
||||
}
|
||||
@ -88,8 +90,10 @@ QVariant ZoneListModel::dataDisplay(const QModelIndex &index) const
|
||||
return zoneSource.title();
|
||||
}
|
||||
case 2:
|
||||
return zoneRow.lastRun;
|
||||
return zoneRow.addressCount;
|
||||
case 3:
|
||||
return zoneRow.lastRun;
|
||||
case 4:
|
||||
return zoneRow.lastSuccess;
|
||||
}
|
||||
|
||||
@ -163,12 +167,12 @@ bool ZoneListModel::updateZoneEnabled(int zoneId, bool enabled)
|
||||
return confManager()->updateZoneEnabled(zoneId, enabled);
|
||||
}
|
||||
|
||||
bool ZoneListModel::updateZoneResult(int zoneId, const QString &textChecksum,
|
||||
bool ZoneListModel::updateZoneResult(int zoneId, int addressCount, const QString &textChecksum,
|
||||
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess)
|
||||
{
|
||||
return confManager()->updateZoneResult(
|
||||
zoneId, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess);
|
||||
zoneId, addressCount, textChecksum, binChecksum, sourceModTime, lastRun, lastSuccess);
|
||||
}
|
||||
|
||||
void ZoneListModel::deleteZone(int zoneId, int row)
|
||||
@ -182,8 +186,7 @@ void ZoneListModel::deleteZone(int zoneId, int row)
|
||||
|
||||
QString ZoneListModel::zoneNameById(int zoneId)
|
||||
{
|
||||
static const char *const sql = "SELECT name FROM zone"
|
||||
" WHERE zone_id = ?1;";
|
||||
static const char *const sql = "SELECT name FROM zone WHERE zone_id = ?1;";
|
||||
|
||||
SqliteStmt stmt;
|
||||
if (sqliteDb()->prepare(stmt, sql, { zoneId }) && stmt.step() == SqliteStmt::StepRow) {
|
||||
@ -215,11 +218,12 @@ bool ZoneListModel::updateTableRow(int row) const
|
||||
m_zoneRow.sourceCode = stmt.columnText(4);
|
||||
m_zoneRow.url = stmt.columnText(5);
|
||||
m_zoneRow.formData = stmt.columnText(6);
|
||||
m_zoneRow.textChecksum = stmt.columnText(7);
|
||||
m_zoneRow.binChecksum = stmt.columnText(8);
|
||||
m_zoneRow.sourceModTime = stmt.columnDateTime(9);
|
||||
m_zoneRow.lastRun = stmt.columnDateTime(10);
|
||||
m_zoneRow.lastSuccess = stmt.columnDateTime(11);
|
||||
m_zoneRow.addressCount = stmt.columnInt(7);
|
||||
m_zoneRow.textChecksum = stmt.columnText(8);
|
||||
m_zoneRow.binChecksum = stmt.columnText(9);
|
||||
m_zoneRow.sourceModTime = stmt.columnDateTime(10);
|
||||
m_zoneRow.lastRun = stmt.columnDateTime(11);
|
||||
m_zoneRow.lastSuccess = stmt.columnDateTime(12);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -234,6 +238,7 @@ QString ZoneListModel::sqlBase() const
|
||||
" source_code,"
|
||||
" url,"
|
||||
" form_data,"
|
||||
" address_count,"
|
||||
" text_checksum,"
|
||||
" bin_checksum,"
|
||||
" source_modtime,"
|
||||
|
@ -16,6 +16,8 @@ struct ZoneRow : TableRow
|
||||
|
||||
int zoneId = 0;
|
||||
|
||||
int addressCount = 0;
|
||||
|
||||
QString zoneName;
|
||||
QString sourceCode;
|
||||
|
||||
@ -59,8 +61,9 @@ public:
|
||||
const QString &url, const QString &formData, bool enabled, bool customUrl);
|
||||
bool updateZoneName(int zoneId, const QString &zoneName);
|
||||
bool updateZoneEnabled(int zoneId, bool enabled);
|
||||
bool updateZoneResult(int zoneId, const QString &textChecksum, const QString &binChecksum,
|
||||
const QDateTime &sourceModTime, const QDateTime &lastRun, const QDateTime &lastSuccess);
|
||||
bool updateZoneResult(int zoneId, int addressCount, const QString &textChecksum,
|
||||
const QString &binChecksum, const QDateTime &sourceModTime, const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess);
|
||||
void deleteZone(int zoneId, int row);
|
||||
|
||||
QString zoneNameById(int zoneId);
|
||||
|
@ -139,6 +139,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
|
||||
auto worker = zoneDownloader();
|
||||
|
||||
const auto zoneId = worker->zoneId();
|
||||
const auto addressCount = worker->addressCount();
|
||||
const auto textChecksum = worker->textChecksum();
|
||||
const auto binChecksum = worker->binChecksum();
|
||||
|
||||
@ -147,7 +148,7 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
|
||||
const auto lastSuccess = success ? now : worker->lastSuccess();
|
||||
|
||||
zoneListModel()->updateZoneResult(
|
||||
zoneId, textChecksum, binChecksum, sourceModTime, now, lastSuccess);
|
||||
zoneId, addressCount, textChecksum, binChecksum, sourceModTime, now, lastSuccess);
|
||||
|
||||
addSubResult(worker, success);
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ void TaskZoneDownloader::downloadFinished(bool success)
|
||||
&& (this->textChecksum() != textChecksum
|
||||
|| !FileUtil::fileExists(cacheFileBinPath()))) {
|
||||
setTextChecksum(textChecksum);
|
||||
|
||||
success = storeAddresses(list);
|
||||
setAddressCount(success ? list.size() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ public:
|
||||
int zoneId() const { return m_zoneId; }
|
||||
void setZoneId(int v) { m_zoneId = v; }
|
||||
|
||||
int addressCount() const { return m_addressCount; }
|
||||
void setAddressCount(int v) { m_addressCount = v; }
|
||||
|
||||
QString zoneName() const { return m_zoneName; }
|
||||
void setZoneName(const QString &v) { m_zoneName = v; }
|
||||
|
||||
@ -81,6 +84,8 @@ private:
|
||||
|
||||
int m_zoneId = 0;
|
||||
|
||||
int m_addressCount = 0;
|
||||
|
||||
QString m_zoneName;
|
||||
|
||||
QString m_url;
|
||||
|
@ -39,7 +39,9 @@ void NetDownloader::start()
|
||||
|
||||
m_process.start("curl", args, QIODevice::ReadOnly);
|
||||
|
||||
if (!m_process.waitForStarted()) {
|
||||
if (!m_process.waitForStarted(1000)) {
|
||||
qWarning() << "NetDownloader: Cannot start `curl`:" << m_process.errorString();
|
||||
|
||||
abort();
|
||||
}
|
||||
}
|
||||
@ -73,12 +75,17 @@ void NetDownloader::processError(QProcess::ProcessError error)
|
||||
if (m_aborted)
|
||||
return;
|
||||
|
||||
qWarning() << "NetDownloader: Cannot run `curl`:" << error;
|
||||
qWarning() << "NetDownloader: Cannot run `curl`:" << error << m_process.errorString();
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
void NetDownloader::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
abort(exitCode == 0 && exitStatus == QProcess::NormalExit && !m_buffer.isEmpty());
|
||||
const bool success = (exitCode == 0 && exitStatus == QProcess::NormalExit);
|
||||
if (!success) {
|
||||
qWarning() << "NetDownloader: `curl` error code:" << exitCode;
|
||||
}
|
||||
|
||||
abort(success && !m_buffer.isEmpty());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user