2016-07-13 23:04:49 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2024-10-28 21:39:14 +03:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-07-13 23:04:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-04-15 00:45:12 +03:00
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
2021-06-25 09:41:48 +03:00
|
|
|
require_once __DIR__ . '/src/Response.php';
|
2016-07-13 23:04:49 +03:00
|
|
|
|
|
|
|
// Set Content-Type to XML
|
|
|
|
header('Content-Type: application/xml');
|
|
|
|
// Enforce browser based XSS filters
|
|
|
|
header('X-XSS-Protection: 1; mode=block');
|
|
|
|
// Disable sniffing the content type for IE
|
|
|
|
header('X-Content-Type-Options: nosniff');
|
|
|
|
// Disallow iFraming from other domains
|
|
|
|
header('X-Frame-Options: Sameorigin');
|
|
|
|
// https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag
|
|
|
|
header('X-Robots-Tag: none');
|
|
|
|
|
2019-04-15 15:28:07 +03:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' &&
|
|
|
|
isset($_SERVER['PATH_INFO']) &&
|
|
|
|
substr($_SERVER['PATH_INFO'], -5) === '/hook' &&
|
|
|
|
isset($_SERVER['HTTP_X_HUB_SIGNATURE']) &&
|
|
|
|
isset($_SERVER['HTTP_X_GITHUB_EVENT']) &&
|
|
|
|
$_SERVER['HTTP_X_GITHUB_EVENT'] === 'push') {
|
|
|
|
|
|
|
|
if (!file_exists(__DIR__ . '/config/secrets.php')) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$config = new \ClientUpdateServer\Config(__DIR__ . '/config/secrets.php');
|
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$webhookSecret = $config->get('githubWebhookSecret');
|
|
|
|
$branch = $config->get('githubWebhookBranch');
|
|
|
|
if (!is_string($webhookSecret) || !is_string($branch)) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$body = file_get_contents('php://input');
|
|
|
|
$expectedSecretHeader = $_SERVER['HTTP_X_HUB_SIGNATURE'];
|
|
|
|
$actualSecret = 'sha1=' . hash_hmac('sha1', $body, $webhookSecret);
|
|
|
|
|
|
|
|
if ($actualSecret !== $expectedSecretHeader) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = json_decode($body, true);
|
|
|
|
|
|
|
|
if (!is_array($data)) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['ref']) && $data['ref'] === 'refs/heads/' . $branch) {
|
|
|
|
$escapedDir = escapeshellarg(__DIR__);
|
2022-04-15 00:45:12 +03:00
|
|
|
exec("cd $escapedDir && git pull && composer update --no-dev");
|
2019-04-15 15:28:07 +03:00
|
|
|
echo "Deployed";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:04:49 +03:00
|
|
|
// Read parameters
|
2016-08-22 11:36:09 +03:00
|
|
|
$oem = isset($_GET['oem']) ? (string)$_GET['oem'] : null;
|
2016-07-13 23:04:49 +03:00
|
|
|
$platform = isset($_GET['platform']) ? (string)$_GET['platform'] : null;
|
2020-12-22 16:34:48 +03:00
|
|
|
$buildArch = isset($_GET['buildArch']) ? (string)$_GET['buildArch'] : "x86_64";
|
|
|
|
$currentArch = isset($_GET['currentArch']) ? (string)$_GET['currentArch'] : "x86_64";
|
2016-07-13 23:04:49 +03:00
|
|
|
$version = isset($_GET['version']) ? (string)$_GET['version'] : null;
|
|
|
|
$isSparkle = isset($_GET['sparkle']) ? true : false;
|
2024-04-23 17:55:15 +03:00
|
|
|
$isFileProvider = isset($_GET['fileprovider']) ? true : false;
|
2022-01-27 17:20:06 +03:00
|
|
|
$channel = isset($_GET['channel']) ? (string)$_GET['channel'] : 'stable';
|
2016-08-22 11:36:09 +03:00
|
|
|
|
2024-08-27 16:40:03 +03:00
|
|
|
$osRelease = isset($_GET['osRelease']) ? (string)$_GET['osRelease'] : '';
|
|
|
|
$osVersion = isset($_GET['osVersion']) ? (string)$_GET['osVersion'] : '';
|
|
|
|
$kernelVersion = isset($_GET['kernelVersion']) ? (string)$_GET['kernelVersion'] : '';
|
2024-08-27 16:24:54 +03:00
|
|
|
|
2016-08-22 11:36:09 +03:00
|
|
|
if($oem === null || $platform === null || $version === null) {
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:04:49 +03:00
|
|
|
$config = require_once __DIR__ . '/config/config.php';
|
|
|
|
|
|
|
|
// Deliver update
|
|
|
|
$response = new \ClientUpdateServer\Response(
|
|
|
|
$oem,
|
|
|
|
$platform,
|
|
|
|
$version,
|
2024-08-27 16:24:54 +03:00
|
|
|
$osRelease,
|
|
|
|
$osVersion,
|
|
|
|
$kernelVersion,
|
2022-01-27 17:20:06 +03:00
|
|
|
$channel,
|
2016-07-13 23:04:49 +03:00
|
|
|
$isSparkle,
|
2024-08-27 16:24:54 +03:00
|
|
|
$isFileProvider,
|
2016-07-13 23:04:49 +03:00
|
|
|
$config
|
|
|
|
);
|
|
|
|
echo $response->buildResponse();
|