diff --git a/docker_container_version/main.py b/docker_container_version/main.py index 8d06484..d8f189f 100644 --- a/docker_container_version/main.py +++ b/docker_container_version/main.py @@ -5,8 +5,8 @@ import json import os +# point to templates directory relative to home directory template_dir = template_dir = os.path.join(os.path.dirname(__file__), 'templates') - app = Flask(__name__, template_folder=template_dir) def get_asn_from_as(asn): # Remove the "AS" from the beginning of the ASN @@ -26,7 +26,12 @@ def get_more_specifics(data): origins.append(prefix_origin['origin']) return [prefixes, origins] def get_prefix_roa_status(prefix, origin): - """ given a prefix, determine if it is covered by an existing ROA""" + """ + :param prefix: prefix to check + :param origin: origin ASN to check + :return: ROV status of the prefix based on RIPEstat ROA data + """ + url = f"https://stat.ripe.net/data/rpki-validation/data.json?resource={origin}&prefix={prefix}" response = requests.get(url) data = json.loads(response.text) @@ -38,7 +43,10 @@ def get_prefix_roa_status(prefix, origin): return None return(validation_status) def get_prefix_info(prefix): - """ given a prefix, return the more specific prefixes and their origins as seen by RIPEstat""" + """ + :param prefix: covering prefix to check for more specific prefixes + :return: list of more specific prefixes and their origins + """ url = "https://stat.ripe.net/data/routing-status/data.json?resource=" + prefix try: response = requests.get(url) @@ -92,6 +100,11 @@ def is_valid_asn(asn): return False def is_valid_prefix_maxlength(ip_prefix, prefix_maxlength): + """ check to see prefix_maxlength is a valid value for the prefix + :param ip_prefix: prefix to check + :param prefix_maxlength: maximum length of the prefix + :return: True if prefix_maxlength is valid, False otherwise + """ try: # Try to parse the prefix maxlength as an integer prefix_maxlength = int(prefix_maxlength) @@ -106,6 +119,15 @@ def is_valid_prefix_maxlength(ip_prefix, prefix_maxlength): def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, roa_maxlen, roa_asn): + """ given a list of prefixes and their origins, check if the ROA covers them + :param origin: origin ASN + :param prefixes: list of prefixes + :param origins: list of origins + :param roa_prefix: prefix from the ROA + :param roa_maxlen: maximum length of the prefix from the ROA + :param roa_asn: ASN from the ROA + :return: list output lines to be displayed on the web page + """ messages = [] existing_roa_status = get_prefix_roa_status(roa_prefix, origin) @@ -120,6 +142,10 @@ def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, ro @app.route('/', methods=['GET', 'POST']) def index(): + """ main function to handle the web page + :return: web page + """ + if request.method == 'POST': # Get the user input roa_ip_prefix = request.form['ip_prefix'] diff --git a/docker_container_version/templates/index.html b/docker_container_version/templates/index.html index 305a88d..1d00251 100644 --- a/docker_container_version/templates/index.html +++ b/docker_container_version/templates/index.html @@ -42,7 +42,7 @@
-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
+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