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