Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$config=array(
"tag"=>"15811375356",
"imei"=>"666", //server does not seem to check this
"sim"=>"666",
"operator"=>"666",
"login_url"=>"http://xxx/fota/download/login.php",
"check_url"=>"http://xxx/fota/download/checkversion.php",
"down_url"=>"http://xxx/fota/download/download.php",
"curversion"=>'xxx', //get this using fiddler or any http sniffer
);
$fields_string="";
$fields=array("imei"=>$config["imei"],"sn"=>$config["tag"],"sim"=>$config["sim"],"operator"=>$config["operator"]);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch=curl_init();
//step 1. login
curl_setopt($ch,CURLOPT_URL,$config["login_url"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$body = str_replace("\r\n", "\n", $body);
$body = str_replace("\r", "\n", $body);
$body = str_replace("\n", "\\n", $body);
$loginbody=json_decode($body);
if($loginbody===null||$loginbody===false)
die("login return is not json\n");
echo "logged in, rand=".$loginbody->rand.", sid=".$loginbody->sessionId."\n";
//step 2. checkversion
curl_setopt($ch,CURLOPT_URL,$config["check_url"]);
$fields=array("version"=>$config["curversion"],"token"=>md5($config["tag"].$loginbody->rand));
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$body = str_replace("\r\n", "\n", $body);
$body = str_replace("\r", "\n", $body);
$body = str_replace("\n", "\\n", $body);
$checkbody=json_decode($body);
if($checkbody===null||$checkbody===false)
die("checkversion return is not json: '$body'\n");
if(property_exists($checkbody,"deltaId")) {
echo "got firmware update, delta id ".$checkbody->deltaId." (name=".$checkbody->name.", size=".$checkbody->size.")\n";
} else {
echo "No firmware update available";
exit;
}
//step 3. download
curl_setopt($ch,CURLOPT_URL,$config["down_url"]);
$fields=array("deltaId"=>$checkbody->deltaId,"token"=>md5($config["tag"].$loginbody->rand));
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$fp=fopen("update-".$checkbody->deltaId.".zip","w");
curl_setopt($ch, CURLOPT_FILE, $fp);
$response = curl_exec($ch);
fclose($fp);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.