commit - /dev/null
commit + 487d86c7c6163a88c2068e285697afde35b378a7
blob - /dev/null
blob + c2826956e241b5d1f6d26591012727acf5dc7362 (mode 644)
--- /dev/null
+++ pushover.conf-example
+token = TOKENTOKEN
+user = USERUSER
blob - /dev/null
blob + aed21894daa0a6e7d5924c315c2eb44542b26ed4 (mode 755)
--- /dev/null
+++ pushover.pl
+#!/usr/bin/env perl
+#
+# Copyright (c) 2020-2022 Mischa Peters <mischa @ openbsd.amsterdam>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+use 5.024;
+use strict;
+use warnings;
+use autodie;
+use Getopt::Long;
+use Config::Tiny;
+use HTTP::Tiny;
+use JSON::PP;
+
+GetOptions(
+ "message=s" => \(my $MESSAGE),
+ "title=s" => \(my $TITLE = "OpenBSD Ansterdam"),
+ "priority=i" => \(my $PRIORITY = 0),
+);
+
+my $USAGE = <<"END_USAGE";
+Usage: $0 [-m message] [-t title] [-p priority]
+Options:
+-m | --message text
+-t | --title text (default: Notification)
+-p | --priority [0|1] (default: 0)
+END_USAGE
+
+$MESSAGE || die($USAGE);
+my @config_files = grep { -e } ('./_pushover.conf', './.pushover.conf', './pushover.conf', "$ENV{'HOME'}/_pushover.conf", "$ENV{'HOME'}/.pushover.conf", "$ENV{'HOME'}/pushover.conf");
+my $config = Config::Tiny->read($config_files[-1], 'utf8');
+my $TOKEN = $config->{_}{token} || die("$USAGE\nError: TOKEN not found.\n");
+my $USER = $config->{_}{user} || die("$USAGE\nError: USER not found.\n");
+
+my $http = HTTP::Tiny->new;
+my %HEADERS = ("Content-Type" => "application/json");
+my $uri = "https://api.pushover.net/1/messages.json";
+my $request = HTTP::Tiny->new('default_headers' => \%HEADERS);
+my $body = JSON::PP->new->encode({token => "$TOKEN", user => "$USER", title => "$TITLE", message => "$MESSAGE", priority => "$PRIORITY"});
+my $response = $request->post($uri, {'content' => $body});
+print "Pushover: $response->{'status'} $response->{'reason'}\n";