From 3a85b7f864e03418de980ff2fb8fb9fc3294b6bd Mon Sep 17 00:00:00 2001 From: Stephen Cochrane Date: Thu, 11 Feb 2021 16:19:23 +0200 Subject: [PATCH] Added templating --- assets/api_templates/domain_status.html | 32 +++++++++++++++++++++++++ src/main.py | 11 +++++---- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 assets/api_templates/domain_status.html diff --git a/assets/api_templates/domain_status.html b/assets/api_templates/domain_status.html new file mode 100644 index 0000000..6bf2c30 --- /dev/null +++ b/assets/api_templates/domain_status.html @@ -0,0 +1,32 @@ + +
{{ TITLE }}
+
+ {% for res in results %} +

{{ res }}

+ {% endfor %} +
diff --git a/src/main.py b/src/main.py index ff2e1bb..7665d92 100644 --- a/src/main.py +++ b/src/main.py @@ -16,16 +16,17 @@ def main(): @app.route('/domain/status/', methods = ["GET"]) def domstatus(dom): + results = [] if dom == 'all': - dom = '' for sub in domains: ip = os.popen('ping -c 1 -w 5 %s.%s | head -1 | cut -d \" \" -f 3' % (sub, main_domain)).read() - dom += sub + ':' + ip + '\n' + results.append("%s.%s:%s" % (sub, main_domain, ip)) elif dom not in domains: - dom = "unknown domain" + results = "unknown domain" else: - dom += ':' + str(os.popen('ping -c 1 -w 5 %s.%s | head -1 | cut -d \" \" -f 3' % (dom, main_domain)).read()) - return dom + ip = os.popen('ping -c 1 -w 5 %s.%s | head -1 | cut -d \" \" -f 3' % (dom, main_domain)).read() + results.append("%s.%s:%s" % (dom, main_domain, ip)) + return render_template('domain_status.html', results=results, TITLE=str("Results for " + dom)) def setup(): app.template_folder = "../assets/api_templates/"