Merge branch 'dev' into 'master'

Dev to master

See merge request crafty-controller/crafty-commander!4
This commit is contained in:
Phillip Tarrant 2020-09-23 12:51:57 +00:00
commit fe54367d44
18 changed files with 119 additions and 110 deletions

View File

@ -250,7 +250,7 @@ class Stats:
Server_Stats.version: server.get("version", False)
}).execute()
# delete 1 week old data
# delete old data
max_age = helper.get_setting("history_max_age")
now = datetime.datetime.now()
last_week = now.day - max_age

View File

@ -13,11 +13,13 @@ import logging
from datetime import datetime
from socket import gethostname
from app.classes.shared.console import console
logger = logging.getLogger(__name__)
try:
import requests
from OpenSSL import crypto
from argon2 import PasswordHasher
@ -96,6 +98,21 @@ class Helpers:
return version_data
@staticmethod
def get_announcements():
r = requests.get('https://craftycontrol.com/notify.json', timeout=2)
data = '[{"id":"1","date":"Unknown","title":"Error getting Announcements","desc":"Error getting ' \
'Announcements","link":""}] '
if r.status_code in [200, 201]:
try:
data = json.loads(r.content)
except:
pass
return data
def get_version_string(self):
version_data = self.get_version()

View File

@ -43,6 +43,7 @@ class Users(BaseModel):
class Meta:
table_name = "users"
class Audit_Log(BaseModel):
audit_id = AutoField()
created = DateTimeField(default=datetime.datetime.now)
@ -53,7 +54,6 @@ class Audit_Log(BaseModel):
log_msg = TextField(default='')
class Host_Stats(BaseModel):
time = DateTimeField(default=datetime.datetime.now)
boot_time = CharField(default="")
@ -83,6 +83,7 @@ class Servers(BaseModel):
auto_start_delay = IntegerField(default=10)
crash_detection = BooleanField(default=0)
stop_command = CharField(default="stop")
server_ip = CharField(default="127.0.0.1")
server_port = IntegerField(default=25565)
class Meta:
@ -166,7 +167,8 @@ class db_builder:
@staticmethod
def default_settings():
logger.info("Fresh Install Detected - Creating Default Settings")
console.info("Fresh Install Detected - Creating Default Settings")
default_data = helper.find_default_password()
username = default_data.get("username", 'admin')
@ -174,7 +176,7 @@ class db_builder:
api_token = helper.random_string_generator(32)
Users.insert({
Users.username: username,
Users.username: username.lower(),
Users.password: helper.encode_pass(password),
Users.api_token: api_token,
Users.enabled: True
@ -184,9 +186,12 @@ class db_builder:
@staticmethod
def is_fresh_install():
if helper.check_file_exists(helper.db_path):
try:
user = Users.get_by_id(1)
return False
return True
except:
return True
pass
class db_shortcuts:

View File

@ -74,4 +74,31 @@ class AjaxHandler(BaseHandler):
logger.warning("Skipping Log Line due to error: {}".format(e))
pass
elif page == "announcements":
data = helper.get_announcements()
page_data['notify_data'] = data
self.render_page('ajax/notify.html', page_data)
def post(self, page):
user_data = json.loads(self.get_secure_cookie("user_data"))
error = bleach.clean(self.get_argument('error', "WTF Error!"))
page_data = {
'user_data': user_data,
'error': error
}
if page == "send_command":
command = bleach.clean(self.get_body_argument('command', default=None, strip=True))
server_id = bleach.clean(self.get_argument('id'))
if server_id is None:
logger.warning("Server ID not found in send_command ajax call")
srv_obj = controller.get_server_obj(server_id)
if command:
if srv_obj.check_running():
srv_obj.send_command(command)

View File

@ -26,6 +26,8 @@ class PanelHandler(BaseHandler):
defined_servers = controller.list_defined_servers()
page_data = {
# todo: make this actually pull and compare version data
'update_available': False,
'version_data': helper.get_version_string(),
'user_data': user_data,
'server_stats': {
@ -128,6 +130,7 @@ class PanelHandler(BaseHandler):
execution_command = self.get_argument('execution_command', None)
stop_command = self.get_argument('stop_command', None)
auto_start_delay = self.get_argument('auto_start_delay', '10')
server_ip = self.get_argument('server_ip', None)
server_port = self.get_argument('server_port', None)
auto_start = int(float(self.get_argument('auto_start', '0')))
crash_detection = int(float(self.get_argument('crash_detection', '0')))
@ -152,6 +155,7 @@ class PanelHandler(BaseHandler):
Servers.execution_command: execution_command,
Servers.stop_command: stop_command,
Servers.auto_start_delay: auto_start_delay,
Servers.server_ip: server_ip,
Servers.server_port: server_port,
Servers.auto_start: auto_start,
Servers.crash_detection: crash_detection,

View File

@ -95,10 +95,10 @@ class PublicHandler(BaseHandler):
logger.info("User: {} Logged in from IP: {}".format(user_data, self.get_remote_ip()))
# record this login
Users.update({
Users.last_ip: self.get_remote_ip(),
Users.last_login: helper.get_time_as_string()
}).where(Users.username == entered_username).execute()
q = Users.select().where(Users.username == entered_username.lower()).get()
q.last_ip = self.get_remote_ip()
q.last_login = helper.get_time_as_string()
q.save()
# log this login
db_helper.add_to_audit_log(user_data.user_id, "Logged in", 0, self.get_remote_ip())

View File

@ -36,7 +36,7 @@ class ServerHandler(BaseHandler):
defined_servers = controller.list_defined_servers()
page_data = {
'version_data': "version_data_here",
'version_data': helper.get_version_string(),
'user_data': user_data,
'server_stats': {
'total': len(controller.list_defined_servers()),

View File

@ -1,5 +1,5 @@
{
"last_refreshed": "09/17/2020, 18:43:17",
"last_refreshed": "09/21/2020, 21:59:31",
"servers": {
"nukkitx": [
"1.14"

View File

@ -0,0 +1,14 @@
{% for item in data['notify_data'] %}
<!-- <div class="hidden">{{ item['id'] }}</div>-->
<div class="event">
<p class="font-weight-medium">{{ item['title'] }}</p>
<a class="d-flex align-items-center">
<div class="badge badge-primary">{{ item['date'] }}</div>
<span class="text-muted ml-2">{{ item['desc'] }}</span>
</a>
</div>
{% end %}

View File

@ -44,30 +44,6 @@
<button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
<span class="mdi mdi-menu"></span>
</button>
<ul class="navbar-nav">
<li class="nav-item dropdown language-dropdown">
<a class="nav-link dropdown-toggle px-2 d-flex align-items-center" id="LanguageDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
<div class="d-inline-flex mr-0 mr-md-3">
<div class="flag-icon-holder">
<i class="flag-icon flag-icon-us"></i>
</div>
</div>
<span class="profile-text font-weight-medium d-none d-md-block">English</span>
</a>
<div class="dropdown-menu dropdown-menu-left navbar-dropdown py-2" aria-labelledby="LanguageDropdown">
<a class="dropdown-item">
<div class="flag-icon-holder">
<i class="flag-icon flag-icon-us"></i>
</div>English
</a>
<a class="dropdown-item">
<div class="flag-icon-holder">
<i class="flag-icon flag-icon-fr"></i>
</div>French
</a>
</div>
</li>
</ul>
{% include notify.html %}
@ -111,6 +87,20 @@
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
<!-- Notify-->
$(document).ready(function(){
$("#notificationDropdown").click(function(){
$.get("/ajax/announcements", function(data){
console.log(data);
bootbox.alert({
title: "Notifications",
message: data,
});
});
});
});
</script>
{% block js %}

View File

@ -1,8 +1,11 @@
<!-- partial:partials/_footer.html -->
<footer class="footer">
<div class="container-fluid clearfix">
<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">Copyright © 2020 <a href="http://www.rentmydatacenter.com/" target="_blank">RMDC</a>. All rights reserved.</span>
<div class="container-fluid ">
<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">Copyright © 2020 <a href="http://www.craftycontrol.com/" target="_blank">Crafty Controller</a>. All rights reserved.</span>
<span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">Version: {{ data['version_data'] }}
</span>
</div>
</footer>
<!-- partial -->

View File

@ -33,43 +33,16 @@
</ul>
</div>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#apps-dropdown" aria-expanded="false" aria-controls="apps-dropdown">
<i class="fas fa-cogs"></i> &nbsp;
<span class="menu-title">Configuration</span>
<i class="menu-arrow"></i>
</a>
<div class="collapse" id="apps-dropdown">
<ul class="nav flex-column sub-menu">
<li class="nav-item">
<a class="nav-link" href="pages/apps/kanban-board.html">History Limit</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/apps/email.html">Claims</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/apps/calendar.html">Calendar</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/apps/todo.html">Todo List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/apps/gallery.html">API Keys</a>
</li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/samples/widgets.html">
<a class="nav-link" href="https://gitlab.com/crafty-controller/crafty-web/-/wikis/home" target="_blank">
<i class="fas fa-book"></i> &nbsp;
<span class="menu-title">Documentation</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/samples/widgets.html">
<a class="nav-link" href="https://discord.gg/9VJPhCE" target="_blank">
<i class="fab fa-discord"></i> &nbsp;
<span class="menu-title">Discord</span>
</a>

View File

@ -1,42 +1,13 @@
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link count-indicator" id="notificationDropdown" href="#" data-toggle="dropdown">
<i class="mdi mdi-email-outline"></i>
<span class="count bg-success">3</span>
<i class="fas fa-broadcast-tower
{% if data.get('update_available') %}
text-danger
{% end %}
"></i>
<!-- <span class="count bg-success">3</span>-->
</a>
<div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list pb-0" aria-labelledby="notificationDropdown">
<a class="dropdown-item py-3 border-bottom">
<p class="mb-0 font-weight-medium float-left">You have 4 new notifications </p>
<span class="badge badge-pill badge-primary float-right">View all</span>
</a>
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-alert m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">Application Error</h6>
<p class="font-weight-light small-text mb-0"> Just now </p>
</div>
</a>
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-settings m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">Settings</h6>
<p class="font-weight-light small-text mb-0"> Private message </p>
</div>
</a>
<a class="dropdown-item preview-item py-3">
<div class="preview-thumbnail">
<i class="mdi mdi-airballoon m-auto text-primary"></i>
</div>
<div class="preview-item-content">
<h6 class="preview-subject font-weight-normal mb-1">New user registration</h6>
<p class="font-weight-light small-text mb-0"> 2 days ago </p>
</div>
</a>
</div>
</li>
<li class="nav-item dropdown user-dropdown">
<a class="nav-link dropdown-toggle" id="UserDropdown" href="#" data-toggle="dropdown" aria-expanded="false">
@ -45,11 +16,9 @@
<div class="dropdown-header text-center">
<img class="img-md rounded-circle" src="/static/assets/images/faces-clipart/pic-1.png" alt="Profile image">
<p class="mb-1 mt-3 font-weight-semibold">{{ data['user_data']['username'] }}</p>
<p class="font-weight-light text-muted mb-0">Plan: {{ str(data['user_data']['account_type']).upper() }}</p>
<p class="font-weight-light text-muted mb-0">Role: Admin</p>
</div>
<a class="dropdown-item"><i class="dropdown-item-icon mdi mdi-account-outline text-primary"></i> My Profile <span class="badge badge-pill badge-danger">1</span></a>
<a class="dropdown-item"><i class="dropdown-item-icon mdi mdi-calendar-check-outline text-primary"></i> Activity</a>
<a class="dropdown-item"><i class="dropdown-item-icon mdi mdi-help-circle-outline text-primary"></i> FAQ</a>
<a class="dropdown-item" href="/public/login"><i class="dropdown-item-icon mdi mdi-power text-primary"></i>Sign Out</a>
</div>
</li>

View File

@ -65,8 +65,8 @@
</div>
<div class="wrapper my-auto ml-auto ml-lg-4">
<p class="mb-0 text-success">35 Max (24 H)</p>
<p class="mb-0 text-warning">10 Avg (24 H)</p>
<p class="mb-0 text-success">35 Max</p>
<p class="mb-0 text-warning">10 Avg</p>
</div>
</div>
</div>

View File

@ -103,7 +103,12 @@
</div>
<div class="form-group">
<label for="server_port">Server Port <small class="text-muted ml-1"> - Port crafty should connect to for stats</small> </label>
<label for="server_ip">Server IP <small class="text-muted ml-1"> - IP Crafty should connect to for stats (Try a real ip instead of 127.0.0.1 if you have issues)</small> </label>
<input type="text" class="form-control" name="server_ip" id="server_ip" value="{{ data['server_stats'][0]['server_id']['server_ip'] }}">
</div>
<div class="form-group">
<label for="server_port">Server Port <small class="text-muted ml-1"> - Port Crafty should connect to for stats</small> </label>
<input type="number" class="form-control" name="server_port" id="server_port" value="{{ data['server_stats'][0]['server_id']['server_port'] }}" step="1" max="65566" min="1" >
</div>

View File

@ -75,6 +75,7 @@
<div class="input-group">
<input type="text" class="form-control" id="server_command" name="server_command" placeholder="Enter your server command" autofocus="">
<span class="input-group-btn ml-5">
<input type="hidden" value="" id="last_command"/>
<button id="submit" class="btn btn-sm btn-info" type="button">Send Command</button>
</span>
</div>

View File

@ -8,7 +8,6 @@
"show_errors": true,
"history_max_age": 7,
"stats_update_frequency": 30,
"max_stats_count": 1000,
"delete_default_json": false,
"show_contribute_link": true,
"virtual_terminal_lines": 10,

View File

@ -82,7 +82,9 @@ if __name__ == '__main__':
helper.create_session_file(ignore=args.ignore)
# do our installer stuff
if not installer.is_fresh_install():
fresh_install = installer.is_fresh_install()
if fresh_install:
installer.create_tables()
installer.default_settings()