]> git.sesse.net Git - skvidarsync/commitdiff
Support event.pl replaying JSON from stdin.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 27 Oct 2023 13:19:41 +0000 (15:19 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 27 Oct 2023 13:19:41 +0000 (15:19 +0200)
www/event.pl

index 974352034bca4bf5abc78b0df5ebd75d6bed6dd3..75106df1d5007f74ca79bfd90a262b6e9016f4f7 100755 (executable)
@@ -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 = <STDIN>;
+} 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'})) {