| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_NTFY_UI_HTML_H |
| 3 | #define SX_NTFY_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>ntfy</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);\n" |
| 15 | " font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | ".wrap{max-width:1080px;margin:0 auto;padding:16px 16px 40px}\n" |
| 17 | ".top{display:flex;align-items:center;gap:10px;margin-bottom:6px;flex-wrap:wrap}\n" |
| 18 | ".title{font-size:19px;font-weight:700;margin:0;letter-spacing:-.01em}\n" |
| 19 | ".pill{font-size:11px;font-weight:600;padding:2px 9px;border-radius:999px;\n" |
| 20 | " background:var(--surface-2);color:var(--text-2);border:1px solid var(--line);white-space:nowrap}\n" |
| 21 | ".pill.ok{color:var(--green);border-color:rgba(48,209,88,.35);background:rgba(48,209,88,.12)}\n" |
| 22 | ".pill.bad{color:var(--red);border-color:rgba(255,69,58,.35);background:rgba(255,69,58,.12)}\n" |
| 23 | ".pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35);background:rgba(255,159,10,.12)}\n" |
| 24 | ".sp{flex:1}\n" |
| 25 | ".icon{display:inline-flex;align-items:center;justify-content:center;gap:6px;\n" |
| 26 | " background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n" |
| 27 | " border-radius:9px;min-width:30px;height:30px;padding:0 8px;cursor:pointer;font-family:inherit;\n" |
| 28 | " font-size:12px;font-weight:600}\n" |
| 29 | ".icon:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 30 | ".icon svg{width:15px;height:15px;display:block;fill:none;stroke:currentColor;\n" |
| 31 | " stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}\n" |
| 32 | ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:8px 15px;\n" |
| 33 | " font-weight:600;font-size:13px;cursor:pointer;font-family:inherit}\n" |
| 34 | ".btn:disabled{opacity:.55;cursor:default}\n" |
| 35 | ".btn.gh{background:transparent;color:var(--text);border:1px solid var(--line)}\n" |
| 36 | ".btn.gr{background:var(--green);color:#04210d}\n" |
| 37 | ".btn.rd{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.4)}\n" |
| 38 | ".btn.sm{padding:5px 11px;font-size:12px}\n" |
| 39 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;\n" |
| 40 | " padding:16px;margin-bottom:14px;box-shadow:var(--shadow)}\n" |
| 41 | ".card h2{margin:0 0 10px;font-size:11.5px;letter-spacing:.07em;text-transform:uppercase;\n" |
| 42 | " color:var(--text-2);font-weight:600}\n" |
| 43 | ".hint{color:var(--text-2);font-size:12px;margin:0 0 12px}\n" |
| 44 | ".hint code{font-family:var(--mono);font-size:11.5px;background:var(--surface-2);\n" |
| 45 | " border:1px solid var(--line);border-radius:5px;padding:1px 5px}\n" |
| 46 | ".grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(215px,1fr));gap:10px}\n" |
| 47 | ".kpi{background:var(--surface-2);border:1px solid var(--line);border-radius:10px;padding:10px 12px}\n" |
| 48 | ".kpi .k{font-size:10.5px;color:var(--text-2);text-transform:uppercase;letter-spacing:.05em}\n" |
| 49 | ".kpi .v{font-size:15px;font-weight:700;font-family:var(--mono);margin-top:3px;word-break:break-word}\n" |
| 50 | "label{display:block;font-size:11.5px;color:var(--text-2);margin:0 0 4px;\n" |
| 51 | " text-transform:uppercase;letter-spacing:.05em;font-weight:600}\n" |
| 52 | "input[type=text],input[type=password],select,textarea{width:100%;background:var(--surface-2);\n" |
| 53 | " border:1px solid var(--line);color:var(--text);border-radius:9px;padding:8px 10px;\n" |
| 54 | " font-family:var(--mono);font-size:12.5px;outline:none}\n" |
| 55 | "input:focus,textarea:focus,select:focus{border-color:var(--blue)}\n" |
| 56 | "textarea{min-height:66px;resize:vertical}\n" |
| 57 | ".row{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:12px}\n" |
| 58 | ".row.one{grid-template-columns:1fr}\n" |
| 59 | ".check{display:flex;align-items:center;gap:8px;margin:0 0 10px;font-size:13px;color:var(--text)}\n" |
| 60 | ".check input{width:15px;height:15px;accent-color:var(--blue)}\n" |
| 61 | ".check span{color:var(--text);text-transform:none;letter-spacing:0;font-weight:500}\n" |
| 62 | ".actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:4px}\n" |
| 63 | ".tb{width:100%;overflow-x:auto}\n" |
| 64 | "table{width:100%;border-collapse:collapse;font-size:12.5px}\n" |
| 65 | "th{text-align:left;font-size:10.5px;text-transform:uppercase;letter-spacing:.05em;\n" |
| 66 | " color:var(--text-2);font-weight:600;padding:6px 8px;border-bottom:1px solid var(--line);white-space:nowrap}\n" |
| 67 | "td{padding:8px;border-bottom:1px solid var(--line);vertical-align:top;word-break:break-word}\n" |
| 68 | ".mono{font-family:var(--mono);font-size:11.5px}\n" |
| 69 | ".empty{color:var(--text-2);font-size:12.5px;padding:10px 0}\n" |
| 70 | "pre.log{background:var(--bg-2);border:1px solid var(--line);border-radius:10px;\n" |
| 71 | " padding:10px;font-family:var(--mono);font-size:11px;max-height:280px;overflow:auto;\n" |
| 72 | " white-space:pre-wrap;word-break:break-word;margin:0;color:var(--text-2)}\n" |
| 73 | ".msg{font-size:12.5px;border-radius:9px;padding:9px 11px;margin:0 0 12px;display:none}\n" |
| 74 | ".msg.show{display:block}\n" |
| 75 | ".msg.ok{background:rgba(48,209,88,.12);border:1px solid rgba(48,209,88,.35);color:var(--green)}\n" |
| 76 | ".msg.err{background:rgba(255,69,58,.12);border:1px solid rgba(255,69,58,.35);color:var(--red)}\n" |
| 77 | ".msg.info{background:var(--surface-2);border:1px solid var(--line);color:var(--text-2)}\n" |
| 78 | ".tabs{display:flex;gap:6px;margin-bottom:14px;flex-wrap:wrap}\n" |
| 79 | ".tab{background:var(--surface-2);border:1px solid var(--line);color:var(--text-2);\n" |
| 80 | " border-radius:980px;padding:6px 14px;font-size:12.5px;font-weight:600;cursor:pointer;\n" |
| 81 | " font-family:inherit}\n" |
| 82 | ".tab[aria-selected=true]{background:var(--blue);border-color:var(--blue);color:#fff}\n" |
| 83 | ".sec{display:none}\n" |
| 84 | ".sec.show{display:block}\n" |
| 85 | ".tag{display:inline-block;font-size:10.5px;font-weight:700;padding:1px 7px;border-radius:999px;\n" |
| 86 | " background:var(--surface-2);border:1px solid var(--line);color:var(--text-2);\n" |
| 87 | " font-family:var(--mono);text-transform:lowercase}\n" |
| 88 | ".key{font-family:var(--mono);font-size:10.5px;color:var(--text-2);word-break:break-all}\n" |
| 89 | ".foot{color:var(--text-2);font-size:11.5px;text-align:center;padding:10px 0 0}\n" |
| 90 | ".foot a{color:var(--text-2)}\n" |
| 91 | "@media (max-width:720px){.row{grid-template-columns:1fr}.wrap{padding:12px 12px 32px}\n" |
| 92 | " td,th{padding:6px 5px}}\n" |
| 93 | "</style></head>\n" |
| 94 | "<body>\n" |
| 95 | "<div class=\"wrap\">\n" |
| 96 | " <div class=\"top\">\n" |
| 97 | " <h1 class=\"title\">ntfy</h1>\n" |
| 98 | " <span class=\"pill\" id=\"kindPill\">hybrid connector</span>\n" |
| 99 | " <span class=\"pill\" id=\"runPill\">daemon: checking</span>\n" |
| 100 | " <span class=\"pill\" id=\"tlsPill\">tls: -</span>\n" |
| 101 | " <span class=\"sp\"></span>\n" |
| 102 | " <button class=\"icon\" id=\"themeBtn\" type=\"button\" title=\"Theme\" aria-label=\"Theme\">\n" |
| 103 | " <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><circle cx=\"12\" cy=\"12\" r=\"4.2\"/>\n" |
| 104 | " <path d=\"M12 2.6v2.1M12 19.3v2.1M2.6 12h2.1M19.3 12h2.1M5.3 5.3l1.5 1.5M17.2 17.2l1.5 1.5M18.7 5.3l-1.5 1.5M6.8 17.2l-1.5 1.5\"/></svg>\n" |
| 105 | " </button>\n" |
| 106 | " </div>\n" |
| 107 | " <p class=\"hint\" style=\"margin:0 0 14px\">Push notifications and a two-way chat channel over\n" |
| 108 | " <span class=\"mono\">ntfy</span>. Inbound messages from <b>approved senders only</b> go to a SCORPIOX BOT\n" |
| 109 | " session; the agent's replies come back to your phone. Nothing is forwarded until you approve it here.</p>\n" |
| 110 | "\n" |
| 111 | " <div class=\"msg\" id=\"msg\"></div>\n" |
| 112 | "\n" |
| 113 | " <div class=\"tabs\" role=\"tablist\">\n" |
| 114 | " <button class=\"tab\" role=\"tab\" id=\"tabStatus\" aria-selected=\"true\" data-sec=\"st\">Status</button>\n" |
| 115 | " <button class=\"tab\" role=\"tab\" id=\"tabSetup\" aria-selected=\"false\" data-sec=\"sf\">Setup</button>\n" |
| 116 | " <button class=\"tab\" role=\"tab\" id=\"tabPair\" aria-selected=\"false\" data-sec=\"pr\">Pairing <span id=\"pendCount\"></span></button>\n" |
| 117 | " <button class=\"tab\" role=\"tab\" id=\"tabSend\" aria-selected=\"false\" data-sec=\"sn\">Send test</button>\n" |
| 118 | " <button class=\"tab\" role=\"tab\" id=\"tabLog\" aria-selected=\"false\" data-sec=\"lg\">Log</button>\n" |
| 119 | " </div>\n" |
| 120 | "\n" |
| 121 | " <!-- status -->\n" |
| 122 | " <div class=\"sec show\" id=\"sec-st\">\n" |
| 123 | " <div class=\"card\">\n" |
| 124 | " <h2>Gateway</h2>\n" |
| 125 | " <div class=\"grid\" id=\"kpis\"></div>\n" |
| 126 | " <div class=\"actions\" style=\"margin-top:12px\">\n" |
| 127 | " <button class=\"btn gr\" id=\"startBtn\" type=\"button\">Start daemon</button>\n" |
| 128 | " <button class=\"btn rd\" id=\"stopBtn\" type=\"button\">Stop daemon</button>\n" |
| 129 | " <button class=\"btn gh\" id=\"refreshBtn\" type=\"button\">Refresh</button>\n" |
| 130 | " </div>\n" |
| 131 | " </div>\n" |
| 132 | " </div>\n" |
| 133 | "\n" |
| 134 | " <!-- setup -->\n" |
| 135 | " <div class=\"sec\" id=\"sec-sf\">\n" |
| 136 | " <div class=\"card\">\n" |
| 137 | " <h2>ntfy server</h2>\n" |
| 138 | " <p class=\"hint\">Any ntfy server works: the public <span class=\"mono\">https://ntfy.sh</span> or your own\n" |
| 139 | " self-hosted one. For a private CA add a PEM bundle path, or pin the server key\n" |
| 140 | " (<span class=\"mono\">allowed_pins</span>, comma-separated SHA-256 of the leaf SPKI).</p>\n" |
| 141 | " <div class=\"row\">\n" |
| 142 | " <div><label for=\"f_server\">Server URL</label>\n" |
| 143 | " <input type=\"text\" id=\"f_server\" placeholder=\"https://ntfy.sh\" autocomplete=\"off\"></div>\n" |
| 144 | " <div><label for=\"f_token\">Access token (write-only)</label>\n" |
| 145 | " <input type=\"password\" id=\"f_token\" placeholder=\"Bearer xyz / Basic b64\" autocomplete=\"new-password\">\n" |
| 146 | " <span class=\"mono\" id=\"tokState\"></span></div>\n" |
| 147 | " </div>\n" |
| 148 | " <div class=\"row\">\n" |
| 149 | " <div><label for=\"f_topic\">Subscribe topic (inbound)</label>\n" |
| 150 | " <input type=\"text\" id=\"f_topic\" placeholder=\"hermes-in\" autocomplete=\"off\"></div>\n" |
| 151 | " <div><label for=\"f_ptopic\">Publish topic (replies)</label>\n" |
| 152 | " <input type=\"text\" id=\"f_ptopic\" placeholder=\"same as subscribe\" autocomplete=\"off\"></div>\n" |
| 153 | " </div>\n" |
| 154 | " <div class=\"row\">\n" |
| 155 | " <div><label for=\"f_ca\">Extra CA bundle path</label>\n" |
| 156 | " <input type=\"text\" id=\"f_ca\" placeholder=\"/etc/ssl/certs/my-relay-ca.pem\" autocomplete=\"off\"></div>\n" |
| 157 | " <div><label for=\"f_pins\">Allowed pins (SHA-256, comma separated)</label>\n" |
| 158 | " <input type=\"text\" id=\"f_pins\" placeholder=\"ab12... (64 hex)\" autocomplete=\"off\"></div>\n" |
| 159 | " </div>\n" |
| 160 | " </div>\n" |
| 161 | "\n" |
| 162 | " <div class=\"card\">\n" |
| 163 | " <h2>SCORPIOX BOT bridge</h2>\n" |
| 164 | " <p class=\"hint\">Inbound messages are posted to this node's\n" |
| 165 | " <span class=\"mono\">POST /inbox?id=<session></span> and the assistant's newest reply is published\n" |
| 166 | " back. The node password stays on the node: it is write-only here.</p>\n" |
| 167 | " <div class=\"row\">\n" |
| 168 | " <div><label for=\"f_session\">Target session</label>\n" |
| 169 | " <input type=\"text\" id=\"f_session\" placeholder=\"my-session\" autocomplete=\"off\"></div>\n" |
| 170 | " <div><label for=\"f_api\">Node API URL</label>\n" |
| 171 | " <input type=\"text\" id=\"f_api\" placeholder=\"http://127.0.0.1:8150\" autocomplete=\"off\"></div>\n" |
| 172 | " </div>\n" |
| 173 | " <div class=\"row\">\n" |
| 174 | " <div><label for=\"f_pwd\">Node password (write-only)</label>\n" |
| 175 | " <input type=\"password\" id=\"f_pwd\" placeholder=\"leave blank to keep\" autocomplete=\"new-password\">\n" |
| 176 | " <span class=\"mono\" id=\"pwdState\"></span></div>\n" |
| 177 | " <div><label for=\"f_reply\">Reply prefix</label>\n" |
| 178 | " <input type=\"text\" id=\"f_reply\" placeholder=\"BOT: \" autocomplete=\"off\"></div>\n" |
| 179 | " </div>\n" |
| 180 | " <div class=\"row\">\n" |
| 181 | " <div><label for=\"f_title\">Reply title</label>\n" |
| 182 | " <input type=\"text\" id=\"f_title\" placeholder=\"SCORPIOX BOT\" autocomplete=\"off\"></div>\n" |
| 183 | " <div><label for=\"f_tags\">Tags on replies</label>\n" |
| 184 | " <input type=\"text\" id=\"f_tags\" placeholder=\"robot\" autocomplete=\"off\"></div>\n" |
| 185 | " </div>\n" |
| 186 | " <div class=\"row\">\n" |
| 187 | " <div><label for=\"f_prio\">Priority (1-5)</label>\n" |
| 188 | " <input type=\"text\" id=\"f_prio\" placeholder=\"3\" autocomplete=\"off\"></div>\n" |
| 189 | " <div><label for=\"f_poll\">Reply poll (ms)</label>\n" |
| 190 | " <input type=\"text\" id=\"f_poll\" placeholder=\"700\" autocomplete=\"off\"></div>\n" |
| 191 | " </div>\n" |
| 192 | " <div class=\"check\"><input type=\"checkbox\" id=\"f_md\"><span>Send replies as Markdown</span></div>\n" |
| 193 | " <div class=\"check\"><input type=\"checkbox\" id=\"f_pair\"><span>Accept <b>PAIR <code></b> on the topic (pairing by code)</span></div>\n" |
| 194 | " <div class=\"check\"><input type=\"checkbox\" id=\"f_all\"><span>Allow every sender (development only — disables the allowlist)</span></div>\n" |
| 195 | " <div class=\"actions\">\n" |
| 196 | " <button class=\"btn\" id=\"saveBtn\" type=\"button\">Save</button>\n" |
| 197 | " <button class=\"btn gh\" id=\"testBtn\" type=\"button\">Send test notification</button>\n" |
| 198 | " </div>\n" |
| 199 | " </div>\n" |
| 200 | " </div>\n" |
| 201 | "\n" |
| 202 | " <!-- pairing -->\n" |
| 203 | " <div class=\"sec\" id=\"sec-pr\">\n" |
| 204 | " <div class=\"card\">\n" |
| 205 | " <h2>Pending approval</h2>\n" |
| 206 | " <p class=\"hint\">Default-deny: an unknown sender is held here and <b>never</b> reaches the agent.\n" |
| 207 | " Approve the row, or have the sender publish <span class=\"mono\">PAIR <code></span> on the topic.\n" |
| 208 | " The identity is a hash of the publisher's claimed user + tags + topic — ntfy cannot prove who sent\n" |
| 209 | " anything, which is exactly why this gate exists.</p>\n" |
| 210 | " <div class=\"tb\"><table><thead><tr><th>Sender</th><th>Sample</th><th>Code</th><th>Seen</th><th></th></tr></thead>\n" |
| 211 | " <tbody id=\"pendBody\"><tr><td colspan=\"5\" class=\"empty\">Loading...</td></tr></tbody></table></div>\n" |
| 212 | " </div>\n" |
| 213 | " <div class=\"card\">\n" |
| 214 | " <h2>Approved senders</h2>\n" |
| 215 | " <div class=\"tb\"><table><thead><tr><th>Sender</th><th>Messages</th><th>Added</th><th>Via</th><th></th></tr></thead>\n" |
| 216 | " <tbody id=\"apprBody\"><tr><td colspan=\"5\" class=\"empty\">Loading...</td></tr></tbody></table></div>\n" |
| 217 | " </div>\n" |
| 218 | " </div>\n" |
| 219 | "\n" |
| 220 | " <!-- send -->\n" |
| 221 | " <div class=\"sec\" id=\"sec-sn\">\n" |
| 222 | " <div class=\"card\">\n" |
| 223 | " <h2>Publish a notification</h2>\n" |
| 224 | " <p class=\"hint\">The same call the agent makes through the <span class=\"mono\">ntfy_send</span> MCP tool.</p>\n" |
| 225 | " <div class=\"row\"><div><label for=\"s_topic\">Topic (blank = publish topic)</label>\n" |
| 226 | " <input type=\"text\" id=\"s_topic\" autocomplete=\"off\"></div>\n" |
| 227 | " <div><label for=\"s_title\">Title</label><input type=\"text\" id=\"s_title\" autocomplete=\"off\"></div></div>\n" |
| 228 | " <div class=\"row one\"><div><label for=\"s_tags\">Tags</label>\n" |
| 229 | " <input type=\"text\" id=\"s_tags\" placeholder=\"warning,bell\" autocomplete=\"off\"></div></div>\n" |
| 230 | " <div class=\"row one\"><div><label for=\"s_msg\">Message</label>\n" |
| 231 | " <textarea id=\"s_msg\" placeholder=\"Backup finished in 4 minutes.\"></textarea></div></div>\n" |
| 232 | " <div class=\"actions\"><button class=\"btn\" id=\"sendBtn\" type=\"button\">Publish</button></div>\n" |
| 233 | " </div>\n" |
| 234 | " </div>\n" |
| 235 | "\n" |
| 236 | " <!-- log -->\n" |
| 237 | " <div class=\"sec\" id=\"sec-lg\">\n" |
| 238 | " <div class=\"card\">\n" |
| 239 | " <h2>Daemon log (tail)</h2>\n" |
| 240 | " <pre class=\"log\" id=\"logBox\">Loading...</pre>\n" |
| 241 | " <div class=\"actions\"><button class=\"btn gh\" id=\"logBtn\" type=\"button\">Reload log</button></div>\n" |
| 242 | " </div>\n" |
| 243 | " </div>\n" |
| 244 | "\n" |
| 245 | " <p class=\"foot\">part of SCORPIOX BOT · open source at plugingit.scorpiox.net ·\n" |
| 246 | " <span id=\"verTxt\"></span></p>\n" |
| 247 | "</div>\n" |
| 248 | "\n" |
| 249 | "<script>\n" |
| 250 | "(function(){\n" |
| 251 | "'use strict';\n" |
| 252 | "var $=function(i){return document.getElementById(i);};\n" |
| 253 | "function esc(s){return String(s==null?'':s).replace(/[&<>\"']/g,function(c){\n" |
| 254 | " return {'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c];});}\n" |
| 255 | "function qs(){var h=window.location.search||'';return h;}\n" |
| 256 | "function tok(){var m=/(?:^|[?&])pwd=([^&]*)/.exec(qs());return m?('&pwd='+m[1]):'';}\n" |
| 257 | "function say(kind,text){var m=$('msg');m.className='msg show '+kind;m.textContent=text;\n" |
| 258 | " if(kind==='ok'){setTimeout(function(){m.className='msg';},4200);}}\n" |
| 259 | "function api(action,params,cb){\n" |
| 260 | " var u='?action='+action+tok();\n" |
| 261 | " var body=null;\n" |
| 262 | " if(params){body=JSON.stringify(params);u='?action='+action+tok();}\n" |
| 263 | " var o={method:params?'POST':'GET',headers:{},credentials:'same-origin'};\n" |
| 264 | " if(params){o.headers['Content-Type']='application/json';o.body=body;}\n" |
| 265 | " fetch(u,o).then(function(r){return r.json().then(function(j){return {s:r.status,j:j};});})\n" |
| 266 | " .then(function(x){cb(null,x);}).catch(function(e){cb(e,null);});\n" |
| 267 | "}\n" |
| 268 | "function clock(){var d=new Date();return d.toLocaleTimeString([],{hour:'2-digit',minute:'2-digit',second:'2-digit'});}\n" |
| 269 | "\n" |
| 270 | "/* tabs */\n" |
| 271 | "var tabs=[].slice.call(document.querySelectorAll('.tab'));\n" |
| 272 | "tabs.forEach(function(t){t.addEventListener('click',function(){\n" |
| 273 | " tabs.forEach(function(x){x.setAttribute('aria-selected', x===t?'true':'false');});\n" |
| 274 | " [].slice.call(document.querySelectorAll('.sec')).forEach(function(s){s.className='sec';});\n" |
| 275 | " var s=$('sec-'+t.getAttribute('data-sec')); if(s) s.className='sec show';\n" |
| 276 | " if(t.getAttribute('data-sec')==='pr'){loadPending();loadApproved();}\n" |
| 277 | " if(t.getAttribute('data-sec')==='lg'){loadLog();}\n" |
| 278 | "});});\n" |
| 279 | "\n" |
| 280 | "/* theme button */\n" |
| 281 | "$('themeBtn').addEventListener('click',function(){\n" |
| 282 | " var cur=document.documentElement.getAttribute('data-theme')==='light'?'light':'dark';\n" |
| 283 | " var nx=cur==='light'?'dark':'light';\n" |
| 284 | " document.documentElement.setAttribute('data-theme',nx);\n" |
| 285 | " try{localStorage.setItem('bot_theme',nx);}catch(e){}\n" |
| 286 | "});\n" |
| 287 | "\n" |
| 288 | "function kpi(k,v,cls){return '<div class=\"kpi\"><div class=\"k\">'+esc(k)+'</div>'+\n" |
| 289 | " '<div class=\"v'+(cls?(' '+cls):'')+'\">'+esc(v)+'</div></div>';}\n" |
| 290 | "function ago(t){ if(!t) return '-';\n" |
| 291 | " var d=Math.max(0,Math.floor(Date.now()/1000)-t);\n" |
| 292 | " if(d<60) return d+'s'; if(d<3600) return Math.floor(d/60)+'m';\n" |
| 293 | " if(d<86400) return Math.floor(d/3600)+'h'; return Math.floor(d/86400)+'d';}\n" |
| 294 | "\n" |
| 295 | "function loadStatus(){\n" |
| 296 | " api('status',null,function(err,x){\n" |
| 297 | " if(err||!x||!x.j||!x.j.ok){$('runPill').className='pill bad';$('runPill').textContent='daemon: unreachable';return;}\n" |
| 298 | " var s=x.j.status||{};\n" |
| 299 | " $('verTxt').textContent='v'+(x.j.version||'?');\n" |
| 300 | " var rp=$('runPill');\n" |
| 301 | " if(s.running){rp.className='pill ok';rp.textContent='daemon: running';}\n" |
| 302 | " else{rp.className='pill';rp.textContent='daemon: stopped';}\n" |
| 303 | " var tp=$('tlsPill');\n" |
| 304 | " if(s.tls_insecure){tp.className='pill bad';tp.textContent='tls: verification OFF';}\n" |
| 305 | " else if(s.pinned){tp.className='pill warn';tp.textContent='tls: pinned';}\n" |
| 306 | " else if(s.tls){tp.className='pill ok';tp.textContent='tls: verified';}\n" |
| 307 | " else{tp.className='pill warn';tp.textContent='tls: plain http';}\n" |
| 308 | " $('startBtn').disabled=!!s.running; $('stopBtn').disabled=!s.running;\n" |
| 309 | " var k=[];\n" |
| 310 | " k.push(kpi('State',s.running?(s.connected?'subscribed':'connecting'):'stopped'));\n" |
| 311 | " k.push(kpi('Inbound',String(s.inbound_count||0)));\n" |
| 312 | " k.push(kpi('Replies sent',String(s.outbound_count||0)));\n" |
| 313 | " k.push(kpi('Blocked',String(s.blocked_count||0)));\n" |
| 314 | " k.push(kpi('Pending pairing',String(s.pending_count||0)));\n" |
| 315 | " k.push(kpi('Last inbound',ago(s.last_inbound_at)));\n" |
| 316 | " k.push(kpi('Last reply',ago(s.last_outbound_at)));\n" |
| 317 | " k.push(kpi('Errors',String(s.error_count||0)));\n" |
| 318 | " k.push(kpi('Topic',s.topic||'(not set)'));\n" |
| 319 | " k.push(kpi('Publish topic',s.publish_topic||'(not set)'));\n" |
| 320 | " k.push(kpi('Session',s.target_session||'(not set)'));\n" |
| 321 | " k.push(kpi('Server',s.server_url||'-'));\n" |
| 322 | " k.push(kpi('Policy',s.allow_all?'ALL SENDERS':'allowlist'));\n" |
| 323 | " k.push(kpi('Last error',s.last_error||'none'));\n" |
| 324 | " $('kpis').innerHTML=k.join('');\n" |
| 325 | " });\n" |
| 326 | "}\n" |
| 327 | "function loadCfg(){\n" |
| 328 | " api('config',null,function(err,x){\n" |
| 329 | " if(err||!x||!x.j||!x.j.config) return;\n" |
| 330 | " var c=x.j.config;\n" |
| 331 | " $('f_server').value=c.server_url||''; $('f_topic').value=c.topic||'';\n" |
| 332 | " $('f_ptopic').value=c.publish_topic||''; $('f_session').value=c.target_session||'';\n" |
| 333 | " $('f_api').value=c.bot_api_url||''; $('f_tags').value=c.tags||'';\n" |
| 334 | " $('f_reply').value=c.reply_prefix||''; $('f_title').value=c.title_prefix||'';\n" |
| 335 | " $('f_ca').value=c.ca_file||''; $('f_prio').value=String(c.priority||3);\n" |
| 336 | " $('f_poll').value=String(c.reply_poll_ms||700);\n" |
| 337 | " $('f_md').checked=!!c.markdown; $('f_pair').checked=!!c.pairing_code_enabled;\n" |
| 338 | " $('f_all').checked=!!c.allow_all;\n" |
| 339 | " });\n" |
| 340 | " api('status',null,function(err,x){\n" |
| 341 | " if(err||!x||!x.j||!x.j.status) return;\n" |
| 342 | " var s=x.j.status;\n" |
| 343 | " $('tokState').textContent=s.has_bearer?'stored (hidden)':'';\n" |
| 344 | " $('pwdState').textContent=s.has_bot_password?'stored (hidden)':'';\n" |
| 345 | " $('f_pins').value=s.pinned?'(stored)':'';\n" |
| 346 | " });\n" |
| 347 | "}\n" |
| 348 | "function saveCfg(cb){\n" |
| 349 | " var p={\n" |
| 350 | " server_url:$('f_server').value.trim(), topic:$('f_topic').value.trim(),\n" |
| 351 | " publish_topic:$('f_ptopic').value.trim(), target_session:$('f_session').value.trim(),\n" |
| 352 | " bot_api_url:$('f_api').value.trim(), tags:$('f_tags').value.trim(),\n" |
| 353 | " reply_prefix:$('f_reply').value, title_prefix:$('f_title').value.trim(),\n" |
| 354 | " ca_file:$('f_ca').value.trim(), priority:$('f_prio').value.trim(),\n" |
| 355 | " reply_poll_ms:$('f_poll').value.trim(), markdown:$('f_md').checked,\n" |
| 356 | " pairing_code_enabled:$('f_pair').checked, allow_all:$('f_all').checked\n" |
| 357 | " };\n" |
| 358 | " var pins=$('f_pins').value.trim(); if(pins && pins!=='(stored)') p.allowed_pins=pins;\n" |
| 359 | " if($('f_token').value) p.bearer_token=$('f_token').value;\n" |
| 360 | " if($('f_pwd').value) p.bot_password=$('f_pwd').value;\n" |
| 361 | " api('save',p,function(err,x){\n" |
| 362 | " if(err||!x){say('err','Save failed: network error');return;}\n" |
| 363 | " if(!x.j.ok){say('err','Save failed: '+(x.j.error||'unknown'));return;}\n" |
| 364 | " if(x.j.validation) say('info','Saved. Note: '+x.j.validation);\n" |
| 365 | " else say('ok','Saved at '+clock()+'.');\n" |
| 366 | " $('f_token').value=''; $('f_pwd').value='';\n" |
| 367 | " loadCfg(); loadStatus();\n" |
| 368 | " if(cb)cb();\n" |
| 369 | " });\n" |
| 370 | "}\n" |
| 371 | "function rowBtn(id,label,cls,fn){var b=$(id);if(b&&!b.dataset.bound){b.dataset.bound='1';\n" |
| 372 | " b.addEventListener('click',fn);}}\n" |
| 373 | "\n" |
| 374 | "function loadPending(){\n" |
| 375 | " api('pending',null,function(err,x){\n" |
| 376 | " var b=$('pendBody');\n" |
| 377 | " if(err||!x||!x.j||!x.j.pending){b.innerHTML='<tr><td colspan=\"5\" class=\"empty\">Unavailable.</td></tr>';return;}\n" |
| 378 | " var a=x.j.pending;\n" |
| 379 | " $('pendCount').textContent=a.length?('('+a.length+')'):'';\n" |
| 380 | " if(!a.length){b.innerHTML='<tr><td colspan=\"5\" class=\"empty\">Nothing waiting. Publish anything on the subscribe topic to create a request.</td></tr>';return;}\n" |
| 381 | " var h='';\n" |
| 382 | " for(var i=0;i<a.length;i++){\n" |
| 383 | " h+='<tr><td><div>'+esc(a[i].label)+'</div><div class=\"key\">'+esc(a[i].key)+'</div></td>'+\n" |
| 384 | " '<td>'+esc((a[i].sample||'').slice(0,140))+'</td>'+\n" |
| 385 | " '<td class=\"mono\">'+esc(a[i].code||'-')+'</td>'+\n" |
| 386 | " '<td class=\"mono\">'+ago(a[i].last_seen)+' x'+(a[i].count||1)+'</td>'+\n" |
| 387 | " '<td style=\"white-space:nowrap\"><button class=\"btn sm\" data-approve=\"'+esc(a[i].key)+'\">Approve</button> '+\n" |
| 388 | " '<button class=\"btn rd sm\" data-deny=\"'+esc(a[i].key)+'\">Deny</button></td></tr>';\n" |
| 389 | " }\n" |
| 390 | " b.innerHTML=h;\n" |
| 391 | " [].slice.call(b.querySelectorAll('[data-approve]')).forEach(function(btn){\n" |
| 392 | " btn.addEventListener('click',function(){api('approve',{key:btn.getAttribute('data-approve')},function(e,x2){\n" |
| 393 | " if(e||!x2||!x2.j.ok){say('err','Approve failed: '+((x2&&x2.j&&x2.j.error)||'network'));return;}\n" |
| 394 | " say('ok','Sender approved.');loadPending();loadStatus();});});});\n" |
| 395 | " [].slice.call(b.querySelectorAll('[data-deny]')).forEach(function(btn){\n" |
| 396 | " btn.addEventListener('click',function(){api('deny',{key:btn.getAttribute('data-deny')},function(e,x2){\n" |
| 397 | " if(e||!x2||!x2.j.ok){say('err','Deny failed: '+((x2&&x2.j&&x2.j.error)||'network'));return;}\n" |
| 398 | " say('ok','Request removed.');loadPending();loadStatus();});});});\n" |
| 399 | " });\n" |
| 400 | "}\n" |
| 401 | "function loadApproved(){\n" |
| 402 | " api('approved',null,function(err,x){\n" |
| 403 | " var b=$('apprBody');\n" |
| 404 | " if(err||!x||!x.j||!x.j.approved){b.innerHTML='<tr><td colspan=\"5\" class=\"empty\">Unavailable.</td></tr>';return;}\n" |
| 405 | " var a=x.j.approved;\n" |
| 406 | " if(!a.length){b.innerHTML='<tr><td colspan=\"5\" class=\"empty\">No approved senders yet.</td></tr>';return;}\n" |
| 407 | " var h='';\n" |
| 408 | " for(var i=0;i<a.length;i++){\n" |
| 409 | " h+='<tr><td><div>'+esc(a[i].label)+'</div><div class=\"key\">'+esc(a[i].key)+'</div></td>'+\n" |
| 410 | " '<td class=\"mono\">'+(a[i].count||0)+'</td><td class=\"mono\">'+ago(a[i].added_at)+'</td>'+\n" |
| 411 | " '<td>'+(a[i].via===1?'<span class=\"tag\">code</span>':'<span class=\"tag\">ui</span>')+'</td>'+\n" |
| 412 | " '<td><button class=\"btn rd sm\" data-unapp=\"'+esc(a[i].key)+'\">Revoke</button></td></tr>';\n" |
| 413 | " }\n" |
| 414 | " b.innerHTML=h;\n" |
| 415 | " [].slice.call(b.querySelectorAll('[data-unapp]')).forEach(function(btn){\n" |
| 416 | " btn.addEventListener('click',function(){api('unapprove',{key:btn.getAttribute('data-unapp')},function(e,x2){\n" |
| 417 | " if(e||!x2||!x2.j.ok){say('err','Revoke failed: '+((x2&&x2.j&&x2.j.error)||'network'));return;}\n" |
| 418 | " say('ok','Sender revoked.');loadApproved();});});});\n" |
| 419 | " });\n" |
| 420 | "}\n" |
| 421 | "function loadLog(){\n" |
| 422 | " api('logs',null,function(err,x){\n" |
| 423 | " if(err||!x||!x.j||!x.j.ok){$('logBox').textContent='Log unavailable.';return;}\n" |
| 424 | " $('logBox').textContent=x.j.log&&x.j.log.length?x.j.log:'(empty — the daemon has not logged yet)';\n" |
| 425 | " });\n" |
| 426 | "}\n" |
| 427 | "\n" |
| 428 | "rowBtn('saveBtn','Save','btn',function(){saveCfg();});\n" |
| 429 | "rowBtn('testBtn','Test','btn',function(){saveCfg(function(){\n" |
| 430 | " api('test',null,function(err,x){\n" |
| 431 | " if(err||!x||!x.j||!x.j.ok){say('err','Test failed: '+((x&&x.j&&x.j.error)||'network'));return;}\n" |
| 432 | " say('ok','Published (id '+(x.j.published_id||'?')+'). Check your phone.');});});});\n" |
| 433 | "rowBtn('sendBtn','Send','btn',function(){\n" |
| 434 | " var p={message:$('s_msg').value,title:$('s_title').value,tags:$('s_tags').value,\n" |
| 435 | " topic:$('s_topic').value};\n" |
| 436 | " if(!p.message.trim()){say('err','Write a message first.');return;}\n" |
| 437 | " api('send',p,function(err,x){\n" |
| 438 | " if(err||!x||!x.j||!x.j.ok){say('err','Publish failed: '+((x&&x.j&&x.j.error)||'network'));return;}\n" |
| 439 | " say('ok','Published to '+(x.j.topic||'topic')+' (id '+(x.j.published_id||'?')+').');});});\n" |
| 440 | "rowBtn('startBtn','Start','btn',function(){saveCfg(function(){\n" |
| 441 | " api('start',null,function(err,x){\n" |
| 442 | " if(err||!x||!x.j||!x.j.ok){say('err','Start failed: '+((x&&x.j&&x.j.error)||'network'));return;}\n" |
| 443 | " say('ok','Daemon started.');setTimeout(function(){loadStatus();loadLog();},700);});});});\n" |
| 444 | "rowBtn('stopBtn','Stop','btn',function(){\n" |
| 445 | " api('stop',null,function(err,x){\n" |
| 446 | " if(err||!x||!x.j||!x.j.ok){say('err','Stop failed: '+((x&&x.j&&x.j.error)||'network'));return;}\n" |
| 447 | " say('ok','Daemon stopped.');loadStatus();});});\n" |
| 448 | "rowBtn('refreshBtn','Refresh','btn',function(){loadStatus();loadPending();});\n" |
| 449 | "rowBtn('logBtn','Log','btn',function(){loadLog();});\n" |
| 450 | "\n" |
| 451 | "loadStatus();loadCfg();loadPending();\n" |
| 452 | "setInterval(function(){\n" |
| 453 | " var st=$('sec-st');\n" |
| 454 | " if(st&&st.className.indexOf('show')>=0) loadStatus();\n" |
| 455 | "},5000);\n" |
| 456 | "})();\n" |
| 457 | "</script>\n" |
| 458 | "\002</body></html>\n" |
| 459 | ; |
| 460 | |
| 461 | #endif /* SX_NTFY_UI_HTML_H */ |