* @throws OCSException * * 200: Wizard action result */ #[AuthorizedAdminSetting(settings: Admin::class)] #[ApiRoute(verb: 'POST', url: '/api/v1/wizard/{configID}/{action}')] public function action(string $configID, string $action, ?string $loginName, ?string $key, ?string $val) { try { $wizard = $this->wizardFactory->get($configID); switch ($action) { case 'guessPortAndTLS': case 'guessBaseDN': case 'detectEmailAttribute': case 'detectUserDisplayNameAttribute': case 'determineGroupMemberAssoc': case 'determineUserObjectClasses': case 'determineGroupObjectClasses': case 'determineGroupsForUsers': case 'determineGroupsForGroups': case 'determineAttributes': case 'getUserListFilter': case 'getUserLoginFilter': case 'getGroupFilter': case 'countUsers': case 'countGroups': case 'countInBaseDN': try { $result = $wizard->$action(); if ($result !== false) { return new DataResponse($result->getResultArray()); } } catch (\Exception $e) { throw new OCSException($e->getMessage()); } throw new OCSException(); case 'testLoginName': try { if ($loginName === null || $loginName === '') { throw new OCSException('No login name passed'); } $result = $wizard->$action($loginName); if ($result !== false) { return new DataResponse($result->getResultArray()); } } catch (\Exception $e) { throw new OCSException($e->getMessage()); } throw new OCSException(); case 'save': if ($key === null || $val === null) { throw new OCSException($this->l->t('No data specified')); exit; } $setParameters = []; $configuration = new Configuration($configID); $configuration->setConfiguration([$key => $val], $setParameters); if (!in_array($key, $setParameters)) { throw new OCSException($this->l->t('Could not set configuration %1$s to %2$s', [$key, $setParameters[0]])); } $configuration->saveConfiguration(); //clear the cache on save $connection = $this->connectionFactory->get($configID); $connection->clearCache(); return new DataResponse(); break; default: throw new OCSException($this->l->t('Action does not exist')); break; } } catch (OCSException $e) { throw $e; } catch (\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); throw new OCSException('An issue occurred when creating the new config.'); } } }