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]>
136 lines
7.7 KiB
HTML
136 lines
7.7 KiB
HTML
{{define "title"}}{{if .Paste}}Edit Paste{{else}}New Paste{{end}} — Admin{{end}}
|
|
{{define "content"}}
|
|
|
|
<div class="page-header">
|
|
<div class="page-title">
|
|
<h1>{{if .Paste}}Edit Paste{{else}}New Paste{{end}}</h1>
|
|
<p>{{if .Paste}}Update the content and access settings.{{else}}Write a new paste — Markdown or plain text, optionally token-protected.{{end}}</p>
|
|
</div>
|
|
<div class="page-actions">
|
|
<a href="/admin/bin" class="btn btn-secondary">Back to pastes</a>
|
|
</div>
|
|
</div>
|
|
|
|
{{if .Error}}
|
|
<div class="alert alert-error">{{.Error}}</div>
|
|
{{end}}
|
|
|
|
<div class="card">
|
|
{{if .Paste}}
|
|
{{with .Paste}}<form method="post" action="/admin/bin/edit/{{.ID}}">{{else}}{{end}}
|
|
{{else}}
|
|
<form method="post" action="/admin/bin/new">
|
|
{{end}}
|
|
|
|
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="name" class="form-label">Name <small class="text-muted">(URL slug)</small></label>
|
|
{{if .Paste}}
|
|
{{with .Paste}}<input type="text" id="name" name="name" value="{{.Name}}" required pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores">{{end}}
|
|
{{else}}
|
|
<input type="text" id="name" name="name" required pattern="[a-zA-Z0-9_-]+" placeholder="my-script" title="Letters, numbers, hyphens, underscores">
|
|
{{end}}
|
|
<small class="form-help">Path: <code>/bin/<span id="name-preview">{{if .Paste}}{{with .Paste}}{{.Name}}{{end}}{{else}}...{{end}}</span></code></small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="title" class="form-label">Title <small class="text-muted">(optional)</small></label>
|
|
{{if .Paste}}
|
|
{{with .Paste}}<input type="text" id="title" name="title" value="{{.Title}}" placeholder="A short description">{{end}}
|
|
{{else}}
|
|
<input type="text" id="title" name="title" placeholder="A short description">
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="format" class="form-label">Format</label>
|
|
<select id="format" name="format">
|
|
{{if .Paste}}
|
|
{{with .Paste}}
|
|
<option value="markdown"{{if eq .Format "markdown"}} selected{{end}}>Markdown</option>
|
|
<option value="text"{{if eq .Format "text"}} selected{{end}}>Plain text</option>
|
|
{{end}}
|
|
{{else}}
|
|
<option value="markdown" selected>Markdown</option>
|
|
<option value="text">Plain text</option>
|
|
{{end}}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="content" class="form-label">Content</label>
|
|
<div class="upload-controls" style="margin-bottom: 0.5rem;">
|
|
<button type="button" id="upload-img-btn" class="btn btn-secondary btn-sm" data-max-mb="{{$.UploadMaxMB}}" title="PNG, JPEG, GIF, WebP — up to 50 MB">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"/></svg>
|
|
Upload Image
|
|
</button>
|
|
<button type="button" id="upload-file-btn" class="btn btn-secondary btn-sm" title="Any file type — up to 5 MB">
|
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:16px;height:16px"><path stroke-linecap="round" stroke-linejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"/></svg>
|
|
Upload File
|
|
</button>
|
|
<input type="file" id="img-input" accept="image/png,image/jpeg,image/gif,image/webp" style="display:none">
|
|
<input type="file" id="file-input" style="display:none">
|
|
<small id="upload-status" class="upload-status"></small>
|
|
</div>
|
|
{{if .Paste}}
|
|
{{with .Paste}}<textarea id="content" name="content" rows="20">{{.Content}}</textarea>{{end}}
|
|
{{else}}
|
|
<textarea id="content" name="content" rows="20" placeholder="# Hello Write your markdown here..."></textarea>
|
|
{{end}}
|
|
</div>
|
|
|
|
<fieldset>
|
|
<legend>Access Token</legend>
|
|
{{if .Paste}}
|
|
{{with .Paste}}
|
|
{{if .Token}}
|
|
<p class="text-muted" style="margin-bottom: 0.75rem;">
|
|
Current token: <code>{{.Token}}</code> — URL: <code>/bin/{{.Name}}/{{.Token}}</code>
|
|
</p>
|
|
<label><input type="radio" name="token_action" value="keep" checked> Keep current token</label>
|
|
<label><input type="radio" name="token_action" value="regenerate"> Regenerate token</label>
|
|
<label><input type="radio" name="token_action" value="custom"> Set custom token</label>
|
|
<label><input type="radio" name="token_action" value="disable"> Disable token (public access)</label>
|
|
{{else}}
|
|
<p class="text-muted" style="margin-bottom: 0.75rem;">Token is currently <strong>disabled</strong> — paste is publicly accessible.</p>
|
|
<label><input type="radio" name="token_action" value="keep" checked> Keep disabled</label>
|
|
<label><input type="radio" name="token_action" value="regenerate"> Enable with new token</label>
|
|
<label><input type="radio" name="token_action" value="custom"> Set custom token</label>
|
|
{{end}}
|
|
<div id="custom-token-wrap" style="display:none; margin: 0.5rem 0 0.5rem 1.5rem;">
|
|
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
|
|
</div>
|
|
<label style="margin-top: 0.5rem;">
|
|
<input type="checkbox" name="hidden" value="1" {{if .Hidden}}checked{{end}}>
|
|
Hide paste (return 404 if accessed without token)
|
|
</label>
|
|
{{end}}
|
|
{{else}}
|
|
<label><input type="radio" name="enable_token" value="0" checked> No token (public access)</label>
|
|
<label><input type="radio" name="enable_token" value="1"> Generate access token</label>
|
|
<label><input type="radio" name="enable_token" value="custom"> Custom token</label>
|
|
<div id="custom-token-wrap" style="display:none; margin: 0.5rem 0 0.5rem 1.5rem;">
|
|
<input type="text" name="custom_token" placeholder="Enter custom token" pattern="[a-zA-Z0-9_-]+" maxlength="64">
|
|
</div>
|
|
<label style="margin-top: 0.5rem;">
|
|
<input type="checkbox" name="hidden" value="1">
|
|
Hide paste (return 404 if accessed without token)
|
|
</label>
|
|
{{end}}
|
|
</fieldset>
|
|
|
|
<div class="flex gap-1" style="margin-top: 1.5rem;">
|
|
<button type="submit" class="btn btn-primary btn-lg">Save paste</button>
|
|
<a href="/admin/bin" class="btn btn-secondary btn-lg">Cancel</a>
|
|
</div>
|
|
</form>
|
|
{{if .Paste}}{{with .Paste}}{{end}}{{end}}
|
|
</div>
|
|
|
|
<script src="/static/upload.js"></script>
|
|
<script src="/static/js/admin_bin_edit.js"></script>
|
|
{{end}}
|