From: arno Date: Sat, 15 Aug 2009 14:08:29 +0000 (+0200) Subject: improve wizard (hand editing of settings.php is no more needed) X-Git-Tag: v0.3b_thomas~22 X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=commitdiff_plain;h=b6cae6a5698c5d0655d921f78f0ccab470bf034c improve wizard (hand editing of settings.php is no more needed) --- diff --git a/.gitignore b/.gitignore index 9ef67c4..5484253 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ upload/* +inc/settings.php diff --git a/README.txt b/README.txt index f85228b..33f29a3 100644 --- a/README.txt +++ b/README.txt @@ -14,10 +14,25 @@ Requirements Installation ------------ -upload syp to your webserver -edit inc/settings.php -open http://yoururl.com/wizard.php with your web browser -follow instructions + +* manual configuration + +- edit inc/settings.php.in and copy it to inc/settings.php +- upload syp to your webserver +- open http://yoururl.com/install.php with your web browser to finalize + installation (database tables creation). + +* automatic configuration +- upload syp to your webserver +- open http://yoururl.com/install.php with your web browser and follow + instructions. + +For automatic configuration to work, inc/ directory needs to be writeable. Use +chmod to set the appropriate directory permissions. If in doubt, chmod to 0777. +Alternatively, you can use manual method. + +Some advanced configuration options are not available with automatic method. If +you need to set those options, use manual configuration. Upgrade ------------ diff --git a/api.php b/api.php index a9df091..0d6e727 100644 --- a/api.php +++ b/api.php @@ -2,10 +2,6 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("./inc/settings.php"); -require_once ("./inc/db/mysql.php"); -require_once ("./inc/utils.php"); - function exit_document ($body) { exit ("$body"); } @@ -314,6 +310,12 @@ function main ($con) { server_error (); } +if (!@include_once ("./inc/settings.php")) { + server_error (); +} +require_once ("./inc/db/mysql.php"); +require_once ("./inc/utils.php"); + try { $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); } catch (Exception $e) { diff --git a/build.sh b/build.sh index 2af3bb8..82aacec 100755 --- a/build.sh +++ b/build.sh @@ -15,7 +15,7 @@ mkdir -p $DESTDIR cp -RLp inc/ $DESTDIR/ # other php files -cp -p admin.*php index.*php upgrade.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/ +cp -p admin.*php index.*php upgrade.*php install.*php news.php api.php items.php logout.php $DESTDIR/ # media cp -RLp media/ $DESTDIR/ diff --git a/inc/i10n/en/syp.php b/inc/i10n/en/syp.php index 3bf57b9..a16e4ce 100644 --- a/inc/i10n/en/syp.php +++ b/inc/i10n/en/syp.php @@ -32,6 +32,51 @@ "You need at least PHP version 5" => "", + "Cannot save config file. You need either to set inc/ writable, or use manual method. See README.txt for more informations." + => "", + + "SYP configuration" + => "", + + "address of the database server (example: localhost, db.myhost.com or 192.168.0.15)." + => "", + + "database server hostname:" + => "", + + "The name of the database that SYP will be installed into. The database must exist." + => "", + + "database name:" + => "", + + "The username with which you connect to the database." + => "", + + "database user:" + => "", + + "The password with which you connect to the database." + => "", + + "database password:" + => "", + + "You can specify a table prefix. This way you can run multiple SYP installations in the same database, each with its own prefix." + => "", + + "tables prefix:" + => "", + + "The title you want to give to your SYP site." + => "", + + "site title:" + => "", + + "Start install" + => "", + "not supported" => "", @@ -44,6 +89,15 @@ "Unknown error when connecting to database." => "", + "Could not read inc/settings.php.in" + => "", + + "Config file created" + => "", + + "Config file exists" + => "", + "Unknown error when checking user table." => "", @@ -108,7 +162,7 @@ => "", "SYP is not correctly installed. Please follow README.txt instructions\n" . - " and go to wizard." + " and go to wizard." => "", "add a place" diff --git a/inc/i10n/fr/syp.php b/inc/i10n/fr/syp.php index 0ebe330..ff5c29b 100644 --- a/inc/i10n/fr/syp.php +++ b/inc/i10n/fr/syp.php @@ -43,6 +43,81 @@ "Vous devez utiliser une version de PHP au moins égale à la version 5" , + "Cannot save config file. You need either to set inc/ writable, or use manual method. See README.txt for more informations." + => + "Impossible d'enregistrer le fichier de configuration. Vous devez rendre le répertoire inc/ accessible en écriture ou utiliser la méthode manuelle. Consultez README.txt pour plus d'informations." + , + + "SYP configuration" + => + "Configuration de SYP" + , + + "address of the database server (example: localhost, db.myhost.com or 192.168.0.15)." + => + "addresse du serveur de base de données (exemple: localhost, db.myhost.com ou 192.168.0.15)" + , + + "database server hostname:" + => + "addresse du serveur de base de données :" + , + + "The name of the database that SYP will be installed into. The database must exist." + => + "Le nom de la base de données dans laquelle SYP va être installé. La base doit exister." + , + + "database name:" + => + "nom de la base de données :" + , + + "The username with which you connect to the database." + => + "Le nom d'utilisateur avec lequel vous vous connectez à la base." + , + + "database user:" + => + "nom d'utilisateur de la base :" + , + + "The password with which you connect to the database." + => + "Le mot de passe avec lequel vous vous connectez à la base." + , + + "database password:" + => + "mot de passe de la base :" + , + + "You can specify a table prefix. This way you can run multiple SYP installations in the same database, each with its own prefix." + => + "Vous pouvez définir un préfixe de table. Vous pourrez ainsi avoir plusieurs installations de SYP sur la même base, chacune avec son propre préfixe." + , + + "tables prefix:" + => + "préfixe de tables: " + , + + "The title you want to give to your SYP site." + => + "Le titre que vous voulez donner à votre site SYP." + , + + "site title:" + => + "titre du site " + , + + "Start install" + => + "Commencer l'installation" + , + "not supported" => "support non détecté" @@ -63,6 +138,21 @@ "Erreur inconnue lors de la connexion à la base." , + "Could not read inc/settings.php.in" + => + "Impossible de lire inc/settings.php.in" + , + + "Config file created" + => + "Fichier de configuration créé" + , + + "Config file exists" + => + "Le fichier de configuration existe" + , + "Unknown error when checking user table." => "Erreur inconnue lors de la vérification de la table utilisateur." @@ -169,11 +259,11 @@ , "SYP is not correctly installed. Please follow README.txt instructions\n" . - " and go to wizard." + " and go to wizard." => "SYP n'est pas correctement installé. Veuillez\n" . " suivre les instructions du fichier README.txt et vous rendre\n" . - " sur la page du wizard." + " sur la page du wizard." , "add a place" @@ -322,4 +412,4 @@ , ) -?> \ No newline at end of file +?> diff --git a/inc/i10n/updatelang.php b/inc/i10n/updatelang.php index 023797f..ff049eb 100755 --- a/inc/i10n/updatelang.php +++ b/inc/i10n/updatelang.php @@ -10,7 +10,7 @@ if (!(isset ($argc)) || !(isset ($argv))) { $ROOTDIR = "../../"; // scripts in rootdir we need to link to -$SCRIPTS = array ("admin", "index", "upgrade", "wizard"); +$SCRIPTS = array ("admin", "index", "upgrade", "install"); function usage() { global $argv; diff --git a/inc/install_utils.php b/inc/install_utils.php new file mode 100644 index 0000000..14ef093 --- /dev/null +++ b/inc/install_utils.php @@ -0,0 +1,42 @@ +"); +} +function par_success ($message) { + printf ("

%s

", $message); +} +function par_error ($message) { + printf ("

%s

", $message); +} +function par_warn ($message) { + printf ("

%s

", $message); +} +function par_error_and_leave ($message) { + printf ("

%s

", $message); + leave (); +} +?> diff --git a/inc/settings.php b/inc/settings.php.in similarity index 100% rename from inc/settings.php rename to inc/settings.php.in diff --git a/inc/templates_admin.php b/inc/templates_admin.php index 814ca45..1f28e79 100644 --- a/inc/templates_admin.php +++ b/inc/templates_admin.php @@ -2,11 +2,14 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("./inc/settings.php"); +$error = false; + +if (!@include_once ("./inc/settings.php")) { + $error = true; +} require_once ("./inc/db/mysql.php"); require_once ("./inc/utils.php"); -$error = false; try { $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); $usrtblexists = $connection->users_table_exists (); @@ -29,7 +32,7 @@ if (!$usrtblexists || !$itemstblexists) {

wizard.')?>

+ and go to wizard.')?>

"> - <?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?> + <?php echo defined ("SITETITLE") ? htmlspecialchars (SITETITLE) : "SYP"?> diff --git a/inc/templates_install.php b/inc/templates_install.php new file mode 100644 index 0000000..86c8566 --- /dev/null +++ b/inc/templates_install.php @@ -0,0 +1,246 @@ + + + + + + + <?php ptrans ('SYP wizard')?> + + + + +
' . "\n"; + print '' . trans ("SYP configuration") . '' . "\n"; + + print '
' . "\n" . + '
' . "\n"; + + print '
' . "\n" . + '
' . "\n"; + + print '
' . "\n" . + '
' . "\n"; + + print '
' . "\n" . + '
' . "\n"; + + print '
' . "\n" . + '' . "\n"; + + print '
' . "\n" . + '' . "\n"; + + print '
'; + print '
'; + } + + if (file_exists (CONFIG_FILE)) { + require_once (CONFIG_FILE); + } else if (isset ($_POST["db_form_submit"])) { // user has submitted form + + function _unquote($gpc_str) { + if (!isset ($gpc_str)) { + return $gpc_str; + } + if (get_magic_quotes_gpc ()) { + return stripslashes ($gpc_str); + } else { + return $gpc_str; + } + } + + define (DBHOST, _unquote ($_POST ["db_host"])); + define (DBNAME, _unquote ($_POST ["db_name"])); + define (DBUSER, _unquote ($_POST ["db_user"])); + define (DBPWD, _unquote ($_POST ["db_pass"])); + define (DBPREFIX, _unquote ($_POST ["db_prefix"])); + define (SITETITLE, _unquote ($_POST ["site_title"])); + + // default values + define (UPLOADDIR, "upload"); + define (THUMBSDIR, "upload/_thumbs"); + } else { + if (!is_writable (dirname (CONFIG_FILE))) { + error_unwritable_config (); + } + + create_install_form (); + leave (); + } + + require_once ("./inc/db/mysql.php"); + require_once ("./inc/utils.php"); + + try { + $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); + } catch (Exception $e) { + switch ($e->getMessage ()) { + case anydbConnection::err_driver_unavailable: + par_error ($connection->getdbname() . ': ' . trans ('not supported')); + break; + case anydbConnection::err_connection: + par_error (trans ('Could not connect to database.')); + break; + case anydbConnection::err_unknown_database: + par_error (trans ('Database does not exist.')); + break; + default: + par_error (trans ('Unknown error when connecting to database.')); + break; + } + + if (isset ($_POST ["db_form_submit"])) { + // user had submited database informations. They seem to be wrong. + // Ask again. + create_install_form (); + } + leave (); + } + + // we can connect to table. If config file does not exist, try to create it now. + if (!file_exists (CONFIG_FILE)) { + $handle = fopen ("./inc/settings.php.in", "r"); + $lines = array(); + if ($handle) { + while (!feof ($handle)) { + $line = fgets ($handle, 4096); + foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) { + $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)"; + if (preg_match( "/$pattern/", $line, $match )) { + $line = $match[1] . addslashes (constant ($value)) . $match[2]; + break; + } + } + array_push ($lines, $line); + } + fclose ($handle); + } else { + par_error_and_leave (trans ('Could not read inc/settings.php.in')); + } + + $handle = fopen(CONFIG_FILE, 'w'); + if (!$handle) { + error_unwritable_config (); + } + fwrite ($handle, join($lines)); + par_success (trans ('Config file created')); + } else { + par_success (trans ('Config file exists')); + } + + try { + $users_table_exists = $connection->users_table_exists (); + } catch(Exception $e) { + par_error_and_leave (trans ('Unknown error when checking user table.')); + } + + if ($users_table_exists) { + par_success (trans ('Found user table.')); + } else { + if (isset($_POST ["admin_pass"])) { + try { + $connection->create_users_table (true); + } catch (Exception $e) { + par_error_and_leave (trans ('Error when creating user table.')); + } + par_success (trans ('User table created.')); + try { + $connection->setpwd ("admin", $_POST ["admin_pass"]); + } catch (Exception $e) { + par_error_and_leave (trans ('Error when initializing password.')); + } + par_success (trans ('Admin password initialized.')); + + } else { + print ('
+ + + +
'); + leave (); + } + } + + try { + $items_table_exists = $connection->items_table_exists (); + } catch (Exception $e) { + par_error_and_leave (trans ('Unknown error when checking data table.')); + } + if ($items_table_exists) { + par_success (trans ('Found data table.')); + } else { + try { + $connection->create_items_table (true); + } catch (Exception $e) { + par_error_and_leave (trans ('Error when creating data table.')); + } + par_success (trans ('Data table created.')); + } + + safe_create_writable_dir (UPLOADDIR); + safe_create_writable_dir (getthumbsdir ()); + + if (!function_exists ("gd_info")) { + par_warn (trans ('It looks like GD extension is not installed.')); + } + + par_success (trans ('SYP is installed. You can now go to admin area')); +?> + + + diff --git a/inc/templates_upgrade.php b/inc/templates_upgrade.php index a636145..9c3a24a 100644 --- a/inc/templates_upgrade.php +++ b/inc/templates_upgrade.php @@ -1,6 +1,9 @@ @@ -27,8 +30,8 @@ return true; } - require_once ("./inc/settings.php"); require_once ("./inc/db/mysql.php"); + require_once ("./inc/install_utils.php"); require_once ("./inc/utils.php"); $error = false; @@ -44,14 +47,14 @@ } if ($error) { die(sprintf('

%s

', trans('SYP is not correctly installed. Please follow README.txt instructions - and go to wizard.'))); + and go to wizard.'))); } safe_create_writable_dir (getthumbsdir ()); if (create_all_thumbs ($connection)) { par_success (trans('Thumbnails successfully created.')); } else { - par_error (trans('Error when creating thumbnails.')); + par_error_and_leave (trans('Error when creating thumbnails.')); } par_success (trans ('SYP upgrade went smoothly. You can now go to admin area')); diff --git a/inc/templates_wizard.php b/inc/templates_wizard.php deleted file mode 100644 index b678025..0000000 --- a/inc/templates_wizard.php +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - <?php ptrans ('SYP wizard')?> - - - - -connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); - } catch (Exception $e) { - switch ($e->getMessage ()) { - case anydbConnection::err_driver_unavailable: - par_error ($connection->getdbname() . ': ' . trans ('not supported')); - case anydbConnection::err_connection: - par_error (trans ('Could not connect to database.')); - case anydbConnection::err_unknown_database: - par_error (trans ('Database does not exist.')); - default: - par_error (trans ('Unknown error when connecting to database.')); - } - } - try { - $users_table_exists = $connection->users_table_exists (); - } catch(Exception $e) { - par_error (trans ('Unknown error when checking user table.')); - } - - if ($users_table_exists) { - par_success (trans ('Found user table.')); - } else { - if (isset($_POST ["password"])) { - try { - $connection->create_users_table (true); - } catch (Exception $e) { - par_error (trans ('Error when creating user table.')); - } - par_success (trans ('User table created.')); - try { - $connection->setpwd ("admin", $_POST ["password"]); - } catch (Exception $e) { - par_error (trans ('Error when initializing password.')); - } - par_success (trans ('Admin password initialized.')); - - } else { - print ('
- - - -
'); - leave (); - } - - } - - try { - $items_table_exists = $connection->items_table_exists (); - } catch (Exception $e) { - par_error (trans ('Unknown error when checking data table.')); - } - if ($items_table_exists) { - par_success (trans ('Found data table.')); - } else { - try { - $connection->create_items_table (true); - } catch (Exception $e) { - par_error (trans ('Error when creating data table.')); - } - par_success (trans ('Data table created.')); - } - - safe_create_writable_dir (UPLOADDIR); - safe_create_writable_dir (getthumbsdir ()); - - if (!function_exists ("gd_info")) { - par_warn (trans ('It looks like GD extension is not installed.')); - } - - par_success (trans ('SYP is installed. You can now go to admin area')); -?> - - - diff --git a/inc/utils.php b/inc/utils.php index b093b0b..a5a1c8b 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -2,7 +2,9 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("inc/settings.php"); +// using include because that file may be sourced even if config file has not +// been created. +@include_once ("inc/settings.php"); function getthumbsdir () { if (THUMBSDIR) { @@ -180,39 +182,4 @@ function create_thumbnail ($filename, $destfile) { return true; } - -function safe_create_dir ($dirname) { - if (is_dir ($dirname)) { - return; - } - if (file_exists ($dirname)) { - par_error ($dirname . ": " . trans ('exist but is not a directory')); - } - if (!mkdir ($dirname)) { - par_error ($dirname . ": " . trans ('could not create directory')); - } else { - par_success ($dirname . ": " . trans ('directory created')); - } -} - -function safe_create_writable_dir ($dirname) { - safe_create_dir ($dirname); - if (!is_writeable ($dirname) || !is_executable ($dirname)) { - par_error ($dirname . ": " . trans ('could not write in directory')); - } -} - -function leave () { - exit ("\n"); -} -function par_success ($message) { - printf ("

%s

", $message); -} -function par_error ($message) { - printf ("

%s

", $message); - leave (); -} -function par_warn ($message) { - printf ("

%s

", $message); -} ?> diff --git a/inc/version.php b/inc/version.php deleted file mode 100644 index e69de29..0000000 diff --git a/install.en.php b/install.en.php new file mode 120000 index 0000000..94a71af --- /dev/null +++ b/install.en.php @@ -0,0 +1 @@ +install.php \ No newline at end of file diff --git a/install.fr.php b/install.fr.php new file mode 120000 index 0000000..94a71af --- /dev/null +++ b/install.fr.php @@ -0,0 +1 @@ +install.php \ No newline at end of file diff --git a/wizard.php b/install.php similarity index 76% rename from wizard.php rename to install.php index eca5098..612c152 100644 --- a/wizard.php +++ b/install.php @@ -3,5 +3,5 @@ license. */ require ('inc/langutils.php'); - require ('inc/templates_wizard.php'); + require ('inc/templates_install.php'); ?> diff --git a/items.php b/items.php index cd2cd91..a2a0446 100644 --- a/items.php +++ b/items.php @@ -2,10 +2,6 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("./inc/settings.php"); -require_once ("./inc/utils.php"); -require_once ("./inc/db/mysql.php"); - function headers_callback ($output) { $etag = md5 ($output); if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && @@ -29,7 +25,7 @@ function main ($features) { '; if (SITETITLE) { - printf (' %s', SITETITLE); + printf (' %s', htmlspecialchars (SITETITLE)); } foreach ($features as $feature) { $id = $feature->id; @@ -77,6 +73,12 @@ function main ($features) { '; } +if (!@include_once ("./inc/settings.php")) { + exit ("server error"); +} +require_once ("./inc/utils.php"); +require_once ("./inc/db/mysql.php"); + try { $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); $features = $connection->listfeatures ($_GET ['from_user']); diff --git a/logout.php b/logout.php index 02b4b07..25d55a9 100644 --- a/logout.php +++ b/logout.php @@ -2,10 +2,11 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("./inc/settings.php"); +if (!@include_once ("./inc/settings.php")) { + header ('Location: index.php'); +} setcookie (sprintf ("%sauth", DBPREFIX), "", time () - 3600, "" , "",false, true); setcookie (sprintf ("%suser", DBPREFIX), "", time () - 3600, "" , "",false, true); header ('Location: index.php'); - ?> diff --git a/media/install.css b/media/install.css new file mode 100644 index 0000000..46aa7ca --- /dev/null +++ b/media/install.css @@ -0,0 +1,13 @@ +/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD + license. */ + +@import url(common.css); + +label { + display: inline-block; + min-width: 25em; +} +#db_form_submit { + margin-left: 20em; + margin-top: 0.5em; +} diff --git a/news.php b/news.php index 6eb78e6..cc06521 100644 --- a/news.php +++ b/news.php @@ -2,10 +2,6 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("./inc/settings.php"); -require_once ("./inc/db/mysql.php"); -require_once ("./inc/utils.php"); - function headers_callback ($output) { $etag = md5 ($output); if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && @@ -63,7 +59,7 @@ function main ($features) { } if (SITETITLE) { - printf (" %s\n", SITETITLE); + printf (" %s\n", htmlspecialchars (SITETITLE)); } if (WEBMASTERMAIL) { @@ -124,6 +120,12 @@ function main ($features) { printf (""); } +if (!@include_once ("./inc/settings.php")) { + exit ("server error"); +} +require_once ("./inc/db/mysql.php"); +require_once ("./inc/utils.php"); + try { $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); $features = $connection->mostrecentfeatures (10); diff --git a/wizard.en.php b/wizard.en.php deleted file mode 120000 index d9bd4cf..0000000 --- a/wizard.en.php +++ /dev/null @@ -1 +0,0 @@ -wizard.php \ No newline at end of file diff --git a/wizard.fr.php b/wizard.fr.php deleted file mode 120000 index d9bd4cf..0000000 --- a/wizard.fr.php +++ /dev/null @@ -1 +0,0 @@ -wizard.php \ No newline at end of file