class_Install.inc.php 13 KB
<?php
/**
 * @file	Install.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   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 <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * 	class Install
 *
 */
class Install {

	private $install_text = array('check', 'install', 'check');
	private $var_false = FALSE;

	public function __construct($param_DB) {
		?>
		<html>
			<head>
				<link rel="stylesheet" type="text/css"
					  href="include/Forest/netz.coop/Design/old/css/default_install.css" title="" />
			</head>
			<body>
				<span class="Title">LOSP Installation</span>


				<!--	Menu  -->
				<span class="Menu"> <span class="Button"><a href="install.php">Menu</a></span>
					<?php
					for ($i = 0; $i < count($this->install_text); $i++) {
						?> <span class="Button"><a
								href="install.php?step=<?php echo $this->install_text[$i] ?>"><?php echo $i ?>. <?php echo $this->install_text[$i];?></a></span>
							<?php
						}
						?> </span>



				<!--	Screen  -->
				<span class="Screen"> <?php
// 		Check the System
					if ($_GET["step"] == $this->install_text[0]) {
						?> <span class="Box"> <span class="Title">Server System: (Allgemein)</span>

							<!--	MySQL  --> <span class="row"> <span class="var">MySQL</span> <?php
								if (extension_loaded("MySQL")) {
									echo "<span class=\"value\">OK</span>";
								} else {
									$this->var_false = TRUE;
									echo "<span class=\"value\">MySQL Modul ist nicht geladen, Installation nicht m&ouml;glich</span>";
								}
								?> </span> <!-- 	PHP --> <span class="row"> <span class="var">PHP</span>
								<?php
								$version = explode('.', phpversion());
								if (((int) $version[0]) >= 5) {
									echo "<span class=\"value\">OK Version ist aussreichend (" . phpversion() . ">5)</span>";
								} else {
									$this->var_false = TRUE;
									echo "<span class=\"value\"><b>eine zu alte PHP Version (" . phpversion() . "<5)</b></span>";
								}
								?> </span> <!--  	XSL	--> <span class="row"> <span class="var">XSL</span>
									<?php
									if (extension_loaded("XSL")) {
										echo "<span class=\"value\">OK</span>";
									} else {
										$this->var_false = TRUE;
										echo "<span class=\"value\">XSL Modul ist nicht geladen, Installation nicht m&ouml;glich</span>";
									}
									?> </span> </span> <?php
									if (!$this->var_false) {
										?> <span class="Box"> <span class="Title">Datenbank Benutzer Daten:</span>

								<br>
								<p class=install>Bitte die Datei config/config.php mit den
									Datenbankdaten f&uuml;llen</p>
								<p class=install>Folgende Daten werden beim n&auml;chsten Schritt
									verwendet</p>

								<span class="row"><span class="var">MySQL:</span></span> <span
									class="row"><span class="var">Server:</span> <span class="value">"<?php echo $param_DB["config_dbserver"] ?>"</span></span>
								<span class="row"><span class="var">Benutzer:</span><span class="value">"<?php echo $param_DB["config_user"] ?>"</span></span>
								<span class="row"><span class="var">Passwort:</span><span class="value">"***"</span></span>
								<span class="row"><span class="var">Datenbank:</span><span class="value">"<?php echo $param_DB["config_db"] ?>"</span></span>
							</span> <?php
				$link = mysql_connect($param_DB["config_dbserver"], $param_DB["config_user"], $param_DB["config_passwd"]);
				if ($link) {
					?> <span class="Box"> <span class="Title">MySQL Datenbank</span> <span
										class="row"><span class="var">Version:</span> <span class="value"><?php echo mysql_get_server_info() ?></span></span>
									<span class="row"><span class="var">Host:</span> <span class="value"><?php echo mysql_get_host_info() ?></span></span>
									<span class="row"><span class="var">Client:</span> <span class="value"><?php echo mysql_get_client_info() ?></span></span>
								</span> <span class="Box"> <span class="Title">spezielle Datenbank
										Rechte</span> <?php
										$query = "SELECT * FROM information_schema.`USER_PRIVILEGES` where GRANTEE=\"'" . $param_DB["config_user"] . "'@'" . $param_DB["config_dbserver"] . "'\" and  PRIVILEGE_TYPE='ALTER ROUTINE';";
										$this->resource = mysql_db_query($param_DB["config_db"], $query);
										$row = mysql_fetch_array($this->resource);
										?> <span class="row"> <span class="value">(Alter Routine: <?php
										if ($row["PRIVILEGE_TYPE"] != "ALTER ROUTINE") {
											$var_false = TRUE;
											echo "Fehler";
										} else {
											echo "OK";
										}
										?> )</span> </span> <?php
									$query = "SELECT * FROM information_schema.`USER_PRIVILEGES` where GRANTEE=\"'" . $param_DB["config_user"] . "'@'" . $param_DB["config_dbserver"] . "'\" and  PRIVILEGE_TYPE='CREATE ROUTINE';";
//				echo "<li>".$query."</li>";
									$this->resource = mysql_db_query($param_DB["config_db"], $query);
									$row = mysql_fetch_array($this->resource);
									?> <span class="row"> <span class="value">Create Routine: <?php
											if ($row["PRIVILEGE_TYPE"] != "CREATE ROUTINE") {
												$var_false = TRUE;
												echo "Fehler";
											} else {
												echo "OK";
											}
											?> </span> </span> <?php
									if ($row["PRIVILEGE_TYPE"] == "CREATE ROUTINE") {
										?> <span class="row"> <span class="var">Test: Erstelle Test Funktion:</span>
											<span class="value"> <?php
												$sql_fnc = "DROP FUNCTION IF EXISTS testing";
												$this->resource = mysql_db_query($param_DB["config_db"], $sql_fnc);

												$sql_fnc = "CREATE FUNCTION testing(param_test int)
							RETURNS INT
							DETERMINISTIC
							BEGIN
								return param_test;
							END";

												$this->resource = mysql_db_query($param_DB["config_db"], $sql_fnc);

												if (!mysql_error()) {
													echo "OK ";
													echo mysql_error();
													?> </span> <?php
											} else {
												echo "Fehler: ";
												echo mysql_error();
												?> </span> <?php
												if (strripos(mysql_error(), "log_bin_trust_function_creators")) {

													$query = "show variables like 'log_bin_trust_function_creators'";
													$this->resource = mysql_db_query($param_DB["config_db"], $query);
													$row = mysql_fetch_array($this->resource);

													if ($row["Value"] == "ON") {
														echo "log_bin_trust_function_creators: = " . $row["Value"] . "<br>";
													} else {
														$var_false = TRUE;
														?> <span class="row"> <span class="value">log_bin_trust_function_creators:
															= <?php echo $row["Value"] ?></span> </span> <span class="row"> <span
															class="value">in der Datenbank k&ouml;nnen keine Funktionen angelegt
															werden</span> </span> <span class="row"> <span class="value">Sie
															m&uuml;ssen die globale Systemvariable log_bin_trust_function_creators
															auf 1 setzen.<br>
															[mysql> SET GLOBAL log_bin_trust_function_creators = 1;]</span> </span>
													<?php
												}
											}
										}
										?> <span class="row"> <span class="var">Test: Erstelle Test Prozedur:</span>
											<span class="value"> <?php
// $link = mysql_connect($param_DB["config_dbserver"], $param_DB["config_user"], $param_DB["config_passwd"]);
						$sql_fnc = "DROP PROCEDURE IF EXISTS testing";
						$this->resource = mysql_db_query($param_DB["config_db"], $sql_fnc);

						$sql_fnc = "CREATE PROCEDURE testing(IN param_test int) DETERMINISTIC BEGIN END";

						$this->resource = mysql_db_query($param_DB["config_db"], $sql_fnc);

						if (!mysql_error()) {
							echo "OK ";
							echo mysql_error();
						} else {
							echo "Fehler: ";
							echo mysql_error();
						}
										?> </span> </span> <?php
											} else {
												$var_false = TRUE;
												?> <span class="row"> <span class="var">Erstelle Test
												Funktion/Procedure:</span> <span class="value">No</span> </span> <span
											class="row"> <span class="var">PRIVILEGE_TYPE:</span> <span
												class="value">No</span> </span> <span class="row"><span class="value">
												<b>in der Datenbank k&ouml;nnen keine Funktionen angelegt werden
													(fehlende Rechte)</b> </span></span> <span class="row"> <span
												class="var">externe Dokumentation:</span> <span class="value"><a
													href="http://dev.mysql.com/doc/refman/5.1/de/create-procedure.html">MySQL
													5.1 Referenzhandbuch 19.2.1. CREATE PROCEDURE und CREATE FUNCTION</a></span>
										</span> <span class="row"> <span class="var">Anleitung:</span> <span
												class="value">Als priviligierter MySQL Administrator folgende Rechte
												dem Nutzer und der Datenbank zur Verf&uuml;gung stellen</span> </span> <span
													class="row"><span class="value"> <!-- mysql> <i>UPDATE mysql.`db` SET `Create_routine_priv` = 'Y',  `Alter_routine_priv` = 'Y' WHERE CONVERT( `Db` USING utf8 ) = '<?php echo $param_DB["config_db"] ?>' AND CONVERT( `User` USING utf8 ) = '<?php echo $param_DB["config_user"] ?>';</i> -->
												<!-- mysql> <i>UPDATE `mysql`.`db` SET `Host` = 'localhost', `Select_priv` = 'Y', `Insert_priv` = 'Y', `Update_priv` = 'Y', `Delete_priv` = 'Y', `Create_priv` = 'Y', `Drop_priv` = 'Y', `Reload_priv` = 'Y', `Create_view_priv` = 'Y', `Show_view_priv` = 'Y', `Create_routine_priv` = 'Y', `Alter_routine_priv` = 'Y' WHERE CONVERT( `Db` USING utf8 ) = '<?php echo $param_DB["config_db"] ?>' AND `user`.`User`= '<?php echo $param_DB["config_user"] ?>' LIMIT 1 ;</i> -->
												mysql> <i>UPDATE `mysql`.`db` SET `Host` = 'localhost', `Select_priv` =
													'Y', `Insert_priv` = 'Y', `Update_priv` = 'Y', `Delete_priv` = 'Y',
													`Create_priv` = 'Y', `Drop_priv` = 'Y', `Create_view_priv` = 'Y',
													`Show_view_priv` = 'Y', `Create_routine_priv` = 'Y',
													`Alter_routine_priv` = 'Y' WHERE CONVERT( `Db` USING utf8 ) = '<?php echo $param_DB["config_db"] ?>'
													AND `User`= '<?php echo $param_DB["config_user"] ?>' LIMIT 1 ;</i> </span></span>

						<span class="row"><span class="value"> <!-- mysql> UPDATE mysql.user SET Create_routine_priv='Y', Alter_routine_priv='Y', ssl_cipher='', x509_issuer='',  x509_subject='' WHERE CONVERT(Host USING utf8 )='<?php echo $param_DB["config_dbserver"] ?>' AND CONVERT(User USING utf8 )='<?php echo $param_DB["config_user"] ?>' LIMIT 1; -->
												mysql> <i>UPDATE `mysql`.`user` SET `Host` = 'localhost', `Select_priv`
													= 'Y', `Insert_priv` = 'Y', `Update_priv` = 'Y', `Delete_priv` = 'Y',
													`Create_priv` = 'Y', `Drop_priv` = 'Y', `Reload_priv` = 'Y',
													`Create_view_priv` = 'Y', `Show_view_priv` = 'Y', `Create_routine_priv`
													= 'Y', `Alter_routine_priv` = 'Y' WHERE `user`.`User`= '<?php echo $param_DB["config_user"] ?>'
													LIMIT 1 ;</i> </span></span> <span class="row"><span class="value">
												mysql> <i>FLUSH PRIVILEGES ;</i> </span></span> <?php
					}
					?> </span> <span class="Box"> <span class="Title">Resultat</span> <?php
									if ($var_false) {
										?> <span class="row"> <a
												href="install.php?step=<?php echo $this->install_text[0] ?>" class=install>noch
												mal [Schritt 1]</a> </span> <?php
											} else {
												?> <span class="row"> <a
												href="install.php?step=<?php echo $this->install_text[1] ?>" class=install>weiter
												[Schritt 1]</a> (Tabellen werden erstellt) </span> <?php
									}
									?> </span> <?php
					} else {
						echo "<b>Ueberpr&uuml;fen sie die Daten f&uuml;r die Datenbankverbindung config/config.php</b><br>";
						echo "<a href=\"?install=2\" class=install>zur&uuml;ck [Schritt 2]</a><br>";
						echo('Keine Verbindung m&ouml;glich: ' . mysql_error());
									?> <span class="Box"> <span class="row"> <b>evt. soll vielleicht auch
											alles erst angelegt werden</b> </span> <span class="row"> rechner:/$ <i>mysql
											-u root --password='Passwort'</i> </span> <span class="row"> mysql> <i>create
											database lospdb;</i> </span> <span class="row"> mysql> <i>GRANT ALL
											PRIVILEGES ON lospdb.* TO lospuser IDENTIFIED BY 'losppassword';</i> </span>
								</span> <?php
				}
			}
		} else if ($_GET["step"] == $this->install_text[1]) {
			$DB = StorableFactory::create("MySql", $param_DB);
			echo $DB->transformFileToDatabase("include/System/sql/MySql_Tables.sql");
			echo $DB->transformFileToDatabase("include/System/sql/MySql_Function.sql");
		} else {
			
		}
						?> </span>
			</body>
		</html>
					<?php
				}

			}