@@ -46,7 +46,7 @@ |
||
| 46 | 46 | <label for="release-channel"><?php p($l->t('Update channel:')) ?></label> |
| 47 | 47 | <select id="release-channel"> |
| 48 | 48 | <option value="<?php p($currentChannel); ?>"><?php p($currentChannel); ?></option> |
| 49 | - <?php foreach ($channels as $channel => $channelTitle){ ?> |
|
| 49 | + <?php foreach ($channels as $channel => $channelTitle) { ?> |
|
| 50 | 50 | <option value="<?php p($channelTitle) ?>"> |
| 51 | 51 | <?php p($channelTitle) ?> |
| 52 | 52 | </option> |
@@ -61,10 +61,19 @@ |
||
| 61 | 61 | <p id="oca_updatenotification_groups"> |
| 62 | 62 | <?php p($l->t('Notify members of the following groups about available updates:')); ?> |
| 63 | 63 | <input name="oca_updatenotification_groups_list" type="hidden" id="oca_updatenotification_groups_list" value="<?php p($_['notify_groups']) ?>" style="width: 400px"><br /> |
| 64 | - <em class="<?php if (!in_array($currentChannel, ['daily', 'git'])) p('hidden'); ?>"> |
|
| 64 | + <em class="<?php if (!in_array($currentChannel, ['daily', 'git'])) { |
|
| 65 | + p('hidden'); |
|
| 66 | +} |
|
| 67 | +?>"> |
|
| 65 | 68 | <?php p($l->t('Only notification for app updates are available.')); ?> |
| 66 | - <?php if ($currentChannel === 'daily') p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); ?> |
|
| 67 | - <?php if ($currentChannel === 'git') p($l->t('The selected update channel does not support updates of the server.')); ?> |
|
| 69 | + <?php if ($currentChannel === 'daily') { |
|
| 70 | + p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); |
|
| 71 | +} |
|
| 72 | +?> |
|
| 73 | + <?php if ($currentChannel === 'git') { |
|
| 74 | + p($l->t('The selected update channel does not support updates of the server.')); |
|
| 75 | +} |
|
| 76 | +?> |
|
| 68 | 77 | </em> |
| 69 | 78 | </p> |
| 70 | 79 | </form> |
@@ -1,24 +1,24 @@ |
||
| 1 | 1 | <?php |
| 2 | - script('updatenotification', 'admin'); |
|
| 3 | - style('updatenotification', 'admin'); |
|
| 2 | + script('updatenotification', 'admin'); |
|
| 3 | + style('updatenotification', 'admin'); |
|
| 4 | 4 | |
| 5 | - /** @var array $_ */ |
|
| 6 | - /** @var bool $isNewVersionAvailable */ |
|
| 7 | - $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
| 8 | - /** @var string $newVersionString */ |
|
| 9 | - $newVersionString = $_['newVersionString']; |
|
| 10 | - /** @var bool $isUpdateChecked */ |
|
| 11 | - $isUpdateChecked = $_['isUpdateChecked']; |
|
| 12 | - /** @var string $lastCheckedDate */ |
|
| 13 | - $lastCheckedDate = $_['lastChecked']; |
|
| 14 | - /** @var array $channels */ |
|
| 15 | - $channels = $_['channels']; |
|
| 16 | - /** @var string $currentChannel */ |
|
| 17 | - $currentChannel = $_['currentChannel']; |
|
| 18 | - /** @var string $updateServerURL */ |
|
| 19 | - $updateServerURL = $_['updateServerURL']; |
|
| 20 | - /** @var bool $isDefaultUpdateServerURL */ |
|
| 21 | - $isDefaultUpdateServerURL = $_['isDefaultUpdateServerURL']; |
|
| 5 | + /** @var array $_ */ |
|
| 6 | + /** @var bool $isNewVersionAvailable */ |
|
| 7 | + $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
| 8 | + /** @var string $newVersionString */ |
|
| 9 | + $newVersionString = $_['newVersionString']; |
|
| 10 | + /** @var bool $isUpdateChecked */ |
|
| 11 | + $isUpdateChecked = $_['isUpdateChecked']; |
|
| 12 | + /** @var string $lastCheckedDate */ |
|
| 13 | + $lastCheckedDate = $_['lastChecked']; |
|
| 14 | + /** @var array $channels */ |
|
| 15 | + $channels = $_['channels']; |
|
| 16 | + /** @var string $currentChannel */ |
|
| 17 | + $currentChannel = $_['currentChannel']; |
|
| 18 | + /** @var string $updateServerURL */ |
|
| 19 | + $updateServerURL = $_['updateServerURL']; |
|
| 20 | + /** @var bool $isDefaultUpdateServerURL */ |
|
| 21 | + $isDefaultUpdateServerURL = $_['isDefaultUpdateServerURL']; |
|
| 22 | 22 | ?> |
| 23 | 23 | <form id="oca_updatenotification_section" class="followupsection"> |
| 24 | 24 | <p> |
@@ -37,143 +37,143 @@ |
||
| 37 | 37 | use OCP\Settings\ISettings; |
| 38 | 38 | |
| 39 | 39 | class AdminController extends Controller implements ISettings { |
| 40 | - /** @var IJobList */ |
|
| 41 | - private $jobList; |
|
| 42 | - /** @var ISecureRandom */ |
|
| 43 | - private $secureRandom; |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - private $config; |
|
| 46 | - /** @var ITimeFactory */ |
|
| 47 | - private $timeFactory; |
|
| 48 | - /** @var UpdateChecker */ |
|
| 49 | - private $updateChecker; |
|
| 50 | - /** @var IL10N */ |
|
| 51 | - private $l10n; |
|
| 52 | - /** @var IDateTimeFormatter */ |
|
| 53 | - private $dateTimeFormatter; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $appName |
|
| 57 | - * @param IRequest $request |
|
| 58 | - * @param IJobList $jobList |
|
| 59 | - * @param ISecureRandom $secureRandom |
|
| 60 | - * @param IConfig $config |
|
| 61 | - * @param ITimeFactory $timeFactory |
|
| 62 | - * @param IL10N $l10n |
|
| 63 | - * @param UpdateChecker $updateChecker |
|
| 64 | - * @param IDateTimeFormatter $dateTimeFormatter |
|
| 65 | - */ |
|
| 66 | - public function __construct($appName, |
|
| 67 | - IRequest $request, |
|
| 68 | - IJobList $jobList, |
|
| 69 | - ISecureRandom $secureRandom, |
|
| 70 | - IConfig $config, |
|
| 71 | - ITimeFactory $timeFactory, |
|
| 72 | - IL10N $l10n, |
|
| 73 | - UpdateChecker $updateChecker, |
|
| 74 | - IDateTimeFormatter $dateTimeFormatter) { |
|
| 75 | - parent::__construct($appName, $request); |
|
| 76 | - $this->jobList = $jobList; |
|
| 77 | - $this->secureRandom = $secureRandom; |
|
| 78 | - $this->config = $config; |
|
| 79 | - $this->timeFactory = $timeFactory; |
|
| 80 | - $this->l10n = $l10n; |
|
| 81 | - $this->updateChecker = $updateChecker; |
|
| 82 | - $this->dateTimeFormatter = $dateTimeFormatter; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return TemplateResponse |
|
| 87 | - */ |
|
| 88 | - public function displayPanel() { |
|
| 89 | - $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 90 | - $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); |
|
| 91 | - |
|
| 92 | - $channels = [ |
|
| 93 | - 'daily', |
|
| 94 | - 'beta', |
|
| 95 | - 'stable', |
|
| 96 | - 'production', |
|
| 97 | - ]; |
|
| 98 | - $currentChannel = \OCP\Util::getChannel(); |
|
| 99 | - |
|
| 100 | - // Remove the currently used channel from the channels list |
|
| 101 | - if(($key = array_search($currentChannel, $channels)) !== false) { |
|
| 102 | - unset($channels[$key]); |
|
| 103 | - } |
|
| 104 | - $updateState = $this->updateChecker->getUpdateState(); |
|
| 105 | - |
|
| 106 | - $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 107 | - |
|
| 108 | - $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; |
|
| 109 | - $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); |
|
| 110 | - |
|
| 111 | - $params = [ |
|
| 112 | - 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
| 113 | - 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, |
|
| 114 | - 'lastChecked' => $lastUpdateCheck, |
|
| 115 | - 'currentChannel' => $currentChannel, |
|
| 116 | - 'channels' => $channels, |
|
| 117 | - 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
| 118 | - 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
| 119 | - 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
| 120 | - 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, |
|
| 121 | - 'updateServerURL' => $updateServerURL, |
|
| 122 | - 'notify_groups' => implode('|', $notifyGroups), |
|
| 123 | - ]; |
|
| 124 | - |
|
| 125 | - return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @UseSession |
|
| 130 | - * |
|
| 131 | - * @param string $channel |
|
| 132 | - * @return DataResponse |
|
| 133 | - */ |
|
| 134 | - public function setChannel($channel) { |
|
| 135 | - \OCP\Util::setChannel($channel); |
|
| 136 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 137 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return DataResponse |
|
| 142 | - */ |
|
| 143 | - public function createCredentials() { |
|
| 144 | - // Create a new job and store the creation date |
|
| 145 | - $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
| 146 | - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 147 | - |
|
| 148 | - // Create a new token |
|
| 149 | - $newToken = $this->secureRandom->generate(64); |
|
| 150 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 151 | - |
|
| 152 | - return new DataResponse($newToken); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 157 | - */ |
|
| 158 | - public function getForm() { |
|
| 159 | - return $this->displayPanel(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return string the section ID, e.g. 'sharing' |
|
| 164 | - */ |
|
| 165 | - public function getSection() { |
|
| 166 | - return 'server'; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return int whether the form should be rather on the top or bottom of |
|
| 171 | - * the admin section. The forms are arranged in ascending order of the |
|
| 172 | - * priority values. It is required to return a value between 0 and 100. |
|
| 173 | - * |
|
| 174 | - * E.g.: 70 |
|
| 175 | - */ |
|
| 176 | - public function getPriority() { |
|
| 177 | - return 1; |
|
| 178 | - } |
|
| 40 | + /** @var IJobList */ |
|
| 41 | + private $jobList; |
|
| 42 | + /** @var ISecureRandom */ |
|
| 43 | + private $secureRandom; |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + private $config; |
|
| 46 | + /** @var ITimeFactory */ |
|
| 47 | + private $timeFactory; |
|
| 48 | + /** @var UpdateChecker */ |
|
| 49 | + private $updateChecker; |
|
| 50 | + /** @var IL10N */ |
|
| 51 | + private $l10n; |
|
| 52 | + /** @var IDateTimeFormatter */ |
|
| 53 | + private $dateTimeFormatter; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $appName |
|
| 57 | + * @param IRequest $request |
|
| 58 | + * @param IJobList $jobList |
|
| 59 | + * @param ISecureRandom $secureRandom |
|
| 60 | + * @param IConfig $config |
|
| 61 | + * @param ITimeFactory $timeFactory |
|
| 62 | + * @param IL10N $l10n |
|
| 63 | + * @param UpdateChecker $updateChecker |
|
| 64 | + * @param IDateTimeFormatter $dateTimeFormatter |
|
| 65 | + */ |
|
| 66 | + public function __construct($appName, |
|
| 67 | + IRequest $request, |
|
| 68 | + IJobList $jobList, |
|
| 69 | + ISecureRandom $secureRandom, |
|
| 70 | + IConfig $config, |
|
| 71 | + ITimeFactory $timeFactory, |
|
| 72 | + IL10N $l10n, |
|
| 73 | + UpdateChecker $updateChecker, |
|
| 74 | + IDateTimeFormatter $dateTimeFormatter) { |
|
| 75 | + parent::__construct($appName, $request); |
|
| 76 | + $this->jobList = $jobList; |
|
| 77 | + $this->secureRandom = $secureRandom; |
|
| 78 | + $this->config = $config; |
|
| 79 | + $this->timeFactory = $timeFactory; |
|
| 80 | + $this->l10n = $l10n; |
|
| 81 | + $this->updateChecker = $updateChecker; |
|
| 82 | + $this->dateTimeFormatter = $dateTimeFormatter; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return TemplateResponse |
|
| 87 | + */ |
|
| 88 | + public function displayPanel() { |
|
| 89 | + $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 90 | + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); |
|
| 91 | + |
|
| 92 | + $channels = [ |
|
| 93 | + 'daily', |
|
| 94 | + 'beta', |
|
| 95 | + 'stable', |
|
| 96 | + 'production', |
|
| 97 | + ]; |
|
| 98 | + $currentChannel = \OCP\Util::getChannel(); |
|
| 99 | + |
|
| 100 | + // Remove the currently used channel from the channels list |
|
| 101 | + if(($key = array_search($currentChannel, $channels)) !== false) { |
|
| 102 | + unset($channels[$key]); |
|
| 103 | + } |
|
| 104 | + $updateState = $this->updateChecker->getUpdateState(); |
|
| 105 | + |
|
| 106 | + $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 107 | + |
|
| 108 | + $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; |
|
| 109 | + $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); |
|
| 110 | + |
|
| 111 | + $params = [ |
|
| 112 | + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
| 113 | + 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, |
|
| 114 | + 'lastChecked' => $lastUpdateCheck, |
|
| 115 | + 'currentChannel' => $currentChannel, |
|
| 116 | + 'channels' => $channels, |
|
| 117 | + 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
| 118 | + 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
| 119 | + 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
| 120 | + 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, |
|
| 121 | + 'updateServerURL' => $updateServerURL, |
|
| 122 | + 'notify_groups' => implode('|', $notifyGroups), |
|
| 123 | + ]; |
|
| 124 | + |
|
| 125 | + return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @UseSession |
|
| 130 | + * |
|
| 131 | + * @param string $channel |
|
| 132 | + * @return DataResponse |
|
| 133 | + */ |
|
| 134 | + public function setChannel($channel) { |
|
| 135 | + \OCP\Util::setChannel($channel); |
|
| 136 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 137 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return DataResponse |
|
| 142 | + */ |
|
| 143 | + public function createCredentials() { |
|
| 144 | + // Create a new job and store the creation date |
|
| 145 | + $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
| 146 | + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 147 | + |
|
| 148 | + // Create a new token |
|
| 149 | + $newToken = $this->secureRandom->generate(64); |
|
| 150 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 151 | + |
|
| 152 | + return new DataResponse($newToken); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 157 | + */ |
|
| 158 | + public function getForm() { |
|
| 159 | + return $this->displayPanel(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return string the section ID, e.g. 'sharing' |
|
| 164 | + */ |
|
| 165 | + public function getSection() { |
|
| 166 | + return 'server'; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return int whether the form should be rather on the top or bottom of |
|
| 171 | + * the admin section. The forms are arranged in ascending order of the |
|
| 172 | + * priority values. It is required to return a value between 0 and 100. |
|
| 173 | + * |
|
| 174 | + * E.g.: 70 |
|
| 175 | + */ |
|
| 176 | + public function getPriority() { |
|
| 177 | + return 1; |
|
| 178 | + } |
|
| 179 | 179 | } |