Forked from eyecatchup/watchAndroid44Nexus5.cronjob.php
Created
October 17, 2013 02:10
-
-
Save thomasbabuj/7018213 to your computer and use it in GitHub Desktop.
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 | |
ini_set('may_execution_time', 600); | |
if (!ini_get('date.timezone') && function_exists('date_default_timezone_set')) { | |
date_default_timezone_set('UTC'); // You may change this (eg 'Europe/Berlin'). | |
} | |
/** | |
* Android 4.4 Kitkat / Nexus 5 email alert cronjob script. | |
* | |
* 1. Download this script. | |
* Browser download: https://gist.github.com/eyecatchup/7017108/download/ | |
* Or, for the console users, one of: | |
* # wget --no-check-certificate https://gist.github.com/eyecatchup/7017108/raw/ /path/android.cron.php | |
* # wget --no-check-certificate https://gist.github.com/eyecatchup/7017108/raw/watchAndroid44Nexus5.cronjob.php | |
* | |
* 2. Set the value for the variable $notifyEmailAddress to your email address. | |
* | |
* 3. Create a new cronjob (for a Windows Xampp stack alternative see: http://stackoverflow.com/a/4231634/624466). | |
* On your console, type: | |
* # crontab -e | |
* | |
* 4. Paste the following (adjust script/logfile path): | |
* 0 * * * * php /absolute/path/to/script.php >> /absolute/path/to/cronjob.log | |
* | |
* Exit crontab and you'Re done. You'll get an email as soon as there's something to checkout. | |
*/ | |
/** | |
* CHANGE THIS TO YOUR EMAIL ADDRESS !!! | |
*/ | |
$notifyEmailAddress = '[email protected]'; | |
/** | |
* NO NEED FOR CHANGES BELOW | |
*/ | |
$urls = array( | |
//check potential product URLs | |
'check404' => array( | |
'www.google.com/nexus/5/', | |
'www.android.com/devices/detail/nexus-5', | |
'www.android.com/devices/images/device/nexus-5/large/0', | |
'www.android.com/about/kitkat/', | |
'developer.android.com/about/versions/android-4.4.html', | |
'developer.android.com/sdk/api_diff/19/changes/changes-summary.html', | |
'android.googlesource.com/device/lge/hammerhead/', | |
'static.googleusercontent.com/external_content/untrusted_dlcp/source.android.com/en//compatibility/android-4.4-cdd.pdf', | |
), | |
//check for string "Nexus 5" (case-insensitive) | |
'checkStringNexus5' => array( | |
'www.android.com/about/', | |
'www.android.com/whatsnew/', | |
'play.google.com/store/devices', | |
'developers.google.com/android/nexus/images', | |
'developers.google.com/android/nexus/drivers', | |
'source.android.com/source/build-numbers.html', | |
'source.android.com/source/building-devices.html', | |
'source.android.com/source/building-kernels.html', | |
), | |
//check for string "Hammerhead" (case-insensitive) | |
'checkStringHammerhead' => array( | |
'developers.google.com/android/nexus/images', | |
'developers.google.com/android/nexus/drivers', | |
'source.android.com/source/building-devices.html', | |
'source.android.com/source/building-kernels.html', | |
'android.googlesource.com/device/ti/hammerhead', | |
), | |
//check for string "4.4" | |
'checkStringAndroid44' => array( | |
'www.android.com/whatsnew/', | |
'www.android.com/about/', | |
'source.android.com/', | |
'developers.google.com/android/nexus/images', | |
'developers.google.com/android/nexus/drivers', | |
'source.android.com/source/build-numbers.html', | |
'source.android.com/compatibility/downloads.html', | |
) | |
); | |
class N5 | |
{ | |
const UA = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36'; | |
public static function matchNexus5($url) { | |
$str = self::getHttpResponse($url); | |
return !$str ? false : (bool)preg_match('/nexus 5/iu', trim($str)); | |
} | |
public static function matchHammerhead($url) { | |
$str = self::getHttpResponse($url); | |
return !$str ? false : (bool)preg_match('/hammerhead/iu', trim($str)); | |
} | |
public static function matchAndroid44($url) { | |
$str = self::getHttpResponse($url); | |
return !$str ? false : (bool)preg_match('/4\.4/iu', trim($str)); | |
} | |
public static function getHttpCode($url) { | |
$ch = curl_init($url); | |
curl_setopt_array($ch, array( | |
CURLOPT_USERAGENT => N5::UA, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_CONNECTTIMEOUT => 15, | |
CURLOPT_FOLLOWLOCATION => 1, | |
CURLOPT_MAXREDIRS => 3, | |
CURLOPT_SSL_VERIFYPEER => 0, | |
CURLOPT_NOBODY => 1, | |
)); | |
curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
return (int)$httpCode; | |
} | |
public static function getHttpResponse($url) { | |
$ch = curl_init($url); | |
curl_setopt_array($ch, array( | |
CURLOPT_USERAGENT => N5::UA, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_CONNECTTIMEOUT => 30, | |
CURLOPT_FOLLOWLOCATION => 1, | |
CURLOPT_MAXREDIRS => 3, | |
CURLOPT_SSL_VERIFYPEER => 0, | |
)); | |
$response = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
return 200 == (int)$httpCode ? $response : false; | |
} | |
} | |
$found = array(); | |
$https = 'https://'; | |
//check potential product URLs | |
foreach ($urls['check404'] as $url) { | |
(200 == N5::getHttpCode($https . $url)) && array_push($found, | |
$url . ' (product URL)'); | |
} | |
//check for string "Nexus 5" (case-insensitive) | |
foreach ($urls['checkStringNexus5'] as $url) { | |
(false !== N5::matchNexus5($https . $url)) && array_push($found, | |
$url . ' (contains string "Nexus 5")'); | |
} | |
//check for string "Hammerhead" (case-insensitive) | |
foreach ($urls['checkStringHammerhead'] as $url) { | |
(false !== N5::matchHammerhead($https . $url)) && array_push($found, | |
$url . ' (contains string "Hammerhead")'); | |
} | |
//check for string "4.4" | |
foreach ($urls['checkStringAndroid44'] as $url) { | |
(false !== N5::matchAndroid44($https . $url)) && array_push($found, | |
$url . ' (contains string "4.4")'); | |
} | |
if (0 < sizeof($found)) { | |
$msg = 'Strike! Check the following URL(s):' . PHP_EOL; | |
foreach ($found as $url) { | |
$msg .= $https . $url . PHP_EOL; | |
} | |
mail($notifyEmailAddress, 'Android 4.4 Kitkat / Nexus 5 Alert', $msg); | |
print trim($msg); | |
} | |
else { | |
printf('[%s]: Nothing found.' . PHP_EOL, date('Y/m/d H:i')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment