| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_WEBHOOK_UI_HTML_H |
| 3 | #define SX_WEBHOOK_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>webhook</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | ".wrap{max-width:1040px;margin:0 auto;padding:16px}\n" |
| 17 | ".head{display:flex;align-items:flex-start;gap:12px;flex-wrap:wrap}\n" |
| 18 | "h1{font-size:20px;margin:0 0 2px;font-weight:650;letter-spacing:-.01em}\n" |
| 19 | ".sub{color:var(--text-2);font-size:12.5px}\n" |
| 20 | ".sub2{color:var(--text-2);font-size:11.5px;margin-top:2px}\n" |
| 21 | ".spacer{flex:1 1 auto}\n" |
| 22 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;\n" |
| 23 | " padding:16px;margin-bottom:14px}\n" |
| 24 | ".card h2{font-size:12px;font-weight:650;margin:0 0 12px;color:var(--text-2);\n" |
| 25 | " text-transform:uppercase;letter-spacing:.06em}\n" |
| 26 | ".row{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-end}\n" |
| 27 | ".col{display:flex;flex-direction:column;gap:8px}\n" |
| 28 | "label{display:block;font-size:11px;color:var(--text-2);margin-bottom:4px;\n" |
| 29 | " text-transform:uppercase;letter-spacing:.05em}\n" |
| 30 | "input,select,textarea{background:var(--input-bg);border:1px solid var(--line);\n" |
| 31 | " color:var(--text);border-radius:9px;padding:7px 10px;font-size:13.5px;\n" |
| 32 | " font-family:var(--font);outline:none;min-width:0;width:100%}\n" |
| 33 | "textarea{font-family:var(--mono);font-size:12.5px;resize:vertical;min-height:88px;\n" |
| 34 | " line-height:1.45}\n" |
| 35 | "input:focus,select:focus,textarea:focus{border-color:var(--blue)}\n" |
| 36 | "button{background:var(--blue);color:#fff;border:0;border-radius:980px;\n" |
| 37 | " padding:7px 15px;font-size:13px;font-weight:600;cursor:pointer;font-family:var(--font)}\n" |
| 38 | "button.ghost{background:var(--surface-2);color:var(--text)}\n" |
| 39 | "button.danger{background:var(--red)}\n" |
| 40 | "button.tiny{padding:3px 10px;font-size:12px;border-radius:8px}\n" |
| 41 | "button:active{transform:scale(.98)}\n" |
| 42 | "button:disabled{opacity:.55;cursor:default}\n" |
| 43 | ".grow1{flex:1 1 200px}.grow2{flex:2 1 320px}\n" |
| 44 | "table{width:100%;border-collapse:collapse;font-size:13px}\n" |
| 45 | "th{text-align:left;font-size:10.5px;color:var(--text-2);text-transform:uppercase;\n" |
| 46 | " letter-spacing:.05em;font-weight:600;padding:0 8px 7px 0;\n" |
| 47 | " border-bottom:1px solid var(--line);white-space:nowrap}\n" |
| 48 | "td{padding:9px 8px 9px 0;border-bottom:1px solid var(--line);vertical-align:top}\n" |
| 49 | "tr:last-child td{border-bottom:0}\n" |
| 50 | "td.mono,.mono{font-family:var(--mono);font-size:12px;\n" |
| 51 | " font-variant-numeric:tabular-nums;word-break:break-all}\n" |
| 52 | ".tbl-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}\n" |
| 53 | ".pill{display:inline-block;font-size:10.5px;font-weight:600;padding:2px 8px;\n" |
| 54 | " border-radius:980px;border:1px solid var(--line);color:var(--text-2);\n" |
| 55 | " background:var(--surface-2);white-space:nowrap}\n" |
| 56 | ".pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)}\n" |
| 57 | ".pill.bad{color:var(--red);border-color:rgba(255,69,58,.35)}\n" |
| 58 | ".pill.sig{color:var(--blue);border-color:rgba(10,132,255,.35)}\n" |
| 59 | ".pill.muted{color:var(--text-2)}\n" |
| 60 | ".empty{color:var(--text-2);font-size:12.5px;padding:10px 0}\n" |
| 61 | ".hint{color:var(--text-2);font-size:11.5px;margin-top:6px}\n" |
| 62 | ".out{margin-top:12px;padding:12px;border-radius:11px;background:var(--code-bg);\n" |
| 63 | " font-family:var(--mono);font-size:12px;white-space:pre-wrap;\n" |
| 64 | " word-break:break-word;display:none}\n" |
| 65 | ".out.on{display:block}\n" |
| 66 | ".out.err{color:var(--red)}\n" |
| 67 | ".hdr-row{display:grid;grid-template-columns:1fr 1fr auto;gap:8px;align-items:end}\n" |
| 68 | ".icon-btn{background:transparent;border:1px solid var(--line);color:var(--text-2);\n" |
| 69 | " border-radius:8px;padding:6px 9px;font-size:12px}\n" |
| 70 | ".hidden{display:none!important}\n" |
| 71 | ".foot{color:var(--text-2);font-size:11.5px;margin-top:2px}\n" |
| 72 | "kbd{font-family:var(--mono);font-size:11px;background:var(--surface-2);\n" |
| 73 | " border:1px solid var(--line);border-radius:5px;padding:1px 5px}\n" |
| 74 | "/* A five-column table cannot fit 390 px without squeezing the name into a\n" |
| 75 | " * vertical ribbon, so below 700 px each row becomes a labelled block. */\n" |
| 76 | "@media(max-width:700px){\n" |
| 77 | " #tbl thead{display:none}\n" |
| 78 | " #tbl,#tbl tbody{display:block}\n" |
| 79 | " #tbl tr{display:block;border:1px solid var(--line);border-radius:12px;\n" |
| 80 | " padding:10px 12px;margin-bottom:10px}\n" |
| 81 | " #tbl td{display:grid;grid-template-columns:76px minmax(0,1fr);gap:8px;\n" |
| 82 | " padding:2px 0;border:0;align-items:baseline;word-break:break-word}\n" |
| 83 | " #tbl td::before{content:attr(data-label);color:var(--text-2);font-size:10.5px;\n" |
| 84 | " text-transform:uppercase;letter-spacing:.05em}\n" |
| 85 | " #tbl td > .hint{grid-column:2;color:var(--text-2);font-size:11.5px}\n" |
| 86 | " #tbl td.actions{grid-template-columns:1fr 1fr;margin-top:8px;gap:6px}\n" |
| 87 | " #tbl td.actions::before{content:none}\n" |
| 88 | " #tbl td > span,#tbl td > button{justify-self:start}\n" |
| 89 | " #tbl td.actions > button{justify-self:stretch}\n" |
| 90 | " /* The delivery log has the same problem: six columns at 390 px. */\n" |
| 91 | " #logtbl thead{display:none}\n" |
| 92 | " #logtbl,#logtbl tbody{display:block}\n" |
| 93 | " #logtbl tr{display:block;border-bottom:1px solid var(--line);padding:8px 0}\n" |
| 94 | " #logtbl td{display:grid;grid-template-columns:86px minmax(0,1fr);gap:8px;\n" |
| 95 | " padding:1px 0;border:0;word-break:break-word}\n" |
| 96 | " #logtbl td::before{content:attr(data-label);color:var(--text-2);font-size:10.5px;\n" |
| 97 | " text-transform:uppercase;letter-spacing:.05em}\n" |
| 98 | " #logtbl td > span{justify-self:start}\n" |
| 99 | "}\n" |
| 100 | "@media(max-width:640px){\n" |
| 101 | " .wrap{padding:12px}\n" |
| 102 | " .hdr-row{grid-template-columns:1fr}\n" |
| 103 | " .head{gap:8px}\n" |
| 104 | "}\n" |
| 105 | "</style>\n" |
| 106 | "</head>\n" |
| 107 | "<body>\n" |
| 108 | "<div class=\"wrap\">\n" |
| 109 | "\n" |
| 110 | " <div class=\"head\">\n" |
| 111 | " <div>\n" |
| 112 | " <h1>webhook</h1>\n" |
| 113 | " <div class=\"sub\">Named webhook & REST triggers — secrets stay on this node</div>\n" |
| 114 | " <div class=\"sub2\" id=\"policynote\"></div>\n" |
| 115 | " </div>\n" |
| 116 | " <div class=\"spacer\"></div>\n" |
| 117 | " <button class=\"embed-hide icon-btn\" id=\"themeToggle\" type=\"button\">Theme</button>\n" |
| 118 | " </div>\n" |
| 119 | "\n" |
| 120 | " <div class=\"card\">\n" |
| 121 | " <h2>Hooks <span id=\"count\" class=\"pill muted\">0</span></h2>\n" |
| 122 | " <div class=\"tbl-wrap\">\n" |
| 123 | " <table id=\"tbl\">\n" |
| 124 | " <thead><tr>\n" |
| 125 | " <th>Name</th><th>Method</th><th>Endpoint</th><th>Signature</th><th>Secrets</th><th></th>\n" |
| 126 | " </tr></thead>\n" |
| 127 | " <tbody id=\"rows\"><tr><td colspan=\"6\" class=\"empty\">Loading…</td></tr></tbody>\n" |
| 128 | " </table>\n" |
| 129 | " </div>\n" |
| 130 | " <div class=\"row\" style=\"margin-top:12px\">\n" |
| 131 | " <button id=\"btnNew\" type=\"button\">New hook</button>\n" |
| 132 | " <button class=\"ghost\" id=\"btnReload\" type=\"button\">Reload</button>\n" |
| 133 | " </div>\n" |
| 134 | " </div>\n" |
| 135 | "\n" |
| 136 | " <div class=\"card hidden\" id=\"editor\">\n" |
| 137 | " <h2 id=\"editorTitle\">New hook</h2>\n" |
| 138 | " <div class=\"row\">\n" |
| 139 | " <div class=\"grow1\"><label for=\"fName\">Name</label>\n" |
| 140 | " <input id=\"fName\" placeholder=\"deploy-note\" autocomplete=\"off\"></div>\n" |
| 141 | " <div class=\"grow1\"><label for=\"fMethod\">Method</label>\n" |
| 142 | " <select id=\"fMethod\">\n" |
| 143 | " <option>POST</option><option>GET</option><option>PUT</option>\n" |
| 144 | " <option>PATCH</option><option>DELETE</option><option>HEAD</option>\n" |
| 145 | " </select></div>\n" |
| 146 | " <div class=\"grow2\"><label for=\"fUrl\">URL</label>\n" |
| 147 | " <input id=\"fUrl\" placeholder=\"https://example.com/hooks/abc\" autocomplete=\"off\"></div>\n" |
| 148 | " </div>\n" |
| 149 | " <div class=\"row\" style=\"margin-top:10px\">\n" |
| 150 | " <div class=\"grow2\"><label for=\"fDesc\">Description</label>\n" |
| 151 | " <input id=\"fDesc\" placeholder=\"Deploy notification\" autocomplete=\"off\"></div>\n" |
| 152 | " <div class=\"grow1\"><label for=\"fSig\">Signature</label>\n" |
| 153 | " <select id=\"fSig\">\n" |
| 154 | " <option value=\"\">none</option>\n" |
| 155 | " <option value=\"github\">github — X-Hub-Signature-256</option>\n" |
| 156 | " <option value=\"gitlab\">gitlab — X-Gitlab-Token</option>\n" |
| 157 | " <option value=\"v2\">v2 — timestamped HMAC</option>\n" |
| 158 | " </select></div>\n" |
| 159 | " <div class=\"grow1\"><label for=\"fSecret\">HMAC secret</label>\n" |
| 160 | " <input id=\"fSecret\" type=\"password\" autocomplete=\"new-password\"\n" |
| 161 | " placeholder=\"leave blank to keep\"></div>\n" |
| 162 | " </div>\n" |
| 163 | "\n" |
| 164 | " <div style=\"margin-top:12px\">\n" |
| 165 | " <label>Headers</label>\n" |
| 166 | " <div class=\"col\" id=\"hdrList\"></div>\n" |
| 167 | " <div class=\"row\" style=\"margin-top:8px\">\n" |
| 168 | " <button class=\"ghost tiny\" id=\"btnAddHdr\" type=\"button\">Add header</button>\n" |
| 169 | " </div>\n" |
| 170 | " <div class=\"hint\">A stored value is never sent back to the browser. Leave the\n" |
| 171 | " value blank to keep the secret already saved for that header name.</div>\n" |
| 172 | " </div>\n" |
| 173 | "\n" |
| 174 | " <div class=\"row\" style=\"margin-top:14px\">\n" |
| 175 | " <button id=\"btnSave\" type=\"button\">Save hook</button>\n" |
| 176 | " <button class=\"ghost\" id=\"btnCancel\" type=\"button\">Cancel</button>\n" |
| 177 | " <span id=\"saveMsg\" class=\"hint\"></span>\n" |
| 178 | " </div>\n" |
| 179 | " </div>\n" |
| 180 | "\n" |
| 181 | " <div class=\"card\">\n" |
| 182 | " <h2>Test fire</h2>\n" |
| 183 | " <div class=\"row\">\n" |
| 184 | " <div class=\"grow1\"><label for=\"fFire\">Hook</label>\n" |
| 185 | " <select id=\"fFire\"></select></div>\n" |
| 186 | " <div class=\"grow2\"><label for=\"fQuery\">Query string (optional)</label>\n" |
| 187 | " <input id=\"fQuery\" placeholder=\"event=deploy&env=prod\" autocomplete=\"off\"></div>\n" |
| 188 | " </div>\n" |
| 189 | " <div style=\"margin-top:10px\">\n" |
| 190 | " <label for=\"fPayload\">Payload (JSON)</label>\n" |
| 191 | " <textarea id=\"fPayload\">{\n" |
| 192 | " \"event\": \"deploy\",\n" |
| 193 | " \"service\": \"scorpiox-bot\",\n" |
| 194 | " \"status\": \"ok\"\n" |
| 195 | "}</textarea>\n" |
| 196 | " </div>\n" |
| 197 | " <div class=\"row\" style=\"margin-top:10px\">\n" |
| 198 | " <button id=\"btnFire\" type=\"button\">Send</button>\n" |
| 199 | " <span class=\"hint\">Sent from this node with the stored headers and signature.</span>\n" |
| 200 | " </div>\n" |
| 201 | " <div class=\"out\" id=\"fireOut\"></div>\n" |
| 202 | " </div>\n" |
| 203 | "\n" |
| 204 | " <div class=\"card\">\n" |
| 205 | " <h2>Recent deliveries</h2>\n" |
| 206 | " <div class=\"tbl-wrap\">\n" |
| 207 | " <table id=\"logtbl\">\n" |
| 208 | " <thead><tr><th>When (UTC)</th><th>Hook</th><th>Status</th><th>Bytes</th><th>ms</th><th>Detail</th></tr></thead>\n" |
| 209 | " <tbody id=\"logRows\"><tr><td colspan=\"6\" class=\"empty\">No deliveries yet.</td></tr></tbody>\n" |
| 210 | " </table>\n" |
| 211 | " </div>\n" |
| 212 | " </div>\n" |
| 213 | "\n" |
| 214 | " <div class=\"foot\">\n" |
| 215 | " Tool contract: <span class=\"mono\">webhook_list</span>,\n" |
| 216 | " <span class=\"mono\">webhook_trigger</span>. Press\n" |
| 217 | " <kbd>Ctrl</kbd>+<kbd>Enter</kbd> in the payload box to send.\n" |
| 218 | " </div>\n" |
| 219 | "</div>\n" |
| 220 | "\n" |
| 221 | "<script>\n" |
| 222 | "/* ------------------------------------------------------------------ routes\n" |
| 223 | " * Two call shapes, and getting this wrong is the classic plugin bug:\n" |
| 224 | " * served through the hub (bot.scorpiox.net/plugins?plugin=plugin_webhook…)\n" |
| 225 | " * -> call the hub proxy back: /plugins?plugin=plugin_webhook&action=…\n" |
| 226 | " * opened directly on the node\n" |
| 227 | " * -> the plugin IS the route: /plugin_webhook?action=…\n" |
| 228 | " * Never call /plugins?plugin= on the node itself: that is the discovery\n" |
| 229 | " * endpoint and it answers with the plugin list, not with this plugin. */\n" |
| 230 | "var Q = new URLSearchParams(location.search);\n" |
| 231 | "var HUB = Q.get('plugin') || '';\n" |
| 232 | "var NODE = Q.get('node') || '';\n" |
| 233 | "var PW = Q.get('pwd') || (NODE && localStorage.getItem('bot_pwd_' + NODE)) ||\n" |
| 234 | " localStorage.getItem('bot_active_pwd') || '';\n" |
| 235 | "\n" |
| 236 | "function api(action, payload, method) {\n" |
| 237 | " var u = (HUB ? '/plugins?plugin=' + encodeURIComponent(HUB)\n" |
| 238 | " : '/plugin_webhook') +\n" |
| 239 | " '?action=' + encodeURIComponent(action) + '&format=json' +\n" |
| 240 | " (NODE ? '&node=' + encodeURIComponent(NODE) : '') +\n" |
| 241 | " (PW ? '&pwd=' + encodeURIComponent(PW) : '');\n" |
| 242 | " var opt = {\n" |
| 243 | " method: method || (payload ? 'POST' : 'GET'),\n" |
| 244 | " headers: PW ? {'X-Bot-Password': PW} : {}\n" |
| 245 | " };\n" |
| 246 | " if (payload) {\n" |
| 247 | " opt.headers['Content-Type'] = 'application/json';\n" |
| 248 | " opt.body = JSON.stringify(payload);\n" |
| 249 | " }\n" |
| 250 | " return fetch(u, opt).then(function (r) {\n" |
| 251 | " return r.text().then(function (t) {\n" |
| 252 | " var d;\n" |
| 253 | " try { d = JSON.parse(t); } catch (e) { throw new Error('not JSON: ' + t.slice(0, 200)); }\n" |
| 254 | " if (!r.ok || d.ok === false) {\n" |
| 255 | " throw new Error(d.error || ('HTTP ' + r.status));\n" |
| 256 | " }\n" |
| 257 | " return d;\n" |
| 258 | " });\n" |
| 259 | " });\n" |
| 260 | "}\n" |
| 261 | "\n" |
| 262 | "function el(id) { return document.getElementById(id); }\n" |
| 263 | "function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); }\n" |
| 264 | "function txt(s) { return document.createTextNode(s == null ? '' : String(s)); }\n" |
| 265 | "\n" |
| 266 | "var state = { hooks: [], log: [], editing: null, allowPrivate: false };\n" |
| 267 | "\n" |
| 268 | "function renderPolicy() {\n" |
| 269 | " el('policynote').textContent = state.allowPrivate\n" |
| 270 | " ? 'Private / loopback endpoints are allowed on this node (WEBHOOK_ALLOW_PRIVATE=1).'\n" |
| 271 | " : 'Outbound only to public addresses; loopback and private ranges are refused.';\n" |
| 272 | "}\n" |
| 273 | "\n" |
| 274 | "function headersSummary(h) {\n" |
| 275 | " var n = (h.headers || []).length;\n" |
| 276 | " var s = [];\n" |
| 277 | " if (n) s.push(n + ' header' + (n === 1 ? '' : 's'));\n" |
| 278 | " if (h.has_secret) s.push('HMAC');\n" |
| 279 | " return s.length ? s.join(' + ') : 'none';\n" |
| 280 | "}\n" |
| 281 | "\n" |
| 282 | "function renderHooks() {\n" |
| 283 | " var tb = el('rows');\n" |
| 284 | " clear(tb);\n" |
| 285 | " el('count').textContent = String(state.hooks.length);\n" |
| 286 | " if (!state.hooks.length) {\n" |
| 287 | " var tr = document.createElement('tr');\n" |
| 288 | " var td = document.createElement('td');\n" |
| 289 | " td.colSpan = 6; td.className = 'empty';\n" |
| 290 | " td.appendChild(txt('No hooks yet. Create one to give the agent a tool it can fire.'));\n" |
| 291 | " tr.appendChild(td); tb.appendChild(tr);\n" |
| 292 | " }\n" |
| 293 | " state.hooks.forEach(function (h) {\n" |
| 294 | " var tr = document.createElement('tr');\n" |
| 295 | "\n" |
| 296 | " var c1 = document.createElement('td');\n" |
| 297 | " c1.className = 'mono';\n" |
| 298 | " c1.dataset.label = 'Name';\n" |
| 299 | " c1.appendChild(txt(h.name));\n" |
| 300 | " if (h.desc) {\n" |
| 301 | " var d = document.createElement('div');\n" |
| 302 | " d.className = 'hint';\n" |
| 303 | " d.appendChild(txt(h.desc));\n" |
| 304 | " c1.appendChild(d);\n" |
| 305 | " }\n" |
| 306 | " tr.appendChild(c1);\n" |
| 307 | "\n" |
| 308 | " var c2 = document.createElement('td');\n" |
| 309 | " c2.dataset.label = 'Method';\n" |
| 310 | " var p = document.createElement('span');\n" |
| 311 | " p.className = 'pill'; p.appendChild(txt(h.method));\n" |
| 312 | " c2.appendChild(p);\n" |
| 313 | " tr.appendChild(c2);\n" |
| 314 | "\n" |
| 315 | " var c3 = document.createElement('td');\n" |
| 316 | " c3.className = 'mono';\n" |
| 317 | " c3.dataset.label = 'Endpoint';\n" |
| 318 | " c3.appendChild(txt(h.url || ''));\n" |
| 319 | " tr.appendChild(c3);\n" |
| 320 | "\n" |
| 321 | " var c4 = document.createElement('td');\n" |
| 322 | " c4.dataset.label = 'Signature';\n" |
| 323 | " var sp = document.createElement('span');\n" |
| 324 | " if (h.sig) { sp.className = 'pill sig'; sp.appendChild(txt(h.sig)); }\n" |
| 325 | " else { sp.className = 'pill muted'; sp.appendChild(txt('none')); }\n" |
| 326 | " c4.appendChild(sp);\n" |
| 327 | " tr.appendChild(c4);\n" |
| 328 | "\n" |
| 329 | " var c5 = document.createElement('td');\n" |
| 330 | " c5.className = 'hint';\n" |
| 331 | " c5.dataset.label = 'Secrets';\n" |
| 332 | " c5.appendChild(txt(headersSummary(h)));\n" |
| 333 | " tr.appendChild(c5);\n" |
| 334 | "\n" |
| 335 | " var c6 = document.createElement('td');\n" |
| 336 | " c6.className = 'actions';\n" |
| 337 | " c6.dataset.label = '';\n" |
| 338 | " c6.style.whiteSpace = 'nowrap';\n" |
| 339 | " var bEdit = document.createElement('button');\n" |
| 340 | " bEdit.className = 'ghost tiny'; bEdit.type = 'button';\n" |
| 341 | " bEdit.appendChild(txt('Edit'));\n" |
| 342 | " bEdit.onclick = function () { openEditor(h); };\n" |
| 343 | " var bDel = document.createElement('button');\n" |
| 344 | " bDel.className = 'ghost tiny'; bDel.type = 'button';\n" |
| 345 | " bDel.style.marginLeft = '6px';\n" |
| 346 | " bDel.appendChild(txt('Delete'));\n" |
| 347 | " bDel.onclick = function () { removeHook(h.name); };\n" |
| 348 | " c6.appendChild(bEdit); c6.appendChild(bDel);\n" |
| 349 | " tr.appendChild(c6);\n" |
| 350 | "\n" |
| 351 | " tb.appendChild(tr);\n" |
| 352 | " });\n" |
| 353 | "\n" |
| 354 | " var sel = el('fFire');\n" |
| 355 | " var keep = sel.value;\n" |
| 356 | " clear(sel);\n" |
| 357 | " state.hooks.forEach(function (h) {\n" |
| 358 | " var o = document.createElement('option');\n" |
| 359 | " o.value = h.name; o.appendChild(txt(h.name + ' (' + h.method + ')'));\n" |
| 360 | " sel.appendChild(o);\n" |
| 361 | " });\n" |
| 362 | " if (keep) sel.value = keep;\n" |
| 363 | "}\n" |
| 364 | "\n" |
| 365 | "function renderLog() {\n" |
| 366 | " var tb = el('logRows');\n" |
| 367 | " clear(tb);\n" |
| 368 | " if (!state.log.length) {\n" |
| 369 | " var tr = document.createElement('tr');\n" |
| 370 | " var td = document.createElement('td');\n" |
| 371 | " td.colSpan = 6; td.className = 'empty';\n" |
| 372 | " td.appendChild(txt('No deliveries yet.'));\n" |
| 373 | " tr.appendChild(td); tb.appendChild(tr);\n" |
| 374 | " return;\n" |
| 375 | " }\n" |
| 376 | " /* The store keeps 50 deliveries; a page that lists all of them is a wall.\n" |
| 377 | " * The newest eight are what a person is looking for. */\n" |
| 378 | " state.log.slice(0, 8).forEach(function (e) {\n" |
| 379 | " var tr = document.createElement('tr');\n" |
| 380 | " var c1 = document.createElement('td');\n" |
| 381 | " c1.className = 'mono'; c1.dataset.label = 'When'; c1.appendChild(txt(e.at));\n" |
| 382 | " tr.appendChild(c1);\n" |
| 383 | " var c2 = document.createElement('td');\n" |
| 384 | " c2.className = 'mono'; c2.dataset.label = 'Hook'; c2.appendChild(txt(e.name));\n" |
| 385 | " tr.appendChild(c2);\n" |
| 386 | " var c3 = document.createElement('td');\n" |
| 387 | " c3.dataset.label = 'Status';\n" |
| 388 | " var p = document.createElement('span');\n" |
| 389 | " p.className = 'pill ' + (e.ok ? 'ok' : 'bad');\n" |
| 390 | " p.appendChild(txt(e.status ? String(e.status) : 'error'));\n" |
| 391 | " c3.appendChild(p);\n" |
| 392 | " tr.appendChild(c3);\n" |
| 393 | " var c4 = document.createElement('td');\n" |
| 394 | " c4.className = 'mono'; c4.dataset.label = 'Bytes'; c4.appendChild(txt(e.bytes));\n" |
| 395 | " tr.appendChild(c4);\n" |
| 396 | " var c5 = document.createElement('td');\n" |
| 397 | " c5.className = 'mono'; c5.dataset.label = 'ms'; c5.appendChild(txt(e.ms));\n" |
| 398 | " tr.appendChild(c5);\n" |
| 399 | " /* An empty Detail row is five lines of nothing on a phone, so it is only\n" |
| 400 | " * emitted when there is something to say. */\n" |
| 401 | " if (e.error) {\n" |
| 402 | " var c6 = document.createElement('td');\n" |
| 403 | " c6.className = 'hint'; c6.dataset.label = 'Detail';\n" |
| 404 | " c6.appendChild(txt(e.error));\n" |
| 405 | " tr.appendChild(c6);\n" |
| 406 | " }\n" |
| 407 | " tb.appendChild(tr);\n" |
| 408 | " });\n" |
| 409 | "}\n" |
| 410 | "\n" |
| 411 | "function load() {\n" |
| 412 | " return api('list').then(function (d) {\n" |
| 413 | " state.hooks = d.hooks || [];\n" |
| 414 | " state.log = d.log || [];\n" |
| 415 | " state.allowPrivate = !!d.allow_private;\n" |
| 416 | " renderPolicy();\n" |
| 417 | " renderHooks();\n" |
| 418 | " renderLog();\n" |
| 419 | " }).catch(function (e) {\n" |
| 420 | " var tb = el('rows');\n" |
| 421 | " clear(tb);\n" |
| 422 | " var tr = document.createElement('tr');\n" |
| 423 | " var td = document.createElement('td');\n" |
| 424 | " td.colSpan = 6; td.className = 'empty';\n" |
| 425 | " td.appendChild(txt('Could not load hooks: ' + e.message));\n" |
| 426 | " tr.appendChild(td); tb.appendChild(tr);\n" |
| 427 | " });\n" |
| 428 | "}\n" |
| 429 | "\n" |
| 430 | "/* ---------------------------------------------------------------- editor */\n" |
| 431 | "\n" |
| 432 | "function addHeaderRow(name, value, hasSecret) {\n" |
| 433 | " var row = document.createElement('div');\n" |
| 434 | " row.className = 'hdr-row';\n" |
| 435 | "\n" |
| 436 | " var n = document.createElement('div');\n" |
| 437 | " var ln = document.createElement('label'); ln.appendChild(txt('Header'));\n" |
| 438 | " var inName = document.createElement('input');\n" |
| 439 | " inName.className = 'hdr-name'; inName.value = name || '';\n" |
| 440 | " inName.placeholder = 'Authorization'; inName.autocomplete = 'off';\n" |
| 441 | " n.appendChild(ln); n.appendChild(inName);\n" |
| 442 | "\n" |
| 443 | " var v = document.createElement('div');\n" |
| 444 | " var lv = document.createElement('label'); lv.appendChild(txt('Value'));\n" |
| 445 | " var inVal = document.createElement('input');\n" |
| 446 | " inVal.className = 'hdr-value'; inVal.value = value || '';\n" |
| 447 | " inVal.type = 'password'; inVal.autocomplete = 'new-password';\n" |
| 448 | " inVal.placeholder = hasSecret ? 'stored — leave blank to keep' : 'Bearer …';\n" |
| 449 | " v.appendChild(lv); v.appendChild(inVal);\n" |
| 450 | "\n" |
| 451 | " var b = document.createElement('button');\n" |
| 452 | " b.type = 'button'; b.className = 'icon-btn'; b.appendChild(txt('Remove'));\n" |
| 453 | " b.onclick = function () { row.parentNode.removeChild(row); };\n" |
| 454 | "\n" |
| 455 | " row.appendChild(n); row.appendChild(v); row.appendChild(b);\n" |
| 456 | " el('hdrList').appendChild(row);\n" |
| 457 | "}\n" |
| 458 | "\n" |
| 459 | "function openEditor(hook) {\n" |
| 460 | " state.editing = hook ? hook.name : null;\n" |
| 461 | " el('editor').classList.remove('hidden');\n" |
| 462 | " el('editorTitle').textContent = hook ? ('Edit ' + hook.name) : 'New hook';\n" |
| 463 | " el('fName').value = hook ? hook.name : '';\n" |
| 464 | " el('fName').disabled = !!hook;\n" |
| 465 | " el('fMethod').value = hook ? hook.method : 'POST';\n" |
| 466 | " el('fUrl').value = hook ? (hook.url || '') : '';\n" |
| 467 | " el('fDesc').value = hook ? (hook.desc || '') : '';\n" |
| 468 | " el('fSig').value = hook ? (hook.sig || '') : '';\n" |
| 469 | " el('fSecret').value = '';\n" |
| 470 | " el('fSecret').placeholder = hook && hook.has_secret\n" |
| 471 | " ? 'stored — leave blank to keep' : 'optional';\n" |
| 472 | " clear(el('hdrList'));\n" |
| 473 | " if (hook) {\n" |
| 474 | " (hook.headers || []).forEach(function (hd) {\n" |
| 475 | " addHeaderRow(hd.name, '', !!hd.has_secret);\n" |
| 476 | " });\n" |
| 477 | " } else {\n" |
| 478 | " addHeaderRow('Content-Type', 'application/json', false);\n" |
| 479 | " }\n" |
| 480 | " el('saveMsg').textContent = '';\n" |
| 481 | " el('fName').focus();\n" |
| 482 | "}\n" |
| 483 | "\n" |
| 484 | "function collectHook() {\n" |
| 485 | " var headers = [];\n" |
| 486 | " var rows = el('hdrList').children;\n" |
| 487 | " for (var i = 0; i < rows.length; i++) {\n" |
| 488 | " var n = rows[i].querySelector('.hdr-name');\n" |
| 489 | " var v = rows[i].querySelector('.hdr-value');\n" |
| 490 | " if (!n || !n.value.trim()) continue;\n" |
| 491 | " var entry = { name: n.value.trim() };\n" |
| 492 | " /* An empty value means \"keep whatever is stored for this name\". Sending\n" |
| 493 | " * the key at all with an empty string would clear the secret. */\n" |
| 494 | " if (v && v.value !== '') entry.value = v.value;\n" |
| 495 | " headers.push(entry);\n" |
| 496 | " }\n" |
| 497 | " var body = {\n" |
| 498 | " name: el('fName').value.trim(),\n" |
| 499 | " url: el('fUrl').value.trim(),\n" |
| 500 | " method: el('fMethod').value,\n" |
| 501 | " desc: el('fDesc').value.trim(),\n" |
| 502 | " sig: el('fSig').value,\n" |
| 503 | " headers: headers\n" |
| 504 | " };\n" |
| 505 | " if (el('fSecret').value) body.secret = el('fSecret').value;\n" |
| 506 | " return body;\n" |
| 507 | "}\n" |
| 508 | "\n" |
| 509 | "function saveHook() {\n" |
| 510 | " var body = collectHook();\n" |
| 511 | " if (!body.name) { el('saveMsg').textContent = 'A name is required.'; return; }\n" |
| 512 | " if (!body.url) { el('saveMsg').textContent = 'A URL is required.'; return; }\n" |
| 513 | " el('saveMsg').textContent = 'Saving…';\n" |
| 514 | " api('save', body).then(function () {\n" |
| 515 | " el('editor').classList.add('hidden');\n" |
| 516 | " return load();\n" |
| 517 | " }).catch(function (e) {\n" |
| 518 | " el('saveMsg').textContent = 'Error: ' + e.message;\n" |
| 519 | " });\n" |
| 520 | "}\n" |
| 521 | "\n" |
| 522 | "function removeHook(name) {\n" |
| 523 | " api('delete', { name: name }).then(load).catch(function (e) {\n" |
| 524 | " el('fireOut').className = 'out on err';\n" |
| 525 | " el('fireOut').textContent = 'Delete failed: ' + e.message;\n" |
| 526 | " });\n" |
| 527 | "}\n" |
| 528 | "\n" |
| 529 | "/* ------------------------------------------------------------------- fire */\n" |
| 530 | "\n" |
| 531 | "function fire() {\n" |
| 532 | " var name = el('fFire').value;\n" |
| 533 | " var out = el('fireOut');\n" |
| 534 | " if (!name) {\n" |
| 535 | " out.className = 'out on err';\n" |
| 536 | " out.textContent = 'Create a hook first.';\n" |
| 537 | " return;\n" |
| 538 | " }\n" |
| 539 | " var payload = el('fPayload').value;\n" |
| 540 | " try { JSON.parse(payload || '{}'); }\n" |
| 541 | " catch (e) {\n" |
| 542 | " out.className = 'out on err';\n" |
| 543 | " out.textContent = 'The payload is not valid JSON: ' + e.message;\n" |
| 544 | " return;\n" |
| 545 | " }\n" |
| 546 | " var body = { name: name, payload: payload || '{}' };\n" |
| 547 | " if (el('fQuery').value.trim()) body.query = el('fQuery').value.trim();\n" |
| 548 | "\n" |
| 549 | " out.className = 'out on';\n" |
| 550 | " out.textContent = 'Sending…';\n" |
| 551 | " api('fire', body).then(function (d) {\n" |
| 552 | " out.className = 'out on' + (d.ok_status ? '' : ' err');\n" |
| 553 | " out.textContent = JSON.stringify(d, null, 2);\n" |
| 554 | " return load();\n" |
| 555 | " }).catch(function (e) {\n" |
| 556 | " out.className = 'out on err';\n" |
| 557 | " out.textContent = 'Send failed: ' + e.message;\n" |
| 558 | " });\n" |
| 559 | "}\n" |
| 560 | "\n" |
| 561 | "/* ------------------------------------------------------------------- wire */\n" |
| 562 | "\n" |
| 563 | "el('btnNew').onclick = function () { openEditor(null); };\n" |
| 564 | "el('btnReload').onclick = function () { load(); };\n" |
| 565 | "el('btnCancel').onclick = function () { el('editor').classList.add('hidden'); };\n" |
| 566 | "el('btnSave').onclick = saveHook;\n" |
| 567 | "el('btnAddHdr').onclick = function () { addHeaderRow('', '', false); };\n" |
| 568 | "el('btnFire').onclick = fire;\n" |
| 569 | "el('fPayload').addEventListener('keydown', function (e) {\n" |
| 570 | " if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') fire();\n" |
| 571 | "});\n" |
| 572 | "el('themeToggle').onclick = function () {\n" |
| 573 | " if (window.sxApplyTheme) {\n" |
| 574 | " window.sxApplyTheme(window.sxTheme && window.sxTheme() === 'dark' ? 'light' : 'dark');\n" |
| 575 | " }\n" |
| 576 | "};\n" |
| 577 | "\n" |
| 578 | "load();\n" |
| 579 | "</script>\n" |
| 580 | "\002</body></html>\n" |
| 581 | ; |
| 582 | |
| 583 | #endif /* SX_WEBHOOK_UI_HTML_H */ |