mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:46:41 +00:00
UI: Prepare Zones conf.
This commit is contained in:
parent
77dd3c1e7f
commit
d6623703a4
@ -229,6 +229,11 @@ RESOURCES += \
|
||||
stat/stat-migrations.qrc \
|
||||
util/app/app-migrations.qrc
|
||||
|
||||
# Zone
|
||||
OTHER_FILES += zone/data/*.json
|
||||
|
||||
RESOURCES += zone/data/fort_zone_data.qrc
|
||||
|
||||
# Shadow Build: Copy i18n/ to build path
|
||||
!equals(PWD, $${OUT_PWD}) {
|
||||
i18n.files = $$files(i18n/*.qm)
|
||||
|
@ -24,7 +24,7 @@ Q_LOGGING_CATEGORY(CLOG_CONF_MANAGER, "fort.confManager")
|
||||
#define logWarning() qCWarning(CLOG_CONF_MANAGER,)
|
||||
#define logCritical() qCCritical(CLOG_CONF_MANAGER,)
|
||||
|
||||
#define DATABASE_USER_VERSION 5
|
||||
#define DATABASE_USER_VERSION 6
|
||||
|
||||
namespace {
|
||||
|
||||
@ -174,6 +174,30 @@ const char * const sqlUpdateAppResetGroup =
|
||||
" WHERE app_group_id = ?1;"
|
||||
;
|
||||
|
||||
bool migrateFunc(SqliteDb *db, int version, void *ctx)
|
||||
{
|
||||
if (version != DATABASE_USER_VERSION)
|
||||
return true;
|
||||
|
||||
Q_UNUSED(ctx)
|
||||
|
||||
if (version == 6) {
|
||||
// Add TAS-IX zone
|
||||
db->execute(
|
||||
"INSERT INTO zone(name, enabled, zone_type, url, form_data) VALUES"
|
||||
" ('Local Addresses', 1, 'local', NULL, NULL),"
|
||||
" ('TAS-IX Addresses', 1, 'bgp',"
|
||||
" 'http://mrlg.tas-ix.uz/index.cgi',"
|
||||
" 'router=cisco&pass1=&query=1&arg=');"
|
||||
|
||||
"INSERT INTO address_group_zone(addr_group_id, zone_id, include) VALUES"
|
||||
" (1, 1, 0), (1, 2, 0);"
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ConfManager::ConfManager(const QString &filePath,
|
||||
@ -224,8 +248,8 @@ bool ConfManager::initialize()
|
||||
|
||||
m_sqliteDb->execute(sqlPragmas);
|
||||
|
||||
if (!m_sqliteDb->migrate(":/conf/migrations",
|
||||
DATABASE_USER_VERSION, true, true)) {
|
||||
if (!m_sqliteDb->migrate(":/conf/migrations", DATABASE_USER_VERSION,
|
||||
true, true, &migrateFunc)) {
|
||||
logCritical() << "Migration error"
|
||||
<< m_sqliteDb->filePath();
|
||||
return false;
|
||||
@ -675,7 +699,7 @@ bool ConfManager::saveToDb(const FirewallConf &conf)
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< (rowExists ? addrGroup->id() : QVariant())
|
||||
<< orderIndex++
|
||||
<< orderIndex
|
||||
<< addrGroup->includeAll()
|
||||
<< addrGroup->excludeAll()
|
||||
<< addrGroup->includeText()
|
||||
|
@ -1,3 +1,14 @@
|
||||
CREATE TABLE zone(
|
||||
zone_id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
enabled BOOLEAN NOT NULL,
|
||||
zone_type TEXT NOT NULL,
|
||||
url TEXT,
|
||||
form_data TEXT,
|
||||
last_run INTEGER,
|
||||
last_success INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE address_group(
|
||||
addr_group_id INTEGER PRIMARY KEY,
|
||||
order_index INTEGER NOT NULL,
|
||||
@ -7,6 +18,12 @@ CREATE TABLE address_group(
|
||||
exclude_text TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE address_group_zone(
|
||||
addr_group_id INTEGER NOT NULL,
|
||||
zone_id INTEGER NOT NULL,
|
||||
include BOOLEAN NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE app_group(
|
||||
app_group_id INTEGER PRIMARY KEY,
|
||||
order_index INTEGER NOT NULL,
|
||||
|
@ -65,7 +65,7 @@ QString Ip4Range::toText() const
|
||||
return text;
|
||||
}
|
||||
|
||||
bool Ip4Range::fromText(const QString &text, int emptyMask)
|
||||
bool Ip4Range::fromText(const QString &text, int emptyNetMask)
|
||||
{
|
||||
clear();
|
||||
|
||||
@ -83,7 +83,7 @@ bool Ip4Range::fromText(const QString &text, int emptyMask)
|
||||
continue;
|
||||
|
||||
quint32 from, to;
|
||||
if (!parseAddressMask(lineTrimmed, from, to, emptyMask)) {
|
||||
if (!parseAddressMask(lineTrimmed, from, to, emptyNetMask)) {
|
||||
setErrorLineNo(lineNo);
|
||||
return false;
|
||||
}
|
||||
@ -105,7 +105,7 @@ bool Ip4Range::fromText(const QString &text, int emptyMask)
|
||||
// Parse "127.0.0.0-127.255.255.255" or "127.0.0.0/24" or "127.0.0.0"
|
||||
bool Ip4Range::parseAddressMask(const QStringRef &line,
|
||||
quint32 &from, quint32 &to,
|
||||
int emptyMask)
|
||||
int emptyNetMask)
|
||||
{
|
||||
const QRegularExpression re(R"(([\d.]+)\s*([/-]?)\s*(\S*))");
|
||||
const QRegularExpressionMatch match = re.match(line);
|
||||
@ -145,7 +145,7 @@ bool Ip4Range::parseAddressMask(const QStringRef &line,
|
||||
}
|
||||
} else if (sep == QLatin1Char('/')) { // e.g. "127.0.0.0/24", "127.0.0.0"
|
||||
bool ok = true;
|
||||
const int nbits = mask.isEmpty() ? emptyMask : mask.toInt(&ok);
|
||||
const int nbits = mask.isEmpty() ? emptyNetMask : mask.toInt(&ok);
|
||||
|
||||
if (!ok || nbits < 0 || nbits > 32) {
|
||||
setErrorMessage(tr("Bad mask"));
|
||||
|
@ -50,7 +50,7 @@ public slots:
|
||||
QString toText() const;
|
||||
|
||||
// Parse IPv4 ranges from text
|
||||
bool fromText(const QString &text, int emptyMask = 32);
|
||||
bool fromText(const QString &text, int emptyNetMask = 32);
|
||||
|
||||
private:
|
||||
void setErrorLineNo(int lineNo);
|
||||
@ -58,7 +58,7 @@ private:
|
||||
|
||||
bool parseAddressMask(const QStringRef &line,
|
||||
quint32 &from, quint32 &to,
|
||||
int emptyMask = 32);
|
||||
int emptyNetMask = 32);
|
||||
|
||||
void fillRange(const ip4range_map_t &ipRangeMap, int pairSize);
|
||||
|
||||
|
6
src/ui/zone/data/fort_zone_data.qrc
Normal file
6
src/ui/zone/data/fort_zone_data.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>zone_types.json</file>
|
||||
<file>zone_urls.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
16
src/ui/zone/data/zone_types.json
Normal file
16
src/ui/zone/data/zone_types.json
Normal file
@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"id": "local",
|
||||
"title": "Local",
|
||||
"description": "Local addresses",
|
||||
"local": true
|
||||
},
|
||||
{
|
||||
"id": "bgp",
|
||||
"title": "BGP",
|
||||
"description": "BGP table",
|
||||
"sort": true,
|
||||
"regex": "^*??([^\\s]+)",
|
||||
"emptyNetMask": 24
|
||||
}
|
||||
]
|
7
src/ui/zone/data/zone_urls.json
Normal file
7
src/ui/zone/data/zone_urls.json
Normal file
@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"title": "TAS-IX Addresses",
|
||||
"url": "http://mrlg.tas-ix.uz/index.cgi",
|
||||
"formData": "router=cisco&pass1=&query=1&arg="
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user