Created
December 8, 2016 15:22
-
-
Save skorotkiewicz/3fb0d7e194275c25d2546586c0e8715d to your computer and use it in GitHub Desktop.
Notification of the new linux kernel on your Android in PHP
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
<?PHP | |
/* | |
how to use? very simple! | |
$ crontab -e | |
add line | |
* 7 * * * php /home/mod/notification.php>/dev/null 2>&1 | |
and save | |
now script will be run from cron every day at 7:00 am and notify you of a new kernel! | |
my blog: http://www.sebastian.korotkiewicz.eu/2013/02/02/notification-of-the-new-linux-kernel-on-your-android-in-php/ | |
:) | |
*/ | |
function notificationAndroid($apikey, $application, $event, $description, $url) { | |
$curlchanel = curl_init("https://www.notifymyandroid.com/publicapi/notify"); | |
curl_setopt($curlchanel, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/16.0.2'); | |
curl_setopt($curlchanel, CURLOPT_HEADER, 0); | |
curl_setopt($curlchanel, CURLOPT_TIMEOUT, 6); | |
curl_setopt($curlchanel, CURLOPT_RETURNTRANSFER, 0); | |
curl_setopt($curlchanel, CURLOPT_POSTFIELDS, trim("apikey=$apikey&application=$application&event=$event&description=$description&url=$url")); | |
curl_exec($curlchanel); | |
curl_close($curlchanel); | |
} | |
$curlchanel2 = curl_init("https://www.kernel.org/"); | |
curl_setopt($curlchanel2, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/16.0.2'); | |
curl_setopt($curlchanel2, CURLOPT_HEADER, 1); | |
curl_setopt($curlchanel2, CURLOPT_TIMEOUT, 6); | |
curl_setopt($curlchanel2, CURLOPT_RETURNTRANSFER, 1); | |
$strona = trim(curl_exec($curlchanel2)); | |
curl_close($curlchanel2); | |
//preg_match_all('#<a href="http://www.kernel.org/pub/linux/kernel/(.*)/linux-(.*).tar.bz2">(.*)</a>#msU', trim($strona), $ciag1); | |
preg_match_all('#<a href="./pub/linux/kernel/(.*)/(.*)">(.*)</a>#msU', trim($strona), $ciag1); | |
$linuxKernel = $ciag1[3][1]; | |
$cache = "lastVersion.cache"; | |
if (file_exists($cache)) { | |
// read | |
$fh = fopen($cache, 'r'); | |
$data = fread($fh, 10); | |
fclose($fh); | |
if ($data == $linuxKernel) { | |
// old kernel, do nothing, wait for the new kernel | |
die(); | |
} else { | |
// new kernel + notification + override cache | |
// write | |
$file = fopen($cache, 'w') or die("can't open file"); | |
fwrite($file, $linuxKernel); | |
fclose($file); | |
// notification | |
notificationAndroid("api-key", "LinuxKernel", "New Linux Kernel!", "Kernel: {$ciag1[2][0]}", "http://kernel.org/"); | |
} | |
} else { | |
// write | |
$file = fopen($cache, 'w') or die("can't open file"); | |
fwrite($file, $linuxKernel); | |
fclose($file); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment