diff --git a/src/gui/DialogFactory.cpp b/src/gui/DialogFactory.cpp index 35cb75680..1ed0662d9 100644 --- a/src/gui/DialogFactory.cpp +++ b/src/gui/DialogFactory.cpp @@ -43,6 +43,7 @@ #include "AddressTableDialog.h" #include "NetworkDialog.h" #include "NetworkDialogIPv6.h" +#include "UserDialog.h" #include "CustomServiceDialog.h" #include "ICMPServiceDialog.h" #include "IPServiceDialog.h" @@ -99,6 +100,7 @@ #include "fwbuilder/Rule.h" #include "fwbuilder/Resources.h" #include "fwbuilder/TagService.h" +#include "fwbuilder/UserService.h" #include #include "ProjectPanel.h" @@ -108,6 +110,8 @@ using namespace libfwbuilder; QWidget *DialogFactory::createDialog(ProjectPanel *project, QWidget *parent,const QString &objType) { + if (objType==UserService::TYPENAME) return new UserDialog(project, parent); + if (objType==Policy::TYPENAME) return new RuleSetDialog(project, parent); if (objType==NAT::TYPENAME) return new RuleSetDialog(project, parent); diff --git a/src/gui/ObjectEditor.cpp b/src/gui/ObjectEditor.cpp index 7dc95abdc..e3d0ba8e8 100644 --- a/src/gui/ObjectEditor.cpp +++ b/src/gui/ObjectEditor.cpp @@ -75,6 +75,7 @@ #include "fwbuilder/UDPService.h" #include "fwbuilder/ServiceGroup.h" #include "fwbuilder/TagService.h" +#include "fwbuilder/UserService.h" #include "fwbuilder/Interval.h" #include "fwbuilder/IntervalGroup.h" @@ -105,6 +106,10 @@ ObjectEditor::ObjectEditor( QWidget *parent, ProjectPanel *project): #endif QWidget *w; + w= DialogFactory::createDialog(m_project, parent,UserService::TYPENAME); + stackIds[UserService::TYPENAME] = parentWidget->addWidget(w); + dialogs[stackIds[UserService::TYPENAME]] = w; + w= DialogFactory::createDialog(m_project, parent,Policy::TYPENAME); stackIds[Policy::TYPENAME] = parentWidget->addWidget(w); dialogs[stackIds[Policy::TYPENAME]] = w; diff --git a/src/gui/UserDialog.cpp b/src/gui/UserDialog.cpp new file mode 100644 index 000000000..3753136e2 --- /dev/null +++ b/src/gui/UserDialog.cpp @@ -0,0 +1,161 @@ +/* + + Firewall Builder + + Copyright (C) 2003 NetCitadel, LLC + + Author: Vadim Kurland vadim@fwbuilder.org + + $Id: UserDialog.cpp,v 1.22 2007/04/14 00:18:43 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 "config.h" +#include "global.h" +#include "utils.h" + +#include "FWBTree.h" +#include "UserDialog.h" + +#include "ProjectPanel.h" +#include "fwbuilder/Library.h" +#include "fwbuilder/UserService.h" +#include "fwbuilder/Interface.h" +#include "fwbuilder/FWException.h" + +#include +#include +#include +#include +#include +#include +#include +#include "FWBSettings.h" + +#include "FWWindow.h" +using namespace std; +using namespace libfwbuilder; + +UserDialog::UserDialog(ProjectPanel *project, QWidget *parent) : QWidget(parent), m_project(project) +{ + m_dialog = new Ui::UserDialog_q; + m_dialog->setupUi(this); + setFont(st->getUiFont()); + obj=NULL; +} + +UserDialog::~UserDialog() { delete m_dialog; } + +void UserDialog::loadFWObject(FWObject *o) +{ + obj=o; + UserService *s = dynamic_cast(obj); + assert(s!=NULL); + + init=true; + + fillLibraries(m_dialog->libs,obj); + + m_dialog->obj_name->setText( QString::fromUtf8(s->getName().c_str()) ); + m_dialog->userid->setText( s->getUserId().c_str() ); + m_dialog->comment->setText( QString::fromUtf8(s->getComment().c_str()) ); + + //apply->setEnabled( false ); + + m_dialog->obj_name->setEnabled(!o->isReadOnly()); + setDisabledPalette(m_dialog->obj_name); + + m_dialog->libs->setEnabled(!o->isReadOnly()); + setDisabledPalette(m_dialog->libs); + + m_dialog->userid->setEnabled(!o->isReadOnly()); + setDisabledPalette(m_dialog->userid); + + m_dialog->comment->setReadOnly(o->isReadOnly()); + setDisabledPalette(m_dialog->comment); + + + init=false; +} + +void UserDialog::changed() +{ + //apply->setEnabled( true ); + emit changed_sign(); +} + +void UserDialog::validate(bool *res) +{ + *res=true; + + if (!isTreeReadWrite(this,obj)) { *res=false; return; } + if (!validateName(this,obj,m_dialog->obj_name->text())) { *res=false; return; } + + UserService *s = dynamic_cast(obj); + assert(s!=NULL); +} + +void UserDialog::isChanged(bool*) +{ + //*res=(!init && apply->isEnabled()); +} + +void UserDialog::libChanged() +{ + changed(); +} + +void UserDialog::applyChanges() +{ + UserService *s = dynamic_cast(obj); + assert(s!=NULL); + s->dump(false,false); + string oldname=obj->getName(); + obj->setName( string(m_dialog->obj_name->text().toUtf8().constData()) ); + obj->setComment( string(m_dialog->comment->toPlainText().toUtf8().constData()) ); + obj->setName( string(m_dialog->userid->text().toUtf8().constData()) ); + + mw->updateObjName(obj,QString::fromUtf8(oldname.c_str())); + + init=true; + +/* move to another lib if we have to */ + if (! m_project->isSystem(obj) && m_dialog->libs->currentText() != QString(obj->getLibrary()->getName().c_str())) + mw->moveObject(m_dialog->libs->currentText(), obj); + + init=false; + //apply->setEnabled( false ); + mw->updateLastModifiedTimestampForAllFirewalls(obj); +} + +void UserDialog::discardChanges() +{ + loadFWObject(obj); +} + + +/* ObjectEditor class connects its slot to this signal and does all + * the verification for us, then accepts (or not) the event. So we do + * nothing here and defer all the processing to ObjectEditor + */ +void UserDialog::closeEvent(QCloseEvent *e) +{ + emit close_sign(e); + +} + diff --git a/src/gui/UserDialog.h b/src/gui/UserDialog.h new file mode 100644 index 000000000..60f8c2bd6 --- /dev/null +++ b/src/gui/UserDialog.h @@ -0,0 +1,72 @@ +/* + + Firewall Builder + + Copyright (C) 2003 NetCitadel, LLC + + Author: Vadim Kurland vadim@fwbuilder.org + + $Id: UserDialog.h,v 1.7 2006/05/13 06:53:05 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 __USERDIALOG_H_ +#define __USERDIALOG_H_ + +#include "config.h" +#include +#include + +#include "fwbuilder/FWObject.h" + + +class ProjectPanel; +class UserDialog : public QWidget +{ + Q_OBJECT + + libfwbuilder::FWObject *obj; + Ui::UserDialog_q *m_dialog; + bool init; + ProjectPanel *m_project; + + public: + UserDialog(ProjectPanel *project, QWidget *parent); + ~UserDialog(); + +public slots: + virtual void changed(); + virtual void libChanged(); + virtual void applyChanges(); + virtual void discardChanges(); + virtual void loadFWObject(libfwbuilder::FWObject *obj); + virtual void validate(bool*); + virtual void isChanged(bool*); + virtual void closeEvent(QCloseEvent *e); + + signals: +/** + * This signal is emitted from closeEvent, ObjectEditor connects + * to this signal to make checks before the object editor can be closed + * and to store its position on the screen + */ + void close_sign(QCloseEvent *e); + void changed_sign(); + +}; + +#endif // UserDialog_H diff --git a/src/gui/gui.pro b/src/gui/gui.pro index d1a479ba1..6a846e390 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -68,7 +68,8 @@ HEADERS += ../../config.h \ PhysicalAddressDialog.h \ NetworkDialog.h \ NetworkDialogIPv6.h \ - RuleSetDialog.h \ + UserDialog.h \ + RuleSetDialog.h \ LibraryDialog.h \ CustomServiceDialog.h \ IPServiceDialog.h \ @@ -179,6 +180,7 @@ SOURCES += ProjectPanel.cpp \ PhysicalAddressDialog.cpp \ NetworkDialog.cpp \ NetworkDialogIPv6.cpp \ + UserDialog.cpp \ LibraryDialog.cpp \ CustomServiceDialog.cpp \ IPServiceDialog.cpp \ @@ -252,6 +254,7 @@ FORMS = FWBMainWindow_q.ui \ addresstabledialog_q.ui \ networkdialog_q.ui \ networkdialogipv6_q.ui \ + userdialog_q.ui \ hostdialog_q.ui \ firewalldialog_q.ui \ interfacedialog_q.ui \ diff --git a/src/gui/userdialog_q.ui b/src/gui/userdialog_q.ui new file mode 100644 index 000000000..a9b6fe796 --- /dev/null +++ b/src/gui/userdialog_q.ui @@ -0,0 +1,398 @@ + + UserDialog_q + + + true + + + + 0 + 0 + 562 + 166 + + + + + 0 + 0 + + + + User + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 16 + 20 + + + + QFrame::Box + + + QFrame::Sunken + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 0 + 0 + + + + + 75 + true + + + + QFrame::NoFrame + + + QFrame::Plain + + + User + + + false + + + + + + + + 0 + 0 + + + + + + + true + + + false + + + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Sunken + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 0 + 100 + + + + + 200 + 0 + + + + true + + + + + + + Comment: + + + false + + + + + + + QFrame::Box + + + QFrame::Sunken + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 5 + + + + + + + + Name: + + + false + + + + + + + Library: + + + false + + + + + + + + 0 + 0 + + + + + + + + User id: + + + false + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + + obj_name + libs + userid + comment + + + + + obj_name + textChanged(QString) + UserDialog_q + changed() + + + 20 + 20 + + + 20 + 20 + + + + + libs + activated(int) + UserDialog_q + libChanged() + + + 20 + 20 + + + 20 + 20 + + + + + userid + textChanged(QString) + UserDialog_q + changed() + + + 20 + 20 + + + 20 + 20 + + + + + comment + textChanged() + UserDialog_q + changed() + + + 20 + 20 + + + 20 + 20 + + + + +