diff --git a/mailer.js b/mailer.js index 312ede4..f0b0f09 100644 --- a/mailer.js +++ b/mailer.js @@ -1,4 +1,4 @@ -// Outbound mail via SendGrid v3 (domain-authenticated instantadpay.com). +// Outbound mail via SendGrid v3 (domain-authenticated instantadpay.com; links in bodies go out on the share domain, see mailLinks). // Key sources: SENDGRID_KEY env, else DATA_DIR/sendgrid.key in the volume. // No key = email sign-in stays feature-flagged off in production. const fs = require('fs'); @@ -19,6 +19,17 @@ function hasKey() { return !!key(); } // codes and mail to the admin is skipped for anyone who unsubscribed, carries // the signed unsubscribe link (appended unless the body already has one) and // RFC 8058 one-click List-Unsubscribe headers. New senders inherit this. +// Links in mail go on the share domain (2026-11-17, Spamhaus DBL): instantadpay.com is on the DBL, so every URL to it in a body +// (and the List-Unsubscribe header) counts against each email. One rewrite here covers every sender; the share host passes +// /my, /ledger, /join/, ... through to the same page and answers /unsubscribe and /banners/* itself. The From address +// and any name@instantadpay.com in the text stay as they are. MAIL_BASE='' turns it off. +const MAIL_BASE = String(process.env.MAIL_BASE == null ? 'https://instantadpay.link' : process.env.MAIL_BASE).trim().replace(/\/+$/, ''); +const IAP_LINK_RE = /(? /^https?:/i.test(m) ? MAIL_BASE : bare); +} function isAdmin(to) { const a = String(process.env.ADMIN_EMAIL || '').trim().toLowerCase(); return !!a && String(to).trim().toLowerCase() === a; } async function send(to, subject, text, html, opts) { // html optional (2026-10-01): sent alongside the plain text, never instead of it @@ -29,6 +40,7 @@ async function send(to, subject, text, html, opts) { // html optional (2026-10-0 try { if (await drip.isUnsubscribed(to)) return false; } catch (e) { console.error('mailer opt-out check', e.message); } try { unsub = drip.unsubUrl(to); } catch (e) { console.error('mailer unsub link', e.message); } } + unsub = mailLinks(unsub); text = mailLinks(text); if (html) html = mailLinks(html); subject = mailLinks(subject); if (unsub && !String(text).includes('/unsubscribe?')) text = text + '\n\n--\nStop these emails: ' + unsub; if (unsub && html && !String(html).includes('/unsubscribe?')) { const foot = '

Stop these emails: unsubscribe

'; @@ -68,4 +80,4 @@ function sendCode(to, code) { + 'InstantAdPay\nAdvertise and earn instantly. Locked in code, not promises.\nhttps://instantadpay.com', null, { transactional: true }); } -module.exports = { init, hasKey, send, sendCode }; +module.exports = { init, hasKey, send, sendCode, mailLinks }; diff --git a/nas.js b/nas.js index 864bf7a..7570cbd 100644 --- a/nas.js +++ b/nas.js @@ -76,7 +76,7 @@ async function pushCampaign(c, opts = {}) { Name, Email, PaymentDetails, EDate, sp, width, height, BannerURL, pid, ref_by, catid) VALUES (?,?,?,?,?,?,0,1,?,?,?,?,?,?,'',?,?,?,?,0,?)`, // clicks route through our redirect so they count and carry the network site as the referrer - [token, c.title || null, c.type === 'text' ? (c.body || null) : null, 'https://instantadpay.com/api/ads/click/' + c.id, + [token, c.title || null, c.type === 'text' ? (c.body || null) : null, (process.env.NAS_CLICK_BASE || 'https://instantadpay.link') + '/api/ads/click/' + c.id, assigned, assigned, now, kind.adtype, opts.name || 'InstantAdPay member', opts.email || 'ads@instantadpay.com', 'InstantAdPay campaign #' + c.id, edate, @@ -122,7 +122,7 @@ async function deactivate(nasAdId) { // point an existing NAS ad at our click redirect (migration for rows pushed before 2026-09-10) async function setClickUrl(nasAdId, campaignId) { if (!enabled()) return { skipped: 'flag-off' }; - await q('UPDATE sponsorads SET WebsiteURL=? WHERE ID=?', ['https://instantadpay.com/api/ads/click/' + Number(campaignId), Number(nasAdId)]); + await q('UPDATE sponsorads SET WebsiteURL=? WHERE ID=?', [(process.env.NAS_CLICK_BASE || 'https://instantadpay.link') + '/api/ads/click/' + Number(campaignId), Number(nasAdId)]); return { ok: true }; } async function topUp(nasAdId, addImpressions, days) { diff --git a/public/assets/my.js b/public/assets/my.js index 5f0264a..1bdc3b3 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -3059,7 +3059,9 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str if (bridge) { // the bridge page with this member's referral: any public page + ?ref sets the sponsor cookie const inv = (document.getElementById('inviteLine') || {}).textContent || ''; - const fl = inv.replace(/\/join\/([^/?#]+).*$/, '/' + bridge.page + '?ref=$1'); + // the invite line is the share link (https:///) or the old /join/ form (2026-11-17: the share form never matched, so the bridge link was the plain invite) + const im = /\/(?:join\/)?([A-Za-z0-9_]{1,40})\/?(?:[?#].*)?$/.exec(inv.trim()); + const fl = im ? (SHARE_DOMAIN ? 'https://' + SHARE_DOMAIN : location.origin) + '/' + bridge.page + '?ref=' + im[1] : inv; const note = document.createElement('div'); note.className = 'pb-note'; note.innerHTML = 'Post any of these with your ' + esc(bridge.name) + ' link: '; @@ -3070,7 +3072,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str grid.before(note); } for (const b of g.items) { - const url = location.origin + '/banners/' + b.file; + const url = (SHARE_DOMAIN ? 'https://' + SHARE_DOMAIN : location.origin) + '/banners/' + b.file; // share hosts serve /banners/* in place (2026-11-17, instantadpay.com is on Spamhaus DBL) const d = document.createElement('div'); d.className = 'pb-item'; d.innerHTML = 'InstantAdPay banner ' + b.size + '' diff --git a/public/my.html b/public/my.html index 387769a..df92c25 100644 --- a/public/my.html +++ b/public/my.html @@ -1313,7 +1313,7 @@ - + diff --git a/server.js b/server.js index dfa6620..bde29d6 100644 --- a/server.js +++ b/server.js @@ -2405,9 +2405,12 @@ const server = http.createServer(async (req, res) => { // share-link domains (instantadpay.link active since 2026-11-04; ctbgo.com and mylinehq.com still answer): / goes to that member's join page, anything else to the same path // here. 302 (not 301) so links never get pinned in caches; the query (?v= angle, ?promo=) rides along. { const sh = String(req.headers.host || '').toLowerCase().replace(/:\d+$/, '').replace(/^www\./, ''); - if (SHARE_HOSTS.includes(sh)) { - // a public page name is that page, not a username (2026-11-17: the Network Weekend email links instantadpay.link/weekend) - const ref = /^\/(weekend|friday|wednesday|ledger|refuel|facts|games|support|my|join)\/?$/.test(p) ? null : /^\/([A-Za-z0-9_]{1,40})\/?$/.exec(p); + // answered in place on a share host, never redirected (2026-11-17, mail links moved to the share domain): the + // unsubscribe link (RFC 8058 one-click is a POST, which a 302 would break) and the banner images mail and promo tools embed + if (SHARE_HOSTS.includes(sh) && !(p === '/unsubscribe' || ((req.method === 'GET' || req.method === 'HEAD') && /^\/banners\/[\w.-]+$/.test(p)))) { + // a public page name is that page, not a username (2026-11-17: the Network Weekend email links instantadpay.link/weekend; + // leaderboard/blog/presentation added the same day when every email's links moved here; no member holds those names) + const ref = /^\/(weekend|friday|wednesday|ledger|refuel|facts|games|support|my|join|leaderboard|blog|presentation|partners|launch|plays|bixpay|wall)\/?$/.test(p) ? null : /^\/([A-Za-z0-9_]{1,40})\/?$/.exec(p); const to = 'https://instantadpay.com' + (p === '/' ? '/' : ref ? '/join/' + ref[1] : p) + (u.search || ''); res.writeHead(302, { Location: to, 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' }); return res.end(); } } @@ -5644,6 +5647,10 @@ const server = http.createServer(async (req, res) => { let own = false, cm = null; try { cm = await ads.campaignById(m[1]); } catch (e) {} try { const s = cm && await auth.fromRequest(req); if (s && s.email) own = !!(cm.owner && String(cm.owner).toLowerCase() === String(s.email).toLowerCase()); } catch (e) {} + // only a running campaign redirects off-site (2026-11-17, Spamhaus DBL): an ended, paused, archived or flagged campaign's + // click link used to keep forwarding to its target forever (e.g. #164 -> a URL shortener), a ready-made instantadpay.com + // redirector for anyone. Those now land on the home page, uncounted. The owner can still open their own link. + if (!own && (!cm || cm.status !== 'active')) { res.writeHead(302, baseHeaders({ Location: '/', 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' })); return res.end(); } const target = own ? await ads.targetOf(m[1]) : await ads.click(m[1]); if (!target) { res.writeHead(404, baseHeaders()); return res.end(); } if (!own) coach.recordClick(m[1], req.headers.referer); // where the click happened diff --git a/toolkit.js b/toolkit.js index 9cccbd7..922f79e 100644 --- a/toolkit.js +++ b/toolkit.js @@ -92,7 +92,7 @@ async function status(email) { const u = usage()[email] || {}; const used = (u.months || {})[monthKey()] || 0; const allowance = allowanceFor(tier, sc); const cost = Number(sc.aiCreditsPerGen) || 10; let available = 0; try { const st = await R.ads.viewStatus(email); available = st.earnedAvailable != null ? st.earnedAvailable : (st.earned || 0); } catch (e) {} - const link = 'https://instantadpay.com/join/' + (acct.username || acct.code); + const link = SHARE() + '/join/' + (acct.username || acct.code); const partner = tier === 'nexus' ? await partnerStatus(email) : null; const handoutUrl = rank[tier] >= rank.spark && acct.username ? 'https://instantadpay.com/handout/' + acct.username : null; return { tier, badges, username: acct.username || null, partner, handoutUrl, videoMaker: !!(R.videomaker && R.videomaker.available()), unlocked: ['surge', 'circuit', 'nexus'].includes(tier), engine: !!key(), allowance, used, freeLeft: Math.max(0, allowance - used), cost, available, link, @@ -129,6 +129,9 @@ async function adminUsage() { // ---- the rest of the ladder (Marty, 2026-09-14): Spark templates + handout, Circuit split tester + Video // Maker, Nexus Leader Ops + team grants + a member-funded partner code ---- const KIT = 'https://instantadpay.com'; +// member links that get pasted elsewhere go out on the share domain (2026-11-17, Spamhaus DBL: instantadpay.com is listed); +// /join/ passes through to the join page. shareDomain '' (admin settings) = the old instantadpay.com links. +const SHARE = () => { const d = String((R && R.siteConfig && R.siteConfig().shareDomain) || '').trim().toLowerCase(); return /^[a-z0-9.-]+\.[a-z]{2,}$/.test(d) ? 'https://' + d : KIT; }; async function tierOf(email) { return tierFor(await R.ads.milestonesOf(email)); } const rank = { free: 0, spark: 1, surge: 2, circuit: 3, nexus: 4 }; const atLeast = (tier, need) => rank[tier] >= rank[need]; @@ -154,7 +157,7 @@ async function template(email, memberId, ids, kind, budget) { async function handout(username) { const a = await R.accounts.byUsername(username); if (!a) return null; if (!atLeast(await tierOf(a.email), 'spark')) return null; - const link = KIT + '/join/' + username; const qr = '/api/qr?d=' + encodeURIComponent(link); + const link = SHARE() + '/join/' + username; const qr = '/api/qr?d=' + encodeURIComponent(link); const esc = t => String(t || '').replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); return 'InstantAdPay handout for @' + esc(username) + '' + '' @@ -168,7 +171,7 @@ async function handout(username) { async function split(email) { const tier = await tierOf(email); const st = await R.coach.linkStats(email); - const acct = await R.accounts.byEmail(email); const base = KIT + '/join/' + (acct.username || acct.code); + const acct = await R.accounts.byEmail(email); const base = SHARE() + '/join/' + (acct.username || acct.code); const rows = (st.angles || []).map(a => ({ angle: a.angle, link: base + (a.angle && a.angle !== 'plain' ? '?v=' + a.angle : ''), views: a.views || 0, views30: a.views30 || 0, joins: a.joins || 0, buyers: a.buyers || 0, rate: a.views ? Math.round(1000 * (a.joins || 0) / a.views) / 10 : 0 })); const withData = rows.filter(r => r.views >= 10); const best = withData.length ? withData.slice().sort((x, y) => y.rate - x.rate || y.joins - x.joins)[0] : null; return { unlocked: atLeast(tier, 'circuit'), rows, best: best ? best.angle : null, sources: st.sources || [] }; @@ -219,12 +222,12 @@ async function partnerCode(email, code, credits) { const r = await R.promos.create({ code, credits: n, funder: email, partner: 'member: ' + email, note: 'member-funded partner code', maxUses: 0, expires: null, active: true }); if (r.error) return r; const acct = await R.accounts.byEmail(email); - return { ok: true, code: r.code.code, credits: n, link: KIT + '/join/' + (acct.username || acct.code) + '?promo=' + r.code.code, kit: KIT + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + r.code.code }; + return { ok: true, code: r.code.code, credits: n, link: SHARE() + '/join/' + (acct.username || acct.code) + '?promo=' + r.code.code, kit: SHARE() + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + r.code.code }; } async function partnerStatus(email) { const mine = await R.promos.byFunder(email); const acct = await R.accounts.byEmail(email); if (!mine.length) return null; const c = mine[0]; - return { code: c.code, credits: c.credits, uses: (await R.promos.adminView()).codes.find(x => x.code === c.code)?.uses || 0, link: KIT + '/join/' + (acct.username || acct.code) + '?promo=' + c.code, kit: KIT + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + c.code }; + return { code: c.code, credits: c.credits, uses: (await R.promos.adminView()).codes.find(x => x.code === c.code)?.uses || 0, link: SHARE() + '/join/' + (acct.username || acct.code) + '?promo=' + c.code, kit: SHARE() + '/partners?ref=' + (acct.username || acct.code) + '&promo=' + c.code }; } module.exports = { init, status, generate, adminUsage, TIERS, KINDS, template, handout, split, videos, makeVideo, team, nudge, grant, partnerCode, partnerStatus };