Skip to content

Commit

Permalink
refactored to use GET method
Browse files Browse the repository at this point in the history
  • Loading branch information
ssw committed Jan 10, 2023
1 parent 45b8eb3 commit 0dc2241
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 25 deletions.
40 changes: 20 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,39 +139,35 @@ def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, ro
existing_roa_status])
return messages

@app.route('/', methods=['GET', 'POST'])
def index():
""" main function to handle the web page
:return: web page
"""
@app.route('/results', methods=['GET'])
def results():
""" process the form data and return the results """
if request.method == 'GET':

if request.method == 'POST':
# Get the user input
roa_ip_prefix = request.form['ip_prefix']
roa_ip_prefix = request.args.get('ip_prefix')
roa_ip_prefix = roa_ip_prefix.strip()
# Validate the IP prefix
if not is_valid_prefix(roa_ip_prefix):
return f"\"{roa_ip_prefix}\" is an Invalid IP prefix"

origin_asn = request.form['origin_asn']
origin_asn = request.args.get('origin_asn')
origin_asn = origin_asn.strip()

origin_asn = get_asn_from_as(origin_asn)
roa_origin_asn = origin_asn
roa_prefix_maxlength = request.args.get('prefix_maxlength')
roa_prefix_maxlength = roa_prefix_maxlength.strip()


# Validate the IP prefix
if not is_valid_prefix(roa_ip_prefix):
return f"\"{roa_ip_prefix}\" is an Invalid IP prefix"

# Validate the origin ASN
if not is_valid_asn(origin_asn):
return f"\"{origin_asn}\" is an Invalid origin ASN"
roa_prefix_maxlength = request.form['prefix_maxlength']
roa_prefix_maxlength = roa_prefix_maxlength.strip()

# Validate the prefix maxlength
if not is_valid_prefix_maxlength(roa_ip_prefix, roa_prefix_maxlength):
return f"\"{roa_prefix_maxlength}\" is an Invalid prefix maxlength"

roa_ip_prefix = request.form['ip_prefix']
roa_prefix_maxlength = int(request.form['prefix_maxlength'])
roa_origin_asn = request.form['origin_asn']
roa_origin_asn = get_asn_from_as(roa_origin_asn)
roa_prefix_maxlength = int(roa_prefix_maxlength)

prefix_info = get_prefix_info(roa_ip_prefix)
if prefix_info is None:
return "Prefix not found or problems with RIPEstat API"
Expand All @@ -184,6 +180,10 @@ def index():
else:
return render_template('index.html')

@app.route('/', methods=['GET'])
def index():
return render_template('index.html')

if __name__ == '__main__':
print("new version - ssw")
app.run(port=8000, host='0.0.0.0')
Expand Down
10 changes: 5 additions & 5 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</head>
<body>
<p style="text-align: center">This app queries the stat.ripe.net to determine if a RPKI-ROA created with the following information<br>would likely agree (i.e., not evaluate as invalid) for routes currently seen in the Internet</p>
<form method="post">
<form form action="/results" method="get">>
<label for="ip_prefix">IP Prefix:</label>
<input type="text" name="ip_prefix" placeholder="10.1.0.0/16" required>
<input type="text" id="ip_prefix" name="ip_prefix" placeholder="10.1.0.0/16" required>
<label for="prefix_maxlength">Prefix Maxlength:</label>
<input type="number" placeholder="24" name="prefix_maxlength" required>
<input type="number" placeholder="24" id="prefix_maxlength" name="prefix_maxlength" required>
<label for="origin_asn">Origin ASN:</label>
<input type="text" name="origin_asn" required>
<input type="submit" value="Submit">
<input type="text" id="origin_asn" name="origin_asn" required>
<input type="submit" id="submit" value="Submit">
</form>
</body>
</html>
51 changes: 51 additions & 0 deletions templates/results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<p>Proposed ROA Prefix = {{ roa_info[0] }}</p>
<p>Max Length = {{ roa_info[1]}}</p>
<p>and origin ASN = {{roa_info[2] }}</p>
</div>

<table>
<thead>
<tr>
<th style="white-space pre-line;text-align: left">The first row is the prefix specified in the proposed ROA.
Subsequent lines list more specifics that are seen in the global routing table.</th>
<th style="white-space pre-line;text-align: left">If you create the proposed ROA, this is how it would be evaluated for each prefix.</th>
<th style="white-space pre-line;text-align: left">For this prefix, this is the origin ASN as seen in the global Internet.</th>
<th style="white-space pre-line;text-align: left">This is the status of this prefix due to an existing ROA. </th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td style="text-align: center; border: 1px solid black;">{{ item[0] }}</td>

{% if item[1] == "invalid" %}
<td style="text-align: center; border: 1px solid black; background-color:red;">{{ item[1] }}</td>
{% elif item[1] =="valid" %}
<td style="text-align: center; border: 1px solid black; background-color:green">{{ item[1] }}</td>
{% else %}
<td style="text-align: center; border: 1px solid black; background-color:yellow">{{ item[1] }}</td>
{% endif %}
<td style="text-align: center; border: 1px solid black;">{{ item[2] }}</td>
{% if item[3] == "valid" %}
<td style="text-align: center; border: 1px solid black; background-color:green">{{ item[3] }}</td>
{% elif item[3] == "invalid" %}
<td style="text-align: center; border: 1px solid black; background-color:red">{{ item[3] }}</td>
{% else %}
<td style="text-align: center; border: 1px solid black; background-color:yellow;">{{ item[3] }}</td>
{% endif %}

</tr>
{% endfor %}
</tbody>
</table>

</body>
</html>

0 comments on commit 0dc2241

Please sign in to comment.