From 5fa7a2770197078e9d5e94f1aaea5b197f126ebf Mon Sep 17 00:00:00 2001 From: "ssw@internet2.edu" Date: Tue, 10 Jan 2023 17:03:44 -0500 Subject: [PATCH] fixed type checking --- docker_container_version/main.py | 48 ++++++++--------- docker_container_version/templates/index.html | 10 ++-- templates/render.html | 51 ------------------- 3 files changed, 29 insertions(+), 80 deletions(-) delete mode 100644 templates/render.html diff --git a/docker_container_version/main.py b/docker_container_version/main.py index 81476ec..9585e67 100644 --- a/docker_container_version/main.py +++ b/docker_container_version/main.py @@ -12,6 +12,7 @@ def get_asn_from_as(asn): # Remove the "AS" from the beginning of the ASN if asn.startswith("AS") or asn.startswith("as"): asn = asn[2:] + asn = int(asn) return asn def get_more_specifics(data): """ @@ -90,11 +91,10 @@ def is_valid_prefix(prefix): return False def is_valid_asn(asn): - # Check if the ASN is a string starting with "AS", followed by numbers - if re.match(r'^[Aa][Ss]\d+$', asn): + # Check if the ASN is a string starting with "AS", followed by numbers or just a number + if asn.isdigit(): return True - # Check if the ASN is just numbers - elif asn.isdigit(): + if re.match(r'^[Aa][Ss]\d+$', asn): return True else: return False @@ -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" @@ -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') diff --git a/docker_container_version/templates/index.html b/docker_container_version/templates/index.html index 1d00251..c5a8894 100644 --- a/docker_container_version/templates/index.html +++ b/docker_container_version/templates/index.html @@ -43,14 +43,14 @@

This app queries the stat.ripe.net to determine if a RPKI-ROA created with the following information
would likely agree (i.e., not evaluate as invalid) for routes currently seen in the Internet

-
+ - + - + - - + +
diff --git a/templates/render.html b/templates/render.html deleted file mode 100644 index 8a353b2..0000000 --- a/templates/render.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - Title - - -
-

Proposed ROA Prefix = {{ roa_info[0] }}

-

Max Length = {{ roa_info[1]}}

-

and origin ASN = {{roa_info[2] }}

-
- - - - - - - - - - - - {% for item in items %} - - - - {% if item[1] == "invalid" %} - - {% elif item[1] =="valid" %} - - {% else %} - - {% endif %} - - {% if item[3] == "valid" %} - - {% elif item[3] == "invalid" %} - - {% else %} - - {% endif %} - - - {% endfor %} - -
The first row is the prefix specified in the proposed ROA. - Subsequent lines list more specifics that are seen in the global routing table.If you create the proposed ROA, this is how it would be evaluated for each prefix.For this prefix, this is the origin ASN as seen in the global Internet.This is the status of this prefix due to an existing ROA.
{{ item[0] }}{{ item[1] }}{{ item[1] }}{{ item[1] }}{{ item[2] }}{{ item[3] }}{{ item[3] }}{{ item[3] }}
- - - \ No newline at end of file