mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-22 19:27:13 +01:00
fixed bug 2640: WhereUsed finds TagService and RuleSet objects referenced from rule actions
This commit is contained in:
parent
acced349be
commit
3976821769
@ -180,7 +180,6 @@ QString FWObjectPropertiesFactory::getObjectProperties(FWObject *obj)
|
||||
FWObjectTypedChildIterator j = obj->findByType(IPv4::TYPENAME);
|
||||
for ( ; j!=j.end(); ++j)
|
||||
{
|
||||
IPv4 *intf = IPv4::cast(*j);
|
||||
str << getObjectProperties(*j);
|
||||
str << "<br>";
|
||||
}
|
||||
@ -330,7 +329,6 @@ QString FWObjectPropertiesFactory::getObjectPropertiesDetailed(FWObject *obj,
|
||||
Interface::TYPENAME);
|
||||
for ( ; j!=j.end(); ++j)
|
||||
{
|
||||
Interface *intf = Interface::cast(*j);
|
||||
str += (*j)->getName().c_str();
|
||||
str += ": ";
|
||||
str += getObjectProperties(*j);
|
||||
@ -425,7 +423,6 @@ QString FWObjectPropertiesFactory::getObjectPropertiesDetailed(FWObject *obj,
|
||||
FWObjectTypedChildIterator j = obj->findByType(IPv4::TYPENAME);
|
||||
for ( ; j!=j.end(); ++j)
|
||||
{
|
||||
IPv4 *intf = IPv4::cast(*j);
|
||||
str += getObjectProperties(*j);
|
||||
str += "<br>";
|
||||
}
|
||||
@ -558,22 +555,33 @@ QString FWObjectPropertiesFactory::getRuleActionProperties(PolicyRule *rule)
|
||||
{
|
||||
switch (rule->getAction())
|
||||
{
|
||||
case PolicyRule::Reject :
|
||||
case PolicyRule::Reject:
|
||||
par = ropt->getStr("action_on_reject").c_str();
|
||||
break;
|
||||
case PolicyRule::Tag :
|
||||
par = rule->getTagValue().c_str();//ropt->getStr("tagvalue").c_str();
|
||||
case PolicyRule::Tag:
|
||||
{
|
||||
FWObject *tag_object = rule->getTagObject();
|
||||
if (tag_object)
|
||||
par = tag_object->getName().c_str();
|
||||
else
|
||||
par = rule->getTagValue().c_str();
|
||||
break;
|
||||
}
|
||||
case PolicyRule::Accounting :
|
||||
par = ropt->getStr("rule_name_accounting").c_str();
|
||||
break;
|
||||
case PolicyRule::Custom :
|
||||
case PolicyRule::Custom:
|
||||
par = ropt->getStr("custom_str").c_str();
|
||||
break;
|
||||
case PolicyRule::Branch :
|
||||
par = rule->getBranch()->getName().c_str();//ropt->getStr("branch_name").c_str();
|
||||
case PolicyRule::Branch:
|
||||
{
|
||||
FWObject *branch_ruleset = rule->getBranch();
|
||||
if (branch_ruleset)
|
||||
par = branch_ruleset->getName().c_str();
|
||||
// ropt->getStr("branch_name").c_str();
|
||||
break;
|
||||
case PolicyRule::Classify :
|
||||
}
|
||||
case PolicyRule::Classify:
|
||||
if (platform=="ipfw")
|
||||
{
|
||||
if (ropt->getInt("ipfw_classify_method") == DUMMYNETPIPE)
|
||||
|
||||
@ -633,6 +633,15 @@ void FWWindow::ensureObjectVisibleInRules(FWReference *obj)
|
||||
activeProject()->ensureObjectVisibleInRules(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make rule visible and highlight given column
|
||||
*/
|
||||
void FWWindow::ensureRuleIsVisible(Rule *rule, int col)
|
||||
{
|
||||
if (activeProject())
|
||||
activeProject()->ensureRuleIsVisible(rule, col);
|
||||
}
|
||||
|
||||
void FWWindow::updateRuleSetViewSelection()
|
||||
{
|
||||
if (activeProject())
|
||||
|
||||
@ -184,6 +184,7 @@ public slots:
|
||||
bool editingLibrary();
|
||||
|
||||
void ensureObjectVisibleInRules(libfwbuilder::FWReference *obj);
|
||||
void ensureRuleIsVisible(libfwbuilder::Rule *rule, int col=0);
|
||||
|
||||
QString chooseNewFileName(const QString &fname,
|
||||
bool checkPresence, const QString &title);
|
||||
|
||||
@ -78,7 +78,10 @@ using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
|
||||
FindWhereUsedWidget::FindWhereUsedWidget(QWidget*p, const char * n, Qt::WindowFlags f, bool f_mini) : QWidget(p)
|
||||
FindWhereUsedWidget::FindWhereUsedWidget(QWidget*p,
|
||||
const char * n,
|
||||
Qt::WindowFlags f,
|
||||
bool f_mini) : QWidget(p)
|
||||
{
|
||||
m_widget = new Ui::findWhereUsedWidget_q;
|
||||
m_widget->setupUi(this);
|
||||
@ -94,7 +97,6 @@ FindWhereUsedWidget::FindWhereUsedWidget(QWidget*p, const char * n, Qt::WindowFl
|
||||
}
|
||||
else
|
||||
{
|
||||
//connect (m_widget->dropArea,SIGNAL(objectInserted()),this,SLOT(findFromDrop()));
|
||||
connect (m_widget->dropArea,SIGNAL(objectDeleted()),this,SLOT(init()));
|
||||
}
|
||||
}
|
||||
@ -112,7 +114,7 @@ void FindWhereUsedWidget::setShowObject(bool fl)
|
||||
void FindWhereUsedWidget::itemActivated(QTreeWidgetItem* item)
|
||||
{
|
||||
FWObject *o;
|
||||
o=mapping[item];
|
||||
o = mapping[item];
|
||||
|
||||
if (flShowObject && o!=NULL)
|
||||
{
|
||||
@ -139,7 +141,7 @@ void FindWhereUsedWidget::_find(FWObject *obj)
|
||||
resset.clear();
|
||||
|
||||
|
||||
mw->db()->findWhereUsed(obj,mw->db(),resset);
|
||||
mw->db()->findWhereUsed(obj, mw->db(), resset);
|
||||
|
||||
set<FWObject*>::iterator i=resset.begin();
|
||||
QTreeWidgetItem *item;
|
||||
@ -156,11 +158,17 @@ void FindWhereUsedWidget::_find(FWObject *obj)
|
||||
r=NULL;
|
||||
rs=NULL;
|
||||
|
||||
if (findRef(object,o)==NULL) continue;
|
||||
if (RuleElement::cast(o)!=NULL)
|
||||
{
|
||||
fw=o->getParent();
|
||||
// if (findRef(object,o)==NULL) continue;
|
||||
|
||||
if (mw->isSystem(o) || RuleSet::cast(o) ||
|
||||
Firewall::cast(o) || Library::cast(o)) continue;
|
||||
|
||||
c1 = QString::fromUtf8(o->getName().c_str());
|
||||
c2 = tr("Type: ")+QString::fromUtf8(o->getTypeName().c_str());
|
||||
|
||||
if (RuleElement::cast(o)!=NULL || Rule::cast(o)!=NULL)
|
||||
{
|
||||
fw = o;
|
||||
while (fw!=NULL && !Firewall::isA(fw))
|
||||
{
|
||||
if (Rule::cast(fw))
|
||||
@ -170,12 +178,11 @@ void FindWhereUsedWidget::_find(FWObject *obj)
|
||||
{
|
||||
rs=RuleSet::cast(fw);
|
||||
}
|
||||
|
||||
fw=fw->getParent();
|
||||
}
|
||||
if (fw==NULL || r==NULL || rs==NULL) continue;
|
||||
|
||||
c1=QString::fromUtf8(fw->getName().c_str());
|
||||
c1 = QString::fromUtf8(fw->getName().c_str());
|
||||
|
||||
if (NAT::isA(rs))
|
||||
{
|
||||
@ -191,25 +198,12 @@ void FindWhereUsedWidget::_find(FWObject *obj)
|
||||
c2=tr("Unknown rule set");
|
||||
}
|
||||
c2+=tr("/Rule%1").arg(r->getPosition());
|
||||
|
||||
} else if (
|
||||
mw->isSystem(o) ||
|
||||
Rule::cast(o) ||
|
||||
RuleSet::cast(o) ||
|
||||
Firewall::cast(o) ||
|
||||
Library::cast(o))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
c1=QString::fromUtf8(o->getName().c_str());
|
||||
c2=tr("Type: ")+QString::fromUtf8(o->getTypeName().c_str());
|
||||
}
|
||||
|
||||
FWObject *pixobj=(fw==NULL)?o:fw;
|
||||
|
||||
QString icn_file = (":/Icons/"+pixobj->getTypeName()+"/icon-tree").c_str();
|
||||
QString icn_file =
|
||||
(":/Icons/"+pixobj->getTypeName()+"/icon-tree").c_str();
|
||||
|
||||
QPixmap pm;
|
||||
if ( ! QPixmapCache::find( icn_file, pm) )
|
||||
@ -220,9 +214,9 @@ void FindWhereUsedWidget::_find(FWObject *obj)
|
||||
|
||||
QStringList qsl;
|
||||
qsl << c1 << c2;
|
||||
item=new QTreeWidgetItem(m_widget->resListView, qsl);
|
||||
item->setIcon(0,QIcon(pm));
|
||||
mapping[item]=o;
|
||||
item = new QTreeWidgetItem(m_widget->resListView, qsl);
|
||||
item->setIcon(0, QIcon(pm));
|
||||
mapping[item] = o;
|
||||
}
|
||||
show();
|
||||
}
|
||||
@ -252,11 +246,14 @@ void FindWhereUsedWidget::showObject(FWObject* o)
|
||||
|
||||
if (RuleElement::cast(o)!=NULL)
|
||||
{
|
||||
ref=findRef(object,o);
|
||||
ref = findRef(object, o);
|
||||
if (ref==NULL) return;
|
||||
mw->activeProject()->openRuleSet(o->getParent()->getParent());
|
||||
mw->clearManipulatorFocus();
|
||||
mw->ensureObjectVisibleInRules( ref );
|
||||
RuleSetView *rsv = mw->activeProject()->getCurrentRuleSetView();
|
||||
rsv->selectRE( ref );
|
||||
|
||||
// mw->selectRules();
|
||||
if (mw->isEditorVisible())
|
||||
{
|
||||
@ -264,6 +261,23 @@ void FindWhereUsedWidget::showObject(FWObject* o)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Rule::cast(o)!=NULL)
|
||||
{
|
||||
mw->activeProject()->openRuleSet(o->getParent());
|
||||
mw->clearManipulatorFocus();
|
||||
mw->ensureRuleIsVisible( Rule::cast(o) );
|
||||
RuleSetView *rsv = mw->activeProject()->getCurrentRuleSetView();
|
||||
rsv->selectRE( Rule::cast(o)->getPosition(),
|
||||
rsv->getColByType(RuleSetView::Action));
|
||||
|
||||
if (mw->isEditorVisible())
|
||||
{
|
||||
mw->editObject( object );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mw->unselectRules();
|
||||
|
||||
if (Group::cast(o)!=NULL)
|
||||
|
||||
@ -10,11 +10,11 @@
|
||||
<file alias="Icons/Pipe">Icons/pipe_25.png</file>
|
||||
<file alias="Icons/Reject">Icons/reject_25.png</file>
|
||||
<file alias="Icons/Route">Icons/route_25.png</file>
|
||||
<file alias="Icons/Tag">Icons/tag_25.png</file>
|
||||
<file alias="Icons/Tag">Icons/service-tag_25.png</file>
|
||||
<file alias="Icons/Options">Icons/options_25.png</file>
|
||||
|
||||
<file alias="Icons/Options-tree">Icons/options_16.png</file>
|
||||
<file alias="Icons/Tag-tree">Icons/tag_16.png</file>
|
||||
<file alias="Icons/Tag-tree">Icons/service-tag_16.png</file>
|
||||
<file alias="Icons/Route-tree">Icons/route_16.png</file>
|
||||
<file alias="Icons/Reject-tree">Icons/reject_16.png</file>
|
||||
<file alias="Icons/Pipe-tree">Icons/pipe_16.png</file>
|
||||
|
||||
@ -624,6 +624,28 @@ void ProjectPanel::ensureObjectVisibleInRules(FWReference *obj)
|
||||
rsv->selectRE( obj );
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure rule is visible and highlight given column
|
||||
*/
|
||||
void ProjectPanel::ensureRuleIsVisible(Rule *rule, int col)
|
||||
{
|
||||
FWObject *p = rule;
|
||||
|
||||
while (p && RuleSet::cast(p)==NULL ) p=p->getParent();
|
||||
if (p==NULL) return; // something is broken
|
||||
|
||||
RuleSetView *rsv = ruleSetViews[p];
|
||||
|
||||
if (rsv==NULL)
|
||||
{
|
||||
if (fwbdebug)
|
||||
qDebug("ProjectPanel::ensureRuleIsVisible : orphan rule set found");
|
||||
return;
|
||||
}
|
||||
|
||||
m_panel->ruleSets->setCurrentIndex(m_panel->ruleSets->indexOf(rsv));
|
||||
rsv->selectRE( rule->getPosition(), col );
|
||||
}
|
||||
|
||||
void ProjectPanel::updateRuleSetViewSelection()
|
||||
{
|
||||
|
||||
@ -241,6 +241,7 @@ public:
|
||||
|
||||
void clearFirewallTabs();
|
||||
void ensureObjectVisibleInRules(libfwbuilder::FWReference *obj);
|
||||
void ensureRuleIsVisible(libfwbuilder::Rule *rule, int col=0);
|
||||
|
||||
libfwbuilder::FWObject* getVisibleFirewall() { return visibleFirewall; }
|
||||
RuleSetView* getRuleSetViews(libfwbuilder::FWObject *o)
|
||||
|
||||
@ -1319,6 +1319,20 @@ RuleSetView::REType RuleSetView::getColType(int col) const
|
||||
return i->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns column number for the given column type.
|
||||
* Note that for some types this operation is ambiguous because we have
|
||||
* several columns with the same type. In that case return the number
|
||||
* of the first column that matches.
|
||||
*/
|
||||
int RuleSetView::getColByType(REType type) const
|
||||
{
|
||||
map<int,REType>::const_iterator i;
|
||||
for (i=colTypes.begin(); i!=colTypes.end(); ++i)
|
||||
if (i->second == type) return i->first;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
QString RuleSetView::objectText(RuleElement *re,FWObject *obj)
|
||||
{
|
||||
@ -1929,7 +1943,13 @@ void RuleSetView::selectRE( int row, int col)
|
||||
if (row!=currentRow() || col!=currentColumn())
|
||||
{
|
||||
selectedObject = NULL;
|
||||
updateCell(currentRow(),currentColumn());
|
||||
|
||||
setCurrentCell(row,col);
|
||||
scrollTo( ruleModel->index(row,col),
|
||||
QAbstractItemView::EnsureVisible);
|
||||
updateCell(row,col);
|
||||
|
||||
// updateCell(currentRow(),currentColumn());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1948,12 +1968,14 @@ void RuleSetView::selectRE(libfwbuilder::FWReference *ref)
|
||||
int col;
|
||||
for (col=0; col<ncols; ++col)
|
||||
if (re==getRE(r,col))
|
||||
{
|
||||
setCurrentCell(row,col);
|
||||
scrollTo( ruleModel->index(row,col), QAbstractItemView::EnsureVisible);
|
||||
updateCell(row,col);
|
||||
break;
|
||||
}
|
||||
{
|
||||
selectRE(row, col);
|
||||
//setCurrentCell(row,col);
|
||||
//scrollTo( ruleModel->index(row,col),
|
||||
// QAbstractItemView::EnsureVisible);
|
||||
//updateCell(row,col);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RuleSetView::itemDoubleClicked(const QModelIndex & index)
|
||||
|
||||
@ -446,6 +446,7 @@ class RuleSetView : public QTableView
|
||||
void openObjectInTree(libfwbuilder::FWObject *obj);
|
||||
|
||||
REType getColType(int col) const;
|
||||
int getColByType(REType) const;
|
||||
|
||||
private:
|
||||
ProjectPanel *m_project;
|
||||
|
||||
@ -95,9 +95,8 @@ void findByObjectType(FWObject *o,
|
||||
}
|
||||
|
||||
|
||||
FWReference* findRef(FWObject *o,FWObject *p)
|
||||
FWReference* findRef(FWObject *o, FWObject *p)
|
||||
{
|
||||
|
||||
FWReference* ref=NULL;
|
||||
FWObject::iterator i=p->begin();
|
||||
for(;i!=p->end();++i)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user