diff --git a/config.py b/config.py index 193e1e0046cbc6420e220266bd1ae35b18c15b7c..e11486b9f230f6f021aa57770870e62dcfcf4cb4 100644 --- a/config.py +++ b/config.py @@ -33,9 +33,9 @@ disabled_symbols = () # Привилегии (Эти привелегии не трогать! Иначе сломается))) ) priviliges = { - 'admin': 1000, + 'user': 200, 'moder': 500, - 'user': 200 + 'admin': 1000 } moder_bypass = True # Модерам будет разрешено обходить cooldown @@ -43,15 +43,15 @@ moder_bypass = True # Модерам будет разрешено обходи #Разрешённые команды enabled_commands = { 'unban': { - 'need_privilige': 200, # NEED PRIVILIGE WITH RATING 200 + 'need_priority': 200, # NEED PRIVILIGE WITH RATING 200 'cooldown': 100 # IN SECONDS }, 'ban': { - 'need_privilige': 200, # NEED PRIVILIGE WITH RATING 1 + 'need_priority': 200, # NEED PRIVILIGE WITH RATING 1 'cooldown': 100 # IN SECONDS }, - 'unban': { - 'need_privilige': 200, # NEED PRIVILIGE WITH RATING 1 + 'admin pizduk': { + 'need_priority': 1000, # NEED PRIVILIGE WITH RATING 1 'cooldown': 100 # IN SECONDS } diff --git a/handlers/panel.py b/handlers/panel.py index 5a9c375a74c85496fbb167b2a4459b110bc49421..5a705cca534142bb178c42e328c0d45a5c21a739 100644 --- a/handlers/panel.py +++ b/handlers/panel.py @@ -1,13 +1,50 @@ -from flask import Blueprint,jsonify,request,redirect,render_template,session +from flask import Blueprint,jsonify,request,render_template,redirect,session from utils import user_control +from server import utils as su +import datetime module = Blueprint('panel', __name__, template_folder='templates') @module.route("/panel") -def panel(): - print(session) +def access_panel(): if not 'token' in session or not user_control._check_session(session['token']): - del(session) + session.clear() return redirect("/") + + return session['token'] + +@module.route("/panel/console") +def console(): + if not 'token' in session or not user_control._check_session(session['token']): + session.clear() + return redirect("/") + + return render_template("console.tpl") + +@module.route("/panel/console/execute", methods=['POST']) +def console_execute(): + if not 'token' in session or not user_control._check_session(session['token']): + session.clear() + return redirect("/") + + if not request.form.get("command"): + return jsonify({'error_code': 'command is empty'}) + + command = request.form.get("command").lower().split(" ") + if not command: + return jsonify({'error_code': 'command is empty'}) + + u = user_control._get_user_by_token(session['token']) + r = user_control._can_user_execute_command(u, command[0]) + if not r: + return jsonify({'error_code': 'У вас нет доступа к этой команде'}) + elif type(r) is int or type(r) is float: + nowtime = datetime.datetime.now().timestamp() + endtime = int(r)-int(nowtime) + + return jsonify({'error_code': f'Вы не можете исполнять эту команду {endtime} сек.'}) + elif r: + r_command = su._send_command(request.form.get("command")) + user_control._add_cooldown(u, command[0]) + return jsonify({'success': 'Команда была исполнена'}) - return "I'm Panel" \ No newline at end of file diff --git a/utils/user_control.py b/utils/user_control.py index bfb3bbdfe1113f195e444797e7ab66cfbf1b653f..952e684f3d2666b2c1dfd495a21ce6b244d73227 100644 --- a/utils/user_control.py +++ b/utils/user_control.py @@ -6,7 +6,7 @@ import datetime def _create_user(id: int, token: str): try: - Users.create(user_id=id, user_role=200, token=token) + Users.create(user_id=id, user_role=1, token=token) return True except Exception: return False @@ -17,11 +17,21 @@ def _clear_user_token(user: Users): user.save() return True - def _get_user(idd: int): u = Users.select().where(Users.user_id == idd) return u +def _get_user_by_token(token: str): + try: + payload = token_util.decode(token) + u = Users.select().where(Users.user_id == payload['userid']) + if not u: + return None + u = u.get() + return u + except Exception: + return None + def _update_user_token(user: Users, token: str): user = user.get() user.token = token @@ -38,7 +48,7 @@ def _delete_user(id: int): def _clear_user_role(user: Users): user = user.get() - user.user_role = 200 + user.user_role = 1 user.save() def _check_session(token): @@ -47,8 +57,9 @@ def _check_session(token): u = Users.select().where(Users.user_id == payload['userid']) if not u: return False - - if not u.token is token: + + u = u.get() + if not u.token == token: return False except Exception: return False @@ -58,7 +69,7 @@ def _check_session(token): def _add_cooldown(user: Users, command: str): nowtime = datetime.datetime.now().timestamp() try: - commandcd = config.enabled_commands['command']['cooldown'] + commandcd = config.enabled_commands[command]['cooldown'] CommandCooldown.create(user_id=user.user_id, command=command, timestamp=nowtime+commandcd) return True except KeyError: @@ -86,7 +97,7 @@ def _can_user_execute_command(user: Users, command: str): return False else: try: - need_role = config.enabled_commands[command]['need_privilige'] + need_role = config.enabled_commands[command]['need_priority'] if userrole.get().priority < need_role: return False except KeyError: @@ -94,9 +105,9 @@ def _can_user_execute_command(user: Users, command: str): return True else: + ch_user = ch_user.get() userrole = Roles.select().where(Roles.id == user.user_role) if not userrole: - ch_user = ch_user.get() nowtime = datetime.datetime.now().timestamp() if ch_user.timestamp