Created
July 15, 2012 13:19
-
-
Save e7o-de/3116889 to your computer and use it in GitHub Desktop.
notify-server
This file contains 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/php5 | |
<?php | |
set_time_limit(0); | |
pcntl_signal(SIGTERM, 'sig_handler'); | |
$sock = socket_create(AF_INET, SOCK_STREAM, 0); | |
socket_bind($sock, 'localhost', 2828) or die('Could not bind to address'); | |
socket_listen($sock); | |
while (true) { | |
$client = socket_accept($sock); | |
socket_getpeername($client, $ip); | |
$input = socket_read($client, 1024); | |
$nodisp = false; | |
if (substr($input, 0, 4) == '[nl]') { | |
if ($ip == '127.0.0.1') { | |
$nodisp = true; | |
} else { | |
$input = substr($input, 4); | |
} | |
} | |
if (!$nodisp) exec('notify-send -t 1000 -u low '.$ip.' "'.str_replace('"', '', $input).'"'); | |
echo $ip.' '.$input."\n"; | |
socket_close($client); | |
} | |
socket_close($sock); | |
function sig_handler($sig) | |
{ | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment