Add scn_send.sh to repo
This commit is contained in:
parent
b712ad3488
commit
0a380f861e
@ -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}" )
|
@ -45,8 +45,8 @@ 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"
|
||||
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"
|
||||
|
||||
|
@ -10,9 +10,11 @@
|
||||
|
||||
- ios purchase verification
|
||||
|
||||
- use goext.ginWrapper
|
||||
- (!) use goext.ginWrapper
|
||||
|
||||
- use goext.exerr
|
||||
- (!) use goext.exerr
|
||||
|
||||
- use bfcodegen (enums+id)
|
||||
|
||||
#### UNSURE
|
||||
|
||||
|
@ -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"`
|
||||
|
@ -14,13 +14,10 @@
|
||||
<span class="c1"># or scn_send "@${channel} "${title}" ${content}"</span>
|
||||
<span class="c1"># or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}"</span>
|
||||
<span class="c1">#</span>
|
||||
<span class="c1"># content can be of format "--scnsend-read-body-from-file={path}" to read body from file</span>
|
||||
<span class="c1"># (this circumvents max commandline length)</span>
|
||||
<span class="c1">#</span>
|
||||
|
||||
<span class="c1">################################################################################</span>
|
||||
<span class="c1"># INSERT YOUR DATA HERE #</span>
|
||||
<span class="c1">################################################################################</span>
|
||||
<span class="nv">user_id</span><span class="o">=</span><span class="s2">"999"</span><span class="w"> </span><span class="c1"># your user_id</span>
|
||||
<span class="nv">user_key</span><span class="o">=</span><span class="s2">"??"</span><span class="w"> </span><span class="c1"># use userkey with SEND permissions on the used channel</span>
|
||||
<span class="c1">################################################################################</span>
|
||||
|
||||
usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
@ -34,16 +31,40 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
<span class="k">function</span><span class="w"> </span>rederr<span class="o">()</span><span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="k">if</span><span class="w"> </span>cfgcol<span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span>><span class="p">&</span><span class="m">2</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>-e<span class="w"> </span><span class="s2">"\x1B[31m</span><span class="nv">$1</span><span class="s2">\x1B[0m"</span><span class="p">;</span><span class="w"> </span><span class="k">else</span><span class="w"> </span>><span class="p">&</span><span class="m">2</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span><span class="p">;</span><span class="w"> </span><span class="k">fi</span><span class="p">;</span><span class="w"> </span><span class="o">}</span>
|
||||
<span class="k">function</span><span class="w"> </span>green<span class="o">()</span><span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="k">if</span><span class="w"> </span>cfgcol<span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>-e<span class="w"> </span><span class="s2">"\x1B[32m</span><span class="nv">$1</span><span class="s2">\x1B[0m"</span><span class="p">;</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span><span class="p">;</span><span class="w"> </span><span class="k">fi</span><span class="p">;</span><span class="w"> </span><span class="o">}</span>
|
||||
|
||||
<span class="c1">################################################################################</span>
|
||||
|
||||
<span class="c1">#</span>
|
||||
<span class="c1"># Get env 'SCN_UID' and 'SCN_KEY' from conf file</span>
|
||||
<span class="c1"># </span>
|
||||
<span class="c1"># shellcheck source=/dev/null</span>
|
||||
.<span class="w"> </span><span class="s2">"/etc/scn.conf"</span>
|
||||
<span class="nv">SCN_UID</span><span class="o">=</span><span class="si">${</span><span class="nv">SCN_UID</span><span class="k">:-</span><span class="si">}</span>
|
||||
<span class="nv">SCN_KEY</span><span class="o">=</span><span class="si">${</span><span class="nv">SCN_KEY</span><span class="k">:-</span><span class="si">}</span>
|
||||
|
||||
<span class="o">[</span><span class="w"> </span>-z<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">SCN_UID</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="o">{</span><span class="w"> </span>rederr<span class="w"> </span><span class="s2">"Missing config value 'SCN_UID' in /etc/scn.conf"</span><span class="p">;</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="o">}</span>
|
||||
<span class="o">[</span><span class="w"> </span>-z<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">SCN_KEY</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="o">{</span><span class="w"> </span>rederr<span class="w"> </span><span class="s2">"Missing config value 'SCN_KEY' in /etc/scn.conf"</span><span class="p">;</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="o">}</span>
|
||||
|
||||
<span class="c1">################################################################################</span>
|
||||
|
||||
<span class="nv">args</span><span class="o">=(</span><span class="w"> </span><span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
|
||||
<span class="nv">title</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">content</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">channel</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">priority</span><span class="o">=</span><span class="m">1</span>
|
||||
<span class="nv">priority</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">usr_msg_id</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>head<span class="w"> </span>/dev/urandom<span class="w"> </span><span class="p">|</span><span class="w"> </span>tr<span class="w"> </span>-dc<span class="w"> </span>A-Za-z0-9<span class="w"> </span><span class="p">|</span><span class="w"> </span>head<span class="w"> </span>-c<span class="w"> </span><span class="m">32</span><span class="k">)</span><span class="s2">"</span>
|
||||
<span class="nv">sendtime</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>date<span class="w"> </span>+%s<span class="k">)</span><span class="s2">"</span>
|
||||
<span class="nv">sender</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2">"</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="nb">command</span><span class="w"> </span>-v<span class="w"> </span>srvname<span class="w"> </span><span class="p">&</span>><span class="w"> </span>/dev/null<span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">sender</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span><span class="w"> </span>srvname<span class="w"> </span><span class="k">)</span><span class="s2">"</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"--"</span><span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="c1"># only positional args form here on (currently not handled)</span>
|
||||
<span class="w"> </span><span class="nv">args</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[@]:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-lt<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span>rederr<span class="w"> </span><span class="s2">"[ERROR]: no title supplied via parameter"</span>
|
||||
<span class="w"> </span>usage
|
||||
@ -83,6 +104,11 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span><span class="s2">"</span><span class="nv">$content</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span>--scnsend-read-body-from-file<span class="o">=</span>*<span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">path</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span><span class="w"> </span>awk<span class="w"> </span><span class="s1">'{ print substr($0, 31) }'</span><span class="w"> </span><span class="o"><<<</span><span class="w"> </span><span class="s2">"</span><span class="nv">$content</span><span class="s2">"</span><span class="w"> </span><span class="k">)</span><span class="s2">"</span>
|
||||
<span class="w"> </span><span class="nv">content</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span><span class="w"> </span>cat<span class="w"> </span><span class="s2">"</span><span class="nv">$path</span><span class="s2">"</span><span class="w"> </span><span class="k">)</span><span class="s2">"</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="nv">curlparams</span><span class="o">=()</span>
|
||||
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data-urlencode"</span><span class="w"> </span><span class="s2">"user_id=</span><span class="si">${</span><span class="nv">SCN_UID</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
|
Loading…
Reference in New Issue
Block a user