| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 5 | |
|---|
| 6 | // +-------------------------------------------------------------------+ |
|---|
| 7 | // | WiFiDog Authentication Server | |
|---|
| 8 | // | ============================= | |
|---|
| 9 | // | | |
|---|
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 11 | // | portal suite. | |
|---|
| 12 | // +-------------------------------------------------------------------+ |
|---|
| 13 | // | PHP version 5 required. | |
|---|
| 14 | // +-------------------------------------------------------------------+ |
|---|
| 15 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 17 | // +-------------------------------------------------------------------+ |
|---|
| 18 | // | This program is free software; you can redistribute it and/or | |
|---|
| 19 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 20 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 21 | // | the License, or (at your option) any later version. | |
|---|
| 22 | // | | |
|---|
| 23 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 26 | // | GNU General Public License for more details. | |
|---|
| 27 | // | | |
|---|
| 28 | // | You should have received a copy of the GNU General Public License | |
|---|
| 29 | // | along with this program; if not, contact: | |
|---|
| 30 | // | | |
|---|
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 34 | // | | |
|---|
| 35 | // +-------------------------------------------------------------------+ |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * WiFiDog Authentication Server installation and configuration script |
|---|
| 39 | * |
|---|
| 40 | * @package WiFiDogAuthServer |
|---|
| 41 | * @author Pascal Leclerc <isf@plec.ca> |
|---|
| 42 | * @copyright 2005-2006 Pascal Leclerc |
|---|
| 43 | * @version Subversion $Id$ |
|---|
| 44 | * @link http://www.wifidog.org/ |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Load required files |
|---|
| 49 | */ |
|---|
| 50 | require_once ('include/path_defines_base.php'); |
|---|
| 51 | empty ($_REQUEST['page']) ? $page = 'Welcome' : $page = $_REQUEST['page']; # The page to be loaded |
|---|
| 52 | empty ($_REQUEST['action']) ? $action = '' : $action = $_REQUEST['action']; # The action to be done (in page) |
|---|
| 53 | empty ($_REQUEST['debug']) ? $debug = 0 : $debug = $_REQUEST['debug']; # Use for MySQL debugging |
|---|
| 54 | empty ($_REQUEST['config']) ? $config = '' : $config = $_REQUEST['config']; # Store data to be saved in config.php |
|---|
| 55 | |
|---|
| 56 | # Security : Minimal access validation is use by asking user to retreive a random password in a local file. This prevent remote user to access unprotected installation script. It's dummy, easy to implement and better than nothing. |
|---|
| 57 | |
|---|
| 58 | # Random password generator |
|---|
| 59 | $password_file = '/tmp/dog_cookie.txt'; |
|---|
| 60 | $random_password = null; |
|---|
| 61 | if (!file_exists($password_file)) { |
|---|
| 62 | srand(date("s")); |
|---|
| 63 | $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|---|
| 64 | $password = ""; |
|---|
| 65 | while (strlen($random_password) < 8) { |
|---|
| 66 | $random_password .= substr($possible_charactors, rand() % (strlen($possible_charactors)), 1); |
|---|
| 67 | } |
|---|
| 68 | $fd = fopen($password_file, 'w'); |
|---|
| 69 | fwrite($fd, $random_password."\n"); |
|---|
| 70 | fclose($fd); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | # Read password file |
|---|
| 74 | $fd = fopen($password_file, "rb"); |
|---|
| 75 | $password = trim(fread($fd, filesize($password_file))); |
|---|
| 76 | fclose($fd); |
|---|
| 77 | |
|---|
| 78 | $auth = false; |
|---|
| 79 | |
|---|
| 80 | if ($page != 'Welcome') { |
|---|
| 81 | if (isset ($_SERVER['PHP_AUTH_PW'])) { |
|---|
| 82 | #echo "PHP_AUTH_USER=(" . $_SERVER['PHP_AUTH_USER'] . ") PHP_AUTH_PW=(" . $_SERVER['PHP_AUTH_PW'] . ")"; # DEBUG |
|---|
| 83 | if ($password == $_SERVER['PHP_AUTH_PW']) |
|---|
| 84 | $auth = true; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | else |
|---|
| 88 | $auth = true; |
|---|
| 89 | |
|---|
| 90 | if (!$auth) { # Ask user for the passorwd |
|---|
| 91 | header('WWW-Authenticate: Basic realm="Private"'); |
|---|
| 92 | header('HTTP/1.0 401 Unauthorized'); |
|---|
| 93 | echo "Authorization Required !"; |
|---|
| 94 | exit; |
|---|
| 95 | } |
|---|
| 96 | # End of Security validation |
|---|
| 97 | |
|---|
| 98 | print<<<EndHTML |
|---|
| 99 | <HTML> |
|---|
| 100 | <HEAD> |
|---|
| 101 | <TITLE>$page - Wifidog Auth-server configuration</TITLE> |
|---|
| 102 | |
|---|
| 103 | <SCRIPT type="text/javascript"> |
|---|
| 104 | // This function add new configuration value to the "config" hidden input |
|---|
| 105 | // On submit, config will be parsed and value saved to config.php file |
|---|
| 106 | function newConfig(dataAdd) { |
|---|
| 107 | // TODO : Validate input data |
|---|
| 108 | if (document.myform.config.value == '') { |
|---|
| 109 | document.myform.config.value = dataAdd; |
|---|
| 110 | } |
|---|
| 111 | else { |
|---|
| 112 | document.myform.config.value = document.myform.config.value + '|' + dataAdd; |
|---|
| 113 | } |
|---|
| 114 | //alert(document.myform.config.value); // DEBUG |
|---|
| 115 | } |
|---|
| 116 | </SCRIPT> |
|---|
| 117 | |
|---|
| 118 | </HEAD> |
|---|
| 119 | <BODY text="black" bgcolor="#CFCFCF"> |
|---|
| 120 | |
|---|
| 121 | <style type="text/css"> |
|---|
| 122 | <!-- |
|---|
| 123 | .button |
|---|
| 124 | { |
|---|
| 125 | font-size: 12pt; |
|---|
| 126 | font-weight: bold; |
|---|
| 127 | color: black; |
|---|
| 128 | background: #D4D0C8; |
|---|
| 129 | text-decoration: none; |
|---|
| 130 | border-top: 1px solid white; |
|---|
| 131 | border-right: 2px solid gray; |
|---|
| 132 | border-bottom: 2px solid gray; |
|---|
| 133 | border-left: 1px solid white; |
|---|
| 134 | padding: 3px 5px 3px 5px; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | td |
|---|
| 138 | { |
|---|
| 139 | padding: 1px 4px 1px 4px; |
|---|
| 140 | } |
|---|
| 141 | //--> |
|---|
| 142 | </style> |
|---|
| 143 | |
|---|
| 144 | <FORM NAME="myform" METHOD="post"> |
|---|
| 145 | <INPUT TYPE="HIDDEN" NAME="page"> |
|---|
| 146 | <INPUT TYPE="HIDDEN" NAME="action"> |
|---|
| 147 | <INPUT TYPE="HIDDEN" NAME="debug"> |
|---|
| 148 | <INPUT TYPE="HIDDEN" NAME="config"> |
|---|
| 149 | |
|---|
| 150 | EndHTML; |
|---|
| 151 | |
|---|
| 152 | #print "<pre>"; # DEBUG |
|---|
| 153 | #print_r($_SERVER); # DEBUG |
|---|
| 154 | #print_r($_REQUEST); # DEBUG |
|---|
| 155 | #print "</pre>"; # DEBUG |
|---|
| 156 | #exit(); |
|---|
| 157 | |
|---|
| 158 | # Minimal version needed |
|---|
| 159 | $requiredPHPVersion = '5.0.0'; |
|---|
| 160 | $requiredPostgeSQLVersion = '0.0.0'; // Todo |
|---|
| 161 | |
|---|
| 162 | # Needed files/directories with write access |
|---|
| 163 | $dir_array = array ( |
|---|
| 164 | 'tmp', |
|---|
| 165 | 'tmp/simplepie_cache', |
|---|
| 166 | 'lib/smarty', |
|---|
| 167 | 'lib/smarty/plugins', |
|---|
| 168 | 'tmp/smarty/templates_c', |
|---|
| 169 | 'tmp/smarty/cache', |
|---|
| 170 | 'lib/simplepie', |
|---|
| 171 | 'lib/feedpressreview', |
|---|
| 172 | 'lib/Phlickr', |
|---|
| 173 | 'config.php' |
|---|
| 174 | ); |
|---|
| 175 | |
|---|
| 176 | $smarty_full_url = 'http://smarty.php.net/do_download.php?download_file=Smarty-2.6.14.tar.gz'; |
|---|
| 177 | $phlickr_full_url = 'http://easynews.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.4.tgz'; |
|---|
| 178 | |
|---|
| 179 | $neededPackages = array ( |
|---|
| 180 | 'smarty' => array ( |
|---|
| 181 | 'needed' => 1, |
|---|
| 182 | 'available' => 0, |
|---|
| 183 | 'message' => '', |
|---|
| 184 | 'file' => 'lib/smarty/Smarty.class.php' |
|---|
| 185 | ), |
|---|
| 186 | 'simplepie' => array ( |
|---|
| 187 | 'needed' => 0, |
|---|
| 188 | 'available' => 0, |
|---|
| 189 | 'message' => '', |
|---|
| 190 | 'file' => 'lib/simplepie/simplepie.inc', |
|---|
| 191 | 'svn_source' => 'http://svn.simplepie.org/simplepie/branches/1.0_b3/' |
|---|
| 192 | ), |
|---|
| 193 | 'feedpressreview' => array ( |
|---|
| 194 | 'needed' => 0, |
|---|
| 195 | 'available' => 0, |
|---|
| 196 | 'message' => '', |
|---|
| 197 | 'file' => 'lib/feedpressreview/FeedPressReview.inc', |
|---|
| 198 | 'svn_source' => 'http://projects.coeus.ca/svn/feedpressreview/trunk/' |
|---|
| 199 | ), |
|---|
| 200 | 'phlickr' => array ( |
|---|
| 201 | 'needed' => 0, |
|---|
| 202 | 'available' => 0, |
|---|
| 203 | 'message' => '', |
|---|
| 204 | 'file' => 'lib/Phlickr/Photo.php' |
|---|
| 205 | ) |
|---|
| 206 | ); |
|---|
| 207 | |
|---|
| 208 | $loadedExtensions = array_flip(get_loaded_extensions()); # Debug : An empty array for $loadedExtensions will show needed dependencies |
|---|
| 209 | |
|---|
| 210 | $optionsInfo = array ( |
|---|
| 211 | /* TODO: SSL is now configured in the DB, but should still be handled by the install script |
|---|
| 212 | 'SSL_AVAILABLE' => array ( |
|---|
| 213 | 'title' => 'SSL Support', |
|---|
| 214 | 'depend' => 'return 1;', |
|---|
| 215 | 'message' => ' ' |
|---|
| 216 | ), |
|---|
| 217 | */ |
|---|
| 218 | 'CONF_USE_CRON_FOR_DB_CLEANUP' => array ( |
|---|
| 219 | 'title' => 'Use cron for DB cleanup', |
|---|
| 220 | 'depend' => 'return 1;', |
|---|
| 221 | 'message' => ' ' |
|---|
| 222 | ), |
|---|
| 223 | 'XSLT_SUPPORT' => array ( |
|---|
| 224 | 'title' => 'XSLT Support', |
|---|
| 225 | 'depend' => 'return 1;', |
|---|
| 226 | 'message' => ' ' |
|---|
| 227 | ), |
|---|
| 228 | 'GMAPS_HOTSPOTS_MAP_ENABLED' => array ( |
|---|
| 229 | 'title' => 'Google Maps Support', |
|---|
| 230 | 'depend' => 'return 1;', |
|---|
| 231 | 'message' => ' ' |
|---|
| 232 | ) |
|---|
| 233 | ); |
|---|
| 234 | |
|---|
| 235 | foreach ($neededPackages as $key => $value) { # Detect installed libraries (smarty, ...) |
|---|
| 236 | if (file_exists(WIFIDOG_ABS_FILE_PATH . $neededPackages[$key]['file'])) |
|---|
| 237 | $neededPackages[$key]['available'] = 1; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | $CONFIG_FILE = 'config.php'; |
|---|
| 241 | $LOCAL_CONFIG_FILE = 'local.config.php'; |
|---|
| 242 | |
|---|
| 243 | if (!empty ($config)) # If not empty, save javascript 'config' variable to config.php file |
|---|
| 244 | saveConfig($config); |
|---|
| 245 | |
|---|
| 246 | ### Read Configuration file. Keys and Values => define('FOO', 'BRAK'); |
|---|
| 247 | # Use config.php if local.config.php does not exist |
|---|
| 248 | //if(!file_exists(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE")) |
|---|
| 249 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
|---|
| 250 | //else |
|---|
| 251 | // $contentArray = file(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE"); |
|---|
| 252 | |
|---|
| 253 | $configArray = array (); |
|---|
| 254 | |
|---|
| 255 | foreach ($contentArray as $line) { |
|---|
| 256 | #print "$line<BR>"; # Debug |
|---|
| 257 | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
|---|
| 258 | //echo '<pre>';print_r($matchesArray);echo '</pre>'; |
|---|
| 259 | list ($key, $value) = explode(',', $matchesArray[1]); |
|---|
| 260 | $pattern = array ( |
|---|
| 261 | "/^'/", |
|---|
| 262 | "/'$/" |
|---|
| 263 | ); |
|---|
| 264 | $replacement = array ( |
|---|
| 265 | '', |
|---|
| 266 | '' |
|---|
| 267 | ); |
|---|
| 268 | $key = preg_replace($pattern, $replacement, trim($key)); |
|---|
| 269 | $value = preg_replace($pattern, $replacement, trim($value)); |
|---|
| 270 | $configArray[$key] = $value; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | //echo '<pre>';print_r($configArray);echo '</pre>'; |
|---|
| 274 | # Database connections variables |
|---|
| 275 | $CONF_DATABASE_HOST = $configArray['CONF_DATABASE_HOST']; |
|---|
| 276 | $CONF_DATABASE_NAME = $configArray['CONF_DATABASE_NAME']; |
|---|
| 277 | $CONF_DATABASE_USER = $configArray['CONF_DATABASE_USER']; |
|---|
| 278 | $CONF_DATABASE_PASSWORD = $configArray['CONF_DATABASE_PASSWORD']; |
|---|
| 279 | |
|---|
| 280 | //foreach($configArray as $key => $value) { print "K=$key V=$value<BR>"; } exit(); # DEBUG |
|---|
| 281 | |
|---|
| 282 | ################################### |
|---|
| 283 | # array (array1(name1, page1), array2(name2, page2), ..., arrayN(nameN, pageN)); |
|---|
| 284 | # Todo : Supporter HTTP_REFERER (j'me comprends) |
|---|
| 285 | function navigation($dataArray) { |
|---|
| 286 | $SERVER = $_SERVER['HTTP_HOST']; |
|---|
| 287 | $SCRIPT = $_SERVER['SCRIPT_NAME']; |
|---|
| 288 | print "\n<p>"; |
|---|
| 289 | foreach ($dataArray as $num => $navArray) { |
|---|
| 290 | $title = $navArray['title']; |
|---|
| 291 | $page = $navArray['page']; |
|---|
| 292 | empty ($navArray['action']) ? $action = '' : $action = $navArray['action']; |
|---|
| 293 | print<<<EndHTML |
|---|
| 294 | <A HREF="#" ONCLICK="document.myform.page.value = '$page'; document.myform.action.value = '$action'; document.myform.submit();" CLASS="button">$title</A> |
|---|
| 295 | |
|---|
| 296 | EndHTML; |
|---|
| 297 | if (array_key_exists($num +1, $dataArray)) |
|---|
| 298 | print " - "; |
|---|
| 299 | } |
|---|
| 300 | print "</p>\n"; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | ################################### |
|---|
| 304 | # |
|---|
| 305 | function refreshButton() { |
|---|
| 306 | print<<<EndHTML |
|---|
| 307 | |
|---|
| 308 | <p><A HREF="#" ONCLICK="javascript: window.location.reload(true);" CLASS="button">Refresh</A></p> |
|---|
| 309 | EndHTML; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | /** Use PHP internal functions to download a file */ |
|---|
| 313 | function downloadFile($remoteURL, $localPath) { |
|---|
| 314 | set_time_limit(1500); // 25 minutes timeout |
|---|
| 315 | if (copy($remoteURL, $localPath)) |
|---|
| 316 | return true; |
|---|
| 317 | else |
|---|
| 318 | return false; |
|---|
| 319 | } |
|---|
| 320 | /** Use PHP internal functions to execute a command |
|---|
| 321 | @return: Return value of the command*/ |
|---|
| 322 | function execVerbose($command, & $output, & $return_var, $always_show_output = true) { |
|---|
| 323 | print "$command"; |
|---|
| 324 | $retval = exec($command.' 2>&1', & $output, & $return_var); |
|---|
| 325 | if ($return_var != 0) |
|---|
| 326 | print "<p style='color:red'><em>Error:</em> Command did not complete successfully (returned $return_var): <br/>\n"; |
|---|
| 327 | else |
|---|
| 328 | print "<p style='color:green'>Command completed successfully (returned $return_var): <br/>\n"; |
|---|
| 329 | |
|---|
| 330 | if (($return_var != 0 || $always_show_output) && $output) { |
|---|
| 331 | foreach ($output as $output_line) |
|---|
| 332 | print " $output_line <br/>\n"; |
|---|
| 333 | } |
|---|
| 334 | print "</p>\n"; |
|---|
| 335 | return $retval; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | ################################### |
|---|
| 339 | # |
|---|
| 340 | /*function debugButton() { |
|---|
| 341 | print <<<EndHTML |
|---|
| 342 | <p><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></p> |
|---|
| 343 | EndHTML; |
|---|
| 344 | } */ |
|---|
| 345 | |
|---|
| 346 | ################################### |
|---|
| 347 | # In development |
|---|
| 348 | /*function installPackage($pkg_name, $full_url, $copy) { |
|---|
| 349 | print "<h1>$pkg_name installation</h1>\n"; |
|---|
| 350 | chdir(WIFIDOG_ABS_FILE_PATH."tmp"); |
|---|
| 351 | list($url, $filename) = split ("=", $full_url); |
|---|
| 352 | |
|---|
| 353 | print "Download source code ($filename) : "; |
|---|
| 354 | if (!file_exists($filename)) |
|---|
| 355 | execVerbose("wget \"$url\"", $output, $return); |
|---|
| 356 | if (!file_exists($filename)) // wget success if file exists |
|---|
| 357 | execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); |
|---|
| 358 | if (!file_exists($filename)) { |
|---|
| 359 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; |
|---|
| 360 | $output = implode("\n", $output_array); |
|---|
| 361 | print "<pre><em>wget \"$full_url\"</em>\n$output</pre>"; |
|---|
| 362 | exit(); |
|---|
| 363 | } else { |
|---|
| 364 | print "OK<BR>"; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | print "Uncompressing : "; |
|---|
| 368 | $dirname = array_shift(split(".tar.gz", $filename)); |
|---|
| 369 | |
|---|
| 370 | if (!file_exists($dirname)) |
|---|
| 371 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 372 | print "OK<BR>"; |
|---|
| 373 | print "Copying : "; |
|---|
| 374 | if (!file_exists('../../lib/smarty/Smarty.class.php')); |
|---|
| 375 | execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
|---|
| 376 | execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
|---|
| 377 | $copy |
|---|
| 378 | print "OK<BR>"; |
|---|
| 379 | }*/ |
|---|
| 380 | |
|---|
| 381 | ################################### |
|---|
| 382 | # |
|---|
| 383 | function saveConfig($data) { |
|---|
| 384 | print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG |
|---|
| 385 | |
|---|
| 386 | global $CONFIG_FILE; |
|---|
| 387 | |
|---|
| 388 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
|---|
| 389 | $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); |
|---|
| 390 | |
|---|
| 391 | $defineArrayToken = array (); |
|---|
| 392 | $defineArrayToken = explode('|', $data); |
|---|
| 393 | |
|---|
| 394 | foreach ($defineArrayToken as $nameValue) { |
|---|
| 395 | list ($name, $value) = explode('=', $nameValue); |
|---|
| 396 | $defineArray[$name] = $value; # New define value ($name and value) |
|---|
| 397 | #print "K=$name V=$value<BR>"; # DEBUG |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | foreach ($contentArray as $line) { |
|---|
| 401 | #print "L=$line<BR>\n"; |
|---|
| 402 | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
|---|
| 403 | list ($key, $value) = explode(',', $matchesArray[1]); |
|---|
| 404 | $pattern = array ( |
|---|
| 405 | "/^'/", |
|---|
| 406 | "/'$/" |
|---|
| 407 | ); |
|---|
| 408 | $replacement = array ( |
|---|
| 409 | '', |
|---|
| 410 | '' |
|---|
| 411 | ); |
|---|
| 412 | $key = preg_replace($pattern, $replacement, trim($key)); |
|---|
| 413 | //$value = preg_replace($pattern, $replacement, trim($value)); |
|---|
| 414 | |
|---|
| 415 | if (array_key_exists($key, $defineArray)) { // A new value is defined |
|---|
| 416 | #print "$key EXISTS<BR>"; |
|---|
| 417 | #print "define => (" . $defineArray[$key] . ")<BR>"; |
|---|
| 418 | $pattern = array ( |
|---|
| 419 | "/^\\\'/", |
|---|
| 420 | "/\\\'$/" |
|---|
| 421 | ); |
|---|
| 422 | $replacement = array ( |
|---|
| 423 | "'", |
|---|
| 424 | "'" |
|---|
| 425 | ); |
|---|
| 426 | $value = preg_replace($pattern, $replacement, trim($defineArray[$key])); |
|---|
| 427 | #print "(define('$key', $value);)<BR>"; |
|---|
| 428 | fwrite($fd, "define('$key', $value);\n"); # Write the new define($name, $value) |
|---|
| 429 | } |
|---|
| 430 | else { // The key does not exist (no new value to be saved) |
|---|
| 431 | fwrite($fd, $line); # Write the same line in config.php |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | else { |
|---|
| 435 | fwrite($fd, $line); # Write the line (not a define line). Ex: Commented text |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | ################################### |
|---|
| 441 | # MAIN |
|---|
| 442 | switch ($page) { |
|---|
| 443 | case 'permission' : |
|---|
| 444 | print "<h1>Permissions</h1>"; |
|---|
| 445 | |
|---|
| 446 | $process_info_user_id = posix_getpwuid(posix_getuid()); |
|---|
| 447 | $process_info_group_id = posix_getgrgid(posix_getegid()); |
|---|
| 448 | $process_username = $process_info_user_id['name']; |
|---|
| 449 | $process_group = $process_info_group_id['name']; |
|---|
| 450 | $cmd_mkdir = ''; |
|---|
| 451 | $cmd_chown = ''; |
|---|
| 452 | $error = 0; |
|---|
| 453 | |
|---|
| 454 | print "<p><em>Installation directory (WIFIDOG_ABS_FILE_PATH)</em>: " . WIFIDOG_ABS_FILE_PATH . "</p>"; |
|---|
| 455 | print "<p><em>Note:</em> Please validate that 'Installation directory' value is the right one. If this value is wrong, the PATH automatic detection will not work as properly"; |
|---|
| 456 | print "<p><em>HTTP daemon UNIX username/group</em>: $process_username/$process_group</p>"; |
|---|
| 457 | # print "<p><em>HTTPD group</em>: $process_group<BR</p>"; |
|---|
| 458 | print "<p><table BORDER=\"1\"><tr><td><em>Directory</em></td></td><td><em>Owner</em></td><td><em>Writable</em></td></tr>\n"; |
|---|
| 459 | |
|---|
| 460 | foreach ($dir_array as $dir) { |
|---|
| 461 | print "<tr><td>$dir</td>"; |
|---|
| 462 | if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { |
|---|
| 463 | print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</td></tr>\n"; |
|---|
| 464 | $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 465 | $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 466 | $error = 1; |
|---|
| 467 | continue; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH . "$dir")); |
|---|
| 471 | $dir_owner_username = $dir_info['name']; |
|---|
| 472 | print "<td>$dir_owner_username</td>"; |
|---|
| 473 | |
|---|
| 474 | if (is_writable(WIFIDOG_ABS_FILE_PATH . "$dir")) { |
|---|
| 475 | print "<td>YES</td>"; |
|---|
| 476 | } |
|---|
| 477 | else { |
|---|
| 478 | print "<td>NO</td>"; |
|---|
| 479 | $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 480 | $error = 1; |
|---|
| 481 | } |
|---|
| 482 | print "</tr>\n"; |
|---|
| 483 | } |
|---|
| 484 | print "</table>\n"; |
|---|
| 485 | |
|---|
| 486 | if ($error != 1) { |
|---|
| 487 | navigation(array ( |
|---|
| 488 | array ( |
|---|
| 489 | "title" => "Next", |
|---|
| 490 | "page" => "version" |
|---|
| 491 | ) |
|---|
| 492 | )); |
|---|
| 493 | } |
|---|
| 494 | else { |
|---|
| 495 | refreshButton(); |
|---|
| 496 | print "<p>You need to allow UNIX user <em>$process_username</em> to write to these directories (mkdir, chown or chmod)</p>"; |
|---|
| 497 | if (!empty ($cmd_mkdir) || !empty ($cmd_mkdir)) |
|---|
| 498 | print "<p><b>For instance, you may want to use the following commands</b> :</p>\n"; |
|---|
| 499 | if (!empty ($cmd_mkdir)) |
|---|
| 500 | print "mkdir $cmd_mkdir <br />"; |
|---|
| 501 | if (!empty ($cmd_chown)) |
|---|
| 502 | print "chgrp -R $process_group $cmd_chown;<br/>chmod g+wx $cmd_chown;<br/>"; |
|---|
| 503 | print "<p>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; |
|---|
| 504 | } |
|---|
| 505 | break; |
|---|
| 506 | ################################### |
|---|
| 507 | case 'version' : |
|---|
| 508 | print "<h1>Checking dependencies</h1>"; |
|---|
| 509 | print "<table BORDER=\"1\">"; |
|---|
| 510 | |
|---|
| 511 | /* PHP version check */ |
|---|
| 512 | $phpVersion = phpversion(); |
|---|
| 513 | $okMsg = '<TD ALIGN="CENTER" STYLE="background:lime;">OK</td>'; |
|---|
| 514 | $errorMsg = '<TD ALIGN="CENTER" STYLE="background:red;">ERROR</td>'; |
|---|
| 515 | $warningMsg = '<TD ALIGN="CENTER" STYLE="background:yellow;">Warning</td>'; |
|---|
| 516 | $error = 0; |
|---|
| 517 | |
|---|
| 518 | print "<tr><td>PHP</td>"; |
|---|
| 519 | if (version_compare($phpVersion, $requiredPHPVersion, ">=")) { |
|---|
| 520 | print "$okMsg<td>$phpVersion</td>"; // Version 5.0.0 or later |
|---|
| 521 | } |
|---|
| 522 | else { |
|---|
| 523 | print "$errorMsg<td>Version $requiredPHPVersion needed</td>"; // Version < 5.0.0 |
|---|
| 524 | $error = 1; |
|---|
| 525 | } |
|---|
| 526 | print "</tr></table><BR>"; |
|---|
| 527 | |
|---|
| 528 | require_once ('classes/Dependencies.php'); |
|---|
| 529 | $components = Dependencies::getDependencies(); |
|---|
| 530 | print "<table BORDER=\"1\">\n"; |
|---|
| 531 | print "<tr><th>Component</th><th>Type</th><th>Status</th><th>Description</th><th>Message</th></tr>"; |
|---|
| 532 | |
|---|
| 533 | foreach ($components as $dependency) { |
|---|
| 534 | echo "<tr>\n"; |
|---|
| 535 | $websiteUrl = $dependency->getWebsiteURL(); |
|---|
| 536 | $component_key = $dependency->getId(); |
|---|
| 537 | $description = $dependency->getDescription(); |
|---|
| 538 | $mandatory = $dependency->isMandatory(); |
|---|
| 539 | $type = $dependency->getType(); |
|---|
| 540 | if($websiteUrl){ |
|---|
| 541 | echo "<td><A HREF=\"$websiteUrl\">$component_key</A></td>\n"; |
|---|
| 542 | } |
|---|
| 543 | else{ |
|---|
| 544 | echo "<td>$component_key</td>\n"; |
|---|
| 545 | } |
|---|
| 546 | echo "<td>$type</td>\n"; |
|---|
| 547 | $available = Dependencies::check($component_key, $message); |
|---|
| 548 | if ($available) { |
|---|
| 549 | print "$okMsg<td>$description</td><td> </td></tr>"; |
|---|
| 550 | } |
|---|
| 551 | else { |
|---|
| 552 | if ($mandatory) { |
|---|
| 553 | print "$errorMsg<td>$description</td><td>$message</td></tr>"; |
|---|
| 554 | $error = 1; |
|---|
| 555 | } |
|---|
| 556 | else { |
|---|
| 557 | print "$warningMsg<td>$description</td><td>$message</td></tr>"; |
|---|
| 558 | } |
|---|
| 559 | } |
|---|
| 560 | } |
|---|
| 561 | print "</table><BR>"; |
|---|
| 562 | |
|---|
| 563 | //TODO: PostgreSQL and MySQL version are not validated"; |
|---|
| 564 | print "We recommend you use PostgreSQL 8.0 or newer (but it isn't required)"; |
|---|
| 565 | |
|---|
| 566 | refreshButton(); |
|---|
| 567 | if ($error != 1) { |
|---|
| 568 | navigation(array ( |
|---|
| 569 | array ( |
|---|
| 570 | "title" => "Back", |
|---|
| 571 | "page" => "permission" |
|---|
| 572 | ), |
|---|
| 573 | array ( |
|---|
| 574 | "title" => "Next", |
|---|
| 575 | "page" => "smarty" |
|---|
| 576 | ) |
|---|
| 577 | )); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | break; |
|---|
| 581 | ################################### |
|---|
| 582 | case 'smarty' : // Download, uncompress and install Smarty |
|---|
| 583 | print<<< EndHTML |
|---|
| 584 | <h1>Smarty template engine installation</h1> |
|---|
| 585 | <p><A HREF="http://smarty.php.net/">Smarty</A> is Template Engine. WifiDog requires you install it before you continue.</p> |
|---|
| 586 | EndHTML; |
|---|
| 587 | if ($neededPackages['smarty']['available']) { |
|---|
| 588 | print "Already installed !<br/>"; |
|---|
| 589 | } |
|---|
| 590 | else { |
|---|
| 591 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 592 | list ($url, $filename) = split("=", $smarty_full_url); |
|---|
| 593 | |
|---|
| 594 | print "Download source code ($filename) : "; |
|---|
| 595 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) |
|---|
| 596 | //execVerbose("wget \"$smarty_full_url\" 2>&1", $output, $return); |
|---|
| 597 | downloadFile($smarty_full_url, WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 598 | |
|---|
| 599 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) { |
|---|
| 600 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; |
|---|
| 601 | $output = implode("\n", $output); |
|---|
| 602 | print "<pre><em>wget \"$smarty_full_url\"</em>\n$output</pre>"; |
|---|
| 603 | exit (); |
|---|
| 604 | } |
|---|
| 605 | else { |
|---|
| 606 | print "OK<BR>"; |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | print "Uncompressing : "; |
|---|
| 610 | $dir_array = split(".tar.gz", WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 611 | $dirname = array_shift($dir_array); |
|---|
| 612 | |
|---|
| 613 | if (!file_exists($dirname)) |
|---|
| 614 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 615 | print "OK<BR>"; |
|---|
| 616 | print "Copying : "; |
|---|
| 617 | if (!file_exists(WIFIDOG_ABS_FILE_PATH . "lib/smarty")); |
|---|
| 618 | execVerbose("cp -r $dirname/libs/* " . WIFIDOG_ABS_FILE_PATH . "/lib/smarty", $output, $return); # TODO : Utiliser SMARTY_REL_PATH |
|---|
| 619 | print "OK<BR>"; |
|---|
| 620 | |
|---|
| 621 | refreshButton(); |
|---|
| 622 | } |
|---|
| 623 | navigation(array ( |
|---|
| 624 | array ( |
|---|
| 625 | "title" => "Back", |
|---|
| 626 | "page" => "version" |
|---|
| 627 | ), |
|---|
| 628 | array ( |
|---|
| 629 | "title" => "Next", |
|---|
| 630 | "page" => "simplepie" |
|---|
| 631 | ) |
|---|
| 632 | )); |
|---|
| 633 | break; |
|---|
| 634 | ################################### |
|---|
| 635 | case 'simplepie' : // Download, uncompress and install SimplePie |
|---|
| 636 | print "<h1>SimplePie installation</h1>\n"; |
|---|
| 637 | |
|---|
| 638 | if ($neededPackages['simplepie']['available']) { |
|---|
| 639 | print "Already installed !<BR>"; |
|---|
| 640 | navigation(array ( |
|---|
| 641 | array ( |
|---|
| 642 | "title" => "Back", |
|---|
| 643 | "page" => "smarty" |
|---|
| 644 | ), |
|---|
| 645 | array ( |
|---|
| 646 | "title" => "Next", |
|---|
| 647 | "page" => "feedpressreview" |
|---|
| 648 | ) |
|---|
| 649 | )); |
|---|
| 650 | } |
|---|
| 651 | elseif ($action == 'install') { |
|---|
| 652 | |
|---|
| 653 | print "Download source code frpm svn($filename) : "; |
|---|
| 654 | execVerbose("svn co ".escapeshellarg($neededPackages['simplepie']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/simplepie"), $output, $return); |
|---|
| 655 | #execVerbose("locale", $output, $return); |
|---|
| 656 | |
|---|
| 657 | refreshButton(); |
|---|
| 658 | navigation(array ( |
|---|
| 659 | array ( |
|---|
| 660 | "title" => "Back", |
|---|
| 661 | "page" => "smarty" |
|---|
| 662 | ), |
|---|
| 663 | array ( |
|---|
| 664 | "title" => "Next", |
|---|
| 665 | "page" => "feedpressreview" |
|---|
| 666 | ) |
|---|
| 667 | )); |
|---|
| 668 | } |
|---|
| 669 | else { |
|---|
| 670 | print<<< EndHTML |
|---|
| 671 | <p><A HREF="http://simplepie.org/">SimplePie</A> is a dependency of provides an RSS parser in PHP. It is required for RssPressReview. It's is recommended to install it, if you don't, RSS feeds options will be disabled. |
|---|
| 672 | |
|---|
| 673 | <p>Do you want to install SimplePie ? |
|---|
| 674 | EndHTML; |
|---|
| 675 | navigation(array ( |
|---|
| 676 | array ( |
|---|
| 677 | "title" => "Back", |
|---|
| 678 | "page" => "smarty" |
|---|
| 679 | ), |
|---|
| 680 | array ( |
|---|
| 681 | "title" => "Install", |
|---|
| 682 | "page" => "simplepie", |
|---|
| 683 | "action" => "install" |
|---|
| 684 | ), |
|---|
| 685 | array ( |
|---|
| 686 | "title" => "Next", |
|---|
| 687 | "page" => "feedpressreview" |
|---|
| 688 | ) |
|---|
| 689 | )); |
|---|
| 690 | } |
|---|
| 691 | break; |
|---|
| 692 | ################################### |
|---|
| 693 | case 'feedpressreview' : // Download, uncompress and install feedpressreview |
|---|
| 694 | print "<h1>Feed press review installation</h1>\n"; |
|---|
| 695 | |
|---|
| 696 | if ($neededPackages['feedpressreview']['available']) { |
|---|
| 697 | print "Already installed !<BR>"; |
|---|
| 698 | navigation(array ( |
|---|
| 699 | array ( |
|---|
| 700 | "title" => "Back", |
|---|
| 701 | "page" => "simplepie" |
|---|
| 702 | ), |
|---|
| 703 | array ( |
|---|
| 704 | "title" => "Next", |
|---|
| 705 | "page" => "phlickr" |
|---|
| 706 | ) |
|---|
| 707 | )); |
|---|
| 708 | } |
|---|
| 709 | elseif ($action == 'install') { |
|---|
| 710 | |
|---|
| 711 | print "Download source code frpm svn($filename) : "; |
|---|
| 712 | execVerbose("svn co ".escapeshellarg($neededPackages['feedpressreview']['svn_source'])." ".escapeshellarg(WIFIDOG_ABS_FILE_PATH."lib/feedpressreview"), $output, $return); |
|---|
| 713 | #execVerbose("locale", $output, $return); |
|---|
| 714 | |
|---|
| 715 | refreshButton(); |
|---|
| 716 | navigation(array ( |
|---|
| 717 | array ( |
|---|
| 718 | "title" => "Back", |
|---|
| 719 | "page" => "smarty" |
|---|
| 720 | ), |
|---|
| 721 | array ( |
|---|
| 722 | "title" => "Next", |
|---|
| 723 | "page" => "phlickr" |
|---|
| 724 | ) |
|---|
| 725 | )); |
|---|
| 726 | } |
|---|
| 727 | else { |
|---|
| 728 | print<<< EndHTML |
|---|
| 729 | <p><A HREF="http://projects.coeus.ca/feedpressreview/">Feed press review</A> is a dependency that provides a Feed aggregator in PHP. It is recommended to install it. If you don't, RSS feeds options will be disabled. |
|---|
| 730 | |
|---|
| 731 | <p>Do you want to install FeedPressReview ? |
|---|
| 732 | EndHTML; |
|---|
| 733 | navigation(array ( |
|---|
| 734 | array ( |
|---|
| 735 | "title" => "Back", |
|---|
| 736 | "page" => "simplepie" |
|---|
| 737 | ), |
|---|
| 738 | array ( |
|---|
| 739 | "title" => "Install", |
|---|
| 740 | "page" => "feedpressreview", |
|---|
| 741 | "action" => "install" |
|---|
| 742 | ), |
|---|
| 743 | array ( |
|---|
| 744 | "title" => "Next", |
|---|
| 745 | "page" => "phlickr" |
|---|
| 746 | ) |
|---|
| 747 | )); |
|---|
| 748 | } |
|---|
| 749 | break; |
|---|
| 750 | ################################### |
|---|
| 751 | case 'phlickr' : // Download, uncompress and install phlickr library |
|---|
| 752 | print "<h1>Phlickr installation</h1>\n"; |
|---|
| 753 | |
|---|
| 754 | if ($neededPackages['phlickr']['available']) { |
|---|
| 755 | print "Already installed !<BR>"; |
|---|
| 756 | navigation(array ( |
|---|
| 757 | array ( |
|---|
| 758 | "title" => "Back", |
|---|
| 759 | "page" => "simplepie" |
|---|
| 760 | ), |
|---|
| 761 | array ( |
|---|
| 762 | "title" => "Next", |
|---|
| 763 | "page" => "database" |
|---|
| 764 | ) |
|---|
| 765 | )); |
|---|
| 766 | } |
|---|
| 767 | elseif ($action == 'install') { |
|---|
| 768 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 769 | $filename_array = preg_split("/\//", $phlickr_full_url); |
|---|
| 770 | $filename = array_pop($filename_array); |
|---|
| 771 | |
|---|
| 772 | print "Download source code ($filename) : "; |
|---|
| 773 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) |
|---|
| 774 | //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); |
|---|
| 775 | downloadFile($phlickr_full_url, WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 776 | |
|---|
| 777 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) { # Error occured, print output of wget |
|---|
| 778 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp/smarty</em>"; |
|---|
| 779 | $output = implode("\n", $output); |
|---|
| 780 | print "<pre><em>wget \"$phlickr_full_url\"</em>\n$output</pre>"; |
|---|
| 781 | exit (); |
|---|
| 782 | } |
|---|
| 783 | else { |
|---|
| 784 | print "OK<BR>"; |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | print "Uncompressing : "; |
|---|
| 788 | $dirname_array = split(".tgz", WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 789 | $dirname = array_shift($dirname_array); |
|---|
| 790 | if (!file_exists($dirname)) |
|---|
| 791 | execVerbose("tar -xzf $dirname.tgz", $output, $return); |
|---|
| 792 | print "OK<BR>"; |
|---|
| 793 | |
|---|
| 794 | print "Copying : "; |
|---|
| 795 | if (!file_exists(WIFIDOG_ABS_FILE_PATH.'/Phlickr/Photo.php')) |
|---|
| 796 | execVerbose("cp -r $dirname/* ".WIFIDOG_ABS_FILE_PATH."lib/Phlickr", $output, $return); |
|---|
| 797 | print "OK<BR>"; |
|---|
| 798 | |
|---|
| 799 | refreshButton(); |
|---|
| 800 | // Skipping jpgraph install |
|---|
| 801 | navigation(array ( |
|---|
| 802 | array ( |
|---|
| 803 | "title" => "Back", |
|---|
| 804 | "page" => "simplepie" |
|---|
| 805 | ), |
|---|
| 806 | array ( |
|---|
| 807 | "title" => "Next", |
|---|
| 808 | "page" => "database" |
|---|
| 809 | ) |
|---|
| 810 | )); |
|---|
| 811 | } |
|---|
| 812 | else { |
|---|
| 813 | print<<< EndHTML |
|---|
| 814 | <p><A HREF="http://phlickr.sourceforge.net/">Phlickr</A> is an Open Source PHP 5 interface to the Flickr API. <A HREF="http://flickr.com/">Flickr</A> is a digital photo sharing website. Phlickr allows WifiDog to display pictures from Flickr on its portal pages. Phlickr is thus an optional package.. |
|---|
| 815 | |
|---|
| 816 | <p>Do you want to install Phlickr ? |
|---|
| 817 | EndHTML; |
|---|
| 818 | navigation(array ( |
|---|
| 819 | array ( |
|---|
| 820 | "title" => "Back", |
|---|
| 821 | "page" => "simplepie" |
|---|
| 822 | ), |
|---|
| 823 | array ( |
|---|
| 824 | "title" => "Install", |
|---|
| 825 | "page" => "phlickr", |
|---|
| 826 | "action" => "install" |
|---|
| 827 | ), |
|---|
| 828 | array ( |
|---|
| 829 | "title" => "Next", |
|---|
| 830 | "page" => "database" |
|---|
| 831 | ) |
|---|
| 832 | )); |
|---|
| 833 | } |
|---|
| 834 | break; |
|---|
| 835 | ################################### |
|---|
| 836 | case 'jpgraph' : // Download, uncompress and install JpGraph library |
|---|
| 837 | print "<h1>JpGraph installation</h1>\n"; |
|---|
| 838 | |
|---|
| 839 | if ($neededPackages['jpgraph']['available']) { |
|---|
| 840 | print "Already installed !<BR>"; |
|---|
| 841 | navigation(array ( |
|---|
| 842 | array ( |
|---|
| 843 | "title" => "Back", |
|---|
| 844 | "page" => "phlickr" |
|---|
| 845 | ), |
|---|
| 846 | array ( |
|---|
| 847 | "title" => "Next", |
|---|
| 848 | "page" => "database" |
|---|
| 849 | ) |
|---|
| 850 | )); |
|---|
| 851 | } |
|---|
| 852 | elseif ($action == 'install') { |
|---|
| 853 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 854 | $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); |
|---|
| 855 | |
|---|
| 856 | print "Download source code ($filename) : "; |
|---|
| 857 | if (!file_exists($filename)) |
|---|
| 858 | execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); |
|---|
| 859 | if (!file_exists($filename)) { # Error occured, print output of wget |
|---|
| 860 | print "<B STYLE=\"color:red\">Error</b><p>Current working directory : <em>$basepath/tmp</em>"; |
|---|
| 861 | $output = implode("\n", $output); |
|---|
| 862 | print "<pre><em>wget \"$jpgraph_full_url\"</em>\n$output</pre>"; |
|---|
| 863 | exit (); |
|---|
| 864 | } |
|---|
| 865 | else { |
|---|
| 866 | print "OK<BR>"; |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | print "Uncompressing : "; |
|---|
| 870 | $dirname = array_shift(split(".tar.gz", $filename)); |
|---|
| 871 | if (!file_exists($dirname)) |
|---|
| 872 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 873 | print "OK<BR>"; |
|---|
| 874 | |
|---|
| 875 | print "Copying : "; |
|---|
| 876 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."lib/jpgraph/jpgraph.php")) |
|---|
| 877 | execVerbose("cp $dirname/src/* ".WIFIDOG_ABS_FILE_PATH."lib/jpgraph", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH |
|---|
| 878 | |
|---|
| 879 | print "OK<BR>"; |
|---|
| 880 | |
|---|
| 881 | refreshButton(); |
|---|
| 882 | navigation(array ( |
|---|
| 883 | array ( |
|---|
| 884 | "title" => "Back", |
|---|
| 885 | "page" => "phlickr" |
|---|
| 886 | ), |
|---|
| 887 | array ( |
|---|
| 888 | "title" => "Next", |
|---|
| 889 | "page" => "database" |
|---|
| 890 | ) |
|---|
| 891 | )); |
|---|
| 892 | } |
|---|
| 893 | else { |
|---|
| 894 | print<<< EndHTML |
|---|
| 895 | <p><A HREF="http://www.aditus.nu/jpgraph/">JpGraph</A> is a Object-Oriented Graph creating library for PHP. |
|---|
| 896 | JpGraph is not currently use by Wifidog (will be use for statistique graph in a later version). You can skip this installation if your not a developper. |
|---|
| 897 | |
|---|
| 898 | <p>Do you want to install JpGraph ? |
|---|
| 899 | EndHTML; |
|---|
| 900 | navigation(array ( |
|---|
| 901 | array ( |
|---|
| 902 | "title" => "Back", |
|---|
| 903 | "page" => "phlickr" |
|---|
| 904 | ), |
|---|
| 905 | array ( |
|---|
| 906 | "title" => "Install", |
|---|
| 907 | "page" => "jpgraph", |
|---|
| 908 | "action" => "install" |
|---|
| 909 | ), |
|---|
| 910 | array ( |
|---|
| 911 | "title" => "Next", |
|---|
| 912 | "page" => "database" |
|---|
| 913 | ) |
|---|
| 914 | )); |
|---|
| 915 | } |
|---|
| 916 | break; |
|---|
| 917 | ################################### |
|---|
| 918 | case 'database' : |
|---|
| 919 | ### TODO : Valider en javascript que les champs soumit ne sont pas vide |
|---|
| 920 | # Pouvoir choisir le port de la DB ??? |
|---|
| 921 | print<<< EndHTML |
|---|
| 922 | <h1>Database access configuration</h1> |
|---|
| 923 | <BR> |
|---|
| 924 | <table border="1"> |
|---|
| 925 | <tr><td>Host</td><td><INPUT type="text" name="CONF_DATABASE_HOST" value="$CONF_DATABASE_HOST"></td></tr> |
|---|
| 926 | <tr><td>DB Name</td><td><INPUT type="text" name="CONF_DATABASE_NAME" value="$CONF_DATABASE_NAME"></td></tr> |
|---|
| 927 | <tr><td>Username</td><td><INPUT type="text" name="CONF_DATABASE_USER" value="$CONF_DATABASE_USER"></td></tr> |
|---|
| 928 | <tr><td>Password</td><td><INPUT type="text" name="CONF_DATABASE_PASSWORD" value="$CONF_DATABASE_PASSWORD"></td></tr> |
|---|
| 929 | </table> |
|---|
| 930 | |
|---|
| 931 | <p>By clicking Next, your configuration will be automaticaly saved |
|---|
| 932 | |
|---|
| 933 | <script type="text/javascript"> |
|---|
| 934 | function submitDatabaseValue() { |
|---|
| 935 | newConfig("CONF_DATABASE_HOST='" + document.myform.CONF_DATABASE_HOST.value + "'"); |
|---|
| 936 | newConfig("CONF_DATABASE_NAME='" + document.myform.CONF_DATABASE_NAME.value + "'"); |
|---|
| 937 | newConfig("CONF_DATABASE_USER='" + document.myform.CONF_DATABASE_USER.value + "'"); |
|---|
| 938 | newConfig("CONF_DATABASE_PASSWORD='" + document.myform.CONF_DATABASE_PASSWORD.value + "'"); |
|---|
| 939 | } |
|---|
| 940 | </script> |
|---|
| 941 | |
|---|
| 942 | EndHTML; |
|---|
| 943 | |
|---|
| 944 | navigation(array ( |
|---|
| 945 | array ( |
|---|
| 946 | "title" => "Back", |
|---|
| 947 | "page" => "simplepie" |
|---|
| 948 | ) |
|---|
| 949 | )); #, array("title" => "Next", "page" => "testdatabase"))); |
|---|
| 950 | print<<< EndHTML |
|---|
| 951 | <p><A HREF="#" ONCLICK="javascript: document.myform.page.value='testdatabase'; submitDatabaseValue(); document.myform.submit();" CLASS="button">Next</A></p> |
|---|
| 952 | |
|---|
| 953 | EndHTML; |
|---|
| 954 | |
|---|
| 955 | break; |
|---|
| 956 | ################################### |
|---|
| 957 | case 'testdatabase' : |
|---|
| 958 | print "<h1>Database connection</h1>"; |
|---|
| 959 | /* TODO : Tester la version minimale requise de Postgresql */ |
|---|
| 960 | |
|---|
| 961 | print "<UL><LI>Postgresql database connection : "; |
|---|
| 962 | |
|---|
| 963 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 964 | $ptr_connexion = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
|---|
| 965 | |
|---|
| 966 | #if ($ptr_connexion == TRUE) { |
|---|
| 967 | print "Success<BR>"; |
|---|
| 968 | #} |
|---|
| 969 | # } else { |
|---|
| 970 | # print "Unable to connect to database on $CONF_DATABASE_HOST<BR>The database must be online to continue.<BR>Please go back and retry with correct values"; |
|---|
| 971 | # navigation(array(array("title" => "Back", "page" => "database"))); |
|---|
| 972 | # } |
|---|
| 973 | |
|---|
| 974 | $postgresql_info = pg_version(); |
|---|
| 975 | # $postgresql_info['server']; |
|---|
| 976 | # if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } |
|---|
| 977 | |
|---|
| 978 | print "</UL>"; |
|---|
| 979 | refreshButton(); |
|---|
| 980 | navigation(array ( |
|---|
| 981 | array ( |
|---|
| 982 | "title" => "Back", |
|---|
| 983 | "page" => "database" |
|---|
| 984 | ), |
|---|
| 985 | array ( |
|---|
| 986 | "title" => "Next", |
|---|
| 987 | "page" => "dbinit" |
|---|
| 988 | ) |
|---|
| 989 | )); |
|---|
| 990 | break; |
|---|
| 991 | ################################### |
|---|
| 992 | case 'dbinit' : |
|---|
| 993 | print "<h1>Database initialisation</h1>"; |
|---|
| 994 | |
|---|
| 995 | # SQL are executed with PHP, some lignes need to be commented |
|---|
| 996 | $file_db_version = 'UNKNOW'; |
|---|
| 997 | $patterns[0] = '/CREATE DATABASE wifidog/'; |
|---|
| 998 | $patterns[1] = '/\\\connect/'; |
|---|
| 999 | $patterns[2] = '/COMMENT/'; |
|---|
| 1000 | $patterns[3] = '/SET default_tablespace/'; |
|---|
| 1001 | $patterns[4] = '/SET default_with_oids/'; |
|---|
| 1002 | $replacements[0] = '-- '; |
|---|
| 1003 | $replacements[1] = '-- '; |
|---|
| 1004 | $replacements[2] = '-- '; |
|---|
| 1005 | $replacements[3] = '-- '; |
|---|
| 1006 | $replacements[4] = '-- '; |
|---|
| 1007 | |
|---|
| 1008 | $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<em>Error</em>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file |
|---|
| 1009 | $content_schema = implode("", $content_schema_array); |
|---|
| 1010 | $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file |
|---|
| 1011 | $content_data = implode("", $content_data_array); |
|---|
| 1012 | |
|---|
| 1013 | $db_schema_version = ''; # Schema version query from database |
|---|
| 1014 | $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php |
|---|
| 1015 | |
|---|
| 1016 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 1017 | $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
|---|
| 1018 | |
|---|
| 1019 | if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file |
|---|
| 1020 | $file_db_version = $matchesArray[1]; |
|---|
| 1021 | |
|---|
| 1022 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); |
|---|
| 1023 | foreach ($contentArray as $line) { |
|---|
| 1024 | #print "$line<BR>"; # Debug |
|---|
| 1025 | if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { |
|---|
| 1026 | #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; |
|---|
| 1027 | $file_schema_version = $matchesArray[1]; |
|---|
| 1028 | } |
|---|
| 1029 | } |
|---|
| 1030 | |
|---|
| 1031 | # Get current database schema version (if defined) |
|---|
| 1032 | $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; |
|---|
| 1033 | if ($result = @ pg_query($connection, $sql)) { # The @ remove warning display |
|---|
| 1034 | $result_array = pg_fetch_all($result); |
|---|
| 1035 | $db_shema_version = $result_array[0]['value']; |
|---|
| 1036 | |
|---|
| 1037 | print "<p>On <em>$CONF_DATABASE_HOST</em>, Database <em>$CONF_DATABASE_NAME</em> exists and is "; |
|---|
| 1038 | if ($db_shema_version == $file_schema_version) { |
|---|
| 1039 | print "up to date (shema version <em>$db_shema_version</em>)."; |
|---|
| 1040 | navigation(array ( |
|---|
| 1041 | array ( |
|---|
| 1042 | "title" => "Back", |
|---|
| 1043 | "page" => "database" |
|---|
| 1044 | ), |
|---|
| 1045 | array ( |
|---|
| 1046 | "title" => "Next", |
|---|
| 1047 | "page" => "options" |
|---|
| 1048 | ) |
|---|
| 1049 | )); |
|---|
| 1050 | } |
|---|
| 1051 | elseif ($db_shema_version < $file_schema_version) { |
|---|
| 1052 | print "at schema version <em>$db_shema_version</em>. The required schema version is <em>$file_schema_version</em><p>Please upgrade the database"; |
|---|
| 1053 | navigation(array ( |
|---|
| 1054 | array ( |
|---|
| 1055 | "title" => "Back", |
|---|
| 1056 | "page" => "database" |
|---|
| 1057 | ), |
|---|
| 1058 | array ( |
|---|
| 1059 | "title" => "Upgrade", |
|---|
| 1060 | "page" => "schema_validate" |
|---|
| 1061 | ), |
|---|
| 1062 | array ( |
|---|
| 1063 | "title" => "Next", |
|---|
| 1064 | "page" => "options" |
|---|
| 1065 | ) |
|---|
| 1066 | )); |
|---|
| 1067 | } |
|---|
| 1068 | else { |
|---|
| 1069 | print "Error : Unexpected result"; |
|---|
| 1070 | } |
|---|
| 1071 | exit (); |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | print "<UL><LI>Creating wifidog database schema : "; |
|---|
| 1075 | $content_schema = preg_replace($patterns, $replacements, $content_schema); # Comment bad SQL lines |
|---|
| 1076 | |
|---|
| 1077 | $result = pg_query($connection, $content_schema) or die("<em>" . pg_last_error() . "</em> <=<BR>"); |
|---|
| 1078 | print "OK"; |
|---|
| 1079 | |
|---|
| 1080 | print "<LI>Creating wifidog database initial data : "; |
|---|
| 1081 | $content_data = preg_replace($patterns, $replacements, $content_data); # Comment bad SQL lines |
|---|
| 1082 | |
|---|
| 1083 | $result = pg_query($connection, $content_data) or die("<em>" . pg_last_error() . "</em> <=<BR>"); |
|---|
| 1084 | print "OK</UL>"; |
|---|
| 1085 | |
|---|
| 1086 | navigation(array ( |
|---|
| 1087 | array ( |
|---|
| 1088 | "title" => "Back", |
|---|
| 1089 | "page" => "database" |
|---|
| 1090 | ), |
|---|
| 1091 | array ( |
|---|
| 1092 | "title" => "Next", |
|---|
| 1093 | "page" => "options" |
|---|
| 1094 | ) |
|---|
| 1095 | )); |
|---|
| 1096 | break; |
|---|
| 1097 | |
|---|
| 1098 | ################################### |
|---|
| 1099 | case 'schema_validate' : |
|---|
| 1100 | print "<h1>Database schema upgrade</h1>\n"; |
|---|
| 1101 | |
|---|
| 1102 | require_once (dirname(__FILE__) . '/include/common.php'); |
|---|
| 1103 | |
|---|
| 1104 | require_once ('classes/AbstractDb.php'); |
|---|
| 1105 | require_once ('classes/Session.php'); |
|---|
| 1106 | require_once ('include/schema_validate.php'); |
|---|
| 1107 | |
|---|
| 1108 | validate_schema(); |
|---|
| 1109 | |
|---|
| 1110 | navigation(array ( |
|---|
| 1111 | array ( |
|---|
| 1112 | "title" => "Back", |
|---|
| 1113 | "page" => "dbinit" |
|---|
| 1114 | ), |
|---|
| 1115 | array ( |
|---|
| 1116 | "title" => "Next", |
|---|
| 1117 | "page" => "options" |
|---|
| 1118 | ) |
|---|
| 1119 | )); |
|---|
| 1120 | |
|---|
| 1121 | //navigation(array(array("title" => "Back", "page" => "dbinit"))); |
|---|
| 1122 | break; |
|---|
| 1123 | |
|---|
| 1124 | ################################### |
|---|
| 1125 | case 'options' : |
|---|
| 1126 | # TODO : Tester que la connection SSL est fonctionnelle |
|---|
| 1127 | # Options avancees : Supporter les define de [SMARTY|PHLICKR|JPGRAPH]_REL_PATH |
|---|
| 1128 | print<<< EndHTML |
|---|
| 1129 | <h1>Available options</h1> |
|---|
| 1130 | <table border="1"> |
|---|
| 1131 | |
|---|
| 1132 | EndHTML; |
|---|
| 1133 | |
|---|
| 1134 | //echo '<pre>';print_r($optionsInfo);echo '</pre>'; |
|---|
| 1135 | foreach ($optionsInfo as $name => $foo) { # Foreach generate all <table> fields |
|---|
| 1136 | $value = $configArray[$name]; # Value of option in config.php |
|---|
| 1137 | $title = $optionsInfo[$name]['title']; # Field Title |
|---|
| 1138 | $message = $optionsInfo[$name]['message']; # Message why option is disable |
|---|
| 1139 | if(empty($value)) |
|---|
| 1140 | $message .= ", ERROR: unable to find the '$name' directive in the config file"; |
|---|
| 1141 | $depend = @ eval ($optionsInfo[$name]['depend']); # Evaluate the dependencie |
|---|
| 1142 | $selectedTrue = ''; |
|---|
| 1143 | $selectedFalse = ''; # Initialize value |
|---|
| 1144 | $value == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED'; # Use to select the previous saved option |
|---|
| 1145 | $depend == 1 ? $disabled = '' : $disabled = 'DISABLED'; # Disable <SELECT> if dependencie is not satisfied |
|---|
| 1146 | $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) |
|---|
| 1147 | if ($disabled == '') # Dependencie ok, erase $jscript value |
|---|
| 1148 | $jscript = ''; |
|---|
| 1149 | |
|---|
| 1150 | print<<< EndHTML |
|---|
| 1151 | <tr> |
|---|
| 1152 | <td>$title</td> |
|---|
| 1153 | <td><SELECT name="$name" $disabled> |
|---|
| 1154 | <OPTION value="true" $selectedTrue>true</OPTION> |
|---|
| 1155 | <OPTION value="false" $selectedFalse>false</OPTION> |
|---|
| 1156 | </SELECT> |
|---|
| 1157 | </td> |
|---|
| 1158 | <td>$message</td> |
|---|
| 1159 | </tr> |
|---|
| 1160 | $jscript |
|---|
| 1161 | EndHTML; |
|---|
| 1162 | } # End or foreach |
|---|
| 1163 | print<<< EndHTML |
|---|
| 1164 | </table> |
|---|
| 1165 | |
|---|
| 1166 | <script type="text/javascript"> |
|---|
| 1167 | function submitOptionsValue() { |
|---|
| 1168 | |
|---|
| 1169 | EndHTML; |
|---|
| 1170 | |
|---|
| 1171 | foreach ($optionsInfo as $name => $foo) { # Generate the javascript to save value on submit |
|---|
| 1172 | print<<< EndHTML |
|---|
| 1173 | if (!document.myform.$name.disabled) |
|---|
| 1174 | newConfig("$name=" + document.myform.$name.value); |
|---|
| 1175 | |
|---|
| 1176 | EndHTML; |
|---|
| 1177 | } # End Foreach |
|---|
| 1178 | |
|---|
| 1179 | print<<< EndHTML |
|---|
| 1180 | } |
|---|
| 1181 | </script> |
|---|
| 1182 | |
|---|
| 1183 | EndHTML; |
|---|
| 1184 | navigation(array ( |
|---|
| 1185 | array ( |
|---|
| 1186 | "title" => "Back", |
|---|
| 1187 | "page" => "dbinit" |
|---|
| 1188 | ) |
|---|
| 1189 | )); |
|---|
| 1190 | |
|---|
| 1191 | print<<< EndHTML |
|---|
| 1192 | <p><A HREF="#" ONCLICK="javascript: document.myform.page.value='languages'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></p> |
|---|
| 1193 | EndHTML; |
|---|
| 1194 | |
|---|
| 1195 | break; |
|---|
| 1196 | |
|---|
| 1197 | ################################### |
|---|
| 1198 | case 'languages' : |
|---|
| 1199 | print "<h1>Languages configuration</h1>"; |
|---|
| 1200 | print<<< EndHTML |
|---|
| 1201 | <p>Not yet implemented ...</p> |
|---|
| 1202 | <p>Will allow selecting language to use.</p> |
|---|
| 1203 | <em>Error message example</em> : <BR> |
|---|
| 1204 | <DIV style="border:solid black;">Warning: language.php: Unable to setlocale() to fr, return value: , current locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C; [...]</DIV> |
|---|
| 1205 | <p><em>I repeat</em> : This is an example of message you can see in the top of your working auth-server if language are not set correctly. To change these values please edit <em>config.php</em> in auth-server install directory. Look for "Available locales" and "Default language" header in config.php. |
|---|
| 1206 | EndHTML; |
|---|
| 1207 | // execVerbose("locale -a 2>&1", $output, $return); |
|---|
| 1208 | |
|---|
| 1209 | navigation(array ( |
|---|
| 1210 | array ( |
|---|
| 1211 | "title" => "Back", |
|---|
| 1212 | "page" => "options" |
|---|
| 1213 | ), |
|---|
| 1214 | array ( |
|---|
| 1215 | "title" => "Next", |
|---|
| 1216 | "page" => "radius" |
|---|
| 1217 | ) |
|---|
| 1218 | )); |
|---|
| 1219 | break; |
|---|
| 1220 | |
|---|
| 1221 | ################################### |
|---|
| 1222 | case 'radius' : |
|---|
| 1223 | print "<h1>Radius Authenticator configuration</h1>"; |
|---|
| 1224 | print "<p>Not yet implemented ..."; |
|---|
| 1225 | |
|---|
| 1226 | navigation(array ( |
|---|
| 1227 | array ( |
|---|
| 1228 | "title" => "Back", |
|---|
| 1229 | "page" => "languages" |
|---|
| 1230 | ), |
|---|
| 1231 | array ( |
|---|
| 1232 | "title" => "Next", |
|---|
| 1233 | "page" => "admin" |
|---|
| 1234 | ) |
|---|
| 1235 | )); |
|---|
| 1236 | break; |
|---|
| 1237 | |
|---|
| 1238 | ################################### |
|---|
| 1239 | case 'admin' : |
|---|
| 1240 | print "<h1>Administration account</h1>"; |
|---|
| 1241 | # TODO : Allow to create more than one admin account and list the current admin users |
|---|
| 1242 | # Allow admin to choose to show or not is username |
|---|
| 1243 | empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; |
|---|
| 1244 | empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; |
|---|
| 1245 | empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; |
|---|
| 1246 | empty ($_REQUEST['email']) ? $email = $_SERVER['SERVER_ADMIN'] : $email = $_REQUEST['email']; |
|---|
| 1247 | |
|---|
| 1248 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 1249 | $connection = pg_connect($conn_string) or die(); |
|---|
| 1250 | |
|---|
| 1251 | if ($action == 'create') { |
|---|
| 1252 | // require_once(dirname(__FILE__) . '/config.php'); |
|---|
| 1253 | require_once (dirname(__FILE__) . '/include/common.php'); |
|---|
| 1254 | require_once (dirname(__FILE__) . '/classes/User.php'); |
|---|
| 1255 | |
|---|
| 1256 | $created_user = User :: createUser(get_guid(), $username, Network :: getDefaultNetwork(), $email, $password); |
|---|
| 1257 | $user_id = $created_user->getId(); |
|---|
| 1258 | |
|---|
| 1259 | # Add user to admin table, hide his username and set his account status to 1 (allowed) |
|---|
| 1260 | $sql = "INSERT INTO administrators (user_id) VALUES ('$user_id'); UPDATE users SET account_status='1', never_show_username=true WHERE user_id='$user_id'"; |
|---|
| 1261 | $result = pg_query($connection, $sql); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | $sql = "SELECT * FROM users NATURAL JOIN administrators WHERE account_origin = 'default-network'"; |
|---|
| 1265 | $result = pg_query($connection, $sql); |
|---|
| 1266 | $result_array = pg_fetch_all($result); |
|---|
| 1267 | $username_db = $result_array[0]['username']; |
|---|
| 1268 | |
|---|
| 1269 | if (!empty ($username_db)) { |
|---|
| 1270 | print "<p>Your administrator user account is <em>$username_db</em>"; |
|---|
| 1271 | navigation(array ( |
|---|
| 1272 | array ( |
|---|
| 1273 | "title" => "Back", |
|---|
| 1274 | "page" => "radius" |
|---|
| 1275 | ), |
|---|
| 1276 | array ( |
|---|
| 1277 | "title" => "Next", |
|---|
| 1278 | "page" => "network" |
|---|
| 1279 | ) |
|---|
| 1280 | )); |
|---|
| 1281 | } |
|---|
| 1282 | else { |
|---|
| 1283 | print<<<EndHTML |
|---|
| 1284 | <p> |
|---|
| 1285 | <table BORDER="1"> |
|---|
| 1286 | <tr> |
|---|
| 1287 | <td>Username</td><td><INPUT type="text" name="username" value="$username"></td> |
|---|
| 1288 | </tr> |
|---|
| 1289 | <tr> |
|---|
| 1290 | <td>Password</td><td><INPUT type="password" name="password"></td> |
|---|
| 1291 | </tr> |
|---|
| 1292 | <tr> |
|---|
| 1293 | <td>Password again</td><td><INPUT type="password" name="password2"></td> |
|---|
| 1294 | </tr> |
|---|
| 1295 | <tr> |
|---|
| 1296 | <td>Email</td><td><INPUT type="text" name="email" value="$email"></td> |
|---|
| 1297 | </tr> |
|---|
| 1298 | </table> |
|---|
| 1299 | |
|---|
| 1300 | <script type="text/javascript"> |
|---|
| 1301 | function submitValue() { |
|---|
| 1302 | if (document.myform.password.value != document.myform.password2.value) { |
|---|
| 1303 | alert('Password mismatch, Please retry'); |
|---|
| 1304 | exit(); |
|---|
| 1305 | } |
|---|
| 1306 | if (document.myform.password.value == '') { |
|---|
| 1307 | alert('You need to type a password'); |
|---|
| 1308 | exit(); |
|---|
| 1309 | } |
|---|
| 1310 | if (document.myform.email.value == '') { |
|---|
| 1311 | alert('You need to type a email'); |
|---|
| 1312 | exit(); |
|---|
| 1313 | } |
|---|
| 1314 | document.myform.page.value='admin'; |
|---|
| 1315 | document.myform.action.value='create'; |
|---|
| 1316 | document.myform.submit(); |
|---|
| 1317 | } |
|---|
| 1318 | </script> |
|---|
| 1319 | |
|---|
| 1320 | EndHTML; |
|---|
| 1321 | navigation(array ( |
|---|
| 1322 | array ( |
|---|
| 1323 | "title" => "Back", |
|---|
| 1324 | "page" => "radius" |
|---|
| 1325 | ) |
|---|
| 1326 | )); |
|---|
| 1327 | print "<p><A HREF=\"#\" ONCLICK=\"javascript: submitValue();\" CLASS=\"button\">Next</A></p>\n"; |
|---|
| 1328 | } |
|---|
| 1329 | break; |
|---|
| 1330 | |
|---|
| 1331 | ################################### |
|---|
| 1332 | case 'network' : |
|---|
| 1333 | print "<h1>Network</h1>"; |
|---|
| 1334 | |
|---|
| 1335 | //$HOTSPOT_NETWORK_NAME = $configArray['HOTSPOT_NETWORK_NAME']; |
|---|
| 1336 | //$HOTSPOT_NETWORK_URL = $configArray['HOTSPOT_NETWORK_URL']; |
|---|
| 1337 | //$TECH_SUPPORT_EMAIL = $configArray['TECH_SUPPORT_EMAIL']; |
|---|
| 1338 | //$VALIDATION_GRACE_TIME = $configArray['VALIDATION_GRACE_TIME']; |
|---|
| 1339 | //$VALIDATION_EMAIL_FROM_ADDRESS = $configArray['VALIDATION_EMAIL_FROM_ADDRESS']; |
|---|
| 1340 | |
|---|
| 1341 | /** |
|---|
| 1342 | * @deprecated 2005-12-26 Needs to use network abstraction |
|---|
| 1343 | * |
|---|
| 1344 | * |
|---|
| 1345 | * <p> |
|---|
| 1346 | <table border="1"> |
|---|
| 1347 | <tr> |
|---|
| 1348 | <td>Network Name</td><td><INPUT type="text" name="HOTSPOT_NETWORK_NAME" value="" size="30"></td> |
|---|
| 1349 | </tr> |
|---|
| 1350 | <tr> |
|---|
| 1351 | <td>Network URL</td><td><INPUT type="text" name="HOTSPOT_NETWORK_URL" value="" size="30"></td> |
|---|
| 1352 | </tr> |
|---|
| 1353 | <tr> |
|---|
| 1354 | <td>Tech Support Email</td><td><INPUT type="text" name="TECH_SUPPORT_EMAIL" value="" size="30"></td> |
|---|
| 1355 | </tr> |
|---|
| 1356 | <tr> |
|---|
| 1357 | <td>Validation Grace Time (min)</td><td><INPUT type="text" name="VALIDATION_GRACE_TIME" value="" size="30"></td> |
|---|
| 1358 | </tr> |
|---|
| 1359 | <tr> |
|---|
| 1360 | <td>Validation Email (send from)</td><td><INPUT type="text" name="VALIDATION_EMAIL_FROM_ADDRESS" value="" size="30"></td> |
|---|
| 1361 | </tr> |
|---|
| 1362 | </table> |
|---|
| 1363 | */ |
|---|
| 1364 | print "Need to reimplement this... Until then connect to the administration pages and modify it by yourself."; |
|---|
| 1365 | |
|---|
| 1366 | print<<< EndHTML |
|---|
| 1367 | |
|---|
| 1368 | |
|---|
| 1369 | <script type="text/javascript"> |
|---|
| 1370 | function submitOptionsValue() { |
|---|
| 1371 | //newConfig("HOTSPOT_NETWORK_NAME='" + document.myform.HOTSPOT_NETWORK_NAME.value + "'"); |
|---|
| 1372 | //newConfig("HOTSPOT_NETWORK_URL='" + document.myform.HOTSPOT_NETWORK_URL.value + "'"); |
|---|
| 1373 | //newConfig("TECH_SUPPORT_EMAIL='" + document.myform.TECH_SUPPORT_EMAIL.value + "'"); |
|---|
| 1374 | //newConfig("VALIDATION_GRACE_TIME=" + document.myform.VALIDATION_GRACE_TIME.value); |
|---|
| 1375 | //newConfig("VALIDATION_EMAIL_FROM_ADDRESS='" + document.myform.VALIDATION_EMAIL_FROM_ADDRESS.value + "'"); |
|---|
| 1376 | } |
|---|
| 1377 | </script> |
|---|
| 1378 | |
|---|
| 1379 | EndHTML; |
|---|
| 1380 | |
|---|
| 1381 | navigation(array ( |
|---|
| 1382 | array ( |
|---|
| 1383 | "title" => "Back", |
|---|
| 1384 | "page" => "admin" |
|---|
| 1385 | ) |
|---|
| 1386 | )); |
|---|
| 1387 | |
|---|
| 1388 | print<<< EndHTML |
|---|
| 1389 | <p><A HREF="#" ONCLICK="javascript: document.myform.page.value='hotspot'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></p> |
|---|
| 1390 | EndHTML; |
|---|
| 1391 | #navigation(array(array("title" => "Back", "page" => "admin"), array("title" => "Next", "page" => "hotspot"))); |
|---|
| 1392 | break; |
|---|
| 1393 | |
|---|
| 1394 | ################################### |
|---|
| 1395 | case 'hotspot' : |
|---|
| 1396 | print "<h1>Hotspot</h1>"; |
|---|
| 1397 | print "<p>A default hotspot has already been created<p>Use administration interface to add more hotspots."; |
|---|
| 1398 | navigation(array ( |
|---|
| 1399 | array ( |
|---|
| 1400 | "title" => "Back", |
|---|
| 1401 | "page" => "network" |
|---|
| 1402 | ), |
|---|
| 1403 | array ( |
|---|
| 1404 | "title" => "Next", |
|---|
| 1405 | "page" => "end" |
|---|
| 1406 | ) |
|---|
| 1407 | )); |
|---|
| 1408 | break; |
|---|
| 1409 | |
|---|
| 1410 | ################################### |
|---|
| 1411 | case 'delete' : |
|---|
| 1412 | print<<<EndHTML |
|---|
| 1413 | <h1>Delete temporary files</h1> |
|---|
| 1414 | ... |
|---|
| 1415 | EndHTML; |
|---|
| 1416 | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
|---|
| 1417 | break; |
|---|
| 1418 | |
|---|
| 1419 | ################################### |
|---|
| 1420 | case 'end' : |
|---|
| 1421 | $url = 'http://' . $_SERVER['HTTP_HOST'] . SYSTEM_PATH; |
|---|
| 1422 | print<<<EndHTML |
|---|
| 1423 | <h1>Thanks for using Wifidog</h1> |
|---|
| 1424 | Redirection to your new WifiDog Authentification Server in 3 seconds |
|---|
| 1425 | <meta http-equiv="REFRESH" content="3;url=$url"> |
|---|
| 1426 | <pre> |
|---|
| 1427 | |
|---|
| 1428 | |\ /| _ |
|---|
| 1429 | |A\_/A| z z |
|---|
| 1430 | ___| | ( (o) ) |
|---|
| 1431 | o 6 \ z _ z |
|---|
| 1432 | |___ \ /| |
|---|
| 1433 | | \ / | |
|---|
| 1434 | \ \_______/ | |
|---|
| 1435 | | | |
|---|
| 1436 | | WIFIDOG | |
|---|
| 1437 | | Captive Portal | |
|---|
| 1438 | | _____________ | |
|---|
| 1439 | | / \ | |
|---|
| 1440 | | | | | |
|---|
| 1441 | | | | | |
|---|
| 1442 | _/ | _/ | |
|---|
| 1443 | ?_____| ?_____| |
|---|
| 1444 | </pre> |
|---|
| 1445 | EndHTML; |
|---|
| 1446 | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
|---|
| 1447 | break; |
|---|
| 1448 | |
|---|
| 1449 | ################################### |
|---|
| 1450 | case 'toc' : |
|---|
| 1451 | print "<h1>Table of content</h1>"; |
|---|
| 1452 | $contentArray = file(__file__); # Read myself |
|---|
| 1453 | print "<UL>\n"; |
|---|
| 1454 | foreach ($contentArray as $line) { |
|---|
| 1455 | if (preg_match("/^ case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex |
|---|
| 1456 | if ($matchesArray[1] == 'toc') |
|---|
| 1457 | continue; |
|---|
| 1458 | print "<LI><A HREF=\"" . $_SERVER['SCRIPT_NAME'] . "?page=" . $matchesArray[1] . "\">" . $matchesArray[1] . "</A>\n"; # Display a Table of Content |
|---|
| 1459 | } |
|---|
| 1460 | } |
|---|
| 1461 | print "</UL>\n"; |
|---|
| 1462 | break; |
|---|
| 1463 | ################################### |
|---|
| 1464 | case 'notes' : |
|---|
| 1465 | print<<<EndHTML |
|---|
| 1466 | <!-- /* Editor highlighting trick --> |
|---|
| 1467 | <pre> |
|---|
| 1468 | <em>TODO</em> |
|---|
| 1469 | -Support des define de Google Maps dans config.php |
|---|
| 1470 | -Faire une fonction d'execution avec gestion de retour d'erreur et d'affichage de l'exection pour chaque "exec" |
|---|
| 1471 | -Ajouter une veritable validation (user/password admin provenant de la DB) |
|---|
| 1472 | Pour une meilleur securite du script d'installation. |
|---|
| 1473 | Au chargement, valider que la connection DB est fonctionnel, que la DB existe et que l'usager admin existe |
|---|
| 1474 | Si oui, on demande l'authentification |
|---|
| 1475 | Si non, on creer l'usager admin |
|---|
| 1476 | -Faire un vrai menu pour acceder directement aux pages desirees (pas une TOC poche) |
|---|
| 1477 | -Ameliorer le javascript et arreter de faire des document.myform.submit(); |
|---|
| 1478 | -Generate valid HTML code |
|---|
| 1479 | -Integrate this script with the portal skin |
|---|
| 1480 | -Tester que les donnees de AVAIL_LOCALE_ARRAY dans config.php sont valides (fonctionnelles) |
|---|
| 1481 | Regarder le code dans include/language.php |
|---|
| 1482 | -Support pour l'option CUSTOM_SIGNUP_URL |
|---|
| 1483 | -Effacer repertoires/fichiers temporaires des installations |
|---|
| 1484 | |
|---|
| 1485 | -Nice2Have : Si test d'integrite et de fonctionnement existent, les integrer pour assurer le bon fonctionnement |
|---|
| 1486 | -Nice2Have : Si donnees de tests exitent (pour les developpeurs) Permettre d'en ajouter a la DB |
|---|
| 1487 | -Nice2Have : Creer un wifidog.conf (client) selon config + questions si necessaires |
|---|
| 1488 | |
|---|
| 1489 | <em>Change Log</em> |
|---|
| 1490 | 15-08-2005 : Bugs correction + comments added |
|---|
| 1491 | 11-08-2005 : Options rewrite with foreach and dependencies |
|---|
| 1492 | 09-08-2005 : Admin user creation + network configuration |
|---|
| 1493 | 27-07-2005 : Added jpgraph install |
|---|
| 1494 | 26-07-2005 : Added minimal security password validation |
|---|
| 1495 | 14-07-2005 : saveConfig and all javascript code |
|---|
| 1496 | 09-07-2005 : Added Phlickr installation |
|---|
| 1497 | 05-07-2005 : Better PHP extention validation process |
|---|
| 1498 | 17-06-2005 : MySQL schema and data submission |
|---|
| 1499 | 17-06-2005 : Postgresql schema and data submission |
|---|
| 1500 | 24-04-2005 : CSS button |
|---|
| 1501 | |
|---|
| 1502 | </pre> |
|---|
| 1503 | <!-- Editor highlighting trick */ --> |
|---|
| 1504 | EndHTML; |
|---|
| 1505 | break; |
|---|
| 1506 | ################################### |
|---|
| 1507 | /* case 'phpinfo': // Use for debugging, to be removed |
|---|
| 1508 | print "<pre>"; |
|---|
| 1509 | print_r(get_loaded_extensions()); |
|---|
| 1510 | print "</pre><BR><BR>"; |
|---|
| 1511 | phpinfo(); |
|---|
| 1512 | break;*/ |
|---|
| 1513 | |
|---|
| 1514 | default : |
|---|
| 1515 | $WIFIDOG_VERSION = $configArray['WIFIDOG_VERSION']; |
|---|
| 1516 | # TODO : Add links to auth-server web documents |
|---|
| 1517 | print<<<EndHTML |
|---|
| 1518 | <h1>Welcome to WifiDog Auth-Server installation and configuration script.</h1> |
|---|
| 1519 | <p>This installation still needs improvement, so please any report bug to the mailing list for better support.<BR/> |
|---|
| 1520 | The current auth-server version is <em>$WIFIDOG_VERSION</em>.</p> |
|---|
| 1521 | |
|---|
| 1522 | <p><strong>Before going any further</strong> with this installation you need to have/create a valid user and database. |
|---|
| 1523 | <p>Here is a command line example for PostgreSQL (or use the way you like) :</p> |
|---|
| 1524 | |
|---|
| 1525 | <em>Create the PostgreSQL databaser user for WifiDog</em> (createuser and createdb need to be in you PATH) : |
|---|
| 1526 | <pre> <I>postgres@yourserver $></I> createuser wifidog --pwprompt |
|---|
| 1527 | Enter password for new user: |
|---|
| 1528 | Enter it again: |
|---|
| 1529 | Shall the new user be allowed to create databases? (y/n) n |
|---|
| 1530 | Shall the new user be allowed to create more new users? (y/n) n |
|---|
| 1531 | CREATE USER |
|---|
| 1532 | </pre> |
|---|
| 1533 | |
|---|
| 1534 | <em>Create the WifiDog database</em> |
|---|
| 1535 | <pre> <I>postgres@yourserver $></I> createdb wifidog --encoding=UTF-8 --owner=wifidog |
|---|
| 1536 | CREATE DATABASE |
|---|
| 1537 | </pre> |
|---|
| 1538 | |
|---|
| 1539 | <em>Security</em> : A password is needed to continue with the installation. You need to read the random password in <em>$password_file</em> file. No username needed, only the password. This password is only usefull for the installation, you will never use it in Auth-Server administration pages. |
|---|
| 1540 | </pre> |
|---|
| 1541 | |
|---|
| 1542 | <p>When you are ready click next</p> |
|---|
| 1543 | |
|---|
| 1544 | EndHTML; |
|---|
| 1545 | |
|---|
| 1546 | navigation(array ( |
|---|
| 1547 | array ( |
|---|
| 1548 | "title" => "Next", |
|---|
| 1549 | "page" => "permission" |
|---|
| 1550 | ) |
|---|
| 1551 | )); |
|---|
| 1552 | } |
|---|
| 1553 | ?> |
|---|
| 1554 | |
|---|
| 1555 | </form> |
|---|
| 1556 | </body> |
|---|
| 1557 | </html> |
|---|
| 1558 | |
|---|