Embed server operations into the normal account control panel
This commit is contained in:
parent
d0d89e2cc1
commit
985f87904d
7 changed files with 14 additions and 3 deletions
|
|
@ -13,3 +13,5 @@ The existing SSH tunnel now also forwards website-loopback 15433 to game-loopbac
|
|||
Agent systemd service: `dunerealms-server-control`; existing tunnel: `dunerealms-inventory-tunnel`. The agent needs system service control and console FIFO access, and runs under a read-only filesystem sandbox with private temporary files. Deploy agent changes to `/opt/dunerealms/server-control/agent.py` and restart its service. Tests: `python3 -m unittest discover -s network/server-control -p test_agent.py` and the website test suite.
|
||||
|
||||
Live deployment 28 October 2026: website release `20261028-server-panel`, 60 website tests and 4 Python agent tests passed. Authenticated status, logs, a harmless `list` command and an idempotent `start` of the active Arrakis service passed through the public HTTPS API. Foreign-origin writes returned 403; unauthenticated controls returned 401. Browser review confirmed the operator interface. No real restart was required for the panel acceptance test.
|
||||
|
||||
The normal account dashboard also embeds these controls under a Servers navigation tab. The embedded view uses the same session and operator checks, hides duplicate site chrome, and reports only its layout height to its same-origin parent. The CP framing policy explicitly permits itself and the main website; other origins remain blocked.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -15,9 +15,12 @@ $('refresh-rewards').onclick=()=>action($('refresh-rewards'),rewards);
|
|||
$('password-form').onsubmit=event=>{event.preventDefault();action(event.target.querySelector('button'),async()=>{await api('auth/password',Object.fromEntries(new FormData(event.target)));event.target.reset();notice('Password changed. Other sessions have been signed out.');});};
|
||||
async function campaigns(){const data=await api('community/campaigns');$('campaigns').replaceChildren();for(const row of data.campaigns){const card=el('article');card.className='reward';card.append(el('h3',row.month),el('p',new Intl.NumberFormat(undefined,{style:'currency',currency:'EUR'}).format(row.received_cents/100)+' / '+new Intl.NumberFormat(undefined,{style:'currency',currency:'EUR'}).format(row.target_cents/100)),el('p',row.reward_amount+' Dunemarks per UUID · '+(row.reached_at?'Goal reached':'Not reached')));$('campaigns').append(card);}}
|
||||
for(const [form,endpoint]of [['campaign-form','community/campaigns'],['total-form','community/verify-total']])$(form).onsubmit=event=>{event.preventDefault();action(event.target.querySelector('button'),async()=>{const data=Object.fromEntries(new FormData(event.target));for(const key of ['targetCents','rewardAmount','receivedCents'])if(key in data)data[key]=Number(data[key]);if(!confirm(endpoint.endsWith('verify-total')?'Confirm that this total is verified against payment records? Reaching the target unlocks rewards.':'Create this goal? The target and reward cannot be edited afterward.'))return;await api(endpoint,data);notice('Saved.');await campaigns();});};
|
||||
async function load(){const data=await api('auth/session');session=data.user;document.querySelector('.account-summary').textContent=data.authenticated?'Signed in as '+data.user.username:'Your dunerealms.com account';$('auth').hidden=data.authenticated;$('dashboard').hidden=!data.authenticated;$('logout').hidden=!data.authenticated;$('welcome').textContent=data.authenticated?'Welcome, '+data.user.username+'.':'Welcome, traveller.';if(data.authenticated){$('staff').hidden=!data.user.staff;$('staff-tab').hidden=!data.user.staff;await linking();await rewards();if(data.user.staff){await campaigns();await accounts();}}}
|
||||
async function load(){const data=await api('auth/session');session=data.user;document.querySelector('.account-summary').textContent=data.authenticated?'Signed in as '+data.user.username:'Your dunerealms.com account';$('auth').hidden=data.authenticated;$('dashboard').hidden=!data.authenticated;$('logout').hidden=!data.authenticated;$('welcome').textContent=data.authenticated?'Welcome, '+data.user.username+'.':'Welcome, traveller.';if(data.authenticated){$('staff').hidden=!data.user.staff;$('staff-tab').hidden=!data.user.staff;await linking();await rewards();if(data.user.staff){await serverControls();await campaigns();await accounts();}}}
|
||||
async function accounts(){const data=await api('admin/accounts');$('accounts').replaceChildren();for(const row of data.accounts){const card=el('article');card.className='reward';card.append(el('h3',row.username+' · '+row.role),el('p',row.minecraft_uuid?'Linked UUID: '+row.minecraft_uuid:'No verified game account'));const revoke=el('button','Sign out this account');revoke.onclick=()=>{if(confirm('Revoke current sessions for '+row.username+'?'))action(revoke,async()=>{await api('admin/revoke-sessions',{userId:row.id});notice('Sessions revoked.');});};card.append(revoke);$('accounts').append(card);}}
|
||||
$('refresh-accounts').onclick=()=>action($('refresh-accounts'),accounts);
|
||||
load().catch(error=>notice(error.message));
|
||||
// Embedded parent receives only layout information, never credentials, UUIDs or reward codes.
|
||||
new ResizeObserver(()=>{if(parent!==window)for(const origin of ['https://www.dunerealms.com','https://dunerealms.com'])parent.postMessage({type:'dunerealms-account-height',height:document.documentElement.scrollHeight},origin);}).observe(document.body);
|
||||
|
||||
async function serverControls(){let allowed=false;try{await api('servers');allowed=true;}catch{}$('servers-tab').hidden=!allowed;$('server-operations').hidden=!allowed;const frame=$('server-controls-frame');if(allowed&&!frame.getAttribute('src'))frame.src='/servers?embedded=1';if(!allowed)frame.removeAttribute('src');}
|
||||
window.addEventListener('message',event=>{const frame=$('server-controls-frame');if(event.origin!==location.origin||event.source!==frame.contentWindow||event.data?.type!=='dune-server-panel-height')return;const height=event.data.height;if(Number.isFinite(height))frame.style.height=Math.max(700,Math.min(4000,height))+'px';});
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
.server-workspace{padding:clamp(18px,4vw,40px);background:#f7edcf;border:3px double #99835b;color:#283b35}.server-heading{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}.server-heading h2{margin:14px 0}.server-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:20px;margin:26px 0}.server-card{padding:22px;background:#e7dab4;border:2px solid #a58a56;box-shadow:inset 0 0 0 3px #f4e8c7}.server-card h3{margin-top:0}.server-actions{display:flex;gap:8px;flex-wrap:wrap}.server-state{font-weight:bold;color:#6b4933}.server-state.online{color:#28634f}.server-player-count{font-size:1.1em}.console-panel{border-top:2px solid #b19962;padding-top:20px}#console{height:390px;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;padding:20px;background:#142a28;color:#f2df9e;border:3px double #bd9c51;font:13px/1.6 ui-monospace,Consolas,monospace}#command-form{display:flex;gap:16px;align-items:end}#command-form label{flex:1}#command-form button{margin-bottom:0}#notice{min-height:24px;font-weight:bold}select{padding:10px;border:1px solid #8f7b53;background:#fff9e6;color:#19362e;font:inherit}[hidden]{display:none!important}@media(max-width:600px){#command-form{display:block}#console{height:320px}.server-heading{align-items:stretch}}
|
||||
|
||||
.server-embedded .site-header,.server-embedded .panel-hero,.server-embedded .site-footer,.server-embedded .skip{display:none}.server-embedded{min-height:0;background:#f7edcf}.server-embedded .cp-shell{max-width:none;margin:0;padding:0}.server-embedded .server-workspace{padding:16px;border:0}
|
||||
|
|
|
|||
|
|
@ -9,3 +9,5 @@ async function readLog(){try{const id=$('log-server').value;const data=await api
|
|||
$('refresh').onclick=refresh;$('refresh-log').onclick=readLog;$('log-server').onchange=readLog;
|
||||
$('command-form').onsubmit=async event=>{event.preventDefault();const input=$('command'),command=input.value.trim();if(!/^[A-Za-z][ -~]{0,239}$/.test(command)){notice('Enter one command without a leading slash.');return;}await act($('log-server').value,'command',command);input.value='';setTimeout(readLog,1000);};
|
||||
refresh().then(()=>{if(ready)readLog();});setInterval(()=>{if(ready&&!busy&&!document.hidden)refresh();},15000);
|
||||
|
||||
if(new URLSearchParams(location.search).get('embedded')==='1'){document.body.classList.add('server-embedded');const report=()=>parent.postMessage({type:'dune-server-panel-height',height:document.documentElement.scrollHeight},location.origin);new ResizeObserver(report).observe(document.body);report();}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export async function startPanel(settings=process.env){
|
|||
let inventoryPool=null;
|
||||
if(settings.DUNE_INVENTORY_DATABASE_URL){const {Pool}=await import('pg');inventoryPool=new Pool({connectionString:settings.DUNE_INVENTORY_DATABASE_URL,max:3,connectionTimeoutMillis:5000,idleTimeoutMillis:30000});inventoryPool.on('error',()=>console.error('Inventory database connection unavailable.'));}
|
||||
const db=await openDatabase(settings),handle=createPanel(db,settings,{inventoryPool}),origin=settings.CP_ORIGIN||'https://cp.dunerealms.com';
|
||||
const security={'X-Content-Type-Options':'nosniff','Referrer-Policy':'no-referrer','Cache-Control':'no-store','Content-Security-Policy':"default-src 'self'; script-src 'self'; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; connect-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors https://www.dunerealms.com https://dunerealms.com"};
|
||||
const security={'X-Content-Type-Options':'nosniff','Referrer-Policy':'no-referrer','Cache-Control':'no-store','Content-Security-Policy':"default-src 'self'; script-src 'self'; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; connect-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'self' https://www.dunerealms.com https://dunerealms.com"};
|
||||
const server=createServer(async(req,res)=>{try{
|
||||
req.setTimeout(15000);let length=0;const chunks=[];for await(const chunk of req){length+=chunk.length;if(length>16384){res.writeHead(413,security);res.end();return;}chunks.push(chunk);}
|
||||
if(!req.url?.startsWith('/')||req.url.startsWith('//')){res.writeHead(400,security);res.end();return;}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff