-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
1240 lines (1098 loc) · 60.7 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
/*
This file is part of OTSCMS (http://www.otscms.com/) project.
Copyright (C) 2005 - 2008 Wrzasq ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
header('Content-Type: text/html; charset=utf-8');
$version = '3.1.3';
// to make sure OTSCMS will run correctly on various PHP configurations
include('compat.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OTSCMS installation</title>
<style type="text/css">
body
{
font-family: "Verdana", "Tahoma", sans-serif;
}
#wrapper
{
font-size: 12px;
background-color: #CCCCCC;
width: 95%;
padding: 5px;
margin: 20px;
border: 1px solid #000000;
}
.hint
{
font-style: italic;
font-size: 8px;
text-align: justify;
margin: 5px;
text-indent: 15px;
}
#pageFooter
{
font-size: 14px;
width: 100%;
text-align: center;
}
.critical
{
color: #FF0000;
}
.critical p
{
text-indent: 30px;
text-align: justify;
}
.critical p:first-letter
{
size: 20px;
font-weight: bold;
}
pre
{
color: #000000;
border: 1px solid #000000;
background-color: #FFFFFF;
padding: 3px;
width: 90%;
margin: 3px;
}
.code
{
font-family: monospace;
}
table
{
width: 100%;
}
.formLeft
{
width: 50%;
text-align: right;
}
.formRight
{
width: 50%;
text-align: left;
}
td[colspan]
{
width: 100%;
text-align: center;
}
.bold
{
font-weight: bold;
}
</style>
</head>
<body>
<div id="wrapper">
<?php
// by default server is fine
$matches = true;
$phpIni = false;
$winOS = strtolower( substr(PHP_OS, 0, 3) ) == 'win';
// displays requirement
function requiredFeature($label, $text)
{
echo '<div class="critical">
<h3>' . $label . '</h3>
<p>' . $text . '</p>
</div>';
}
// creates index.php files inside all sub directories
function indexDirectory($destination)
{
// full index.php file path
$file = $destination . 'index.php';
// saves index.php file, but not everwrites existing one
if( !file_exists($file) )
{
// saves file
echo '@ Creating : ' . $file . '<br />'."\n";
file_put_contents($file, '<?php
// redirects to upper-directory
header(\'Location: ../\');
?>');
}
else
{
echo '@ ' . $file . ' already exists<br />' . "\n";
}
// indexes also all sub-directories
$dir = opendir($destination);
while($current = readdir($dir) )
{
// checks if those are directories, but not symbols of upper directory
if( is_dir($destination . $current) && $current != '.' && $current != '..' && is_writeable($destination . $current) )
{
// if it's a directory then create index.php file there too
indexDirectory($destination . $current . '/');
}
}
}
// deletes a directory reccurently
function deleteDirectory($source)
{
echo '@ Deleting: ' . $source . '<br />' . "\n";
// copies all source directory files and sub-directories
$dir = opendir($source);
while($new = readdir($dir) )
{
// checks if those are not symbols of upper directory
if($new != '.' && $new != '..')
{
// if it's a directory the remove it reccurently too
if( is_dir($source.$new) )
{
if( !deleteDirectory($source . $new . '/') )
{
echo '- Could not delete directory: ' . $source . $new . '/<br />' . "\n";
return false;
}
}
// otherwise jsut copy a file
else
{
if( !@unlink($source . $new) )
{
echo '- Could not delete file: ' . $source . $new . '<br />' . "\n";
return false;
}
echo '@ Deleted file: ' . $source . $new . '<br />' . "\n";
}
}
}
// creates destination directory
rmdir($source);
echo '@ Deleted directory: ' . $source . '<br />' . "\n";
// returns that directory coping succeeded
return true;
}
// checks PHP version
if( version_compare(PHP_VERSION, '5.2.0', '<') )
{
$matches = false;
requiredFeature('Outdated PHP version', 'PHP version installed on your server is ' . PHP_VERSION . '. OTSCMS requires version at least 5.2. You can download latest PHP version from <a href="http://www.php.net/">php.net</a>.');
}
// checks if SPL is enabled
if( !extension_loaded('SPL') )
{
// filename depended on platform
$file = $winOS ? 'php_spl.dll' : 'spl.so';
$matches = false;
requiredFeature('Missing SPL extension', 'OTSCMS requires SPL (Standard PHP Library) PHP extension for running. You must enable it in your <span class="code">php.ini</span> file by adding following line:</p>
<pre class="code">extension=' . $file . '</pre>
<p>It\'s probably out there already, but commented by semicolon (<span class="code">;</span>). After enabling this extension, save <span class="code">php.ini</span> file and restart server.' . ($phpIni ? '' : '</p>
<p>Make sure you are editing correct <span class="code">php.ini</span> file as in some server packages there can be more then one files. Correct one is usualy the one that is in Apache\'s <span class="code">bin/</span> directory (where Apache executables are placed).'));
$phpIni = true;
}
// checks if PDO is enabled
if( !extension_loaded('PDO') )
{
// filename depended on platform
$file = $winOS ? 'php_pdo.dll' : 'pdo.so';
$matches = false;
requiredFeature('Missing PDO extension', 'OTSCMS requires PDO (PHP Data Objects) PHP extension for running. You must enable it in your <span class="code">php.ini</span> file by adding following line:</p>
<pre class="code">extension=' . $file . '</pre>
<p>It\'s probably out there already, but commented by semicolon (<span class="code">;</span>). After enabling this extension, save <span class="code">php.ini</span> file and restart server.</p>
<p>Also PDO drivers for your database type are required so if you know which one you will use, enable it too (OTSCMS will tell you to do so later if you won\'t do it now).' . ($phpIni ? '' : '</p>
<p>Make sure you are editing correct <span class="code">php.ini</span> file as in some server packages there can be more then one files. Correct one is usualy the one that is in Apache\'s <span class="code">bin/</span> directory (where Apache executables are placed).'));
$phpIni = true;
}
// checks if GD is enabled
if( !extension_loaded('gd') )
{
// filename depended on platform
$file = $winOS ? 'php_gd2.dll' : 'gd.so';
requiredFeature('Missing GD extension', 'OTSCMS uses PHP GD extension for Gallery module. If you want to use this module, uou must enable GD in your <span class="code">php.ini</span> file by adding following line:</p>
<pre class="code">extension=' . $file . '</pre>
<p>It\'s probably out there already, but commented by semicolon (<span class="code">;</span>). After enabling this extension, save <span class="code">php.ini</span> file and restart server.' . ($phpIni ? '' : '</p>
<p>Make sure you are editing correct <span class="code">php.ini</span> file as in some server packages there can be more then one files. Correct one is usualy the one that is in Apache\'s <span class="code">bin/</span> directory (where Apache executables are placed).'));
$phpIni = true;
}
// checks if PCRE is enabled
if( !extension_loaded('pcre') )
{
// filename depended on platform
$file = $winOS ? 'php_pcre.dll' : 'pcre.so';
$matches = false;
requiredFeature('Missing PCRE extension', 'OTSCMS requires PCRE (Perl Compatible Regular Expressions) PHP extension for running. You must enable it in your <span class="code">php.ini</span> file by adding following line:</p>
<pre class="code">extension=' . $file . '</pre>
<p>It\'s probably out there already, but commented by semicolon (<span class="code">;</span>). After enabling this extension, save <span class="code">php.ini</span> file and restart server.' . ($phpIni ? '' : '</p>
<p>Make sure you are editing correct <span class="code">php.ini</span> file as in some server packages there can be more then one files. Correct one is usualy the one that is in Apache\'s <span class="code">bin/</span> directory (where Apache executables are placed).'));
$phpIni = true;
}
// checks if mod_rewrite is enabled
if( function_exists('apache_get_modules') )
{
if( !in_array('mod_rewrite', apache_get_modules() ) )
{
$matches = false;
requiredFeature('Missing mod_rewrite module', 'OTSCMS requires mod_rewrite Apache module for running. You must enable it in your <span class="code">httpd.conf</span> file by adding following line:</p>
<pre class="code">LoadModule rewrite_module modules/mod_rewrite.so</pre>
<p>It\'s probably out there already, but commented by hash (<span class="code">#</span>). After enabling this extension, save <span class="code">httpd.conf</span> file and restart server.');
}
}
// checking if config.php file is writable
if(!(( file_exists('config.php') && is_writable('config.php') ) || ( !file_exists('config.php') && is_writeable('.') ) ))
{
$matches = false;
requiredFeature('<span class="code">config.php</span> is not writeable', 'OTSCMS can\'t write to configuration file. Setup will save startup database connection configuration in that file. Note that usualy user under which OTSCMS runs is the user under which HTTP server is running and usualy it\'s not the same as you, or your FTP user. To make it writeable for OTSCMS execute following command in your command line:</p>
<pre class="code">touch config.php && chmod 777 config.php</pre>
<p>If you are running on Windows then check file properties.');
}
// we can proceed to installation steps
if($matches)
{
$command = '';
// reads command
if( isset($_REQUEST['command']) )
{
$command = $_REQUEST['command'];
}
switch($command)
{
// detailed database configuration
case 'database':
$db = array();
// loads data from config.lua
if( !empty($_FILES['lua']['name']) )
{
preg_match_all('/^([a-z0-9_]+) *= *"?(.*?)"?$/mi', file_get_contents($_FILES['lua']['tmp_name']), $lua);
$lua = array_combine($lua[1], $lua[2]);
// loads certain info
if( isset($lua['sql_type']) )
{
switch($lua['sql_type'])
{
case 'mysql':
$db['type'] = 'MySQL';
break;
case 'sqlite':
$db['type'] = 'SQLite';
break;
case 'pgsql':
$db['type'] = 'PostgreSQL';
break;
}
}
if( isset($lua['sql_host']) )
{
$db['host'] = $lua['sql_host'];
}
if( isset($lua['sql_user']) )
{
$db['user'] = $lua['sql_user'];
}
if( isset($lua['sql_port']) )
{
$db['port'] = $lua['sql_port'];
}
if( isset($lua['sql_pass']) )
{
$db['password'] = $lua['sql_pass'];
}
if( isset($lua['sql_db']) )
{
$db['database'] = $lua['sql_db'];
}
if( isset($lua['passwordtype']) )
{
$password_type = $lua['passwordtype'];
}
if( isset($lua['map'], $lua['mapkind']) && $lua['mapkind'] == 'OTBM')
{
$mapfile = basename($lua['map']);
}
$online = array();
if( isset($lua['worldname']) )
{
$online['name'] = $lua['worldname'];
}
if( isset($lua['ip']) )
{
$online['content'] = $lua['ip'];
}
if( isset($lua['port']) )
{
$online['port'] = $lua['port'];
}
}
// overwrites settings by user choice
if( isset($_REQUEST['db']) )
{
$db['type'] = $_REQUEST['db']['type'];
}
// checks if database type is supported
if( !in_array($db['type'], array('MySQL', 'SQLite', 'PostgreSQL') ) )
{
requiredFeature('Unsupported database type', 'OTSCMS supports MySQL, SQLite and PostrgeSQL databases. Your database type <span class="code">' . $db['type'] . '</span> is not supported, sorry. Make sure you have selected driver from list, or contact OTSCMS developers on <a href="http://otfans.net/forumdisplay.php?f=112">OTSCMS forum</a> posting your request to support this database type.');
}
// checks PDO driver
elseif( !extension_loaded( strtolower('pdo_' . $db['type']) ) )
{
// filename depended on platform
$file = $winOS ? 'php_pdo_' . $db['type'] . '.dll' : 'pdo_' . $db['type'] . '.so';
requiredFeature('Missing PDO driver', 'PDO driver for your database type is not loaded. PDO itself is only data access interface, it requires drivers to connect to certain type of database. You must enable it in your <span class="code">php.ini</span> file by adding following line:</p>
<pre class="code">extension=' . $file . '</pre>
<p>It\'s probably out there already, but commented by semicolon (<span class="code">;</span>). After enabling this extension, save <span class="code">php.ini</span> file and restart server.' . ($phpIni ? '' : '</p>
<p>Make sure you are editing correct <span class="code">php.ini</span> file as in some server packages there can be more then one files. Correct one is usualy the one that is in Apache\'s <span class="code">bin/</span> directory (where Apache executables are placed).'));
}
// continues
else
{
?>
<form action="install.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="command" value="account" />
<input type="hidden" name="db[type]" value="<?php echo $db['type']; ?>" />
<?php if( isset($online['name']) ): ?>
<input type="hidden" name="online[name]" value="<?php echo $online['name']; ?>" />
<?php endif; ?>
<?php if( isset($online['content']) ): ?>
<input type="hidden" name="online[content]" value="<?php echo $online['content']; ?>" />
<?php endif; ?>
<?php if( isset($online['port']) ): ?>
<input type="hidden" name="online[port]" value="<?php echo $online['port']; ?>" />
<?php endif; ?>
<table>
<tbody>
<?php switch($db['type']): ?>
<?php case 'MySQL': ?>
<tr>
<td class="formLeft">MySQL server:</td>
<td class="formRight">
<input type="text" name="db[host]" value="<?php echo isset($db['host']) ? $db['host'] . ( isset($db['port']) && $db['port'] != '3306' ? ':' . $db['port'] : '') : 'localhost'; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">MySQL user:</td>
<td class="formRight">
<input type="text" name="db[user]" value="<?php echo isset($db['user']) ? $db['user'] : 'root'; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">Password:</td>
<td class="formRight">
<input type="text" name="db[password]" value="<?php echo isset($db['password']) ? $db['password'] : ''; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">Database name:</td>
<td class="formRight">
<input type="text" name="db[database]" value="<?php echo isset($db['database']) ? $db['database'] : 'otserv'; ?>" />
</td>
</tr>
<?php break; ?>
<?php case 'SQLite': ?>
<tr>
<td class="formLeft">Path to database file:</td>
<td class="formRight">
<input type="text" name="db[host]" value="/path/to/otserv/<?php echo isset($db['db']) ? $db['db'] : 'db.s3db'; ?>" />
</td>
</tr>
<input type="hidden" name="db[user]" value="" />
<input type="hidden" name="db[password]" value="" />
<input type="hidden" name="db[database]" value="" />
<?php break; ?>
<?php case 'PostgreSQL': ?>
<tr>
<td class="formLeft">PostgreSQL server:</td>
<td class="formRight">
<input type="text" name="db[host]" value="<?php echo isset($db['host']) ? $db['host'] . ( isset($db['port']) && $db['port'] != '5432' ? ':' . $db['port'] : '') : 'localhost'; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">PostgreSQL user:</td>
<td class="formRight">
<input type="text" name="db[user]" value="<?php echo isset($db['user']) ? $db['user'] : ''; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">Password:</td>
<td class="formRight">
<input type="text" name="db[password]" value="<?php echo isset($db['password']) ? $db['password'] : ''; ?>" />
</td>
</tr>
<tr>
<td class="formLeft">Database name:</td>
<td class="formRight">
<input type="text" name="db[database]" value="<?php echo isset($db['database']) ? $db['database'] : 'otserv'; ?>" />
</td>
</tr>
<?php break; ?>
<?php endswitch; ?>
<tr>
<td class="formLeft">Password saving mechanism:
<p class="hint">This is not an OPTION - it must correspond with your OTServ setting!</p>
</td>
<td class="formRight">
<label><input type="radio" name="password_type" value="plain"<?php echo !isset($password_type) || $password_type == 'plain' ? ' checked="checked"': ''; ?> />Plain (no hashing)</label><br />
<label><input type="radio" name="password_type" value="md5"<?php echo isset($password_type) && $password_type == 'md5' ? ' checked="checked"': ''; ?> />MD5 hash</label><br />
<label><input type="radio" name="password_type" value="sha1"<?php echo isset($password_type) && $password_type == 'sha1' ? ' checked="checked"': ''; ?> />SHA1 hash</label><br />
</td>
</tr>
<tr>
<td class="formLeft">data/ directory path:</td>
<td class="formRight">
<input type="text" name="data_directory" value="/path/to/data/" />
</td>
</tr>
<tr>
<td class="formLeft">Map filename:</td>
<td class="formRight">
<input type="text" name="mapfile" value="<?php echo isset($mapfile) ? $mapfile : 'map.otbm'; ?>" />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Proceed" /></td>
</tr>
<?php
if( !isset($_GET['advanced']) )
{
?>
<tr id="advanced_button">
<td colspan="2">
<a href="install.php?advanced" onclick="var advanced_settings = document.getElementById('advanced_settings').style; advanced_settings.display = 'table'; advanced_settings.visibility = 'visible'; this.parentNode.removeChild(this); return false;">Advanced options</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<table id="advanced_settings"<?php if( !isset($_GET['advanced']) ) { echo ' style="display: none; visibility: hidden;"'; } ?>>
<tbody>
<tr>
<td class="formLeft">Should install directory be deleted after installation:</td>
<td class="formRight">
<label><input type="checkbox" name="del_install" />Delete</label>
</td>
</tr>
<tr>
<td class="formLeft">Prefix for <span style="font-weight: bold;">OTSCMS</span> tables (we recommend to leave it as it is):</td>
<td class="formRight">
<input type="text" name="db[cms_prefix]" value="otscms_" />
</td>
</tr>
<tr>
<td class="formLeft">Prefix for <span style="font-weight: bold;">OTServ</span> tables (we recommend to leave it as it is - type only if you use one! Leave empty if you don't know what it is!):</td>
<td class="formRight">
<input type="text" name="db[ots_prefix]" value="" />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Proceed" /></td>
</tr>
</tbody>
</table>
</form>
<?php
}
break;
// detailed installation info
case 'account':
// pre-loads HTTP data
$db = $_POST['db'];
// install scheme
if( !file_exists('Install/' . $db['type'] . '.sql') )
{
requiredFeature('Missing installation schema', 'Installation schema file is missing. Please copy installation schemas (<span class="code">Install/</span> directory) from OTSCMS Lite package to your OTSCMS directory.');
break;
}
// fix for POT
if($db['type'] == 'SQLite')
{
$db['database'] = $db['host'];
}
// loads database handler file
$config['db'] = $db;
$config['directories']['classes'] = 'classes/';
require_once('classes/OTSCMS.php');
POT::getInstance();
try
{
$sql = new SQL($db['host'], $db['user'], $db['password'], $db['database'], $db['cms_prefix'], $db['ots_prefix']);
}
catch(PDOException $e)
{
requiredFeature('Database connection error', 'Could not connect to database. PDO returned following message:</p>
<pre class="code">' . $e->getMessage() . '</pre>
<p>You can continue installation on your own risk, but we recommend you to check database information.');
}
?>
<form action="install.php" method="post">
<input type="hidden" name="command" value="install" />
<input type="hidden" name="db[type]" value="<?php echo $db['type']; ?>" />
<input type="hidden" name="db[host]" value="<?php echo $db['host']; ?>" />
<input type="hidden" name="db[user]" value="<?php echo $db['user']; ?>" />
<input type="hidden" name="db[password]" value="<?php echo $db['password']; ?>" />
<input type="hidden" name="db[database]" value="<?php echo $db['database']; ?>" />
<input type="hidden" name="db[cms_prefix]" value="<?php echo $db['cms_prefix']; ?>" />
<input type="hidden" name="db[ots_prefix]" value="<?php echo $db['ots_prefix']; ?>" />
<input type="hidden" name="mapfile" value="<?php echo $_POST['mapfile']; ?>" />
<input type="hidden" name="data_directory" value="<?php echo $_POST['data_directory']; ?>" />
<input type="hidden" name="del_install" value="<?php echo isset($_POST['del_install']) && $_POST['del_install'] ? '1' : '0'; ?>" />
<input type="hidden" name="password_type" value="<?php echo $_POST['password_type']; ?>" />
<?php if( isset($_POST['online']['name']) ): ?>
<input type="hidden" name="online[name]" value="<?php echo $_POST['online']['name']; ?>" />
<?php endif; ?>
<?php if( isset($_POST['online']['content']) ): ?>
<input type="hidden" name="online[content]" value="<?php echo $_POST['online']['content']; ?>" />
<?php endif; ?>
<?php if( isset($_POST['online']['port']) ): ?>
<input type="hidden" name="online[port]" value="<?php echo $_POST['online']['port']; ?>" />
<?php endif; ?>
<table>
<tbody>
<tr>
<td class="formLeft">Create new GameMaster account:
<p class="hint">This is usefull when you have empty database as this will allow you to log into OTSCMS administration panel. You don't need it if you install OTSCMS on already running OTServ database with existing GameMaster players.</p>
</td>
<td class="formRight">
<input type="checkbox" name="create_gm" value="1" checked="checked" onclick="document.getElementById('gm_account').disabled = !this.checked; document.getElementById('gm_password').disabled = !this.checked; document.getElementById('gm_name').disabled = !this.checked;" />
</td>
</tr>
<tr>
<td class="formLeft">Account number:</td>
<td class="formRight">
<input type="text" name="gm_account" id="gm_account" value="111111" />
</td>
</tr>
<tr>
<td class="formLeft">Password:</p>
</td>
<td class="formRight">
<input type="text" name="gm_password" id="gm_password" value="tibia" />
</td>
</tr>
<tr>
<td class="formLeft">Nick:</p>
</td>
<td class="formRight">
<input type="text" name="gm_name" id="gm_name" value="OTSCMS" />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Install" /></td>
</tr>
</table>
</form>
<?php
break;
// final installation
case 'install':
echo '<pre class="code">';
// pre-loads HTTP data
$db = $_POST['db'];
// install scheme
$install = file_get_contents('Install/' . $db['type'] . '.sql');
// loads database handler file
$config['db'] = $db;
$config['directories']['classes'] = 'classes/';
require_once('classes/OTSCMS.php');
POT::getInstance();
$sql = new SQL($db['host'], $db['user'], $db['password'], $db['database'], $db['cms_prefix'], $db['ots_prefix']);
// current query
$step = 0;
$last = 0;
// installs database scheme
for($i = 0; $i < strlen($install); $i++)
{
// one level deeper
if( strtoupper( substr($install, $i, 5) ) == 'BEGIN')
{
$step++;
$i += 4;
}
// one level finished
if( strtoupper( substr($install, $i, 4) ) == 'END;')
{
$step--;
$i += 2;
}
// checks if current query is finished
if(!$step && $install[$i] == ';')
{
// reads last query and moves pointer after it
$query = trim( substr($install, $last, $i - $last) );
$last = $i + 1;
try
{
$sql->exec($query);
}
catch(PDOException $e)
{
// ignore DROP queries and ALTER queries on existing collumns
if( strtoupper( substr($query, 0, 4) ) != 'DROP' && !( strtoupper( substr($query, 0, 5) ) == 'ALTER' && stripos( $e->getMessage(), 'duplicate column name') !== false))
{
echo '<span class="critical,bold">- Error during executing SQL query:<br />
' . $query . '<br />
returned:<br />
' . $e . '</span></pre>' . "\n";
break 2;
}
}
}
}
echo '<span class="bold">+ Database scheme installed</span><br />' . "\n";
try
{
// inserts database startup content
$sql->beginTransaction();
// startup GM account
if( isset($_POST['create_gm']) && $_POST['create_gm'])
{
// POT initialization
$driver = array('MySQL' => POT::DB_MYSQL, 'SQLite' => POT::DB_SQLITE, 'PostgreSQL' => POT::DB_PGSQL);
$db['driver'] = $driver[ $db['type'] ];
$db['prefix'] = $db['ots_prefix'];
$ots = POT::getInstance();
$ots->connect(null, $db);
// generates password hash
switch($_POST['password_type'])
{
default:
$_POST['password_type'] = 'plain';
case 'plain':
$password = $_POST['gm_password'];
break;
case 'md5':
$password = md5($_POST['gm_password']);
break;
case 'sha1':
$password = sha1($_POST['gm_password']);
break;
}
// GM account
$account = new OTS_Account();
$account->create($_POST['gm_account'], $_POST['gm_account']);
$account->blocked = false;
$account->password = $_POST['gm_password'];
$account->save();
echo '+ GM account created<br />' . "\n";
// searches for GM group
$filter = new OTS_SQLFilter();
$filter->compareField('access', 3, OTS_SQLFilter::OPERATOR_NLOWER);
// loads user group
$list = new OTS_Groups_List();
$list->filter = $filter;
// GM gorup
if( count($list) > 0)
{
$list->rewind();
$group = $list->current();
}
// creates new group
else
{
$group = new OTS_Group();
$group->name = 'OTSCMS';
$group->access = 3;
$group->maxDepotItems = 1000;
$group->maxVIPList = 50;
$group->save();
echo 'GameMasters group not found, created new one<br />' . "\n";
}
// creates GM character
$player = new OTS_Player();
$player->account = $account;
$player->group = $group;
$player->name = $_POST['gm_name'];
$player->setRank();
$player->townId = 1;
$player->conditions = '';
$player->save();
echo '+ GM character created<br />' . "\n";
}
// default OTS server for online statistics
if( isset($_POST['online']['name'], $_POST['online']['content'], $_POST['online']['port']) )
{
$online = $_POST['online'];
$query = $sql->prepare('INSERT INTO [online] (`name`, `content`, `port`) VALUES (:name, :content, :port)');
$query->execute( array(':name' => $online['name'], ':content' => $online['content'], ':port' => $online['port']) );
}
// home website
$query = $sql->prepare('INSERT INTO [sites] (`name`, `content`, `is_home`) VALUES (:name, :content, 1)');
$query->execute( array(':name' => 'OTSCMS credits', ':content' => '<p class="justified">
Describe of your site can goes here. You can edit this text in administration panel.
</p>
<p class="justified">
<b>OTSCMS</b> uses <a href="http://otserv-aac.info/">PHP OTServ Toolkit</a>. While writing extensions for <b>OTSCMS</b> you can use any code written with <b>POT</b>!
</p>
<p class="justified">
There are many people who contributed with our team in developing this project.
</p>
<p class="justified">
Mainly great thans to <b>Foziw</b> for the domain and <b>Yorick</b> for forum!
</p>
<h3>OTSCMS Dev-Team members</h3>
<ul>
<li><b>Wrzasq</b> - Project headmaster, engine, porting and developing, <i>Default</i> skin, website.</li>
</ul>
<h3>OTSCMS version 3 developement</h3>
<ul>
<li><b>Foziw</b> - Project supporter, beta tester, bug finder.</li>
<li><b>Invincible Aznx</b> - Hosting (<a href="http://www.invinciblehost.com/" class="outLink">http://www.invinciblehost.com/</a>).</li>
<li><b>Brave</b> - Helps with "<i>Players Online</i>" script.</li>
<li><b>Chester</b> - Website design.</li>
<li><b>Yorick</b> - Advertising, forum.</li>
<li><b>LooSik</b> - Helps with design.</li>
<li><b>Katten</b> - Code for XML output formating.</li>
<li><b>Ada GT</b> - For help in hard moment by reminding rule "if you don\'t understant, then fuck it" :P.</li>
<li><b>Joddo</b> - Help, POT bugfix.</li>
<li><b>Reks</b> - Beta tester.</li>
<li><b>Winghawk</b> - Beta tester.</li>
<li><b>Slash X</b> - Beta tester.</li>
<li><b>Empty Flask</b> - Beta tester.</li>
<li><b>Rupo</b> - Beta tester.</li>
<li><b>Master-m</b> - Beta tester.</li>
<li><b>Mistik</b> - Beta tester.</li>
<li><b>Morpheus</b> - Beta tester.</li>
<li><b>Critias</b> - Beta tester.</li>
<li><b>FCKEditor</b> - WYSIWYG controll (<a href="http://www.fckeditor.net/" class="outLink">FCK Editor</a>).</li>
</ul>
<h3>OTSCMS version 2 developement</h3>
<ul>
<li><b>Jascman</b> - Some bugfixes.</li>
<li><b>Gabbe</b> - Helps with fixing bugs.</li>
<li><b>GregStar</b> - Critical bug reported and helped fixing it.</li>
</ul>
<h3>OTSCMS version 1 developement</h3>
<ul>
<li><b>Ashganek</b> - Old forum.</li>
<li><b>GriZzmO</b> - Helps with MySQL driver for OTServ database.</li>
<li><b>Erl</b> - Dutch translation.</li>
<li><b>Nuker</b> - Dutch translation.</li>
<li><b>Crismac</b> - Spanish (Chile) translation.</li>
<li><b>Tiago Martines</b> - Portuguese (Brazil) translation.</li>
<li><b>K-Zodron</b> - Swedish translation.</li>
<li><b>Rasmus</b> - English translation fixes.</li>
<li><b>Escman</b> - Portuguese translation fixes.</li>
<li><b>Anarkus Furi</b> - Some portuguese translation fixes.</li>
<li><b>Mroczny_Mis</b> - Technical consultation.</li>
<li><b>FF Wrapzone</b> - "<i>Default</i>" skin (downloaded from <a href="http://www.freelayouts.com/" class="outLink">http://www.freelayouts.com/</a>).</li>
<li><b>Bryan007</b> - Remote OTSCMS tester.</li>
<li><b>Jason</b> - <i>GenX</i> theme.</li>
<li><b>Mick</b> - Helps with MySQL driver for OTServ database, translation fixes.</li>
<li><b>Adki</b> - Designer, port of <a href="http://webmark.shost.pl/" class="outLink">WebMark</a> <i>Multi CSS</i> skin.</li>
<li><b>Katten</b> - Some bugfixes.</li>
<li><b>Anjek</b> - Portuguese (Brazil) translation.</li>
</ul>
<h3>OTSCMS version 0 developement</h3>
<ul>
<li><b>Maniacx86</b> - some bugfixes.</li>
<li><b>Heepee</b> - some minor bugfixes.</li>
<li><b>Sufixx</b> - tester, bug finder.</li>
<li><b>Tibiaboy15</b> - old translation into Dutch.</li>
<li><b>Rozek</b> - technical consultation.</li>
</ul>') );
$query = $sql->prepare('INSERT INTO [settings] (`name`, `content`) VALUES (:name, :content)');
$query->execute( array(':name' => 'version', ':content' => $version) );
$query->execute( array(':name' => 'directories.languages', ':content' => 'languages/') );
$query->execute( array(':name' => 'directories.modules', ':content' => 'modules/') );
$query->execute( array(':name' => 'directories.skins', ':content' => 'skins/') );
$query->execute( array(':name' => 'directories.images', ':content' => 'images/') );
$query->execute( array(':name' => 'directories.data', ':content' => $_POST['data_directory']) );
$query->execute( array(':name' => 'cookies.prefix', ':content' => 'otscms_') );
$query->execute( array(':name' => 'cookies.path', ':content' => '/') );
$query->execute( array(':name' => 'cookies.domain', ':content' => '.example.com') );
$query->execute( array(':name' => 'cookies.expire', ':content' => 2592000) );
$query->execute( array(':name' => 'system.passwords', ':content' => $_POST['password_type']) );
$query->execute( array(':name' => 'system.use_mail', ':content' => false) );
$query->execute( array(':name' => 'system.nick_length', ':content' => 3) );
$query->execute( array(':name' => 'system.default_group', ':content' => 1) );
$query->execute( array(':name' => 'system.min_number', ':content' => 0) );
$query->execute( array(':name' => 'system.max_number', ':content' => 999999) );
$query->execute( array(':name' => 'system.account_limit', ':content' => 5) );
$query->execute( array(':name' => 'system.map', ':content' => $_POST['mapfile']) );
$query->execute( array(':name' => 'system.rook.enabled', ':content' => false) );
$query->execute( array(':name' => 'system.rook.id', ':content' => 0) );
$query->execute( array(':name' => 'system.depots.count', ':content' => 2) );
$query->execute( array(':name' => 'system.depots.item', ':content' => 2590) );
$query->execute( array(':name' => 'system.depots.chest', ':content' => 2594) );
$query->execute( array(':name' => 'statistics.page', ':content' => 30) );
$query->execute( array(':name' => 'site.language', ':content' => 'english') );
$query->execute( array(':name' => 'site.skin', ':content' => 'Default') );
$query->execute( array(':name' => 'site.title', ':content' => 'Powered by OTSCMS 3 - http://www.otscms.com/') );
$query->execute( array(':name' => 'site.date_format', ':content' => 'j F Y G:i') );
$query->execute( array(':name' => 'site.news_limit', ':content' => 5) );
$query->execute( array(':name' => 'gallery.mini_x', ':content' => 100) );
$query->execute( array(':name' => 'gallery.mini_y', ':content' => 100) );
$query->execute( array(':name' => 'forum.limit', ':content' => 20) );
$query->execute( array(':name' => 'forum.avatar.max_x', ':content' => 80) );
$query->execute( array(':name' => 'forum.avatar.max_y', ':content' => 80) );
$query->execute( array(':name' => 'mail.from', ':content' => '[email protected]') );
$query->execute( array(':name' => 'mail.smtp.host', ':content' => 'localhost') );
$query->execute( array(':name' => 'mail.smtp.port', ':content' => 25) );
$query->execute( array(':name' => 'mail.smtp.use_auth', ':content' => false) );
$query->execute( array(':name' => 'mail.smtp.user', ':content' => '') );
$query->execute( array(':name' => 'mail.smtp.password', ':content' => '') );
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'OTSCMS\', \'http://otscms.com/\')');
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'OTFans\', \'http://otfans.net/\')');
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'PHP OTServ Toolkit\', \'http://otserv-aac.info/\')');
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'Open Tibia Server List\', \'http://www.otservlist.org/\')');
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'OTServ News\', \'http://www.otservnews.org/\')');
$sql->exec('INSERT INTO [links] (`name`, `content`) VALUES (\'OTWiki\', \'http://otserv.org/\')');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Access.*\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.*\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.account\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.change\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.create\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.forgot\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.login\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.password\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.remind\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.save\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.signup\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Account.suspend\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.*\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.change\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.create\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.delete\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.display\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.insert\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Character.save\', 0)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Download.*\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Download.download\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Download.list\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Forum.*\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Forum.board\', -1)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Gallery.edit\', 3)');
$sql->exec('INSERT INTO [access] (`name`, `content`) VALUES (\'Gallery.insert\', 3)');