[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/install/ -> etape1.php (source)

   1  <?php
   2  /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   4   * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
   5   * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
   6   *
   7   * This program is free software; you can redistribute it and/or modify
   8   * it under the terms of the GNU General Public License as published by
   9   * the Free Software Foundation; either version 2 of the License, or
  10   * (at your option) any later version.
  11   *
  12   * This program is distributed in the hope that it will be useful,
  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15   * GNU General Public License for more details.
  16   *
  17   * You should have received a copy of the GNU General Public License
  18   * along with this program; if not, write to the Free Software
  19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20   *
  21   * $Id: etape1.php,v 1.47.2.1 2006/01/04 16:19:36 eldy Exp $
  22   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/install/etape1.php,v $
  23   */
  24  
  25  /**
  26          \file       htdocs/install/etape1.php
  27          \brief      Génère le fichier conf.php avec les informations issues de l'étape précédente
  28          \version    $Revision: 1.47.2.1 $
  29  */
  30  
  31  include_once ("./inc.php");
  32  
  33  $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto');
  34  $langs->setDefaultLang($setuplang);
  35  
  36  $langs->load("admin");
  37  $langs->load("install");
  38  
  39  
  40  pHeader($langs->trans("ConfigurationFile"),"etape2");
  41  
  42  
  43  $error = 0;
  44  
  45  
  46  // Répertoire des pages dolibarr
  47  $main_dir=isset($_POST["main_dir"])?trim($_POST["main_dir"]):'';
  48  
  49  // On supprime /  de fin dans main_dir
  50  if (substr($main_dir, strlen($main_dir) -1) == "/")
  51  {
  52      $main_dir = substr($main_dir, 0, strlen($main_dir)-1);
  53  }
  54  
  55  // On supprime /  de fin dans main_url
  56  if (substr($_POST["main_url"], strlen($_POST["main_url"]) -1) == "/")
  57  {
  58      $_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1);
  59  }
  60  
  61  // Répertoire des documents générés (factures, etc...)
  62  $main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:'';
  63  if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; }
  64  
  65  
  66  
  67  /*
  68   * Actions
  69   */
  70  if ($_POST["action"] == "set")
  71  {
  72      umask(0);
  73  
  74      print '<h2>'.$langs->trans("SaveConfigurationFile").'</h2>';
  75  
  76      print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
  77  
  78      // Verification validite parametre main_dir
  79      if (! $error)
  80      {
  81          if (! is_dir($main_dir))
  82          {
  83              dolibarr_syslog ("Repertoire '".$main_dir."' inexistant ou non accessible");
  84  
  85              print "<tr><td>";
  86              print $langs->trans("ErrorDirDoesNotExists",$main_dir).'<br>';
  87              print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'<br>';
  88              print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  89              print '</td><td>';
  90              print $langs->trans("Error");
  91              print "</td></tr>";
  92              $error++;
  93          }
  94      }
  95  
  96      // Sauvegarde fichier configuration
  97      if (! $error)
  98      {
  99          $fp = fopen("$conffile", "w");
 100      
 101          if($fp)
 102          {
 103              clearstatcache();
 104      
 105              fwrite($fp, '<?php');
 106              fputs($fp,"\n");
 107      
 108              fputs($fp, '$dolibarr_main_url_root="'.$_POST["main_url"].'";');
 109              fputs($fp,"\n");
 110      
 111              fputs($fp, '$dolibarr_main_document_root="'.$main_dir.'";');
 112              fputs($fp,"\n");
 113      
 114              fputs($fp, '$dolibarr_main_data_root="'.$main_data_dir.'";');
 115              fputs($fp,"\n");
 116      
 117              fputs($fp, '$dolibarr_main_db_host="'.$_POST["db_host"].'";');
 118              fputs($fp,"\n");
 119      
 120              fputs($fp, '$dolibarr_main_db_name="'.$_POST["db_name"].'";');
 121              fputs($fp,"\n");
 122      
 123              fputs($fp, '$dolibarr_main_db_user="'.$_POST["db_user"].'";');
 124              fputs($fp,"\n");
 125      
 126              fputs($fp, '$dolibarr_main_db_pass="'.$_POST["db_pass"].'";');
 127              fputs($fp,"\n");
 128      
 129              fputs($fp, '$dolibarr_main_db_type="'.$_POST["db_type"].'";');
 130              fputs($fp,"\n");
 131      
 132              fputs($fp, '?>');
 133              fclose($fp);
 134      
 135              if (file_exists("$conffile"))
 136              {
 137                  include ("$conffile");
 138                  print "<tr><td>".$langs->trans("ConfigurationSaving")."</td><td>".$langs->trans("OK")."</td>";
 139              }
 140              else
 141              {
 142                  $error++;
 143              }
 144          }
 145      
 146          if($dolibarr_main_db_type == "mysql")
 147          {
 148              $choix=1;
 149          }
 150          else
 151          {
 152              $choix=2;
 153          }
 154  
 155          // Chargement driver acces bases
 156          include_once("../lib/".$dolibarr_main_db_type.".lib.php");
 157  
 158      }
 159  
 160      /***************************************************************************
 161      *
 162      * Creation des répertoires
 163      *
 164      ***************************************************************************/
 165  
 166      // Creation des sous-répertoires main_data_dir
 167      if (! $error)
 168      {
 169          dolibarr_syslog ("Le dossier '".$main_dir."' existe");
 170  
 171          // Répertoire des documents
 172          if (! is_dir($main_data_dir))
 173          {
 174              @mkdir($main_data_dir, 0755);
 175          }
 176  
 177          if (! is_dir($main_data_dir))
 178          {
 179              print "<tr><td>".$langs->trans("DirDoesNotExists",$main_data_dir);
 180              print "Vous devez créer ce dossier et permettre au serveur web d'écrire dans celui-ci";
 181              print '</td><td>';
 182              print $langs->trans("Error");
 183              print "</td></tr>";
 184              $error++;
 185          }
 186          else
 187          {
 188              // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés en passant outre l'authentification
 189              $dir[0] = "$main_data_dir/facture";
 190              $dir[1] = "$main_data_dir/users";
 191              $dir[2] = "$main_data_dir/propale";
 192              $dir[3] = "$main_data_dir/societe";
 193              $dir[4] = "$main_data_dir/ficheinter";
 194              $dir[5] = "$main_data_dir/produit";
 195              $dir[6] = "$main_data_dir/rapport";
 196              $dir[7] = "$main_data_dir/rsscache";
 197              $dir[8] = "$main_data_dir/logo";
 198  
 199              // Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas
 200              for ($i = 0 ; $i < sizeof($dir) ; $i++)
 201              {
 202                  if (is_dir($dir[$i]))
 203                  {
 204                      dolibarr_syslog ("Le dossier '".$dir[$i]."' existe");
 205                  }
 206                  else
 207                  {
 208                      if (! @mkdir($dir[$i], 0755))
 209                      {
 210                          print "<tr><td>";
 211                          print "Impossible de créer : ".$dir[$i];
 212                          print '</td><td>';
 213                          print $langs->trans("Error");
 214                          print "</td></tr>";
 215                          $error++;
 216                      }
 217                      else
 218                      {
 219                          dolibarr_syslog ("Le dossier '".$dir[$i]."' a ete cree");
 220                      }
 221                  }
 222              }
 223          }
 224      }
 225  
 226  
 227      /*
 228       * Base de données
 229       *
 230       */
 231      if (! $error)
 232      {
 233          include_once($dolibarr_main_document_root . "/conf/conf.class.php");
 234  
 235          $conf = new Conf();
 236          $conf->db->type = trim($dolibarr_main_db_type);
 237          $conf->db->host = trim($dolibarr_main_db_host);
 238          $conf->db->name = trim($dolibarr_main_db_name);
 239          $conf->db->user = trim($dolibarr_main_db_user);
 240          $conf->db->pass = trim($dolibarr_main_db_pass);
 241  
 242          $userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
 243          $passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
 244  
 245  
 246          /*
 247           * Si creation utilisateur admin demandée, on le crée
 248           */
 249          if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
 250          {
 251              dolibarr_syslog("Creation de l'utilisateur: ".$dolibarr_main_db_user." choix base: ".$choix);
 252  
 253              if ($choix == 1)     //choix 1=mysql
 254              {
 255                  //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
 256  
 257                  // Creation handler de base, verification du support et connexion
 258                  $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql');
 259                  if ($db->error)
 260                  {
 261                      print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql');
 262                      $error++;
 263                  }
 264                  
 265                  if (! $error)
 266                  {
 267                      if ($db->connected)
 268                      {
 269                          $sql = "INSERT INTO user ";
 270                          $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
 271                          $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')";
 272                          $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
 273      
 274                          //print "$sql<br>\n";
 275      
 276                          $db->query($sql);
 277      
 278                          $sql = "INSERT INTO db ";
 279                          $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)";
 280                          $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'";
 281                          $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');";
 282      
 283                          //print "$sql<br>\n";
 284      
 285                          $resql=$db->query($sql);
 286                          if ($resql)
 287                          {
 288                              dolibarr_syslog("flush privileges");
 289                              $db->query("FLUSH Privileges;");
 290      
 291                              print '<tr><td>';
 292                              print $langs->trans("UserCreation").' : ';
 293                              print $dolibarr_main_db_user;
 294                              print '</td>';
 295                              print '<td>'.$langs->trans("OK").'</td></tr>';
 296                          }
 297                          else
 298                          {
 299                              if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 300                              {
 301                                  dolibarr_syslog("Utilisateur deja existant");
 302                                  print '<tr><td>';
 303                                  print $langs->trans("UserCreation").' : ';
 304                                  print $dolibarr_main_db_user;
 305                                  print '</td>';
 306                                  print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
 307                              }
 308                              else
 309                              {
 310                                  dolibarr_syslog("impossible de creer l'utilisateur");
 311                                  print '<tr><td>';
 312                                  print $langs->trans("UserCreation").' : ';
 313                                  print $dolibarr_main_db_user;
 314                                  print '</td>';
 315                                  print '<td>'.$langs->trans("Error").' '.$db->error()."</td></tr>";
 316                              }
 317                          }
 318      
 319                          $db->close();
 320                      }
 321                      else
 322                      {
 323                          print '<tr><td>';
 324                          print $langs->trans("UserCreation").' : ';
 325                          print $dolibarr_main_db_user;
 326                          print '</td>';
 327                          print '<td>'.$langs->trans("Error").'</td>';
 328                          print '</tr>';
 329      
 330                          // Affiche aide diagnostique
 331                          print '<tr><td colspan="2"><br>Vous avez demandé la création du login Dolibarr "<b>'.$dolibarr_main_db_user.'</b>", mais pour cela, ';
 332                          print 'Dolibarr doit se connecter sur le serveur "<b>'.$dolibarr_main_db_host.'</b>" via le super utilisateur "<b>'.$userroot.'</b>", mot de passe "<b>'.$passroot.'</b>".<br>';
 333                          print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
 334                          print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
 335                          print '</td></tr>';
 336      
 337                          $error++;
 338                      }
 339                  }
 340              }
 341              else        //choix 2=postgresql
 342              {
 343                  //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
 344  
 345                  // Creation handler de base, verification du support et connexion
 346                  $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,$conf->db->name);
 347                  if ($db->error)
 348                  {
 349                      print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql');
 350                      $error++;
 351                  }
 352  
 353                  if (! $error)
 354                  {
 355                      if ($db->connected)
 356                      {
 357                          $nom = $dolibarr_main_db_user;
 358                          $sql = "create user \"".$nom."\" with password '".$dolibarr_main_db_pass."';";
 359                          //print $query_str;
 360                          $resql = $db->query($sql);
 361                          if ($resql)
 362                          {
 363                              print '<tr><td>';
 364                              print $langs->trans("UserCreation").' : ';
 365                              print $dolibarr_main_db_user;
 366                              print '</td>';
 367                              print '<td>'.$langs->trans("OK").'</td>';
 368                              print '</tr>';
 369                          }
 370                          else
 371                          {
 372                              if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 373                              {
 374                                  dolibarr_syslog("Utilisateur deja existant");
 375                                  print '<tr><td>';
 376                                  print $langs->trans("UserCreation").' : ';
 377                                  print $dolibarr_main_db_user;
 378                                  print '</td>';
 379                                  print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
 380                              }
 381                              else
 382                              {
 383                                  dolibarr_syslog("impossible de creer l'utilisateur");
 384                                  print '<tr><td>';
 385                                  print $langs->trans("UserCreation").' : ';
 386                                  print $dolibarr_main_db_user;
 387                                  print '</td>';
 388                                  print '<td>'.$langs->trans("Error").' '.$db->error()."</td></tr>";
 389                              }
 390                          }
 391                      }
 392                      else
 393                      {
 394                          print '<tr><td>';
 395                          print $langs->trans("UserCreation").' : ';
 396                          print $dolibarr_main_db_user;
 397                          print '</td>';
 398                          print '<td>'.$langs->trans("Error").'</td>';
 399                          print '</tr>';
 400      
 401                          // Affiche aide diagnostique
 402                          print '<tr><td colspan="2"><br>Vous avez demandé la création du login Dolibarr "<b>'.$dolibarr_main_db_user.'</b>", mais pour cela, ';
 403                          print 'Dolibarr doit se connecter sur le serveur "<b>'.$dolibarr_main_db_host.'</b>" via le super utilisateur "<b>'.$userroot.'</b>", mot de passe "<b>'.$passroot.'</b>".<br>';
 404                          print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
 405                          print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
 406                          print '</td></tr>';
 407      
 408                          $error++;
 409                      }
 410                  }
 411              }
 412  
 413          }   // Fin si "creation utilisateur"
 414  
 415  
 416          /*
 417          * Si creation database demandée, on la crée
 418          */
 419          if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on"))
 420          {
 421              dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name);
 422  
 423              $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot);
 424  
 425              if ($db->connected)
 426              {
 427                  if ($db->create_db($dolibarr_main_db_name))
 428                  {
 429                      print '<tr><td>';
 430                      print $langs->trans("DatabaseCreation").' : ';
 431                      print $dolibarr_main_db_name;
 432                      print '</td>';
 433                      print "<td>".$langs->trans("OK")."</td></tr>";
 434                  }
 435                  else
 436                  {
 437                      print '<tr><td>';
 438                      print $langs->trans("DatabaseCreation").' : ';
 439                      print $dolibarr_main_db_name;
 440                      print '</td>';
 441                      print '<td>'.$langs->trans("Error").' '.$db->errno().'</td></tr>';
 442  
 443                      // Affiche aide diagnostique
 444                      print '<tr><td colspan="2"><br>La création de la base Dolibarr "<b>'.$dolibarr_main_db_name.'</b>" a échoué.';
 445                      print 'Si la base existe déjà, revenez en arrière et désactiver l\'option "Créer la base de donnée".<br>';
 446                      print '</td></tr>';
 447  
 448                      $error++;
 449                  }
 450                  $db->close();
 451              }
 452              else {
 453                  print '<tr><td>';
 454                  print $langs->trans("DatabaseCreation").' : ';
 455                  print $dolibarr_main_db_name;
 456                  print '</td>';
 457                  print '<td>'.$langs->trans("Error").'</td>';
 458                  print '</tr>';
 459  
 460                  // Affiche aide diagnostique
 461                  print '<tr><td colspan="2"><br>Vous avez demandé la création de la base Dolibarr "<b>'.$dolibarr_main_db_name.'</b>", mais pour cela, ';
 462                  print 'Dolibarr doit se connecter sur le serveur "<b>'.$dolibarr_main_db_host.'</b>" via le super utilisateur "<b>'.$userroot.'</b>", mot de passe "<b>'.$passroot.'</b>".<br>';
 463                  print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. ';
 464                  print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
 465                  print '</td></tr>';
 466  
 467                  $error++;
 468              }
 469          }   // Fin si "creation database"
 470  
 471  
 472          /*
 473           * On test maintenant l'accès par le user admin dolibarr
 474           */
 475          if (! $error)
 476          {
 477              dolibarr_syslog("connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name);
 478              //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name;
 479  
 480              $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
 481  
 482              if ($db->connected == 1)
 483              {
 484                  // 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.
 485                  if ($db->database_selected == 1)
 486                  {
 487                      dolibarr_syslog("la connexion au serveur par le user ".$conf->db->user." est reussie");
 488                      print "<tr><td>";
 489                      print $langs->trans("ServerConnection")." : ";
 490                      print $dolibarr_main_db_host;
 491                      print "</td><td>";
 492                      print $langs->trans("OK");
 493                      print "</td></tr>";
 494  
 495                      dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie");
 496                      print "<tr><td>";
 497                      print $langs->trans("DatabaseConnection")." : ";
 498                      print $dolibarr_main_db_name;
 499                      print "</td><td>";
 500                      print $langs->trans("OK");
 501                      print "</td></tr>";
 502  
 503                      $error = 0;
 504                  }
 505                  else
 506                  {
 507                      dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est reussie");
 508                      print "<tr><td>";
 509                      print $langs->trans("ServerConnection")." : ";
 510                      print $dolibarr_main_db_host;
 511                      print "</td><td>";
 512                      print $langs->trans("OK");
 513                      print "</td></tr>";
 514  
 515                      dolibarr_syslog("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué");
 516                      print "<tr><td>";
 517                      print $langs->trans("DatabaseConnection")." : ";
 518                      print $dolibarr_main_db_name;
 519                      print '</td><td>';
 520                      print $langs->trans("Error");
 521                      print "</td></tr>";
 522  
 523                      // Affiche aide diagnostique
 524                      print '<tr><td colspan="2"><br>Vérifier que le nom de base "<b>'.$dolibarr_main_db_name.'</b>" est correct.<br>';
 525                      print 'Si ce nom est correct et que cette base n\'existe pas déjà, vous devez cocher l\'option "Créer la base de donnée". ';
 526                      print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
 527                      print '</td></tr>';
 528  
 529                      $error++;
 530                  }
 531              }
 532              else
 533              {
 534                  dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est rate");
 535                  print "<tr><td>";
 536                  print $langs->trans("ServerConnection")." : ";
 537                  print $dolibarr_main_db_host;
 538                  print '</td><td>';
 539                  print $langs->trans("Error");
 540                  print "</td></tr>";
 541  
 542                  // Affiche aide diagnostique
 543                  print '<tr><td colspan="2"><br>Le serveur "<b>'.$conf->db->host.'</b>", nom de base "<b>'.$conf->db->name.'</b>", login "<b>'.$conf->db->user.'</b>", ou mot de passe <b>"'.$conf->db->pass.'</b>" de la base de donnée est peut-être incorrect ou la version du client PHP trop ancienne par rapport à la version de la base de donnée.<br>';
 544                  print 'Si le login n\'existe pas encore, vous devez cocher l\'option "Créer l\'utilisateur".<br>';
 545                  print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
 546                  print '</td></tr>';
 547  
 548                  $error++;
 549              }
 550          }
 551      }
 552  
 553      print '</table>';
 554  }
 555  
 556  pFooter($error,$setuplang);
 557  
 558  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics