mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-21 10:47:16 +01:00
see #2163 pages that set up snmp crawler and crawler background process with progress log now work. Using QThread to run background process.
This commit is contained in:
parent
2eed260387
commit
68a5bc7ef8
80
src/libgui/QThreadLogger.cpp
Normal file
80
src/libgui/QThreadLogger.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "QThreadLogger.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
QThreadLogger::QThreadLogger() : Logger() {}
|
||||
|
||||
Logger& QThreadLogger::operator<< (char c)
|
||||
{
|
||||
emit lineReady(QString(c));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (char *str)
|
||||
{
|
||||
emit lineReady(QString(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (const char *str)
|
||||
{
|
||||
emit lineReady(QString(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (const std::string &str)
|
||||
{
|
||||
emit lineReady(QString(str.c_str()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (int i )
|
||||
{
|
||||
QString s; s.setNum(i);
|
||||
emit lineReady(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (long l )
|
||||
{
|
||||
QString s; s.setNum(l);
|
||||
emit lineReady(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Logger& QThreadLogger::operator<< (std::ostringstream &sstr)
|
||||
{
|
||||
emit lineReady(QString(sstr.str().c_str()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
53
src/libgui/QThreadLogger.h
Normal file
53
src/libgui/QThreadLogger.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _QTHREAD_LOGGER_H_
|
||||
#define _QTHREAD_LOGGER_H_
|
||||
|
||||
#include "fwbuilder/Logger.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QThreadLogger : public QObject, public libfwbuilder::Logger
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
|
||||
QThreadLogger();
|
||||
|
||||
virtual Logger& operator<< (char c) ;
|
||||
virtual Logger& operator<< (char *str) ;
|
||||
virtual Logger& operator<< (const char *str) ;
|
||||
virtual Logger& operator<< (const std::string &str) ;
|
||||
virtual Logger& operator<< (int i ) ;
|
||||
virtual Logger& operator<< (long l ) ;
|
||||
virtual Logger& operator<< (std::ostringstream &sstr);
|
||||
|
||||
signals:
|
||||
void lineReady(const QString &txt);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@ -196,6 +196,7 @@ HEADERS += ../../config.h \
|
||||
networkZoneManager.h \
|
||||
\
|
||||
ObjectDescriptor.h \
|
||||
QThreadLogger.h \
|
||||
\
|
||||
importAddressListWizard/ChooseObjectsPage.h \
|
||||
importAddressListWizard/CreateObjectsPage.h \
|
||||
@ -213,8 +214,8 @@ HEADERS += ../../config.h \
|
||||
snmpNetworkDiscoveryWizard/ND_SelectLibraryPage.h \
|
||||
snmpNetworkDiscoveryWizard/ND_SetupPage.h \
|
||||
snmpNetworkDiscoveryWizard/ND_SNMPParametersPage.h \
|
||||
snmpNetworkDiscoveryWizard/SNMPNetworkDiscoveryWizard.h
|
||||
|
||||
snmpNetworkDiscoveryWizard/SNMPNetworkDiscoveryWizard.h \
|
||||
snmpNetworkDiscoveryWizard/SNMPCrawlerThread.h
|
||||
|
||||
|
||||
SOURCES += ProjectPanel.cpp \
|
||||
@ -406,6 +407,7 @@ SOURCES += ProjectPanel.cpp \
|
||||
networkZoneManager.cpp \
|
||||
\
|
||||
ObjectDescriptor.cpp \
|
||||
QThreadLogger.cpp \
|
||||
\
|
||||
importAddressListWizard/ChooseObjectsPage.cpp \
|
||||
importAddressListWizard/CreateObjectsPage.cpp \
|
||||
@ -423,7 +425,9 @@ SOURCES += ProjectPanel.cpp \
|
||||
snmpNetworkDiscoveryWizard/ND_SelectLibraryPage.cpp \
|
||||
snmpNetworkDiscoveryWizard/ND_SetupPage.cpp \
|
||||
snmpNetworkDiscoveryWizard/ND_SNMPParametersPage.cpp \
|
||||
snmpNetworkDiscoveryWizard/SNMPNetworkDiscoveryWizard.cpp
|
||||
snmpNetworkDiscoveryWizard/SNMPNetworkDiscoveryWizard.cpp \
|
||||
snmpNetworkDiscoveryWizard/SNMPCrawlerThread.cpp
|
||||
|
||||
|
||||
FORMS = FWBMainWindow_q.ui \
|
||||
compileroutputpanel_q.ui \
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "global.h"
|
||||
#include "utils.h"
|
||||
#include "FWWindow.h"
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#include "ND_DiscoveryParametersPage.h"
|
||||
|
||||
@ -34,11 +35,31 @@ using namespace std;
|
||||
//using namespace libfwbuilder;
|
||||
|
||||
|
||||
#define DISCOVERY_DRUID_PREFIX "DiscoveryDruid/"
|
||||
#define DISCOVERY_DRUID_SNMPRECURSIVE "SNMPRecursive"
|
||||
#define DISCOVERY_DRUID_SNMPFOLLOWP2P "SNMPFollowP2P"
|
||||
#define DISCOVERY_DRUID_SNMPINCLUDEUNNUMBERED "SnmpIncludeUnnumbered"
|
||||
#define DISCOVERY_DRUID_SNMPDODNS "SNMPDoDNS"
|
||||
|
||||
ND_DiscoveryParametersPage::ND_DiscoveryParametersPage(QWidget *parent) : QWizardPage(parent)
|
||||
{
|
||||
m_dialog = new Ui::ND_DiscoveryParametersPage_q;
|
||||
m_dialog->setupUi(this);
|
||||
|
||||
m_dialog->snmpRecursive->setChecked(st->getBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPRECURSIVE));
|
||||
m_dialog->snmpFollowP2P->setChecked(st->getBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPFOLLOWP2P));
|
||||
m_dialog->snmpIncludeUnnumbered->setChecked(st->getBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINCLUDEUNNUMBERED));
|
||||
m_dialog->snmpDoDNS->setChecked(st->getBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPDODNS));
|
||||
|
||||
registerField("snmpRecursive", m_dialog->snmpRecursive);
|
||||
registerField("snmpFollowP2P", m_dialog->snmpFollowP2P);
|
||||
registerField("snmpIncludeUnnumbered", m_dialog->snmpIncludeUnnumbered);
|
||||
registerField("snmpDoDNS", m_dialog->snmpDoDNS);
|
||||
|
||||
}
|
||||
|
||||
void ND_DiscoveryParametersPage::initializePage()
|
||||
@ -47,3 +68,22 @@ void ND_DiscoveryParametersPage::initializePage()
|
||||
qDebug() << "ND_DiscoveryParametersPage::initializePage()";
|
||||
|
||||
}
|
||||
|
||||
bool ND_DiscoveryParametersPage::validatePage()
|
||||
{
|
||||
st->setBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPRECURSIVE,
|
||||
m_dialog->snmpRecursive->isChecked());
|
||||
st->setBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPFOLLOWP2P,
|
||||
m_dialog->snmpFollowP2P->isChecked());
|
||||
st->setBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINCLUDEUNNUMBERED,
|
||||
m_dialog->snmpIncludeUnnumbered->isChecked());
|
||||
st->setBool(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPDODNS,
|
||||
m_dialog->snmpDoDNS->isChecked());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ public:
|
||||
virtual ~ND_DiscoveryParametersPage() {}
|
||||
|
||||
virtual void initializePage();
|
||||
virtual bool validatePage();
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -24,14 +24,23 @@
|
||||
#include "global.h"
|
||||
#include "utils.h"
|
||||
#include "FWWindow.h"
|
||||
#include "utils.h"
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#include "ND_ProgressPage.h"
|
||||
#include "SNMPCrawlerThread.h"
|
||||
|
||||
#include "fwbuilder/snmp.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFile>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextCursor>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
using namespace std;
|
||||
//using namespace libfwbuilder;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
ND_ProgressPage::ND_ProgressPage(QWidget *parent) : QWizardPage(parent)
|
||||
@ -39,11 +48,174 @@ ND_ProgressPage::ND_ProgressPage(QWidget *parent) : QWizardPage(parent)
|
||||
m_dialog = new Ui::ND_ProgressPage_q;
|
||||
m_dialog->setupUi(this);
|
||||
|
||||
crawler = NULL;
|
||||
|
||||
QTextCursor cursor(m_dialog->discoveryLog->textCursor());
|
||||
normal_format = cursor.charFormat();
|
||||
|
||||
error_format = normal_format;
|
||||
error_format.setForeground(QBrush(Qt::red));
|
||||
error_format.setAnchorHref("http://somewhere.com");
|
||||
error_format.setAnchor(true);
|
||||
// weight must be between 0 and 99. Qt 4.4.1 does not seem to mind if
|
||||
// it is >99 (just caps it) but older versions assert
|
||||
error_format.setProperty(QTextFormat::FontWeight, 99);
|
||||
|
||||
warning_format = normal_format;
|
||||
warning_format.setForeground(QBrush(Qt::blue));
|
||||
warning_format.setProperty(QTextFormat::FontWeight, 99);
|
||||
warning_format.setAnchor(true);
|
||||
warning_format.setAnchorHref("http://somewhere.com");
|
||||
}
|
||||
|
||||
ND_ProgressPage::~ND_ProgressPage()
|
||||
{
|
||||
if (crawler)
|
||||
{
|
||||
stop();
|
||||
crawler->wait();
|
||||
delete crawler;
|
||||
}
|
||||
}
|
||||
|
||||
void ND_ProgressPage::initializePage()
|
||||
{
|
||||
if (fwbdebug)
|
||||
qDebug() << "ND_ProgressPage::initializePage()";
|
||||
if (fwbdebug) qDebug() << "ND_ProgressPage::initializePage()";
|
||||
|
||||
#ifdef HAVE_LIBSNMP
|
||||
QString seedHostName = field("seedHostName").toString();
|
||||
QString snmpInclAddr = field("snmpInAddr").toString();
|
||||
QString snmpInclMask = field("snmpInMask").toString();
|
||||
|
||||
bool snmpRecursive = field("snmpRecursive").toBool();
|
||||
bool snmpFollowP2P = field("snmpFollowP2P").toBool();
|
||||
// bool snmpIncludeUnnumbered = field("snmpIncludeUnnumbered").toBool();
|
||||
|
||||
QString snmpCommunity = field("snmpCommunity").toString();
|
||||
int snmpRetries = field("snmpRetries").toInt();
|
||||
int snmpTimeoutSec = field("snmpTimeout").toInt();
|
||||
|
||||
QString seedHostAddress = getAddrByName(seedHostName, AF_INET);
|
||||
InetAddr seedHostInetAddr = InetAddr( seedHostAddress.toLatin1().constData() );
|
||||
|
||||
vector<libfwbuilder::InetAddrMask> include_networks;
|
||||
|
||||
bool limit_scan = false;
|
||||
if ( ! snmpInclAddr.isEmpty() && ! snmpInclMask.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
InetAddrMask in(
|
||||
InetAddr(snmpInclAddr.toStdString()),
|
||||
InetAddr(snmpInclMask.toStdString())
|
||||
);
|
||||
include_networks.push_back(in);
|
||||
limit_scan = true;
|
||||
}
|
||||
catch (const FWException &ex)
|
||||
{
|
||||
//TODO: do something usefull
|
||||
}
|
||||
}
|
||||
|
||||
if (crawler != NULL) delete crawler;
|
||||
|
||||
crawler = new SNMPCrawlerThread(this,
|
||||
seedHostName,
|
||||
snmpCommunity,
|
||||
snmpRecursive,
|
||||
snmpFollowP2P,
|
||||
snmpRetries,
|
||||
snmpTimeoutSec,
|
||||
&include_networks);
|
||||
crawler->start();
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void ND_ProgressPage::cleanupPage()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void ND_ProgressPage::stop()
|
||||
{
|
||||
crawler->stop();
|
||||
}
|
||||
|
||||
|
||||
void ND_ProgressPage::logLine(const QString &buf)
|
||||
{
|
||||
if (buf.isEmpty()) return;
|
||||
|
||||
foreach(QString line, buf.trimmed().split("\n"))
|
||||
{
|
||||
QTextCharFormat format = normal_format;
|
||||
|
||||
if (line.contains("Parser error"))
|
||||
format = error_format;
|
||||
|
||||
if (line.contains("Parser warning"))
|
||||
format = warning_format;
|
||||
|
||||
if (line.contains("SNMP error, status 2 Timeout"))
|
||||
format = warning_format;
|
||||
|
||||
QString txt = line;
|
||||
while (!txt.isEmpty() && (txt.endsWith("\n") || txt.endsWith("\r")))
|
||||
txt.chop(1);
|
||||
|
||||
if (format == error_format || format == warning_format)
|
||||
format.setAnchorHref(txt);
|
||||
|
||||
QTextCursor cursor = m_dialog->discoveryLog->textCursor();
|
||||
cursor.insertBlock();
|
||||
cursor.insertText(txt, format);
|
||||
}
|
||||
|
||||
m_dialog->discoveryLog->ensureCursorVisible();
|
||||
|
||||
}
|
||||
|
||||
void ND_ProgressPage::saveLog()
|
||||
{
|
||||
QString dir;
|
||||
dir = st->getWDir();
|
||||
if (dir.isEmpty()) dir = st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir = "~";
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
"Text file (*.txt)");
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
if (s.endsWith(".txt"))
|
||||
{
|
||||
s += ".txt";
|
||||
}
|
||||
QFile f(s);
|
||||
if (f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("Saving crawler log to file: %d chars",
|
||||
m_dialog->discoveryLog->toPlainText().length());
|
||||
qDebug("--------------------------------");
|
||||
}
|
||||
QTextStream strm(&f);
|
||||
QString txt = m_dialog->discoveryLog->toPlainText();
|
||||
strm << txt << endl;
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("%s",txt.toAscii().constData());
|
||||
qDebug("--------------------------------");
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,21 +26,32 @@
|
||||
|
||||
#include "ui_nd_progresspage_q.h"
|
||||
|
||||
#include <QTextCharFormat>
|
||||
|
||||
class SNMPCrawlerThread;
|
||||
|
||||
|
||||
class ND_ProgressPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
Ui::ND_ProgressPage_q *m_dialog;
|
||||
QTextCharFormat normal_format;
|
||||
QTextCharFormat error_format;
|
||||
QTextCharFormat warning_format;
|
||||
SNMPCrawlerThread *crawler;
|
||||
|
||||
public:
|
||||
ND_ProgressPage(QWidget *parent);
|
||||
virtual ~ND_ProgressPage() {}
|
||||
virtual ~ND_ProgressPage();
|
||||
|
||||
virtual void initializePage();
|
||||
virtual void cleanupPage();
|
||||
|
||||
public slots:
|
||||
|
||||
void stop();
|
||||
void saveLog();
|
||||
void logLine(const QString &line);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "global.h"
|
||||
#include "utils.h"
|
||||
#include "FWWindow.h"
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#include "ND_SNMPParametersPage.h"
|
||||
|
||||
@ -34,11 +35,32 @@ using namespace std;
|
||||
//using namespace libfwbuilder;
|
||||
|
||||
|
||||
#define DISCOVERY_DRUID_PREFIX "DiscoveryDruid/"
|
||||
#define DISCOVERY_DRUID_SNMPCOMMUNITY "SNMPCommunity"
|
||||
#define DISCOVERY_DRUID_SNMPRETRIES "SNMPRetries"
|
||||
#define DISCOVERY_DRUID_SNMPTIMEOUT "SNMPTimeout"
|
||||
|
||||
|
||||
ND_SNMPParametersPage::ND_SNMPParametersPage(QWidget *parent) : QWizardPage(parent)
|
||||
{
|
||||
m_dialog = new Ui::ND_SNMPParametersPage_q;
|
||||
m_dialog->setupUi(this);
|
||||
|
||||
QString s = st->getStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPCOMMUNITY);
|
||||
m_dialog->snmpCommunity->setText((s.isEmpty())?"public":s);
|
||||
|
||||
int i = st->getInt(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPRETRIES);
|
||||
m_dialog->snmpRetries->setValue((i)?i:1);
|
||||
|
||||
i = st->getInt(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPTIMEOUT);
|
||||
m_dialog->snmpTimeout->setValue((i)?i:2);
|
||||
|
||||
registerField("snmpCommunity", m_dialog->snmpCommunity);
|
||||
registerField("snmpRetries", m_dialog->snmpRetries);
|
||||
registerField("snmpTimeout", m_dialog->snmpTimeout);
|
||||
}
|
||||
|
||||
void ND_SNMPParametersPage::initializePage()
|
||||
@ -46,3 +68,19 @@ void ND_SNMPParametersPage::initializePage()
|
||||
if (fwbdebug)
|
||||
qDebug() << "ND_SNMPParametersPage::initializePage()";
|
||||
}
|
||||
|
||||
bool ND_SNMPParametersPage::validatePage()
|
||||
{
|
||||
st->setStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPCOMMUNITY,
|
||||
m_dialog->snmpCommunity->text());
|
||||
st->setInt(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPRETRIES,
|
||||
m_dialog->snmpRetries->value());
|
||||
st->setInt(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPTIMEOUT,
|
||||
m_dialog->snmpTimeout->value());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ public:
|
||||
virtual ~ND_SNMPParametersPage() {}
|
||||
|
||||
virtual void initializePage();
|
||||
virtual bool validatePage();
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "global.h"
|
||||
#include "utils.h"
|
||||
#include "FWWindow.h"
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#include "ND_SetupPage.h"
|
||||
|
||||
@ -36,6 +37,10 @@
|
||||
using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
#define DISCOVERY_DRUID_PREFIX "DiscoveryDruid/"
|
||||
#define DISCOVERY_DRUID_SEEDHOST "SeedHost"
|
||||
#define DISCOVERY_DRUID_SNMPINADDR "SNMPInAddr"
|
||||
#define DISCOVERY_DRUID_SNMPINMASK "SNMPInMask"
|
||||
|
||||
ND_SetupPage::ND_SetupPage(QWidget *parent) : QWizardPage(parent)
|
||||
{
|
||||
@ -49,6 +54,13 @@ ND_SetupPage::ND_SetupPage(QWidget *parent) : QWizardPage(parent)
|
||||
seedHostOK = false;
|
||||
limitScanConfigurationOK = true;
|
||||
|
||||
m_dialog->seedHostName->setText(st->getStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SEEDHOST));
|
||||
m_dialog->snmpInAddr->setText(st->getStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINADDR));
|
||||
m_dialog->snmpInMask->setText(st->getStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINMASK));
|
||||
|
||||
registerField("seedHostName*", m_dialog->seedHostName);
|
||||
registerField("snmpInAddr", m_dialog->snmpInAddr);
|
||||
registerField("snmpInMask", m_dialog->snmpInMask);
|
||||
@ -62,6 +74,21 @@ void ND_SetupPage::initializePage()
|
||||
qDebug() << "ND_SetupPage::initializePage()";
|
||||
}
|
||||
|
||||
bool ND_SetupPage::validatePage()
|
||||
{
|
||||
st->setStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SEEDHOST,
|
||||
m_dialog->seedHostName->text());
|
||||
st->setStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINADDR,
|
||||
m_dialog->snmpInAddr->text());
|
||||
st->setStr(
|
||||
QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPINMASK,
|
||||
m_dialog->snmpInMask->text());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ND_SetupPage::isComplete() const
|
||||
{
|
||||
return seedHostOK && limitScanConfigurationOK;
|
||||
|
||||
@ -52,6 +52,7 @@ public:
|
||||
virtual ~ND_SetupPage();
|
||||
|
||||
virtual void initializePage();
|
||||
virtual bool validatePage();
|
||||
virtual bool isComplete() const;
|
||||
|
||||
public slots:
|
||||
|
||||
91
src/libgui/snmpNetworkDiscoveryWizard/SNMPCrawlerThread.cpp
Normal file
91
src/libgui/snmpNetworkDiscoveryWizard/SNMPCrawlerThread.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "SNMPCrawlerThread.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "QThreadLogger.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
SNMPCrawlerThread::SNMPCrawlerThread(QWidget *ui,
|
||||
const QString &seedHostName,
|
||||
const QString &community,
|
||||
bool recursive,
|
||||
bool followP2P,
|
||||
int snmpRetries,
|
||||
int snmpTimeout,
|
||||
const std::vector<InetAddrMask> *include_net)
|
||||
{
|
||||
this->ui = ui;
|
||||
|
||||
stop_flag = new SyncFlag();
|
||||
|
||||
QString seedHostAddress = getAddrByName(seedHostName, AF_INET);
|
||||
InetAddr seedHostInetAddr = InetAddr( seedHostAddress.toLatin1().constData());
|
||||
|
||||
q = new SNMPCrawler();
|
||||
q->init(seedHostInetAddr,
|
||||
community.toLatin1().constData(),
|
||||
recursive,
|
||||
false,
|
||||
followP2P,
|
||||
0,
|
||||
snmpRetries,
|
||||
1000000L * snmpTimeout,
|
||||
0,
|
||||
0,
|
||||
(include_net->size() > 0) ? include_net : NULL);
|
||||
|
||||
}
|
||||
|
||||
SNMPCrawlerThread::~SNMPCrawlerThread()
|
||||
{
|
||||
delete q;
|
||||
delete stop_flag;
|
||||
}
|
||||
|
||||
void SNMPCrawlerThread::run()
|
||||
{
|
||||
QThreadLogger *logger = new QThreadLogger();
|
||||
connect(logger, SIGNAL(lineReady(QString)),
|
||||
this->ui, SLOT(logLine(QString)),
|
||||
Qt::QueuedConnection);
|
||||
q->run_impl(logger, stop_flag);
|
||||
|
||||
*logger << string("\n");
|
||||
*logger << string("Network crawler stopped");
|
||||
}
|
||||
|
||||
void SNMPCrawlerThread::stop()
|
||||
{
|
||||
stop_flag->set(true);
|
||||
}
|
||||
|
||||
|
||||
57
src/libgui/snmpNetworkDiscoveryWizard/SNMPCrawlerThread.h
Normal file
57
src/libgui/snmpNetworkDiscoveryWizard/SNMPCrawlerThread.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _SNMPCRAWLERTHREAD_H_
|
||||
#define _SNMPCRAWLERTHREAD_H_
|
||||
|
||||
#include "fwbuilder/snmp.h"
|
||||
#include "fwbuilder/InetAddrMask.h"
|
||||
#include "fwbuilder/ThreadTools.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QThread>
|
||||
|
||||
|
||||
class SNMPCrawlerThread : public QThread
|
||||
{
|
||||
libfwbuilder::SNMPCrawler *q;
|
||||
libfwbuilder::SyncFlag *stop_flag;
|
||||
|
||||
QWidget *ui;
|
||||
|
||||
public:
|
||||
SNMPCrawlerThread(QWidget *ui,
|
||||
const QString &seedHost,
|
||||
const QString &community,
|
||||
bool recursive,
|
||||
bool followP2P,
|
||||
int snmpRetries,
|
||||
int snmpTimeout,
|
||||
const std::vector<libfwbuilder::InetAddrMask> *include);
|
||||
virtual ~SNMPCrawlerThread();
|
||||
void run();
|
||||
void stop();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@ -28,7 +28,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="snmprecursive">
|
||||
<widget class="QCheckBox" name="snmpRecursive">
|
||||
<property name="text">
|
||||
<string>Run network scan recursively</string>
|
||||
</property>
|
||||
@ -61,7 +61,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="snmpfollowp2p">
|
||||
<widget class="QCheckBox" name="snmpFollowP2P">
|
||||
<property name="text">
|
||||
<string>Follow point-to-point links</string>
|
||||
</property>
|
||||
@ -94,7 +94,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="snmpincludeunnumbered">
|
||||
<widget class="QCheckBox" name="snmpIncludeUnnumbered">
|
||||
<property name="text">
|
||||
<string>Include interfaces with no ip addresses</string>
|
||||
</property>
|
||||
@ -127,7 +127,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QCheckBox" name="snmpdodns">
|
||||
<widget class="QCheckBox" name="snmpDoDNS">
|
||||
<property name="text">
|
||||
<string>Run reverse name lookup DNS queries to determine host names</string>
|
||||
</property>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="processname">
|
||||
<widget class="QLabel" name="processName">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>16</pointsize>
|
||||
@ -48,32 +48,22 @@
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="_3">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QProgressBar" name="discoveryprogress">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="discoveryStopButton">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="logSaveButton">
|
||||
<property name="text">
|
||||
<string>Save scan log to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="0" column="2">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -102,7 +92,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="discoverylog">
|
||||
<widget class="QTextEdit" name="discoveryLog">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -114,5 +104,42 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>discoveryStopButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ND_ProgressPage_q</receiver>
|
||||
<slot>stop()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>57</x>
|
||||
<y>73</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>304</x>
|
||||
<y>268</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>logSaveButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ND_ProgressPage_q</receiver>
|
||||
<slot>saveLog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>170</x>
|
||||
<y>73</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>304</x>
|
||||
<y>268</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>stop()</slot>
|
||||
<slot>saveLog()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="snmpretries">
|
||||
<widget class="QSpinBox" name="snmpRetries">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@ -77,7 +77,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="snmptimeout">
|
||||
<widget class="QSpinBox" name="snmpTimeout">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@ -87,7 +87,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="snmpcommunity">
|
||||
<widget class="QLineEdit" name="snmpCommunity">
|
||||
<property name="text">
|
||||
<string>public</string>
|
||||
</property>
|
||||
@ -145,97 +145,6 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QGroupBox" name="snmpdnsparameters">
|
||||
<property name="title">
|
||||
<string>DNS parameters:</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="_2">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="2">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel15">
|
||||
<property name="text">
|
||||
<string>number of retries:</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="textLabel16">
|
||||
<property name="text">
|
||||
<string>timeout (sec) :</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="textLabel17">
|
||||
<property name="text">
|
||||
<string>Number of threads:</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="snmpdnsretries">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="snmpdnstimeout">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="snmpdnsthreads">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="snmpcommunity_message">
|
||||
<property name="text">
|
||||
<string/>
|
||||
@ -245,7 +154,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="3" column="0">
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user