tinyfiles.tv
tinyfiles.tv / dms — Dead Man's Switch

If you don't
come back,
it sends it.

Arm a DMS. Set a timer. If you don't deactivate it with your crypto + PIN in time, it sends an email to your record with what you said + the description.

⚠️

This feature is under development and does not work, don't use it

This DMS page is a mockup / preview only. The timer, deactivation, and email sending do not actually work yet. Do not rely on it to send anything important.

How it works
1Arm

Type it all in

Crypto, email, PIN, description, what you want to say, timer. Hit Arm. Timer starts.

2Deactivate

Come back in time

Type your crypto + PIN again to deactivate. Must match exactly. No other way to stop it.

3If not

It sends the email

Timer hits 0? It sends an email to your record — your email — with what you said + the description.

Arm a DMS — All fields required

Arm it.

Demo only — no real email is sent until timer hits 0 in this mockup. In real use, server sends it.

Backend  ·  Template · Proposed · Not connected

⬇ Backend — DMS Backend — Template

Right now this page is local-only — armed lives in JS, the timer lives in the browser, and “email sent” is a mock. Close the tab and nothing sends. This backend is the map to make it real: the server is the source of truth, a worker sends the email, and the browser is just the remote. Proposed, not connected. The yellow warning above still applies — do not rely on this until the backend + worker + email are live.

01 / Files to create
api/dms/arm.php           POST /api/dms/arm
api/dms/deactivate.php    POST /api/dms/deactivate
api/dms/checkin.php       POST /api/dms/checkin   (extend timer / ping)
api/dms/status.php        GET  /api/dms/status?id=...
worker/dms-send-due.php   cron every minute, sends due DMS
sql/dms_tables.sql
templates/dms-email.html

Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), member session for auth, prepared PDO statements.

02 / Database tables
-- sql/dms_tables.sql
dms_switches
  id VARCHAR(40) PRIMARY KEY          -- e.g. 'dms_abc123'
  member VARCHAR(80) NULL            -- NULL = guest (email-only), else member
  crypto_hash VARCHAR(255) NOT NULL   -- password_hash(crypto), never plaintext
  pin_hash VARCHAR(255) NOT NULL      -- password_hash(pin), never plaintext
  email_enc TEXT NOT NULL             -- encrypted, see 04
  desc_enc TEXT NOT NULL              -- encrypted
  msg_enc TEXT NOT NULL               -- encrypted
  expires_at DATETIME NOT NULL
  status ENUM('armed','deactivated','triggered','expired') NOT NULL DEFAULT 'armed'
  created_at DATETIME NOT NULL
  deactivated_at DATETIME NULL
  triggered_at DATETIME NULL
  last_checkin_at DATETIME NULL
  send_attempts INT NOT NULL DEFAULT 0

dms_checkins
  id INT AUTO_INCREMENT PRIMARY KEY
  switch_id VARCHAR(40) NOT NULL
  checked_in_at DATETIME NOT NULL
  FOREIGN KEY (switch_id) REFERENCES dms_switches(id)

dms_audit
  id INT AUTO_INCREMENT PRIMARY KEY
  switch_id VARCHAR(40) NOT NULL
  event ENUM('armed','checkin','deactivated','triggered','send_failed') NOT NULL
  created_at DATETIME NOT NULL
  FOREIGN KEY (switch_id) REFERENCES dms_switches(id)

Never store crypto, PIN, email, description, or message in plaintext. Hashes for verification, ciphertext for content.

03 / API endpoints & request flow
POST /api/dms/arm
{ "crypto": "...", "email": "...", "pin": "1234",
  "desc": "...", "msg": "...", "timer": 86400 }
- validate: all fields present, PIN 4 digits, email valid, timer in allow-list
- crypto_hash = password_hash(crypto), pin_hash = password_hash(pin)
- email_enc / desc_enc / msg_enc = encrypt with server key (see 04)
- expires_at = NOW() + timer
- returns { "ok": true, "id": "dms_...", "expires_at": "..." }

POST /api/dms/deactivate
{ "id": "dms_...", "crypto": "...", "pin": "1234" }
- load switch, if status != 'armed' return { "ok": false, "error": "not-armed" }
- password_verify(crypto, crypto_hash) AND password_verify(pin, pin_hash)
- if match: status='deactivated', deactivated_at=NOW()
- if no match: return error, do NOT change status, log attempt

POST /api/dms/checkin
{ "id": "dms_...", "crypto": "...", "pin": "1234", "extend": 86400 }
- same verification as deactivate
- if match: expires_at = NOW() + extend, last_checkin_at=NOW(), insert into dms_checkins

GET /api/dms/status?id=dms_...
- returns { "ok": true, "status": "armed", "expires_at": "...", "seconds_left": 1234 }
- never returns email / desc / msg / hashes

Deactivation must re-enter crypto + PIN exactly like the front-end does now — but verified on the server via hash, not by comparing plaintext in JS like the current deactivate() does.

04 / Crypto & validation (server owns this)
// Never trust the browser for time, status, or verification.
// Browser timer is display only. Server expires_at is truth.

// Hashes (for deactivation / check-in):
//   crypto_hash = password_hash(crypto, PASSWORD_ARGON2ID)
//   pin_hash    = password_hash(pin, PASSWORD_ARGON2ID)
//   verify with password_verify(), rate-limit failed attempts.

// Encryption (for email / desc / msg):
//   Server key from env, e.g. DMS_ENC_KEY (32 bytes, libsodium)
//   email_enc = sodium_crypto_secretbox(msg, nonce, key)
//   Store nonce + ciphertext together, base64.
//   Worker decrypts with same server key to send the email.
//   Trade-off is honest: server can read to send. If you want
//   zero-knowledge, the worker cannot send without the user key.

// Validation:
//   PIN must be exactly 4 digits, timer must be in allow-list
//   (1h, 24h, 7d, 30d, 90d), email must pass FILTER_VALIDATE_EMAIL
//   desc / msg length caps, e.g. desc <= 200 chars, msg <= 5000 chars

Current front-end stores armed = {crypto, pin, email, desc, msg} in plain JS. That must go away — the browser should only keep id + expires_at after arming.

05 / Worker & timing (cron is truth)
// worker/dms-send-due.php — run every minute via cron:
//   */1 * * * * php /opt/tinyfiles/worker/dms-send-due.php

// 1. SELECT * FROM dms_switches
//    WHERE status='armed' AND expires_at <= NOW()
//    LIMIT 20 FOR UPDATE SKIP LOCKED
// 2. For each:
//    - decrypt email / desc / msg with server key
//    - send via SMTP / mail() using templates/dms-email.html
//    - on success: status='triggered', triggered_at=NOW()
//    - on failure: send_attempts++, log to dms_audit, retry next minute
//    - insert into dms_audit (event='triggered' or 'send_failed')
// 3. Idempotent: only 'armed' rows can trigger. Re-running cron
//    must not send twice. Use transaction + status check.

// Email subject: "DMS Triggered — {desc}"
// Email body: desc + msg + "This DMS is now closed."
// From: tinyfiles.tv / dms

The browser setInterval() in this page must never be the trigger. If the user closes the tab, the worker still sends. That is the whole point of a Dead Man's Switch.

06 / Frontend wiring
// Replace armDMS() in this page:
async function armDMS(){
  const res = await fetch('/api/dms/arm', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ crypto, email, pin, desc, msg, timer })
  });
  const data = await res.json();
  // keep only data.id + data.expires_at in JS, never crypto/PIN/message
  // poll GET /api/dms/status?id=... every 30s for countdown
}

// Replace deactivate():
async function deactivate(){
  const res = await fetch('/api/dms/deactivate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ id, crypto: crypto2, pin: pin2 })
  });
  // if data.ok, show "DEACTIVATED", else "Wrong crypto / PIN — still armed"
}

// Remove triggerNow() mock, keep only for demo:
//   if API fails, fall back to current local mock + warning.

Keep the local mock playable with no backend — if /api/dms/arm fails, show the current in-page timer + mock email and keep the “does not work” warning.

Copy the snippets above into api/dms/ + worker/dms-send-due.php + sql/dms_tables.sql — no GitHub needed. The <pre> blocks are the backend spec: server-owned timer, hash-verified deactivation, encrypted storage, cron worker sends.