Move every inline <script> block and on*= attribute out of the templates into per-page files under static/js/, then tighten the CSP to script-src 'self' so injected inline scripts are actually blocked. - static/js/base.js: QR modal, form[data-confirm] submit confirmation, and a shared glimmerCopy clipboard helper (loaded by base.html) - One script per template: index, bin_view, bin_token, admin, admin_edit, admin_bin, admin_bin_edit, admin_uploads - Template data now flows through data-* attributes (data-slug, data-filename, data-max-mb, ...) instead of being interpolated into JS; confirm() prompts use data-confirm - style-src keeps unsafe-inline for the style="" attributes - Update CLAUDE.md / AGENTS.md with the no-inline-JS rule Verified in a live browser session: shorten flow, login, QR modal, paste editor (token radios, name preview), paste cards (preview dialog, expand/close), public paste view, token prompt redirect, and uploads page - no console errors or CSP violations. Co-Authored-By: Claude Fable 5 <[email protected]>
161 lines
6.8 KiB
HTML
161 lines
6.8 KiB
HTML
{{define "title"}}Admin — Glimmer{{end}}
|
|
{{define "content"}}
|
|
|
|
<div class="page-header">
|
|
<div class="page-title">
|
|
<h1>Dashboard</h1>
|
|
<p>Overview of your short links and recent activity.</p>
|
|
</div>
|
|
<div class="page-actions">
|
|
<a href="/" class="btn btn-primary">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:18px;height:18px"><path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15"/></svg>
|
|
New Link
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{{if .Success}}
|
|
<div class="alert alert-success">{{.Success}}</div>
|
|
{{end}}
|
|
|
|
<div class="stats-bar">
|
|
<div class="stats-card">
|
|
<span class="stats-value">{{len .AdminLinks}}</span>
|
|
<span class="stats-label">My Links</span>
|
|
</div>
|
|
<div class="stats-card">
|
|
<span class="stats-value">{{len .AnonLinks}}</span>
|
|
<span class="stats-label">Anonymous</span>
|
|
</div>
|
|
<div class="stats-card">
|
|
<span class="stats-value">{{len .TopLinks}}</span>
|
|
<span class="stats-label">Quick Links</span>
|
|
</div>
|
|
</div>
|
|
|
|
{{if .TopLinks}}
|
|
<section style="margin-bottom: 2rem;">
|
|
<div class="section-header">
|
|
<div>
|
|
<h2 class="section-title">Quick Links</h2>
|
|
<p class="section-subtitle">Top 20 most-clicked links — one click to open.</p>
|
|
</div>
|
|
</div>
|
|
<div class="tile-grid">
|
|
{{range .TopLinks}}
|
|
<a href="/{{.Slug}}" class="tile" target="_blank" rel="noopener noreferrer" title="{{.URL}}">
|
|
<span class="tile-slug">/{{.Slug}}</span>
|
|
<span class="tile-dest" data-hostname>{{.URL}}</span>
|
|
<span class="tile-clicks">{{.Clicks}} clicks</span>
|
|
</a>
|
|
{{end}}
|
|
</div>
|
|
</section>
|
|
{{end}}
|
|
|
|
<section style="margin-bottom: 2rem;">
|
|
<div class="section-header">
|
|
<div>
|
|
<h2 class="section-title">My Links</h2>
|
|
<p class="section-subtitle">{{len .AdminLinks}} links created by you.</p>
|
|
</div>
|
|
</div>
|
|
<div class="card card-flush">
|
|
<div class="data-table-wrapper">
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Slug</th>
|
|
<th>Destination</th>
|
|
<th class="col-numeric">Clicks</th>
|
|
<th>Created</th>
|
|
<th class="col-actions">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{range .AdminLinks}}
|
|
<tr>
|
|
<td><a href="/{{.Slug}}" target="_blank" rel="noopener noreferrer">/{{.Slug}}</a></td>
|
|
<td title="{{.URL}}"><span class="text-truncate" style="display:inline-block;max-width:340px;vertical-align:middle">{{.URL}}</span></td>
|
|
<td class="col-numeric">{{.Clicks}}</td>
|
|
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
|
|
<td class="col-actions">
|
|
<div class="flex gap-1">
|
|
<a href="/admin/edit/{{.ID}}" class="btn btn-secondary btn-sm">Edit</a>
|
|
<button type="button" class="btn btn-secondary btn-sm js-qr" data-slug="{{.Slug}}">QR</button>
|
|
<form method="post" action="/admin/delete/{{.ID}}" style="display:inline" data-confirm="Delete /{{.Slug}}?">
|
|
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
|
<button type="submit" class="btn btn-danger btn-sm">Del</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{{else}}
|
|
<tr><td colspan="5">
|
|
<div class="empty-state">
|
|
<span class="empty-state-icon">🔗</span>
|
|
<p class="empty-state-text">No links yet.</p>
|
|
<a href="/" class="btn btn-primary btn-sm empty-state-action">Create your first link</a>
|
|
</div>
|
|
</td></tr>
|
|
{{end}}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section style="margin-bottom: 2rem;">
|
|
<div class="section-header">
|
|
<div>
|
|
<h2 class="section-title">Anonymous Links</h2>
|
|
<p class="section-subtitle">{{len .AnonLinks}} links created by unauthenticated users.</p>
|
|
</div>
|
|
</div>
|
|
<div class="card card-flush">
|
|
<div class="data-table-wrapper">
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Slug</th>
|
|
<th>Destination</th>
|
|
<th class="col-numeric">Clicks</th>
|
|
<th>Created</th>
|
|
<th class="col-actions">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{{range .AnonLinks}}
|
|
<tr>
|
|
<td><a href="/{{.Slug}}" target="_blank" rel="noopener noreferrer">/{{.Slug}}</a></td>
|
|
<td title="{{.URL}}"><span class="text-truncate" style="display:inline-block;max-width:340px;vertical-align:middle">{{.URL}}</span></td>
|
|
<td class="col-numeric">{{.Clicks}}</td>
|
|
<td>{{.CreatedAt.Format "2006-01-02 15:04"}}</td>
|
|
<td class="col-actions">
|
|
<div class="flex gap-1">
|
|
<a href="/admin/edit/{{.ID}}" class="btn btn-secondary btn-sm">Edit</a>
|
|
<button type="button" class="btn btn-secondary btn-sm js-qr" data-slug="{{.Slug}}">QR</button>
|
|
<form method="post" action="/admin/delete/{{.ID}}" style="display:inline" data-confirm="Delete /{{.Slug}}?">
|
|
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
|
<button type="submit" class="btn btn-danger btn-sm">Del</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{{else}}
|
|
<tr><td colspan="5">
|
|
<div class="empty-state">
|
|
<span class="empty-state-icon">👥</span>
|
|
<p class="empty-state-text">No anonymous links.</p>
|
|
</div>
|
|
</td></tr>
|
|
{{end}}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<script src="/static/js/admin.js"></script>
|
|
{{end}}
|