migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,177 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;
use OCP\SpeechToText\ISpeechToTextManager;
use OCP\TextProcessing\IManager;
use OCP\TextProcessing\IProvider;
use OCP\TextProcessing\ITaskType;
use OCP\Translation\ITranslationManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class ArtificialIntelligence implements IDelegatedSettings {
public function __construct(
private IConfig $config,
private IL10N $l,
private IInitialState $initialState,
private ITranslationManager $translationManager,
private ISpeechToTextManager $sttManager,
private IManager $textProcessingManager,
private ContainerInterface $container,
private \OCP\TextToImage\IManager $text2imageManager,
) {
}
/**
* @return TemplateResponse
*/
public function getForm() {
$translationProviders = [];
$translationPreferences = [];
foreach ($this->translationManager->getProviders() as $provider) {
$translationProviders[] = [
'class' => $provider::class,
'name' => $provider->getName(),
];
$translationPreferences[] = $provider::class;
}
$sttProviders = [];
foreach ($this->sttManager->getProviders() as $provider) {
$sttProviders[] = [
'class' => $provider::class,
'name' => $provider->getName(),
];
}
$textProcessingProviders = [];
/** @var array<class-string<ITaskType>, class-string<IProvider>> $textProcessingSettings */
$textProcessingSettings = [];
foreach ($this->textProcessingManager->getProviders() as $provider) {
$textProcessingProviders[] = [
'class' => $provider::class,
'name' => $provider->getName(),
'taskType' => $provider->getTaskType(),
];
$textProcessingSettings[$provider->getTaskType()] = $provider::class;
}
$textProcessingTaskTypes = [];
foreach ($textProcessingSettings as $taskTypeClass => $providerClass) {
/** @var ITaskType $taskType */
try {
$taskType = $this->container->get($taskTypeClass);
} catch (NotFoundExceptionInterface $e) {
continue;
} catch (ContainerExceptionInterface $e) {
continue;
}
$textProcessingTaskTypes[] = [
'class' => $taskTypeClass,
'name' => $taskType->getName(),
'description' => $taskType->getDescription(),
];
}
$text2imageProviders = [];
foreach ($this->text2imageManager->getProviders() as $provider) {
$text2imageProviders[] = [
'id' => $provider->getId(),
'name' => $provider->getName(),
];
}
$this->initialState->provideInitialState('ai-stt-providers', $sttProviders);
$this->initialState->provideInitialState('ai-translation-providers', $translationProviders);
$this->initialState->provideInitialState('ai-text-processing-providers', $textProcessingProviders);
$this->initialState->provideInitialState('ai-text-processing-task-types', $textProcessingTaskTypes);
$this->initialState->provideInitialState('ai-text2image-providers', $text2imageProviders);
$settings = [
'ai.stt_provider' => count($sttProviders) > 0 ? $sttProviders[0]['class'] : null,
'ai.textprocessing_provider_preferences' => $textProcessingSettings,
'ai.translation_provider_preferences' => $translationPreferences,
'ai.text2image_provider' => count($text2imageProviders) > 0 ? $text2imageProviders[0]['id'] : null,
];
foreach ($settings as $key => $defaultValue) {
$value = $defaultValue;
$json = $this->config->getAppValue('core', $key, '');
if ($json !== '') {
$value = json_decode($json, true);
switch($key) {
case 'ai.textprocessing_provider_preferences':
// fill $value with $defaultValue values
$value = array_merge($defaultValue, $value);
break;
case 'ai.translation_provider_preferences':
$value += array_diff($defaultValue, $value); // Add entries from $defaultValue that are not in $value to the end of $value
break;
default:
break;
}
}
$settings[$key] = $value;
}
$this->initialState->provideInitialState('ai-settings', $settings);
return new TemplateResponse('settings', 'settings/admin/ai');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'ai';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 10;
}
public function getName(): ?string {
return $this->l->t('Artificial Intelligence');
}
public function getAuthorizedAppConfig(): array {
return [
'core' => ['/ai..*/'],
];
}
}
@@ -0,0 +1,148 @@
<?php
/**
* @copyright Copyright (c) 2021 Carl Schwan <carl@carlschwan.eu>
*
* @author Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OCA\Settings\AppInfo\Application;
use OCA\Settings\Service\AuthorizedGroupService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\Settings\IDelegatedSettings;
use OCP\Settings\IManager;
use OCP\Settings\ISettings;
class Delegation implements ISettings {
private IManager $settingManager;
private IInitialState $initialStateService;
private IGroupManager $groupManager;
private AuthorizedGroupService $authorizedGroupService;
private IURLGenerator $urlGenerator;
public function __construct(
IManager $settingManager,
IInitialState $initialStateService,
IGroupManager $groupManager,
AuthorizedGroupService $authorizedGroupService,
IURLGenerator $urlGenerator
) {
$this->settingManager = $settingManager;
$this->initialStateService = $initialStateService;
$this->groupManager = $groupManager;
$this->authorizedGroupService = $authorizedGroupService;
$this->urlGenerator = $urlGenerator;
}
/**
* Filter out the ISettings that are not IDelegatedSettings from $innerSection
* and add them to $settings.
*
* @param IDelegatedSettings[] $settings
* @param ISettings[] $innerSection
* @return IDelegatedSettings[]
*/
private function getDelegatedSettings(array $settings, array $innerSection): array {
foreach ($innerSection as $setting) {
if ($setting instanceof IDelegatedSettings) {
$settings[] = $setting;
}
}
return $settings;
}
private function initSettingState(): void {
// Available settings page initialization
$sections = $this->settingManager->getAdminSections();
$settings = [];
foreach ($sections as $sectionPriority) {
foreach ($sectionPriority as $section) {
$sectionSettings = $this->settingManager->getAdminSettings($section->getId());
$sectionSettings = array_reduce($sectionSettings, [$this, 'getDelegatedSettings'], []);
$settings = array_merge(
$settings,
array_map(function (IDelegatedSettings $setting) use ($section) {
$sectionName = $section->getName() . ($setting->getName() !== null ? ' - ' . $setting->getName() : '');
return [
'class' => get_class($setting),
'sectionName' => $sectionName,
'id' => mb_strtolower(str_replace(' ', '-', $sectionName)),
'priority' => $section->getPriority(),
];
}, $sectionSettings)
);
}
}
usort($settings, function (array $a, array $b) {
if ($a['priority'] == $b['priority']) {
return 0;
}
return ($a['priority'] < $b['priority']) ? -1 : 1;
});
$this->initialStateService->provideInitialState('available-settings', $settings);
}
public function initAvailableGroupState(): void {
// Available groups initialization
$groups = [];
$groupsClass = $this->groupManager->search('');
foreach ($groupsClass as $group) {
if ($group->getGID() === 'admin') {
continue; // Admin already have access to everything
}
$groups[] = [
'displayName' => $group->getDisplayName(),
'gid' => $group->getGID(),
];
}
$this->initialStateService->provideInitialState('available-groups', $groups);
}
public function initAuthorizedGroupState(): void {
// Already set authorized groups
$this->initialStateService->provideInitialState('authorized-groups', $this->authorizedGroupService->findAll());
}
public function getForm(): TemplateResponse {
$this->initSettingState();
$this->initAvailableGroupState();
$this->initAuthorizedGroupState();
$this->initialStateService->provideInitialState('authorized-settings-doc-link', $this->urlGenerator->linkToDocs('admin-delegation'));
return new TemplateResponse(Application::APP_ID, 'settings/admin/delegation', [], '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'admindelegation';
}
/*
* @inheritdoc
*/
public function getPriority() {
return 75;
}
}
@@ -0,0 +1,106 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;
class Mail implements IDelegatedSettings {
/** @var IConfig */
private $config;
/** @var IL10N $l */
private $l;
/**
* @param IConfig $config
* @param IL10N $l
*/
public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
$this->l = $l;
}
/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
// Mail
'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
'mail_domain' => $this->config->getSystemValue('mail_domain', ''),
'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''),
'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''),
'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''),
'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''),
'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''),
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'),
];
if ($parameters['mail_smtppassword'] !== '') {
$parameters['mail_smtppassword'] = '********';
}
if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') {
$parameters['mail_smtpmode'] = 'smtp';
}
return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'server';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 10;
}
public function getName(): ?string {
return $this->l->t('Email server');
}
public function getAuthorizedAppConfig(): array {
return [];
}
}
@@ -0,0 +1,81 @@
<?php
/**
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;
class Overview implements IDelegatedSettings {
/** @var IConfig */
private $config;
/** @var IL10N $l*/
private $l;
public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
$this->l = $l;
}
/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
];
return new TemplateResponse('settings', 'settings/admin/overview', $parameters, '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'overview';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 10;
}
public function getName(): ?string {
return $this->l->t('Security & setup warnings');
}
public function getAuthorizedAppConfig(): array {
return [];
}
}
@@ -0,0 +1,99 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Julius Härtl <jus@bitgrid.net>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Encryption\IManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Settings\ISettings;
class Security implements ISettings {
private IManager $manager;
private IUserManager $userManager;
private MandatoryTwoFactor $mandatoryTwoFactor;
private IInitialState $initialState;
private IURLGenerator $urlGenerator;
public function __construct(IManager $manager,
IUserManager $userManager,
MandatoryTwoFactor $mandatoryTwoFactor,
IInitialState $initialState,
IURLGenerator $urlGenerator) {
$this->manager = $manager;
$this->userManager = $userManager;
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
$this->initialState = $initialState;
$this->urlGenerator = $urlGenerator;
}
/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$encryptionModules = $this->manager->getEncryptionModules();
$defaultEncryptionModuleId = $this->manager->getDefaultEncryptionModuleId();
$encryptionModuleList = [];
foreach ($encryptionModules as $module) {
$encryptionModuleList[$module['id']]['displayName'] = $module['displayName'];
$encryptionModuleList[$module['id']]['default'] = false;
if ($module['id'] === $defaultEncryptionModuleId) {
$encryptionModuleList[$module['id']]['default'] = true;
}
}
$this->initialState->provideInitialState('mandatory2FAState', $this->mandatoryTwoFactor->getState());
$this->initialState->provideInitialState('two-factor-admin-doc', $this->urlGenerator->linkToDocs('admin-2fa'));
$this->initialState->provideInitialState('encryption-enabled', $this->manager->isEnabled());
$this->initialState->provideInitialState('encryption-ready', $this->manager->isReady());
$this->initialState->provideInitialState('external-backends-enabled', count($this->userManager->getBackends()) > 1);
$this->initialState->provideInitialState('encryption-modules', $encryptionModuleList);
$this->initialState->provideInitialState('encryption-admin-doc', $this->urlGenerator->linkToDocs('admin-encryption'));
return new TemplateResponse('settings', 'settings/admin/security', [], '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection(): string {
return 'security';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority(): int {
return 10;
}
}
@@ -0,0 +1,135 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OC\Profile\ProfileManager;
use OC\Profile\TProfileHelper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IDelegatedSettings;
class Server implements IDelegatedSettings {
use TProfileHelper;
private IDBConnection $connection;
private IInitialState $initialStateService;
private ProfileManager $profileManager;
private ITimeFactory $timeFactory;
private IConfig $config;
private IL10N $l;
private IURLGenerator $urlGenerator;
public function __construct(IDBConnection $connection,
IInitialState $initialStateService,
ProfileManager $profileManager,
ITimeFactory $timeFactory,
IURLGenerator $urlGenerator,
IConfig $config,
IL10N $l) {
$this->connection = $connection;
$this->initialStateService = $initialStateService;
$this->profileManager = $profileManager;
$this->timeFactory = $timeFactory;
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
}
/**
* @return TemplateResponse
*/
public function getForm() {
// Background jobs
$this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
$this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0'));
$this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
$this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
$this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));
$this->initialStateService->provideInitialState('cliBasedCronUser', function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '');
$this->initialStateService->provideInitialState('backgroundJobsDocUrl', $this->urlGenerator->linkToDocs('admin-background-jobs'));
// Profile page
$this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
$this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));
return new TemplateResponse('settings', 'settings/admin/server', [
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
], '');
}
protected function cronMaxAge(): int {
$query = $this->connection->getQueryBuilder();
$query->select('last_checked')
->from('jobs')
->orderBy('last_checked', 'ASC')
->setMaxResults(1);
$result = $query->execute();
if ($row = $result->fetch()) {
$maxAge = (int) $row['last_checked'];
} else {
$maxAge = $this->timeFactory->getTime();
}
$result->closeCursor();
return $maxAge;
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection(): string {
return 'server';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority(): int {
return 0;
}
public function getName(): ?string {
return $this->l->t('Background jobs');
}
public function getAuthorizedAppConfig(): array {
return [
'core' => [
'/mail_general_settings/',
],
];
}
}
@@ -0,0 +1,144 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
* @author Vincent Petry <vincent@nextcloud.com>
* @author Thomas Citharel <nextcloud@tcit.fr>
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Admin;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IDelegatedSettings;
use OCP\Share\IManager;
use OCP\Util;
class Sharing implements IDelegatedSettings {
public function __construct(
private IConfig $config,
private IL10N $l,
private IManager $shareManager,
private IAppManager $appManager,
private IURLGenerator $urlGenerator,
private IInitialState $initialState,
private string $appName,
) {
}
/**
* @return TemplateResponse
*/
public function getForm() {
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '');
$excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
$parameters = [
// Built-In Sharing
'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true),
'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true),
'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [],
'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true),
'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true),
'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true),
'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true),
'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true),
'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true),
'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'),
'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),
'passwordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
'excludeGroups' => $this->getHumanBooleanConfig('core', 'shareapi_exclude_groups'),
'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'),
'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),
'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'),
'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'),
'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'),
];
$this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing'));
$this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing'));
$this->initialState->provideInitialState('sharingSettings', $parameters);
\OCP\Util::addScript($this->appName, 'vue-settings-admin-sharing');
return new TemplateResponse($this->appName, 'settings/admin/sharing', [], '');
}
/**
* Helper function to retrive boolean values from human readable strings ('yes' / 'no')
*/
private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool {
return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes';
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'sharing';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 0;
}
public function getAuthorizedAppConfig(): array {
return [
'core' => ['/shareapi_.*/'],
];
}
public function getName(): ?string {
return null;
}
}
@@ -0,0 +1,58 @@
<?php
/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
class Additional implements ISettings {
/**
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1
*/
public function getForm(): TemplateResponse {
return new TemplateResponse('settings', 'settings/empty');
}
/**
* @return string the section ID, e.g. 'sharing'
* @since 9.1
*/
public function getSection(): string {
return 'additional';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
* @since 9.1
*/
public function getPriority(): int {
return 5;
}
}
@@ -0,0 +1,375 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Christopher Ng <chrng8@gmail.com>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Citharel <nextcloud@tcit.fr>
* @author Vincent Petry <vincent@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal;
use OC\Profile\ProfileManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Files\FileInfo;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\IManager;
use OCP\Settings\ISettings;
class PersonalInfo implements ISettings {
/** @var IConfig */
private $config;
/** @var IUserManager */
private $userManager;
/** @var IAccountManager */
private $accountManager;
/** @var ProfileManager */
private $profileManager;
/** @var IGroupManager */
private $groupManager;
/** @var IAppManager */
private $appManager;
/** @var IFactory */
private $l10nFactory;
/** @var IL10N */
private $l;
/** @var IInitialState */
private $initialStateService;
/** @var IManager */
private $manager;
public function __construct(
IConfig $config,
IUserManager $userManager,
IGroupManager $groupManager,
IAccountManager $accountManager,
ProfileManager $profileManager,
IAppManager $appManager,
IFactory $l10nFactory,
IL10N $l,
IInitialState $initialStateService,
IManager $manager
) {
$this->config = $config;
$this->userManager = $userManager;
$this->accountManager = $accountManager;
$this->profileManager = $profileManager;
$this->groupManager = $groupManager;
$this->appManager = $appManager;
$this->l10nFactory = $l10nFactory;
$this->l = $l;
$this->initialStateService = $initialStateService;
$this->manager = $manager;
}
public function getForm(): TemplateResponse {
$federationEnabled = $this->appManager->isEnabledForUser('federation');
$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
$lookupServerUploadEnabled = false;
if ($federatedFileSharingEnabled) {
/** @var FederatedShareProvider $shareProvider */
$shareProvider = \OC::$server->query(FederatedShareProvider::class);
$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
}
$uid = \OC_User::getUser();
$user = $this->userManager->get($uid);
$account = $this->accountManager->getAccount($user);
// make sure FS is setup before querying storage related stuff...
\OC_Util::setupFS($user->getUID());
$storageInfo = \OC_Helper::getStorageInfo('/');
if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
$totalSpace = $this->l->t('Unlimited');
} else {
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
}
$messageParameters = $this->getMessageParameters($account);
$parameters = [
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
] + $messageParameters;
$personalInfoParameters = [
'userId' => $uid,
'avatar' => $this->getProperty($account, IAccountManager::PROPERTY_AVATAR),
'groups' => $this->getGroups($user),
'quota' => $storageInfo['quota'],
'totalSpace' => $totalSpace,
'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
'usageRelative' => round($storageInfo['relative']),
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
'emailMap' => $this->getEmailMap($account),
'phone' => $this->getProperty($account, IAccountManager::PROPERTY_PHONE),
'defaultPhoneRegion' => $this->config->getSystemValueString('default_phone_region'),
'location' => $this->getProperty($account, IAccountManager::PROPERTY_ADDRESS),
'website' => $this->getProperty($account, IAccountManager::PROPERTY_WEBSITE),
'twitter' => $this->getProperty($account, IAccountManager::PROPERTY_TWITTER),
'fediverse' => $this->getProperty($account, IAccountManager::PROPERTY_FEDIVERSE),
'languageMap' => $this->getLanguageMap($user),
'localeMap' => $this->getLocaleMap($user),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
'profileEnabled' => $this->profileManager->isProfileEnabled($user),
'organisation' => $this->getProperty($account, IAccountManager::PROPERTY_ORGANISATION),
'role' => $this->getProperty($account, IAccountManager::PROPERTY_ROLE),
'headline' => $this->getProperty($account, IAccountManager::PROPERTY_HEADLINE),
'biography' => $this->getProperty($account, IAccountManager::PROPERTY_BIOGRAPHY),
];
$accountParameters = [
'avatarChangeSupported' => $user->canChangeAvatar(),
'displayNameChangeSupported' => $user->canChangeDisplayName(),
'federationEnabled' => $federationEnabled,
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
];
$profileParameters = [
'profileConfig' => $this->profileManager->getProfileConfigWithMetadata($user, $user),
];
$this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
$this->initialStateService->provideInitialState('personalInfoParameters', $personalInfoParameters);
$this->initialStateService->provideInitialState('accountParameters', $accountParameters);
$this->initialStateService->provideInitialState('profileParameters', $profileParameters);
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
}
/**
* Check if is fair use of free push service
* @return boolean
*/
private function isFairUseOfFreePushService(): bool {
return $this->manager->isFairUseOfFreePushService();
}
/**
* returns the property data in an
* associative array
*/
private function getProperty(IAccount $account, string $property): array {
$property = [
'name' => $account->getProperty($property)->getName(),
'value' => $account->getProperty($property)->getValue(),
'scope' => $account->getProperty($property)->getScope(),
'verified' => $account->getProperty($property)->getVerified(),
];
return $property;
}
/**
* returns the section ID string, e.g. 'sharing'
* @since 9.1
*/
public function getSection(): string {
return 'personal-info';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
* @since 9.1
*/
public function getPriority(): int {
return 10;
}
/**
* returns a sorted list of the user's group GIDs
*/
private function getGroups(IUser $user): array {
$groups = array_map(
static function (IGroup $group) {
return $group->getDisplayName();
},
$this->groupManager->getUserGroups($user)
);
sort($groups);
return $groups;
}
/**
* returns the primary email and additional emails in an
* associative array
*/
private function getEmailMap(IAccount $account): array {
$systemEmail = [
'name' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getName(),
'value' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(),
'scope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(),
'verified' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(),
];
$additionalEmails = array_map(
function (IAccountProperty $property) {
return [
'name' => $property->getName(),
'value' => $property->getValue(),
'scope' => $property->getScope(),
'verified' => $property->getVerified(),
'locallyVerified' => $property->getLocallyVerified(),
];
},
$account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties(),
);
$emailMap = [
'primaryEmail' => $systemEmail,
'additionalEmails' => $additionalEmails,
'notificationEmail' => (string)$account->getUser()->getPrimaryEMailAddress(),
];
return $emailMap;
}
/**
* returns the user's active language, common languages, and other languages in an
* associative array
*/
private function getLanguageMap(IUser $user): array {
$forceLanguage = $this->config->getSystemValue('force_language', false);
if ($forceLanguage !== false) {
return [];
}
$uid = $user->getUID();
$userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
$languages = $this->l10nFactory->getLanguages();
// associate the user language with the proper array
$userLangIndex = array_search($userConfLang, array_column($languages['commonLanguages'], 'code'));
$userLang = $languages['commonLanguages'][$userLangIndex];
// search in the other languages
if ($userLangIndex === false) {
$userLangIndex = array_search($userConfLang, array_column($languages['otherLanguages'], 'code'));
$userLang = $languages['otherLanguages'][$userLangIndex];
}
// if user language is not available but set somehow: show the actual code as name
if (!is_array($userLang)) {
$userLang = [
'code' => $userConfLang,
'name' => $userConfLang,
];
}
return array_merge(
['activeLanguage' => $userLang],
$languages
);
}
private function getLocaleMap(IUser $user): array {
$forceLanguage = $this->config->getSystemValue('force_locale', false);
if ($forceLanguage !== false) {
return [];
}
$uid = $user->getUID();
$userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale());
$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
$localeCodes = $this->l10nFactory->findAvailableLocales();
$userLocale = array_filter($localeCodes, fn ($value) => $userLocaleString === $value['code']);
if (!empty($userLocale)) {
$userLocale = reset($userLocale);
}
$localesForLanguage = array_values(array_filter($localeCodes, fn ($localeCode) => str_starts_with($localeCode['code'], $userLang)));
$otherLocales = array_values(array_filter($localeCodes, fn ($localeCode) => !str_starts_with($localeCode['code'], $userLang)));
if (!$userLocale) {
$userLocale = [
'code' => 'en',
'name' => 'English'
];
}
return [
'activeLocaleLang' => $userLocaleString,
'activeLocale' => $userLocale,
'localesForLanguage' => $localesForLanguage,
'otherLocales' => $otherLocales,
];
}
/**
* returns the message parameters
*/
private function getMessageParameters(IAccount $account): array {
$needVerifyMessage = [IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER];
$messageParameters = [];
foreach ($needVerifyMessage as $property) {
switch ($account->getProperty($property)->getVerified()) {
case IAccountManager::VERIFIED:
$message = $this->l->t('Verifying');
break;
case IAccountManager::VERIFICATION_IN_PROGRESS:
$message = $this->l->t('Verifying …');
break;
default:
$message = $this->l->t('Verify');
}
$messageParameters[$property . 'Message'] = $message;
}
return $messageParameters;
}
}
@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal\Security;
use OC\Authentication\Token\INamedToken;
use OC\Authentication\Token\IProvider as IAuthTokenProvider;
use OC\Authentication\Token\IToken;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\Exceptions\InvalidTokenException;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\Settings\ISettings;
use function array_map;
class Authtokens implements ISettings {
/** @var IAuthTokenProvider */
private $tokenProvider;
/** @var ISession */
private $session;
/** @var IInitialState */
private $initialState;
/** @var string|null */
private $uid;
/** @var IUserSession */
private $userSession;
public function __construct(IAuthTokenProvider $tokenProvider,
ISession $session,
IUserSession $userSession,
IInitialState $initialState,
?string $UserId) {
$this->tokenProvider = $tokenProvider;
$this->session = $session;
$this->initialState = $initialState;
$this->uid = $UserId;
$this->userSession = $userSession;
}
public function getForm(): TemplateResponse {
$this->initialState->provideInitialState(
'app_tokens',
$this->getAppTokens()
);
$this->initialState->provideInitialState(
'can_create_app_token',
$this->userSession->getImpersonatingUserID() === null
);
return new TemplateResponse('settings', 'settings/personal/security/authtokens');
}
public function getSection(): string {
return 'security';
}
public function getPriority(): int {
return 100;
}
private function getAppTokens(): array {
$tokens = $this->tokenProvider->getTokenByUser($this->uid);
try {
$sessionId = $this->session->getId();
} catch (SessionNotAvailableException $ex) {
return [];
}
try {
$sessionToken = $this->tokenProvider->getToken($sessionId);
} catch (InvalidTokenException $ex) {
return [];
}
return array_map(function (IToken $token) use ($sessionToken) {
$data = $token->jsonSerialize();
$data['canDelete'] = true;
$data['canRename'] = $token instanceof INamedToken && $data['type'] !== IToken::WIPE_TOKEN;
if ($sessionToken->getId() === $token->getId()) {
$data['canDelete'] = false;
$data['canRename'] = false;
$data['current'] = true;
}
return $data;
}, $tokens);
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Julius Härtl <jus@bitgrid.net>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal\Security;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IUserManager;
use OCP\Settings\ISettings;
class Password implements ISettings {
/** @var IUserManager */
private $userManager;
/** @var string|null */
private $uid;
public function __construct(IUserManager $userManager,
?string $UserId) {
$this->userManager = $userManager;
$this->uid = $UserId;
}
public function getForm(): TemplateResponse {
$user = $this->userManager->get($this->uid);
$passwordChangeSupported = false;
if ($user !== null) {
$passwordChangeSupported = $user->canChangePassword();
}
return new TemplateResponse('settings', 'settings/personal/security/password', [
'passwordChangeSupported' => $passwordChangeSupported,
]);
}
public function getSection(): string {
return 'security';
}
public function getPriority(): int {
return 10;
}
}
@@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal\Security;
use Exception;
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\Authentication\TwoFactorAuth\IProvidesPersonalSettings;
use OCP\IConfig;
use OCP\IUserSession;
use OCP\Settings\ISettings;
use function array_filter;
use function array_map;
use function is_null;
class TwoFactor implements ISettings {
/** @var ProviderLoader */
private $providerLoader;
/** @var MandatoryTwoFactor */
private $mandatoryTwoFactor;
/** @var IUserSession */
private $userSession;
/** @var string|null */
private $uid;
/** @var IConfig */
private $config;
public function __construct(ProviderLoader $providerLoader,
MandatoryTwoFactor $mandatoryTwoFactor,
IUserSession $userSession,
IConfig $config,
?string $UserId) {
$this->providerLoader = $providerLoader;
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
$this->userSession = $userSession;
$this->uid = $UserId;
$this->config = $config;
}
public function getForm(): TemplateResponse {
return new TemplateResponse('settings', 'settings/personal/security/twofactor', [
'twoFactorProviderData' => $this->getTwoFactorProviderData(),
]);
}
public function getSection(): ?string {
if (!$this->shouldShow()) {
return null;
}
return 'security';
}
public function getPriority(): int {
return 15;
}
private function shouldShow(): bool {
$user = $this->userSession->getUser();
if (is_null($user)) {
// Actually impossible, but still …
return false;
}
// Anyone who's supposed to use 2FA should see 2FA settings
if ($this->mandatoryTwoFactor->isEnforcedFor($user)) {
return true;
}
// If there is at least one provider with personal settings but it's not
// the backup codes provider, then these settings should show.
try {
$providers = $this->providerLoader->getProviders($user);
} catch (Exception $e) {
// Let's hope for the best
return true;
}
foreach ($providers as $provider) {
if ($provider instanceof IProvidesPersonalSettings
&& !($provider instanceof BackupCodesProvider)) {
return true;
}
}
return false;
}
private function getTwoFactorProviderData(): array {
$user = $this->userSession->getUser();
if (is_null($user)) {
// Actually impossible, but still …
return [];
}
return [
'providers' => array_map(function (IProvidesPersonalSettings $provider) use ($user) {
return [
'provider' => $provider,
'settings' => $provider->getPersonalSettings($user)
];
}, array_filter($this->providerLoader->getProviders($user), function (IProvider $provider) {
return $provider instanceof IProvidesPersonalSettings;
}))
];
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal\Security;
use OC\Authentication\WebAuthn\Db\PublicKeyCredentialMapper;
use OC\Authentication\WebAuthn\Manager;
use OCA\Settings\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\Settings\ISettings;
class WebAuthn implements ISettings {
/** @var PublicKeyCredentialMapper */
private $mapper;
/** @var string */
private $uid;
/** @var IInitialStateService */
private $initialStateService;
/** @var Manager */
private $manager;
public function __construct(PublicKeyCredentialMapper $mapper,
string $UserId,
IInitialStateService $initialStateService,
Manager $manager) {
$this->mapper = $mapper;
$this->uid = $UserId;
$this->initialStateService = $initialStateService;
$this->manager = $manager;
}
public function getForm() {
$this->initialStateService->provideInitialState(
Application::APP_ID,
'webauthn-devices',
$this->mapper->findAllForUid($this->uid)
);
return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
]);
}
public function getSection(): ?string {
if (!$this->manager->isWebAuthnAvailable()) {
return null;
}
return 'security';
}
public function getPriority(): int {
return 20;
}
}
@@ -0,0 +1,120 @@
<?php
/**
* @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Jan C. Borchardt <hey@jancborchardt.net>
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\Settings\Personal;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Settings\ISettings;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;
class ServerDevNotice implements ISettings {
/** @var IRegistry */
private $registry;
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var IRootFolder */
private $rootFolder;
/** @var IUserSession */
private $userSession;
/** @var IInitialState */
private $initialState;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(IRegistry $registry,
IEventDispatcher $eventDispatcher,
IRootFolder $rootFolder,
IUserSession $userSession,
IInitialState $initialState,
IURLGenerator $urlGenerator) {
$this->registry = $registry;
$this->eventDispatcher = $eventDispatcher;
$this->rootFolder = $rootFolder;
$this->userSession = $userSession;
$this->initialState = $initialState;
$this->urlGenerator = $urlGenerator;
}
/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$userFolder = $this->rootFolder->getUserFolder($this->userSession->getUser()->getUID());
$hasInitialState = false;
// If the Reasons to use Nextcloud.pdf file is here, let's init Viewer, also check that Viewer is there
if (class_exists(LoadViewer::class) && $userFolder->nodeExists('Reasons to use Nextcloud.pdf')) {
/**
* @psalm-suppress UndefinedClass, InvalidArgument
*/
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
$hasInitialState = true;
}
// Always load the script
Util::addScript('settings', 'vue-settings-nextcloud-pdf');
$this->initialState->provideInitialState('has-reasons-use-nextcloud-pdf', $hasInitialState);
return new TemplateResponse('settings', 'settings/personal/development.notice', [
'reasons-use-nextcloud-pdf-link' => $this->urlGenerator->linkToRoute('settings.Reasons.getPdf')
]);
}
/**
* @return string|null the section ID, e.g. 'sharing'
*/
public function getSection(): ?string {
if ($this->registry->delegateHasValidSubscription()) {
return null;
}
return 'personal-info';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority(): int {
return 1000;
}
}