mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-20 18:27:16 +01:00
see #2163 creting objects discovered via snmp; snmp network discovery wizard is now functional
This commit is contained in:
parent
c21214c6a2
commit
56ad849d50
@ -54,7 +54,7 @@ ObjectSelectorWidget::~ObjectSelectorWidget()
|
||||
delete flt_obj_d;
|
||||
}
|
||||
|
||||
void ObjectSelectorWidget::init(const list<ObjectDescriptor> &objects)
|
||||
void ObjectSelectorWidget::init(const QList<ObjectDescriptor> &objects)
|
||||
{
|
||||
this->objects = objects;
|
||||
fillListOfObjects();
|
||||
|
||||
@ -44,7 +44,7 @@ class ObjectSelectorWidget : public QWidget
|
||||
|
||||
Filter * flt_obj;
|
||||
FilterDialog * flt_obj_d;
|
||||
std::list<ObjectDescriptor> objects;
|
||||
QList<ObjectDescriptor> objects;
|
||||
QStringList objects_to_use;
|
||||
|
||||
// configure this as a proprty so it can be accessed as a field after
|
||||
@ -56,7 +56,7 @@ public:
|
||||
ObjectSelectorWidget(QWidget *parent);
|
||||
virtual ~ObjectSelectorWidget();
|
||||
|
||||
void init(const std::list<ObjectDescriptor> &objects);
|
||||
void init(const QList<ObjectDescriptor> &objects);
|
||||
|
||||
int count() { return objects_to_use.count(); }
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ void ChooseObjectsPage::initializePage()
|
||||
importer.parse();
|
||||
map<InetAddr, QStringList> imported_hosts_info = importer.getAll();
|
||||
|
||||
list<ObjectDescriptor> objects;
|
||||
QList<ObjectDescriptor> objects;
|
||||
map<InetAddr, QStringList>::iterator i;
|
||||
for (i=imported_hosts_info.begin(); i!=imported_hosts_info.end(); ++i)
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "FWWindow.h"
|
||||
|
||||
#include "ND_ChooseNetworksPage.h"
|
||||
#include "ND_ProgressPage.h"
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
@ -49,15 +49,10 @@ void ND_ChooseNetworksPage::initializePage()
|
||||
if (fwbdebug)
|
||||
qDebug() << "ND_ChooseNetworksPage::initializePage()";
|
||||
|
||||
ND_ProgressPage *progress_page = NULL;
|
||||
foreach(int page_id, wizard()->pageIds())
|
||||
{
|
||||
progress_page = dynamic_cast<ND_ProgressPage*>(wizard()->page(page_id));
|
||||
if (progress_page != NULL) break;
|
||||
}
|
||||
assert(progress_page != NULL);
|
||||
ObjectDescriptorList *networks =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getNetworks();
|
||||
|
||||
m_dialog->objectSelector->init(progress_page->getNetworks());
|
||||
m_dialog->objectSelector->init(*networks);
|
||||
|
||||
/*
|
||||
list<ObjectDescriptor> objects;
|
||||
|
||||
@ -26,12 +26,13 @@
|
||||
#include "FWWindow.h"
|
||||
|
||||
#include "ND_ChooseObjectTypePage.h"
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
using namespace std;
|
||||
//using namespace libfwbuilder;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
ND_ChooseObjectTypePage::ND_ChooseObjectTypePage(QWidget *parent) : QWizardPage(parent)
|
||||
@ -45,4 +46,70 @@ void ND_ChooseObjectTypePage::initializePage()
|
||||
{
|
||||
if (fwbdebug)
|
||||
qDebug() << "ND_ChooseObjectTypePage::initializePage()";
|
||||
|
||||
objects = dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
objectsToUse = dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjectsToUse();
|
||||
|
||||
fillTypeChangingList();
|
||||
}
|
||||
|
||||
void ND_ChooseObjectTypePage::fillTypeChangingList()
|
||||
{
|
||||
m_dialog->typeChangingList->clear();
|
||||
|
||||
qDebug() << objectsToUse;
|
||||
|
||||
int idx = 0;
|
||||
foreach(ObjectDescriptor od, *objects)
|
||||
{
|
||||
if (objectsToUse->contains(QString::fromUtf8(od.sysname.c_str())))
|
||||
{
|
||||
QString ins;
|
||||
ins = (od.interfaces.size()) ?
|
||||
QString("%1").arg(od.interfaces.size()) : "";
|
||||
QStringList sl;
|
||||
sl << QString::fromUtf8(od.toString().c_str())
|
||||
<< ins << od.type.c_str();
|
||||
QTreeWidgetItem *itm = new QTreeWidgetItem(
|
||||
m_dialog->typeChangingList, sl );
|
||||
itm->setData(0, Qt::UserRole, idx);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
m_dialog->typeChangingList->resizeColumnToContents(0);
|
||||
m_dialog->typeChangingList->resizeColumnToContents(1);
|
||||
}
|
||||
|
||||
void ND_ChooseObjectTypePage::typeAddress()
|
||||
{
|
||||
changeTargetObject(IPv4::TYPENAME);
|
||||
}
|
||||
|
||||
void ND_ChooseObjectTypePage::typeHost()
|
||||
{
|
||||
changeTargetObject(Host::TYPENAME);
|
||||
}
|
||||
|
||||
void ND_ChooseObjectTypePage::typeFirewall()
|
||||
{
|
||||
changeTargetObject(Firewall::TYPENAME);
|
||||
}
|
||||
|
||||
void ND_ChooseObjectTypePage::changeTargetObject(const QString &buf)
|
||||
{
|
||||
QTreeWidgetItem* item = m_dialog->typeChangingList->topLevelItem(0);
|
||||
|
||||
while (item!=0)
|
||||
{
|
||||
if (item->isSelected())
|
||||
{
|
||||
int idx = item->data(0, Qt::UserRole).toInt();
|
||||
(*objects)[idx].type = buf.toStdString();
|
||||
item->setText(2, buf);
|
||||
}
|
||||
item = m_dialog->typeChangingList->topLevelItem(
|
||||
m_dialog->typeChangingList->indexOfTopLevelItem(item)+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,8 @@
|
||||
#ifndef __ND_CHOOSEOBJECTTYPEPAGE_H_
|
||||
#define __ND_CHOOSEOBJECTTYPEPAGE_H_
|
||||
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include "ui_nd_chooseobjecttypepage_q.h"
|
||||
|
||||
|
||||
@ -32,6 +34,8 @@ class ND_ChooseObjectTypePage : public QWizardPage
|
||||
Q_OBJECT;
|
||||
|
||||
Ui::ND_ChooseObjectTypePage_q *m_dialog;
|
||||
ObjectDescriptorList *objects;
|
||||
QStringList *objectsToUse;
|
||||
|
||||
public:
|
||||
ND_ChooseObjectTypePage(QWidget *parent);
|
||||
@ -39,8 +43,14 @@ public:
|
||||
|
||||
virtual void initializePage();
|
||||
|
||||
void fillTypeChangingList();
|
||||
|
||||
void changeTargetObject(const QString &buf);
|
||||
|
||||
public slots:
|
||||
void typeAddress();
|
||||
void typeHost();
|
||||
void typeFirewall();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "FWWindow.h"
|
||||
|
||||
#include "ND_ChooseObjectsPage.h"
|
||||
#include "ND_ProgressPage.h"
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
@ -51,15 +51,10 @@ void ND_ChooseObjectsPage::initializePage()
|
||||
if (fwbdebug)
|
||||
qDebug() << "ND_ChooseObjectsPage::initializePage()";
|
||||
|
||||
ND_ProgressPage *progress_page = NULL;
|
||||
foreach(int page_id, wizard()->pageIds())
|
||||
{
|
||||
progress_page = dynamic_cast<ND_ProgressPage*>(wizard()->page(page_id));
|
||||
if (progress_page != NULL) break;
|
||||
}
|
||||
assert(progress_page != NULL);
|
||||
ObjectDescriptorList *objects =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
|
||||
m_dialog->objectSelector->init(progress_page->getObjects());
|
||||
m_dialog->objectSelector->init(*objects);
|
||||
|
||||
/*
|
||||
list<ObjectDescriptor> objects;
|
||||
@ -74,6 +69,12 @@ void ND_ChooseObjectsPage::initializePage()
|
||||
bool ND_ChooseObjectsPage::validatePage()
|
||||
{
|
||||
if (fwbdebug) qDebug() << "ND_ChooseObjectsPage::validatePage()";
|
||||
|
||||
QStringList *objectsToUse =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjectsToUse();
|
||||
|
||||
*objectsToUse = m_dialog->objectSelector->getObjectsToUse();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -26,15 +26,27 @@
|
||||
#include "events.h"
|
||||
#include "FWWindow.h"
|
||||
#include "ProjectPanel.h"
|
||||
#include "platforms.h"
|
||||
|
||||
#include "ND_CreateObjectsPage.h"
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include "interfaceProperties.h"
|
||||
#include "interfacePropertiesObjectFactory.h"
|
||||
|
||||
#include "fwbuilder/IPv4.h"
|
||||
#include "fwbuilder/IPv6.h"
|
||||
#include "fwbuilder/Network.h"
|
||||
#include "fwbuilder/NetworkIPv6.h"
|
||||
#include "fwbuilder/Resources.h"
|
||||
#include "fwbuilder/InterfaceData.h"
|
||||
#include "fwbuilder/Firewall.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMessageBox>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
@ -51,58 +63,43 @@ void ND_CreateObjectsPage::initializePage()
|
||||
{
|
||||
if (fwbdebug) qDebug() << "ND_CreateObjectsPage::initializePage()";
|
||||
|
||||
ObjectDescriptorList *objects =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
QStringList *objectsToUse =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjectsToUse();
|
||||
ObjectDescriptorList *networks =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getNetworks();
|
||||
|
||||
int lib_index = field("libIndex").toInt();
|
||||
QStringList libraries = field("libraries").toStringList();
|
||||
QStringList objects = field("objectsToUse").toStringList();
|
||||
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug() << "libraries=" << libraries;
|
||||
qDebug() << "objects=" << objects;
|
||||
}
|
||||
|
||||
m_dialog->progressBar->setFormat("%v / %m");
|
||||
m_dialog->progressBar->setMaximum(objects.size() / 2);
|
||||
|
||||
m_dialog->progressBar->setMaximum(objectsToUse->size() / 2 + networks->size());
|
||||
FWObject *last_object = NULL;
|
||||
QString name;
|
||||
QString addr;
|
||||
int counter = 1;
|
||||
while (objects.size() > 0)
|
||||
string type, name, a;
|
||||
int counter = 0;
|
||||
|
||||
foreach(ObjectDescriptor od, *networks)
|
||||
{
|
||||
name = objects.front(); objects.pop_front();
|
||||
addr = objects.front(); objects.pop_front();
|
||||
type = od.type; // Network or NetworkIPv6
|
||||
name = od.sysname;
|
||||
a = od.addr.toString().c_str();
|
||||
|
||||
Address *net = Address::cast(
|
||||
mw->createObject(type.c_str(), name.c_str()));
|
||||
|
||||
QString type;
|
||||
try
|
||||
{
|
||||
InetAddr(AF_INET6, addr.toLatin1().constData() );
|
||||
type = IPv6::TYPENAME;
|
||||
} catch (FWException &ex)
|
||||
{
|
||||
}
|
||||
assert(net!=NULL);
|
||||
|
||||
if (type.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
InetAddr(AF_INET, addr.toLatin1().constData() );
|
||||
type = IPv4::TYPENAME;
|
||||
} catch (FWException &ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
net->setName(name);
|
||||
net->setAddress(od.addr);
|
||||
net->setNetmask(od.netmask);
|
||||
|
||||
mw->moveObject(libraries[lib_index], net);
|
||||
|
||||
if (! type.isEmpty())
|
||||
{
|
||||
Address *obj = Address::cast(mw->createObject(type, name));
|
||||
assert(obj!=NULL);
|
||||
obj->setName(name.toUtf8().constData());
|
||||
obj->setAddress(InetAddr(addr.toStdString()));
|
||||
obj->setNetmask(InetAddr(InetAddr::getAllOnes()));
|
||||
mw->moveObject(libraries[lib_index], obj);
|
||||
last_object = obj;
|
||||
}
|
||||
last_object = net;
|
||||
|
||||
m_dialog->progressBar->setValue(counter);
|
||||
qApp->processEvents();
|
||||
@ -110,6 +107,205 @@ void ND_CreateObjectsPage::initializePage()
|
||||
counter++;
|
||||
}
|
||||
|
||||
foreach(ObjectDescriptor od, *objects)
|
||||
{
|
||||
if (objectsToUse->contains(QString::fromUtf8(od.sysname.c_str())))
|
||||
{
|
||||
type = od.type;
|
||||
|
||||
name = od.sysname;
|
||||
|
||||
QString platform;
|
||||
QString os;
|
||||
QString version;
|
||||
guessOSAndPlatformFromSysDescr(od.descr.c_str(), platform, os, version);
|
||||
|
||||
a = od.addr.toString();
|
||||
|
||||
if (type==Host::TYPENAME || type==Firewall::TYPENAME)
|
||||
{
|
||||
FWObject *o=NULL;
|
||||
|
||||
o = mw->createObject(type.c_str(), name.c_str());
|
||||
o->setName(name);
|
||||
|
||||
if (type==Firewall::TYPENAME)
|
||||
{
|
||||
if (os == "linux")
|
||||
{
|
||||
o->setStr("platform", "iptables");
|
||||
o->setStr("host_OS", "linux24");
|
||||
}
|
||||
if (os == "freebsd")
|
||||
{
|
||||
o->setStr("platform", "pf");
|
||||
o->setStr("host_OS", "freebsd");
|
||||
}
|
||||
if (os == "openbsd")
|
||||
{
|
||||
o->setStr("platform", "pf");
|
||||
o->setStr("host_OS", "openbsd");
|
||||
}
|
||||
if (os == "ios")
|
||||
{
|
||||
o->setStr("platform", "iosacl");
|
||||
o->setStr("host_OS", "ios");
|
||||
}
|
||||
if (os == "pix" || os == "fwsm")
|
||||
{
|
||||
o->setStr("platform", "pix");
|
||||
o->setStr("host_OS", "pix_os");
|
||||
}
|
||||
if (os == "apple")
|
||||
{
|
||||
o->setStr("platform", "ipfw");
|
||||
o->setStr("host_OS", "macosx");
|
||||
}
|
||||
if (os == "solaris")
|
||||
{
|
||||
o->setStr("platform", "ipf");
|
||||
o->setStr("host_OS", "solaris");
|
||||
}
|
||||
|
||||
Resources::setDefaultTargetOptions( o->getStr("platform"),
|
||||
Firewall::cast(o) );
|
||||
Resources::setDefaultTargetOptions( o->getStr("host_OS"),
|
||||
Firewall::cast(o) );
|
||||
}
|
||||
|
||||
if (od.interfaces.size()==0)
|
||||
{
|
||||
Interface *itf= Interface::cast(
|
||||
mw->createObject(o,Interface::TYPENAME,"nic1")
|
||||
);
|
||||
|
||||
if (od.addr.isV4())
|
||||
{
|
||||
IPv4 *ipv4= IPv4::cast(
|
||||
mw->createObject(itf, IPv4::TYPENAME, a.c_str())
|
||||
);
|
||||
ipv4->setAddress(od.addr);
|
||||
ipv4->setNetmask(InetAddr());
|
||||
}
|
||||
|
||||
if (od.addr.isV6())
|
||||
{
|
||||
IPv6 *ipv6 = IPv6::cast(
|
||||
mw->createObject(itf, IPv6::TYPENAME, a.c_str())
|
||||
);
|
||||
ipv6->setAddress(od.addr);
|
||||
ipv6->setNetmask(InetAddr());
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
if (fwbdebug)
|
||||
{
|
||||
map<int,InterfaceData>::iterator i;
|
||||
for (i=od.interfaces.begin(); i!=od.interfaces.end(); ++i)
|
||||
{
|
||||
InterfaceData *intf = &(i->second);
|
||||
QString str("Discovered interface %1: %2");
|
||||
qDebug() <<
|
||||
str.arg(intf->name.c_str()).arg(intf->mac_addr.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
list<InterfaceData*> interface_tree;
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(o));
|
||||
int_prop->rearrangeInterfaces(od.interfaces, interface_tree);
|
||||
|
||||
if (interface_tree.size() != od.interfaces.size())
|
||||
{
|
||||
// Some interfaces have been converted to subinterfaces
|
||||
// Show warning
|
||||
|
||||
QMessageBox::warning(
|
||||
this, "Firewall Builder",
|
||||
tr(
|
||||
"Some discovered interfaces have been rearranged in "
|
||||
"fwbuilder objects and recreated as subinterfaces to "
|
||||
"reflect VLANs, bonding and bridging configurations. "
|
||||
"The algorithm used to guess correct relationship "
|
||||
"between interfaces and subinterfaces is imperfect "
|
||||
"because of the limited information provided by SNMP "
|
||||
"daemon. Pelase review created objects to make sure "
|
||||
"generated configuration is accurate. "
|
||||
"\n"
|
||||
"\n"
|
||||
"The program expects MAC addresses of bonding, bridge "
|
||||
"and vlan interfaces to be the same. It is especially "
|
||||
"important to review and fix generated objects if you "
|
||||
"use MAC address spoofing."
|
||||
),
|
||||
tr("&Continue"), 0, 0,
|
||||
0 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
list<InterfaceData*>::iterator it;
|
||||
for (it=interface_tree.begin(); it!=interface_tree.end(); ++it)
|
||||
{
|
||||
InterfaceData *in = *it;
|
||||
// if this interface has subinterfaces, add even if it
|
||||
// has no ip address (last arg)
|
||||
|
||||
FWObject *intf = addInterface(
|
||||
o, in, in->subinterfaces.size()!=0);
|
||||
if (intf == NULL) continue;
|
||||
|
||||
list<InterfaceData*>::iterator sit;
|
||||
for (sit=in->subinterfaces.begin();
|
||||
sit!=in->subinterfaces.end(); ++sit)
|
||||
{
|
||||
InterfaceData *subint = *sit;
|
||||
addInterface(intf, subint, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!od.descr.empty())
|
||||
{
|
||||
FWOptions* opt=(dynamic_cast<Host*>(o))->getOptionsObject();
|
||||
opt->setStr("snmp_description",od.descr);
|
||||
opt->setStr("snmp_location", od.location);
|
||||
opt->setStr("snmp_contact", od.contact);
|
||||
}
|
||||
|
||||
mw->moveObject(libraries[lib_index], o);
|
||||
|
||||
} else if (type==Network::TYPENAME)
|
||||
{
|
||||
Network *net=dynamic_cast<Network*>(
|
||||
mw->createObject(type.c_str(),name.c_str())
|
||||
);
|
||||
assert(net!=NULL);
|
||||
net->setName(name);
|
||||
net->setAddress(InetAddr(a));
|
||||
net->setNetmask(InetAddr(InetAddr(a)));
|
||||
mw->moveObject(libraries[lib_index], net);
|
||||
} else if (type==IPv4::TYPENAME)
|
||||
{
|
||||
IPv4 *obj=dynamic_cast<IPv4*>(
|
||||
mw->createObject(type.c_str(),name.c_str())
|
||||
);
|
||||
assert(obj!=NULL);
|
||||
obj->setName(name);
|
||||
obj->setAddress(InetAddr(a));
|
||||
obj->setNetmask(InetAddr(InetAddr::getAllOnes()));
|
||||
mw->moveObject(libraries[lib_index], obj);
|
||||
}
|
||||
|
||||
m_dialog->progressBar->setValue(counter);
|
||||
qApp->processEvents();
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
ProjectPanel *pp = mw->activeProject();
|
||||
QString filename = pp->getFileName();
|
||||
QCoreApplication::postEvent(mw, new reloadObjectTreeEvent(filename));
|
||||
@ -118,3 +314,110 @@ void ND_CreateObjectsPage::initializePage()
|
||||
filename, last_object->getId()));
|
||||
}
|
||||
|
||||
FWObject* ND_CreateObjectsPage::addInterface(FWObject *parent, InterfaceData *in,
|
||||
bool skip_ip_address_check)
|
||||
{
|
||||
ObjectManipulator *om = mw->activeProject()->m_panel->om;
|
||||
|
||||
bool includeUnnumbered = field("snmpIncludeUnnumbered").toBool();
|
||||
|
||||
if ( ! includeUnnumbered && ! skip_ip_address_check)
|
||||
{
|
||||
if (in->addr_mask.size()==0) return NULL;
|
||||
if (in->addr_mask.front()->getAddressPtr()->isAny())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
QString obj_name = in->name.c_str();
|
||||
Interface *itf = NULL;
|
||||
itf = Interface::cast(
|
||||
mw->createObject(parent,
|
||||
QString(Interface::TYPENAME), obj_name));
|
||||
|
||||
QString iname = om->getStandardName(itf, physAddress::TYPENAME, "mac");
|
||||
iname = om->makeNameUnique(itf, iname, physAddress::TYPENAME);
|
||||
|
||||
physAddress *paddr = physAddress::cast(
|
||||
mw->createObject(itf, physAddress::TYPENAME, iname)
|
||||
);
|
||||
paddr->setPhysAddress(in->mac_addr);
|
||||
|
||||
itf->setLabel(in->label);
|
||||
itf->setSecurityLevel(in->securityLevel);
|
||||
|
||||
if (fwbdebug)
|
||||
qDebug() << "Interface=" << obj_name
|
||||
<< "type=" << in->interface_type.c_str();
|
||||
|
||||
if (!in->interface_type.empty())
|
||||
{
|
||||
itf->getOptionsObject()->setStr("type", in->interface_type);
|
||||
if (in->interface_type == "8021q")
|
||||
itf->getOptionsObject()->setInt("vlan_id", in->vlan_id);
|
||||
} else
|
||||
{
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(parent));
|
||||
if (int_prop->looksLikeVlanInterface(obj_name))
|
||||
{
|
||||
QString base_name;
|
||||
int vlan_id;
|
||||
int_prop->parseVlan(obj_name, &base_name, &vlan_id);
|
||||
|
||||
itf->getOptionsObject()->setStr("type", "8021q");
|
||||
itf->getOptionsObject()->setInt("vlan_id", vlan_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (in->addr_mask.size()==0 ||
|
||||
in->addr_mask.front()->getAddressPtr()->isAny())
|
||||
{
|
||||
itf->setUnnumbered(true);
|
||||
} else
|
||||
{
|
||||
list<InetAddrMask*>::iterator n;
|
||||
for (n=in->addr_mask.begin(); n!=in->addr_mask.end(); ++n)
|
||||
{
|
||||
const InetAddr *addr = (*n)->getAddressPtr();
|
||||
const InetAddr *netm = (*n)->getNetmaskPtr();
|
||||
|
||||
if (addr->isV4())
|
||||
{
|
||||
try
|
||||
{
|
||||
QString iname = om->getStandardName(itf, IPv4::TYPENAME, "ip");
|
||||
iname = om->makeNameUnique(itf, iname, IPv4::TYPENAME);
|
||||
|
||||
IPv4 *ipv4= IPv4::cast(
|
||||
om->createObject(itf, IPv4::TYPENAME, iname)
|
||||
);
|
||||
ipv4->setAddress(*addr);
|
||||
ipv4->setNetmask(*netm);
|
||||
} catch (FWException &ex)
|
||||
{
|
||||
cerr << "FWException: " << ex.toString() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (addr->isV6())
|
||||
{
|
||||
try
|
||||
{
|
||||
QString iname = om->getStandardName(itf, IPv6::TYPENAME, "ip");
|
||||
iname = om->makeNameUnique(itf, iname, IPv6::TYPENAME);
|
||||
|
||||
IPv6 *ipv6 = IPv6::cast(
|
||||
om->createObject(itf, IPv6::TYPENAME, iname)
|
||||
);
|
||||
ipv6->setAddress(*addr);
|
||||
ipv6->setNetmask(*netm);
|
||||
} catch (FWException &ex)
|
||||
{
|
||||
cerr << "FWException: " << ex.toString() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return itf;
|
||||
}
|
||||
|
||||
|
||||
@ -26,13 +26,22 @@
|
||||
|
||||
#include "ui_nd_createobjectspage_q.h"
|
||||
|
||||
namespace libfwbuilder
|
||||
{
|
||||
class InterfaceData;
|
||||
class FWObject;
|
||||
};
|
||||
|
||||
class ND_CreateObjectsPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
Ui::ND_CreateObjectsPage_q *m_dialog;
|
||||
|
||||
|
||||
libfwbuilder::FWObject* addInterface(libfwbuilder::FWObject *parent,
|
||||
libfwbuilder::InterfaceData *in,
|
||||
bool skip_ip_address_check);
|
||||
|
||||
public:
|
||||
ND_CreateObjectsPage(QWidget *parent);
|
||||
virtual ~ND_CreateObjectsPage() {}
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
#include "ND_ProgressPage.h"
|
||||
#include "SNMPCrawlerThread.h"
|
||||
#include "SNMPNetworkDiscoveryWizard.h"
|
||||
|
||||
#include "fwbuilder/snmp.h"
|
||||
#include "fwbuilder/NetworkIPv6.h"
|
||||
@ -97,14 +98,17 @@ ND_ProgressPage::~ND_ProgressPage()
|
||||
|
||||
bool ND_ProgressPage::validatePage()
|
||||
{
|
||||
ObjectDescriptorList *objects =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
|
||||
if (fwbdebug_nd)
|
||||
qDebug() << "ND_ProgressPage::validatePage()"
|
||||
<< "crawler=" << crawler
|
||||
<< "isRunning=" << ((crawler) ? crawler->isRunning() : 0)
|
||||
<< "objects.size()=" << objects.size();
|
||||
<< "objects->size()=" << objects->size();
|
||||
|
||||
if (crawler != NULL && crawler->isRunning()) return false;
|
||||
return (objects.size() > 0);
|
||||
return (objects->size() > 0);
|
||||
}
|
||||
|
||||
void ND_ProgressPage::crawlerDestroyed(QObject *obj)
|
||||
@ -118,6 +122,14 @@ void ND_ProgressPage::initializePage()
|
||||
if (fwbdebug_nd) qDebug() << "ND_ProgressPage::initializePage()";
|
||||
|
||||
#ifdef HAVE_LIBSNMP
|
||||
|
||||
ObjectDescriptorList *objects =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
|
||||
ObjectDescriptorList *networks =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getNetworks();
|
||||
|
||||
|
||||
QString seedHostName = field("seedHostName").toString();
|
||||
QString snmpInclAddr = field("snmpInAddr").toString();
|
||||
QString snmpInclMask = field("snmpInMask").toString();
|
||||
@ -163,8 +175,8 @@ void ND_ProgressPage::initializePage()
|
||||
delete crawler;
|
||||
}
|
||||
|
||||
objects.clear();
|
||||
networks.clear();
|
||||
objects->clear();
|
||||
networks->clear();
|
||||
|
||||
emit completeChanged();
|
||||
|
||||
@ -215,6 +227,13 @@ void ND_ProgressPage::crawlerFinished()
|
||||
{
|
||||
if (fwbdebug_nd) qDebug() << "ND_ProgressPage::crawlerFinished()";
|
||||
|
||||
ObjectDescriptorList *networks =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getNetworks();
|
||||
|
||||
ObjectDescriptorList *objects =
|
||||
dynamic_cast<SNMPNetworkDiscoveryWizard*>(wizard())->getObjects();
|
||||
|
||||
|
||||
logLine("\n");
|
||||
logLine(tr("Network crawler stopped"));
|
||||
|
||||
@ -252,7 +271,7 @@ void ND_ProgressPage::crawlerFinished()
|
||||
od.netmask = *(net->getNetmaskPtr());
|
||||
od.isSelected = false;
|
||||
|
||||
networks.push_back(od);
|
||||
networks->push_back(od);
|
||||
}
|
||||
|
||||
logLine(tr("Discovered %1 addresses").arg(discovered_addresses.size()));
|
||||
@ -288,10 +307,10 @@ void ND_ProgressPage::crawlerFinished()
|
||||
for(si=od.dns_info.aliases.begin(); si!=od.dns_info.aliases.end(); ++si)
|
||||
{
|
||||
od.sysname = (*si);
|
||||
objects.push_back(od);;
|
||||
objects->push_back(od);;
|
||||
}
|
||||
} else
|
||||
objects.push_back(od);
|
||||
objects->push_back(od);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -25,15 +25,12 @@
|
||||
#define __ND_PROGRESSPAGE_H_
|
||||
|
||||
#include "ui_nd_progresspage_q.h"
|
||||
#include "ObjectDescriptor.h"
|
||||
|
||||
#include <QTextCharFormat>
|
||||
|
||||
class SNMPCrawlerThread;
|
||||
|
||||
|
||||
typedef std::list<ObjectDescriptor> ObjectDescriptorMap;
|
||||
|
||||
class ND_ProgressPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT;
|
||||
@ -43,8 +40,6 @@ class ND_ProgressPage : public QWizardPage
|
||||
QTextCharFormat error_format;
|
||||
QTextCharFormat warning_format;
|
||||
SNMPCrawlerThread *crawler;
|
||||
ObjectDescriptorMap networks;
|
||||
ObjectDescriptorMap objects;
|
||||
|
||||
public:
|
||||
ND_ProgressPage(QWidget *parent);
|
||||
@ -54,9 +49,6 @@ public:
|
||||
virtual void cleanupPage();
|
||||
virtual bool validatePage();
|
||||
|
||||
ObjectDescriptorMap getNetworks() { return networks; }
|
||||
ObjectDescriptorMap getObjects() { return objects; }
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void saveLog();
|
||||
|
||||
@ -24,16 +24,28 @@
|
||||
#ifndef __SNMPNETWORKDISCOVERYWIZARD_H_
|
||||
#define __SNMPNETWORKDISCOVERYWIZARD_H_
|
||||
|
||||
#include "ObjectDescriptor.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QWizard>
|
||||
|
||||
typedef QList<ObjectDescriptor> ObjectDescriptorList;
|
||||
|
||||
class SNMPNetworkDiscoveryWizard : public QWizard
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
ObjectDescriptorList networks;
|
||||
ObjectDescriptorList objects;
|
||||
QStringList objectsToUse;
|
||||
|
||||
public:
|
||||
SNMPNetworkDiscoveryWizard(QWidget *parent);
|
||||
virtual ~SNMPNetworkDiscoveryWizard() {}
|
||||
|
||||
ObjectDescriptorList* getNetworks() { return &networks; }
|
||||
ObjectDescriptorList* getObjects() { return &objects; }
|
||||
QStringList* getObjectsToUse() { return &objectsToUse; }
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -14,6 +14,43 @@
|
||||
<string>WizardPage</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QGroupBox" name="groupBox4">
|
||||
<property name="title">
|
||||
<string>Change type of selected objects:</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="_2">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addresTypeButton">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="hostTypeButton">
|
||||
<property name="text">
|
||||
<string>Host</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="firewallTypeButton">
|
||||
<property name="text">
|
||||
<string>Firewall</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1_6">
|
||||
<property name="text">
|
||||
@ -52,109 +89,62 @@
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QGridLayout">
|
||||
<item row="1" 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>30</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="unselAllLastButton">
|
||||
<property name="text">
|
||||
<string>Unselect All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="removeLastFilterButton">
|
||||
<property name="text">
|
||||
<string>Remove Filter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="addLastFilterButton">
|
||||
<property name="text">
|
||||
<string>Filter ...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="selAllLastButton">
|
||||
<property name="text">
|
||||
<string>Select All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" rowspan="2">
|
||||
<widget class="QGroupBox" name="groupBox4">
|
||||
<property name="title">
|
||||
<string>Change type of selected objects:</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="_2">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addresTypeButton">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="hostTypeButton">
|
||||
<property name="text">
|
||||
<string>Host</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton26">
|
||||
<property name="text">
|
||||
<string>Firewall</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>textLabel1_6</zorder>
|
||||
<zorder>layoutWidget</zorder>
|
||||
<zorder>typeChangingList</zorder>
|
||||
<zorder>groupBox4</zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>addresTypeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ND_ChooseObjectTypePage_q</receiver>
|
||||
<slot>typeAddress()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>104</x>
|
||||
<y>487</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>288</x>
|
||||
<y>259</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>hostTypeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ND_ChooseObjectTypePage_q</receiver>
|
||||
<slot>typeHost()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>288</x>
|
||||
<y>487</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>288</x>
|
||||
<y>259</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>firewallTypeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ND_ChooseObjectTypePage_q</receiver>
|
||||
<slot>typeFirewall()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>472</x>
|
||||
<y>487</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>288</x>
|
||||
<y>259</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>typeAddress()</slot>
|
||||
<slot>typeHost()</slot>
|
||||
<slot>typeFirewall()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user