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>
352 lines
12 KiB
PHP
Executable file
352 lines
12 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/admin/setup.php
|
|
* \ingroup agendwrapper
|
|
* \brief AgendWrapper Einstellungsseite
|
|
*/
|
|
|
|
// 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) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
|
|
require_once '../lib/agendwrapper.lib.php';
|
|
|
|
/**
|
|
* @var Conf $conf
|
|
* @var DoliDB $db
|
|
* @var HookManager $hookmanager
|
|
* @var Translate $langs
|
|
* @var User $user
|
|
*/
|
|
|
|
$langs->loadLangs(array("admin", "agendwrapper@agendwrapper"));
|
|
|
|
// Zugriffskontrolle
|
|
if (!$user->admin) {
|
|
accessforbidden();
|
|
}
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$backtopage = GETPOST('backtopage', 'alpha');
|
|
|
|
|
|
/*
|
|
* Aktionen
|
|
*/
|
|
|
|
if ($action == 'update' && $user->admin) {
|
|
$db->begin();
|
|
$error = 0;
|
|
|
|
// Nextcloud-URL
|
|
$val = GETPOST('AGENDWRAPPER_NEXTCLOUD_URL', 'alpha');
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_URL', trim($val), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
|
|
// Benutzername
|
|
$val = GETPOST('AGENDWRAPPER_NEXTCLOUD_USER', 'alpha');
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_USER', trim($val), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
|
|
// Passwort (nur wenn ausgefuellt, verschluesselt speichern)
|
|
$pass = GETPOST('AGENDWRAPPER_NEXTCLOUD_PASS', 'none');
|
|
if (!empty($pass)) {
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_NEXTCLOUD_PASS', dolEncrypt($pass), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
}
|
|
|
|
// Kalender 1
|
|
$val = GETPOST('AGENDWRAPPER_CAL1_NAME', 'alpha');
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CAL1_NAME', trim($val), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
|
|
// Kalender 2
|
|
$val = GETPOST('AGENDWRAPPER_CAL2_NAME', 'alpha');
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CAL2_NAME', trim($val), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
|
|
// Cache-Dauer
|
|
$val = GETPOSTINT('AGENDWRAPPER_CACHE_DURATION');
|
|
if ($val < 30) {
|
|
$val = 300;
|
|
}
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_CACHE_DURATION', $val, 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
|
|
// API-Key
|
|
$val = GETPOST('AGENDWRAPPER_API_KEY', 'alpha');
|
|
if (!empty($val)) {
|
|
$res = dolibarr_set_const($db, 'AGENDWRAPPER_API_KEY', trim($val), 'chaine', 0, '', $conf->entity);
|
|
if (!($res > 0)) {
|
|
$error++;
|
|
}
|
|
}
|
|
|
|
if (!$error) {
|
|
$db->commit();
|
|
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
|
} else {
|
|
$db->rollback();
|
|
setEventMessages($langs->trans("Error"), null, 'errors');
|
|
}
|
|
}
|
|
|
|
// Verbindungstest
|
|
if ($action == 'testconnection' && $user->admin) {
|
|
dol_include_once('/agendwrapper/class/IcsProxy.class.php');
|
|
$proxy = new IcsProxy($db);
|
|
|
|
$testResults = array();
|
|
for ($c = 1; $c <= 2; $c++) {
|
|
$calName = getDolGlobalString('AGENDWRAPPER_CAL'.$c.'_NAME');
|
|
if (empty($calName)) {
|
|
continue;
|
|
}
|
|
|
|
$rawIcs = $proxy->fetchFromNextcloud($calName);
|
|
if ($rawIcs === false) {
|
|
setEventMessages($langs->trans('ConnectionFailed', $proxy->error), null, 'errors');
|
|
} else {
|
|
$eventCount = $proxy->countEvents($rawIcs);
|
|
setEventMessages($langs->trans('ConnectionSuccess', $eventCount).' (Kalender '.$c.': '.$calName.')', null, 'mesgs');
|
|
}
|
|
}
|
|
|
|
if (empty(getDolGlobalString('AGENDWRAPPER_CAL1_NAME')) && empty(getDolGlobalString('AGENDWRAPPER_CAL2_NAME'))) {
|
|
setEventMessages($langs->trans('CalendarNotConfigured', '1+2'), null, 'warnings');
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Ansicht
|
|
*/
|
|
|
|
$form = new Form($db);
|
|
|
|
$title = "AgendWrapperSetup";
|
|
$help_url = '';
|
|
|
|
llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-agendwrapper page-admin');
|
|
|
|
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
|
|
|
|
print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
|
|
|
|
$head = agendwrapperAdminPrepareHead();
|
|
print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "agendwrapper@agendwrapper");
|
|
|
|
print '<span class="opacitymedium">'.$langs->trans("AgendWrapperSetupPage").'</span><br><br>';
|
|
|
|
// Formular
|
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="action" value="update">';
|
|
|
|
// === Nextcloud-Verbindung ===
|
|
print load_fiche_titre($langs->trans("NextcloudSection"), '', 'fa-cloud');
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
|
|
|
// URL
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("NextcloudUrl"), $langs->trans("NextcloudUrlHelp"));
|
|
print '</td><td>';
|
|
print '<input type="url" name="AGENDWRAPPER_NEXTCLOUD_URL" class="minwidth500" value="'.dol_escape_htmltag(getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_URL')).'" placeholder="https://cloud.example.de/remote.php/dav/calendars/user/">';
|
|
print '</td></tr>';
|
|
|
|
// Benutzername
|
|
print '<tr class="oddeven"><td>';
|
|
print $langs->trans("NextcloudUser");
|
|
print '</td><td>';
|
|
print '<input type="text" name="AGENDWRAPPER_NEXTCLOUD_USER" class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_USER')).'">';
|
|
print '</td></tr>';
|
|
|
|
// Passwort
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("NextcloudPass"), $langs->trans("NextcloudPassHelp"));
|
|
print '</td><td>';
|
|
print '<input type="password" name="AGENDWRAPPER_NEXTCLOUD_PASS" class="minwidth300" value="" autocomplete="new-password" placeholder="';
|
|
if (getDolGlobalString('AGENDWRAPPER_NEXTCLOUD_PASS')) {
|
|
print dol_escape_htmltag($langs->trans("NextcloudPassSet"));
|
|
} else {
|
|
print dol_escape_htmltag($langs->trans("NextcloudPass"));
|
|
}
|
|
print '">';
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
print '<br>';
|
|
|
|
// === Kalender ===
|
|
print load_fiche_titre($langs->trans("CalendarSection"), '', 'fa-calendar');
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
|
|
|
// Kalender 1
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("Cal1Name"), $langs->trans("Cal1NameHelp"));
|
|
print '</td><td>';
|
|
print '<input type="text" name="AGENDWRAPPER_CAL1_NAME" class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString('AGENDWRAPPER_CAL1_NAME')).'" placeholder="firmenkalender">';
|
|
print '</td></tr>';
|
|
|
|
// Kalender 2
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("Cal2Name"), $langs->trans("Cal2NameHelp"));
|
|
print '</td><td>';
|
|
print '<input type="text" name="AGENDWRAPPER_CAL2_NAME" class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString('AGENDWRAPPER_CAL2_NAME')).'" placeholder="privatkalender">';
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
print '<br>';
|
|
|
|
// === Cache ===
|
|
print load_fiche_titre($langs->trans("CacheSection"), '', 'fa-database');
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
|
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("CacheDuration"), $langs->trans("CacheDurationHelp"));
|
|
print '</td><td>';
|
|
$cacheDuration = getDolGlobalString('AGENDWRAPPER_CACHE_DURATION', '300');
|
|
print '<input type="number" name="AGENDWRAPPER_CACHE_DURATION" class="width100" value="'.dol_escape_htmltag($cacheDuration).'" min="30" step="30"> '.$langs->trans("Seconds");
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
print '<br>';
|
|
|
|
// === Proxy / API-Key ===
|
|
print load_fiche_titre($langs->trans("ProxySection"), '', 'fa-key');
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
|
|
|
|
print '<tr class="oddeven"><td>';
|
|
print $form->textwithpicto($langs->trans("ApiKey"), $langs->trans("ApiKeyHelp"));
|
|
print '</td><td>';
|
|
print '<input type="text" name="AGENDWRAPPER_API_KEY" id="apikey_field" class="minwidth400" value="'.dol_escape_htmltag(getDolGlobalString('AGENDWRAPPER_API_KEY')).'">';
|
|
print ' <a class="button" href="#" onclick="document.getElementById(\'apikey_field\').value = generateApiKey(); return false;">'.$langs->trans("GenerateApiKey").'</a>';
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
|
|
// Speichern-Button
|
|
print '<div class="center">';
|
|
print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
print '<br>';
|
|
|
|
// === Verbindungstest ===
|
|
print '<div class="center">';
|
|
print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?action=testconnection&token='.newToken().'">'.$langs->trans("TestConnection").'</a>';
|
|
print '</div>';
|
|
|
|
print '<br>';
|
|
|
|
// === Proxy-URLs anzeigen ===
|
|
$apiKey = getDolGlobalString('AGENDWRAPPER_API_KEY');
|
|
$cal1 = getDolGlobalString('AGENDWRAPPER_CAL1_NAME');
|
|
$cal2 = getDolGlobalString('AGENDWRAPPER_CAL2_NAME');
|
|
|
|
if (!empty($apiKey) && (!empty($cal1) || !empty($cal2))) {
|
|
print load_fiche_titre($langs->trans("ProxyUrlSection"), '', 'fa-link');
|
|
|
|
print '<div class="info">';
|
|
print $langs->trans("ProxyUrlInfo").'<br><br>';
|
|
|
|
$baseProxyUrl = DOL_MAIN_URL_ROOT.'/custom/agendwrapper/proxy.php';
|
|
|
|
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>';
|
|
} else {
|
|
print '<div class="warning">'.$langs->trans("ProxyNotConfigured").'</div>';
|
|
}
|
|
|
|
print dol_get_fiche_end();
|
|
|
|
// JavaScript fuer API-Key-Generierung
|
|
print '<script>
|
|
function generateApiKey() {
|
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
var key = "";
|
|
for (var i = 0; i < 32; i++) {
|
|
key += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return key;
|
|
}
|
|
</script>';
|
|
|
|
llxFooter();
|
|
$db->close();
|