added on local at 2026-07-01 15:02:46
| 1 | #!/usr/bin/perl | |
| 2 | #====================================================================== | |
| 3 | # ContactForge -- /h.cgi heatmap ingest (clicks + scroll depth). | |
| 4 | # Same STDIN-first rule as c.cgi. Routes by payload {t} to | |
| 5 | # record_heatmap_click or record_heatmap_scroll. | |
| 6 | #====================================================================== | |
| 7 | use strict; | |
| 8 | use warnings; | |
| 9 | use lib '/var/www/vhosts/3dshawn.com/crm.3dshawn.com'; | |
| 10 | ||
| 11 | my $raw = ''; | |
| 12 | if (($ENV{REQUEST_METHOD} || '') eq 'POST') { | |
| 13 | my $len = int($ENV{CONTENT_LENGTH} || 0); | |
| 14 | if ($len > 0 && $len < 1_048_576) { | |
| 15 | read STDIN, $raw, $len; | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | use CGI; | |
| 20 | use MODS::DBConnect; | |
| 21 | use MODS::ContactForge::Config; | |
| 22 | use MODS::ContactForge::Tracking; | |
| 23 | use JSON::PP; | |
| 24 | ||
| 25 | my $cfg = MODS::ContactForge::Config->new; | |
| 26 | my $db = MODS::DBConnect->new; | |
| 27 | my $trk = MODS::ContactForge::Tracking->new; | |
| 28 | my $DB = $cfg->settings('database_name'); | |
| 29 | ||
| 30 | print "Access-Control-Allow-Origin: *\n"; | |
| 31 | print "Access-Control-Allow-Methods: POST, OPTIONS\n"; | |
| 32 | print "Access-Control-Allow-Headers: Content-Type\n"; | |
| 33 | print "Cache-Control: no-store\n"; | |
| 34 | ||
| 35 | if (($ENV{REQUEST_METHOD} || '') eq 'OPTIONS') { | |
| 36 | print "Content-Type: text/plain\n\nok"; exit; | |
| 37 | } | |
| 38 | print "Content-Type: application/json\n\n"; | |
| 39 | ||
| 40 | my $body = eval { JSON::PP::decode_json($raw) } || {}; | |
| 41 | # Default to click row if the caller didn't tag it. | |
| 42 | $body->{t} ||= 'hm'; | |
| 43 | ||
| 44 | my $dbh = $db->db_connect(); | |
| 45 | unless ($dbh) { print '{"ok":0}'; exit; } | |
| 46 | ||
| 47 | $body->{ip} = $ENV{HTTP_X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} || ''; | |
| 48 | $body->{user_agent} = $ENV{HTTP_USER_AGENT} || ''; | |
| 49 | ||
| 50 | eval { $trk->ingest_heatmap($db, $dbh, $DB, $body) }; | |
| 51 | $db->db_disconnect($dbh); | |
| 52 | print '{"ok":1}'; |