mirror of
https://github.com/skiqqy/skiqqy.github.io
synced 2024-12-21 22:49:58 +00:00
Basic api working
This commit is contained in:
parent
3cc8b35863
commit
3d0bfeac13
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*.swp
|
||||
__pycache__
|
||||
index.html
|
||||
site/
|
||||
bin/
|
||||
|
5
api.sh
Executable file
5
api.sh
Executable 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
1
assets/api_deps.txt
Normal file
@ -0,0 +1 @@
|
||||
flask
|
33
src/main.py
Normal file
33
src/main.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user