-
Notifications
You must be signed in to change notification settings - Fork 31
/
install.php
2558 lines (2326 loc) · 72.2 KB
/
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
/**
* Coppermine Photo Gallery
*
* v1.0 originally written by Gregory Demar
*
* @copyright Copyright (c) 2003-2023 Coppermine Dev Team
* @license GNU General Public License version 3 or later; see LICENSE
*
* install.php
* @since 1.6.24
*/
########################
####Install Main Code###
########################
define('IN_COPPERMINE', true);
define('INSTALL_PHP', true);
define('VERSIONCHECK_PHP', true);
define('INFORMATION', 1);
define('ERROR', 2);
define('CRITICAL_ERROR', 3);
//Define installation steps
define('STEP_INIT_AND_LANG', 1);
define('STEP_VERSIONCHECK', 2);
define('STEP_FOLDER_PERMISSIONS', 3);
define('STEP_SELECT_IMG_PROC', 4);
define('STEP_TEST_IMG_PROC', 5);
define('STEP_DB_INFO', 6);
define('STEP_DB_SELECT', 7);
define('STEP_DB_INIT', 8);
define('STEP_SET_ADMIN', 9);
define('STEP_FINALISE', 10);
// Set global vars
$LINEBREAK = "\r\n"; // For compatibility both on Windows as well as *nix
// Set required versions
$required_php_version = '5.4.0';
// Set the parameters that normally get populated by the option form
$displayOption_array = array(
'errors_only' => 1,
'do_not_connect_to_online_repository' => 1,
);
// Populate the $CONFIG vars if they are empty
$CONFIG = array(
'fullpath' => 'albums/',
'userpics' => 'userpics/',
);
if (!defined('COPPERMINE_VERSION')) { // we need to define the constant COPPERMINE_VERSION that normally get's populated by include/init.inc.php, as we check the repository against that version number
$handle = @fopen('include/init.inc.php', 'r');
if ($handle == FALSE) {
$page_title = 'Could not fopen';
html_header();
echo 'Could not open the file include/init.inc.php for reading. Make sure it exists and is readable, then try again.';
html_footer();
die;
}
$found = 0;
while (!feof($handle) && $found != 1) {
$buffer = fgets($handle, 4096);
if (strpos($buffer, "define('COPPERMINE_VERSION', '") === FALSE) {
$found = 0;
} else {
$found = 1;
$version_number = trim(str_replace("');", '', str_replace("define('COPPERMINE_VERSION', '", '', $buffer)));
}
}
@fclose($handle);
if ($version_number != '' && version_compare($version_number, '1.5', '>') == TRUE) {
define('COPPERMINE_VERSION', $version_number);
} else {
$page_title = 'Could not determine version number';
html_header();
echo 'Could not extract the Coppermine version number from the file inlucde/init.inc.php. Please download a fresh copy of the Coppermine package.';
html_footer();
die;
}
}
// include Inspekt for sanitization
$incp = get_include_path().PATH_SEPARATOR.dirname(__FILE__).PATH_SEPARATOR.dirname(__FILE__).DIRECTORY_SEPARATOR.'include';
set_include_path($incp);
require_once 'include/inspekt.php';
$superCage = Inspekt::makeSuperCage();
//load language
$config = array(); // (array) temp config
$config_file['temporary'] = 'include/config.tmp.php';
$config_file['permanent'] = 'include/config.inc.php';
$error = ''; // (string) holds errors
$temp_data; // holds various data
$page_title = ''; // (string) holds the title of the current installation step
// Check if install has already been done, else load temporary config.
loadTempConfig();
//load language
$language = getLanguage(); // (array) holds the language
$icon = array();
$icon['submit'] = '<img src="images/icons/right.png" border="0" alt="" width="16" height="16" class="icon" />';
$icon['lang'] = '<img src="images/icons/babelfish.png" border="0" alt="" width="16" height="16" class="icon" />';
$icon['test'] = '<img src="images/icons/reload.png" border="0" alt="" width="16" height="16" class="icon" />';
$icon['retry'] = '<img src="images/icons/reload.png" border="0" alt="" width="16" height="16" class="icon" />';
$icon['add'] = '<img src="images/icons/add.png" border="0" alt="" width="16" height="16" class="icon" />';
// get installation step
if ($superCage->get->keyExists('step') && isset($config['steps_done']) && is_array($config['steps_done'])
&& in_array($superCage->get->getInt('step'), $config['steps_done']))
{
$step = $superCage->get->getInt('step');
} else {
if (isset($config['step'])) {
$step = $config['step'];
} else {
$step = STEP_INIT_AND_LANG;
}
}
// check if we have an update instead of a next step request
if ($superCage->post->keyExists('update_lang')) {
$step = STEP_INIT_AND_LANG;
}
if ($superCage->post->keyExists('update_im_path')) {
$step = STEP_SELECT_IMG_PROC;
}
if ($superCage->post->keyExists('update_check_connection')) {
$step = STEP_DB_INFO;
}
if ($superCage->post->keyExists('update_create_db')) {
$step = STEP_DB_SELECT;
}
// if installation is done, only show last page
if (isset($config['install_finished'])) {
$step = STEP_FINALISE;
}
setTmpConfig('steps_done', $step, true);
// check if the installer has already been run succefully
if ($error != '') {
html_header();
html_installer_locked();
html_footer();
exit;
}
// check if we have new user input and put it in the temp config
if ($superCage->post->keyExists('thumb_method')) {
setTmpConfig('thumb_method', $superCage->post->getAlnum('thumb_method'));
}
if ($superCage->post->keyExists('im_path') &&
$superCage->post->getPath('im_path') !=
(dirname($superCage->server->getPath('SCRIPT_FILENAME') . DIRECTORY_SEPARATOR)))
{
$im_path = $superCage->post->getPath('im_path');
$im_path = str_replace('\\', '/', $im_path);
if (!preg_match('|[/\\\\]\Z|', $im_path)) {
$im_path .= '/';
}
setTmpConfig('im_path', $im_path);
}
switch($step) {
case STEP_INIT_AND_LANG: // Initialisation & natural language selection
//write a coockie to check in the next step
setcookie('cpg_install_cookie_check', 'passed', time() + 3600);
$page_title = $language['title_welcome'];
html_header();
html_welcome();
html_footer();
break;
case STEP_VERSIONCHECK: // Are all mandatory files there
// Here we also do an extensive version check of php + check of javascript/cookies/register_globals
// the cookie for this check is inserted in the previous step!
// javascript is tested by altering a hidden form element in the previous step.
//PHP VERSION CHECK
$php_version = phpversion();
if (version_compare($required_php_version, $php_version, '>=')) {
//check if php_version is actualy a version number
if ($php_version == '') {
//version could not be detected, show corresponding error
$error .= sprintf($language['version_undetected'], 'PHP', $required_php_version) . '<br />';
} else {
//user is using incompatible php version
$error .= sprintf($language['version_incompatible'], $php_version, 'PHP', $required_php_version) . '<br />';
}
}
//COOKIE CHECK
if ($superCage->cookie->getAlpha('cpg_install_cookie_check') != 'passed') {
//no cookie found, you're in trouble now :)
$error .= $language['no_cookie'] . '<br />';
}
//JAVASCRIPT CHECK
if ($superCage->post->keyExists('javascript_check') && $superCage->post->getAlpha('javascript_check') != 'passed' && !$config['javascript_test_passed']) {
//javascripts seems to be disabled, send them the message...
$error .= $language['no_javascript'] . '<br />';
} else {
$config['javascript_test_passed'] = true;
}
//REGISTER_GLOBALS CHECK
if (ini_get('register_globals')) {
//register_globals is turned on, please turn it of.
$error .= $language['register_globals_detected'];
$error .= '[<a href="https://coppermine-gallery.net/docs/curr/en/install.htm#install_server_config_register_globals">' . $language['more'] . '</a>]';
$error .= '<br />';
}
//XML PARSER CHECK
if (function_exists('simplexml_load_string') || function_exists('xml_parser_create')) {
$has_XML = true;
} else {
$has_XML = false;
$error = $language['no_xml_parser'] . '<br />';
}
$page_title = $language['title_file_check'];
html_header();
if ($error != '') {
html_error(false /*false to not include a button*/);
}
if ($has_XML) {
//use versioncheck to check file versions
$lang_versioncheck_php = $language['versioncheck'];
$lang_common = $language['lang_common'];
require_once 'include/versioncheck.inc.php';
// TODO: need to deal with connection failing and skip this step (and maybe allow a retry)
// Connect to the repository and populate the array with data from the XML file
$file_data_array = cpgVersioncheckConnectRepository($displayOption_array);
$file_data_array = cpg_versioncheckPopulateArray($file_data_array);
//$file_data_array = cpg_versioncheckPopulateArray($file_data_array, $displayOption_array, $textFileExtensions_array, $imageFileExtensions_array, $CONFIG, $maxLength_array, $lang_versioncheck_php);
$file_data_count = count($file_data_array);
// Print the results
$outputResult = cpg_versioncheckCreateHTMLOutput($file_data_array, $textFileExtensions_array, $lang_versioncheck_php, $majorVersion, $displayOption_array);
$versioncheck_output = sprintf($lang_versioncheck_php['files_folder_processed'], $outputResult['display'], $outputResult['total'], $outputResult['error']);
// TODO: end
html_content($versioncheck_output);
}
html_footer();
setTmpConfig('step', STEP_FOLDER_PERMISSIONS);
break;
case STEP_FOLDER_PERMISSIONS: // Check if the folder permissions are set up properly
$page_title = $language['title_dir_check'];
if (!checkPermissions()) {
// not all permissions were set correctly, or folder doesn't exist
html_header();
html_error();
html_content($language['perm_not_ok']); // show all checked folders?
html_footer();
} else {
// permissions are set alright, continue
html_header();
html_content($language['perm_ok']); // show all checked folders?
html_footer();
setTmpConfig('step', STEP_SELECT_IMG_PROC);
}
break;
case STEP_SELECT_IMG_PROC: // Check available image processors & let user choose
$page_title = $language['title_imp'];
$supported_processors = array('gd2' => "GD2", 'im' => 'ImageMagick', 'imx' => 'Imagick Extension');
$image_processors = checkImageProcessor();
html_header();
if ($error != '') {
html_error();
}
if( !($error != '' && !isset($image_processors['gd2'])) ) {
setTmpConfig('step', STEP_TEST_IMG_PROC);
}
$content = $language['im_packages'] . '<br />';
$imp_list = '<select name="thumb_method" class="listbox" size="1">';
if (isset($image_processors['gd2'])) {
// gd2 is avilable, add it to the list
$imp_list .= '<option value="gd2">GD2</option>';
$content .= '<strong>GDlib</strong> Version 2. <br />';
$selected = 'gd2';
}
// check configuration options of im_path
if (isset($image_processors['im'])) {
// im is available, add it to the list
$path = str_replace(array('.exe', '"'), '',$image_processors['im']['path']);
$path = substr($path, 0, (strlen($path) - 7));
$imp_list .= '<option value="im">ImageMagick</option>';
$content .= '<strong>ImageMagick</strong> Version ' . substr($image_processors['im']['version'], 20, 7) . '(at: ' . $path .')<br />';
if($error == ''){
$selected = 'im';
}
$im_not_found = '';
} else {
$path = '';
$im_not_found = '<br /><fieldset style="width:90%" title="ImageMagick">' . $language['im_not_found'] .'</fieldset>';
}
if (isset($image_processors['imx'])) {
// Imagick extension is avilable, add it to the list and make it default
$imp_list .= '<option value="imx">Imagick Extension</option>';
$content .= '<strong>Imagick Extension</strong> '.$image_processors['imx'].'<br />';
$selected = 'imx';
}
// check configuration options
if (isset($config['thumb_method'])) $selected = $config['thumb_method'];
$imp_list .= '</select>';
$imp_list = str_replace($selected . '"', $selected . '" selected="selected"', $imp_list);
// if no image library is found, tell the user so, and select gd2
if (!isset($selected)) {
$content .= '<br /><fieldset style="width:90%" title="GD">' . $language['no_gd'] . '</fieldset><br />' . $im_not_found;
} else {
$content .= '<br />' . $language['installer_selected'] . ' \'' . $supported_processors[$selected] . '\'<br />' . $imp_list . $im_not_found;
}
// add IM path box
if (isset($config['im_path'])
&& $superCage->post->getPath('im_path') !=
(dirname($superCage->server->getPath('SCRIPT_FILENAME') . DIRECTORY_SEPARATOR)))
{
$path = $config['im_path'];
}
$content .= '<br />' . $language['im_path']
. '<br /><input type="text" class="textinput" name="im_path" value="'
. $path . '" /><button type="submit" class="button" name="update_im_path" value="'
. $language['check_path'] . '">'
. $icon['test'] . $language['check_path'] . '</button>';
html_content($content);
html_footer();
break;
case STEP_TEST_IMG_PROC: // Check if the image library information has been set up properly - display some basic test images created with the image library selected
$page_title = $language['title_imp_test'];
html_header();
$content = '<center>' . testImageProcessor() . '</center>';
if ($error != '') {
html_error();
} else {
setTmpConfig('step', STEP_DB_INFO);
}
html_content($content);
html_footer();
break;
case STEP_DB_INFO: // Ask user for database type, host, username and password, try to establish a connection using that info
$db_type = $superCage->post->getRaw('db_type');
if (!isset($db_type)) {
$db_type = $config['db_type'];
} else {
setTmpConfig('db_type', $db_type);
}
list($dext, $dsub) = explode(':', $db_type.':');
if ($db_type) require_once 'include/database/'.$dext.'/install.php';
$page_title = $language['title_dbase_user'];
// check if we are trying to test the connection
if ($superCage->post->keyExists('update_check_connection')
|| (isset($config['db_host']) && $superCage->post->keyExists('db_host')))
{
// here we do not use the setTmpConfig funtion, as this function always writes the new file
// and it will be written in the third step...
$config['db_host'] = $superCage->post->getRaw('db_host');
$config['db_user'] = $superCage->post->getRaw('db_user');
setTmpConfig('db_password', $superCage->post->getRaw('db_password'));
// test the connection
$con_check = 'check'.ucfirst($dext).'Connection';
$con_check($dsub);
}
html_header();
if ($error != '') {
html_error(false /*false to not include a button*/);
} else {
if (isset($config['db_password'])) {
setTmpConfig('step', STEP_DB_SELECT);
}
}
html_dbase_start($db_type);
html_footer();
break;
case STEP_DB_SELECT: // Ask the user if he wants to use an existing db or if he wants the installer to create a new database. Try to perform the selected choice. Ask for the table prefix
$db_type = $config['db_type'];
list($dext, $dsub) = array_pad(explode(':', $db_type), 2, '');
require_once 'include/database/'.$dext.'/install.php';
$page_title = sprintf($language['title_dbase_db_sel'], strtoupper($db_type));
// save the db data from previous step
if ($superCage->post->keyExists('db_host') && !isset($config['db_populated'])) {
// here we do not use the setTmpConfig function, as this function always writes the new file
// and it will be written in the third step...
$config['db_host'] = $superCage->post->getRaw('db_host');
$config['db_user'] = $superCage->post->getRaw('db_user');
setTmpConfig('db_password', $superCage->post->getRaw('db_password'));
if ($error != '') {
$error .= '<br />' . sprintf($language['please_go_back'], '<a href="install.php?step=' . ($step - 1) . '">', '</a>');
}
} elseif ($superCage->post->keyExists('update_create_db')
&& trim($superCage->post->getRaw('new_db_name')) != '')
{
// try to create a new database.
$createDb = 'create'.ucfirst($dext).'Db';
$createDb(trim($superCage->post->getRaw('new_db_name'))); // no /\:*?"<>|.
// save table prefix
setTmpConfig('db_prefix', $superCage->post->getRaw('db_prefix')); // no /\:*?"<>|.
}
$con_check = 'check'.ucfirst($dext).'Connection';
$con_check($dsub);
html_header();
if ($error != '') {
html_error();
} else {
$html_select_db = 'html_'.$dext.'_select_db';
$html_select_db($dsub);
setTmpConfig('step', STEP_DB_INIT);
}
html_footer();
break;
case STEP_DB_INIT: // save db_prefix/_name and finally create the tables
$db_type = $config['db_type'];
list($dext, $dsub) = explode(':', $db_type.':');
require_once 'include/database/'.$dext.'/install.php';
$page_title = $language['title_dbase_pop'];
// save the db data from previous step
if ($superCage->post->keyExists('db_name') && !isset($config['db_populated'])) {
setTmpConfig('db_name', $superCage->post->getRaw('db_name'));
setTmpConfig('db_prefix', $superCage->post->getRaw('db_prefix'));
}
// populate db if not done yet
$set_populated = false;
if (!isset($config['db_populated']) && isset($config['db_name'])) {
$msg = $language['db_populating'];
if (populateDatabase()) {
$set_populated = true;
}
} elseif (!isset($config['db_populated']) && !isset($config['db_name'])) {
$msg = sprintf($language['not_here_yet'], '<strong><a href="install.php?step=7">', '</a></strong>');
}
if (isset($config['db_populated'])) {
html_header();
if ($error != '') {
html_error();
}
$temp_data = '<tr><td><br /><br />' . $language['db_alr_populated']
. '<br /><br /></td></tr>';
html_content($language['db_populating']);
html_footer();
setTmpConfig('step', STEP_SET_ADMIN);
} else {
if ($set_populated) {
// this is a lock to see if the db has been created yet
setTmpConfig('db_populated', 'done');
setTmpConfig('step', STEP_SET_ADMIN);
}
html_header();
if ($error != '') {
html_error();
}
html_content($msg);
html_footer();
break;
}
break;
case STEP_SET_ADMIN: // Ask for coppermine admin username, password and email address
$db_type = $config['db_type'];
list($dext, $dsub) = explode(':', $db_type.':');
require_once 'include/database/'.$dext.'/install.php';
$page_title = $language['title_admin'];
if ($superCage->post->keyExists('admin_username')) {
// check validity of admin details
$admin_username = $superCage->post->getMatched('admin_username', '/\A\w*\Z/');
if ($admin_username[0] == '' || !$admin_username) {
// admin username not correct
$error .= $language['user_err'] . '<br />';
} else {
setTmpConfig('admin_username', $admin_username[0]);
}
// we need a db connection to use getEscaped()
$con_check = 'check'.ucfirst($dext).'Connection';
$con_check($dsub);
$admin_password = $superCage->post->getEscaped('admin_password');
$admin_password_verif = $superCage->post->getEscaped('admin_password_verif');
if ($admin_password != $admin_password_verif || $admin_password == '') {
// admin password not correct
$error .= $language['pass_err'] . '<br />';
} else {
setTmpConfig('admin_password', $superCage->post->getEscaped('admin_password'));
}
$email = $superCage->post->getMatched('admin_email', '/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i');
$ver_email = $superCage->post->getMatched('admin_email_verif', '/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i');
if ($email[0] != $ver_email[0] || $email[0] == '') {
// admin email not correct
$error .= $language['email_no_match'] . '<br />';
} else {
setTmpConfig('admin_email', $email[0]);
}
}
if (isset($config['admin_username']) && isset($config['admin_password']) && isset($config['admin_email']) && !isset($config['install_finished'])) {
// create admin
if (createAdmin()) {
// add finished flag to config
setTmpConfig('install_finished', 'done');
$step = 10;
$page_title = $language['title_finished'];
}
}
html_header();
if ($error != '') {
html_error();
} else {
if (isset($config['install_finished'])) {
setTmpConfig('step', STEP_FINALISE);
finaliseInstall();
html_finish();
} else {
html_admin();
}
}
html_footer();
break;
case STEP_FINALISE: // Finally check if everything is set up properly and tell the user so
finaliseInstall();
$page_title = $language['title_finished'];
html_header();
if ($error != '') {
html_error();
}
html_finish();
html_footer();
break;
}
function finaliseInstall ()
{
// write real config file
writeConfig();
// delete temp config + created test images!!
$files_to_remove = array(
'albums/combined_generated.jpg',
'albums/giftest_generated.gif',
'albums/giftest_generated.jpg',
'albums/jpgtest_generated.jpg',
'albums/pngtest_generated.jpg',
'albums/pngtest_generated.png',
'albums/scaled_generated.jpg',
'albums/texttest_generated.jpg',
'include/config.tmp.php',
);
foreach ($files_to_remove as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
########################
####Install Templates###
########################
/* html_header()
*
* prints the header
*/
function html_header()
{
global $language;
header('Cache-Control: no-cache');
echo <<<EOT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<title>Coppermine - {$language['installation']}</title>
<link rel="stylesheet" href="css/installer.css" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<div align="center">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td valign="top" style="background-color:#EFEFEF"><img src="images/coppermine-logo.png" width="260" height="60" border="0" alt="" /><br />
</td>
</tr>
</table>
EOT;
html_stepper();
}
// end function html_header
/* html_footer()
*
* prints the footer
*/
function html_footer()
{
echo <<<EOT
</div>
</div>
</body>
</html>
<noscript><plaintext>
EOT;
}
// end function html_footer
/* html_stepper()
*
* prints current installation step with links to the next ones
*/
function html_stepper()
{
global $config, $page_title, $step, $language;
$stepper = '';
$tpl_step_done = '<td class="stepper_d" onMouseOver="this.className=\'stepper_do\'" onMouseOut="this.className=\'stepper_d\'" onclick="document.location=\'install.php?step=%s\'"><a href="install.php?step=%s" title="Step: %s">%s</a></td>';
$tpl_step_current = '<td class="stepper_c"><span title="Step: %s">%s</span></td>';
$tpl_step_notyet = '<td class="stepper_n"><span title="Step: %s">%s</span></td>';
for($i = 1; $i < 11; $i++) {
if ($i == $step) {
$stepper .= sprintf($tpl_step_current, $i, $i);
} elseif (isset($config['steps_done']) && is_array($config['steps_done']) && in_array($i, $config['steps_done'])) {
$stepper .= sprintf($tpl_step_done, $i, $i, $i, $i);
} else {
$stepper .= sprintf($tpl_step_notyet, $i, $i);
}
}
print <<< EOT
<table class="stepper_table">
<tr>
<td>{$stepper}</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableh1" colspan="2"><h2>{$page_title}</h2></td>
</tr>
</table>
EOT;
}
/* html_installer_locked()
*
* prints the error when the installer is locked
*/
function html_installer_locked()
{
global $language, $error, $icon;
print <<< EOT
<form action="index.php" style="margin:0px;padding:0px" name="cpgform" id="cpgform">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableh1" colspan="2"><h2>{$language['installer_locked']}</h2>
</td>
</tr>
<tr>
<td class="tableh2" colspan="2"><h3 class="error">{$language['error']}</h3>
</td>
</tr>
<tr>
<td class="tableb" colspan="2">{$error}
</td>
</tr>
<tr>
<td colspan="2" align="center" class="tableb">
<button type="submit" class="button" name="submit" value="{$language['go_to_main']}">{$language['go_to_main']}{$icon['submit']}</button>
</td>
</tr>
</table>
</form>
EOT;
}
/* html_welcome()
*
* prints the welcome message at the start of installation + language selection
*/
function html_welcome()
{
global $language, $error, $icon;
if (!setTmpConfig('step', STEP_VERSIONCHECK)) {
$next_step = STEP_INIT_AND_LANG;
} else {
$next_step = STEP_VERSIONCHECK;
}
print <<< EOT
<br />
<form action="install.php?step={$next_step}" name="cpgform" id="cpgform" method="post" style="margin:0px;padding:0px">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableh1" colspan="2">
<h2>{$language['license']}</h2>
</td>
</tr>
<tr>
<td class="tableb" colspan="2">
{$language['license_info']}
</td>
</tr>
<tr>
<td class="tableb" colspan="2">
<iframe src="https://coppermine-gallery.net/docs/curr/en/copyrights.htm?hide_nav=1" width="100%" height="300" name="license">
{$language['cpg_info_frames']}</a>.
</iframe>
</td>
</tr>
</table>
<br />
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
EOT;
if ($error != '') {
print <<< EOT
<tr>
<td class="tableh2" colspan="2" align="left"><span class="error">{$language['error']}</span>
</td>
</tr>
<tr>
<td class="tableb" colspan="2">{$language['error_need_corr']}<br /><strong>{$error}</strong>
</td>
</tr>
EOT;
}
$getLangSelect = getLangSelect();
print <<< EOT
<tr>
<td class="tableh1" colspan="2"><strong>{$language['select_lang']}</strong>
</td>
</tr>
<tr>
<td class="tableb" align="center" colspan="2">
{$getLangSelect}
<button type="submit" class="button" name="update_lang" value="{$language['change_lang']}">{$icon['lang']}{$language['change_lang']}</button>
</td>
</tr>
<tr>
<td colspan="2" align="center" class="tableh2"><br />
<button type="submit" class="button" name="submit" value="{$language['lets_go']}">{$language['lets_go']}{$icon['submit']}</button>
</td>
</tr>
</table>
<input type="hidden" name="javascript_check" value="failed" />
</form>
<!-- This code will check if javascript is enabled -->
<script type="text/javascript">
<!--
document.forms[0][3].value = "passed";
-->
</script>
EOT;
}
/* html_content()
*
* prints standard page with variable content
*/
function html_content($content)
{
global $language, $step, $temp_data, $icon;
$step_next = $step + 1;
echo <<<EOT
<form action="install.php?step={$step_next}" name="cpgform" id="cpgform" method="post" style="margin:0px;padding:0px">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableb" colspan="2">{$content}<br /><br /></td>
</tr>
EOT;
if ($temp_data != '') {
echo $temp_data;
}
echo <<<EOT
<tr>
<td colspan="2" align="center" class="tableh2"><br />
<button type="submit" class="button" name="submit" value="{$language['continue']}">{$language['continue']}{$icon['submit']}</button>
</td>
</tr>
</table>
</form>
EOT;
}
// end function html_content
/* html_error()
*
* prints error message
*
* @param boolean $button
*/
function html_error($button = true)
{
global $language, $step, $error, $icon;
print <<< EOT
<form action="install.php?step={$step}" name="cpgform" id="cpgform" method="post" style="margin:0px;padding:0px">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableh2" colspan="2" align="left"><span class="error">{$language['error']}</span>
</td>
</tr>
<tr>
<td class="tableb" colspan="2">{$language['error_need_corr']}<br /><strong>{$error}</strong>
</td>
</tr>
EOT;
if ($button) {
print <<< EOT
<tr>
<td colspan="2" align="center" class="tableh2">
<button type="submit" class="button" name="try_again" value="{$language['try_again']}">{$icon['retry']}{$language['try_again']}</button>
</td>
</tr>
EOT;
}
print <<< EOT
</table>
</form>
EOT;
}
/* html_dbase_start()
*
* prints page with basic database config
*/
function html_dbase_start($type=null)
{
global $language, $step, $dbase_connected, $config, $icon;
$step_next = $step + 1;
$slct = $type ?: 'mysqli';
require_once 'include/dbselect.inc.php';
$dbselect = new DbaseSelect();
echo <<<EOT
<form action="install.php?step={$step_next}" name="cpgform" id="cpgform" method="post" style="margin:0px;padding:0px">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableb" colspan="2">
{$language['sect_dbase_info']}<br />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td align="right">Database Type</td>
<td><select name="db_type">{$dbselect->options($slct)}</select></td>
</tr>
EOT;
if ($dbase_connected) {
echo <<<EOT
<tr>
<td></td>
<td align="left"><div class="cpg_message_success">{$language['dbase_succ']}</div></td>
</tr>
EOT;
}
$db_host = isset($config['db_host']) && $dbase_connected ? $config['db_host'] : 'localhost';
$db_user = isset($config['db_user']) && $dbase_connected ? $config['db_user'] : '';
$db_password = isset($config['db_password']) && $dbase_connected ? $config['db_password'] : '';
echo <<<EOT
<tr>
<td align="right">{$language['dbase_host']}</td>
<td><input type="text" class="textinput" name="db_host" value="$db_host" /></td>
</tr>
<tr>
<td align="right">{$language['dbase_username']}</td>
<td><input type="text" class="textinput" name="db_user" value="$db_user" /></td>
</tr>
<tr>
<td align="right">{$language['dbase_password']}</td>
<td><input type="password" name="db_password" value="$db_password" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="submit" class="button" name="update_check_connection" value="{$language['dbase_test_connection']}">{$icon['test']}{$language['dbase_test_connection']}</button>
</td>
</tr>
EOT;
if ($dbase_connected) {
echo <<<EOT
<tr>
<td colspan="2" align="center" class="tableh2">
<button type="submit" class="button" name="submit" value="{$language['continue']}">{$language['continue']}{$icon['submit']}</button>
</td>
</tr>
EOT;
} else {
echo <<<EOT
<tr>
<td colspan="2" align="center" class="tableh2"> <br /></td>
</tr>
EOT;
}
echo <<<EOT
</table>
</form>
EOT;
}
// end function html_dbase_start
/* html_admin()
*
* prints page for admin details
*/
function html_admin()
{
global $language, $step, $icon;
$admin_username = isset($config['admin_username']) ? $config['admin_username'] : '';
$admin_password = isset($config['admin_password']) ? $config['admin_password'] : '';
// TODO: check verify field in $config to see if checked against password
$admin_password_verify = isset($config['admin_password']) ? $config['admin_password'] : '';
$admin_email = isset($config['admin_email']) ? $config['admin_email'] : '';
// TODO: ditto above
$admin_email_verify = isset($config['admin_email']) ? $config['admin_email'] : '';
echo <<<EOT
<form action="install.php?step={$step}" name="cpgform" id="cpgform" method="post" style="margin:0px;padding:0px">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<td class="tableb" colspan="2">
{$language['sect_create_adm']}<br />
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td align="right">{$language['username']}</td>
<td><input type="text" class="textinput" name="admin_username" value="$admin_username" /></td>
</tr>
<tr>
<td align="right">{$language['password']}</td>
<td><input type="password" name="admin_password" value="$admin_password" /></td>
</tr>
<tr>
<td align="right">{$language['password_verif']}</td>
<td><input type="password" name="admin_password_verif" value="$admin_password_verify" /></td>
</tr>
<tr>
<td align="right">{$language['email']}</td>
<td><input type="text" class="textinput" name="admin_email" value="$admin_email" /></td>
</tr>
<tr>
<td align="right">{$language['email_verif']}</td>
<td><input type="text" class="textinput" name="admin_email_verif" value="$admin_email_verify" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="center" class="tableh2">
<button type="submit" class="button" name="submit" value="{$language['continue']}">{$language['continue']}{$icon['submit']}</button>
</td>
</tr>
</table>