Erstes Release des Moduls. Fungiert als ICS-Proxy zwischen Nextcloud CalDAV und Dolibarr, um VTIMEZONE-Inkompatibilitaeten zu umgehen. - Proxy-Endpunkt mit API-Key-Absicherung - Automatische VTIMEZONE->UTC Konvertierung - Basic-Auth-Anbindung an Nextcloud - Datei-basiertes Caching - Admin-Seite mit Verbindungstest - Statusseite mit Cache-Verwaltung - Optionaler Cron-Job - Sprachdateien de_DE + en_US Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.4 KiB
PHP
Executable file
117 lines
3.4 KiB
PHP
Executable file
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file agendwrapper/proxy.php
|
|
* \ingroup agendwrapper
|
|
* \brief ICS-Proxy-Endpunkt - liefert bereinigtes ICS an Dolibarr
|
|
*
|
|
* Wird als externe Kalender-URL in Dolibarr eingetragen.
|
|
* Authentifizierung ueber API-Key im GET-Parameter.
|
|
*/
|
|
|
|
if (!defined('NOTOKENRENEWAL')) {
|
|
define('NOTOKENRENEWAL', '1');
|
|
}
|
|
if (!defined('NOREQUIREMENU')) {
|
|
define('NOREQUIREMENU', '1');
|
|
}
|
|
if (!defined('NOREQUIREHTML')) {
|
|
define('NOREQUIREHTML', '1');
|
|
}
|
|
if (!defined('NOREQUIREAJAX')) {
|
|
define('NOREQUIREAJAX', '1');
|
|
}
|
|
if (!defined('NOLOGIN')) {
|
|
define('NOLOGIN', '1');
|
|
}
|
|
if (!defined('NOCSRFCHECK')) {
|
|
define('NOCSRFCHECK', '1');
|
|
}
|
|
|
|
// Dolibarr-Umgebung laden
|
|
$res = 0;
|
|
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
|
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
|
}
|
|
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
|
$tmp2 = realpath(__FILE__);
|
|
$i = strlen($tmp) - 1;
|
|
$j = strlen($tmp2) - 1;
|
|
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
|
$i--;
|
|
$j--;
|
|
}
|
|
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
|
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
|
}
|
|
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
|
|
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../main.inc.php")) {
|
|
$res = @include "../main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../main.inc.php")) {
|
|
$res = @include "../../main.inc.php";
|
|
}
|
|
if (!$res) {
|
|
http_response_code(500);
|
|
die('Include of main fails');
|
|
}
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
|
|
dol_include_once('/agendwrapper/class/IcsProxy.class.php');
|
|
|
|
// Parameter
|
|
$calNumber = GETPOSTINT('cal');
|
|
$apiKey = GETPOST('key', 'alpha');
|
|
|
|
// Kalender-Nummer validieren
|
|
if (!in_array($calNumber, array(1, 2))) {
|
|
http_response_code(400);
|
|
die('Ungueltiger Kalender-Parameter');
|
|
}
|
|
|
|
// Modul aktiv?
|
|
if (!isModEnabled('agendwrapper')) {
|
|
http_response_code(503);
|
|
die('Modul nicht aktiviert');
|
|
}
|
|
|
|
// API-Key pruefen
|
|
$storedKey = getDolGlobalString('AGENDWRAPPER_API_KEY');
|
|
if (empty($storedKey) || empty($apiKey) || $apiKey !== $storedKey) {
|
|
http_response_code(403);
|
|
die('Zugriff verweigert');
|
|
}
|
|
|
|
// ICS generieren
|
|
$proxy = new IcsProxy($db);
|
|
$ics = $proxy->getCleanIcs($calNumber);
|
|
|
|
if ($ics === false) {
|
|
http_response_code(502);
|
|
dol_syslog('AgendWrapper proxy.php Fehler: '.$proxy->error, LOG_ERR);
|
|
die('Fehler: '.$proxy->error);
|
|
}
|
|
|
|
// ICS ausliefern
|
|
header('Content-Type: text/calendar; charset=utf-8');
|
|
header('Content-Disposition: inline; filename="calendar'.$calNumber.'.ics"');
|
|
header('Cache-Control: no-cache, must-revalidate');
|
|
header('X-AgendWrapper: 1.0');
|
|
echo $ics;
|