dolibarr/htdocs/install/etape1.php

408 lines
12 KiB
PHP
Raw Normal View History

<?php
2004-02-02 02:41:33 +01:00
/* Copyright (C) 2004 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>
2004-02-02 02:41:33 +01:00
*
* 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$
*
*/
2004-02-12 15:47:09 +01:00
2004-12-04 16:30:14 +01:00
/**
\file htdocs/install/etape1.php
\brief G<EFBFBD>n<EFBFBD>re le fichier conf.php avec les informations issues de l'<EFBFBD>tape pr<EFBFBD>c<EFBFBD>dente
\version $Revision$
*/
include_once("./inc.php");
2004-02-12 15:47:09 +01:00
pHeader("Fichier de configuration","etape2");
2004-01-30 17:00:18 +01:00
$etape = 1;
2004-01-27 15:36:40 +01:00
$conffile = "../conf/conf.php";
2004-01-27 15:36:40 +01:00
2004-07-20 11:10:15 +02:00
// R<>pertoire des pages dolibarr
$main_dir=isset($_POST["main_dir"])?$_POST["main_dir"]:'';
2004-07-20 11:10:15 +02:00
// R<>pertoire des documents g<>n<EFBFBD>r<EFBFBD>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<EFBFBD> de mani<6E>re autonome,
// on le force <20> sa valeur fixe des anciennes versions.
// Eric Seigne 2004
$main_data_dir=ereg_replace("htdocs","documents",$main_dir);
// Quand <20>a sera g<>r<EFBFBD> !
2004-12-04 16:30:14 +01:00
if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; }
if ($_POST["action"] == "set")
2004-01-27 15:36:40 +01:00
{
umask(0);
print '<h2>Enregistrement des valeurs</h2>';
2004-12-04 16:30:14 +01:00
print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
2004-01-27 15:36:40 +01:00
$error=0;
$fp = fopen("$conffile", "w");
if($fp)
2004-01-27 15:36:40 +01:00
{
if (substr($main_dir, strlen($main_dir) -1) == "/")
{
$main_dir = substr($main_dir, 0, strlen($main_dir)-1);
}
2004-01-27 15:36:40 +01:00
if (substr($_POST["main_url"], strlen($_POST["main_url"]) -1) == "/")
{
$_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1);
}
2004-01-27 15:36:40 +01:00
clearstatcache();
2004-01-27 15:36:40 +01:00
fwrite($fp, '<?php');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_url_root="'.$_POST["main_url"].'";');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_document_root="'.$main_dir.'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_data_root="'.$main_data_dir.'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_db_host="'.$_POST["db_host"].'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_db_name="'.$_POST["db_name"].'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_db_user="'.$_POST["db_user"].'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_db_pass="'.$_POST["db_pass"].'";');
fputs($fp,"\n");
2004-01-27 15:36:40 +01:00
fputs($fp, '$dolibarr_main_db_type="'.$_POST["db_type"].'";');
fputs($fp,"\n");
fputs($fp, '?>');
fclose($fp);
2004-01-27 15:36:40 +01:00
if (file_exists("$conffile"))
{
include ("$conffile");
print "<tr><td>Configuration enregistr<74>e</td><td>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;
}
2004-02-12 15:47:09 +01:00
/***************************************************************************
*
* Creation des r<EFBFBD>pertoires
*
***************************************************************************/
if ($error == 0)
{
// Les images g<>n<EFBFBD>r<EFBFBD>s dynamiquement sont dans main_dir car doivent etre accessibles par url
$dir[0] = "$main_dir/images";
2004-06-11 17:41:08 +02:00
// Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre t<>l<EFBFBD>charg<72>s en passant outre l'authentification
$dir[1] = "$main_data_dir/facture";
$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";
$dir[9] = "$main_data_dir/users";
2004-02-12 15:47:09 +01:00
if (! is_dir($main_dir))
2004-01-27 15:36:40 +01:00
{
print "<tr><td>Le dossier '".$main_dir."' n'existe pas !</td><td>Erreur</td></tr>";
$error++;
}
else
{
dolibarr_syslog ("Le dossier '".$main_dir."' existe");
// R<>pertoire des documents
if (! is_dir($main_data_dir))
2004-01-27 15:36:40 +01:00
{
@mkdir($main_data_dir, 0755);
2004-01-27 15:36:40 +01:00
}
if (! is_dir($main_data_dir))
2004-01-27 15:36:40 +01:00
{
print "<tr><td>Le dossier '$main_data_dir' n'existe pas ! ";
print "Vous devez cr<63>er ce dossier et permettre au serveur web d'<27>crire dans celui-ci";
print '</td><td bgcolor="red">Erreur</td></tr>';
$error++;
}
else
{
// Boucle sur chaque r<>pertoire de dir[] pour les cr<63>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>Impossible de cr<63>er : ".$dir[$i]."</td><td bgcolor=\"red\">Erreur</td></tr>";
$error++;
}
else
{
dolibarr_syslog ("Le dossier '".$dir[$i]."' a ete cree");
}
}
}
2004-01-27 15:36:40 +01:00
}
}
2004-01-30 17:00:18 +01:00
}
2004-01-30 17:00:18 +01:00
/*
* Base de donn<EFBFBD>es
*
*/
2004-01-27 15:36:40 +01:00
if ($error == 0)
{
include_once($dolibarr_main_document_root . "/conf/conf.class.php");
// TODO
// Il y a encore des pb ds la proc<6F>dure d'install qui ne passe dans pas tous les cas
// (exemple, rien n'existe et on veut cr<63>er une base avec un compte admin != root)
// L'algorithme ne semble pas adapt<70> <20> tous les cas, il devrait etre remplac<61> par le suivant:
//
// On essaie l'acc<63>s par le user admin dolibarr
// si acc<63>s serveur ok et acc<63>s base ok, tout est ok, on ne va pas plus loin, on a m<>me pas utilis<69> le compte root.
// si acc<63>s serveur ok et acc<63>s base ko, warning 1
// si acc<63>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<63>s base ko, on la cr<63><72>e
// Si cr<63>ation ok, on y acc<63>de
// Si cr<63>ation ko, erreur
// Si connexion serveur par root ok et si acc<63>s base ok,
// si compte admin existe deja et db_create_user positionn<6E>, on ajoute les droits,
// si compte admin existe deja et db_create_user non positionn<6E>, erreur compte admin incorrect "Le compte admin indiqu<71> 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<6E>, on cr<63>e le compte
// si compte admin n'existe pas deja et db_create_user non positionn<6E>, erreur compte admin inexistant "Veuillez cocher pour le cr<63>er"
// Si creation utilisateur admin demand<6E>e, on le cr<63>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();
2004-02-12 15:47:09 +01:00
$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;
2004-08-20 11:11:28 +02:00
$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');";
2004-02-12 15:47:09 +01:00
print $sql;
2004-08-20 11:11:28 +02:00
if ($db->query($sql))
{
dolibarr_syslog("flush privileges");
$db->query("flush privileges");
2004-02-12 15:47:09 +01:00
print "<tr><td>Cr<43>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<43>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<43>ation de l'utilisateur : $dolibarr_main_db_user</td><td>ERREUR ".$db->error()."</td></tr>";
}
}
2004-01-30 17:00:18 +01:00
$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<43>ation de l'utilisateur:\"$nom\"</td><td>OK</td></tr>";
else
print "<tr><td>Cr<43>ation de l'utilisateur:\"$nom\"</td><td>ERREUR</td></tr>";
}
}
2004-02-14 13:37:37 +01:00
// Tentative acc<63>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;
2004-02-12 15:47:09 +01:00
if ($db->connected == 1)
{
dolibarr_syslog("la connexion au serveur est reussie");
print "<tr><td>Connexion au serveur : $dolibarr_main_db_host</td><td>OK</td></tr>";
}
else
{
dolibarr_syslog("la connection au serveur est rate");
print "<tr><td>Connexion au serveur : $dolibarr_main_db_host</td><td>ERREUR</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>Connexion <20> la base : $dolibarr_main_db_name</td><td>OK</td></tr>";
$ok = 1 ;
}
else
{
//
// Cr<43>ation de la base
//
dolibarr_syslog("la connexion a la database est rate");
print "<tr><td>Echec de connexion <20> la base : $dolibarr_main_db_name</td><td>Warning</td></tr>";
print '<tr><td colspan="2">Cr<43>ation de la base : '.$dolibarr_main_db_name.'</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<65> pris pour connexion pr<70>c<EFBFBD>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>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>ERREUR</td></tr>";
$ok = 0;
}
}
if ($ok)
{
if($dbt->database_selected == 1)
{
}
else
{
print "<tr><td>V<>rification des droits de cr<63>ation</td><td>ERREUR</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<43>ation de la base : $dolibarr_main_db_name</td><td>OK</td></tr>";
}
else
{
print "<tr><td>Cr<43>ation de la base : $dolibarr_main_db_name</td><td>ERREUR</td></tr>";
$ok = 0;
}
}
}
}
}
2004-01-27 15:36:40 +01:00
}
?>
</table>
<?php
2004-02-12 15:47:09 +01:00
pFooter($err);
2004-01-30 17:00:18 +01:00
?>