@@ -35,84 +35,84 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class TestConfig extends Command { |
38 | - protected const ESTABLISHED = 0; |
|
39 | - protected const CONF_INVALID = 1; |
|
40 | - protected const BINDFAILURE = 2; |
|
41 | - protected const SEARCHFAILURE = 3; |
|
38 | + protected const ESTABLISHED = 0; |
|
39 | + protected const CONF_INVALID = 1; |
|
40 | + protected const BINDFAILURE = 2; |
|
41 | + protected const SEARCHFAILURE = 3; |
|
42 | 42 | |
43 | - /** @var AccessFactory */ |
|
44 | - protected $accessFactory; |
|
43 | + /** @var AccessFactory */ |
|
44 | + protected $accessFactory; |
|
45 | 45 | |
46 | - public function __construct(AccessFactory $accessFactory) { |
|
47 | - $this->accessFactory = $accessFactory; |
|
48 | - parent::__construct(); |
|
49 | - } |
|
46 | + public function __construct(AccessFactory $accessFactory) { |
|
47 | + $this->accessFactory = $accessFactory; |
|
48 | + parent::__construct(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function configure() { |
|
52 | - $this |
|
53 | - ->setName('ldap:test-config') |
|
54 | - ->setDescription('tests an LDAP configuration') |
|
55 | - ->addArgument( |
|
56 | - 'configID', |
|
57 | - InputArgument::REQUIRED, |
|
58 | - 'the configuration ID' |
|
59 | - ) |
|
60 | - ; |
|
61 | - } |
|
51 | + protected function configure() { |
|
52 | + $this |
|
53 | + ->setName('ldap:test-config') |
|
54 | + ->setDescription('tests an LDAP configuration') |
|
55 | + ->addArgument( |
|
56 | + 'configID', |
|
57 | + InputArgument::REQUIRED, |
|
58 | + 'the configuration ID' |
|
59 | + ) |
|
60 | + ; |
|
61 | + } |
|
62 | 62 | |
63 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); |
|
65 | - $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
66 | - $configID = $input->getArgument('configID'); |
|
67 | - if (!in_array($configID, $availableConfigs)) { |
|
68 | - $output->writeln('Invalid configID'); |
|
69 | - return 1; |
|
70 | - } |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | + $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); |
|
65 | + $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
66 | + $configID = $input->getArgument('configID'); |
|
67 | + if (!in_array($configID, $availableConfigs)) { |
|
68 | + $output->writeln('Invalid configID'); |
|
69 | + return 1; |
|
70 | + } |
|
71 | 71 | |
72 | - $result = $this->testConfig($configID); |
|
73 | - switch ($result) { |
|
74 | - case static::ESTABLISHED: |
|
75 | - $output->writeln('The configuration is valid and the connection could be established!'); |
|
76 | - return 0; |
|
77 | - case static::CONF_INVALID: |
|
78 | - $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
79 | - break; |
|
80 | - case static::BINDFAILURE: |
|
81 | - $output->writeln('The configuration is valid, but the bind failed. Please check the server settings and credentials.'); |
|
82 | - break; |
|
83 | - case static::SEARCHFAILURE: |
|
84 | - $output->writeln('The configuration is valid and the bind passed, but a simple search on the base fails. Please check the server base setting.'); |
|
85 | - break; |
|
86 | - default: |
|
87 | - $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
88 | - break; |
|
89 | - } |
|
90 | - return 1; |
|
91 | - } |
|
72 | + $result = $this->testConfig($configID); |
|
73 | + switch ($result) { |
|
74 | + case static::ESTABLISHED: |
|
75 | + $output->writeln('The configuration is valid and the connection could be established!'); |
|
76 | + return 0; |
|
77 | + case static::CONF_INVALID: |
|
78 | + $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
79 | + break; |
|
80 | + case static::BINDFAILURE: |
|
81 | + $output->writeln('The configuration is valid, but the bind failed. Please check the server settings and credentials.'); |
|
82 | + break; |
|
83 | + case static::SEARCHFAILURE: |
|
84 | + $output->writeln('The configuration is valid and the bind passed, but a simple search on the base fails. Please check the server base setting.'); |
|
85 | + break; |
|
86 | + default: |
|
87 | + $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
88 | + break; |
|
89 | + } |
|
90 | + return 1; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Tests the specified connection |
|
95 | - */ |
|
96 | - protected function testConfig(string $configID): int { |
|
97 | - $lw = new \OCA\User_LDAP\LDAP(); |
|
98 | - $connection = new Connection($lw, $configID); |
|
93 | + /** |
|
94 | + * Tests the specified connection |
|
95 | + */ |
|
96 | + protected function testConfig(string $configID): int { |
|
97 | + $lw = new \OCA\User_LDAP\LDAP(); |
|
98 | + $connection = new Connection($lw, $configID); |
|
99 | 99 | |
100 | - // Ensure validation is run before we attempt the bind |
|
101 | - $connection->getConfiguration(); |
|
100 | + // Ensure validation is run before we attempt the bind |
|
101 | + $connection->getConfiguration(); |
|
102 | 102 | |
103 | - if (!$connection->setConfiguration([ |
|
104 | - 'ldap_configuration_active' => 1, |
|
105 | - ])) { |
|
106 | - return static::CONF_INVALID; |
|
107 | - } |
|
108 | - if (!$connection->bind()) { |
|
109 | - return static::BINDFAILURE; |
|
110 | - } |
|
111 | - $access = $this->accessFactory->get($connection); |
|
112 | - $result = $access->countObjects(1); |
|
113 | - if (!is_int($result) || ($result <= 0)) { |
|
114 | - return static::SEARCHFAILURE; |
|
115 | - } |
|
116 | - return static::ESTABLISHED; |
|
117 | - } |
|
103 | + if (!$connection->setConfiguration([ |
|
104 | + 'ldap_configuration_active' => 1, |
|
105 | + ])) { |
|
106 | + return static::CONF_INVALID; |
|
107 | + } |
|
108 | + if (!$connection->bind()) { |
|
109 | + return static::BINDFAILURE; |
|
110 | + } |
|
111 | + $access = $this->accessFactory->get($connection); |
|
112 | + $result = $access->countObjects(1); |
|
113 | + if (!is_int($result) || ($result <= 0)) { |
|
114 | + return static::SEARCHFAILURE; |
|
115 | + } |
|
116 | + return static::ESTABLISHED; |
|
117 | + } |
|
118 | 118 | } |