mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Make monitored mount points user configurable
This commit is contained in:
parent
a6d1f7b62c
commit
f381562b3b
@ -417,6 +417,7 @@ class Helpers:
|
||||
"allow_nsfw_profile_pictures": False,
|
||||
"enable_user_self_delete": False,
|
||||
"reset_secrets_on_next_boot": False,
|
||||
"monitored_mounts": [],
|
||||
}
|
||||
|
||||
def get_all_settings(self):
|
||||
|
@ -702,6 +702,7 @@ class TasksManager:
|
||||
"disk_usage": json.loads(
|
||||
host_stats.get("disk_json").replace("'", '"')
|
||||
),
|
||||
"mounts": self.helper.get_setting("monitored_mounts"),
|
||||
},
|
||||
)
|
||||
except:
|
||||
|
@ -12,6 +12,7 @@ import bleach
|
||||
import requests
|
||||
import tornado.web
|
||||
import tornado.escape
|
||||
import psutil
|
||||
from tornado import iostream
|
||||
|
||||
# TZLocal is set as a hidden import on win pipeline
|
||||
@ -293,6 +294,7 @@ class PanelHandler(BaseHandler):
|
||||
"background": self.controller.cached_login,
|
||||
"login_opacity": self.controller.management.get_login_opacity(),
|
||||
"serverTZ": tz,
|
||||
"monitored": self.helper.get_setting("monitored_mounts"),
|
||||
"version_data": self.helper.get_version_string(),
|
||||
"failed_servers": self.controller.servers.failed_servers,
|
||||
"user_data": exec_user,
|
||||
@ -885,6 +887,9 @@ class PanelHandler(BaseHandler):
|
||||
page_data["config-json"] = data
|
||||
page_data["availables_languages"] = []
|
||||
page_data["all_languages"] = []
|
||||
page_data["all_partitions"] = []
|
||||
for item in psutil.disk_partitions(all=False):
|
||||
page_data["all_partitions"].append(item.mountpoint)
|
||||
|
||||
for file in sorted(
|
||||
os.listdir(
|
||||
|
@ -6,7 +6,8 @@
|
||||
{% block title %}Crafty Controller - {{ translate('panelConfig', 'pageTitle', data['lang']) }}{% end %}
|
||||
|
||||
{% block content %}
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.10/css/bootstrap-select.min.css">
|
||||
<link rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.10/css/bootstrap-select.min.css">
|
||||
|
||||
|
||||
<div class="content-wrapper">
|
||||
@ -50,62 +51,87 @@
|
||||
{% for item in data['config-json'].items() %}
|
||||
{% if item[0] == "reset_secrets_on_next_boot" %}
|
||||
<div class="form-group" style="background: rgba(243, 21, 6, 0.3); outline: 1px solid red; padding: 10px;">
|
||||
{% else %}
|
||||
<div class="form-group">
|
||||
{% end %}
|
||||
<label class="form" for="{{item[0]}}">{{item[0]}}
|
||||
<small class="text-muted ml-1">
|
||||
</small> </label><br />
|
||||
{% if item[0] == 'language' %}
|
||||
<select name="{{item[0]}}" class="form-control">
|
||||
{% for lang in data['availables_languages'] %}
|
||||
{% if lang == item[1] %}
|
||||
<option selected>{{lang}}</option>
|
||||
{% else %}
|
||||
<option>{{lang}}</option>
|
||||
{% else %}
|
||||
<div class="form-group">
|
||||
{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
{% elif item[0] == 'disabled_language_files' %}
|
||||
<div class="input-group">
|
||||
<button type="button" class="btn btn-outline-default custom-picker" onclick="$('option', $('#lang_select')).each(function(element) {
|
||||
$(this).removeAttr('selected').prop('selected', false); $('.selectpicker').selectpicker('refresh')
|
||||
});">Enable all Languages</button>
|
||||
<select id="lang_select" class="form-control selectpicker show-tick" data-icon-base="fas" data-tick-icon="fa-check" multiple data-style="custom-picker">
|
||||
{% for lang in data['all_languages'] %}
|
||||
{% if lang in item[1] %}
|
||||
<label class="form" for="{{item[0]}}">{{item[0]}}
|
||||
<small class="text-muted ml-1">
|
||||
</small> </label><br />
|
||||
{% if item[0] == 'language' %}
|
||||
<select name="{{item[0]}}" class="form-control">
|
||||
{% for lang in data['availables_languages'] %}
|
||||
{% if lang == item[1] %}
|
||||
<option selected>{{lang}}</option>
|
||||
{% else %}
|
||||
<option>{{lang}}</option>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
<textarea id="disabled_lang" name="{{item[0]}}" class="form-control list hidden" rows="{{ len(data['all_languages']) }}" value="{{','.join(item[1])}}" hidden>{{','.join(item[1])}}</textarea>
|
||||
{% elif item[0] == 'disabled_language_files' %}
|
||||
<div class="input-group">
|
||||
<button type="button" class="btn btn-outline-default custom-picker" onclick="$('option', $('#lang_select')).each(function(element) {
|
||||
$(this).removeAttr('selected').prop('selected', false); $('.selectpicker').selectpicker('refresh')
|
||||
});">Enable all Languages</button>
|
||||
<select id="lang_select" class="form-control selectpicker show-tick" data-icon-base="fas"
|
||||
data-tick-icon="fa-check" multiple data-style="custom-picker">
|
||||
{% for lang in data['all_languages'] %}
|
||||
{% if lang in item[1] %}
|
||||
<option selected>{{lang}}</option>
|
||||
{% else %}
|
||||
<option>{{lang}}</option>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
<textarea id="disabled_lang" name="{{item[0]}}" class="form-control list hidden"
|
||||
rows="{{ len(data['all_languages']) }}" value="{{','.join(item[1])}}"
|
||||
hidden>{{','.join(item[1])}}</textarea>
|
||||
</div>
|
||||
{% elif item[0] == 'monitored_mounts'%}
|
||||
<div class="input-group">
|
||||
<button type="button" class="btn btn-outline-default custom-picker" onclick="$('option', $('#mount_select')).each(function(element) {
|
||||
$(this).removeAttr('selected').prop('selected', false); $('.selectpicker').selectpicker('refresh')
|
||||
});">Disable All Mounts</button>
|
||||
<select id="mount_select" class="form-control selectpicker show-tick" data-icon-base="fas"
|
||||
data-tick-icon="fa-check" multiple data-style="custom-picker">
|
||||
{% for mount in data['all_partitions'] %}
|
||||
{% if mount in item[1] %}
|
||||
<option selected>{{mount}}</option>
|
||||
{% else %}
|
||||
<option>{{mount}}</option>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
<textarea id="monitored_mounts" name="{{item[0]}}" class="form-control list hidden"
|
||||
rows="{{ len(data['all_partitions']) }}" value="{{','.join(item[1])}}"
|
||||
hidden>{{','.join(item[1])}}</textarea>
|
||||
</div>
|
||||
{% elif isinstance(item[1], list) %}
|
||||
<textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}"
|
||||
class="form-control list">{{','.join(item[1])}}</textarea>
|
||||
{% elif isinstance(item[1], bool) %}
|
||||
<div style="margin-left: 30px;">
|
||||
{% if item[1] == True %}
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked>
|
||||
<label for="True">True</label><br>
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False">
|
||||
<label for="False">False</label>
|
||||
{% else %}
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True">
|
||||
<label for="True">True</label><br>
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False" checked>
|
||||
<label for="False">False</label>
|
||||
{% end %}
|
||||
</div>
|
||||
{% elif isinstance(item[1], int) %}
|
||||
<input type="number" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}"
|
||||
step="1" min="0" required>
|
||||
{% else %}
|
||||
<input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}"
|
||||
step="2" min="0" required>
|
||||
{% end %}
|
||||
</div>
|
||||
{% elif isinstance(item[1], list) %}
|
||||
<textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}" class="form-control list">{{','.join(item[1])}}</textarea>
|
||||
{% elif isinstance(item[1], bool) %}
|
||||
<div style="margin-left: 30px;">
|
||||
{% if item[1] == True %}
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True" checked>
|
||||
<label for="True">True</label><br>
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False">
|
||||
<label for="False">False</label>
|
||||
{% else %}
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="True" value="True">
|
||||
<label for="True">True</label><br>
|
||||
<input type="radio" class="form-check-input" name="{{item[0]}}" id="False" value="False" checked>
|
||||
<label for="False">False</label>
|
||||
{% end %}
|
||||
</div>
|
||||
{% elif isinstance(item[1], int) %}
|
||||
<input type="number" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="1" min="0" required>
|
||||
{% else %}
|
||||
<input type="text" class="form-control" name="{{item[0]}}" id="{{item[0]}}" value="{{ item[1] }}" step="2" min="0" required>
|
||||
{% end %}
|
||||
</div>
|
||||
{% end %}
|
||||
<button class="btn btn-success" type="submit">Submit</button> <span id="submit-status"></span>
|
||||
<button class="btn btn-success" type="submit">Submit</button> <span id="submit-status"></span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@ -153,6 +179,9 @@
|
||||
let selected_Lang = $('#lang_select').val();
|
||||
$('#disabled_lang').val(selected_Lang);
|
||||
|
||||
let mounts = $('#mount_select').val();
|
||||
$('#monitored_mounts').val(mounts);
|
||||
|
||||
let class_list = document.getElementsByClassName("list");
|
||||
let form_json = convertFormToJSON($("#config-form"));
|
||||
for (let i = 0; i < class_list.length; i++) {
|
||||
|
@ -109,6 +109,7 @@
|
||||
<div id="storage_data">
|
||||
<ul style="width: 100%; list-style: none;">
|
||||
{% for item in data.get('hosts_data').get('disk_json') %}
|
||||
{% if item["mount"] in data["monitored"] %}
|
||||
<li id="{{item['device']}}">
|
||||
<h6 style="display: inline-block;">{{item["mount"]}}</h6>
|
||||
<div class="progress"
|
||||
@ -128,6 +129,7 @@
|
||||
|
||||
</li>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -926,24 +928,26 @@
|
||||
|
||||
var storage_html = '<ul style="width: 100%; list-style: none;">';
|
||||
for (i = 0; i < hostStats.disk_usage.length; i++) {
|
||||
storage_html += `<li id="${hostStats.disk_usage[i].device}">
|
||||
if (hostStats.mounts.includes(hostStats.disk_usage[i].mount)) {
|
||||
storage_html += `<li id="${hostStats.disk_usage[i].device}">
|
||||
<h6 style="display: inline-block;">${hostStats.disk_usage[i].mount}</h6>
|
||||
<div class="progress"
|
||||
style="display: inline-block; height: 20%; width: 70%; background-color: rgb(139, 139, 139) !important;"><div class="progress-bar`;
|
||||
|
||||
if (hostStats.disk_usage[i].percent_used <= 33) {
|
||||
storage_html += ` bg-success`;
|
||||
} else if (hostStats.disk_usage[i].percent_used <= 75 && hostStats.disk_usage[i].percent_used >= 34) {
|
||||
storage_html += ` bg-warning`;
|
||||
} else {
|
||||
storage_html += ` bg-danger`;
|
||||
}
|
||||
storage_html += `" role="progressbar" style="color: black; height: 100%; width: ${hostStats.disk_usage[i].percent_used}%;"
|
||||
if (hostStats.disk_usage[i].percent_used <= 33) {
|
||||
storage_html += ` bg-success`;
|
||||
} else if (hostStats.disk_usage[i].percent_used <= 75 && hostStats.disk_usage[i].percent_used >= 34) {
|
||||
storage_html += ` bg-warning`;
|
||||
} else {
|
||||
storage_html += ` bg-danger`;
|
||||
}
|
||||
storage_html += `" role="progressbar" style="color: black; height: 100%; width: ${hostStats.disk_usage[i].percent_used}%;"
|
||||
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">${hostStats.disk_usage[i].used} / ${hostStats.disk_usage[i].total}
|
||||
</div>
|
||||
</div >
|
||||
|
||||
</li >`;
|
||||
}
|
||||
}
|
||||
storage_html += `</ul>`;
|
||||
$("#storage_data").html(storage_html);
|
||||
|
Loading…
Reference in New Issue
Block a user