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>
217 lines
6.6 KiB
PHP
Executable file
217 lines
6.6 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/agendwrapperindex.php
|
|
* \ingroup agendwrapper
|
|
* \brief AgendWrapper Statusseite
|
|
*/
|
|
|
|
// 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 && file_exists("../../../main.inc.php")) {
|
|
$res = @include "../../../main.inc.php";
|
|
}
|
|
if (!$res) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
dol_include_once('/agendwrapper/class/IcsProxy.class.php');
|
|
dol_include_once('/agendwrapper/lib/agendwrapper.lib.php');
|
|
|
|
/**
|
|
* @var Conf $conf
|
|
* @var DoliDB $db
|
|
* @var Translate $langs
|
|
* @var User $user
|
|
*/
|
|
|
|
$langs->loadLangs(array("agendwrapper@agendwrapper"));
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
|
|
// Zugriffskontrolle
|
|
if (!$user->admin) {
|
|
accessforbidden();
|
|
}
|
|
|
|
|
|
/*
|
|
* Aktionen
|
|
*/
|
|
|
|
$proxy = new IcsProxy($db);
|
|
|
|
if ($action == 'clearcache' && $user->admin) {
|
|
$proxy->clearCache();
|
|
setEventMessages($langs->trans("CacheCleared"), null, 'mesgs');
|
|
header('Location: '.$_SERVER["PHP_SELF"]);
|
|
exit;
|
|
}
|
|
|
|
if ($action == 'warmcache' && $user->admin) {
|
|
for ($c = 1; $c <= 2; $c++) {
|
|
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
|
|
if (empty($calName)) {
|
|
continue;
|
|
}
|
|
$proxy->clearCache($c);
|
|
$result = $proxy->getCleanIcs($c);
|
|
if ($result === false) {
|
|
setEventMessages($langs->trans('CacheWarmFailed', $proxy->error), null, 'errors');
|
|
} else {
|
|
$eventCount = $proxy->countEvents($result);
|
|
setEventMessages($langs->trans('CacheWarmed', $eventCount, $c), null, 'mesgs');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Ansicht
|
|
*/
|
|
|
|
llxHeader("", $langs->trans("AgendWrapperArea"), '', '', 0, 0, '', '', '', 'mod-agendwrapper page-index');
|
|
|
|
print load_fiche_titre($langs->trans("AgendWrapperArea"), '', 'fa-calendar-alt');
|
|
|
|
// Konfiguration pruefen
|
|
$ncUrl = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_URL');
|
|
$ncUser = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_USER');
|
|
$ncPass = getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_PASS');
|
|
$apiKey = getDolGlobalString('AGENDWRAPPER_API_KEY');
|
|
|
|
if (empty($ncUrl) || empty($ncUser) || empty($ncPass) || empty($apiKey)) {
|
|
print '<div class="warning">';
|
|
print $langs->trans("ConfigIncomplete");
|
|
print ' <a href="'.dol_buildpath('/agendwrapper/admin/setup.php', 1).'">'.$langs->trans("Settings").'</a>';
|
|
print '</div><br>';
|
|
}
|
|
|
|
// === Cache-Status ===
|
|
print load_fiche_titre($langs->trans("CacheStatus"), '', 'fa-database');
|
|
|
|
$cacheDuration = (int) getDolGlobalString('AGENDWRAPPER_CACHE_DURATION', '300');
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<td class="titlefield">'.$langs->trans("Parameter").'</td>';
|
|
print '<td>'.$langs->trans("CacheStatus").'</td>';
|
|
print '<td class="center">'.$langs->trans("EventCount").'</td>';
|
|
print '<td class="center">'.$langs->trans("CacheAge").'</td>';
|
|
print '</tr>';
|
|
|
|
for ($c = 1; $c <= 2; $c++) {
|
|
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
|
|
$info = $proxy->getCacheInfo($c);
|
|
|
|
print '<tr class="oddeven">';
|
|
print '<td>Kalender '.$c;
|
|
if (!empty($calName)) {
|
|
print ' (<strong>'.dol_escape_htmltag($calName).'</strong>)';
|
|
}
|
|
print '</td>';
|
|
|
|
if (empty($calName)) {
|
|
print '<td colspan="3" class="opacitymedium">'.$langs->trans("CalendarNotConfigured", $c).'</td>';
|
|
} elseif (!$info['exists']) {
|
|
print '<td>'.$langs->trans("CacheEmpty").'</td>';
|
|
print '<td class="center">-</td>';
|
|
print '<td class="center">-</td>';
|
|
} else {
|
|
// Status
|
|
if ($info['age'] <= $cacheDuration) {
|
|
print '<td><span class="badge badge-status4">'.$langs->trans("CacheFresh", $info['age']).'</span></td>';
|
|
} else {
|
|
print '<td><span class="badge badge-status1">'.$langs->trans("CacheExpired", $info['age']).'</span></td>';
|
|
}
|
|
// Event-Anzahl
|
|
print '<td class="center">'.$info['event_count'].'</td>';
|
|
// Alter
|
|
print '<td class="center">'.dol_print_date(time() - $info['age'], 'dayhour').'</td>';
|
|
}
|
|
|
|
print '</tr>';
|
|
}
|
|
|
|
print '</table>';
|
|
|
|
print '<br>';
|
|
|
|
// Buttons
|
|
print '<div class="center">';
|
|
print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?action=warmcache&token='.newToken().'">'.$langs->trans("WarmCache").'</a>';
|
|
print ' ';
|
|
print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?action=clearcache&token='.newToken().'">'.$langs->trans("ClearCache").'</a>';
|
|
print '</div>';
|
|
|
|
print '<br>';
|
|
|
|
// === Proxy-URLs ===
|
|
if (!empty($apiKey)) {
|
|
$cal1 = getDolGlobalString('AGENDWRAPPER_CAL1_NAME');
|
|
$cal2 = getDolGlobalString('AGENDWRAPPER_CAL2_NAME');
|
|
|
|
if (!empty($cal1) || !empty($cal2)) {
|
|
print load_fiche_titre($langs->trans("ProxyUrlSection"), '', 'fa-link');
|
|
|
|
$baseProxyUrl = DOL_MAIN_URL_ROOT.'/custom/agendwrapper/proxy.php';
|
|
|
|
print '<div class="info">';
|
|
print $langs->trans("ProxyUrlInfo").'<br><br>';
|
|
|
|
if (!empty($cal1)) {
|
|
$proxyUrl1 = $baseProxyUrl.'?cal=1&key='.urlencode($apiKey);
|
|
print '<strong>'.$langs->trans("ProxyUrlCal1").' ('.$cal1.'):</strong><br>';
|
|
print '<code>'.dol_escape_htmltag($proxyUrl1).'</code><br><br>';
|
|
}
|
|
|
|
if (!empty($cal2)) {
|
|
$proxyUrl2 = $baseProxyUrl.'?cal=2&key='.urlencode($apiKey);
|
|
print '<strong>'.$langs->trans("ProxyUrlCal2").' ('.$cal2.'):</strong><br>';
|
|
print '<code>'.dol_escape_htmltag($proxyUrl2).'</code><br>';
|
|
}
|
|
|
|
print '</div>';
|
|
}
|
|
}
|
|
|
|
llxFooter();
|
|
$db->close();
|