Some checks are pending
Deploy netdiag / deploy (push) Waiting to run
Netzwerk-Diagnose-Modul mit JSON-API für die NetDiag-App: - 3 Tabellen (protocol/device/measurement), generisches JSON-result - JSON-API: auth, customers, orders, protocols (idempotenter Sync), pdf - JWT-Auth (HS256), CORS für die Capacitor-App - Tabs an Thirdparty + Auftrag, Protokoll-Card, PDF-Generator - QR-Code zum App-Download in der Modul-Konfiguration - de_DE + en_US, Rechtesystem netdiag->protocol read/write/delete Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
134 lines
3.7 KiB
PHP
134 lines
3.7 KiB
PHP
<?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 htdocs/custom/netdiag/lib/netdiag.lib.php
|
|
* \ingroup netdiag
|
|
* \brief Hilfsfunktionen für das Modul NetDiag
|
|
*/
|
|
|
|
/**
|
|
* Tabs für die Admin-Seiten des Moduls vorbereiten
|
|
*
|
|
* @return array<int,array<int,string>> Tab-Array
|
|
*/
|
|
function netdiagAdminPrepareHead()
|
|
{
|
|
global $langs, $conf;
|
|
|
|
$langs->load("netdiag@netdiag");
|
|
|
|
$h = 0;
|
|
$head = array();
|
|
|
|
$head[$h][0] = dol_buildpath("/netdiag/admin/setup.php", 1);
|
|
$head[$h][1] = $langs->trans("Settings");
|
|
$head[$h][2] = 'settings';
|
|
$h++;
|
|
|
|
$head[$h][0] = dol_buildpath("/netdiag/admin/about.php", 1);
|
|
$head[$h][1] = $langs->trans("About");
|
|
$head[$h][2] = 'about';
|
|
$h++;
|
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'netdiag@netdiag');
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'netdiag@netdiag', 'remove');
|
|
|
|
return $head;
|
|
}
|
|
|
|
/**
|
|
* Tabs für die Detailansicht eines Diagnose-Protokolls vorbereiten
|
|
*
|
|
* @param NetDiagProtocol $object Protokoll-Objekt
|
|
* @return array<int,array<int,string>> Tab-Array
|
|
*/
|
|
function netdiagProtocolPrepareHead($object)
|
|
{
|
|
global $langs, $conf;
|
|
|
|
$langs->load("netdiag@netdiag");
|
|
|
|
$h = 0;
|
|
$head = array();
|
|
|
|
$head[$h][0] = dol_buildpath("/netdiag/netdiagprotocol_card.php", 1).'?id='.$object->id;
|
|
$head[$h][1] = $langs->trans("NetDiagProtocol");
|
|
$head[$h][2] = 'card';
|
|
$h++;
|
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'netdiagprotocol@netdiag');
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'netdiagprotocol@netdiag', 'remove');
|
|
|
|
return $head;
|
|
}
|
|
|
|
/**
|
|
* Ausgabeverzeichnis des Moduls ermitteln (für PDF-Dokumente)
|
|
*
|
|
* @return string Absoluter Pfad zum Dokumentenverzeichnis
|
|
*/
|
|
function netdiagGetOutputDir()
|
|
{
|
|
global $conf;
|
|
if (!empty($conf->netdiag->dir_output)) {
|
|
return $conf->netdiag->dir_output;
|
|
}
|
|
return DOL_DATA_ROOT.'/netdiag';
|
|
}
|
|
|
|
/**
|
|
* Ein Mess-Ergebnis (JSON) lesbar als HTML aufbereiten.
|
|
*
|
|
* Generisch: rendert flache Schlüssel/Wert-Paare und einfache Listen,
|
|
* damit auch künftige Tools ohne Code-Änderung dargestellt werden.
|
|
*
|
|
* @param string $json JSON-String des Ergebnisses
|
|
* @return string HTML-Schnipsel
|
|
*/
|
|
function netdiagFormatResult($json)
|
|
{
|
|
if (empty($json)) {
|
|
return '<span class="opacitymedium">-</span>';
|
|
}
|
|
$data = json_decode($json, true);
|
|
if ($data === null) {
|
|
return dol_escape_htmltag(dol_trunc($json, 120));
|
|
}
|
|
if (!is_array($data)) {
|
|
return dol_escape_htmltag((string) $data);
|
|
}
|
|
|
|
$out = '<div class="netdiag-result">';
|
|
foreach ($data as $key => $val) {
|
|
$label = dol_escape_htmltag(ucfirst((string) $key));
|
|
if (is_array($val)) {
|
|
$flat = array();
|
|
foreach ($val as $item) {
|
|
$flat[] = is_array($item) ? json_encode($item, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : (string) $item;
|
|
}
|
|
$valstr = implode(', ', $flat);
|
|
} elseif (is_bool($val)) {
|
|
$valstr = $val ? 'ja' : 'nein';
|
|
} else {
|
|
$valstr = (string) $val;
|
|
}
|
|
$out .= '<span class="netdiag-kv"><strong>'.$label.':</strong> '.dol_escape_htmltag(dol_trunc($valstr, 200)).'</span> ';
|
|
}
|
|
$out .= '</div>';
|
|
return $out;
|
|
}
|