Skip to content

Commit

Permalink
Hook up its rc service
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Oct 29, 2023
1 parent 0b553ad commit 70a6c0c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion sysop/client
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh

socat - udp:localhost:5557 <<< "shutdown:$(<shutdown.pre)"
CMD=${1-shutdown}
socat - udp:localhost:5557 <<< "$CMD:$(<$CMD.pre)"
1 change: 1 addition & 0 deletions sysop/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
useradd -d /var/empty -s /sbin/nologin sysop
19 changes: 14 additions & 5 deletions sysop/openbsd.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
app = "sysop"

[[site.patch.doas.files]]
lines = [ "permit nopass :wheel" ]
lines = [
"permit nopass :wheel",
"permit nopass sysop as root cmd /usr/bin/nc args -ulkd 0.0.0.0 557",
"permit nopass sysop as root cmd /sbin/shutdown",
]
mode = 0o400
dst = "/etc/doas.conf"

[site.patch.sysop]
service = "sysop"
install = "install"

[[site.patch.sysop.files]]
src = "server"
mode = 0o755
Expand All @@ -14,14 +22,15 @@ dst = "/usr/local/bin/sysop"
src = "shutdown.cmd"
dst = "/var/sysop/commands/shutdown"

[[site.patch.sysop.files]]
src = "shutdown.cmd"
dst = "/var/sysop/commands/shutdown"

[[site.patch.sysop.files]]
src = "shutdown.tok"
dst = "/var/sysop/tokens/shutdown"

[[site.patch.sysop.files]]
src = "service"
mode = 0o755
dst = "/etc/rc.d/sysop"

[[run.hostfwd.udp]]
hport = 5557
gport = 557
4 changes: 2 additions & 2 deletions sysop/server
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ PORT=557
ADDR=0.0.0.0

log() {
logger -ct sysop -f-
logger -ct sysop
}

ROOT=/var/sysop
TOKENS=$ROOT/tokens
COMMANDS=$ROOT/commands

echo "listening udp:$ADDR:$PORT" | log
doas nc -ulkd "$ADDR" "$PORT" | while IFS=: read CMD TOKEN; do
doas "$(which /usr/bin/nc)" -ulkd "$ADDR" "$PORT" | while IFS=: read CMD TOKEN; do
if [ ! -f "$TOKENS/$CMD" ] || [ ! -f "$COMMANDS/$CMD" ]; then
echo "unknown command: $CMD" | log
continue
Expand Down
9 changes: 9 additions & 0 deletions sysop/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/ksh

daemon="/usr/local/bin/sysop"
daemon_user=sysop
rc_bg=YES

. /etc/rc.d/rc.subr

rc_cmd $1
2 changes: 1 addition & 1 deletion sysop/shutdown.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
doas shutdown -p now
doas /sbin/shutdown -p now

0 comments on commit 70a6c0c

Please sign in to comment.