Skip to content

Commit

Permalink
Filter applied
Browse files Browse the repository at this point in the history
  • Loading branch information
FischLord committed Feb 1, 2024
1 parent a9170e9 commit fb5da01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
14 changes: 8 additions & 6 deletions ip-atlas/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ def filter_data(search, key, data):
# ? inputs have to be strings
def filterByIp(octed1, octed2, octed3, octed4, data):
# convert all octeds to int
goThrough = ["*",""]
result = {"hosts": []}
for i in range(len(data["hosts"])):
ip = devideIp(data["hosts"][i]["ip"])
if (
(octed1 == "*" or ip[0] == octed1)
and (octed2 == "*" or ip[1] == octed2)
and (octed3 == "*" or ip[2] == octed3)
and (octed4 == "*" or ip[3] == octed4)
(octed1 in goThrough or ip[0] == octed1)
and (octed2 in goThrough or ip[1] == octed2)
and (octed3 in goThrough or ip[2] == octed3)
and (octed4 in goThrough or ip[3] == octed4)
):
result["hosts"].append(data["hosts"][i])
return result
Expand All @@ -78,9 +79,10 @@ def filterByName(search, data):


def filterByPort(search, data):
goThrough = ["*",""]
result = {"hosts": []}
# for host in data:
if not search == "":
if not search in goThrough:
for i in range(len(data["hosts"])):
dataPorts = data["hosts"][i]["ports"]
for port in dataPorts:
Expand Down Expand Up @@ -125,7 +127,7 @@ def filterAll(ip, name, port, tag, data):

# print(filterAll("*.*.*.*", "", "", "", loadJson()))
#! tests
# print(filterByIp("*", "*", "*", "47", loadJson()))
# print(filterByIp("*", "", "", "4", loadJson()))
# print(filterByName("40", loadJson()))
# data = filterByPort(99, loadJson())
# print(data)
Expand Down
29 changes: 4 additions & 25 deletions ip-atlas/routes/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,11 @@ def index():
return render_template('ip/list.html', data=data)


@bp_atlas.route('/ip/list', methods=['GET', 'POST'])
@bp_atlas.route('/ip/list')
def list():

ipocted1 = request.form.get('ipocted1', '*')
ipocted2 = request.form.get('ipocted2', '*')
ipocted3 = request.form.get('ipocted3', '*')
ipocted4 = request.form.get('ipocted4', '*')
name = request.form.get('name', '')
port = request.form.get('port', '')
tag = request.form.get('tag', '')

createJson()
# printJson()
data = loadJson()

# Apply filters if any filter is provided
if any([ip, name, port, tag]):
filtered_data = filterAll(ip, name, port, tag)
else:
filtered_data = data
if any([ipocted1, ipocted2, ipocted3, ipocted4, nameFilter, portFilter, tagFilter]):
filtered_data = filterAll(
ipocted1, ipocted2, ipocted3, ipocted4, nameFilter, portFilter, tagFilter)

return render_template('ip/list.html', data=filtered_data)
return render_template('ip/list.html', data=data)


@bp_atlas.route('/ip/ping/<ip_address>')
Expand Down Expand Up @@ -155,8 +135,7 @@ def filter():
ipocted4 = request.args.get('ipocted4', '')
tags = request.args.get('tags', '')
ports = request.args.get('ports', '')
print("Filter: ", name, ipocted1, ipocted2,
ipocted3, ipocted4, tags, ports)
print("Filter: ", name, ipocted1, ipocted2, ipocted3, ipocted4, tags, ports)
# Combine IP octets into a single string
ip = f"{ipocted1}.{ipocted2}.{ipocted3}.{ipocted4}"
print("IP: ", ip)
Expand All @@ -166,4 +145,4 @@ def filter():
print("Filtered data: ", filtered_data)

# Render the template with the filtered data
return render_template('ip/list.html', data={'hosts': filtered_data})
return render_template('ip/list.html', data=filtered_data)
10 changes: 5 additions & 5 deletions ip-atlas/templates/ip/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ <h1 class="text-lg font-semibold md:text-2xl">IP Addresses</h1>
<div class="space-y-1">
<label for="ipInput1" class="block text-sm font-semibold">IP Address</label>
<div class="flex items-center gap-2">
<input type="number" id="ipInput1" name="ipocted1" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<input type="text" id="ipInput1" name="ipocted1" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<span>.</span>
<input type="number" id="ipInput2" name="ipocted2" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<input type="text" id="ipInput2" name="ipocted2" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<span>.</span>
<input type="number" id="ipInput3" name="ipocted3" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<input type="text" id="ipInput3" name="ipocted3" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<span>.</span>
<input type="number" id="ipInput4" name="ipocted4" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
<input type="text" id="ipInput4" name="ipocted4" maxlength="3" class="w-1/4 p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent ip-input">
</div>
</div>
<div class="flex gap-2">
Expand All @@ -44,7 +44,7 @@ <h1 class="text-lg font-semibold md:text-2xl">IP Addresses</h1>
<div class="w-1/2">
<div class="space-y-1">
<label for="portsInput" class="block text-sm font-semibold">Ports</label>
<input type="number" id="portsInput" name="ports" value="{{ request.args.get('ports', '') }}"
<input type="text" id="portsInput" name="ports" value="{{ request.args.get('ports', '') }}"
class="w-full p-2 text-sm text-white bg-gray-700 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent">
</div>
</div>
Expand Down

0 comments on commit fb5da01

Please sign in to comment.