|
|
@@ -7,10 +7,10 @@ use Opentalent\OtAdmin\Controller\ScanController;
|
|
|
use Opentalent\OtAdmin\Controller\SiteController;
|
|
|
use Psr\Log\LoggerAwareInterface;
|
|
|
use Psr\Log\LoggerAwareTrait;
|
|
|
+use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
|
use TYPO3\CMS\Core\Http\JsonResponse;
|
|
|
use TYPO3\CMS\Core\Http\ServerRequest;
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
-use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
|
|
/**
|
|
|
* Actions for Http API calls
|
|
|
@@ -21,7 +21,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
{
|
|
|
use LoggerAwareTrait;
|
|
|
|
|
|
- const ALLOWED_IPS = [
|
|
|
+ const array ALLOWED_IPS = [
|
|
|
'/^127\.0\.0\.[0-1]$/', // Localhost
|
|
|
'/^localhost$/', // Localhost
|
|
|
'/^10\.8\.0\.\d{1,3}$/', // 10.8.0.[0-255] - VPN
|
|
|
@@ -30,6 +30,10 @@ class ApiController implements LoggerAwareInterface
|
|
|
'/^172\.20\.\d{1,3}\.\d{1,3}$/', // 172.20.[0-255].[0-255] - Docker
|
|
|
];
|
|
|
|
|
|
+ public function __construct(
|
|
|
+ private readonly SiteController $siteController
|
|
|
+ ) {}
|
|
|
+
|
|
|
/**
|
|
|
* Returns true if the client Ip is allowed
|
|
|
*
|
|
|
@@ -95,9 +99,8 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
|
|
|
- $infos = $controller->getSiteInfosAction($organizationId);
|
|
|
+ $infos = $this->siteController->getSiteInfosAction($organizationId);
|
|
|
|
|
|
return new JsonResponse($infos);
|
|
|
}
|
|
|
@@ -118,8 +121,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->createSiteAction($organizationId);
|
|
|
+ $rootUid = $this->siteController->createSiteAction($organizationId);
|
|
|
|
|
|
$this->logger->info(sprintf(
|
|
|
"OtAdmin API: A new website has been created with root page uid=" . $rootUid .
|
|
|
@@ -151,8 +153,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
$deep = (isset($queryParams['deep']) && $queryParams['deep']);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->updateSiteAction($organizationId, $deep);
|
|
|
+ $rootUid = $this->siteController->updateSiteAction($organizationId, $deep);
|
|
|
|
|
|
$this->logger->info(sprintf(
|
|
|
"OtAdmin API: The website with root uid " . $rootUid . " has been updated " .
|
|
|
@@ -184,8 +185,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
$fromDomain = (isset($queryParams['from-domain']) && $queryParams['from-domain']);
|
|
|
$toDomain = (isset($queryParams['to-domain']) && $queryParams['to-domain']);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $res = $controller->addRedirection($fromDomain, $toDomain);
|
|
|
+ $res = $this->siteController->addRedirection($fromDomain, $toDomain);
|
|
|
|
|
|
if ($res === SiteController::REDIRECTION_UPDATED) {
|
|
|
$msg = "An existing redirection has been updated ";
|
|
|
@@ -221,8 +221,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$params = $request->getQueryParams();
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->deleteSiteAction($organizationId);
|
|
|
+ $rootUid = $this->siteController->deleteSiteAction($organizationId);
|
|
|
|
|
|
$this->logger->info(sprintf(
|
|
|
"OtAdmin API: The website with root uid " . $rootUid . " has been soft-deleted " .
|
|
|
@@ -253,8 +252,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->undeleteSiteAction($organizationId);
|
|
|
+ $rootUid = $this->siteController->undeleteSiteAction($organizationId);
|
|
|
|
|
|
$this->logger->info(sprintf(
|
|
|
"OtAdmin API: The website with root uid " . $rootUid . " has been restored " .
|
|
|
@@ -288,8 +286,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
$clearAll = (isset($queryParams['all']) && $queryParams['all']);;
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->clearSiteCacheAction($organizationId, $clearAll);
|
|
|
+ $rootUid = $this->siteController->clearSiteCacheAction($organizationId, $clearAll);
|
|
|
|
|
|
return new JsonResponse(
|
|
|
[
|
|
|
@@ -324,8 +321,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
}
|
|
|
$redirect = (isset($queryParams['redirect']) && $queryParams['redirect']);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->setSiteCustomDomainAction($organizationId, $domain, $redirect);
|
|
|
+ $rootUid = $this->siteController->setSiteCustomDomainAction($organizationId, $domain, $redirect);
|
|
|
|
|
|
return new JsonResponse(
|
|
|
[
|
|
|
@@ -352,8 +348,7 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
- $rootUid = $controller->resetBeUserPermsAction($organizationId);
|
|
|
+ $rootUid = $this->siteController->resetBeUserPermsAction($organizationId);
|
|
|
|
|
|
return new JsonResponse(
|
|
|
[
|
|
|
@@ -380,11 +375,9 @@ class ApiController implements LoggerAwareInterface
|
|
|
|
|
|
$organizationId = $this->getOrganizationId($request);
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(SiteController::class);
|
|
|
-
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
$full = (isset($queryParams['full']) && $queryParams['full']);
|
|
|
- $status = $controller->getSiteStatusAction($organizationId, $full);
|
|
|
+ $status = $this->siteController->getSiteStatusAction($organizationId, $full);
|
|
|
|
|
|
return new JsonResponse($status->toArray());
|
|
|
}
|
|
|
@@ -402,11 +395,9 @@ class ApiController implements LoggerAwareInterface
|
|
|
{
|
|
|
$this->assertIpAllowed();
|
|
|
|
|
|
- $controller = GeneralUtility::makeInstance(ObjectManager::class)->get(ScanController::class);
|
|
|
-
|
|
|
$queryParams = $request->getQueryParams();
|
|
|
$full = (isset($queryParams['full']) && $queryParams['full']);
|
|
|
- $results = $controller->scanAllAction($full);
|
|
|
+ $results = $this->siteController->scanAllAction($full);
|
|
|
|
|
|
return new JsonResponse($results);
|
|
|
}
|