Initial commit

This commit is contained in:
whatever127 2019-09-14 17:38:35 +02:00
commit b925e9a5f6
12 changed files with 313 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

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

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 whatever127
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 d628c2fe69ed91adb397d966812477767b2d8a69

37
fetchupd.php Normal file
View File

@ -0,0 +1,37 @@
<?php
require_once 'api/fetchupd.php';
require_once 'shared/main.php';
require_once 'shared/ratelimits.php';
$arch = isset($_GET['arch']) ? $_GET['arch'] : 'amd64';
$ring = isset($_GET['ring']) ? $_GET['ring'] : 'WIF';
$flight = isset($_GET['flight']) ? $_GET['flight'] : 'Active';
$build = isset($_GET['build']) ? $_GET['build'] : 'latest';
$sku = isset($_GET['sku']) ? $_GET['sku'] : '48';
header('Content-Type: application/json');
$resource = hash('sha1', strtolower("fetch-$arch-$ring-$flight-$build-$sku"));
if(checkIfUserIsRateLimited($resource)) {
http_response_code(429);
sendResponse(['error' => 'USER_RATE_LIMITED']);
die();
}
$apiResponse = uupFetchUpd($arch, $ring, $flight, $build, 0, $sku, 1);
if(isset($apiResponse['error'])) {
switch($apiResponse['error']) {
case 'EMPTY_FILELIST':
http_response_code(500);
break;
case 'NO_UPDATE_FOUND':
http_response_code(500);
break;
default:
http_response_code(400);
}
}
sendResponse($apiResponse);

39
get.php Normal file
View File

@ -0,0 +1,39 @@
<?php
require_once 'api/get.php';
require_once 'shared/main.php';
require_once 'shared/ratelimits.php';
$updateId = isset($_GET['id']) ? $_GET['id'] : null;
$usePack = isset($_GET['lang']) ? $_GET['lang'] : 0;
$desiredEdition = isset($_GET['edition']) ? $_GET['edition'] : 0;
header('Content-Type: application/json');
$resource = hash('sha1', strtolower("get-$updateId-$usePack-$desiredEdition"));
if(checkIfUserIsRateLimited($resource)) {
http_response_code(429);
sendResponse(['error' => 'USER_RATE_LIMITED']);
die();
}
$apiResponse = uupGetFiles($updateId, $usePack, $desiredEdition, 1);
if(isset($apiResponse['error'])) {
switch($apiResponse['error']) {
case 'NO_FILES':
http_response_code(500);
break;
case 'XML_PARSE_ERROR':
http_response_code(500);
break;
case 'EMPTY_FILELIST':
http_response_code(500);
break;
default:
http_response_code(400);
}
}
sendResponse($apiResponse);

7
index.php Normal file
View File

@ -0,0 +1,7 @@
<?php
require_once 'api/shared/main.php';
require_once 'shared/main.php';
header('Content-Type: application/json');
sendResponse(['apiVersion' => uupApiVersion()]);

14
listeditions.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once 'api/listeditions.php';
require_once 'shared/main.php';
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'en-us';
$updateId = isset($_GET['id']) ? $_GET['id'] : null;
header('Content-Type: application/json');
$apiResponse = uupListEditions($lang, $updateId);
if(isset($apiResponse['error']))
http_response_code(400);
sendResponse($apiResponse);

14
listid.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once 'api/listid.php';
require_once 'shared/main.php';
$search = isset($_GET['search']) ? $_GET['search'] : null;
$sortByDate = isset($_GET['sortByDate']) ? $_GET['sortByDate'] : false;
header('Content-Type: application/json');
$apiResponse = uupListIds($search, $sortByDate);
if(isset($apiResponse['error']))
http_response_code(400);
sendResponse($apiResponse);

13
listlangs.php Normal file
View File

@ -0,0 +1,13 @@
<?php
require_once 'api/listlangs.php';
require_once 'shared/main.php';
$updateId = isset($_GET['id']) ? $_GET['id'] : null;
header('Content-Type: application/json');
$apiResponse = uupListLangs($updateId);
if(isset($apiResponse['error']))
http_response_code(400);
sendResponse($apiResponse);

100
readme.md Normal file
View File

@ -0,0 +1,100 @@
UUP dump JSON API
-----------------
### Description
A simple endpoint allowing access of the UUP dump API using HTTP requests.
### Usage
All requests are done using GET requests with parameters specified in the URL.
Response is provided as an JSON.
Example response:
```json
{
"response": {
"apiVersion": "1.27.0"
},
"jsonApiVersion": "0.1.0-alpha"
}
```
Responses from the UUP dump API are always returned in the `response` key.
If requests fails, a HTTP error code will be set to:
- `400` if request was malformed
- `429` if user is being rate limited
- `500` if retrieval of data was unsuccessful
In such cases `response` key will contain an `error` key with short description
of the error.
### Supported endpoints
#### `/` or `/index.php`
Returns versions of APIs
Parameters:
- None
#### `/listid.php`
Returns a list of builds in the local database.
Parameters:
- `search` - Search query (optional)
- **Supported values:** any text
- `sortByDate` - Sort results by creation date (optional)
- **Supported values:** 0 = Disable, 1 = Enable
#### `/fetchupd.php`
Fetches the latest builds from Windows Update servers using specified
parameters.
Parameters:
- `arch` - Architecture of build to find
- **Supported values:** `amd64`, `arm64`, `x86`
- `ring` - Ring to use when fetching information
- **Supported values:** `WIF`, `WIS`, `RP`, `RETAIL`
- `flight` - Flight to use when fetching information
- **Supported values:** `Active`, `Skip`, `Current`
- **NOTE:** `Skip` is for `WIF` ring only. `Current` is for `RP` ring only.
- `build` - Build number to use when fetching information
- **Supported values:** >= 9841 and <= PHP_INT_MAX-1
- `sku` - SKU number to use when fetching information
- **Supported values:** Any integer
#### `/get.php`
Retrieves download links for specified Update ID and provides lists of ready to
use UUP sets.
Parameters:
- `id` - Update identifier
- **Supported values:** any update identifier
- `lang` - Create UUP set for selected language (optional)
- **Supported values:** language name in xx-xx format
- `edition` - Create UUP set for selected edition (optional)
- **Supported values:** any edition name
- **NOTE:** You need to specify `lang` to get successful request
#### `/listlangs.php`
Lists available languages for specified Update ID
Parameters:
- `id` - Update identifier (optional)
- **Supported values:** any update identifier
#### `/listlangs.php`
Lists available editions for specified Update ID
Parameters:
- `lang` - Generate list for selected language
- **Supported values:** language name in xx-xx format
- `id` - Update identifier (optional)
- **Supported values:** any update identifier

13
shared/main.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$webApiVersion = '0.1.0';
function sendResponse($apiResponse) {
global $webApiVersion;
$response = [
'response' => $apiResponse,
'jsonApiVersion' => $webApiVersion,
];
echo json_encode($response);
}

51
shared/ratelimits.php Normal file
View File

@ -0,0 +1,51 @@
<?php
/*
Copyright 2019 whatever127
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.
*/
function checkIfUserIsRateLimited($resource, $timeLimit = 10, $currentResLimit = 1) {
$clientIP = $_SERVER['REMOTE_ADDR'];
$ipHash = hash('sha256', "ratelimits-$clientIP");
$info = @file_get_contents('cache/'.$ipHash.'.json');
$info = json_decode($info, 1);
if(!isset($info['resource'])) {
$info['resource'] = $resource;
}
if(!isset($info['lastAccess'])) {
$info['lastAccess'] = 0;
}
$lastAccess = $info['lastAccess'];
$accessedRes = $info['resource'];
$blockAccessTime = $lastAccess + $timeLimit;
if($blockAccessTime > microtime(1) && $accessedRes != $resource) {
return true;
}
$info['lastAccess'] = microtime(1);
$info['resource'] = $resource;
@file_put_contents('cache/'.$ipHash.'.json', json_encode($info)."\n");
if($lastAccess + $currentResLimit > microtime(1) && $accessedRes == $resource) {
return true;
}
return false;
}