コード例 #1
0
ファイル: Einstellungen.php プロジェクト: sawh/ostepu-system
 /**
  * Lädt die globale Konfiguration von $serverName
  *
  * @param string $serverName Der Name der Konfiguration
  * @param string[][] $data Die Serverdaten
  */
 public static function ladeEinstellungen($serverName, &$data)
 {
     ///$begin = microtime(true);
     $serverHash = md5($serverName);
     Einstellungen::$path = dirname(__FILE__) . '/../config';
     Einstellungen::generatepath(Einstellungen::$path);
     Einstellungen::resetConf();
     Einstellungen::$accessAllowed = false;
     // erzeuge die Liste der Passwörter anhand des masterPasswort für die Verschlüsselung
     $keys = array();
     if (isset(self::$masterPassword[$serverHash]) && trim(self::$masterPassword[$serverHash]) != '') {
         $keys = self::makeKeys(self::$masterPassword[$serverHash]);
         $keys = array_reverse($keys, false);
     }
     if (file_exists(Einstellungen::$path . '/' . $serverName . ".ini") && is_readable(Einstellungen::$path . '/' . $serverName . ".ini")) {
         $temp = file_get_contents(Einstellungen::$path . '/' . $serverName . ".ini");
         if (isset(self::$masterPassword[$serverHash]) && trim(self::$masterPassword[$serverHash]) != '') {
             foreach ($keys as $key) {
                 if ($key === '_BASE64') {
                     $element2 = @base64_decode($temp, true);
                     if ($element2 === false) {
                         // die base64 dekodierung ist fehlgeschlagen
                         Einstellungen::$konfiguration = array();
                         return;
                     }
                     $temp = $element2;
                 } else {
                     $temp = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $temp, MCRYPT_MODE_ECB);
                 }
             }
         }
         $temp = explode("\n", $temp);
         foreach ($temp as $element) {
             if (trim($element) == '') {
                 continue;
             }
             $pos = strpos($element, '=');
             if ($pos === false || $pos === 0) {
                 // es wurde kein gültiges '=' gefunden
                 Einstellungen::$konfiguration = array();
                 return;
             }
             $value = substr($element, $pos + 1);
             $dat = @parse_ini_string('a=' . $value);
             if ($dat === false) {
                 // die Daten konnten nicht geparst werden
                 Einstellungen::$konfiguration = array();
                 return;
             }
             $dat = trim($dat['a']);
             Einstellungen::$konfiguration[substr($element, 0, $pos)] = $dat;
         }
     }
     if (count(Einstellungen::$konfiguration) === 0) {
         Einstellungen::$accessAllowed = true;
     } elseif (!isset(Einstellungen::$konfiguration['data[SV][hash]']) && count(Einstellungen::$konfiguration) > 0) {
         Einstellungen::$accessAllowed = false;
     } else {
         $existingHash = Einstellungen::$konfiguration['data[SV][hash]'];
         unset(Einstellungen::$konfiguration['data[SV][hash]']);
         $hash = self::makeHash(Einstellungen::$konfiguration);
         if ($existingHash == $hash) {
             Einstellungen::$accessAllowed = true;
         } else {
             Einstellungen::$accessAllowed = false;
         }
     }
     ///echo "Ladezeit: ".(round((microtime(true) - $begin)*1000,2)). 'ms<br>';
 }