From 31855fdbc687f2c9b29e067cad475fbbadc8e39d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 27 Oct 2023 15:19:41 +0200 Subject: [PATCH] Support event.pl replaying JSON from stdin. --- www/event.pl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/www/event.pl b/www/event.pl index 9743520..75106df 100755 --- a/www/event.pl +++ b/www/event.pl @@ -20,14 +20,20 @@ my $dbh = DBI->connect("dbi:Pg:dbname=$config::dbname;host=127.0.0.1", $config:: or die "Could not connect to Postgres: " . DBI->errstr; my $cgi = CGI->new; -my $post = $cgi->param('POSTDATA'); -my $ts = $cgi->http('X-Slack-Request-Timestamp'); -my $sig = $cgi->http('X-Slack-Signature'); +my $post; +if ($#ARGV >= 0 && $ARGV[0] eq '--stdin') { + local $/ = undef; + $post = ; +} else { + $post = $cgi->param('POSTDATA'); + my $ts = $cgi->http('X-Slack-Request-Timestamp'); + my $sig = $cgi->http('X-Slack-Signature'); -my $digest = Digest::SHA::hmac_sha256_hex("v0:$ts:$post", $config::signing_secret); -die "Failed signature" unless ($sig eq "v0=$digest"); + my $digest = Digest::SHA::hmac_sha256_hex("v0:$ts:$post", $config::signing_secret); + die "Failed signature" unless ($sig eq "v0=$digest"); -print STDERR "JSON: $post\n"; + print STDERR "JSON: $post\n"; +} my $json = JSON::XS::decode_json($post); if (exists($json->{'challenge'})) { -- 2.39.2