Hello world, whatever

master
informatic 2019-05-20 21:37:57 +02:00
commit 1d2b54d55b
3 changed files with 54 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.py[co]
.ropeproject
__pycache__

45
app.py Normal file
View File

@ -0,0 +1,45 @@
from flask import Flask, render_template
from flask_admin import Admin
from flask_sqlalchemy import SQLAlchemy
from flask_admin.contrib.sqla import ModelView
import requests
app = Flask(__name__)
app.config['SECRET_KEY'] = 'changeme'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/database.db'
db = SQLAlchemy(app)
admin = Admin(app, name='microblog', template_mode='bootstrap3')
class Site(db.Model):
__tablename__ = 'sites'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
api_key = db.Column(db.String)
network_id = db.Column(db.String)
admin.add_view(ModelView(Site, db.session))
@app.route('/')
def index():
return render_template('index.html', sites=Site.query.all())
@app.route('/fix/<site_id>')
def fix_firewall(site_id):
site = Site.query.get(site_id)
resp = requests.get('https://kasownik.hackerspace.pl/api/judgement/%s.json' % (site.api_key,))
return resp.json()['status']
@app.route('/break/<site_id>')
def break_firewall(site_id):
return site_id

6
templates/index.html Normal file
View File

@ -0,0 +1,6 @@
{% for site in sites %}
<h1>{{ site.name }}</h1>
<code>{{ site.api_key }}</code>
<a href="{{ url_for('fix_firewall', site_id=site.id) }}">Fix firewall</a>
<a href="{{ url_for('break_firewall', site_id=site.id) }}">Break firewall</a>
{% endfor %}