2016-02-09 18:58:29 +00:00
|
|
|
<?php
|
2019-12-03 18:57:53 +00:00
|
|
|
|
2018-01-17 12:42:02 +00:00
|
|
|
declare(strict_types=1);
|
2019-12-03 18:57:53 +00:00
|
|
|
|
2016-02-09 18:58:29 +00:00
|
|
|
/**
|
2024-05-30 18:13:41 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-09 18:58:29 +00:00
|
|
|
*/
|
|
|
|
namespace OCA\UpdateNotification\Controller;
|
|
|
|
|
2024-03-02 20:04:56 +00:00
|
|
|
use OCA\UpdateNotification\BackgroundJob\ResetToken;
|
2016-02-09 18:58:29 +00:00
|
|
|
use OCP\AppFramework\Controller;
|
2021-02-17 08:34:01 +00:00
|
|
|
use OCP\AppFramework\Http;
|
2016-02-09 18:58:29 +00:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
2024-03-02 20:04:56 +00:00
|
|
|
use OCP\IAppConfig;
|
2016-02-09 18:58:29 +00:00
|
|
|
use OCP\IConfig;
|
2016-03-04 12:56:13 +00:00
|
|
|
use OCP\IL10N;
|
2016-02-09 18:58:29 +00:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\Security\ISecureRandom;
|
2018-01-11 10:38:26 +00:00
|
|
|
use OCP\Util;
|
2016-02-09 18:58:29 +00:00
|
|
|
|
2018-01-15 11:06:03 +00:00
|
|
|
class AdminController extends Controller {
|
2016-02-09 18:58:29 +00:00
|
|
|
|
2024-03-02 20:04:56 +00:00
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
2016-02-09 18:58:29 +00:00
|
|
|
IRequest $request,
|
2024-03-02 20:04:56 +00:00
|
|
|
private IJobList $jobList,
|
|
|
|
private ISecureRandom $secureRandom,
|
|
|
|
private IConfig $config,
|
|
|
|
private IAppConfig $appConfig,
|
|
|
|
private ITimeFactory $timeFactory,
|
|
|
|
private IL10N $l10n,
|
|
|
|
) {
|
2016-02-09 18:58:29 +00:00
|
|
|
parent::__construct($appName, $request);
|
2016-03-04 12:56:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 08:34:01 +00:00
|
|
|
private function isUpdaterEnabled() {
|
|
|
|
return !$this->config->getSystemValue('upgrade.disable-web', false);
|
|
|
|
}
|
|
|
|
|
2016-03-04 12:56:13 +00:00
|
|
|
/**
|
|
|
|
* @param string $channel
|
|
|
|
* @return DataResponse
|
|
|
|
*/
|
2018-01-17 12:42:02 +00:00
|
|
|
public function setChannel(string $channel): DataResponse {
|
2018-01-11 10:38:26 +00:00
|
|
|
Util::setChannel($channel);
|
2024-03-02 20:04:56 +00:00
|
|
|
$this->appConfig->setValueInt('core', 'lastupdatedat', 0);
|
2016-09-07 14:38:12 +00:00
|
|
|
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
|
2016-02-09 18:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DataResponse
|
|
|
|
*/
|
2018-01-17 12:42:02 +00:00
|
|
|
public function createCredentials(): DataResponse {
|
2021-02-17 08:34:01 +00:00
|
|
|
if (!$this->isUpdaterEnabled()) {
|
|
|
|
return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Web updater is disabled')], Http::STATUS_FORBIDDEN);
|
|
|
|
}
|
|
|
|
|
2016-02-09 18:58:29 +00:00
|
|
|
// Create a new job and store the creation date
|
2024-03-02 20:04:56 +00:00
|
|
|
$this->jobList->add(ResetToken::class);
|
|
|
|
$this->appConfig->setValueInt('core', 'updater.secret.created', $this->timeFactory->getTime());
|
2016-02-09 18:58:29 +00:00
|
|
|
|
|
|
|
// Create a new token
|
2016-02-10 13:41:47 +00:00
|
|
|
$newToken = $this->secureRandom->generate(64);
|
|
|
|
$this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
|
2016-02-09 18:58:29 +00:00
|
|
|
|
|
|
|
return new DataResponse($newToken);
|
|
|
|
}
|
|
|
|
}
|