示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configPrefix = $input->getArgument('configID');
     $success = $this->helper->deleteServerConfiguration($configPrefix);
     if ($success) {
         $output->writeln("Deleted configuration with configID '{$configPrefix}'");
     } else {
         $output->writeln("Cannot delete configuration with configID '{$configPrefix}'");
     }
 }
示例#2
0
 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'));
 }
 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;
 }
示例#4
0
 /**
  * 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();
 }
示例#5
0
 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'));
 }
示例#6
0
 /**
  * checks whether the setup allows reliable checking of LDAP user existence
  * @throws \Exception
  * @return true
  */
 protected function isAllowed($force)
 {
     if ($this->helper->haveDisabledConfigurations() && !$force) {
         throw new \Exception('Cannot check user existence, because ' . 'disabled LDAP configurations are present.');
     }
     // we don't check ldapUserCleanupInterval from config.php because this
     // action is triggered manually, while the setting only controls the
     // background job.
     return true;
 }
示例#7
0
 /**
  * checks whether cleaning up LDAP users is allowed
  * @return bool
  */
 public function isCleanUpAllowed()
 {
     try {
         if ($this->ldapHelper->haveDisabledConfigurations()) {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
     $enabled = $this->isCleanUpEnabled();
     return $enabled;
 }
示例#8
0
 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);
     }
 }
示例#9
0
 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.');
             }
         }
     }
 }
示例#10
0
 /**
  * checks if the given DN is part of the given base DN(s)
  * @param string $dn the DN
  * @param string[] $bases array containing the allowed base DN or DNs
  * @return bool
  */
 public function isDNPartOfBase($dn, $bases)
 {
     $belongsToBase = false;
     $bases = $this->helper->sanitizeDN($bases);
     foreach ($bases as $base) {
         $belongsToBase = true;
         if (mb_strripos($dn, $base, 0, 'UTF-8') !== mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8')) {
             $belongsToBase = false;
         }
         if ($belongsToBase) {
             break;
         }
     }
     return $belongsToBase;
 }
示例#11
0
 /**
  * @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;
 }
示例#12
0
 * 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));
示例#13
0
 /**
  * tries to determine a base dn from User DN or LDAP Host
  * @return WizardResult|false WizardResult on success, false otherwise
  */
 public function guessBaseDN()
 {
     if (!$this->checkRequirements(array('ldapHost', 'ldapPort'))) {
         return false;
     }
     //check whether a DN is given in the agent name (99.9% of all cases)
     $base = null;
     $i = stripos($this->configuration->ldapAgentName, 'dc=');
     if ($i !== false) {
         $base = substr($this->configuration->ldapAgentName, $i);
         if ($this->testBaseDN($base)) {
             $this->applyFind('ldap_base', $base);
             return $this->result;
         }
     }
     //this did not help :(
     //Let's see whether we can parse the Host URL and convert the domain to
     //a base DN
     $helper = new Helper();
     $domain = $helper->getDomainFromURL($this->configuration->ldapHost);
     if (!$domain) {
         return false;
     }
     $dparts = explode('.', $domain);
     while (count($dparts) > 0) {
         $base2 = 'dc=' . implode(',dc=', $dparts);
         if ($base !== $base2 && $this->testBaseDN($base2)) {
             $this->applyFind('ldap_base', $base2);
             return $this->result;
         }
         array_shift($dparts);
     }
     return false;
 }