Programmatic short-link creation that shares the same bearer key as the
MCP endpoint. Registered only when [mcp].enabled is true and api_key is
set, so a misconfigured server never exposes the route unauthenticated;
unauthenticated visitors hitting /api/links get a plain 404.
- POST /api/links accepts {"url","slug?"}, returns 201/200 with the
same snake_case payload shape as the MCP create_link tool.
- Constant-time Bearer / X-API-Key auth (reuses mcpAPIKeyAuth helper).
- 4 KB body cap, DisallowUnknownFields, URL auto-scheme, dedupe on URL.
- 13 unit tests cover auth, validation, dedupe, and duplicate-slug.
Glimmer
A lightweight, single-binary URL shortener and pastebin built in Go. Hosted on luci.ooo. Designed to run on a Raspberry Pi Zero (512MB RAM, single-core ARM) with minimal dependencies and no external runtime requirements.
Features
URL Shortener
- Public: Anyone can shorten a URL — no account required
- Auto-scheme: Submitting
google.comautomatically becomeshttps://google.com - Deduplication: Submitting the same URL a second time returns the existing short link
- QR codes: Server-side SVG QR codes generated for every short link (crisp, no CDN)
- Click tracking: Every redirect increments the click counter
- IP rate limiting: Anonymous users limited to 1 short link per second; admin is never limited
- Short slugs: 3-character base-36 auto-generated (
a-z,0-9); up to 64 characters for custom (admin only)
Admin Dashboard
- Login protected with bcrypt-hashed password; centered dark-theme login card
- Dark UI throughout all admin pages (login, dashboard, edit forms, pastes)
- Stats bar: live counts of My Links, Anonymous Links, and Quick Links at a glance
- My Links card: links the admin created, with edit/delete/QR and click counts
- Anonymous Links card: links created by unauthenticated users, also manageable
- Quick Links tile grid: Top 20 most-clicked admin links displayed as tiles with favicon, destination hostname, and click count; one click to open
- Pastes list: format and token-status badges; empty states with guidance
- Create links with custom slugs (blocked for anonymous users)
- Edit slug and destination URL
Pastebin
- Admin: Create, edit, delete pastes
- Public: Read-only access; optionally protected by a 12-character access token
- Formats: Markdown (GitHub-Flavored, rendered server-side) and plain text
- Raw view: Append
?raw=1to any paste URL fortext/plainoutput - Copy button: One-click clipboard copy in the paste viewer
- Image embedding: Paste an image from clipboard or use the Upload Image button in the paste editor — image is uploaded and a markdown link is inserted at the cursor automatically
- File attachments: Use the Upload File button to attach any file type (up to 5 MB); a markdown download link is inserted at the cursor
Image & File Uploads
- Two upload modes:
- Images — PNG, JPEG, GIF, WebP up to 50 MB (configurable). Validated by magic bytes, not file extension.
- Files — any file type up to 5 MB (hard-coded). Validated by extension regex only.
- Original filenames preserved: Stored on disk as
[32 hex chars].[ext]but the user's original filename is recorded in a SQLiteuploadstable and used in the admin listing and theContent-Dispositionheader when the file is downloaded. - Uploads management tab: View all uploaded files with thumbnails (images) or document icons (files), extension chip, original name, file size, and image dimensions.
- Resize: Downscale PNG or JPEG images in-place by setting a max dimension — re-encodes JPEG at 85% quality; no additional dependencies.
- Delete: Remove individual uploads from the admin uploads tab.
- Copy markdown: One-click copy of the
(images) or[name](/uploads/...)(files) link for use in any paste. - Public serving: Uploaded images are served inline at
/uploads/{filename}and render in public paste views. Non-image files are forced to download withContent-Disposition: attachmentto prevent same-origin XSS via uploaded HTML/SVG/JS. - Per-upload timeout: Upload requests get a 120-second read/write deadline via
http.NewResponseController; all other routes keep the 5s/10s defaults.
Security
- CSRF protection on every state-changing POST (double-submit cookie pattern)
crypto/subtle.ConstantTimeComparefor CSRF and paste token comparisons- Session cookie:
HttpOnly,SameSite=Lax, conditionallySecurewhen behind HTTPS proxy - Security headers on all responses:
X-Frame-Options: DENY,X-Content-Type-Options: nosniff,Referrer-Policy - Input length limits: URLs 2048 chars, paste content 512 KB
- URL scheme re-validated before every redirect (defense in depth)
- In-memory sessions with hourly cleanup goroutine
Project Layout
glimmer/
├── main.go # Entry point; flag parsing; --hash-password helper
├── config.toml # Runtime configuration (port, admin creds, db path)
├── go.mod / go.sum
├── Makefile
├── deploy/
│ ├── install.sh # Install script (auto-detects systemd vs SysV)
│ ├── glimmer.service # systemd unit file (Ubuntu 15.04+)
│ └── glimmer.init # SysV init script (Ubuntu 14.04 and older)
├── data/
│ ├── urls.db # SQLite database (auto-created on first run)
│ └── uploads/ # Uploaded images & files (auto-created on first run)
└── internal/
├── config/
│ └── config.go # TOML config loader; Config struct (incl. UploadConfig)
├── db/
│ └── db.go # SQLite open/migrate; Link & Paste & Upload CRUD
├── slug/
│ └── slug.go # Base-36 slug generation and validation
└── server/
├── server.go # HTTP mux registration; security headers middleware
├── handlers.go # All request handlers; template rendering helpers
├── middleware.go # requireAuth, requireCSRF, rateLimiter, sessionStore, clientIP
├── static/
│ ├── style.css # Custom styles on top of Pico CSS
│ └── upload.js # Shared client-side upload helper (window.GlimmerUpload)
└── templates/
├── index.html # Public home: shorten form + QR result
├── admin_login.html # Login form (dark, centered card)
├── admin.html # Admin dashboard: stats bar, tiles, links tables
├── admin_edit.html # Edit a single link
├── admin_bin.html # Pastes list with format/token badges
├── admin_bin_edit.html # Create / edit a paste (with image + file upload)
├── admin_uploads.html # Upload management: list, resize, delete
├── bin_view.html # Public paste viewer (GitHub Gist style)
└── 404.html # Not found page
Dependencies
| Package | Purpose |
|---|---|
github.com/BurntSushi/toml |
TOML config parsing |
golang.org/x/crypto/bcrypt |
Admin password hashing |
modernc.org/sqlite |
Pure-Go SQLite driver (no CGo required) |
github.com/yuin/goldmark |
Markdown rendering (GFM + tables) |
rsc.io/qr |
Server-side QR code generation (SVG) |
All other entries in go.sum are transitive dependencies of the above.
Getting Started
Prerequisites
- Go 1.22 or later
- No CGo, no external C libraries, no system SQLite needed
Windows note: If Go is not in your bash
PATH, prefix every command:export PATH="/c/Program Files/Go/bin:$PATH"
1. Clone and install dependencies
git clone <repo-url>
cd url
go mod download
2. Configure
Edit config.toml:
[server]
port = 8888
base_url = "http://localhost:8888" # Override by Host header at runtime
read_timeout = "5s"
write_timeout = "10s"
[admin]
username = "admin"
password_hash = "$2a$10$..." # See step 3 below
session_hours = 24
[mcp]
enabled = false # Enable POST /mcp
api_key = "replace-with-a-long-random-token"
[database]
path = "./data/urls.db"
[slugs]
length = 3 # Auto-generated slug length (characters)
[upload]
dir = "./data/uploads" # Where uploaded images & files are stored (auto-created)
max_size_mb = 50 # Max image upload size in MB (file uploads are hard-capped at 5 MB)
3. Set your admin password
./glimmer --hash-password "your-secure-password"
# or via make:
make hash
Copy the printed bcrypt hash into config.toml under admin.password_hash.
MCP Access
Glimmer can expose a Model Context Protocol endpoint at POST /mcp. Enable it in config.toml:
[mcp]
enabled = true
api_key = "replace-with-a-long-random-token"
MCP clients can authenticate with Authorization: Bearer <api_key> or X-API-Key: <api_key>. Basic auth using the configured admin username and password is also accepted. The endpoint exposes tools for listing, creating, updating, and deleting links and pastes, plus listing and deleting upload metadata/files.
REST API
A small REST surface shares the same [mcp].api_key. It is registered only when [mcp].enabled = true and api_key is set, so a misconfigured server never exposes the endpoint unauthenticated. The route is intentionally undocumented in any public-facing template — visitors who don't know it exists get a 404.
POST /api/links
Create a short link. Authenticate with Authorization: Bearer <api_key> or X-API-Key: <api_key>. Both are checked with constant-time comparison.
Request body (JSON):
{
"url": "https://example.com/very/long/path",
"slug": "docs" // optional; omit for auto-generated
}
Rules:
url— required. Max 2048 chars. Must behttp://orhttps://. Bare domains are auto-prefixed withhttps://.slug— optional. Lowercase letters, digits, hyphens, and underscores, up to 64 chars.- Deduplication: if the same URL is submitted twice and no custom slug is given, the second call returns the existing link with HTTP 200 (idempotent).
- Links created via the API are recorded as
created_by = "admin"and appear in the admin dashboard.
Responses:
201 Created— new link created. Body is the link payload.200 OK— same URL already existed; returns the existing link.400 Bad Request— invalid JSON, bad URL, or bad slug.401 Unauthorized— missing or wrong API key.409 Conflict— custom slug already taken.500 Internal Server Error— database error.
Response body (snake_case to match the MCP payload):
{
"id": 42,
"slug": "docs",
"url": "https://example.com/very/long/path",
"short_url": "https://s.example.com/docs",
"created_by": "admin",
"clicks": 0,
"created_at": "2026-06-08T20:36:55Z"
}
Example:
curl -X POST https://s.example.com/api/links \
-H "Authorization: Bearer $GLIMMER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/docs","slug":"docs"}'
4. Build and run
# Windows
make build
./glimmer.exe
# Linux / macOS
make build-linux
./glimmer
# Raspberry Pi Zero (ARMv5)
make build-arm
# Copy glimmer-arm to the Pi, then run it there
The server starts on http://localhost:8888 (or whatever port you set).
Makefile Targets
| Target | Description |
|---|---|
make build |
Build glimmer.exe for Windows (stripped binary) |
make build-linux |
Build glimmer for Linux x86-64 |
make build-arm |
Cross-compile glimmer-arm for Raspberry Pi Zero (ARMv5) |
make run |
Build then immediately run on Windows |
make clean |
Remove all compiled binaries |
make hash |
Interactively hash a password for config.toml |
Deploying to Raspberry Pi Zero
# On your dev machine — cross-compile for ARMv5 (Pi Zero)
make build-arm
# Copy binary, config, and deploy scripts to the Pi
scp glimmer-arm [email protected]:~/glimmer
scp config.toml [email protected]:~/config.toml
scp -r deploy/ [email protected]:~/deploy/
The binary is fully self-contained — no Go runtime, no system SQLite, no shared libraries required.
Install as a system service
The deploy/ directory contains an install script and service files compatible with Ubuntu/Debian (both modern systemd and older SysV init systems):
# On the Pi (or any Ubuntu/Debian host):
chmod +x glimmer
sudo ./deploy/install.sh
The script will:
- Create a dedicated
glimmersystem user - Install the binary to
/opt/glimmer/ - Install the config to
/etc/glimmer/config.toml - Create
/var/lib/glimmer/for the database - Register and enable the service (systemd or SysV, auto-detected)
After install, set your admin password hash in the config:
/opt/glimmer/glimmer -hash-password "your-secure-password"
# Paste the output into /etc/glimmer/config.toml → admin.password_hash
sudo systemctl start glimmer
Service management:
sudo systemctl status glimmer
sudo systemctl restart glimmer
sudo journalctl -u glimmer -f # live logs
Behind a Reverse Proxy — nginx
The app reads Host and X-Forwarded-Proto headers automatically to build correct short URLs and set Secure cookies. No base_url change is needed in config.toml when running behind a proxy.
1. Install nginx
sudo apt update
sudo apt install -y nginx
2. Create a site config
sudo nano /etc/nginx/sites-available/glimmer
Paste the following, replacing short.example.com with your domain:
server {
listen 80;
server_name short.example.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s; # Allow time for large image uploads (up to 50 MB)
proxy_send_timeout 120s;
}
}
sudo ln -s /etc/nginx/sites-available/glimmer /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
At this point the site is reachable over HTTP. Proceed to step 3 to add HTTPS.
3. Add HTTPS with Let's Encrypt (certbot)
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d short.example.com
Certbot will automatically update the nginx config to add SSL and redirect HTTP → HTTPS. Certificates auto-renew via a systemd timer or cron job that certbot installs.
No public domain? If running on a local network (e.g. Raspberry Pi at home), skip certbot and use a self-signed certificate instead:
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ -keyout /etc/ssl/private/glimmer.key \ -out /etc/ssl/certs/glimmer.crt \ -subj "/CN=glimmer"Then reference them manually in the nginx config (
ssl_certificate,ssl_certificate_key).
4. Recommended production nginx config
After certbot runs, your config will look roughly like this. The additions below tighten security headers and enable compression:
server {
listen 80;
server_name short.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name short.example.com;
# TLS — managed by certbot
ssl_certificate /etc/letsencrypt/live/short.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/short.example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# Compression
gzip on;
gzip_types text/css text/html application/javascript;
gzip_min_length 1024;
# Security headers
add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin" always;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s; # Allow time for large image uploads (up to 50 MB)
proxy_send_timeout 120s;
proxy_buffering off;
}
}
sudo nginx -t && sudo systemctl reload nginx
5. Update config.toml base_url (optional)
base_url is only used as a fallback when no Host header is present (e.g. direct curl on localhost). When nginx is in front, the Host header is always forwarded, so the generated short links will automatically use your domain. If you want the fallback to also be correct:
[server]
base_url = "https://short.example.com"
Then restart the service: sudo systemctl restart glimmer
Verify everything works
# Confirm redirect (should return 301 to https)
curl -I http://short.example.com/
# Confirm HTTPS proxy is working
curl -I https://short.example.com/
# Check glimmer is running and nginx can reach it
sudo systemctl status glimmer
sudo systemctl status nginx
Cloudflare note
If proxying through Cloudflare, X-Forwarded-For is safe to trust for rate limiting since Cloudflare controls the header. For direct-to-internet deployments without a trusted proxy, clients could spoof X-Forwarded-For to bypass IP rate limits — see "Possible Future Improvements".
URL Routes
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/ |
Public | Home / shorten form |
POST |
/shorten |
Public | Create short link |
GET |
/{slug} |
Public | Redirect to destination |
GET |
/bin/{name} |
Public | View paste |
GET |
/bin/{name}/{token} |
Public | View token-protected paste |
GET |
/uploads/{filename} |
Public | Serve uploaded image inline; non-images forced as attachment |
GET |
/uploads/thumb/{filename} |
Public | Serve a 512px (long side) JPEG thumbnail of an uploaded image, generated and cached on first request |
GET |
/admin/login |
Public | Login form |
POST |
/admin/login |
Public | Submit login |
POST |
/admin/logout |
Admin | Logout (CSRF protected) |
GET |
/admin |
Admin | Dashboard: links + tiles |
GET |
/admin/edit/{id} |
Admin | Edit link form |
POST |
/admin/edit/{id} |
Admin | Save link edit (CSRF) |
POST |
/admin/delete/{id} |
Admin | Delete link (CSRF) |
GET |
/admin/qr/{slug} |
Admin | QR code SVG for a short link |
GET |
/admin/bin |
Admin | Pastes list |
GET |
/admin/bin/new |
Admin | New paste form |
POST |
/admin/bin/new |
Admin | Create paste (CSRF) |
GET |
/admin/bin/edit/{id} |
Admin | Edit paste form |
POST |
/admin/bin/edit/{id} |
Admin | Save paste edit (CSRF) |
POST |
/admin/bin/delete/{id} |
Admin | Delete paste (CSRF) |
GET |
/admin/uploads |
Admin | Uploads management list |
POST |
/admin/upload |
Admin | Upload an image — PNG/JPEG/GIF/WebP, up to 50 MB (returns JSON) |
POST |
/admin/upload-file |
Admin | Upload any file — up to 5 MB (returns JSON) |
POST |
/admin/uploads/delete/{filename} |
Admin | Delete an uploaded file (CSRF) |
POST |
/admin/uploads/resize/{filename} |
Admin | Resize a PNG/JPEG in-place (returns JSON) |
POST |
/mcp |
MCP auth | JSON-RPC MCP endpoint, when [mcp].enabled = true |
POST |
/api/links |
API key | REST: create a short link (when [mcp].enabled = true and api_key is set) |
GET |
/static/* |
Public | CSS / static assets |
Database Schema
SQLite, WAL mode, single writer, auto-migrated on startup.
CREATE TABLE links (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
url TEXT NOT NULL,
created_by TEXT NOT NULL DEFAULT 'anonymous', -- 'admin' or 'anonymous'
clicks INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE pastes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE, -- URL slug, e.g. "my-script"
title TEXT NOT NULL DEFAULT '',
content TEXT NOT NULL DEFAULT '',
format TEXT NOT NULL DEFAULT 'markdown', -- 'markdown' | 'text'
token TEXT, -- NULL = public; non-null = token required
hidden INTEGER NOT NULL DEFAULT 0, -- 1 = return 404 instead of token prompt
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE uploads (
filename TEXT PRIMARY KEY, -- on-disk name, e.g. "abc123…def.pdf"
original_name TEXT NOT NULL DEFAULT '', -- sanitised original from the upload form
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
To reset the database (e.g. during development):
rm -f data/urls.db
# Restart the server — it will recreate the DB automatically
Configuration Reference
[server]
port = 8888 # TCP port to listen on
base_url = "http://localhost:8888" # Fallback base URL (overridden by Host header)
read_timeout = "5s" # HTTP read timeout (uploads extend their own deadline to 120s)
write_timeout = "10s" # HTTP write timeout (uploads extend their own deadline to 120s)
[admin]
username = "admin" # Admin login username
password_hash = "$2a$10$..." # bcrypt hash — generate with: ./glimmer --hash-password
session_hours = 24 # How long admin sessions last
[mcp]
enabled = false # Enable the MCP endpoint at POST /mcp
api_key = "" # Recommended: a long random bearer token for MCP clients
[database]
path = "./data/urls.db" # Path to SQLite file (directory auto-created)
[slugs]
length = 3 # Length of auto-generated slugs (recommended: 3–6)
[upload]
dir = "./data/uploads" # Directory for uploaded images & files (auto-created)
max_size_mb = 50 # Max image upload size in MB; file uploads are hard-capped at 5 MB
Security Notes
- Change the default password. The default hash in
config.tomlis for the passwordadmin. Run./glimmer --hash-passwordimmediately. - CSRF protection uses the double-submit cookie pattern. Every admin POST requires a
csrf_tokenform field matching thecsrfcookie value, compared with constant-time equality. - Sessions are stored in memory. They are lost when the server restarts (acceptable for single-user use). Session IDs are 32 bytes of
crypto/rand. - Paste tokens are 12-character random strings. Token comparison uses
crypto/subtle.ConstantTimeCompareto prevent timing attacks. - Rate limiting is 1 short link per second per IP for anonymous users. The rate limiter table is lazily cleaned up at 10,000 entries.
Development Tips
Rebuild and restart quickly (Windows)
export PATH="/c/Program Files/Go/bin:$PATH"
pkill -f glimmer.exe; sleep 1
go build -o glimmer.exe ./ && ./glimmer.exe &
Check logs
# If started with output redirected:
tail -f /tmp/glimmer.log
Useful one-liners
# Hash a new password
go run . --hash-password "mynewpassword"
# Check what's listening on 8888 (Windows PowerShell)
Get-NetTCPConnection -LocalPort 8888 | Select-Object OwningProcess
# Kill whatever is on port 8888 (Windows PowerShell)
Get-NetTCPConnection -LocalPort 8888 | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
Possible Future Improvements
- Configurable trusted-proxy IP list (for safer
X-Forwarded-Forhandling) - Persistent sessions (write to SQLite) so restarts don't log out admin
- Optional expiry date per link
- Bulk delete / bulk import via CSV
- Syntax highlighting for code pastes
- Animated GIF resize support
- WebP encode support for resize (requires an external library)
- Upload storage quota display in the uploads tab