CORS, trusted domain

This commit is contained in:
2024-04-11 11:51:50 -04:00
parent a238ad3b7f
commit 3851b7f289
12 changed files with 80 additions and 14 deletions

View File

@@ -105,6 +105,8 @@ namespace Core\API\Logs {
"message" => $content,
"timestamp" => $date->format(Parameter::DATE_TIME_FORMAT)
];
$this->result["pagination"]["total"] += 1;
}
}
}
@@ -139,6 +141,7 @@ namespace Core\API\Logs {
"timestamp" => (new \DateTime())->format(Parameter::DATE_TIME_FORMAT)
]
];
$this->result["pagination"]["total"] += 1;
}
$this->loadFromFileSystem($this->result["logs"]);

View File

@@ -161,8 +161,20 @@ abstract class Request {
return true;
}
protected function getCORS(): array {
$settings = $this->context->getSettings();
return $settings->getTrustedDomains();
}
public final function execute($values = array()): bool {
if ($this->externalCall) {
$trustedDomains = $this->getCORS();
if (!empty($trustedDomains)) {
header("Access-Control-Allow-Origin: " . implode(", ", $trustedDomains));
}
}
$this->params = array_merge([], $this->defaultParams);
$this->success = false;
$this->result = array();

View File

@@ -53,6 +53,7 @@ namespace Core\API\Settings {
}
}
// TODO: we need additional validation for built-in settings here, e.g. csv-values, bool values, etc.
class Set extends SettingsAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, array(

View File

@@ -13,9 +13,12 @@ class Swagger extends Request {
$this->csrfTokenRequired = false;
}
protected function getCORS(): array {
return ["*"];
}
public function _execute(): bool {
header("Content-Type: application/x-yaml");
header("Access-Control-Allow-Origin: *");
die($this->getDocumentation());
}