Skip to content

Commit 771dfc8

Browse files
rullzerLukasReschke
authored andcommitted
No longer add trusted servers on federated share creation
It was disabled by default for ages. And often resulted in unwanted behavior. If admins want trusted servers they just have to do it manually. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent d18aa63 commit 771dfc8

11 files changed

Lines changed: 48 additions & 185 deletions

File tree

apps/federation/appinfo/routes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
'url' => '/trusted-servers/{id}',
3535
'verb' => 'DELETE'
3636
],
37-
[
38-
'name' => 'Settings#autoAddServers',
39-
'url' => '/auto-add-servers',
40-
'verb' => 'POST'
41-
],
4237
],
4338
'ocs' => [
4439
// old endpoints, only used by Nextcloud and ownCloud

apps/federation/composer/composer/ClassLoader.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
*
3838
* @author Fabien Potencier <fabien@symfony.com>
3939
* @author Jordi Boggiano <j.boggiano@seld.be>
40-
* @see http://www.php-fig.org/psr/psr-0/
41-
* @see http://www.php-fig.org/psr/psr-4/
40+
* @see https://www.php-fig.org/psr/psr-0/
41+
* @see https://www.php-fig.org/psr/psr-4/
4242
*/
4343
class ClassLoader
4444
{
45+
private $vendorDir;
46+
4547
// PSR-4
4648
private $prefixLengthsPsr4 = array();
4749
private $prefixDirsPsr4 = array();
@@ -57,10 +59,17 @@ class ClassLoader
5759
private $missingClasses = array();
5860
private $apcuPrefix;
5961

62+
private static $registeredLoaders = array();
63+
64+
public function __construct($vendorDir = null)
65+
{
66+
$this->vendorDir = $vendorDir;
67+
}
68+
6069
public function getPrefixes()
6170
{
6271
if (!empty($this->prefixesPsr0)) {
63-
return call_user_func_array('array_merge', $this->prefixesPsr0);
72+
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
6473
}
6574

6675
return array();
@@ -300,6 +309,17 @@ public function getApcuPrefix()
300309
public function register($prepend = false)
301310
{
302311
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
312+
313+
if (null === $this->vendorDir) {
314+
return;
315+
}
316+
317+
if ($prepend) {
318+
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
319+
} else {
320+
unset(self::$registeredLoaders[$this->vendorDir]);
321+
self::$registeredLoaders[$this->vendorDir] = $this;
322+
}
303323
}
304324

305325
/**
@@ -308,6 +328,10 @@ public function register($prepend = false)
308328
public function unregister()
309329
{
310330
spl_autoload_unregister(array($this, 'loadClass'));
331+
332+
if (null !== $this->vendorDir) {
333+
unset(self::$registeredLoaders[$this->vendorDir]);
334+
}
311335
}
312336

313337
/**
@@ -367,6 +391,16 @@ public function findFile($class)
367391
return $file;
368392
}
369393

394+
/**
395+
* Returns the currently registered loaders indexed by their corresponding vendor directories.
396+
*
397+
* @return self[]
398+
*/
399+
public static function getRegisteredLoaders()
400+
{
401+
return self::$registeredLoaders;
402+
}
403+
370404
private function findFileWithExtension($class, $ext)
371405
{
372406
// PSR-4 lookup

apps/federation/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
$baseDir = $vendorDir;
77

88
return array(
9+
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
910
'OCA\\Federation\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
1011
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => $baseDir . '/../lib/BackgroundJob/GetSharedSecret.php',
1112
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => $baseDir . '/../lib/BackgroundJob/RequestSharedSecret.php',
@@ -14,7 +15,6 @@
1415
'OCA\\Federation\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php',
1516
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php',
1617
'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php',
17-
'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php',
1818
'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php',
1919
'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
2020
'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php',

apps/federation/composer/composer/autoload_real.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public static function getLoader()
2323
}
2424

2525
spl_autoload_register(array('ComposerAutoloaderInitFederation', 'loadClassLoader'), true, true);
26-
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
26+
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
2727
spl_autoload_unregister(array('ComposerAutoloaderInitFederation', 'loadClassLoader'));
2828

2929
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
3030
if ($useStaticLoader) {
31-
require_once __DIR__ . '/autoload_static.php';
31+
require __DIR__ . '/autoload_static.php';
3232

3333
call_user_func(\Composer\Autoload\ComposerStaticInitFederation::getInitializer($loader));
3434
} else {

apps/federation/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ComposerStaticInitFederation
2121
);
2222

2323
public static $classMap = array (
24+
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
2425
'OCA\\Federation\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
2526
'OCA\\Federation\\BackgroundJob\\GetSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/GetSharedSecret.php',
2627
'OCA\\Federation\\BackgroundJob\\RequestSharedSecret' => __DIR__ . '/..' . '/../lib/BackgroundJob/RequestSharedSecret.php',
@@ -29,7 +30,6 @@ class ComposerStaticInitFederation
2930
'OCA\\Federation\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php',
3031
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php',
3132
'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php',
32-
'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
3333
'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php',
3434
'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
3535
'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php',

apps/federation/js/settings-admin.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@
1919
*/
2020

2121
(function( $ ) {
22-
22+
2323
// ocFederationAddServer
2424
$.fn.ocFederationAddServer = function() {
2525

2626
/* Go easy on jquery and define some vars
2727
========================================================================== */
2828

2929
var $wrapper = $(this),
30-
30+
3131
// Buttons
3232
$btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
3333
$btnSubmit = $wrapper.find("#ocFederationSubmit"),
34-
34+
3535
// Inputs
3636
$inpServerUrl = $wrapper.find("#serverUrl"),
37-
$inpAutoAddServers = $wrapper.find("#autoAddServers"),
3837

3938
// misc
4039
$msgBox = $wrapper.find("#ocFederationAddServer .msg"),
@@ -55,17 +54,8 @@
5554
$srvList.on('click', 'li > .icon-delete', function() {
5655
var $this = $(this).parent();
5756
var id = $this.attr('id');
58-
59-
removeServer( id );
60-
});
6157

62-
$inpAutoAddServers.on("change", function() {
63-
$.post(
64-
OC.generateUrl('/apps/federation/auto-add-servers'),
65-
{
66-
autoAddServers: $(this).is(":checked")
67-
}
68-
);
58+
removeServer( id );
6959
});
7060

7161
$btnSubmit.on("click", function()
@@ -94,7 +84,7 @@
9484
}
9585
});
9686
};
97-
87+
9888
/* private Functions
9989
========================================================================== */
10090

@@ -132,11 +122,11 @@
132122
});
133123
}
134124

135-
125+
136126
})( jQuery );
137127

138128
$(document).ready(function () {
139129

140130
$('#ocFederationSettings').ocFederationAddServer();
141-
131+
142132
});

apps/federation/lib/AppInfo/Application.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
namespace OCA\Federation\AppInfo;
2929

3030
use OCA\Federation\DAV\FedAuth;
31-
use OCA\Federation\Hooks;
3231
use OCA\Federation\Middleware\AddServerMiddleware;
3332
use OCP\AppFramework\App;
3433
use OCP\SabrePluginEvent;
@@ -53,20 +52,8 @@ private function registerMiddleware() {
5352
$container->registerMiddleWare('AddServerMiddleware');
5453
}
5554

56-
/**
57-
* listen to federated_share_added hooks to auto-add new servers to the
58-
* list of trusted servers.
59-
*/
6055
public function registerHooks() {
6156
$container = $this->getContainer();
62-
$hooksManager = $container->query(Hooks::class);
63-
64-
Util::connectHook(
65-
Share::class,
66-
'federated_share_added',
67-
$hooksManager,
68-
'addServerHook'
69-
);
7057

7158
$dispatcher = $container->getServer()->getEventDispatcher();
7259
$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function ($event) use ($container) {

apps/federation/lib/Controller/SettingsController.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ public function removeServer($id) {
8787
return new DataResponse();
8888
}
8989

90-
/**
91-
* enable/disable to automatically add servers to the list of trusted servers
92-
* once a federated share was created and accepted successfully
93-
*
94-
* @param bool $autoAddServers
95-
*/
96-
public function autoAddServers($autoAddServers) {
97-
$this->trustedServers->setAutoAddServers($autoAddServers);
98-
}
99-
10090
/**
10191
* check if the server should be added to the list of trusted servers or not
10292
*

apps/federation/lib/Hooks.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

apps/federation/templates/settings-admin.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
<h2><?php p($l->t('Trusted servers')); ?></h2>
1111
<p class="settings-hint"><?php p($l->t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></p>
1212

13-
<p>
14-
<input id="autoAddServers" type="checkbox" class="checkbox" <?php if ($_['autoAddServers']) {
15-
p('checked');
16-
} ?> />
17-
<label for="autoAddServers"><?php p($l->t('Add server automatically once a federated share was created successfully')); ?></label>
18-
</p>
19-
2013
<ul id="listOfTrustedServers">
2114
<?php foreach ($_['trustedServers'] as $trustedServer) { ?>
2215
<li id="<?php p($trustedServer['id']); ?>">

0 commit comments

Comments
 (0)