diff --git a/core/util.py b/core/util.py index 849f5ba..bc7ad6b 100644 --- a/core/util.py +++ b/core/util.py @@ -40,6 +40,23 @@ def get_default_interface(): continue return fields[0] +def get_mounts(): + mounts = [] + with open("/proc/mounts") as mount: + for line in mount: + fields = line.strip().split() + if fields[0].startswith("/dev"): + if ("boot" in fields[1]) or ("fuse" in fields): + continue + else: + mounts.append(fields[1]) + with open("/etc/fstab") as fstab: + for line in fstab: + fields = line.strip().split() + if "bind" in str(fields): + mounts.remove(fields[1]) + return mounts + def generate_page_list(user): admin_user = current_app.config['ADMIN_USER'] pages = [] diff --git a/static/css/swizzin.css b/static/css/swizzin.css index b5046c6..8637ae8 100644 --- a/static/css/swizzin.css +++ b/static/css/swizzin.css @@ -2,6 +2,29 @@ margin-bottom: 0; } +.progress { + margin-bottom: 5px; +} + +#diskinfo a.collapsed:after { + content: '+ Show More'; +} + +#diskinfo a:not(.collapsed):after { + content: '- Show Less'; +} + +#diskglances a.collapsed:after { + content: '+ Show More'; + display: inline-block; + width: 100%; + text-align: right; +} + +#diskglances a:not(.collapsed):after { + content: '- Show Less'; +} + a[post=true] { cursor: pointer; } diff --git a/swizzin.py b/swizzin.py index d8e6fc9..5f58c72 100755 --- a/swizzin.py +++ b/swizzin.py @@ -104,7 +104,12 @@ def index(user): # thread = Thread(target=current_speed) # thread.start() pages = generate_page_list(user) - return flask.render_template('index.html', title='{user} - swizzin dashboard'.format(user=user), user=user, pages=pages, async_mode=socketio.async_mode) + mounts = get_mounts() + if os.path.isfile("/install/.quota.lock"): + quota = True + else: + quota = False + return flask.render_template('index.html', title='{user} - swizzin dashboard'.format(user=user), user=user, pages=pages, quota=quota, mounts=mounts, async_mode=socketio.async_mode) @socketio.on('connect', namespace='/websocket') def socket_connect(): @@ -228,12 +233,21 @@ def vnstat(user): @app.route('/stats/disk') @htpasswd.required def disk_free(user): - location = "/" + mounts = get_mounts() + data = {} + for mount in mounts: + total, used, free, usage = disk_usage(mount) + data[mount] = {"disktotal": total, "diskused": used, "diskfree": free, "perutil": usage} + return flask.jsonify(data) + +@app.route('/stats/quota') +@htpasswd.required +def quota_free(user): if os.path.isfile("/install/.quota.lock"): total, used, free, usage = quota_usage(user) + return flask.jsonify({"quota": {"disktotal": total, "diskused": used, "diskfree": free, "perutil": usage}}) else: - total, used, free, usage = disk_usage(location) - return flask.jsonify({"disktotal": total, "diskused": used, "diskfree": free, "perutil": usage}) + return """Quota not installed""" @app.route('/stats/boot') @htpasswd.required diff --git a/templates/diskinfo.html b/templates/diskinfo.html index 8e20b84..e5b9fed 100644 --- a/templates/diskinfo.html +++ b/templates/diskinfo.html @@ -1,23 +1,6 @@
Disk Info
-
-
-
-
Used
-

-
-
-
Free
-

-
-
-
Total
-

-
-
-
-
-
-

You have used % of your disk

+
+ {{macros.build_disk_info(mounts=mounts)}}
\ No newline at end of file diff --git a/templates/glance.html b/templates/glance.html index 6d368e9..a93d52b 100644 --- a/templates/glance.html +++ b/templates/glance.html @@ -6,10 +6,12 @@
Load

+ {% if quota == True %}
Disk
-

+

+ {% endif %}
RAM

@@ -19,6 +21,9 @@

--

+ {% if (quota == False or config.ADMIN_USER == user) %} + {{macros.build_disk_glances(mounts=mounts)}} + {% endif %}
Uptime

diff --git a/templates/index.html b/templates/index.html index 3f85dc7..3eb1fb3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,7 +22,12 @@ {% include 'glance.html' %} {{ macros.build_app_table(apps=pages) }} {% include 'systeminfo.html' %} - {% include 'diskinfo.html' %} + {% if quota == True %} + {% include 'quotainfo.html' %} + {% endif %} + {% if (quota == False or config.ADMIN_USER == user) %} + {% include 'diskinfo.html' %} + {% endif %} {% include 'raminfo.html' %} {% if (config.SHAREDSERVER == True or config.ADMIN_USER == user) %} {% include 'netinfo.html' %} @@ -46,6 +51,29 @@ {{ macros.build_widget_js_shared() }} {% endif %} +{% if quota == True %} +(function quotausage() { + $.get('{{ url_for('quota_free') }}', function(data) { + var percent = Math.trunc(data["quota"]['perutil']); + $("#quotafree").html(data["quota"]['diskfree']); + $("#quotaused").html(data["quota"]['diskused']); + $("#quotatotal").html(data["quota"]['disktotal']); + $("#quotapercent").html(data["quota"]['perutil']); + if (Number(data["quota"]['perutil']) > 90) { + $("#quotaindicator.systemindicator").addClass("bg-danger").removeClass("bg-success bg-warning"); + $("#quotaprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-danger").removeClass("bg-success bg-warning"); + } else if (Number(data["quota"]['perutil']) > 75) { + $("#quotaindicator.systemindicator").addClass("bg-warning").removeClass("bg-success bg-danger"); + $("#quotaprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-warning").removeClass("bg-success bg-danger"); + } else { + $("#quotaindicator.systemindicator").addClass("bg-success").removeClass("bg-warning bg-danger"); + $("#quotaprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-success").removeClass("bg-danger bg-warning"); + } + setTimeout(function(){quotausage()}, 60000); + }); +})(); +{% endif %} + diff --git a/templates/macros.html b/templates/macros.html index 912f46b..4a3703e 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -133,7 +133,119 @@

{% endmacro %} +{% macro build_disk_info(mounts) %} + + + + + + + + + + {% for mount in mounts %} + + + + + + + + + + + + + + + + {% if (loop.index == 3 and not loop.last) %} +
MountUsedFreeTotal
{{ mount }}
%
+ + {% endif %} + {% if loop.last %} + + {% if loop.index > 3 %} + + {% endif %} + {% endif %} + {% endfor %} +{% endmacro %} + +{% macro build_disk_glances(mounts) %} +
+
+ {% for mount in mounts %} +
+
{{ mount }}
+

+
+ {% if (loop.index == 3 and not loop.last) %} +
+ + {% if loop.index > 3%} + + {% endif %} + {% endif %} + {% endfor %} +
+{% endmacro %} + {% macro build_widget_js() %} +function getdisks() { + $('#diskinfo').html('') + var html =` + + + + + + + + + + ` + $.get('{{ url_for('disk_free') }}', function(data) { + var datalength = $(data).length + var i = 0 + for (var mount in data) { + html += ` + + + + + + + + + + + + + + + + + ` + if (i < $(data).length) { + html += `` + } + i++ + } + html += ` +
MountUsedFreeTotal
`+mount+`
%
+ ` + $('#diskinfo').append(html) + } + ); + + +} +//getdisks() + function appstatus(){ $.get("{{ url_for('app_status') }}", function(data){ for (var apps in data) { @@ -177,24 +289,25 @@ appstatus(); (function diskusage() { $.get('{{ url_for('disk_free') }}', function(data) { - var percent = Math.trunc(data['perutil']); - $("#diskfree").html(data['diskfree']); - $("#diskused").html(data['diskused']); - $("#disktotal").html(data['disktotal']); - $("#diskpercent").html(data['perutil']); - if (Number(data['perutil']) > 90) { - $("#diskindicator.systemindicator").addClass("bg-danger").removeClass("bg-success bg-warning"); - $("#diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-danger").removeClass("bg-success bg-warning"); - } else if (Number(data['perutil']) > 75) { - $("#diskindicator.systemindicator").addClass("bg-warning").removeClass("bg-success bg-danger"); - $("#diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-warning").removeClass("bg-success bg-danger"); - } else { - $("#diskindicator.systemindicator").addClass("bg-success").removeClass("bg-warning bg-danger"); - $("#diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-success").removeClass("bg-danger bg-warning"); - } - setTimeout(function(){diskusage()}, 60000); - } - ); + for (var mount in data) { + var percent = Math.trunc(data[mount]['perutil']); + $("#"+$.escapeSelector(mount)+"diskfree").html(data[mount]['diskfree']); + $("#"+$.escapeSelector(mount)+"diskused").html(data[mount]['diskused']); + $("#"+$.escapeSelector(mount)+"disktotal").html(data[mount]['disktotal']); + $("#"+$.escapeSelector(mount)+"diskpercent").html(data[mount]['perutil']); + if (Number(data[mount]['perutil']) > 90) { + $("#"+$.escapeSelector(mount)+"indicator.systemindicator").addClass("bg-danger").removeClass("bg-success bg-warning"); + $("#"+$.escapeSelector(mount)+"diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-danger").removeClass("bg-success bg-warning"); + } else if (Number(data[mount]['perutil']) > 75) { + $("#"+$.escapeSelector(mount)+"indicator.systemindicator").addClass("bg-warning").removeClass("bg-success bg-danger"); + $("#"+$.escapeSelector(mount)+"diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-warning").removeClass("bg-success bg-danger"); + } else { + $("#"+$.escapeSelector(mount)+"indicator.systemindicator").addClass("bg-success").removeClass("bg-warning bg-danger"); + $("#"+$.escapeSelector(mount)+"diskprogress").css("width", percent + "%").attr("aria-valuenow", percent).addClass("bg-success").removeClass("bg-danger bg-warning"); + } + } + setTimeout(function(){diskusage()}, 60000); + }); })(); (function ramusage() { diff --git a/templates/quotainfo.html b/templates/quotainfo.html new file mode 100644 index 0000000..e43e0ac --- /dev/null +++ b/templates/quotainfo.html @@ -0,0 +1,23 @@ +
+
Disk Quota Info
+
+
+
+
Used
+

+
+
+
Free
+

+
+
+
Total
+

+
+
+
+
+
+

You have used % of your disk quota

+
+
\ No newline at end of file