Skip to content
Snippets Groups Projects
Commit dd0502fd authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Fix: Convert user input to ip range. (Redmine issue: #7603)

parent 8cc60ea5
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ from sqlalchemy import or_ ...@@ -32,7 +32,7 @@ from sqlalchemy import or_
from sqlalchemy import text from sqlalchemy import text
from mentat.datatype.sqldb import NetworkModel, GroupModel, ItemChangeLogModel from mentat.datatype.sqldb import NetworkModel, GroupModel, ItemChangeLogModel
from mentat.datatype.internal import t_net from ipranges import from_str, ip_from_str
import hawat.acl import hawat.acl
import hawat.menu import hawat.menu
...@@ -112,10 +112,16 @@ class ListView(HTMLMixin, SQLAlchemyMixin, ItemListView): ...@@ -112,10 +112,16 @@ class ListView(HTMLMixin, SQLAlchemyMixin, ItemListView):
def build_query(query, model, form_args): def build_query(query, model, form_args):
# Adjust query based on text search string. # Adjust query based on text search string.
if 'search' in form_args and form_args['search']: if 'search' in form_args and form_args['search']:
# First of all, assume the user entered address/net/range.
try: try:
net = t_net(form_args['search']) # Convert user input to ipranges object.
query = query.filter(text("network >>= '{}'".format(str(net)))) net = from_str(form_args['search'])
# 'a >>= b' means: a contains b or is equal to b
# So search for networks which contain the address/net/range from the user input.
# Also, the user input is converted to range to solve issues with addresses such as 195.113.144.1/24
query = query.filter(text("network >>= '{}-{}'".format(ip_from_str(net.low()), ip_from_str(net.high()))))
except ValueError: except ValueError:
# Try searching by the name of the network or the description.
query = query \ query = query \
.filter( .filter(
or_( or_(
......
  • Pavel Kácha @ph

    mentioned in issue #7603 (closed)

    By Rajmund Hruška on 2024-12-26T14:26:30

    · Imported

    mentioned in issue #7603 (closed)

    By Rajmund Hruška on 2024-12-26T14:26:30

    Toggle commit list
  • Pavel Kácha @ph

    mentioned in issue #7676 (closed)

    By Rajmund Hruška on 2024-12-26T15:00:21

    · Imported

    mentioned in issue #7676 (closed)

    By Rajmund Hruška on 2024-12-26T15:00:21

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment