From 0a380f861e2efa06046cc0c89c3c34bf507768d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 14 Oct 2023 21:37:00 +0200 Subject: [PATCH] Add scn_send.sh to repo --- .../website/scn_send.sh.txt => scn_send.sh | 38 ++++++++++++++++--- scnserver/Makefile | 8 ++-- scnserver/TODO.md | 6 ++- scnserver/api/handler/apiMessage.go | 13 ++++--- scnserver/website/scn_send.html | 38 ++++++++++++++++--- 5 files changed, 79 insertions(+), 24 deletions(-) rename scnserver/website/scn_send.sh.txt => scn_send.sh (82%) diff --git a/scnserver/website/scn_send.sh.txt b/scn_send.sh similarity index 82% rename from scnserver/website/scn_send.sh.txt rename to scn_send.sh index 58897d3..f39545e 100644 --- a/scnserver/website/scn_send.sh.txt +++ b/scn_send.sh @@ -14,13 +14,10 @@ # or scn_send "@${channel} "${title}" ${content}" # or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}" # +# content can be of format "--scnsend-read-body-from-file={path}" to read body from file +# (this circumvents max commandline length) # -################################################################################ -# INSERT YOUR DATA HERE # -################################################################################ -user_id="999" # your user_id -user_key="??" # use userkey with SEND permissions on the used channel ################################################################################ usage() { @@ -34,16 +31,40 @@ function cfgcol { [ -t 1 ] && [ -n "$(tput colors)" ] && [ "$(tput colors)" -ge function rederr() { if cfgcol; then >&2 echo -e "\x1B[31m$1\x1B[0m"; else >&2 echo "$1"; fi; } function green() { if cfgcol; then echo -e "\x1B[32m$1\x1B[0m"; else echo "$1"; fi; } +################################################################################ + +# +# Get env 'SCN_UID' and 'SCN_KEY' from conf file +# +# shellcheck source=/dev/null +. "/etc/scn.conf" +SCN_UID=${SCN_UID:-} +SCN_KEY=${SCN_KEY:-} + +[ -z "${SCN_UID}" ] && { rederr "Missing config value 'SCN_UID' in /etc/scn.conf"; exit 1; } +[ -z "${SCN_KEY}" ] && { rederr "Missing config value 'SCN_KEY' in /etc/scn.conf"; exit 1; } + +################################################################################ + args=( "$@" ) title="" content="" channel="" -priority=1 +priority="" usr_msg_id="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)" sendtime="$(date +%s)" sender="$(hostname)" +if command -v srvname &> /dev/null; then + sender="$( srvname )" +fi + +if [[ "${args[0]}" = "--" ]]; then + # only positional args form here on (currently not handled) + args=("${args[@]:1}") +fi + if [ ${#args[@]} -lt 1 ]; then rederr "[ERROR]: no title supplied via parameter" usage @@ -83,6 +104,11 @@ if [ ${#args[@]} -gt 0 ]; then exit 1 fi +if [[ "$content" == --scnsend-read-body-from-file=* ]]; then + path="$( awk '{ print substr($0, 31) }' <<< "$content" )" + content="$( cat "$path" )" +fi + curlparams=() curlparams+=( "--data-urlencode" "user_id=${SCN_UID}" ) diff --git a/scnserver/Makefile b/scnserver/Makefile index 68a5edb..3acbdd8 100644 --- a/scnserver/Makefile +++ b/scnserver/Makefile @@ -45,10 +45,10 @@ swagger: pygmentize: website/scn_send.html -website/scn_send.html: website/scn_send.sh.txt - _pygments/pygmentizew -l bash -f html "$(shell pwd)/website/scn_send.sh.txt" > "$(shell pwd)/website/scn_send.html" - _pygments/pygmentizew -S monokai -f html > "$(shell pwd)/website/css/pygmnetize-dark.css" - _pygments/pygmentizew -S borland -f html > "$(shell pwd)/website/css/pygmnetize-light.css" +website/scn_send.html: ../scn_send.sh + _pygments/pygmentizew -l bash -f html "$(shell pwd)/../scn_send.sh" > "$(shell pwd)/website/scn_send.html" + _pygments/pygmentizew -S monokai -f html > "$(shell pwd)/website/css/pygmnetize-dark.css" + _pygments/pygmentizew -S borland -f html > "$(shell pwd)/website/css/pygmnetize-light.css" run-docker-local: docker mkdir -p .run-data diff --git a/scnserver/TODO.md b/scnserver/TODO.md index ac167c1..dacc673 100644 --- a/scnserver/TODO.md +++ b/scnserver/TODO.md @@ -10,9 +10,11 @@ - ios purchase verification - - use goext.ginWrapper + - (!) use goext.ginWrapper - - use goext.exerr + - (!) use goext.exerr + + - use bfcodegen (enums+id) #### UNSURE diff --git a/scnserver/api/handler/apiMessage.go b/scnserver/api/handler/apiMessage.go index e5d29fe..b7fdfbc 100644 --- a/scnserver/api/handler/apiMessage.go +++ b/scnserver/api/handler/apiMessage.go @@ -1,18 +1,19 @@ package handler import ( + "database/sql" + "errors" + "net/http" + "strings" + "time" + "blackforestbytes.com/simplecloudnotifier/api/apierr" "blackforestbytes.com/simplecloudnotifier/api/ginresp" ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken" "blackforestbytes.com/simplecloudnotifier/models" - "database/sql" - "errors" "github.com/gin-gonic/gin" "gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/mathext" - "net/http" - "strings" - "time" ) // ListMessages swaggerdoc @@ -174,7 +175,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse { // @Failure 404 {object} ginresp.apiError "message not found" // @Failure 500 {object} ginresp.apiError "internal server error" // -// @Router /api/v2/messages/{mid} [PATCH] +// @Router /api/v2/messages/{mid} [GET] func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse { type uri struct { MessageID models.MessageID `uri:"mid" binding:"entityid"` diff --git a/scnserver/website/scn_send.html b/scnserver/website/scn_send.html index 97c348c..cf58d65 100644 --- a/scnserver/website/scn_send.html +++ b/scnserver/website/scn_send.html @@ -14,13 +14,10 @@ # or scn_send "@${channel} "${title}" ${content}" # or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}" # +# content can be of format "--scnsend-read-body-from-file={path}" to read body from file +# (this circumvents max commandline length) # -################################################################################ -# INSERT YOUR DATA HERE # -################################################################################ -user_id="999" # your user_id -user_key="??" # use userkey with SEND permissions on the used channel ################################################################################ usage() { @@ -34,16 +31,40 @@ usage() { function rederr() { if cfgcol; then >&2 echo -e "\x1B[31m$1\x1B[0m"; else >&2 echo "$1"; fi; } function green() { if cfgcol; then echo -e "\x1B[32m$1\x1B[0m"; else echo "$1"; fi; } +################################################################################ + +# +# Get env 'SCN_UID' and 'SCN_KEY' from conf file +# +# shellcheck source=/dev/null +. "/etc/scn.conf" +SCN_UID=${SCN_UID:-} +SCN_KEY=${SCN_KEY:-} + +[ -z "${SCN_UID}" ] && { rederr "Missing config value 'SCN_UID' in /etc/scn.conf"; exit 1; } +[ -z "${SCN_KEY}" ] && { rederr "Missing config value 'SCN_KEY' in /etc/scn.conf"; exit 1; } + +################################################################################ + args=( "$@" ) title="" content="" channel="" -priority=1 +priority="" usr_msg_id="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)" sendtime="$(date +%s)" sender="$(hostname)" +if command -v srvname &> /dev/null; then + sender="$( srvname )" +fi + +if [[ "${args[0]}" = "--" ]]; then + # only positional args form here on (currently not handled) + args=("${args[@]:1}") +fi + if [ ${#args[@]} -lt 1 ]; then rederr "[ERROR]: no title supplied via parameter" usage @@ -83,6 +104,11 @@ usage() { exit 1 fi +if [[ "$content" == --scnsend-read-body-from-file=* ]]; then + path="$( awk '{ print substr($0, 31) }' <<< "$content" )" + content="$( cat "$path" )" +fi + curlparams=() curlparams+=( "--data-urlencode" "user_id=${SCN_UID}" )