diff options
Diffstat (limited to 'cgi-bin')
-rwxr-xr-x | cgi-bin/get.py | 131 | ||||
-rwxr-xr-x | cgi-bin/hostname.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_failed_system.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_failed_user.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_status_system.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_status_user.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_timers_system.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/systemctl_timers_user.sh | 8 | ||||
-rwxr-xr-x | cgi-bin/top.sh | 8 |
9 files changed, 131 insertions, 64 deletions
diff --git a/cgi-bin/get.py b/cgi-bin/get.py new file mode 100755 index 0000000..99c4569 --- /dev/null +++ b/cgi-bin/get.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 + +import cgi, cgitb +import json +import os +import socket +import subprocess +from subprocess import PIPE, STDOUT + + +def headers(): + print("Content-Type: text/html; charset=utf-8") + print() + + +def debugging(): + # TODO: figure out how to include this on the web page + #cgitb.enable() + pass + + +def setup(): + headers() + debugging() + + +def format_response(response): + return json.dumps(response, ensure_ascii=False) + + +def run(*args, **kwargs): + output = subprocess.run(args, stdout=PIPE, stderr=STDOUT, universal_newlines=True, **kwargs) + return output.stdout + + +def hostname(): + return socket.gethostname() + + +def top(): + return run('top', '-b', '-n', '1', '-w', '512') + + +systemd_env = os.environ.copy() +systemd_env['SYSTEMD_PAGER'] = '' +systemd_env['SYSTEMD_COLORS'] = 'no' + + +def run_systemd_command(*args): + return run(*args, env=systemd_env) + + +def run_systemctl(*args): + return run_systemd_command('systemctl', *args) + + +def system_status_overview(): + return run_systemctl('--system', 'status', '--full') + + +def system_status_failed(): + return run_systemctl('--system', 'list-units', '--failed', '--full') + + +def user_status_overview(): + return run_systemctl('--user', 'status', '--full') + + +def user_status_failed(): + return run_systemctl('--user', 'list-units', '--failed', '--full') + + +def system_timers(): + return run_systemctl('--system', 'list-timers', '--all', '--full') + + +def user_timers(): + return run_systemctl('--user', 'list-timers', '--all', '--full') + + +def status(): + status = { + 'hostname': hostname(), + 'top': top(), + 'system': { + 'overview': system_status_overview(), + 'failed': system_status_failed(), + 'timers': system_timers(), + }, + 'user': { + 'overview': user_status_overview(), + 'failed': user_status_failed(), + 'timers': user_timers(), + }, + } + return status + + +def timers(): + timers = { + 'system': { + 'timers': system_timers(), + }, + 'user': { + 'timers': user_timers(), + }, + } + return timers + + +def do(): + params = cgi.FieldStorage() + what = params['what'].value + if what == 'status': + response = status() + elif what == 'timers': + response = timers() + elif what == 'top': + response = top() + else: + raise RuntimeError(f'invalid parameter "what": {what}') + print(format_response(response)) + + +def main(): + setup() + do() + + +if __name__ == '__main__': + main() diff --git a/cgi-bin/hostname.sh b/cgi-bin/hostname.sh deleted file mode 100755 index 38b7700..0000000 --- a/cgi-bin/hostname.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: plain/text; charset=utf-8' -echo - -hostname diff --git a/cgi-bin/systemctl_failed_system.sh b/cgi-bin/systemctl_failed_system.sh deleted file mode 100755 index 39d3fc1..0000000 --- a/cgi-bin/systemctl_failed_system.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl list-units --failed --no-pager --full diff --git a/cgi-bin/systemctl_failed_user.sh b/cgi-bin/systemctl_failed_user.sh deleted file mode 100755 index fe9ddc0..0000000 --- a/cgi-bin/systemctl_failed_user.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl --user list-units --failed --no-pager --full diff --git a/cgi-bin/systemctl_status_system.sh b/cgi-bin/systemctl_status_system.sh deleted file mode 100755 index 119b2e2..0000000 --- a/cgi-bin/systemctl_status_system.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl --system status --no-pager --full diff --git a/cgi-bin/systemctl_status_user.sh b/cgi-bin/systemctl_status_user.sh deleted file mode 100755 index 7ba1dd3..0000000 --- a/cgi-bin/systemctl_status_user.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl --user status --no-pager --full diff --git a/cgi-bin/systemctl_timers_system.sh b/cgi-bin/systemctl_timers_system.sh deleted file mode 100755 index 3c93d8b..0000000 --- a/cgi-bin/systemctl_timers_system.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl --system list-timers --all --no-pager --full diff --git a/cgi-bin/systemctl_timers_user.sh b/cgi-bin/systemctl_timers_user.sh deleted file mode 100755 index c8b0a95..0000000 --- a/cgi-bin/systemctl_timers_user.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -SYSTEMD_COLORS=no systemctl --user list-timers --all --no-pager --full diff --git a/cgi-bin/top.sh b/cgi-bin/top.sh deleted file mode 100755 index 9edf850..0000000 --- a/cgi-bin/top.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -echo 'Content-Type: text/plain; charset=utf-8' -echo - -top -b -n 1 -w 512 |