mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-20 08:21:29 +01:00
439 lines
14 KiB
PHP
439 lines
14 KiB
PHP
<?php
|
|
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
|
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
|
*
|
|
* 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 2 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, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
* $Id$
|
|
* $Source$
|
|
*
|
|
*/
|
|
|
|
/**
|
|
\file htdocs/install/etape1.php
|
|
\brief Génère le fichier conf.php avec les informations issues de l'étape précédente
|
|
\version $Revision$
|
|
*/
|
|
|
|
include_once("./inc.php");
|
|
|
|
$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:$langcode);
|
|
$langs->defaultlang=$setuplang;
|
|
$langs->load("admin");
|
|
$langs->load("install");
|
|
|
|
pHeader($langs->trans("ConfigurationFile"),"etape2");
|
|
|
|
$etape = 1;
|
|
|
|
// Répertoire des pages dolibarr
|
|
$main_dir=isset($_POST["main_dir"])?$_POST["main_dir"]:'';
|
|
|
|
// Répertoire des documents générés (factures, etc...)
|
|
$main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:'';
|
|
|
|
// En attendant que le main_data_dir soit géré de manière autonome,
|
|
// on le force à sa valeur fixe des anciennes versions.
|
|
// Eric Seigne 2004
|
|
$main_data_dir=ereg_replace("htdocs","documents",$main_dir);
|
|
|
|
// Quand ça sera géré !
|
|
if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; }
|
|
|
|
if ($_POST["action"] == "set")
|
|
{
|
|
umask(0);
|
|
print '<h2>'.$langs->trans("SaveConfigurationFile").'</h2>';
|
|
|
|
print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
|
|
$error=0;
|
|
$fp = fopen("$conffile", "w");
|
|
|
|
if($fp)
|
|
{
|
|
if (substr($main_dir, strlen($main_dir) -1) == "/")
|
|
{
|
|
$main_dir = substr($main_dir, 0, strlen($main_dir)-1);
|
|
}
|
|
|
|
if (substr($_POST["main_url"], strlen($_POST["main_url"]) -1) == "/")
|
|
{
|
|
$_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1);
|
|
}
|
|
|
|
clearstatcache();
|
|
|
|
fwrite($fp, '<?php');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_url_root="'.$_POST["main_url"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_document_root="'.$main_dir.'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_data_root="'.$main_data_dir.'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_db_host="'.$_POST["db_host"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_db_name="'.$_POST["db_name"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_db_user="'.$_POST["db_user"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_db_pass="'.$_POST["db_pass"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '$dolibarr_main_db_type="'.$_POST["db_type"].'";');
|
|
fputs($fp,"\n");
|
|
|
|
fputs($fp, '?>');
|
|
fclose($fp);
|
|
|
|
if (file_exists("$conffile"))
|
|
{
|
|
include ("$conffile");
|
|
print "<tr><td>".$langs->trans("ConfigurationSaving")."</td><td>".$langs->trans("OK")."</td>";
|
|
$error = 0;
|
|
}
|
|
else
|
|
{
|
|
$error = 1;
|
|
}
|
|
}
|
|
|
|
if($dolibarr_main_db_type == "mysql")
|
|
{
|
|
include_once("../lib/mysql.lib.php");
|
|
$choix=1;
|
|
}
|
|
else
|
|
{
|
|
include_once("../lib/pgsql.lib.php");
|
|
$choix=2;
|
|
}
|
|
|
|
|
|
/***************************************************************************
|
|
*
|
|
* Creation des répertoires
|
|
*
|
|
***************************************************************************/
|
|
|
|
if ($error == 0)
|
|
{
|
|
|
|
// Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés en passant outre l'authentification
|
|
$dir[0] = "$main_data_dir/facture";
|
|
$dir[1] = "$main_data_dir/users";
|
|
$dir[2] = "$main_data_dir/propale";
|
|
$dir[3] = "$main_data_dir/societe";
|
|
$dir[4] = "$main_data_dir/ficheinter";
|
|
$dir[5] = "$main_data_dir/produit";
|
|
$dir[6] = "$main_data_dir/rapport";
|
|
$dir[7] = "$main_data_dir/rsscache";
|
|
$dir[8] = "$main_data_dir/logo";
|
|
|
|
|
|
if (! is_dir($main_dir))
|
|
{
|
|
print "<tr><td>";
|
|
print $langs->trans("DirDoesNotExists",$main_dir);
|
|
print "</td><td>";
|
|
print $langs->trans("Error");
|
|
print "</td></tr>";
|
|
$error++;
|
|
}
|
|
else
|
|
{
|
|
dolibarr_syslog ("Le dossier '".$main_dir."' existe");
|
|
|
|
// Répertoire des documents
|
|
if (! is_dir($main_data_dir))
|
|
{
|
|
@mkdir($main_data_dir, 0755);
|
|
}
|
|
|
|
if (! is_dir($main_data_dir))
|
|
{
|
|
print "<tr><td>Le dossier '$main_data_dir' n'existe pas ! ";
|
|
print "Vous devez créer ce dossier et permettre au serveur web d'écrire dans celui-ci";
|
|
print '</td><td bgcolor="red">Erreur</td></tr>';
|
|
$error++;
|
|
}
|
|
else
|
|
{
|
|
// Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas
|
|
for ($i = 0 ; $i < sizeof($dir) ; $i++)
|
|
{
|
|
if (is_dir($dir[$i]))
|
|
{
|
|
dolibarr_syslog ("Le dossier '".$dir[$i]."' existe");
|
|
}
|
|
else
|
|
{
|
|
if (! @mkdir($dir[$i], 0755))
|
|
{
|
|
print "<tr><td>";
|
|
print "Impossible de créer : ".$dir[$i];
|
|
print "</td><td bgcolor=\"red\">";
|
|
print $langs->trans("Error");
|
|
print "</td></tr>";
|
|
$error++;
|
|
}
|
|
else
|
|
{
|
|
dolibarr_syslog ("Le dossier '".$dir[$i]."' a ete cree");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Base de données
|
|
*
|
|
*/
|
|
|
|
if ($error == 0)
|
|
{
|
|
include_once($dolibarr_main_document_root . "/conf/conf.class.php");
|
|
|
|
// TODO
|
|
// Il y a encore des pb ds la procédure d'install qui ne passe dans pas tous les cas
|
|
// (exemple, rien n'existe et on veut créer une base avec un compte admin != root)
|
|
// L'algorithme ne semble pas adapté à tous les cas, il devrait etre remplacé par le suivant:
|
|
//
|
|
// On essaie l'accès par le user admin dolibarr
|
|
// si accès serveur ok et accès base ok, tout est ok, on ne va pas plus loin, on a même pas utilisé le compte root.
|
|
// si accès serveur ok et accès base ko, warning 1
|
|
// si accès serveur ko, warning 2
|
|
// Si warning, on essai de se connecter au serveur via le super user root
|
|
// Si connexion serveur par root ok et accès base ko, on la créée
|
|
// Si création ok, on y accède
|
|
// Si création ko, erreur
|
|
// Si connexion serveur par root ok et si accès base ok,
|
|
// si compte admin existe deja et db_create_user positionné, on ajoute les droits,
|
|
// si compte admin existe deja et db_create_user non positionné, erreur compte admin incorrect "Le compte admin indiqué existe mais n'a pas les droits sur la base. Veuillez cocher pour les ajouter"
|
|
// si compte admin n'existe pas deja et db_create_user positionné, on crée le compte
|
|
// si compte admin n'existe pas deja et db_create_user non positionné, erreur compte admin inexistant "Veuillez cocher pour le créer"
|
|
|
|
// Si creation utilisateur admin demandée, on le crée
|
|
if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
|
|
{
|
|
dolibarr_syslog ("Creation de l'utilisateur : ".$dolibarr_main_db_user);
|
|
|
|
if($choix == 1)
|
|
{ //choix 1=mysql
|
|
|
|
$conf = new Conf();
|
|
$conf->db->host = $dolibarr_main_db_host;
|
|
$conf->db->name = $dolibarr_main_db_name;
|
|
$conf->db->name = $dolibarr_main_db_type;
|
|
$conf->db->user = isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
|
|
$conf->db->pass = isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
|
|
|
|
//print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
|
|
|
|
$db = new DoliDb();
|
|
|
|
$sql = "INSERT INTO user ";
|
|
$sql .= "(Host,User,password,elect_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
|
|
$sql .= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')";
|
|
$sql .= ",'Y','Y','Y','Y','Y',Y','Y','Y');";
|
|
|
|
print $sql;
|
|
|
|
$db->query($sql);
|
|
|
|
$sql = "INSERT INTO db ";
|
|
$sql .= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
|
|
$sql .= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'";
|
|
$sql .= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
|
|
|
|
print $sql;
|
|
|
|
if ($db->query($sql))
|
|
{
|
|
dolibarr_syslog("flush privileges");
|
|
$db->query("flush privileges");
|
|
|
|
print "<tr><td>Création de l'utilisateur : $dolibarr_main_db_user</td><td>OK</td></tr>";
|
|
}
|
|
else
|
|
{
|
|
if ($db->errno() == 1062)
|
|
{
|
|
dolibarr_syslog("Utilisateur deja existant");
|
|
print "<tr><td>Création de l'utilisateur : $dolibarr_main_db_user</td><td>Deja existant</td></tr>";
|
|
}
|
|
else
|
|
{
|
|
dolibarr_syslog("impossible de creer l'utilisateur");
|
|
print "<tr><td>Création de l'utilisateur : $dolibarr_main_db_user</td><td>ERREUR ".$db->error()."</td></tr>";
|
|
}
|
|
}
|
|
|
|
$db->close();
|
|
}
|
|
else
|
|
{ //choix 2=postgresql
|
|
|
|
$nom = $dolibarr_main_db_user;
|
|
$con=pg_connect("host=localhost dbname=dolibarr user=postgres");
|
|
$query_str = "create user \"$nom\" with password '".$dolibarr_main_db_pass."';";
|
|
//print $query_str;
|
|
$ret = pg_query($con,$query_str);
|
|
|
|
if ($ret)
|
|
print "<tr><td>Création de l'utilisateur:\"$nom\"</td><td>OK</td></tr>";
|
|
else
|
|
print "<tr><td>Création de l'utilisateur:\"$nom\"</td><td>ERREUR</td></tr>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Tentative accès serveur et base par le user admin dolibarr
|
|
|
|
$conf = new Conf();
|
|
$conf->db->host = $dolibarr_main_db_host;
|
|
$conf->db->name = $dolibarr_main_db_name;
|
|
$conf->db->user = $dolibarr_main_db_user;
|
|
$conf->db->pass = $dolibarr_main_db_pass;
|
|
//print $conf->db->host.",".$conf->db->name.",".$conf->db->user.",".$conf->db->pass;
|
|
|
|
$db = new DoliDb();
|
|
$ok = 1;
|
|
|
|
if ($db->connected == 1)
|
|
{
|
|
dolibarr_syslog("la connexion au serveur est reussie");
|
|
print "<tr><td>";
|
|
print $langs->trans("ServerConnection")." : ";
|
|
print $dolibarr_main_db_host;
|
|
print "</td><td>";
|
|
print $langs->trans("OK");
|
|
print "</td></tr>";
|
|
}
|
|
else
|
|
{
|
|
dolibarr_syslog("la connection au serveur est rate");
|
|
print "<tr><td>";
|
|
print $langs->trans("ServerConnection")." : ";
|
|
print $dolibarr_main_db_host;
|
|
print "</td><td>";
|
|
print $langs->trans("Error");
|
|
print "</td></tr>";
|
|
$ok = 0;
|
|
}
|
|
|
|
if ($ok)
|
|
{
|
|
if($db->database_selected == 1)
|
|
{
|
|
//
|
|
// Connexion base existante
|
|
//
|
|
dolibarr_syslog("la connexion a la database est reussie");
|
|
print "<tr><td>";
|
|
print $langs->trans("DatabaseConnection")." : ";
|
|
print $dolibarr_main_db_name;
|
|
print "</td><td>";
|
|
print $langs->trans("OK");
|
|
print "</td></tr>";
|
|
$ok = 1 ;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Création de la base
|
|
//
|
|
dolibarr_syslog("la connexion a la database est rate");
|
|
print "<tr><td>";
|
|
print "Echec de connexion à la base : ";
|
|
print $dolibarr_main_db_name;
|
|
print "</td><td>";
|
|
print $langs->trans("Warning");
|
|
print "</td></tr>";
|
|
print '<tr><td colspan="2">';
|
|
print "Création de la base : ";
|
|
print $dolibarr_main_db_name;
|
|
print '</td></tr>';
|
|
|
|
$conf = new Conf();
|
|
$conf->db->host = $dolibarr_main_db_host;
|
|
$conf->db->name = $dolibarr_main_db_name;
|
|
$conf->db->user = isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
|
|
$conf->db->pass = isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
|
|
|
|
$dbt = new DoliDb(); // Ne pas prendre $db comme nom de variable car dejà pris pour connexion précédente et bug mémoire sur php windows dans ce cas
|
|
|
|
if ($ok)
|
|
{
|
|
if ($dbt->connected == 1)
|
|
{
|
|
dolibarr_syslog("la connexion au serveur avec l'utilisateur root reussi");
|
|
print "<tr><td>Connexion au serveur : $dolibarr_main_db_host avec l'utilisateur : ".$_POST["db_user_root"]."</td><td>".$langs->trans("OK")."</td></tr>";
|
|
}
|
|
else
|
|
{
|
|
dolibarr_syslog("la connexion au serveur avec l'utilisateur root rate");
|
|
print "<tr><td>Connexion au serveur : $dolibarr_main_db_host avec l'utilisateur : ".$_POST["db_user_root"]."</td><td>".$langs->trans("Error")."</td></tr>";
|
|
$ok = 0;
|
|
}
|
|
}
|
|
|
|
if ($ok)
|
|
{
|
|
if($dbt->database_selected == 1)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
print "<tr><td>Vérification des droits de création</td><td>".$langs->trans("Error")."</td></tr>";
|
|
print '<tr><td colspna="2">-- Droits insuffissant</td></tr>';
|
|
//$ok = 0;
|
|
}
|
|
}
|
|
|
|
if ($ok)
|
|
{
|
|
if ($dbt->create_db ($dolibarr_main_db_name))
|
|
{
|
|
print "<tr><td>Création de la base : $dolibarr_main_db_name</td><td>".$langs->trans("OK")."</td></tr>";
|
|
}
|
|
else
|
|
{
|
|
print "<tr><td>Création de la base : $dolibarr_main_db_name</td><td>".$langs->trans("Error")."</td></tr>";
|
|
$ok = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</table>
|
|
<?php
|
|
pFooter($err);
|
|
?>
|