Beispiel #1
0
 /**
  * Die Hauptfunktion des Installationsassistenten
  *
  * @param bool $console true = Konsolendarstellung, false = HTML
  */
 public function CallInstall($console = false)
 {
     $output = array();
     $installFail = false;
     $simple = false;
     $data = array();
     $tmp = array();
     if (isset($_POST['data'])) {
         $data = $_POST['data'];
     }
     if (isset($_POST['tmp'])) {
         $tmp = $_POST['tmp'];
     }
     if (isset($_POST['simple'])) {
         $simple = true;
     }
     if (isset($_POST['update'])) {
         $_POST['action'] = 'update';
     }
     if (isset($_POST['actionInstall'])) {
         $_POST['action'] = 'install';
     }
     if (isset($_POST['actionUpdate'])) {
         $_POST['action'] = 'update';
     }
     if (!isset($data['PL']['language'])) {
         $data['PL']['language'] = 'de';
     }
     if (!isset($data['PL']['init'])) {
         $data['PL']['init'] = 'DB/CControl';
     }
     // URLs und Pfade sollen keinen / am Ende haben (damit es einheitlich ist)
     if (isset($data['PL']['url'])) {
         $data['PL']['url'] = rtrim($data['PL']['url'], '/');
     }
     if (isset($data['PL']['urlExtern'])) {
         $data['PL']['urlExtern'] = rtrim($data['PL']['urlExtern'], '/');
     }
     if (isset($data['PL']['temp'])) {
         $data['PL']['temp'] = rtrim($data['PL']['temp'], '/');
     }
     if (isset($data['PL']['files'])) {
         $data['PL']['files'] = rtrim($data['PL']['files'], '/');
     }
     if (isset($data['PL']['init'])) {
         $data['PL']['init'] = rtrim($data['PL']['init'], '/');
     }
     // check which server is selected
     $server = isset($_POST['server']) ? $_POST['server'] : null;
     Einstellungen::$selected_server = isset($_POST['selected_server']) ? $_POST['selected_server'] : null;
     // behandle das MasterPasswort
     $serverHash = md5(Einstellungen::$selected_server);
     $tmp[$serverHash]['newMasterPassword'] = isset($tmp[$serverHash]['masterPassword']) ? $tmp[$serverHash]['masterPassword'] : null;
     if (isset($_POST['changeMasterPassword'])) {
         Einstellungen::$masterPassword[$serverHash] = isset($tmp[$serverHash]['oldMasterPassword']) ? $tmp[$serverHash]['oldMasterPassword'] : null;
         $tmp[$serverHash]['masterPassword'] = Einstellungen::$masterPassword[$serverHash];
     } else {
         Einstellungen::$masterPassword[$serverHash] = $tmp[$serverHash]['newMasterPassword'];
         $tmp[$serverHash]['masterPassword'] = Einstellungen::$masterPassword[$serverHash];
     }
     foreach ($tmp as $key => $tm) {
         if (!isset($tm['masterPassword']) && isset($tm['oldMasterPassword']) && trim($tm['oldMasterPassword']) != '') {
             $tmp[$key]['masterPassword'] = $tm['oldMasterPassword'];
             $tmp[$key]['newMasterPassword'] = isset($tmp[$key]['oldMasterPassword']) ? $tmp[$key]['oldMasterPassword'] : null;
             Einstellungen::$masterPassword[$key] = $tm['oldMasterPassword'];
         }
         if (!isset(Einstellungen::$masterPassword[$key]) && isset($tmp[$key]['masterPassword']) && trim($tmp[$key]['masterPassword']) != '') {
             $tmp[$key]['newMasterPassword'] = isset($tmp[$key]['masterPassword']) ? $tmp[$key]['masterPassword'] : null;
             Einstellungen::$masterPassword[$key] = $tm['masterPassword'];
         }
     }
     // prüfe ob der Servername geändert wurde
     if (isset($data['SV']['name']) && $data['SV']['name'] !== null && Einstellungen::$selected_server !== null) {
         if ($data['SV']['name'] != Einstellungen::$selected_server) {
             $oldServerHash = md5($data['SV']['name']);
             $newServerHash = md5(Einstellungen::$selected_server);
             if (isset(Einstellungen::$masterPassword[$oldServerHash])) {
                 Einstellungen::$masterPassword[$newServerHash] = Einstellungen::$masterPassword[$oldServerHash];
                 unset(Einstellungen::$masterPassword[$oldServerHash]);
             }
             Einstellungen::umbenennenEinstellungen(Einstellungen::$selected_server, $data['SV']['name']);
         }
     }
     // check which menu is selected
     $selected_menu = intval(isset($_POST['selected_menu']) ? $_POST['selected_menu'] : self::$menuItems[0]);
     if (isset($_POST['action']) && $_POST['action'] == 'update') {
         $selected_menu = -1;
     }
     // check server configs
     Einstellungen::$serverFiles = Installation::GibServerDateien();
     // add Server
     $addServer = false;
     $addServerResult = array();
     if ((isset($_POST['action']) && $_POST['action'] === 'install' || isset($_POST['actionAddServer']) || count(Einstellungen::$serverFiles) == 0) && !$installFail) {
         $addServer = true;
         $server = Einstellungen::NeuenServerAnlegen();
         Einstellungen::$serverFiles[] = $server;
         $server = pathinfo($server)['filename'];
         Einstellungen::ladeEinstellungen($server, $data);
         ///$data['SV']['name'] = $server;
         Einstellungen::speichereEinstellungen($server, $data);
     }
     // save data on switching between server-confs
     if (Einstellungen::$selected_server !== null && $server != null) {
         if ($server != Einstellungen::$selected_server) {
             Einstellungen::ladeEinstellungen(Einstellungen::$selected_server, $data);
             //Einstellungen::speichereEinstellungen(Einstellungen::$selected_server,$data);
             Einstellungen::resetConf();
         }
     }
     // select first if no server is selected
     if (Einstellungen::$selected_server == null && $server == null) {
         Einstellungen::$selected_server = pathinfo(Einstellungen::$serverFiles[0])['filename'];
         $server = Einstellungen::$selected_server;
     }
     if ($server != null) {
         Einstellungen::$selected_server = $server;
     }
     $server = Einstellungen::$selected_server;
     $data['SV']['name'] = Einstellungen::$selected_server;
     $serverHash = md5(Einstellungen::$selected_server);
     if (!isset($tmp[$serverHash]['masterPassword'])) {
         $tmp[$serverHash]['masterPassword'] = null;
     }
     // nun kann die Konfiguration des gewählten Servers geladen werden (selected_server)
     Einstellungen::ladeEinstellungen(Einstellungen::$selected_server, $data);
     Einstellungen::$masterPassword[$serverHash] = isset($tmp[$serverHash]['newMasterPassword']) ? $tmp[$serverHash]['newMasterPassword'] : '';
     if (isset(Einstellungen::$masterPassword[$serverHash])) {
         $tmp[$serverHash]['masterPassword'] = Einstellungen::$masterPassword[$serverHash];
     }
     // load language
     Language::loadLanguage($data['PL']['language'], 'default', 'ini');
     // ermittle alle Segmente
     $this->loadSegments();
     if (Einstellungen::$accessAllowed) {
         if ($console) {
             $data['ZV']['zv_type'] = 'local';
         }
         if ($simple) {
             $data['ZV']['zv_type'] = 'local';
         }
         if (isset($_POST['action'])) {
             $data['action'] = $_POST['action'];
         }
         $fail = false;
         $errno = null;
         $error = null;
         if ($simple) {
             $selected_menu = -1;
         }
     }
     if (!$console && !$simple) {
         // select language - german
         if (isset($_POST['actionSelectGerman']) || isset($_POST['actionSelectGerman_x'])) {
             $data['PL']['language'] = 'de';
         }
         // select language - english
         if (isset($_POST['actionSelectEnglish']) || isset($_POST['actionSelectEnglish_x'])) {
             $data['PL']['language'] = 'en';
         }
         echo "<html><head>";
         echo "<link rel='stylesheet' type='text/css' href='css/format.css'>";
         $titleText = Language::Get('main', 'title' . $selected_menu);
         if ($selected_menu == -1) {
             if (isset($_POST['action'])) {
                 $titleText = Language::Get('main', 'title' . $_POST['action']);
             }
         }
         echo "</head><body><div class='center'>";
         if (Einstellungen::$accessAllowed && $titleText !== '???') {
             echo "<h1>" . $titleText . "</h1></br>";
         }
         echo "<form action='' method='post' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'>";
     }
     if (Einstellungen::$accessAllowed) {
         // führe die Initialisierungsfunktionen der Segmente aus
         foreach (Einstellungen::$segments as $segs) {
             if (!is_callable("{$segs}::init")) {
                 continue;
             }
             ///if (!isset($segs::$initialized)) continue;
             ///if ($segs::$initialized) continue;
             $segs::init($console, $data, $fail, $errno, $error);
         }
         $segmentResults = array();
         // installiere die Segmente
         foreach (Einstellungen::$segments as $segs) {
             if (!isset($segs::$onEvents)) {
                 continue;
             }
             foreach ($segs::$onEvents as $event) {
                 if (isset($event['enabledInstall']) && !$event['enabledInstall']) {
                     continue;
                 }
                 $isSetEvent = false;
                 if (isset($_POST['action']) && in_array($_POST['action'], $event['event'])) {
                     $isSetEvent = true;
                 }
                 foreach ($event['event'] as $ev) {
                     if (isset($_POST[$ev])) {
                         $isSetEvent = true;
                         break;
                     }
                 }
                 if (!$installFail && ($segs::$page === $selected_menu && in_array('page', $event['event']) || $isSetEvent)) {
                     $result = array();
                     $procedure = 'install';
                     if (isset($event['procedure'])) {
                         $procedure = $event['procedure'];
                     }
                     $result['content'] = Zugang::Ermitteln($event['name'], $segs . '::' . $procedure, $data, $fail, $errno, $error);
                     $segs::$installed = true;
                     $installFail = $fail;
                     $result['fail'] = $fail;
                     $result['errno'] = $errno;
                     $result['error'] = $error;
                     if ($console && !$simple) {
                         $output[$segs::$name] = $result;
                     }
                     $fail = false;
                     $errno = null;
                     $error = null;
                     if (!isset($segmentResults[$segs::$name])) {
                         $segmentResults[$segs::$name] = array();
                     }
                     $segmentResults[$segs::$name][$event['name']] = $result;
                 }
             }
         }
     }
     if (!$console && !$simple) {
         echo "<table border='0'><tr>";
         echo "<th valign='top'>";
         echo "<div style='width:150px;word-break: break-all;'>";
         echo "<table border='0'>";
         // ab hier wird die linke Infoleiste erzeugt
         foreach (Einstellungen::$segments as $segs) {
             if (isset($segs::$enabledShow) && !$segs::$enabledShow) {
                 continue;
             }
             if (!is_callable("{$segs}::showInfoBar")) {
                 continue;
             }
             $segs::showInfoBar($data);
             echo "<tr><th height='10'></th></tr>";
         }
         echo "</table>";
         echo "</div";
         echo "</th>";
         echo "<th width='2'></th>";
         echo "</th>";
         echo "<th width='600'><hr />";
         if (Einstellungen::$accessAllowed) {
             echo "<table border='0' cellpadding='4' width='600'>";
             echo "<input type='hidden' name='selected_menu' value='{$selected_menu}'>";
             echo "<tr>";
             $text = '';
             for ($i = 0; $i < count(self::$menuItems); $i++) {
                 if ($i % 5 == 0 && $i > 0) {
                     $text .= "<tr>";
                 }
                 $item = self::$menuItems[$i];
                 $type = self::$menuTypes[$i];
                 echo "<td class='" . ($type == 0 ? 'h' : 'k') . "'><div align='center'>" . Design::erstelleSubmitButtonFlach('selected_menu', $item, $selected_menu == $item ? '<font color="maroon">' . Language::Get('main', 'title' . $item) . '</font>' : Language::Get('main', 'title' . $item)) . "</div></td>";
             }
             echo "</tr>";
             echo "</table>";
         } else {
             $text = '';
             $text .= Design::erstelleBeschreibung($console, Language::Get('main', 'insertMasterPassword'));
             echo Design::erstelleBlock($console, '', $text);
         }
         echo "<hr />";
     }
     #region Sprachwahl
     if (!$console && !$simple) {
         echo "<input type='hidden' name='data[PL][language]' value='{$data['PL']['language']}'>";
         echo "<div align='center'>" . Design::erstelleSubmitButtonGrafisch('actionSelectGerman', './images/de.gif', 32, 22) . Design::erstelleSubmitButtonGrafisch('actionSelectEnglish', './images/en.gif', 32, 22) . "</div>";
     }
     #endregion Sprachwahl
     if (Einstellungen::$accessAllowed) {
         // show segments
         foreach (Einstellungen::$segments as $segs) {
             if (isset($segs::$enabledShow) && !$segs::$enabledShow) {
                 continue;
             }
             if (!isset($segs::$page) || $segs::$page === $selected_menu || isset($segs::$installed) && $segs::$installed) {
                 if (!is_callable("{$segs}::show")) {
                     continue;
                 }
                 $result = isset($segmentResults[$segs::$name]) ? $segmentResults[$segs::$name] : array();
                 $segs::show($console, $result, $data);
             }
         }
         if ($simple) {
             if ($installFail) {
                 echo "0";
             } else {
                 echo "1";
             }
         }
         if (!$console && !$simple) {
             if (($selected_menu === 2 || $selected_menu === 3 || $selected_menu === 4) && false) {
                 echo "<table border='0' cellpadding='3' width='600'>";
                 echo "<tr><td class='h'><div align='center'><input type='submit' name='actionInstall' value=' " . Language::Get('main', 'installAll') . " '></div></td></tr>";
                 echo "</table><br />";
             }
             #region zurück_weiter_buttons
             $a = '';
             $b = '';
             if (array_search($selected_menu, self::$menuItems) > 0) {
                 $item = self::$menuItems[array_search($selected_menu, self::$menuItems) - 1];
                 $a = Design::erstelleSubmitButtonFlach('selected_menu', $item, Language::Get('main', 'back')) . '<br><font size=1>(' . Language::Get('main', 'title' . $item) . ')</font>';
             }
             if ($selected_menu >= 0 && array_search($selected_menu, self::$menuItems) < count(self::$menuItems) - 1) {
                 $item = self::$menuItems[array_search($selected_menu, self::$menuItems) + 1];
                 $b = Design::erstelleSubmitButtonFlach('selected_menu', $item, Language::Get('main', 'next')) . '<br><font size=1>(' . Language::Get('main', 'title' . $item) . ')</font>';
             }
             echo "<table border='0' cellpadding='3' width='600'>";
             echo "<thead><tr><th align='left' width='50%'>{$a}</th><th align='right' width='50%'>{$b}</th></tr></thead>";
             if ($selected_menu == 0) {
                 if (!isset($_POST['actionShowPhpInfo'])) {
                     echo "<tr><th colspan='2'>" . Design::erstelleSubmitButton("actionShowPhpInfo", 'PHPInfo') . "</th></tr>";
                 }
             }
             echo "</table>";
             #endregion zurück_weiter_buttons
             echo "<div>";
             echo "</div>";
             echo "</th>";
             echo "<th width='2'></th>";
             echo "<th valign='top'>";
             // ab hier wird die Infoleiste mit der aktuellen Konfiguration erstellt
             // (die Leiste rechts am Rand)
             echo "<div style='width:150px;word-break: break-all;'>";
             echo "<table border='0'>";
             foreach (Einstellungen::$segments as $segs) {
                 if (!is_callable("{$segs}::getSettingsBar")) {
                     continue;
                 }
                 $settings = $segs::getSettingsBar($data);
                 if (count($settings) > 0) {
                     foreach ($settings as $key => $values) {
                         if (!isset($values[0]) || !isset($values[1])) {
                             continue;
                         }
                         echo "<tr><td class='e'>" . $values[0] . "</td></tr>";
                         echo "<tr><td>" . $values[1] . "</td></tr>";
                         echo "<tr><th></th></tr>";
                     }
                 }
             }
             echo "</table>";
             echo "</div";
             echo "</th></tr></form></table>";
             echo "</div></body></html>";
         }
         if (isset($_POST['actionShowPhpInfo'])) {
             ob_start();
             phpinfo();
             $phpinfo = array('phpinfo' => array());
             if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     if (strlen($match[1])) {
                         $phpinfo[$match[1]] = array();
                     } elseif (isset($match[3])) {
                         $arr = array_keys($phpinfo);
                         $phpinfo[end($arr)][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
                     } else {
                         $arr = array_keys($phpinfo);
                         $phpinfo[end($arr)][] = $match[2];
                     }
                 }
             }
             echo "<br><br><br><br><div align='center'>";
             foreach ($phpinfo as $name => $section) {
                 echo "<h3>{$name}</h3>\n<table>\n";
                 foreach ($section as $key => $val) {
                     if (is_array($val)) {
                         echo "<tr><td>{$key}</td><td>{$val['0']}</td><td>{$val['1']}</td></tr>\n";
                     } elseif (is_string($key)) {
                         echo "<tr><td>{$key}</td><td>{$val}</td></tr>\n";
                     } else {
                         echo "<tr><td>{$val}</td></tr>\n";
                     }
                 }
                 echo "</table>\n";
             }
             echo "</div>";
         }
     }
     if ($console && !$simple) {
         echo json_encode($output);
     }
     if (!$console && !$simple) {
         Einstellungen::speichereEinstellungen($server, $data);
     }
 }