summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/command')
-rw-r--r--apps/user_ldap/command/checkuser.php121
-rw-r--r--apps/user_ldap/command/search.php17
-rw-r--r--apps/user_ldap/command/setconfig.php3
-rw-r--r--apps/user_ldap/command/showconfig.php3
-rw-r--r--apps/user_ldap/command/showremnants.php73
-rw-r--r--apps/user_ldap/command/testconfig.php3
6 files changed, 215 insertions, 5 deletions
diff --git a/apps/user_ldap/command/checkuser.php b/apps/user_ldap/command/checkuser.php
new file mode 100644
index 00000000000..202855e4853
--- /dev/null
+++ b/apps/user_ldap/command/checkuser.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\user_ldap\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use OCA\user_ldap\lib\user\User;
+use OCA\User_LDAP\lib\User\DeletedUsersIndex;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\user_ldap\lib\Helper as LDAPHelper;
+use OCA\user_ldap\User_Proxy;
+
+class CheckUser extends Command {
+ /** @var \OCA\user_ldap\User_Proxy */
+ protected $backend;
+
+ /** @var \OCA\User_LDAP\lib\Helper */
+ protected $helper;
+
+ /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
+ protected $dui;
+
+ /** @var \OCA\User_LDAP\Mapping\UserMapping */
+ protected $mapping;
+
+ /**
+ * @param OCA\user_ldap\User_Proxy $uBackend
+ * @param OCA\user_ldap\lib\Helper $helper
+ * @param OCA\User_LDAP\lib\User\DeletedUsersIndex $dui
+ * @param OCA\User_LDAP\Mapping\UserMapping $mapping
+ */
+ public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
+ $this->backend = $uBackend;
+ $this->helper = $helper;
+ $this->dui = $dui;
+ $this->mapping = $mapping;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('ldap:check-user')
+ ->setDescription('checks whether a user exists on LDAP.')
+ ->addArgument(
+ 'ocName',
+ InputArgument::REQUIRED,
+ 'the user name as used in ownCloud'
+ )
+ ->addOption(
+ 'force',
+ null,
+ InputOption::VALUE_NONE,
+ 'ignores disabled LDAP configuration'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ try {
+ $uid = $input->getArgument('ocName');
+ $this->isAllowed($input->getOption('force'));
+ $this->confirmUserIsMapped($uid);
+ $exists = $this->backend->userExistsOnLDAP($uid);
+ if($exists === true) {
+ $output->writeln('The user is still available on LDAP.');
+ return;
+ }
+
+ $this->dui->markUser($uid);
+ $output->writeln('The user does not exists on LDAP anymore.');
+ $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
+ . $uid . '"');
+ } catch (\Exception $e) {
+ $output->writeln('<error>' . $e->getMessage(). '</error>');
+ }
+ }
+
+ /**
+ * checks whether a user is actually mapped
+ * @param string $ocName the username as used in ownCloud
+ * @throws \Exception
+ * @return true
+ */
+ protected function confirmUserIsMapped($ocName) {
+ $dn = $this->mapping->getDNByName($ocName);
+ if ($dn === false) {
+ throw new \Exception('The given user is not a recognized LDAP user.');
+ }
+
+ return true;
+ }
+
+ /**
+ * 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;
+ }
+
+}
diff --git a/apps/user_ldap/command/search.php b/apps/user_ldap/command/search.php
index e20255510d8..ba87982d167 100644
--- a/apps/user_ldap/command/search.php
+++ b/apps/user_ldap/command/search.php
@@ -18,8 +18,20 @@ use OCA\user_ldap\User_Proxy;
use OCA\user_ldap\Group_Proxy;
use OCA\user_ldap\lib\Helper;
use OCA\user_ldap\lib\LDAP;
+use OCP\IConfig;
class Search extends Command {
+ /** @var \OCP\IConfig */
+ protected $ocConfig;
+
+ /**
+ * @param \OCP\IConfig $ocConfig
+ */
+ public function __construct(IConfig $ocConfig) {
+ $this->ocConfig = $ocConfig;
+ parent::__construct();
+ }
+
protected function configure() {
$this
->setName('ldap:search')
@@ -74,7 +86,8 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $configPrefixes = Helper::getServerConfigurationPrefixes(true);
+ $helper = new Helper();
+ $configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
$offset = intval($input->getOption('offset'));
@@ -86,7 +99,7 @@ class Search extends Command {
$getMethod = 'getGroups';
$printID = false;
} else {
- $proxy = new User_Proxy($configPrefixes, $ldapWrapper);
+ $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig);
$getMethod = 'getDisplayNames';
$printID = true;
}
diff --git a/apps/user_ldap/command/setconfig.php b/apps/user_ldap/command/setconfig.php
index ab1c8d39ead..9128fcf04fc 100644
--- a/apps/user_ldap/command/setconfig.php
+++ b/apps/user_ldap/command/setconfig.php
@@ -41,7 +41,8 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $availableConfigs = Helper::getServerConfigurationPrefixes();
+ $helper = new Helper();
+ $availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if(!in_array($configID, $availableConfigs)) {
$output->writeln("Invalid configID");
diff --git a/apps/user_ldap/command/showconfig.php b/apps/user_ldap/command/showconfig.php
index f51d641beec..ddbc45243ff 100644
--- a/apps/user_ldap/command/showconfig.php
+++ b/apps/user_ldap/command/showconfig.php
@@ -31,7 +31,8 @@ class ShowConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $availableConfigs = Helper::getServerConfigurationPrefixes();
+ $helper = new Helper();
+ $availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if(!is_null($configID)) {
$configIDs[] = $configID;
diff --git a/apps/user_ldap/command/showremnants.php b/apps/user_ldap/command/showremnants.php
new file mode 100644
index 00000000000..5cfab34ef95
--- /dev/null
+++ b/apps/user_ldap/command/showremnants.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\user_ldap\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use OCA\user_ldap\lib\user\DeletedUsersIndex;
+use OCP\IDateTimeFormatter;
+
+class ShowRemnants extends Command {
+ /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
+ protected $dui;
+
+ /** @var \OCP\IDateTimeFormatter */
+ protected $dateFormatter;
+
+ /**
+ * @param OCA\user_ldap\lib\user\DeletedUsersIndex $dui
+ * @param OCP\IDateTimeFormatter $dateFormatter
+ */
+ public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
+ $this->dui = $dui;
+ $this->dateFormatter = $dateFormatter;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('ldap:show-remnants')
+ ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.')
+ ;
+ }
+
+ /**
+ * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
+ *
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ /** @var \Symfony\Component\Console\Helper\Table $table */
+ $table = $this->getHelperSet()->get('table');
+ $table->setHeaders(array(
+ 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
+ 'Dir', 'Sharer'));
+ $rows = array();
+ $resultSet = $this->dui->getUsers();
+ foreach($resultSet as $user) {
+ $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
+ $lastLogin = ($user->getLastLogin() > 0) ?
+ $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
+ $rows[] = array(
+ $user->getOCName(),
+ $user->getDisplayName(),
+ $user->getUid(),
+ $user->getDN(),
+ $lastLogin,
+ $user->getHomePath(),
+ $hAS
+ );
+ }
+
+ $table->setRows($rows);
+ $table->render($output);
+ }
+}
diff --git a/apps/user_ldap/command/testconfig.php b/apps/user_ldap/command/testconfig.php
index 00b4acf2f66..a44e22415e9 100644
--- a/apps/user_ldap/command/testconfig.php
+++ b/apps/user_ldap/command/testconfig.php
@@ -31,7 +31,8 @@ class TestConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $availableConfigs = Helper::getServerConfigurationPrefixes();
+ $helper = new Helper();
+ $availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if(!in_array($configID, $availableConfigs)) {
$output->writeln("Invalid configID");