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 <QCoreApplication>
|
||||
|
||||
#include "../util/net/netutil.h"
|
||||
#include "addressgroup.h"
|
||||
#include "appgroup.h"
|
||||
|
||||
@ -237,3 +240,14 @@ void FirewallConf::fromVariant(const QVariant &v)
|
||||
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;
|
||||
void fromVariant(const QVariant &v);
|
||||
|
||||
void setupDefault();
|
||||
|
||||
signals:
|
||||
void provBootChanged();
|
||||
void filterEnabledChanged();
|
||||
|
@ -282,11 +282,17 @@ void FortManager::setFirewallConfToEdit(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());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isNewConf) {
|
||||
conf->setupDefault();
|
||||
}
|
||||
|
||||
return updateDriverConf(conf);
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ QString FortSettings::confBackupFilePath() const
|
||||
return confFilePath() + QLatin1String(".backup");
|
||||
}
|
||||
|
||||
bool FortSettings::readConf(FirewallConf &conf)
|
||||
bool FortSettings::readConf(FirewallConf &conf, bool &isNew)
|
||||
{
|
||||
const QString filePath = confFilePath();
|
||||
const QString backupFilePath = confBackupFilePath();
|
||||
@ -140,8 +140,9 @@ bool FortSettings::readConf(FirewallConf &conf)
|
||||
const bool fileExists = FileUtil::fileExists(filePath);
|
||||
const bool backupFileExists = FileUtil::fileExists(backupFilePath);
|
||||
|
||||
return (!(fileExists || backupFileExists)
|
||||
|| (fileExists && tryToReadConf(conf, filePath))
|
||||
isNew = !(fileExists || backupFileExists);
|
||||
|
||||
return (isNew || (fileExists && tryToReadConf(conf, filePath))
|
||||
|| tryToReadConf(conf, backupFilePath))
|
||||
&& readConfIni(conf); // read flags at the end to use correct app groups
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ signals:
|
||||
void errorMessageChanged();
|
||||
|
||||
public slots:
|
||||
bool readConf(FirewallConf &conf);
|
||||
bool readConf(FirewallConf &conf, bool &isNew);
|
||||
bool writeConf(const FirewallConf &conf);
|
||||
|
||||
bool readConfIni(FirewallConf &conf) const;
|
||||
|
@ -36,13 +36,7 @@ ColumnLayout {
|
||||
Layout.fillHeight: true
|
||||
|
||||
textArea {
|
||||
placeholderText: "
|
||||
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
|
||||
"
|
||||
placeholderText: netUtil.localIpv4Networks().join('\n')
|
||||
text: addressGroup.text
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#endif
|
||||
#include "../util/net/ip4range.h"
|
||||
#include "../util/net/netdownloader.h"
|
||||
#include "../util/net/netutil.h"
|
||||
|
||||
TaskTasix::TaskTasix(QObject *parent) :
|
||||
TaskDownloader(parent)
|
||||
@ -92,11 +93,7 @@ QStringList TaskTasix::parseTasixBuffer(const QByteArray &buffer)
|
||||
|
||||
// Include local networks
|
||||
if (!list.isEmpty()) {
|
||||
list.append("10.0.0.0/8");
|
||||
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");
|
||||
list.append(NetUtil::localIpv4Networks());
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -96,3 +96,15 @@ QString NetUtil::getHostName(const QString &address)
|
||||
|
||||
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);
|
||||
|
||||
static QString getHostName(const QString &address);
|
||||
Q_INVOKABLE static QString getHostName(const QString &address);
|
||||
|
||||
Q_INVOKABLE static QStringList localIpv4Networks();
|
||||
|
||||
private:
|
||||
static int first0Bit(quint32 u);
|
||||
|
Loading…
Reference in New Issue
Block a user