commit 82418944c5a0d066d9d524f4ade0e03bd1c01269 Author: Peter Ludikovsky Date: Thu Nov 29 19:50:26 2018 +0100 Inital commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..802676e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# spacestatus + +A simple `bash` script to display the open/close status of `/usr/space`. + +Depends on: +- `isc-dhcp-server` +- `arping` diff --git a/spacestatus.json b/spacestatus.json new file mode 100644 index 0000000..d70bb99 --- /dev/null +++ b/spacestatus.json @@ -0,0 +1 @@ +{"api":"0.13","space":"/usr/space","logo":"","url":"https://usrspace.at","location":{"lat":47.92305,"lon":16.21173,"address":"Mühlgasse 8, 2544 Leobersdorf, Austria"},"state":{"open":%s},"contact":{"twitter":"@usrspace_at","email":"kernel AT usrspace.at","facebook":"https://facebook.com/usrspace.at","keymasters":[{"name":"Peter","twitter":"@pludikovsky"}]},"issue_report_channels":["email","twitter"],"feeds":{"calendar":{"type":"ical","url":"https://usrspace.at/termine.ics"}},"cache":{"schedule":"m.05"},"projects":["https://gitlab.usrspace.at/","https://www.usrspace.at/w/index.php?title=Kategorie:Projekte"]} diff --git a/spacestatus.sh b/spacestatus.sh new file mode 100755 index 0000000..0bb15cf --- /dev/null +++ b/spacestatus.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +[ ! -z "$DEBUG" ] && set -x + +set -eu + +function write_html { + status=$1 + STATUS_HTML=/srv/www/spacestatus.html + TEMPLATE_HTML='Status /usr/space: %s

%s

' + CLOSED_HTML='Closed darkred Closed' + OPEN_HTML='Open brightgreen Open' + + if [ "$status" -gt 0 ] + then + printf "$TEMPLATE_HTML" $OPEN_HTML > $STATUS_HTML + else + printf "$TEMPLATE_HTML" $CLOSED_HTML > $STATUS_HTML + fi +} + +function write_json { + status=$1 + STATUS_JSON=/srv/www/spacestatus.json + TEMPLATE_JSON=$( cat /usr/local/etc/spacestatus.json ) + CLOSED_JSON='false' + OPEN_JSON='true' + + if [ "$status" -gt 0 ] + then + printf "$TEMPLATE_JSON" $OPEN_JSON > $STATUS_JSON + else + printf "$TEMPLATE_JSON" $CLOSED_JSON > $STATUS_JSON + fi +} + +tmpcount=$(mktemp) +exec 3>$tmpcount +/usr/sbin/dhcp-lease-list --parsable | awk '{print $4}' | while read ip +do + /usr/bin/arping -w 1 -f -q $ip + [ $? -eq 0 ] && echo 1 >&3 +done + +exec 3>&- + +leases=$( cat $tmpcount | wc -l ) + +write_html $leases +write_json $leases + +rm $tmpcount