diff --git a/.gitignore b/.gitignore index dc6cd95..b437387 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,10 @@ node_modules/ .env .env.production +# real DB credentials for the launch-list endpoint (never commit) +subscribe.config.php +**/subscribe.config.php + # macOS .DS_Store diff --git a/public/subscribe.php b/public/subscribe.php new file mode 100644 index 0000000..080dbe9 --- /dev/null +++ b/public/subscribe.php @@ -0,0 +1,84 @@ + $ok, 'message' => $message]); + } else { + header('Location: /?subscribed=' . ($ok ? '1' : '0') . '#subscribe'); + } + exit; +} + +$wantsJson = isset($_SERVER['HTTP_X_REQUESTED_WITH']) + && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'fetch'; + +if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') { + respond(false, 405, 'Method not allowed.', $wantsJson); +} + +// Honeypot: bots fill hidden fields, people don't. Accept silently, store nothing. +if (trim((string) ($_POST['website'] ?? '')) !== '') { + respond(true, 200, "You're on the list.", $wantsJson); +} + +$email = trim((string) ($_POST['email'] ?? '')); +if ($email === '' || strlen($email) > 254 || !filter_var($email, FILTER_VALIDATE_EMAIL)) { + respond(false, 422, 'Please enter a valid email address.', $wantsJson); +} + +// Config one level above the web root is preferred; same-dir is a fallback. +$configFile = __DIR__ . '/../subscribe.config.php'; +if (!is_file($configFile)) { + $configFile = __DIR__ . '/subscribe.config.php'; +} +if (!is_file($configFile)) { + error_log('subscribe: missing subscribe.config.php'); + respond(false, 500, 'Signups are not configured yet.', $wantsJson); +} +$config = require $configFile; + +try { + $pdo = new PDO($config['dsn'], $config['user'], $config['pass'], [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_EMULATE_PREPARES => false, + ]); + // Unique index on email makes this idempotent — a repeat signup is a no-op. + $stmt = $pdo->prepare( + 'INSERT INTO subscribers (email, created_at, ip) VALUES (:email, NOW(), :ip) + ON DUPLICATE KEY UPDATE email = email' + ); + $stmt->execute([ + ':email' => $email, + ':ip' => $_SERVER['REMOTE_ADDR'] ?? null, + ]); +} catch (Throwable $e) { + error_log('subscribe: ' . $e->getMessage()); + respond(false, 500, 'Could not save that right now — try again later.', $wantsJson); +} + +// Optional heads-up email. Never fatal: the DB row is the source of truth. +if (!empty($config['notify'])) { + @mail( + (string) $config['notify'], + 'Green Tea: new subscriber', + "New launch-list signup: {$email}", + 'From: Green Tea <' . $config['notify'] . '>' + ); +} + +respond(true, 200, "You're on the list — we'll ping you at 1.0.", $wantsJson); diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..a378283 --- /dev/null +++ b/server/README.md @@ -0,0 +1,24 @@ +# Launch-list backend (cPanel) + +The email capture on the site posts to `subscribe.php`, which ships in the build +(`public/subscribe.php` → `dist/subscribe.php`). To wire it up on cPanel: + +1. **Create the DB** in cPanel → MySQL Databases. Note db name, user, password. +2. **Create the table**: run `schema.sql` in phpMyAdmin against that DB. +3. **Add credentials**: copy `subscribe.config.example.php` to `subscribe.config.php`, + fill in the DB values, and upload it **one level above** the subdomain's docroot + (so it is never web-servable). `subscribe.php` looks there first. +4. **Deploy** the built `dist/` into the subdomain docroot. `subscribe.php` is already inside it. +5. **Smoke test**: + ``` + curl -i -X POST -H 'X-Requested-With: fetch' \ + --data 'email=test@example.com' \ + https://green-tea.expressive-tea.io/subscribe.php + ``` + Expect `{"ok":true,...}` and a row in `subscribers`. + +Notes: +- Duplicate signups are a silent success (unique index on `email`). +- A hidden honeypot field blocks basic bots. +- No-JS visitors are redirected to `/?subscribed=1`; with JS they get inline feedback. +- No rate limiting yet — add one at the cPanel/CDN layer if signups get abused. diff --git a/server/schema.sql b/server/schema.sql new file mode 100644 index 0000000..18f301a --- /dev/null +++ b/server/schema.sql @@ -0,0 +1,7 @@ +-- Launch-list table for subscribe.php. Run once against the green-tea DB. +CREATE TABLE IF NOT EXISTS subscribers ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + email VARCHAR(254) NOT NULL UNIQUE, + created_at DATETIME NOT NULL, + ip VARCHAR(45) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/server/subscribe.config.example.php b/server/subscribe.config.example.php new file mode 100644 index 0000000..52e432b --- /dev/null +++ b/server/subscribe.config.example.php @@ -0,0 +1,18 @@ + 'mysql:host=localhost;dbname=YOUR_DB;charset=utf8mb4', + 'user' => 'YOUR_DB_USER', + 'pass' => 'YOUR_DB_PASSWORD', + 'notify' => 'support@expressive-tea.io', // set to '' to skip notification emails +]; diff --git a/src/components/sections/HonestBeta.astro b/src/components/sections/HonestBeta.astro index f36df89..8b886fe 100644 --- a/src/components/sections/HonestBeta.astro +++ b/src/components/sections/HonestBeta.astro @@ -10,6 +10,27 @@ ergonomics. If you're tired of maintaining someone else's foundation, come try it.
+ +