Rev 229 Rev 237
1 <?php 1 <?php
2   2  
3 /** 3 /**
4 * Contains functions used during the install process. 4 * Contains functions used during the install process.
5 * 5 *
6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License 7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
8 * @copyright (c)2003-2005 Tamlyn Rhodes 8 * @copyright (c)2003-2005 Tamlyn Rhodes
9 * @version $Id: install.inc.php,v 1.4 2006/01/22 03:25:37 tamlyn Exp $ 9 * @version $Id: install.inc.php,v 1.4 2006/01/22 03:25:37 tamlyn Exp $
10 */ 10 */
11   11  
12 /** 12 /**
13 * Test server configuration. 13 * Test server configuration.
14 * @return bool true if no errors occurred; false otherwise 14 * @return bool true if no errors occurred; false otherwise
15 */ 15 */
16 function testServer() 16 function testServer()
17 { 17 {
18 setupHeader("Testing PHP version"); 18 setupHeader("Testing PHP version");
19 setupMessage("PHP version is ".phpversion()); 19 setupMessage("PHP version is ".phpversion());
20 $bits = explode(".",phpversion()); 20 $bits = explode(".",phpversion());
21 if(strcmp($bits[0],"4")<0 || strcmp($bits[0],"4")==0 && strcmp($bits[1],"1")<0) 21 if(strcmp($bits[0],"4")<0 || strcmp($bits[0],"4")==0 && strcmp($bits[1],"1")<0)
22 return setupError("singapore requires PHP 4.1.0 or higher "); 22 return setupError("singapore requires PHP 4.1.0 or higher ");
23 23
24 $success = true; 24 $success = true;
25 25
26 setupHeader("Testing PHP configuration"); 26 setupHeader("Testing PHP configuration");
27 //setupMessage("If any of these tests fail, you may be able to change the configuration ". 27 //setupMessage("If any of these tests fail, you may be able to change the configuration ".
28 // "directive (specified in brackets) either in php.ini or by adding ". 28 // "directive (specified in brackets) either in php.ini or by adding ".
29 // "<code>ini_set(\"<b>directive_name</b>, 1)</code> to <code>includes/header.php</code>"); 29 // "<code>ini_set(\"<b>directive_name</b>, 1)</code> to <code>includes/header.php</code>");
30   30  
31 if(!ini_get("safe_mode")) setupMessage("Safe mode disabled"); 31 if(!ini_get("safe_mode")) setupMessage("Safe mode disabled");
32 else $success &= setupError("PHP is running in 'safe mode' (<code>safe_mode</code>). Singapore may still function correctly but safe mode operation is not supported"); 32 else $success &= setupError("PHP is running in 'safe mode' (<code>safe_mode</code>). Singapore may still function correctly but safe mode operation is not supported");
33 33
34 $session_save_path = ini_get("session.save_path"); 34 $session_save_path = ini_get("session.save_path");
35 if(!empty($session_save_path) && is_writable($session_save_path) || ini_get("session.save_handler")!="files") setupMessage("Session save path seems to be correctly specified"); 35 if(!empty($session_save_path) && is_writable($session_save_path) || ini_get("session.save_handler")!="files") setupMessage("Session save path seems to be correctly specified");
36 else $success &= setupError("Session save path does not exist or is not writable (<code>session.save_path</code>). Singapore will function but you may not be able to use the admin interface"); 36 else $success &= setupError("Session save path does not exist or is not writable (<code>session.save_path</code>). Singapore will function but you may not be able to use the admin interface");
37   37  
38 if(ini_get("session.use_trans_sid")) setupMessage("Transparent session id support enabled"); 38 if(ini_get("session.use_trans_sid")) setupMessage("Transparent session id support enabled");
39 else setupMessage("Transparent session id support disabled (<code>use_trans_sid</code>). Singapore will function but will <b>require</b> cookies for the admin interface to function"); 39 else setupMessage("Transparent session id support disabled (<code>use_trans_sid</code>). Singapore will function but will <b>require</b> cookies for the admin interface to function");
40   40  
41 if(ini_get("file_uploads")) setupMessage("File uploading enabled"); 41 if(ini_get("file_uploads")) setupMessage("File uploading enabled");
42 else $success &= setupError("File uploading disabled (<code>file_uploads</code>). Singapore will function but you will not be able to upload images via the admin interface"); 42 else $success &= setupError("File uploading disabled (<code>file_uploads</code>). Singapore will function but you will not be able to upload images via the admin interface");
43   43  
44 $upload_tmp_dir = ini_get("upload_tmp_dir"); 44 $upload_tmp_dir = ini_get("upload_tmp_dir");
45 if(empty($upload_tmp_dir) || is_writable($upload_tmp_dir)) setupMessage("Upload temp directory seems to be correctly specified"); 45 if(empty($upload_tmp_dir) || is_writable($upload_tmp_dir)) setupMessage("Upload temp directory seems to be correctly specified");
46 else $success &= setupError("Upload directory directory does not exist or is not writable (<code>upload_tmp_dir</code>). Singapore will function but you may not be able to upload images via the admin interface"); 46 else $success &= setupError("Upload directory directory does not exist or is not writable (<code>upload_tmp_dir</code>). Singapore will function but you may not be able to upload images via the admin interface");
47 47
48 //setupMessage("Maximum upload size is ".floor(ini_get("upload_max_filesize")/1024)."KB. You will not be able to upload files larger than this via the admin interface"); 48 //setupMessage("Maximum upload size is ".floor(ini_get("upload_max_filesize")/1024)."KB. You will not be able to upload files larger than this via the admin interface");
49 49
50 if(ini_get("allow_url_fopen")) setupMessage("Remote file handling enabled"); 50 if(ini_get("allow_url_fopen")) setupMessage("Remote file handling enabled");
51 else $success &= setupError("Remote file handling disabled (<code>allow_url_fopen</code>). Singapore will function but you will not be able to generate thumbnails for remotely hosted files"); 51 else $success &= setupError("Remote file handling disabled (<code>allow_url_fopen</code>). Singapore will function but you will not be able to generate thumbnails for remotely hosted files");
52 52
53 setupHeader("Testing for config file"); 53 setupHeader("Testing for config file");
54 54
55 if(file_exists($GLOBALS['basePath']."singapore.ini")) setupMessage("Config file found"); 55 if(file_exists($GLOBALS['basePath']."singapore.ini")) setupMessage("Config file found");
56 else $success &= setupError("Config file not found - singapore.ini must be located in the root singapore directory"); 56 else $success &= setupError("Config file not found - singapore.ini must be located in the root singapore directory");
57 57
58 setupHeader("Testing for GD"); 58 setupHeader("Testing for GD");
59 //get phpinfo data 59 //get phpinfo data
60 ob_start(); 60 ob_start();
61 phpinfo(8); 61 phpinfo(8);
62 $phpinfo = ob_get_contents(); 62 $phpinfo = ob_get_contents();
63 ob_end_clean(); 63 ob_end_clean();
64 64
65 //find gd version 65 //find gd version
66 $phpinfo = strip_tags($phpinfo); 66 $phpinfo = strip_tags($phpinfo);
67 $phpinfo = stristr($phpinfo,"gd version"); 67 $phpinfo = stristr($phpinfo,"gd version");
68 $phpinfo = stristr($phpinfo,"version"); 68 $phpinfo = stristr($phpinfo,"version");
69 69
70 if(!$phpinfo) $success &= setupError("GD not found. You may be able to use ImageMagick instead"); 70 if(!$phpinfo) $success &= setupError("GD not found. You may be able to use ImageMagick instead");
71 else { 71 else {
72 //extract text version and number version 72 //extract text version and number version
73 $gd_version_text = substr($phpinfo,0,strpos($phpinfo,"\n")); 73 $gd_version_text = substr($phpinfo,0,strpos($phpinfo,"\n"));
74 $gd_version_number = substr($gd_version_text,0,strpos($gd_version_text,".")); 74 $gd_version_number = substr($gd_version_text,0,strpos($gd_version_text,"."));
75 $gd_version_number = substr($gd_version_number, strlen($gd_version_number)-1); 75 $gd_version_number = substr($gd_version_number, strlen($gd_version_number)-1);
76 setupMessage("Found GD: $gd_version_text"); 76 setupMessage("Found GD: $gd_version_text");
77 if($gd_version_number=="1") setupMessage("Please change the <code>thumbnail_software</code> option in singapore.ini to \"gd1\". Note: GD1 produces very poor quality thumbnails so please use GD2 or ImageMagick if available"); 77 if($gd_version_number=="1") setupMessage("Please change the <code>thumbnail_software</code> option in singapore.ini to \"gd1\". Note: GD1 produces very poor quality thumbnails so please use GD2 or ImageMagick if available");
78 } 78 }
79 79
80 80
81 setupHeader("Testing for ImageMagick"); 81 setupHeader("Testing for ImageMagick");
82 82
83 $foundIM = exec("mogrify"); 83 $foundIM = exec("mogrify");
84 $whereIM = exec("whereis mogrify"); 84 $whereIM = exec("whereis mogrify");
85 if($foundIM) { 85 if($foundIM) {
86 if($whereIM) setupMessage("Found ImageMagick at $whereIM"); 86 if($whereIM) setupMessage("Found ImageMagick at $whereIM");
87 else setupMessage("Found ImageMagick"); 87 else setupMessage("Found ImageMagick");
88 setupMessage("To take advantage of ImageMagick change the <code>thumbnail_software</code> option in singapore.ini to \"im\""); 88 setupMessage("To take advantage of ImageMagick change the <code>thumbnail_software</code> option in singapore.ini to \"im\"");
89 } else setupMessage("ImageMagick not found but that doesn't mean it's not there. If it really is not available you may be able to install it yourself (even without shell access to the server)"); 89 } else setupMessage("ImageMagick not found but that doesn't mean it's not there. If it really is not available you may be able to install it yourself (even without shell access to the server)");
90 90
91 return $success; 91 return $success;
92 } 92 }
93   93  
94   94  
95 /** 95 /**
96 * Creates cache and logs directories required to run singapore and ensures 96 * Creates cache and logs directories required to run singapore and ensures
97 * all required directories are writeable. 97 * all required directories are writeable.
98 * @return bool true if no errors occurred; false otherwise 98 * @return bool true if no errors occurred; false otherwise
99 */ 99 */
100 function createDirectories($config) 100 function createDirectories($config)
101 { 101 {
102 $success = true; 102 $success = true;
103 setupHeader("Creating directories"); 103 setupHeader("Creating directories");
104 104
105 if(is_writable($config->base_path.$config->pathto_data_dir)) { 105 if(is_writable($config->base_path.$config->pathto_data_dir)) {
106 setupMessage("Data directory is writable"); 106 setupMessage("Data directory is writable");
107 if(file_exists($config->base_path.$config->pathto_cache)) 107 if(file_exists($config->base_path.$config->pathto_cache))
108 if(is_writable($config->base_path.$config->pathto_cache)) 108 if(is_writable($config->base_path.$config->pathto_cache))
109 setupMessage("Cache directory already exists at ".$config->base_path.$config->pathto_cache." and is writable"); 109 setupMessage("Cache directory already exists at ".$config->base_path.$config->pathto_cache." and is writable");
110 else 110 else
111 $success = setupError("Cache directory already exists at ".$config->base_path.$config->pathto_cache." but is not writable. Please CHMOD to 777"); 111 $success = setupError("Cache directory already exists at ".$config->base_path.$config->pathto_cache." but is not writable. Please CHMOD to 777");
112 else 112 else
113 if(mkdir($config->base_path.$config->pathto_cache, $config->directory_mode)) { 113 if(mkdir($config->base_path.$config->pathto_cache, $config->directory_mode)) {
114 @chmod($config->base_path.$config->pathto_cache, $config->directory_mode); 114 @chmod($config->base_path.$config->pathto_cache, $config->directory_mode);
115 setupMessage("Created cache directory at ".$config->base_path.$config->pathto_cache); 115 setupMessage("Created cache directory at ".$config->base_path.$config->pathto_cache);
116 } else 116 } else
117 $success = setupError("Could not create cache directory at ".$config->base_path.$config->pathto_cache); 117 $success = setupError("Could not create cache directory at ".$config->base_path.$config->pathto_cache);
118 if($config->track_views) 118 if($config->track_views)
119 if(file_exists($config->base_path.$config->pathto_logs)) 119 if(file_exists($config->base_path.$config->pathto_logs))
120 if(is_writable($config->base_path.$config->pathto_logs)) 120 if(is_writable($config->base_path.$config->pathto_logs))
121 setupMessage("Logs directory already exists at ".$config->base_path.$config->pathto_logs." and is writable"); 121 setupMessage("Logs directory already exists at ".$config->base_path.$config->pathto_logs." and is writable");
122 else 122 else
123 $success = setupError("Logs directory already exists at ".$config->base_path.$config->pathto_logs." but is not writable. Please CHMOD to 777"); 123 $success = setupError("Logs directory already exists at ".$config->base_path.$config->pathto_logs." but is not writable. Please CHMOD to 777");
124 else 124 else
125 if(mkdir($config->base_path.$config->pathto_logs, $config->directory_mode)) { 125 if(mkdir($config->base_path.$config->pathto_logs, $config->directory_mode)) {
126 @chmod($config->base_path.$config->pathto_logs, $config->directory_mode); 126 @chmod($config->base_path.$config->pathto_logs, $config->directory_mode);
127 setupMessage("Created logs directory at ".$config->base_path.$config->pathto_logs); 127 setupMessage("Created logs directory at ".$config->base_path.$config->pathto_logs);
128 } else 128 } else
129 $success = setupError("Could not create logs directory at ".$config->base_path.$config->pathto_logs); 129 $success = setupError("Could not create logs directory at ".$config->base_path.$config->pathto_logs);
130 else 130 else
131 setupMessage("View logging disabled. Logs directory not created"); 131 setupMessage("View logging disabled. Logs directory not created");
132 } 132 }
133 else 133 else
134 $success = setupError("Data directory (".$config->base_path.$config->pathto_data_dir.") is not writable. Please CHMOD to 777"); 134 $success = setupError("Data directory (".$config->base_path.$config->pathto_data_dir.") is not writable. Please CHMOD to 777");
135   135  
136 return $success; 136 return $success;
137 137
138 } 138 }
139   139  
140 /** 140 /**
141 * Creates the tables and inserts the default users. 141 * Creates the tables and inserts the default users.
142 * @param sgIO_sql pointer to a singapore SQL backend object 142 * @param sgIO_sql pointer to a singapore SQL backend object
143 */ 143 */
144 function sqlCreateTables(&$io) { 144 function sqlCreateTables(&$io) {
145 $success = true; 145 $success = true;
146 setupHeader("Creating tables"); 146 setupHeader("Creating tables");
147 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."galleries")) 147 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."galleries"))
148 setupMessage("'".$io->config->sql_prefix."galleries' table already exists - skipped"); 148 setupMessage("'".$io->config->sql_prefix."galleries' table already exists - skipped");
149 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."galleries (". 149 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."galleries (".
150 "id varchar(250) NOT NULL, ". 150 "id varchar(250) NOT NULL, ".
151 "lang varchar(16) NOT NULL DEFAULT '', ". 151 "lang varchar(16) NOT NULL DEFAULT '', ".
152 "filename varchar(200), ". 152 "filename varchar(200), ".
153 "owner varchar(32), ". 153 "owner varchar(32), ".
154 "groups varchar(64), ". 154 "groups varchar(64), ".
155 "permissions int UNSIGNED, ". 155 "permissions int UNSIGNED, ".
156 "categories varchar(255), ". 156 "categories varchar(255), ".
157 "name varchar(255), ". 157 "name varchar(255), ".
158 "artist varchar(255), ". 158 "artist varchar(255), ".
159 "email varchar(255), ". 159 "email varchar(255), ".
160 "copyright varchar(255), ". 160 "copyright varchar(255), ".
161 "description text, ". 161 "description text, ".
162 "summary text, ". 162 "summary text, ".
163 "date varchar(255),". 163 "date varchar(255),".
164 "hits smallint UNSIGNED,". 164 "hits smallint UNSIGNED,".
165 "lasthit int UNSIGNED,". 165 "lasthit int UNSIGNED,".
166 "PRIMARY KEY (id, lang)". 166 "PRIMARY KEY (id, lang)".
167 ")")) setupMessage("'".$io->config->sql_prefix."galleries' table created"); 167 ")")) setupMessage("'".$io->config->sql_prefix."galleries' table created");
168 else 168 else
169 $success = setupError("Unable to create '".$io->config->sql_prefix."galleries' table:".$io->error()); 169 $success = setupError("Unable to create '".$io->config->sql_prefix."galleries' table:".$io->error());
170 170
171 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."images")) 171 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."images"))
172 setupMessage("'".$io->config->sql_prefix."images' table already exists - skipped"); 172 setupMessage("'".$io->config->sql_prefix."images' table already exists - skipped");
173 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."images (". 173 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."images (".
174 "galleryid varchar(250) NOT NULL, ". 174 "galleryid varchar(250) NOT NULL, ".
175 "filename varchar(200) NOT NULL, ". 175 "filename varchar(200) NOT NULL, ".
176 "lang varchar(16) NOT NULL DEFAULT '', ". 176 "lang varchar(16) NOT NULL DEFAULT '', ".
177 "thumbnail varchar(255), ". 177 "thumbnail varchar(255), ".
178 "owner varchar(32), ". 178 "owner varchar(32), ".
179 "groups varchar(64), ". 179 "groups varchar(64), ".
180 "permissions int, ". 180 "permissions int, ".
181 "categories varchar(64), ". 181 "categories varchar(64), ".
182 "name varchar(255), ". 182 "name varchar(255), ".
183 "artist varchar(255), ". 183 "artist varchar(255), ".
184 "email varchar(255), ". 184 "email varchar(255), ".
185 "copyright varchar(255), ". 185 "copyright varchar(255), ".
186 "description text, ". 186 "description text, ".
187 "width smallint UNSIGNED, ". 187 "width smallint UNSIGNED, ".
188 "height smallint UNSIGNED, ". 188 "height smallint UNSIGNED, ".
189 "type tinyint UNSIGNED, ". 189 "type tinyint UNSIGNED, ".
190 "location varchar(255), ". 190 "location varchar(255), ".
191 "date varchar(255), ". 191 "date varchar(255), ".
192 "camera varchar(255), ". 192 "camera varchar(255), ".
193 "lens varchar(255), ". 193 "lens varchar(255), ".
194 "film varchar(255), ". 194 "film varchar(255), ".
195 "darkroom text, ". 195 "darkroom text, ".
196 "digital text, ". 196 "digital text, ".
197 "hits smallint UNSIGNED,". 197 "hits smallint UNSIGNED,".
198 "lasthit int UNSIGNED,". 198 "lasthit int UNSIGNED,".
199 "PRIMARY KEY (galleryid, filename, lang)". 199 "PRIMARY KEY (galleryid, filename, lang)".
200 ")")) setupMessage("'".$io->config->sql_prefix."images' table created"); 200 ")")) setupMessage("'".$io->config->sql_prefix."images' table created");
201 else 201 else
202 $success = setupError("Unable to create '".$io->config->sql_prefix."images' table:".$io->error()); 202 $success = setupError("Unable to create '".$io->config->sql_prefix."images' table:".$io->error());
203 203
204 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."users")) 204 if(@$io->query("SELECT * FROM ".$io->config->sql_prefix."users"))
205 setupMessage("'".$io->config->sql_prefix."users' table already exists - skipped"); 205 setupMessage("'".$io->config->sql_prefix."users' table already exists - skipped");
206 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."users (". 206 elseif($io->query("CREATE TABLE ".$io->config->sql_prefix."users (".
207 "username varchar(32) NOT NULL, ". 207 "username varchar(32) NOT NULL, ".
208 "userpass char(32) NOT NULL, ". 208 "userpass char(32) NOT NULL, ".
209 "permissions int UNSIGNED, ". 209 "permissions int UNSIGNED, ".
210 "groups varchar(64), ". 210 "groups varchar(64), ".
211 "email varchar(255), ". 211 "email varchar(255), ".
212 "fullname varchar(255), ". 212 "fullname varchar(255), ".
213 "description varchar(255), ". 213 "description varchar(255), ".
214 "stats varchar(255), ". 214 "stats varchar(255), ".
215 "PRIMARY KEY (username)". 215 "PRIMARY KEY (username)".
216 ")")) { 216 ")")) {
217 setupMessage("'".$io->config->sql_prefix."users' table created"); 217 setupMessage("'".$io->config->sql_prefix."users' table created");
218 if($io->query("INSERT INTO ".$io->config->sql_prefix."users VALUES". 218 if($io->query("INSERT INTO ".$io->config->sql_prefix."users VALUES".
219 '("admin", "5f4dcc3b5aa765d61d8327deb882cf99", 1024, "", "", "Administrator", "Default administrator account", "")') && 219 '("admin", "5f4dcc3b5aa765d61d8327deb882cf99", 1024, "", "", "Administrator", "Default administrator account", "")') &&
220 $io->query("INSERT INTO ".$io->config->sql_prefix."users VALUES". 220 $io->query("INSERT INTO ".$io->config->sql_prefix."users VALUES".
221 '("guest", "5f4dcc3b5aa765d61d8327deb882cf99", 0, "", "", "Guest", "Restricted use account for guests who do not have a user account", "")')) 221 '("guest", "5f4dcc3b5aa765d61d8327deb882cf99", 0, "", "", "Guest", "Restricted use account for guests who do not have a user account", "")'))
222 setupMessage("Inserted default users into '".$io->config->sql_prefix."users' table"); 222 setupMessage("Inserted default users into '".$io->config->sql_prefix."users' table");
223 else 223 else
224 $success = setupError("Unable to insert default users into '".$io->config->sql_prefix."users' table:".$io->error()); 224 $success = setupError("Unable to insert default users into '".$io->config->sql_prefix."users' table:".$io->error());
225 } else 225 } else
226 $success = setupError("Unable to create '".$io->config->sql_prefix."users' table:".$io->error()); 226 $success = setupError("Unable to create '".$io->config->sql_prefix."users' table:".$io->error());
227 227
228 return $success; 228 return $success;
229 } 229 }
230   230  
231   231  
232 //output functions 232 //output functions
233 function setupHeader($var) 233 function setupHeader($var)
234 { 234 {
235 echo "\n</p>\n\n<h2>{$var}</h2>\n\n<p>\n"; 235 echo "\n</p>\n\n<h2>{$var}</h2>\n\n<p>\n";
236 } 236 }
237   237  
238 /** 238 /**
239 * Print an information message. Always returns true. 239 * Print an information message. Always returns true.
240 * @return true 240 * @return true
241 */ 241 */
242 function setupMessage($var) 242 function setupMessage($var)
243 { 243 {
244 echo "{$var}.<br />\n"; 244 echo "{$var}.<br />\n";
245 return true; 245 return true;
246 } 246 }
247   247  
248 /** 248 /**
249 * Print an error message. Always returns false. 249 * Print an error message. Always returns false.
250 * @return false 250 * @return false
251 */ 251 */
252 function setupError($var) 252 function setupError($var)
253 { 253 {
254 echo "<span class=\"error\">{$var}</span>.<br />\n"; 254 echo "<span class=\"error\">{$var}</span>.<br />\n";
255 return false; 255 return false;
256 } 256 }
257   257  
258 ?> 258 ?>