studyable-math 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin.html +227 -227
- package/package.json +24 -24
package/admin.html
CHANGED
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
-
<title>Admin</title>
|
|
7
|
-
<style>
|
|
8
|
-
:root{--bg:#000;--panel:rgba(255,255,255,.07);--line:rgba(255,255,255,.14);--txt:#f5f5f7;--mut:#9a9aa3;--acc:#fff}
|
|
9
|
-
*{box-sizing:border-box}
|
|
10
|
-
body{margin:0;min-height:100vh;background:var(--bg);color:var(--txt);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}
|
|
11
|
-
.wrap{max-width:1180px;margin:0 auto;padding:26px 18px 80px}
|
|
12
|
-
.card{background:var(--panel);border:1px solid var(--line);border-radius:22px;padding:20px;margin:16px 0;backdrop-filter:blur(20px)}
|
|
13
|
-
h1{font-size:28px;margin:0}.sub{color:var(--mut);font-size:13px}
|
|
14
|
-
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
|
15
|
-
input,textarea,select{width:100%;background:rgba(255,255,255,.08);border:1px solid var(--line);color:var(--txt);border-radius:14px;padding:11px 13px;font:inherit}
|
|
16
|
-
textarea{min-height:80px;resize:vertical}
|
|
17
|
-
button,.btn{appearance:none;border:1px solid var(--line);background:rgba(255,255,255,.1);color:var(--txt);border-radius:14px;padding:10px 14px;font:inherit;font-weight:700;cursor:pointer;transition:.15s}
|
|
18
|
-
button:hover,.btn:hover{background:rgba(255,255,255,.18);transform:translateY(-1px)}
|
|
19
|
-
.btn.primary{background:#fff;color:#000;border-color:#fff}
|
|
20
|
-
.btn.danger{background:rgba(255,69,58,.16);border-color:rgba(255,69,58,.4);color:#ff8a80}
|
|
21
|
-
.btn.good{background:rgba(52,199,89,.14);border-color:rgba(52,199,89,.35);color:#7dffa8}
|
|
22
|
-
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:14px}
|
|
23
|
-
label{display:block;font-size:12px;color:var(--mut);margin:10px 0 6px;font-weight:700;text-transform:uppercase;letter-spacing:.06em}
|
|
24
|
-
table{width:100%;border-collapse:collapse;font-size:13px}
|
|
25
|
-
th,td{text-align:left;padding:9px 8px;border-bottom:1px solid rgba(255,255,255,.08);vertical-align:top}
|
|
26
|
-
th{color:var(--mut);font-size:11px;text-transform:uppercase;letter-spacing:.06em}
|
|
27
|
-
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
28
|
-
.pill{display:inline-block;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:800;border:1px solid var(--line)}
|
|
29
|
-
.pill.open{background:rgba(52,199,89,.14);color:#7dffa8;border-color:rgba(52,199,89,.4)}
|
|
30
|
-
.pill.closed,.pill.maintenance{background:rgba(255,159,10,.14);color:#ffd180;border-color:rgba(255,159,10,.4)}
|
|
31
|
-
.stat{font-size:26px;font-weight:900}.stat small{display:block;font-size:11px;color:var(--mut);font-weight:600}
|
|
32
|
-
.login{max-width:420px;margin:12vh auto}
|
|
33
|
-
.hidden{display:none!important}
|
|
34
|
-
.small{font-size:12px;color:var(--mut)}
|
|
35
|
-
.item{display:flex;justify-content:space-between;gap:10px;padding:9px 0;border-bottom:1px solid rgba(255,255,255,.08)}
|
|
36
|
-
.item:last-child{border-bottom:0}
|
|
37
|
-
@media(max-width:720px){.wrap{padding:16px 12px 60px}}
|
|
38
|
-
</style>
|
|
39
|
-
</head>
|
|
40
|
-
<body>
|
|
41
|
-
<div class="wrap">
|
|
42
|
-
<div id="login" class="card login hidden">
|
|
43
|
-
<h1>Admin</h1>
|
|
44
|
-
<p class="sub">Enter admin password.</p>
|
|
45
|
-
<label>Admin password</label>
|
|
46
|
-
<input id="pass" type="password" placeholder="Password" autocomplete="off">
|
|
47
|
-
<div style="height:14px"></div>
|
|
48
|
-
<button class="btn primary" id="loginBtn" style="width:100%">Unlock</button>
|
|
49
|
-
<div class="small" id="loginErr" style="margin-top:10px"></div>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
<div id="dash" class="hidden">
|
|
53
|
-
<div class="card row" style="justify-content:space-between">
|
|
54
|
-
<div>
|
|
55
|
-
<h1>Admin Panel</h1>
|
|
56
|
-
<div class="sub">Global controls for every visitor. Changes apply instantly.</div>
|
|
57
|
-
</div>
|
|
58
|
-
<div class="row">
|
|
59
|
-
<span id="statusPill" class="pill open">open</span>
|
|
60
|
-
<button id="refreshBtn">Refresh</button>
|
|
61
|
-
<button id="logoutBtn">Lock</button>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
|
|
65
|
-
<div class="grid">
|
|
66
|
-
<div class="card">
|
|
67
|
-
<h2 style="margin:0 0 6px">Site Control</h2>
|
|
68
|
-
<p class="sub">Kill switch works server-side for all IPs.</p>
|
|
69
|
-
<div class="row" style="margin-top:12px">
|
|
70
|
-
<button class="btn good" id="openBtn">Open Site</button>
|
|
71
|
-
<button class="btn danger" id="closeBtn">Close Site</button>
|
|
72
|
-
<button class="btn" id="maintBtn">Maintenance</button>
|
|
73
|
-
</div>
|
|
74
|
-
<label>Message shown to visitors</label>
|
|
75
|
-
<textarea id="statusMsg" placeholder="Optional message for closed/maintenance mode"></textarea>
|
|
76
|
-
<div style="height:10px"></div>
|
|
77
|
-
<button class="btn primary" id="applyStatusBtn">Apply Status</button>
|
|
78
|
-
</div>
|
|
79
|
-
|
|
80
|
-
<div class="card">
|
|
81
|
-
<h2 style="margin:0 0 6px">Announcement</h2>
|
|
82
|
-
<p class="sub">Shown as a toast on every page.</p>
|
|
83
|
-
<label><input type="checkbox" id="annActive" style="width:auto"> Active</label>
|
|
84
|
-
<label>Announcement text</label>
|
|
85
|
-
<input id="annText" placeholder="Announcement">
|
|
86
|
-
<div style="height:10px"></div>
|
|
87
|
-
<button class="btn primary" id="applyAnnBtn">Publish</button>
|
|
88
|
-
<button id="clearAnnBtn">Clear</button>
|
|
89
|
-
</div>
|
|
90
|
-
|
|
91
|
-
<div class="card">
|
|
92
|
-
<h2 style="margin:0 0 6px">AI Control</h2>
|
|
93
|
-
<p class="sub">Global Gemini defaults.</p>
|
|
94
|
-
<label><input type="checkbox" id="aiEnabled" style="width:auto"> AI enabled</label>
|
|
95
|
-
<label>Model</label>
|
|
96
|
-
<input id="aiModel" placeholder="gemini-2.0-flash">
|
|
97
|
-
<label>System prompt</label>
|
|
98
|
-
<textarea id="aiPrompt" placeholder="You are a helpful assistant."></textarea>
|
|
99
|
-
<div class="row">
|
|
100
|
-
<div style="flex:1"><label>Temperature <span id="aiTempVal"></span></label><input id="aiTemp" type="range" min="0" max="2" step="0.1"></div>
|
|
101
|
-
<div style="flex:1"><label>Max tokens <span id="aiTokVal"></span></label><input id="aiTok" type="range" min="128" max="4096" step="128"></div>
|
|
102
|
-
</div>
|
|
103
|
-
<div style="height:10px"></div>
|
|
104
|
-
<button class="btn primary" id="applyAiBtn">Apply AI</button>
|
|
105
|
-
</div>
|
|
106
|
-
|
|
107
|
-
<div class="card">
|
|
108
|
-
<h2 style="margin:0 0 6px">Stats</h2>
|
|
109
|
-
<div class="grid">
|
|
110
|
-
<div class="stat" id="stReq">0<small>Requests</small></div>
|
|
111
|
-
<div class="stat" id="stIps">0<small>Unique IPs</small></div>
|
|
112
|
-
<div class="stat" id="stBan">0<small>Banned</small></div>
|
|
113
|
-
<div class="stat" id="stStatus">open<small>Status</small></div>
|
|
114
|
-
</div>
|
|
115
|
-
<div class="small" id="stSince" style="margin-top:10px"></div>
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
<div class="grid">
|
|
119
|
-
<div class="card">
|
|
120
|
-
<h2 style="margin:0 0 6px">Bans</h2>
|
|
121
|
-
<p class="sub">Banned IPs cannot load any page.</p>
|
|
122
|
-
<div class="row">
|
|
123
|
-
<input id="banIp" placeholder="IP address" style="flex:1">
|
|
124
|
-
<button class="btn danger" id="banBtn">Ban IP</button>
|
|
125
|
-
<button id="clearBansBtn">Clear</button>
|
|
126
|
-
</div>
|
|
127
|
-
<div style="max-height:280px;overflow:auto;margin-top:12px">
|
|
128
|
-
<table><thead><tr><th>IP</th><th>Since</th><th></th></tr></thead><tbody id="banBody"></tbody></table>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
<div class="card">
|
|
133
|
-
<h2 style="margin:0 0 6px">All IPs</h2>
|
|
134
|
-
<p class="sub">Every IP that has touched the server.</p>
|
|
135
|
-
<div class="row"><button id="refreshIpsBtn">Refresh IPs</button><button id="clearIpsBtn">Clear Stats</button></div>
|
|
136
|
-
<div style="max-height:340px;overflow:auto;margin-top:12px">
|
|
137
|
-
<table><thead><tr><th>IP</th><th>Hits</th><th>Last seen</th><th></th></tr></thead><tbody id="ipBody"></tbody></table>
|
|
138
|
-
</div>
|
|
139
|
-
</div>
|
|
140
|
-
</div>
|
|
141
|
-
|
|
142
|
-
<div class="grid">
|
|
143
|
-
<div class="card">
|
|
144
|
-
<h2 style="margin:0 0 6px">Site Settings</h2>
|
|
145
|
-
<p class="sub">Server-side key/value overrides.</p>
|
|
146
|
-
<div class="row">
|
|
147
|
-
<input id="siteKey" placeholder="key" style="flex:1">
|
|
148
|
-
<input id="siteVal" placeholder="value" style="flex:2">
|
|
149
|
-
<button id="siteAddBtn">Set</button>
|
|
150
|
-
</div>
|
|
151
|
-
<div id="siteList" style="margin-top:12px"></div>
|
|
152
|
-
</div>
|
|
153
|
-
|
|
154
|
-
<div class="card">
|
|
155
|
-
<h2 style="margin:0 0 6px">Danger Zone</h2>
|
|
156
|
-
<p class="sub">Nuclear options.</p>
|
|
157
|
-
<div class="row">
|
|
158
|
-
<button class="btn danger" id="wipeBtn">Reset All Admin Data</button>
|
|
159
|
-
<button class="btn danger" id="closeAllBtn">Close Site Now</button>
|
|
160
|
-
</div>
|
|
161
|
-
<p class="small" style="margin-top:12px">Reset clears bans, IP stats, announcements, AI overrides, and reopens the site.</p>
|
|
162
|
-
</div>
|
|
163
|
-
</div>
|
|
164
|
-
</div>
|
|
165
|
-
</div>
|
|
166
|
-
|
|
167
|
-
<script>
|
|
168
|
-
const $=id=>document.getElementById(id);
|
|
169
|
-
let KEY=sessionStorage.getItem('phk_admin_key')||'';
|
|
170
|
-
let S=null;
|
|
171
|
-
function esc(s){return String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
|
172
|
-
function fmtTime(t){return t?new Date(t).toLocaleString():'—'}
|
|
173
|
-
async function api(path,opts={}){
|
|
174
|
-
const r=await fetch(path,{...opts,headers:{'Content-Type':'application/json','x-admin-key':KEY,...(opts.headers||{})}});
|
|
175
|
-
const j=await r.json().catch(()=>({}));
|
|
176
|
-
if(r.status===401){sessionStorage.removeItem('phk_admin_key');showLogin('Bad password');throw new Error('auth')}
|
|
177
|
-
if(!r.ok)throw new Error(j.error||('HTTP '+r.status));
|
|
178
|
-
return j;
|
|
179
|
-
}
|
|
180
|
-
function showLogin(msg){$('login').classList.remove('hidden');$('dash').classList.add('hidden');$('loginErr').textContent=msg||''}
|
|
181
|
-
function showDash(){ $('login').classList.add('hidden');$('dash').classList.remove('hidden'); }
|
|
182
|
-
async function load(){ S=
|
|
183
|
-
async function act(action,payload={}){ const j=await api('/api/admin/action',{method:'POST',body:JSON.stringify({action,...payload})}); S=j.state; render(); }
|
|
184
|
-
function render(){
|
|
185
|
-
if(!S)return;
|
|
186
|
-
$('statusPill').textContent=S.status;$('statusPill').className='pill '+S.status;
|
|
187
|
-
$('stReq').innerHTML=S.stats.requests+'<small>Requests</small>';
|
|
188
|
-
$('stIps').innerHTML=S.stats.uniqueIps+'<small>Unique IPs</small>';
|
|
189
|
-
$('stBan').innerHTML=S.stats.banned+'<small>Banned</small>';
|
|
190
|
-
$('stStatus').textContent=S.status;$('stSince').textContent='Tracking since '+fmtTime(S.stats.started);
|
|
191
|
-
$('statusMsg').value=S.message||'';
|
|
192
|
-
$('annActive').checked=!!S.announcement.active;$('annText').value=S.announcement.text||'';
|
|
193
|
-
$('aiEnabled').checked=S.ai.enabled!==false;$('aiModel').value=S.ai.model||'';$('aiPrompt').value=S.ai.systemPrompt||'';
|
|
194
|
-
$('aiTemp').value=S.ai.temperature??0.8;$('aiTok').value=S.ai.maxTokens??800;
|
|
195
|
-
$('aiTempVal').textContent=$('aiTemp').value;$('aiTokVal').textContent=$('aiTok').value;
|
|
196
|
-
$('banBody').innerHTML=S.bans.map(b=>`<tr><td class="mono">${esc(b.ip)}</td><td>${fmtTime(b.since)}</td><td><button data-unban="${esc(b.ip)}">Unban</button></td></tr>`).join('')||'<tr><td colspan="3" class="small">No bans</td></tr>';
|
|
197
|
-
$('ipBody').innerHTML=S.ips.map(i=>`<tr><td class="mono">${esc(i.ip)}</td><td>${i.count}</td><td>${fmtTime(i.last)}</td><td><button data-banip="${esc(i.ip)}">Ban</button></td></tr>`).join('')||'<tr><td colspan="4" class="small">No IPs yet</td></tr>';
|
|
198
|
-
const site=Object.entries(S.site||{});
|
|
199
|
-
$('siteList').innerHTML=site.map(([k,v])=>`<div class="item"><div><b>${esc(k)}</b><div class="small mono">${esc(v)}</div></div><button data-delsite="${esc(k)}">Delete</button></div>`).join('')||'<div class="small">No site settings</div>';
|
|
200
|
-
}
|
|
201
|
-
$('loginBtn').onclick=async()=>{KEY=$('pass').value.trim();sessionStorage.setItem('phk_admin_key',KEY);try{await load();showDash()}catch(e){
|
|
202
|
-
$('pass').addEventListener('keydown',e=>{if(e.key==='Enter')$('loginBtn').click()});
|
|
203
|
-
$('logoutBtn').onclick=()=>{sessionStorage.removeItem('phk_admin_key');KEY='';showLogin('')};
|
|
204
|
-
$('refreshBtn').onclick=load;$('refreshIpsBtn').onclick=load;
|
|
205
|
-
$('openBtn').onclick=()=>act('status',{status:'open',message:$('statusMsg').value});
|
|
206
|
-
$('closeBtn').onclick=()=>act('status',{status:'closed',message:$('statusMsg').value});
|
|
207
|
-
$('maintBtn').onclick=()=>act('status',{status:'maintenance',message:$('statusMsg').value});
|
|
208
|
-
$('applyStatusBtn').onclick=()=>act('status',{status:S.status,message:$('statusMsg').value});
|
|
209
|
-
$('applyAnnBtn').onclick=()=>act('announcement',{active:$('annActive').checked,text:$('annText').value});
|
|
210
|
-
$('clearAnnBtn').onclick=()=>act('announcement',{active:false,text:''});
|
|
211
|
-
$('applyAiBtn').onclick=()=>act('ai',{enabled:$('aiEnabled').checked,model:$('aiModel').value.trim(),systemPrompt:$('aiPrompt').value,temperature:parseFloat($('aiTemp').value),maxTokens:parseInt($('aiTok').value,10)});
|
|
212
|
-
$('banBtn').onclick=()=>{const ip=$('banIp').value.trim();if(ip)act('ban',{ip}).then(()=>{$('banIp').value='';load()})};
|
|
213
|
-
$('clearBansBtn').onclick=()=>act('clearBans');$('clearIpsBtn').onclick=()=>act('clearIps');
|
|
214
|
-
$('siteAddBtn').onclick=()=>{const k=$('siteKey').value.trim(),v=$('siteVal').value;if(k)act('siteSetting',{key:k,value:v}).then(()=>{$('siteKey').value='';$('siteVal').value=''})};
|
|
215
|
-
$('wipeBtn').onclick=async()=>{if(confirm('Reset ALL admin data and reopen the site?'))await act('resetState')};
|
|
216
|
-
$('closeAllBtn').onclick=async()=>{if(confirm('Close the entire site for everyone right now?'))await act('status',{status:'closed',message:'Closed by admin.'})};
|
|
217
|
-
$('aiTemp').oninput=()=>$('aiTempVal').textContent=$('aiTemp').value;
|
|
218
|
-
$('aiTok').oninput=()=>$('aiTokVal').textContent=$('aiTok').value;
|
|
219
|
-
document.addEventListener('click',async e=>{
|
|
220
|
-
const ub=e.target.dataset&&e.target.dataset.unban;if(ub)await act('unban',{ip:ub});
|
|
221
|
-
const bi=e.target.dataset&&e.target.dataset.banip;if(bi)await act('ban',{ip:bi});
|
|
222
|
-
const ds=e.target.dataset&&e.target.dataset.delsite;if(ds)await act('siteSettingDelete',{key:ds});
|
|
223
|
-
});
|
|
224
|
-
(async()=>{if(KEY){try{await load();showDash();return}catch(e){
|
|
225
|
-
</script>
|
|
226
|
-
</body>
|
|
227
|
-
</html>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>Admin</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root{--bg:#000;--panel:rgba(255,255,255,.07);--line:rgba(255,255,255,.14);--txt:#f5f5f7;--mut:#9a9aa3;--acc:#fff}
|
|
9
|
+
*{box-sizing:border-box}
|
|
10
|
+
body{margin:0;min-height:100vh;background:var(--bg);color:var(--txt);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif}
|
|
11
|
+
.wrap{max-width:1180px;margin:0 auto;padding:26px 18px 80px}
|
|
12
|
+
.card{background:var(--panel);border:1px solid var(--line);border-radius:22px;padding:20px;margin:16px 0;backdrop-filter:blur(20px)}
|
|
13
|
+
h1{font-size:28px;margin:0}.sub{color:var(--mut);font-size:13px}
|
|
14
|
+
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
|
|
15
|
+
input,textarea,select{width:100%;background:rgba(255,255,255,.08);border:1px solid var(--line);color:var(--txt);border-radius:14px;padding:11px 13px;font:inherit}
|
|
16
|
+
textarea{min-height:80px;resize:vertical}
|
|
17
|
+
button,.btn{appearance:none;border:1px solid var(--line);background:rgba(255,255,255,.1);color:var(--txt);border-radius:14px;padding:10px 14px;font:inherit;font-weight:700;cursor:pointer;transition:.15s}
|
|
18
|
+
button:hover,.btn:hover{background:rgba(255,255,255,.18);transform:translateY(-1px)}
|
|
19
|
+
.btn.primary{background:#fff;color:#000;border-color:#fff}
|
|
20
|
+
.btn.danger{background:rgba(255,69,58,.16);border-color:rgba(255,69,58,.4);color:#ff8a80}
|
|
21
|
+
.btn.good{background:rgba(52,199,89,.14);border-color:rgba(52,199,89,.35);color:#7dffa8}
|
|
22
|
+
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:14px}
|
|
23
|
+
label{display:block;font-size:12px;color:var(--mut);margin:10px 0 6px;font-weight:700;text-transform:uppercase;letter-spacing:.06em}
|
|
24
|
+
table{width:100%;border-collapse:collapse;font-size:13px}
|
|
25
|
+
th,td{text-align:left;padding:9px 8px;border-bottom:1px solid rgba(255,255,255,.08);vertical-align:top}
|
|
26
|
+
th{color:var(--mut);font-size:11px;text-transform:uppercase;letter-spacing:.06em}
|
|
27
|
+
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
28
|
+
.pill{display:inline-block;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:800;border:1px solid var(--line)}
|
|
29
|
+
.pill.open{background:rgba(52,199,89,.14);color:#7dffa8;border-color:rgba(52,199,89,.4)}
|
|
30
|
+
.pill.closed,.pill.maintenance{background:rgba(255,159,10,.14);color:#ffd180;border-color:rgba(255,159,10,.4)}
|
|
31
|
+
.stat{font-size:26px;font-weight:900}.stat small{display:block;font-size:11px;color:var(--mut);font-weight:600}
|
|
32
|
+
.login{max-width:420px;margin:12vh auto}
|
|
33
|
+
.hidden{display:none!important}
|
|
34
|
+
.small{font-size:12px;color:var(--mut)}
|
|
35
|
+
.item{display:flex;justify-content:space-between;gap:10px;padding:9px 0;border-bottom:1px solid rgba(255,255,255,.08)}
|
|
36
|
+
.item:last-child{border-bottom:0}
|
|
37
|
+
@media(max-width:720px){.wrap{padding:16px 12px 60px}}
|
|
38
|
+
</style>
|
|
39
|
+
</head>
|
|
40
|
+
<body>
|
|
41
|
+
<div class="wrap">
|
|
42
|
+
<div id="login" class="card login hidden">
|
|
43
|
+
<h1>Admin</h1>
|
|
44
|
+
<p class="sub">Enter admin password. Requires server.js running.</p>
|
|
45
|
+
<label>Admin password</label>
|
|
46
|
+
<input id="pass" type="password" placeholder="Password" autocomplete="off">
|
|
47
|
+
<div style="height:14px"></div>
|
|
48
|
+
<button class="btn primary" id="loginBtn" style="width:100%">Unlock</button>
|
|
49
|
+
<div class="small" id="loginErr" style="margin-top:10px"></div>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<div id="dash" class="hidden">
|
|
53
|
+
<div class="card row" style="justify-content:space-between">
|
|
54
|
+
<div>
|
|
55
|
+
<h1>Admin Panel</h1>
|
|
56
|
+
<div class="sub">Global controls for every visitor. Changes apply instantly.</div>
|
|
57
|
+
</div>
|
|
58
|
+
<div class="row">
|
|
59
|
+
<span id="statusPill" class="pill open">open</span>
|
|
60
|
+
<button id="refreshBtn">Refresh</button>
|
|
61
|
+
<button id="logoutBtn">Lock</button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div class="grid">
|
|
66
|
+
<div class="card">
|
|
67
|
+
<h2 style="margin:0 0 6px">Site Control</h2>
|
|
68
|
+
<p class="sub">Kill switch works server-side for all IPs.</p>
|
|
69
|
+
<div class="row" style="margin-top:12px">
|
|
70
|
+
<button class="btn good" id="openBtn">Open Site</button>
|
|
71
|
+
<button class="btn danger" id="closeBtn">Close Site</button>
|
|
72
|
+
<button class="btn" id="maintBtn">Maintenance</button>
|
|
73
|
+
</div>
|
|
74
|
+
<label>Message shown to visitors</label>
|
|
75
|
+
<textarea id="statusMsg" placeholder="Optional message for closed/maintenance mode"></textarea>
|
|
76
|
+
<div style="height:10px"></div>
|
|
77
|
+
<button class="btn primary" id="applyStatusBtn">Apply Status</button>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<div class="card">
|
|
81
|
+
<h2 style="margin:0 0 6px">Announcement</h2>
|
|
82
|
+
<p class="sub">Shown as a toast on every page.</p>
|
|
83
|
+
<label><input type="checkbox" id="annActive" style="width:auto"> Active</label>
|
|
84
|
+
<label>Announcement text</label>
|
|
85
|
+
<input id="annText" placeholder="Announcement">
|
|
86
|
+
<div style="height:10px"></div>
|
|
87
|
+
<button class="btn primary" id="applyAnnBtn">Publish</button>
|
|
88
|
+
<button id="clearAnnBtn">Clear</button>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
<div class="card">
|
|
92
|
+
<h2 style="margin:0 0 6px">AI Control</h2>
|
|
93
|
+
<p class="sub">Global Gemini defaults.</p>
|
|
94
|
+
<label><input type="checkbox" id="aiEnabled" style="width:auto"> AI enabled</label>
|
|
95
|
+
<label>Model</label>
|
|
96
|
+
<input id="aiModel" placeholder="gemini-2.0-flash">
|
|
97
|
+
<label>System prompt</label>
|
|
98
|
+
<textarea id="aiPrompt" placeholder="You are a helpful assistant."></textarea>
|
|
99
|
+
<div class="row">
|
|
100
|
+
<div style="flex:1"><label>Temperature <span id="aiTempVal"></span></label><input id="aiTemp" type="range" min="0" max="2" step="0.1"></div>
|
|
101
|
+
<div style="flex:1"><label>Max tokens <span id="aiTokVal"></span></label><input id="aiTok" type="range" min="128" max="4096" step="128"></div>
|
|
102
|
+
</div>
|
|
103
|
+
<div style="height:10px"></div>
|
|
104
|
+
<button class="btn primary" id="applyAiBtn">Apply AI</button>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div class="card">
|
|
108
|
+
<h2 style="margin:0 0 6px">Stats</h2>
|
|
109
|
+
<div class="grid">
|
|
110
|
+
<div class="stat" id="stReq">0<small>Requests</small></div>
|
|
111
|
+
<div class="stat" id="stIps">0<small>Unique IPs</small></div>
|
|
112
|
+
<div class="stat" id="stBan">0<small>Banned</small></div>
|
|
113
|
+
<div class="stat" id="stStatus">open<small>Status</small></div>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="small" id="stSince" style="margin-top:10px"></div>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
<div class="grid">
|
|
119
|
+
<div class="card">
|
|
120
|
+
<h2 style="margin:0 0 6px">Bans</h2>
|
|
121
|
+
<p class="sub">Banned IPs cannot load any page.</p>
|
|
122
|
+
<div class="row">
|
|
123
|
+
<input id="banIp" placeholder="IP address" style="flex:1">
|
|
124
|
+
<button class="btn danger" id="banBtn">Ban IP</button>
|
|
125
|
+
<button id="clearBansBtn">Clear</button>
|
|
126
|
+
</div>
|
|
127
|
+
<div style="max-height:280px;overflow:auto;margin-top:12px">
|
|
128
|
+
<table><thead><tr><th>IP</th><th>Since</th><th></th></tr></thead><tbody id="banBody"></tbody></table>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div class="card">
|
|
133
|
+
<h2 style="margin:0 0 6px">All IPs</h2>
|
|
134
|
+
<p class="sub">Every IP that has touched the server.</p>
|
|
135
|
+
<div class="row"><button id="refreshIpsBtn">Refresh IPs</button><button id="clearIpsBtn">Clear Stats</button></div>
|
|
136
|
+
<div style="max-height:340px;overflow:auto;margin-top:12px">
|
|
137
|
+
<table><thead><tr><th>IP</th><th>Hits</th><th>Last seen</th><th></th></tr></thead><tbody id="ipBody"></tbody></table>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<div class="grid">
|
|
143
|
+
<div class="card">
|
|
144
|
+
<h2 style="margin:0 0 6px">Site Settings</h2>
|
|
145
|
+
<p class="sub">Server-side key/value overrides.</p>
|
|
146
|
+
<div class="row">
|
|
147
|
+
<input id="siteKey" placeholder="key" style="flex:1">
|
|
148
|
+
<input id="siteVal" placeholder="value" style="flex:2">
|
|
149
|
+
<button id="siteAddBtn">Set</button>
|
|
150
|
+
</div>
|
|
151
|
+
<div id="siteList" style="margin-top:12px"></div>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<div class="card">
|
|
155
|
+
<h2 style="margin:0 0 6px">Danger Zone</h2>
|
|
156
|
+
<p class="sub">Nuclear options.</p>
|
|
157
|
+
<div class="row">
|
|
158
|
+
<button class="btn danger" id="wipeBtn">Reset All Admin Data</button>
|
|
159
|
+
<button class="btn danger" id="closeAllBtn">Close Site Now</button>
|
|
160
|
+
</div>
|
|
161
|
+
<p class="small" style="margin-top:12px">Reset clears bans, IP stats, announcements, AI overrides, and reopens the site.</p>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<script>
|
|
168
|
+
const $=id=>document.getElementById(id);
|
|
169
|
+
let KEY=sessionStorage.getItem('phk_admin_key')||'';
|
|
170
|
+
let S=null;
|
|
171
|
+
function esc(s){return String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
|
172
|
+
function fmtTime(t){return t?new Date(t).toLocaleString():'—'}
|
|
173
|
+
async function api(path,opts={}){
|
|
174
|
+
const r=await fetch(path,{...opts,headers:{'Content-Type':'application/json','x-admin-key':KEY,...(opts.headers||{})}});
|
|
175
|
+
const j=await r.json().catch(()=>({}));
|
|
176
|
+
if(r.status===401){sessionStorage.removeItem('phk_admin_key');showLogin('Bad password');throw new Error('auth')}
|
|
177
|
+
if(!r.ok)throw new Error(j.error||('HTTP '+r.status));
|
|
178
|
+
return j;
|
|
179
|
+
}
|
|
180
|
+
function showLogin(msg){$('login').classList.remove('hidden');$('dash').classList.add('hidden');$('loginErr').textContent=msg||''}
|
|
181
|
+
function showDash(){ $('login').classList.add('hidden');$('dash').classList.remove('hidden'); }
|
|
182
|
+
async function load(){ S=await api('/api/admin/state'); render(); }
|
|
183
|
+
async function act(action,payload={}){ const j=await api('/api/admin/action',{method:'POST',body:JSON.stringify({action,...payload})}); S=j.state; render(); }
|
|
184
|
+
function render(){
|
|
185
|
+
if(!S)return;
|
|
186
|
+
$('statusPill').textContent=S.status;$('statusPill').className='pill '+S.status;
|
|
187
|
+
$('stReq').innerHTML=S.stats.requests+'<small>Requests</small>';
|
|
188
|
+
$('stIps').innerHTML=S.stats.uniqueIps+'<small>Unique IPs</small>';
|
|
189
|
+
$('stBan').innerHTML=S.stats.banned+'<small>Banned</small>';
|
|
190
|
+
$('stStatus').textContent=S.status;$('stSince').textContent='Tracking since '+fmtTime(S.stats.started);
|
|
191
|
+
$('statusMsg').value=S.message||'';
|
|
192
|
+
$('annActive').checked=!!S.announcement.active;$('annText').value=S.announcement.text||'';
|
|
193
|
+
$('aiEnabled').checked=S.ai.enabled!==false;$('aiModel').value=S.ai.model||'';$('aiPrompt').value=S.ai.systemPrompt||'';
|
|
194
|
+
$('aiTemp').value=S.ai.temperature??0.8;$('aiTok').value=S.ai.maxTokens??800;
|
|
195
|
+
$('aiTempVal').textContent=$('aiTemp').value;$('aiTokVal').textContent=$('aiTok').value;
|
|
196
|
+
$('banBody').innerHTML=S.bans.map(b=>`<tr><td class="mono">${esc(b.ip)}</td><td>${fmtTime(b.since)}</td><td><button data-unban="${esc(b.ip)}">Unban</button></td></tr>`).join('')||'<tr><td colspan="3" class="small">No bans</td></tr>';
|
|
197
|
+
$('ipBody').innerHTML=S.ips.map(i=>`<tr><td class="mono">${esc(i.ip)}</td><td>${i.count}</td><td>${fmtTime(i.last)}</td><td><button data-banip="${esc(i.ip)}">Ban</button></td></tr>`).join('')||'<tr><td colspan="4" class="small">No IPs yet</td></tr>';
|
|
198
|
+
const site=Object.entries(S.site||{});
|
|
199
|
+
$('siteList').innerHTML=site.map(([k,v])=>`<div class="item"><div><b>${esc(k)}</b><div class="small mono">${esc(v)}</div></div><button data-delsite="${esc(k)}">Delete</button></div>`).join('')||'<div class="small">No site settings</div>';
|
|
200
|
+
}
|
|
201
|
+
$('loginBtn').onclick=async()=>{KEY=$('pass').value.trim();sessionStorage.setItem('phk_admin_key',KEY);try{await load();showDash()}catch(e){showLogin(e.message==='auth'?'Bad password':('Admin API unreachable ('+e.message+') — start server.js first'))}};
|
|
202
|
+
$('pass').addEventListener('keydown',e=>{if(e.key==='Enter')$('loginBtn').click()});
|
|
203
|
+
$('logoutBtn').onclick=()=>{sessionStorage.removeItem('phk_admin_key');KEY='';showLogin('')};
|
|
204
|
+
$('refreshBtn').onclick=load;$('refreshIpsBtn').onclick=load;
|
|
205
|
+
$('openBtn').onclick=()=>act('status',{status:'open',message:$('statusMsg').value});
|
|
206
|
+
$('closeBtn').onclick=()=>act('status',{status:'closed',message:$('statusMsg').value});
|
|
207
|
+
$('maintBtn').onclick=()=>act('status',{status:'maintenance',message:$('statusMsg').value});
|
|
208
|
+
$('applyStatusBtn').onclick=()=>act('status',{status:S.status,message:$('statusMsg').value});
|
|
209
|
+
$('applyAnnBtn').onclick=()=>act('announcement',{active:$('annActive').checked,text:$('annText').value});
|
|
210
|
+
$('clearAnnBtn').onclick=()=>act('announcement',{active:false,text:''});
|
|
211
|
+
$('applyAiBtn').onclick=()=>act('ai',{enabled:$('aiEnabled').checked,model:$('aiModel').value.trim(),systemPrompt:$('aiPrompt').value,temperature:parseFloat($('aiTemp').value),maxTokens:parseInt($('aiTok').value,10)});
|
|
212
|
+
$('banBtn').onclick=()=>{const ip=$('banIp').value.trim();if(ip)act('ban',{ip}).then(()=>{$('banIp').value='';load()})};
|
|
213
|
+
$('clearBansBtn').onclick=()=>act('clearBans');$('clearIpsBtn').onclick=()=>act('clearIps');
|
|
214
|
+
$('siteAddBtn').onclick=()=>{const k=$('siteKey').value.trim(),v=$('siteVal').value;if(k)act('siteSetting',{key:k,value:v}).then(()=>{$('siteKey').value='';$('siteVal').value=''})};
|
|
215
|
+
$('wipeBtn').onclick=async()=>{if(confirm('Reset ALL admin data and reopen the site?'))await act('resetState')};
|
|
216
|
+
$('closeAllBtn').onclick=async()=>{if(confirm('Close the entire site for everyone right now?'))await act('status',{status:'closed',message:'Closed by admin.'})};
|
|
217
|
+
$('aiTemp').oninput=()=>$('aiTempVal').textContent=$('aiTemp').value;
|
|
218
|
+
$('aiTok').oninput=()=>$('aiTokVal').textContent=$('aiTok').value;
|
|
219
|
+
document.addEventListener('click',async e=>{
|
|
220
|
+
const ub=e.target.dataset&&e.target.dataset.unban;if(ub)await act('unban',{ip:ub});
|
|
221
|
+
const bi=e.target.dataset&&e.target.dataset.banip;if(bi)await act('ban',{ip:bi});
|
|
222
|
+
const ds=e.target.dataset&&e.target.dataset.delsite;if(ds)await act('siteSettingDelete',{key:ds});
|
|
223
|
+
});
|
|
224
|
+
(async()=>{if(KEY){try{await load();showDash();return}catch(e){showLogin(e.message==='auth'?'Bad password':('Admin API unreachable ('+e.message+') — start server.js first')}}showLogin('')})();
|
|
225
|
+
</script>
|
|
226
|
+
</body>
|
|
227
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "studyable-math",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Studyable math games site",
|
|
5
|
-
"main": "index.html",
|
|
6
|
-
"unpkg": "index.html",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"files": [
|
|
9
|
-
"index.html",
|
|
10
|
-
"home.html",
|
|
11
|
-
"games.html",
|
|
12
|
-
"ai.html",
|
|
13
|
-
"settings.html",
|
|
14
|
-
"admin.html",
|
|
15
|
-
"settings.js",
|
|
16
|
-
"games.js",
|
|
17
|
-
"games-data.js",
|
|
18
|
-
"rug-catalog.js",
|
|
19
|
-
"style.css"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"start": "node server.js"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "studyable-math",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Studyable math games site",
|
|
5
|
+
"main": "index.html",
|
|
6
|
+
"unpkg": "index.html",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.html",
|
|
10
|
+
"home.html",
|
|
11
|
+
"games.html",
|
|
12
|
+
"ai.html",
|
|
13
|
+
"settings.html",
|
|
14
|
+
"admin.html",
|
|
15
|
+
"settings.js",
|
|
16
|
+
"games.js",
|
|
17
|
+
"games-data.js",
|
|
18
|
+
"rug-catalog.js",
|
|
19
|
+
"style.css"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"start": "node server.js"
|
|
23
|
+
}
|
|
24
|
+
}
|