dark-mode

This commit is contained in:
Mike Schwörer 2022-11-26 16:30:30 +01:00
parent 3a0c65a849
commit bf0ce5c963
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
15 changed files with 323 additions and 72 deletions

View File

@ -10,7 +10,6 @@
- full-text-search: https://www.sqlite.org/fts5.html#contentless_tables - full-text-search: https://www.sqlite.org/fts5.html#contentless_tables
- dark mode toggle for html
- app-store link in HTML - app-store link in HTML
- route to re-check all pro-token - route to re-check all pro-token

View File

@ -6,6 +6,7 @@ import (
"blackforestbytes.com/simplecloudnotifier/website" "blackforestbytes.com/simplecloudnotifier/website"
"errors" "errors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -20,7 +21,7 @@ type WebsiteHandler struct {
func NewWebsiteHandler(app *logic.Application) WebsiteHandler { func NewWebsiteHandler(app *logic.Application) WebsiteHandler {
return WebsiteHandler{ return WebsiteHandler{
app: app, app: app,
rexTemplate: regexp.MustCompile("{{template\\|[A-Za-z0-9_\\-.]+}}"), rexTemplate: regexp.MustCompile("{{template\\|[A-Za-z0-9_\\-\\[\\].]+}}"),
rexConfig: regexp.MustCompile("{{config\\|[A-Za-z0-9_\\-.]+}}"), rexConfig: regexp.MustCompile("{{config\\|[A-Za-z0-9_\\-.]+}}"),
} }
} }
@ -86,9 +87,13 @@ func (h WebsiteHandler) serveAsset(g *gin.Context, fn string, repl bool) ginresp
data = h.rexTemplate.ReplaceAllFunc(data, func(match []byte) []byte { data = h.rexTemplate.ReplaceAllFunc(data, func(match []byte) []byte {
prefix := len("{{template|") prefix := len("{{template|")
suffix := len("}}") suffix := len("}}")
fnSub := match[prefix : len(match)-suffix] fnSub := string(match[prefix : len(match)-suffix])
subdata, err := website.Assets.ReadFile(string(fnSub))
fnSub = strings.ReplaceAll(fnSub, "[theme]", h.getTheme(g))
subdata, err := website.Assets.ReadFile(fnSub)
if err != nil { if err != nil {
log.Error().Str("templ", string(match)).Str("fnSub", fnSub).Str("source", fn).Msg("Failed to replace template")
failed = true failed = true
} }
return subdata return subdata
@ -104,6 +109,7 @@ func (h WebsiteHandler) serveAsset(g *gin.Context, fn string, repl bool) ginresp
cval, ok := h.getReplConfig(string(cfgKey)) cval, ok := h.getReplConfig(string(cfgKey))
if !ok { if !ok {
log.Error().Str("templ", string(match)).Str("source", fn).Msg("Failed to replace config")
failed = true failed = true
} }
return []byte(cval) return []byte(cval)
@ -154,3 +160,15 @@ func (h WebsiteHandler) getReplConfig(key string) (string, bool) {
return "", false return "", false
} }
func (h WebsiteHandler) getTheme(g *gin.Context) string {
if c, err := g.Cookie("theme"); err != nil {
return "light"
} else if c == "light" {
return "light"
} else if c == "dark" {
return "dark"
} else {
return "light"
}
}

View File

@ -5,6 +5,7 @@ import (
"blackforestbytes.com/simplecloudnotifier/api" "blackforestbytes.com/simplecloudnotifier/api"
"blackforestbytes.com/simplecloudnotifier/common/ginext" "blackforestbytes.com/simplecloudnotifier/common/ginext"
"blackforestbytes.com/simplecloudnotifier/db" "blackforestbytes.com/simplecloudnotifier/db"
"blackforestbytes.com/simplecloudnotifier/google"
"blackforestbytes.com/simplecloudnotifier/jobs" "blackforestbytes.com/simplecloudnotifier/jobs"
"blackforestbytes.com/simplecloudnotifier/logic" "blackforestbytes.com/simplecloudnotifier/logic"
"blackforestbytes.com/simplecloudnotifier/push" "blackforestbytes.com/simplecloudnotifier/push"

View File

@ -1,15 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> {{template|header.[theme].html}}
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/docs -->
<title>Simple Cloud Notifications - API</title>
<!--<link rel="stylesheet" href="/css/mini-nord.min.css">-->
<!--<link rel="stylesheet" href="/css/mini-dark.min.css">-->
<link rel="stylesheet" href="/css/style.css">
<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.ico"/>
</head> </head>
<body> <body>
@ -18,10 +10,12 @@
<a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a> <a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a>
</div> </div>
<div id="mainpnl"> {{template|theme_switch.[theme].html}}
<a tabindex="-1" href="/documentation/swagger" class="button bordered" id="tl_linkDocs"><span class="icn-openapi"></span><span class="tl_btntxt">API Documentation</span></a>
<a tabindex="-1" href="/" class="button bordered" id="tr_link">Send</a> <div id="mainpnl">
<a tabindex="-1" href="/documentation/swagger" class="button bordered edge-btn" id="tl_linkDocs"><span class="icn-openapi"></span><span class="tl_btntxt">API Documentation</span></a>
<a tabindex="-1" href="/" class="button bordered edge-btn" id="tr_link">Send</a>
<a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a> <a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a>

View File

@ -1,15 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> {{template|header.[theme].html}}
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/docs -->
<title>Simple Cloud Notifications - API</title>
<!--<link rel="stylesheet" href="/css/mini-nord.min.css">-->
<!--<link rel="stylesheet" href="/css/mini-dark.min.css">-->
<link rel="stylesheet" href="/css/style.css">
<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.ico"/>
</head> </head>
<body> <body>
@ -18,10 +10,12 @@
<a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a> <a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a>
</div> </div>
<div id="mainpnl"> {{template|theme_switch.[theme].html}}
<a tabindex="-1" href="/documentation/swagger" class="button bordered" id="tl_linkDocs"><span class="icn-openapi"></span><span class="tl_btntxt">API Documentation</span></a>
<a tabindex="-1" href="/" class="button bordered" id="tr_link">Send</a> <div id="mainpnl">
<a tabindex="-1" href="/documentation/swagger" class="button bordered edge-btn" id="tl_linkDocs"><span class="icn-openapi"></span><span class="tl_btntxt">API Documentation</span></a>
<a tabindex="-1" href="/" class="button bordered edge-btn" id="tr_link">Send</a>
<a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a> <a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a>
@ -70,16 +64,10 @@
<pre class="red-code">{ <pre class="red-code">{
"success":true, "success":true,
"message":"Message sent", "message":"Message sent",
"response": "messagecount": 634,
{
"multicast_id":8000000000000000006,
"success":1,
"failure":0,
"canonical_ids":0,
"results": [{"message_id":"0:10000000000000000000000000000000d"}]
},
"quota":17, "quota":17,
"quota_max":100 "quota_max":100,
"scn_msg_id":993625
}</pre> }</pre>
<p> <p>
If the operation is <b>not</b> successful the API will respond with a 4xx or 500 HTTP statuscode. If the operation is <b>not</b> successful the API will respond with a 4xx or 500 HTTP statuscode.
@ -116,7 +104,7 @@
</table> </table>
<p> <p>
There is also always a JSON payload with additional information. There is also always a JSON payload with additional information.
The <code>success</code> field is always there and in the error state you the <code>message</code> field to get a descritpion of the problem. The <code>success</code> field is always there and in the error case you can read the <code>message</code> field to get a more information about the problem.
</p> </p>
<pre class="red-code">{ <pre class="red-code">{
"success": false, "success": false,
@ -162,7 +150,7 @@
{{config|baseURL}}/</pre> {{config|baseURL}}/</pre>
</div> </div>
<h2>Channels</h2> <h2>Channel</h2>
<div class="section"> <div class="section">
<p> <p>
By default all messages are sent to the user default channel (typically <code>main</code>) By default all messages are sent to the user default channel (typically <code>main</code>)
@ -222,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>
<pre style="color:#000000; margin: 0; line-height: 125%" class="yellow-code">{{template|scn_send.html}}</pre> {{template|scn_send.[theme].html}}
</div> </div>
</div> </div>

View File

@ -0,0 +1,34 @@
#mainpnl {
box-shadow: initial;
}
#mainpnl h1
{
text-align: center;
margin-top: 0;
margin-bottom: 24px;
font-weight: bold;
color: #CFCFCF;
text-shadow: #000 0 0 2px, #666 0 0 8px;
}
.edge-btn {
position: absolute;
border-color: #888 !important;
}
pre.yellow-code,
pre.yellow-code span {
background: none;
}
#theme-switch {
fill: #EA0;
}
#theme-switch:hover {
fill: #88F;
}

View File

@ -113,9 +113,12 @@ body
color: #0288D1; color: #0288D1;
} }
.edge-btn {
position: absolute;
}
#tr_link #tr_link
{ {
position: absolute;
top: 0; top: 0;
right: 0; right: 0;
margin: -1px -1px 0 0; margin: -1px -1px 0 0;
@ -127,7 +130,6 @@ body
#tl_link1 #tl_link1
{ {
position: absolute;
top: 0; top: 0;
left: 0; left: 0;
margin: -1px 0 0 -1px; margin: -1px 0 0 -1px;
@ -138,7 +140,6 @@ body
#tl_link2 #tl_link2
{ {
position: absolute;
top: 0; top: 0;
left: 48px; left: 48px;
margin: -1px 0 0 -1px; margin: -1px 0 0 -1px;
@ -149,7 +150,6 @@ body
#tl_linkDocs #tl_linkDocs
{ {
position: absolute;
top: 0; top: 0;
left: 0; left: 0;
margin: -1px 0 0 -1px; margin: -1px 0 0 -1px;
@ -298,3 +298,16 @@ pre, pre span
.display_none { .display_none {
display: none; display: none;
} }
#theme-switch {
position: absolute;
top: 0.75rem;
right: 0.75rem;
cursor: pointer;
fill: #000;
}
#theme-switch:hover {
filter: blur(1px);
fill: #008;
}

View File

@ -0,0 +1,14 @@
<meta charset="utf-8">
<title>Simple Cloud Notifications</title>
<link rel="stylesheet" href="/css/toastify.min.css"/>
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/ -->
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/mini-dark.min.css">
<link rel="stylesheet" href="/css/style-dark.css">
<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.ico"/>

View File

@ -0,0 +1,11 @@
<meta charset="utf-8">
<title>Simple Cloud Notifications</title>
<link rel="stylesheet" href="/css/toastify.min.css"/>
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/ -->
<link rel="stylesheet" href="/css/style.css">
<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.ico"/>

View File

@ -1,16 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> {{template|header.[theme].html}}
<title>Simple Cloud Notifications</title>
<link rel="stylesheet" href="/css/toastify.min.css"/>
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/ -->
<!--<link rel="stylesheet" href="/css/mini-nord.min.css">-->
<!--<link rel="stylesheet" href="/css/mini-dark.min.css">-->
<link rel="stylesheet" href="/css/style.css">
<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.ico"/>
</head> </head>
<body> <body>
@ -19,12 +10,14 @@
<a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a> <a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a>
</div> </div>
{{template|theme_switch.[theme].html}}
<form id="mainpnl"> <form id="mainpnl">
<a tabindex="-1" href="https://play.google.com/store/apps/details?id=com.blackforestbytes.simplecloudnotifier" class="button bordered" id="tl_link1"><span class="icn-google-play"></span></a> <a tabindex="-1" href="https://play.google.com/store/apps/details?id=com.blackforestbytes.simplecloudnotifier" class="button bordered edge-btn" id="tl_link1"><span class="icn-google-play"></span></a>
<a tabindex="-1" href="#" class="button bordered" id="tl_link2"><span class="icn-app-store"></span></a> <a tabindex="-1" href="#" class="button bordered edge-btn" id="tl_link2"><span class="icn-app-store"></span></a>
<a tabindex="-1" href="/api" class="button bordered" id="tr_link">API</a> <a tabindex="-1" href="/api" class="button bordered edge-btn" id="tr_link">API</a>
<a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a> <a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a>

View File

@ -1,15 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> {{template|header.[theme].html}}
<title>Simple Cloud Notifications</title>
<link rel="stylesheet" href="/css/mini-default.min.css"> <!-- https://minicss.org/docs -->
<!--<link rel="stylesheet" href="/css/mini-nord.min.css">-->
<!--<link rel="stylesheet" href="/css/mini-dark.min.css">-->
<link rel="stylesheet" href="/css/style.css">
<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.ico"/>
</head> </head>
<body> <body>
@ -18,12 +10,14 @@
<a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a> <a tabindex="-1" href="https://www.mikescher.com">made by Mike Schw&ouml;rer</a>
</div> </div>
<div id="mainpnl"> {{template|theme_switch.[theme].html}}
<a tabindex="-1" href="https://play.google.com/store/apps/details?id=com.blackforestbytes.simplecloudnotifier" class="button bordered" id="tl_link1"><span class="icn-google-play"></span></a> <div id="mainpnl">
<a tabindex="-1" href="#" class="button bordered" id="tl_link2"><span class="icn-app-store"></span></a>
<a tabindex="-1" href="/" class="button bordered" id="tr_link">Send</a> <a tabindex="-1" href="https://play.google.com/store/apps/details?id=com.blackforestbytes.simplecloudnotifier" class="button bordered edge-btn" id="tl_link1"><span class="icn-google-play"></span></a>
<a tabindex="-1" href="#" class="button bordered edge-btn" id="tl_link2"><span class="icn-app-store"></span></a>
<a tabindex="-1" href="/" class="button bordered edge-btn" id="tr_link">Send</a>
<a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a> <a tabindex="-1" href="/" class="linkcaption"><h1>Simple Cloud Notifier</h1></a>

View File

@ -0,0 +1,136 @@
<!-- 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 &quot;${title}&quot;</span>
<span style="color: #75715e"># or scn_send &quot;${title}&quot; ${content}&quot;</span>
<span style="color: #75715e"># or scn_send &quot;${title}&quot; ${content}&quot; &quot;${priority:0|1|2}&quot;</span>
<span style="color: #75715e"># or scn_send &quot;@${channel} &quot;${title}&quot;</span>
<span style="color: #75715e"># or scn_send &quot;@${channel} &quot;${title}&quot; ${content}&quot;</span>
<span style="color: #75715e"># or scn_send &quot;@${channel} &quot;${title}&quot; ${content}&quot; &quot;${priority:0|1|2}&quot;</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">&quot;999&quot;</span>
<span style="color: #f8f8f2">user_key</span><span style="color: #f92672">=</span><span style="color: #e6db74">&quot;??&quot;</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">&quot;Usage: &quot;</span>
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">&quot; scn_send [@channel] title [content] [priority]&quot;</span>
<span style="color: #f8f8f2">echo</span> <span style="color: #e6db74">&quot;&quot;</span>
<span style="color: #f92672">}</span>
<span style="color: #f8f8f2">args</span><span style="color: #f92672">=(</span> <span style="color: #e6db74">&quot;$@&quot;</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">&quot;&quot;</span>
<span style="color: #f8f8f2">channel</span><span style="color: #f92672">=</span><span style="color: #e6db74">&quot;&quot;</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: #66d9ef">$(</span>uuidgen<span style="color: #66d9ef">)</span>
<span style="color: #f8f8f2">sendtime</span><span style="color: #f92672">=</span><span style="color: #66d9ef">$(</span>date +%s<span style="color: #66d9ef">)</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">&quot;[ERROR]: no title supplied via parameter&quot;</span> 1&gt;&amp;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">&quot;${args[0]}&quot;</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">&quot;${args[0]}&quot;</span>
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">&quot;args[0]&quot;</span>
<span style="color: #f8f8f2">channel</span><span style="color: #f92672">=</span><span style="color: #e6db74">&quot;${channel:1}&quot;</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">&quot;[ERROR]: no title supplied via parameter&quot;</span> 1&gt;&amp;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">&quot;${args[0]}&quot;</span>
<span style="color: #f8f8f2">content</span><span style="color: #f92672">=</span><span style="color: #e6db74">&quot;&quot;</span>
<span style="color: #f8f8f2">sendtime</span><span style="color: #f92672">=</span><span style="color: #66d9ef">$(</span>date +%s<span style="color: #66d9ef">)</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">&quot;${args[0]}&quot;</span>
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">&quot;args[0]&quot;</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">&quot;${args[0]}&quot;</span>
<span style="color: #f8f8f2">unset</span> <span style="color: #e6db74">&quot;args[0]&quot;</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">&quot;Too many arguments to scn_send&quot;</span> 1&gt;&amp;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">&quot;%{http_code}&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;user_id=$user_id&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;user_key=$user_key&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;title=$title&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;timestamp=$sendtime&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;content=$content&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;priority=$priority&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;msg_id=$usr_msg_id&quot;</span> <span style="color: #ae81ff">\</span>
--data <span style="color: #e6db74">&quot;channel=$channel&quot;</span> <span style="color: #ae81ff">\</span>
<span style="color: #e6db74">&quot;https://scn.blackforestbytes.com/&quot;</span> <span style="color: #66d9ef">)</span>
<span style="color: #66d9ef">if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">&quot;$curlresp&quot;</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">&quot;Successfully send&quot;</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">&quot;$curlresp&quot;</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">&quot;Bad request - something went wrong&quot;</span> 1&gt;&amp;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">&quot;$curlresp&quot;</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">&quot;Unauthorized - wrong userid/userkey&quot;</span> 1&gt;&amp;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">&quot;$curlresp&quot;</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">&quot;Quota exceeded - wait one hour before re-try&quot;</span> 1&gt;&amp;2
sleep 3600
<span style="color: #66d9ef">fi</span>
<span style="color: #66d9ef"> if</span> <span style="color: #f92672">[</span> <span style="color: #e6db74">&quot;$curlresp&quot;</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">&quot;Precondition Failed - No device linked&quot;</span> 1&gt;&amp;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">&quot;$curlresp&quot;</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">&quot;Internal server error - waiting for better times&quot;</span> 1&gt;&amp;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">&quot;Send failed (response code $curlresp) ... try again in 5s&quot;</span> 1&gt;&amp;2
sleep 5
<span style="color: #66d9ef">done</span>
</pre>

View File

@ -1,7 +1,10 @@
<!-- https://hilite.me/ | bash | borland --> <!-- https://hilite.me/ | bash | borland -->
<!-- HTML generated using hilite.me --><span style="color: #008800; font-style: italic">#!/usr/bin/env bash</span> <!-- 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">#</span>
<span style="color: #008800; font-style: italic"># Wrapper around SCN ( https://scn.blackforestbytes.com/ )</span> <span style="color: #008800; font-style: italic"># Wrapper around SCN ( https://scn.blackforestbytes.com/ )</span>
@ -129,3 +132,4 @@ sendtime=<span style="color: #000080; font-weight: bold">$(</span>date +%s<span
echo <span style="color: #0000FF">&quot;Send failed (response code $curlresp) ... try again in 5s&quot;</span> 1&gt;&amp;2 echo <span style="color: #0000FF">&quot;Send failed (response code $curlresp) ... try again in 5s&quot;</span> 1&gt;&amp;2
sleep 5 sleep 5
<span style="color: #000080; font-weight: bold">done</span> <span style="color: #000080; font-weight: bold">done</span>
</pre>

View File

@ -0,0 +1,26 @@
<div id="theme-switch">
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="32px" height="32px" viewBox="0 0 493.761 493.762">
<path d="M290.652,402.646h-87.595c-6.781,0-12.283,5.503-12.283,12.283c0,6.785,5.502,12.287,12.283,12.287h87.595 c6.781,0,12.289-5.502,12.289-12.287C302.942,408.149,297.435,402.646,290.652,402.646z"/>
<path d="M224.299,474.245c1.666,11.026,11.086,19.517,22.586,19.517c11.488,0,20.93-8.487,22.589-19.517 c15.037-0.888,26.987-13.245,26.987-28.504H197.25C197.25,461.009,209.235,473.375,224.299,474.245z"/>
<path d="M246.884,70.87c9.062,0,16.387-7.335,16.387-16.381V16.381C263.271,7.332,255.947,0,246.884,0 c-9.053,0-16.377,7.332-16.377,16.381v38.108C230.508,63.535,237.832,70.87,246.884,70.87z"/>
<path d="M139.39,94.736c3.217,4.417,8.209,6.761,13.283,6.761c3.326,0,6.699-1.017,9.609-3.129 c7.313-5.312,8.945-15.555,3.633-22.873l-22.396-30.84c-5.326-7.312-15.549-8.96-22.887-3.632 c-7.311,5.309-8.943,15.555-3.631,22.873L139.39,94.736z"/>
<path d="M354.354,334.861c-5.313-7.312-15.549-8.934-22.881-3.621c-7.306,5.317-8.937,15.562-3.61,22.879l22.409,30.841 c3.196,4.407,8.188,6.753,13.265,6.753c3.338,0,6.698-1.017,9.608-3.128c7.312-5.319,8.942-15.565,3.619-22.884L354.354,334.861 z"/>
<path d="M99.502,149.684l-36.252-11.79c-8.686-2.799-17.846,1.911-20.648,10.518c-2.803,8.597,1.904,17.843,10.508,20.642 l36.252,11.79c1.693,0.544,3.387,0.809,5.066,0.809c6.91,0,13.324-4.4,15.582-11.327 C112.812,161.729,108.106,152.482,99.502,149.684z"/>
<path d="M440.649,260.538l-36.243-11.773c-8.611-2.778-17.841,1.918-20.638,10.516c-2.802,8.606,1.918,17.848,10.521,20.646 l36.252,11.772c1.681,0.545,3.373,0.807,5.054,0.807c6.909,0,13.323-4.407,15.581-11.324 C453.971,272.572,449.258,263.337,440.649,260.538z"/>
<path d="M89.375,248.765L53.11,260.522c-8.604,2.79-13.324,12.026-10.521,20.635c2.238,6.927,8.664,11.334,15.574,11.334 c1.668,0,3.381-0.267,5.061-0.811l36.258-11.756c8.611-2.792,13.33-12.03,10.529-20.635 C107.229,250.689,98.059,245.986,89.375,248.765z"/>
<path d="M399.35,181.653c1.681,0,3.373-0.265,5.056-0.809l36.243-11.773c8.608-2.799,13.322-12.039,10.526-20.642 c-2.803-8.6-12.077-13.3-20.635-10.518l-36.252,11.772c-8.604,2.798-13.322,12.038-10.521,20.642 C386.02,177.246,392.44,181.653,399.35,181.653z"/>
<path d="M139.412,334.855l-22.431,30.822c-5.326,7.318-3.707,17.563,3.619,22.883c2.896,2.119,6.27,3.138,9.609,3.138 c5.074,0,10.066-2.336,13.264-6.744l22.43-30.824c5.326-7.316,3.707-17.562-3.619-22.883 C154.991,325.898,144.702,327.538,139.412,334.855z"/>
<path d="M350.258,44.654l-22.396,30.84c-5.312,7.318-3.681,17.562,3.633,22.873c2.91,2.112,6.283,3.129,9.608,3.129 c5.074,0,10.065-2.343,13.276-6.761l22.396-30.841c5.311-7.318,3.68-17.564-3.634-22.873 C365.786,35.68,355.584,37.326,350.258,44.654z"/>
<path d="M365.194,215.404c0-65.354-52.976-118.333-118.322-118.333c-65.359,0-118.336,52.979-118.336,118.333 c0,27.569,9.482,52.884,25.322,72.981c13.881,17.612,27.027,36.839,38.42,56.187v39.306h108.516v-38.263 c11.288-18.818,25.881-40.484,39.065-57.211C355.713,268.301,365.194,242.991,365.194,215.404z"/>
</svg>
</div>
<script type="application/javascript">
window.addEventListener("load", function () {
document.getElementById("theme-switch").onclick = function () {
document.cookie = "theme=light";
location.reload();
return false;
};
});
</script>

View File

@ -0,0 +1,26 @@
<div id="theme-switch">
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="32px" height="32px" viewBox="0 0 493.761 493.762">
<path d="M290.652,402.646h-87.595c-6.781,0-12.283,5.503-12.283,12.283c0,6.785,5.502,12.287,12.283,12.287h87.595 c6.781,0,12.289-5.502,12.289-12.287C302.942,408.149,297.435,402.646,290.652,402.646z"/>
<path d="M224.299,474.245c1.666,11.026,11.086,19.517,22.586,19.517c11.488,0,20.93-8.487,22.589-19.517 c15.037-0.888,26.987-13.245,26.987-28.504H197.25C197.25,461.009,209.235,473.375,224.299,474.245z"/>
<path d="M246.884,70.87c9.062,0,16.387-7.335,16.387-16.381V16.381C263.271,7.332,255.947,0,246.884,0 c-9.053,0-16.377,7.332-16.377,16.381v38.108C230.508,63.535,237.832,70.87,246.884,70.87z"/>
<path d="M139.39,94.736c3.217,4.417,8.209,6.761,13.283,6.761c3.326,0,6.699-1.017,9.609-3.129 c7.313-5.312,8.945-15.555,3.633-22.873l-22.396-30.84c-5.326-7.312-15.549-8.96-22.887-3.632 c-7.311,5.309-8.943,15.555-3.631,22.873L139.39,94.736z"/>
<path d="M354.354,334.861c-5.313-7.312-15.549-8.934-22.881-3.621c-7.306,5.317-8.937,15.562-3.61,22.879l22.409,30.841 c3.196,4.407,8.188,6.753,13.265,6.753c3.338,0,6.698-1.017,9.608-3.128c7.312-5.319,8.942-15.565,3.619-22.884L354.354,334.861 z"/>
<path d="M99.502,149.684l-36.252-11.79c-8.686-2.799-17.846,1.911-20.648,10.518c-2.803,8.597,1.904,17.843,10.508,20.642 l36.252,11.79c1.693,0.544,3.387,0.809,5.066,0.809c6.91,0,13.324-4.4,15.582-11.327 C112.812,161.729,108.106,152.482,99.502,149.684z"/>
<path d="M440.649,260.538l-36.243-11.773c-8.611-2.778-17.841,1.918-20.638,10.516c-2.802,8.606,1.918,17.848,10.521,20.646 l36.252,11.772c1.681,0.545,3.373,0.807,5.054,0.807c6.909,0,13.323-4.407,15.581-11.324 C453.971,272.572,449.258,263.337,440.649,260.538z"/>
<path d="M89.375,248.765L53.11,260.522c-8.604,2.79-13.324,12.026-10.521,20.635c2.238,6.927,8.664,11.334,15.574,11.334 c1.668,0,3.381-0.267,5.061-0.811l36.258-11.756c8.611-2.792,13.33-12.03,10.529-20.635 C107.229,250.689,98.059,245.986,89.375,248.765z"/>
<path d="M399.35,181.653c1.681,0,3.373-0.265,5.056-0.809l36.243-11.773c8.608-2.799,13.322-12.039,10.526-20.642 c-2.803-8.6-12.077-13.3-20.635-10.518l-36.252,11.772c-8.604,2.798-13.322,12.038-10.521,20.642 C386.02,177.246,392.44,181.653,399.35,181.653z"/>
<path d="M139.412,334.855l-22.431,30.822c-5.326,7.318-3.707,17.563,3.619,22.883c2.896,2.119,6.27,3.138,9.609,3.138 c5.074,0,10.066-2.336,13.264-6.744l22.43-30.824c5.326-7.316,3.707-17.562-3.619-22.883 C154.991,325.898,144.702,327.538,139.412,334.855z"/>
<path d="M350.258,44.654l-22.396,30.84c-5.312,7.318-3.681,17.562,3.633,22.873c2.91,2.112,6.283,3.129,9.608,3.129 c5.074,0,10.065-2.343,13.276-6.761l22.396-30.841c5.311-7.318,3.68-17.564-3.634-22.873 C365.786,35.68,355.584,37.326,350.258,44.654z"/>
<path d="M365.194,215.404c0-65.354-52.976-118.333-118.322-118.333c-65.359,0-118.336,52.979-118.336,118.333 c0,27.569,9.482,52.884,25.322,72.981c13.881,17.612,27.027,36.839,38.42,56.187v39.306h108.516v-38.263 c11.288-18.818,25.881-40.484,39.065-57.211C355.713,268.301,365.194,242.991,365.194,215.404z"/>
</svg>
</div>
<script type="application/javascript">
window.addEventListener("load", function () {
document.getElementById("theme-switch").onclick = function () {
document.cookie = "theme=dark";
location.reload();
return false;
};
});
</script>