From 52088d391b6a62f984fa2ad4546558751643495b Mon Sep 17 00:00:00 2001 From: SuperSonic Date: Fri, 7 Feb 2020 22:11:44 +0800 Subject: [PATCH] Update and remove page-transitions for some security reason --- libs/webadmin/api.py | 33 +++- libs/webadmin/server.py | 25 ++- libs/webadmin/static/{ => css}/main.css | 0 libs/webadmin/static/events.js | 0 libs/webadmin/static/js/events.js | 16 ++ libs/webadmin/static/{ => js}/header.js | 2 +- libs/webadmin/static/{ => js}/verify.js | 0 libs/webadmin/templates/index.html | 4 +- libs/webadmin/templates/manage/events.html | 180 ++----------------- libs/webadmin/templates/manage/groups.html | 113 ++++++------ libs/webadmin/templates/manage/index.html | 125 ++++++------- libs/webadmin/templates/manage/settings.html | 73 ++++++++ main.py | 2 +- 13 files changed, 257 insertions(+), 316 deletions(-) rename libs/webadmin/static/{ => css}/main.css (100%) delete mode 100644 libs/webadmin/static/events.js create mode 100644 libs/webadmin/static/js/events.js rename libs/webadmin/static/{ => js}/header.js (90%) rename libs/webadmin/static/{ => js}/verify.js (100%) create mode 100644 libs/webadmin/templates/manage/settings.html diff --git a/libs/webadmin/api.py b/libs/webadmin/api.py index 9ea28b1..1f227b4 100644 --- a/libs/webadmin/api.py +++ b/libs/webadmin/api.py @@ -5,4 +5,35 @@ Yuuki_Libs This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -""" \ No newline at end of file +""" +from .reader import Yuuki_WebDataReader + +class Yuuki_WebAdminAPI: + def __init__(self, YuukiData): + self.YukkiData = YuukiData + self.Yuuki_DataHandle = Yuuki_WebDataReader(YuukiData) + self.events = { + "": self.nothing, + "get_logs": self.get_logs, + "get_groups_joined": self.get_groups_joined, + } + + def init(self, **action): + action.setdefault('task', "") + action.setdefault('data', None) + return self.events[action["task"]](action["data"]) + + def get_groups_joined(self, **data): + data.setdefault('data', None) + return self.YukkiData.getData(["Global", "GroupJoined"]) + + def get_logs(self, **data): + data.setdefault('name', None) + if data.get("name"): + return self.Yuuki_DataHandle.get_log(data["name"]) + return self.Yuuki_DataHandle.get_all_logs() + + @staticmethod + def nothing(data): + if data: + pass diff --git a/libs/webadmin/server.py b/libs/webadmin/server.py index 015eecb..9f518e2 100644 --- a/libs/webadmin/server.py +++ b/libs/webadmin/server.py @@ -15,11 +15,11 @@ from flask import Flask, render_template, Response, request, redirect from flask_bootstrap import Bootstrap from gevent.pywsgi import WSGIServer -from .reader import Yuuki_WebDataReader +from .api import Yuuki_WebAdminAPI wa_app = Flask(__name__) Yuuki_Handle = None -Yuuki_DataHandle = None +Yuuki_APIHandle = None passports = [] password = str(hash(random.random())) @@ -27,9 +27,9 @@ password = str(hash(random.random())) class Yuuki_WebAdmin: def __init__(self, Yuuki): - global Yuuki_Handle, Yuuki_DataHandle + global Yuuki_Handle, Yuuki_APIHandle Yuuki_Handle = Yuuki - Yuuki_DataHandle = Yuuki_WebDataReader(Yuuki_Handle.data) + Yuuki_APIHandle = Yuuki_WebAdminAPI(Yuuki_Handle.data) self.app = wa_app Bootstrap(self.app) @@ -99,7 +99,7 @@ class Yuuki_WebAdmin: if "yuuki_admin" in request.cookies: if request.cookies["yuuki_admin"] in passports: return render_template( - 'manage/groups.html' + 'manage/settings.html' ) response = redirect("/") response.set_cookie( @@ -155,16 +155,15 @@ class Yuuki_WebAdmin: return response @staticmethod - @wa_app.route("/api/logs") - @wa_app.route("/api/logs/") - def logs(name=""): + @wa_app.route("/api", methods=['GET', 'POST']) + def api(): result = {"status": 403} - if "yuuki_admin" in request.cookies: + if request.method == "POST" and "task" in request.values: if request.cookies.get("yuuki_admin") in passports: - if name: - result = Yuuki_DataHandle.get_log(name) - else: - result = Yuuki_DataHandle.get_all_logs() + query_result = Yuuki_APIHandle.init(request.values) + result = {"status": 200, "result": query_result} + else: + result = {"status": 401} return Response(json.dumps(result), mimetype='application/json') @staticmethod diff --git a/libs/webadmin/static/main.css b/libs/webadmin/static/css/main.css similarity index 100% rename from libs/webadmin/static/main.css rename to libs/webadmin/static/css/main.css diff --git a/libs/webadmin/static/events.js b/libs/webadmin/static/events.js deleted file mode 100644 index e69de29..0000000 diff --git a/libs/webadmin/static/js/events.js b/libs/webadmin/static/js/events.js new file mode 100644 index 0000000..943e8b7 --- /dev/null +++ b/libs/webadmin/static/js/events.js @@ -0,0 +1,16 @@ +$(function () { + $.ajax({ + url: "/api", + type: "GET", + data: { + user_name: $("#user_name").val() + }, + error: function(xhr) { + alert("Something was wrong."); + }, + success: function(response) { + $("#msg_user_name").html(response); + $("#msg_user_name").fadeIn(); + } + }); +}) \ No newline at end of file diff --git a/libs/webadmin/static/header.js b/libs/webadmin/static/js/header.js similarity index 90% rename from libs/webadmin/static/header.js rename to libs/webadmin/static/js/header.js index be00b08..a4b8069 100644 --- a/libs/webadmin/static/header.js +++ b/libs/webadmin/static/js/header.js @@ -13,7 +13,7 @@ if (window.location.pathname === p_key) nav_list += "" + page_list[p_key] + ""; else - nav_list += "" + page_list[p_key] + ""; + nav_list += "" + page_list[p_key] + ""; } var html_text = "