2014-10-03 13:14:22 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2015-03-26 10:44:34 +00:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-10-03 13:14:22 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-10-03 13:14:22 +00:00
|
|
|
namespace OC\Settings;
|
|
|
|
|
2016-10-27 15:41:15 +00:00
|
|
|
use OC\AppFramework\Utility\TimeFactory;
|
2016-10-05 14:31:28 +00:00
|
|
|
use OC\Authentication\Token\IProvider;
|
2016-04-25 12:56:11 +00:00
|
|
|
use OC\Server;
|
2017-04-12 13:19:45 +00:00
|
|
|
use OC\Settings\Activity\Provider;
|
2017-05-16 07:37:21 +00:00
|
|
|
use OC\Settings\Activity\SecurityFilter;
|
|
|
|
use OC\Settings\Activity\SecurityProvider;
|
|
|
|
use OC\Settings\Activity\SecuritySetting;
|
2017-04-12 13:19:45 +00:00
|
|
|
use OC\Settings\Activity\Setting;
|
2017-04-07 12:51:05 +00:00
|
|
|
use OC\Settings\Mailer\NewUserMailHelper;
|
2014-12-04 13:15:55 +00:00
|
|
|
use OC\Settings\Middleware\SubadminMiddleware;
|
2016-05-18 10:03:22 +00:00
|
|
|
use OCP\AppFramework\App;
|
2017-04-07 20:42:43 +00:00
|
|
|
use OCP\Defaults;
|
2014-12-04 13:15:55 +00:00
|
|
|
use OCP\IContainer;
|
2016-10-05 14:31:28 +00:00
|
|
|
use OCP\Settings\IManager;
|
2016-05-18 10:03:22 +00:00
|
|
|
use OCP\Util;
|
2014-10-03 13:14:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OC\Settings
|
|
|
|
*/
|
|
|
|
class Application extends App {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $urlParams
|
|
|
|
*/
|
2015-03-26 13:51:33 +00:00
|
|
|
public function __construct(array $urlParams=[]){
|
2014-10-03 13:14:22 +00:00
|
|
|
parent::__construct('settings', $urlParams);
|
|
|
|
|
|
|
|
$container = $this->getContainer();
|
|
|
|
|
2016-10-05 14:31:28 +00:00
|
|
|
// Register Middleware
|
|
|
|
$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
|
2016-11-22 12:33:23 +00:00
|
|
|
$container->registerMiddleWare('SubadminMiddleware');
|
|
|
|
|
2014-10-03 13:14:22 +00:00
|
|
|
/**
|
|
|
|
* Core class wrappers
|
|
|
|
*/
|
2014-12-04 13:15:55 +00:00
|
|
|
/** FIXME: Remove once OC_User is non-static and mockable */
|
2016-10-05 14:31:28 +00:00
|
|
|
$container->registerService('isAdmin', function() {
|
2014-12-04 13:15:55 +00:00
|
|
|
return \OC_User::isAdminUser(\OC_User::getUser());
|
|
|
|
});
|
|
|
|
/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
|
2016-10-05 14:31:28 +00:00
|
|
|
$container->registerService('isSubAdmin', function(IContainer $c) {
|
2015-10-27 13:09:45 +00:00
|
|
|
$userObject = \OC::$server->getUserSession()->getUser();
|
|
|
|
$isSubAdmin = false;
|
|
|
|
if($userObject !== null) {
|
|
|
|
$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
|
|
|
|
}
|
|
|
|
return $isSubAdmin;
|
2015-01-30 13:16:16 +00:00
|
|
|
});
|
2016-10-05 14:31:28 +00:00
|
|
|
$container->registerService('userCertificateManager', function(IContainer $c) {
|
2015-04-15 12:21:23 +00:00
|
|
|
return $c->query('ServerContainer')->getCertificateManager();
|
2016-10-05 14:31:28 +00:00
|
|
|
}, false);
|
|
|
|
$container->registerService('systemCertificateManager', function (IContainer $c) {
|
2015-12-22 16:42:28 +00:00
|
|
|
return $c->query('ServerContainer')->getCertificateManager(null);
|
2016-10-05 14:31:28 +00:00
|
|
|
}, false);
|
|
|
|
$container->registerService(IProvider::class, function (IContainer $c) {
|
|
|
|
return $c->query('ServerContainer')->query(IProvider::class);
|
2015-12-22 16:42:28 +00:00
|
|
|
});
|
2016-10-05 14:31:28 +00:00
|
|
|
$container->registerService(IManager::class, function (IContainer $c) {
|
2016-08-08 21:31:26 +00:00
|
|
|
return $c->query('ServerContainer')->getSettingsManager();
|
|
|
|
});
|
2017-04-07 12:51:05 +00:00
|
|
|
|
|
|
|
$container->registerService(NewUserMailHelper::class, function (IContainer $c) {
|
|
|
|
/** @var Server $server */
|
|
|
|
$server = $c->query('ServerContainer');
|
2017-04-07 20:42:43 +00:00
|
|
|
/** @var Defaults $defaults */
|
|
|
|
$defaults = $server->query(Defaults::class);
|
2017-04-07 12:51:05 +00:00
|
|
|
|
|
|
|
return new NewUserMailHelper(
|
2017-04-07 20:42:43 +00:00
|
|
|
$defaults,
|
2017-04-07 12:51:05 +00:00
|
|
|
$server->getURLGenerator(),
|
2018-09-24 20:54:57 +00:00
|
|
|
$server->getL10NFactory(),
|
2017-04-07 12:51:05 +00:00
|
|
|
$server->getMailer(),
|
|
|
|
$server->getSecureRandom(),
|
|
|
|
new TimeFactory(),
|
|
|
|
$server->getConfig(),
|
|
|
|
$server->getCrypto(),
|
|
|
|
Util::getDefaultEmailAddress('no-reply')
|
|
|
|
);
|
|
|
|
});
|
2014-10-03 13:14:22 +00:00
|
|
|
}
|
2017-04-12 13:19:45 +00:00
|
|
|
|
|
|
|
public function register() {
|
|
|
|
$activityManager = $this->getContainer()->getServer()->getActivityManager();
|
|
|
|
$activityManager->registerSetting(Setting::class); // FIXME move to info.xml
|
|
|
|
$activityManager->registerProvider(Provider::class); // FIXME move to info.xml
|
2017-05-16 07:37:21 +00:00
|
|
|
$activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml
|
|
|
|
$activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml
|
|
|
|
$activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml
|
2017-04-12 13:19:45 +00:00
|
|
|
|
2017-04-13 09:58:19 +00:00
|
|
|
Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
|
2017-04-12 13:19:45 +00:00
|
|
|
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
|
2018-10-10 12:12:10 +00:00
|
|
|
|
|
|
|
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
|
2017-04-12 13:19:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 09:49:02 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \BadMethodCallException
|
|
|
|
* @throws \Exception
|
2017-04-13 09:58:19 +00:00
|
|
|
* @throws \OCP\AppFramework\QueryException
|
2017-04-13 09:49:02 +00:00
|
|
|
*/
|
2017-04-13 09:58:19 +00:00
|
|
|
public function onChangePassword(array $parameters) {
|
|
|
|
/** @var Hooks $hooks */
|
|
|
|
$hooks = $this->getContainer()->query(Hooks::class);
|
|
|
|
$hooks->onChangePassword($parameters['uid']);
|
2017-04-12 13:19:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 09:58:19 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \BadMethodCallException
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \OCP\AppFramework\QueryException
|
|
|
|
*/
|
|
|
|
public function onChangeInfo(array $parameters) {
|
2017-04-12 13:19:45 +00:00
|
|
|
if ($parameters['feature'] !== 'eMailAddress') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-13 09:58:19 +00:00
|
|
|
/** @var Hooks $hooks */
|
|
|
|
$hooks = $this->getContainer()->query(Hooks::class);
|
2017-04-13 10:34:34 +00:00
|
|
|
$hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
|
2017-04-12 13:19:45 +00:00
|
|
|
}
|
2018-10-10 12:12:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $settings
|
|
|
|
*/
|
|
|
|
public function extendJsConfig(array $settings) {
|
|
|
|
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
|
|
|
|
|
|
|
|
$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', '');
|
|
|
|
if (!empty($publicWebFinger)) {
|
|
|
|
$appConfig['core']['public_webfinger'] = $publicWebFinger;
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings['array']['oc_appconfig'] = json_encode($appConfig);
|
|
|
|
}
|
2014-10-03 13:14:22 +00:00
|
|
|
}
|