2017-08-28 10:35:15 +00:00
|
|
|
#include "firewallconf.h"
|
|
|
|
|
2017-09-02 10:17:51 +00:00
|
|
|
#include "addressgroup.h"
|
2017-08-29 08:40:23 +00:00
|
|
|
#include "appgroup.h"
|
|
|
|
|
2017-08-28 10:35:15 +00:00
|
|
|
FirewallConf::FirewallConf(QObject *parent) :
|
|
|
|
QObject(parent),
|
2017-10-27 11:59:09 +00:00
|
|
|
m_provBoot(false),
|
2017-09-01 10:05:30 +00:00
|
|
|
m_filterEnabled(true),
|
2017-11-20 14:39:57 +00:00
|
|
|
m_resolveAddress(false),
|
2017-11-03 04:18:37 +00:00
|
|
|
m_logBlocked(false),
|
|
|
|
m_logStat(false),
|
2017-08-28 10:35:15 +00:00
|
|
|
m_appBlockAll(true),
|
2017-09-02 10:17:51 +00:00
|
|
|
m_appAllowAll(false),
|
2017-12-11 06:05:49 +00:00
|
|
|
m_trafHourKeepDays(DEFAULT_TRAF_HOUR_KEEP_DAYS),
|
|
|
|
m_trafDayKeepDays(DEFAULT_TRAF_DAY_KEEP_DAYS),
|
|
|
|
m_trafMonthKeepMonths(DEFAULT_TRAF_MONTH_KEEP_MONTHS),
|
|
|
|
m_trafUnit(UnitAdaptive),
|
2017-09-02 10:17:51 +00:00
|
|
|
m_ipInclude(new AddressGroup(this)),
|
|
|
|
m_ipExclude(new AddressGroup(this))
|
2017-08-28 10:35:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-27 11:59:09 +00:00
|
|
|
void FirewallConf::setProvBoot(bool provBoot)
|
|
|
|
{
|
|
|
|
if (m_provBoot != provBoot) {
|
|
|
|
m_provBoot = provBoot;
|
|
|
|
emit provBootChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 10:05:30 +00:00
|
|
|
void FirewallConf::setFilterEnabled(bool filterEnabled)
|
2017-08-28 10:35:15 +00:00
|
|
|
{
|
2017-09-01 10:05:30 +00:00
|
|
|
if (m_filterEnabled != filterEnabled) {
|
|
|
|
m_filterEnabled = filterEnabled;
|
|
|
|
emit filterEnabledChanged();
|
2017-08-28 10:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 14:39:57 +00:00
|
|
|
void FirewallConf::setResolveAddress(bool resolveAddress)
|
|
|
|
{
|
|
|
|
if (m_resolveAddress != resolveAddress) {
|
|
|
|
m_resolveAddress = resolveAddress;
|
|
|
|
emit resolveAddressChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 04:18:37 +00:00
|
|
|
void FirewallConf::setLogBlocked(bool logBlocked)
|
2017-08-28 10:35:15 +00:00
|
|
|
{
|
2017-11-03 04:18:37 +00:00
|
|
|
if (m_logBlocked != logBlocked) {
|
|
|
|
m_logBlocked = logBlocked;
|
|
|
|
emit logBlockedChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setLogStat(bool logStat)
|
|
|
|
{
|
|
|
|
if (m_logStat != logStat) {
|
|
|
|
m_logStat = logStat;
|
|
|
|
emit logStatChanged();
|
2017-08-28 10:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setAppBlockAll(bool appBlockAll)
|
|
|
|
{
|
|
|
|
if (m_appBlockAll != appBlockAll) {
|
|
|
|
m_appBlockAll = appBlockAll;
|
|
|
|
emit appBlockAllChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setAppAllowAll(bool appAllowAll)
|
|
|
|
{
|
|
|
|
if (m_appAllowAll != appAllowAll) {
|
|
|
|
m_appAllowAll = appAllowAll;
|
|
|
|
emit appAllowAllChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 06:05:49 +00:00
|
|
|
void FirewallConf::setTrafHourKeepDays(int trafHourKeepDays)
|
|
|
|
{
|
|
|
|
if (m_trafHourKeepDays != trafHourKeepDays) {
|
|
|
|
m_trafHourKeepDays = trafHourKeepDays;
|
|
|
|
emit trafHourKeepDaysChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setTrafDayKeepDays(int trafDayKeepDays)
|
|
|
|
{
|
|
|
|
if (m_trafDayKeepDays != trafDayKeepDays) {
|
|
|
|
m_trafDayKeepDays = trafDayKeepDays;
|
|
|
|
emit trafDayKeepDaysChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setTrafMonthKeepMonths(int trafMonthKeepMonths)
|
|
|
|
{
|
|
|
|
if (m_trafMonthKeepMonths != trafMonthKeepMonths) {
|
|
|
|
m_trafMonthKeepMonths = trafMonthKeepMonths;
|
|
|
|
emit trafMonthKeepMonthsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setTrafUnit(int trafUnit)
|
|
|
|
{
|
|
|
|
if (m_trafUnit != trafUnit) {
|
|
|
|
m_trafUnit = static_cast<TrafUnit>(trafUnit);
|
|
|
|
emit trafUnitChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 16:20:31 +00:00
|
|
|
quint32 FirewallConf::appGroupBits() const
|
|
|
|
{
|
|
|
|
quint32 groupBits = 0;
|
|
|
|
int i = 0;
|
|
|
|
foreach (const AppGroup *appGroup, appGroupsList()) {
|
|
|
|
if (appGroup->enabled()) {
|
|
|
|
groupBits |= (1 << i);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return groupBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::setAppGroupBits(quint32 groupBits)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
foreach (AppGroup *appGroup, appGroupsList()) {
|
|
|
|
appGroup->setEnabled(groupBits & (1 << i));
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 10:35:15 +00:00
|
|
|
QQmlListProperty<AppGroup> FirewallConf::appGroups()
|
|
|
|
{
|
|
|
|
return QQmlListProperty<AppGroup>(this, m_appGroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::addAppGroup(AppGroup *appGroup, int to)
|
|
|
|
{
|
|
|
|
appGroup->setParent(this);
|
|
|
|
|
|
|
|
if (to < 0) {
|
|
|
|
m_appGroups.append(appGroup);
|
|
|
|
} else {
|
|
|
|
m_appGroups.insert(to, appGroup);
|
|
|
|
}
|
|
|
|
emit appGroupsChanged();
|
|
|
|
}
|
|
|
|
|
2017-09-02 12:52:39 +00:00
|
|
|
void FirewallConf::addAppGroupByName(const QString &name)
|
|
|
|
{
|
|
|
|
AppGroup *appGroup = new AppGroup();
|
|
|
|
appGroup->setName(name);
|
|
|
|
addAppGroup(appGroup);
|
|
|
|
}
|
|
|
|
|
2017-08-28 10:35:15 +00:00
|
|
|
void FirewallConf::moveAppGroup(int from, int to)
|
|
|
|
{
|
|
|
|
m_appGroups.move(from, to);
|
|
|
|
emit appGroupsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::removeAppGroup(int from, int to)
|
|
|
|
{
|
|
|
|
for (int i = to; i >= from; --i) {
|
2017-09-02 12:52:39 +00:00
|
|
|
AppGroup *appGroup = m_appGroups.at(i);
|
|
|
|
appGroup->deleteLater();
|
|
|
|
|
2017-08-28 10:35:15 +00:00
|
|
|
m_appGroups.removeAt(i);
|
|
|
|
}
|
|
|
|
emit appGroupsChanged();
|
|
|
|
}
|
2017-08-30 07:03:28 +00:00
|
|
|
|
2017-09-03 03:48:29 +00:00
|
|
|
void FirewallConf::copyFlags(const FirewallConf &o)
|
|
|
|
{
|
2017-10-27 11:59:09 +00:00
|
|
|
setProvBoot(o.provBoot());
|
2017-09-03 03:48:29 +00:00
|
|
|
setFilterEnabled(o.filterEnabled());
|
|
|
|
ipInclude()->setUseAll(o.ipInclude()->useAll());
|
|
|
|
ipExclude()->setUseAll(o.ipExclude()->useAll());
|
|
|
|
setAppBlockAll(o.appBlockAll());
|
|
|
|
setAppAllowAll(o.appAllowAll());
|
|
|
|
setAppGroupBits(o.appGroupBits());
|
2017-11-20 14:39:57 +00:00
|
|
|
|
2017-12-11 06:05:49 +00:00
|
|
|
copyImmediateValues(o);
|
2017-09-03 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 06:05:49 +00:00
|
|
|
void FirewallConf::copyImmediateValues(const FirewallConf &o)
|
2017-09-04 11:39:15 +00:00
|
|
|
{
|
2017-11-20 14:39:57 +00:00
|
|
|
setResolveAddress(o.resolveAddress());
|
2017-11-03 04:18:37 +00:00
|
|
|
setLogBlocked(o.logBlocked());
|
2017-11-20 07:50:16 +00:00
|
|
|
setLogStat(o.logStat());
|
2017-12-11 06:05:49 +00:00
|
|
|
setTrafUnit(o.trafUnit());
|
2017-09-04 11:39:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 07:03:28 +00:00
|
|
|
QVariant FirewallConf::toVariant() const
|
|
|
|
{
|
|
|
|
QVariantMap map;
|
|
|
|
|
2017-09-02 10:17:51 +00:00
|
|
|
map["ipInclude"] = ipInclude()->toVariant();
|
|
|
|
map["ipExclude"] = ipExclude()->toVariant();
|
2017-08-30 07:03:28 +00:00
|
|
|
|
|
|
|
QVariantList groups;
|
|
|
|
foreach (const AppGroup *appGroup, appGroupsList()) {
|
|
|
|
groups.append(appGroup->toVariant());
|
|
|
|
}
|
|
|
|
map["appGroups"] = groups;
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirewallConf::fromVariant(const QVariant &v)
|
|
|
|
{
|
2017-09-09 00:07:38 +00:00
|
|
|
const QVariantMap map = v.toMap();
|
2017-08-30 07:03:28 +00:00
|
|
|
|
2017-09-02 10:17:51 +00:00
|
|
|
m_ipInclude->fromVariant(map["ipInclude"]);
|
|
|
|
m_ipExclude->fromVariant(map["ipExclude"]);
|
2017-08-30 07:03:28 +00:00
|
|
|
|
|
|
|
const QVariantList groups = map["appGroups"].toList();
|
|
|
|
foreach (const QVariant &gv, groups) {
|
|
|
|
AppGroup *appGroup = new AppGroup();
|
|
|
|
appGroup->fromVariant(gv);
|
|
|
|
addAppGroup(appGroup);
|
|
|
|
}
|
|
|
|
}
|