Completed
Push — master ( 3d671c...42e805 )
by Blizzz
48:26 queued 33:21
created
apps/user_ldap/lib/Controller/RenewPasswordController.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,6 @@
 block discarded – undo
23 23
 namespace OCA\User_LDAP\Controller;
24 24
 
25 25
 use OC\HintException;
26
-use OC_Util;
27 26
 use OCP\AppFramework\Controller;
28 27
 use OCP\AppFramework\Http\RedirectResponse;
29 28
 use OCP\AppFramework\Http\TemplateResponse;
Please login to merge, or discard this patch.
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -37,144 +37,144 @@
 block discarded – undo
37 37
 use OCP\IUserManager;
38 38
 
39 39
 class RenewPasswordController extends Controller {
40
-	/** @var IUserManager */
41
-	private $userManager;
42
-	/** @var IConfig */
43
-	private $config;
44
-	/** @var IL10N */
45
-	protected $l10n;
46
-	/** @var ISession */
47
-	private $session;
48
-	/** @var IURLGenerator */
49
-	private $urlGenerator;
40
+    /** @var IUserManager */
41
+    private $userManager;
42
+    /** @var IConfig */
43
+    private $config;
44
+    /** @var IL10N */
45
+    protected $l10n;
46
+    /** @var ISession */
47
+    private $session;
48
+    /** @var IURLGenerator */
49
+    private $urlGenerator;
50 50
 
51
-	/**
52
-	 * @param string $appName
53
-	 * @param IRequest $request
54
-	 * @param IUserManager $userManager
55
-	 * @param IConfig $config
56
-	 * @param IURLGenerator $urlGenerator
57
-	 */
58
-	function __construct($appName, IRequest $request, IUserManager $userManager, 
59
-		IConfig $config, IL10N $l10n, ISession $session, IURLGenerator $urlGenerator) {
60
-		parent::__construct($appName, $request);
61
-		$this->userManager = $userManager;
62
-		$this->config = $config;
63
-		$this->l10n = $l10n;
64
-		$this->session = $session;
65
-		$this->urlGenerator = $urlGenerator;
66
-	}
51
+    /**
52
+     * @param string $appName
53
+     * @param IRequest $request
54
+     * @param IUserManager $userManager
55
+     * @param IConfig $config
56
+     * @param IURLGenerator $urlGenerator
57
+     */
58
+    function __construct($appName, IRequest $request, IUserManager $userManager, 
59
+        IConfig $config, IL10N $l10n, ISession $session, IURLGenerator $urlGenerator) {
60
+        parent::__construct($appName, $request);
61
+        $this->userManager = $userManager;
62
+        $this->config = $config;
63
+        $this->l10n = $l10n;
64
+        $this->session = $session;
65
+        $this->urlGenerator = $urlGenerator;
66
+    }
67 67
 
68
-	/**
69
-	 * @PublicPage
70
-	 * @NoCSRFRequired
71
-	 *
72
-	 * @return RedirectResponse
73
-	 */
74
-	public function cancel() {
75
-		return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
76
-	}
68
+    /**
69
+     * @PublicPage
70
+     * @NoCSRFRequired
71
+     *
72
+     * @return RedirectResponse
73
+     */
74
+    public function cancel() {
75
+        return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
76
+    }
77 77
 
78
-	/**
79
-	 * @PublicPage
80
-	 * @NoCSRFRequired
81
-	 * @UseSession
82
-	 *
83
-	 * @param string $user
84
-	 *
85
-	 * @return TemplateResponse|RedirectResponse
86
-	 */
87
-	public function showRenewPasswordForm($user) {
88
-		if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
89
-			return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
90
-		}
91
-		$parameters = [];
92
-		$renewPasswordMessages = $this->session->get('renewPasswordMessages');
93
-		$errors = [];
94
-		$messages = [];
95
-		if (is_array($renewPasswordMessages)) {
96
-			list($errors, $messages) = $renewPasswordMessages;
97
-		}
98
-		$this->session->remove('renewPasswordMessages');
99
-		foreach ($errors as $value) {
100
-			$parameters[$value] = true;
101
-		}
78
+    /**
79
+     * @PublicPage
80
+     * @NoCSRFRequired
81
+     * @UseSession
82
+     *
83
+     * @param string $user
84
+     *
85
+     * @return TemplateResponse|RedirectResponse
86
+     */
87
+    public function showRenewPasswordForm($user) {
88
+        if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
89
+            return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
90
+        }
91
+        $parameters = [];
92
+        $renewPasswordMessages = $this->session->get('renewPasswordMessages');
93
+        $errors = [];
94
+        $messages = [];
95
+        if (is_array($renewPasswordMessages)) {
96
+            list($errors, $messages) = $renewPasswordMessages;
97
+        }
98
+        $this->session->remove('renewPasswordMessages');
99
+        foreach ($errors as $value) {
100
+            $parameters[$value] = true;
101
+        }
102 102
 
103
-		$parameters['messages'] = $messages;
104
-		$parameters['user'] = $user;
103
+        $parameters['messages'] = $messages;
104
+        $parameters['user'] = $user;
105 105
 
106
-		$parameters['canResetPassword'] = true;
107
-		$parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', '');
108
-		if (!$parameters['resetPasswordLink']) {
109
-			$userObj = $this->userManager->get($user);
110
-			if ($userObj instanceof IUser) {
111
-				$parameters['canResetPassword'] = $userObj->canChangePassword();
112
-			}
113
-		}
114
-		$parameters['cancelLink'] = $this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm');
106
+        $parameters['canResetPassword'] = true;
107
+        $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', '');
108
+        if (!$parameters['resetPasswordLink']) {
109
+            $userObj = $this->userManager->get($user);
110
+            if ($userObj instanceof IUser) {
111
+                $parameters['canResetPassword'] = $userObj->canChangePassword();
112
+            }
113
+        }
114
+        $parameters['cancelLink'] = $this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm');
115 115
 
116
-		return new TemplateResponse(
117
-			$this->appName, 'renewpassword', $parameters, 'guest'
118
-		);
119
-	}
116
+        return new TemplateResponse(
117
+            $this->appName, 'renewpassword', $parameters, 'guest'
118
+        );
119
+    }
120 120
 
121
-	/**
122
-	 * @PublicPage
123
-	 * @UseSession
124
-	 *
125
-	 * @param string $user
126
-	 * @param string $oldPassword
127
-	 * @param string $newPassword
128
-	 *
129
-	 * @return RedirectResponse
130
-	 */
131
-	public function tryRenewPassword($user, $oldPassword, $newPassword) {
132
-		if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
133
-			return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
134
-		}
135
-		$args = !is_null($user) ? ['user' => $user] : [];
136
-		$loginResult = $this->userManager->checkPassword($user, $oldPassword);
137
-		if ($loginResult === false) {
138
-			$this->session->set('renewPasswordMessages', [
139
-				['invalidpassword'], []
140
-			]);
141
-			return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
142
-		}
121
+    /**
122
+     * @PublicPage
123
+     * @UseSession
124
+     *
125
+     * @param string $user
126
+     * @param string $oldPassword
127
+     * @param string $newPassword
128
+     *
129
+     * @return RedirectResponse
130
+     */
131
+    public function tryRenewPassword($user, $oldPassword, $newPassword) {
132
+        if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
133
+            return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
134
+        }
135
+        $args = !is_null($user) ? ['user' => $user] : [];
136
+        $loginResult = $this->userManager->checkPassword($user, $oldPassword);
137
+        if ($loginResult === false) {
138
+            $this->session->set('renewPasswordMessages', [
139
+                ['invalidpassword'], []
140
+            ]);
141
+            return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
142
+        }
143 143
 		
144
-		try {
145
-			if (!is_null($newPassword) && \OC_User::setPassword($user, $newPassword)) {
146
-				$this->session->set('loginMessages', [
147
-					[], [$this->l10n->t("Please login with the new password")]
148
-				]);
149
-				$this->session->remove('needPasswordRenewal');
150
-				return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
151
-			} else {
152
-				$this->session->set('renewPasswordMessages', [
153
-					['internalexception'], []
154
-				]);
155
-			}
156
-		} catch (HintException $e) {
157
-			$this->session->set('renewPasswordMessages', [
158
-				[], [$e->getHint()]
159
-			]);
160
-		}
144
+        try {
145
+            if (!is_null($newPassword) && \OC_User::setPassword($user, $newPassword)) {
146
+                $this->session->set('loginMessages', [
147
+                    [], [$this->l10n->t("Please login with the new password")]
148
+                ]);
149
+                $this->session->remove('needPasswordRenewal');
150
+                return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
151
+            } else {
152
+                $this->session->set('renewPasswordMessages', [
153
+                    ['internalexception'], []
154
+                ]);
155
+            }
156
+        } catch (HintException $e) {
157
+            $this->session->set('renewPasswordMessages', [
158
+                [], [$e->getHint()]
159
+            ]);
160
+        }
161 161
 
162
-		return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
163
-	}
162
+        return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args));
163
+    }
164 164
 
165
-	/**
166
-	 * @PublicPage
167
-	 * @NoCSRFRequired
168
-	 * @UseSession
169
-	 *
170
-	 * @return RedirectResponse
171
-	 */
172
-	public function showLoginFormInvalidPassword($user) {
173
-		$args = !is_null($user) ? ['user' => $user] : [];
174
-		$this->session->set('loginMessages', [
175
-			['invalidpassword'], []
176
-		]);
177
-		return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
178
-	}
165
+    /**
166
+     * @PublicPage
167
+     * @NoCSRFRequired
168
+     * @UseSession
169
+     *
170
+     * @return RedirectResponse
171
+     */
172
+    public function showLoginFormInvalidPassword($user) {
173
+        $args = !is_null($user) ? ['user' => $user] : [];
174
+        $this->session->set('loginMessages', [
175
+            ['invalidpassword'], []
176
+        ]);
177
+        return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
178
+    }
179 179
 
180 180
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @return TemplateResponse|RedirectResponse
86 86
 	 */
87 87
 	public function showRenewPasswordForm($user) {
88
-		if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
88
+		if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
89 89
 			return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
90 90
 		}
91 91
 		$parameters = [];
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @return RedirectResponse
130 130
 	 */
131 131
 	public function tryRenewPassword($user, $oldPassword, $newPassword) {
132
-		if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
132
+		if ($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') {
133 133
 			return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
134 134
 		}
135 135
 		$args = !is_null($user) ? ['user' => $user] : [];
Please login to merge, or discard this patch.
apps/user_ldap/templates/renewpassword.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php /** @var $l OC_L10N */ ?>
2 2
 <?php
3 3
 script('core', [
4
-	'jquery-showpassword',
4
+    'jquery-showpassword',
5 5
 ]);
6 6
 script('user_ldap', [
7
-	'renewPassword',
7
+    'renewPassword',
8 8
 ]);
9 9
 style('user_ldap', 'renewPassword');
10 10
 \OC_Util::addVendorScript('strengthify/jquery.strengthify');
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		<div class="warning title">
19 19
 			<?php p($l->t('Please renew your password.')); ?><br>
20 20
 		</div>
21
-		<?php foreach($_['messages'] as $message): ?>
21
+		<?php foreach ($_['messages'] as $message): ?>
22 22
 			<div class="warning">
23 23
 				<?php p($message); ?><br>
24 24
 			</div>
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
 		<?php endif; ?>
32 32
 		<div id="message" class="hidden">
33 33
 			<img class="float-spinner" alt=""
34
-				src="<?php p(image_path('core', 'loading-dark.gif'));?>">
34
+				src="<?php p(image_path('core', 'loading-dark.gif')); ?>">
35 35
 			<span id="messageText"></span>
36 36
 			<!-- the following div ensures that the spinner is always inside the #message div -->
37 37
 			<div style="clear: both;"></div>
38 38
 		</div>
39 39
 		<p class="grouptop">
40 40
 			<input type="password" id="oldPassword" name="oldPassword"
41
-				placeholder="<?php echo $l->t('Current password');?>"
41
+				placeholder="<?php echo $l->t('Current password'); ?>"
42 42
 				autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/>
43 43
 			<label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label>
44 44
 		</p>
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			<input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label>
48 48
 			<label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label>
49 49
 			<input type="password" id="newPassword" name="newPassword"
50
-				placeholder="<?php echo $l->t('New password');?>"
50
+				placeholder="<?php echo $l->t('New password'); ?>"
51 51
 				data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/>
52 52
 		</p>
53 53
 		
Please login to merge, or discard this patch.
apps/user_ldap/ajax/wizard.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
 $l = \OC::$server->getL10N('user_ldap');
34 34
 
35 35
 if(!isset($_POST['action'])) {
36
-	\OCP\JSON::error(array('message' => $l->t('No action specified')));
36
+    \OCP\JSON::error(array('message' => $l->t('No action specified')));
37 37
 }
38 38
 $action = (string)$_POST['action'];
39 39
 
40 40
 
41 41
 if(!isset($_POST['ldap_serverconfig_chooser'])) {
42
-	\OCP\JSON::error(array('message' => $l->t('No configuration specified')));
42
+    \OCP\JSON::error(array('message' => $l->t('No configuration specified')));
43 43
 }
44 44
 $prefix = (string)$_POST['ldap_serverconfig_chooser'];
45 45
 
@@ -52,91 +52,91 @@  discard block
 block discarded – undo
52 52
 $con->setIgnoreValidation(true);
53 53
 
54 54
 $userManager = new \OCA\User_LDAP\User\Manager(
55
-	\OC::$server->getConfig(),
56
-	new \OCA\User_LDAP\FilesystemHelper(),
57
-	new \OCA\User_LDAP\LogWrapper(),
58
-	\OC::$server->getAvatarManager(),
59
-	new \OCP\Image(),
60
-	\OC::$server->getDatabaseConnection(),
61
-	\OC::$server->getUserManager(),
62
-	\OC::$server->getNotificationManager());
55
+    \OC::$server->getConfig(),
56
+    new \OCA\User_LDAP\FilesystemHelper(),
57
+    new \OCA\User_LDAP\LogWrapper(),
58
+    \OC::$server->getAvatarManager(),
59
+    new \OCP\Image(),
60
+    \OC::$server->getDatabaseConnection(),
61
+    \OC::$server->getUserManager(),
62
+    \OC::$server->getNotificationManager());
63 63
 
64 64
 $access = new \OCA\User_LDAP\Access($con, $ldapWrapper, $userManager, new \OCA\User_LDAP\Helper(
65
-	\OC::$server->getConfig()
65
+    \OC::$server->getConfig()
66 66
 ));
67 67
 
68 68
 $wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access);
69 69
 
70 70
 switch($action) {
71
-	case 'guessPortAndTLS':
72
-	case 'guessBaseDN':
73
-	case 'detectEmailAttribute':
74
-	case 'detectUserDisplayNameAttribute':
75
-	case 'determineGroupMemberAssoc':
76
-	case 'determineUserObjectClasses':
77
-	case 'determineGroupObjectClasses':
78
-	case 'determineGroupsForUsers':
79
-	case 'determineGroupsForGroups':
80
-	case 'determineAttributes':
81
-	case 'getUserListFilter':
82
-	case 'getUserLoginFilter':
83
-	case 'getGroupFilter':
84
-	case 'countUsers':
85
-	case 'countGroups':
86
-	case 'countInBaseDN':
87
-		try {
88
-			$result = $wizard->$action();
89
-			if($result !== false) {
90
-				OCP\JSON::success($result->getResultArray());
91
-				exit;
92
-			}
93
-		} catch (\Exception $e) {
94
-			\OCP\JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode()));
95
-			exit;
96
-		}
97
-		\OCP\JSON::error();
98
-		exit;
99
-		break;
71
+    case 'guessPortAndTLS':
72
+    case 'guessBaseDN':
73
+    case 'detectEmailAttribute':
74
+    case 'detectUserDisplayNameAttribute':
75
+    case 'determineGroupMemberAssoc':
76
+    case 'determineUserObjectClasses':
77
+    case 'determineGroupObjectClasses':
78
+    case 'determineGroupsForUsers':
79
+    case 'determineGroupsForGroups':
80
+    case 'determineAttributes':
81
+    case 'getUserListFilter':
82
+    case 'getUserLoginFilter':
83
+    case 'getGroupFilter':
84
+    case 'countUsers':
85
+    case 'countGroups':
86
+    case 'countInBaseDN':
87
+        try {
88
+            $result = $wizard->$action();
89
+            if($result !== false) {
90
+                OCP\JSON::success($result->getResultArray());
91
+                exit;
92
+            }
93
+        } catch (\Exception $e) {
94
+            \OCP\JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode()));
95
+            exit;
96
+        }
97
+        \OCP\JSON::error();
98
+        exit;
99
+        break;
100 100
 
101
-	case 'testLoginName': {
102
-		try {
103
-			$loginName = $_POST['ldap_test_loginname'];
104
-			$result = $wizard->$action($loginName);
105
-			if($result !== false) {
106
-				OCP\JSON::success($result->getResultArray());
107
-				exit;
108
-			}
109
-		} catch (\Exception $e) {
110
-			\OCP\JSON::error(array('message' => $e->getMessage()));
111
-			exit;
112
-		}
113
-		\OCP\JSON::error();
114
-		exit;
115
-		break;
116
-	}
101
+    case 'testLoginName': {
102
+        try {
103
+            $loginName = $_POST['ldap_test_loginname'];
104
+            $result = $wizard->$action($loginName);
105
+            if($result !== false) {
106
+                OCP\JSON::success($result->getResultArray());
107
+                exit;
108
+            }
109
+        } catch (\Exception $e) {
110
+            \OCP\JSON::error(array('message' => $e->getMessage()));
111
+            exit;
112
+        }
113
+        \OCP\JSON::error();
114
+        exit;
115
+        break;
116
+    }
117 117
 
118
-	case 'save':
119
-		$key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
120
-		$val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
121
-		if($key === false || is_null($val)) {
122
-			\OCP\JSON::error(array('message' => $l->t('No data specified')));
123
-			exit;
124
-		}
125
-		$cfg = array($key => $val);
126
-		$setParameters = array();
127
-		$configuration->setConfiguration($cfg, $setParameters);
128
-		if(!in_array($key, $setParameters)) {
129
-			\OCP\JSON::error(array('message' => $l->t($key.
130
-				' Could not set configuration %s', $setParameters[0])));
131
-			exit;
132
-		}
133
-		$configuration->saveConfiguration();
134
-		//clear the cache on save
135
-		$connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
136
-		$connection->clearCache();
137
-		OCP\JSON::success();
138
-		break;
139
-	default:
140
-		\OCP\JSON::error(array('message' => $l->t('Action does not exist')));
141
-		break;
118
+    case 'save':
119
+        $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
120
+        $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
121
+        if($key === false || is_null($val)) {
122
+            \OCP\JSON::error(array('message' => $l->t('No data specified')));
123
+            exit;
124
+        }
125
+        $cfg = array($key => $val);
126
+        $setParameters = array();
127
+        $configuration->setConfiguration($cfg, $setParameters);
128
+        if(!in_array($key, $setParameters)) {
129
+            \OCP\JSON::error(array('message' => $l->t($key.
130
+                ' Could not set configuration %s', $setParameters[0])));
131
+            exit;
132
+        }
133
+        $configuration->saveConfiguration();
134
+        //clear the cache on save
135
+        $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
136
+        $connection->clearCache();
137
+        OCP\JSON::success();
138
+        break;
139
+    default:
140
+        \OCP\JSON::error(array('message' => $l->t('Action does not exist')));
141
+        break;
142 142
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Notification/Notifier.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -30,40 +30,40 @@
 block discarded – undo
30 30
 
31 31
 class Notifier implements INotifier {
32 32
 
33
-	/** @var IFactory */
34
-	protected $l10nFactory;
33
+    /** @var IFactory */
34
+    protected $l10nFactory;
35 35
 
36
-	/**
37
-	 * @param IFactory $l10nFactory
38
-	 */
39
-	 public function __construct(\OCP\L10N\IFactory $l10nFactory) {
40
-		$this->l10nFactory = $l10nFactory;
41
-	}
36
+    /**
37
+     * @param IFactory $l10nFactory
38
+     */
39
+        public function __construct(\OCP\L10N\IFactory $l10nFactory) {
40
+        $this->l10nFactory = $l10nFactory;
41
+    }
42 42
 
43
-	/**
44
-	 * @param INotification $notification
45
-	 * @param string $languageCode The code of the language that should be used to prepare the notification
46
-	 * @return INotification
47
-	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
48
-	 */
49
-	public function prepare(INotification $notification, $languageCode) {
50
-		if ($notification->getApp() !== 'user_ldap') {
51
-			// Not my app => throw
52
-			throw new \InvalidArgumentException();
53
-		}
43
+    /**
44
+     * @param INotification $notification
45
+     * @param string $languageCode The code of the language that should be used to prepare the notification
46
+     * @return INotification
47
+     * @throws \InvalidArgumentException When the notification was not prepared by a notifier
48
+     */
49
+    public function prepare(INotification $notification, $languageCode) {
50
+        if ($notification->getApp() !== 'user_ldap') {
51
+            // Not my app => throw
52
+            throw new \InvalidArgumentException();
53
+        }
54 54
 
55
-		// Read the language from the notification
56
-		$l = $this->l10nFactory->get('user_ldap', $languageCode);
55
+        // Read the language from the notification
56
+        $l = $this->l10nFactory->get('user_ldap', $languageCode);
57 57
 
58
-		switch ($notification->getSubject()) {
59
-			// Deal with known subjects
60
-			case 'pwd_exp_warn_days':
61
-				$notification->setParsedSubject($l->t('Your password will expire within %s day(s).', $notification->getSubjectParameters()));
62
-				return $notification;
58
+        switch ($notification->getSubject()) {
59
+            // Deal with known subjects
60
+            case 'pwd_exp_warn_days':
61
+                $notification->setParsedSubject($l->t('Your password will expire within %s day(s).', $notification->getSubjectParameters()));
62
+                return $notification;
63 63
 
64
-			default:
65
-				// Unknown subject => Unknown notification => throw
66
-				throw new \InvalidArgumentException();
67
-		}
68
-	}
64
+            default:
65
+                // Unknown subject => Unknown notification => throw
66
+                throw new \InvalidArgumentException();
67
+        }
68
+    }
69 69
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Jobs/UpdateGroups.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -41,183 +41,183 @@
 block discarded – undo
41 41
 use OCA\User_LDAP\User\Manager;
42 42
 
43 43
 class UpdateGroups extends \OC\BackgroundJob\TimedJob {
44
-	static private $groupsFromDB;
45
-
46
-	static private $groupBE;
47
-
48
-	public function __construct(){
49
-		$this->interval = self::getRefreshInterval();
50
-	}
51
-
52
-	/**
53
-	 * @param mixed $argument
54
-	 */
55
-	public function run($argument){
56
-		self::updateGroups();
57
-	}
58
-
59
-	static public function updateGroups() {
60
-		\OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', \OCP\Util::DEBUG);
61
-
62
-		$knownGroups = array_keys(self::getKnownGroups());
63
-		$actualGroups = self::getGroupBE()->getGroups();
64
-
65
-		if(empty($actualGroups) && empty($knownGroups)) {
66
-			\OCP\Util::writeLog('user_ldap',
67
-				'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.',
68
-				\OCP\Util::INFO);
69
-			return;
70
-		}
71
-
72
-		self::handleKnownGroups(array_intersect($actualGroups, $knownGroups));
73
-		self::handleCreatedGroups(array_diff($actualGroups, $knownGroups));
74
-		self::handleRemovedGroups(array_diff($knownGroups, $actualGroups));
75
-
76
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Finished.', \OCP\Util::DEBUG);
77
-	}
78
-
79
-	/**
80
-	 * @return int
81
-	 */
82
-	static private function getRefreshInterval() {
83
-		//defaults to every hour
84
-		return \OCP\Config::getAppValue('user_ldap', 'bgjRefreshInterval', 3600);
85
-	}
86
-
87
-	/**
88
-	 * @param string[] $groups
89
-	 */
90
-	static private function handleKnownGroups($groups) {
91
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', \OCP\Util::DEBUG);
92
-		$query = \OCP\DB::prepare('
44
+    static private $groupsFromDB;
45
+
46
+    static private $groupBE;
47
+
48
+    public function __construct(){
49
+        $this->interval = self::getRefreshInterval();
50
+    }
51
+
52
+    /**
53
+     * @param mixed $argument
54
+     */
55
+    public function run($argument){
56
+        self::updateGroups();
57
+    }
58
+
59
+    static public function updateGroups() {
60
+        \OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', \OCP\Util::DEBUG);
61
+
62
+        $knownGroups = array_keys(self::getKnownGroups());
63
+        $actualGroups = self::getGroupBE()->getGroups();
64
+
65
+        if(empty($actualGroups) && empty($knownGroups)) {
66
+            \OCP\Util::writeLog('user_ldap',
67
+                'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.',
68
+                \OCP\Util::INFO);
69
+            return;
70
+        }
71
+
72
+        self::handleKnownGroups(array_intersect($actualGroups, $knownGroups));
73
+        self::handleCreatedGroups(array_diff($actualGroups, $knownGroups));
74
+        self::handleRemovedGroups(array_diff($knownGroups, $actualGroups));
75
+
76
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Finished.', \OCP\Util::DEBUG);
77
+    }
78
+
79
+    /**
80
+     * @return int
81
+     */
82
+    static private function getRefreshInterval() {
83
+        //defaults to every hour
84
+        return \OCP\Config::getAppValue('user_ldap', 'bgjRefreshInterval', 3600);
85
+    }
86
+
87
+    /**
88
+     * @param string[] $groups
89
+     */
90
+    static private function handleKnownGroups($groups) {
91
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', \OCP\Util::DEBUG);
92
+        $query = \OCP\DB::prepare('
93 93
 			UPDATE `*PREFIX*ldap_group_members`
94 94
 			SET `owncloudusers` = ?
95 95
 			WHERE `owncloudname` = ?
96 96
 		');
97
-		foreach($groups as $group) {
98
-			//we assume, that self::$groupsFromDB has been retrieved already
99
-			$knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
100
-			$actualUsers = self::getGroupBE()->usersInGroup($group);
101
-			$hasChanged = false;
102
-			foreach(array_diff($knownUsers, $actualUsers) as $removedUser) {
103
-				\OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group));
104
-				\OCP\Util::writeLog('user_ldap',
105
-				'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
106
-				\OCP\Util::INFO);
107
-				$hasChanged = true;
108
-			}
109
-			foreach(array_diff($actualUsers, $knownUsers) as $addedUser) {
110
-				\OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group));
111
-				\OCP\Util::writeLog('user_ldap',
112
-				'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
113
-				\OCP\Util::INFO);
114
-				$hasChanged = true;
115
-			}
116
-			if($hasChanged) {
117
-				$query->execute(array(serialize($actualUsers), $group));
118
-			}
119
-		}
120
-		\OCP\Util::writeLog('user_ldap',
121
-			'bgJ "updateGroups" – FINISHED dealing with known Groups.',
122
-			\OCP\Util::DEBUG);
123
-	}
124
-
125
-	/**
126
-	 * @param string[] $createdGroups
127
-	 */
128
-	static private function handleCreatedGroups($createdGroups) {
129
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with created Groups.', \OCP\Util::DEBUG);
130
-		$query = \OCP\DB::prepare('
97
+        foreach($groups as $group) {
98
+            //we assume, that self::$groupsFromDB has been retrieved already
99
+            $knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
100
+            $actualUsers = self::getGroupBE()->usersInGroup($group);
101
+            $hasChanged = false;
102
+            foreach(array_diff($knownUsers, $actualUsers) as $removedUser) {
103
+                \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group));
104
+                \OCP\Util::writeLog('user_ldap',
105
+                'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
106
+                \OCP\Util::INFO);
107
+                $hasChanged = true;
108
+            }
109
+            foreach(array_diff($actualUsers, $knownUsers) as $addedUser) {
110
+                \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group));
111
+                \OCP\Util::writeLog('user_ldap',
112
+                'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
113
+                \OCP\Util::INFO);
114
+                $hasChanged = true;
115
+            }
116
+            if($hasChanged) {
117
+                $query->execute(array(serialize($actualUsers), $group));
118
+            }
119
+        }
120
+        \OCP\Util::writeLog('user_ldap',
121
+            'bgJ "updateGroups" – FINISHED dealing with known Groups.',
122
+            \OCP\Util::DEBUG);
123
+    }
124
+
125
+    /**
126
+     * @param string[] $createdGroups
127
+     */
128
+    static private function handleCreatedGroups($createdGroups) {
129
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with created Groups.', \OCP\Util::DEBUG);
130
+        $query = \OCP\DB::prepare('
131 131
 			INSERT
132 132
 			INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`)
133 133
 			VALUES (?, ?)
134 134
 		');
135
-		foreach($createdGroups as $createdGroup) {
136
-			\OCP\Util::writeLog('user_ldap',
137
-				'bgJ "updateGroups" – new group "'.$createdGroup.'" found.',
138
-				\OCP\Util::INFO);
139
-			$users = serialize(self::getGroupBE()->usersInGroup($createdGroup));
140
-			$query->execute(array($createdGroup, $users));
141
-		}
142
-		\OCP\Util::writeLog('user_ldap',
143
-			'bgJ "updateGroups" – FINISHED dealing with created Groups.',
144
-			\OCP\Util::DEBUG);
145
-	}
146
-
147
-	/**
148
-	 * @param string[] $removedGroups
149
-	 */
150
-	static private function handleRemovedGroups($removedGroups) {
151
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with removed groups.', \OCP\Util::DEBUG);
152
-		$query = \OCP\DB::prepare('
135
+        foreach($createdGroups as $createdGroup) {
136
+            \OCP\Util::writeLog('user_ldap',
137
+                'bgJ "updateGroups" – new group "'.$createdGroup.'" found.',
138
+                \OCP\Util::INFO);
139
+            $users = serialize(self::getGroupBE()->usersInGroup($createdGroup));
140
+            $query->execute(array($createdGroup, $users));
141
+        }
142
+        \OCP\Util::writeLog('user_ldap',
143
+            'bgJ "updateGroups" – FINISHED dealing with created Groups.',
144
+            \OCP\Util::DEBUG);
145
+    }
146
+
147
+    /**
148
+     * @param string[] $removedGroups
149
+     */
150
+    static private function handleRemovedGroups($removedGroups) {
151
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with removed groups.', \OCP\Util::DEBUG);
152
+        $query = \OCP\DB::prepare('
153 153
 			DELETE
154 154
 			FROM `*PREFIX*ldap_group_members`
155 155
 			WHERE `owncloudname` = ?
156 156
 		');
157
-		foreach($removedGroups as $removedGroup) {
158
-			\OCP\Util::writeLog('user_ldap',
159
-				'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.',
160
-				\OCP\Util::INFO);
161
-			$query->execute(array($removedGroup));
162
-		}
163
-		\OCP\Util::writeLog('user_ldap',
164
-			'bgJ "updateGroups" – FINISHED dealing with removed groups.',
165
-			\OCP\Util::DEBUG);
166
-	}
167
-
168
-	/**
169
-	 * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy
170
-	 */
171
-	static private function getGroupBE() {
172
-		if(!is_null(self::$groupBE)) {
173
-			return self::$groupBE;
174
-		}
175
-		$helper = new Helper(\OC::$server->getConfig());
176
-		$configPrefixes = $helper->getServerConfigurationPrefixes(true);
177
-		$ldapWrapper = new LDAP();
178
-		if(count($configPrefixes) === 1) {
179
-			//avoid the proxy when there is only one LDAP server configured
180
-			$dbc = \OC::$server->getDatabaseConnection();
181
-			$userManager = new Manager(
182
-				\OC::$server->getConfig(),
183
-				new FilesystemHelper(),
184
-				new LogWrapper(),
185
-				\OC::$server->getAvatarManager(),
186
-				new \OCP\Image(),
187
-				$dbc,
188
-				\OC::$server->getUserManager(),
189
-				\OC::$server->getNotificationManager());
190
-			$connector = new Connection($ldapWrapper, $configPrefixes[0]);
191
-			$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper);
192
-			$groupMapper = new GroupMapping($dbc);
193
-			$userMapper  = new UserMapping($dbc);
194
-			$ldapAccess->setGroupMapper($groupMapper);
195
-			$ldapAccess->setUserMapper($userMapper);
196
-			self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess);
197
-		} else {
198
-			self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper);
199
-		}
200
-
201
-		return self::$groupBE;
202
-	}
203
-
204
-	/**
205
-	 * @return array
206
-	 */
207
-	static private function getKnownGroups() {
208
-		if(is_array(self::$groupsFromDB)) {
209
-			return self::$groupsFromDB;
210
-		}
211
-		$query = \OCP\DB::prepare('
157
+        foreach($removedGroups as $removedGroup) {
158
+            \OCP\Util::writeLog('user_ldap',
159
+                'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.',
160
+                \OCP\Util::INFO);
161
+            $query->execute(array($removedGroup));
162
+        }
163
+        \OCP\Util::writeLog('user_ldap',
164
+            'bgJ "updateGroups" – FINISHED dealing with removed groups.',
165
+            \OCP\Util::DEBUG);
166
+    }
167
+
168
+    /**
169
+     * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy
170
+     */
171
+    static private function getGroupBE() {
172
+        if(!is_null(self::$groupBE)) {
173
+            return self::$groupBE;
174
+        }
175
+        $helper = new Helper(\OC::$server->getConfig());
176
+        $configPrefixes = $helper->getServerConfigurationPrefixes(true);
177
+        $ldapWrapper = new LDAP();
178
+        if(count($configPrefixes) === 1) {
179
+            //avoid the proxy when there is only one LDAP server configured
180
+            $dbc = \OC::$server->getDatabaseConnection();
181
+            $userManager = new Manager(
182
+                \OC::$server->getConfig(),
183
+                new FilesystemHelper(),
184
+                new LogWrapper(),
185
+                \OC::$server->getAvatarManager(),
186
+                new \OCP\Image(),
187
+                $dbc,
188
+                \OC::$server->getUserManager(),
189
+                \OC::$server->getNotificationManager());
190
+            $connector = new Connection($ldapWrapper, $configPrefixes[0]);
191
+            $ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper);
192
+            $groupMapper = new GroupMapping($dbc);
193
+            $userMapper  = new UserMapping($dbc);
194
+            $ldapAccess->setGroupMapper($groupMapper);
195
+            $ldapAccess->setUserMapper($userMapper);
196
+            self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess);
197
+        } else {
198
+            self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper);
199
+        }
200
+
201
+        return self::$groupBE;
202
+    }
203
+
204
+    /**
205
+     * @return array
206
+     */
207
+    static private function getKnownGroups() {
208
+        if(is_array(self::$groupsFromDB)) {
209
+            return self::$groupsFromDB;
210
+        }
211
+        $query = \OCP\DB::prepare('
212 212
 			SELECT `owncloudname`, `owncloudusers`
213 213
 			FROM `*PREFIX*ldap_group_members`
214 214
 		');
215
-		$result = $query->execute()->fetchAll();
216
-		self::$groupsFromDB = array();
217
-		foreach($result as $dataset) {
218
-			self::$groupsFromDB[$dataset['owncloudname']] = $dataset;
219
-		}
220
-
221
-		return self::$groupsFromDB;
222
-	}
215
+        $result = $query->execute()->fetchAll();
216
+        self::$groupsFromDB = array();
217
+        foreach($result as $dataset) {
218
+            self::$groupsFromDB[$dataset['owncloudname']] = $dataset;
219
+        }
220
+
221
+        return self::$groupsFromDB;
222
+    }
223 223
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Jobs/CleanUp.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -40,195 +40,195 @@
 block discarded – undo
40 40
  * @package OCA\User_LDAP\Jobs;
41 41
  */
42 42
 class CleanUp extends TimedJob {
43
-	/** @var int $limit amount of users that should be checked per run */
44
-	protected $limit = 50;
45
-
46
-	/** @var int $defaultIntervalMin default interval in minutes */
47
-	protected $defaultIntervalMin = 51;
48
-
49
-	/** @var User_LDAP|User_Proxy $userBackend */
50
-	protected $userBackend;
51
-
52
-	/** @var \OCP\IConfig $ocConfig */
53
-	protected $ocConfig;
54
-
55
-	/** @var \OCP\IDBConnection $db */
56
-	protected $db;
57
-
58
-	/** @var Helper $ldapHelper */
59
-	protected $ldapHelper;
60
-
61
-	/** @var \OCA\User_LDAP\Mapping\UserMapping */
62
-	protected $mapping;
63
-
64
-	/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
65
-	protected $dui;
66
-
67
-	public function __construct() {
68
-		$minutes = \OC::$server->getConfig()->getSystemValue(
69
-			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
70
-		$this->setInterval(intval($minutes) * 60);
71
-	}
72
-
73
-	/**
74
-	 * assigns the instances passed to run() to the class properties
75
-	 * @param array $arguments
76
-	 */
77
-	public function setArguments($arguments) {
78
-		//Dependency Injection is not possible, because the constructor will
79
-		//only get values that are serialized to JSON. I.e. whatever we would
80
-		//pass in app.php we do add here, except something else is passed e.g.
81
-		//in tests.
82
-
83
-		if(isset($arguments['helper'])) {
84
-			$this->ldapHelper = $arguments['helper'];
85
-		} else {
86
-			$this->ldapHelper = new Helper(\OC::$server->getConfig());
87
-		}
88
-
89
-		if(isset($arguments['ocConfig'])) {
90
-			$this->ocConfig = $arguments['ocConfig'];
91
-		} else {
92
-			$this->ocConfig = \OC::$server->getConfig();
93
-		}
94
-
95
-		if(isset($arguments['userBackend'])) {
96
-			$this->userBackend = $arguments['userBackend'];
97
-		} else {
98
-			$this->userBackend =  new User_Proxy(
99
-				$this->ldapHelper->getServerConfigurationPrefixes(true),
100
-				new LDAP(),
101
-				$this->ocConfig,
102
-				\OC::$server->getNotificationManager()
103
-			);
104
-		}
105
-
106
-		if(isset($arguments['db'])) {
107
-			$this->db = $arguments['db'];
108
-		} else {
109
-			$this->db = \OC::$server->getDatabaseConnection();
110
-		}
111
-
112
-		if(isset($arguments['mapping'])) {
113
-			$this->mapping = $arguments['mapping'];
114
-		} else {
115
-			$this->mapping = new UserMapping($this->db);
116
-		}
117
-
118
-		if(isset($arguments['deletedUsersIndex'])) {
119
-			$this->dui = $arguments['deletedUsersIndex'];
120
-		} else {
121
-			$this->dui = new DeletedUsersIndex(
122
-				$this->ocConfig, $this->db, $this->mapping);
123
-		}
124
-	}
125
-
126
-	/**
127
-	 * makes the background job do its work
128
-	 * @param array $argument
129
-	 */
130
-	public function run($argument) {
131
-		$this->setArguments($argument);
132
-
133
-		if(!$this->isCleanUpAllowed()) {
134
-			return;
135
-		}
136
-		$users = $this->mapping->getList($this->getOffset(), $this->limit);
137
-		if(!is_array($users)) {
138
-			//something wrong? Let's start from the beginning next time and
139
-			//abort
140
-			$this->setOffset(true);
141
-			return;
142
-		}
143
-		$resetOffset = $this->isOffsetResetNecessary(count($users));
144
-		$this->checkUsers($users);
145
-		$this->setOffset($resetOffset);
146
-	}
147
-
148
-	/**
149
-	 * checks whether next run should start at 0 again
150
-	 * @param int $resultCount
151
-	 * @return bool
152
-	 */
153
-	public function isOffsetResetNecessary($resultCount) {
154
-		return ($resultCount < $this->limit) ? true : false;
155
-	}
156
-
157
-	/**
158
-	 * checks whether cleaning up LDAP users is allowed
159
-	 * @return bool
160
-	 */
161
-	public function isCleanUpAllowed() {
162
-		try {
163
-			if($this->ldapHelper->haveDisabledConfigurations()) {
164
-				return false;
165
-			}
166
-		} catch (\Exception $e) {
167
-			return false;
168
-		}
169
-
170
-		$enabled = $this->isCleanUpEnabled();
171
-
172
-		return $enabled;
173
-	}
174
-
175
-	/**
176
-	 * checks whether clean up is enabled by configuration
177
-	 * @return bool
178
-	 */
179
-	private function isCleanUpEnabled() {
180
-		return (bool)$this->ocConfig->getSystemValue(
181
-			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
182
-	}
183
-
184
-	/**
185
-	 * checks users whether they are still existing
186
-	 * @param array $users result from getMappedUsers()
187
-	 */
188
-	private function checkUsers(array $users) {
189
-		foreach($users as $user) {
190
-			$this->checkUser($user);
191
-		}
192
-	}
193
-
194
-	/**
195
-	 * checks whether a user is still existing in LDAP
196
-	 * @param string[] $user
197
-	 */
198
-	private function checkUser(array $user) {
199
-		if($this->userBackend->userExistsOnLDAP($user['name'])) {
200
-			//still available, all good
201
-
202
-			return;
203
-		}
204
-
205
-		$this->dui->markUser($user['name']);
206
-	}
207
-
208
-	/**
209
-	 * gets the offset to fetch users from the mappings table
210
-	 * @return int
211
-	 */
212
-	private function getOffset() {
213
-		return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0));
214
-	}
215
-
216
-	/**
217
-	 * sets the new offset for the next run
218
-	 * @param bool $reset whether the offset should be set to 0
219
-	 */
220
-	public function setOffset($reset = false) {
221
-		$newOffset = $reset ? 0 :
222
-			$this->getOffset() + $this->limit;
223
-		$this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
224
-	}
225
-
226
-	/**
227
-	 * returns the chunk size (limit in DB speak)
228
-	 * @return int
229
-	 */
230
-	public function getChunkSize() {
231
-		return $this->limit;
232
-	}
43
+    /** @var int $limit amount of users that should be checked per run */
44
+    protected $limit = 50;
45
+
46
+    /** @var int $defaultIntervalMin default interval in minutes */
47
+    protected $defaultIntervalMin = 51;
48
+
49
+    /** @var User_LDAP|User_Proxy $userBackend */
50
+    protected $userBackend;
51
+
52
+    /** @var \OCP\IConfig $ocConfig */
53
+    protected $ocConfig;
54
+
55
+    /** @var \OCP\IDBConnection $db */
56
+    protected $db;
57
+
58
+    /** @var Helper $ldapHelper */
59
+    protected $ldapHelper;
60
+
61
+    /** @var \OCA\User_LDAP\Mapping\UserMapping */
62
+    protected $mapping;
63
+
64
+    /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
65
+    protected $dui;
66
+
67
+    public function __construct() {
68
+        $minutes = \OC::$server->getConfig()->getSystemValue(
69
+            'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
70
+        $this->setInterval(intval($minutes) * 60);
71
+    }
72
+
73
+    /**
74
+     * assigns the instances passed to run() to the class properties
75
+     * @param array $arguments
76
+     */
77
+    public function setArguments($arguments) {
78
+        //Dependency Injection is not possible, because the constructor will
79
+        //only get values that are serialized to JSON. I.e. whatever we would
80
+        //pass in app.php we do add here, except something else is passed e.g.
81
+        //in tests.
82
+
83
+        if(isset($arguments['helper'])) {
84
+            $this->ldapHelper = $arguments['helper'];
85
+        } else {
86
+            $this->ldapHelper = new Helper(\OC::$server->getConfig());
87
+        }
88
+
89
+        if(isset($arguments['ocConfig'])) {
90
+            $this->ocConfig = $arguments['ocConfig'];
91
+        } else {
92
+            $this->ocConfig = \OC::$server->getConfig();
93
+        }
94
+
95
+        if(isset($arguments['userBackend'])) {
96
+            $this->userBackend = $arguments['userBackend'];
97
+        } else {
98
+            $this->userBackend =  new User_Proxy(
99
+                $this->ldapHelper->getServerConfigurationPrefixes(true),
100
+                new LDAP(),
101
+                $this->ocConfig,
102
+                \OC::$server->getNotificationManager()
103
+            );
104
+        }
105
+
106
+        if(isset($arguments['db'])) {
107
+            $this->db = $arguments['db'];
108
+        } else {
109
+            $this->db = \OC::$server->getDatabaseConnection();
110
+        }
111
+
112
+        if(isset($arguments['mapping'])) {
113
+            $this->mapping = $arguments['mapping'];
114
+        } else {
115
+            $this->mapping = new UserMapping($this->db);
116
+        }
117
+
118
+        if(isset($arguments['deletedUsersIndex'])) {
119
+            $this->dui = $arguments['deletedUsersIndex'];
120
+        } else {
121
+            $this->dui = new DeletedUsersIndex(
122
+                $this->ocConfig, $this->db, $this->mapping);
123
+        }
124
+    }
125
+
126
+    /**
127
+     * makes the background job do its work
128
+     * @param array $argument
129
+     */
130
+    public function run($argument) {
131
+        $this->setArguments($argument);
132
+
133
+        if(!$this->isCleanUpAllowed()) {
134
+            return;
135
+        }
136
+        $users = $this->mapping->getList($this->getOffset(), $this->limit);
137
+        if(!is_array($users)) {
138
+            //something wrong? Let's start from the beginning next time and
139
+            //abort
140
+            $this->setOffset(true);
141
+            return;
142
+        }
143
+        $resetOffset = $this->isOffsetResetNecessary(count($users));
144
+        $this->checkUsers($users);
145
+        $this->setOffset($resetOffset);
146
+    }
147
+
148
+    /**
149
+     * checks whether next run should start at 0 again
150
+     * @param int $resultCount
151
+     * @return bool
152
+     */
153
+    public function isOffsetResetNecessary($resultCount) {
154
+        return ($resultCount < $this->limit) ? true : false;
155
+    }
156
+
157
+    /**
158
+     * checks whether cleaning up LDAP users is allowed
159
+     * @return bool
160
+     */
161
+    public function isCleanUpAllowed() {
162
+        try {
163
+            if($this->ldapHelper->haveDisabledConfigurations()) {
164
+                return false;
165
+            }
166
+        } catch (\Exception $e) {
167
+            return false;
168
+        }
169
+
170
+        $enabled = $this->isCleanUpEnabled();
171
+
172
+        return $enabled;
173
+    }
174
+
175
+    /**
176
+     * checks whether clean up is enabled by configuration
177
+     * @return bool
178
+     */
179
+    private function isCleanUpEnabled() {
180
+        return (bool)$this->ocConfig->getSystemValue(
181
+            'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
182
+    }
183
+
184
+    /**
185
+     * checks users whether they are still existing
186
+     * @param array $users result from getMappedUsers()
187
+     */
188
+    private function checkUsers(array $users) {
189
+        foreach($users as $user) {
190
+            $this->checkUser($user);
191
+        }
192
+    }
193
+
194
+    /**
195
+     * checks whether a user is still existing in LDAP
196
+     * @param string[] $user
197
+     */
198
+    private function checkUser(array $user) {
199
+        if($this->userBackend->userExistsOnLDAP($user['name'])) {
200
+            //still available, all good
201
+
202
+            return;
203
+        }
204
+
205
+        $this->dui->markUser($user['name']);
206
+    }
207
+
208
+    /**
209
+     * gets the offset to fetch users from the mappings table
210
+     * @return int
211
+     */
212
+    private function getOffset() {
213
+        return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0));
214
+    }
215
+
216
+    /**
217
+     * sets the new offset for the next run
218
+     * @param bool $reset whether the offset should be set to 0
219
+     */
220
+    public function setOffset($reset = false) {
221
+        $newOffset = $reset ? 0 :
222
+            $this->getOffset() + $this->limit;
223
+        $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
224
+    }
225
+
226
+    /**
227
+     * returns the chunk size (limit in DB speak)
228
+     * @return int
229
+     */
230
+    public function getChunkSize() {
231
+        return $this->limit;
232
+    }
233 233
 
234 234
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -15 removed lines patch added patch discarded remove patch
@@ -80,22 +80,22 @@  discard block
 block discarded – undo
80 80
 		//pass in app.php we do add here, except something else is passed e.g.
81 81
 		//in tests.
82 82
 
83
-		if(isset($arguments['helper'])) {
83
+		if (isset($arguments['helper'])) {
84 84
 			$this->ldapHelper = $arguments['helper'];
85 85
 		} else {
86 86
 			$this->ldapHelper = new Helper(\OC::$server->getConfig());
87 87
 		}
88 88
 
89
-		if(isset($arguments['ocConfig'])) {
89
+		if (isset($arguments['ocConfig'])) {
90 90
 			$this->ocConfig = $arguments['ocConfig'];
91 91
 		} else {
92 92
 			$this->ocConfig = \OC::$server->getConfig();
93 93
 		}
94 94
 
95
-		if(isset($arguments['userBackend'])) {
95
+		if (isset($arguments['userBackend'])) {
96 96
 			$this->userBackend = $arguments['userBackend'];
97 97
 		} else {
98
-			$this->userBackend =  new User_Proxy(
98
+			$this->userBackend = new User_Proxy(
99 99
 				$this->ldapHelper->getServerConfigurationPrefixes(true),
100 100
 				new LDAP(),
101 101
 				$this->ocConfig,
@@ -103,19 +103,19 @@  discard block
 block discarded – undo
103 103
 			);
104 104
 		}
105 105
 
106
-		if(isset($arguments['db'])) {
106
+		if (isset($arguments['db'])) {
107 107
 			$this->db = $arguments['db'];
108 108
 		} else {
109 109
 			$this->db = \OC::$server->getDatabaseConnection();
110 110
 		}
111 111
 
112
-		if(isset($arguments['mapping'])) {
112
+		if (isset($arguments['mapping'])) {
113 113
 			$this->mapping = $arguments['mapping'];
114 114
 		} else {
115 115
 			$this->mapping = new UserMapping($this->db);
116 116
 		}
117 117
 
118
-		if(isset($arguments['deletedUsersIndex'])) {
118
+		if (isset($arguments['deletedUsersIndex'])) {
119 119
 			$this->dui = $arguments['deletedUsersIndex'];
120 120
 		} else {
121 121
 			$this->dui = new DeletedUsersIndex(
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
 	public function run($argument) {
131 131
 		$this->setArguments($argument);
132 132
 
133
-		if(!$this->isCleanUpAllowed()) {
133
+		if (!$this->isCleanUpAllowed()) {
134 134
 			return;
135 135
 		}
136 136
 		$users = $this->mapping->getList($this->getOffset(), $this->limit);
137
-		if(!is_array($users)) {
137
+		if (!is_array($users)) {
138 138
 			//something wrong? Let's start from the beginning next time and
139 139
 			//abort
140 140
 			$this->setOffset(true);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function isCleanUpAllowed() {
162 162
 		try {
163
-			if($this->ldapHelper->haveDisabledConfigurations()) {
163
+			if ($this->ldapHelper->haveDisabledConfigurations()) {
164 164
 				return false;
165 165
 			}
166 166
 		} catch (\Exception $e) {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @return bool
178 178
 	 */
179 179
 	private function isCleanUpEnabled() {
180
-		return (bool)$this->ocConfig->getSystemValue(
180
+		return (bool) $this->ocConfig->getSystemValue(
181 181
 			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
182 182
 	}
183 183
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 * @param array $users result from getMappedUsers()
187 187
 	 */
188 188
 	private function checkUsers(array $users) {
189
-		foreach($users as $user) {
189
+		foreach ($users as $user) {
190 190
 			$this->checkUser($user);
191 191
 		}
192 192
 	}
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 * @param string[] $user
197 197
 	 */
198 198
 	private function checkUser(array $user) {
199
-		if($this->userBackend->userExistsOnLDAP($user['name'])) {
199
+		if ($this->userBackend->userExistsOnLDAP($user['name'])) {
200 200
 			//still available, all good
201 201
 
202 202
 			return;
@@ -218,8 +218,7 @@  discard block
 block discarded – undo
218 218
 	 * @param bool $reset whether the offset should be set to 0
219 219
 	 */
220 220
 	public function setOffset($reset = false) {
221
-		$newOffset = $reset ? 0 :
222
-			$this->getOffset() + $this->limit;
221
+		$newOffset = $reset ? 0 : $this->getOffset() + $this->limit;
223 222
 		$this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
224 223
 	}
225 224
 
Please login to merge, or discard this patch.
apps/user_ldap/lib/AppInfo/Application.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 use OCP\AppFramework\IAppContainer;
28 28
 
29 29
 class Application extends App {
30
-	public function __construct () {
30
+	public function __construct() {
31 31
 		parent::__construct('user_ldap');
32 32
 		$container = $this->getContainer();
33 33
 
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -28,25 +28,25 @@
 block discarded – undo
28 28
 use OCP\AppFramework\IAppContainer;
29 29
 
30 30
 class Application extends App {
31
-	public function __construct () {
32
-		parent::__construct('user_ldap');
33
-		$container = $this->getContainer();
31
+    public function __construct () {
32
+        parent::__construct('user_ldap');
33
+        $container = $this->getContainer();
34 34
 
35
-		/**
36
-		 * Controller
37
-		 */
38
-		$container->registerService('RenewPasswordController', function(IAppContainer $c) {
39
-			/** @var \OC\Server $server */
40
-			$server = $c->query('ServerContainer');
35
+        /**
36
+         * Controller
37
+         */
38
+        $container->registerService('RenewPasswordController', function(IAppContainer $c) {
39
+            /** @var \OC\Server $server */
40
+            $server = $c->query('ServerContainer');
41 41
 
42
-			return new RenewPasswordController(
43
-				$c->getAppName(),
44
-				$server->getRequest(),
45
-				$c->query('UserManager'),
46
-				$server->getConfig(),
47
-				$c->query('OCP\IL10N'),
48
-				$server->getURLGenerator()
49
-			);
50
-		});
51
-	}
42
+            return new RenewPasswordController(
43
+                $c->getAppName(),
44
+                $server->getRequest(),
45
+                $c->query('UserManager'),
46
+                $server->getConfig(),
47
+                $c->query('OCP\IL10N'),
48
+                $server->getURLGenerator()
49
+            );
50
+        });
51
+    }
52 52
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Helper.php 2 patches
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -34,126 +34,126 @@  discard block
 block discarded – undo
34 34
 
35 35
 class Helper {
36 36
 
37
-	/** @var IConfig */
38
-	private $config;
39
-
40
-	/**
41
-	 * Helper constructor.
42
-	 *
43
-	 * @param IConfig $config
44
-	 */
45
-	public function __construct(IConfig $config) {
46
-		$this->config = $config;
47
-	}
48
-
49
-	/**
50
-	 * returns prefixes for each saved LDAP/AD server configuration.
51
-	 * @param bool $activeConfigurations optional, whether only active configuration shall be
52
-	 * retrieved, defaults to false
53
-	 * @return array with a list of the available prefixes
54
-	 *
55
-	 * Configuration prefixes are used to set up configurations for n LDAP or
56
-	 * AD servers. Since configuration is stored in the database, table
57
-	 * appconfig under appid user_ldap, the common identifiers in column
58
-	 * 'configkey' have a prefix. The prefix for the very first server
59
-	 * configuration is empty.
60
-	 * Configkey Examples:
61
-	 * Server 1: ldap_login_filter
62
-	 * Server 2: s1_ldap_login_filter
63
-	 * Server 3: s2_ldap_login_filter
64
-	 *
65
-	 * The prefix needs to be passed to the constructor of Connection class,
66
-	 * except the default (first) server shall be connected to.
67
-	 *
68
-	 */
69
-	public function getServerConfigurationPrefixes($activeConfigurations = false) {
70
-		$referenceConfigkey = 'ldap_configuration_active';
71
-
72
-		$keys = $this->getServersConfig($referenceConfigkey);
73
-
74
-		$prefixes = [];
75
-		foreach ($keys as $key) {
76
-			if ($activeConfigurations && $this->config->getAppValue('user_ldap', $key, '0') !== '1') {
77
-				continue;
78
-			}
79
-
80
-			$len = strlen($key) - strlen($referenceConfigkey);
81
-			$prefixes[] = substr($key, 0, $len);
82
-		}
83
-
84
-		return $prefixes;
85
-	}
86
-
87
-	/**
88
-	 *
89
-	 * determines the host for every configured connection
90
-	 * @return array an array with configprefix as keys
91
-	 *
92
-	 */
93
-	public function getServerConfigurationHosts() {
94
-		$referenceConfigkey = 'ldap_host';
95
-
96
-		$keys = $this->getServersConfig($referenceConfigkey);
97
-
98
-		$result = array();
99
-		foreach($keys as $key) {
100
-			$len = strlen($key) - strlen($referenceConfigkey);
101
-			$prefix = substr($key, 0, $len);
102
-			$result[$prefix] = $this->config->getAppValue('user_ldap', $key);
103
-		}
104
-
105
-		return $result;
106
-	}
107
-
108
-	/**
109
-	 * return the next available configuration prefix
110
-	 *
111
-	 * @return string
112
-	 */
113
-	public function getNextServerConfigurationPrefix() {
114
-		$serverConnections = $this->getServerConfigurationPrefixes();
115
-
116
-		if(count($serverConnections) === 0) {
117
-			return 's01';
118
-		}
119
-
120
-		sort($serverConnections);
121
-		$lastKey = array_pop($serverConnections);
122
-		$lastNumber = intval(str_replace('s', '', $lastKey));
123
-		$nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
124
-		return $nextPrefix;
125
-	}
126
-
127
-	private function getServersConfig($value) {
128
-		$regex = '/' . $value . '$/S';
129
-
130
-		$keys = $this->config->getAppKeys('user_ldap');
131
-		$result = [];
132
-		foreach ($keys as $key) {
133
-			if (preg_match($regex, $key) === 1) {
134
-				$result[] = $key;
135
-			}
136
-		}
137
-
138
-		return $result;
139
-	}
140
-
141
-	/**
142
-	 * deletes a given saved LDAP/AD server configuration.
143
-	 * @param string $prefix the configuration prefix of the config to delete
144
-	 * @return bool true on success, false otherwise
145
-	 */
146
-	public function deleteServerConfiguration($prefix) {
147
-		if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
148
-			return false;
149
-		}
150
-
151
-		$saveOtherConfigurations = '';
152
-		if(empty($prefix)) {
153
-			$saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
154
-		}
155
-
156
-		$query = \OCP\DB::prepare('
37
+    /** @var IConfig */
38
+    private $config;
39
+
40
+    /**
41
+     * Helper constructor.
42
+     *
43
+     * @param IConfig $config
44
+     */
45
+    public function __construct(IConfig $config) {
46
+        $this->config = $config;
47
+    }
48
+
49
+    /**
50
+     * returns prefixes for each saved LDAP/AD server configuration.
51
+     * @param bool $activeConfigurations optional, whether only active configuration shall be
52
+     * retrieved, defaults to false
53
+     * @return array with a list of the available prefixes
54
+     *
55
+     * Configuration prefixes are used to set up configurations for n LDAP or
56
+     * AD servers. Since configuration is stored in the database, table
57
+     * appconfig under appid user_ldap, the common identifiers in column
58
+     * 'configkey' have a prefix. The prefix for the very first server
59
+     * configuration is empty.
60
+     * Configkey Examples:
61
+     * Server 1: ldap_login_filter
62
+     * Server 2: s1_ldap_login_filter
63
+     * Server 3: s2_ldap_login_filter
64
+     *
65
+     * The prefix needs to be passed to the constructor of Connection class,
66
+     * except the default (first) server shall be connected to.
67
+     *
68
+     */
69
+    public function getServerConfigurationPrefixes($activeConfigurations = false) {
70
+        $referenceConfigkey = 'ldap_configuration_active';
71
+
72
+        $keys = $this->getServersConfig($referenceConfigkey);
73
+
74
+        $prefixes = [];
75
+        foreach ($keys as $key) {
76
+            if ($activeConfigurations && $this->config->getAppValue('user_ldap', $key, '0') !== '1') {
77
+                continue;
78
+            }
79
+
80
+            $len = strlen($key) - strlen($referenceConfigkey);
81
+            $prefixes[] = substr($key, 0, $len);
82
+        }
83
+
84
+        return $prefixes;
85
+    }
86
+
87
+    /**
88
+     *
89
+     * determines the host for every configured connection
90
+     * @return array an array with configprefix as keys
91
+     *
92
+     */
93
+    public function getServerConfigurationHosts() {
94
+        $referenceConfigkey = 'ldap_host';
95
+
96
+        $keys = $this->getServersConfig($referenceConfigkey);
97
+
98
+        $result = array();
99
+        foreach($keys as $key) {
100
+            $len = strlen($key) - strlen($referenceConfigkey);
101
+            $prefix = substr($key, 0, $len);
102
+            $result[$prefix] = $this->config->getAppValue('user_ldap', $key);
103
+        }
104
+
105
+        return $result;
106
+    }
107
+
108
+    /**
109
+     * return the next available configuration prefix
110
+     *
111
+     * @return string
112
+     */
113
+    public function getNextServerConfigurationPrefix() {
114
+        $serverConnections = $this->getServerConfigurationPrefixes();
115
+
116
+        if(count($serverConnections) === 0) {
117
+            return 's01';
118
+        }
119
+
120
+        sort($serverConnections);
121
+        $lastKey = array_pop($serverConnections);
122
+        $lastNumber = intval(str_replace('s', '', $lastKey));
123
+        $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
124
+        return $nextPrefix;
125
+    }
126
+
127
+    private function getServersConfig($value) {
128
+        $regex = '/' . $value . '$/S';
129
+
130
+        $keys = $this->config->getAppKeys('user_ldap');
131
+        $result = [];
132
+        foreach ($keys as $key) {
133
+            if (preg_match($regex, $key) === 1) {
134
+                $result[] = $key;
135
+            }
136
+        }
137
+
138
+        return $result;
139
+    }
140
+
141
+    /**
142
+     * deletes a given saved LDAP/AD server configuration.
143
+     * @param string $prefix the configuration prefix of the config to delete
144
+     * @return bool true on success, false otherwise
145
+     */
146
+    public function deleteServerConfiguration($prefix) {
147
+        if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
148
+            return false;
149
+        }
150
+
151
+        $saveOtherConfigurations = '';
152
+        if(empty($prefix)) {
153
+            $saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
154
+        }
155
+
156
+        $query = \OCP\DB::prepare('
157 157
 			DELETE
158 158
 			FROM `*PREFIX*appconfig`
159 159
 			WHERE `configkey` LIKE ?
@@ -161,146 +161,146 @@  discard block
 block discarded – undo
161 161
 				AND `appid` = \'user_ldap\'
162 162
 				AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\')
163 163
 		');
164
-		$delRows = $query->execute(array($prefix.'%'));
165
-
166
-		if(\OCP\DB::isError($delRows)) {
167
-			return false;
168
-		}
169
-
170
-		if($delRows === 0) {
171
-			return false;
172
-		}
173
-
174
-		return true;
175
-	}
176
-
177
-	/**
178
-	 * checks whether there is one or more disabled LDAP configurations
179
-	 * @throws \Exception
180
-	 * @return bool
181
-	 */
182
-	public function haveDisabledConfigurations() {
183
-		$all = $this->getServerConfigurationPrefixes(false);
184
-		$active = $this->getServerConfigurationPrefixes(true);
185
-
186
-		if(!is_array($all) || !is_array($active)) {
187
-			throw new \Exception('Unexpected Return Value');
188
-		}
189
-
190
-		return count($all) !== count($active) || count($all) === 0;
191
-	}
192
-
193
-	/**
194
-	 * extracts the domain from a given URL
195
-	 * @param string $url the URL
196
-	 * @return string|false domain as string on success, false otherwise
197
-	 */
198
-	public function getDomainFromURL($url) {
199
-		$uinfo = parse_url($url);
200
-		if(!is_array($uinfo)) {
201
-			return false;
202
-		}
203
-
204
-		$domain = false;
205
-		if(isset($uinfo['host'])) {
206
-			$domain = $uinfo['host'];
207
-		} else if(isset($uinfo['path'])) {
208
-			$domain = $uinfo['path'];
209
-		}
210
-
211
-		return $domain;
212
-	}
164
+        $delRows = $query->execute(array($prefix.'%'));
165
+
166
+        if(\OCP\DB::isError($delRows)) {
167
+            return false;
168
+        }
169
+
170
+        if($delRows === 0) {
171
+            return false;
172
+        }
173
+
174
+        return true;
175
+    }
176
+
177
+    /**
178
+     * checks whether there is one or more disabled LDAP configurations
179
+     * @throws \Exception
180
+     * @return bool
181
+     */
182
+    public function haveDisabledConfigurations() {
183
+        $all = $this->getServerConfigurationPrefixes(false);
184
+        $active = $this->getServerConfigurationPrefixes(true);
185
+
186
+        if(!is_array($all) || !is_array($active)) {
187
+            throw new \Exception('Unexpected Return Value');
188
+        }
189
+
190
+        return count($all) !== count($active) || count($all) === 0;
191
+    }
192
+
193
+    /**
194
+     * extracts the domain from a given URL
195
+     * @param string $url the URL
196
+     * @return string|false domain as string on success, false otherwise
197
+     */
198
+    public function getDomainFromURL($url) {
199
+        $uinfo = parse_url($url);
200
+        if(!is_array($uinfo)) {
201
+            return false;
202
+        }
203
+
204
+        $domain = false;
205
+        if(isset($uinfo['host'])) {
206
+            $domain = $uinfo['host'];
207
+        } else if(isset($uinfo['path'])) {
208
+            $domain = $uinfo['path'];
209
+        }
210
+
211
+        return $domain;
212
+    }
213 213
 	
214
-	/**
215
-	 *
216
-	 * Set the LDAPProvider in the config
217
-	 *
218
-	 */
219
-	public function setLDAPProvider() {
220
-		$current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null);
221
-		if(is_null($current)) {
222
-			\OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory');
223
-		}
224
-	}
214
+    /**
215
+     *
216
+     * Set the LDAPProvider in the config
217
+     *
218
+     */
219
+    public function setLDAPProvider() {
220
+        $current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null);
221
+        if(is_null($current)) {
222
+            \OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory');
223
+        }
224
+    }
225 225
 	
226
-	/**
227
-	 * sanitizes a DN received from the LDAP server
228
-	 * @param array $dn the DN in question
229
-	 * @return array the sanitized DN
230
-	 */
231
-	public function sanitizeDN($dn) {
232
-		//treating multiple base DNs
233
-		if(is_array($dn)) {
234
-			$result = array();
235
-			foreach($dn as $singleDN) {
236
-				$result[] = $this->sanitizeDN($singleDN);
237
-			}
238
-			return $result;
239
-		}
240
-
241
-		//OID sometimes gives back DNs with whitespace after the comma
242
-		// a la "uid=foo, cn=bar, dn=..." We need to tackle this!
243
-		$dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn);
244
-
245
-		//make comparisons and everything work
246
-		$dn = mb_strtolower($dn, 'UTF-8');
247
-
248
-		//escape DN values according to RFC 2253 – this is already done by ldap_explode_dn
249
-		//to use the DN in search filters, \ needs to be escaped to \5c additionally
250
-		//to use them in bases, we convert them back to simple backslashes in readAttribute()
251
-		$replacements = array(
252
-			'\,' => '\5c2C',
253
-			'\=' => '\5c3D',
254
-			'\+' => '\5c2B',
255
-			'\<' => '\5c3C',
256
-			'\>' => '\5c3E',
257
-			'\;' => '\5c3B',
258
-			'\"' => '\5c22',
259
-			'\#' => '\5c23',
260
-			'('  => '\28',
261
-			')'  => '\29',
262
-			'*'  => '\2A',
263
-		);
264
-		$dn = str_replace(array_keys($replacements), array_values($replacements), $dn);
265
-
266
-		return $dn;
267
-	}
226
+    /**
227
+     * sanitizes a DN received from the LDAP server
228
+     * @param array $dn the DN in question
229
+     * @return array the sanitized DN
230
+     */
231
+    public function sanitizeDN($dn) {
232
+        //treating multiple base DNs
233
+        if(is_array($dn)) {
234
+            $result = array();
235
+            foreach($dn as $singleDN) {
236
+                $result[] = $this->sanitizeDN($singleDN);
237
+            }
238
+            return $result;
239
+        }
240
+
241
+        //OID sometimes gives back DNs with whitespace after the comma
242
+        // a la "uid=foo, cn=bar, dn=..." We need to tackle this!
243
+        $dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn);
244
+
245
+        //make comparisons and everything work
246
+        $dn = mb_strtolower($dn, 'UTF-8');
247
+
248
+        //escape DN values according to RFC 2253 – this is already done by ldap_explode_dn
249
+        //to use the DN in search filters, \ needs to be escaped to \5c additionally
250
+        //to use them in bases, we convert them back to simple backslashes in readAttribute()
251
+        $replacements = array(
252
+            '\,' => '\5c2C',
253
+            '\=' => '\5c3D',
254
+            '\+' => '\5c2B',
255
+            '\<' => '\5c3C',
256
+            '\>' => '\5c3E',
257
+            '\;' => '\5c3B',
258
+            '\"' => '\5c22',
259
+            '\#' => '\5c23',
260
+            '('  => '\28',
261
+            ')'  => '\29',
262
+            '*'  => '\2A',
263
+        );
264
+        $dn = str_replace(array_keys($replacements), array_values($replacements), $dn);
265
+
266
+        return $dn;
267
+    }
268 268
 	
269
-	/**
270
-	 * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters
271
-	 * @param string $dn the DN
272
-	 * @return string
273
-	 */
274
-	public function DNasBaseParameter($dn) {
275
-		return str_ireplace('\\5c', '\\', $dn);
276
-	}
277
-
278
-	/**
279
-	 * listens to a hook thrown by server2server sharing and replaces the given
280
-	 * login name by a username, if it matches an LDAP user.
281
-	 *
282
-	 * @param array $param
283
-	 * @throws \Exception
284
-	 */
285
-	public static function loginName2UserName($param) {
286
-		if(!isset($param['uid'])) {
287
-			throw new \Exception('key uid is expected to be set in $param');
288
-		}
289
-
290
-		//ain't it ironic?
291
-		$helper = new Helper(\OC::$server->getConfig());
292
-
293
-		$configPrefixes = $helper->getServerConfigurationPrefixes(true);
294
-		$ldapWrapper = new LDAP();
295
-		$ocConfig = \OC::$server->getConfig();
296
-		$notificationManager = \OC::$server->getNotificationManager();
297
-
298
-		$userBackend  = new User_Proxy(
299
-			$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager
300
-		);
301
-		$uid = $userBackend->loginName2UserName($param['uid'] );
302
-		if($uid !== false) {
303
-			$param['uid'] = $uid;
304
-		}
305
-	}
269
+    /**
270
+     * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters
271
+     * @param string $dn the DN
272
+     * @return string
273
+     */
274
+    public function DNasBaseParameter($dn) {
275
+        return str_ireplace('\\5c', '\\', $dn);
276
+    }
277
+
278
+    /**
279
+     * listens to a hook thrown by server2server sharing and replaces the given
280
+     * login name by a username, if it matches an LDAP user.
281
+     *
282
+     * @param array $param
283
+     * @throws \Exception
284
+     */
285
+    public static function loginName2UserName($param) {
286
+        if(!isset($param['uid'])) {
287
+            throw new \Exception('key uid is expected to be set in $param');
288
+        }
289
+
290
+        //ain't it ironic?
291
+        $helper = new Helper(\OC::$server->getConfig());
292
+
293
+        $configPrefixes = $helper->getServerConfigurationPrefixes(true);
294
+        $ldapWrapper = new LDAP();
295
+        $ocConfig = \OC::$server->getConfig();
296
+        $notificationManager = \OC::$server->getNotificationManager();
297
+
298
+        $userBackend  = new User_Proxy(
299
+            $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager
300
+        );
301
+        $uid = $userBackend->loginName2UserName($param['uid'] );
302
+        if($uid !== false) {
303
+            $param['uid'] = $uid;
304
+        }
305
+    }
306 306
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		$keys = $this->getServersConfig($referenceConfigkey);
97 97
 
98 98
 		$result = array();
99
-		foreach($keys as $key) {
99
+		foreach ($keys as $key) {
100 100
 			$len = strlen($key) - strlen($referenceConfigkey);
101 101
 			$prefix = substr($key, 0, $len);
102 102
 			$result[$prefix] = $this->config->getAppValue('user_ldap', $key);
@@ -113,19 +113,19 @@  discard block
 block discarded – undo
113 113
 	public function getNextServerConfigurationPrefix() {
114 114
 		$serverConnections = $this->getServerConfigurationPrefixes();
115 115
 
116
-		if(count($serverConnections) === 0) {
116
+		if (count($serverConnections) === 0) {
117 117
 			return 's01';
118 118
 		}
119 119
 
120 120
 		sort($serverConnections);
121 121
 		$lastKey = array_pop($serverConnections);
122 122
 		$lastNumber = intval(str_replace('s', '', $lastKey));
123
-		$nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
123
+		$nextPrefix = 's'.str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT);
124 124
 		return $nextPrefix;
125 125
 	}
126 126
 
127 127
 	private function getServersConfig($value) {
128
-		$regex = '/' . $value . '$/S';
128
+		$regex = '/'.$value.'$/S';
129 129
 
130 130
 		$keys = $this->config->getAppKeys('user_ldap');
131 131
 		$result = [];
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
 	 * @return bool true on success, false otherwise
145 145
 	 */
146 146
 	public function deleteServerConfiguration($prefix) {
147
-		if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
147
+		if (!in_array($prefix, self::getServerConfigurationPrefixes())) {
148 148
 			return false;
149 149
 		}
150 150
 
151 151
 		$saveOtherConfigurations = '';
152
-		if(empty($prefix)) {
152
+		if (empty($prefix)) {
153 153
 			$saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
154 154
 		}
155 155
 
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 		');
164 164
 		$delRows = $query->execute(array($prefix.'%'));
165 165
 
166
-		if(\OCP\DB::isError($delRows)) {
166
+		if (\OCP\DB::isError($delRows)) {
167 167
 			return false;
168 168
 		}
169 169
 
170
-		if($delRows === 0) {
170
+		if ($delRows === 0) {
171 171
 			return false;
172 172
 		}
173 173
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		$all = $this->getServerConfigurationPrefixes(false);
184 184
 		$active = $this->getServerConfigurationPrefixes(true);
185 185
 
186
-		if(!is_array($all) || !is_array($active)) {
186
+		if (!is_array($all) || !is_array($active)) {
187 187
 			throw new \Exception('Unexpected Return Value');
188 188
 		}
189 189
 
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function getDomainFromURL($url) {
199 199
 		$uinfo = parse_url($url);
200
-		if(!is_array($uinfo)) {
200
+		if (!is_array($uinfo)) {
201 201
 			return false;
202 202
 		}
203 203
 
204 204
 		$domain = false;
205
-		if(isset($uinfo['host'])) {
205
+		if (isset($uinfo['host'])) {
206 206
 			$domain = $uinfo['host'];
207
-		} else if(isset($uinfo['path'])) {
207
+		} else if (isset($uinfo['path'])) {
208 208
 			$domain = $uinfo['path'];
209 209
 		}
210 210
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 */
219 219
 	public function setLDAPProvider() {
220 220
 		$current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null);
221
-		if(is_null($current)) {
221
+		if (is_null($current)) {
222 222
 			\OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory');
223 223
 		}
224 224
 	}
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	public function sanitizeDN($dn) {
232 232
 		//treating multiple base DNs
233
-		if(is_array($dn)) {
233
+		if (is_array($dn)) {
234 234
 			$result = array();
235
-			foreach($dn as $singleDN) {
235
+			foreach ($dn as $singleDN) {
236 236
 				$result[] = $this->sanitizeDN($singleDN);
237 237
 			}
238 238
 			return $result;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 * @throws \Exception
284 284
 	 */
285 285
 	public static function loginName2UserName($param) {
286
-		if(!isset($param['uid'])) {
286
+		if (!isset($param['uid'])) {
287 287
 			throw new \Exception('key uid is expected to be set in $param');
288 288
 		}
289 289
 
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 		$ocConfig = \OC::$server->getConfig();
296 296
 		$notificationManager = \OC::$server->getNotificationManager();
297 297
 
298
-		$userBackend  = new User_Proxy(
298
+		$userBackend = new User_Proxy(
299 299
 			$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager
300 300
 		);
301
-		$uid = $userBackend->loginName2UserName($param['uid'] );
302
-		if($uid !== false) {
301
+		$uid = $userBackend->loginName2UserName($param['uid']);
302
+		if ($uid !== false) {
303 303
 			$param['uid'] = $uid;
304 304
 		}
305 305
 	}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Configuration.php 1 patch
Indentation   +460 added lines, -460 removed lines patch added patch discarded remove patch
@@ -36,489 +36,489 @@
 block discarded – undo
36 36
  */
37 37
 class Configuration {
38 38
 
39
-	protected $configPrefix = null;
40
-	protected $configRead = false;
39
+    protected $configPrefix = null;
40
+    protected $configRead = false;
41 41
 
42
-	//settings
43
-	protected $config = array(
44
-		'ldapHost' => null,
45
-		'ldapPort' => null,
46
-		'ldapBackupHost' => null,
47
-		'ldapBackupPort' => null,
48
-		'ldapBase' => null,
49
-		'ldapBaseUsers' => null,
50
-		'ldapBaseGroups' => null,
51
-		'ldapAgentName' => null,
52
-		'ldapAgentPassword' => null,
53
-		'ldapTLS' => null,
54
-		'turnOffCertCheck' => null,
55
-		'ldapIgnoreNamingRules' => null,
56
-		'ldapUserDisplayName' => null,
57
-		'ldapUserDisplayName2' => null,
58
-		'ldapUserFilterObjectclass' => null,
59
-		'ldapUserFilterGroups' => null,
60
-		'ldapUserFilter' => null,
61
-		'ldapUserFilterMode' => null,
62
-		'ldapGroupFilter' => null,
63
-		'ldapGroupFilterMode' => null,
64
-		'ldapGroupFilterObjectclass' => null,
65
-		'ldapGroupFilterGroups' => null,
66
-		'ldapGroupDisplayName' => null,
67
-		'ldapGroupMemberAssocAttr' => null,
68
-		'ldapLoginFilter' => null,
69
-		'ldapLoginFilterMode' => null,
70
-		'ldapLoginFilterEmail' => null,
71
-		'ldapLoginFilterUsername' => null,
72
-		'ldapLoginFilterAttributes' => null,
73
-		'ldapQuotaAttribute' => null,
74
-		'ldapQuotaDefault' => null,
75
-		'ldapEmailAttribute' => null,
76
-		'ldapCacheTTL' => null,
77
-		'ldapUuidUserAttribute' => 'auto',
78
-		'ldapUuidGroupAttribute' => 'auto',
79
-		'ldapOverrideMainServer' => false,
80
-		'ldapConfigurationActive' => false,
81
-		'ldapAttributesForUserSearch' => null,
82
-		'ldapAttributesForGroupSearch' => null,
83
-		'ldapExperiencedAdmin' => false,
84
-		'homeFolderNamingRule' => null,
85
-		'hasPagedResultSupport' => false,
86
-		'hasMemberOfFilterSupport' => false,
87
-		'useMemberOfToDetectMembership' => true,
88
-		'ldapExpertUsernameAttr' => null,
89
-		'ldapExpertUUIDUserAttr' => null,
90
-		'ldapExpertUUIDGroupAttr' => null,
91
-		'lastJpegPhotoLookup' => null,
92
-		'ldapNestedGroups' => false,
93
-		'ldapPagingSize' => null,
94
-		'turnOnPasswordChange' => false,
95
-		'ldapDynamicGroupMemberURL' => null,
96
-		'ldapDefaultPPolicyDN' => null,
97
-	);
42
+    //settings
43
+    protected $config = array(
44
+        'ldapHost' => null,
45
+        'ldapPort' => null,
46
+        'ldapBackupHost' => null,
47
+        'ldapBackupPort' => null,
48
+        'ldapBase' => null,
49
+        'ldapBaseUsers' => null,
50
+        'ldapBaseGroups' => null,
51
+        'ldapAgentName' => null,
52
+        'ldapAgentPassword' => null,
53
+        'ldapTLS' => null,
54
+        'turnOffCertCheck' => null,
55
+        'ldapIgnoreNamingRules' => null,
56
+        'ldapUserDisplayName' => null,
57
+        'ldapUserDisplayName2' => null,
58
+        'ldapUserFilterObjectclass' => null,
59
+        'ldapUserFilterGroups' => null,
60
+        'ldapUserFilter' => null,
61
+        'ldapUserFilterMode' => null,
62
+        'ldapGroupFilter' => null,
63
+        'ldapGroupFilterMode' => null,
64
+        'ldapGroupFilterObjectclass' => null,
65
+        'ldapGroupFilterGroups' => null,
66
+        'ldapGroupDisplayName' => null,
67
+        'ldapGroupMemberAssocAttr' => null,
68
+        'ldapLoginFilter' => null,
69
+        'ldapLoginFilterMode' => null,
70
+        'ldapLoginFilterEmail' => null,
71
+        'ldapLoginFilterUsername' => null,
72
+        'ldapLoginFilterAttributes' => null,
73
+        'ldapQuotaAttribute' => null,
74
+        'ldapQuotaDefault' => null,
75
+        'ldapEmailAttribute' => null,
76
+        'ldapCacheTTL' => null,
77
+        'ldapUuidUserAttribute' => 'auto',
78
+        'ldapUuidGroupAttribute' => 'auto',
79
+        'ldapOverrideMainServer' => false,
80
+        'ldapConfigurationActive' => false,
81
+        'ldapAttributesForUserSearch' => null,
82
+        'ldapAttributesForGroupSearch' => null,
83
+        'ldapExperiencedAdmin' => false,
84
+        'homeFolderNamingRule' => null,
85
+        'hasPagedResultSupport' => false,
86
+        'hasMemberOfFilterSupport' => false,
87
+        'useMemberOfToDetectMembership' => true,
88
+        'ldapExpertUsernameAttr' => null,
89
+        'ldapExpertUUIDUserAttr' => null,
90
+        'ldapExpertUUIDGroupAttr' => null,
91
+        'lastJpegPhotoLookup' => null,
92
+        'ldapNestedGroups' => false,
93
+        'ldapPagingSize' => null,
94
+        'turnOnPasswordChange' => false,
95
+        'ldapDynamicGroupMemberURL' => null,
96
+        'ldapDefaultPPolicyDN' => null,
97
+    );
98 98
 
99
-	/**
100
-	 * @param string $configPrefix
101
-	 * @param bool $autoRead
102
-	 */
103
-	public function __construct($configPrefix, $autoRead = true) {
104
-		$this->configPrefix = $configPrefix;
105
-		if($autoRead) {
106
-			$this->readConfiguration();
107
-		}
108
-	}
99
+    /**
100
+     * @param string $configPrefix
101
+     * @param bool $autoRead
102
+     */
103
+    public function __construct($configPrefix, $autoRead = true) {
104
+        $this->configPrefix = $configPrefix;
105
+        if($autoRead) {
106
+            $this->readConfiguration();
107
+        }
108
+    }
109 109
 
110
-	/**
111
-	 * @param string $name
112
-	 * @return mixed|null
113
-	 */
114
-	public function __get($name) {
115
-		if(isset($this->config[$name])) {
116
-			return $this->config[$name];
117
-		}
118
-		return null;
119
-	}
110
+    /**
111
+     * @param string $name
112
+     * @return mixed|null
113
+     */
114
+    public function __get($name) {
115
+        if(isset($this->config[$name])) {
116
+            return $this->config[$name];
117
+        }
118
+        return null;
119
+    }
120 120
 
121
-	/**
122
-	 * @param string $name
123
-	 * @param mixed $value
124
-	 */
125
-	public function __set($name, $value) {
126
-		$this->setConfiguration(array($name => $value));
127
-	}
121
+    /**
122
+     * @param string $name
123
+     * @param mixed $value
124
+     */
125
+    public function __set($name, $value) {
126
+        $this->setConfiguration(array($name => $value));
127
+    }
128 128
 
129
-	/**
130
-	 * @return array
131
-	 */
132
-	public function getConfiguration() {
133
-		return $this->config;
134
-	}
129
+    /**
130
+     * @return array
131
+     */
132
+    public function getConfiguration() {
133
+        return $this->config;
134
+    }
135 135
 
136
-	/**
137
-	 * set LDAP configuration with values delivered by an array, not read
138
-	 * from configuration. It does not save the configuration! To do so, you
139
-	 * must call saveConfiguration afterwards.
140
-	 * @param array $config array that holds the config parameters in an associated
141
-	 * array
142
-	 * @param array &$applied optional; array where the set fields will be given to
143
-	 * @return false|null
144
-	 */
145
-	public function setConfiguration($config, &$applied = null) {
146
-		if(!is_array($config)) {
147
-			return false;
148
-		}
136
+    /**
137
+     * set LDAP configuration with values delivered by an array, not read
138
+     * from configuration. It does not save the configuration! To do so, you
139
+     * must call saveConfiguration afterwards.
140
+     * @param array $config array that holds the config parameters in an associated
141
+     * array
142
+     * @param array &$applied optional; array where the set fields will be given to
143
+     * @return false|null
144
+     */
145
+    public function setConfiguration($config, &$applied = null) {
146
+        if(!is_array($config)) {
147
+            return false;
148
+        }
149 149
 
150
-		$cta = $this->getConfigTranslationArray();
151
-		foreach($config as $inputKey => $val) {
152
-			if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
153
-				$key = $cta[$inputKey];
154
-			} elseif(array_key_exists($inputKey, $this->config)) {
155
-				$key = $inputKey;
156
-			} else {
157
-				continue;
158
-			}
150
+        $cta = $this->getConfigTranslationArray();
151
+        foreach($config as $inputKey => $val) {
152
+            if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
153
+                $key = $cta[$inputKey];
154
+            } elseif(array_key_exists($inputKey, $this->config)) {
155
+                $key = $inputKey;
156
+            } else {
157
+                continue;
158
+            }
159 159
 
160
-			$setMethod = 'setValue';
161
-			switch($key) {
162
-				case 'ldapAgentPassword':
163
-					$setMethod = 'setRawValue';
164
-					break;
165
-				case 'homeFolderNamingRule':
166
-					$trimmedVal = trim($val);
167
-					if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
168
-						$val = 'attr:'.$trimmedVal;
169
-					}
170
-					break;
171
-				case 'ldapBase':
172
-				case 'ldapBaseUsers':
173
-				case 'ldapBaseGroups':
174
-				case 'ldapAttributesForUserSearch':
175
-				case 'ldapAttributesForGroupSearch':
176
-				case 'ldapUserFilterObjectclass':
177
-				case 'ldapUserFilterGroups':
178
-				case 'ldapGroupFilterObjectclass':
179
-				case 'ldapGroupFilterGroups':
180
-				case 'ldapLoginFilterAttributes':
181
-					$setMethod = 'setMultiLine';
182
-					break;
183
-			}
184
-			$this->$setMethod($key, $val);
185
-			if(is_array($applied)) {
186
-				$applied[] = $inputKey;
187
-			}
188
-		}
189
-		return null;
190
-	}
160
+            $setMethod = 'setValue';
161
+            switch($key) {
162
+                case 'ldapAgentPassword':
163
+                    $setMethod = 'setRawValue';
164
+                    break;
165
+                case 'homeFolderNamingRule':
166
+                    $trimmedVal = trim($val);
167
+                    if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
168
+                        $val = 'attr:'.$trimmedVal;
169
+                    }
170
+                    break;
171
+                case 'ldapBase':
172
+                case 'ldapBaseUsers':
173
+                case 'ldapBaseGroups':
174
+                case 'ldapAttributesForUserSearch':
175
+                case 'ldapAttributesForGroupSearch':
176
+                case 'ldapUserFilterObjectclass':
177
+                case 'ldapUserFilterGroups':
178
+                case 'ldapGroupFilterObjectclass':
179
+                case 'ldapGroupFilterGroups':
180
+                case 'ldapLoginFilterAttributes':
181
+                    $setMethod = 'setMultiLine';
182
+                    break;
183
+            }
184
+            $this->$setMethod($key, $val);
185
+            if(is_array($applied)) {
186
+                $applied[] = $inputKey;
187
+            }
188
+        }
189
+        return null;
190
+    }
191 191
 
192
-	public function readConfiguration() {
193
-		if(!$this->configRead && !is_null($this->configPrefix)) {
194
-			$cta = array_flip($this->getConfigTranslationArray());
195
-			foreach($this->config as $key => $val) {
196
-				if(!isset($cta[$key])) {
197
-					//some are determined
198
-					continue;
199
-				}
200
-				$dbKey = $cta[$key];
201
-				switch($key) {
202
-					case 'ldapBase':
203
-					case 'ldapBaseUsers':
204
-					case 'ldapBaseGroups':
205
-					case 'ldapAttributesForUserSearch':
206
-					case 'ldapAttributesForGroupSearch':
207
-					case 'ldapUserFilterObjectclass':
208
-					case 'ldapUserFilterGroups':
209
-					case 'ldapGroupFilterObjectclass':
210
-					case 'ldapGroupFilterGroups':
211
-					case 'ldapLoginFilterAttributes':
212
-						$readMethod = 'getMultiLine';
213
-						break;
214
-					case 'ldapIgnoreNamingRules':
215
-						$readMethod = 'getSystemValue';
216
-						$dbKey = $key;
217
-						break;
218
-					case 'ldapAgentPassword':
219
-						$readMethod = 'getPwd';
220
-						break;
221
-					case 'ldapUserDisplayName2':
222
-					case 'ldapGroupDisplayName':
223
-						$readMethod = 'getLcValue';
224
-						break;
225
-					case 'ldapUserDisplayName':
226
-					default:
227
-						// user display name does not lower case because
228
-						// we rely on an upper case N as indicator whether to
229
-						// auto-detect it or not. FIXME
230
-						$readMethod = 'getValue';
231
-						break;
232
-				}
233
-				$this->config[$key] = $this->$readMethod($dbKey);
234
-			}
235
-			$this->configRead = true;
236
-		}
237
-	}
192
+    public function readConfiguration() {
193
+        if(!$this->configRead && !is_null($this->configPrefix)) {
194
+            $cta = array_flip($this->getConfigTranslationArray());
195
+            foreach($this->config as $key => $val) {
196
+                if(!isset($cta[$key])) {
197
+                    //some are determined
198
+                    continue;
199
+                }
200
+                $dbKey = $cta[$key];
201
+                switch($key) {
202
+                    case 'ldapBase':
203
+                    case 'ldapBaseUsers':
204
+                    case 'ldapBaseGroups':
205
+                    case 'ldapAttributesForUserSearch':
206
+                    case 'ldapAttributesForGroupSearch':
207
+                    case 'ldapUserFilterObjectclass':
208
+                    case 'ldapUserFilterGroups':
209
+                    case 'ldapGroupFilterObjectclass':
210
+                    case 'ldapGroupFilterGroups':
211
+                    case 'ldapLoginFilterAttributes':
212
+                        $readMethod = 'getMultiLine';
213
+                        break;
214
+                    case 'ldapIgnoreNamingRules':
215
+                        $readMethod = 'getSystemValue';
216
+                        $dbKey = $key;
217
+                        break;
218
+                    case 'ldapAgentPassword':
219
+                        $readMethod = 'getPwd';
220
+                        break;
221
+                    case 'ldapUserDisplayName2':
222
+                    case 'ldapGroupDisplayName':
223
+                        $readMethod = 'getLcValue';
224
+                        break;
225
+                    case 'ldapUserDisplayName':
226
+                    default:
227
+                        // user display name does not lower case because
228
+                        // we rely on an upper case N as indicator whether to
229
+                        // auto-detect it or not. FIXME
230
+                        $readMethod = 'getValue';
231
+                        break;
232
+                }
233
+                $this->config[$key] = $this->$readMethod($dbKey);
234
+            }
235
+            $this->configRead = true;
236
+        }
237
+    }
238 238
 
239
-	/**
240
-	 * saves the current Configuration in the database
241
-	 */
242
-	public function saveConfiguration() {
243
-		$cta = array_flip($this->getConfigTranslationArray());
244
-		foreach($this->config as $key => $value) {
245
-			switch ($key) {
246
-				case 'ldapAgentPassword':
247
-					$value = base64_encode($value);
248
-					break;
249
-				case 'ldapBase':
250
-				case 'ldapBaseUsers':
251
-				case 'ldapBaseGroups':
252
-				case 'ldapAttributesForUserSearch':
253
-				case 'ldapAttributesForGroupSearch':
254
-				case 'ldapUserFilterObjectclass':
255
-				case 'ldapUserFilterGroups':
256
-				case 'ldapGroupFilterObjectclass':
257
-				case 'ldapGroupFilterGroups':
258
-				case 'ldapLoginFilterAttributes':
259
-					if(is_array($value)) {
260
-						$value = implode("\n", $value);
261
-					}
262
-					break;
263
-				//following options are not stored but detected, skip them
264
-				case 'ldapIgnoreNamingRules':
265
-				case 'hasPagedResultSupport':
266
-				case 'ldapUuidUserAttribute':
267
-				case 'ldapUuidGroupAttribute':
268
-					continue 2;
269
-			}
270
-			if(is_null($value)) {
271
-				$value = '';
272
-			}
273
-			$this->saveValue($cta[$key], $value);
274
-		}
275
-	}
239
+    /**
240
+     * saves the current Configuration in the database
241
+     */
242
+    public function saveConfiguration() {
243
+        $cta = array_flip($this->getConfigTranslationArray());
244
+        foreach($this->config as $key => $value) {
245
+            switch ($key) {
246
+                case 'ldapAgentPassword':
247
+                    $value = base64_encode($value);
248
+                    break;
249
+                case 'ldapBase':
250
+                case 'ldapBaseUsers':
251
+                case 'ldapBaseGroups':
252
+                case 'ldapAttributesForUserSearch':
253
+                case 'ldapAttributesForGroupSearch':
254
+                case 'ldapUserFilterObjectclass':
255
+                case 'ldapUserFilterGroups':
256
+                case 'ldapGroupFilterObjectclass':
257
+                case 'ldapGroupFilterGroups':
258
+                case 'ldapLoginFilterAttributes':
259
+                    if(is_array($value)) {
260
+                        $value = implode("\n", $value);
261
+                    }
262
+                    break;
263
+                //following options are not stored but detected, skip them
264
+                case 'ldapIgnoreNamingRules':
265
+                case 'hasPagedResultSupport':
266
+                case 'ldapUuidUserAttribute':
267
+                case 'ldapUuidGroupAttribute':
268
+                    continue 2;
269
+            }
270
+            if(is_null($value)) {
271
+                $value = '';
272
+            }
273
+            $this->saveValue($cta[$key], $value);
274
+        }
275
+    }
276 276
 
277
-	/**
278
-	 * @param string $varName
279
-	 * @return array|string
280
-	 */
281
-	protected function getMultiLine($varName) {
282
-		$value = $this->getValue($varName);
283
-		if(empty($value)) {
284
-			$value = '';
285
-		} else {
286
-			$value = preg_split('/\r\n|\r|\n/', $value);
287
-		}
277
+    /**
278
+     * @param string $varName
279
+     * @return array|string
280
+     */
281
+    protected function getMultiLine($varName) {
282
+        $value = $this->getValue($varName);
283
+        if(empty($value)) {
284
+            $value = '';
285
+        } else {
286
+            $value = preg_split('/\r\n|\r|\n/', $value);
287
+        }
288 288
 
289
-		return $value;
290
-	}
289
+        return $value;
290
+    }
291 291
 
292
-	/**
293
-	 * Sets multi-line values as arrays
294
-	 * 
295
-	 * @param string $varName name of config-key
296
-	 * @param array|string $value to set
297
-	 */
298
-	protected function setMultiLine($varName, $value) {
299
-		if(empty($value)) {
300
-			$value = '';
301
-		} else if (!is_array($value)) {
302
-			$value = preg_split('/\r\n|\r|\n|;/', $value);
303
-			if($value === false) {
304
-				$value = '';
305
-			}
306
-		}
292
+    /**
293
+     * Sets multi-line values as arrays
294
+     * 
295
+     * @param string $varName name of config-key
296
+     * @param array|string $value to set
297
+     */
298
+    protected function setMultiLine($varName, $value) {
299
+        if(empty($value)) {
300
+            $value = '';
301
+        } else if (!is_array($value)) {
302
+            $value = preg_split('/\r\n|\r|\n|;/', $value);
303
+            if($value === false) {
304
+                $value = '';
305
+            }
306
+        }
307 307
 
308
-		if(!is_array($value)) {
309
-			$finalValue = trim($value);
310
-		} else {
311
-			$finalValue = [];
312
-			foreach($value as $key => $val) {
313
-				if(is_string($val)) {
314
-					$val = trim($val);
315
-					if ($val !== '') {
316
-						//accidental line breaks are not wanted and can cause
317
-						// odd behaviour. Thus, away with them.
318
-						$finalValue[] = $val;
319
-					}
320
-				} else {
321
-					$finalValue[] = $val;
322
-				}
323
-			}
324
-		}
308
+        if(!is_array($value)) {
309
+            $finalValue = trim($value);
310
+        } else {
311
+            $finalValue = [];
312
+            foreach($value as $key => $val) {
313
+                if(is_string($val)) {
314
+                    $val = trim($val);
315
+                    if ($val !== '') {
316
+                        //accidental line breaks are not wanted and can cause
317
+                        // odd behaviour. Thus, away with them.
318
+                        $finalValue[] = $val;
319
+                    }
320
+                } else {
321
+                    $finalValue[] = $val;
322
+                }
323
+            }
324
+        }
325 325
 
326
-		$this->setRawValue($varName, $finalValue);
327
-	}
326
+        $this->setRawValue($varName, $finalValue);
327
+    }
328 328
 
329
-	/**
330
-	 * @param string $varName
331
-	 * @return string
332
-	 */
333
-	protected function getPwd($varName) {
334
-		return base64_decode($this->getValue($varName));
335
-	}
329
+    /**
330
+     * @param string $varName
331
+     * @return string
332
+     */
333
+    protected function getPwd($varName) {
334
+        return base64_decode($this->getValue($varName));
335
+    }
336 336
 
337
-	/**
338
-	 * @param string $varName
339
-	 * @return string
340
-	 */
341
-	protected function getLcValue($varName) {
342
-		return mb_strtolower($this->getValue($varName), 'UTF-8');
343
-	}
337
+    /**
338
+     * @param string $varName
339
+     * @return string
340
+     */
341
+    protected function getLcValue($varName) {
342
+        return mb_strtolower($this->getValue($varName), 'UTF-8');
343
+    }
344 344
 
345
-	/**
346
-	 * @param string $varName
347
-	 * @return string
348
-	 */
349
-	protected function getSystemValue($varName) {
350
-		//FIXME: if another system value is added, softcode the default value
351
-		return \OCP\Config::getSystemValue($varName, false);
352
-	}
345
+    /**
346
+     * @param string $varName
347
+     * @return string
348
+     */
349
+    protected function getSystemValue($varName) {
350
+        //FIXME: if another system value is added, softcode the default value
351
+        return \OCP\Config::getSystemValue($varName, false);
352
+    }
353 353
 
354
-	/**
355
-	 * @param string $varName
356
-	 * @return string
357
-	 */
358
-	protected function getValue($varName) {
359
-		static $defaults;
360
-		if(is_null($defaults)) {
361
-			$defaults = $this->getDefaults();
362
-		}
363
-		return \OCP\Config::getAppValue('user_ldap',
364
-										$this->configPrefix.$varName,
365
-										$defaults[$varName]);
366
-	}
354
+    /**
355
+     * @param string $varName
356
+     * @return string
357
+     */
358
+    protected function getValue($varName) {
359
+        static $defaults;
360
+        if(is_null($defaults)) {
361
+            $defaults = $this->getDefaults();
362
+        }
363
+        return \OCP\Config::getAppValue('user_ldap',
364
+                                        $this->configPrefix.$varName,
365
+                                        $defaults[$varName]);
366
+    }
367 367
 
368
-	/**
369
-	 * Sets a scalar value.
370
-	 * 
371
-	 * @param string $varName name of config key
372
-	 * @param mixed $value to set
373
-	 */
374
-	protected function setValue($varName, $value) {
375
-		if(is_string($value)) {
376
-			$value = trim($value);
377
-		}
378
-		$this->config[$varName] = $value;
379
-	}
368
+    /**
369
+     * Sets a scalar value.
370
+     * 
371
+     * @param string $varName name of config key
372
+     * @param mixed $value to set
373
+     */
374
+    protected function setValue($varName, $value) {
375
+        if(is_string($value)) {
376
+            $value = trim($value);
377
+        }
378
+        $this->config[$varName] = $value;
379
+    }
380 380
 
381
-	/**
382
-	 * Sets a scalar value without trimming.
383
-	 *
384
-	 * @param string $varName name of config key
385
-	 * @param mixed $value to set
386
-	 */
387
-	protected function setRawValue($varName, $value) {
388
-		$this->config[$varName] = $value;
389
-	}
381
+    /**
382
+     * Sets a scalar value without trimming.
383
+     *
384
+     * @param string $varName name of config key
385
+     * @param mixed $value to set
386
+     */
387
+    protected function setRawValue($varName, $value) {
388
+        $this->config[$varName] = $value;
389
+    }
390 390
 
391
-	/**
392
-	 * @param string $varName
393
-	 * @param string $value
394
-	 * @return bool
395
-	 */
396
-	protected function saveValue($varName, $value) {
397
-		\OC::$server->getConfig()->setAppValue(
398
-			'user_ldap',
399
-			$this->configPrefix.$varName,
400
-			$value
401
-		);
402
-		return true;
403
-	}
391
+    /**
392
+     * @param string $varName
393
+     * @param string $value
394
+     * @return bool
395
+     */
396
+    protected function saveValue($varName, $value) {
397
+        \OC::$server->getConfig()->setAppValue(
398
+            'user_ldap',
399
+            $this->configPrefix.$varName,
400
+            $value
401
+        );
402
+        return true;
403
+    }
404 404
 
405
-	/**
406
-	 * @return array an associative array with the default values. Keys are correspond
407
-	 * to config-value entries in the database table
408
-	 */
409
-	public function getDefaults() {
410
-		return array(
411
-			'ldap_host'                         => '',
412
-			'ldap_port'                         => '',
413
-			'ldap_backup_host'                  => '',
414
-			'ldap_backup_port'                  => '',
415
-			'ldap_override_main_server'         => '',
416
-			'ldap_dn'                           => '',
417
-			'ldap_agent_password'               => '',
418
-			'ldap_base'                         => '',
419
-			'ldap_base_users'                   => '',
420
-			'ldap_base_groups'                  => '',
421
-			'ldap_userlist_filter'              => '',
422
-			'ldap_user_filter_mode'             => 0,
423
-			'ldap_userfilter_objectclass'       => '',
424
-			'ldap_userfilter_groups'            => '',
425
-			'ldap_login_filter'                 => '',
426
-			'ldap_login_filter_mode'            => 0,
427
-			'ldap_loginfilter_email'            => 0,
428
-			'ldap_loginfilter_username'         => 1,
429
-			'ldap_loginfilter_attributes'       => '',
430
-			'ldap_group_filter'                 => '',
431
-			'ldap_group_filter_mode'            => 0,
432
-			'ldap_groupfilter_objectclass'      => '',
433
-			'ldap_groupfilter_groups'           => '',
434
-			'ldap_display_name'                 => 'displayName',
435
-			'ldap_user_display_name_2'			=> '',
436
-			'ldap_group_display_name'           => 'cn',
437
-			'ldap_tls'                          => 0,
438
-			'ldap_quota_def'                    => '',
439
-			'ldap_quota_attr'                   => '',
440
-			'ldap_email_attr'                   => '',
441
-			'ldap_group_member_assoc_attribute' => 'uniqueMember',
442
-			'ldap_cache_ttl'                    => 600,
443
-			'ldap_uuid_user_attribute'          => 'auto',
444
-			'ldap_uuid_group_attribute'         => 'auto',
445
-			'home_folder_naming_rule'           => '',
446
-			'ldap_turn_off_cert_check'          => 0,
447
-			'ldap_configuration_active'         => 0,
448
-			'ldap_attributes_for_user_search'   => '',
449
-			'ldap_attributes_for_group_search'  => '',
450
-			'ldap_expert_username_attr'         => '',
451
-			'ldap_expert_uuid_user_attr'        => '',
452
-			'ldap_expert_uuid_group_attr'       => '',
453
-			'has_memberof_filter_support'       => 0,
454
-			'use_memberof_to_detect_membership' => 1,
455
-			'last_jpegPhoto_lookup'             => 0,
456
-			'ldap_nested_groups'                => 0,
457
-			'ldap_paging_size'                  => 500,
458
-			'ldap_turn_on_pwd_change'           => 0,
459
-			'ldap_experienced_admin'            => 0,
460
-			'ldap_dynamic_group_member_url'     => '',
461
-			'ldap_default_ppolicy_dn'           => '',
462
-		);
463
-	}
405
+    /**
406
+     * @return array an associative array with the default values. Keys are correspond
407
+     * to config-value entries in the database table
408
+     */
409
+    public function getDefaults() {
410
+        return array(
411
+            'ldap_host'                         => '',
412
+            'ldap_port'                         => '',
413
+            'ldap_backup_host'                  => '',
414
+            'ldap_backup_port'                  => '',
415
+            'ldap_override_main_server'         => '',
416
+            'ldap_dn'                           => '',
417
+            'ldap_agent_password'               => '',
418
+            'ldap_base'                         => '',
419
+            'ldap_base_users'                   => '',
420
+            'ldap_base_groups'                  => '',
421
+            'ldap_userlist_filter'              => '',
422
+            'ldap_user_filter_mode'             => 0,
423
+            'ldap_userfilter_objectclass'       => '',
424
+            'ldap_userfilter_groups'            => '',
425
+            'ldap_login_filter'                 => '',
426
+            'ldap_login_filter_mode'            => 0,
427
+            'ldap_loginfilter_email'            => 0,
428
+            'ldap_loginfilter_username'         => 1,
429
+            'ldap_loginfilter_attributes'       => '',
430
+            'ldap_group_filter'                 => '',
431
+            'ldap_group_filter_mode'            => 0,
432
+            'ldap_groupfilter_objectclass'      => '',
433
+            'ldap_groupfilter_groups'           => '',
434
+            'ldap_display_name'                 => 'displayName',
435
+            'ldap_user_display_name_2'			=> '',
436
+            'ldap_group_display_name'           => 'cn',
437
+            'ldap_tls'                          => 0,
438
+            'ldap_quota_def'                    => '',
439
+            'ldap_quota_attr'                   => '',
440
+            'ldap_email_attr'                   => '',
441
+            'ldap_group_member_assoc_attribute' => 'uniqueMember',
442
+            'ldap_cache_ttl'                    => 600,
443
+            'ldap_uuid_user_attribute'          => 'auto',
444
+            'ldap_uuid_group_attribute'         => 'auto',
445
+            'home_folder_naming_rule'           => '',
446
+            'ldap_turn_off_cert_check'          => 0,
447
+            'ldap_configuration_active'         => 0,
448
+            'ldap_attributes_for_user_search'   => '',
449
+            'ldap_attributes_for_group_search'  => '',
450
+            'ldap_expert_username_attr'         => '',
451
+            'ldap_expert_uuid_user_attr'        => '',
452
+            'ldap_expert_uuid_group_attr'       => '',
453
+            'has_memberof_filter_support'       => 0,
454
+            'use_memberof_to_detect_membership' => 1,
455
+            'last_jpegPhoto_lookup'             => 0,
456
+            'ldap_nested_groups'                => 0,
457
+            'ldap_paging_size'                  => 500,
458
+            'ldap_turn_on_pwd_change'           => 0,
459
+            'ldap_experienced_admin'            => 0,
460
+            'ldap_dynamic_group_member_url'     => '',
461
+            'ldap_default_ppolicy_dn'           => '',
462
+        );
463
+    }
464 464
 
465
-	/**
466
-	 * @return array that maps internal variable names to database fields
467
-	 */
468
-	public function getConfigTranslationArray() {
469
-		//TODO: merge them into one representation
470
-		static $array = array(
471
-			'ldap_host'                         => 'ldapHost',
472
-			'ldap_port'                         => 'ldapPort',
473
-			'ldap_backup_host'                  => 'ldapBackupHost',
474
-			'ldap_backup_port'                  => 'ldapBackupPort',
475
-			'ldap_override_main_server'         => 'ldapOverrideMainServer',
476
-			'ldap_dn'                           => 'ldapAgentName',
477
-			'ldap_agent_password'               => 'ldapAgentPassword',
478
-			'ldap_base'                         => 'ldapBase',
479
-			'ldap_base_users'                   => 'ldapBaseUsers',
480
-			'ldap_base_groups'                  => 'ldapBaseGroups',
481
-			'ldap_userfilter_objectclass'       => 'ldapUserFilterObjectclass',
482
-			'ldap_userfilter_groups'            => 'ldapUserFilterGroups',
483
-			'ldap_userlist_filter'              => 'ldapUserFilter',
484
-			'ldap_user_filter_mode'             => 'ldapUserFilterMode',
485
-			'ldap_login_filter'                 => 'ldapLoginFilter',
486
-			'ldap_login_filter_mode'            => 'ldapLoginFilterMode',
487
-			'ldap_loginfilter_email'            => 'ldapLoginFilterEmail',
488
-			'ldap_loginfilter_username'         => 'ldapLoginFilterUsername',
489
-			'ldap_loginfilter_attributes'       => 'ldapLoginFilterAttributes',
490
-			'ldap_group_filter'                 => 'ldapGroupFilter',
491
-			'ldap_group_filter_mode'            => 'ldapGroupFilterMode',
492
-			'ldap_groupfilter_objectclass'      => 'ldapGroupFilterObjectclass',
493
-			'ldap_groupfilter_groups'           => 'ldapGroupFilterGroups',
494
-			'ldap_display_name'                 => 'ldapUserDisplayName',
495
-			'ldap_user_display_name_2'			=> 'ldapUserDisplayName2',
496
-			'ldap_group_display_name'           => 'ldapGroupDisplayName',
497
-			'ldap_tls'                          => 'ldapTLS',
498
-			'ldap_quota_def'                    => 'ldapQuotaDefault',
499
-			'ldap_quota_attr'                   => 'ldapQuotaAttribute',
500
-			'ldap_email_attr'                   => 'ldapEmailAttribute',
501
-			'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr',
502
-			'ldap_cache_ttl'                    => 'ldapCacheTTL',
503
-			'home_folder_naming_rule'           => 'homeFolderNamingRule',
504
-			'ldap_turn_off_cert_check'          => 'turnOffCertCheck',
505
-			'ldap_configuration_active'         => 'ldapConfigurationActive',
506
-			'ldap_attributes_for_user_search'   => 'ldapAttributesForUserSearch',
507
-			'ldap_attributes_for_group_search'  => 'ldapAttributesForGroupSearch',
508
-			'ldap_expert_username_attr'         => 'ldapExpertUsernameAttr',
509
-			'ldap_expert_uuid_user_attr'        => 'ldapExpertUUIDUserAttr',
510
-			'ldap_expert_uuid_group_attr'       => 'ldapExpertUUIDGroupAttr',
511
-			'has_memberof_filter_support'       => 'hasMemberOfFilterSupport',
512
-			'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
513
-			'last_jpegPhoto_lookup'             => 'lastJpegPhotoLookup',
514
-			'ldap_nested_groups'                => 'ldapNestedGroups',
515
-			'ldap_paging_size'                  => 'ldapPagingSize',
516
-			'ldap_turn_on_pwd_change'           => 'turnOnPasswordChange',
517
-			'ldap_experienced_admin'            => 'ldapExperiencedAdmin',
518
-			'ldap_dynamic_group_member_url'     => 'ldapDynamicGroupMemberURL',
519
-			'ldap_default_ppolicy_dn'           => 'ldapDefaultPPolicyDN',
520
-		);
521
-		return $array;
522
-	}
465
+    /**
466
+     * @return array that maps internal variable names to database fields
467
+     */
468
+    public function getConfigTranslationArray() {
469
+        //TODO: merge them into one representation
470
+        static $array = array(
471
+            'ldap_host'                         => 'ldapHost',
472
+            'ldap_port'                         => 'ldapPort',
473
+            'ldap_backup_host'                  => 'ldapBackupHost',
474
+            'ldap_backup_port'                  => 'ldapBackupPort',
475
+            'ldap_override_main_server'         => 'ldapOverrideMainServer',
476
+            'ldap_dn'                           => 'ldapAgentName',
477
+            'ldap_agent_password'               => 'ldapAgentPassword',
478
+            'ldap_base'                         => 'ldapBase',
479
+            'ldap_base_users'                   => 'ldapBaseUsers',
480
+            'ldap_base_groups'                  => 'ldapBaseGroups',
481
+            'ldap_userfilter_objectclass'       => 'ldapUserFilterObjectclass',
482
+            'ldap_userfilter_groups'            => 'ldapUserFilterGroups',
483
+            'ldap_userlist_filter'              => 'ldapUserFilter',
484
+            'ldap_user_filter_mode'             => 'ldapUserFilterMode',
485
+            'ldap_login_filter'                 => 'ldapLoginFilter',
486
+            'ldap_login_filter_mode'            => 'ldapLoginFilterMode',
487
+            'ldap_loginfilter_email'            => 'ldapLoginFilterEmail',
488
+            'ldap_loginfilter_username'         => 'ldapLoginFilterUsername',
489
+            'ldap_loginfilter_attributes'       => 'ldapLoginFilterAttributes',
490
+            'ldap_group_filter'                 => 'ldapGroupFilter',
491
+            'ldap_group_filter_mode'            => 'ldapGroupFilterMode',
492
+            'ldap_groupfilter_objectclass'      => 'ldapGroupFilterObjectclass',
493
+            'ldap_groupfilter_groups'           => 'ldapGroupFilterGroups',
494
+            'ldap_display_name'                 => 'ldapUserDisplayName',
495
+            'ldap_user_display_name_2'			=> 'ldapUserDisplayName2',
496
+            'ldap_group_display_name'           => 'ldapGroupDisplayName',
497
+            'ldap_tls'                          => 'ldapTLS',
498
+            'ldap_quota_def'                    => 'ldapQuotaDefault',
499
+            'ldap_quota_attr'                   => 'ldapQuotaAttribute',
500
+            'ldap_email_attr'                   => 'ldapEmailAttribute',
501
+            'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr',
502
+            'ldap_cache_ttl'                    => 'ldapCacheTTL',
503
+            'home_folder_naming_rule'           => 'homeFolderNamingRule',
504
+            'ldap_turn_off_cert_check'          => 'turnOffCertCheck',
505
+            'ldap_configuration_active'         => 'ldapConfigurationActive',
506
+            'ldap_attributes_for_user_search'   => 'ldapAttributesForUserSearch',
507
+            'ldap_attributes_for_group_search'  => 'ldapAttributesForGroupSearch',
508
+            'ldap_expert_username_attr'         => 'ldapExpertUsernameAttr',
509
+            'ldap_expert_uuid_user_attr'        => 'ldapExpertUUIDUserAttr',
510
+            'ldap_expert_uuid_group_attr'       => 'ldapExpertUUIDGroupAttr',
511
+            'has_memberof_filter_support'       => 'hasMemberOfFilterSupport',
512
+            'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
513
+            'last_jpegPhoto_lookup'             => 'lastJpegPhotoLookup',
514
+            'ldap_nested_groups'                => 'ldapNestedGroups',
515
+            'ldap_paging_size'                  => 'ldapPagingSize',
516
+            'ldap_turn_on_pwd_change'           => 'turnOnPasswordChange',
517
+            'ldap_experienced_admin'            => 'ldapExperiencedAdmin',
518
+            'ldap_dynamic_group_member_url'     => 'ldapDynamicGroupMemberURL',
519
+            'ldap_default_ppolicy_dn'           => 'ldapDefaultPPolicyDN',
520
+        );
521
+        return $array;
522
+    }
523 523
 
524 524
 }
Please login to merge, or discard this patch.