public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / install / install.php
100644 958 lines (822 sloc) 34.705 kb
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
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
function test_cfg_var_bool( $name, $desc, $success, $row = 'row2' )
{
  $icon = 'false.gif';
  $alt = 'Failure';
  $ret = false;
  
  $str = (bool) ini_get( $name );
  $str = ($str) ? 1 : 0;
  if( $success == $str )
    {
      $icon = 'true.gif';
      $alt = 'Success';
      $ret = true;
    }
 
  echo "<tr class=\"$row\"><td>$desc have $str</td><td class=\"col2\">";
  echo "<img src=\"../images/cms/install/$icon\" alt=\"$alt\" height=\"16\" width=\"16\" border=\"0\" />";
  echo "</td></tr>\n";
  return $ret;
}
 
function test_cfg_var_range( $name, $desc, $yellowlimit, $greenlimit, $row = 'row2' )
{
  $icon = 'red.gif';
  $alt="Failure";
  $ret = false;
  if( is_int( $yellowlimit ) && is_int( $greenlimit ) )
    {
      $str = (int) ini_get( $name );
      if( $str >= $greenlimit )
  {
   $alt = 'Success';
   $icon = 'green.gif';
   $ret = true;
  }
      else if( $str >= $yellowlimit )
  {
   $alt = 'Caution';
   $icon = 'yellow.gif';
   $ret = true;
  }
    }
  else
    {
      $warning = "";
      $str = strtoupper(ini_get( $name ));
      if( $str == "" )
  {
   $str = $yellowlimit;
   $warning = "Could not retrieve a value.... passing anyways";
  }
      if( strcmp( $str, $yellowlimit ) >= 0 )
  {
   $alt = 'Caution';
   $icon = 'yellow.gif';
   $ret = true;
  }
      if( strcmp( $str, $greenlimit ) >= 0 )
  {
   $alt = 'Success';
   $icon = 'green.gif';
   $ret = true;
  }
    }
  echo "<tr class=\"$row\"><td>$desc have \"$str\"";
  if( isset( $warning ) && $warning != "" )
    {
      echo "<br/>$warning";
    }
  echo "</td><td class=\"col2\">";
  echo "<img src=\"../images/cms/install/$icon\" alt=\"$alt\" height=\"16\" width=\"16\" border=\"0\" />";
  echo "</td></tr>\n";
  return $ret;
}
 
$LOAD_ALL_MODULES=1;
require(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'fileloc.php');
 
$config = CONFIG_FILE_LOCATION;
if (!file_exists($config)) {
    $file = @fopen($config, "w");
    if ($file != 0) {
    $cwd = addslashes(dirname(dirname(__FILE__)));
        fwrite($file,"<?php\n".'$config[\'root_path\'] = "'.$cwd.'";'."\n?>\n");
        fclose($file);
    } else {
        echo "Cannot create $config, please change permissions to allow this\n";
        exit;
    } ## if
} ## if
else if (filesize($config) == 0) {
    $file = @fopen($config, "w");
    if ($file != 0) {
      $cwd = addslashes(dirname(dirname(__FILE__)));
      fwrite($file,"<?php\n".'$config[\'root_path\'] = "'.$cwd.'";'."\n?>\n");
      fclose($file);
    } else {
      echo "Cannot modify $config, please change permissions to allow this\n";
      exit;
    } ## if
}
 
$pages = 4;
if (isset($_POST["page"])) {
    $currentpage = $_POST["page"];
} elseif (isset($_GET["page"])) {
    $currentpage = $_GET["page"];
} else {
    $currentpage = 1;
} ## if
 
$DONT_LOAD_DB = true;
 
if ($currentpage > 1) { require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include.php"); }
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CMS Made Simple Install</title>
<link rel="stylesheet" type="text/css" href="install.css" />
<script src="../admin/themes/default/includes/standard.js" type="text/javascript"></script>
</head>
 
<body>
 
<div class="body">
 
<img src="../images/cms/cmsbanner.jpg" width="800" height="100" alt="CMS Banner Logo" />
 
<div class="headerish">
 
<h1>Install System</h1>
 
</div>
 
<div class="main">
<?php
 
echo "<h2>Thanks for installing CMS Made Simple</h2>\n";
echo "<table class=\"countdown\" cellspacing=\"2\" cellpadding=\"2\"><tr>";
echo "<td><img src=\"../images/cms/install/".($currentpage>=1?"1":"1off").".gif\" alt=\"Step 1\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage>=2?"2":"2off").".gif\" alt=\"Step 2\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage>=3?"3":"3off").".gif\" alt=\"Step 3\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage>=4?"4":"4off").".gif\" alt=\"Step 4\" /></td>";
echo "<td><img src=\"../images/cms/install/".($currentpage>=5?"5":"5off").".gif\" alt=\"Step 5\" /></td>";
echo "</tr></table>\n";
echo "<br />";
 
 
switch ($currentpage) {
    case 1:
        showPageOne();
        break;
    case 2:
        showPageTwo();
        break;
    case 3:
        showPageThree();
        break;
    case 4:
        showPageFour();
        break;
    case 5:
        showPageFive();
        break;
    default:
        echo "You were supposed to turn <a href=\"install.php\">right</a> at Alberquerque.<p>\n";
        break;
} ## switch
 
function showPageOne() {
  ## test file permissions
  ## apache (or other webserver) user needs to have write access to the cache and template_c dirs
  ## as well as the cms root for config.php to be created.
 
  ## find the user running this script
  #$userid = posix_getuid();
  #$userdata = posix_getpwuid($userid);
  #$username = $userdata['name'];
 
  ## echo "Userid ($userid) is named $username is running this script<p>\n";
 
  ## check file perms
  $continueon = true;
  echo "<h3>Checking permissions and PHP settings</h3>\n";
  #$files = array(TMP_CACHE_LOCATION, TMP_TEMPLATES_C_LOCATION, dirname(dirname(__FILE__)).'/uploads', CONFIG_FILE_LOCATION);
  $files = array(TMP_CACHE_LOCATION, TMP_TEMPLATES_C_LOCATION, CONFIG_FILE_LOCATION, dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads' );
 
  // legend
  echo "<table class=\"regtable\" border=\"1\">\n";
  echo "<thead class=\"tbhead\"><tr><th>Symbol</th><th>Definition</th><tr></thead>\n";
  echo "<tbody>\n";
  echo '<tr><td><img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" /></td><td>A required test passed</td></tr>';
  echo '<tr><td><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" /></td><td>A required test failed</td></tr>';
  echo '<tr><td><img src="../images/cms/install/red.gif" alt="Failure" height="16" width="16" border="0" /></td><td>A setting is below a required minumum value</td></tr>';
  echo '<tr><td><img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" /></td><td>A setting is above the required value, but below the recommended value<br /><br />or... A capability that <em>may</em> be required for some optional functionality is unavailable</p></td></tr>';
  echo '<tr><td><img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" /></td><td>A setting meets or exceeds the recommended threshhold<br /><br />or... A capability that <em>may</em> be required for some optional functionality is available</td></tr>';
  echo "</tbody>\n";
  echo "</table><br/>\n";
 
  // body
  echo "<table class=\"regtable\" border=\"1\">\n";
  echo "<thead class=\"tbhead\"><tr><th>Test</th><th>Result</th></tr></thead><tbody>\n";
 
  echo "<tr class=\"row1\"><td>Checking for PHP version 4.2+</td><td class=\"col2\">";
  echo (@version_compare(phpversion(),"4.2.0") > -1?'<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />':'<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />');
  (@version_compare(phpversion(),"4.2.0") > -1?null:$continueon=false);
  echo "</td></tr>\n";
    
  echo "<tr class=\"row2\"><td>Checking for Session Functions</td><td class=\"col2\">";
  if (function_exists("session_start"))
    {
      echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
    }
  else
    {
      echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
      $continueon = false;
    }
  echo "</td></tr>\n";
    
  echo "<tr class=\"row1\"><td>Checking for md5 Function</td><td class=\"col2\">";
  if (function_exists("md5"))
    {
      echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
    }
  else
    {
      echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
      $continueon = false;
    }
  echo "</td></tr>\n";
    
  echo "<tr class=\"row2\"><td>Checking for tokenizer functions</td><td class=\"col2\">";
  if (function_exists("token_get_all"))
    {
      echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
    }
  else
    {
      echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
      $continueon = false;
    }
  echo "</td></tr>\n";
 
  $currow = "row1";
  $continueon &= test_cfg_var_range( "memory_limit", "Checking PHP memory limit (min 12M, recommend 16M)", "12M", "16M", $currow );
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
  $continueon &= test_cfg_var_range( "max_input_time", "Checking max input time (min 45s, recommend 60s)", 45, 60, $currow );
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
  $continueon &= test_cfg_var_range( "max_execution_time", "Checking max execution time (min 30s, recommend 45s)", 30, 45, $currow );
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
  $continueon &= test_cfg_var_bool( "file_uploads", "Checking file uploads (require on)", 1, $currow );
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
  $continueon &= test_cfg_var_range( "upload_max_filesize", "Checking max upload file size (min 2M)", "2M", "10M", $currow );
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
 
  // do we have the file_get_contents function
  echo "<tr class=\"$currow\"><td>Checking for file_get_contents<br/><br/>
<em>The file_get_contents function was added in PHP 4.3 and although a workaround has been added that should allow most functionality that uses this function to work properly in PHP 4.2, it may be advisable to upgrade to PHP 4.3 or greater.</em>
</td><td class=\"col2\">";
  if (function_exists("file_get_contents"))
    {
      echo '<img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" />';
    }
  else
    {
      echo '<img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" />';
    }
  echo "</td></tr>\n";
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
 
  // can we set a php ini variable
  echo "<tr class=\"$currow\"><td>Checking if ini_set works<br/><br/>
<em>Although the ability to override php ini settings is not mandatory, some addon (optional) functionality uses ini_set to extend timeouts, and allow uploading of larger files, etc. You may have difficulty with some addon functionality without this capability.</em>
</td><td class=\"col2\">";
  ini_set( 'max_execution_time', '123' );
  if( ini_get('max_execution_time') == 123 )
    {
      echo '<img src="../images/cms/install/green.gif" alt="Success" height="16" width="16" border="0" />';
    }
  else
    {
      echo '<img src="../images/cms/install/yellow.gif" alt="Caution" height="16" width="16" border="0" />';
    }
  echo "</td></tr>\n";
  $currow = ($currow == 'row1') ? 'row2' : 'row1';
  
  $special_failed=false;
  foreach ($files as $f) {
    #echo "<tr><td>\n";
    ## check if we can write to the this file
    echo "<tr class=\"$currow\"><td>Checking write permission on $f";
      
    //special check for modules dir
    if ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules' && !is_writable($f))
      {
  echo '<br /><br /><em>Modules is not writable. You can still install the system, but you will not be able to install modules via the admin panel.</em>';
  $special_failed=true;
      }
      
    //special check for uploads dir
    if ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads' && !is_writable($f))
      {
  echo '<br /><br /><em>Uploads is not writable. You can still install the system, but you will not be able to upload files via the admin panel.</em>';
  $special_failed=true;
      }
    echo "</td><td class=\"col2\">";
      
    if (is_writable($f))
      {
  echo '<img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
      } else {
  
      //special check for modules dir
      if (!(($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules') || ($f == dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'uploads')))
  {
   $continueon=false;
  }
  
      echo '<img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
    } ## if
    echo "</td></tr>\n";
    ($currow=="row1"?$currow="row2":$currow="row1");
  } ## foreach
    
  echo "<tr class=\"$currow\"><td>Checking if session.save_path is set and writable";
  if (session_save_path() == '')
    {
      echo '<br /><br /><em>session.save_path is not set. Not having a session.save_path disallows any logins to the admin panel. Please adjust before continuing..</em>';
      echo '</td><td class=\"col2\"><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
      $continueon = false;
    }
  else
    {
      if (is_writable(session_save_path()))
  {
   echo '</td><td class="col2"><img src="../images/cms/install/true.gif" alt="Success" height="16" width="16" border="0" />';
  }
      else
  {
   echo '<br /><br /><em>session.save_path("'.session_save_path().'") is not writable. Not having this as writable disallows any logins to the admin panel. Please adjust before continuing..</em>';
   echo '</td><td class="col2"><img src="../images/cms/install/false.gif" alt="Failure" height="16" width="16" border="0" />';
   $continueon = false;
  }
    }
  echo "</td></tr>\n";
    
  echo "</tbody></table>\n";
    
  echo '<form method="post" action="install.php">';
    
  if ($continueon)
    {
      if($special_failed) {
  echo '<p class="failure" align="center">One or more tests have failed. You can still install the system but some functions may not work correctly. Please click the Continue button.</p>';
      } else {
  echo '<p class="success" align="center">All tests passed (at least at a minimum level). Please click the Continue button.</p>';
      }
      echo '<p class="continue" align="center"><input type="hidden" name="page" value="2" /><input class="defaultfocus" type="submit" value="Continue" /></p>';
    }
  else
    {
      echo '<p class="failure" align="center">One or more tests have failed. Please correct the problem and click the button below to recheck.</p>';
      echo '<p class="continue" align="center"><input class="defaultfocus" type="Submit" value="Try Again" /></p>';
    }
  echo '</form>';
 
} ## showPageOne
 
function showPageTwo($errorMessage='',$username='',$email='')
{
 
  if ($errorMessage != '')
  {
    echo "<p class=\"error\">$errorMessage</p>";
  }
  ?>
 
<h3>Admin Account Information</h3>
 
<p>
Select the username, password and email address for your admin account. Please make sure you record this password somewhere, as
there will be no other way to login to your CMS Made Simple admin system without it.
</p>
 
<form action="install.php" method="post" name="page2form" id="page2form">
 
<table cellpadding="2" border="1" class="regtable">
 
  <tr class="row1">
    <td>Username</td>
    <td><input class="defaultfocus" type="text" name="adminusername" value="<?php echo $username?>" size="20" maxlength="50" /></td>
  </tr>
 
  <tr class="row2">
    <td>Email Address</td>
    <td><input type="text" name="adminemail" value="<?php echo $email?>" size="20" maxlength="50" /></td>
  </tr>
 
  <tr class="row1">
    <td>Password</td>
    <td><input type="password" name="adminpassword" value="" size="20" maxlength="50" /></td>
  </tr>
 
  <tr class="row2">
    <td>Password Again</td>
    <td><input type="password" name="adminpasswordagain" value="" size="20" maxlength="50" /></td>