From 923e2fce6df64b6fd2e203027f2cf216108cb24d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 3 Mar 2021 23:16:36 +0300 Subject: merge {reboot,poweroff}.sh into get.py --- cgi-bin/get.py | 28 ++++++++++++++++++++++++++++ cgi-bin/poweroff.sh | 5 ----- cgi-bin/reboot.sh | 5 ----- index.html | 4 ++-- 4 files changed, 30 insertions(+), 12 deletions(-) delete mode 100755 cgi-bin/poweroff.sh delete mode 100755 cgi-bin/reboot.sh diff --git a/cgi-bin/get.py b/cgi-bin/get.py index 1453dc2..e852561 100755 --- a/cgi-bin/get.py +++ b/cgi-bin/get.py @@ -173,6 +173,28 @@ class TopTask(Task): return self.task.result() +class RebootTask(Task): + def __init__(self): + self.cmd = Command('systemctl', 'reboot') + + def run(self): + self.task = self.cmd.run() + + def result(self): + return self.task.result() + + +class PoweroffTask(Task): + def __init__(self): + self.cmd = Command('systemctl', 'poweroff') + + def run(self): + self.task = self.cmd.run() + + def result(self): + return self.task.result() + + class InstanceStatusTask(Task): def __init__(self, systemctl): self.overview_cmd = systemctl('status') @@ -342,6 +364,8 @@ class Request(Enum): STATUS = 'status' TIMERS = 'timers' TOP = 'top' + REBOOT = 'reboot' + POWEROFF = 'poweroff' def __str__(self): return self.value @@ -359,6 +383,10 @@ class Request(Enum): return TimersTask().complete() if self is Request.TOP: return TopTask().complete() + if self is Request.REBOOT: + return RebootTask().complete() + if self is Request.POWEROFF: + return PoweroffTask().complete() raise NotImplementedError(f'unknown request: {self}') diff --git a/cgi-bin/poweroff.sh b/cgi-bin/poweroff.sh deleted file mode 100755 index d0df856..0000000 --- a/cgi-bin/poweroff.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -systemctl poweroff diff --git a/cgi-bin/reboot.sh b/cgi-bin/reboot.sh deleted file mode 100755 index b8bb350..0000000 --- a/cgi-bin/reboot.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -systemctl reboot diff --git a/index.html b/index.html index 35d118e..7c8f487 100644 --- a/index.html +++ b/index.html @@ -59,11 +59,11 @@ h1, .h1 {