2017-02-10 06:10:44 +01:00
|
|
|
#!/usr/bin/env python2
|
2017-08-19 05:52:32 +02:00
|
|
|
from titanembeds.app import app, socketio
|
2017-07-06 23:35:08 +02:00
|
|
|
import subprocess
|
2017-02-10 06:10:44 +01:00
|
|
|
|
2017-03-31 09:34:06 +02:00
|
|
|
def init_debug():
|
2017-03-24 09:22:03 +01:00
|
|
|
import os
|
2017-03-25 08:52:56 +01:00
|
|
|
from flask import jsonify, request
|
2017-04-22 07:53:45 +02:00
|
|
|
|
2017-03-24 09:22:03 +01:00
|
|
|
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' # Testing oauthlib
|
2017-12-07 07:49:32 +01:00
|
|
|
|
|
|
|
app.jinja_env.auto_reload = True
|
|
|
|
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
2017-04-22 07:53:45 +02:00
|
|
|
|
2017-03-25 08:52:56 +01:00
|
|
|
# Session viewer https://gist.github.com/babldev/502364a3f7c9bafaa6db
|
|
|
|
def decode_flask_cookie(secret_key, cookie_str):
|
|
|
|
import hashlib
|
|
|
|
from itsdangerous import URLSafeTimedSerializer
|
|
|
|
from flask.sessions import TaggedJSONSerializer
|
|
|
|
salt = 'cookie-session'
|
|
|
|
serializer = TaggedJSONSerializer()
|
|
|
|
signer_kwargs = {
|
|
|
|
'key_derivation': 'hmac',
|
|
|
|
'digest_method': hashlib.sha1
|
|
|
|
}
|
|
|
|
s = URLSafeTimedSerializer(secret_key, salt=salt, serializer=serializer, signer_kwargs=signer_kwargs)
|
|
|
|
return s.loads(cookie_str)
|
2017-04-22 07:53:45 +02:00
|
|
|
|
2017-03-25 08:52:56 +01:00
|
|
|
@app.route("/session")
|
|
|
|
def session():
|
|
|
|
cookie = request.cookies.get('session')
|
|
|
|
if cookie:
|
|
|
|
decoded = decode_flask_cookie(app.secret_key, request.cookies.get('session'))
|
|
|
|
else:
|
|
|
|
decoded = None
|
|
|
|
return jsonify(session_cookie=decoded)
|
|
|
|
|
2017-07-06 23:35:08 +02:00
|
|
|
@app.route("/github-update", methods=["POST"])
|
|
|
|
def github_update():
|
|
|
|
try:
|
|
|
|
subprocess.Popen("git pull", shell=True).wait()
|
|
|
|
except OSError:
|
|
|
|
return "ERROR"
|
2018-07-30 03:26:54 +02:00
|
|
|
|
|
|
|
@app.route("/error")
|
|
|
|
def make_error():
|
|
|
|
1 / 0
|
2017-07-06 23:35:08 +02:00
|
|
|
|
|
|
|
return "OK"
|
2017-03-31 09:34:06 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
init_debug()
|
2017-08-19 05:52:32 +02:00
|
|
|
socketio.run(app, host="0.0.0.0",port=3000,debug=True)
|