Basic api working

This commit is contained in:
Stephen Cochrane 2021-02-11 16:03:59 +02:00
parent 3cc8b35863
commit 3d0bfeac13
4 changed files with 40 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.swp
__pycache__
index.html
site/
bin/

5
api.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -B
export FLASK_APP=./src/main.py
pip3 install --user -r ./assets/api_deps.txt
python3 -m flask run --host=0.0.0.0 --port=8199

1
assets/api_deps.txt Normal file
View File

@ -0,0 +1 @@
flask

33
src/main.py Normal file
View File

@ -0,0 +1,33 @@
# Needed libs
from flask import Flask, render_template, request, jsonify
from hashlib import sha256
from datetime import datetime
import os
# My libs
main_domain = 'skiqqy.xyz'
domains = ['git', 'irc', 'proj', 'blog', 'pay', 'wiki', 'files', 'social', 'music', 'dev'] # TODO: Save this in file to reduce coupling with dns.py
app = Flask(__name__)
@app.route('/')
def main():
return render_template('index.html')
@app.route('/domain/status/<dom>', methods = ["GET"])
def domstatus(dom):
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'
elif dom not in domains:
dom = "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
def setup():
app.template_folder = "../assets/api_templates/"
setup()