| 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 | |
|---|
| 52 | empty ($_REQUEST['page']) ? $page = 'Welcome' : $page = $_REQUEST['page']; # The page to be loaded |
|---|
| 53 | empty ($_REQUEST['action']) ? $action = '' : $action = $_REQUEST['action']; # The action to be done (in page) |
|---|
| 54 | empty ($_REQUEST['debug']) ? $debug = 0 : $debug = $_REQUEST['debug']; # Use for MySQL debugging |
|---|
| 55 | empty ($_REQUEST['config']) ? $config = '' : $config = $_REQUEST['config']; # Store data to be saved in config.php |
|---|
| 56 | |
|---|
| 57 | # 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. |
|---|
| 58 | |
|---|
| 59 | # Random password generator |
|---|
| 60 | $password_file = '/tmp/dog_cookie.txt'; |
|---|
| 61 | $random_password = null; |
|---|
| 62 | if (!file_exists($password_file)) { |
|---|
| 63 | srand(date("s")); |
|---|
| 64 | $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|---|
| 65 | $password = ""; |
|---|
| 66 | while (strlen($random_password) < 8) { |
|---|
| 67 | $random_password .= substr($possible_charactors, rand() % (strlen($possible_charactors)), 1); |
|---|
| 68 | } |
|---|
| 69 | $fd = fopen($password_file, 'w'); |
|---|
| 70 | fwrite($fd, $random_password); |
|---|
| 71 | fclose($fd); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | # Read password file |
|---|
| 75 | $fd = fopen($password_file, "rb"); |
|---|
| 76 | $password = fread($fd, filesize($password_file)); |
|---|
| 77 | fclose($fd); |
|---|
| 78 | |
|---|
| 79 | $auth = false; |
|---|
| 80 | |
|---|
| 81 | if ($page != 'Welcome') { |
|---|
| 82 | if (isset ($_SERVER['PHP_AUTH_PW'])) { |
|---|
| 83 | #echo "PHP_AUTH_USER=(" . $_SERVER['PHP_AUTH_USER'] . ") PHP_AUTH_PW=(" . $_SERVER['PHP_AUTH_PW'] . ")"; # DEBUG |
|---|
| 84 | if ($password == $_SERVER['PHP_AUTH_PW']) |
|---|
| 85 | $auth = true; |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | else |
|---|
| 89 | $auth = true; |
|---|
| 90 | |
|---|
| 91 | if (!$auth) { # Ask user for the passorwd |
|---|
| 92 | header('WWW-Authenticate: Basic realm="Private"'); |
|---|
| 93 | header('HTTP/1.0 401 Unauthorized'); |
|---|
| 94 | echo "Authorization Required !"; |
|---|
| 95 | exit; |
|---|
| 96 | } |
|---|
| 97 | # End of Security validation |
|---|
| 98 | |
|---|
| 99 | print<<<EndHTML |
|---|
| 100 | <HTML> |
|---|
| 101 | <HEAD> |
|---|
| 102 | <TITLE>$page - Wifidog Auth-server configuration</TITLE> |
|---|
| 103 | |
|---|
| 104 | <SCRIPT type="text/javascript"> |
|---|
| 105 | // This function add new configuration value to the "config" hidden input |
|---|
| 106 | // On submit, config will be parsed and value saved to config.php file |
|---|
| 107 | function newConfig(dataAdd) { |
|---|
| 108 | // TODO : Validate input data |
|---|
| 109 | if (document.myform.config.value == '') { |
|---|
| 110 | document.myform.config.value = dataAdd; |
|---|
| 111 | } |
|---|
| 112 | else { |
|---|
| 113 | document.myform.config.value = document.myform.config.value + '|' + dataAdd; |
|---|
| 114 | } |
|---|
| 115 | //alert(document.myform.config.value); // DEBUG |
|---|
| 116 | } |
|---|
| 117 | </SCRIPT> |
|---|
| 118 | |
|---|
| 119 | </HEAD> |
|---|
| 120 | <BODY text="black" bgcolor="#CFCFCF"> |
|---|
| 121 | |
|---|
| 122 | <style type="text/css"> |
|---|
| 123 | <!-- |
|---|
| 124 | .button |
|---|
| 125 | { |
|---|
| 126 | font-size: 12pt; |
|---|
| 127 | font-weight: bold; |
|---|
| 128 | color: black; |
|---|
| 129 | background: #D4D0C8; |
|---|
| 130 | text-decoration: none; |
|---|
| 131 | border-top: 1px solid white; |
|---|
| 132 | border-right: 2px solid gray; |
|---|
| 133 | border-bottom: 2px solid gray; |
|---|
| 134 | border-left: 1px solid white; |
|---|
| 135 | padding: 3px 5px 3px 5px; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | td |
|---|
| 139 | { |
|---|
| 140 | padding: 1px 4px 1px 4px; |
|---|
| 141 | } |
|---|
| 142 | //--> |
|---|
| 143 | </style> |
|---|
| 144 | |
|---|
| 145 | <FORM NAME="myform" METHOD="post"> |
|---|
| 146 | <INPUT TYPE="HIDDEN" NAME="page"> |
|---|
| 147 | <INPUT TYPE="HIDDEN" NAME="action"> |
|---|
| 148 | <INPUT TYPE="HIDDEN" NAME="debug"> |
|---|
| 149 | <INPUT TYPE="HIDDEN" NAME="config"> |
|---|
| 150 | |
|---|
| 151 | EndHTML; |
|---|
| 152 | |
|---|
| 153 | #print "<PRE>"; # DEBUG |
|---|
| 154 | #print_r($_SERVER); # DEBUG |
|---|
| 155 | #print_r($_REQUEST); # DEBUG |
|---|
| 156 | #print "</PRE>"; # DEBUG |
|---|
| 157 | #exit(); |
|---|
| 158 | |
|---|
| 159 | # Minimal version needed |
|---|
| 160 | $requiredPHPVersion = '5.0.0'; |
|---|
| 161 | $requiredMySQLVersion = '0.0.0'; // Todo |
|---|
| 162 | $requiredPostgeSQLVersion = '0.0.0'; // Todo |
|---|
| 163 | |
|---|
| 164 | # Needed files/directories with write access |
|---|
| 165 | $dir_array = array ( |
|---|
| 166 | 'tmp', |
|---|
| 167 | 'tmp/magpie_cache', |
|---|
| 168 | 'lib/smarty', |
|---|
| 169 | 'tmp/smarty/templates_c', |
|---|
| 170 | 'tmp/smarty/cache', |
|---|
| 171 | 'lib/magpie', |
|---|
| 172 | 'lib/Phlickr', |
|---|
| 173 | 'config.php' |
|---|
| 174 | ); |
|---|
| 175 | |
|---|
| 176 | $smarty_full_url = 'http://smarty.php.net/do_download.php?download_file=Smarty-2.6.13.tar.gz'; |
|---|
| 177 | $magpierss_full_url = 'http://easynews.dl.sourceforge.net/sourceforge/magpierss/magpierss-0.72.tar.gz'; |
|---|
| 178 | $phlickr_full_url = 'http://easynews.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.4.tgz'; |
|---|
| 179 | |
|---|
| 180 | $neededPackages = array ( |
|---|
| 181 | 'smarty' => array ( |
|---|
| 182 | 'needed' => 1, |
|---|
| 183 | 'available' => 0, |
|---|
| 184 | 'message' => '', |
|---|
| 185 | 'file' => 'lib/smarty/Smarty.class.php' |
|---|
| 186 | ), |
|---|
| 187 | 'magpierss' => array ( |
|---|
| 188 | 'needed' => 0, |
|---|
| 189 | 'available' => 0, |
|---|
| 190 | 'message' => '', |
|---|
| 191 | 'file' => 'lib/magpie/rss_fetch.inc' |
|---|
| 192 | ), |
|---|
| 193 | 'phlickr' => array ( |
|---|
| 194 | 'needed' => 0, |
|---|
| 195 | 'available' => 0, |
|---|
| 196 | 'message' => '', |
|---|
| 197 | 'file' => 'lib/Phlickr/Photo.php' |
|---|
| 198 | ) |
|---|
| 199 | ); |
|---|
| 200 | |
|---|
| 201 | $neededExtentions = array ( |
|---|
| 202 | 'xml' => array ( |
|---|
| 203 | 'needed' => 0, |
|---|
| 204 | 'available' => 0, |
|---|
| 205 | 'message' => '<B>xml</B> extention is missing', |
|---|
| 206 | 'note' => 'Required for RSS support' |
|---|
| 207 | ), |
|---|
| 208 | 'pgsql' => array ( |
|---|
| 209 | 'needed' => 1, |
|---|
| 210 | 'available' => 0, |
|---|
| 211 | 'message' => '<B>Posgresql</B> extention is missing', |
|---|
| 212 | 'note' => 'Required to connect to Postgresql database' |
|---|
| 213 | ), |
|---|
| 214 | 'dom' => array ( |
|---|
| 215 | 'needed' => 1, |
|---|
| 216 | 'available' => 0, |
|---|
| 217 | 'message' => '<B>DOM</B> extention is missing', |
|---|
| 218 | 'note' => 'Required if you want to export the list of HotSpots as a RSS feed' |
|---|
| 219 | ), |
|---|
| 220 | 'gettext' => array ( |
|---|
| 221 | 'needed' => 0, |
|---|
| 222 | 'available' => 0, |
|---|
| 223 | 'message' => 'Gettext is unavailable, the auth-server will work, but you will loose internationalization', |
|---|
| 224 | 'note' => 'Internationalization support' |
|---|
| 225 | ), |
|---|
| 226 | 'mbstring' => array ( |
|---|
| 227 | 'needed' => 1, |
|---|
| 228 | 'available' => 0, |
|---|
| 229 | 'message' => '<B>mbstring</B> extention is missing', |
|---|
| 230 | 'note' => 'Required for core auth-server and RSS support' |
|---|
| 231 | ), |
|---|
| 232 | 'mcrypt' => array ( |
|---|
| 233 | 'needed' => 0, |
|---|
| 234 | 'available' => 0, |
|---|
| 235 | 'message' => '<B>mcrypt</B> extention is missing', |
|---|
| 236 | 'note' => 'Required for RADIUS support' |
|---|
| 237 | ), |
|---|
| 238 | 'mhash' => array ( |
|---|
| 239 | 'needed' => 0, |
|---|
| 240 | 'available' => 0, |
|---|
| 241 | 'message' => '<B>mhash</B> extention is missing', |
|---|
| 242 | 'note' => 'Required for RADIUS support' |
|---|
| 243 | ), |
|---|
| 244 | 'session' => array ( |
|---|
| 245 | 'needed' => 1, |
|---|
| 246 | 'available' => 0, |
|---|
| 247 | 'message' => '<B>session</B> extention is missing', |
|---|
| 248 | 'note' => 'Required for core auth-server' |
|---|
| 249 | ), |
|---|
| 250 | 'xmlrpc' => array ( |
|---|
| 251 | 'needed' => 0, |
|---|
| 252 | 'available' => 0, |
|---|
| 253 | 'message' => '<B>xmlrpc</B> extention is missing', |
|---|
| 254 | 'note' => 'Required for RADIUS support' |
|---|
| 255 | ) |
|---|
| 256 | ); |
|---|
| 257 | |
|---|
| 258 | $loadedExtensions = array_flip(get_loaded_extensions()); # Debug : An empty array for $loadedExtensions will show needed dependencies |
|---|
| 259 | |
|---|
| 260 | $neededPEARPackages = array ( |
|---|
| 261 | 'radius' => array ( |
|---|
| 262 | 'needed' => 0, |
|---|
| 263 | 'available' => 0, |
|---|
| 264 | 'command' => "return dl('radius.so');", |
|---|
| 265 | 'message' => 'Try in command line : pear install radius' |
|---|
| 266 | ), |
|---|
| 267 | 'Auth_RADIUS' => array ( |
|---|
| 268 | 'needed' => 0, |
|---|
| 269 | 'available' => 0, |
|---|
| 270 | 'command' => "return include_once 'Auth/RADIUS.php';", |
|---|
| 271 | 'message' => 'Try in command line : pear install Auth_RADIUS' |
|---|
| 272 | ), |
|---|
| 273 | 'Crypt_CHAP' => array ( |
|---|
| 274 | 'needed' => 0, |
|---|
| 275 | 'available' => 0, |
|---|
| 276 | 'command' => "return include_once 'Crypt/CHAP.php';", |
|---|
| 277 | 'message' => 'Try in command line : pear install Crypt_CHAP (mhash and mcrypt extensions are needed)' |
|---|
| 278 | ) |
|---|
| 279 | ); |
|---|
| 280 | |
|---|
| 281 | $optionsInfo = array ( |
|---|
| 282 | 'SSL_AVAILABLE' => array ( |
|---|
| 283 | 'title' => 'SSL Support', |
|---|
| 284 | 'depend' => 'return 1;', |
|---|
| 285 | 'message' => ' ' |
|---|
| 286 | ), |
|---|
| 287 | 'RSS_SUPPORT' => array ( |
|---|
| 288 | 'title' => 'RSS Support', |
|---|
| 289 | 'depend' => 'return ($neededExtentions[\'xml\'][\'available\'] && $neededPackages[\'magpierss\'][\'available\']);', |
|---|
| 290 | 'message' => 'Missing <B>xml</B> extentions or <B>MagpieRSS</B>' |
|---|
| 291 | ), |
|---|
| 292 | 'PHLICKR_SUPPORT' => array ( |
|---|
| 293 | 'title' => 'Flickr Photostream content support', |
|---|
| 294 | 'depend' => 'return $neededPackages[\'phlickr\'][\'available\'];', |
|---|
| 295 | 'message' => '<B>Phlickr</B> library not installed' |
|---|
| 296 | ), |
|---|
| 297 | 'CONF_USE_CRON_FOR_DB_CLEANUP' => array ( |
|---|
| 298 | 'title' => 'Use cron for DB cleanup', |
|---|
| 299 | 'depend' => 'return 1;', |
|---|
| 300 | 'message' => ' ' |
|---|
| 301 | ), |
|---|
| 302 | 'XSLT_SUPPORT' => array ( |
|---|
| 303 | 'title' => 'XSLT Support', |
|---|
| 304 | 'depend' => 'return 1;', |
|---|
| 305 | 'message' => ' ' |
|---|
| 306 | ), |
|---|
| 307 | 'GMAPS_HOTSPOTS_MAP_ENABLED' => array ( |
|---|
| 308 | 'title' => 'Google Maps Support', |
|---|
| 309 | 'depend' => 'return 1;', |
|---|
| 310 | 'message' => ' ' |
|---|
| 311 | ) |
|---|
| 312 | ); |
|---|
| 313 | |
|---|
| 314 | foreach ($neededExtentions as $key => $value) { # Detect availables extentions |
|---|
| 315 | if (array_key_exists($key, $loadedExtensions)) |
|---|
| 316 | $neededExtentions[$key]['available'] = 1; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | foreach ($neededPEARPackages as $key => $value) { # Detect availables PEAR Packages |
|---|
| 320 | if (@ eval ($neededPEARPackages[$key]['command'])) |
|---|
| 321 | $neededPEARPackages[$key]['available'] = 1; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | foreach ($neededPackages as $key => $value) { # Detect installed libraries (smarty, ...) |
|---|
| 325 | if (file_exists(WIFIDOG_ABS_FILE_PATH . $neededPackages[$key]['file'])) |
|---|
| 326 | $neededPackages[$key]['available'] = 1; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | $CONFIG_FILE = 'config.php'; |
|---|
| 330 | $LOCAL_CONFIG_FILE = 'local.config.php'; |
|---|
| 331 | |
|---|
| 332 | if (!empty ($config)) # If not empty, save javascript 'config' variable to config.php file |
|---|
| 333 | saveConfig($config); |
|---|
| 334 | |
|---|
| 335 | ### Read Configuration file. Keys and Values => define('FOO', 'BRAK'); |
|---|
| 336 | # Use config.php if local.config.php does not exist |
|---|
| 337 | //if(!file_exists(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE")) |
|---|
| 338 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
|---|
| 339 | //else |
|---|
| 340 | // $contentArray = file(WIFIDOG_ABS_FILE_PATH."$LOCAL_CONFIG_FILE"); |
|---|
| 341 | |
|---|
| 342 | $configArray = array (); |
|---|
| 343 | |
|---|
| 344 | foreach ($contentArray as $line) { |
|---|
| 345 | #print "$line<BR>"; # Debug |
|---|
| 346 | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
|---|
| 347 | list ($key, $value) = explode(',', $matchesArray[1]); |
|---|
| 348 | $pattern = array ( |
|---|
| 349 | "/^'/", |
|---|
| 350 | "/'$/" |
|---|
| 351 | ); |
|---|
| 352 | $replacement = array ( |
|---|
| 353 | '', |
|---|
| 354 | '' |
|---|
| 355 | ); |
|---|
| 356 | $key = preg_replace($pattern, $replacement, trim($key)); |
|---|
| 357 | $value = preg_replace($pattern, $replacement, trim($value)); |
|---|
| 358 | $configArray[$key] = $value; |
|---|
| 359 | } |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | # Database connections variables |
|---|
| 363 | $CONF_DBMS = $configArray['CONF_DBMS']; |
|---|
| 364 | $CONF_DATABASE_HOST = $configArray['CONF_DATABASE_HOST']; |
|---|
| 365 | $CONF_DATABASE_NAME = $configArray['CONF_DATABASE_NAME']; |
|---|
| 366 | $CONF_DATABASE_USER = $configArray['CONF_DATABASE_USER']; |
|---|
| 367 | $CONF_DATABASE_PASSWORD = $configArray['CONF_DATABASE_PASSWORD']; |
|---|
| 368 | |
|---|
| 369 | //foreach($configArray as $key => $value) { print "K=$key V=$value<BR>"; } exit(); # DEBUG |
|---|
| 370 | |
|---|
| 371 | ################################### |
|---|
| 372 | # array (array1(name1, page1), array2(name2, page2), ..., arrayN(nameN, pageN)); |
|---|
| 373 | # Todo : Supporter HTTP_REFERER (j'me comprends) |
|---|
| 374 | function navigation($dataArray) { |
|---|
| 375 | $SERVER = $_SERVER['HTTP_HOST']; |
|---|
| 376 | $SCRIPT = $_SERVER['SCRIPT_NAME']; |
|---|
| 377 | print "\n<P>"; |
|---|
| 378 | foreach ($dataArray as $num => $navArray) { |
|---|
| 379 | $title = $navArray['title']; |
|---|
| 380 | $page = $navArray['page']; |
|---|
| 381 | empty ($navArray['action']) ? $action = '' : $action = $navArray['action']; |
|---|
| 382 | print<<<EndHTML |
|---|
| 383 | <A HREF="#" ONCLICK="document.myform.page.value = '$page'; document.myform.action.value = '$action'; document.myform.submit();" CLASS="button">$title</A> |
|---|
| 384 | |
|---|
| 385 | EndHTML; |
|---|
| 386 | if (array_key_exists($num +1, $dataArray)) |
|---|
| 387 | print " - "; |
|---|
| 388 | } |
|---|
| 389 | print "</P>\n"; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | ################################### |
|---|
| 393 | # |
|---|
| 394 | function refreshButton() { |
|---|
| 395 | print<<<EndHTML |
|---|
| 396 | |
|---|
| 397 | <P><A HREF="#" ONCLICK="javascript: window.location.reload(true);" CLASS="button">Refresh</A></P> |
|---|
| 398 | EndHTML; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | /** Use PHP internal functions to download a file */ |
|---|
| 402 | function downloadFile($remoteURL, $localPath) { |
|---|
| 403 | set_time_limit(1500); // 25 minutes timeout |
|---|
| 404 | if (copy($remoteURL, $localPath)) |
|---|
| 405 | return true; |
|---|
| 406 | else |
|---|
| 407 | return false; |
|---|
| 408 | } |
|---|
| 409 | /** Use PHP internal functions to download a file */ |
|---|
| 410 | function execVerbose($command, & $output, & $return_var) { |
|---|
| 411 | print "$command"; |
|---|
| 412 | $retval = exec($command.' 2>&1', & $output, & $return_var); |
|---|
| 413 | if ($return_var != 0) { |
|---|
| 414 | print "<p style='color:red'>Error:</em> Command did not complete successfully (returned $return_var): <br/>\n"; |
|---|
| 415 | if ($output) { |
|---|
| 416 | foreach ($output as $output_line) |
|---|
| 417 | print " $output_line <br/>\n"; |
|---|
| 418 | } |
|---|
| 419 | print "</p>\n"; |
|---|
| 420 | } |
|---|
| 421 | return $retval; |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | ################################### |
|---|
| 425 | # |
|---|
| 426 | /*function debugButton() { |
|---|
| 427 | print <<<EndHTML |
|---|
| 428 | <P><INPUT TYPE="button" VALUE="Debug" ONCLICK="javascript: window.location.reload(true);"></P> |
|---|
| 429 | EndHTML; |
|---|
| 430 | } */ |
|---|
| 431 | |
|---|
| 432 | ################################### |
|---|
| 433 | # In development |
|---|
| 434 | /*function installPackage($pkg_name, $full_url, $copy) { |
|---|
| 435 | print "<H1>$pkg_name installation</H1>\n"; |
|---|
| 436 | chdir(WIFIDOG_ABS_FILE_PATH."tmp"); |
|---|
| 437 | list($url, $filename) = split ("=", $full_url); |
|---|
| 438 | |
|---|
| 439 | print "Download source code ($filename) : "; |
|---|
| 440 | if (!file_exists($filename)) |
|---|
| 441 | execVerbose("wget \"$url\"", $output, $return); |
|---|
| 442 | if (!file_exists($filename)) // wget success if file exists |
|---|
| 443 | execVerbose("wget \"$full_url\" 2>&1", $output_array, $return); |
|---|
| 444 | if (!file_exists($filename)) { |
|---|
| 445 | print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; |
|---|
| 446 | $output = implode("\n", $output_array); |
|---|
| 447 | print "<PRE><B>wget \"$full_url\"</B>\n$output</PRE>"; |
|---|
| 448 | exit(); |
|---|
| 449 | } else { |
|---|
| 450 | print "OK<BR>"; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | print "Uncompressing : "; |
|---|
| 454 | $dirname = array_shift(split(".tar.gz", $filename)); |
|---|
| 455 | |
|---|
| 456 | if (!file_exists($dirname)) |
|---|
| 457 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 458 | print "OK<BR>"; |
|---|
| 459 | print "Copying : "; |
|---|
| 460 | if (!file_exists('../../lib/smarty/Smarty.class.php')); |
|---|
| 461 | execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
|---|
| 462 | execVerbose("cp -r $dirname/libs/* ../../lib/smarty", $output, $return); |
|---|
| 463 | $copy |
|---|
| 464 | print "OK<BR>"; |
|---|
| 465 | }*/ |
|---|
| 466 | |
|---|
| 467 | ################################### |
|---|
| 468 | # |
|---|
| 469 | function saveConfig($data) { |
|---|
| 470 | print "<!-- saveConfig DATA=($data) -->\n"; # DEBUG |
|---|
| 471 | |
|---|
| 472 | global $CONFIG_FILE; |
|---|
| 473 | |
|---|
| 474 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE"); |
|---|
| 475 | $fd = fopen(WIFIDOG_ABS_FILE_PATH . "$CONFIG_FILE", 'w'); |
|---|
| 476 | |
|---|
| 477 | $defineArrayToken = array (); |
|---|
| 478 | $defineArrayToken = explode('|', $data); |
|---|
| 479 | |
|---|
| 480 | foreach ($defineArrayToken as $nameValue) { |
|---|
| 481 | list ($name, $value) = explode('=', $nameValue); |
|---|
| 482 | $defineArray[$name] = $value; # New define value ($name and value) |
|---|
| 483 | #print "K=$name V=$value<BR>"; # DEBUG |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | foreach ($contentArray as $line) { |
|---|
| 487 | #print "L=$line<BR>\n"; |
|---|
| 488 | if (preg_match("/^define\((.+)\);/", $line, $matchesArray)) { |
|---|
| 489 | list ($key, $value) = explode(',', $matchesArray[1]); |
|---|
| 490 | $pattern = array ( |
|---|
| 491 | "/^'/", |
|---|
| 492 | "/'$/" |
|---|
| 493 | ); |
|---|
| 494 | $replacement = array ( |
|---|
| 495 | '', |
|---|
| 496 | '' |
|---|
| 497 | ); |
|---|
| 498 | $key = preg_replace($pattern, $replacement, trim($key)); |
|---|
| 499 | //$value = preg_replace($pattern, $replacement, trim($value)); |
|---|
| 500 | |
|---|
| 501 | if (array_key_exists($key, $defineArray)) { // A new value is defined |
|---|
| 502 | #print "$key EXISTS<BR>"; |
|---|
| 503 | #print "define => (" . $defineArray[$key] . ")<BR>"; |
|---|
| 504 | $pattern = array ( |
|---|
| 505 | "/^\\\'/", |
|---|
| 506 | "/\\\'$/" |
|---|
| 507 | ); |
|---|
| 508 | $replacement = array ( |
|---|
| 509 | "'", |
|---|
| 510 | "'" |
|---|
| 511 | ); |
|---|
| 512 | $value = preg_replace($pattern, $replacement, trim($defineArray[$key])); |
|---|
| 513 | #print "(define('$key', $value);)<BR>"; |
|---|
| 514 | fwrite($fd, "define('$key', $value);\n"); # Write the new define($name, $value) |
|---|
| 515 | } |
|---|
| 516 | else { // The key does not exist (no new value to be saved) |
|---|
| 517 | fwrite($fd, $line); # Write the same line in config.php |
|---|
| 518 | } |
|---|
| 519 | } |
|---|
| 520 | else { |
|---|
| 521 | fwrite($fd, $line); # Write the line (not a define line). Ex: Commented text |
|---|
| 522 | } |
|---|
| 523 | } |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | ################################### |
|---|
| 527 | # MAIN |
|---|
| 528 | switch ($page) { |
|---|
| 529 | case 'version' : |
|---|
| 530 | /* TODO : Valider qu'au moins une extention de DB est existante (pgsql, mysql, etc) |
|---|
| 531 | Definir les versions minimales de Posgres et MySQL */ |
|---|
| 532 | |
|---|
| 533 | print "<H1>Version validation</H1>"; |
|---|
| 534 | print "<TABLE BORDER=\"1\">"; |
|---|
| 535 | |
|---|
| 536 | $phpVersion = phpversion(); |
|---|
| 537 | $okMsg = '<TD ALIGN="CENTER" STYLE="background:lime;">OK</TD>'; |
|---|
| 538 | $errorMsg = '<TD ALIGN="CENTER" STYLE="background:red;">ERROR</TD>'; |
|---|
| 539 | $warningMsg = '<TD ALIGN="CENTER" STYLE="background:yellow;">Warning</TD>'; |
|---|
| 540 | $error = 0; |
|---|
| 541 | |
|---|
| 542 | print "<TR><TD>PHP</TD>"; |
|---|
| 543 | if (version_compare($phpVersion, $requiredPHPVersion, ">=")) { |
|---|
| 544 | print "$okMsg<TD>$phpVersion</TD>"; // Version 5.0.0 or later |
|---|
| 545 | } |
|---|
| 546 | else { |
|---|
| 547 | print "$errorMsg<TD>Version $requiredPHPVersion needed</TD>"; // Version < 5.0.0 |
|---|
| 548 | $error = 1; |
|---|
| 549 | } |
|---|
| 550 | print "</TR></TABLE><BR>"; |
|---|
| 551 | |
|---|
| 552 | print "<TABLE BORDER=\"1\"><TR><TD><B>Extention</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD><TD><B>Message</B></TD></TR>"; |
|---|
| 553 | foreach ($neededExtentions as $key => $value) { |
|---|
| 554 | print "<TR><TD><A HREF=\"http://www.php.net/$key\">$key</A></TD>"; |
|---|
| 555 | $note = $neededExtentions[$key]['note']; |
|---|
| 556 | if ($neededExtentions[$key]['available']) { |
|---|
| 557 | print "$okMsg<TD>$note</TD><TD> </TD></TR>"; |
|---|
| 558 | } |
|---|
| 559 | else { |
|---|
| 560 | $message = $neededExtentions[$key]['message']; |
|---|
| 561 | if ($neededExtentions[$key]['needed'] == 1) { |
|---|
| 562 | print "$errorMsg<TD>$note</TD><TD>$message</TD></TR>"; |
|---|
| 563 | $error = 1; |
|---|
| 564 | } |
|---|
| 565 | else { |
|---|
| 566 | print "$warningMsg<TD>$note</TD><TD>$message</TD></TR>"; |
|---|
| 567 | } |
|---|
| 568 | } |
|---|
| 569 | } |
|---|
| 570 | print "</TABLE><BR>"; |
|---|
| 571 | |
|---|
| 572 | /************************************ |
|---|
| 573 | * PEAR Components |
|---|
| 574 | *************************************/ |
|---|
| 575 | print "<TABLE BORDER=\"1\"><TR><TD COLSPAN=\"3\"><CENTER><B>PEAR</B></CENTER></TD></TR>"; |
|---|
| 576 | print "<TR><TD><B>Component</B></TD><TD><B>Status</B></TD><TD><B>Note</B></TD></TR>"; |
|---|
| 577 | |
|---|
| 578 | foreach ($neededPEARPackages as $key => $value) { |
|---|
| 579 | $return = 0; |
|---|
| 580 | print "<TR><TD><A HREF=\"http://pear.php.net/package/$key\">$key</A></TD>"; |
|---|
| 581 | if ($neededPEARPackages[$key]['available']) { |
|---|
| 582 | print "$okMsg<TD> </TD></TR>"; |
|---|
| 583 | } |
|---|
| 584 | else { |
|---|
| 585 | $message = $neededPEARPackages[$key]['message']; |
|---|
| 586 | if ($neededPEARPackages[$key]['needed'] == 1) { |
|---|
| 587 | print "$errorMsg<TD>$message</TD></TR>"; |
|---|
| 588 | $error = 1; |
|---|
| 589 | } |
|---|
| 590 | else { |
|---|
| 591 | print "$warningMsg<TD>$message</TD></TR>"; |
|---|
| 592 | } |
|---|
| 593 | } |
|---|
| 594 | } |
|---|
| 595 | print "</TABLE><BR>"; |
|---|
| 596 | |
|---|
| 597 | /************************************ |
|---|
| 598 | * GD with PNG and JPEG support (will be needed by stats and graphics) |
|---|
| 599 | *************************************/ |
|---|
| 600 | /* $gdInfo = @gd_info(); |
|---|
| 601 | print "<TABLE BORDER=\"1\"><TR><TD><PRE>"; |
|---|
| 602 | print_r($gdInfo); |
|---|
| 603 | print "</PRE></TD></TR></TABLE>"; |
|---|
| 604 | */ |
|---|
| 605 | |
|---|
| 606 | # if (!($neededExtentions['pgsql']['available'] && $neededExtentions['mysql']['available'])) |
|---|
| 607 | # print "At least one DB extentions is nedded<BR>"; |
|---|
| 608 | |
|---|
| 609 | //TODO: PostgreSQL and MySQL version are not validated"; |
|---|
| 610 | print "We recommend you use PostgreSQL 8.0 or newer"; |
|---|
| 611 | |
|---|
| 612 | refreshButton(); |
|---|
| 613 | if ($error != 1) { |
|---|
| 614 | navigation(array ( |
|---|
| 615 | array ( |
|---|
| 616 | "title" => "Next", |
|---|
| 617 | "page" => "permission" |
|---|
| 618 | ) |
|---|
| 619 | )); |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | break; |
|---|
| 623 | ################################### |
|---|
| 624 | case 'permission' : |
|---|
| 625 | print "<H1>Permissions</H1>"; |
|---|
| 626 | |
|---|
| 627 | $process_info_user_id = posix_getpwuid(posix_getuid()); |
|---|
| 628 | $process_info_group_id = posix_getgrgid(posix_getegid()); |
|---|
| 629 | $process_username = $process_info_user_id['name']; |
|---|
| 630 | $process_group = $process_info_group_id['name']; |
|---|
| 631 | $cmd_mkdir = ''; |
|---|
| 632 | $cmd_chown = ''; |
|---|
| 633 | $error = 0; |
|---|
| 634 | |
|---|
| 635 | print "<P><B>Installation directory</B>: " . WIFIDOG_ABS_FILE_PATH . "</P>"; |
|---|
| 636 | print "<P><B>HTTP daemon UNIX username/group</B>: $process_username/$process_group</P>"; |
|---|
| 637 | # print "<P><B>HTTPD group</B>: $process_group<BR</P>"; |
|---|
| 638 | print "<P><TABLE BORDER=\"1\"><TR><TD><B>Directory</B></TD></TD><TD><B>Owner</B></TD><TD><B>Writable</B></TD></TR>\n"; |
|---|
| 639 | |
|---|
| 640 | foreach ($dir_array as $dir) { |
|---|
| 641 | print "<TR><TD>$dir</TD>"; |
|---|
| 642 | if (!file_exists(WIFIDOG_ABS_FILE_PATH . "$dir")) { |
|---|
| 643 | print "<TD COLSPAN=\"2\" STYLE=\"text-align:center;\">Missing</TD></TR>\n"; |
|---|
| 644 | $cmd_mkdir .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 645 | $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 646 | $error = 1; |
|---|
| 647 | continue; |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | $dir_info = posix_getpwuid(fileowner(WIFIDOG_ABS_FILE_PATH . "$dir")); |
|---|
| 651 | $dir_owner_username = $dir_info['name']; |
|---|
| 652 | print "<TD>$dir_owner_username</TD>"; |
|---|
| 653 | |
|---|
| 654 | if (is_writable(WIFIDOG_ABS_FILE_PATH . "$dir")) { |
|---|
| 655 | print "<TD>YES</TD>"; |
|---|
| 656 | } |
|---|
| 657 | else { |
|---|
| 658 | print "<TD>NO</TD>"; |
|---|
| 659 | $cmd_chown .= WIFIDOG_ABS_FILE_PATH . "$dir "; |
|---|
| 660 | $error = 1; |
|---|
| 661 | } |
|---|
| 662 | print "</TR>\n"; |
|---|
| 663 | } |
|---|
| 664 | print "</TABLE>\n"; |
|---|
| 665 | |
|---|
| 666 | if ($error != 1) { |
|---|
| 667 | print "<P><B>Note:</B> Please validate that 'Installation directory' value is the right one. If this value is wrong, the PATH de automatic detection will not work as expected"; |
|---|
| 668 | navigation(array ( |
|---|
| 669 | array ( |
|---|
| 670 | "title" => "Back", |
|---|
| 671 | "page" => "version" |
|---|
| 672 | ), |
|---|
| 673 | array ( |
|---|
| 674 | "title" => "Next", |
|---|
| 675 | "page" => "smarty" |
|---|
| 676 | ) |
|---|
| 677 | )); |
|---|
| 678 | } |
|---|
| 679 | else { |
|---|
| 680 | refreshButton(); |
|---|
| 681 | print "<P>You need to allow UNIX user <B>$process_username</B> to write to these directories (mkdir, chown or chmod)</P>"; |
|---|
| 682 | if (!empty ($cmd_mkdir)) |
|---|
| 683 | print "<P><B>For instance</B> : mkdir $cmd_mkdir"; |
|---|
| 684 | if (!empty ($cmd_chown)) |
|---|
| 685 | print "<P><B>For instance</B> :<br/>chgrp -R $process_group $cmd_chown;<br/>chmod g+wx $cmd_chown;"; |
|---|
| 686 | print "<P>After permissions modification done, hit the REFRESH button to see the NEXT button and continue with the installation"; |
|---|
| 687 | } |
|---|
| 688 | break; |
|---|
| 689 | ################################### |
|---|
| 690 | case 'smarty' : // Download, uncompress and install Smarty |
|---|
| 691 | print<<< EndHTML |
|---|
| 692 | <H1>Smarty template engine installation</H1> |
|---|
| 693 | <P><A HREF="http://smarty.php.net/">Smarty</A> is Template Engine. WifiDog requires you install it before you continue.</P> |
|---|
| 694 | EndHTML; |
|---|
| 695 | if ($neededPackages['smarty']['available']) { |
|---|
| 696 | print "Already installed !<br/>"; |
|---|
| 697 | } |
|---|
| 698 | else { |
|---|
| 699 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 700 | list ($url, $filename) = split("=", $smarty_full_url); |
|---|
| 701 | |
|---|
| 702 | print "Download source code ($filename) : "; |
|---|
| 703 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) |
|---|
| 704 | //execVerbose("wget \"$smarty_full_url\" 2>&1", $output, $return); |
|---|
| 705 | downloadFile($smarty_full_url, WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 706 | |
|---|
| 707 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) { |
|---|
| 708 | print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; |
|---|
| 709 | $output = implode("\n", $output); |
|---|
| 710 | print "<PRE><B>wget \"$smarty_full_url\"</B>\n$output</PRE>"; |
|---|
| 711 | exit (); |
|---|
| 712 | } |
|---|
| 713 | else { |
|---|
| 714 | print "OK<BR>"; |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | print "Uncompressing : "; |
|---|
| 718 | $dir_array = split(".tar.gz", WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 719 | $dirname = array_shift($dir_array); |
|---|
| 720 | |
|---|
| 721 | if (!file_exists($dirname)) |
|---|
| 722 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 723 | print "OK<BR>"; |
|---|
| 724 | print "Copying : "; |
|---|
| 725 | if (!file_exists(WIFIDOG_ABS_FILE_PATH . "lib/smarty")); |
|---|
| 726 | execVerbose("cp -r $dirname/libs/* " . WIFIDOG_ABS_FILE_PATH . "/lib/smarty", $output, $return); # TODO : Utiliser SMARTY_REL_PATH |
|---|
| 727 | print "OK<BR>"; |
|---|
| 728 | |
|---|
| 729 | refreshButton(); |
|---|
| 730 | } |
|---|
| 731 | navigation(array ( |
|---|
| 732 | array ( |
|---|
| 733 | "title" => "Back", |
|---|
| 734 | "page" => "permission" |
|---|
| 735 | ), |
|---|
| 736 | array ( |
|---|
| 737 | "title" => "Next", |
|---|
| 738 | "page" => "magpierss" |
|---|
| 739 | ) |
|---|
| 740 | )); |
|---|
| 741 | break; |
|---|
| 742 | ################################### |
|---|
| 743 | case 'magpierss' : // Download, uncompress and install MagpieRSS |
|---|
| 744 | print "<H1>MagpieRSS installation</H1>\n"; |
|---|
| 745 | |
|---|
| 746 | if ($neededPackages['magpierss']['available']) { |
|---|
| 747 | print "Already installed !<BR>"; |
|---|
| 748 | navigation(array ( |
|---|
| 749 | array ( |
|---|
| 750 | "title" => "Back", |
|---|
| 751 | "page" => "smarty" |
|---|
| 752 | ), |
|---|
| 753 | array ( |
|---|
| 754 | "title" => "Next", |
|---|
| 755 | "page" => "phlickr" |
|---|
| 756 | ) |
|---|
| 757 | )); |
|---|
| 758 | } |
|---|
| 759 | elseif ($action == 'install') { |
|---|
| 760 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 761 | $filename_array = preg_split("/\//", $magpierss_full_url); |
|---|
| 762 | $filename = array_pop($filename_array); |
|---|
| 763 | |
|---|
| 764 | print "Download source code ($filename) : "; |
|---|
| 765 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) |
|---|
| 766 | //execVerbose("wget \"$magpierss_full_url\" 2>&1", $output, $return); |
|---|
| 767 | downloadFile($magpierss_full_url, WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 768 | |
|---|
| 769 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) { |
|---|
| 770 | print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; |
|---|
| 771 | $output = implode("\n", $output); |
|---|
| 772 | print "<PRE><B>wget \"$magpierss_full_url\"</B>\n$output</PRE>"; |
|---|
| 773 | exit (); |
|---|
| 774 | } |
|---|
| 775 | else { |
|---|
| 776 | print "OK<BR>"; |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | print "Uncompressing : "; |
|---|
| 780 | $dir_array = split(".tar.gz", WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 781 | $dirname = array_shift($dir_array); |
|---|
| 782 | if (!file_exists($dirname)) |
|---|
| 783 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 784 | print "OK<BR>"; |
|---|
| 785 | |
|---|
| 786 | print "Copying : "; |
|---|
| 787 | execVerbose("cp -r $dirname/* ".WIFIDOG_ABS_FILE_PATH."lib/magpie", $output, $return); # TODO : Utiliser MAGPIE_REL_PATH |
|---|
| 788 | print "OK<BR>"; |
|---|
| 789 | |
|---|
| 790 | refreshButton(); |
|---|
| 791 | navigation(array ( |
|---|
| 792 | array ( |
|---|
| 793 | "title" => "Back", |
|---|
| 794 | "page" => "smarty" |
|---|
| 795 | ), |
|---|
| 796 | array ( |
|---|
| 797 | "title" => "Next", |
|---|
| 798 | "page" => "phlickr" |
|---|
| 799 | ) |
|---|
| 800 | )); |
|---|
| 801 | } |
|---|
| 802 | else { |
|---|
| 803 | print<<< EndHTML |
|---|
| 804 | <P><A HREF="http://magpierss.sourceforge.net/">MagpieRSS</A> provides an XML-based (expat) RSS parser in PHP. MagpieRSS is needed by Wifidog for RSS feeds. It's is recommended to install MagpieRSS, if you don't, RSS feeds options will be disabled. |
|---|
| 805 | |
|---|
| 806 | <P>Do you want to install MagpieRSS ? |
|---|
| 807 | EndHTML; |
|---|
| 808 | navigation(array ( |
|---|
| 809 | array ( |
|---|
| 810 | "title" => "Back", |
|---|
| 811 | "page" => "smarty" |
|---|
| 812 | ), |
|---|
| 813 | array ( |
|---|
| 814 | "title" => "Install", |
|---|
| 815 | "page" => "magpierss", |
|---|
| 816 | "action" => "install" |
|---|
| 817 | ), |
|---|
| 818 | array ( |
|---|
| 819 | "title" => "Next", |
|---|
| 820 | "page" => "phlickr" |
|---|
| 821 | ) |
|---|
| 822 | )); |
|---|
| 823 | } |
|---|
| 824 | break; |
|---|
| 825 | ################################### |
|---|
| 826 | case 'phlickr' : // Download, uncompress and install phlickr library |
|---|
| 827 | print "<H1>Phlickr installation</H1>\n"; |
|---|
| 828 | |
|---|
| 829 | if ($neededPackages['phlickr']['available']) { |
|---|
| 830 | print "Already installed !<BR>"; |
|---|
| 831 | navigation(array ( |
|---|
| 832 | array ( |
|---|
| 833 | "title" => "Back", |
|---|
| 834 | "page" => "magpierss" |
|---|
| 835 | ), |
|---|
| 836 | array ( |
|---|
| 837 | "title" => "Next", |
|---|
| 838 | "page" => "database" |
|---|
| 839 | ) |
|---|
| 840 | )); |
|---|
| 841 | } |
|---|
| 842 | elseif ($action == 'install') { |
|---|
| 843 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 844 | $filename_array = preg_split("/\//", $phlickr_full_url); |
|---|
| 845 | $filename = array_pop($filename_array); |
|---|
| 846 | |
|---|
| 847 | print "Download source code ($filename) : "; |
|---|
| 848 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) |
|---|
| 849 | //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); |
|---|
| 850 | downloadFile($phlickr_full_url, WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 851 | |
|---|
| 852 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."tmp/" . $filename)) { # Error occured, print output of wget |
|---|
| 853 | print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp/smarty</B>"; |
|---|
| 854 | $output = implode("\n", $output); |
|---|
| 855 | print "<PRE><B>wget \"$phlickr_full_url\"</B>\n$output</PRE>"; |
|---|
| 856 | exit (); |
|---|
| 857 | } |
|---|
| 858 | else { |
|---|
| 859 | print "OK<BR>"; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | print "Uncompressing : "; |
|---|
| 863 | $dirname_array = split(".tgz", WIFIDOG_ABS_FILE_PATH."tmp/" . $filename); |
|---|
| 864 | $dirname = array_shift($dirname_array); |
|---|
| 865 | if (!file_exists($dirname)) |
|---|
| 866 | execVerbose("tar -xzf $dirname.tgz", $output, $return); |
|---|
| 867 | print "OK<BR>"; |
|---|
| 868 | |
|---|
| 869 | print "Copying : "; |
|---|
| 870 | if (!file_exists(WIFIDOG_ABS_FILE_PATH.'/Phlickr/Photo.php')) |
|---|
| 871 | execVerbose("cp -r $dirname/* ".WIFIDOG_ABS_FILE_PATH."lib/Phlickr", $output, $return); # TODO : Utiliser PHLICKR_REL_PATH |
|---|
| 872 | print "OK<BR>"; |
|---|
| 873 | |
|---|
| 874 | refreshButton(); |
|---|
| 875 | // Skipping jpgraph install |
|---|
| 876 | navigation(array ( |
|---|
| 877 | array ( |
|---|
| 878 | "title" => "Back", |
|---|
| 879 | "page" => "magpierss" |
|---|
| 880 | ), |
|---|
| 881 | array ( |
|---|
| 882 | "title" => "Next", |
|---|
| 883 | "page" => "database" |
|---|
| 884 | ) |
|---|
| 885 | )); |
|---|
| 886 | } |
|---|
| 887 | else { |
|---|
| 888 | print<<< EndHTML |
|---|
| 889 | <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.. |
|---|
| 890 | |
|---|
| 891 | <P>Do you want to install Phlickr ? |
|---|
| 892 | EndHTML; |
|---|
| 893 | navigation(array ( |
|---|
| 894 | array ( |
|---|
| 895 | "title" => "Back", |
|---|
| 896 | "page" => "magpierss" |
|---|
| 897 | ), |
|---|
| 898 | array ( |
|---|
| 899 | "title" => "Install", |
|---|
| 900 | "page" => "phlickr", |
|---|
| 901 | "action" => "install" |
|---|
| 902 | ), |
|---|
| 903 | array ( |
|---|
| 904 | "title" => "Next", |
|---|
| 905 | "page" => "database" |
|---|
| 906 | ) |
|---|
| 907 | )); |
|---|
| 908 | } |
|---|
| 909 | break; |
|---|
| 910 | ################################### |
|---|
| 911 | case 'jpgraph' : // Download, uncompress and install JpGraph library |
|---|
| 912 | print "<H1>JpGraph installation</H1>\n"; |
|---|
| 913 | |
|---|
| 914 | if ($neededPackages['jpgraph']['available']) { |
|---|
| 915 | print "Already installed !<BR>"; |
|---|
| 916 | navigation(array ( |
|---|
| 917 | array ( |
|---|
| 918 | "title" => "Back", |
|---|
| 919 | "page" => "phlickr" |
|---|
| 920 | ), |
|---|
| 921 | array ( |
|---|
| 922 | "title" => "Next", |
|---|
| 923 | "page" => "database" |
|---|
| 924 | ) |
|---|
| 925 | )); |
|---|
| 926 | } |
|---|
| 927 | elseif ($action == 'install') { |
|---|
| 928 | chdir(WIFIDOG_ABS_FILE_PATH . "tmp"); |
|---|
| 929 | $filename = array_pop(preg_split("/\//", $jpgraph_full_url)); |
|---|
| 930 | |
|---|
| 931 | print "Download source code ($filename) : "; |
|---|
| 932 | if (!file_exists($filename)) |
|---|
| 933 | execVerbose("wget \"$jpgraph_full_url\" 2>&1", $output, $return); |
|---|
| 934 | if (!file_exists($filename)) { # Error occured, print output of wget |
|---|
| 935 | print "<B STYLE=\"color:red\">Error</B><P>Current working directory : <B>$basepath/tmp</B>"; |
|---|
| 936 | $output = implode("\n", $output); |
|---|
| 937 | print "<PRE><B>wget \"$jpgraph_full_url\"</B>\n$output</PRE>"; |
|---|
| 938 | exit (); |
|---|
| 939 | } |
|---|
| 940 | else { |
|---|
| 941 | print "OK<BR>"; |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | print "Uncompressing : "; |
|---|
| 945 | $dirname = array_shift(split(".tar.gz", $filename)); |
|---|
| 946 | if (!file_exists($dirname)) |
|---|
| 947 | execVerbose("tar -xzf $dirname.tar.gz", $output, $return); |
|---|
| 948 | print "OK<BR>"; |
|---|
| 949 | |
|---|
| 950 | print "Copying : "; |
|---|
| 951 | if (!file_exists(WIFIDOG_ABS_FILE_PATH."lib/jpgraph/jpgraph.php")) |
|---|
| 952 | execVerbose("cp $dirname/src/* ".WIFIDOG_ABS_FILE_PATH."lib/jpgraph", $output, $return); # TODO : Utiliser JPGRAPH_REL_PATH |
|---|
| 953 | |
|---|
| 954 | print "OK<BR>"; |
|---|
| 955 | |
|---|
| 956 | refreshButton(); |
|---|
| 957 | navigation(array ( |
|---|
| 958 | array ( |
|---|
| 959 | "title" => "Back", |
|---|
| 960 | "page" => "phlickr" |
|---|
| 961 | ), |
|---|
| 962 | array ( |
|---|
| 963 | "title" => "Next", |
|---|
| 964 | "page" => "database" |
|---|
| 965 | ) |
|---|
| 966 | )); |
|---|
| 967 | } |
|---|
| 968 | else { |
|---|
| 969 | print<<< EndHTML |
|---|
| 970 | <P><A HREF="http://www.aditus.nu/jpgraph/">JpGraph</A> is a Object-Oriented Graph creating library for PHP. |
|---|
| 971 | 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. |
|---|
| 972 | |
|---|
| 973 | <P>Do you want to install JpGraph ? |
|---|
| 974 | EndHTML; |
|---|
| 975 | navigation(array ( |
|---|
| 976 | array ( |
|---|
| 977 | "title" => "Back", |
|---|
| 978 | "page" => "phlickr" |
|---|
| 979 | ), |
|---|
| 980 | array ( |
|---|
| 981 | "title" => "Install", |
|---|
| 982 | "page" => "jpgraph", |
|---|
| 983 | "action" => "install" |
|---|
| 984 | ), |
|---|
| 985 | array ( |
|---|
| 986 | "title" => "Next", |
|---|
| 987 | "page" => "database" |
|---|
| 988 | ) |
|---|
| 989 | )); |
|---|
| 990 | } |
|---|
| 991 | break; |
|---|
| 992 | ################################### |
|---|
| 993 | case 'database' : |
|---|
| 994 | ### TODO : Valider en javascript que les champs soumit ne sont pas vide |
|---|
| 995 | # Pouvoir choisir le port de la DB ??? |
|---|
| 996 | print<<< EndHTML |
|---|
| 997 | <H1>Database access configuration</H1> |
|---|
| 998 | <BR> |
|---|
| 999 | <TABLE border="1"> |
|---|
| 1000 | <TR><TD>DB</TD><TD><SELECT name="CONF_DBMS"> |
|---|
| 1001 | |
|---|
| 1002 | EndHTML; |
|---|
| 1003 | |
|---|
| 1004 | foreach ($configArray as $key => $value) { # In config.php, find all DBMS_* define |
|---|
| 1005 | if (preg_match("/^(DBMS_)(.*)/", $key, $matchesArray)) { |
|---|
| 1006 | $dbname_lower = strtolower($matchesArray[2]); |
|---|
| 1007 | if ($dbname_lower == 'postgres') # config.php use postgres and PHP use pgsql |
|---|
| 1008 | $dbname_lower = 'pgsql'; |
|---|
| 1009 | if ($neededExtentions[$dbname_lower]['available'] == 0) # Validate dependencie |
|---|
| 1010 | continue; |
|---|
| 1011 | if ($CONF_DBMS == $key) |
|---|
| 1012 | print " <OPTION value=\"$key\" SELECTED>" . $matchesArray[2] . "</OPTION>\n"; |
|---|
| 1013 | else |
|---|
| 1014 | print " <OPTION value=\"$key\">" . $matchesArray[2] . "</OPTION>\n"; |
|---|
| 1015 | } |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | print<<< EndHTML |
|---|
| 1019 | </TD></TR> |
|---|
| 1020 | <TR><TD>Host</TD><TD><INPUT type="text" name="CONF_DATABASE_HOST" value="$CONF_DATABASE_HOST"></TD></TR> |
|---|
| 1021 | <TR><TD>DB Name</TD><TD><INPUT type="text" name="CONF_DATABASE_NAME" value="$CONF_DATABASE_NAME"></TD></TR> |
|---|
| 1022 | <TR><TD>Username</TD><TD><INPUT type="text" name="CONF_DATABASE_USER" value="$CONF_DATABASE_USER"></TD></TR> |
|---|
| 1023 | <TR><TD>Password</TD><TD><INPUT type="text" name="CONF_DATABASE_PASSWORD" value="$CONF_DATABASE_PASSWORD"></TD></TR> |
|---|
| 1024 | </TABLE> |
|---|
| 1025 | |
|---|
| 1026 | <P>By clicking Next, your configuration will be automaticaly saved |
|---|
| 1027 | |
|---|
| 1028 | <script type="text/javascript"> |
|---|
| 1029 | function submitDatabaseValue() { |
|---|
| 1030 | newConfig("CONF_DBMS=" + document.myform.CONF_DBMS.value); |
|---|
| 1031 | newConfig("CONF_DATABASE_HOST='" + document.myform.CONF_DATABASE_HOST.value + "'"); |
|---|
| 1032 | newConfig("CONF_DATABASE_NAME='" + document.myform.CONF_DATABASE_NAME.value + "'"); |
|---|
| 1033 | newConfig("CONF_DATABASE_USER='" + document.myform.CONF_DATABASE_USER.value + "'"); |
|---|
| 1034 | newConfig("CONF_DATABASE_PASSWORD='" + document.myform.CONF_DATABASE_PASSWORD.value + "'"); |
|---|
| 1035 | } |
|---|
| 1036 | </script> |
|---|
| 1037 | |
|---|
| 1038 | EndHTML; |
|---|
| 1039 | |
|---|
| 1040 | navigation(array ( |
|---|
| 1041 | array ( |
|---|
| 1042 | "title" => "Back", |
|---|
| 1043 | "page" => "magpierss" |
|---|
| 1044 | ) |
|---|
| 1045 | )); #, array("title" => "Next", "page" => "testdatabase"))); |
|---|
| 1046 | print<<< EndHTML |
|---|
| 1047 | <P><A HREF="#" ONCLICK="javascript: document.myform.page.value='testdatabase'; submitDatabaseValue(); document.myform.submit();" CLASS="button">Next</A></P> |
|---|
| 1048 | |
|---|
| 1049 | EndHTML; |
|---|
| 1050 | |
|---|
| 1051 | break; |
|---|
| 1052 | ################################### |
|---|
| 1053 | case 'testdatabase' : |
|---|
| 1054 | print "<H1>Database connection</H1>"; |
|---|
| 1055 | /* TODO : Tester la version minimale requise de Postgresql */ |
|---|
| 1056 | |
|---|
| 1057 | switch ($CONF_DBMS) { |
|---|
| 1058 | case 'DBMS_POSTGRES' : |
|---|
| 1059 | print "<UL><LI>Postgresql database connection : "; |
|---|
| 1060 | |
|---|
| 1061 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 1062 | $ptr_connexion = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
|---|
| 1063 | |
|---|
| 1064 | #if ($ptr_connexion == TRUE) { |
|---|
| 1065 | print "Success<BR>"; |
|---|
| 1066 | #} |
|---|
| 1067 | # } else { |
|---|
| 1068 | # 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"; |
|---|
| 1069 | # navigation(array(array("title" => "Back", "page" => "database"))); |
|---|
| 1070 | # } |
|---|
| 1071 | |
|---|
| 1072 | $postgresql_info = pg_version(); |
|---|
| 1073 | # $postgresql_info['server']; |
|---|
| 1074 | # if ($postgresql_info['server'] > $requiredPostgeSQLVersion) { Todo : Do something } |
|---|
| 1075 | |
|---|
| 1076 | print "</UL>"; |
|---|
| 1077 | refreshButton(); |
|---|
| 1078 | navigation(array ( |
|---|
| 1079 | array ( |
|---|
| 1080 | "title" => "Back", |
|---|
| 1081 | "page" => "database" |
|---|
| 1082 | ), |
|---|
| 1083 | array ( |
|---|
| 1084 | "title" => "Next", |
|---|
| 1085 | "page" => "dbinit" |
|---|
| 1086 | ) |
|---|
| 1087 | )); |
|---|
| 1088 | break; |
|---|
| 1089 | ################################### |
|---|
| 1090 | case 'DBMS_MYSQL' : |
|---|
| 1091 | $ptr_connexion = @ mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); |
|---|
| 1092 | print "<UL>\n"; |
|---|
| 1093 | |
|---|
| 1094 | if ($ptr_connexion == TRUE) { |
|---|
| 1095 | print "<LI>MySQL database connection : Success"; |
|---|
| 1096 | |
|---|
| 1097 | $mysql_server_version = mysql_get_server_info(); |
|---|
| 1098 | print ("<LI>MySQL server version: $mysql_server_version"); |
|---|
| 1099 | |
|---|
| 1100 | #if ($mysql_server_version > $requiredMySQLVersion) { Todo : Do something } |
|---|
| 1101 | |
|---|
| 1102 | #printf("<LI>MySQL host info: %s\n", mysql_get_host_info()); |
|---|
| 1103 | |
|---|
| 1104 | print "<LI>Select DB $CONF_DATABASE_NAME : "; |
|---|
| 1105 | $select_db = mysql_select_db($CONF_DATABASE_NAME); |
|---|
| 1106 | |
|---|
| 1107 | if ($select_db == TRUE) { |
|---|
| 1108 | print "Success</UL>"; |
|---|
| 1109 | navigation(array ( |
|---|
| 1110 | array ( |
|---|
| 1111 | "title" => "Back", |
|---|
| 1112 | "page" => "database" |
|---|
| 1113 | ), |
|---|
| 1114 | array ( |
|---|
| 1115 | "title" => "Next", |
|---|
| 1116 | "page" => "dbinit" |
|---|
| 1117 | ) |
|---|
| 1118 | )); |
|---|
| 1119 | } |
|---|
| 1120 | else { |
|---|
| 1121 | print "</UL>ERROR (Unable to select the database)<BR>"; |
|---|
| 1122 | refreshButton(); |
|---|
| 1123 | navigation(array ( |
|---|
| 1124 | array ( |
|---|
| 1125 | "title" => "Back", |
|---|
| 1126 | "page" => "database" |
|---|
| 1127 | ) |
|---|
| 1128 | )); |
|---|
| 1129 | } |
|---|
| 1130 | } |
|---|
| 1131 | else { |
|---|
| 1132 | print "Unable to connect to database on <B>$CONF_DATABASE_HOST</B><BR>The database must be online to continue.<P>Please go back and retry with correct values"; |
|---|
| 1133 | refreshButton(); |
|---|
| 1134 | navigation(array ( |
|---|
| 1135 | array ( |
|---|
| 1136 | "title" => "Back", |
|---|
| 1137 | "page" => "database" |
|---|
| 1138 | ) |
|---|
| 1139 | )); |
|---|
| 1140 | } |
|---|
| 1141 | break; |
|---|
| 1142 | default : |
|---|
| 1143 | print<<<EndHTML |
|---|
| 1144 | The CONF_DBMS value <B>$CONF_DBMS</B> is not currently suported by this install script. |
|---|
| 1145 | EndHTML; |
|---|
| 1146 | navigation(array ( |
|---|
| 1147 | array ( |
|---|
| 1148 | "title" => "Back", |
|---|
| 1149 | "page" => "database" |
|---|
| 1150 | ) |
|---|
| 1151 | )); |
|---|
| 1152 | } |
|---|
| 1153 | break; |
|---|
| 1154 | ################################### |
|---|
| 1155 | case 'dbinit' : |
|---|
| 1156 | print "<H1>Database initialisation</H1>"; |
|---|
| 1157 | |
|---|
| 1158 | # SQL are executed with PHP, some lignes need to be commented |
|---|
| 1159 | $file_db_version = 'UNKNOW'; |
|---|
| 1160 | $patterns[0] = '/CREATE DATABASE wifidog/'; |
|---|
| 1161 | $patterns[1] = '/\\\connect/'; |
|---|
| 1162 | $patterns[2] = '/COMMENT/'; |
|---|
| 1163 | $patterns[3] = '/SET default_tablespace/'; |
|---|
| 1164 | $patterns[4] = '/SET default_with_oids/'; |
|---|
| 1165 | $replacements[0] = '-- '; |
|---|
| 1166 | $replacements[1] = '-- '; |
|---|
| 1167 | $replacements[2] = '-- '; |
|---|
| 1168 | $replacements[3] = '-- '; |
|---|
| 1169 | $replacements[4] = '-- '; |
|---|
| 1170 | |
|---|
| 1171 | $content_schema_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-schema.sql") or die("<B>Error</B>: Can not open $basepath/../sql/wifidog-postgres-schema.sql"); # Read SQL schema file |
|---|
| 1172 | $content_schema = implode("", $content_schema_array); |
|---|
| 1173 | $content_data_array = file(WIFIDOG_ABS_FILE_PATH . "../sql/wifidog-postgres-initial-data.sql"); # Read SQL initial data file |
|---|
| 1174 | $content_data = implode("", $content_data_array); |
|---|
| 1175 | |
|---|
| 1176 | $db_schema_version = ''; # Schema version query from database |
|---|
| 1177 | $file_schema_version = ''; # Schema version from define(REQUIRED_SCHEMA_VERSION) in schema_validate.php |
|---|
| 1178 | |
|---|
| 1179 | switch ($CONF_DBMS) { |
|---|
| 1180 | case 'DBMS_POSTGRES' : |
|---|
| 1181 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 1182 | $connection = pg_connect($conn_string) or die(); # or die("Couldn't Connect ==".pg_last_error()."==<BR>"); |
|---|
| 1183 | |
|---|
| 1184 | if (preg_match("/\('schema_version', '(\d+)'\);/", $content_data, $matchesArray)) # Get schema_version from initial data file |
|---|
| 1185 | $file_db_version = $matchesArray[1]; |
|---|
| 1186 | |
|---|
| 1187 | $contentArray = file(WIFIDOG_ABS_FILE_PATH . "include/schema_validate.php"); |
|---|
| 1188 | foreach ($contentArray as $line) { |
|---|
| 1189 | #print "$line<BR>"; # Debug |
|---|
| 1190 | if (preg_match("/^define\('REQUIRED_SCHEMA_VERSION', (\d+)\);/", $line, $matchesArray)) { |
|---|
| 1191 | #print "REQUIRED_SCHEMA_VERSION = " . $matchesArray[1] . "<BR>"; |
|---|
| 1192 | $file_schema_version = $matchesArray[1]; |
|---|
| 1193 | } |
|---|
| 1194 | } |
|---|
| 1195 | |
|---|
| 1196 | # Get current database schema version (if defined) |
|---|
| 1197 | $sql = "SELECT * FROM schema_info WHERE tag='schema_version'"; |
|---|
| 1198 | if ($result = @ pg_query($connection, $sql)) { # The @ remove warning display |
|---|
| 1199 | $result_array = pg_fetch_all($result); |
|---|
| 1200 | $db_shema_version = $result_array[0]['value']; |
|---|
| 1201 | |
|---|
| 1202 | print "<P>On <B>$CONF_DATABASE_HOST</B>, Database <B>$CONF_DATABASE_NAME</B> exists and is "; |
|---|
| 1203 | if ($db_shema_version == $file_schema_version) { |
|---|
| 1204 | print "up to date (shema version <B>$db_shema_version</B>)."; |
|---|
| 1205 | navigation(array ( |
|---|
| 1206 | array ( |
|---|
| 1207 | "title" => "Back", |
|---|
| 1208 | "page" => "database" |
|---|
| 1209 | ), |
|---|
| 1210 | array ( |
|---|
| 1211 | "title" => "Next", |
|---|
| 1212 | "page" => "options" |
|---|
| 1213 | ) |
|---|
| 1214 | )); |
|---|
| 1215 | } |
|---|
| 1216 | elseif ($db_shema_version < $file_schema_version) { |
|---|
| 1217 | print "at schema version <B>$db_shema_version</B>. The required schema version is <B>$file_schema_version</B><P>Please upgrade the database"; |
|---|
| 1218 | navigation(array ( |
|---|
| 1219 | array ( |
|---|
| 1220 | "title" => "Back", |
|---|
| 1221 | "page" => "database" |
|---|
| 1222 | ), |
|---|
| 1223 | array ( |
|---|
| 1224 | "title" => "Upgrade", |
|---|
| 1225 | "page" => "schema_validate" |
|---|
| 1226 | ), |
|---|
| 1227 | array ( |
|---|
| 1228 | "title" => "Next", |
|---|
| 1229 | "page" => "options" |
|---|
| 1230 | ) |
|---|
| 1231 | )); |
|---|
| 1232 | } |
|---|
| 1233 | else { |
|---|
| 1234 | print "Error : Unexpected result"; |
|---|
| 1235 | } |
|---|
| 1236 | exit (); |
|---|
| 1237 | } |
|---|
| 1238 | |
|---|
| 1239 | print "<UL><LI>Creating wifidog database schema : "; |
|---|
| 1240 | $content_schema = preg_replace($patterns, $replacements, $content_schema); # Comment bad SQL lines |
|---|
| 1241 | |
|---|
| 1242 | $result = pg_query($connection, $content_schema) or die("<B>" . pg_last_error() . "</B> <=<BR>"); |
|---|
| 1243 | print "OK"; |
|---|
| 1244 | |
|---|
| 1245 | print "<LI>Creating wifidog database initial data : "; |
|---|
| 1246 | $content_data = preg_replace($patterns, $replacements, $content_data); # Comment bad SQL lines |
|---|
| 1247 | |
|---|
| 1248 | $result = pg_query($connection, $content_data) or die("<B>" . pg_last_error() . "</B> <=<BR>"); |
|---|
| 1249 | print "OK</UL>"; |
|---|
| 1250 | |
|---|
| 1251 | navigation(array ( |
|---|
| 1252 | array ( |
|---|
| 1253 | "title" => "Back", |
|---|
| 1254 | "page" => "database" |
|---|
| 1255 | ), |
|---|
| 1256 | array ( |
|---|
| 1257 | "title" => "Next", |
|---|
| 1258 | "page" => "options" |
|---|
| 1259 | ) |
|---|
| 1260 | )); |
|---|
| 1261 | break; |
|---|
| 1262 | ################################### |
|---|
| 1263 | case 'DBMS_MYSQL' : |
|---|
| 1264 | print "MYSQL ... (Not working)<BR>\n"; |
|---|
| 1265 | $ptr_connexion = @ mysql_connect($CONF_DATABASE_HOST, $CONF_DATABASE_USER, $CONF_DATABASE_PASSWORD); |
|---|
| 1266 | $select_db = mysql_select_db($CONF_DATABASE_NAME); |
|---|
| 1267 | |
|---|
| 1268 | $previous_line = ''; # Used to remove "," on the line before CONSTRAINT removed line. |
|---|
| 1269 | |
|---|
| 1270 | if ($debug) |
|---|
| 1271 | print "<PRE>"; |
|---|
| 1272 | |
|---|
| 1273 | $inTable = 0; |
|---|
| 1274 | foreach ($content_schema_array as $lineNum => $line) { |
|---|
| 1275 | # if (preg_match("/^--/", $line)) continue; # Remove commented lines |
|---|
| 1276 | # if (preg_match("/^$/", $line)) continue; # Remove empty lines |
|---|
| 1277 | if ($debug) |
|---|
| 1278 | print "<B>ORI</B> $line"; |
|---|
| 1279 | if (preg_match("/^CREATE TABLE/", $line, $matchesArray)) |
|---|
| 1280 | $inTable = 1; |
|---|
| 1281 | if ($inTable) { |
|---|
| 1282 | if ($inTable && preg_match("/^\);$/", $line, $matchesArray)) { |
|---|
| 1283 | #print "<B STYLE=\"color:#FF0000;\">OUT</B>\n"; |
|---|
| 1284 | |
|---|
| 1285 | # PG => ); |
|---|
| 1286 | # MySQL => ) TYPE=InnoDB; |
|---|
| 1287 | $line = preg_replace("/^\);$/", ") TYPE=InnoDB;", $line); |
|---|
| 1288 | $inTable = 0; |
|---|
| 1289 | } |
|---|
| 1290 | else { |
|---|
| 1291 | #print "<B>IN \n</B>"; # The line is in CREATE TABLE |
|---|
| 1292 | |
|---|
| 1293 | if (preg_match("/\s*CONSTRAINT.*\n$/", $line)) { # Remove CONSTRAINT. TODO : support constraint |
|---|
| 1294 | $line = preg_replace("/\s*CONSTRAINT.*\n$/", "", $line); |
|---|
| 1295 | $previous_line = preg_replace("/,$/", "", $previous_line); |
|---|
| 1296 | #print "<B STYLE=\"color:#FF0000;\">ICI : L=$line PL=$previous_line</B>"; |
|---|
| 1297 | } |
|---|
| 1298 | # Mettre TYPE=InnoDB uniquement pour table avec CONSTRAINT ??? |
|---|
| 1299 | |
|---|
| 1300 | # PG => token_status character varying(10) NOT NULL |
|---|
| 1301 | # MySQL => `token_status` character varying(10) NOT NULL |
|---|
| 1302 | $line = preg_replace("/^(\s+)(\w+)/", "\${1}`\${2}`", $line); |
|---|
| 1303 | |
|---|
| 1304 | $line = preg_replace("/DEFAULT ('.*')::character varying NOT NULL/", "NOT NULL default \${1}", $line); |
|---|
| 1305 | |
|---|
| 1306 | $line = preg_replace("/text DEFAULT [\w':]+/", "text DEFAULT ''", $line); # MySQL does not support "text" default value |
|---|
| 1307 | #??? Erreur : 1101 - BLOB/TEXT column 'venue_type' can't have a default value. Solution : Changer 'text' pour varchar ??? |
|---|
| 1308 | |
|---|
| 1309 | # PG => token_status character varying(10) NOT NULL |
|---|
| 1310 | # MySQL => token_status VARCHAR(10) NOT NULL |
|---|
| 1311 | $line = preg_replace("/character varying\(/", "VARCHAR(", $line); |
|---|
| 1312 | |
|---|
| 1313 | $line = preg_replace("/::character varying/", "", $line); # Remove string "::character varying" |
|---|
| 1314 | |
|---|
| 1315 | # PG => account_status integer, |
|---|
| 1316 | # MySQL => account_status int, |
|---|
| 1317 | $line = preg_replace("/integer/", "int", $line); |
|---|
| 1318 | |
|---|
| 1319 | # TODO : Comprendre : Le timestamp de postgres est sous le format '2005-04-07 16:33:49.917127' |
|---|
| 1320 | # datetime de MySQL est '0000-00-00 00:00:00' |
|---|
| 1321 | $line = preg_replace("/timestamp without time zone/", "datetime", $line); |
|---|
| 1322 | |
|---|
| 1323 | $line = preg_replace("/now\(\)/", "'NOW()'", $line); |
|---|
| 1324 | |
|---|
| 1325 | #$line = preg_replace("/::text/", "", $line); |
|---|
| 1326 | |
|---|
| 1327 | $line = preg_replace("/false/", "0", $line); # Change "false" strings for 0 (zero) |
|---|
| 1328 | $line = preg_replace("/true/", "1", $line); # Change "true" strings for 1 (one) |
|---|
| 1329 | $line = preg_replace("/WITHOUT OIDS/", "", $line); # Remove "WITHOUT OIDS" |
|---|
| 1330 | |
|---|
| 1331 | # PG => binary_data bytea, |
|---|
| 1332 | # MySQL => binary_data MEDIUMBLOB |
|---|
| 1333 | # Uploading, Saving and Downloading Binary Data in a MySQL Database http://www.onlamp.com/lpt/a/370 |
|---|
| 1334 | $line = preg_replace("/bytea/", "MEDIUMBLOB", $line); # maximum 16777215 (2^24 - 1) bytes |
|---|
| 1335 | } ### End of else. Regex in CREATE TABLE {}; |
|---|
| 1336 | } ### End of if ($inTable). |
|---|
| 1337 | |
|---|
| 1338 | # PG => CREATE INDEX idx_token ON connections USING btree (token); |
|---|
| 1339 | # MySQL => CREATE INDEX idx_token USING btree ON connections (token); |
|---|
| 1340 | $line = preg_replace("/(ON \w+) USING btree/", "USING btree \${1}", $line); |
|---|
| 1341 | |
|---|
| 1342 | # SQL-query : CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users(username,account_origin) |
|---|
| 1343 | # MySQL said: #1170 - BLOB/TEXT column 'username' used in key specification without a key length |
|---|
| 1344 | # Solution : http://www.dbforums.com/t1100992.html |
|---|
| 1345 | $line = preg_replace("/CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users \(username, account_origin\);/", "CREATE UNIQUE INDEX idx_unique_username_and_account_origin USING btree ON users (username(100), account_origin(100));", $line); |
|---|
| 1346 | |
|---|
| 1347 | $line = preg_replace("/CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element \(content_group_id\);/", "CREATE INDEX idx_content_group_element_content_group_id USING btree ON content_group_element (content_group_id(100));", $line); |
|---|
| 1348 | |
|---|
| 1349 | if ($debug) |
|---|
| 1350 | print "NEW $line"; |
|---|
| 1351 | $content_mysql .= $previous_line; |
|---|
| 1352 | $previous_line = $line; |
|---|
| 1353 | } ### End of foreach ($content_schema_array as $lineNum => $line) |
|---|
| 1354 | |
|---|
| 1355 | $content_mysql .= $previous_line; # TODO: verif save the last line ? |
|---|
| 1356 | if ($debug) |
|---|
| 1357 | print "<B STYLE=\"color:#FF0000;\">####################################################################</B>\n\n$content_mysql"; # Debug |
|---|
| 1358 | if ($debug) |
|---|
| 1359 | print "</PRE>"; |
|---|
| 1360 | |
|---|
| 1361 | # $content_data = implode("", $content_mysql); |
|---|
| 1362 | |
|---|
| 1363 | $patterns[3] = '/SET client_encoding/'; |
|---|
| 1364 | $patterns[4] = '/SET check_function_bodies/'; |
|---|
| 1365 | $patterns[5] = '/SET search_path/'; |
|---|
| 1366 | $replacements[3] = '-- '; |
|---|
| 1367 | $replacements[4] = '-- '; |
|---|
| 1368 | $replacements[5] = '-- '; |
|---|
| 1369 | |
|---|
| 1370 | $content_mysql = preg_replace($patterns, $replacements, $content_mysql); |
|---|
| 1371 | |
|---|
| 1372 | print "<PRE>$content_mysql</PRE>"; # Debug |
|---|
| 1373 | |
|---|
| 1374 | exit (); |
|---|
| 1375 | |
|---|
| 1376 | $result = mysql_query($content_mysql); |
|---|
| 1377 | if (!$result) { |
|---|
| 1378 | die('Invalid query: ' . mysql_error()); |
|---|
| 1379 | } |
|---|
| 1380 | |
|---|
| 1381 | navigation(array ( |
|---|
| 1382 | array ( |
|---|
| 1383 | "title" => "Back", |
|---|
| 1384 | "page" => "database" |
|---|
| 1385 | ), |
|---|
| 1386 | array ( |
|---|
| 1387 | "title" => "Next", |
|---|
| 1388 | "page" => "dbinit" |
|---|
| 1389 | ) |
|---|
| 1390 | )); |
|---|
| 1391 | break; |
|---|
| 1392 | default : |
|---|
| 1393 | print<<<EndHTML |
|---|
| 1394 | The CONF_DBMS value <B>$CONF_DBMS</B> is not currently suported by this install script. |
|---|
| 1395 | EndHTML; |
|---|
| 1396 | navigation(array ( |
|---|
| 1397 | array ( |
|---|
| 1398 | "title" => "Back", |
|---|
| 1399 | "page" => "database" |
|---|
| 1400 | ) |
|---|
| 1401 | )); |
|---|
| 1402 | } |
|---|
| 1403 | break; |
|---|
| 1404 | |
|---|
| 1405 | ################################### |
|---|
| 1406 | case 'schema_validate' : |
|---|
| 1407 | print "<H1>Database schema upgrade</H1>\n"; |
|---|
| 1408 | |
|---|
| 1409 | require_once (dirname(__FILE__) . '/include/common.php'); |
|---|
| 1410 | |
|---|
| 1411 | require_once ('classes/AbstractDb.php'); |
|---|
| 1412 | require_once ('classes/Session.php'); |
|---|
| 1413 | require_once ('include/schema_validate.php'); |
|---|
| 1414 | |
|---|
| 1415 | validate_schema(); |
|---|
| 1416 | |
|---|
| 1417 | navigation(array ( |
|---|
| 1418 | array ( |
|---|
| 1419 | "title" => "Back", |
|---|
| 1420 | "page" => "dbinit" |
|---|
| 1421 | ), |
|---|
| 1422 | array ( |
|---|
| 1423 | "title" => "Next", |
|---|
| 1424 | "page" => "options" |
|---|
| 1425 | ) |
|---|
| 1426 | )); |
|---|
| 1427 | |
|---|
| 1428 | //navigation(array(array("title" => "Back", "page" => "dbinit"))); |
|---|
| 1429 | break; |
|---|
| 1430 | |
|---|
| 1431 | ################################### |
|---|
| 1432 | case 'options' : |
|---|
| 1433 | # TODO : Tester que la connection SSL est fonctionnelle |
|---|
| 1434 | # Options avancees : Supporter les define de [SMARTY|MAGPIE|PHLICKR|JPGRAPH]_REL_PATH |
|---|
| 1435 | print<<< EndHTML |
|---|
| 1436 | <H1>Options</H1> |
|---|
| 1437 | <TABLE border="1"> |
|---|
| 1438 | |
|---|
| 1439 | EndHTML; |
|---|
| 1440 | |
|---|
| 1441 | #$neededPackages['phlickr']['available'] = 0; |
|---|
| 1442 | #$neededExtentions['xml']['available'] = 0; |
|---|
| 1443 | foreach ($optionsInfo as $name => $foo) { # Foreach generate all <TABLE> fields |
|---|
| 1444 | $value = $configArray[$name]; # Value of option in config.php |
|---|
| 1445 | $title = $optionsInfo[$name]['title']; # Field Title |
|---|
| 1446 | $message = $optionsInfo[$name]['message']; # Message why option is disable |
|---|
| 1447 | $depend = @ eval ($optionsInfo[$name]['depend']); # Evaluate the dependencie |
|---|
| 1448 | $selectedTrue = ''; |
|---|
| 1449 | $selectedFalse = ''; # Initialize value |
|---|
| 1450 | $value == 'true' ? $selectedTrue = 'SELECTED' : $selectedFalse = 'SELECTED'; # Use to select the previous saved option |
|---|
| 1451 | $depend == 1 ? $disabled = '' : $disabled = 'DISABLED'; # Disable <SELECT> if dependencie is not satisfied |
|---|
| 1452 | $jscript = "<script type=\"text/javascript\"> newConfig(\"$name=false\"); </script>\n"; # Use to save a failed dependencie (option=false) |
|---|
| 1453 | if ($disabled == '') # Dependencie ok, erase $jscript value |
|---|
| 1454 | $jscript = ''; |
|---|
| 1455 | |
|---|
| 1456 | print<<< EndHTML |
|---|
| 1457 | <TR> |
|---|
| 1458 | <TD>$title</TD> |
|---|
| 1459 | <TD><SELECT name="$name" $disabled> |
|---|
| 1460 | <OPTION value="true" $selectedTrue>true</OPTION> |
|---|
| 1461 | <OPTION value="false" $selectedFalse>false</OPTION> |
|---|
| 1462 | </SELECT> |
|---|
| 1463 | </TD> |
|---|
| 1464 | <TD>$message</TD> |
|---|
| 1465 | </TR> |
|---|
| 1466 | $jscript |
|---|
| 1467 | EndHTML; |
|---|
| 1468 | } # End or foreach |
|---|
| 1469 | print<<< EndHTML |
|---|
| 1470 | </TABLE> |
|---|
| 1471 | |
|---|
| 1472 | <script type="text/javascript"> |
|---|
| 1473 | function submitOptionsValue() { |
|---|
| 1474 | |
|---|
| 1475 | EndHTML; |
|---|
| 1476 | |
|---|
| 1477 | foreach ($optionsInfo as $name => $foo) { # Generate the javascript to save value on submit |
|---|
| 1478 | print<<< EndHTML |
|---|
| 1479 | if (!document.myform.$name.disabled) |
|---|
| 1480 | newConfig("$name=" + document.myform.$name.value); |
|---|
| 1481 | |
|---|
| 1482 | EndHTML; |
|---|
| 1483 | } # End Foreach |
|---|
| 1484 | |
|---|
| 1485 | print<<< EndHTML |
|---|
| 1486 | } |
|---|
| 1487 | </script> |
|---|
| 1488 | |
|---|
| 1489 | EndHTML; |
|---|
| 1490 | navigation(array ( |
|---|
| 1491 | array ( |
|---|
| 1492 | "title" => "Back", |
|---|
| 1493 | "page" => "dbinit" |
|---|
| 1494 | ) |
|---|
| 1495 | )); |
|---|
| 1496 | |
|---|
| 1497 | print<<< EndHTML |
|---|
| 1498 | <P><A HREF="#" ONCLICK="javascript: document.myform.page.value='languages'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></P> |
|---|
| 1499 | EndHTML; |
|---|
| 1500 | |
|---|
| 1501 | break; |
|---|
| 1502 | |
|---|
| 1503 | ################################### |
|---|
| 1504 | case 'languages' : |
|---|
| 1505 | print "<H1>Languages configuration</H1>"; |
|---|
| 1506 | print<<< EndHTML |
|---|
| 1507 | <P>Not yet implemented ...</P> |
|---|
| 1508 | <P>Will allow selecting language to use.</P> |
|---|
| 1509 | <B>Error message example</B> : <BR> |
|---|
| 1510 | <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> |
|---|
| 1511 | <P><B>I repeat</B> : 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 <B>config.php</B> in auth-server install directory. Look for "Available locales" and "Default language" header in config.php. |
|---|
| 1512 | EndHTML; |
|---|
| 1513 | // execVerbose("locale -a 2>&1", $output, $return); |
|---|
| 1514 | |
|---|
| 1515 | navigation(array ( |
|---|
| 1516 | array ( |
|---|
| 1517 | "title" => "Back", |
|---|
| 1518 | "page" => "options" |
|---|
| 1519 | ), |
|---|
| 1520 | array ( |
|---|
| 1521 | "title" => "Next", |
|---|
| 1522 | "page" => "radius" |
|---|
| 1523 | ) |
|---|
| 1524 | )); |
|---|
| 1525 | break; |
|---|
| 1526 | |
|---|
| 1527 | ################################### |
|---|
| 1528 | case 'radius' : |
|---|
| 1529 | print "<H1>Radius Authenticator configuration</H1>"; |
|---|
| 1530 | print "<P>Not yet implemented ..."; |
|---|
| 1531 | |
|---|
| 1532 | # Dependencies |
|---|
| 1533 | #$neededExtentions['mcrypt']['available']; |
|---|
| 1534 | #$neededExtentions['mhash']['available']; |
|---|
| 1535 | #$neededExtentions['xmlrpc']['available']; |
|---|
| 1536 | #$neededPEARPackages['radius']['available']; |
|---|
| 1537 | #$neededPEARPackages['Auth_RADIUS']['available']; |
|---|
| 1538 | #$neededPEARPackages['Crypt_CHAP']['available']; |
|---|
| 1539 | |
|---|
| 1540 | navigation(array ( |
|---|
| 1541 | array ( |
|---|
| 1542 | "title" => "Back", |
|---|
| 1543 | "page" => "languages" |
|---|
| 1544 | ), |
|---|
| 1545 | array ( |
|---|
| 1546 | "title" => "Next", |
|---|
| 1547 | "page" => "admin" |
|---|
| 1548 | ) |
|---|
| 1549 | )); |
|---|
| 1550 | break; |
|---|
| 1551 | |
|---|
| 1552 | ################################### |
|---|
| 1553 | case 'admin' : |
|---|
| 1554 | print "<H1>Administration account</H1>"; |
|---|
| 1555 | # TODO : Allow to create more than one admin account and list the current admin users |
|---|
| 1556 | # Allow admin to choose to show or not is username |
|---|
| 1557 | empty ($_REQUEST['username']) ? $username = 'admin' : $username = $_REQUEST['username']; |
|---|
| 1558 | empty ($_REQUEST['password']) ? $password = '' : $password = $_REQUEST['password']; |
|---|
| 1559 | empty ($_REQUEST['password2']) ? $password2 = '' : $password2 = $_REQUEST['password2']; |
|---|
| 1560 | empty ($_REQUEST['email']) ? $email = $_SERVER['SERVER_ADMIN'] : $email = $_REQUEST['email']; |
|---|
| 1561 | |
|---|
| 1562 | $conn_string = "host=$CONF_DATABASE_HOST dbname=$CONF_DATABASE_NAME user=$CONF_DATABASE_USER password=$CONF_DATABASE_PASSWORD"; |
|---|
| 1563 | $connection = pg_connect($conn_string) or die(); |
|---|
| 1564 | |
|---|
| 1565 | if ($action == 'create') { |
|---|
| 1566 | // require_once(dirname(__FILE__) . '/config.php'); |
|---|
| 1567 | require_once (dirname(__FILE__) . '/include/common.php'); |
|---|
| 1568 | require_once (dirname(__FILE__) . '/classes/User.php'); |
|---|
| 1569 | |
|---|
| 1570 | $created_user = User :: createUser(get_guid(), $username, Network :: getDefaultNetwork(), $email, $password); |
|---|
| 1571 | $user_id = $created_user->getId(); |
|---|
| 1572 | |
|---|
| 1573 | # Add user to admin table, hide his username and set his account status to 1 (allowed) |
|---|
| 1574 | $sql = "INSERT INTO administrators (user_id) VALUES ('$user_id'); UPDATE users SET account_status='1', never_show_username=true WHERE user_id='$user_id'"; |
|---|
| 1575 | $result = pg_query($connection, $sql); |
|---|
| 1576 | } |
|---|
| 1577 | |
|---|
| 1578 | $sql = "SELECT * FROM users NATURAL JOIN administrators WHERE account_origin = 'default-network'"; |
|---|
| 1579 | $result = pg_query($connection, $sql); |
|---|
| 1580 | $result_array = pg_fetch_all($result); |
|---|
| 1581 | $username_db = $result_array[0]['username']; |
|---|
| 1582 | |
|---|
| 1583 | if (!empty ($username_db)) { |
|---|
| 1584 | print "<P>Your administrator user account is <B>$username_db</B>"; |
|---|
| 1585 | navigation(array ( |
|---|
| 1586 | array ( |
|---|
| 1587 | "title" => "Back", |
|---|
| 1588 | "page" => "radius" |
|---|
| 1589 | ), |
|---|
| 1590 | array ( |
|---|
| 1591 | "title" => "Next", |
|---|
| 1592 | "page" => "network" |
|---|
| 1593 | ) |
|---|
| 1594 | )); |
|---|
| 1595 | } |
|---|
| 1596 | else { |
|---|
| 1597 | print<<<EndHTML |
|---|
| 1598 | <P> |
|---|
| 1599 | <TABLE BORDER="1"> |
|---|
| 1600 | <TR> |
|---|
| 1601 | <TD>Username</TD><TD><INPUT type="text" name="username" value="$username"></TD> |
|---|
| 1602 | </TR> |
|---|
| 1603 | <TR> |
|---|
| 1604 | <TD>Password</TD><TD><INPUT type="password" name="password"></TD> |
|---|
| 1605 | </TR> |
|---|
| 1606 | <TR> |
|---|
| 1607 | <TD>Password again</TD><TD><INPUT type="password" name="password2"></TD> |
|---|
| 1608 | </TR> |
|---|
| 1609 | <TR> |
|---|
| 1610 | <TD>Email</TD><TD><INPUT type="text" name="email" value="$email"></TD> |
|---|
| 1611 | </TR> |
|---|
| 1612 | </TABLE> |
|---|
| 1613 | |
|---|
| 1614 | <script type="text/javascript"> |
|---|
| 1615 | function submitValue() { |
|---|
| 1616 | if (document.myform.password.value != document.myform.password2.value) { |
|---|
| 1617 | alert('Password mismatch, Please retry'); |
|---|
| 1618 | exit(); |
|---|
| 1619 | } |
|---|
| 1620 | if (document.myform.password.value == '') { |
|---|
| 1621 | alert('You need to type a password'); |
|---|
| 1622 | exit(); |
|---|
| 1623 | } |
|---|
| 1624 | if (document.myform.email.value == '') { |
|---|
| 1625 | alert('You need to type a email'); |
|---|
| 1626 | exit(); |
|---|
| 1627 | } |
|---|
| 1628 | document.myform.page.value='admin'; |
|---|
| 1629 | document.myform.action.value='create'; |
|---|
| 1630 | document.myform.submit(); |
|---|
| 1631 | } |
|---|
| 1632 | </script> |
|---|
| 1633 | |
|---|
| 1634 | EndHTML; |
|---|
| 1635 | navigation(array ( |
|---|
| 1636 | array ( |
|---|
| 1637 | "title" => "Back", |
|---|
| 1638 | "page" => "radius" |
|---|
| 1639 | ) |
|---|
| 1640 | )); |
|---|
| 1641 | print "<P><A HREF=\"#\" ONCLICK=\"javascript: submitValue();\" CLASS=\"button\">Next</A></P>\n"; |
|---|
| 1642 | } |
|---|
| 1643 | break; |
|---|
| 1644 | |
|---|
| 1645 | ################################### |
|---|
| 1646 | case 'network' : |
|---|
| 1647 | print "<H1>Network</H1>"; |
|---|
| 1648 | |
|---|
| 1649 | //$HOTSPOT_NETWORK_NAME = $configArray['HOTSPOT_NETWORK_NAME']; |
|---|
| 1650 | //$HOTSPOT_NETWORK_URL = $configArray['HOTSPOT_NETWORK_URL']; |
|---|
| 1651 | //$TECH_SUPPORT_EMAIL = $configArray['TECH_SUPPORT_EMAIL']; |
|---|
| 1652 | //$VALIDATION_GRACE_TIME = $configArray['VALIDATION_GRACE_TIME']; |
|---|
| 1653 | //$VALIDATION_EMAIL_FROM_ADDRESS = $configArray['VALIDATION_EMAIL_FROM_ADDRESS']; |
|---|
| 1654 | |
|---|
| 1655 | /** |
|---|
| 1656 | * @deprecated 2005-12-26 Needs to use network abstraction |
|---|
| 1657 | * |
|---|
| 1658 | * |
|---|
| 1659 | * <P> |
|---|
| 1660 | <TABLE border="1"> |
|---|
| 1661 | <TR> |
|---|
| 1662 | <TD>Network Name</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_NAME" value="" size="30"></TD> |
|---|
| 1663 | </TR> |
|---|
| 1664 | <TR> |
|---|
| 1665 | <TD>Network URL</TD><TD><INPUT type="text" name="HOTSPOT_NETWORK_URL" value="" size="30"></TD> |
|---|
| 1666 | </TR> |
|---|
| 1667 | <TR> |
|---|
| 1668 | <TD>Tech Support Email</TD><TD><INPUT type="text" name="TECH_SUPPORT_EMAIL" value="" size="30"></TD> |
|---|
| 1669 | </TR> |
|---|
| 1670 | <TR> |
|---|
| 1671 | <TD>Validation Grace Time (min)</TD><TD><INPUT type="text" name="VALIDATION_GRACE_TIME" value="" size="30"></TD> |
|---|
| 1672 | </TR> |
|---|
| 1673 | <TR> |
|---|
| 1674 | <TD>Validation Email (send from)</TD><TD><INPUT type="text" name="VALIDATION_EMAIL_FROM_ADDRESS" value="" size="30"></TD> |
|---|
| 1675 | </TR> |
|---|
| 1676 | </TABLE> |
|---|
| 1677 | */ |
|---|
| 1678 | print "Need to reimplement this... Until then connect to the administration pages and modify it by yourself."; |
|---|
| 1679 | |
|---|
| 1680 | print<<< EndHTML |
|---|
| 1681 | |
|---|
| 1682 | |
|---|
| 1683 | <script type="text/javascript"> |
|---|
| 1684 | function submitOptionsValue() { |
|---|
| 1685 | //newConfig("HOTSPOT_NETWORK_NAME='" + document.myform.HOTSPOT_NETWORK_NAME.value + "'"); |
|---|
| 1686 | //newConfig("HOTSPOT_NETWORK_URL='" + document.myform.HOTSPOT_NETWORK_URL.value + "'"); |
|---|
| 1687 | //newConfig("TECH_SUPPORT_EMAIL='" + document.myform.TECH_SUPPORT_EMAIL.value + "'"); |
|---|
| 1688 | //newConfig("VALIDATION_GRACE_TIME=" + document.myform.VALIDATION_GRACE_TIME.value); |
|---|
| 1689 | //newConfig("VALIDATION_EMAIL_FROM_ADDRESS='" + document.myform.VALIDATION_EMAIL_FROM_ADDRESS.value + "'"); |
|---|
| 1690 | } |
|---|
| 1691 | </script> |
|---|
| 1692 | |
|---|
| 1693 | EndHTML; |
|---|
| 1694 | |
|---|
| 1695 | navigation(array ( |
|---|
| 1696 | array ( |
|---|
| 1697 | "title" => "Back", |
|---|
| 1698 | "page" => "admin" |
|---|
| 1699 | ) |
|---|
| 1700 | )); |
|---|
| 1701 | |
|---|
| 1702 | print<<< EndHTML |
|---|
| 1703 | <P><A HREF="#" ONCLICK="javascript: document.myform.page.value='hotspot'; submitOptionsValue(); document.myform.submit();" CLASS="button">Next</A></P> |
|---|
| 1704 | EndHTML; |
|---|
| 1705 | #navigation(array(array("title" => "Back", "page" => "admin"), array("title" => "Next", "page" => "hotspot"))); |
|---|
| 1706 | break; |
|---|
| 1707 | |
|---|
| 1708 | ################################### |
|---|
| 1709 | case 'hotspot' : |
|---|
| 1710 | print "<H1>Hotspot</H1>"; |
|---|
| 1711 | print "<P>A default hotspot has already been created<P>Use administration interface to add more hotspots."; |
|---|
| 1712 | navigation(array ( |
|---|
| 1713 | array ( |
|---|
| 1714 | "title" => "Back", |
|---|
| 1715 | "page" => "network" |
|---|
| 1716 | ), |
|---|
| 1717 | array ( |
|---|
| 1718 | "title" => "Next", |
|---|
| 1719 | "page" => "end" |
|---|
| 1720 | ) |
|---|
| 1721 | )); |
|---|
| 1722 | break; |
|---|
| 1723 | |
|---|
| 1724 | ################################### |
|---|
| 1725 | case 'delete' : |
|---|
| 1726 | print<<<EndHTML |
|---|
| 1727 | <H1>Delete temporary files</H1> |
|---|
| 1728 | ... |
|---|
| 1729 | EndHTML; |
|---|
| 1730 | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
|---|
| 1731 | break; |
|---|
| 1732 | |
|---|
| 1733 | ################################### |
|---|
| 1734 | case 'end' : |
|---|
| 1735 | $url = 'http://' . $_SERVER['HTTP_HOST'] . SYSTEM_PATH; |
|---|
| 1736 | print<<<EndHTML |
|---|
| 1737 | <H1>Thanks for using Wifidog</H1> |
|---|
| 1738 | Redirection to your new WifiDog Authentification Server in 3 seconds |
|---|
| 1739 | <meta http-equiv="REFRESH" content="3;url=$url"> |
|---|
| 1740 | <PRE> |
|---|
| 1741 | |
|---|
| 1742 | |\ /| _ |
|---|
| 1743 | |A\_/A| z z |
|---|
| 1744 | ___| | ( (o) ) |
|---|
| 1745 | o 6 \ z _ z |
|---|
| 1746 | |___ \ /| |
|---|
| 1747 | | \ / | |
|---|
| 1748 | \ \_______/ | |
|---|
| 1749 | | | |
|---|
| 1750 | | WIFIDOG | |
|---|
| 1751 | | Captive Portal | |
|---|
| 1752 | | _____________ | |
|---|
| 1753 | | / \ | |
|---|
| 1754 | | | | | |
|---|
| 1755 | | | | | |
|---|
| 1756 | _/ | _/ | |
|---|
| 1757 | ?_____| ?_____| |
|---|
| 1758 | </PRE> |
|---|
| 1759 | EndHTML; |
|---|
| 1760 | #navigation(array(array("title" => "Back", "page" => "hotspot"))); |
|---|
| 1761 | break; |
|---|
| 1762 | |
|---|
| 1763 | ################################### |
|---|
| 1764 | case 'toc' : |
|---|
| 1765 | print "<H1>Table of content</H1>"; |
|---|
| 1766 | $contentArray = file(__file__); # Read myself |
|---|
| 1767 | print "<UL>\n"; |
|---|
| 1768 | foreach ($contentArray as $line) { |
|---|
| 1769 | if (preg_match("/^ case '(\w+)':/", $line, $matchesArray)) { # Parse for "case" regex |
|---|
| 1770 | if ($matchesArray[1] == 'toc') |
|---|
| 1771 | continue; |
|---|
| 1772 | print "<LI><A HREF=\"" . $_SERVER['SCRIPT_NAME'] . "?page=" . $matchesArray[1] . "\">" . $matchesArray[1] . "</A>\n"; # Display a Table of Content |
|---|
| 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | print "</UL>\n"; |
|---|
| 1776 | break; |
|---|
| 1777 | ################################### |
|---|
| 1778 | case 'notes' : |
|---|
| 1779 | print<<<EndHTML |
|---|
| 1780 | <!-- /* Editor highlighting trick --> |
|---|
| 1781 | <PRE> |
|---|
| 1782 | <B>TODO</B> |
|---|
| 1783 | -Support des define de Google Maps dans config.php |
|---|
| 1784 | -Faire une fonction d'execution avec gestion de retour d'erreur et d'affichage de l'exection pour chaque "exec" |
|---|
| 1785 | -Ajouter une veritable validation (user/password admin provenant de la DB) |
|---|
| 1786 | Pour une meilleur securite du script d'installation. |
|---|
| 1787 | Au chargement, valider que la connection DB est fonctionnel, que la DB existe et que l'usager admin existe |
|---|
| 1788 | Si oui, on demande l'authentification |
|---|
| 1789 | Si non, on creer l'usager admin |
|---|
| 1790 | -Faire un vrai menu pour acceder directement aux pages desirees (pas une TOC poche) |
|---|
| 1791 | -Ameliorer le javascript et arreter de faire des document.myform.submit(); |
|---|
| 1792 | -Generate valid HTML code |
|---|
| 1793 | -Integrate this script with the portal skin |
|---|
| 1794 | -Tester que les donnees de AVAIL_LOCALE_ARRAY dans config.php sont valides (fonctionnelles) |
|---|
| 1795 | Regarder le code dans include/language.php |
|---|
| 1796 | -Support pour l'option CUSTOM_SIGNUP_URL |
|---|
| 1797 | -Effacer repertoires/fichiers temporaires des installations |
|---|
| 1798 | |
|---|
| 1799 | -Nice2Have : Si test d'integrite et de fonctionnement existent, les integrer pour assurer le bon fonctionnement |
|---|
| 1800 | -Nice2Have : Si donnees de tests exitent (pour les developpeurs) Permettre d'en ajouter a la DB |
|---|
| 1801 | -Nice2Have : Creer un wifidog.conf (client) selon config + questions si necessaires |
|---|
| 1802 | |
|---|
| 1803 | <B>Change Log</B> |
|---|
| 1804 | 15-08-2005 : Bugs correction + comments added |
|---|
| 1805 | 11-08-2005 : Options rewrite with foreach and dependencies |
|---|
| 1806 | 09-08-2005 : Admin user creation + network configuration |
|---|
| 1807 | 27-07-2005 : Added jpgraph install |
|---|
| 1808 | 26-07-2005 : Added minimal security password validation |
|---|
| 1809 | 14-07-2005 : saveConfig and all javascript code |
|---|
| 1810 | 09-07-2005 : Added Phlickr installation |
|---|
| 1811 | 05-07-2005 : Better PHP extention validation process |
|---|
| 1812 | 17-06-2005 : MySQL schema and data submission |
|---|
| 1813 | 17-06-2005 : Postgresql schema and data submission |
|---|
| 1814 | 24-04-2005 : CSS button |
|---|
| 1815 | |
|---|
| 1816 | </PRE> |
|---|
| 1817 | <!-- Editor highlighting trick */ --> |
|---|
| 1818 | EndHTML; |
|---|
| 1819 | break; |
|---|
| 1820 | ################################### |
|---|
| 1821 | /* case 'phpinfo': // Use for debugging, to be removed |
|---|
| 1822 | print "<PRE>"; |
|---|
| 1823 | print_r(get_loaded_extensions()); |
|---|
| 1824 | print "</PRE><BR><BR>"; |
|---|
| 1825 | phpinfo(); |
|---|
| 1826 | break;*/ |
|---|
| 1827 | |
|---|
| 1828 | default : |
|---|
| 1829 | $WIFIDOG_VERSION = $configArray['WIFIDOG_VERSION']; |
|---|
| 1830 | # TODO : Add links to auth-server web documents |
|---|
| 1831 | print<<<EndHTML |
|---|
| 1832 | <H1>Welcome to WifiDog Auth-Server installation and configuration script.</H1> |
|---|
| 1833 | <P>This installation still needs improvement, so please any report bug to the mailing list for better support.<BR/> |
|---|
| 1834 | The current auth-server version is <B>$WIFIDOG_VERSION</B>.</P> |
|---|
| 1835 | |
|---|
| 1836 | <P><strong>Before going any further</strong> with this installation you need to have/create a valid user and database. |
|---|
| 1837 | <P>Here is a command line example for PostgreSQL (or use the way you like) :</P> |
|---|
| 1838 | |
|---|
| 1839 | <B>Create the PostgreSQL databaser user for WifiDog</B> (createuser and createdb need to be in you PATH) : |
|---|
| 1840 | <PRE> <I>postgres@yourserver $></I> createuser wifidog --pwprompt |
|---|
| 1841 | Enter password for new user: |
|---|
| 1842 | Enter it again: |
|---|
| 1843 | Shall the new user be allowed to create databases? (y/n) n |
|---|
| 1844 | Shall the new user be allowed to create more new users? (y/n) n |
|---|
| 1845 | CREATE USER |
|---|
| 1846 | </PRE> |
|---|
| 1847 | |
|---|
| 1848 | <B>Create the WifiDog database</B> |
|---|
| 1849 | <PRE> <I>postgres@yourserver $></I> createdb wifidog --encoding=UTF-8 --owner=wifidog |
|---|
| 1850 | CREATE DATABASE |
|---|
| 1851 | </PRE> |
|---|
| 1852 | |
|---|
| 1853 | <B>Security</B> : A password is needed to continue with the installation. You need to read the random password in <B>$password_file</B> 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. |
|---|
| 1854 | </PRE> |
|---|
| 1855 | |
|---|
| 1856 | <P>When you are ready click next</P> |
|---|
| 1857 | |
|---|
| 1858 | EndHTML; |
|---|
| 1859 | |
|---|
| 1860 | navigation(array ( |
|---|
| 1861 | array ( |
|---|
| 1862 | "title" => "Next", |
|---|
| 1863 | "page" => "version" |
|---|
| 1864 | ) |
|---|
| 1865 | )); |
|---|
| 1866 | } |
|---|
| 1867 | ?> |
|---|
| 1868 | |
|---|
| 1869 | </form> |
|---|
| 1870 | </body> |
|---|
| 1871 | </html> |
|---|
| 1872 | |
|---|