From 579704a6946270592611883d2e1807cf5f411818 Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Wed, 2 Jul 2008 23:00:16 +0000 Subject: [PATCH] fixed snmp discovery --- src/gui/DiscoveryDruid.cpp | 303 ++++++++++++++++++---------------- src/gui/DiscoveryDruid.h | 5 +- src/gui/InterfaceData.cpp | 214 ------------------------ src/gui/InterfaceData.h | 86 ---------- src/gui/ObjectManipulator.cpp | 83 +++++----- src/gui/gui.pro | 2 - src/gui/newFirewallDialog.cpp | 21 +-- src/gui/newFirewallDialog.h | 2 +- src/gui/newHostDialog.cpp | 14 +- src/gui/newHostDialog.h | 2 +- src/gui/projectpanel_q.ui | 18 +- 11 files changed, 245 insertions(+), 505 deletions(-) delete mode 100644 src/gui/InterfaceData.cpp delete mode 100644 src/gui/InterfaceData.h diff --git a/src/gui/DiscoveryDruid.cpp b/src/gui/DiscoveryDruid.cpp index d478c1b4e..db36884b1 100644 --- a/src/gui/DiscoveryDruid.cpp +++ b/src/gui/DiscoveryDruid.cpp @@ -68,6 +68,7 @@ #include "fwbuilder/dns.h" #include "fwbuilder/snmp.h" +#include "fwbuilder/Logger.h" #include "FWBSettings.h" #include "ObjectManipulator.h" @@ -98,18 +99,23 @@ DiscoveryDruid::DiscoveryDruid(QWidget *parent, bool start_with_import) : dm_method->addButton(m_dialog->dm_usesnmp,2); dm_method->addButton(m_dialog->dm_import_config,3); - connect(dm_method, SIGNAL( buttonClicked(int) ), this, SLOT( changedDiscoveryMethod(int) ) ); - connect(m_dialog->dnsfromlist, SIGNAL( clicked(bool) ), this, SLOT( changedNameServer() ) ); - connect(m_dialog->dnscustom, SIGNAL( clicked(bool) ), this, SLOT( changedNameServer() ) ); - connect(m_dialog->nameserverlist, SIGNAL( editTextChanged(QString) ), this, SLOT( changedNameServer() ) ); - connect(m_dialog->nameserverline, SIGNAL( textChanged(QString) ), this, SLOT( changedNameServer() ) ); + connect(dm_method, SIGNAL( buttonClicked(int) ), + this, SLOT( changedDiscoveryMethod(int) ) ); + connect(m_dialog->dnsfromlist, SIGNAL( clicked(bool) ), + this, SLOT( changedNameServer() ) ); + connect(m_dialog->dnscustom, SIGNAL( clicked(bool) ), + this, SLOT( changedNameServer() ) ); + connect(m_dialog->nameserverlist, SIGNAL( editTextChanged(QString) ), + this, SLOT( changedNameServer() ) ); + connect(m_dialog->nameserverline, SIGNAL( textChanged(QString) ), + this, SLOT( changedNameServer() ) ); - thread=NULL; + thread = NULL; - timer=new QTimer(this); - prg_timer=new QTimer(this); - unBar=NULL; - unProg=0; + timer = new QTimer(this); + prg_timer = new QTimer(this); + unBar = NULL; + unProg = 0; connect(prg_timer,SIGNAL(timeout()),this,SLOT(updatePrg())); @@ -251,8 +257,9 @@ void DiscoveryDruid::restore() m_dialog->dnstimeout->setValue((i)?i:2); i=st->getInt(QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_DNSRETRIES); m_dialog->dnsretries->setValue((i)?i:1); - //m_dialog->seedhostname->setText(st->getStr( - // QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SEEDHOST)); + + 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( @@ -309,9 +316,9 @@ void DiscoveryDruid::save() QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SNMPDNSTIMEOUT, m_dialog->snmpdnstimeout->value()); } - //st->setStr( - // QString(DISCOVERY_DRUID_PREFIX) + DISCOVERY_DRUID_SEEDHOST, - // m_dialog->seedhostname->text()); + 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()); @@ -472,11 +479,11 @@ void DiscoveryDruid::changedSelected( const int &page ) QApplication::processEvents(QEventLoop::ExcludeUserInputEvents,100); - setNextEnabled(page,false); + setNextEnabled(page, false); cancelButton->hide(); - setBackEnabled(page,false); - disconnect(timer,SIGNAL(timeout()),0,0); - connect(timer,SIGNAL(timeout()),this,SLOT(updateLog())); + setBackEnabled(page, false); + disconnect(timer, SIGNAL(timeout()), 0, 0); + connect(timer, SIGNAL(timeout()), this, SLOT(updateLog())); timer->setSingleShot(false); timer->start(1000); @@ -698,46 +705,6 @@ void DiscoveryDruid::changedDiscoveryMethod(int c) } } -void DiscoveryDruid::saveScanLog() -{ - 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()); - if (fwbdebug) - qDebug("--------------------------------"); - f.close(); - } - } -} - void DiscoveryDruid::startHostsScan() { if (thread!=NULL) @@ -866,60 +833,6 @@ InetAddr DiscoveryDruid::getSeedHostAddress() return seed_host_addr; } -void DiscoveryDruid::startSNMPScan() -{ -#ifdef HAVE_LIBSNMP - - - bool use_incl=!m_dialog->snmpinaddr->text().isEmpty() && !m_dialog->snmpinmask->text().isEmpty(); - if (use_incl) - { - try - { - InetAddrMask in( - InetAddr(m_dialog->snmpinaddr->text().toLatin1().constData()), - InetAddr(m_dialog->snmpinmask->text().toLatin1().constData()) - ); - include_networks.push_back(in); - } - catch (const FWException &ex) - { - //TODO: to do something usefull - } - } - libfwbuilder::SNMPCrawler *q=new SNMPCrawler(); - q->init(getSeedHostAddress(), - m_dialog->snmpcommunity->text().toLatin1().constData(), - m_dialog->snmprecursive->isChecked(), - ! m_dialog->snmpincludevirt->isChecked(), - false, - m_dialog->snmpfollowp2p->isChecked(), - 0, - m_dialog->snmpretries->value(), - 1000000L*m_dialog->snmptimeout->value(), - 0, - 0, - (use_incl) ? &include_networks : NULL); - - m_dialog->discoveryprogress->setMaximum(0); - unBar=m_dialog->discoveryprogress; - - bop=q; - try - { - logger=bop->start_operation(); - m_dialog->discoverylog->append("Collecting data ..."); - - } catch(const FWException &ex) - { - delete q; - q=NULL; - } - - -#endif -} - void DiscoveryDruid::changedDomainName() { if (m_dialog->domainname->text().isEmpty()) @@ -1387,6 +1300,106 @@ void DiscoveryDruid::loadDataFromImporter() } } +void DiscoveryDruid::saveScanLog() +{ + 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()); + if (fwbdebug) + qDebug("--------------------------------"); + f.close(); + } + } +} + +void DiscoveryDruid::startSNMPScan() +{ +#ifdef HAVE_LIBSNMP + + + bool use_incl=!m_dialog->snmpinaddr->text().isEmpty() && !m_dialog->snmpinmask->text().isEmpty(); + if (use_incl) + { + try + { + InetAddrMask in( + InetAddr(m_dialog->snmpinaddr->text().toLatin1().constData()), + InetAddr(m_dialog->snmpinmask->text().toLatin1().constData()) + ); + include_networks.push_back(in); + } + catch (const FWException &ex) + { + //TODO: to do something usefull + } + } + libfwbuilder::SNMPCrawler *q = new SNMPCrawler(); + q->init(getSeedHostAddress(), + m_dialog->snmpcommunity->text().toLatin1().constData(), + m_dialog->snmprecursive->isChecked(), + ! m_dialog->snmpincludevirt->isChecked(), + false, + m_dialog->snmpfollowp2p->isChecked(), + 0, + m_dialog->snmpretries->value(), + 1000000L*m_dialog->snmptimeout->value(), + 0, + 0, + (use_incl) ? &include_networks : NULL); + + m_dialog->discoveryprogress->setMaximum(0); + unBar = m_dialog->discoveryprogress; + + bop=q; + try + { + logger = bop->start_operation(); + if (fwbdebug) logger->copyToStderr(); + m_dialog->discoverylog->append("Collecting data ..."); + + disconnect(timer, SIGNAL(timeout()), 0, 0); + connect(timer, SIGNAL(timeout()), this, SLOT(updateLog())); + timer->setSingleShot(false); + timer->start(100); + + } catch(const FWException &ex) + { + delete q; + q=NULL; + } + + +#endif +} + void DiscoveryDruid::loadDataFromCrawler() { #ifdef HAVE_LIBSNMP @@ -1615,6 +1628,8 @@ void DiscoveryDruid::customEvent(QEvent *event) void DiscoveryDruid::updateLog() { + if (fwbdebug) qDebug("DiscoveryDruid::updateLog"); + if (current_task==BT_HOSTS || current_task==BT_IMPORT) { QString buf; @@ -1981,9 +1996,7 @@ void DiscoveryDruid::createRealObjects() m_dialog->lastprogress->setMaximum( Objects.size()); QMap::iterator i; - for(i=Networks.begin(); - i!=Networks.end(); - ++i) + for(i=Networks.begin(); i!=Networks.end(); ++i) { od=i.value(); if (od.isSelected) @@ -2003,15 +2016,13 @@ void DiscoveryDruid::createRealObjects() } } - for(i=Objects.begin(); - i!=Objects.end(); - ++i) + for(i=Objects.begin(); i!=Objects.end(); ++i) { - od=i.value(); - type=od.type; + od = i.value(); + type = od.type; - name=od.sysname; - a=od.addr.toString(); + name = od.sysname; + a = od.addr.toString(); if(od.isSelected) { @@ -2019,7 +2030,7 @@ void DiscoveryDruid::createRealObjects() { FWObject *o=NULL; - o=mw->createObject(type.c_str(),name.c_str()); + o = mw->createObject(type.c_str(), name.c_str()); o->setName(name); if (od.interfaces.size()==0) @@ -2036,18 +2047,32 @@ void DiscoveryDruid::createRealObjects() ipv4->setNetmask(InetAddr()); } else { - map::const_iterator i; + map::const_iterator i; for (i=od.interfaces.begin(); i!=od.interfaces.end(); ++i) { - Interface in=i->second; - Interface *itf= - Interface::cast(mw->createObject( - o, - Interface::TYPENAME, - (i->second).getName().c_str(), - &in)); - mw->autorename(itf,IPv4::TYPENAME,"ip"); - mw->autorename(itf,physAddress::TYPENAME,"mac"); + InterfaceData in = i->second; + if (in.addr_mask.getAddressPtr()->isAny()) continue; + + Interface *itf = Interface::cast( + mw->createObject(o, + QString(Interface::TYPENAME), + QString(i->second.name.c_str()))); + + itf->setPhysicalAddress(in.mac_addr); + itf->setLabel(in.label); + itf->setExt(in.ext); + itf->setSecurityLevel(in.securityLevel); + + const InetAddr *addr = in.addr_mask.getAddressPtr(); + IPv4 *ipv4= IPv4::cast( + mw->createObject(itf, IPv4::TYPENAME, + addr->toString().c_str()) + ); + ipv4->setAddress(*addr); + ipv4->setNetmask(*(in.addr_mask.getNetmaskPtr())); + + mw->autorename(itf, IPv4::TYPENAME, "ip"); + mw->autorename(itf, physAddress::TYPENAME, "mac"); } } if (!od.descr.empty()) @@ -2101,14 +2126,14 @@ void DiscoveryDruid::createRealObjects() } void DiscoveryDruid::autorename(FWObject *obj, - const string &objtype, - const string &namesuffix) + const string &objtype, + const string &namesuffix) { FWObject *hst = obj->getParent(); list ol = obj->getByType(objtype); int sfxn = 1; - for (list::iterator j=ol.begin(); j!=ol.end(); ++j,sfxn++) + for (list::iterator j=ol.begin(); j!=ol.end(); ++j,++sfxn) { QString sfx; if (ol.size()==1) sfx=""; @@ -2214,7 +2239,7 @@ ObjectDescriptor& ObjectDescriptor::operator=(const ObjectDescriptor& od) { WorkerThread::WorkerThread() : QThread() { - Log=new QueueLogger(); + Log = new QueueLogger(); } WorkerThread::~WorkerThread() @@ -2224,7 +2249,7 @@ WorkerThread::~WorkerThread() void WorkerThread::setProgress(int p) { - ProgressEvent *event=new ProgressEvent(); + ProgressEvent *event = new ProgressEvent(); event->value=p; QApplication::postEvent(Widget,event); diff --git a/src/gui/DiscoveryDruid.h b/src/gui/DiscoveryDruid.h index b8ec3cc53..59b9b8ee0 100644 --- a/src/gui/DiscoveryDruid.h +++ b/src/gui/DiscoveryDruid.h @@ -36,6 +36,7 @@ #include #include "fwbuilder/Interface.h" +#include "fwbuilder/InterfaceData.h" #include "fwbuilder/dns.h" #include "fwbuilder/snmp.h" #include "fwbuilder/InetAddr.h" @@ -65,7 +66,7 @@ class ObjectDescriptor bool isSelected; - map interfaces ; + map interfaces ; string MAC_addr ; libfwbuilder::HostEnt dns_info ; @@ -118,7 +119,7 @@ class DoneEvent : public QEvent typedef enum {BT_NONE,BT_HOSTS,BT_DNS,BT_SNMP,BT_IMPORT} BackgroundTask; -class WorkerThread : public QThread, QObject +class WorkerThread : public QThread { QWidget *Widget; diff --git a/src/gui/InterfaceData.cpp b/src/gui/InterfaceData.cpp deleted file mode 100644 index f1dee7d76..000000000 --- a/src/gui/InterfaceData.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - - Firewall Builder - - Copyright (C) 2001 NetCitadel, LLC - - Author: Vadim Kurland vadim@vk.crocodile.org - - $Id: InterfaceData.cpp,v 1.2 2006/03/06 03:02:57 vkurland Exp $ - - - 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 "fwbuilder_ph.h" - -#include "InterfaceData.h" - -#include "fwbuilder/Resources.h" -#include "fwbuilder/InetAddr.h" - -using namespace libfwbuilder; -using namespace std; - -InterfaceData::InterfaceData(const libfwbuilder::Interface &iface) -{ - id = iface.getId(); - name = iface.getName(); - - IPv4 *addr = IPv4::cast(iface.getFirstByType(IPv4::TYPENAME)); - if (addr) - { - address = addr->getAddressPtr()->toString(); - netmask = addr->getNetmaskPtr()->toString(); - } - else - { - address = ""; - netmask = ""; - } - - securityLevel = iface.getSecurityLevel(); - isDyn = iface.isDyn(); - isUnnumbered = iface.isUnnumbered(); - isBridgePort = iface.isBridgePort(); - libfwbuilder::physAddress *pa = iface.getPhysicalAddress(); - if (pa!=NULL) - physicalAddress = pa->getPhysAddress(); - label = iface.getLabel(); - networkZone = iface.getStr("network_zone"); -} - -void InterfaceData::guessLabel(const string&) -{ -/* - * some firewalls report fairly regular names for interfaces through - * their built-in SNMP agent. We can use this to assign labels - * automatically. - * - * in PIX interfaces have names like "PIX Firewall 'inside' interface" - * - */ - string pat1="PIX Firewall '"; - string pat2="' interface"; - string::size_type p2; - if ( name.find(pat1)==0 && (p2=name.find(pat2))!=string::npos ) - label=name.substr( pat1.size() , p2-pat1.size() ); - - if (!isDyn && - !isUnnumbered && - !isBridgePort && - address == InetAddr::getLoopbackAddr().toString()) - label="loopback"; -} - - - -void InterfaceData::guessSecurityLevel(const string&) -{ - InetAddrMask n10(InetAddr("10.0.0.0"), InetAddr("255.0.0.0")); - InetAddrMask n172(InetAddr("172.16.0.0"), InetAddr("255.240.0.0")); - InetAddrMask n192(InetAddr("192.168.0.0"), InetAddr("255.255.0.0")); - - securityLevel=-1; - - string llbl=label; - - for (string::size_type i=0; i &ifaces) -{ -// first pass - try to find internal and external interfaces and -// assign sec. levels and labels - -// bool supports_security_levels=Resources::getTargetCapabilityBool(platform, -// "security_levels"); - - list res; - - if (ifaces.size()==1) - { - ifaces.front().guessSecurityLevel(platform); - return; - } - - if (ifaces.size()==2) - { - if (ifaces.front().address==InetAddr::getLoopbackAddr().toString()) - { - ifaces.front().securityLevel=100; - ifaces.back().securityLevel=0; - } else - { - if (ifaces.back().address==InetAddr::getLoopbackAddr().toString()) - { - ifaces.front().securityLevel=0; - ifaces.back().securityLevel=100; - } else - { - ifaces.front().guessSecurityLevel(platform); - ifaces.back().guessSecurityLevel(platform); - } - } - ifaces.sort(sort_order_func_adaptor()); - return; - } - else - { - for (list::iterator i=ifaces.begin(); i!=ifaces.end(); i++) - { - i->guessSecurityLevel(platform); - } - } - - ifaces.sort(sort_order_func_adaptor()); - -// second pass - Assign sec. levels evenly if it is pix, or all zeros in all other cases. - - int sec_level_step= 100 / ( ifaces.size() - 1 ); - int sec_level = 0; - - for (list::iterator i=ifaces.begin(); i!=ifaces.end(); i++) - { - i->securityLevel=sec_level; - sec_level += sec_level_step; - } -} - - diff --git a/src/gui/InterfaceData.h b/src/gui/InterfaceData.h deleted file mode 100644 index 917aafcb5..000000000 --- a/src/gui/InterfaceData.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - - Firewall Builder - - Copyright (C) 2001 NetCitadel, LLC - - Author: Vadim Kurland vadim@vk.crocodile.org - - $Id: InterfaceData.h,v 1.2 2006/03/06 03:02:57 vkurland Exp $ - - - 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 __INTERFACE_DATA_HH_ -#define __INTERFACE_DATA_HH_ - - -#include "fwbuilder/Interface.h" -#include "fwbuilder/physAddress.h" - -struct InterfaceData -{ - std::string id; - std::string name; - std::string address; - std::string netmask; - int securityLevel; - bool isDyn; - bool isUnnumbered; - bool isBridgePort; - std::string physicalAddress; - std::string label; - std::string networkZone; - - InterfaceData() - { - isDyn = false; - isUnnumbered = false; - isBridgePort = false; - securityLevel = 0; - } - - InterfaceData(const libfwbuilder::Interface &iface); - -/** - * this method is a collection of heuristics that allow us to assign - * a reasonable label to the interface based on firewall platform, - * name of the interface, its label and other parameters. - */ - void guessLabel(const std::string &platform); - -/** - * this method is a collection of heuristics that allow us to make an - * educated guess about interface's security level based on the - * firewall platform, name of the interface, its label and other - * parameters. - */ - void guessSecurityLevel(const std::string &platform); - -/** - * This method is a collection of heuristics that allow us to assign - * a reasonable security level to many interfaces based on firewall - * platform, their names and labels and other parameters. This method - * compares parameters of many interfaces and in certain cases can - * guess their relative security levels. - */ - static void guessSecurityLevel(const std::string &platform, - std::list &interfaces); - -}; -#endif diff --git a/src/gui/ObjectManipulator.cpp b/src/gui/ObjectManipulator.cpp index 46944c7c9..d507712f6 100644 --- a/src/gui/ObjectManipulator.cpp +++ b/src/gui/ObjectManipulator.cpp @@ -520,13 +520,15 @@ void ObjectManipulator::updateObjName(FWObject *obj, itm->setText(0, pom->getTreeLabel( obj ) ); - if (!Library::isA(obj)) itm->parent()->sortChildren(0, Qt::AscendingOrder); + if (!Library::isA(obj)) + itm->parent()->sortChildren(0, Qt::AscendingOrder); - /* need to update name of the firewall in the drop-down list */ + /* need to update name of the firewall in the drop-down list */ if (Firewall::isA(obj)) { pom->m_project->updateFirewallName(obj,oldName); } + if (RuleSet::cast(obj)!=NULL) { pom->m_project->updateFirewallName(obj,oldName); @@ -571,7 +573,7 @@ void ObjectManipulator::updateObjName(FWObject *obj, info(); // need to update info in case user edited comments and other attributes. } -void ObjectManipulator::autorename(FWObject *obj,bool ask) +void ObjectManipulator::autorename(FWObject *obj, bool ask) { if (Host::isA(obj) || Firewall::isA(obj)) { @@ -637,35 +639,36 @@ void ObjectManipulator::autorename(FWObject *obj, const string &objtype, const string &namesuffix) { - QVector oms = getAllMdiObjectManipulators(); - for (int i = 0 ; i < oms.size(); i++) - { - ObjectManipulator* pom = oms[i] ; - - FWObject *hst = obj->getParent(); - list ol = obj->getByType(objtype); - int sfxn = 1; - - for (list::iterator j=ol.begin(); j!=ol.end(); ++j,sfxn++) + QVector oms = getAllMdiObjectManipulators(); + for (int i = 0 ; i < oms.size(); i++) { - QString sfx; - if (ol.size()==1) sfx=""; - else sfx.setNum(sfxn); - QString nn = QString("%1:%2:%3%4") - .arg(QString::fromUtf8(hst->getName().c_str())) - .arg(QString::fromUtf8(obj->getName().c_str())) - .arg(namesuffix.c_str()) - .arg(sfx); + ObjectManipulator* pom = oms[i] ; - (*j)->setName(string(nn.toUtf8())); - QTreeWidgetItem *itm1 = pom->allItems[ *j ]; - assert(itm1!=NULL); - itm1->setText(0, getTreeLabel( *j ) ); - itm1->parent()->sortChildren(0, Qt::AscendingOrder);//(); - } - ol.clear(); - } + FWObject *hst = obj->getParent(); + list ol = obj->getByType(objtype); + int sfxn = 1; + for (list::iterator j=ol.begin(); j!=ol.end(); ++j,sfxn++) + { + QString sfx; + if (ol.size()==1) sfx=""; + else sfx.setNum(sfxn); + QString nn = QString("%1:%2:%3%4") + .arg(QString::fromUtf8(hst->getName().c_str())) + .arg(QString::fromUtf8(obj->getName().c_str())) + .arg(namesuffix.c_str()) + .arg(sfx); + + (*j)->setName(string(nn.toUtf8())); + QTreeWidgetItem *itm1 = pom->allItems[ *j ]; + if (itm1!=NULL) + { + itm1->setText(0, getTreeLabel( *j ) ); + itm1->parent()->sortChildren(0, Qt::AscendingOrder);//(); + } + } + ol.clear(); + } } void ObjectManipulator::clearObjects() @@ -2468,7 +2471,7 @@ void ObjectManipulator::invalidateDialog() void ObjectManipulator::libChangedById(int id) { - for (int i = 0 ; i < idxToLibs.size(); i++) + for (vector::size_type i = 0 ; i < idxToLibs.size(); i++) { if (idxToLibs[i]->getId()==id) { @@ -2483,7 +2486,7 @@ void ObjectManipulator::changeFirstNotSystemLib() { QString sid2 = "syslib000"; QString sid3 = "syslib001"; - for (int i = 0 ; i < idxToLibs.size(); i++) + for (vector::size_type i = 0 ; i < idxToLibs.size(); i++) { QString sid1 = FWObjectDatabase::getStringId(idxToLibs[i]->getId()).c_str(); if ( sid1 != sid2) @@ -2630,15 +2633,17 @@ FWObject* ObjectManipulator::createObject(const QString &objType, lib->getName().c_str(), FWObjectDatabase::getStringId(lib->getId()).c_str()); qDebug("lib: isReadOnly=%d isLoaded=%d", - lib->isReadOnly(), m_project->getAddOnLibs()->isLoaded( lib->getName().c_str() ) ); + lib->isReadOnly(), + m_project->getAddOnLibs()->isLoaded(lib->getName().c_str())); } i++; } - FWObject *parent=m_project->getFWTree()->getStandardSlotForObject(lib, objType); + FWObject *parent = + m_project->getFWTree()->getStandardSlotForObject(lib, objType); + if (parent==NULL) { - QMessageBox::warning(this,"Firewall Builder", QObject::tr( "Type '%1': new object can not be created because\n" @@ -2647,18 +2652,16 @@ FWObject* ObjectManipulator::createObject(const QString &objType, .arg(objType), "&Continue", QString::null, QString::null, 0, 1 ); - - return NULL; } + return actuallyCreateObject(parent,objType,objName,copyFrom); - } FWObject* ObjectManipulator::createObject(FWObject *parent, - const QString &objType, - const QString &objName, - FWObject *copyFrom) + const QString &objType, + const QString &objName, + FWObject *copyFrom) { if (!validateDialog()) return NULL; diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 81d7d9a19..c4b0a5f3c 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -36,7 +36,6 @@ HEADERS += ../../config.h \ newGroupDialog.h \ filePropDialog.h \ DialogData.h \ - InterfaceData.h \ execDialog.h \ SimpleTextEditor.h \ SimpleIntEditor.h \ @@ -149,7 +148,6 @@ SOURCES += ProjectPanel.cpp \ newGroupDialog.cpp \ filePropDialog.cpp \ DialogData.cpp \ - InterfaceData.cpp \ execDialog.cpp \ SimpleTextEditor.cpp \ SimpleIntEditor.cpp \ diff --git a/src/gui/newFirewallDialog.cpp b/src/gui/newFirewallDialog.cpp index e72fa0e83..5b4560a27 100644 --- a/src/gui/newFirewallDialog.cpp +++ b/src/gui/newFirewallDialog.cpp @@ -32,7 +32,6 @@ #include "platforms.h" #include "newFirewallDialog.h" -#include "InterfaceData.h" #include "FWWindow.h" #include "ObjConflictResolutionDialog.h" #include "upgradePredicate.h" @@ -230,10 +229,11 @@ void newFirewallDialog::monitor() timer->stop(); - const map &intf = q->getInterfaces(); - for(map::const_iterator i=intf.begin();i!=intf.end(); ++i) + const map &intf = q->getInterfaces(); + map::const_iterator i; + for(i=intf.begin();i!=intf.end(); ++i) { - if ( i->second.isUp() ) + if ( i->second.ostatus ) { InterfaceData idata( i->second ); @@ -247,10 +247,10 @@ void newFirewallDialog::monitor() QStringList qsl; qsl << idata.name.c_str() << idata.label.c_str() - << idata.address.c_str() - << idata.netmask.c_str() + << idata.addr_mask.getAddressPtr()->toString().c_str() + << idata.addr_mask.getNetmaskPtr()->toString().c_str() << dn - << idata.physicalAddress.c_str(); + << idata.mac_addr.c_str(); new QTreeWidgetItem(m_dialog->iface_list, qsl); // cerr << "Added interface " << idata.name << endl; @@ -485,9 +485,10 @@ void newFirewallDialog::fillInterfaceSLList() idata.isBridgePort = itm->text(4).indexOf("Bridge")!=-1; if (!idata.isDyn && !idata.isUnnumbered && !idata.isBridgePort) - idata.address = itm->text(2).toLatin1().constData(); + idata.addr_mask.setAddress(itm->text(2).toLatin1().constData()); else - idata.address = QObject::tr("dynamic").toLatin1().constData(); + idata.addr_mask.setAddress( + QObject::tr("dynamic").toLatin1().constData()); try { @@ -506,7 +507,7 @@ void newFirewallDialog::fillInterfaceSLList() QStringList qsl; qsl << idata.name.c_str() << idata.label.c_str() - << idata.address.c_str() + << idata.addr_mask.getAddressPtr()->toString().c_str() << QString::number(idata.securityLevel); new QTreeWidgetItem(m_dialog->iface_sl_list, qsl); diff --git a/src/gui/newFirewallDialog.h b/src/gui/newFirewallDialog.h index 2d336554b..81060d445 100644 --- a/src/gui/newFirewallDialog.h +++ b/src/gui/newFirewallDialog.h @@ -30,7 +30,7 @@ #include "../../config.h" #include -#include "InterfaceData.h" +#include "fwbuilder/InterfaceData.h" #include "fakeWizard.h" #include diff --git a/src/gui/newHostDialog.cpp b/src/gui/newHostDialog.cpp index bdaf4763a..cf5a5de3d 100644 --- a/src/gui/newHostDialog.cpp +++ b/src/gui/newHostDialog.cpp @@ -33,7 +33,6 @@ #include "platforms.h" #include "newHostDialog.h" -#include "InterfaceData.h" #include "FWWindow.h" #include "ObjConflictResolutionDialog.h" #include "upgradePredicate.h" @@ -224,10 +223,11 @@ void newHostDialog::monitor() timer->stop(); - const map &intf = q->getInterfaces(); - for(map::const_iterator i=intf.begin();i!=intf.end(); ++i) + const map &intf = q->getInterfaces(); + map::const_iterator i; + for(i=intf.begin();i!=intf.end(); ++i) { - if ( i->second.isUp() ) + if ( i->second.ostatus ) { InterfaceData idata( i->second ); @@ -240,10 +240,10 @@ void newHostDialog::monitor() QStringList qsl; qsl << idata.name.c_str() << idata.label.c_str() - << idata.address.c_str() - << idata.netmask.c_str() + << idata.addr_mask.getAddressPtr()->toString().c_str() + << idata.addr_mask.getNetmaskPtr()->toString().c_str() << dn - << idata.physicalAddress.c_str(); + << idata.mac_addr.c_str(); new QTreeWidgetItem(m_dialog->iface_list, qsl); // cerr << "Added interface " << idata.name << endl; diff --git a/src/gui/newHostDialog.h b/src/gui/newHostDialog.h index 2839d932e..ca484150c 100644 --- a/src/gui/newHostDialog.h +++ b/src/gui/newHostDialog.h @@ -30,7 +30,7 @@ #include "../../config.h" #include -#include "InterfaceData.h" +#include "fwbuilder/InterfaceData.h" #include "fakeWizard.h" #include diff --git a/src/gui/projectpanel_q.ui b/src/gui/projectpanel_q.ui index 8fc956f0a..5eafdc47f 100644 --- a/src/gui/projectpanel_q.ui +++ b/src/gui/projectpanel_q.ui @@ -88,9 +88,15 @@ true + + + 0 + 0 + + - 150 + 0 50 @@ -121,6 +127,12 @@ + + + 0 + 0 + + QFrame::StyledPanel @@ -206,7 +218,7 @@ - + 0 0 @@ -266,7 +278,7 @@ - + 0 0