Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file handles the ping request that is sent by the front-end of grommunio Web
|
||||
* to check if a broken connection with the server can be re-established.
|
||||
*/
|
||||
|
||||
// Include the files that this script need
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
require_once UMAPI_PATH . '/mapi.util.php';
|
||||
|
||||
$pingTag = [
|
||||
'info' => [
|
||||
'hresult' => WebAppAuthentication::getErrorCode(),
|
||||
'hresult_name' => get_mapi_error_name(WebAppAuthentication::getErrorCode()),
|
||||
],
|
||||
];
|
||||
|
||||
switch (WebAppAuthentication::getErrorCode()) {
|
||||
// A network error indicates that the connection
|
||||
// to the server could not be established.
|
||||
case MAPI_E_NETWORK_ERROR:
|
||||
$pingTag['success'] = false;
|
||||
break;
|
||||
|
||||
// The following errors are specific to logging on,
|
||||
// it means the connection to the server did work,
|
||||
// but the user simply isn't logged in.
|
||||
case MAPI_E_PASSWORD_CHANGE_REQUIRED:
|
||||
case MAPI_E_PASSWORD_EXPIRED:
|
||||
case MAPI_E_INVALID_WORKSTATION_ACCOUNT:
|
||||
case MAPI_E_INVALID_ACCESS_TIME:
|
||||
case MAPI_E_ACCOUNT_DISABLED:
|
||||
// Error name says it all, connection exists, but cannot logon.
|
||||
case MAPI_E_LOGON_FAILED:
|
||||
// MAPI_E_UNCONFIGURED means we didn't try to connect to the server,
|
||||
// but the user is not logged in, so the state has changed for the user.
|
||||
case MAPI_E_UNCONFIGURED:
|
||||
// NOERROR means the logon was successful, and the connection to the
|
||||
// server is working as expected.
|
||||
case NOERROR:
|
||||
// All other errors are considered a 'success' for connecting to the
|
||||
// server and the 'active' property will indicate if the user still
|
||||
// has an active session to the server.
|
||||
default:
|
||||
$pingTag['success'] = true;
|
||||
$pingTag['active'] = WebAppAuthentication::isAuthenticated();
|
||||
break;
|
||||
}
|
||||
|
||||
// Write the JSON response
|
||||
echo json_encode($pingTag);
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This controller handles the following request:
|
||||
*
|
||||
* authenticate (login)
|
||||
*
|
||||
* Method: POST
|
||||
* GET Parameters:
|
||||
* service=authenticate
|
||||
* POST Parameters:
|
||||
* username=username
|
||||
* password=password
|
||||
* Response:
|
||||
* 200 Ok
|
||||
* JSON
|
||||
* {
|
||||
* 'authenticated': 'true',
|
||||
* 'username': '<username>'
|
||||
* }
|
||||
*
|
||||
* 401 Unauthorized
|
||||
* JSON
|
||||
* {
|
||||
* 'error': {
|
||||
* 'code': <nr>
|
||||
* 'message: '<error message>'
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
|
||||
// This request only works when POSTed
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
Response::wrongMethod();
|
||||
}
|
||||
|
||||
if (isset($_POST['username'], $_POST['password'])) {
|
||||
WebAppAuthentication::authenticateWithPostedCredentials();
|
||||
}
|
||||
|
||||
if (WebAppAuthentication::getErrorCode() !== NOERROR) {
|
||||
// If we have an error, we will communicate it in our response
|
||||
$response['error'] = [
|
||||
'code' => WebAppAuthentication::getErrorCode(),
|
||||
'hcode' => get_mapi_error_name(WebAppAuthentication::getErrorCode()),
|
||||
'message' => WebAppAuthentication::getErrorMessage(),
|
||||
];
|
||||
}
|
||||
else {
|
||||
// We successfully logged in, so we can communicate this in our response
|
||||
$response = [
|
||||
'authenticated' => WebAppAuthentication::isAuthenticated(),
|
||||
'user' => WebAppAuthentication::getUserName(),
|
||||
];
|
||||
}
|
||||
|
||||
// We will send a 401 header when the user is not authenticated
|
||||
// We also send it when there was an error when we tried to log in. This error
|
||||
// could be that another user is already logged in. (Not sure if 401 is logical then)
|
||||
if (!WebAppAuthentication::isAuthenticated() || WebAppAuthentication::getErrorCode() !== NOERROR) {
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
}
|
||||
|
||||
// Send the response and stop the script
|
||||
echo json_encode($response);
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This controller handles the following request:
|
||||
*
|
||||
* authenticated
|
||||
*
|
||||
* Method: GET
|
||||
* GET Parameters:
|
||||
* service=authenticated
|
||||
* Response:
|
||||
* 200/Ok
|
||||
* JSON
|
||||
* {
|
||||
* 'authenticated': 'true' | 'false',
|
||||
* 'username': '<username>'
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
|
||||
// This request only works with GET
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
Response::wrongMethod();
|
||||
}
|
||||
|
||||
// We will always respond with status 200 for this request.
|
||||
// The response will tell the requester if he is authenticated
|
||||
// or not.
|
||||
echo json_encode([
|
||||
'authenticated' => WebAppAuthentication::isAuthenticated(),
|
||||
'username' => WebAppAuthentication::getUserName(),
|
||||
]);
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This service should read the fingerprint that was sent by the frontend.
|
||||
* If the user is not yet logged in, the fingerprint will be stored in the
|
||||
* session. If the user is logged in and the fingerprint request is sent,
|
||||
* the fingerprint will be compared to the one stored in the session. If
|
||||
* the fingerprint do not match, the session will be destroyed.
|
||||
*
|
||||
* This controller handles the following request:
|
||||
*
|
||||
* fingerprint
|
||||
*
|
||||
* Method: POST
|
||||
* GET Parameters:
|
||||
* service=fingerprint
|
||||
* JSON body:
|
||||
* {"fingerprint":"<fingerprint>"}
|
||||
* Response:
|
||||
* 200 Ok
|
||||
*
|
||||
* 401 Unauthorized
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappsession.php';
|
||||
|
||||
// This request only works when POSTed
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
Response::wrongMethod();
|
||||
}
|
||||
|
||||
// Make sure the session is started
|
||||
$phpSession = WebAppSession::getInstance();
|
||||
|
||||
// If we get a keep-alive request from the fingerprint script
|
||||
// and the user is not authenticated (i.e. user is at login page)
|
||||
// we will respond with the php session expiration time
|
||||
// The fingerprint script will then send another keep-alive request
|
||||
// after half the expiration time has been passed.
|
||||
if (isset($_GET['type']) && $_GET['type'] === 'keepalive') {
|
||||
if (!WebAppAuthentication::isAuthenticated()) {
|
||||
echo ini_get('session.gc_maxlifetime');
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// The fingerprint can destroy an authenticated session when it differs. Do
|
||||
// not accept CORS-simple form posts that another website can submit with the
|
||||
// victim's cookies.
|
||||
$contentType = strtolower(trim(explode(';', (string) ($_SERVER['CONTENT_TYPE'] ?? ''), 2)[0]));
|
||||
if ($contentType !== 'application/json') {
|
||||
http_response_code(415);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$input = json_decode((string) file_get_contents('php://input'), true);
|
||||
if (!is_array($input) || !array_key_exists('fingerprint', $input)) {
|
||||
http_response_code(400);
|
||||
|
||||
exit;
|
||||
}
|
||||
$fingerprint = (string) $input['fingerprint'];
|
||||
|
||||
// Store the fingerprint in the session when the user is not yet
|
||||
// authenticated. (i.e. when the login page is loaded)
|
||||
if (!WebAppAuthentication::isAuthenticated()) {
|
||||
updateSession(function () use ($fingerprint) {
|
||||
$_SESSION['frontend-fingerprint'] = $fingerprint;
|
||||
});
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// If the frontend fingerprint was never stored (e.g. SSO/Keycloak where
|
||||
// the login page is skipped or the fingerprint request was cancelled
|
||||
// during redirect), store it now instead of killing the session.
|
||||
if (!isset($_SESSION['frontend-fingerprint'])) {
|
||||
updateSession(function () use ($fingerprint) {
|
||||
$_SESSION['frontend-fingerprint'] = $fingerprint;
|
||||
});
|
||||
}
|
||||
elseif (!DISABLE_FINGERPRINT_CHECK && $fingerprint !== $_SESSION['frontend-fingerprint']) {
|
||||
error_log('frontend-fingerprint did not match. Session terminated. ' . WebAppAuthentication::getUserName());
|
||||
$phpSession->destroy();
|
||||
Response::unAuthorized();
|
||||
}
|
||||
|
||||
// If we get here, then everything is fine. The user is authenticated and the
|
||||
// frontend fingerprints match. So we don't have to do anything anymore.
|
||||
exit;
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This controller handles the following request:
|
||||
*
|
||||
* authenticated
|
||||
*
|
||||
* Method: POST (GET is accepted only with same-origin browser metadata)
|
||||
* GET Parameters:
|
||||
* service=logout
|
||||
* Response:
|
||||
* 200/Ok
|
||||
* JSON
|
||||
* {
|
||||
* 'authenticated': 'false'
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
|
||||
// Preserve the historical GET endpoint for same-origin callers only. A bare
|
||||
// cross-site navigation has no trustworthy initiator metadata and must fail.
|
||||
$requestMethod = strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? ''));
|
||||
if ($requestMethod !== 'POST' &&
|
||||
($requestMethod !== 'GET' || !Response::isSameOriginRequestSource())) {
|
||||
header('Allow: POST');
|
||||
Response::wrongMethod();
|
||||
}
|
||||
|
||||
// Destroy the session. This will effectively logout the user
|
||||
WebAppSession::getInstance()->destroy();
|
||||
|
||||
exit;
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This controller script handles REST requests. Every request needs its own controller script
|
||||
* to handle the request. This script will only check if a controller for the request
|
||||
* exists, and if so it will delegate control to that script. If a controller for the
|
||||
* request can not be found, this script will respond with
|
||||
* 404 Not Found
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
|
||||
$service = $_GET['service'] ?? null;
|
||||
if (!is_string($service) || preg_match('/\A[a-z]+\z/D', $service) !== 1 ||
|
||||
!file_exists(BASE_PATH . 'server/includes/controllers/service.' . $service . '.php')) {
|
||||
Response::notFound();
|
||||
}
|
||||
|
||||
include BASE_PATH . 'server/includes/controllers/service.' . $service . '.php';
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
|
||||
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
|
||||
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* This controller handles the following request:
|
||||
*
|
||||
* update token (login)
|
||||
*
|
||||
* Method: POST
|
||||
* GET Parameters:
|
||||
* service=authenticate
|
||||
* POST Parameters:
|
||||
* username=username
|
||||
* token=token
|
||||
* new=new
|
||||
* Response:
|
||||
* 200 Ok
|
||||
* JSON
|
||||
* {
|
||||
* 'authenticated': 'true',
|
||||
* 'username': '<username>'
|
||||
* }
|
||||
*
|
||||
* 401 Unauthorized
|
||||
* JSON
|
||||
* {
|
||||
* 'error': {
|
||||
* 'code': <nr>
|
||||
* 'message: '<error message>'
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
require_once BASE_PATH . 'server/includes/core/class.response.php';
|
||||
require_once BASE_PATH . 'server/includes/core/class.webappauthentication.php';
|
||||
|
||||
/**
|
||||
* Decode an JWT access token which contains of a header, payload and
|
||||
* verify signature separated by a dot.
|
||||
*
|
||||
* @param string $accessToken the accessToken to extract the user entryid from
|
||||
*
|
||||
* @return string empty string when entryid is not found
|
||||
*/
|
||||
function extractUserEntryId($accessToken) {
|
||||
$parts = explode(".", $accessToken);
|
||||
if (count($parts) !== 3) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$data = base64_decode($parts[1]);
|
||||
if (!$data) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$json = json_decode($data, true);
|
||||
if (!$json) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!isset($json['kc.identity']) || !isset($json['kc.identity']['kc.i.id'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $json['kc.identity']['kc.i.id'];
|
||||
}
|
||||
|
||||
// This request only works when POSTed
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
Response::wrongMethod();
|
||||
}
|
||||
|
||||
$new = isset($_POST['new']);
|
||||
|
||||
if (isset($_POST['token'])) {
|
||||
$_POST['username'] = extractUserEntryid($_POST['token']);
|
||||
WebAppAuthentication::authenticateWithToken($new);
|
||||
}
|
||||
|
||||
if (WebAppAuthentication::getErrorCode() !== NOERROR) {
|
||||
// If we have an error, we will communicate it in our response
|
||||
$response['error'] = [
|
||||
'code' => WebAppAuthentication::getErrorCode(),
|
||||
'hcode' => get_mapi_error_name(WebAppAuthentication::getErrorCode()),
|
||||
'message' => WebAppAuthentication::getErrorMessage(),
|
||||
];
|
||||
}
|
||||
else {
|
||||
// We successfully logged in, so we can communicate this in our response
|
||||
$response = [
|
||||
'authenticated' => WebAppAuthentication::isAuthenticated(),
|
||||
'user' => WebAppAuthentication::getUserName(),
|
||||
];
|
||||
}
|
||||
|
||||
// We will send a 401 header when the user is not authenticated
|
||||
// We also send it when there was an error when we tried to log in. This error
|
||||
// could be that another user is already logged in. (Not sure if 401 is logical then)
|
||||
if (!WebAppAuthentication::isAuthenticated() || WebAppAuthentication::getErrorCode() !== NOERROR) {
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
}
|
||||
|
||||
// Send the response and stop the script
|
||||
echo json_encode($response);
|
||||
|
||||
exit;
|
||||
Reference in new issue
Block a user