-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoli_install.php
1298 lines (1148 loc) · 60.6 KB
/
doli_install.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
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (C) 2020-2023 ksar <[email protected]>
* Copyright (C) 2021 Gaëtan MAISON <[email protected]>
*
* From an original idea of elarifr / accedinfo.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 doli_install.php
* \brief File that help to install or upgrade dolibarr
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
@set_time_limit (120);
if (function_exists("apache_setenv")){
@apache_setenv('no-gzip', 1);
}
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
/***********************************************************************
* *
* Parameters *
* *
************************************************************************/
define('SCRIPT_VERSION','1.1.0 Version');
$github_url = 'https://github.com/Dolibarr/dolibarr/archive/%s.zip';
$github_dev = 'https://github.com/Dolibarr/dolibarr/archive/develop.zip';
$github_api = 'https://api.github.com/repos/Dolibarr/dolibarr/branches';
$sourceforge_rss_url = 'https://sourceforge.net/projects/dolibarr/rss?path=/Dolibarr%20ERP-CRM';
$sourceforge_url = 'https://sourceforge.net/projects/dolibarr/files/Dolibarr%%20ERP-CRM/%s/dolibarr-%s.zip/download';
$conffile = "./conf/conf.php";
$download_file = "mydoli.zip";
$log_file = "doli_install.log";
/***********************************************************************
* *
* Functions *
* *
************************************************************************/
/**
* Write logs
*
* @param string $message Message
* @param array $log_array Array of log
* @return void
*/
function write_log($message, $log_array = ''){
global $log_file ;
$message = date("Y-m-d H:i:s")." ".$message."\n";
@file_put_contents($log_file, $message , FILE_APPEND);
if($log_array != ''){
@file_put_contents($log_file, print_r($log_array, true) , FILE_APPEND);
}
}
/**
* Load the lang
*
* @param string $lang Lang
* @return lang table
*/
function language($lang){
//French Language
if ($lang == 'fr'){
$lang_array = array(
"DolibarrSetup" => "Installation ou Mise à jour de Dolibarr",
"NextStep" => "Étape Suivante",
"SelectLanguage" => "Sélection de la langue",
"DefaultLanguage" => "Langue par défaut",
"Check" => "Vérifications",
"MiscellaneousChecks" => "Vérification des prérequis",
"PHPVersion" => "Version PHP",
"ErrorPHPVersionTooLow" => "Version de PHP trop ancienne. PHP 5.5 Minimum requise. Votre Version PHP est",
"ErrorPHPDoesNotSupportCurl" => "Votre version de PHP ne supporte pas l'extension Curl.",
"ErrorPHPDoesNotSupportZip" => "Votre version de PHP ne supporte pas l'extension Zip.",
"PHPSupportCurl" => "PHP supporte l'extension Curl.",
"PHPSupportZip" => "PHP supporte l'extension Zip.",
"PHPMemoryOK" => "Votre mémoire maximum de session PHP est définie à",
"PHPMemoryTooLow" => "Votre mémoire maximum de session PHP est trop faible. Il est recommandé de modifier le paramètre <b>memory_limit</b> de votre fichier <b>php.ini</b> à au moins 64M octets. Elle est pour le moment définie à",
"ErrorDocRootNotWrit" => "Le répertoire d'installation ne peut être écrit",
"DocRootWrit" => "Le répertoire d'installation peut être écrit",
"UpgradeDetected" => "Un fichier conf.php a été trouvé : <b> Mise à jour de Dolibarr </b>. Version détecté",
"IntallNewDetected" => "Aucun fichier conf.php n'a été trouvé : <b> Installation Neuve de Dolibarr </b>.",
"ChooseVersion" => "Choisir la version à installer",
"Download" => "Téléchargement",
"ErrorNoVersionSelectec" => "Vous n'avez pas sélectionné de version.",
"UrlDownload" => "Adresse de téléchargement",
"ErrorDuringDownload" => "Erreur pendant le téléchargement",
"DownloadPackage" => "Téléchargement du package Dolibarr Version",
"DownloadProgress" => "Progression du téléchargement",
"DownloadCompleted" => "Téléchargement terminé. Taille du package",
"ErrorDownloadFile" => "Le fichier téléchargé n'est pas une archive !",
"Install" => "Installer la version téléchargée",
"FileIsAZip" => "Le fichier téléchargé est bien un zip",
"ErrorNotAZip" => "Le fichier téléchargé n'est pas un zip",
"NumbersOfDirectories" => "Nombre de dossiers crées",
"NumbersOfFiles" => "Nombre de fichiers crées",
"NoErrors" => "Aucune erreur lors de l'extraction",
"SomeErrors" => "Quelques erreurs lors de l'extraction. Nombre d'erreurs",
"RedirectToInstall" => "L'installation ou mise à jour est maintenant terminée. En cliquant sur \"Suivant\" vous allez être redirigé vers l'installation de Dolibarr",
"InstallLockDeleted" => "Le fichier install.lock a été trouvé et supprimé",
"InstallLockNotFounded" => "Aucun fichier install.lock n'a été trouvé. Si il existe vous devez le supprimer manuellement",
"InstallLockFoundNoDeleted" => "Le fichier install.lock existe mais n'a pas pu être supprimé",
"DeleteScript" => "Supprimer ce script php du serveur (Recommandé)",
"DeleteLog" => "Supprimer le fichier log de ce script (Recommandé)",
"AFewAdditionalOptions" => "Quelques options supplémentaires",
"From" => "depuis"
);
}else{
$lang_array = array(
"DolibarrSetup" => "Dolibarr Install or Upgrade",
"NextStep" => "Next Step",
"SelectLanguage" => "Language selection",
"DefaultLanguage" => "Default language",
"Check" => "Initial Checks",
"MiscellaneousChecks" => "Prerequisites check",
"PHPVersion" => "PHP Version",
"ErrorPHPVersionTooLow" => "PHP version too old. PHP 5.5 Minimum is required. Your PHP Version is",
"ErrorPHPDoesNotSupportCurl" => "Your PHP installation does not support Curl.",
"PHPSupportCurl" => "This PHP supports Curl.",
"ErrorPHPDoesNotSupportZip" => "Your PHP installation does not support Zip.",
"PHPSupportZip" => "This PHP supports Zip.",
"PHPMemoryOK" => "Your PHP max session memory is set to",
"PHPMemoryTooLow" => "Your maximum PHP session memory is too low. It is recommended to change the <b>memory_limit</b> parameter of your <b>php.ini</b> file to at least 64M bytes. It is currently set to",
"ErrorDocRootNotWrit" => "The installation directory is not writtable",
"DocRootWrit" => "The installation directory is writtable",
"UpgradeDetected" => "A conf.php file has been found: <b> Dolibar update </b>. Version detected",
"IntallNewDetected" => "No conf.php file was found : <b> New installation of Dolibar </b>.",
"ChooseVersion" => "Choose the version to be installed",
"Download" => "Download",
"ErrorNoVersionSelectec" => "No versions has been selected.",
"UrlDownload" => "Download URL",
"ErrorDuringDownload" => "Error during Download",
"DownloadPackage" => "Download Dolibarr package Version",
"DownloadProgress" => "Download Progress",
"DownloadCompleted" => "Download completed. Package size",
"ErrorDownloadFile" => "The downloaded package is not a zip file !",
"Install" => "Install the downloaded version",
"FileIsAZip" => "The downloaded file is a zip",
"ErrorNotAZip" => "The downloaded file is not a zip",
"NumbersOfDirectories" => "Numbers of directories created",
"NumbersOfFiles" => "Numbers of files created",
"NoErrors" => "No error during extraction",
"SomeErrors" => "Some errors during extractions. Errors numbers",
"RedirectToInstall" => "The Dolibarr new install or update is now over. When you will click on \"Next\" you will be redirected to dolibarr installation script",
"InstallLockDeleted" => "The install.lock files has been found and removed",
"InstallLockNotFounded" => "No install.lock file has been found. If it exist, you have to remove it manualy",
"InstallLockFoundNoDeleted" => "The install.lock file exist but not possible to delete it",
"DeleteScript" => "Delete this php script from the server (Recommended)",
"DeleteLog" => "Delete the log file of this script (Recommended)",
"AFewAdditionalOptions" => "A few additional options",
"From" => "from"
);
}
return $lang_array;
}
/**
* Show HTML header of install pages
*
* @param string $subtitle Title
* @param string $action Action code
* @param array $langs Language
* @return void
*/
function pHeader($subtitle, $action = '', $langs = ''){
// We force the content charset
header("Content-type: text/html; charset=utf-8");
header("X-Content-Type-Options: nosniff");
print '<!DOCTYPE HTML>'."\n";
print '<html>'."\n";
print '<head>'."\n";
print '<meta charset="utf-8">'."\n";
print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
print '<meta name="generator" content="Dolibarr installer">'."\n";
print '<link rel="stylesheet" type="text/css" href="'.$_SERVER["PHP_SELF"].'?action=css">'."\n";
print '<title>'.$langs["DolibarrSetup"].'</title>'."\n";
print '</head>'."\n";
print '<body>'."\n";
print '<div class="divlogoinstall" style="text-align:center">';
print '<img class="imglogoinstall" src="'.$_SERVER["PHP_SELF"].'?action=img&file=logo" alt="Dolibarr logo" width="300px"><br>';
print SCRIPT_VERSION;
print '</div><br>';
print '<span class="titre">'.$langs["DolibarrSetup"];
if ($subtitle) {
print ' - '.$subtitle;
}
print '</span>'."\n";
print '<form name="forminstall" style="width: 100%" action="'.$_SERVER["PHP_SELF"].($action?'?action='.$action:'').'" method="POST">'."\n";
print '<input type="hidden" name="action" value="'.$action.'">'."\n";
print '<table class="main" width="100%"><tr><td>'."\n";
print '<table class="main-inside" width="100%"><tr><td>'."\n";
}
/**
* Print HTML footer of install pages
*
* @param integer $nonext 1=No button "Next step"
* @param array $langs Language array
* @param string $selectlang Language code
* @return void
*/
function pFooter($nonext = 0, $langs = '', $selectlang = ''){
print '</td></tr></table>'."\n";
print '</td></tr></table>'."\n";
if (! $nonext){
print '<div class="nextbutton" id="nextbutton">';
print '<input type="submit" value="'.$langs["NextStep"].' ->"></div>';
}
if ($selectlang)
{
print '<input type="hidden" name="selectlang" value="'.$selectlang.'">';
}
print '</form>'."\n";
print '</body>'."\n";
print '</html>'."\n";
}
/**
* Return image relative URL
*
* @param string $image Image tag
* @return string Relative URL of the image
*/
function url_img($image){
return $_SERVER["PHP_SELF"].'?action=img&file='.$image ;
}
/**
* Get le list of versions from Sourcforge
*
* @param string $url URL of the RSS field
* @return array List of versions
*/
function get_sourceforge_files($url){
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
$sourceforge_versions = array();
foreach($xml->channel->item as $file){
if (strstr($file->link,".zip")){
preg_match ('/[0-9]+\.[0-9]+\.[0-9]+/', $file->link , $matches);
$sourceforge_versions[] = $matches[0];
}
}
rsort($sourceforge_versions, SORT_NUMERIC );
return $sourceforge_versions;
}
/**
* Get le list of branches from GitHub
*
* @param string $url URL of the github branches API
* @return array List of versions
*/
function get_github_banches($url){
$context = stream_context_create(array('http' => array('header' => 'User-Agent: request')));
$jsonResponse = file_get_contents($url, false, $context);
// Convertir la réponse JSON en tableau associatif
$data = json_decode($jsonResponse, true);
$github_versions = array();
// Vérifier si la conversion a réussi
if ($data === null) {
// La conversion a échoué
write_log('Github Branches answer was not a JSON '.$url.' '.$jsonResponse);
} else {
// La conversion a réussi
// Parcourir chaque tableau dans la liste
foreach ($data as $version) {
// Accéder aux données de chaque version
$found_version = $version['name'];
if (preg_match('/^\d+\.\d+$/', $found_version)){
$github_versions[] = $found_version;
}
}
}
rsort($github_versions, SORT_NUMERIC );
return $github_versions;
}
/**
* CURL follow redirections event if open_basedir or safe_mode are ON
*
* @param resource $ch Curl Resource
* @param Int $maxredirect Max redirections
* @return curl_exec Execution of CURL
* Code from : https://www.php.net/manual/fr/function.curl-setopt.php#102121
*/
function curl_exec_follow($ch, &$maxredirect = null) {
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/i', $header, $matches);
$newurl = trim(array_pop($matches));
write_log('New URL found '.$newurl);
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
write_log('Too many redirects');
trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
/**
* CURL Progress function
*
* @param resource $ch Curl Resource
* @param Int $download_size Downloaded size
* @param Int $downloaded Downloaded
* @param Int $upload_size Uploaded size
* @param Int $uploaded Uploaded
* @return Nothing
* Code from : https://stackoverflow.com/questions/13958303/curl-download-progress-in-php
*/
function progress($resource,$download_size, $downloaded, $upload_size, $uploaded)
{
static $previousProgress = 0;
if ( $download_size == 0 ) {
//Github doesn't send the size, so estimated size
$progress = round($downloaded / 650000);
} else {
$progress = round($downloaded * 100 / $download_size);
}
if ( $progress > $previousProgress)
{
$previousProgress = $progress;
//update JavaScript progress bar to show download progress
echo '<script>
//size : '.$download_size.' downloaded : '.$downloaded.'
document.getElementById(\'prog\').value = '.$progress.';</script>'."\n";
}
}
/**
* Output Human file size
*
* @param Int $bytes Size in bytes
* @param Int $decimals Numbers of decimals
* @return String
* Code from : https://www.php.net/manual/fr/function.filesize.php#120250
*/
function human_filesize($bytes, $decimals = 2) {
$factor = floor((strlen($bytes) - 1) / 3);
if ($factor > 0) $sz = 'KMGT';
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor - 1] . 'B';
}
/**
* Extend class ZipArchive for directory extraction
*
* Code from : https://www.php.net/manual/fr/ziparchive.extractto.php#116353
*/
if (class_exists("ZipArchive")){
class my_ZipArchive extends ZipArchive{
public function extractSubdirTo($destination, $subdir){
$errors = array();
$nb_directories = 0;
$nb_files = 0;
// Prepare dirs
$destination = str_replace(array("/", "\\"), DIRECTORY_SEPARATOR, $destination);
$subdir = str_replace(array("/", "\\"), "/", $subdir);
if (substr($destination, mb_strlen(DIRECTORY_SEPARATOR, "UTF-8") * -1) != DIRECTORY_SEPARATOR)
$destination .= DIRECTORY_SEPARATOR;
if (substr($subdir, -1) != "/")
$subdir .= "/";
// Extract files
for ($i = 0; $i < $this->numFiles; $i++){
$filename = $this->getNameIndex($i);
if (substr($filename, 0, mb_strlen($subdir, "UTF-8")) == $subdir){
$relativePath = substr($filename, mb_strlen($subdir, "UTF-8"));
$relativePath = str_replace(array("/", "\\"), DIRECTORY_SEPARATOR, $relativePath);
if (mb_strlen($relativePath, "UTF-8") > 0){
// Directory
if (substr($filename, -1) == "/"){
// New dir
if (!is_dir($destination . $relativePath)){
if (!@mkdir($destination . $relativePath, 0755, true)){
$errors[$i] = $filename;
}else{
$nb_directories++;
}
}
}else{
if (dirname($relativePath) != "."){
if (!is_dir($destination . dirname($relativePath))){
// New dir (for file)
@mkdir($destination . dirname($relativePath), 0755, true);
$nb_directories++;
}
}
// New file
if (@file_put_contents($destination . $relativePath, $this->getFromIndex($i)) === false){
$errors[$i] = $filename;
}else{
$nb_files++;
}
}
}
}
}
return array(
"nb_directories" => $nb_directories,
"nb_files" => $nb_files,
"errors" => $errors );
}
}
}
/***********************************************************************
* *
* Main *
* *
************************************************************************/
// initialize action variable
$action = (!empty($_GET['action'])) ? $_GET['action'] : '';
write_log('Action = '.$action);
// initialize lang table
if (!empty($_POST['selectlang'])){
$selectlang = $_POST['selectlang'];
$langs = language($selectlang);
}else{
$templang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$selectlang = '';
$langs = language($templang);
}
//If conf.php exist, load the conf
if (file_exists($conffile)){
include ($conffile);
// Just to define version DOL_VERSION
if (! defined('DOL_INC_FOR_VERSION_ERROR')) define('DOL_INC_FOR_VERSION_ERROR', '1');
require_once './filefunc.inc.php';
write_log('Conf file exits. Dolibarr version installed : '.DOL_VERSION);
}else{
//we use the current folder to extract dolibarr
$dolibarr_main_document_root=__DIR__;
$dolibarr_main_data_root="../documents";
write_log('Conf file doesn\'t exist');
}
//Index page
if ($action == ''){
write_log('--- Enter in Index Page ---');
pHeader($langs["SelectLanguage"], 'check', $langs);
echo '<br /><br /><div class="center">'."\n";
echo '<table><tr><td>'."\n";
echo $langs["DefaultLanguage"].': </td>'."\n";
echo '<td><select class="flat" id="selectlang" name="selectlang">'."\n";
echo '<option value="fr">Français</option>'."\n";
echo '<option value="en">English</option>'."\n";
echo '</select></td></tr></table></div><br><br>'."\n";
pFooter( 0, $langs, $selectlang);
}
//Check page
if ($action == 'check'){
write_log('--- Enter in Check Page ---');
$checkfail = 0;
pHeader($langs["Check"], 'download', $langs);
print '<h3><img class="valigntextbottom" src="'.url_img('gear').'" width="20" alt="Database"> '.$langs["MiscellaneousChecks"]." :</h3>\n";
//Check PHP version
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["PHPVersion"]." ".PHP_VERSION."<br>\n";
}else{
print '<img src="'.url_img('error').'" alt="Error"> '.$langs["ErrorPHPVersionTooLow"]." ".PHP_VERSION."<br>\n";
$checkfail=1;
}
write_log('PHP Version : '.PHP_VERSION);
// Check if Curl supported
if (! function_exists("curl_init")){
print '<img src="'.url_img('error').'" alt="Error"> '.$langs["ErrorPHPDoesNotSupportCurl"]."<br>\n";
$checkfail=1;
write_log('Curl is not supported');
}else{
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["PHPSupportCurl"]."<br>\n";
write_log('Curl is supported');
}
// Check if Zip supported
if (! class_exists("ZipArchive")){
print '<img src="'.url_img('error').'" alt="Error"> '.$langs["ErrorPHPDoesNotSupportZip"]."<br>\n";
$checkfail=1;
write_log('Zip is not supported');
}else{
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["PHPSupportZip"]."<br>\n";
write_log('Zip is supported');
}
// Check memory
$memrequired=64*1024*1024;
$memmaxorig=@ini_get("memory_limit");
$memmax=@ini_get("memory_limit");
if ($memmaxorig != ''){
preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
if ($reg[2]){
if (strtoupper($reg[2]) == 'G') $memmax=$reg[1]*1024*1024*1024;
if (strtoupper($reg[2]) == 'M') $memmax=$reg[1]*1024*1024;
if (strtoupper($reg[2]) == 'K') $memmax=$reg[1]*1024;
}
if ($memmax >= $memrequired || $memmax == -1){
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["PHPMemoryOK"]." ".$memmaxorig."<br>\n";
}else{
print '<img src="'.url_img('warning').'" alt="Warning"> '.$langs["PHPMemoryTooLow"]." ".$memmaxorig."<br>\n";
}
write_log('PHP Memory limit : '.$memmaxorig);
}
// Check if main dir is writable
if (! is_writable($dolibarr_main_document_root)){
print '<img src="'.url_img('error').'" alt="Error"> '.$langs["ErrorDocRootNotWrit"]."<br>\n";
$checkfail=1;
write_log('Directory is not writtable');
}else{
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["DocRootWrit"]."<br>\n";
write_log('Directory is writtable');
}
print "<br>\n";
//Display if it is new install or upgrade
if (defined('DOL_VERSION')) {
print $langs["UpgradeDetected"].': <b><span class="ok">'.DOL_VERSION.'</span></b>'."<br>\n";
}else{
print $langs["IntallNewDetected"]."<br>\n";
}
echo '<br /><br /><div class="center">'."\n";
echo '<table><tr><td>'."\n";
$sourceforge_versions = get_sourceforge_files($sourceforge_rss_url);
$github_versions = get_github_banches($github_api);
write_log('SourceForge versions found ',$sourceforge_versions);
write_log('GitHub versions found ',$github_versions);
echo $langs["ChooseVersion"].': </td>'."\n";
echo '<td><select class="flat" id="selectversion" name="selectversion">'."\n";
echo '<option value="develop">Develop Branch '.$langs["From"].' GITHUB</option>'."\n";
foreach ($github_versions as $version){
echo '<option value="'.$version.'">'.$version.' Branch '.$langs["From"].' GitHub</option>'."\n";
}
foreach ($sourceforge_versions as $version){
echo '<option value="'.$version.'">'.$version.' '.$langs["From"].' Sourceforge</option>'."\n";
}
echo '</select></td></tr></table></div><br><br>'."\n";
pFooter( $checkfail, $langs, $selectlang);
}
//Download page
if ($action == 'download'){
write_log('--- Enter in Download Page ---');
// initialize download version
if (!empty($_POST['selectversion'])){
if ($_POST['selectversion'] == 'develop'){
$url_version = $github_dev ;
}elseif (preg_match('/^\d+\.\d+$/', $_POST['selectversion'])){
$url_version = sprintf($github_url,$_POST['selectversion']);
}else{
$url_version = sprintf($sourceforge_url,$_POST['selectversion'],$_POST['selectversion']);
}
}else{
$url_version = '';
}
write_log('URL to download version : '.$url_version);
$error = 0;
pHeader($langs["Download"], 'install', $langs);
print '<input type="hidden" name="selectversion" value="'.$_POST['selectversion'].'">'."\n";
print '<h3><img class="valigntextbottom" src="'.url_img('gear').'" width="20" alt="Database"> '.$langs["DownloadPackage"]." ".$_POST['selectversion']." :</h3>\n";
//Check if we have an URL
if ($url_version != ''){
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["UrlDownload"]." : ".$url_version."<br>\n";
}else{
print '<div class="error">'.$langs["ErrorNoVersionSelectec"].'</div>'."<br />\n";
$error=1;
}
echo $langs["DownloadProgress"] . ' : <progress id="prog" value="0" max="100"></progress>'."<br>\n";
//Delete the file if exist
if (file_exists ($download_file)){
if (@unlink ($download_file)){
write_log('Archive already exist. Delete successful');
}else{
write_log('Archive already exist. Delete impossible');
}
}
//Open the archive
$file = fopen($download_file, 'wb'); // (w)rite mode (b)inary
$new = 1;
while ($new){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_version);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress');
curl_setopt($ch, CURLOPT_NOPROGRESS, false); // needed to make progress function work
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$contents = curl_exec_follow($ch);
//For Sourceforge need to extract the mirror
if (preg_match('/<meta http-equiv="refresh" content="5; url=([^"]+)"/', $contents, $matches)){
$url_version = $matches[1];
write_log('New url found : '.$url_version);
}else{
$new = 0;
}
}
if (curl_error($ch)!="") {
//Error during download
print '<div class="error">'.$langs["ErrorDuringDownload"]." : ".curl_error($ch)."<br />\n";
$error=1;
$info = curl_getinfo($ch);
write_log('Curl Error : '.$curl_error($ch),$info);
curl_close ($ch);
exit();
} else {
//Download is completed
fwrite($file, $contents);
fclose($file);
curl_close ($ch);
write_log('Download successful');
}
//Check if it is a ZIP
$zip = new ZipArchive;
$res = $zip->open($download_file);
if ($res === TRUE) {
$zip->close();
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["DownloadCompleted"]." : ".human_filesize(filesize($download_file))."<br>\n";
write_log('Downloaded archive is a zip. Size : '.human_filesize(filesize($download_file)));
} else {
print '<div class="error">'.$langs["ErrorDownloadFile"]." : ".$res."<br />\n";
$error=1;
write_log('Downloaded archive is not a zip. Error : '.$res);
}
pFooter( $error, $langs, $selectlang);
}
//Install page
if ($action == 'install'){
write_log('--- Enter in Install Page ---');
// initialize download version
if (!empty($_POST['selectversion'])){
$selected_version = $_POST['selectversion'] ;
if ($selected_version == 'dev'){
$zip_directory = 'dolibarr-develop/htdocs/';
}elseif ($selected_version == 'stable'){
$zip_directory = 'dolibarr-'.STABLE.'/htdocs/';
}elseif ($selected_version == 'old_stable'){
$zip_directory = 'dolibarr-'.OLD_STABLE.'/htdocs/';
}else{
$zip_directory = 'dolibarr-'.$selected_version.'/htdocs/';
}
}
write_log('Zip directory : '.$zip_directory);
$error = 0;
pHeader($langs["Install"], 'redirect', $langs);
print '<h3><img class="valigntextbottom" src="'.url_img('gear').'" width="20" alt="Database"> '.$langs["Install"]." ".$selected_version." :</h3>\n";
//extract the zip
$zip = new my_ZipArchive();
if ($zip->open($download_file) === TRUE){
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["FileIsAZip"]."<br>\n";
write_log('File is a zip');
$output = $zip->extractSubdirTo("./", $zip_directory);
$zip->close();
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["NumbersOfDirectories"]." : ".$output["nb_directories"]."<br>\n";
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["NumbersOfFiles"]." : ".$output["nb_files"]."<br>\n";
if (count ($output["errors"]) == 0){
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["NoErrors"]."<br>\n";
write_log('Unzip successful. Number of directories : '.$output["nb_directories"].' Numbers of files :'.$output["nb_files"]);
}else{
print '<img src="'.url_img('warning').'" alt="Warning"> '.$langs["SomeErrors"]." : ".count($output["errors"])."<br>\n";
write_log('Unzip successful with errors. Number of directories : '.$output["nb_directories"].' Numbers of files :'.$output["nb_files"],$output["errors"]);
}
}else{
print '<div class="error">'.$langs["ErrorNotAZip"].'</div>'."<br />\n";
$error=1;
write_log('Archive is not a zip');
}
//Delete the archive
if (@unlink ($download_file)){
write_log('Delete archive done');
}else{
write_log('Impossible to delete archive');
}
//Try to remove install.lock
$install_lock_found = false ;
$install_lock_deleted = false ;
if(file_exists($dolibarr_main_document_root.'/install.lock')){
$install_lock_found = true ;
write_log('Install.lock found on document dir');
if (@unlink($dolibarr_main_document_root.'/install.lock')){
$install_lock_deleted = true ;
write_log('Install.lock deleted');
}
}
if(file_exists($dolibarr_main_data_root.'/install.lock')){
$install_lock_found = true ;
write_log('Install.lock found on htdocs dir');
if (@unlink($dolibarr_main_data_root.'/install.lock')){
$install_lock_deleted = true ;
write_log('Install.lock deleted');
}
}
if(file_exists('install.lock')){
$install_lock_found = true ;
write_log('Install.lock found on current dir');
if (@unlink('install.lock')){
$install_lock_deleted = true ;
write_log('Install.lock deleted');
}
}
if ($install_lock_found && $install_lock_deleted){
print '<img src="'.url_img('tick').'" alt="Ok"> '.$langs["InstallLockDeleted"]."<br>\n";
}
if (!$install_lock_found){
print '<img src="'.url_img('warning').'" alt="Warning"> '.$langs["InstallLockNotFounded"]."<br>\n";
}
if ($install_lock_found && !$install_lock_deleted){
print '<img src="'.url_img('error').'" alt="Error"> '.$langs["InstallLockFoundNoDeleted"]."<br>\n";
}
if (!$error ){
print "<br />\n";
print "<br />\n";
print $langs["RedirectToInstall"]."<br />\n";
print "<br />\n";
print $langs["AFewAdditionalOptions"]."<br />\n";
print '<div class="label">'."\n";
print ' <input type="checkbox" id="removescript" name="removescript" checked> '.$langs["DeleteScript"]."<br />\n";
print ' <input type="checkbox" id="removelog" name="removelog" checked> '.$langs["DeleteLog"]."<br />\n";
}
pFooter( $error, $langs, $selectlang);
}
//Redirection page
if ($action == 'redirect'){
write_log('--- Enter in Redirect Page ---');
//try to remove ourselves
if (isset($_POST['removescript'])){
if (@unlink (__FILE__)){
write_log('Remove of this script done');
}else{
write_log('Not possible to remove this script');
}
}
//try to remove logs
if (isset($_POST['removelog'])){
@unlink ($log_file);
}
header("Location: install/index.php");
exit;
}
/***********************************************************************
* *
* Includes *
* *
************************************************************************/
//Output the CSS
if ($action == 'css'){
//set the content type header
header("Content-type: text/css");
echo "
.opacitymedium {
opacity: 0.5;
}
body {
font-size:14px;
font-family: roboto,arial,tahoma,verdana,helvetica;
/* background: #fcfcfc; */
margin: 15px 30px 10px;
}
table.main-inside {
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
margin-bottom: 10px;
margin-top: 10px;
color: #000000;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
line-height: 22px;
}
table.main {
padding-left: 6px;
padding-right: 6px;
padding-top: 12px;
padding-bottom: 12px;
background-color: #fff;
}
div.titre {
padding: 5px 5px 5px 5px;
margin: 0 0 0 0;
}
span.titre {
/* font-weight: bold; */
background: #FFFFFF;
color: rgb(0,113,121);
border: 1px solid #bbb;
padding: 10px 10px 10px 10px;
margin: 0 0 10px 10px;
}
div.soustitre {
font-size: 15px;
font-weight: bold;
color: #4965B3;
padding: 0 1.2em 0.5em 2em;
margin: 1.2em 1.2em 1.2em 1.2em;
border-bottom: 1px solid #999;
border-right: 1px solid #999;
text-align: right;
}
.minwidth100 { min-width: 100px; }
.minwidth200 { min-width: 200px; }
.minwidth300 { min-width: 300px; }
.minwidth400 { min-width: 400px; }
.minwidth500 { min-width: 500px; }
.minwidth50imp { min-width: 50px !important; }
.minwidth100imp { min-width: 100px !important; }
.minwidth200imp { min-width: 200px !important; }
.minwidth300imp { min-width: 300px !important; }
.minwidth400imp { min-width: 400px !important; }
.minwidth500imp { min-width: 500px !important; }
tr.trlineforchoice {
height: 4em;
}
a.button.runupgrade {
padding: 10px;
}
/* Force values for small screen 570 */
@media only screen and (max-width: 570px)
{
body {
margin: 15px 4px 4px;
}
input, input[type=text], input[type=password], select, textarea {
min-width: 20px;
min-height: 1.4em;
line-height: 1.4em;
padding: .4em .1em;
border: 1px solid #BBB;
/* max-width: inherit; why this ? */
}
.hideonsmartphone { display: none; }
.noenlargeonsmartphone { width : 50px !important; display: inline !important; }
.maxwidthonsmartphone { max-width: 100px; }
.maxwidth50onsmartphone { max-width: 40px; }
.maxwidth75onsmartphone { max-width: 50px; }
.maxwidth100onsmartphone { max-width: 70px; }
.maxwidth150onsmartphone { max-width: 120px; }
.maxwidth200onsmartphone { max-width: 200px; }
.maxwidth300onsmartphone { max-width: 300px; }
.maxwidth400onsmartphone { max-width: 400px; }
.minwidth50imp { min-width: 50px !important; }
.minwidth100imp { min-width: 50px !important; }
.minwidth200imp { min-width: 50px !important; }
.minwidth300imp { min-width: 50px !important; }
.minwidth400imp { min-width: 50px !important; }
.minwidth500imp { min-width: 50px !important; }
table.main {
padding-left: 0;
padding-right: 0;
}
table.main-inside {
padding-left: 1px;
padding-right: 1px;
line-height: 20px;
}
span.titre {
font-size: 90%;
font-weight: normal;
background: #FFFFFF;
color: #444;
border: 1px solid #999;