add support of sha256 for files
This commit is contained in:
parent
4e992e1562
commit
fcbc2ef1a8
@ -305,7 +305,7 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
|
|||||||
if(!file_exists('fileinfo')) mkdir('fileinfo');
|
if(!file_exists('fileinfo')) mkdir('fileinfo');
|
||||||
|
|
||||||
$fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]);
|
$fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]);
|
||||||
preg_match_all('/<File .*?>/', $fileList, $fileList);
|
preg_match_all('/<File.*?<\/File>/', $fileList, $fileList);
|
||||||
|
|
||||||
$shaArray = array();
|
$shaArray = array();
|
||||||
|
|
||||||
@ -320,9 +320,13 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
|
|||||||
preg_match('/Size=".*?"/', $val, $size);
|
preg_match('/Size=".*?"/', $val, $size);
|
||||||
$size = preg_replace('/Size="|"$/', '', $size[0]);
|
$size = preg_replace('/Size="|"$/', '', $size[0]);
|
||||||
|
|
||||||
|
preg_match('/(<AdditionalDigest.*Algorithm="SHA256".*>)(.*?)(<\/AdditionalDigest>)/', $val, $sha256);
|
||||||
|
$sha256 = bin2hex(base64_decode($sha256[2]));
|
||||||
|
|
||||||
$temp = array(
|
$temp = array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
|
'sha256' => $sha256,
|
||||||
);
|
);
|
||||||
|
|
||||||
$shaArray = array_merge($shaArray, array($sha1 => $temp));
|
$shaArray = array_merge($shaArray, array($sha1 => $temp));
|
||||||
@ -350,6 +354,7 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
|
|||||||
}
|
}
|
||||||
|
|
||||||
$temp['created'] = time();
|
$temp['created'] = time();
|
||||||
|
$temp['sha256ready'] = true;
|
||||||
$temp['files'] = $shaArray;
|
$temp['files'] = $shaArray;
|
||||||
|
|
||||||
consoleLogger('Successfully parsed the information.');
|
consoleLogger('Successfully parsed the information.');
|
||||||
|
63
get.php
63
get.php
@ -137,6 +137,7 @@ function uupGetFiles(
|
|||||||
$updateArch = (isset($info['arch'])) ? $info['arch'] : 'UNKNOWN';
|
$updateArch = (isset($info['arch'])) ? $info['arch'] : 'UNKNOWN';
|
||||||
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
|
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
|
||||||
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
|
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
|
||||||
|
$sha256capable = isset($info['sha256ready']);
|
||||||
|
|
||||||
if(isset($info['releasetype'])) {
|
if(isset($info['releasetype'])) {
|
||||||
$type = $info['releasetype'];
|
$type = $info['releasetype'];
|
||||||
@ -158,6 +159,7 @@ function uupGetFiles(
|
|||||||
return $filesInfoList;
|
return $filesInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$sha256capable) {
|
||||||
$baseless = preg_grep('/^baseless_|-baseless\....$/i', array_keys($filesInfoList));
|
$baseless = preg_grep('/^baseless_|-baseless\....$/i', array_keys($filesInfoList));
|
||||||
foreach($baseless as $val) {
|
foreach($baseless as $val) {
|
||||||
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
||||||
@ -199,6 +201,7 @@ function uupGetFiles(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($removeFiles);
|
unset($removeFiles);
|
||||||
|
}
|
||||||
|
|
||||||
$filesInfoKeys = array_keys($filesInfoList);
|
$filesInfoKeys = array_keys($filesInfoList);
|
||||||
|
|
||||||
@ -236,28 +239,44 @@ function uupGetFiles(
|
|||||||
$filesPacksList = array_merge($filesPacksList, $temp);
|
$filesPacksList = array_merge($filesPacksList, $temp);
|
||||||
|
|
||||||
$newFiles = array();
|
$newFiles = array();
|
||||||
|
$failedFile = false;
|
||||||
|
if($sha256capable) {
|
||||||
|
$tmp = [];
|
||||||
|
foreach($filesInfoList as $key => $val) {
|
||||||
|
$tmp[$val['sha256']] = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($filesPacksList as $val) {
|
||||||
|
if(isset($tmp[$val])) {
|
||||||
|
$name = $tmp[$val];
|
||||||
|
$newFiles[$name] = $filesInfoList[$name];
|
||||||
|
} else if(isset($filesInfoList[$val])) {
|
||||||
|
$name = $val;
|
||||||
|
$newFiles[$name] = $filesInfoList[$name];
|
||||||
|
} else {
|
||||||
|
$failedFile = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
foreach($filesPacksList as $val) {
|
foreach($filesPacksList as $val) {
|
||||||
$name = $uupCleanFunc($val);
|
$name = $uupCleanFunc($val);
|
||||||
$filesPacksKeys[] = $name;
|
$filesPacksKeys[] = $name;
|
||||||
|
|
||||||
if(isset($filesInfoList[$name])) {
|
if(isset($filesInfoList[$name])) {
|
||||||
$newFiles[$name] = $filesInfoList[$name];
|
$newFiles[$name] = $filesInfoList[$name];
|
||||||
|
} else {
|
||||||
|
$failedFile = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($failedFile) {
|
||||||
|
consoleLogger("Missing file: $failedFile");
|
||||||
|
return array('error' => 'MISSING_FILES');
|
||||||
|
}
|
||||||
|
|
||||||
$filesInfoList = $newFiles;
|
$filesInfoList = $newFiles;
|
||||||
$filesInfoKeys = array_keys($filesInfoList);
|
$filesInfoKeys = array_keys($filesInfoList);
|
||||||
|
|
||||||
$filesPacksKeys = array_unique($filesPacksKeys);
|
|
||||||
sort($filesPacksKeys);
|
|
||||||
$compare = array_diff($filesPacksKeys, $filesInfoKeys);
|
|
||||||
|
|
||||||
if(count($compare)) {
|
|
||||||
foreach($compare as $val) {
|
|
||||||
consoleLogger("Missing file: $val");
|
|
||||||
}
|
|
||||||
return array('error' => 'MISSING_FILES');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($filesInfoKeys)) {
|
if(empty($filesInfoKeys)) {
|
||||||
@ -338,12 +357,15 @@ function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
|
|||||||
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
||||||
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
||||||
|
|
||||||
|
$sha256capable = isset($info['sha256ready']);
|
||||||
|
|
||||||
$fileLocations = $getResult->FileLocations;
|
$fileLocations = $getResult->FileLocations;
|
||||||
$info = $info['files'];
|
$info = $info['files'];
|
||||||
|
|
||||||
$files = array();
|
$files = array();
|
||||||
foreach($fileLocations->FileLocation as $val) {
|
foreach($fileLocations->FileLocation as $val) {
|
||||||
$sha1 = bin2hex(base64_decode((string)$val->FileDigest));
|
$sha1 = bin2hex(base64_decode((string)$val->FileDigest));
|
||||||
|
$sha256 = isset($info[$sha1]['sha256']) ? $info[$sha1]['sha256'] : null;
|
||||||
$url = (string)$val->Url;
|
$url = (string)$val->Url;
|
||||||
|
|
||||||
preg_match('/files\/(.{8}-.{4}-.{4}-.{4}-.{12})/', $url, $guid);
|
preg_match('/files\/(.{8}-.{4}-.{4}-.{4}-.{12})/', $url, $guid);
|
||||||
@ -378,13 +400,21 @@ function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
|
|||||||
|
|
||||||
$temp = array();
|
$temp = array();
|
||||||
$temp['sha1'] = $sha1;
|
$temp['sha1'] = $sha1;
|
||||||
|
$temp['sha256'] = $sha256;
|
||||||
$temp['size'] = $size;
|
$temp['size'] = $size;
|
||||||
$temp['url'] = $url;
|
$temp['url'] = $url;
|
||||||
$temp['uuid'] = $guid;
|
$temp['uuid'] = $guid;
|
||||||
$temp['expire'] = $expire;
|
$temp['expire'] = $expire;
|
||||||
$temp['debug'] = $val->asXML();
|
$temp['debug'] = $val->asXML();
|
||||||
|
|
||||||
|
if($sha256capable) {
|
||||||
|
$n = strrpos($name, '.');
|
||||||
|
if($n === false) $n = strlen($name);
|
||||||
|
$newName = substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
||||||
|
} else {
|
||||||
$newName = $uupCleanFunc($name);
|
$newName = $uupCleanFunc($name);
|
||||||
|
}
|
||||||
|
|
||||||
$files[$newName] = $temp;
|
$files[$newName] = $temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,10 +440,13 @@ function uupGetOfflineFiles($info) {
|
|||||||
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
||||||
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
||||||
|
|
||||||
|
$sha256capable = isset($info['sha256ready']);
|
||||||
|
|
||||||
consoleLogger('Parsing information...');
|
consoleLogger('Parsing information...');
|
||||||
foreach($info['files'] as $sha1 => $val) {
|
foreach($info['files'] as $sha1 => $val) {
|
||||||
$name = $val['name'];
|
$name = $val['name'];
|
||||||
$size = $val['size'];
|
$size = $val['size'];
|
||||||
|
$sha256 = isset($val['sha256']) ? $val['sha256'] : null;
|
||||||
if(!isset($fileSizes[$name])) $fileSizes[$name] = 0;
|
if(!isset($fileSizes[$name])) $fileSizes[$name] = 0;
|
||||||
|
|
||||||
if($size > $fileSizes[$name]) {
|
if($size > $fileSizes[$name]) {
|
||||||
@ -421,13 +454,21 @@ function uupGetOfflineFiles($info) {
|
|||||||
|
|
||||||
$temp = array();
|
$temp = array();
|
||||||
$temp['sha1'] = $sha1;
|
$temp['sha1'] = $sha1;
|
||||||
|
$temp['sha256'] = $sha256;
|
||||||
$temp['size'] = $size;
|
$temp['size'] = $size;
|
||||||
$temp['url'] = null;
|
$temp['url'] = null;
|
||||||
$temp['uuid'] = null;
|
$temp['uuid'] = null;
|
||||||
$temp['expire'] = 0;
|
$temp['expire'] = 0;
|
||||||
$temp['debug'] = null;
|
$temp['debug'] = null;
|
||||||
|
|
||||||
|
if($sha256capable) {
|
||||||
|
$n = strrpos($name, '.');
|
||||||
|
if($n === false) $n = strlen($name);
|
||||||
|
$newName = substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
||||||
|
} else {
|
||||||
$newName = $uupCleanFunc($name);
|
$newName = $uupCleanFunc($name);
|
||||||
|
}
|
||||||
|
|
||||||
$files[$newName] = $temp;
|
$files[$newName] = $temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function uupApiVersion() {
|
function uupApiVersion() {
|
||||||
return '1.31.1';
|
return '1.32.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once dirname(__FILE__).'/auths.php';
|
require_once dirname(__FILE__).'/auths.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user