Created
May 2, 2014 03:47
-
-
Save skorotkiewicz/d02a8b8f4afddc564ca8 to your computer and use it in GitHub Desktop.
Notification of the new linux kernel on your Android in PHP
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
<?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