1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-18 17:27:20 +01:00

see #2436, #2435 added GUI controls to let user choose host OS and version as part of the PF import process. Using this information to configure firewall object

This commit is contained in:
Vadim Kurland 2011-05-27 11:38:29 -07:00
parent 765060c29c
commit 3b229be520
7 changed files with 157 additions and 95 deletions

View File

@ -54,10 +54,10 @@ OTHER_LIBS = ../common/$$BINARY_SUBDIR/libcommon.a \
../libfwbuilder/src/fwcompiler/$$BINARY_SUBDIR/libfwcompiler.a \
../libfwbuilder/src/fwbuilder/$$BINARY_SUBDIR/libfwbuilder.a
PRE_TARGETDEPS = $$OTHER_LIBS $$IMPORT_LIB $$FWBPARSER_LIB $$ANTLR_LIBS
STATIC_LIBS += $$OTHER_LIBS
PRE_TARGETDEPS = $$STATIC_LIBS
macx:STATIC_LIBS += -framework \
Carbon
STATIC_LIBS += $$LIBS_FWCOMPILER

View File

@ -49,12 +49,10 @@ IC_FirewallNamePage::IC_FirewallNamePage(QWidget *parent) : QWizardPage(parent)
void IC_FirewallNamePage::initializePage()
{
QString platform =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getPlatform();
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())-> platform;
QStringList *buf =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getBufferPtr();
&(dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->buffer);
qDebug() << "platform=" << platform;

View File

@ -29,12 +29,18 @@
#include "PreImport.h"
#include "platforms.h"
#include <QString>
#include <QFile>
#include <QRegExp>
#include <QTextStream>
#include <QDesktopServices>
#include <list>
using namespace std;
IC_PlatformWarningPage::IC_PlatformWarningPage(QWidget *parent) : QWizardPage(parent)
{
@ -43,29 +49,42 @@ IC_PlatformWarningPage::IC_PlatformWarningPage(QWidget *parent) : QWizardPage(pa
setField("platform", "");
m_dialog->voteForFeatureButton->hide();
// user-chosen host os and version, so far we only show these for PF
registerField("hostOS*", m_dialog->hostOS);
registerField("version*", m_dialog->version);
m_dialog->hostOSAndVersionFrame->hide();
platformOk = false;
}
bool IC_PlatformWarningPage::isComplete() const
{
return platformOk;
if (!platformOk) return false;
if (dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
platform == "pf")
{
QString host_os = m_dialog->hostOS->currentText();
QString version = m_dialog->version->currentText();
return (! host_os.isEmpty() && ! version.isEmpty());
} else
return true;
}
void IC_PlatformWarningPage::initializePage()
{
QString fileName = field("fileName").toString();
ImportFirewallConfigurationWizard* wz = dynamic_cast<ImportFirewallConfigurationWizard*>(wizard());
QFile cf(fileName);
if (cf.open(QIODevice::ReadOnly ))
{
m_dialog->configFileBrowser->clear();
m_dialog->platform->setText(tr("Unknown"));
QStringList *buf =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getBufferPtr();
QStringList *buf = &(wz->buffer);
buf->clear();
QTextStream stream(&cf);
@ -178,16 +197,49 @@ void IC_PlatformWarningPage::initializePage()
break;
case PreImport::PF:
{
m_dialog->platform->setText(tr("pf"));
m_dialog->platformSpecificWarning->setText(
tr("Firewall Builder supports import PF "
tr("<html><p>Firewall Builder supports import PF "
"configuration from a pf.conf file. Tables will be imported "
"as object groups and their names will be preserved. "
"Macros are expanded in place and not imported as "
"objects. Import of anchors is not supported at this time."
"</p>"
"<p>PF version in Firewall Builder corresponds to its "
"versions in OpenBSD. If you run FreeBSD 8.2 or earlier, "
"choose \"3.9\"."
"</p></html>"
));
platformOk = true;
// populate host OS items using standard function from platforms.cpp
// but add an empty item on top and make it current
setHostOS(m_dialog->hostOS, "pf", "");
m_dialog->hostOS->insertItem(0, "");
m_dialog->hostOS->setCurrentIndex(0);
for (int i=0; i<m_dialog->hostOS->count(); ++i)
{
wz->host_os_list.append(m_dialog->hostOS->itemText(i));
}
// populate versions using standard function from platforms.cpp
// and add empty item on top
list<QStringPair> vl;
getVersionsForPlatform("pf", vl);
vl.push_front(QStringPair("", QObject::tr("")));
for (list<QStringPair>::iterator i1=vl.begin(); i1!=vl.end(); i1++)
{
m_dialog->version->addItem( i1->second );
wz->version_list.append(i1->first);
}
m_dialog->hostOSAndVersionFrame->show();
break;
}
case PreImport::PF_REVERSE:
m_dialog->platform->setText(tr("pf"));
@ -208,18 +260,9 @@ void IC_PlatformWarningPage::initializePage()
break;
}
QString platform_string = pi.getPlatformAsString();
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
setPlatform(platform_string);
wz->platform = pi.getPlatformAsString();
}
emit completeChanged();
}
void IC_PlatformWarningPage::voteForFeature()
{
QString url("http://www.fwbuilder.org/4.0/surveys/pf_import_registration.html");
QDesktopServices::openUrl(QUrl(url, QUrl::StrictMode));
}

View File

@ -42,8 +42,6 @@ public:
virtual void initializePage();
virtual bool isComplete() const;
public slots:
void voteForFeature();
};
#endif // IC_PLATFORMWARNINGPAGE_H

View File

@ -83,12 +83,10 @@ int IC_ProgressPage::nextId() const
{
if (fwbdebug_ic) qDebug() << "IC_ProgressPage::nextId()";
QString platform =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getPlatform();
ImportFirewallConfigurationWizard* wz = dynamic_cast<ImportFirewallConfigurationWizard*>(wizard());
Firewall *fw =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->getFirewall();
QString platform = wz->platform;
Firewall *fw = wz->getFirewall();
// Move on to the next page only if firewall object has been created
// and the next page only makes sense for pix and fwsm
@ -138,19 +136,16 @@ void IC_ProgressPage::initializePage()
m_dialog->errors_count_display->setText("0");
m_dialog->warnings_count_display->setText("0");
QString platform =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getPlatform();
ImportFirewallConfigurationWizard* wz = dynamic_cast<ImportFirewallConfigurationWizard*>(wizard());
QString platform = wz->platform;
QString firewallName = field("firewallName").toString();
bool deduplicate = field("deduplicate").toBool();
QStringList *buffer =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getBufferPtr();
QStringList *buffer = &(wz->buffer);
QString fileName = field("fileName").toString();
Library *lib = dynamic_cast<ImportFirewallConfigurationWizard*>(
wizard())->currentLib();
Library *lib = wz->currentLib();
importer = new ImporterThread(this,
lib,
*buffer, platform, firewallName, fileName,
@ -180,17 +175,32 @@ void IC_ProgressPage::importerFinished()
Firewall *fw = importer->getFirewallObject();
qApp->processEvents(); // to flush the log
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->setFirewall(fw);
ImportFirewallConfigurationWizard* wz = dynamic_cast<ImportFirewallConfigurationWizard*>(wizard());
QString platform =
dynamic_cast<ImportFirewallConfigurationWizard*>(wizard())->
getPlatform();
wz->setFirewall(fw);
QString platform = wz->platform;
if (fw) // fw can be NULL if import was uncussessful
{
QString fwName = field("firewallName").toString();
fw->setName(fwName.toUtf8().constData());
// lists host_os_list and version_list are used-chosen host os and version.
// We ask user to choose these only for PF, so for other platforms
// these lists are going to be empty.
if ( wz->host_os_list.size() > 0 && wz->version_list.size() > 0)
{
int host_os_idx = field("hostOS").toInt();
int version_idx = field("version").toInt();
QString hostOS = wz->host_os_list.at( host_os_idx );
QString version = wz->version_list.at( version_idx );
if ( ! hostOS.isEmpty()) fw->setStr("hostOS", hostOS.toStdString());
if ( ! version.isEmpty()) fw->setStr("version", version.toStdString());
}
setFinalPage(false); // this triggers call to nextId()
} else

View File

@ -34,11 +34,21 @@ namespace libfwbuilder
class Library;
};
class IC_FirewallNamePage;
class IC_PlatformWarningPage;
class IC_ProgressPage;
class ImportFirewallConfigurationWizard : public QWizard
{
friend class IC_FirewallNamePage;
friend class IC_PlatformWarningPage;
friend class IC_ProgressPage;
Q_OBJECT;
QString platform;
QList<QString> host_os_list;
QList<QString> version_list;
QStringList buffer;
libfwbuilder::Firewall *fw;
libfwbuilder::FWObjectDatabase *db_orig;
@ -53,11 +63,6 @@ public:
libfwbuilder::FWObjectDatabase *db);
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; }

View File

@ -6,16 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>512</width>
<height>527</height>
<width>631</width>
<height>710</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="platformSpecificWarning">
<property name="text">
@ -26,48 +26,76 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QPushButton" name="voteForFeatureButton">
<property name="text">
<string>Vote for PF import feature (opens web browser)</string>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>188</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Firewall Platform:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QLabel" name="platform">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="2">
<item row="1" column="2" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>318</width>
<width>388</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QFrame" name="hostOSAndVersionFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Host OS:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="hostOS"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="version"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>258</width>
<height>20</height>
</size>
</property>
@ -81,25 +109,5 @@
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>voteForFeatureButton</sender>
<signal>clicked()</signal>
<receiver>IC_PlatformWarningPage_q</receiver>
<slot>voteForFeature()</slot>
<hints>
<hint type="sourcelabel">
<x>150</x>
<y>47</y>
</hint>
<hint type="destinationlabel">
<x>255</x>
<y>263</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>voteForFeature()</slot>
</slots>
<connections/>
</ui>