mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-05-02 15:17:28 +02:00
feat: Allow entering IPv6 into AddressRangeDialog
This commit is contained in:
parent
17b6279e22
commit
cbfcb387a8
@ -605,35 +605,39 @@ void Compiler::_expandAddressRanges(Rule *rule, FWObject *re)
|
|||||||
{
|
{
|
||||||
if (MatchesAddressFamily(o))
|
if (MatchesAddressFamily(o))
|
||||||
{
|
{
|
||||||
InetAddr a1 = aro->getRangeStart();
|
if (aro->isV6()) {
|
||||||
InetAddr a2 = aro->getRangeEnd();
|
cl.push_back(o);
|
||||||
vector<InetAddrMask> vn =
|
} else {
|
||||||
libfwbuilder::convertAddressRange(a1,a2);
|
InetAddr a1 = aro->getRangeStart();
|
||||||
|
InetAddr a2 = aro->getRangeEnd();
|
||||||
|
vector<InetAddrMask> vn =
|
||||||
|
libfwbuilder::convertAddressRange(a1,a2);
|
||||||
|
|
||||||
if (vn.size() == 0)
|
if (vn.size() == 0)
|
||||||
{
|
|
||||||
abort(rule,
|
|
||||||
"Address Range object '" + aro->getName() +
|
|
||||||
"' can not be converted to set of addresses");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (vector<InetAddrMask>::iterator i=vn.begin();
|
|
||||||
i!=vn.end(); i++)
|
|
||||||
{
|
|
||||||
Network *h = dbcopy->createNetwork();
|
|
||||||
h->setName(string("%n-")+(*i).toString()+string("%") );
|
|
||||||
h->setNetmask(*(i->getNetmaskPtr()));
|
|
||||||
h->setAddress(*(i->getAddressPtr()));
|
|
||||||
persistent_objects->add(h, false);
|
|
||||||
cl.push_back(h);
|
|
||||||
|
|
||||||
// see GroupRegistry::registerGroupObject()
|
|
||||||
if (group_registry != nullptr)
|
|
||||||
{
|
{
|
||||||
group_registry->setGroupRegistryKey(
|
abort(rule,
|
||||||
h, group_registry->getGroupRegistryKey(aro));
|
"Address Range object '" + aro->getName() +
|
||||||
|
"' can not be converted to set of addresses");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
for (vector<InetAddrMask>::iterator i=vn.begin();
|
||||||
|
i!=vn.end(); i++)
|
||||||
|
{
|
||||||
|
Network *h = dbcopy->createNetwork();
|
||||||
|
h->setName(string("%n-")+(*i).toString()+string("%") );
|
||||||
|
h->setNetmask(*(i->getNetmaskPtr()));
|
||||||
|
h->setAddress(*(i->getAddressPtr()));
|
||||||
|
persistent_objects->add(h, false);
|
||||||
|
cl.push_back(h);
|
||||||
|
|
||||||
|
// see GroupRegistry::registerGroupObject()
|
||||||
|
if (group_registry != nullptr)
|
||||||
|
{
|
||||||
|
group_registry->setGroupRegistryKey(
|
||||||
|
h, group_registry->getGroupRegistryKey(aro));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,6 +34,8 @@
|
|||||||
#include "fwbuilder/Library.h"
|
#include "fwbuilder/Library.h"
|
||||||
#include "fwbuilder/AddressRange.h"
|
#include "fwbuilder/AddressRange.h"
|
||||||
#include "fwbuilder/FWException.h"
|
#include "fwbuilder/FWException.h"
|
||||||
|
#include "fwbuilder/InetAddrMask.h"
|
||||||
|
#include "fwbuilder/Inet6AddrMask.h"
|
||||||
|
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
#include <qspinbox.h>
|
#include <qspinbox.h>
|
||||||
@ -171,6 +173,43 @@ void AddressRangeDialog::applyChanges()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddressRangeDialog::addressEntered()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QString addrStr = m_dialog->rangeStart->text();
|
||||||
|
InetAddr rangeStartAddress(AF_UNSPEC, addrStr.toStdString());
|
||||||
|
|
||||||
|
if (addrStr.contains('/'))
|
||||||
|
{
|
||||||
|
unique_ptr<InetAddrMask> address_and_mask = nullptr;
|
||||||
|
|
||||||
|
if (rangeStartAddress.isV4()) {
|
||||||
|
address_and_mask.reset(new InetAddrMask(addrStr.toStdString()));
|
||||||
|
} else if (rangeStartAddress.isV6()) {
|
||||||
|
address_and_mask.reset(new Inet6AddrMask(addrStr.toStdString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dialog->rangeStart->setText(
|
||||||
|
address_and_mask->getFirstHostPtr()->toString().c_str());
|
||||||
|
m_dialog->rangeEnd->setText(
|
||||||
|
address_and_mask->getLastHostPtr()->toString().c_str());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
InetAddr rangeEndAddress(AF_UNSPEC, m_dialog->rangeEnd->text().toStdString());
|
||||||
|
if (rangeEndAddress.addressFamily() != rangeStartAddress.addressFamily()) {
|
||||||
|
m_dialog->rangeEnd->setText(m_dialog->rangeStart->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (FWException &ex)
|
||||||
|
{
|
||||||
|
// exception thrown if user types illegal m_dialog->rangeStart do
|
||||||
|
// not show error dialog. This method is called by
|
||||||
|
// editingFinished signal and therefore is invoked when user
|
||||||
|
// switches focus from the address input widget to some other
|
||||||
|
// widget or even when user switches to another application to
|
||||||
|
// look up the address. Error dialog interrupts the workflow
|
||||||
|
// in the latter case which is annoying.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -50,6 +50,7 @@ public slots:
|
|||||||
virtual void applyChanges();
|
virtual void applyChanges();
|
||||||
virtual void loadFWObject(libfwbuilder::FWObject *obj);
|
virtual void loadFWObject(libfwbuilder::FWObject *obj);
|
||||||
virtual void validate(bool*);
|
virtual void validate(bool*);
|
||||||
|
virtual void addressEntered();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADDRESSRANGEDIALOG_H
|
#endif // ADDRESSRANGEDIALOG_H
|
||||||
|
|||||||
@ -172,5 +172,41 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<include location="MainRes.qrc"/>
|
<include location="MainRes.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>rangeStart</sender>
|
||||||
|
<signal>editingFinished()</signal>
|
||||||
|
<receiver>AddressRangeDialog_q</receiver>
|
||||||
|
<slot>addressEntered()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>220</x>
|
||||||
|
<y>69</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>364</x>
|
||||||
|
<y>123</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>rangeStart</sender>
|
||||||
|
<signal>returnPressed()</signal>
|
||||||
|
<receiver>AddressRangeDialog_q</receiver>
|
||||||
|
<slot>addressEntered()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>220</x>
|
||||||
|
<y>69</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>364</x>
|
||||||
|
<y>123</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
<slots>
|
||||||
|
<slot>addressEntered()</slot>
|
||||||
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user