763e83d41b0e99703975ba181c22a114003861c2
[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                 // save blank index.html pages to those directories
47                 @copy('../images/index.html', $_POST['content_dir'] . '/import/index.html');
48                 @copy('../images/index.html', $_POST['content_dir'] . '/index.html');
49         }
50
51         if (!isset($errors)) {
52                 unset($errors);
53                 unset($_POST['submit']);
54                 unset($action);
55
56                 if (substr($_POST['content_dir'], -1) !='\\'){
57                         $_POST['content_dir'] .= DIRECTORY_SEPARATOR;
58                 }
59
60                 // kludge to fix the missing slashes when magic_quotes_gpc is On
61                 if ($addslashes != 'mysql_real_escape_string') {
62                         $_POST['content_dir'] = addslashes($_POST['content_dir']);
63                 }
64
65                 store_steps($step);
66                 $step++;
67                 return;
68         } else {
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 }       
75
76 print_progress($step);
77
78 if (isset($errors)) {
79         print_errors($errors);
80 }
81
82 if (isset($_POST['step1']['old_version'])) 
83 {
84         //get real path to old content
85
86         $old_install   = realpath('../../' . DIRECTORY_SEPARATOR . $_POST['step1']['old_path']);
87         $old_config_cd = urldecode($_POST['step1']['content_dir']); // this path may not exist
88         $new_install   = realpath('../');
89
90         $path_info = pathinfo($old_config_cd);
91         $content_dir_name = $path_info['basename'];
92
93         if ($new_install . DIRECTORY_SEPARATOR . $content_dir_name . DIRECTORY_SEPARATOR == $old_config_cd) {
94                 // case 2
95                 $copy_from     = $old_install . DIRECTORY_SEPARATOR . $content_dir_name;
96         } else {
97                 // case 3 + 4
98                 // it's outside
99                 $copy_from = '';
100         }
101
102         $_defaults['content_dir'] = $old_config_cd;
103
104 }
105 else
106 {
107         $defaults = $_defaults;
108         $blurb = '';
109         
110         // the following code checks to see if get.php is being executed, then sets $_POST['get_file'] appropriately:
111         $headers = array();
112         $path  = substr($_SERVER['PHP_SELF'], 0, -strlen('install/install.php')) . 'get.php/?test';
113         $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
114         
115         $host = parse_url($_SERVER['HTTP_HOST']);
116         
117         if (isset($host['path'])) {
118                 $host = $host['path'];
119         } else if (isset($host['host'])) {
120                 $host = $host['host'];
121         } else {
122                 $_SERVER['HTTP_HOST'];
123         }
124         if ($port == 443) {
125                 // if we're using SSL, but don't know if support is compiled into PHP:
126                 $fd = @fopen('https://'.$host.$path, 'rb');
127                 print('https://'.$host.$path);
128                 if ($fd === false) {
129                         $content = false;
130                 } else {
131                         $content = @fread($fd, filesize($filename));
132                         @fclose($fd);
133                 }
134         
135                 if (strlen($content) == 0) {
136                         $headers[] = 'Trans-Get: OK';
137                 } else {
138                         $headers[] = '';
139                 }
140         } else {
141                 $fp   = @fsockopen($host, $port, $errno, $errstr, 15);
142                 
143                 if($fp) {
144                         $head = 'HEAD '.@$path. " HTTP/1.0\r\nHost: ".@$host."\r\n\r\n";
145                         fputs($fp, $head);
146                         while(!feof($fp)) {
147                                 if ($header = trim(fgets($fp, 1024))) {
148                                         $headers[] = $header;
149                                 }
150                         }
151                 }
152         }
153         
154         if (in_array('Trans-Get: OK', $headers)) {
155                 $get_file = 'TRUE';
156         } else {
157                 $get_file = 'FALSE';
158         }
159 }
160
161 ?>
162 <br />
163 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
164         <input type="hidden" name="step" value="<?php echo $step; ?>" />
165         <input type="hidden" name="copy_from" value="<?php echo $copy_from; ?>" />
166         <input type="hidden" name="get_file" value="<?php echo $get_file; ?>" />
167         <?php print_hidden($step); ?>
168
169 <?php if (isset($_POST['step1']['old_version'])) : ?>
170         <input type="hidden" name="content_dir" value="<?php echo $_defaults['content_dir']; ?>" />
171         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
172         <tr>
173                 <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>
174         </tr>
175         </table>
176 <?php elseif ($get_file == 'FALSE') : ?>
177         <input type="hidden" name="content_dir" value="<?php if (!empty($_POST['content_dir'])) { echo $_POST['content_dir']; } else { echo $_defaults['content_dir']; } ?>" />
178
179         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
180         <tr>
181                 <td class="row1"><div class="required" title="Required Field">*</div><strong><label for="contentdir">Content Directory</label></strong>
182                 <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>
183                 <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>
184                 <br /><br />
185                 <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>
186         </tr>
187         </table>
188 <?php else: ?>
189         <table width="80%" class="tableborder" cellspacing="0" cellpadding="1" align="center">  
190         <tr>
191                 <td class="row1"><div class="required" title="Required Field">*</div><strong><label for="contentdir">Content Directory</label></strong>
192                 <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>
193                 
194                 <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>
195                 
196                 <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>
197
198                 <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>
199         </tr>
200         </table>
201 <?php endif; ?>
202         <br /><br /><p align="center"><input type="submit" class="button" value=" Next &raquo;" name="submit" /></p>
203 </form>