2020-08-13 14:38:36 +00:00
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import tornado.web
|
|
|
|
import tornado.escape
|
|
|
|
import bleach
|
2020-12-14 21:52:46 +00:00
|
|
|
import time
|
|
|
|
import datetime
|
2020-08-13 14:38:36 +00:00
|
|
|
|
|
|
|
from app.classes.shared.console import console
|
2020-08-17 02:47:53 +00:00
|
|
|
from app.classes.shared.models import Users, installer
|
2020-08-13 14:38:36 +00:00
|
|
|
from app.classes.web.base_handler import BaseHandler
|
2020-08-31 17:46:25 +00:00
|
|
|
from app.classes.shared.controller import controller
|
2020-09-04 16:35:06 +00:00
|
|
|
from app.classes.shared.models import db_helper, Servers
|
2020-08-28 18:38:42 +00:00
|
|
|
from app.classes.shared.helpers import helper
|
2021-03-05 08:58:38 +00:00
|
|
|
from app.classes.minecraft.stats import stats
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
class PanelHandler(BaseHandler):
|
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
def get(self, page):
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
2020-09-01 17:29:39 +00:00
|
|
|
error = bleach.clean(self.get_argument('error', "WTF Error!"))
|
2020-08-13 14:38:36 +00:00
|
|
|
|
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-12-14 21:52:46 +00:00
|
|
|
now = time.time()
|
|
|
|
formatted_time = str(datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
|
2020-08-24 17:08:17 +00:00
|
|
|
defined_servers = controller.list_defined_servers()
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
page_data = {
|
2020-09-23 01:43:22 +00:00
|
|
|
# todo: make this actually pull and compare version data
|
2020-09-23 01:42:41 +00:00
|
|
|
'update_available': False,
|
2020-09-01 17:29:39 +00:00
|
|
|
'version_data': helper.get_version_string(),
|
2020-08-19 01:04:43 +00:00
|
|
|
'user_data': user_data,
|
|
|
|
'server_stats': {
|
2020-08-24 17:08:17 +00:00
|
|
|
'total': len(defined_servers),
|
2020-08-19 01:04:43 +00:00
|
|
|
'running': len(controller.list_running_servers()),
|
|
|
|
'stopped': (len(controller.list_defined_servers()) - len(controller.list_running_servers()))
|
|
|
|
},
|
2020-08-24 17:08:17 +00:00
|
|
|
'menu_servers': defined_servers,
|
2020-08-28 18:38:42 +00:00
|
|
|
'hosts_data': db_helper.get_latest_hosts_stats(),
|
2020-09-01 17:29:39 +00:00
|
|
|
'show_contribute': helper.get_setting("show_contribute_link", True),
|
2020-12-14 21:52:46 +00:00
|
|
|
'error': error,
|
|
|
|
'time': formatted_time
|
2020-08-13 14:38:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 17:21:19 +00:00
|
|
|
# if no servers defined, let's go to the build server area
|
2020-12-12 19:35:41 +00:00
|
|
|
if page_data['server_stats']['total'] == 0 and page != "error":
|
2020-08-19 17:54:10 +00:00
|
|
|
self.set_status(301)
|
|
|
|
self.redirect("/server/step1")
|
2020-08-24 02:17:36 +00:00
|
|
|
return False
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
if page == 'unauthorized':
|
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-09-01 17:29:39 +00:00
|
|
|
elif page == "error":
|
|
|
|
template = "public/error.html"
|
|
|
|
|
2020-08-28 03:21:55 +00:00
|
|
|
elif page == 'credits':
|
|
|
|
template = "panel/credits.html"
|
|
|
|
|
2020-08-28 18:38:42 +00:00
|
|
|
elif page == 'contribute':
|
|
|
|
template = "panel/contribute.html"
|
|
|
|
|
2020-12-11 23:59:52 +00:00
|
|
|
elif page == 'file_edit':
|
|
|
|
template = "panel/file_edit.html"
|
|
|
|
|
2020-09-14 18:05:17 +00:00
|
|
|
elif page == "remove_server":
|
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
server_data = controller.get_server_data(server_id)
|
|
|
|
server_name = server_data['server_name']
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(user_data['user_id'],
|
|
|
|
"Deleted server {} named {}".format(server_id, server_name),
|
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
|
|
|
|
controller.remove_server(server_id)
|
|
|
|
self.redirect("/panel/dashboard")
|
|
|
|
return
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
elif page == 'dashboard':
|
2020-08-24 17:08:17 +00:00
|
|
|
page_data['servers'] = db_helper.get_all_servers_stats()
|
2020-08-27 22:30:56 +00:00
|
|
|
|
2020-08-24 23:11:17 +00:00
|
|
|
for s in page_data['servers']:
|
|
|
|
try:
|
|
|
|
data = json.loads(s['int_ping_results'])
|
|
|
|
s['int_ping_results'] = data
|
|
|
|
except:
|
|
|
|
pass
|
2020-08-28 03:21:55 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
template = "panel/dashboard.html"
|
|
|
|
|
2020-08-31 17:46:25 +00:00
|
|
|
elif page == 'server_detail':
|
2020-09-01 17:29:39 +00:00
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
subpage = bleach.clean(self.get_argument('subpage', ""))
|
|
|
|
|
|
|
|
if server_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
server_id = bleach.clean(server_id)
|
|
|
|
|
|
|
|
# does this server id exist?
|
|
|
|
if not db_helper.server_id_exists(server_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return False
|
|
|
|
|
2021-03-05 08:58:38 +00:00
|
|
|
valid_subpages = ['term', 'logs', 'config', 'files', 'admin_controls']
|
2020-09-01 17:29:39 +00:00
|
|
|
|
|
|
|
if subpage not in valid_subpages:
|
2021-01-19 13:56:00 +00:00
|
|
|
logger.debug('not a valid subpage')
|
2020-09-01 17:29:39 +00:00
|
|
|
subpage = 'term'
|
2021-01-19 13:56:00 +00:00
|
|
|
logger.debug('Subpage: "{}"'.format(subpage))
|
2020-09-01 17:29:39 +00:00
|
|
|
|
|
|
|
# server_data isn't needed since the server_stats also pulls server data
|
|
|
|
# page_data['server_data'] = db_helper.get_server_data_by_id(server_id)
|
|
|
|
page_data['server_stats'] = db_helper.get_server_stats_by_id(server_id)
|
2021-03-05 08:58:38 +00:00
|
|
|
page_data['get_players'] = lambda: stats.get_server_players(server_id)
|
|
|
|
|
|
|
|
def get_banned_players_html():
|
|
|
|
banned_players = helper.get_banned_players(server_id, db_helper)
|
|
|
|
if banned_players is None:
|
|
|
|
return """
|
|
|
|
<li class="playerItem banned">
|
|
|
|
<h3>Error while reading banned-players.json</h3>
|
|
|
|
</li>
|
|
|
|
"""
|
|
|
|
html = ""
|
|
|
|
for player in banned_players:
|
|
|
|
html += """
|
|
|
|
<li class="playerItem banned">
|
|
|
|
<h3>{}</h3>
|
|
|
|
<span>Banned by {} for reason: {}</span>
|
|
|
|
<button onclick="send_command_to_server('pardon {}')" type="button" class="btn btn-danger">Unban</button>
|
|
|
|
</li>
|
|
|
|
""".format(player['name'], player['source'], player['reason'], player['name'])
|
|
|
|
|
|
|
|
return html
|
|
|
|
if subpage == "admin_controls":
|
|
|
|
page_data['banned_players'] = get_banned_players_html()
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2020-09-01 17:29:39 +00:00
|
|
|
# template = "panel/server_details.html"
|
|
|
|
template = "panel/server_{subpage}.html".format(subpage=subpage)
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2020-12-06 20:42:49 +00:00
|
|
|
elif page == 'panel_config':
|
|
|
|
page_data['users'] = db_helper.get_all_users()
|
2020-12-27 16:00:26 +00:00
|
|
|
page_data['roles'] = db_helper.get_all_roles()
|
2020-12-26 03:00:28 +00:00
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
for user in page_data['users']:
|
|
|
|
if user.user_id != exec_user['user_id']:
|
|
|
|
user.api_token = "********"
|
2020-12-06 20:42:49 +00:00
|
|
|
template = "panel/panel_config.html"
|
2020-08-31 17:46:25 +00:00
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
elif page == "add_user":
|
|
|
|
page_data['new_user'] = True
|
|
|
|
page_data['user'] = {}
|
|
|
|
page_data['user']['username'] = ""
|
|
|
|
page_data['user']['user_id'] = -1
|
|
|
|
page_data['user']['enabled'] = True
|
|
|
|
page_data['user']['superuser'] = False
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['user']['api_token'] = "N/A"
|
|
|
|
page_data['user']['created'] = "N/A"
|
|
|
|
page_data['user']['last_login'] = "N/A"
|
|
|
|
page_data['user']['last_ip'] = "N/A"
|
2020-12-27 16:00:26 +00:00
|
|
|
page_data['role']['last_update'] = "N/A"
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['user']['roles'] = set()
|
|
|
|
page_data['user']['servers'] = set()
|
2020-12-24 22:55:15 +00:00
|
|
|
|
2020-12-27 16:00:26 +00:00
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
page_data['roles_all'] = db_helper.get_all_roles()
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['servers_all'] = controller.list_defined_servers()
|
2020-12-24 22:55:15 +00:00
|
|
|
template = "panel/panel_edit_user.html"
|
|
|
|
|
|
|
|
elif page == "edit_user":
|
|
|
|
page_data['new_user'] = False
|
2020-12-27 16:00:26 +00:00
|
|
|
user_id = self.get_argument('id', None)
|
|
|
|
page_data['user'] = db_helper.get_user(user_id)
|
2020-12-24 22:55:15 +00:00
|
|
|
page_data['roles_all'] = db_helper.get_all_roles()
|
2020-12-26 03:00:28 +00:00
|
|
|
page_data['servers_all'] = controller.list_defined_servers()
|
|
|
|
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
2020-12-27 16:00:26 +00:00
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return False
|
|
|
|
|
2020-12-26 03:00:28 +00:00
|
|
|
if exec_user['user_id'] != page_data['user']['user_id']:
|
|
|
|
page_data['user']['api_token'] = "********"
|
2020-12-24 22:55:15 +00:00
|
|
|
template = "panel/panel_edit_user.html"
|
|
|
|
|
|
|
|
elif page == "remove_user":
|
|
|
|
user_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
target_user = db_helper.get_user(user_id)
|
|
|
|
if not target_user:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return False
|
|
|
|
elif target_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Cannot remove a superuser")
|
|
|
|
return False
|
|
|
|
|
|
|
|
db_helper.remove_user(user_id)
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Removed user {} (UID:{})".format(target_user['username'], user_id),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
2020-12-27 16:00:26 +00:00
|
|
|
elif page == "add_role":
|
|
|
|
page_data['new_role'] = True
|
|
|
|
page_data['role'] = {}
|
|
|
|
page_data['role']['role_name'] = ""
|
|
|
|
page_data['role']['role_id'] = -1
|
|
|
|
page_data['role']['created'] = "N/A"
|
|
|
|
page_data['role']['last_update'] = "N/A"
|
|
|
|
page_data['role']['servers'] = set()
|
|
|
|
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
|
|
|
|
page_data['servers_all'] = controller.list_defined_servers()
|
|
|
|
template = "panel/panel_edit_role.html"
|
|
|
|
|
|
|
|
elif page == "edit_role":
|
|
|
|
page_data['new_role'] = False
|
|
|
|
role_id = self.get_argument('id', None)
|
|
|
|
page_data['role'] = db_helper.get_role(role_id)
|
|
|
|
page_data['servers_all'] = controller.list_defined_servers()
|
|
|
|
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif role_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
|
|
|
return False
|
|
|
|
|
|
|
|
template = "panel/panel_edit_role.html"
|
|
|
|
|
|
|
|
elif page == "remove_role":
|
|
|
|
role_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif role_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
target_role = db_helper.get_user(role_id)
|
|
|
|
if not target_role:
|
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
|
|
|
return False
|
|
|
|
|
|
|
|
db_helper.remove_role(role_id)
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Removed role {} (RID:{})".format(target_role['role_name'], role_id),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
2020-12-13 18:40:55 +00:00
|
|
|
elif page == "activity_logs":
|
|
|
|
page_data['audit_logs'] = db_helper.get_actity_log()
|
|
|
|
|
|
|
|
template = "panel/activity_logs.html"
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
self.render(
|
|
|
|
template,
|
2020-12-15 23:17:41 +00:00
|
|
|
data=page_data,
|
|
|
|
time=time,
|
|
|
|
utc_offset=(time.timezone * -1 / 60 / 60),
|
2020-08-24 17:08:17 +00:00
|
|
|
)
|
2020-09-04 16:35:06 +00:00
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
def post(self, page):
|
|
|
|
|
|
|
|
if page == 'server_detail':
|
|
|
|
server_id = self.get_argument('id', None)
|
|
|
|
server_name = self.get_argument('server_name', None)
|
|
|
|
server_path = self.get_argument('server_path', None)
|
|
|
|
log_path = self.get_argument('log_path', None)
|
|
|
|
executable = self.get_argument('executable', None)
|
|
|
|
execution_command = self.get_argument('execution_command', None)
|
|
|
|
stop_command = self.get_argument('stop_command', None)
|
2020-09-04 18:05:42 +00:00
|
|
|
auto_start_delay = self.get_argument('auto_start_delay', '10')
|
2020-09-22 16:11:16 +00:00
|
|
|
server_ip = self.get_argument('server_ip', None)
|
2020-09-04 16:35:06 +00:00
|
|
|
server_port = self.get_argument('server_port', None)
|
2020-09-04 18:05:42 +00:00
|
|
|
auto_start = int(float(self.get_argument('auto_start', '0')))
|
|
|
|
crash_detection = int(float(self.get_argument('crash_detection', '0')))
|
2021-01-20 15:20:42 +00:00
|
|
|
logs_delete_after = int(float(self.get_argument('logs_delete_after', '0')))
|
2020-09-04 16:35:06 +00:00
|
|
|
subpage = self.get_argument('subpage', None)
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user.superuser:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif server_id is None:
|
2020-09-04 16:35:06 +00:00
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
server_id = bleach.clean(server_id)
|
|
|
|
|
|
|
|
# does this server id exist?
|
|
|
|
if not db_helper.server_id_exists(server_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Server ID")
|
|
|
|
return False
|
|
|
|
|
|
|
|
Servers.update({
|
|
|
|
Servers.server_name: server_name,
|
|
|
|
Servers.path: server_path,
|
|
|
|
Servers.log_path: log_path,
|
|
|
|
Servers.executable: executable,
|
|
|
|
Servers.execution_command: execution_command,
|
|
|
|
Servers.stop_command: stop_command,
|
|
|
|
Servers.auto_start_delay: auto_start_delay,
|
2020-09-22 16:11:16 +00:00
|
|
|
Servers.server_ip: server_ip,
|
2020-09-04 16:35:06 +00:00
|
|
|
Servers.server_port: server_port,
|
|
|
|
Servers.auto_start: auto_start,
|
|
|
|
Servers.crash_detection: crash_detection,
|
2021-01-20 15:20:42 +00:00
|
|
|
Servers.logs_delete_after: logs_delete_after,
|
2020-09-04 16:35:06 +00:00
|
|
|
}).where(Servers.server_id == server_id).execute()
|
|
|
|
|
2020-10-07 13:19:47 +00:00
|
|
|
controller.refresh_server_settings(server_id)
|
|
|
|
|
2020-09-04 18:05:42 +00:00
|
|
|
db_helper.add_to_audit_log(user_data['user_id'],
|
|
|
|
"Edited server {} named {}".format(server_id, server_name),
|
|
|
|
server_id,
|
|
|
|
self.get_remote_ip())
|
|
|
|
|
2020-09-04 16:35:06 +00:00
|
|
|
self.redirect("/panel/server_detail?id={}&subpage=config".format(server_id))
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
elif page == "edit_user":
|
|
|
|
user_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
username = bleach.clean(self.get_argument('username', None))
|
|
|
|
password0 = bleach.clean(self.get_argument('password0', None))
|
|
|
|
password1 = bleach.clean(self.get_argument('password1', None))
|
|
|
|
enabled = int(float(bleach.clean(self.get_argument('enabled'), '0')))
|
|
|
|
regen_api = int(float(bleach.clean(self.get_argument('regen_api', '0'))))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
2020-12-27 16:00:26 +00:00
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif username is None or username == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
|
|
|
return False
|
|
|
|
elif user_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
if not db_helper.user_id_exists(user_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid User ID")
|
|
|
|
return False
|
|
|
|
|
|
|
|
if password0 != password1:
|
|
|
|
self.redirect("/panel/error?error=Passwords must match")
|
|
|
|
return False
|
|
|
|
|
2020-12-26 03:00:28 +00:00
|
|
|
roles = set()
|
2020-12-27 16:00:26 +00:00
|
|
|
for role in db_helper.get_all_roles():
|
2020-12-26 03:00:28 +00:00
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
2020-12-27 16:00:26 +00:00
|
|
|
self.get_argument('role_{}_membership'.format(role.role_id), '0')
|
2020-12-26 03:00:28 +00:00
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
2020-12-27 16:00:26 +00:00
|
|
|
roles.add(role.role_id)
|
2020-12-26 03:00:28 +00:00
|
|
|
|
|
|
|
servers = set()
|
|
|
|
for server in controller.list_defined_servers():
|
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
|
|
|
self.get_argument('server_{}_access'.format(server['server_id']), '0')
|
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
servers.add(server['server_id'])
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
user_data = {
|
|
|
|
"username": username,
|
|
|
|
"password": password0,
|
|
|
|
"enabled": enabled,
|
|
|
|
"regen_api": regen_api,
|
2020-12-26 03:00:28 +00:00
|
|
|
"roles": roles,
|
|
|
|
"servers": servers
|
2020-12-24 22:55:15 +00:00
|
|
|
}
|
|
|
|
db_helper.update_user(user_id, user_data=user_data)
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
2020-12-26 03:00:28 +00:00
|
|
|
"Edited user {} (UID:{}) with roles {} and servers {}".format(username, user_id, roles, servers),
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
|
|
|
|
|
|
|
elif page == "add_user":
|
|
|
|
username = bleach.clean(self.get_argument('username', None))
|
|
|
|
password0 = bleach.clean(self.get_argument('password0', None))
|
|
|
|
password1 = bleach.clean(self.get_argument('password1', None))
|
|
|
|
enabled = int(float(bleach.clean(self.get_argument('enabled'), '0')))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif username is None or username == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
if db_helper.get_userid_by_name(username) is not None:
|
|
|
|
self.redirect("/panel/error?error=User exists")
|
|
|
|
return False
|
|
|
|
|
|
|
|
if password0 != password1:
|
|
|
|
self.redirect("/panel/error?error=Passwords must match")
|
|
|
|
return False
|
|
|
|
|
2020-12-26 03:00:28 +00:00
|
|
|
roles = set()
|
2020-12-27 16:00:26 +00:00
|
|
|
for role in db_helper.get_all_roles():
|
2020-12-26 03:00:28 +00:00
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
2020-12-27 16:00:26 +00:00
|
|
|
self.get_argument('role_{}_membership'.format(role.role_id), '0')
|
2020-12-26 03:00:28 +00:00
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
roles.add(role['role_id'])
|
|
|
|
|
|
|
|
servers = set()
|
|
|
|
for server in controller.list_defined_servers():
|
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
|
|
|
self.get_argument('server_{}_access'.format(server['server_id']), '0')
|
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
servers.add(server['server_id'])
|
|
|
|
|
2020-12-24 22:55:15 +00:00
|
|
|
user_id = db_helper.add_user(username, password=password0, enabled=enabled)
|
2020-12-26 03:00:28 +00:00
|
|
|
db_helper.update_user(user_id, {"roles":roles, "servers": servers})
|
2020-12-24 22:55:15 +00:00
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Added user {} (UID:{})".format(username, user_id),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
2020-12-26 03:00:28 +00:00
|
|
|
"Edited user {} (UID:{}) with roles {} and servers {}".format(username, user_id, roles, servers),
|
2020-12-24 22:55:15 +00:00
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2020-12-27 16:00:26 +00:00
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
|
|
|
elif page == "edit_role":
|
|
|
|
role_id = bleach.clean(self.get_argument('id', None))
|
|
|
|
role_name = bleach.clean(self.get_argument('role_name', None))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif role_name is None or role_name == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid username")
|
|
|
|
return False
|
|
|
|
elif role_id is None:
|
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
if not db_helper.role_id_exists(role_id):
|
|
|
|
self.redirect("/panel/error?error=Invalid Role ID")
|
|
|
|
return False
|
|
|
|
|
|
|
|
servers = set()
|
|
|
|
for server in controller.list_defined_servers():
|
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
|
|
|
self.get_argument('server_{}_access'.format(server['server_id']), '0')
|
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
servers.add(server['server_id'])
|
|
|
|
|
|
|
|
role_data = {
|
|
|
|
"role_name": role_name,
|
|
|
|
"servers": servers
|
|
|
|
}
|
|
|
|
db_helper.update_role(role_id, role_data=role_data)
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Edited role {} (RID:{}) with servers {}".format(role_name, role_id, servers),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
self.redirect("/panel/panel_config")
|
|
|
|
|
|
|
|
|
|
|
|
elif page == "add_role":
|
|
|
|
role_name = bleach.clean(self.get_argument('role_name', None))
|
|
|
|
|
|
|
|
user_data = json.loads(self.get_secure_cookie("user_data"))
|
|
|
|
exec_user = db_helper.get_user(user_data['user_id'])
|
|
|
|
if not exec_user['superuser']:
|
|
|
|
self.redirect("/panel/error?error=Unauthorized access: not superuser")
|
|
|
|
return False
|
|
|
|
elif role_name is None or role_name == "":
|
|
|
|
self.redirect("/panel/error?error=Invalid role name")
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
# does this user id exist?
|
|
|
|
if db_helper.get_roleid_by_name(role_name) is not None:
|
|
|
|
self.redirect("/panel/error?error=Role exists")
|
|
|
|
return False
|
|
|
|
|
|
|
|
servers = set()
|
|
|
|
for server in controller.list_defined_servers():
|
|
|
|
argument = int(float(
|
|
|
|
bleach.clean(
|
|
|
|
self.get_argument('server_{}_access'.format(server['server_id']), '0')
|
|
|
|
)
|
|
|
|
))
|
|
|
|
if argument:
|
|
|
|
servers.add(server['server_id'])
|
|
|
|
|
|
|
|
role_id = db_helper.add_role(role_name)
|
|
|
|
db_helper.update_role(role_id, {"servers": servers})
|
|
|
|
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Added role {} (RID:{})".format(role_name, role_id),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
|
|
|
db_helper.add_to_audit_log(exec_user['user_id'],
|
|
|
|
"Edited role {} (RID:{}) with servers {}".format(role_name, role_id, servers),
|
|
|
|
server_id=0,
|
|
|
|
source_ip=self.get_remote_ip())
|
2020-12-24 22:55:15 +00:00
|
|
|
self.redirect("/panel/panel_config")
|