Directly use pygmentize in Makefile (for scn script in Website)
This commit is contained in:
parent
28c2721036
commit
fd72b512f8
@ -5,9 +5,9 @@ PORT=9090
|
|||||||
NAMESPACE=$(shell git rev-parse --abbrev-ref HEAD)
|
NAMESPACE=$(shell git rev-parse --abbrev-ref HEAD)
|
||||||
HASH=$(shell git rev-parse HEAD)
|
HASH=$(shell git rev-parse HEAD)
|
||||||
|
|
||||||
.PHONY: test swagger
|
.PHONY: test swagger pygmentize
|
||||||
|
|
||||||
build: swagger fmt
|
build: swagger pygmentize fmt
|
||||||
mkdir -p _build
|
mkdir -p _build
|
||||||
rm -f ./_build/scn_backend
|
rm -f ./_build/scn_backend
|
||||||
go generate ./...
|
go generate ./...
|
||||||
@ -18,8 +18,8 @@ run: build
|
|||||||
_build/scn_backend
|
_build/scn_backend
|
||||||
|
|
||||||
gow:
|
gow:
|
||||||
# go install github.com/mitranim/gow@latest
|
which gow || go install github.com/mitranim/gow@latest
|
||||||
gow run blackforestbytes.com/portfoliomanager2/cmd/server
|
gow -e "go,mod,html,css,json,yaml,js" run -tags "timetzdata sqlite_fts5 sqlite_foreign_keys" blackforestbytes.com/simplecloudnotifier/cmd/scnserver
|
||||||
|
|
||||||
docker: build
|
docker: build
|
||||||
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
|
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
|
||||||
@ -40,6 +40,13 @@ swagger:
|
|||||||
which swag || go install github.com/swaggo/swag/cmd/swag@v1.8.12
|
which swag || go install github.com/swaggo/swag/cmd/swag@v1.8.12
|
||||||
swag init -generalInfo api/router.go --propertyStrategy snakecase --output ./swagger/ --outputTypes "json,yaml"
|
swag init -generalInfo api/router.go --propertyStrategy snakecase --output ./swagger/ --outputTypes "json,yaml"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
run-docker-local: docker
|
run-docker-local: docker
|
||||||
mkdir -p .run-data
|
mkdir -p .run-data
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
|
@ -39,8 +39,6 @@
|
|||||||
|
|
||||||
- jobs to clear requests-db and logs-db after to only keep X entries...
|
- jobs to clear requests-db and logs-db after to only keep X entries...
|
||||||
|
|
||||||
-> logs and request-logging into their own sqlite files (sqlite-files are prepped)
|
|
||||||
|
|
||||||
- /send endpoint should be compatible with the [ webhook ] notifier of uptime-kuma
|
- /send endpoint should be compatible with the [ webhook ] notifier of uptime-kuma
|
||||||
(or add another /kuma endpoint)
|
(or add another /kuma endpoint)
|
||||||
-> https://webhook.site/
|
-> https://webhook.site/
|
||||||
@ -49,13 +47,10 @@
|
|||||||
|
|
||||||
- ios purchase verification
|
- ios purchase verification
|
||||||
|
|
||||||
- [X] re-add ack labels as compat table for v1 api user
|
|
||||||
- return channel as "[..] asdf" in compat methods (mark clients as compat and send compat FB to them...)
|
- return channel as "[..] asdf" in compat methods (mark clients as compat and send compat FB to them...)
|
||||||
(then we can replace the old server without switching phone clients)
|
(then we can replace the old server without switching phone clients)
|
||||||
(still needs switching of the send-script)
|
(still needs switching of the send-script)
|
||||||
|
|
||||||
- do not use uuidgen in bash script (potetnially not installed) - use `head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 `
|
|
||||||
|
|
||||||
- move to KeyToken model
|
- move to KeyToken model
|
||||||
* [X] User can have multiple keys with different permissions
|
* [X] User can have multiple keys with different permissions
|
||||||
* [X] compat simply uses default-keys
|
* [X] compat simply uses default-keys
|
||||||
|
3
scnserver/_pygments/.gitignore
vendored
Normal file
3
scnserver/_pygments/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
env
|
16
scnserver/_pygments/pygmentizew
Executable file
16
scnserver/_pygments/pygmentizew
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o nounset # disallow usage of unset vars ( set -u )
|
||||||
|
set -o errexit # Exit immediately if a pipeline returns non-zero. ( set -e )
|
||||||
|
set -o errtrace # Allow the above trap be inherited by all functions in the script. ( set -E )
|
||||||
|
set -o pipefail # Return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status
|
||||||
|
IFS=$'\n\t' # Set $IFS to only newline and tab.
|
||||||
|
|
||||||
|
cd "$(dirname "$0")" || exit 1
|
||||||
|
|
||||||
|
1>&2 virtualenv env
|
||||||
|
1>&2 source env/bin/activate
|
||||||
|
|
||||||
|
1>&2 pip install Pygments
|
||||||
|
|
||||||
|
pygmentize "$@"
|
@ -27,7 +27,7 @@ curl \
|
|||||||
--data "title=${message_title}" \
|
--data "title=${message_title}" \
|
||||||
--data "content=${message_body}" \
|
--data "content=${message_body}" \
|
||||||
--data "priority=${0|1|2}" \
|
--data "priority=${0|1|2}" \
|
||||||
--data "msg_id=$(uuidgen)" \
|
--data "msg_id=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)" \
|
||||||
--data "timestamp=$(date +%s)" \
|
--data "timestamp=$(date +%s)" \
|
||||||
--data "channel={channel_name}" \
|
--data "channel={channel_name}" \
|
||||||
--data "sender_name=$(hostname)" \
|
--data "sender_name=$(hostname)" \
|
||||||
|
@ -171,7 +171,7 @@
|
|||||||
Sometimes your script can run in an environment with an unstable connection and you want to implement an automatic re-try mechanism to send a message again if the last try failed due to bad connectivity.
|
Sometimes your script can run in an environment with an unstable connection and you want to implement an automatic re-try mechanism to send a message again if the last try failed due to bad connectivity.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
To ensure that a message is only send once you can generate a unique id for your message (I would recommend a simple <code>uuidgen</code>).
|
To ensure that a message is only send once you can generate a unique id for your message (I would recommend a simple <code>uuidgen</code> or <code>head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32</code>).
|
||||||
If you send a message with a UUID that was already used in the near past the API still returns OK, but no new message is sent.
|
If you send a message with a UUID that was already used in the near past the API still returns OK, but no new message is sent.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@ -210,7 +210,7 @@
|
|||||||
Depending on your use case it can be useful to create a bash script that handles things like resending messages if you have connection problems or waiting if there is no quota left.<br/>
|
Depending on your use case it can be useful to create a bash script that handles things like resending messages if you have connection problems or waiting if there is no quota left.<br/>
|
||||||
Here is an example how such a scrippt could look like, you can put it into <code>/usr/local/sbin</code> and call it with <code>scn_send "title" "content"</code> (or with more parameters, see the script itself)
|
Here is an example how such a scrippt could look like, you can put it into <code>/usr/local/sbin</code> and call it with <code>scn_send "title" "content"</code> (or with more parameters, see the script itself)
|
||||||
</p>
|
</p>
|
||||||
{{template|scn_send.[theme].html}}
|
<div class="yellow-code">{{template|scn_send.html}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
83
scnserver/website/css/pygmnetize-dark.css
Normal file
83
scnserver/website/css/pygmnetize-dark.css
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
pre { line-height: 125%; }
|
||||||
|
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
|
||||||
|
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
|
||||||
|
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
|
||||||
|
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
|
||||||
|
.hll { background-color: #49483e }
|
||||||
|
.c { color: #75715e } /* Comment */
|
||||||
|
.err { color: #960050; background-color: #1e0010 } /* Error */
|
||||||
|
.esc { color: #f8f8f2 } /* Escape */
|
||||||
|
.g { color: #f8f8f2 } /* Generic */
|
||||||
|
.k { color: #66d9ef } /* Keyword */
|
||||||
|
.l { color: #ae81ff } /* Literal */
|
||||||
|
.n { color: #f8f8f2 } /* Name */
|
||||||
|
.o { color: #f92672 } /* Operator */
|
||||||
|
.x { color: #f8f8f2 } /* Other */
|
||||||
|
.p { color: #f8f8f2 } /* Punctuation */
|
||||||
|
.ch { color: #75715e } /* Comment.Hashbang */
|
||||||
|
.cm { color: #75715e } /* Comment.Multiline */
|
||||||
|
.cp { color: #75715e } /* Comment.Preproc */
|
||||||
|
.cpf { color: #75715e } /* Comment.PreprocFile */
|
||||||
|
.c1 { color: #75715e } /* Comment.Single */
|
||||||
|
.cs { color: #75715e } /* Comment.Special */
|
||||||
|
.gd { color: #f92672 } /* Generic.Deleted */
|
||||||
|
.ge { color: #f8f8f2; font-style: italic } /* Generic.Emph */
|
||||||
|
.gr { color: #f8f8f2 } /* Generic.Error */
|
||||||
|
.gh { color: #f8f8f2 } /* Generic.Heading */
|
||||||
|
.gi { color: #a6e22e } /* Generic.Inserted */
|
||||||
|
.go { color: #66d9ef } /* Generic.Output */
|
||||||
|
.gp { color: #f92672; font-weight: bold } /* Generic.Prompt */
|
||||||
|
.gs { color: #f8f8f2; font-weight: bold } /* Generic.Strong */
|
||||||
|
.gu { color: #75715e } /* Generic.Subheading */
|
||||||
|
.gt { color: #f8f8f2 } /* Generic.Traceback */
|
||||||
|
.kc { color: #66d9ef } /* Keyword.Constant */
|
||||||
|
.kd { color: #66d9ef } /* Keyword.Declaration */
|
||||||
|
.kn { color: #f92672 } /* Keyword.Namespace */
|
||||||
|
.kp { color: #66d9ef } /* Keyword.Pseudo */
|
||||||
|
.kr { color: #66d9ef } /* Keyword.Reserved */
|
||||||
|
.kt { color: #66d9ef } /* Keyword.Type */
|
||||||
|
.ld { color: #e6db74 } /* Literal.Date */
|
||||||
|
.m { color: #ae81ff } /* Literal.Number */
|
||||||
|
.s { color: #e6db74 } /* Literal.String */
|
||||||
|
.na { color: #a6e22e } /* Name.Attribute */
|
||||||
|
.nb { color: #f8f8f2 } /* Name.Builtin */
|
||||||
|
.nc { color: #a6e22e } /* Name.Class */
|
||||||
|
.no { color: #66d9ef } /* Name.Constant */
|
||||||
|
.nd { color: #a6e22e } /* Name.Decorator */
|
||||||
|
.ni { color: #f8f8f2 } /* Name.Entity */
|
||||||
|
.ne { color: #a6e22e } /* Name.Exception */
|
||||||
|
.nf { color: #a6e22e } /* Name.Function */
|
||||||
|
.nl { color: #f8f8f2 } /* Name.Label */
|
||||||
|
.nn { color: #f8f8f2 } /* Name.Namespace */
|
||||||
|
.nx { color: #a6e22e } /* Name.Other */
|
||||||
|
.py { color: #f8f8f2 } /* Name.Property */
|
||||||
|
.nt { color: #f92672 } /* Name.Tag */
|
||||||
|
.nv { color: #f8f8f2 } /* Name.Variable */
|
||||||
|
.ow { color: #f92672 } /* Operator.Word */
|
||||||
|
.pm { color: #f8f8f2 } /* Punctuation.Marker */
|
||||||
|
.w { color: #f8f8f2 } /* Text.Whitespace */
|
||||||
|
.mb { color: #ae81ff } /* Literal.Number.Bin */
|
||||||
|
.mf { color: #ae81ff } /* Literal.Number.Float */
|
||||||
|
.mh { color: #ae81ff } /* Literal.Number.Hex */
|
||||||
|
.mi { color: #ae81ff } /* Literal.Number.Integer */
|
||||||
|
.mo { color: #ae81ff } /* Literal.Number.Oct */
|
||||||
|
.sa { color: #e6db74 } /* Literal.String.Affix */
|
||||||
|
.sb { color: #e6db74 } /* Literal.String.Backtick */
|
||||||
|
.sc { color: #e6db74 } /* Literal.String.Char */
|
||||||
|
.dl { color: #e6db74 } /* Literal.String.Delimiter */
|
||||||
|
.sd { color: #e6db74 } /* Literal.String.Doc */
|
||||||
|
.s2 { color: #e6db74 } /* Literal.String.Double */
|
||||||
|
.se { color: #ae81ff } /* Literal.String.Escape */
|
||||||
|
.sh { color: #e6db74 } /* Literal.String.Heredoc */
|
||||||
|
.si { color: #e6db74 } /* Literal.String.Interpol */
|
||||||
|
.sx { color: #e6db74 } /* Literal.String.Other */
|
||||||
|
.sr { color: #e6db74 } /* Literal.String.Regex */
|
||||||
|
.s1 { color: #e6db74 } /* Literal.String.Single */
|
||||||
|
.ss { color: #e6db74 } /* Literal.String.Symbol */
|
||||||
|
.bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
|
||||||
|
.fm { color: #a6e22e } /* Name.Function.Magic */
|
||||||
|
.vc { color: #f8f8f2 } /* Name.Variable.Class */
|
||||||
|
.vg { color: #f8f8f2 } /* Name.Variable.Global */
|
||||||
|
.vi { color: #f8f8f2 } /* Name.Variable.Instance */
|
||||||
|
.vm { color: #f8f8f2 } /* Name.Variable.Magic */
|
||||||
|
.il { color: #ae81ff } /* Literal.Number.Integer.Long */
|
56
scnserver/website/css/pygmnetize-light.css
Normal file
56
scnserver/website/css/pygmnetize-light.css
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
pre { line-height: 125%; }
|
||||||
|
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
|
||||||
|
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
|
||||||
|
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
|
||||||
|
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
|
||||||
|
.hll { background-color: #ffffcc }
|
||||||
|
.c { color: #008800; font-style: italic } /* Comment */
|
||||||
|
.err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
||||||
|
.k { color: #000080; font-weight: bold } /* Keyword */
|
||||||
|
.ch { color: #008800; font-style: italic } /* Comment.Hashbang */
|
||||||
|
.cm { color: #008800; font-style: italic } /* Comment.Multiline */
|
||||||
|
.cp { color: #008080 } /* Comment.Preproc */
|
||||||
|
.cpf { color: #008800; font-style: italic } /* Comment.PreprocFile */
|
||||||
|
.c1 { color: #008800; font-style: italic } /* Comment.Single */
|
||||||
|
.cs { color: #008800; font-weight: bold } /* Comment.Special */
|
||||||
|
.gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
||||||
|
.ge { font-style: italic } /* Generic.Emph */
|
||||||
|
.gr { color: #aa0000 } /* Generic.Error */
|
||||||
|
.gh { color: #999999 } /* Generic.Heading */
|
||||||
|
.gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
||||||
|
.go { color: #888888 } /* Generic.Output */
|
||||||
|
.gp { color: #555555 } /* Generic.Prompt */
|
||||||
|
.gs { font-weight: bold } /* Generic.Strong */
|
||||||
|
.gu { color: #aaaaaa } /* Generic.Subheading */
|
||||||
|
.gt { color: #aa0000 } /* Generic.Traceback */
|
||||||
|
.kc { color: #000080; font-weight: bold } /* Keyword.Constant */
|
||||||
|
.kd { color: #000080; font-weight: bold } /* Keyword.Declaration */
|
||||||
|
.kn { color: #000080; font-weight: bold } /* Keyword.Namespace */
|
||||||
|
.kp { color: #000080; font-weight: bold } /* Keyword.Pseudo */
|
||||||
|
.kr { color: #000080; font-weight: bold } /* Keyword.Reserved */
|
||||||
|
.kt { color: #000080; font-weight: bold } /* Keyword.Type */
|
||||||
|
.m { color: #0000FF } /* Literal.Number */
|
||||||
|
.s { color: #0000FF } /* Literal.String */
|
||||||
|
.na { color: #FF0000 } /* Name.Attribute */
|
||||||
|
.nt { color: #000080; font-weight: bold } /* Name.Tag */
|
||||||
|
.ow { font-weight: bold } /* Operator.Word */
|
||||||
|
.w { color: #bbbbbb } /* Text.Whitespace */
|
||||||
|
.mb { color: #0000FF } /* Literal.Number.Bin */
|
||||||
|
.mf { color: #0000FF } /* Literal.Number.Float */
|
||||||
|
.mh { color: #0000FF } /* Literal.Number.Hex */
|
||||||
|
.mi { color: #0000FF } /* Literal.Number.Integer */
|
||||||
|
.mo { color: #0000FF } /* Literal.Number.Oct */
|
||||||
|
.sa { color: #0000FF } /* Literal.String.Affix */
|
||||||
|
.sb { color: #0000FF } /* Literal.String.Backtick */
|
||||||
|
.sc { color: #800080 } /* Literal.String.Char */
|
||||||
|
.dl { color: #0000FF } /* Literal.String.Delimiter */
|
||||||
|
.sd { color: #0000FF } /* Literal.String.Doc */
|
||||||
|
.s2 { color: #0000FF } /* Literal.String.Double */
|
||||||
|
.se { color: #0000FF } /* Literal.String.Escape */
|
||||||
|
.sh { color: #0000FF } /* Literal.String.Heredoc */
|
||||||
|
.si { color: #0000FF } /* Literal.String.Interpol */
|
||||||
|
.sx { color: #0000FF } /* Literal.String.Other */
|
||||||
|
.sr { color: #0000FF } /* Literal.String.Regex */
|
||||||
|
.s1 { color: #0000FF } /* Literal.String.Single */
|
||||||
|
.ss { color: #0000FF } /* Literal.String.Symbol */
|
||||||
|
.il { color: #0000FF } /* Literal.Number.Integer.Long */
|
@ -20,8 +20,9 @@
|
|||||||
border-color: #888 !important;
|
border-color: #888 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre.yellow-code,
|
.yellow-code,
|
||||||
pre.yellow-code span {
|
.yellow-code pre,
|
||||||
|
.yellow-code span {
|
||||||
background: none;
|
background: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,3 +33,8 @@ pre.yellow-code span {
|
|||||||
#theme-switch:hover {
|
#theme-switch:hover {
|
||||||
fill: #88F;
|
fill: #88F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background: var(--secondary-back-color);
|
||||||
|
border: .0625rem solid #444;
|
||||||
|
}
|
@ -41,7 +41,7 @@ body
|
|||||||
border-left: .25rem solid #E53935;
|
border-left: .25rem solid #E53935;
|
||||||
}
|
}
|
||||||
|
|
||||||
.yellow-code
|
.yellow-code pre
|
||||||
{
|
{
|
||||||
border-left: .25rem solid #FFCB05;
|
border-left: .25rem solid #FFCB05;
|
||||||
}
|
}
|
||||||
@ -270,6 +270,7 @@ a.card:hover
|
|||||||
|
|
||||||
table.scode_table {
|
table.scode_table {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.scode_table td:nth-child(2) {
|
table.scode_table td:nth-child(2) {
|
||||||
@ -300,7 +301,7 @@ pre, pre span
|
|||||||
}
|
}
|
||||||
|
|
||||||
#theme-switch {
|
#theme-switch {
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 0.75rem;
|
top: 0.75rem;
|
||||||
right: 0.75rem;
|
right: 0.75rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@ -311,3 +312,8 @@ pre, pre span
|
|||||||
filter: blur(1px);
|
filter: blur(1px);
|
||||||
fill: #008;
|
fill: #008;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background: #F9F9F9;
|
||||||
|
border: .0625rem solid var(--secondary-border-color);
|
||||||
|
}
|
@ -8,6 +8,8 @@
|
|||||||
<link rel="stylesheet" href="/css/mini-dark.min.css">
|
<link rel="stylesheet" href="/css/mini-dark.min.css">
|
||||||
<link rel="stylesheet" href="/css/style-dark.css">
|
<link rel="stylesheet" href="/css/style-dark.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/css/pygmnetize-dark.css">
|
||||||
|
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/png" href="/favicon.png"/>
|
<link rel="icon" type="image/png" href="/favicon.png"/>
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
<link rel="stylesheet" href="/css/style.css">
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/css/pygmnetize-light.css">
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/png" href="/favicon.png"/>
|
<link rel="icon" type="image/png" href="/favicon.png"/>
|
||||||
<link rel="icon" type="image/png" href="/favicon.ico"/>
|
<link rel="icon" type="image/png" href="/favicon.ico"/>
|
@ -1,138 +0,0 @@
|
|||||||
|
|
||||||
<!-- https://hilite.me/ | bash | monokai -->
|
|
||||||
|
|
||||||
<!-- HTML generated using hilite.me -->
|
|
||||||
|
|
||||||
<pre style="color:#7e7e7e; margin: 0; line-height: 125%" class="yellow-code">
|
|
||||||
<span style="color: #75715e">#!/usr/bin/env bash</span>
|
|
||||||
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
<span style="color: #75715e"># Wrapper around SCN ( https://scn.blackforestbytes.com/ )</span>
|
|
||||||
<span style="color: #75715e"># ========================================================</span>
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
<span style="color: #75715e"># ./scn_send [@channel] title [content] [priority]</span>
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
<span style="color: #75715e"># Call with scn_send "${title}"</span>
|
|
||||||
<span style="color: #75715e"># or scn_send "${title}" ${content}"</span>
|
|
||||||
<span style="color: #75715e"># or scn_send "${title}" ${content}" "${priority:0|1|2}"</span>
|
|
||||||
<span style="color: #75715e"># or scn_send "@${channel} "${title}"</span>
|
|
||||||
<span style="color: #75715e"># or scn_send "@${channel} "${title}" ${content}"</span>
|
|
||||||
<span style="color: #75715e"># or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}"</span>
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
<span style="color: #75715e">#</span>
|
|
||||||
|
|
||||||
<span style="color: #75715e">################################################################################</span>
|
|
||||||
<span style="color: #75715e"># INSERT YOUR DATA HERE #</span>
|
|
||||||
<span style="color: #75715e">################################################################################</span>
|
|
||||||
<span style="color: #f8f8f2">user_id</span><span style="color: #f92672">=</span><span style="color: #e6db74">"999"</span>
|
|
||||||
<span style="color: #f8f8f2">user_key</span><span style="color: #f92672">=</span><span style="color: #e6db74">"??"</span>
|
|
||||||
<span style="color: #75715e">################################################################################</span>
|
|
||||||
|
|
||||||
usage<span style="color: #f92672">()</span> <span style="color: #f92672">{</span>
|
|
||||||
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Usage: "</span>
|
|
||||||
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">" scn_send [@channel] title [content] [priority]"</span>
|
|
||||||
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">""</span>
|
|
||||||
<span style="color: #f92672">}</span>
|
|
||||||
|
|
||||||
<span style="color: #f8f8f2">args</span><span style="color: #f92672">=(</span> <span style="color: #e6db74">"$@"</span> <span style="color: #f92672">)</span>
|
|
||||||
|
|
||||||
<span style="color: #f8f8f2">title</span><span style="color: #f92672">=</span><span style="color: #f8f8f2">$1</span>
|
|
||||||
<span style="color: #f8f8f2">content</span><span style="color: #f92672">=</span><span style="color: #e6db74">""</span>
|
|
||||||
<span style="color: #f8f8f2">channel</span><span style="color: #f92672">=</span><span style="color: #e6db74">""</span>
|
|
||||||
<span style="color: #f8f8f2">priority</span><span style="color: #f92672">=</span>1
|
|
||||||
<span style="color: #f8f8f2">usr_msg_id</span><span style="color: #f92672">=</span><span style="color: #e6db74">"$(uuidgen)"</span>
|
|
||||||
<span style="color: #f8f8f2">sendtime</span><span style="color: #f92672">=</span><span style="color: #e6db74">"$(date +%s)"</span>
|
|
||||||
<span style="color: #f8f8f2">sender</span><span style="color: #f92672">=</span><span style="color: #e6db74">"$(hostname)"</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #66d9ef">${#</span><span style="color: #f8f8f2">args[@]</span><span style="color: #66d9ef">}</span> -lt 1 <span style="color: #f92672">]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"[ERROR]: no title supplied via parameter"</span> 1>&2
|
|
||||||
usage
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[[</span> <span style="color: #e6db74">"${args[0]}"</span> <span style="color: #f92672">=</span>~ ^@.* <span style="color: #f92672">]]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">channel</span><span style="color: #f92672">=</span><span style="color: #e6db74">"${args[0]}"</span>
|
|
||||||
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">"args[0]"</span>
|
|
||||||
<span style="color: #f8f8f2">channel</span><span style="color: #f92672">=</span><span style="color: #e6db74">"${channel:1}"</span>
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #66d9ef">${#</span><span style="color: #f8f8f2">args[@]</span><span style="color: #66d9ef">}</span> -lt 1 <span style="color: #f92672">]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"[ERROR]: no title supplied via parameter"</span> 1>&2
|
|
||||||
usage
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #f8f8f2">title</span><span style="color: #f92672">=</span><span style="color: #e6db74">"${args[0]}"</span>
|
|
||||||
<span style="color: #f8f8f2">content</span><span style="color: #f92672">=</span><span style="color: #e6db74">""</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #66d9ef">${#</span><span style="color: #f8f8f2">args[@]</span><span style="color: #66d9ef">}</span> -gt 1 <span style="color: #f92672">]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">content</span><span style="color: #f92672">=</span><span style="color: #e6db74">"${args[0]}"</span>
|
|
||||||
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">"args[0]"</span>
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #66d9ef">${#</span><span style="color: #f8f8f2">args[@]</span><span style="color: #66d9ef">}</span> -gt 1 <span style="color: #f92672">]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">priority</span><span style="color: #f92672">=</span><span style="color: #e6db74">"${args[0]}"</span>
|
|
||||||
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">"args[0]"</span>
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #66d9ef">${#</span><span style="color: #f8f8f2">args[@]</span><span style="color: #66d9ef">}</span> -gt 1 <span style="color: #f92672">]</span>; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Too many arguments to scn_send"</span> 1>&2
|
|
||||||
usage
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">while </span><span style="color: #f8f8f2">true</span> ; <span style="color: #66d9ef">do</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">curlresp</span><span style="color: #f92672">=</span><span style="color: #66d9ef">$(</span>curl --silent <span style="color: #ae81ff">\</span>
|
|
||||||
--output /dev/null <span style="color: #ae81ff">\</span>
|
|
||||||
--write-out <span style="color: #e6db74">"%{http_code}"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"user_id=$user_id"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"key=$key"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"title=$title"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"timestamp=$sendtime"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"content=$content"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"priority=$priority"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"msg_id=$usr_msg_id"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"channel=$channel"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
--data <span style="color: #e6db74">"sender_name=$sender"</span> <span style="color: #ae81ff">\</span>
|
|
||||||
<span style="color: #e6db74">"https://scn.blackforestbytes.com/"</span> <span style="color: #66d9ef">)</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 200 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Successfully send"</span>
|
|
||||||
<span style="color: #f8f8f2">exit </span>0
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 400 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Bad request - something went wrong"</span> 1>&2
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 401 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Unauthorized - wrong userid/userkey"</span> 1>&2
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 403 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Quota exceeded - wait one hour before re-try"</span> 1>&2
|
|
||||||
sleep 3600
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 412 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Precondition Failed - No device linked"</span> 1>&2
|
|
||||||
<span style="color: #f8f8f2">exit </span>1
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">"$curlresp"</span> <span style="color: #f92672">==</span> 500 <span style="color: #f92672">]</span> ; <span style="color: #66d9ef">then</span>
|
|
||||||
<span style="color: #66d9ef"> </span><span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Internal server error - waiting for better times"</span> 1>&2
|
|
||||||
sleep 60
|
|
||||||
<span style="color: #66d9ef">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #75715e"># if none of the above matched we probably hav no network ...</span>
|
|
||||||
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">"Send failed (response code $curlresp) ... try again in 5s"</span> 1>&2
|
|
||||||
sleep 5
|
|
||||||
<span style="color: #66d9ef">done</span>
|
|
||||||
|
|
||||||
</pre>
|
|
||||||
|
|
142
scnserver/website/scn_send.html
Normal file
142
scnserver/website/scn_send.html
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env bash</span>
|
||||||
|
|
||||||
|
<span class="c1">#</span>
|
||||||
|
<span class="c1"># Wrapper around SCN ( https://scn.blackforestbytes.com/ )</span>
|
||||||
|
<span class="c1"># ========================================================</span>
|
||||||
|
<span class="c1">#</span>
|
||||||
|
<span class="c1"># ./scn_send [@channel] title [content] [priority]</span>
|
||||||
|
<span class="c1">#</span>
|
||||||
|
<span class="c1">#</span>
|
||||||
|
<span class="c1"># Call with scn_send "${title}"</span>
|
||||||
|
<span class="c1"># or scn_send "${title}" ${content}"</span>
|
||||||
|
<span class="c1"># or scn_send "${title}" ${content}" "${priority:0|1|2}"</span>
|
||||||
|
<span class="c1"># or scn_send "@${channel} "${title}"</span>
|
||||||
|
<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">#</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>
|
||||||
|
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"Usage: "</span>
|
||||||
|
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">" scn_send [@channel] title [content] [priority]"</span>
|
||||||
|
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">""</span>
|
||||||
|
<span class="o">}</span>
|
||||||
|
|
||||||
|
<span class="k">function</span><span class="w"> </span>cfgcol<span class="w"> </span><span class="o">{</span><span class="w"> </span><span class="o">[</span><span class="w"> </span>-t<span class="w"> </span><span class="m">1</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>-n<span class="w"> </span><span class="s2">"</span><span class="k">$(</span>tput<span class="w"> </span>colors<span class="k">)</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><span class="s2">"</span><span class="k">$(</span>tput<span class="w"> </span>colors<span class="k">)</span><span class="s2">"</span><span class="w"> </span>-ge<span class="w"> </span><span class="m">8</span><span class="w"> </span><span class="o">]</span><span class="p">;</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="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="nv">$1</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">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="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
|
||||||
|
<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="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="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">channel</span><span class="o">=</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="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</span>
|
||||||
|
<span class="w"> </span><span class="nv">channel</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">channel</span><span class="p">:</span><span class="nv">1</span><span class="si">}</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="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
|
||||||
|
<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="nv">title</span><span class="o">=</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="nv">content</span><span class="o">=</span><span class="s2">""</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>-gt<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><span class="nv">content</span><span class="o">=</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="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</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>-gt<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><span class="nv">priority</span><span class="o">=</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="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</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>-gt<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">"Too many arguments to scn_send"</span>
|
||||||
|
<span class="w"> </span>usage
|
||||||
|
<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">while</span><span class="w"> </span><span class="nb">true</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">do</span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nv">outf</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>mktemp<span class="k">)</span><span class="s2">"</span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nv">curlresp</span><span class="o">=</span><span class="k">$(</span>curl<span class="w"> </span>--silent<span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--output<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">outf</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--write-out<span class="w"> </span><span class="s2">"%{http_code}"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"user_id=</span><span class="nv">$user_id</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"key=</span><span class="nv">$user_key</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"title=</span><span class="nv">$title</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"timestamp=</span><span class="nv">$sendtime</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"content=</span><span class="nv">$content</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"priority=</span><span class="nv">$priority</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"msg_id=</span><span class="nv">$usr_msg_id</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"channel=</span><span class="nv">$channel</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"sender_name=</span><span class="nv">$sender</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||||
|
<span class="w"> </span><span class="s2">"https://scn.blackforestbytes.com/"</span><span class="w"> </span><span class="k">)</span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nv">curlout</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat<span class="w"> </span><span class="s2">"</span><span class="nv">$outf</span><span class="s2">"</span><span class="k">)</span><span class="s2">"</span>
|
||||||
|
<span class="w"> </span>rm<span class="w"> </span><span class="s2">"</span><span class="nv">$outf</span><span class="s2">"</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">200</span><span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||||
|
<span class="w"> </span>green<span class="w"> </span><span class="s2">"Successfully send"</span>
|
||||||
|
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">0</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">400</span><span class="w"> </span><span class="o">]</span><span class="w"> </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">"Bad request - something went wrong"</span>
|
||||||
|
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"</span><span class="nv">$curlout</span><span class="s2">"</span>
|
||||||
|
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">""</span>
|
||||||
|
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">401</span><span class="w"> </span><span class="o">]</span><span class="w"> </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">"Unauthorized - wrong userid/userkey"</span>
|
||||||
|
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">403</span><span class="w"> </span><span class="o">]</span><span class="w"> </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">"Quota exceeded - wait 5 min before re-try"</span>
|
||||||
|
<span class="w"> </span>sleep<span class="w"> </span><span class="m">300</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">412</span><span class="w"> </span><span class="o">]</span><span class="w"> </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">"Precondition Failed - No device linked"</span>
|
||||||
|
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </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">$curlresp</span><span class="s2">"</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">500</span><span class="w"> </span><span class="o">]</span><span class="w"> </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">"Internal server error - waiting for better times"</span>
|
||||||
|
<span class="w"> </span>sleep<span class="w"> </span><span class="m">60</span>
|
||||||
|
<span class="w"> </span><span class="k">fi</span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="c1"># if none of the above matched we probably have no network ...</span>
|
||||||
|
<span class="w"> </span>rederr<span class="w"> </span><span class="s2">"Send failed (response code </span><span class="nv">$curlresp</span><span class="s2">) ... try again in 5s"</span>
|
||||||
|
<span class="w"> </span>sleep<span class="w"> </span><span class="m">5</span>
|
||||||
|
<span class="k">done</span>
|
||||||
|
</pre></div>
|
@ -1,136 +0,0 @@
|
|||||||
|
|
||||||
<!-- https://hilite.me/ | bash | borland -->
|
|
||||||
|
|
||||||
<!-- HTML generated using hilite.me -->
|
|
||||||
|
|
||||||
<pre style="color:#000000; margin: 0; line-height: 125%" class="yellow-code">
|
|
||||||
<span style="color: #008800; font-style: italic">#!/usr/bin/env bash</span>
|
|
||||||
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># Wrapper around SCN ( https://scn.blackforestbytes.com/ )</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># ========================================================</span>
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># ./scn_send [@channel] title [content] [priority]</span>
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># Call with scn_send "${title}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># or scn_send "${title}" ${content}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># or scn_send "${title}" ${content}" "${priority:0|1|2}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># or scn_send "@${channel} "${title}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># or scn_send "@${channel} "${title}" ${content}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}"</span>
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
<span style="color: #008800; font-style: italic">#</span>
|
|
||||||
|
|
||||||
<span style="color: #008800; font-style: italic">################################################################################</span>
|
|
||||||
<span style="color: #008800; font-style: italic"># INSERT YOUR DATA HERE #</span>
|
|
||||||
<span style="color: #008800; font-style: italic">################################################################################</span>
|
|
||||||
user_id=<span style="color: #0000FF">"999"</span>
|
|
||||||
key=<span style="color: #0000FF">"??"</span>
|
|
||||||
<span style="color: #008800; font-style: italic">################################################################################</span>
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo <span style="color: #0000FF">"Usage: "</span>
|
|
||||||
echo <span style="color: #0000FF">" scn_send [@channel] title [content] [priority]"</span>
|
|
||||||
echo <span style="color: #0000FF">""</span>
|
|
||||||
}
|
|
||||||
|
|
||||||
args=( <span style="color: #0000FF">"$@"</span> )
|
|
||||||
|
|
||||||
title=$1
|
|
||||||
content=<span style="color: #0000FF">""</span>
|
|
||||||
channel=<span style="color: #0000FF">""</span>
|
|
||||||
priority=1
|
|
||||||
usr_msg_id=<span style="color: #0000FF">"$(uuidgen)"</span>
|
|
||||||
sendtime=<span style="color: #0000FF">"$(date +%s)"</span>
|
|
||||||
sender=<span style="color: #0000FF">"$(hostname)"</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #000080; font-weight: bold">${#</span>args[@]<span style="color: #000080; font-weight: bold">}</span> -lt 1 ]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"[ERROR]: no title supplied via parameter"</span> 1>&2
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [[ <span style="color: #0000FF">"${args[0]}"</span> =~ ^@.* ]]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>channel=<span style="color: #0000FF">"${args[0]}"</span>
|
|
||||||
unset <span style="color: #0000FF">"args[0]"</span>
|
|
||||||
channel=<span style="color: #0000FF">"${channel:1}"</span>
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #000080; font-weight: bold">${#</span>args[@]<span style="color: #000080; font-weight: bold">}</span> -lt 1 ]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"[ERROR]: no title supplied via parameter"</span> 1>&2
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
title=<span style="color: #0000FF">"${args[0]}"</span>
|
|
||||||
content=<span style="color: #0000FF">""</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #000080; font-weight: bold">${#</span>args[@]<span style="color: #000080; font-weight: bold">}</span> -gt 1 ]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>content=<span style="color: #0000FF">"${args[0]}"</span>
|
|
||||||
unset <span style="color: #0000FF">"args[0]"</span>
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #000080; font-weight: bold">${#</span>args[@]<span style="color: #000080; font-weight: bold">}</span> -gt 1 ]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>priority=<span style="color: #0000FF">"${args[0]}"</span>
|
|
||||||
unset <span style="color: #0000FF">"args[0]"</span>
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #000080; font-weight: bold">${#</span>args[@]<span style="color: #000080; font-weight: bold">}</span> -gt 1 ]; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Too many arguments to scn_send"</span> 1>&2
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">while </span>true ; <span style="color: #000080; font-weight: bold">do</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>curlresp=<span style="color: #000080; font-weight: bold">$(</span>curl --silent <span style="color: #0000FF">\</span>
|
|
||||||
--output /dev/null <span style="color: #0000FF">\</span>
|
|
||||||
--write-out <span style="color: #0000FF">"%{http_code}"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"user_id=$user_id"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"key=$key"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"title=$title"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"timestamp=$sendtime"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"content=$content"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"priority=$priority"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"msg_id=$usr_msg_id"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"channel=$channel"</span> <span style="color: #0000FF">\</span>
|
|
||||||
--data <span style="color: #0000FF">"sender_name=$sender"</span> <span style="color: #0000FF">\</span>
|
|
||||||
<span style="color: #0000FF">"https://scn.blackforestbytes.com/"</span> <span style="color: #000080; font-weight: bold">)</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold">if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 200 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Successfully send"</span>
|
|
||||||
exit 0
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 400 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Bad request - something went wrong"</span> 1>&2
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 401 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Unauthorized - wrong userid/userkey"</span> 1>&2
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 403 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Quota exceeded - wait one hour before re-try"</span> 1>&2
|
|
||||||
sleep 3600
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 412 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Precondition Failed - No device linked"</span> 1>&2
|
|
||||||
exit 1
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #000080; font-weight: bold"> if</span> [ <span style="color: #0000FF">"$curlresp"</span> == 500 ] ; <span style="color: #000080; font-weight: bold">then</span>
|
|
||||||
<span style="color: #000080; font-weight: bold"> </span>echo <span style="color: #0000FF">"Internal server error - waiting for better times"</span> 1>&2
|
|
||||||
sleep 60
|
|
||||||
<span style="color: #000080; font-weight: bold">fi</span>
|
|
||||||
|
|
||||||
<span style="color: #008800; font-style: italic"># if none of the above matched we probably hav no network ...</span>
|
|
||||||
echo <span style="color: #0000FF">"Send failed (response code $curlresp) ... try again in 5s"</span> 1>&2
|
|
||||||
sleep 5
|
|
||||||
<span style="color: #000080; font-weight: bold">done</span>
|
|
||||||
</pre>
|
|
141
scnserver/website/scn_send.sh.txt
Normal file
141
scnserver/website/scn_send.sh.txt
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Wrapper around SCN ( https://scn.blackforestbytes.com/ )
|
||||||
|
# ========================================================
|
||||||
|
#
|
||||||
|
# ./scn_send [@channel] title [content] [priority]
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Call with scn_send "${title}"
|
||||||
|
# or scn_send "${title}" ${content}"
|
||||||
|
# or scn_send "${title}" ${content}" "${priority:0|1|2}"
|
||||||
|
# or scn_send "@${channel} "${title}"
|
||||||
|
# or scn_send "@${channel} "${title}" ${content}"
|
||||||
|
# or scn_send "@${channel} "${title}" ${content}" "${priority:0|1|2}"
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# INSERT YOUR DATA HERE #
|
||||||
|
################################################################################
|
||||||
|
user_id="999" # your user_id
|
||||||
|
user_key="??" # use userkey with SEND permissions on the used channel
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: "
|
||||||
|
echo " scn_send [@channel] title [content] [priority]"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function cfgcol { [ -t 1 ] && [ -n "$(tput colors)" ] && [ "$(tput colors)" -ge 8 ]; }
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
args=( "$@" )
|
||||||
|
|
||||||
|
title=$1
|
||||||
|
content=""
|
||||||
|
channel=""
|
||||||
|
priority=1
|
||||||
|
usr_msg_id="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)"
|
||||||
|
sendtime="$(date +%s)"
|
||||||
|
sender="$(hostname)"
|
||||||
|
|
||||||
|
if [ ${#args[@]} -lt 1 ]; then
|
||||||
|
rederr "[ERROR]: no title supplied via parameter"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${args[0]}" =~ ^@.* ]]; then
|
||||||
|
channel="${args[0]}"
|
||||||
|
unset "args[0]"
|
||||||
|
channel="${channel:1}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#args[@]} -lt 1 ]; then
|
||||||
|
rederr "[ERROR]: no title supplied via parameter"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
title="${args[0]}"
|
||||||
|
content=""
|
||||||
|
|
||||||
|
if [ ${#args[@]} -gt 1 ]; then
|
||||||
|
content="${args[0]}"
|
||||||
|
unset "args[0]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#args[@]} -gt 1 ]; then
|
||||||
|
priority="${args[0]}"
|
||||||
|
unset "args[0]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#args[@]} -gt 1 ]; then
|
||||||
|
rederr "Too many arguments to scn_send"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
while true ; do
|
||||||
|
|
||||||
|
outf="$(mktemp)"
|
||||||
|
|
||||||
|
curlresp=$(curl --silent \
|
||||||
|
--output "${outf}" \
|
||||||
|
--write-out "%{http_code}" \
|
||||||
|
--data "user_id=$user_id" \
|
||||||
|
--data "key=$user_key" \
|
||||||
|
--data "title=$title" \
|
||||||
|
--data "timestamp=$sendtime" \
|
||||||
|
--data "content=$content" \
|
||||||
|
--data "priority=$priority" \
|
||||||
|
--data "msg_id=$usr_msg_id" \
|
||||||
|
--data "channel=$channel" \
|
||||||
|
--data "sender_name=$sender" \
|
||||||
|
"https://scn.blackforestbytes.com/" )
|
||||||
|
|
||||||
|
curlout="$(cat "$outf")"
|
||||||
|
rm "$outf"
|
||||||
|
|
||||||
|
if [ "$curlresp" == 200 ] ; then
|
||||||
|
green "Successfully send"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$curlresp" == 400 ] ; then
|
||||||
|
rederr "Bad request - something went wrong"
|
||||||
|
echo "$curlout"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$curlresp" == 401 ] ; then
|
||||||
|
rederr "Unauthorized - wrong userid/userkey"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$curlresp" == 403 ] ; then
|
||||||
|
rederr "Quota exceeded - wait 5 min before re-try"
|
||||||
|
sleep 300
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$curlresp" == 412 ] ; then
|
||||||
|
rederr "Precondition Failed - No device linked"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$curlresp" == 500 ] ; then
|
||||||
|
rederr "Internal server error - waiting for better times"
|
||||||
|
sleep 60
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if none of the above matched we probably have no network ...
|
||||||
|
rederr "Send failed (response code $curlresp) ... try again in 5s"
|
||||||
|
sleep 5
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user