Implement hidden paste feature with QR code generation and access token handling
This commit is contained in:
1 parent
22fe12012b
commit
f80903c7eb
10 files changed
+232
-33
No files matched your search
@@ -13,10 +13,11 @@
|
||||
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
|
||||
<ul><li><a href="/">Home</a></li></ul>
|
||||
</nav>
|
||||
<main class="container" style="text-align:center;padding-top:4rem">
|
||||
<h1>404</h1>
|
||||
<p>This short link doesn't exist.</p>
|
||||
<a href="/" role="button">Create a new one</a>
|
||||
<main class="container" style="text-align:center;padding-top:6rem;max-width:640px">
|
||||
<p style="font-size:8rem;line-height:1;margin:0;font-weight:800;opacity:0.15">404</p>
|
||||
<h2 style="margin-top:0.5rem">Page Not Found</h2>
|
||||
<p style="color:var(--pico-muted-color)">The page you're looking for doesn't exist or may have been removed.</p>
|
||||
<a href="/" role="button" style="margin-top:1.5rem">Go Home</a>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -56,11 +56,13 @@
|
||||
<td><a href="/bin/{{.Name}}{{if .Token}}/{{.Token}}{{end}}" target="_blank">{{.Name}}</a></td>
|
||||
<td>{{.Title}}</td>
|
||||
<td><mark class="badge-format">{{.Format}}</mark></td>
|
||||
<td>{{if .Token}}<mark class="badge-token">🔒 token</mark>{{else}}<mark class="badge-public">public</mark>{{end}}</td>
|
||||
<td>{{if .Token}}<mark class="badge-token">🔒 token</mark>{{else}}<mark class="badge-public">public</mark>{{end}}{{if .Hidden}} <mark class="badge-hidden">hidden</mark>{{end}}</td>
|
||||
<td>{{.UpdatedAt.Format "2006-01-02 15:04"}}</td>
|
||||
<td>
|
||||
<div role="group">
|
||||
<a href="/admin/bin/edit/{{.ID}}" role="button" class="outline">Edit</a>
|
||||
<button type="button" class="outline" onclick="showBinQR('{{.Name}}', false)">QR</button>
|
||||
{{if .Token}}<button type="button" class="outline" onclick="showBinQR('{{.Name}}', true)">Full QR</button>{{end}}
|
||||
<form method="post" action="/admin/bin/delete/{{.ID}}" onsubmit="return confirm('Delete paste {{.Name}}?')">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
|
||||
<button type="submit" class="outline secondary">Del</button>
|
||||
@@ -84,5 +86,36 @@
|
||||
</figure>
|
||||
</article>
|
||||
</main>
|
||||
<dialog id="qr-dialog">
|
||||
<article>
|
||||
<header>
|
||||
<button aria-label="Close" rel="prev" onclick="document.getElementById('qr-dialog').close()"></button>
|
||||
<h3 id="qr-title">QR Code</h3>
|
||||
</header>
|
||||
<div id="qr-container" style="text-align:center"></div>
|
||||
</article>
|
||||
</dialog>
|
||||
<script>
|
||||
function showBinQR(name, full) {
|
||||
var container = document.getElementById('qr-container');
|
||||
var title = document.getElementById('qr-title');
|
||||
container.innerHTML = '<p>Loading...</p>';
|
||||
title.textContent = full ? 'Full QR Code (with token)' : 'QR Code';
|
||||
document.getElementById('qr-dialog').showModal();
|
||||
var url = '/admin/bin/qr/' + encodeURIComponent(name);
|
||||
if (full) url += '?full=1';
|
||||
fetch(url)
|
||||
.then(function(r) { return r.text(); })
|
||||
.then(function(svg) {
|
||||
var fullLink = location.origin + '/bin/' + name;
|
||||
var note = '';
|
||||
if (full) {
|
||||
note = '<small style="color:var(--pico-muted-color)">(includes access token)</small>';
|
||||
}
|
||||
container.innerHTML = svg +
|
||||
'<p style="margin-top:0.5rem;word-break:break-all">' + fullLink + '</p>' + note;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -91,18 +91,35 @@
|
||||
{{with .Paste}}
|
||||
{{if .Token}}
|
||||
<p>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="disable"> Disable token (public access)</label>
|
||||
<label><input type="radio" name="token_action" value="keep" checked onchange="toggleCustomToken()"> Keep current token</label>
|
||||
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Regenerate token</label>
|
||||
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
|
||||
<label><input type="radio" name="token_action" value="disable" onchange="toggleCustomToken()"> Disable token (public access)</label>
|
||||
{{else}}
|
||||
<p>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="keep" checked onchange="toggleCustomToken()"> Keep disabled</label>
|
||||
<label><input type="radio" name="token_action" value="regenerate" onchange="toggleCustomToken()"> Enable with new token</label>
|
||||
<label><input type="radio" name="token_action" value="custom" onchange="toggleCustomToken()"> Set custom token</label>
|
||||
{{end}}
|
||||
<div id="custom-token-wrap" style="display:none;margin-left:2rem">
|
||||
<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="0" checked onchange="toggleCustomToken()"> No token (public access)</label>
|
||||
<label><input type="radio" name="enable_token" value="1" onchange="toggleCustomToken()"> Generate access token</label>
|
||||
<label><input type="radio" name="enable_token" value="custom" onchange="toggleCustomToken()"> Custom token</label>
|
||||
<div id="custom-token-wrap" style="display:none;margin-left:2rem">
|
||||
<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>
|
||||
|
||||
@@ -115,5 +132,14 @@
|
||||
{{if .Paste}}{{with .Paste}}{{end}}{{end}}
|
||||
</article>
|
||||
</main>
|
||||
<script>
|
||||
function toggleCustomToken() {
|
||||
var wrap = document.getElementById('custom-token-wrap');
|
||||
if (!wrap) return;
|
||||
var checked = document.querySelector('input[name="token_action"][value="custom"]:checked') ||
|
||||
document.querySelector('input[name="enable_token"][value="custom"]:checked');
|
||||
wrap.style.display = checked ? 'block' : 'none';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
<head>
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Access Token Required — Glimmer</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<ul><li><strong><a href="/">Glimmer</a></strong></li></ul>
|
||||
<ul><li><a href="/">Home</a></li></ul>
|
||||
</nav>
|
||||
<main class="container" style="max-width:480px;padding-top:4rem;text-align:center">
|
||||
<p style="font-size:4rem;line-height:1;margin:0">🔒</p>
|
||||
<h2 style="margin-top:0.5rem">Access Token Required</h2>
|
||||
<p style="color:var(--pico-muted-color)">This paste is protected. Enter the access token to view it.</p>
|
||||
|
||||
{{if .Error}}
|
||||
<article aria-label="error" class="alert-error" style="text-align:left">{{.Error}}</article>
|
||||
{{end}}
|
||||
|
||||
<form id="token-form" style="text-align:left;margin-top:1.5rem">
|
||||
<label>
|
||||
Token
|
||||
<input type="text" id="token-input" required placeholder="Enter access token" autofocus>
|
||||
</label>
|
||||
<button type="submit" style="width:100%">View Paste</button>
|
||||
</form>
|
||||
</main>
|
||||
<script>
|
||||
document.getElementById('token-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var token = document.getElementById('token-input').value.trim();
|
||||
if (token) {
|
||||
window.location.href = window.location.pathname + '/' + encodeURIComponent(token);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user