|
@@ -6,6 +6,7 @@ namespace Opentalent\OtAdmin\Http;
|
|
|
use Opentalent\OtAdmin\Controller\SiteController;
|
|
use Opentalent\OtAdmin\Controller\SiteController;
|
|
|
use Psr\Log\LoggerAwareInterface;
|
|
use Psr\Log\LoggerAwareInterface;
|
|
|
use Psr\Log\LoggerAwareTrait;
|
|
use Psr\Log\LoggerAwareTrait;
|
|
|
|
|
+use TYPO3\CMS\Core\Core\Bootstrap;
|
|
|
use TYPO3\CMS\Core\Http\JsonResponse;
|
|
use TYPO3\CMS\Core\Http\JsonResponse;
|
|
|
use TYPO3\CMS\Core\Http\ServerRequest;
|
|
use TYPO3\CMS\Core\Http\ServerRequest;
|
|
|
|
|
|
|
@@ -20,18 +21,18 @@ class ApiController implements LoggerAwareInterface
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Retrieve the organization's id from the given request parameters
|
|
|
|
|
|
|
+ * Returns true if the client Ip is allowed
|
|
|
*
|
|
*
|
|
|
- * @param ServerRequest $request
|
|
|
|
|
- * @return int
|
|
|
|
|
|
|
+ * @param string $clientIp
|
|
|
|
|
+ * @return bool
|
|
|
*/
|
|
*/
|
|
|
- private function getOrganizationId(ServerRequest $request) {
|
|
|
|
|
- $params = $request->getQueryParams();
|
|
|
|
|
- $organizationId = $params['organization-id'];
|
|
|
|
|
- if (!$organizationId) {
|
|
|
|
|
- throw new \RuntimeException("Missing parameter: 'organization-id'");
|
|
|
|
|
|
|
+ public static function isIpAllowed(string $clientIp) {
|
|
|
|
|
+ foreach (self::ALLOWED_IPS as $ipRule) {
|
|
|
|
|
+ if (preg_match($ipRule, $clientIp)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return (int)$organizationId;
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -41,16 +42,29 @@ class ApiController implements LoggerAwareInterface
|
|
|
*/
|
|
*/
|
|
|
private function assertIpAllowed() {
|
|
private function assertIpAllowed() {
|
|
|
$clientIp = $_SERVER['REMOTE_ADDR'];
|
|
$clientIp = $_SERVER['REMOTE_ADDR'];
|
|
|
- foreach (self::ALLOWED_IPS as $ipRule) {
|
|
|
|
|
- if (preg_match($ipRule, $clientIp)) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!self::isIpAllowed($clientIp)){
|
|
|
|
|
+ $route = $_REQUEST['route'];
|
|
|
|
|
+ $this->logger->error(sprintf(
|
|
|
|
|
+ "OtAdmin API: an attempt was made to call the route " .
|
|
|
|
|
+ $route . " from an non-allowed IP (" . $clientIp . ")"));
|
|
|
|
|
+ throw new \RuntimeException("Not allowed");
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Retrieve the organization's id from the given request parameters
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param ServerRequest $request
|
|
|
|
|
+ * @return int
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getOrganizationId(ServerRequest $request) {
|
|
|
|
|
+ $params = $request->getQueryParams();
|
|
|
|
|
+ $organizationId = $params['organization-id'];
|
|
|
|
|
+ if (!$organizationId) {
|
|
|
|
|
+ throw new \RuntimeException("Missing parameter: 'organization-id'");
|
|
|
}
|
|
}
|
|
|
- $route = $_REQUEST['route'];
|
|
|
|
|
- $this->logger->error(sprintf(
|
|
|
|
|
- "OtAdmin API: an attempt was made to call the route " .
|
|
|
|
|
- $route . " from an non-allowed IP (" . $clientIp . ")"));
|
|
|
|
|
- throw new \RuntimeException("Not allowed");
|
|
|
|
|
|
|
+ return (int)$organizationId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|