Skip to content


Browse files Browse the repository at this point in the history
fixed type checking
  • Loading branch information
ssw committed Jan 10, 2023
1 parent 182a08f commit 5fa7a27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 80 deletions.
48 changes: 24 additions & 24 deletions docker_container_version/
Expand Up @@ -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):
Expand Down Expand Up @@ -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
return False
Expand Down Expand Up @@ -139,39 +139,35 @@ def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, ro
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():
return render_template('index.html')

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

if __name__ == '__main__':
print("new version - ssw"), host='')
Expand Down
10 changes: 5 additions & 5 deletions docker_container_version/templates/index.html
Expand Up @@ -43,14 +43,14 @@
<p style="text-align: center">This app queries the 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="" required>
<input type="text" id="ip_prefix" name="ip_prefix" placeholder="" 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">
51 changes: 0 additions & 51 deletions templates/render.html

This file was deleted.

0 comments on commit 5fa7a27

Please sign in to comment.