diff --git a/webapp/run.py b/webapp/run.py index 4cb2554..9d611b3 100644 --- a/webapp/run.py +++ b/webapp/run.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 from titanembeds.app import app +import subprocess def init_debug(): import os @@ -30,6 +31,14 @@ def init_debug(): decoded = None return jsonify(session_cookie=decoded) + @app.route("/github-update", methods=["POST"]) + def github_update(): + try: + subprocess.Popen("git pull", shell=True).wait() + except OSError: + return "ERROR" + + return "OK" if __name__ == "__main__": init_debug() app.run(host="0.0.0.0",port=3000,debug=True,processes=3) diff --git a/webapp/titanembeds/__init__.py b/webapp/titanembeds/__init__.py index e69de29..55c0afe 100644 --- a/webapp/titanembeds/__init__.py +++ b/webapp/titanembeds/__init__.py @@ -0,0 +1,2 @@ +global devs +devs = [ "138881969185357825" , "197322731115642880", "193908323911860224" ] \ No newline at end of file diff --git a/webapp/titanembeds/app.py b/webapp/titanembeds/app.py index 956e394..14afba9 100644 --- a/webapp/titanembeds/app.py +++ b/webapp/titanembeds/app.py @@ -5,8 +5,10 @@ from flask_sslify import SSLify from titanembeds.utils import rate_limiter, discord_api, bot_alive import blueprints.api import blueprints.user +import blueprints.admin import blueprints.embed import os +from titanembeds import devs os.chdir(config['app-location']) @@ -23,6 +25,7 @@ rate_limiter.init_app(app) sslify = SSLify(app, permanent=True) app.register_blueprint(blueprints.api.api, url_prefix="/api", template_folder="/templates") +app.register_blueprint(blueprints.admin.admin, url_prefix="/admin", template_folder="/templates") app.register_blueprint(blueprints.user.user, url_prefix="/user", template_folder="/templates") app.register_blueprint(blueprints.embed.embed, url_prefix="/embed", template_folder="/templates") @@ -42,4 +45,4 @@ def before_request(): @app.context_processor def context_processor(): bot_status = bot_alive() - return {"bot_status": bot_status} \ No newline at end of file + return {"bot_status": bot_status, "devs": devs} \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/admin/__init__.py b/webapp/titanembeds/blueprints/admin/__init__.py new file mode 100644 index 0000000..003e90d --- /dev/null +++ b/webapp/titanembeds/blueprints/admin/__init__.py @@ -0,0 +1 @@ +from admin import admin \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/admin/admin.py b/webapp/titanembeds/blueprints/admin/admin.py new file mode 100644 index 0000000..381a774 --- /dev/null +++ b/webapp/titanembeds/blueprints/admin/admin.py @@ -0,0 +1,22 @@ +from flask import Blueprint, url_for, redirect, session, render_template +from functools import wraps +from titanembeds import devs + +admin = Blueprint("admin", __name__) + +def is_admin(f): + def decorator(f): + @wraps(f) + def decorated_function(*args, **kwargs): + if 'user_id' not in session: + return redirect(url_for("index")) + if session['user_id'] not in devs: + return redirect(url_for("index")) + return f(*args, **kwargs) + return decorated_function + return decorator(f) + +@admin.route("/") +@is_admin +def index(): + return render_template("admin_index.html.j2") diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index d7a0451..0572595 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -2,6 +2,7 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, Unauthenticat from titanembeds.decorators import valid_session_required, discord_users_only from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild +from titanembeds import devs from flask import Blueprint, abort, jsonify, session, request, url_for from sqlalchemy import and_ import random @@ -380,7 +381,6 @@ def post(): userid = session["user_id"] content = format_everyone_mention(chan, content) webhook = get_channel_webhook_url(guild_id, channel_id) - devs = [ "138881969185357825" , "197322731115642880" ] if userid in devs: oldcontent = content content = "(Titan Dev) " + oldcontent diff --git a/webapp/titanembeds/templates/admin_index.html.j2 b/webapp/titanembeds/templates/admin_index.html.j2 new file mode 100644 index 0000000..5e88938 --- /dev/null +++ b/webapp/titanembeds/templates/admin_index.html.j2 @@ -0,0 +1,6 @@ +{% extends 'site_layout.html.j2' %} +{% block title %}Admin{% endblock %} + +{% block content %} + +{% endblock %} diff --git a/webapp/titanembeds/templates/site_layout.html.j2 b/webapp/titanembeds/templates/site_layout.html.j2 index 8a1ed18..b7e2397 100644 --- a/webapp/titanembeds/templates/site_layout.html.j2 +++ b/webapp/titanembeds/templates/site_layout.html.j2 @@ -24,6 +24,10 @@ {% if session['unauthenticated'] is defined and not session['unauthenticated'] %}