-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
etape1.php
953 lines (817 loc) · 38.7 KB
/
etape1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
<?php
/* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 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>
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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/>.
*/
/**
* \file htdocs/install/etape1.php
* \ingroup install
* \brief Build conf file on disk
*/
define('DONOTLOADCONF',1); // To avoid loading conf by file inc.php
include 'inc.php';
$action=GETPOST('action','alpha');
$setuplang=(GETPOST('selectlang','',3)?GETPOST('selectlang','',3):'auto');
$langs->setDefaultLang($setuplang);
$langs->load("admin");
$langs->load("install");
$langs->load("errors");
// Recuparation des information de connexion
$userroot=GETPOST('db_user_root');
$passroot=GETPOST('db_pass_root');
// Repertoire des pages dolibarr
$main_dir=GETPOST('main_dir');
$main_url=GETPOST('main_url');
// Database server
$db_type=GETPOST('db_type','alpha');
$db_host=GETPOST('db_host','alpha');
$db_name=GETPOST('db_name','alpha');
$db_user=GETPOST('db_user','alpha');
$db_pass=GETPOST('db_pass');
$db_port=GETPOST('db_port','int');
$db_prefix=GETPOST('db_prefix','alpha');
session_start(); // To be able to keep info into session (used for not loosing pass during navigation. pass must not transit throug parmaeters)
// Save a flag to tell to restore input value if we do back
$_SESSION['dol_save_pass']=$db_pass;
//$_SESSION['dol_save_passroot']=$passroot;
// Now we load forced value from install.forced.php file.
$useforcedwizard=false;
$forcedfile="./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php";
if (@file_exists($forcedfile)) { $useforcedwizard=true; include_once $forcedfile; }
dolibarr_install_syslog("--- etape1: Entering etape1.php page");
$error = 0;
/*
* View
*/
pHeader($langs->trans("ConfigurationFile"),"etape2");
// Test if we can run a first install process
if (! is_writable($conffile))
{
print $langs->trans("ConfFileIsNotWritable",$conffiletoshow);
pFooter(1,$setuplang,'jscheckparam');
exit;
}
// Check parameters
if (empty($db_type))
{
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseType")).'</div>';
$error++;
}
if (empty($db_host))
{
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Server")).'</div>';
$error++;
}
if (empty($db_name))
{
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseName")).'</div>';
$error++;
}
if (empty($db_user))
{
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login")).'</div>';
$error++;
}
if (! empty($db_port) && ! is_numeric($db_port))
{
print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_port,$langs->transnoentities("Port")).'</div>';
$error++;
}
if (! empty($db_prefix) && ! preg_match('/^[a-z0-9]+_$/i', $db_prefix))
{
print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_prefix,$langs->transnoentities("DatabasePrefix")).'</div>';
$error++;
}
// Remove last / into dans main_dir
if (substr($main_dir, dol_strlen($main_dir) -1) == "/")
{
$main_dir = substr($main_dir, 0, dol_strlen($main_dir)-1);
}
// Remove last / into dans main_url
if (! empty($main_url) && substr($main_url, dol_strlen($main_url) -1) == "/")
{
$main_url = substr($main_url, 0, dol_strlen($main_url)-1);
}
// Directory for generated documents (invoices, orders, ecm, etc...)
$main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:'';
if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; }
// Test database connexion
if (! $error)
{
$result=@include_once $main_dir."/core/db/".$db_type.'.class.php';
if ($result)
{
// If we ask database or user creation we need to connect as root, so we need root login
if (! empty($_POST["db_create_database"]) && ! $userroot)
{
print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$db_name).'</div>';
print '<br>';
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
if (! empty($_POST["db_create_user"]) && ! $userroot)
{
print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect",$db_user).'</div>';
print '<br>';
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
// If we need root access
if (! $error && (! empty($_POST["db_create_database"]) || ! empty($_POST["db_create_user"])))
{
$databasefortest=$db_name;
if (! empty($_POST["db_create_database"]))
{
if ($db_type == 'mysql' || $db_type == 'mysqli')
{
$databasefortest='mysql';
}
elseif ($db_type == 'pgsql')
{
$databasefortest='postgres';
}
else
{
$databasefortest='mssql';
}
}
//print $_POST["db_type"].",".$_POST["db_host"].",$userroot,$passroot,$databasefortest,".$_POST["db_port"];
$db=getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, $db_port);
dol_syslog("databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected, LOG_DEBUG);
//print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected;
if (empty($_POST["db_create_database"]) && $db->connected && ! $db->database_selected)
{
print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound",$db_name).'</div>';
print '<br>';
if (! $db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
elseif ($db->error && ! (! empty($_POST["db_create_database"]) && $db->connected))
{
// Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
print '<div class="error">'.$db->error.'</div>';
if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
//print '<a href="#" onClick="javascript: history.back();">';
print $langs->trans("ErrorGoBackAndCorrectParameters");
//print '</a>';
$error++;
}
}
// If we need simple access
if (! $error && (empty($_POST["db_create_database"]) && empty($_POST["db_create_user"])))
{
$db=getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
if ($db->error)
{
print '<div class="error">'.$db->error.'</div>';
if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
}
}
else
{
print "<br>\nFailed to include_once(\"".$main_dir."/core/db/".$db_type.".class.php\")<br>\n";
print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter",$langs->transnoentities("WebPagesDirectory")).'</div>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
}
else
{
if (isset($db)) print $db->lasterror();
if (isset($db) && ! $db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
if (! $error && $db->connected)
{
if (! empty($_POST["db_create_database"]))
{
$result=$db->select_db($db_name);
if ($result)
{
print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
}
}
// Define $defaultCharacterSet and $defaultDBSortingCollation
if (! $error && $db->connected)
{
if (! empty($_POST["db_create_database"])) // If we create database, we force default value
{
//$defaultCharacterSet=getStaticMember(get_class($db),'forcecharset');
//$defaultDBSortingCollation=getStaticMember(get_class($db),'forcecollate');
$defaultCharacterSet=$db->forcecharset;
$defaultDBSortingCollation=$db->forcecollate;
}
else // If already created, we take current value
{
$defaultCharacterSet=$db->getDefaultCharacterSetDatabase();
$defaultDBSortingCollation=$db->getDefaultCollationDatabase();
}
print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
$db_character_set=$defaultCharacterSet;
$db_collation=$defaultDBSortingCollation;
dolibarr_install_syslog("db_character_set=".$db_character_set." db_collation=".$db_collation);
}
// Create config file
if (! $error && $db->connected && $action == "set")
{
umask(0);
foreach($_POST as $key => $value)
{
if (! preg_match('/^db_pass/i', $key))
dolibarr_install_syslog("Choice for ".$key." = ".$value);
}
// Show title of step
print '<h3>'.$langs->trans("ConfigurationFile").'</h3>';
print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
// Check parameter main_dir
if (! $error)
{
if (! is_dir($main_dir))
{
dolibarr_install_syslog("etape1: Repertoire '".$main_dir."' inexistant ou non accessible");
print "<tr><td>";
print $langs->trans("ErrorDirDoesNotExists",$main_dir).'<br>';
print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'<br>';
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
print '</td><td>';
print $langs->trans("Error");
print "</td></tr>";
$error++;
}
}
if (! $error)
{
dolibarr_install_syslog("etape1: Directory '".$main_dir."' exists");
}
// Create subdirectory main_data_dir
if (! $error)
{
// Create directory for documents
if (! is_dir($main_data_dir))
{
dol_mkdir($main_data_dir);
}
if (! is_dir($main_data_dir))
{
print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
print '</td><td>';
print '<font class="error">'.$langs->trans("Error").'</font>';
print "</td></tr>";
print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
$error++;
}
else
{
// Create .htaccess file in document directory
$pathhtaccess=$main_data_dir.'/.htaccess';
if (! file_exists($pathhtaccess))
{
dolibarr_install_syslog("etape1: .htaccess file does not exists, we create it in '".$main_data_dir."'");
$handlehtaccess=@fopen($pathhtaccess,'w');
if ($handlehtaccess)
{
fwrite($handlehtaccess,'Order allow,deny'."\n");
fwrite($handlehtaccess,'Deny from all'."\n");
fclose($handlehtaccess);
dolibarr_install_syslog("etape1: .htaccess file created");
}
}
// Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre telecharges en passant outre l'authentification
$dir[0] = $main_data_dir."/mycompany";
$dir[1] = $main_data_dir."/users";
$dir[2] = $main_data_dir."/custom";
$dir[3] = $main_data_dir."/facture";
$dir[4] = $main_data_dir."/propale";
$dir[5] = $main_data_dir."/ficheinter";
$dir[6] = $main_data_dir."/produit";
$dir[7] = $main_data_dir."/doctemplates";
// Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
$num=count($dir);
for ($i = 0; $i < $num; $i++)
{
if (is_dir($dir[$i]))
{
dolibarr_install_syslog("etape1: Directory '".$dir[$i]."' exists");
}
else
{
if (dol_mkdir($dir[$i]) < 0)
{
print "<tr><td>";
print "Failed to create directory: ".$dir[$i];
print '</td><td>';
print $langs->trans("Error");
print "</td></tr>";
$error++;
}
else
{
dolibarr_install_syslog("etape1: Directory '".$dir[$i]."' created");
}
}
}
if ($error)
{
print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
print '</td><td>';
print '<font class="error">'.$langs->trans("Error").'</font>';
print "</td></tr>";
print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
}
else
{
//ODT templates
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$srcroot=$main_dir.'/install/doctemplates';
$destroot=$main_data_dir.'/doctemplates';
$docs=array('thirdparties' => 'thirdparty', 'proposals' => 'proposal', 'orders' => 'order', 'invoices' => 'invoice', 'projects' => 'project');
foreach($docs as $cursordir => $cursorfile)
{
$src=$srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
$dirodt=$destroot.'/'.$cursordir;
$dest=$dirodt.'/template_'.$cursorfile.'.odt';
dol_mkdir($dirodt);
$result=dol_copy($src,$dest,0,0);
if ($result < 0)
{
print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile',$src,$dest).'</td></tr>';
}
}
}
}
}
// Table prefix
$main_db_prefix = (! empty($db_prefix) ? $db_prefix : 'llx_');
// Force https
$main_force_https = ((GETPOST("main_force_https") && (GETPOST("main_force_https") == "on" || GETPOST("main_force_https") == 1)) ? '1' : '0');
// Use alternative directory
$main_use_alt_dir = ((GETPOST("main_use_alt_dir") && (GETPOST("main_use_alt_dir") == "on" || GETPOST("main_use_alt_dir") == 1)) ? '' : '//');
// Alternative root directory name
$main_alt_dir_name = ((GETPOST("main_alt_dir_name") && GETPOST("main_alt_dir_name") != '') ? GETPOST("main_alt_dir_name") : 'custom');
// Write conf file on disk
if (! $error)
{
// Save old conf file on disk
if (file_exists("$conffile"))
{
// We must ignore errors as an existing old file may already exists and not be replacable or
// the installer (like for ubuntu) may not have permission to create another file than conf.php.
// Also no other process must be able to read file or we expose the new file, so content with password.
@dol_copy($conffile, $conffile.'.old', '0400');
}
$error+=write_conf_file($conffile);
}
// Write main.inc.php and master.inc.php into documents/custom dir
$error+=write_main_file($main_data_dir.'/custom/main.inc.php',$main_dir);
$error+=write_master_file($main_data_dir.'/custom/master.inc.php',$main_dir);
// Create database and admin user database
if (! $error)
{
// We reload configuration file
conf($dolibarr_main_document_root);
print '<tr><td>';
print $langs->trans("ConfFileReload");
print '</td>';
print '<td>'.$langs->trans("OK").'</td></tr>';
$userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:"";
$passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
// Si creation utilisateur admin demandee, on le cree
if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on")
{
dolibarr_install_syslog("etape1: Create database user: ".$dolibarr_main_db_user);
//print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
$databasefortest=$conf->db->name;
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
{
$databasefortest='mysql';
}
else if ($conf->db->type == 'pgsql')
{
$databasefortest='postgres';
}
else if ($conf->db->type == 'mssql')
{
$databasefortest='mssql';
}
// Creation handler de base, verification du support et connexion
$db=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest,$conf->db->port);
if ($db->error)
{
print '<div class="error">'.$db->error.'</div>';
$error++;
}
if (! $error)
{
if ($db->connected)
{
$result=$db->DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name);
if ($result > 0)
{
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("OK").'</td></tr>';
}
else
{
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
|| $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
|| $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS')
{
dolibarr_install_syslog("etape1: User already exists");
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
}
else
{
dolibarr_install_syslog("etape1: Failed to create user");
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error()."</td></tr>";
}
}
$db->close();
}
else
{
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("Error").'</td>';
print '</tr>';
// Affiche aide diagnostique
print '<tr><td colspan="2"><br>';
print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
print '<br>';
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
print '</td></tr>';
$error++;
}
}
} // Fin si "creation utilisateur"
// If database creation is asked, we create it
if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on"))
{
dolibarr_install_syslog("etape1: Create database : ".$dolibarr_main_db_name." ".$dolibarr_main_db_character_set." ".$dolibarr_main_db_collation." ".$dolibarr_main_db_user, LOG_DEBUG);
$newdb=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port);
//print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
if ($newdb->connected)
{
$result=$newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
if ($result)
{
print '<tr><td>';
print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
print $dolibarr_main_db_name;
print '</td>';
print "<td>".$langs->trans("OK")."</td></tr>";
$check1=$newdb->getDefaultCharacterSetDatabase();
$check2=$newdb->getDefaultCollationDatabase();
dolibarr_install_syslog('etape1: Note that default server was charset='.$check1.' collation='.$check2, LOG_DEBUG);
// If values differs, we save conf file again
//if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('etape1: Value for character_set is not the one asked for database creation', LOG_WARNING);
//if ($check2 != $dolibarr_main_db_collation) dolibarr_install_syslog('etape1: Value for collation is not the one asked for database creation', LOG_WARNING);
}
else
{
// Affiche aide diagnostique
print '<tr><td colspan="2"><br>';
print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'<br>';
print $newdb->lasterror().'<br>';
print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
print '<br>';
print '</td></tr>';
dolibarr_install_syslog('etape1: Failed to create database '.$dolibarr_main_db_name.' '.$newdb->lasterrno().' '.$newdb->lasterror(), LOG_ERR);
$error++;
}
$newdb->close();
}
else {
print '<tr><td>';
print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
print $dolibarr_main_db_name;
print '</td>';
print '<td>'.$langs->trans("Error").'</td>';
print '</tr>';
// Affiche aide diagnostique
print '<tr><td colspan="2"><br>';
print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
print '<br>';
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
print '</td></tr>';
$error++;
}
} // Fin si "creation database"
// We test access with dolibarr database user (not admin)
if (! $error)
{
dolibarr_install_syslog("etape1: connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name, LOG_DEBUG);
//print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
$db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
if ($db->connected == 1)
{
// si acces serveur ok et acces base ok, tout est ok, on ne va pas plus loin, on a meme pas utilise le compte root.
if ($db->database_selected == 1)
{
dolibarr_install_syslog("etape1: connexion to server by user ".$conf->db->user." is ok", LOG_DEBUG);
print "<tr><td>";
print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
print $dolibarr_main_db_host;
print "</td><td>";
print $langs->trans("OK");
print "</td></tr>";
dolibarr_install_syslog("etape1: connexion to database : ".$conf->db->name.", by user : ".$conf->db->user." is ok", LOG_DEBUG);
print "<tr><td>";
print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
print $dolibarr_main_db_name;
print "</td><td>";
print $langs->trans("OK");
print "</td></tr>";
$error = 0;
}
else
{
dolibarr_install_syslog("etape1: connexion to server by user ".$conf->db->user." is ok", LOG_DEBUG);
print "<tr><td>";
print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
print $dolibarr_main_db_host;
print "</td><td>";
print $langs->trans("OK");
print "</td></tr>";
dolibarr_install_syslog("etape1: connexion to database ".$conf->db->name.", by user : ".$conf->db->user." has failed", LOG_ERR);
print "<tr><td>";
print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
print $dolibarr_main_db_name;
print '</td><td>';
print $langs->trans("Error");
print "</td></tr>";
// Affiche aide diagnostique
print '<tr><td colspan="2"><br>';
print $langs->trans('CheckThatDatabasenameIsCorrect',$dolibarr_main_db_name).'<br>';
print $langs->trans('IfAlreadyExistsCheckOption').'<br>';
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
print '</td></tr>';
$error++;
}
}
else
{
dolibarr_install_syslog("etape1: la connexion au serveur par le user ".$conf->db->user." est rate");
print "<tr><td>";
print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
print $dolibarr_main_db_host;
print '</td><td>';
print '<font class="error">'.$db->error.'</div>';
print "</td></tr>";
// Affiche aide diagnostique
print '<tr><td colspan="2"><br>';
print $langs->trans("ErrorConnection",$conf->db->host,$conf->db->name,$conf->db->user);
print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'<br>';
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
print '</td></tr>';
$error++;
}
}
}
print '</table>';
}
?>
<script type="text/javascript">
function jsinfo()
{
ok=true;
//alert('<?php echo dol_escape_js($langs->transnoentities("NextStepMightLastALongTime")); ?>');
document.getElementById('nextbutton').style.visibility="hidden";
document.getElementById('pleasewait').style.visibility="visible";
return ok;
}
</script>
<?php
dolibarr_install_syslog("--- install/etape1.php end", LOG_INFO);
pFooter($error,$setuplang,'jsinfo',1);
/**
* Create main file. No particular permissions are set by installer.
*
* @param string $mainfile Full path name of main file to generate/update
* @param string $main_dir Full path name to main.inc.php file
* @return void
*/
function write_main_file($mainfile,$main_dir)
{
$fp = @fopen("$mainfile", "w");
if($fp)
{
clearstatcache();
fputs($fp, '<?php'."\n");
fputs($fp, "// Wrapper to include main into htdocs\n");
fputs($fp, "include_once '".$main_dir."/main.inc.php';\n");
fputs($fp, '?>');
fclose($fp);
}
}
/**
* Create master file. No particular permissions are set by installer.
*
* @param string $masterfile Full path name of master file to generate/update
* @param string $main_dir Full path name to master.inc.php file
* @return void
*/
function write_master_file($masterfile,$main_dir)
{
$fp = @fopen("$masterfile", "w");
if($fp)
{
clearstatcache();
fputs($fp, '<?php'."\n");
fputs($fp, "// Wrapper to include master into htdocs\n");
fputs($fp, "include_once '".$main_dir."/master.inc.php';\n");
fputs($fp, '?>');
fclose($fp);
}
}
/**
* Save configuration file. No particular permissions are set by installer.
*
* @param string $conffile Path to conf file to generate/update
* @return void
*/
function write_conf_file($conffile)
{
global $conf,$langs;
global $main_url,$main_dir,$main_data_dir,$main_force_https,$main_use_alt_dir,$main_alt_dir_name,$main_db_prefix;
global $dolibarr_main_url_root,$dolibarr_main_document_root,$dolibarr_main_data_root,$dolibarr_main_db_host;
global $dolibarr_main_db_port,$dolibarr_main_db_name,$dolibarr_main_db_user,$dolibarr_main_db_pass;
global $dolibarr_main_db_type,$dolibarr_main_db_character_set,$dolibarr_main_db_collation,$dolibarr_main_authentication;
global $db_host,$db_port,$db_name,$db_user,$db_pass,$db_type,$db_character_set,$db_collation;
global $conffile,$conffiletoshow,$conffiletoshowshort;
global $force_dolibarr_lib_ADODB_PATH, $force_dolibarr_lib_NUSOAP_PATH;
global $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
global $force_dolibarr_lib_PHPEXCEL_PATH, $force_dolibarr_lib_GEOIP_PATH;
global $force_dolibarr_lib_ODTPHP_PATH, $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP;
global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI, $force_dolibarr_js_JQUERY_FLOT;
global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
$error=0;
$key = md5(uniqid(mt_rand(),TRUE)); // Generate random hash
$fp = fopen("$conffile", "w");
if($fp)
{
clearstatcache();
fputs($fp,'<?php'."\n");
fputs($fp,'//'."\n");
fputs($fp,'// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(),'')."\n");
fputs($fp,'//'."\n");
fputs($fp,'// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
fputs($fp,'// and explanations for all possibles parameters.'."\n");
fputs($fp,'//'."\n");
fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'","\'",($main_url)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'","\'",($main_dir)).'\';');
fputs($fp,"\n");
fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'","\'",($main_url."/".$main_alt_dir_name)).'\';');
fputs($fp,"\n");
fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'","\'",($main_dir."/".$main_alt_dir_name)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_data_root=\''.str_replace("'","\'",($main_data_dir)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_host=\''.str_replace("'","\'",($db_host)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_port=\''.str_replace("'","\'",($db_port)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_name=\''.str_replace("'","\'",($db_name)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_prefix=\''.str_replace("'","\'",($main_db_prefix)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_user=\''.str_replace("'","\'",($db_user)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_pass=\''.str_replace("'","\'",($db_pass)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_type=\''.str_replace("'","\'",($db_type)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_character_set=\''.str_replace("'","\'",($db_character_set)).'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_db_collation=\''.str_replace("'","\'",($db_collation)).'\';');
fputs($fp,"\n");
/* Authentication */
fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
fputs($fp,"\n\n");
fputs($fp, '// Specific settings');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_prod=\'0\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_force_https=\''.$main_force_https.'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_main_cookie_cryptkey=\''.$key.'\';');
fputs($fp,"\n");
fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
fputs($fp,"\n");
// Write params to overwrites default lib path
fputs($fp,"\n");
if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH=''; }
fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH=''; }
fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH=''; }
fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH=''; }
fputs($fp, '$dolibarr_lib_ADODB_PATH=\''.$force_dolibarr_lib_ADODB_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH=''; }
fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH=''; }
fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_PHPEXCEL_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_PHPEXCEL_PATH=''; }
fputs($fp, '$dolibarr_lib_PHPEXCEL_PATH=\''.$force_dolibarr_lib_PHPEXCEL_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH=''; }
fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP=''; }
fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR=''; }
fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY=''; }
fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI=''; }
fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_js_JQUERY_FLOT)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_FLOT=''; }
fputs($fp, '$dolibarr_js_JQUERY_FLOT=\''.$force_dolibarr_js_JQUERY_FLOT.'\';');
fputs($fp,"\n");
// Write params to overwrites default font path
fputs($fp,"\n");
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF=''; }
fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
fputs($fp,"\n");
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD=''; }
fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
fputs($fp,"\n");
fputs($fp, '?>');
fclose($fp);
if (file_exists("$conffile"))
{
include $conffile; // On force rechargement. Ne pas mettre include_once !
conf($dolibarr_main_document_root);
print "<tr><td>";
print $langs->trans("SaveConfigurationFile");
print ' <strong>'.$conffile.'</strong>';
print "</td><td>";
print $langs->trans("OK");
print "</td></tr>";
}
else
{
$error++;
}
}
return $error;
}
?>