b9e25b4a790e8477ecfc45167c2df66f473d490d
[acontent.git] / docs / install / include / step4.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14
15 if (isset($_POST['submit'])) {
16         $_POST['content_dir'] = $stripslashes($_POST['content_dir']);
17
18         unset($errors);
19
20         if (!file_exists($_POST['content_dir']) || !realpath($_POST['content_dir'])) {
21                 $errors[] = '<strong>Content Directory</strong> entered does not exist.';
22         } else if (!is_dir($_POST['content_dir'])) {
23                 $errors[] = '<strong>Content Directory</strong> is not a directory.';
24         } else if (!is_writable($_POST['content_dir'])){
25                 $errors[] = 'The Content Directory is not writable.';
26         } else {
27
28                 $_POST['content_dir'] = realpath(urldecode($_POST['content_dir']));
29
30                 if (!is_dir($_POST['content_dir'].'/import')) {
31                         if (!@mkdir($_POST['content_dir'].'/import')) {
32                                 $errors[] = '<strong>'.$_POST['content_dir'].'/import</strong> directory does not exist and cannot be created.';  
33                         }
34                 } else if (!is_writable($_POST['content_dir'].'/import')){
35                         $errors[] = '<strong>'.$_POST['content_dir'].'/import</strong> directory is not writable.';
36                 } 
37
38                 if (!is_dir($_POST['content_dir'].'/updater')) {
39                         if (!@mkdir($_POST['content_dir'].'/updater')) {
40                                 $errors[] = '<strong>'.$_POST['content_dir'].'/updater</strong> directory does not exist and cannot be created.';  
41                         }
42                 } else if (!is_writable($_POST['content_dir'].'/updater')){
43                         $errors[] = '<strong>'.$_POST['content_dir'].'/updater</strong> directory is not writable.';
44                 }
45
46                 // content directory for the default HowTo lesson
47                 if (!is_dir($_POST['content_dir'].'/1')) {
48                         if (!@mkdir($_POST['content_dir'].'/1')) {
49                                 $errors[] = '<strong>'.$_POST['content_dir'].'/1</strong> directory does not exist and cannot be created.';  
50                         }
51                 } else if (!is_writable($_POST['content_dir'].'/1')){
52                         $errors[] = '<strong>'.$_POST['content_dir'].'/1</strong> directory is not writable.';
53                 }
54
55                 // save blank index.html pages to those directories
56                 @copy('../images/index.html', $_POST['content_dir'] . '/import/index.html');
57                 @copy('../images/index.html', $_POST['content_dir'] . '/index.html');
58         }
59
60         if (!isset($errors)) {
61                 unset($errors);
62                 unset($_POST['submit']);
63                 unset($action);
64
65                 if (substr($_POST['content_dir'], -1) !='\\'){
66                         $_POST['content_dir'] .= DIRECTORY_SEPARATOR;
67                 }
68
69                 // kludge to fix the missing slashes when magic_quotes_gpc is On
70                 if ($addslashes != 'mysql_real_escape_string') {
71                         $_POST['content_dir'] = addslashes($_POST['content_dir']);
72                 }
73
74                 store_steps($step);
75                 $step++;
76                 return;
77         } else {
78                 // kludge to fix the missing slashes when magic_quotes_gpc is On
79                 if ($addslashes != 'mysql_real_escape_string') {
80                         $_POST['content_dir'] = addslashes($_POST['content_dir']);
81                 }
82         }
83 }       
84
85 print_progress($step);
86
87 if (isset($errors)) {
88         print_errors($errors);
89 }
90
91 if (isset($_POST['step1']['old_version'])) 
92 {
93         //get real path to old content
94
95         $old_install   = realpath('../../' . DIRECTORY_SEPARATOR . $_POST['step1']['old_path']);
96         $old_config_cd = urldecode($_POST['step1']['content_dir']); // this path may not exist
97         $new_install   = realpath('../');
98
99         $path_info = pathinfo($old_config_cd);
100         $content_dir_name = $path_info['basename'];
101
102         if ($new_install . DIRECTORY_SEPARATOR . $content_dir_name . DIRECTORY_SEPARATOR == $old_config_cd) {
103                 // case 2
104                 $copy_from     = $old_install . DIRECTORY_SEPARATOR . $content_dir_name;
105         } else {
106                 // case 3 + 4
107                 // it's outside
108                 $copy_from = '';
109         }
110
111         $_defaults['content_dir'] = $old_config_cd;
112
113 }
114 else
115 {
116         $defaults = $_defaults;
117         $blurb = '';
118         
119         // the following code checks to see if get.php is being executed, then sets $_POST['get_file'] appropriately:
120         $headers = array();
121         $path  = substr($_SERVER['PHP_SELF'], 0, -strlen('install/install.php')) . 'get.php/?test';
122         $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
123         
124         $host = parse_url($_SERVER['HTTP_HOST']);
125         
126         if (isset($host['path'])) {
127                 $host = $host['path'];
128         } else if (isset($host['host'])) {
129                 $host = $host['host'];
130         } else {
131                 $_SERVER['HTTP_HOST'];
132         }
133         if ($port == 443) {
134                 // if we're using SSL, but don't know if support is compiled into PHP:
135                 $fd = @fopen('https://'.$host.$path, 'rb');
136                 print('https://'.$host.$path);
137                 if ($fd === false) {
138                         $content = false;
139                 } else {
140                         $content = @fread($fd, filesize($filename));
141                         @fclose($fd);
142                 }
143         
144                 if (strlen($content) == 0) {
145                         $headers[] = 'Trans-Get: OK';
146                 } else {
147                         $headers[] = '';
148                 }
149         } else {
150                 $fp   = @fsockopen($host, $port, $errno, $errstr, 15);
151                 
152                 if($fp) {
153                         $head = 'HEAD '.@$path. " HTTP/1.0\r\nHost: ".@$host."\r\n\r\n";
154                         fputs($fp, $head);
155                         while(!feof($fp)) {
156                                 if ($header = trim(fgets($fp, 1024))) {
157                                         $headers[] = $header;
158                                 }
159                         }
160                 }
161         }
162         
163         if (in_array('Trans-Get: OK', $headers)) {
164                 $get_file = 'TRUE';
165         } else {
166                 $get_file = 'FALSE';
167         }
168 }
169
170 ?>
171 <br />
172 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
173         <input type="hidden" name="step" value="<?php echo $step; ?>" />
174         <input type="hidden" name="copy_from" value="<?php echo $copy_from; ?>" />
175         <input type="hidden" name="get_file" value="<?php echo $get_file; ?>" />
176         <?php print_hidden($step); ?>
177
178 <?php if (isset($_POST['step1']['old_version'])) : ?>
179         <input type="hidden" name="content_dir" value="<?php echo $_defaults['content_dir']; ?>" />
180         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
181         <tr>
182                 <td class="row1">The content directory at <strong><?php echo $_defaults['content_dir']; ?> </strong> will be used for this installation. Please create it if it does not already exist.</td>
183         </tr>
184         </table>
185 <?php elseif ($get_file == 'FALSE') : ?>
186         <input type="hidden" name="content_dir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" />
187
188         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
189         <tr>
190                 <td class="row1"><div class="required" title="Required Field">*</div><strong><label for="contentdir">Content Directory</label></strong>
191                 <p>It has been detected that your webserver does not support the protected content directory feature. The content directory stores all of the content files.</p>
192                 <p>Due to that restriction your content directory must exist within your AContent installation directory and cannot be moved. Its path is specified below. Please create it if it does not already exist.</p>
193                 <br /><br />
194                 <input type="text" name="content_dir_disabled" id="contentdir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" class="formfield" size="70" disabled="disabled" /></td>
195         </tr>
196         </table>
197 <?php else: ?>
198         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
199         <tr>
200                 <td class="row1"><div class="required" title="Required Field">*</div><strong><label for="contentdir">Content Directory</label></strong>
201                 <p>Please specify where the content directory should be. The content directory stores all of the content files. As a security measure, the content directory should be placed <em>outside</em> of your AContent installation (for example, to a non-web-accessible location that is not publically available).</p>
202                 
203                 <p>On a Windows machine, the path should look like <kbd>C:\content</kbd>, while on Unix it should look like <kbd>/var/content</kbd>.</p>
204                 
205                 <p>The directory you specify must be created if it does not already exist and be writeable by the webserver. On Unix machines issue the command <kbd>chmod a+rwx content</kbd>, additionally the path may not contain any symbolic links.</p>
206
207                 <input type="text" name="content_dir" id="contentdir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" class="formfield" size="70" /></td>
208         </tr>
209         </table>
210 <?php endif; ?>
211         <br /><br /><p align="center"><input type="submit" class="button" value=" Next &raquo;" name="submit" /></p>
212 </form>