Initial commit

This commit is contained in:
mischa 2022-07-19 11:41:54 +02:00
commit 487d86c7c6
2 changed files with 54 additions and 0 deletions

2
pushover.conf-example Normal file
View File

@ -0,0 +1,2 @@
token = TOKENTOKEN
user = USERUSER

52
pushover.pl Executable file
View File

@ -0,0 +1,52 @@
#!/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";