2017-09-22 21:24:31 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2019-02-08 17:20:28 +01:00
|
|
|
Copyright 2019 UUP dump API authors
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-29 23:40:56 +02:00
|
|
|
require_once dirname(__FILE__).'/shared/main.php';
|
|
|
|
require_once dirname(__FILE__).'/shared/requests.php';
|
2017-09-30 16:38:26 +02:00
|
|
|
require_once dirname(__FILE__).'/listid.php';
|
2017-09-23 17:47:19 +02:00
|
|
|
|
2018-11-16 17:59:48 +01:00
|
|
|
function uupFetchUpd(
|
|
|
|
$arch = 'amd64',
|
|
|
|
$ring = 'WIF',
|
|
|
|
$flight = 'Active',
|
|
|
|
$build = 'latest',
|
|
|
|
$minor = '0',
|
|
|
|
$sku = '48',
|
|
|
|
$cacheRequests = 0
|
|
|
|
) {
|
2017-09-23 17:47:19 +02:00
|
|
|
uupApiPrintBrand();
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
$arch = strtolower($arch);
|
|
|
|
$ring = strtoupper($ring);
|
|
|
|
$flight = ucwords(strtolower($flight));
|
|
|
|
if($flight == 'Current') $flight = 'Active';
|
|
|
|
|
2018-06-14 19:40:51 +02:00
|
|
|
if($build == 'latest' || (!$build)) {
|
|
|
|
$builds = array('17134.1');
|
|
|
|
|
|
|
|
$ids = uupListIds();
|
|
|
|
if(isset($ids['error'])) {
|
|
|
|
$ids['builds'] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $ids['builds'];
|
|
|
|
foreach($ids as $val) {
|
|
|
|
$builds[] = $val['build'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$builds = array_unique($builds);
|
|
|
|
rsort($builds);
|
|
|
|
|
|
|
|
$build = $builds[0];
|
|
|
|
unset($builds, $ids);
|
|
|
|
}
|
|
|
|
|
2017-11-03 19:33:17 +01:00
|
|
|
$build = explode('.', $build);
|
|
|
|
if(isset($build[1])) $minor = intval($build[1]);
|
|
|
|
$build = intval($build[0]);
|
2018-04-29 21:33:19 +02:00
|
|
|
$sku = intval($sku);
|
2017-11-03 19:33:17 +01:00
|
|
|
|
2019-01-31 20:28:32 +01:00
|
|
|
if(!($arch == 'amd64' || $arch == 'x86' || $arch == 'arm64' || $arch == 'arm')) {
|
2017-09-22 21:24:31 +02:00
|
|
|
return array('error' => 'UNKNOWN_ARCH');
|
|
|
|
}
|
|
|
|
|
2018-12-13 21:19:51 +01:00
|
|
|
if(!($ring == 'WIF' || $ring == 'WIS' || $ring == 'RP' || $ring == 'RETAIL' || $ring == 'MSIT')) {
|
2017-09-22 21:24:31 +02:00
|
|
|
return array('error' => 'UNKNOWN_RING');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!($flight == 'Skip' || $flight == 'Active')) {
|
|
|
|
return array('error' => 'UNKNOWN_FLIGHT');
|
|
|
|
}
|
|
|
|
|
|
|
|
if($flight == 'Skip' && $ring != 'WIF') {
|
|
|
|
return array('error' => 'UNKNOWN_COMBINATION');
|
|
|
|
}
|
|
|
|
|
2019-01-25 20:29:53 +01:00
|
|
|
if($build < 9841 || $build > PHP_INT_MAX-1) {
|
2017-09-22 21:24:31 +02:00
|
|
|
return array('error' => 'ILLEGAL_BUILD');
|
|
|
|
}
|
|
|
|
|
2019-01-25 20:29:53 +01:00
|
|
|
if($minor < 0 || $minor > PHP_INT_MAX-1) {
|
2017-10-13 22:55:46 +02:00
|
|
|
return array('error' => 'ILLEGAL_MINOR');
|
|
|
|
}
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
if($flight == 'Active' && $ring == 'RP') $flight = 'Current';
|
|
|
|
|
2017-10-13 22:55:46 +02:00
|
|
|
$build = '10.0.'.$build.'.'.$minor;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2019-02-08 17:20:28 +01:00
|
|
|
$cacheHash = hash('sha256', strtolower("api-fetch-$arch-$ring-$flight-$build-$minor-$sku"));
|
2018-11-16 17:59:48 +01:00
|
|
|
$cached = 0;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2018-11-16 17:59:48 +01:00
|
|
|
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) {
|
|
|
|
$cache = @gzdecode(@file_get_contents('cache/'.$cacheHash.'.json.gz'));
|
|
|
|
$cache = json_decode($cache, 1);
|
|
|
|
|
|
|
|
if(!empty($cache['content']) && ($cache['expires'] > time())) {
|
|
|
|
consoleLogger('Using cached response...');
|
|
|
|
$out = $cache['content'];
|
|
|
|
$cached = 1;
|
|
|
|
} else {
|
|
|
|
$cached = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$cached) {
|
|
|
|
consoleLogger('Fetching information from the server...');
|
|
|
|
$postData = composeFetchUpdRequest(uupDevice(), uupEncryptedData(), $arch, $flight, $ring, $build, $sku);
|
|
|
|
$out = sendWuPostRequest('https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx', $postData);
|
|
|
|
|
|
|
|
$out = html_entity_decode($out);
|
|
|
|
consoleLogger('Information has been successfully fetched.');
|
|
|
|
|
|
|
|
if($cacheRequests == 1) {
|
|
|
|
$cache = array(
|
|
|
|
'expires' => time()+90,
|
|
|
|
'content' => $out,
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!file_exists('cache')) mkdir('cache');
|
|
|
|
@file_put_contents('cache/'.$cacheHash.'.json.gz', gzencode(json_encode($cache)."\n"));
|
|
|
|
|
|
|
|
unset($cache);
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2017-10-13 22:55:46 +02:00
|
|
|
preg_match_all('/<UpdateInfo>.*?<\/UpdateInfo>/', $out, $updateInfos);
|
|
|
|
$updateInfo = preg_grep('/<Action>Install<\/Action>/', $updateInfos[0]);
|
|
|
|
sort($updateInfo);
|
|
|
|
|
2018-04-11 18:01:27 +02:00
|
|
|
if(empty($updateInfo)) {
|
2017-10-13 22:55:46 +02:00
|
|
|
consoleLogger('An error has occurred');
|
|
|
|
return array('error' => 'NO_UPDATE_FOUND');
|
|
|
|
}
|
|
|
|
|
2018-04-11 18:01:27 +02:00
|
|
|
$errorCount = 0;
|
|
|
|
$updatesNum = count($updateInfo);
|
|
|
|
$num = 0;
|
|
|
|
$updateArray = array();
|
|
|
|
|
|
|
|
foreach($updateInfo as $val) {
|
|
|
|
$num++;
|
|
|
|
consoleLogger("Checking build information for update {$num} of {$updatesNum}...");
|
|
|
|
|
2018-04-29 21:33:19 +02:00
|
|
|
$info = parseFetchUpdate($val, $out, $arch, $ring, $flight, $build, $sku);
|
2018-04-11 18:01:27 +02:00
|
|
|
if(isset($info['error'])) {
|
|
|
|
$errorCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$updateArray[] = $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($errorCount == $updatesNum) {
|
|
|
|
return array('error' => 'EMPTY_FILELIST');
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'apiVersion' => uupApiVersion(),
|
|
|
|
'updateId' => $updateArray[0]['updateId'],
|
|
|
|
'updateTitle' => $updateArray[0]['updateTitle'],
|
|
|
|
'foundBuild' => $updateArray[0]['foundBuild'],
|
|
|
|
'arch' => $updateArray[0]['arch'],
|
|
|
|
'fileWrite' => $updateArray[0]['foundBuild'],
|
|
|
|
'updateArray' => $updateArray,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-29 21:33:19 +02:00
|
|
|
function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku = '48') {
|
2018-04-11 18:01:27 +02:00
|
|
|
$updateNumId = preg_replace('/<UpdateInfo><ID>|<\/ID>.*/i', '', $updateInfo);
|
2017-10-13 22:55:46 +02:00
|
|
|
|
|
|
|
$updates = preg_replace('/<Update>/', "\n<Update>", $out);
|
|
|
|
preg_match_all('/<Update>.*<\/Update>/', $updates, $updates);
|
|
|
|
|
|
|
|
$updateMeta = preg_grep('/<ID>'.$updateNumId.'<\/ID>/', $updates[0]);
|
|
|
|
sort($updateMeta);
|
|
|
|
|
|
|
|
$updateFiles = preg_grep('/<Files>.*<\/Files>/', $updateMeta);
|
|
|
|
sort($updateFiles);
|
|
|
|
|
|
|
|
preg_match('/<Files>.*<\/Files>/', $updateFiles[0], $fileList);
|
2017-09-22 21:24:31 +02:00
|
|
|
if(empty($fileList[0])) {
|
2017-10-01 16:06:01 +02:00
|
|
|
consoleLogger('An error has occurred');
|
2017-09-30 16:42:48 +02:00
|
|
|
return array('error' => 'EMPTY_FILELIST');
|
2017-09-22 21:24:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-11 18:01:27 +02:00
|
|
|
preg_match('/Version\=".*?"/', $updateInfo, $foundBuild);
|
2017-10-13 22:55:46 +02:00
|
|
|
$foundBuild = preg_replace('/Version="10\.0\.|"/', '', $foundBuild[0]);
|
|
|
|
|
2017-10-14 15:31:30 +02:00
|
|
|
$updateTitle = preg_grep('/<Title>.*<\/Title>/', $updateMeta);
|
|
|
|
sort($updateTitle);
|
|
|
|
|
2017-10-13 22:55:46 +02:00
|
|
|
preg_match('/<Title>.*?<\/Title>/i', $updateTitle[0], $updateTitle);
|
|
|
|
$updateTitle = preg_replace('/<Title>|<\/Title>/i', '', $updateTitle);
|
2017-09-22 21:24:31 +02:00
|
|
|
sort($updateTitle);
|
|
|
|
|
|
|
|
if(isset($updateTitle[0])) {
|
|
|
|
$updateTitle = $updateTitle[0];
|
|
|
|
} else {
|
|
|
|
$updateTitle = 'Windows 10 build '.$foundBuild;
|
|
|
|
}
|
|
|
|
|
2018-01-07 01:17:08 +01:00
|
|
|
$isCumulativeUpdate = 0;
|
2019-04-03 20:17:39 +02:00
|
|
|
if(preg_match('/\d{4}-\d{2}.+Update|Cumulative Update/i', $updateTitle)) {
|
2018-04-11 18:01:27 +02:00
|
|
|
$isCumulativeUpdate = 1;
|
2018-01-07 01:17:08 +01:00
|
|
|
$updateTitle = preg_replace('/ for .{3,5}-based systems| \(KB.*?\)/i', '', $updateTitle);
|
|
|
|
}
|
2017-10-23 22:53:33 +02:00
|
|
|
|
2019-05-14 20:12:50 +02:00
|
|
|
$updateTitle = preg_replace("/ ?\d{4}-\d{2}\w{0,1} ?| ?$arch ?| ?x64 ?/i", '', $updateTitle);
|
2019-03-12 18:26:33 +01:00
|
|
|
|
|
|
|
if(!preg_match("/$foundBuild/i", $updateTitle)) {
|
2017-10-23 22:53:33 +02:00
|
|
|
$updateTitle = $updateTitle.' ('.$foundBuild.')';
|
|
|
|
}
|
|
|
|
|
2018-04-11 18:01:27 +02:00
|
|
|
preg_match('/UpdateID=".*?"/', $updateInfo, $updateId);
|
|
|
|
preg_match('/RevisionNumber=".*?"/', $updateInfo, $updateRev);
|
2017-10-23 22:53:33 +02:00
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
$updateId = preg_replace('/UpdateID="|"$/', '', $updateId[0]);
|
2017-10-23 22:53:33 +02:00
|
|
|
$updateRev = preg_replace('/RevisionNumber="|"$/', '', $updateRev[0]);
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
consoleLogger('Successfully checked build information.');
|
|
|
|
|
2017-10-23 22:53:33 +02:00
|
|
|
$updateString = $updateId;
|
|
|
|
if($updateRev != 1) {
|
|
|
|
$updateString = $updateId.'_rev.'.$updateRev;
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:29:59 +01:00
|
|
|
consoleLogger("--- UPDATE INFORMATION ---");
|
|
|
|
consoleLogger("Title: ".$updateTitle);
|
|
|
|
consoleLogger("Architecture: ".$arch);
|
|
|
|
consoleLogger("Build number: ".$foundBuild);
|
|
|
|
consoleLogger("Update ID: ".$updateString);
|
|
|
|
consoleLogger("--- UPDATE INFORMATION ---");
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
$fileWrite = 'NO_SAVE';
|
2017-10-23 22:53:33 +02:00
|
|
|
if(!file_exists('fileinfo/'.$updateString.'.json')) {
|
2017-09-22 21:24:31 +02:00
|
|
|
consoleLogger('WARNING: This build is NOT in the database. It will be saved now.');
|
2017-09-30 16:38:26 +02:00
|
|
|
consoleLogger('Parsing information to write...');
|
2017-09-22 21:24:31 +02:00
|
|
|
if(!file_exists('fileinfo')) mkdir('fileinfo');
|
|
|
|
|
|
|
|
$fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]);
|
|
|
|
preg_match_all('/<File .*?>/', $fileList, $fileList);
|
|
|
|
|
|
|
|
$shaArray = array();
|
|
|
|
|
|
|
|
foreach($fileList[0] as $val) {
|
|
|
|
preg_match('/Digest=".*?"/', $val, $sha1);
|
|
|
|
$sha1 = preg_replace('/Digest="|"$/', '', $sha1[0]);
|
|
|
|
$sha1 = bin2hex(base64_decode($sha1));
|
|
|
|
|
|
|
|
preg_match('/FileName=".*?"/', $val, $name);
|
|
|
|
$name = preg_replace('/FileName="|"$/', '', $name[0]);
|
|
|
|
|
|
|
|
preg_match('/Size=".*?"/', $val, $size);
|
|
|
|
$size = preg_replace('/Size="|"$/', '', $size[0]);
|
|
|
|
|
|
|
|
$temp = array(
|
|
|
|
'name' => $name,
|
|
|
|
'size' => $size,
|
|
|
|
);
|
|
|
|
|
|
|
|
$shaArray = array_merge($shaArray, array($sha1 => $temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($temp, $sha1, $name, $size);
|
|
|
|
|
|
|
|
ksort($shaArray);
|
|
|
|
|
2017-10-16 18:03:26 +02:00
|
|
|
$temp = array();
|
|
|
|
$temp['title'] = $updateTitle;
|
|
|
|
$temp['ring'] = $ring;
|
|
|
|
$temp['flight'] = $flight;
|
|
|
|
$temp['arch'] = $arch;
|
|
|
|
$temp['build'] = $foundBuild;
|
|
|
|
$temp['checkBuild'] = $build;
|
2018-04-29 21:33:19 +02:00
|
|
|
$temp['sku'] = $sku;
|
2017-10-16 18:03:26 +02:00
|
|
|
|
2018-01-07 01:17:08 +01:00
|
|
|
if($isCumulativeUpdate) {
|
2017-10-16 18:03:26 +02:00
|
|
|
$temp['containsCU'] = 1;
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:20:28 +01:00
|
|
|
$temp['created'] = time();
|
2017-10-16 18:03:26 +02:00
|
|
|
$temp['files'] = $shaArray;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
consoleLogger('Successfully parsed the information.');
|
|
|
|
consoleLogger('Writing new build information to the disk...');
|
|
|
|
|
2017-10-23 22:53:33 +02:00
|
|
|
$success = file_put_contents('fileinfo/'.$updateString.'.json', json_encode($temp)."\n");
|
2017-09-22 21:24:31 +02:00
|
|
|
if($success) {
|
|
|
|
consoleLogger('Successfully written build information to the disk.');
|
|
|
|
$fileWrite = 'INFO_WRITTEN';
|
|
|
|
} else {
|
|
|
|
consoleLogger('An error has occured while writing the information to the disk.');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
consoleLogger('This build already exists in the database.');
|
|
|
|
}
|
|
|
|
|
2017-09-30 16:38:26 +02:00
|
|
|
$ids = uupListIds();
|
|
|
|
if(!isset($ids['error'])) {
|
|
|
|
$ids = $ids['builds'];
|
|
|
|
$buildName = $foundBuild.' '.$updateTitle.' '.$arch;
|
|
|
|
|
|
|
|
foreach($ids as $val) {
|
|
|
|
$testName = $val['build'].' '.$val['title'].' '.$val['arch'];
|
2017-10-23 22:53:33 +02:00
|
|
|
if($buildName == $testName && $val['uuid'] != $updateString) {
|
2017-09-30 16:38:26 +02:00
|
|
|
unlink(realpath('fileinfo/'.$val['uuid'].'.json'));
|
2018-04-29 21:33:19 +02:00
|
|
|
if(file_exists('packs/'.$val['uuid'].'.json.gz')) {
|
|
|
|
unlink(realpath('packs/'.$val['uuid'].'.json.gz'));
|
|
|
|
}
|
2017-09-30 16:38:26 +02:00
|
|
|
consoleLogger('Removed superseded update: '.$val['uuid']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
return array(
|
2017-10-23 22:53:33 +02:00
|
|
|
'updateId' => $updateString,
|
2017-09-22 21:24:31 +02:00
|
|
|
'updateTitle' => $updateTitle,
|
|
|
|
'foundBuild' => $foundBuild,
|
|
|
|
'arch' => $arch,
|
|
|
|
'fileWrite' => $fileWrite,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|