bboschecker 0.2
This commit is contained in:
parent
aca861840a
commit
1bcaaf7f18
5 changed files with 579 additions and 33 deletions
158
bboschecker.php
158
bboschecker.php
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/*
|
||||
bboschecker 0.1 - check for new BB device OS releases
|
||||
Copyright (C) 2007 troyengel
|
||||
bboschecker 0.2 - check for new BB device OS releases
|
||||
Copyright (C) 2008 troyengel
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -16,9 +16,19 @@
|
|||
http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*/
|
||||
|
||||
// This class right here is worth it's weight in gold - give the author
|
||||
// some kudos. See the debug script for basic usage.
|
||||
//
|
||||
// http://jacksleight.com/blog/2008/01/14/really-shiny/scripts/table-extractor.txt
|
||||
include 'tableExtractor.class.php';
|
||||
|
||||
// where is the list of carriers?
|
||||
$BBF_LIST = "http://blackberryfaq.com/index.php/BlackBerry_Operating_System_Downloads";
|
||||
|
||||
// what text immediately preceeds our target table? (not IN the table!)
|
||||
// hopefully nobody changes this, but hey - it's the interweb tubes
|
||||
$BBF_ANCHOR = 'desktop and device software download page';
|
||||
|
||||
// we will delay this many seconds when retrieving pages from the
|
||||
// RIM server, we don't want to be a bad netizen.
|
||||
$RIM_SLEEP = 1;
|
||||
|
|
@ -31,6 +41,9 @@
|
|||
|
||||
// where to store the session cookiejar
|
||||
$SCRIPT_CJ = "/tmp/bbos_cookies";
|
||||
|
||||
// default verbosity, can be changed by user
|
||||
$VERBOSE = false;
|
||||
?>
|
||||
|
||||
<html>
|
||||
|
|
@ -54,6 +67,14 @@ curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
|
|||
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $SCRIPT_CJ);
|
||||
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $SCRIPT_CJ);
|
||||
|
||||
function chatty($text) {
|
||||
global $VERBOSE;
|
||||
if ($VERBOSE) {
|
||||
echo $text;
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
function getPage($url, $method="GET", $postfields="") {
|
||||
global $curl_handle;
|
||||
if (!is_string($url)) {
|
||||
|
|
@ -85,40 +106,84 @@ function getPage($url, $method="GET", $postfields="") {
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['device']) && is_numeric($_REQUEST['device'])) {
|
||||
if (isset($_REQUEST['BB_DEVICE']) && is_numeric($_REQUEST['BB_DEVICE'])) {
|
||||
|
||||
global $VERBOSE;
|
||||
$rimDevice = $_REQUEST['BB_DEVICE'];
|
||||
$rimNetwork = $_REQUEST['BB_NETWORK'];
|
||||
$rimRegion = $_REQUEST['BB_REGION'];
|
||||
if (isset($_REQUEST['BB_VERBOSE']) && $_REQUEST['BB_VERBOSE']) {
|
||||
$VERBOSE = true;
|
||||
}
|
||||
|
||||
$device = $_REQUEST['device'];
|
||||
// IE hack - it buffers and won't display unless 256b
|
||||
print(str_repeat(" ", 300) . "\n");
|
||||
|
||||
echo "Searching for BlackBerry OS releases for:<br>\n".
|
||||
"Device: <b>$rimDevice</b><br>\n".
|
||||
"Network: <b>$rimNetwork</b><br>\n".
|
||||
"Region: <b>$rimRegion</b><br>\n".
|
||||
"<br>\n";
|
||||
flush();
|
||||
|
||||
echo "Downloading carrier list from BlackBerryFAQ... ";
|
||||
flush();
|
||||
$carriers = getPage($BBF_LIST);
|
||||
echo "<b>done</b>.<br>\n";
|
||||
chatty("\n<br> URL:".$BBF_LIST."<br>\n");
|
||||
$tx = new tableExtractor;
|
||||
$tx->source = file_get_contents($BBF_LIST);
|
||||
$tx->anchor = $BBF_ANCHOR;
|
||||
$tx->anchorWithin = false;
|
||||
$carrierArray = $tx->extractTable();
|
||||
echo "<b>done</b>.<br><br>\n";
|
||||
flush();
|
||||
|
||||
echo "Parsing carrier list for links... ";
|
||||
flush();
|
||||
chatty("<br>\n");
|
||||
reset($carrierArray);
|
||||
$link_array = array();
|
||||
$cnt_array = explode("\n", $carriers);
|
||||
foreach ($cnt_array as $line) {
|
||||
if (stristr($line, "www.blackberry.com")) {
|
||||
// http://www.the-art-of-web.com/php/parse-links/
|
||||
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
|
||||
if (preg_match_all("/$regexp/siU", $line, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
# $match[2] = link address
|
||||
# $match[3] = link text
|
||||
$link_array[$match[2]] = $match[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$reject_array = array();
|
||||
foreach($carrierArray as $carrier) {
|
||||
if (($carrier['Network'] == $rimNetwork) ||
|
||||
($rimNetwork == "All")) {
|
||||
if (($carrier['Region'] == $rimRegion) ||
|
||||
($rimRegion == "All")) {
|
||||
if (stristr($carrier['Carrier'], "www.blackberry.com")) {
|
||||
// http://www.the-art-of-web.com/php/parse-links/
|
||||
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
|
||||
if (preg_match_all("/$regexp/siU", $carrier['Carrier'], $matches,
|
||||
PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
# $match[2] = link address
|
||||
# $match[3] = link text
|
||||
chatty("\n <b>Adding:</b> " . $match[3] .
|
||||
" (Network: " . $rimNetwork . ", Region: " .
|
||||
$rimRegion . ")<br>\n");
|
||||
$link_array[$match[2]] = $match[3];
|
||||
} // foreach link
|
||||
} // rexexp match
|
||||
} else {
|
||||
chatty("\n <b>Rejecting:</b> " . $carrier['Carrier'] .
|
||||
" (not hosted on RIM server)<br>\n");
|
||||
$reject_array[] = $carrier['Carrier'];
|
||||
} // blackberry.com match
|
||||
} // region match
|
||||
} // network match
|
||||
} // foreach carrier
|
||||
echo "<b>done</b>.<br><br>\n";
|
||||
flush();
|
||||
|
||||
echo "Searching for OS releases for the BlackBerry <b>$device</b><br><br>\n";
|
||||
flush();
|
||||
// output the list of sites to check by hand
|
||||
if (count($reject_array) > 0) {
|
||||
echo "These downloads are not hosted by RIM, check manually:<br>\n";
|
||||
flush();
|
||||
reset($reject_array);
|
||||
foreach($reject_array as $reject) {
|
||||
echo " " . $reject . "<br>\n";
|
||||
}
|
||||
echo "<br>\n";
|
||||
}
|
||||
|
||||
reset($link_array);
|
||||
while (list($link, $title) = each($link_array)) {
|
||||
echo "Checking <a href=\"$link\"><b>$title</b></a>...<br>\n";
|
||||
|
|
@ -131,7 +196,7 @@ if (isset($_REQUEST['device']) && is_numeric($_REQUEST['device'])) {
|
|||
$code = "";
|
||||
foreach ($rim_array as $line) {
|
||||
// get the value
|
||||
if (stristr($line, $device)) {
|
||||
if (stristr($line, $rimDevice)) {
|
||||
$regexp = "<option\svalue=\"([^\"]*)\">(.*)<\/option>";
|
||||
if (preg_match("/$regexp/siU", $line, $match)) {
|
||||
$got_v = 1;
|
||||
|
|
@ -148,9 +213,10 @@ if (isset($_REQUEST['device']) && is_numeric($_REQUEST['device'])) {
|
|||
}
|
||||
}
|
||||
if ($got_v && $got_c) {
|
||||
echo " Found one, retrieving product page...<br>\n";
|
||||
flush();
|
||||
chatty(" Found one, retrieving product page...<br>\n");
|
||||
$postvars = "productName=$value&code=$code";
|
||||
$os_url = $RIM_DLURL . ", POST, " . $postvars;
|
||||
chatty(" URL Data: ".$os_url."<br>\n");
|
||||
$os_page = getPage($RIM_DLURL, "POST", $postvars);
|
||||
$os_array = explode("\n", $os_page);
|
||||
foreach ($os_array as $osline) {
|
||||
|
|
@ -168,19 +234,47 @@ if (isset($_REQUEST['device']) && is_numeric($_REQUEST['device'])) {
|
|||
} else {
|
||||
?>
|
||||
|
||||
Enter the model number ONLY of the device.<br>
|
||||
(7290, 8100, 8320, 8800, etc.)<br>
|
||||
<form name="deviceselect" method="GET" action="<?php $_PHP_SELF; ?>">
|
||||
<br>
|
||||
<input type="text" size="10" name="device">
|
||||
<input type="submit" value="Search Carriers">
|
||||
<form name="deviceselect" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
|
||||
<b>Device:</b>
|
||||
<input type="text" size="15" name="BB_DEVICE">
|
||||
<br>
|
||||
Enter the model number ONLY of the device.<br>
|
||||
(7290, 8100, 8320, 8703, 8800, etc.)
|
||||
<br><br>
|
||||
<b>Verbose Output:</b>
|
||||
<input type="checkbox" name="BB_VERBOSE" value="true">
|
||||
<br><br>
|
||||
<b>Network:</b>
|
||||
<br>
|
||||
<select name="BB_NETWORK">
|
||||
<option>All</option>
|
||||
<option>CDMA</option>
|
||||
<option>GSM</option>
|
||||
<option>iDEN</option>
|
||||
<option>Mobitex</option>
|
||||
</select>
|
||||
<br><br>
|
||||
<b>Region:</b>
|
||||
<br>
|
||||
<select name="BB_REGION">
|
||||
<option>All</option>
|
||||
<option>Africa</option>
|
||||
<option>Asia Pacific</option>
|
||||
<option>Europe</option>
|
||||
<option>Latin America / South America</option>
|
||||
<option>Middle East</option>
|
||||
<option>North America</option>
|
||||
</select>
|
||||
<br><br>
|
||||
<input type="submit" value="Search Carriers">
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<b>Note</b>: This tool will only search carriers who<br>
|
||||
host their downloads on www.blackberry.com<br>
|
||||
|
||||
<?php
|
||||
} // device
|
||||
} // BB_DEVICE
|
||||
curl_close($curl_handle);
|
||||
?>
|
||||
|
||||
|
|
|
|||
Reference in a new issue