611c5ffbdf
The .drive-agent-extra slot stacked the agent tag row and the agent action row with no vertical gap (and sat flush against the registry action row). The slot is now a flex column with a .6rem gap + top margin, hidden when empty; enrichCard's inline margin removed.
629 lines
38 KiB
HTML
629 lines
38 KiB
HTML
{{define "storage"}}
|
|
{{template "layout_start" .}}
|
|
|
|
<div class="page-header">
|
|
<h2>Tárhely — Meghajtók</h2>
|
|
</div>
|
|
|
|
<!-- Section: Storage Paths -->
|
|
<div class="settings-card">
|
|
<h3>Adattárolók</h3>
|
|
<p class="settings-card-desc">Külső meghajtók kezelése alkalmazásadatok tárolásához.</p>
|
|
|
|
{{if .StorageError}}<div class="alert alert-error">{{.StorageError}}</div>{{end}}
|
|
{{if .StorageSuccess}}<div class="alert alert-info">{{.StorageSuccess}}</div>{{end}}
|
|
|
|
{{if .StoragePaths}}
|
|
<div class="storage-paths-list">
|
|
{{range .StoragePaths}}
|
|
<div class="storage-path-item{{if .Disconnected}} storage-disconnected{{else if .Decommissioned}} storage-decommissioned{{end}}">
|
|
<div class="storage-path-header">
|
|
<div class="storage-path-info">
|
|
<div class="storage-path-label-wrap" id="label-wrap-{{.Path}}">
|
|
<span class="storage-path-label" id="label-display-{{.Path}}">{{.Label}}</span>
|
|
{{if not (or .Disconnected .Decommissioned)}}<button class="btn btn-xs btn-ghost" onclick="editStorageLabel('{{.Path}}', '{{.Label}}')" title="Átnevezés"><svg class="ico ico-sm"><use href="#i-pencil"/></svg></button>{{end}}
|
|
</div>
|
|
<span class="storage-path-path mono">{{.Path}}</span>
|
|
</div>
|
|
<div class="storage-path-badges">
|
|
{{if .Disconnected}}
|
|
<span class="badge badge-error">Leválasztva</span>
|
|
{{else if .Decommissioned}}
|
|
<span class="tag tag-off"><span class="dot"></span>Kiváltva</span>
|
|
{{else}}
|
|
{{if .IsDefault}}<span class="tag">Alapértelmezett</span>{{end}}
|
|
{{if .Schedulable}}<span class="tag tag-run"><span class="dot"></span>Aktív</span>{{else}}<span class="tag tag-off"><span class="dot"></span>Inaktív</span>{{end}}
|
|
{{if .IsUSB}}<span class="badge" style="background:rgba(255,165,0,0.15);color:var(--warn)">USB</span>{{end}}
|
|
{{if not .IsMounted}}<span class="badge badge-warn">Rendszermeghajtón</span>{{end}}
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
{{if .Disconnected}}
|
|
<div class="storage-path-details">
|
|
<div class="storage-disconnected-info">
|
|
{{if .DisconnectedAt}}<span class="form-hint">Leválasztva: {{.DisconnectedAt}}</span>{{end}}
|
|
{{if .StoppedApps}}
|
|
<span class="form-hint">Leállított alkalmazások: {{range $i, $name := .StoppedApps}}{{if $i}}, {{end}}{{$name}}{{end}}</span>
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
<div class="storage-path-actions" id="storage-actions-{{.Path}}">
|
|
<button class="btn btn-xs btn-primary" onclick="storageReconnect('{{.Path}}')">Csatlakoztatás</button>
|
|
</div>
|
|
{{else if .Decommissioned}}
|
|
<div class="storage-path-details">
|
|
<div class="storage-disconnected-info">
|
|
<span class="form-hint">Adatok átköltöztetve ide: <strong>{{.MigratedToLabel}}</strong> ({{.MigratedTo}})</span>
|
|
{{if .DecommissionedAt}}<span class="form-hint">Időpont: {{.DecommissionedAt}}</span>{{end}}
|
|
</div>
|
|
</div>
|
|
<div class="storage-path-actions">
|
|
<button class="btn btn-xs btn-primary" onclick="storageReEnroll('{{.Path}}','{{.Label}}')">Visszacsatlakoztatás</button>
|
|
<form method="POST" action="/settings/storage/remove" style="display:inline"
|
|
onsubmit="return storageRemoveDialog(event, this, 'Biztosan eltávolítja a(z) {{.Label}} ({{.Path}}) meghajtót a rendszerből?\n\nA meghajtó adatai NEM törlődnek.')">
|
|
{{$.CSRFField}}
|
|
<input type="hidden" name="storage_path" value="{{.Path}}">
|
|
<button type="submit" class="btn btn-xs btn-outline">Eltávolítás a rendszerből</button>
|
|
</form>
|
|
</div>
|
|
{{else}}
|
|
<div class="storage-path-details">
|
|
{{if .DiskInfo}}
|
|
<div class="storage-path-disk">
|
|
<div class="system-info-header">
|
|
<span class="system-info-value">{{.DiskInfo.UsedHuman}} / {{.DiskInfo.TotalHuman}}</span>
|
|
</div>
|
|
<div class="meter {{if ge .DiskInfo.UsedPercent 90.0}}crit{{else if ge .DiskInfo.UsedPercent 70.0}}warn{{else}}nominal{{end}}">
|
|
<div class="meter-track">
|
|
<div class="meter-fill" style="width:{{printf "%.0f" .DiskInfo.UsedPercent}}%"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
{{if .FSInfo}}
|
|
<div class="storage-path-fsinfo mono form-hint">
|
|
{{.FSInfo.FSType}} · {{.FSInfo.Device}}{{if .FSInfo.Model}} · {{.FSInfo.Model}}{{end}}
|
|
</div>
|
|
{{end}}
|
|
{{if .StoppedApps}}
|
|
<div class="storage-stopped-apps-info" id="storage-stopped-{{.Path}}">
|
|
<span class="form-hint" style="color:var(--blue-bright)">Újraindításra váró alkalmazások: {{range $i, $name := .StoppedApps}}{{if $i}}, {{end}}{{$name}}{{end}}</span>
|
|
<button class="btn btn-xs btn-primary" onclick="storageRestartApps('{{.Path}}')" style="margin-left:.5rem">Alkalmazások indítása</button>
|
|
</div>
|
|
{{end}}
|
|
<div class="storage-path-meta">
|
|
{{if .AppDetails}}
|
|
<details class="storage-app-details">
|
|
<summary class="form-hint" style="cursor:pointer">
|
|
{{.AppCount}} alkalmazás használja
|
|
</summary>
|
|
<div class="storage-app-list">
|
|
{{range .AppDetails}}
|
|
<div class="storage-app-row">
|
|
<a href="/apps/{{.Stack}}" class="storage-app-link">{{.Name}}</a>
|
|
{{if .SizeHuman}}<span class="mono form-hint">{{.SizeHuman}}</span>{{end}}
|
|
<span class="btn btn-xs btn-outline" style="opacity:.45;cursor:not-allowed" title="Hamarosan"><svg class="ico ico-sm"><use href="#i-upload"/></svg> Mozgatás</span>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</details>
|
|
{{else}}
|
|
<span class="form-hint">Nincs alkalmazás ezen a tárolón</span>
|
|
{{end}}
|
|
</div>
|
|
<div class="drive-agent-extra" id="agent-extra-{{.Path}}"></div>
|
|
</div>
|
|
<div class="storage-path-actions">
|
|
{{if not .IsDefault}}
|
|
<form method="POST" action="/settings/storage/default" style="display:inline">
|
|
{{$.CSRFField}}
|
|
<input type="hidden" name="storage_path" value="{{.Path}}">
|
|
<button type="submit" class="btn btn-xs btn-outline">Legyen alapértelmezett</button>
|
|
</form>
|
|
{{end}}
|
|
{{if .Schedulable}}
|
|
<form method="POST" action="/settings/storage/schedulable" style="display:inline">
|
|
{{$.CSRFField}}
|
|
<input type="hidden" name="storage_path" value="{{.Path}}">
|
|
<input type="hidden" name="schedulable" value="false">
|
|
<button type="submit" class="btn btn-xs btn-outline">Letiltás</button>
|
|
</form>
|
|
{{else}}
|
|
<form method="POST" action="/settings/storage/schedulable" style="display:inline">
|
|
{{$.CSRFField}}
|
|
<input type="hidden" name="storage_path" value="{{.Path}}">
|
|
<input type="hidden" name="schedulable" value="true">
|
|
<button type="submit" class="btn btn-xs btn-outline">Engedélyezés</button>
|
|
</form>
|
|
{{end}}
|
|
{{if .IsUSB}}
|
|
<button class="btn btn-xs btn-danger-outline" onclick="storageDisconnect('{{.Path}}', '{{.Label}}', {{.AppCount}})">Leválasztás</button>
|
|
{{end}}
|
|
{{if and (not .IsDefault) (eq .AppCount 0)}}
|
|
<form method="POST" action="/settings/storage/remove" style="display:inline"
|
|
onsubmit="return storageRemoveDialog(event, this, 'Biztosan eltávolítja a(z) {{.Path}} adattárolót?')">
|
|
{{$.CSRFField}}
|
|
<input type="hidden" name="storage_path" value="{{.Path}}">
|
|
<button type="submit" class="btn btn-xs btn-danger-outline">Eltávolítás</button>
|
|
</form>
|
|
{{end}}
|
|
{{if and (gt .AppCount 0) .HasOtherPaths}}
|
|
{{$src := .Path}}
|
|
<span class="migrate-inline" style="display:inline-flex;gap:.35rem;align-items:center">
|
|
<select id="migrate-target-{{.Path}}" class="btn btn-xs btn-outline">
|
|
<option value="">Áthelyezés ide…</option>
|
|
{{range $.StoragePaths}}{{if and (ne .Path $src) .Schedulable (not .Disconnected) (not .Decommissioned)}}<option value="{{.Path}}">{{.Label}} ({{.Path}})</option>{{end}}{{end}}
|
|
</select>
|
|
<button class="btn btn-xs btn-outline" onclick="storageMigrateAll('{{.Path}}','{{.Label}}')">Összes adat áthelyezése</button>
|
|
</span>
|
|
{{end}}
|
|
<button class="btn btn-xs btn-danger-outline" onclick="storageDecommission('{{.Path}}','{{.Label}}',{{.AppCount}})">Leszerelés</button>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
{{else}}
|
|
<div class="empty-state" style="padding:1.5rem">
|
|
Nincs regisztrált adattároló. Adjon hozzá egyet az alábbi űrlappal.
|
|
</div>
|
|
{{end}}
|
|
|
|
|
|
<div id="migrate-progress" style="display:none;margin-top:1rem;padding:1rem;border:1px solid var(--blue);border-radius:6px;background:rgba(0,136,204,0.06)">
|
|
<strong>Adatok áthelyezése</strong>
|
|
<div id="migrate-progress-body" style="margin-top:.5rem">…</div>
|
|
</div>
|
|
<script>
|
|
// Shared migration progress (used by both migrate-all here and per-app migrate on the app page).
|
|
function migFmtGB(b){ return (Number(b||0)/1e9).toFixed(1)+' GB'; }
|
|
function migRender(job){
|
|
var names={stop:'Alkalmazások leállítása',copy:'Adatok másolása',verify:'Ellenőrzés',flip:'Újratelepítés',redeploy:'Újratelepítés',cleanup:'Forrás törlése'};
|
|
var s=names[job.phase]||job.phase;
|
|
if(job.current_app) s+=': '+job.current_app;
|
|
if(job.phase==='copy'&&job.bytes_total>0){ s+=' ('+Math.floor(100*job.bytes_done/job.bytes_total)+'% — '+migFmtGB(job.bytes_done)+'/'+migFmtGB(job.bytes_total)+')'; }
|
|
return s+'…';
|
|
}
|
|
function migWatch(){
|
|
var panel=document.getElementById('migrate-progress');
|
|
var body=document.getElementById('migrate-progress-body');
|
|
if(panel) panel.style.display='block';
|
|
function tick(){
|
|
fetch('/api/storage/migrate/status').then(function(r){return r.json();}).then(function(d){
|
|
var job=d.data&&d.data.job;
|
|
if(!job){ if(body) body.textContent='Nincs folyamatban migráció.'; return; }
|
|
if(body) body.innerHTML=migRender(job);
|
|
if(job.phase==='done'){ if(body) body.innerHTML+='<br><strong>Kész</strong>'; setTimeout(function(){location.reload();},1500); return; }
|
|
if(job.phase==='aborted'){ if(body) body.innerHTML+='<br><strong style="color:var(--danger,#c0392b)">Megszakadt: '+(job.error||'')+'</strong><br>A forrás adatai érintetlenek.'; return; }
|
|
setTimeout(tick,1500);
|
|
}).catch(function(){ setTimeout(tick,2000); });
|
|
}
|
|
tick();
|
|
}
|
|
function storageMigrateAll(source,label){
|
|
var sel=document.getElementById('migrate-target-'+source);
|
|
var target=sel?sel.value:'';
|
|
if(!target){ alert('Válassz céltárolót a legördülő menüből.'); return; }
|
|
openDialog({title:'Összes adat áthelyezése', confirmLabel:'Áthelyezés',
|
|
message:'Áthelyezed a(z) '+label+' ÖSSZES adatát ide: '+target+'?\n\nAz alkalmazások az áthelyezés alatt rövid időre leállnak. A forrás adatai csak az ellenőrzés és a sikeres újraindítás után törlődnek.',
|
|
onConfirm:function(){
|
|
fetch('/api/storage/migrate',{method:'POST',headers:Object.assign({'Content-Type':'application/json'},csrfHeaders()),body:JSON.stringify({source:source,target:target})})
|
|
.then(function(r){return r.json();}).then(function(d){ if(d.ok){ migWatch(); } else { alert('Hiba: '+(d.error||'ismeretlen')); } })
|
|
.catch(function(e){ alert('Hiba: '+e); });
|
|
}});
|
|
}
|
|
// Resume view: if a migration is STILL IN PROGRESS when the page loads, show the panel and watch.
|
|
// Must NOT re-watch a terminal (done/aborted) job: the journal keeps returning the last completed
|
|
// job indefinitely, and migWatch's done-branch reloads the page — so watching a persisted 'done'
|
|
// job on every load creates an endless refresh loop. Only the active watcher (started from
|
|
// storageMigrateAll) should fire the one-time post-completion reload.
|
|
(function(){ fetch('/api/storage/migrate/status').then(function(r){return r.json();}).then(function(d){ var job=d.data&&d.data.job; if(job && job.phase!=='done' && job.phase!=='aborted'){ migWatch(); } }).catch(function(){}); })();
|
|
</script>
|
|
|
|
<div style="margin-top:1rem;display:flex;gap:.75rem;flex-wrap:wrap">
|
|
<a href="/storage/init" class="btn btn-sm btn-outline"><svg class="ico ico-sm"><use href="#i-plus"/></svg> Új meghajtó inicializálása</a>
|
|
<a href="/storage/attach" class="btn btn-sm btn-outline"><svg class="ico ico-sm"><use href="#i-link"/></svg> Meglévő meghajtó csatolása</a>
|
|
</div>
|
|
|
|
<div id="agent-warn-note"></div>
|
|
|
|
<div style="margin-top:1.5rem" id="agent-unregistered-wrap" hidden>
|
|
<div class="section-h"><h3>Nem regisztrált meghajtók</h3><span class="hint">az ügynök által észlelt, még nem regisztrált adatmeghajtók</span></div>
|
|
<div id="agent-unregistered" class="drive-list"></div>
|
|
</div>
|
|
|
|
<div style="margin-top:1.5rem" id="agent-system-wrap" hidden>
|
|
<div class="section-h"><h3>Rendszermeghajtók</h3><span class="hint">védett — csak operátori aláírással módosíthatók</span></div>
|
|
<div id="agent-system" class="drive-list"></div>
|
|
</div>
|
|
<div id="confirm-root"></div>
|
|
<div id="dialog-root"></div>
|
|
<script>
|
|
window.__registeredPaths=[{{range .StoragePaths}}{{if .Path}}"{{.Path}}",{{end}}{{end}}];
|
|
(function(){
|
|
function esc(s){ return String(s==null?'':s).replace(/[&<>"]/g,function(c){return {'&':'&','<':'<','>':'>','"':'"'}[c];}); }
|
|
function hum(b){ if(!b||b<=0) return ''; var u=['B','KB','MB','GB','TB'],i=0,v=b; while(v>=1024&&i<u.length-1){v/=1024;i++;} return (v>=10||i===0?Math.round(v):v.toFixed(1))+' '+u[i]; }
|
|
function usageColorClass(p){ if(p>=85) return 'crit'; if(p>=70) return 'warn'; return 'nominal'; }
|
|
var LOCK_ICO='<svg class="ico ico-sm"><use href="#i-lock"/></svg>';
|
|
function classTag(d){
|
|
if(d.class==='fast') return '<span class="tag">gyors</span>';
|
|
if(d.class==='slow') return '<span class="tag tag-off">lassú</span>';
|
|
return '';
|
|
}
|
|
function roleTag(role){
|
|
if(role==='system') return '<span class="tag">'+LOCK_ICO+'Rendszer — védett</span>';
|
|
if(role==='backup') return '<span class="tag">'+LOCK_ICO+'Biztonsági mentés — védett</span>';
|
|
if(role==='user-data') return '<span class="tag tag-run"><span class="dot"></span>Felhasználói adat</span>';
|
|
return '<span class="tag">'+LOCK_ICO+'Védett</span>';
|
|
}
|
|
function dataTag(d){ return d.data_bearing ? '<span class="tag tag-warn" title="'+esc(d.data_reason)+'">Adatot tartalmaz</span>' : ''; }
|
|
// regKey is the path a drive is REGISTERED under: the STABLE intermediary path (guest_path,
|
|
// /mnt/felhom-drives/<name>) the agent reports, else the raw mount_path (legacy). The registry
|
|
// stores the STABLE path (handleStorageRegister/runStorageInit), so checking the raw mount_path
|
|
// alone made an enrolled drive read as "Nem regisztrált" + show a spurious Regisztrálás button.
|
|
function regKey(d){ return d.guest_path || d.mount_path; }
|
|
function regTag(d, registered){
|
|
if(!d.mount_path) return '';
|
|
return registered[regKey(d)] ? '<span class="tag tag-run"><span class="dot"></span>Regisztrálva</span>' : '<span class="tag tag-off"><span class="dot"></span>Nem regisztrált</span>';
|
|
}
|
|
// appBackingTag marks the storages that actually hold deployed apps: the internal SSD (app
|
|
// databases + Docker) and the external user-data drives (large app files). Keyed on the agent's
|
|
// authoritative role/type — pure presentation, no agent contract change.
|
|
function appBackingTag(d){
|
|
if(d.type==='lvmthin') return '<span class="tag">Alkalmazás-rendszer</span>';
|
|
if(d.role==='user-data') return '<span class="tag">Alkalmazás-adatok</span>';
|
|
return '';
|
|
}
|
|
// purposeDesc explains, in plain Hungarian, what each storage is for — so the "which one do the
|
|
// apps use?" question is answered per-card. Keyed on type first, then role.
|
|
function purposeDesc(d){
|
|
if(d.type==='lvmthin') return 'Belső SSD — a szerver rendszere, a Docker és a telepített alkalmazások adatbázisai itt találhatók.';
|
|
if(d.type==='local'||d.type==='dir') return 'Host tárhely — rendszer-sablonok, ISO-k, host szintű mentések. Nem tárol alkalmazásadatot.';
|
|
if(d.type==='pbs'||d.role==='backup') return 'A biztonsági mentések tárhelye.';
|
|
if(d.role==='user-data') return 'Külső adattároló — a telepített alkalmazások nagy méretű fájljai (média, dokumentumok) ide kerülnek. Más meghajtók biztonsági mentési céljaként is szolgálhat.';
|
|
return '';
|
|
}
|
|
function capBar(d){
|
|
if(!d.total_bytes || d.total_bytes<=0) return '';
|
|
var pct = d.used_fraction ? d.used_fraction*100 : (d.used_bytes/d.total_bytes*100);
|
|
pct = Math.max(0, Math.min(100, pct));
|
|
return '<div class="drive-cap meter '+usageColorClass(pct)+'"><div class="meter-track"><div class="meter-fill" style="width:'+pct.toFixed(1)+'%"></div></div>'
|
|
+'<div class="drive-cap-label">'+hum(d.used_bytes)+' / '+hum(d.total_bytes)+' ('+pct.toFixed(0)+'%)</div></div>';
|
|
}
|
|
function actions(d, registered){
|
|
// Destructive controls ONLY for user-data drives that are mounted under /mnt. System/backup get none.
|
|
if(d.role!=='user-data' || !d.mount_path || d.mount_path.indexOf('/mnt/')!==0) return '';
|
|
var dev = esc(d.backing_device||''), mpRaw = esc(d.mount_path), reg = esc(regKey(d));
|
|
var btns = '';
|
|
// Two distinct path arguments (the intermediary model):
|
|
// - registerDrive posts the RAW mount_path — its agent guest-attach operates on the raw mount
|
|
// (handleStorageRegister maps it to the stable path for the registry).
|
|
// - eject/wipe post the STABLE (registered) path — their handlers map it to raw for the agent via
|
|
// agentWhere() AND deregister it from the registry (which stores the stable path). Posting the
|
|
// raw path here would unmount the drive but leave the stable registry entry orphaned.
|
|
if(!registered[regKey(d)]){
|
|
btns += '<button class="btn btn-xs btn-primary" onclick="registerDrive(\''+mpRaw+'\')">Regisztrálás</button> ';
|
|
}
|
|
btns += '<button class="btn btn-xs btn-danger-outline" onclick="confirmEject(\''+reg+'\')">Leválasztás</button>';
|
|
if(d.backing_device){ btns += ' <button class="btn btn-xs btn-danger-outline" onclick="confirmWipe(\''+dev+'\',\''+reg+'\')">Törlés…</button>'; }
|
|
return '<div class="drive-actions">'+btns+'</div>';
|
|
}
|
|
// Unified drive view (D1): the agent disk list ENRICHES the registry cards in place
|
|
// (role tag + durable-id + agent-only actions), and two extra groups render below:
|
|
// protected system/backup drives (read-only) and unregistered user-data drives.
|
|
function driveRow(d, registered, withActions){
|
|
var sub = esc(d.type)+' · '+esc(d.backing_device||'—')+(d.mount_path?' · '+esc(regKey(d)):'');
|
|
var badges = roleTag(d.role)+appBackingTag(d)+classTag(d)+dataTag(d);
|
|
if(withActions) badges += regTag(d, registered);
|
|
var purpose = purposeDesc(d);
|
|
return '<div class="drive-card role-'+esc(d.role||'system')+'">'
|
|
+'<div class="drive-card-top"><div class="drive-id"><span class="drive-name">'+esc(d.name)+'</span><span class="drive-sub">'+sub+'</span></div>'
|
|
+'<div class="drive-badges">'+badges+'</div></div>'
|
|
+(purpose?'<div class="drive-purpose">'+esc(purpose)+'</div>':'')
|
|
+(d.durable_id?'<div class="drive-sub mono">'+esc(d.durable_id)+'</div>':'')
|
|
+capBar(d)
|
|
+(withActions?actions(d,registered):'')
|
|
+'</div>';
|
|
}
|
|
function enrichCard(d, registered){
|
|
var slot=document.getElementById('agent-extra-'+regKey(d));
|
|
if(!slot) return false;
|
|
var extra='<div class="metarows">'
|
|
+'<span class="metarow">'+roleTag(d.role)+'</span>'
|
|
+(d.class?'<span class="metarow">'+classTag(d)+'</span>':'')
|
|
+(d.durable_id?'<span class="metarow mono" title="Tartós azonosító">'+esc(d.durable_id)+'</span>':'')
|
|
+'</div>'
|
|
+actions(d,registered);
|
|
slot.innerHTML=extra;
|
|
return true;
|
|
}
|
|
async function load(){
|
|
var warn=document.getElementById('agent-warn-note');
|
|
try{
|
|
var r=await fetch('/api/disks'); var j=await r.json();
|
|
if(!j.ok) throw new Error(j.error||'Nem elérhető');
|
|
var disks=(j.data&&j.data.disks)||[];
|
|
var registered={}; (window.__registeredPaths||[]).forEach(function(p){registered[p]=true;});
|
|
var sysHtml='', unregHtml='';
|
|
disks.forEach(function(d){
|
|
if(d.role==='user-data'){
|
|
if(registered[regKey(d)] && enrichCard(d, registered)) return; // one card, enriched in place
|
|
unregHtml+=driveRow(d, registered, true);
|
|
}else{
|
|
sysHtml+=driveRow(d, registered, false); // protected: read-only, lock tag, NO actions
|
|
}
|
|
});
|
|
var sysWrap=document.getElementById('agent-system-wrap');
|
|
var unregWrap=document.getElementById('agent-unregistered-wrap');
|
|
if(sysHtml){ document.getElementById('agent-system').innerHTML=sysHtml; sysWrap.hidden=false; }
|
|
if(unregHtml){ document.getElementById('agent-unregistered').innerHTML=unregHtml; unregWrap.hidden=false; }
|
|
}catch(e){
|
|
if(warn) warn.innerHTML='<div class="alert alert-warning" style="margin-top:1rem">Az ügynök nem elérhető — élő meghajtóadatok nélkül.</div>';
|
|
}
|
|
}
|
|
|
|
// ---- type-to-confirm modal (destructive user-data actions) ----
|
|
function closeModal(){ document.getElementById('confirm-root').innerHTML=''; }
|
|
window.__closeConfirm=closeModal;
|
|
async function openConfirm(opts){
|
|
// opts: {title, mount, mountName, danger, onConfirm}
|
|
var apps=[], copies=[];
|
|
try{
|
|
var r=await fetch('/api/storage/impact?where='+encodeURIComponent(opts.mount));
|
|
var j=await r.json(); if(j.ok && j.data){ apps=j.data.apps||[]; copies=j.data.backup_copies||[]; }
|
|
}catch(e){}
|
|
var appsHtml = apps.length
|
|
? '<p>A művelet után a következő alkalmazások <strong>nem fognak működni</strong>:</p><ul class="confirm-apps">'+apps.map(function(a){return '<li>'+esc(a)+'</li>';}).join('')+'</ul>'
|
|
: '<p class="form-hint">Ehhez a meghajtóhoz jelenleg nincs telepített alkalmazás rendelve.</p>';
|
|
// P4 (4B): this drive may also hold cross-drive backup COPIES of other apps — a wipe removes them.
|
|
var copiesHtml = copies.length
|
|
? '<div class="alert alert-warning" style="margin-top:.5rem">Ez a meghajtó más alkalmazások <strong>biztonsági másolatait</strong> is tárolja — a törlés ezeket is eltávolítja:<ul class="confirm-apps">'+copies.map(function(a){return '<li>'+esc(a)+'</li>';}).join('')+'</ul><span class="form-hint">(A másolatok redundánsak — az eredetik a forrás-meghajtón maradnak.)</span></div>'
|
|
: '';
|
|
var root=document.getElementById('confirm-root');
|
|
root.innerHTML='<div class="confirm-overlay" onclick="if(event.target===this)__closeConfirm()"><div class="confirm-box">'
|
|
+'<h3>'+esc(opts.title)+'</h3>'
|
|
+'<div class="alert alert-warning">'+esc(opts.danger)+'</div>'
|
|
+appsHtml
|
|
+copiesHtml
|
|
+'<div class="confirm-input"><label>Megerősítéshez írja be a csatlakoztatási nevet: <strong class="mono">'+esc(opts.mountName)+'</strong></label>'
|
|
+'<input type="text" id="confirm-type" class="form-control" autocomplete="off" placeholder="'+esc(opts.mountName)+'" oninput="document.getElementById(\'confirm-go\').disabled=(this.value!==\''+esc(opts.mountName)+'\')"></div>'
|
|
+'<div class="form-actions"><button id="confirm-go" class="btn btn-danger-outline" disabled>Megerősítés</button>'
|
|
+'<button class="btn btn-outline" onclick="__closeConfirm()">Mégsem</button></div>'
|
|
+'<div id="confirm-result" style="margin-top:.6rem"></div></div></div>';
|
|
document.getElementById('confirm-go').onclick=opts.onConfirm;
|
|
}
|
|
|
|
// registerDrive records an already-mounted, unregistered user-data drive into the StoragePath
|
|
// registry (no format, no eject) — makes the existing mount usable (schedulable + FileBrowser sync).
|
|
window.registerDrive=async function(where){
|
|
try{
|
|
var r=await fetch('/api/storage/register',{method:'POST',headers:Object.assign({'Content-Type':'application/json'},csrfHeaders()),body:JSON.stringify({where:where})});
|
|
var j=await r.json(); if(!j.ok){ alert('Regisztráció sikertelen: '+(j.error||'')); return; }
|
|
location.reload();
|
|
}catch(e){ alert('Hiba: '+e.message); }
|
|
};
|
|
window.confirmEject=function(where){
|
|
// The confirm name is the drive BASENAME (matches the server's path.Base(where) check); `where` may
|
|
// be the stable /mnt/felhom-drives/<name> path, so strip the whole directory, not just the /mnt/ prefix.
|
|
var name=where.split('/').filter(Boolean).pop()||where;
|
|
openConfirm({title:'Meghajtó leválasztása', mount:where, mountName:name,
|
|
danger:'A meghajtó leválasztásra kerül. Az adatok megmaradnak, de az ott tárolt alkalmazások elvesztik a tárhelyüket, amíg újra nem csatolja.',
|
|
onConfirm:async function(){
|
|
var out=document.getElementById('confirm-result'); out.innerHTML='<p class="form-hint">Leválasztás folyamatban…</p>';
|
|
try{
|
|
var r=await fetch('/api/storage/eject',{method:'POST',headers:Object.assign({'Content-Type':'application/json'},csrfHeaders()),body:JSON.stringify({where:where})});
|
|
var j=await r.json(); if(!j.ok){ out.innerHTML='<div class="alert alert-error">Hiba: '+esc(j.error||'')+'</div>'; return; }
|
|
location.reload();
|
|
}catch(e){ out.innerHTML='<div class="alert alert-error">Hiba: '+esc(e.message)+'</div>'; }
|
|
}});
|
|
};
|
|
window.confirmWipe=function(device, where){
|
|
// Basename (matches the server's path.Base(where) type-to-confirm check); `where` may be the stable path.
|
|
var name=where.split('/').filter(Boolean).pop()||where;
|
|
openConfirm({title:'Meghajtó törlése (formázás)', mount:where, mountName:name,
|
|
danger:'FIGYELEM: a meghajtón lévő ÖSSZES ADAT véglegesen törlődik (formázás). Ez nem vonható vissza.',
|
|
onConfirm:async function(){
|
|
var out=document.getElementById('confirm-result'); out.innerHTML='<p class="form-hint">Törlés folyamatban…</p>';
|
|
try{
|
|
var r=await fetch('/api/storage/wipe',{method:'POST',headers:Object.assign({'Content-Type':'application/json'},csrfHeaders()),body:JSON.stringify({device:device, where:where, mount_name:name})});
|
|
var j=await r.json(); if(!j.ok){ out.innerHTML='<div class="alert alert-error">Hiba: '+esc(j.error||'')+'</div>'; return; }
|
|
location.reload();
|
|
}catch(e){ out.innerHTML='<div class="alert alert-error">Hiba: '+esc(e.message)+'</div>'; }
|
|
}});
|
|
};
|
|
load();
|
|
})();
|
|
</script>
|
|
|
|
<details class="storage-add-details">
|
|
<summary class="btn btn-sm btn-outline" style="margin-top:.75rem;cursor:pointer">Már csatlakoztatott tárhely hozzáadása kézzel</summary>
|
|
<form method="POST" action="/settings/storage/add" class="storage-add-form">
|
|
{{.CSRFField}}
|
|
<div class="form-group">
|
|
<label for="storage_path">Elérési út</label>
|
|
<input type="text" id="storage_path" name="storage_path" class="form-control"
|
|
placeholder="/mnt/hdd_1" required>
|
|
<span class="form-hint">Pl. /mnt/hdd_1 — a meghajtónak már csatolva kell lennie</span>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="storage_label">Megnevezés (opcionális)</label>
|
|
<input type="text" id="storage_label" name="storage_label" class="form-control"
|
|
placeholder="Külső HDD 1TB">
|
|
</div>
|
|
<label class="toggle" style="margin-bottom:1rem">
|
|
<input type="checkbox" name="storage_default" value="true">
|
|
<span class="toggle-label">Legyen alapértelmezett új telepítéseknél</span>
|
|
</label>
|
|
<button type="submit" class="btn btn-primary">Hozzáadás</button>
|
|
</form>
|
|
</details>
|
|
</div>
|
|
|
|
<script>
|
|
// Light overlay dialog (D1) — replaces the native blocking browser dialogs: same texts,
|
|
// reuses the .confirm-overlay/.confirm-box pattern. typeToConfirm adds the typed-name gate
|
|
// ONLY where the old flow already had one.
|
|
function escText(s){var d=document.createElement('div');d.textContent=String(s==null?'':s);return d.innerHTML;}
|
|
function closeDialog(){ var r=document.getElementById('dialog-root'); if(r) r.innerHTML=''; }
|
|
function openDialog(opts){
|
|
var root=document.getElementById('dialog-root');
|
|
if(!root) return;
|
|
var typeGate=opts.typeToConfirm||'';
|
|
var html='<div class="confirm-overlay" onclick="if(event.target===this)document.getElementById(\'dialog-cancel\').click()"><div class="confirm-box">'
|
|
+'<h3>'+escText(opts.title||'Megerősítés')+'</h3>'
|
|
+'<p style="white-space:pre-line">'+escText(opts.message||'')+'</p>';
|
|
if(typeGate){
|
|
html+='<div class="confirm-input"><label>Megerősítéshez írja be: <strong class="mono">'+escText(typeGate)+'</strong></label>'
|
|
+'<input type="text" id="dialog-type" class="form-control" autocomplete="off" placeholder="'+escText(typeGate)+'"></div>';
|
|
}
|
|
html+='<div class="form-actions"><button id="dialog-go" class="btn '+(typeGate?'btn-danger-outline':'btn-primary')+'"'+(typeGate?' disabled':'')+'>'+escText(opts.confirmLabel||'Megerősítés')+'</button>'
|
|
+'<button type="button" class="btn btn-outline" id="dialog-cancel">Mégsem</button></div>'
|
|
+'</div></div>';
|
|
root.innerHTML=html;
|
|
var go=document.getElementById('dialog-go');
|
|
if(typeGate){
|
|
document.getElementById('dialog-type').oninput=function(){ go.disabled=(this.value.trim()!==typeGate); };
|
|
}
|
|
go.onclick=function(){ closeDialog(); if(opts.onConfirm) opts.onConfirm(); };
|
|
document.getElementById('dialog-cancel').onclick=function(){ closeDialog(); if(opts.onCancel) opts.onCancel(); };
|
|
}
|
|
// Overlay-confirmed POST form submit (registry drive-remove forms).
|
|
function storageRemoveDialog(ev, form, msg){
|
|
ev.preventDefault();
|
|
openDialog({title:'Meghajtó eltávolítása', message:msg, confirmLabel:'Eltávolítás', onConfirm:function(){ form.submit(); }});
|
|
return false;
|
|
}
|
|
|
|
function editStorageLabel(path, currentLabel) {
|
|
var wrap = document.getElementById('label-wrap-' + path);
|
|
if (!wrap) return;
|
|
var csrfTok = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
|
|
wrap.innerHTML = '<form method="POST" action="/settings/storage/label" style="display:inline-flex;gap:.5rem;align-items:center">' +
|
|
'<input type="hidden" name="_csrf" value="' + csrfTok + '">' +
|
|
'<input type="hidden" name="storage_path" value="' + path + '">' +
|
|
'<input type="text" name="storage_label" class="form-control" value="' + currentLabel.replace(/"/g, '"') + '" style="width:200px;padding:.3rem .5rem;font-size:.9rem" maxlength="50">' +
|
|
'<button type="submit" class="btn btn-xs btn-primary">OK</button>' +
|
|
'<button type="button" class="btn btn-xs btn-outline" onclick="cancelEditLabel(\'' + path + '\', \'' + currentLabel.replace(/'/g, "\\'") + '\')">×</button>' +
|
|
'</form>';
|
|
wrap.querySelector('input[name=storage_label]').focus();
|
|
}
|
|
function storageDisconnect(path, label, appCount) {
|
|
var msg = 'Biztos leválasztja a meghajtót: ' + label + '?';
|
|
if (appCount > 0) msg += '\n\nA rajta futó ' + appCount + ' alkalmazás le fog állni.';
|
|
msg += '\n\nA meghajtó ezután biztonságosan eltávolítható.';
|
|
openDialog({title:'Meghajtó leválasztása', message:msg, confirmLabel:'Leválasztás', onConfirm:function(){ doStorageDisconnect(path); }});
|
|
}
|
|
function doStorageDisconnect(path) {
|
|
fetch('/api/storage/disconnect', {
|
|
method: 'POST',
|
|
headers: Object.assign({'Content-Type': 'application/json'}, csrfHeaders()),
|
|
body: JSON.stringify({where: path})
|
|
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
if (data.ok) {
|
|
alert('A meghajtó biztonságosan eltávolítható.');
|
|
location.reload();
|
|
} else {
|
|
alert('Hiba: ' + (data.error || 'ismeretlen'));
|
|
}
|
|
}).catch(function(e) { alert('Hiba: ' + e); });
|
|
}
|
|
function storageReconnect(path) {
|
|
var actionsDiv = document.getElementById('storage-actions-' + path);
|
|
if (actionsDiv) actionsDiv.innerHTML = '<span class="form-hint">Csatlakoztatás...</span>';
|
|
fetch('/api/storage/reconnect', {
|
|
method: 'POST',
|
|
headers: Object.assign({'Content-Type': 'application/json'}, csrfHeaders()),
|
|
body: JSON.stringify({where: path})
|
|
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
if (data.ok) {
|
|
location.reload();
|
|
} else {
|
|
alert('Hiba: ' + (data.error || 'ismeretlen'));
|
|
if (actionsDiv) actionsDiv.innerHTML = '<button class="btn btn-xs btn-primary" onclick="storageReconnect(\'' + path + '\')">Csatlakoztatás</button>';
|
|
}
|
|
}).catch(function(e) {
|
|
alert('Hiba: ' + e);
|
|
if (actionsDiv) actionsDiv.innerHTML = '<button class="btn btn-xs btn-primary" onclick="storageReconnect(\'' + path + '\')">Csatlakoztatás</button>';
|
|
});
|
|
}
|
|
function storageRestartApps(path) {
|
|
fetch('/api/storage/restart-apps', {
|
|
method: 'POST',
|
|
headers: Object.assign({'Content-Type': 'application/json'}, csrfHeaders()),
|
|
body: JSON.stringify({where: path})
|
|
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
if (data.ok) {
|
|
var r2 = data.restarted || [];
|
|
if (r2.length) alert('Elindítva: ' + r2.join(', '));
|
|
location.reload();
|
|
} else {
|
|
alert('Hiba: ' + (data.error || 'ismeretlen'));
|
|
}
|
|
}).catch(function(e) { alert('Hiba: ' + e); });
|
|
}
|
|
// H2: decommission a drive (non-destructive). If a migrate target is picked in the inline select →
|
|
// migrate-then-decommission; otherwise decommission-anyway with type-to-confirm.
|
|
function storageDecommission(path, label, appCount) {
|
|
var sel = document.getElementById('migrate-target-' + path);
|
|
var target = sel ? sel.value : '';
|
|
if (target) {
|
|
openDialog({title:'Leszerelés áthelyezéssel', confirmLabel:'Leszerelés',
|
|
message:'Leszerelés áthelyezéssel: minden adat átmásolása ide: ' + target + ', majd a(z) ' + label + ' leszerelése?\n\nAz adatok NEM törlődnek.',
|
|
onConfirm:function(){ doStorageDecommission({where: path, mode: 'migrate', target: target}); }});
|
|
} else {
|
|
var name = path.split('/').pop();
|
|
openDialog({title:'Meghajtó leszerelése', confirmLabel:'Leszerelés', typeToConfirm:name,
|
|
message:'A(z) ' + label + ' leszereléséhez (áthelyezés nélkül) írja be a meghajtó nevét megerősítésként.' +
|
|
(appCount > 0 ? '\n\nFIGYELEM: ' + appCount + ' alkalmazás leáll (az adatok megmaradnak).' : ''),
|
|
onConfirm:function(){ doStorageDecommission({where: path, mode: 'anyway', mount_name: name}); }});
|
|
}
|
|
}
|
|
function doStorageDecommission(body) {
|
|
fetch('/api/storage/decommission', {
|
|
method: 'POST',
|
|
headers: Object.assign({'Content-Type': 'application/json'}, csrfHeaders()),
|
|
body: JSON.stringify(body)
|
|
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
if (data.ok) { alert('Leszerelés elindítva.'); location.reload(); }
|
|
else { alert('Hiba: ' + (data.error || 'ismeretlen')); }
|
|
}).catch(function(e) { alert('Hiba: ' + e); });
|
|
}
|
|
// H3: one-click re-enroll a decommissioned/ejected drive — clears the marker, re-attaches under the
|
|
// parent, restarts the gate-stopped apps (data is intact).
|
|
function storageReEnroll(path, label) {
|
|
openDialog({title:'Visszacsatlakoztatás', confirmLabel:'Visszacsatlakoztatás',
|
|
message:'Visszacsatlakoztatja a(z) ' + label + ' meghajtót?\n\nAz adatok érintetlenek; a leállított alkalmazások újraindulnak.',
|
|
onConfirm:function(){ doStorageReEnroll(path); }});
|
|
}
|
|
function doStorageReEnroll(path) {
|
|
fetch('/api/storage/reconnect', {
|
|
method: 'POST',
|
|
headers: Object.assign({'Content-Type': 'application/json'}, csrfHeaders()),
|
|
body: JSON.stringify({where: path})
|
|
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
if (data.ok) { location.reload(); }
|
|
else { alert('Hiba: ' + (data.error || 'ismeretlen')); }
|
|
}).catch(function(e) { alert('Hiba: ' + e); });
|
|
}
|
|
function cancelEditLabel(path, label) {
|
|
var wrap = document.getElementById('label-wrap-' + path);
|
|
if (!wrap) return;
|
|
// M11: Use DOM manipulation with textContent to prevent XSS if label contains HTML.
|
|
wrap.innerHTML = '';
|
|
var span = document.createElement('span');
|
|
span.className = 'storage-path-label';
|
|
span.id = 'label-display-' + path;
|
|
span.textContent = label;
|
|
var btn = document.createElement('button');
|
|
btn.className = 'btn btn-xs btn-ghost';
|
|
btn.setAttribute('title', 'Átnevezés');
|
|
btn.innerHTML = '<svg class="ico ico-sm"><use href="#i-pencil"/></svg>';
|
|
btn.addEventListener('click', function() { editStorageLabel(path, label); });
|
|
wrap.appendChild(span);
|
|
wrap.appendChild(document.createTextNode(' '));
|
|
wrap.appendChild(btn);
|
|
}
|
|
</script>
|
|
{{template "layout_end" .}}
|
|
{{end}}
|