mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:57:24 +00:00
UI: Use default conf on 1st start.
This commit is contained in:
parent
dd44c65d31
commit
09142f664b
@ -1,5 +1,8 @@
|
|||||||
#include "firewallconf.h"
|
#include "firewallconf.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include "../util/net/netutil.h"
|
||||||
#include "addressgroup.h"
|
#include "addressgroup.h"
|
||||||
#include "appgroup.h"
|
#include "appgroup.h"
|
||||||
|
|
||||||
@ -237,3 +240,14 @@ void FirewallConf::fromVariant(const QVariant &v)
|
|||||||
addAppGroup(appGroup);
|
addAppGroup(appGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FirewallConf::setupDefault()
|
||||||
|
{
|
||||||
|
m_ipInclude->setUseAll(true);
|
||||||
|
m_ipExclude->setText(NetUtil::localIpv4Networks().join('\n'));
|
||||||
|
|
||||||
|
AppGroup *appGroup = new AppGroup();
|
||||||
|
appGroup->setName("Main");
|
||||||
|
appGroup->setAllowText(qApp->applicationDirPath() + '/');
|
||||||
|
addAppGroup(appGroup);
|
||||||
|
}
|
||||||
|
@ -97,6 +97,8 @@ public:
|
|||||||
QVariant toVariant() const;
|
QVariant toVariant() const;
|
||||||
void fromVariant(const QVariant &v);
|
void fromVariant(const QVariant &v);
|
||||||
|
|
||||||
|
void setupDefault();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void provBootChanged();
|
void provBootChanged();
|
||||||
void filterEnabledChanged();
|
void filterEnabledChanged();
|
||||||
|
@ -282,11 +282,17 @@ void FortManager::setFirewallConfToEdit(FirewallConf *conf)
|
|||||||
|
|
||||||
bool FortManager::loadSettings(FirewallConf *conf)
|
bool FortManager::loadSettings(FirewallConf *conf)
|
||||||
{
|
{
|
||||||
if (!m_fortSettings->readConf(*conf)) {
|
bool isNewConf;
|
||||||
|
|
||||||
|
if (!m_fortSettings->readConf(*conf, isNewConf)) {
|
||||||
showErrorBox("Load Settings: " + m_fortSettings->errorMessage());
|
showErrorBox("Load Settings: " + m_fortSettings->errorMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNewConf) {
|
||||||
|
conf->setupDefault();
|
||||||
|
}
|
||||||
|
|
||||||
return updateDriverConf(conf);
|
return updateDriverConf(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ QString FortSettings::confBackupFilePath() const
|
|||||||
return confFilePath() + QLatin1String(".backup");
|
return confFilePath() + QLatin1String(".backup");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FortSettings::readConf(FirewallConf &conf)
|
bool FortSettings::readConf(FirewallConf &conf, bool &isNew)
|
||||||
{
|
{
|
||||||
const QString filePath = confFilePath();
|
const QString filePath = confFilePath();
|
||||||
const QString backupFilePath = confBackupFilePath();
|
const QString backupFilePath = confBackupFilePath();
|
||||||
@ -140,8 +140,9 @@ bool FortSettings::readConf(FirewallConf &conf)
|
|||||||
const bool fileExists = FileUtil::fileExists(filePath);
|
const bool fileExists = FileUtil::fileExists(filePath);
|
||||||
const bool backupFileExists = FileUtil::fileExists(backupFilePath);
|
const bool backupFileExists = FileUtil::fileExists(backupFilePath);
|
||||||
|
|
||||||
return (!(fileExists || backupFileExists)
|
isNew = !(fileExists || backupFileExists);
|
||||||
|| (fileExists && tryToReadConf(conf, filePath))
|
|
||||||
|
return (isNew || (fileExists && tryToReadConf(conf, filePath))
|
||||||
|| tryToReadConf(conf, backupFilePath))
|
|| tryToReadConf(conf, backupFilePath))
|
||||||
&& readConfIni(conf); // read flags at the end to use correct app groups
|
&& readConfIni(conf); // read flags at the end to use correct app groups
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ signals:
|
|||||||
void errorMessageChanged();
|
void errorMessageChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool readConf(FirewallConf &conf);
|
bool readConf(FirewallConf &conf, bool &isNew);
|
||||||
bool writeConf(const FirewallConf &conf);
|
bool writeConf(const FirewallConf &conf);
|
||||||
|
|
||||||
bool readConfIni(FirewallConf &conf) const;
|
bool readConfIni(FirewallConf &conf) const;
|
||||||
|
@ -36,13 +36,7 @@ ColumnLayout {
|
|||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
textArea {
|
textArea {
|
||||||
placeholderText: "
|
placeholderText: netUtil.localIpv4Networks().join('\n')
|
||||||
10.0.0.0/8
|
|
||||||
127.0.0.0/8
|
|
||||||
169.254.0.0/16
|
|
||||||
172.16.0.0/12
|
|
||||||
192.168.0.0/16
|
|
||||||
"
|
|
||||||
text: addressGroup.text
|
text: addressGroup.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "../util/net/ip4range.h"
|
#include "../util/net/ip4range.h"
|
||||||
#include "../util/net/netdownloader.h"
|
#include "../util/net/netdownloader.h"
|
||||||
|
#include "../util/net/netutil.h"
|
||||||
|
|
||||||
TaskTasix::TaskTasix(QObject *parent) :
|
TaskTasix::TaskTasix(QObject *parent) :
|
||||||
TaskDownloader(parent)
|
TaskDownloader(parent)
|
||||||
@ -92,11 +93,7 @@ QStringList TaskTasix::parseTasixBuffer(const QByteArray &buffer)
|
|||||||
|
|
||||||
// Include local networks
|
// Include local networks
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
list.append("10.0.0.0/8");
|
list.append(NetUtil::localIpv4Networks());
|
||||||
list.append("127.0.0.0/8");
|
|
||||||
list.append("169.254.0.0/16");
|
|
||||||
list.append("172.16.0.0/12");
|
|
||||||
list.append("192.168.0.0/16");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -96,3 +96,15 @@ QString NetUtil::getHostName(const QString &address)
|
|||||||
|
|
||||||
return QString::fromWCharArray(hostName);
|
return QString::fromWCharArray(hostName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList NetUtil::localIpv4Networks()
|
||||||
|
{
|
||||||
|
static QStringList list = QStringList()
|
||||||
|
<< "10.0.0.0/8"
|
||||||
|
<< "127.0.0.0/8"
|
||||||
|
<< "169.254.0.0/16"
|
||||||
|
<< "172.16.0.0/12"
|
||||||
|
<< "192.168.0.0/16";
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
@ -22,7 +22,9 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE static QString formatDataSize(qint64 bytes, int precision = 2);
|
Q_INVOKABLE static QString formatDataSize(qint64 bytes, int precision = 2);
|
||||||
|
|
||||||
static QString getHostName(const QString &address);
|
Q_INVOKABLE static QString getHostName(const QString &address);
|
||||||
|
|
||||||
|
Q_INVOKABLE static QStringList localIpv4Networks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int first0Bit(quint32 u);
|
static int first0Bit(quint32 u);
|
||||||
|
Loading…
Reference in New Issue
Block a user