Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e67afc401b
|
||
|
|
e59d627080
|
||
|
|
3acca19d49
|
||
|
|
2226b88a88
|
||
|
|
8e08b09ae8
|
||
|
|
a3bce1f2aa
|
||
|
|
a84d3a3976
|
||
|
|
7210b24aa3
|
||
|
|
2d48f20aed
|
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM php:7.4.7-cli-buster
|
FROM php:8.1-cli-bookworm
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y unzip
|
RUN apt-get update && apt-get install -y unzip
|
||||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
+3
-3
@@ -5,12 +5,12 @@
|
|||||||
"license": "GNU GPL 3.0",
|
"license": "GNU GPL 3.0",
|
||||||
"require": {
|
"require": {
|
||||||
"vlucas/phpdotenv": "^5.5",
|
"vlucas/phpdotenv": "^5.5",
|
||||||
"symfony/console": "^5.4",
|
"symfony/console": "^6.3",
|
||||||
"phpmailer/phpmailer": "^6.8",
|
"phpmailer/phpmailer": "^6.8",
|
||||||
"cocur/slugify": "^4.3"
|
"cocur/slugify": "^4.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9.6",
|
"phpunit/phpunit": "^10.3",
|
||||||
"phpstan/phpstan": "^1.10"
|
"phpstan/phpstan": "^1.10"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
Generated
+366
-568
File diff suppressed because it is too large.
Load diff
@@ -55,6 +55,11 @@ class HttpResponse
|
|||||||
|
|
||||||
public function render(): void
|
public function render(): void
|
||||||
{
|
{
|
||||||
|
$this->handleCors();
|
||||||
|
if ($this->method === 'options') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$match = $this->routeCollection->match($this->method, $this->parsedUrl['path']);
|
$match = $this->routeCollection->match($this->method, $this->parsedUrl['path']);
|
||||||
if ($match === null) {
|
if ($match === null) {
|
||||||
$this->render404();
|
$this->render404();
|
||||||
@@ -94,6 +99,7 @@ class HttpResponse
|
|||||||
$response = call_user_func([$controller, $handler[1]]);
|
$response = call_user_func([$controller, $handler[1]]);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->dbConnection->rollback();
|
$this->dbConnection->rollback();
|
||||||
|
error_log($exception);
|
||||||
$this->render500($exception);
|
$this->render500($exception);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -109,6 +115,56 @@ class HttpResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function handleCors(): void
|
||||||
|
{
|
||||||
|
$origin = $this->request->header('Origin');
|
||||||
|
if (!$origin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->appConfig['cors']['allow_origins'])) {
|
||||||
|
if (in_array($origin, $this->appConfig['cors']['allow_origins']) || in_array('*', $this->appConfig['cors']['allow_origins'])) {
|
||||||
|
header("Access-Control-Allow-Origin: {$origin}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->appConfig['cors']['allow_credentials'])) {
|
||||||
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->method !== 'options') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->appConfig['cors']['allow_headers'])) {
|
||||||
|
$headers = explode(',', $this->request->header('Access-Control-Request-Headers'));
|
||||||
|
if (in_array('*', $this->appConfig['cors']['allow_headers'])) {
|
||||||
|
$allow_headers = $headers;
|
||||||
|
} else {
|
||||||
|
$allow_headers = array_intersect($this->appConfig['cors']['allow_headers'], $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($allow_headers) > 0) {
|
||||||
|
header('Access-Control-Allow-Headers: ' . join(', ', $allow_headers));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->appConfig['cors']['allow_methods'])) {
|
||||||
|
if (in_array('*', $this->appConfig['cors']['allow_methods'])) {
|
||||||
|
$allow_methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT'];
|
||||||
|
} else {
|
||||||
|
$allow_methods = $this->appConfig['cors']['allow_methods'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($allow_methods) > 0) {
|
||||||
|
header('Access-Control-Allow-Methods: ' . join(', ', $allow_methods));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$max_age = $this->appConfig['cors']['max_age'] ?? 600;
|
||||||
|
header("Access-Control-Max-Age: {$max_age}");
|
||||||
|
}
|
||||||
|
|
||||||
private function redirectToLogin(): void
|
private function redirectToLogin(): void
|
||||||
{
|
{
|
||||||
$this->request->session()->set('redirect_after_login', $this->rawUrl);
|
$this->request->session()->set('redirect_after_login', $this->rawUrl);
|
||||||
|
|||||||
@@ -86,12 +86,12 @@ class DatabaseSessionHandler implements ISessionHandler
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gc($maxlifetime): bool
|
public function gc($maxlifetime): int|false
|
||||||
{
|
{
|
||||||
// empty on purpose
|
// empty on purpose
|
||||||
// old sessions are deleted by MaintainDatabaseCommand
|
// old sessions are deleted by MaintainDatabaseCommand
|
||||||
|
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create_sid(): string
|
public function create_sid(): string
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ final class GoogleOAuthTest extends TestCase
|
|||||||
$redirectUrl = 'http://example.com/oauth';
|
$redirectUrl = 'http://example.com/oauth';
|
||||||
|
|
||||||
$requestMock = $this->getMockBuilder(IRequest::class)
|
$requestMock = $this->getMockBuilder(IRequest::class)
|
||||||
->setMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
->onlyMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$googleOAuth = new GoogleOAuth($requestMock);
|
$googleOAuth = new GoogleOAuth($requestMock);
|
||||||
|
|
||||||
@@ -48,10 +48,10 @@ final class GoogleOAuthTest extends TestCase
|
|||||||
$redirectUrl = 'http://example.com/oauth';
|
$redirectUrl = 'http://example.com/oauth';
|
||||||
|
|
||||||
$requestMock = $this->getMockBuilder(IRequest::class)
|
$requestMock = $this->getMockBuilder(IRequest::class)
|
||||||
->setMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
->onlyMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$responseMock = $this->getMockBuilder(IResponse::class)
|
$responseMock = $this->getMockBuilder(IResponse::class)
|
||||||
->setMethods(['getBody', 'getHeaders'])
|
->onlyMethods(['getBody', 'getHeaders'])
|
||||||
->getMock();
|
->getMock();
|
||||||
$googleOAuth = new GoogleOAuth($requestMock);
|
$googleOAuth = new GoogleOAuth($requestMock);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user