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 @@
-
-
-
You have used % of your disk
+
+
@@ -19,6 +21,9 @@
--
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 %} +