144 lines
5.1 KiB
PHP
144 lines
5.1 KiB
PHP
<?php
|
|
|
|
use Noodlehaus\Config;
|
|
use Slim\Factory\AppFactory;
|
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
require __DIR__ . '/libSignedComms.php';
|
|
|
|
/** Do Configuration */
|
|
$RepositoryUrl = "https://tonoxisisle.services/tononixOS/recovery/repo.json";
|
|
$SelfUpdateUrl = "https://tonoxisisle.services/tononixOS/recovery/BUILD-DATA";
|
|
$SelfUpdateZipUrl = "https://tonoxisisle.services/tononixOS/recovery/recovery.zip";
|
|
$ModelName = "Raspberry Pi 3 Model B Rev 1.2";
|
|
$SerialNumber = "000019292900aTEST";
|
|
$GPGHome = __DIR__ . "/.gpg";
|
|
$RecoveryVersionInfo = file("BUILD-DATA");
|
|
|
|
if (str_contains($_SERVER['USER_AGENT'], "tononixPC/")) {
|
|
if (file_exists("/settings/update-proxy.ini") && !defined("DEBUG")) {
|
|
$Configuration = new Config("/settings/update-proxy.ini", new Ini);
|
|
$SelfUpdateUrl = $Configuration->get("proxy-urls.self-update-url");
|
|
$GPGHome = "/tmp/gpg-UpdateProxy";
|
|
$SelfUpdateZipUrl = $Configuration->get('proxy-urls.self-update-zip');
|
|
$RepositoryUrl = $Configuration->get('proxy-urls.repository-url');
|
|
$SerialNumber = file_get_contents("/sys/firmware/devicetree/base/serial-number");
|
|
$ModelName = file_get_contents("/sys/firmware/devicetree/base/model");
|
|
$RecoveryVersionInfo = file("/mnt/BUILD-DATA");
|
|
}
|
|
}
|
|
|
|
$SerialNumber = str_replace("\r", "", $SerialNumber);
|
|
$SerialNumber = str_replace("\n", "", $SerialNumber);
|
|
|
|
$RecoveryVersion = str_replace("PINN Version: ", "", $RecoveryVersionInfo[1]);
|
|
$RecoveryVersion = str_replace("\r", "", $RecoveryVersion);
|
|
$RecoveryVersion = str_replace("\n", "", $RecoveryVersion);
|
|
|
|
/** Setup headers for cURL to use */
|
|
$UpdateServiceHeaders = [
|
|
'X-Device-Serial-Number' => $SerialNumber,
|
|
'X-Device-Bootloader-Version' => $RecoveryVersion,
|
|
'X-Device-Model-Name' => $ModelName,
|
|
'User-Agent' => 'tononixPC/' . $RecoveryVersion,
|
|
];
|
|
|
|
/** Setup Application */
|
|
|
|
$app = AppFactory::Create();
|
|
$SignedComms = new SignedCommunicationProvider("/mnt/public.key");
|
|
|
|
$app->get("/recovery/version", function ($request, $response, array $args) {
|
|
global $SelfUpdateUrl;
|
|
global $UpdateServiceHeaders;
|
|
global $SignedComms;
|
|
|
|
// Retrieve the data from the server.
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $SelfUpdateUrl);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $UpdateServiceHeaders);
|
|
#curl_setopt($ch, CURLOPT_POST, 1);
|
|
#curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_CRLF, 1);
|
|
$buildData = curl_exec($ch);
|
|
if (curl_errno($ch)) {
|
|
print "Error " . curl_errno($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
$version = $buildData;
|
|
// Process the incoming data.
|
|
$query = $request->getQueryParams();
|
|
$userAgent = $request->getHeader("User-Agent");
|
|
if (str_contains($userAgent, "tononixPC/") == true || $query['signed'] == true || defined('DEFAULT_SIGNED_COMMUNICATIONS')) {
|
|
$result = $SignedComms->verify($version);
|
|
if($result != false) {
|
|
$response->getBody->write($result['data']);
|
|
return $response
|
|
->withStatus(201)
|
|
->withHeader("Content-Type","text/plain");
|
|
} else {
|
|
return $response->withStatus(500);
|
|
}
|
|
}
|
|
});
|
|
|
|
$app->get("/recovery/ota-download", function ($request, $response, array $args) {
|
|
// Recovery.zip verification/proxy handling
|
|
});
|
|
|
|
$app->get("/recovery/repository", function ($request, $response, array $args) {
|
|
// os_repo.json verification/proxy handling
|
|
});
|
|
|
|
$app->get("/recovery/repository/sources", function ($request, $response, array $args) {
|
|
// repo_list.json verification/proxy handling
|
|
});
|
|
|
|
|
|
// Default Route
|
|
$app->get("/", function ($request, $response, array $args) {
|
|
global $RecoveryVersion;
|
|
global $SelfUpdateUrl;
|
|
global $SelfUpdateZipUrl;
|
|
global $RepositoryUrl;
|
|
global $GPGHome;
|
|
|
|
$body = $response->getBody();
|
|
|
|
// Show application version information
|
|
$body->write("tononixPC Device Bootloader Update Proxy\r\n");
|
|
$body->write("Version 1.0.0\r\n");
|
|
$body->write("Running on Bootloader Version: ".$RecoveryVersion."\r\n");
|
|
$body->write("\r\n\r\n");
|
|
|
|
// Show configured URLs
|
|
$body->write("Configured URLs:\r\n\r\n");
|
|
$body->write("\tBUILD-DATA:\t\t".$SelfUpdateUrl."\r\n");
|
|
$body->write("\tRECOVERY.ZIP:\t\t".$SelfUpdateZipUrl."\r\n");
|
|
$body->write("\tOS_REPO.JSON:\t\t".$RepositoryUrl."\r\n");
|
|
$body->write("\r\n");
|
|
|
|
// Show available features and configuration
|
|
$body->write("Features:\r\n\r\n");
|
|
$body->write("\tGNU Privacy Guard Support:\t\t");
|
|
if(function_exists("gnupg_verify")) {
|
|
$gpg = gnupg_init(["home-dir" => $GPGHome]);
|
|
$engineInfo = gnupg_getengineinfo($gpg);
|
|
$engineDir = $engineInfo['file_name'];
|
|
$body->write("True (Engine Path: $engineDir, Engine Home: $GPGHome)\r\n");
|
|
} else {
|
|
$body->write("False\r\n");
|
|
}
|
|
$body->write("\tGemini Protocol Support:\t\t");
|
|
if(class_exists("GeminiClient")) {
|
|
$body->write("True\r\n");
|
|
} else {
|
|
$body->write("False\r\n");
|
|
}
|
|
});
|
|
|
|
$app->run(); |