Initial commit

This commit is contained in:
mkuba50 2019-04-12 15:40:27 +02:00
commit c9a741eaed
14 changed files with 578 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "api"]
path = api
url = git@gitlab.com:uup-dump/api.git

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 UUP dump authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1
api Submodule

@ -0,0 +1 @@
Subproject commit a90dc04636104f9857cf44d41ea29b89efb1cb52

38
fetchdetect.php Normal file
View File

@ -0,0 +1,38 @@
<?php
$arch = isset($argv[1]) ? $argv[1] : 'amd64';
$ring = isset($argv[2]) ? $argv[2] : 'WIF';
$flight = isset($argv[3]) ? $argv[3] : 'Active';
$build = isset($argv[4]) ? intval($argv[4]) : 16251;
$minor = isset($argv[5]) ? intval($argv[5]) : 0;
$sku = isset($argv[6]) ? intval($argv[6]) : 48;
require_once dirname(__FILE__).'/api/fetchupd.php';
require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/genpack.php';
consoleLogger(brand('fetchupd'));
if(!get7ZipLocation()) {
throwError('NO_7ZIP');
}
$fetchedUpdate = uupFetchUpd($arch, $ring, $flight, $build, $minor, $sku);
if(isset($fetchedUpdate['error'])) {
throwError($fetchedUpdate['error']);
}
foreach($fetchedUpdate['updateArray'] as $update) {
generatePack($update['updateId']);
}
echo $fetchedUpdate['foundBuild'];
echo '|';
echo $fetchedUpdate['arch'];
echo '|';
echo $fetchedUpdate['updateId'];
echo '|';
echo $fetchedUpdate['updateTitle'];
echo '|';
echo $fetchedUpdate['fileWrite'];
echo "\n";
?>

28
fetchupd.php Normal file
View File

@ -0,0 +1,28 @@
<?php
$arch = isset($argv[1]) ? $argv[1] : 'amd64';
$ring = isset($argv[2]) ? $argv[2] : 'WIF';
$flight = isset($argv[3]) ? $argv[3] : 'Active';
$build = isset($argv[4]) ? intval($argv[4]) : 16251;
$minor = isset($argv[5]) ? intval($argv[5]) : 0;
$sku = isset($argv[6]) ? intval($argv[6]) : 48;
require_once dirname(__FILE__).'/api/fetchupd.php';
require_once dirname(__FILE__).'/shared/main.php';
consoleLogger(brand('fetchupd'));
$fetchedUpdate = uupFetchUpd($arch, $ring, $flight, $build, $minor, $sku);
if(isset($fetchedUpdate['error'])) {
throwError($fetchedUpdate['error']);
}
echo $fetchedUpdate['foundBuild'];
echo '|';
echo $fetchedUpdate['arch'];
echo '|';
echo $fetchedUpdate['updateId'];
echo '|';
echo $fetchedUpdate['updateTitle'];
echo '|';
echo $fetchedUpdate['fileWrite'];
echo "\n";
?>

42
get.php Normal file
View File

@ -0,0 +1,42 @@
<?php
$updateId = isset($argv[1]) ? $argv[1] : 'c2a1d787-647b-486d-b264-f90f3782cdc6';
$usePack = isset($argv[2]) ? $argv[2] : 0;
$desiredEdition = isset($argv[3]) ? $argv[3] : 0;
$simple = isset($argv[4]) ? $argv[4] : 0;
require_once dirname(__FILE__).'/api/get.php';
require_once dirname(__FILE__).'/shared/main.php';
consoleLogger(brand('get'));
$files = uupGetFiles($updateId, $usePack, $desiredEdition);
if(isset($files['error'])) {
throwError($files['error']);
}
$files = $files['files'];
$filesKeys = array_keys($files);
function sortBySize($a, $b) {
global $files;
if ($files[$a]['size'] == $files[$b]['size']) {
return 0;
}
return ($files[$a]['size'] < $files[$b]['size']) ? -1 : 1;
}
usort($filesKeys, 'sortBySize');
if($simple == 1) {
foreach($filesKeys as $val) {
echo $val."|".$files[$val]['sha1']."|".$files[$val]['url']."\n";
}
die();
}
foreach($filesKeys as $val) {
echo $files[$val]['url']."\n";
echo ' out='.$val."\n";
echo ' checksum=sha-1='.$files[$val]['sha1']."\n\n";
}
?>

52
getdetect.php Normal file
View File

@ -0,0 +1,52 @@
<?php
$updateId = isset($argv[1]) ? $argv[1] : 'c2a1d787-647b-486d-b264-f90f3782cdc6';
$usePack = isset($argv[2]) ? $argv[2] : 0;
$desiredEdition = isset($argv[3]) ? $argv[3] : 0;
$simple = isset($argv[4]) ? $argv[4] : 0;
require_once dirname(__FILE__).'/api/get.php';
require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/genpack.php';
consoleLogger(brand('get'));
if(!get7ZipLocation()) {
throwError('NO_7ZIP');
}
if(!generatePack($updateId)) {
throwError('PACKS_FAILED');
}
$files = uupGetFiles($updateId, $usePack, $desiredEdition);
if(isset($files['error'])) {
throwError($files['error']);
}
$files = $files['files'];
$filesKeys = array_keys($files);
function sortBySize($a, $b) {
global $files;
if ($files[$a]['size'] == $files[$b]['size']) {
return 0;
}
return ($files[$a]['size'] < $files[$b]['size']) ? -1 : 1;
}
usort($filesKeys, 'sortBySize');
if($simple == 1) {
foreach($filesKeys as $val) {
echo $val."|".$files[$val]['sha1']."|".$files[$val]['url']."\n";
}
die();
}
foreach($filesKeys as $val) {
echo $files[$val]['url']."\n";
echo ' out='.$val."\n";
echo ' checksum=sha-1='.$files[$val]['sha1']."\n\n";
}
?>

25
getfile.php Normal file
View File

@ -0,0 +1,25 @@
<?php
$updateId = isset($argv[1]) ? $argv[1] : null;
$file = isset($argv[2]) ? $argv[2] : null;
if(empty($updateId)) die('Unspecified update id');
if(empty($file)) die('Unspecified file');
require_once dirname(__FILE__).'/api/get.php';
$files = uupGetFiles($updateId, 0, 0);
if(isset($files['error'])) {
throwError($files['error']);
}
$files = $files['files'];
$filesKeys = array_keys($files);
if(!isset($files[$file]['url'])) {
throwError('NO_FILES');
}
echo $files[$file]['url']."\n";
echo ' out='.$file."\n";
echo ' checksum=sha-1='.$files[$file]['sha1']."\n\n";
?>

21
listeditions.php Normal file
View File

@ -0,0 +1,21 @@
<?php
$lang = isset($argv[1]) ? $argv[1] : 'en-us';
$updateId = isset($argv[2]) ? $argv[2] : 0;
require_once dirname(__FILE__).'/api/listeditions.php';
$editions = uupListEditions($lang, $updateId);
if(isset($editions['error'])) {
throwError($editions['error']);
}
$editions = $editions['editionFancyNames'];
asort($editions);
foreach($editions as $key => $val) {
echo $key;
echo '|';
echo $val;
echo "\n";
}
?>

23
listid.php Normal file
View File

@ -0,0 +1,23 @@
<?php
$search = isset($argv[1]) ? $argv[1] : 0;
require_once dirname(__FILE__).'/api/listid.php';
require_once dirname(__FILE__).'/shared/main.php';
consoleLogger(brand('listid'));
$ids = uupListIds($search);
if(isset($ids['error'])) {
throwError($ids['error']);
}
foreach($ids['builds'] as $val) {
echo $val['build'];
echo '|';
echo $val['arch'];
echo '|';
echo $val['uuid'];
echo '|';
echo $val['title'];
echo "\n";
}
?>

15
listlangs.php Normal file
View File

@ -0,0 +1,15 @@
<?php
$updateId = isset($argv[1]) ? $argv[1] : 0;
require_once dirname(__FILE__).'/api/listlangs.php';
$langs = uupListLangs($updateId);
$langs = $langs['langFancyNames'];
asort($langs);
foreach($langs as $key => $val) {
echo $key;
echo '|';
echo $val;
echo "\n";
}
?>

14
readme.md Normal file
View File

@ -0,0 +1,14 @@
UUP dump standalone
-------------------
### Description
This code is used by backend server of UUP dump website to automatically
retrieve new builds and automatically generate packs used to create proper
UUP sets.
### Why the code is being publisned now?
Before now the UUP dump website was internally using the UUP dump UUPDL edition
which was a rebrand of UUP dump 2.x series which was meant for console only
purposes and distributed only with UUPDL. Now I have decided to rebrand this
for the third time and publish it as MIT licensed project. This will allow me
easier updates to the backend in much more transparent way.

177
shared/genpack.php Normal file
View File

@ -0,0 +1,177 @@
<?php
require_once dirname(__FILE__).'/../api/get.php';
require_once dirname(__FILE__).'/main.php';
function get7ZipLocation() {
if(PHP_OS == 'WINNT') {
$z7z = realpath(dirname(__FILE__)).'/../../7za.exe';
if(!file_exists($z7z)) return false;
} else {
exec('command -v 7z', $out, $errCode);
if($errCode != 0) {
return false;
}
$z7z = '7z';
}
return $z7z;
}
function generatePack($updateId) {
$z7z = get7ZipLocation();
$tmp = 'uuptmp';
if(!file_exists($tmp)) mkdir($tmp);
if(file_exists('packs/'.$updateId.'.json.gz')) {
return 2;
}
consoleLogger('Generating packs for '.$updateId.'...');
$files = uupGetFiles($updateId, 0, 0);
if(isset($files['error'])) {
throwError($files['error']);
}
$files = $files['files'];
$filesKeys = array_keys($files);
$filesToRead = array();
$aggregatedMetadata = preg_grep('/AggregatedMetadata/i', $filesKeys);
if(!empty($aggregatedMetadata)) {
sort($aggregatedMetadata);
$checkFile = $aggregatedMetadata[0];
$url = $files[$checkFile]['url'];
$loc = "$tmp/$checkFile";
consoleLogger('Downloading aggregated metadata: '.$checkFile);
downloadFile($url, $loc);
if(!file_exists($loc)) {
throwError('INFO_DOWNLOAD_ERROR');
}
consoleLogger('Unpacking aggregated metadata: '.$checkFile);
exec("$z7z l -slt \"$loc\"", $out, $errCode);
if($errCode != 0) {
unlink($loc);
throwError('7ZIP_ERROR');
}
$files = preg_grep('/Path = /', $out);
$files = preg_replace('/Path = /', '', $files);
$dataFiles = preg_grep('/DesktopTargetCompDB_.*_.*\./i', $files);
unset($out);
exec("$z7z x -o\"$tmp\" \"$loc\" -y", $out, $errCode);
if($errCode != 0) {
unlink($loc);
throwError('7ZIP_ERROR');
}
unset($out);
foreach($dataFiles as $val) {
consoleLogger('Unpacking info file: '.$val);
if(preg_match('/.cab$/i', $val)) {
exec("$z7z x -bb2 -o\"$tmp\" \"$tmp/$val\" -y", $out, $errCode);
if($errCode != 0) {
unlink($loc);
throwError('7ZIP_ERROR');
}
$temp = preg_grep('/^-.*DesktopTargetCompDB_.*_.*\./i', $out);
sort($temp);
$temp = preg_replace('/^- /', '', $temp[0]);
$filesToRead[] = preg_replace('/.cab$/i', '', $temp);
unlink("$tmp/$val");
unset($temp, $out);
} else {
$filesToRead[] = $val;
}
}
unlink($loc);
unset($loc, $checkFile, $checkEd, $dataFiles);
} else {
$dataFiles = preg_grep('/DesktopTargetCompDB_.*_.*\./i', $filesKeys);
foreach($dataFiles as $val) {
$url = $files[$val]['url'];
$loc = "$tmp/$val";
consoleLogger('Downloading info file: '.$val);
downloadFile($url, $loc);
if(!file_exists($loc)) {
throwError('INFO_DOWNLOAD_ERROR');
}
if(preg_match('/.cab$/i', $val)) {
exec("$z7z x -bb2 -o\"$tmp\" \"$tmp/$val\" -y", $out, $errCode);
if($errCode != 0) {
unlink($loc);
throwError('7ZIP_ERROR');
}
$temp = preg_grep('/^-.*DesktopTargetCompDB_.*_.*\./i', $out);
sort($temp);
$temp = preg_replace('/^- /', '', $temp[0]);
$filesToRead[] = preg_replace('/.cab$/i', '', $temp);
unlink("$tmp/$val");
unset($temp, $out);
} else {
$filesToRead[] = $val;
}
}
unset($loc, $checkEd, $dataFiles);
}
$langsEditions = array();
$packages = array();
foreach($filesToRead as $val) {
$filNam = preg_replace('/\.xml.*/', '', $val);
$file = $tmp.'/'.$val;
$xml = simplexml_load_file($file);
$lang = preg_replace('/.*DesktopTargetCompDB_.*_/', '', $filNam);
$edition = preg_replace('/.*DesktopTargetCompDB_|_'.$lang.'/', '', $filNam);
$lang = strtolower($lang);
$edition = strtoupper($edition);
foreach($xml->Packages->Package as $val) {
foreach($val->Payload->PayloadItem as $PayloadItem) {
$name = $PayloadItem['Path'];
$name = preg_replace('/.*\\\/', '', $name);
$packages[$lang][$edition][] = $name;
}
}
$packages[$lang][$edition] = array_unique($packages[$lang][$edition]);
sort($packages[$lang][$edition]);
unlink($file);
unset($file, $xml, $name, $newName, $lang, $edition);
}
$removeFiles = scandir($tmp);
foreach($removeFiles as $val) {
if($val == '.' || $val == '..') continue;
unlink($tmp.'/'.$val);
}
if(!file_exists('packs')) mkdir('packs');
$success = file_put_contents(
'packs/'.$updateId.'.json.gz',
gzencode(json_encode($packages)."\n")
);
if($success) {
consoleLogger('Successfully written generated packs.');
} else {
consoleLogger('An error has occured while writing generated packs to the disk.');
return 0;
}
return 1;
}

118
shared/main.php Normal file
View File

@ -0,0 +1,118 @@
<?php
require_once dirname(__FILE__).'/../api/shared/main.php';
function brand($script) {
$projVersion = '1.0.0';
return 'UUP dump standalone v'.$projVersion;
}
function downloadFile($url, $location) {
$file = fopen($location, 'w+');
$req = curl_init($url);
curl_setopt($req, CURLOPT_HEADER, 0);
curl_setopt($req, CURLOPT_FILE, $file);
curl_setopt($req, CURLOPT_ENCODING, '');
curl_setopt($req, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($req);
curl_close($req);
fclose($file);
}
function throwError($errorCode) {
switch ($errorCode) {
case 'ERROR':
$errorFancy = 'Generic error.';
break;
case '7ZIP_ERROR':
$errorFancy = '7-Zip has returned an error.';
break;
case 'INFO_DOWNLOAD_ERROR':
$errorFancy = 'Failed to retrieve information.';
break;
case 'UNSUPPORTED_API':
$errorFancy = 'Installed API version is not compatible with this version of UUP dump.';
break;
case 'NO_FILEINFO_DIR':
$errorFancy = 'The fileinfo directory does not exist.';
break;
case 'NO_BUILDS_IN_FILEINFO':
$errorFancy = 'The fileinfo database does not contain any build.';
break;
case 'SEARCH_NO_RESULTS':
$errorFancy = 'No items could be found for specified query.';
break;
case 'UNKNOWN_ARCH':
$errorFancy = 'Unknown processor architecture.';
break;
case 'UNKNOWN_RING':
$errorFancy = 'Unknown ring.';
break;
case 'UNKNOWN_FLIGHT':
$errorFancy = 'Unknown flight.';
break;
case 'UNKNOWN_COMBINATION':
$errorFancy = 'The flight and ring combination is not correct. Skip ahead is only supported for Insider Fast ring.';
break;
case 'ILLEGAL_BUILD':
$errorFancy = 'Specified build number is less than 9841 or larger than '. (PHP_INT_MAX-1) .'.';
break;
case 'ILLEGAL_MINOR':
$errorFancy = 'Specified build minor is incorrect.';
break;
case 'NO_UPDATE_FOUND':
$errorFancy = 'Server did not return any updates.';
break;
case 'XML_PARSE_ERROR':
$errorFancy = 'Parsing of response XML has failed. This may indicate a temporary problem with Microsoft servers. Try again later.';
break;
case 'EMPTY_FILELIST':
$errorFancy = 'Server has returned an empty list of files.';
break;
case 'NO_FILES':
$errorFancy = 'There are no files available for your selection.';
break;
case 'NO_METADATA_ESD':
$errorFancy = 'There are no metadata ESD files available for your selection.';
break;
case 'UNSUPPORTED_LANG':
$errorFancy = 'Specified language is not supported.';
break;
case 'UNSPECIFIED_LANG':
$errorFancy = 'Language was not specified.';
break;
case 'UNSUPPORTED_EDITION':
$errorFancy = 'Specified edition is not supported.';
break;
case 'UNSUPPORTED_COMBINATION':
$errorFancy = 'The language and edition combination is not correct.';
break;
case 'NOT_CUMULATIVE_UPDATE':
$errorFancy = 'Selected update does not contain Cumulative Update.';
break;
case 'UPDATE_INFORMATION_NOT_EXISTS':
$errorFancy = 'Information about specified update doest not exist in database.';
break;
case 'KEY_NOT_EXISTS':
$errorFancy = 'Specified key does not exist in update information';
break;
case 'UNSPECIFIED_UPDATE':
$errorFancy = 'Update ID was not specified.';
break;
case 'NO_7ZIP':
$errorFancy = '7-Zip cannot be found.';
break;
case 'PACKS_FAILED':
$errorFancy = 'No generated packs.';
break;
default:
$errorFancy = $errorCode;
break;
}
consoleLogger('ERROR: '.$errorFancy);
die(E_ERROR);
}
?>