diff --git a/diagramm_collect.php b/diagramm_collect.php index fe23c29..76efcd0 100644 --- a/diagramm_collect.php +++ b/diagramm_collect.php @@ -9,6 +9,24 @@ // */1 * * * * /usr/bin/php -f /pfad-zu-homehub/diagramm_collect.php >/dev/null 2>&1 +function read_config($file) { + if (!is_file($file)) return false; + $config = file_get_contents($file); + + // BOM erkennen und entfernen + if (strncmp($config, pack("CCC", 0xef, 0xbb, 0xbf), 3) === 0) $config = substr($config, 3); + + // nicht-UTF8 Inhalt zu UTF8 konvertieren + if (extension_loaded('mbstring')) return mb_convert_encoding($config, 'UTF-8', mb_detect_encoding($config, 'UTF-8, ISO-8859-1', true)); + else { + if (!preg_match('/(*UTF8)[äöüÄÖÜß]/', $config)) { + return html_entity_decode(htmlentities($config, ENT_QUOTES, 'ISO-8859-1'), ENT_QUOTES , 'UTF-8'); + } else { + return $config; + } + } +} + require_once(__DIR__.'/interface.php'); @@ -17,7 +35,8 @@ // Lese aus custom.json die diagramm ise_id welche geloggt werden sollen -$data = file_get_contents(__DIR__.'/config/custom.json'); +#$data = file_get_contents(__DIR__.'/config/custom.json'); +$data = read_config(__DIR__.'/config/custom.json'); $json = json_decode($data, true); diff --git a/index.php b/index.php index 746b67c..5ab411a 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,24 @@ //ini_set('display_errors', 'on'); // php8 +function read_config($file) { + if (!is_file($file)) return false; + $config = file_get_contents($file); + + // BOM erkennen und entfernen + if (strncmp($config, pack("CCC", 0xef, 0xbb, 0xbf), 3) === 0) $config = substr($config, 3); + + // nicht-UTF8 Inhalt zu UTF8 konvertieren + if (extension_loaded('mbstring')) return mb_convert_encoding($config, 'UTF-8', mb_detect_encoding($config, 'UTF-8, ISO-8859-1', true)); + else { + if (!preg_match('/(*UTF8)[äöüÄÖÜß]/', $config)) { + return html_entity_decode(htmlentities($config, ENT_QUOTES, 'ISO-8859-1'), ENT_QUOTES , 'UTF-8'); + } else { + return $config; + } + } +} + $page = $_SERVER['PHP_SELF']; $sec = "500"; //header("Refresh: $sec; url=".$page."?".$_SERVER['QUERY_STRING']); @@ -53,19 +71,20 @@ // MENU # json_decode Config files $categories = array(); -$menu = array(); -if(file_exists('config/categories.json')) +$menu = array(); +#if(file_exists('config/categories.json')) +if ($str = read_config('config/categories.json')) { - $str = file_get_contents('config/categories.json'); - +# $str = file_get_contents('config/categories.json'); + // Prüfe UTF-8 - if (extension_loaded("mbstring")) { - if (!mb_check_encoding($str, 'UTF-8')) - { - echo "Datei 'config/categories.json' entspricht nicht dem UTF-8 Format. Bitte als UTF-8 speichern."; - exit(); - } - } + #if (extension_loaded("mbstring")) { + # if (!mb_check_encoding($str, 'UTF-8')) + # { + # echo "Datei 'config/categories.json' entspricht nicht dem UTF-8 Format. Bitte als UTF-8 speichern."; + # exit(); + # } + #} $json = json_decode($str, true); $menu = $json['categories']; @@ -122,19 +141,19 @@ // CUSTOM # Anpassungen des Benutzers $custom = array(); -if(file_exists('config/custom.json')) +#if(file_exists('config/custom.json')) +if($str = read_config('config/custom.json')) { - $str = file_get_contents('config/custom.json'); + #$str = file_get_contents('config/custom.json'); // Prüfe UTF-8 - if (extension_loaded("mbstring")) { - if (!mb_check_encoding($str, 'UTF-8')) - { - echo "Datei 'config/config/custom.json' entspricht nicht dem UTF-8 Format. Bitte als UTF-8 speichern."; - exit(); - } - } - + #if (extension_loaded("mbstring")) { + # if (!mb_check_encoding($str, 'UTF-8')) + # { + # echo "Datei 'config/config/custom.json' entspricht nicht dem UTF-8 Format. Bitte als UTF-8 speichern."; + # exit(); + # } + #} $json = json_decode($str, true); if(isset($json['custom'])) @@ -151,9 +170,10 @@ // MAPPING # Voreingestellte Icon für Komponenten $mapping = array(); -if(file_exists('config/mapping.json')) +#if(file_exists('config/mapping.json')) +if($str = read_config('config/mapping.json')) { - $str = file_get_contents('config/mapping.json'); + #$str = file_get_contents('config/mapping.json'); $json = json_decode($str, true); if(isset($json['mapping'])) { @@ -165,14 +185,14 @@ "Konfigurationsdatei 'config/mapping.json' nicht gefunden!"; exit(); } - // EXPORT # Lade Exportdatei der Homematic $export = array(); -if(file_exists('config/export.json')) +#if(file_exists('config/export.json')) +if($str = read_config('config/export.json')) { - $str = file_get_contents('config/export.json'); + #$str = file_get_contents('config/export.json'); $export = json_decode($str, true); } else @@ -180,7 +200,6 @@ "Konfigurationsdatei 'config/export.json' nicht gefunden!"; exit(); } - // Komponenten einlesen @@ -421,13 +440,14 @@ if($Page == $Servicemeldungen) { - if(file_exists("dev/export.json")) { + #if(file_exists("dev/export.json")) { + if($str = read_config("dev/export.json")) { $xml = simplexml_load_file('dev/systemNotification.php'); - $str = file_get_contents('dev/export.json'); + #$str = file_get_contents('dev/export.json'); } else { - $xml = simplexml_load_string(api_systemNotification($ccu)); - $str = file_get_contents('config/export.json'); + #$str = file_get_contents('config/export.json'); + $str = read_config('config/export.json'); } // Für Devices @@ -624,11 +644,6 @@ "; } ?> "; } ?> - - - - -