Last active
August 29, 2015 14:13
-
-
Save mamemomonga/5af486c07873802a8e33 to your computer and use it in GitHub Desktop.
prowlで現在のwlan0のIPアドレスを通知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use utf8; | |
use strict; | |
use warnings; | |
use URI::Escape; | |
binmode(STDOUT,':utf8'); | |
my %cnf=( | |
name => 'prowl_notify_wifi_addr', | |
curl => '/usr/bin/curl', | |
application => 'Edison', | |
event => 'wlan0がUPしました', | |
dev => 'wlan0', | |
apikey => '' | |
); | |
if(my $kid=fork) { | |
print "$cnf{name} start PID:$kid\n"; | |
} else { | |
open(STDIN, '<','/dev/null') || die $!; | |
open(STDOUT,'| logger -t '.$cnf{name}) || die $!; | |
open(STDERR,'| logger -t '.$cnf{name}) || die $!; | |
print "START $cnf{name}\n"; | |
# 時計が合うのを待つ | |
# 時計が合っていないとSSL証明書が機能せずエラーになる | |
while(1) { | |
last if( time > 1420038000 ); # 2015/1/1 00:00:00 | |
sleep(1); | |
} | |
# IPアドレス取得 | |
my $ipaddr; | |
if(`ip addr show $cnf{dev}` =~/inet ([0-9.\/]+) brd/m) { $ipaddr=$1 } | |
exit unless $ipaddr; | |
# prowl通知 | |
$cnf{event}.="($ARGV[0])" if $ARGV[0]; | |
$cnf{description}="ADDR: $ipaddr"; | |
while(my($key,$val)=each %cnf) { | |
next if $key eq 'apikey'; | |
print 'prowl: '.uc($key).": $val\n"; | |
} | |
# 必須: apikey, application, event, description, curl | |
my @queries; | |
foreach(qw(apikey application event description priority url providerkey)) { | |
push @queries,"$_=".uri_escape_utf8($cnf{$_}) if $cnf{$_}; | |
} | |
my $url="https://prowlapp.com/publicapi/add?".join('&',@queries); | |
exec($cnf{curl},$url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment