add poweroff and reboot functions
This commit is contained in:
30
client/power/poweroff.go
Normal file
30
client/power/poweroff.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package power
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os/exec"
|
||||
|
||||
"git.dubyatp.xyz/orphanage/client/httputil"
|
||||
)
|
||||
|
||||
func PowerOffResponse(success bool) PowerActionResponse {
|
||||
resp := PowerActionResponse{
|
||||
APIVersion: APIVersion,
|
||||
Action: "poweroff",
|
||||
Success: success,
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func PowerOff(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
cmd := exec.Command("systemctl", "poweroff")
|
||||
err := cmd.Run()
|
||||
|
||||
if err != nil {
|
||||
httputil.WriteJSON(w, http.StatusOK, PowerOffResponse(false))
|
||||
} else {
|
||||
httputil.WriteJSON(w, http.StatusOK, PowerOffResponse(true))
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user