protected function getNewConfigurationPrefix() { $serverConnections = $this->helper->getServerConfigurationPrefixes(); // first connection uses no prefix if (sizeof($serverConnections) == 0) { return ''; } sort($serverConnections); $lastKey = array_pop($serverConnections); $lastNumber = intval(str_replace('s', '', $lastKey)); $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); return $nextPrefix; }
protected function execute(InputInterface $input, OutputInterface $output) { $availableConfigs = $this->helper->getServerConfigurationPrefixes(); $configID = $input->getArgument('configID'); if (!is_null($configID)) { $configIDs[] = $configID; if (!in_array($configIDs[0], $availableConfigs)) { $output->writeln("Invalid configID"); return; } } else { $configIDs = $availableConfigs; } $this->renderConfigs($configIDs, $output, $input->getOption('show-password')); }
protected function execute(InputInterface $input, OutputInterface $output) { $helper = new Helper(); $availableConfigs = $helper->getServerConfigurationPrefixes(); $configID = $input->getArgument('configID'); if (!in_array($configID, $availableConfigs)) { $output->writeln("Invalid configID"); return; } $this->setValue($configID, $input->getArgument('configKey'), $input->getArgument('configValue')); }
/** * Constructor * @param ILDAPWrapper $ldap * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections */ public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { parent::__construct($ldap); $this->configPrefix = $configPrefix; $this->configID = $configID; $this->configuration = new Configuration($configPrefix, !is_null($configID)); $memcache = \OC::$server->getMemCacheFactory(); if ($memcache->isAvailable()) { $this->cache = $memcache->create(); } $helper = new Helper(); $this->doNotValidate = !in_array($this->configPrefix, $helper->getServerConfigurationPrefixes()); $this->hasPagedResultSupport = intval($this->configuration->ldapPagingSize) !== 0 || $this->ldap->hasPagedResultSupport(); }
/** * assigns the instances passed to run() to the class properties * @param array $arguments */ public function setArguments($arguments) { //Dependency Injection is not possible, because the constructor will //only get values that are serialized to JSON. I.e. whatever we would //pass in app.php we do add here, except something else is passed e.g. //in tests. if (isset($arguments['helper'])) { $this->ldapHelper = $arguments['helper']; } else { $this->ldapHelper = new Helper(); } if (isset($arguments['ocConfig'])) { $this->ocConfig = $arguments['ocConfig']; } else { $this->ocConfig = \OC::$server->getConfig(); } if (isset($arguments['userBackend'])) { $this->userBackend = $arguments['userBackend']; } else { $this->userBackend = new User_Proxy($this->ldapHelper->getServerConfigurationPrefixes(true), new LDAP(), $this->ocConfig); } if (isset($arguments['db'])) { $this->db = $arguments['db']; } else { $this->db = \OC::$server->getDatabaseConnection(); } if (isset($arguments['mapping'])) { $this->mapping = $arguments['mapping']; } else { $this->mapping = new UserMapping($this->db); } if (isset($arguments['deletedUsersIndex'])) { $this->dui = $arguments['deletedUsersIndex']; } else { $this->dui = new DeletedUsersIndex($this->ocConfig, $this->db, $this->mapping); } }
protected function execute(InputInterface $input, OutputInterface $output) { $helper = new Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new LDAP(); $offset = intval($input->getOption('offset')); $limit = intval($input->getOption('limit')); $this->validateOffsetAndLimit($offset, $limit); if ($input->getOption('group')) { $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); $getMethod = 'getGroups'; $printID = false; } else { $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); $getMethod = 'getDisplayNames'; $printID = true; } $result = $proxy->{$getMethod}($input->getArgument('search'), $limit, $offset); foreach ($result as $id => $name) { $line = $name . ($printID ? ' (' . $id . ')' : ''); $output->writeln($line); } }
protected function execute(InputInterface $input, OutputInterface $output) { $helper = new Helper(); $availableConfigs = $helper->getServerConfigurationPrefixes(); $configID = $input->getArgument('configID'); if (!in_array($configID, $availableConfigs)) { $output->writeln("Invalid configID"); return; } $result = $this->testConfig($configID); if ($result === 0) { $output->writeln('The configuration is valid and the connection could be established!'); } else { if ($result === 1) { $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); } else { if ($result === 2) { $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); } else { $output->writeln('Your LDAP server was kidnapped by aliens.'); } } } }
/** * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy */ private static function getGroupBE() { if (!is_null(self::$groupBE)) { return self::$groupBE; } $helper = new Helper(); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new LDAP(); if (count($configPrefixes) === 1) { //avoid the proxy when there is only one LDAP server configured $dbc = \OC::$server->getDatabaseConnection(); $userManager = new Manager(\OC::$server->getConfig(), new FilesystemHelper(), new LogWrapper(), \OC::$server->getAvatarManager(), new \OCP\Image(), $dbc, \OC::$server->getUserManager()); $connector = new Connection($ldapWrapper, $configPrefixes[0]); $ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper); $groupMapper = new GroupMapping($dbc); $userMapper = new UserMapping($dbc); $ldapAccess->setGroupMapper($groupMapper); $ldapAccess->setUserMapper($userMapper); self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess); } else { self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); } return self::$groupBE; }
* it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ use OCA\User_LDAP\Helper; use OCA\User_LDAP\LDAP; use OCA\User_LDAP\User_Proxy; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\DeletedUsersIndex; $dbConnection = \OC::$server->getDatabaseConnection(); $userMapping = new UserMapping($dbConnection); $helper = new Helper(); $ocConfig = \OC::$server->getConfig(); $uBackend = new User_Proxy($helper->getServerConfigurationPrefixes(true), new LDAP(), $ocConfig); $deletedUsersIndex = new DeletedUsersIndex($ocConfig, $dbConnection, $userMapping); $application->add(new OCA\User_LDAP\Command\ShowConfig($helper)); $application->add(new OCA\User_LDAP\Command\SetConfig()); $application->add(new OCA\User_LDAP\Command\TestConfig()); $application->add(new OCA\User_LDAP\Command\CreateEmptyConfig($helper)); $application->add(new OCA\User_LDAP\Command\DeleteConfig($helper)); $application->add(new OCA\User_LDAP\Command\Search($ocConfig)); $application->add(new OCA\User_LDAP\Command\ShowRemnants($deletedUsersIndex, \OC::$server->getDateTimeFormatter())); $application->add(new OCA\User_LDAP\Command\CheckUser($uBackend, $helper, $deletedUsersIndex, $userMapping));