From 9257e15f5ec6d8029bd98361f23535aa333850b8 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 27 Feb 2021 16:00:11 +0300 Subject: Python server can now be run as root If run as root, the server queries all the users. --- index.html | 150 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 102 insertions(+), 48 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index 2d8639a..1650330 100644 --- a/index.html +++ b/index.html @@ -35,38 +35,25 @@ h1, .h1 {

           
           
-

systemctl --system list-units --failed

-
-

+          

systemctl --system list-units --failed

+
+

           

-

systemctl --user list-units --failed

-
-

+          

systemctl --system status

+
+

           

-

systemctl --system status

-
-

-          
-
-

systemctl --user status

-
-

-          
-
-

systemctl --system list-timers --all refreshed every - seconds

-
-

-          
-
-

systemctl --user list-timers --all refreshed every - seconds

-
-

+          

systemctl --system list-timers --all refreshed every - seconds

+
+

           

+
+
@@ -79,32 +66,18 @@ function shutdown() { $.get('cgi-bin/poweroff.sh'); } -function refresh_top() { - $.get('cgi-bin/get.py?what=top', function(data) { - $('#top').text(JSON.parse(data)); - }); +function set_hostname(data) { + $('#hostname').text(data); + $('title').text(data); } -function refresh_timers() { - $.get('cgi-bin/get.py?what=timers', function(data) { - data = JSON.parse(data); - $('#systemctl_timers_system').text(data['system']['timers']); - $('#systemctl_timers_user').text(data['user']['timers']); - }); +function set_top(data) { + $('#top').text(data); } -function refresh_status() { - $.get('cgi-bin/get.py?what=status', function(data) { - data = JSON.parse(data); - $('#hostname').text(data['hostname']); - $('title').text(data['hostname']); - $('#top').text(data['top']); - $('#systemctl_failed_system').text(data['system']['failed']); - $('#systemctl_failed_user').text(data['user']['failed']); - $('#systemctl_status_system').text(data['system']['overview']); - $('#systemctl_status_user').text(data['user']['overview']); - $('#systemctl_timers_system').text(data['system']['timers']); - $('#systemctl_timers_user').text(data['user']['timers']); +function refresh_top() { + $.get('cgi-bin/get.sh?what=top', function(data) { + set_top(JSON.parse(data)); }); } @@ -115,14 +88,95 @@ function loop_top() { $('#top_refresh_interval').text(top_refresh_interval_seconds); } +function set_system(data) { + if ('failed' in data) { + $('#failed_system').text(data['failed']); + } + if ('overview' in data) { + $('#overview_system').text(data['overview']); + } + if ('timers' in data) { + $('#timers_system').text(data['timers']); + } +} + +var users = []; + +function add_user(name) { + if (users.includes(name)) { + return; + } + let text = ` +
+
+

${name}

+
+

systemctl --user list-units --failed

+
+

+    
+
+

systemctl --user status

+
+

+    
+
+

systemctl --user list-timers --all refreshed every ${timers_refresh_interval_seconds} seconds

+
+

+    
+
+
+
+`; + $('#users').append(text); + users.push(name); +} + +function set_user(name, data) { + add_user(name); + if ('failed' in data) { + $('#failed_user_' + name).text(data['failed']); + } + if ('overview' in data) { + $('#overview_user_' + name).text(data['overview']); + } + if ('timers' in data) { + $('#timers_user_' + name).text(data['timers']); + } +} + +function set_users(data) { + Object.keys(data).forEach(function(name) { + set_user(name, data[name]); + }); +} + +function refresh_status() { + $.get('cgi-bin/get.sh?what=status', function(data) { + data = JSON.parse(data); + set_top(data['top']); + set_hostname(data['hostname']); + set_system(data['system']); + set_users(data['user']); + }); +} + +function refresh_timers() { + $.get('cgi-bin/get.sh?what=timers', function(data) { + data = JSON.parse(data); + set_system(data['system']); + set_users(data['user']); + }); +} + var timers_refresh_interval_seconds = 30; function loop_timers() { setInterval(function() { refresh_timers(); }, timers_refresh_interval_seconds * 1000); - $('#systemctl_timers_system_refresh_interval').text(timers_refresh_interval_seconds); - $('#systemctl_timers_user_refresh_interval').text(timers_refresh_interval_seconds); + $('#timers_system_refresh_interval').text(timers_refresh_interval_seconds); } function loop() { -- cgit v1.2.3