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