From 2e65d946dacdcb3e50e9694779023a040275f7ad Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Fri, 4 Mar 2011 18:06:54 -0800 Subject: [PATCH] see #2161 import wizard finished --- doc/ChangeLog | 4 + src/libgui/discoverydruid_q.ui | 4 +- .../IC_FirewallNamePage.cpp | 25 ++- .../IC_NetworkZonesPage.cpp | 150 ++++++++++++++++ .../IC_NetworkZonesPage.h | 49 +++++ .../IC_PlatformWarningPage.cpp | 13 +- .../IC_ProgressPage.cpp | 169 +++++++++++++++++- .../IC_ProgressPage.h | 20 +++ .../ImportFirewallConfigurationWizard.cpp | 25 ++- .../ImportFirewallConfigurationWizard.h | 18 +- .../ImporterThread.cpp | 109 +++++++++++ .../ImporterThread.h | 73 ++++++++ .../ic_networkzonespage_q.ui | 110 ++++++++++++ .../ic_progresspage_q.ui | 2 +- src/libgui/libgui.pro | 5 + 15 files changed, 744 insertions(+), 32 deletions(-) create mode 100644 src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.cpp create mode 100644 src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.h create mode 100644 src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp create mode 100644 src/libgui/importFirewallConfigurationWizard/ImporterThread.h create mode 100644 src/libgui/importFirewallConfigurationWizard/ic_networkzonespage_q.ui diff --git a/doc/ChangeLog b/doc/ChangeLog index bdb485537..3c5ef1275 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,9 @@ 2011-03-04 vadim + * IC_NetworkZonesPage.cpp (setNetworkZones): see #2161 policy + import wizard shows the page where user can set up network zones + of interfaces if firewall platform was determined to be PIX. + * IC_PlatformWarningPage.cpp (initializePage): see #2161 "import workflow and automatic detection of firewall platform from the config file". When user imports existing firewall configuration, diff --git a/src/libgui/discoverydruid_q.ui b/src/libgui/discoverydruid_q.ui index a1bd084df..174898c2b 100644 --- a/src/libgui/discoverydruid_q.ui +++ b/src/libgui/discoverydruid_q.ui @@ -48,7 +48,7 @@ - 2 + 14 @@ -2052,7 +2052,7 @@ Please enter the domain name below: - :/Images/network_zone_dialog.png + :/Images/network_zone_dialog.png Qt::AlignCenter diff --git a/src/libgui/importFirewallConfigurationWizard/IC_FirewallNamePage.cpp b/src/libgui/importFirewallConfigurationWizard/IC_FirewallNamePage.cpp index e2616621b..94740db1c 100644 --- a/src/libgui/importFirewallConfigurationWizard/IC_FirewallNamePage.cpp +++ b/src/libgui/importFirewallConfigurationWizard/IC_FirewallNamePage.cpp @@ -49,31 +49,26 @@ void IC_FirewallNamePage::initializePage() dynamic_cast(wizard())-> getPlatform(); - QString fileName = field("fileName").toString(); + QStringList *buf = + dynamic_cast(wizard())-> + getBufferPtr(); qDebug() << "platform=" << platform; if (platform == "pix" || platform == "ios_acl") { - QFile cf(fileName); - if (cf.open(QIODevice::ReadOnly )) + QRegExp cisco_re("^hostname\\s+(\\S+)"); + + foreach(QString line, *buf) { - QRegExp cisco_re("^hostname\\s+(\\S+)"); - - QTextStream stream(&cf); - while (true) + if (cisco_re.indexIn(line) > -1) { - QString line = stream.readLine().trimmed(); - if (line.isNull()) break; - - if (cisco_re.indexIn(line) > -1) - { - m_dialog->firewallName->setText(cisco_re.cap(1)); - break; - } + m_dialog->firewallName->setText(cisco_re.cap(1)); + break; } } } + setCommitPage(true); emit completeChanged(); } diff --git a/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.cpp b/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.cpp new file mode 100644 index 000000000..ddae9e2f8 --- /dev/null +++ b/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.cpp @@ -0,0 +1,150 @@ +/* + + 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 "global.h" +#include "events.h" +#include "FWBSettings.h" +#include "FWWindow.h" +#include "ProjectPanel.h" +#include "networkZoneManager.h" + +#include "IC_NetworkZonesPage.h" +#include "ImportFirewallConfigurationWizard.h" + +#include "fwbuilder/Interface.h" +#include "fwbuilder/Firewall.h" + +#include +#include +#include + + +using namespace std; +using namespace libfwbuilder; + + +IC_NetworkZonesPage::IC_NetworkZonesPage(QWidget *parent) : + QWizardPage(parent), + m_dialog(new Ui::IC_NetworkZonesPage_q) +{ + m_dialog->setupUi(this); +} + +IC_NetworkZonesPage::~IC_NetworkZonesPage() +{ + delete m_dialog; +} + +void IC_NetworkZonesPage::initializePage() +{ + Firewall *fw = + dynamic_cast(wizard())->getFirewall(); + + m_dialog->iface_nz_list->clear(); + + QStringList labels; + labels << QObject::tr("Name") << QObject::tr("Label") + << QObject::tr("Address") << QObject::tr("Network Zone"); + m_dialog->iface_nz_list->setHorizontalHeaderLabels(labels); + + NetworkZoneManager netzone_manager; + netzone_manager.load(mw->activeProject()->db()); + + list all_interfaces = fw->getByTypeDeep(Interface::TYPENAME); + list::iterator it; + int row = 0; + for (it=all_interfaces.begin(); it!=all_interfaces.end(); ++it) + { + Interface *iface = Interface::cast(*it); + + m_dialog->iface_nz_list->insertRow(row); + + QTableWidgetItem* itm; + + itm = new QTableWidgetItem(iface->getName().c_str()); + itm->setFlags(itm->flags() & ~Qt::ItemIsEditable); + m_dialog->iface_nz_list->setItem(row, 0, itm); + + itm = new QTableWidgetItem(iface->getLabel().c_str()); + itm->setFlags(itm->flags() & ~Qt::ItemIsEditable); + m_dialog->iface_nz_list->setItem(row, 1, itm); + + QString addr_str; + const InetAddr* addr = iface->getAddressPtr(); + if (addr) addr_str = addr->toString().c_str(); + + itm = new QTableWidgetItem(addr_str); + itm->setFlags(itm->flags() & ~Qt::ItemIsEditable); + m_dialog->iface_nz_list->setItem(row, 2, itm); + + QComboBox *widget = new QComboBox(); + netzone_manager.packComboBox(widget, -1); + m_dialog->iface_nz_list->setCellWidget(row, 3, widget); + + row++; + } + + m_dialog->iface_nz_list->resizeColumnToContents(3); +} + +void IC_NetworkZonesPage::setNetworkZones() +{ + Firewall *fw = + dynamic_cast(wizard())->getFirewall(); + + // read and configure network zones + list all_interfaces = fw->getByTypeDeep(Interface::TYPENAME); + list::iterator it; + for (it=all_interfaces.begin(); it!=all_interfaces.end(); ++it) + { + Interface *iface = Interface::cast(*it); + + string network_zone_str_id = ""; + + QList ltwi = + m_dialog->iface_nz_list->findItems( iface->getName().c_str(), + Qt::MatchExactly ); + if ( ! ltwi.empty()) + { + QTableWidgetItem *itm2 = ltwi[0]; + assert(itm2!=NULL); + int row = itm2->row(); + QComboBox *cb = dynamic_cast( + m_dialog->iface_nz_list->cellWidget(row, 3)); + assert(cb!=NULL); + int network_zone_int_id = + cb->itemData(cb->currentIndex(), Qt::UserRole).toInt(); + if (network_zone_int_id != 0) + network_zone_str_id = FWObjectDatabase::getStringId( + network_zone_int_id); + else + network_zone_str_id = ""; + } + + // only set network zone if it is supported and is not + // empty. See #2014 + if (!network_zone_str_id.empty()) + iface->setStr("network_zone", network_zone_str_id); + + } +} diff --git a/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.h b/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.h new file mode 100644 index 000000000..30f97643d --- /dev/null +++ b/src/libgui/importFirewallConfigurationWizard/IC_NetworkZonesPage.h @@ -0,0 +1,49 @@ +/* + + 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 NETWORKZONESPAGE_H +#define NETWORKZONESPAGE_H + +#include "ui_ic_networkzonespage_q.h" +#include + +namespace Ui { + class IC_NetworkZonesPage_q; +} + +class IC_NetworkZonesPage : public QWizardPage +{ + Q_OBJECT; + + Ui::IC_NetworkZonesPage_q *m_dialog; + +public: + explicit IC_NetworkZonesPage(QWidget *parent = 0); + virtual ~IC_NetworkZonesPage(); + + virtual void initializePage(); + + void setNetworkZones(); +}; + +#endif // NETWORKZONESPAGE_H diff --git a/src/libgui/importFirewallConfigurationWizard/IC_PlatformWarningPage.cpp b/src/libgui/importFirewallConfigurationWizard/IC_PlatformWarningPage.cpp index 46c8c3e35..da7ef4368 100644 --- a/src/libgui/importFirewallConfigurationWizard/IC_PlatformWarningPage.cpp +++ b/src/libgui/importFirewallConfigurationWizard/IC_PlatformWarningPage.cpp @@ -86,19 +86,22 @@ void IC_PlatformWarningPage::initializePage() m_dialog->configFileBrowser->clear(); m_dialog->platform->setText(tr("Unknown")); - QStringList buf; + QStringList *buf = + dynamic_cast(wizard())-> + getBufferPtr(); + QTextStream stream(&cf); while (true) { QString line = stream.readLine().trimmed(); if (line.isNull()) break; m_dialog->configFileBrowser->append(line); - buf << line; + *buf << line; } bool iptables_c = false; - foreach (QString line, buf) + foreach (QString line, *buf) { foreach (QRegExp re, pix_re) { @@ -113,7 +116,7 @@ void IC_PlatformWarningPage::initializePage() { if (re.indexIn(line) > -1) { - detectedPlatform = "ios_acl"; + detectedPlatform = "iosacl"; break; } } @@ -174,7 +177,7 @@ void IC_PlatformWarningPage::initializePage() platformOk = true; } - if (detectedPlatform == "ios_acl") + if (detectedPlatform == "iosacl") { m_dialog->platform->setText(tr("Cisco Router IOS")); m_dialog->platformSpecificWarning->setText( diff --git a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp index 35e0a24c2..ccc5f4f41 100644 --- a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp +++ b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp @@ -23,19 +23,182 @@ #include "global.h" +#include "events.h" #include "FWBSettings.h" +#include "FWWindow.h" +#include "ProjectPanel.h" #include "IC_ProgressPage.h" +#include "ImporterThread.h" +#include "ImportFirewallConfigurationWizard.h" + +#include "fwbuilder/Policy.h" #include #include #include +#include + + +using namespace std; +using namespace libfwbuilder; + +bool fwbdebug_ic = true; IC_ProgressPage::IC_ProgressPage(QWidget *parent) : QWizardPage(parent) { m_dialog = new Ui::IC_ProgressPage_q; m_dialog->setupUi(this); + importer = NULL; + + QTextCursor cursor(m_dialog->importLog->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"); +} + +int IC_ProgressPage::nextId () const +{ + QString platform = + dynamic_cast(wizard())-> + getPlatform(); + + if (platform == "pix") + return ImportFirewallConfigurationWizard::Page_NetworkZones; + + return -1; +} + +bool IC_ProgressPage::validatePage() +{ + if (fwbdebug_ic) + qDebug() << "IC_ProgressPage::validatePage()" + << "importer=" << importer + << "isRunning=" << ((importer) ? importer->isRunning() : 0); + + if (importer != NULL && importer->isRunning()) return false; + return true; +} + +void IC_ProgressPage::importerDestroyed(QObject *obj) +{ + if (fwbdebug_ic) qDebug() << "ND_ProgressPage::importerDestroyed() obj=" << obj; + if (obj == importer) importer = NULL; +} + +void IC_ProgressPage::initializePage() +{ + if (importer != NULL && importer->isRunning()) + { + if (fwbdebug_ic) + qDebug() << "ND_ProgressPage::initializePage()" + << "importer is still runnig; stopping"; + importer->stop(); + importer->wait(); + delete importer; + } + + m_dialog->importLog->clear(); + + QString platform = + dynamic_cast(wizard())-> + getPlatform(); + QString firewallName = field("firewallName").toString(); + QStringList *buffer = + dynamic_cast(wizard())-> + getBufferPtr(); + + importer = new ImporterThread(this, + mw->getCurrentLib(), + *buffer, platform, firewallName); + connect(importer, SIGNAL(destroyed(QObject*)), + this, SLOT(importerDestroyed(QObject*))); + connect(importer, SIGNAL(finished()), + this, SLOT(importerFinished())); + + importer->start(); +} + +void IC_ProgressPage::cleanupPage() +{ + if (fwbdebug_ic) qDebug() << "IC_ProgressPage::cleanupPage()"; + disconnect(this, SLOT(logLine(QString))); + disconnect(this, SLOT(importerFinished())); + if (importer != NULL && importer->isRunning()) importer->wait(); +} + +void IC_ProgressPage::importerFinished() +{ + if (fwbdebug_ic) qDebug() << "IC_ProgressPage::importerFinished()"; + + Firewall *fw = importer->getFirewallObject(); + qApp->processEvents(); // to flush the log + + dynamic_cast(wizard())->setFirewall(fw); + + if (fw) // fw can be NULL if import was uncussessful + { + ProjectPanel *pp = mw->activeProject(); + QString filename = pp->getFileName(); + + QCoreApplication::postEvent(mw, new reloadObjectTreeEvent(filename)); + if (mw->isEditorVisible()) + QCoreApplication::postEvent( + mw, new openObjectInEditorEvent(filename, fw->getId())); + QCoreApplication::postEvent( + mw, new showObjectInTreeEvent(filename, fw->getId())); + + // Open first created Policy ruleset object + FWObject *first_policy = fw->getFirstByType(Policy::TYPENAME); + if (first_policy) + QCoreApplication::postEvent( + mw, new openRulesetEvent(filename, first_policy->getId())); + } +} + +void IC_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->importLog->textCursor(); + cursor.insertBlock(); + cursor.insertText(txt, format); + } + + m_dialog->importLog->ensureCursorVisible(); } @@ -63,12 +226,12 @@ void IC_ProgressPage::saveLog() { if (fwbdebug) { - qDebug("Saving import log to file: %d chars", - m_dialog->discoveryLog->toPlainText().length()); + qDebug("Saving crawler log to file: %d chars", + m_dialog->importLog->toPlainText().length()); qDebug("--------------------------------"); } QTextStream strm(&f); - QString txt = m_dialog->discoveryLog->toPlainText(); + QString txt = m_dialog->importLog->toPlainText(); strm << txt << endl; if (fwbdebug) { diff --git a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.h b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.h index 3ac99b5da..c9c61ef41 100644 --- a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.h +++ b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.h @@ -26,18 +26,38 @@ #include "ui_ic_progresspage_q.h" +#include + +class ImporterThread; + + class IC_ProgressPage : public QWizardPage { Q_OBJECT; Ui::IC_ProgressPage_q *m_dialog; + QTextCharFormat normal_format; + QTextCharFormat error_format; + QTextCharFormat warning_format; + ImporterThread *importer; public: IC_ProgressPage(QWidget *parent); virtual ~IC_ProgressPage() {} + virtual void initializePage(); + virtual void cleanupPage(); + virtual bool validatePage(); + + virtual int nextId () const; + + public slots: void saveLog(); + void logLine(const QString &line); + void importerDestroyed(QObject*); + void importerFinished(); + }; #endif // IC_PROGRESSPAGE_H diff --git a/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.cpp b/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.cpp index 459493c32..db5d5eb1d 100644 --- a/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.cpp +++ b/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.cpp @@ -29,8 +29,10 @@ #include "IC_FirewallNamePage.h" #include "IC_PlatformWarningPage.h" #include "IC_ProgressPage.h" +#include "IC_NetworkZonesPage.h" #include "fwbuilder/FWObject.h" +#include "fwbuilder/Firewall.h" #include @@ -41,17 +43,30 @@ using namespace libfwbuilder; ImportFirewallConfigurationWizard::ImportFirewallConfigurationWizard(QWidget *parent) : QWizard(parent) { + fw = NULL; + QPixmap pm; pm.load(":/Images/fwbuilder3-72x72.png"); setPixmap(QWizard::LogoPixmap, pm); setWindowTitle(tr("Import Firewall Configuration")); - addPage(new IC_FileNamePage(this)); - addPage(new IC_PlatformWarningPage(this)); - addPage(new IC_FirewallNamePage(this)); - addPage(new IC_ProgressPage(this)); + setPage(Page_FileName, new IC_FileNamePage(this)); + setPage(Page_Platform, new IC_PlatformWarningPage(this)); + setPage(Page_FirewallName, new IC_FirewallNamePage(this)); + setPage(Page_Progess, new IC_ProgressPage(this)); + setPage(Page_NetworkZones, new IC_NetworkZonesPage(this)); - resize(700, 500); + resize(600, 600); } +void ImportFirewallConfigurationWizard::accept() +{ + qDebug() << "ImportFirewallConfigurationWizard::accept()"; + + if (platform == "pix" || platform == "fwsm") + dynamic_cast( + page(Page_NetworkZones))->setNetworkZones(); + + QWizard::accept(); +} diff --git a/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.h b/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.h index 7a273a27b..72390f674 100644 --- a/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.h +++ b/src/libgui/importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.h @@ -25,22 +25,38 @@ #define __IMPORTFIREWALLCONFIGURATIONWIZARD_H_ #include +#include + +namespace libfwbuilder +{ + class Firewall; +}; class ImportFirewallConfigurationWizard : public QWizard { Q_OBJECT; QString platform; + QStringList buffer; + libfwbuilder::Firewall *fw; public: + enum { Page_FileName, Page_Platform, Page_FirewallName, + Page_Progess, Page_NetworkZones }; + ImportFirewallConfigurationWizard(QWidget *parent); virtual ~ImportFirewallConfigurationWizard() {} QString getPlatform() { return platform; } void setPlatform(const QString &s) { platform = s; } + + QStringList* getBufferPtr() { return &buffer; } + + libfwbuilder::Firewall* getFirewall() { return fw; } + void setFirewall(libfwbuilder::Firewall* _fw) { fw = _fw; } public slots: - + virtual void accept(); }; diff --git a/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp b/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp new file mode 100644 index 000000000..2c52f366f --- /dev/null +++ b/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp @@ -0,0 +1,109 @@ +/* + + 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 "global.h" + +#include "ImporterThread.h" + +#include "utils.h" +#include "QThreadLogger.h" +#include "IOSImporter.h" +#include "IPTImporter.h" +#include "PIXImporter.h" + +#include +#include + +#include + + +using namespace std; +using namespace libfwbuilder; + + +ImporterThread::ImporterThread(QWidget *ui, + FWObject *lib, + const QStringList &buffer, + const QString &platform, + const QString &firewallName) +{ + this->lib = lib; + this->ui = ui; + this->buffer = buffer; + this->platform = platform; + this->firewallName = firewallName; + importer = NULL; +} + +ImporterThread::~ImporterThread() +{ + if (fwbdebug) qDebug() << "ImporterThread::~ImporterThread()"; +} + +void ImporterThread::run() +{ + QThreadLogger *logger = new QThreadLogger(); + connect(logger, SIGNAL(lineReady(QString)), + this->ui, SLOT(logLine(QString)), + Qt::QueuedConnection); + + std::istringstream instream(buffer.join("\n").toStdString()); + + importer = NULL; + + if (platform == "iosacl") importer = new IOSImporter( + lib, instream, logger, firewallName.toUtf8().constData()); + + if (platform == "iptables") importer = new IPTImporter( + lib, instream, logger, firewallName.toUtf8().constData()); + + if (platform == "pix") importer = new PIXImporter( + lib, instream, logger, firewallName.toUtf8().constData()); + + if (importer) + { + try + { + importer->run(); + } catch(ImporterException &e) + { + *logger << e.toString() << "\n"; + } + + } else + { + *logger << "Can not import configuration for platform " + << platform.toStdString() << "\n"; + } + + fw = importer->finalize(); + + emit finished(); + + deleteLater(); // mark this object for destruction on the next run of event loop +} + +void ImporterThread::stop() +{ +} + diff --git a/src/libgui/importFirewallConfigurationWizard/ImporterThread.h b/src/libgui/importFirewallConfigurationWizard/ImporterThread.h new file mode 100644 index 000000000..270b2b2d7 --- /dev/null +++ b/src/libgui/importFirewallConfigurationWizard/ImporterThread.h @@ -0,0 +1,73 @@ +/* + + 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 _IMPORTERTHREAD_H_ +#define _IMPORTERTHREAD_H_ + +#include "Importer.h" + +#include +#include +#include + +#include +#include + + +namespace libfwbuilder +{ + class FWObject; + class Firewall; +}; + +class ImporterThread : public QThread +{ + Q_OBJECT; + + libfwbuilder::FWObject *lib; + Importer *importer; + QStringList buffer; + QString firewallName; + QString platform; + QWidget *ui; + libfwbuilder::Firewall *fw; + +public: + ImporterThread(QWidget *ui, + libfwbuilder::FWObject *lib, + const QStringList &buffer, + const QString &platform, + const QString &firewallName); + virtual ~ImporterThread(); + + void run(); + void stop(); + + libfwbuilder::Firewall* getFirewallObject() { return fw; } + +signals: + void finished(); +}; + + +#endif diff --git a/src/libgui/importFirewallConfigurationWizard/ic_networkzonespage_q.ui b/src/libgui/importFirewallConfigurationWizard/ic_networkzonespage_q.ui new file mode 100644 index 000000000..4e04d88da --- /dev/null +++ b/src/libgui/importFirewallConfigurationWizard/ic_networkzonespage_q.ui @@ -0,0 +1,110 @@ + + + IC_NetworkZonesPage_q + + + + 0 + 0 + 580 + 630 + + + + WizardPage + + + + + + Firewall Builder uses Network Zones to determine network topology. Each firewall interface must have a Network Zone configured. The Network Zone of an interface represents the set of IP networks that would be the source IP address of traffic arriving inbound on an interface. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + + + + If you do not set the Network Zone now you can update the Network Zone configuration after the firewall has been created by double-clicking on the network interface of the firewall object and then selecting the desired object from the Network Zone dropdown list. + + + true + + + + + + + + + + :/Images/network_zone_dialog.png + + + Qt::AlignCenter + + + + + + + + 0 + 150 + + + + QFrame::NoFrame + + + QFrame::Sunken + + + + 0 + + + + + true + + + true + + + + Name + + + + + Label + + + + + Address + + + + + Security Level + + + + + + + + + + + + + + diff --git a/src/libgui/importFirewallConfigurationWizard/ic_progresspage_q.ui b/src/libgui/importFirewallConfigurationWizard/ic_progresspage_q.ui index 468767ebd..5619f8721 100644 --- a/src/libgui/importFirewallConfigurationWizard/ic_progresspage_q.ui +++ b/src/libgui/importFirewallConfigurationWizard/ic_progresspage_q.ui @@ -24,7 +24,7 @@ 0 - + true diff --git a/src/libgui/libgui.pro b/src/libgui/libgui.pro index 8ed35edbd..ff0073cf1 100644 --- a/src/libgui/libgui.pro +++ b/src/libgui/libgui.pro @@ -221,7 +221,9 @@ HEADERS += ../../config.h \ importFirewallConfigurationWizard/IC_FirewallNamePage.h \ importFirewallConfigurationWizard/IC_PlatformWarningPage.h \ importFirewallConfigurationWizard/IC_ProgressPage.h \ + importFirewallConfigurationWizard/IC_NetworkZonesPage.h \ importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.h \ + importFirewallConfigurationWizard/ImporterThread.h \ @@ -439,7 +441,9 @@ SOURCES += ProjectPanel.cpp \ importFirewallConfigurationWizard/IC_FirewallNamePage.cpp \ importFirewallConfigurationWizard/IC_PlatformWarningPage.cpp \ importFirewallConfigurationWizard/IC_ProgressPage.cpp \ + importFirewallConfigurationWizard/IC_NetworkZonesPage.cpp \ importFirewallConfigurationWizard/ImportFirewallConfigurationWizard.cpp \ + importFirewallConfigurationWizard/ImporterThread.cpp FORMS = FWBMainWindow_q.ui \ @@ -568,6 +572,7 @@ FORMS = FWBMainWindow_q.ui \ importFirewallConfigurationWizard/ic_firewallnamepage_q.ui \ importFirewallConfigurationWizard/ic_platformwarningpage_q.ui \ importFirewallConfigurationWizard/ic_progresspage_q.ui \ + importFirewallConfigurationWizard/ic_networkzonespage_q.ui \ # fwtransfer stuff.