Diff -- /var/www/vhosts/3dshawn.com/abforge.3dshawn.com/c.cgi
Diff

/var/www/vhosts/3dshawn.com/abforge.3dshawn.com/c.cgi

added on local at 2026-07-01 16:01:18

Added
+57
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to a9af42a03496
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# ABForge -- /c.cgi visitor event collector.
4# Accepts a JSON POST body with: k (public key), u (uid), s (sid),
5# t (event type), p (page path), and event-specific fields. Writes
6# pageviews / events / heartbeats / heatmap rows.
7#
8# CORS-open: customer sites are on arbitrary origins. Replies with
9# Access-Control-Allow-Origin: * because no credentials are passed.
10#======================================================================
11use strict;
12use warnings;
13use lib '/var/www/vhosts/3dshawn.com/abforge.3dshawn.com';
14
15# Read STDIN BEFORE loading CGI (which would consume it for form-parsing)
16my $raw = '';
17if (($ENV{REQUEST_METHOD} || '') eq 'POST') {
18 my $len = int($ENV{CONTENT_LENGTH} || 0);
19 if ($len > 0 && $len < 1_048_576) {
20 read STDIN, $raw, $len;
21 }
22}
23
24use MODS::DBConnect;
25use MODS::ABForge::Tracking;
26use JSON::PP;
27
28my $db = MODS::DBConnect->new;
29my $trk = MODS::ABForge::Tracking->new;
30my $DB = 'abforge3dshawn';
31
32print "Access-Control-Allow-Origin: *\n";
33print "Access-Control-Allow-Methods: POST, OPTIONS\n";
34print "Access-Control-Allow-Headers: Content-Type\n";
35print "Access-Control-Max-Age: 86400\n";
36print "Cache-Control: no-store\n";
37
38if (($ENV{REQUEST_METHOD} || '') eq 'OPTIONS') {
39 print "Content-Type: text/plain\n\nok";
40 exit;
41}
42
43print "Content-Type: application/json\n\n";
44my $body = eval { JSON::PP::decode_json($raw) };
45$body ||= {};
46
47my $dbh = $db->db_connect();
48unless ($dbh) {
49 print '{"ok":0,"error":"db_unavailable"}';
50 exit;
51}
52
53my $res = eval { $trk->ingest($dbh, $DB, $body) };
54$res ||= { ok => 0, error => 'ingest_failed' };
55$db->db_disconnect($dbh);
56
57print JSON::PP::encode_json($res);
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help