This repository has been archived on 2024-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
bboschecker/bboschecker.php
2024-03-20 09:29:18 -05:00

286 lines
8.6 KiB
PHP

<?php
/*
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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;
// the common download entry point (saves on useless parsing)
$RIM_DLURL = "https://www.blackberry.com/Downloads/browseSoftware.do";
// the user agent we'll masquerade as
$SCRIPT_UA = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
// where to store the session cookiejar
$SCRIPT_CJ = "/tmp/bbos_cookies";
// default verbosity, can be changed by user
$VERBOSE = false;
?>
<html>
<head>
<title>BlackBerry Device OS Checker</title>
</head>
<body>
<h3>BlackBerry Device OS Checker</h3>
<?php
// we need to set this globally and pass it around so that the session
// and cookie jar work as a cohesive unit
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_USERAGENT, $SCRIPT_UA);
curl_setopt($curl_handle, CURLOPT_HEADER, FALSE);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
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)) {
return "";
} else {
curl_setopt($curl_handle, CURLOPT_URL, $url);
if ($method == "POST") {
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $postfields);
} else {
curl_setopt($curl_handle, CURLOPT_POST, FALSE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "");
}
$output = "";
$output = @curl_exec($curl_handle);
if (curl_errno($curl_handle)) {
print curl_error($curl_handle);
return "";
}
if (!is_string($output) || !strlen($output)) {
echo "Failure Contacting Server";
return "";
}
return $output;
}
}
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;
}
// 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();
chatty("\n<br>&nbsp;&nbsp;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();
$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&nbsp;&nbsp;<b>Adding:</b> " . $match[3] .
" (Network: " . $rimNetwork . ", Region: " .
$rimRegion . ")<br>\n");
$link_array[$match[2]] = $match[3];
} // foreach link
} // rexexp match
} else {
chatty("\n&nbsp;&nbsp;<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();
// 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 "&nbsp;&nbsp;" . $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";
flush();
$rim_page = getPage($link);
$rim_array = explode("\n", $rim_page);
$got_v = 0;
$got_c = 0;
$value = "";
$code = "";
foreach ($rim_array as $line) {
// get the value
if (stristr($line, $rimDevice)) {
$regexp = "<option\svalue=\"([^\"]*)\">(.*)<\/option>";
if (preg_match("/$regexp/siU", $line, $match)) {
$got_v = 1;
$value = $match[1];
}
}
// get the code
if (stristr($line, "type=\"hidden\" name=\"code\"")) {
$regexp = "value=\"([^\"]*)\"(.*)";
if (preg_match("/$regexp/siU", $line, $match)) {
$got_c = 1;
$code = $match[1];
}
}
}
if ($got_v && $got_c) {
chatty("&nbsp;&nbsp;Found one, retrieving product page...<br>\n");
$postvars = "productName=$value&code=$code";
$os_url = $RIM_DLURL . ", POST, " . $postvars;
chatty("&nbsp;&nbsp;URL Data: ".$os_url."<br>\n");
$os_page = getPage($RIM_DLURL, "POST", $postvars);
$os_array = explode("\n", $os_page);
foreach ($os_array as $osline) {
if (stristr($osline, "Applications:")) {
$result = preg_replace("/<(.*)>/siU", "", $osline);
echo "&nbsp;&nbsp;&nbsp;&nbsp;<b>$result</b><br>\n";
}
}
}
sleep($RIM_SLEEP);
}
echo "<br><b>All done!</b><br>\n";
} else {
?>
<form name="deviceselect" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<b>Device:</b>&nbsp;
<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
} // BB_DEVICE
curl_close($curl_handle);
?>
<br>
Code: <a href="https://gitlab.com/troyengel/bboschecker">bboschecker on github</a><br>
Released under the <a href="http://www.gnu.org/licenses/gpl-2.0.txt">GPLv2 license</a><br>
</body>
</html>