2017-09-19 04:46:49 +00:00
|
|
|
#include "tasktasix.h"
|
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
#include "../conf/addressgroup.h"
|
|
|
|
#include "../conf/firewallconf.h"
|
|
|
|
#ifndef TASK_TEST
|
|
|
|
#include "../fortmanager.h"
|
|
|
|
#endif
|
2017-11-07 07:42:42 +00:00
|
|
|
#include "../util/net/ip4range.h"
|
|
|
|
#include "../util/net/netdownloader.h"
|
2018-01-09 08:25:51 +00:00
|
|
|
#include "../util/net/netutil.h"
|
2017-09-19 04:46:49 +00:00
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
TaskTasix::TaskTasix(QObject *parent) :
|
2017-12-21 14:46:22 +00:00
|
|
|
TaskDownloader(parent)
|
2017-09-19 04:46:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:46:22 +00:00
|
|
|
void TaskTasix::setupDownloader()
|
2017-09-19 04:46:49 +00:00
|
|
|
{
|
2017-10-25 12:39:01 +00:00
|
|
|
downloader()->setUrl("http://mrlg.tas-ix.uz/index.cgi");
|
|
|
|
downloader()->setData("router=cisco&pass1=&query=1&arg=");
|
2017-09-19 04:46:49 +00:00
|
|
|
|
2017-12-21 14:46:22 +00:00
|
|
|
m_rangeText = QString();
|
2017-10-03 09:29:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 09:51:35 +00:00
|
|
|
void TaskTasix::downloadFinished(bool success)
|
2017-10-01 03:11:38 +00:00
|
|
|
{
|
2017-10-25 09:51:35 +00:00
|
|
|
if (success) {
|
2017-12-21 14:46:22 +00:00
|
|
|
m_rangeText = parseBuffer(downloader()->buffer());
|
2017-10-25 09:51:35 +00:00
|
|
|
success = !m_rangeText.isEmpty();
|
|
|
|
}
|
2017-10-03 09:29:54 +00:00
|
|
|
|
2017-11-07 09:50:26 +00:00
|
|
|
abort(success);
|
2017-10-01 03:11:38 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
bool TaskTasix::processResult(FortManager *fortManager)
|
2017-09-19 04:46:49 +00:00
|
|
|
{
|
2017-09-21 13:24:45 +00:00
|
|
|
#ifndef TASK_TEST
|
|
|
|
FirewallConf *conf = fortManager->firewallConf();
|
2017-10-25 09:51:35 +00:00
|
|
|
AddressGroup *ipExclude = conf->ipExclude();
|
2017-09-21 13:24:45 +00:00
|
|
|
|
2017-10-25 09:51:35 +00:00
|
|
|
if (ipExclude->text() == m_rangeText)
|
2017-09-21 13:46:34 +00:00
|
|
|
return false;
|
2017-09-21 13:24:45 +00:00
|
|
|
|
2017-10-25 09:51:35 +00:00
|
|
|
ipExclude->setText(m_rangeText);
|
2017-09-19 04:46:49 +00:00
|
|
|
|
2017-10-25 12:39:01 +00:00
|
|
|
return fortManager->saveOriginConf(successMessage());
|
2017-09-21 13:24:45 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(fortManager)
|
2017-09-19 04:46:49 +00:00
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
return true;
|
|
|
|
#endif
|
2017-09-19 04:46:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 12:39:01 +00:00
|
|
|
QString TaskTasix::parseBuffer(const QByteArray &buffer) const
|
|
|
|
{
|
|
|
|
const QStringList list = parseCustomBuffer(buffer);
|
|
|
|
|
|
|
|
if (list.isEmpty())
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
// Merge lines
|
|
|
|
Ip4Range ip4Range;
|
|
|
|
if (!ip4Range.fromText(list.join('\n')))
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
return ip4Range.toText();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList TaskTasix::parseTasixBuffer(const QByteArray &buffer)
|
2017-09-19 04:46:49 +00:00
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
|
|
|
|
// Parse lines
|
2017-10-03 09:29:54 +00:00
|
|
|
const QString text = QString::fromLatin1(buffer);
|
2017-10-25 12:39:01 +00:00
|
|
|
|
|
|
|
foreach (const QStringRef &line, text.splitRef(
|
|
|
|
'\n', QString::SkipEmptyParts)) {
|
2017-09-19 04:46:49 +00:00
|
|
|
if (!line.startsWith('*'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QStringRef addrStr = line.mid(3, 18);
|
|
|
|
const int lastSpacePos = addrStr.lastIndexOf(' ');
|
|
|
|
if (lastSpacePos > 0) {
|
|
|
|
addrStr = addrStr.left(lastSpacePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
addrStr = addrStr.trimmed();
|
|
|
|
if (addrStr.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list.append(addrStr.toString());
|
|
|
|
}
|
|
|
|
|
2017-10-03 08:26:16 +00:00
|
|
|
// Include local networks
|
2017-10-25 12:39:01 +00:00
|
|
|
if (!list.isEmpty()) {
|
2018-01-09 08:25:51 +00:00
|
|
|
list.append(NetUtil::localIpv4Networks());
|
2017-10-25 12:39:01 +00:00
|
|
|
}
|
2017-09-19 04:46:49 +00:00
|
|
|
|
2017-10-25 12:39:01 +00:00
|
|
|
return list;
|
2017-09-19 04:46:49 +00:00
|
|
|
}
|