* * * This software is protected by copyright, please * read the file COPYRIGHT. * 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. Please * read the file LICENCE. * * Ce fichier contient la gestion de l'installation qware * * @author Comendatore * @copyright Copyright © 2009-2018, Rooty * @since 2007/01/07 * @version 0.3 * @link www.rooty.me * @package install */ /** * Fonction de gestion des étapes d'installation * * @author Initiance */ function stepprocess($step,$etat) { global $message, $on, $off, $stepimg; switch($etat) { case 0 : $img =$stepimg; break; case 1 : $img = $on; break; case 2 : $img = $off; break; } if($etat==1) { $chaine = "
  • ".$message->getMessage("Step".$step)."
  • "; } else { if(!isset($_GET["step"])) { $_GET["step"]=0; } if($_GET["step"] == $step) { $chaine = "
  • ".$message->getMessage("Step".$step)."
  • "; } else { $chaine = "
  • ".$message->getMessage("Step".$step)."
  • "; } } return $chaine; } /** * Parse les modules PHP depuis phpinfo() * *

    Retourne le tableau des modules Php

    * * @return tableau tableau des modules Php */ function getPhpModules() { ob_start(); phpinfo(INFO_MODULES); $s = ob_get_contents(); ob_end_clean(); $s = strip_tags($s,'

    '); $s = preg_replace('/]*>([^<]+)<\/th>/',"\\1",$s); $s = preg_replace('/]*>([^<]+)<\/td>/',"\\1",$s); $vTmp = preg_split('/(

    [^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE); $arrayModules = array(); for ($i=1;$i([^<]+)<\/h2>/',$vTmp[$i],$vMat)) { $vName = trim($vMat[1]); $vTmp2 = explode("\n",$vTmp[$i+1]); foreach ($vTmp2 AS $vOne) { $vPat = '([^<]+)<\/info>'; $vPat3 = "/$vPat\s*$vPat\s*$vPat/"; $vPat2 = "/$vPat\s*$vPat/"; if (preg_match($vPat3,$vOne,$vMat)) { // 3 colonnes $arrayModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3])); } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2 colonnes $arrayModules[$vName][trim($vMat[1])] = trim($vMat[2]); } } } } return $arrayModules; } /** * Obtenir le paramètre d'un module * *

    Retourne la valeur du paramètre du module Php demandé

    * * @param chaîne module php * @param chaîne paramètre du module * @return string valeur du paramètre du module php */ function getModuleSetting($modulename,$setting) { $arrayModules = getPhpModules(); if( @$arrayModules[$modulename][$setting] ) return $arrayModules[$modulename][$setting]; else return false; } /** * Définit la version du backend BD à utiliser * *

    Retourne la version du backend BD

    * * @param string Backend BD * @return string Version du backend BD * *
    Trois backends sont actuellement imlémentés : * mysql * pgsql * odbc *
    * @TODO Implémentation des scripts d'installations des backends */ function setVersionDbConnector($dbserver) { switch($dbserver) { case "mysql": $backendString = "Client API version"; break; case "pgsql" : $backendString = "PostgreSQL(libpq) Version"; break; case "odbc" : $backendString = ""; break; } $mysqlclientversion = getModuleSetting($dbserver,$backendString); $mysqlConnector = explode(".", $mysqlclientversion); $mysqlConnector = $mysqlConnector[0]; return $mysqlConnector; } /** * Fonction permettant de remplacer une chaîne de caractères par une * autre dans le fichier cible passé en paramètre. * *

    Retourne true/false

    * * @param array En clé, l'ancienne valeur et en valeur, la valeur a remplacer * @param string chemin absolu du fichier * @return booléen true/false * @TODO Implémenter 2 tableaux à la place des variables */ function updateStringInFile($arrayValue, $filein, $fileout) { $buffer = @fread(@fopen($filein, 'r'), @filesize($filein)); foreach($arrayValue as $oValue=>$nValue){ $buffer = str_replace($oValue, $nValue, $buffer); } if (($fp = @fopen($fileout, "w")) !== false) { if (@fwrite($fp, $buffer) !== false) { $res = true; } else { $res = false; } fclose($fp); } else { $res = false; } return $res; } /** * Créé une chaîne "aléatoire" * *

    Retourne une chaîne aléatoire

    * * @return string chaîne aléatoire */ function makeMcryptKey($lenght) { $i=0;$mcryptKey=null; while($i<$lenght) { $mcryptKey.=chr((rand()%26)+97); $i++; } $mcryptKey=$mcryptKey.substr(uniqid (""),0,22); return $mcryptKey; } /** * Fonction d'affichage de l'aide * * @author Initiance */ function aide($form,$nameField) { global $message, $help; return "\"".$message-getMessage("".$nameField."")."\"/>".$message->getMessage("H".$nameField).""; } /** * */ function datasource($POST="") { global $message, $etat, $CONF_LIB_PATH, $help; if($POST=="") { $chaine = "
    ".aide("myform","NameServeur")."
    ".aide("myform","PortServeur")."
    ".aide("myform","LoginServeur")."
    ".aide("myform","PwdServeur")."
    ".aide("myform","BdServeur")."
    ".aide("myform","PrefxBdServeur")."
    getMessage("Next")."\" class=\"button\"/>
    "; $etat = 0; return $chaine; } else { $chaine = ""; if($_POST) { foreach($_POST as $cle=>$val) { if($val=="" && ($cle !="PwdServeur" && $cle !="NameServeur" && $cle !="PortServeur" && $cle !="PrefxBdServeur" && $cle !="helpdesc")) { $chaine .= $message->getMessage($cle).", "; } } if($chaine!="") { $chaine .= $message->getMessage('obligatory'); } } //Si certains champs sont manquants pour l'inscription if ($chaine != "") { return datasource()."

    ".$chaine."

    "; } else { $dbhost = (!empty($_POST['NameServeur'])) ? $_POST['NameServeur'] : 'localhost'; $dbuser = (!empty($_POST['LoginServeur'])) ? $_POST['LoginServeur']: ""; $dbport = (!empty($_POST['PortServeur'])) ? $_POST['PortServeur']: 3306; $dbpasswd = (!empty($_POST['PwdServeur'])) ? $_POST['PwdServeur'] : ""; $dbname = (!empty($_POST['BdServeur'])) ? $_POST['BdServeur']: ""; $dbnameprefx = (!empty($_POST['PrefxBdServeur'])) ? $_POST['PrefxBdServeur']: ""; try { $bd_connect = new PDO("mysql:host=$dbhost;port=$dbport", "$dbuser", "$dbpasswd"); // PDO Connection } catch (PDOException $e) { // $e->getCode = 1045 = Access denied // $e->getCode = 1049 = Unknown database if( $e->getCode() == '1045' ) return datasource()."

    ".$message->getMessage("NoMysqlConnexion")."

    "; } $dbselect = true; try { $bd_connect = new PDO("mysql:host=$dbhost;port=$dbport;dbname=$dbname;charset=utf8", "$dbuser", "$dbpasswd"); // PDO Connection } catch (PDOException $e) { // $e->getCode = 1049 = Unknown database if( $e->getCode() == '1049' ) $dbselect = false; } if(!$dbselect) { include_once($CONF_LIB_PATH."lib/system/system_data_source/database/sql_parse.php"); $mysqlversion = explode(" ", getModuleSetting('pdo_mysql','Client API version')); $mysqlversion = explode(".",$mysqlversion[1]); $mysqlversion = $mysqlversion[0]; $sql_query = @fread(@fopen("./db_scripts/mysql/".$mysqlversion."_create_database.sql", 'r'), @filesize("./db_scripts/mysql/".$mysqlversion."_create_database.sql")); $sql_query = preg_replace('/{_DATABASE_}/', "`".$dbname."`", $sql_query); $sql_query = remove_remarks($sql_query); $result = $bd_connect->exec($sql_query); if ( !($dbselect = $bd_connect->exec("USE $dbname;")) ) { $sql_query = @fread(@fopen("./db_scripts/mysql/".$mysqlversion."_create_structure.sql", 'r'), @filesize("./db_scripts/mysql/".$mysqlversion."_create_structure.sql")); if($dbnameprefx != "") { $dbnameprefx = $dbnameprefx."_"; } else { $dbnameprefx = "sys_"; } $sql_query = preg_replace('/{_DATABASE_}/', $dbname, $sql_query); $sql_query = preg_replace('/{_PREFIX_}/', $dbnameprefx, $sql_query); $sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ";"); for ($i = 0; $i < sizeof($sql_query); $i++) { if ($result = $bd_connect->exec($sql_query[$i])) { return datasource()."

    ".$message->getMessage('BdStructureError')."

    "; exit; } } $sql_query = ""; $sql_query = @fread(@fopen("./db_scripts/mysql/".$mysqlversion."_insert_datas.sql", 'r'), @filesize("./db_scripts/mysql/".$mysqlversion."_insert_datas.sql")); $sql_query = preg_replace('/{_DATABASE_}/', $dbname, $sql_query); $sql_query = preg_replace('/{_PREFIX_}/', $dbnameprefx, $sql_query); $sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ";"); for ($i = 0; $i < sizeof($sql_query); $i++) { if (trim($sql_query[$i]) != '') { ##################################### ### Ajout du remplacement des paths images!!! $sql_query[$i]=make_path($sql_query[$i]); ##################################### $result = $bd_connect->exec($sql_query[$i]); if( !$result ) { return datasource()."

    ".$message->getMessage('BdDatasError')."

    "; exit; } } } } else { return datasource()."

    ".$message->getMessage('BdStructureError')."2

    "; exit; } } else { include_once($CONF_LIB_PATH."lib/system/system_data_source/database/sql_parse.php"); $mysqlversion = explode(" ", getModuleSetting('pdo_mysql','Client API version')); $mysqlversion = explode(".",$mysqlversion[1]); $mysqlversion = $mysqlversion[0]; $sql_query = @fread(@fopen("db_scripts/mysql/".$mysqlversion."_create_structure.sql", 'r'), @filesize("./db_scripts/mysql/".$mysqlversion."_create_structure.sql")); if($dbnameprefx != "") { $dbnameprefx = $dbnameprefx."_"; } else { $dbnameprefx = "sys_"; } $sql_query = preg_replace('/{_DATABASE_}/', $dbname, $sql_query); $sql_query = preg_replace('/{_PREFIX_}/', $dbnameprefx, $sql_query); $sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ";"); for ($i = 0; $i < sizeof($sql_query); $i++) { if ($result = $bd_connect->exec($sql_query[$i])) { return datasource()."

    ".$message->getMessage('BdStructureError')."

    "; exit; } } $sql_query = ""; $sql_query = @fread(@fopen("./db_scripts/mysql/".$mysqlversion."_insert_datas.sql", 'r'), @filesize("./db_scripts/mysql/".$mysqlversion."_insert_datas.sql")); $sql_query = preg_replace('/{_DATABASE_}/', $dbname, $sql_query); $sql_query = preg_replace('/{_PREFIX_}/', $dbnameprefx, $sql_query); $sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ";"); for ($i = 0; $i < sizeof($sql_query); $i++) { if (trim($sql_query[$i]) != '') { ##################################### ### Ajout du remplacement des paths images!!! $sql_query[$i]=make_path($sql_query[$i]); ##################################### $result = $bd_connect->exec($sql_query[$i]); if( !$result ) { return datasource()."

    ".$message->getMessage('BdDatasError')."

    "; exit; } } } } // On met à jour le fichier config.data_source.php if ( updateStringInFile(array( "{_DBCONNECTOR_}"=>"mysql", "{_DBHOST_}"=>$dbhost, "{_DBPORT_}"=>$dbport, "{_DBUSER_}"=>$dbuser, "{_DBPASSWD_}"=>$dbpasswd, "{_DBNAME_}"=>$dbname, ), $CONF_LIB_PATH.'config/config.data_source.php.install', $CONF_LIB_PATH.'config/config.data_source.php') == false) { redirect("index.php?step=1"); } // On met à jour le fichier config.data_acces.php if ( updateStringInFile(array( "{_PREFIX_}"=>$dbnameprefx ), $CONF_LIB_PATH.'config/config.data_acces.php.install', $CONF_LIB_PATH.'config/config.data_acces.php') !== false) { redirect("index.php?step=2"); } else { redirect("index.php?step=1"); } } } } /** * * * @author Comendatore */ function adapt($POST="") { global $message, $etat, $CONF_LIB_PATH, $help; if($POST=="") { $chaine = "
    ".aide("myform","McryptKey")."
    ".aide("myform","ConfPlatformName")."
    ".aide("myform","ConfPlatformTmplDefault")."
    ".aide("myform","ConfPlatformDescDefault")."
    getMessage("Next")."\" class=\"button\"/>
    "; $etat = 0; return $chaine; } else { $chaine = ""; if($_POST) { foreach($_POST as $cle=>$val) { if($val=="" && ($cle !="McryptKey" && $cle !="ConfPlatformName" && $cle !="ConfPlatformTmplDefault" && $cle !="ConfPlatformDescDefault")) { $chaine .= $message->getMessage($cle).", "; } } if($chaine!="") { $chaine .= $message->getMessage('obligatory'); } } //Si certains champs sont manquants pour l'inscription if ($chaine != "") { return adapt()."

    ".$chaine."

    "; } else { // On met à jour le fichier config.system.php pour {_CONF_SYSTEM_KEY_}, {_CONF_DEFAULT_TEMPLATE_}, {_CONF_DEFAULT_TITLE_}, {_CONF_DEFAULT_DESC_} if( updateStringInFile(array( "{_CONF_SYSTEM_KEY_}"=>$_POST['McryptKey'], "{_CONF_DEFAULT_TEMPLATE_}"=>$_POST['ConfPlatformTmplDefault'], "{_CONF_DEFAULT_NAME_}"=>$_POST['ConfPlatformName'], "{_CONF_DEFAULT_DESC_}"=>$_POST['ConfPlatformDescDefault'] ), $CONF_LIB_PATH.'config/config.system.php.install', $CONF_LIB_PATH.'config/config.system.php') == false) { redirect("index.php?step=2"); } // On met à jour le fichier config.php pour {_CONF_PLATFORM_NAME_}, if ( updateStringInFile(array( "{_CONF_PLATFORM_NAME_}"=>$_POST['ConfPlatformName'] ), $CONF_LIB_PATH.'config/config.php.install', $CONF_LIB_PATH.'config/config.php') !== false) { redirect("index.php?step=3"); } else { redirect("index.php?step=2"); } } } } /** * */ function admin($POST="") { global $message, $etat, $CONF_LIB_PATH; if($POST=="") { $chaine = "
    ".$message->getMessage("Title")." (*) ".$message->getMessage("mr")." ".$message->getMessage("mrs")." ".$message->getMessage("miss")."

    (*) : ".$message->getMessage("obligatory")."
    getMessage("Next")."\" class=\"button\"/>
    "; $etat = 0; return $chaine; } else { $chaine = ""; if($_POST) { foreach($_POST as $cle=>$val) { if($val=="" && ($cle !="FirstName" && $cle !="LastName" && $cle !="Mail" && $cle !="Login" && $cle !="Password" && $cle !="Password2")) { $chaine .= $message->getMessage($cle).", "; } } if($chaine!="") { $chaine .= $message->getMessage('obligatory'); } } //Si certains champs sont manquants pour l'inscription if ($chaine != "") { return admin()."

    ".$chaine."

    "; } else { if($_POST["Password"]!=$_POST["Password2"]) { return admin()."

    ".$message->getMessage('Passworderror')."

    "; } include($CONF_LIB_PATH.'lib/system/system_control/systemcontrol.php'); /* Création des ressources */ $var=SystemControl::includeFiles($CONF_LIB_PATH."config/", "config"); $GLOBALS["CONF_LIB_PATH"]="../"; $var=SystemControl::MakeSystemConn(); /* Création du Manager Utilisateur */ $GLOBALS["SYSTEM_MANAGER"]["USER"]=UserManagerFactory::createInstance( DATA_ACCES_MANAGER_USER ); /* Création du Manager Utilisateur */ $User=new User(); $User->setId($GLOBALS['SYSTEM_DEFAULT_USER_ADMIN']); $User->setPassword($_POST['Password']); $User->setTitle($_POST['Title']); $User->setFirstName($_POST['FirstName']); $User->setLastName($_POST['LastName']); $User->setLogin($_POST['Login']); $User->setMail($_POST['Mail']); $User->SetAccountActive(1); $User=$GLOBALS["SYSTEM_MANAGER"]["USER"]->updateInstance($User); // Création du répertoire de stockage des packages disponible sur la plateforme // Nécessaire pour l'outil installmanager. if( !file_exists($GLOBALS["CONF_LIB_PATH"]."data/upload/install/packagesrc") ) createDirectory($GLOBALS["CONF_LIB_PATH"]."data/upload/install/packagesrc", 700); // Création du répertoire de stockage des packages disponible sur la plateforme // Nécessaire pour l'outil installmanager. if( !file_exists($GLOBALS["CONF_LIB_PATH"]."data/template/cache") ) createDirectory($GLOBALS["CONF_LIB_PATH"]."data/template/cache", 700); if ( updateStringInFile(array( "{_CONF_ADMIN_MAIL_}"=>$_POST['Mail']), $CONF_LIB_PATH.'config/config.php', $CONF_LIB_PATH.'config/config.php') == false) { redirect("index.php?step=3"); } if ( updateStringInFile(array( "{_CONF_ADMIN_MAIL_}"=>$_POST['Mail']), $CONF_LIB_PATH.'config/config.mxconf.php.install', $CONF_LIB_PATH.'config/config.mxconf.php') == false) { redirect("index.php?step=3"); } if ( updateStringInFile(array( "{_CONF_SECURE_ALL_}"=>"true"), $CONF_LIB_PATH.'config/config.navigation.php.install', $CONF_LIB_PATH.'config/config.navigation.php') == false) { redirect("index.php?step=3"); } if ( updateStringInFile(array( "{_QWAREINSTALLED_}"=>"true"), $CONF_LIB_PATH.'config/installcontrol.php.install', $CONF_LIB_PATH.'config/installcontrol.php') !== false) { redirect("index.php?step=4"); } } } } /** * Création d'un répertoire * Gére un path absolu * @access public * @param chemin chemin absolu ou relatif * @param entier droit à attribuer à la création d'un répertoire * @return tableau tableau associatif des états de création des reps */ function createDirectory($chemin, $chmod) { if ( !is_dir($chemin) ) { return mkdir($pathTmp,$chmod, true); } else { $return = true; } return $return; } /** * Vérifie le droit en écriture sur le répertoire cible * *

    Retourne true/false

    * * @author Comendatore * * @param chaîne chemin absolu du répertoire * @return booléen true/false */ function checkRepWritable($chemin) { if (!is_writable($chemin)) { return false; } else { return true; } } /** * Créé un fichier s'il n'existe pas * *

    Retourne true/false

    * * @author Comendatore * * @param chaîne chemin absolu du répertoire (sans le / de fin) * @param chaîne nom du fichier à créer * @return booléen true/false */ function createFileIfNotExists($chemin,$file) { if (checkRepWritable($chemin) == true) { if ((@fopen($chemin."/",$file,"w")) == true) { return true; } else { return false; } } } /** * Vérifie le droit en écriture sur le fichier cible * *

    Retourne true/false

    * * @author Comendatore * * @param chaîne chemin absolu du fichier * @return booléen true/false */ function checkFileWritable($chemin) { if (!is_writable($chemin)) { return false; } else { return true; } } ?>