From a95b8e8626615eb84bd4760a0640d13dc1e67bab Mon Sep 17 00:00:00 2001 From: arno Date: Sat, 25 Jul 2009 12:49:51 +0200 Subject: [PATCH] password is defined by user in wizard + localize wizard --- build.sh | 2 +- inc/db/anydb.php | 12 ++-- inc/db/mysql.php | 6 +- inc/i10n/en/syp.php | 69 +++++++++++++++++++++- inc/i10n/fr/syp.php | 118 +++++++++++++++++++++++++++++++++++-- inc/i10n/updatelang.php | 2 +- inc/settings.php | 6 -- inc/templates_admin.php | 4 +- inc/templates_wizard.php | 124 +++++++++++++++++++++++++++++++++++++++ wizard.en.php | 1 + wizard.fr.php | 1 + wizard.php | 105 +-------------------------------- 12 files changed, 321 insertions(+), 129 deletions(-) create mode 100644 inc/templates_wizard.php create mode 120000 wizard.en.php create mode 120000 wizard.fr.php diff --git a/build.sh b/build.sh index b51f8fb..1d91b80 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 api.php items.php logout.php wizard.php $DESTDIR/ +cp -p admin.*php index.*php wizard.*php api.php items.php logout.php $DESTDIR/ # media cp -RLp media/ $DESTDIR/ diff --git a/inc/db/anydb.php b/inc/db/anydb.php index c88367a..47d9a06 100644 --- a/inc/db/anydb.php +++ b/inc/db/anydb.php @@ -69,10 +69,10 @@ interface anydbConnection { public function users_table_exists(); /* - * create users table; if $error_if_exists is true; throws an err_query - * error in case users table already exists. + * create users table; + * throws an err_query error in case users table already exists. */ - public function create_users_table($error_if_exists); + public function create_users_table(); /* * return true if items table already exists @@ -80,10 +80,10 @@ interface anydbConnection { public function items_table_exists(); /* - * create items table; if $error_if_exists is true; throws an err_query - * error in case items table already exists. + * create items table; + * throws an err_query error in case items table already exists. */ - public function create_items_table($error_if_exists); + public function create_items_table(); /* * set password $pwd for user $usrname. If $usrname does not exist, create diff --git a/inc/db/mysql.php b/inc/db/mysql.php index e4c61d2..8fa49d5 100644 --- a/inc/db/mysql.php +++ b/inc/db/mysql.php @@ -28,9 +28,8 @@ class mysqlConnection implements anydbConnection { public function users_table_exists () { return $this->_tblexists ("users"); } - public function create_users_table ($error_if_exists) { + public function create_users_table () { $query = sprintf ("CREATE TABLE " . - ($error_if_exists ? " " : "IF NOT EXISTS ") . "%susers ( name VARCHAR(255) NOT NULL, pwd CHAR(32), PRIMARY KEY (name));", $this->dbprefix); @@ -40,9 +39,8 @@ class mysqlConnection implements anydbConnection { public function items_table_exists () { return $this->_tblexists ("items"); } - public function create_items_table ($error_if_exists) { + public function create_items_table () { $query = sprintf ("CREATE TABLE " . - ($error_if_exists ? " " : "IF NOT EXISTS ") . "%sitems ( id MEDIUMINT NOT NULL AUTO_INCREMENT, location POINT, diff --git a/inc/i10n/en/syp.php b/inc/i10n/en/syp.php index 843a97c..ffaf07a 100644 --- a/inc/i10n/en/syp.php +++ b/inc/i10n/en/syp.php @@ -11,6 +11,71 @@ "_language_name" => "english", /* starts translation */ + "SYP wizard" + => "", + + "You need at least PHP version 5" + => "", + + "not supported" + => "", + + "Could not connect to database." + => "", + + "Database does not exist." + => "", + + "Unknown error when connecting to database." + => "", + + "Unknown error when checking user table." + => "", + + "Found user table." + => "", + + "Error when creating user table." + => "", + + "User table created." + => "", + + "Error when initializing password." + => "", + + "Admin password initialized." + => "", + + "choose admin password" + => "", + + "Unknown error when checking data table." + => "", + + "Found data table." + => "", + + "Error when creating data table." + => "", + + "Data table created." + => "", + + "exist but is not a directory" + => "", + + "could not create directory" + => "", + + "directory created" + => "", + + "could not write in directory" + => "", + + "SYP is installed. You can now go to admin area" + => "", "SYP needs javascript. Please activate scripts in your browser." => "", @@ -24,8 +89,8 @@ "SYP admin" => "", - "SYP is not correctly installed. Please read README.txt file and follow\n" . - " installation instructions." + "SYP is not correctly installed. Please follow README.txt instructions\n" . + " and go to wizard." => "", "add a place" diff --git a/inc/i10n/fr/syp.php b/inc/i10n/fr/syp.php index acc6b69..1b7031a 100644 --- a/inc/i10n/fr/syp.php +++ b/inc/i10n/fr/syp.php @@ -13,6 +13,116 @@ /* starts translation */ + "SYP wizard" + => + "Assistant d'installation de SYP" + , + + "You need at least PHP version 5" + => + "Vous devez utiliser une version de PHP au moins égale à la version 5" + , + + "not supported" + => + "support non détecté" + , + + "Could not connect to database." + => + "Impossible de se connecter à la base de donnée." + , + + "Database does not exist." + => + "La base de donnée n'existe pas." + , + + "Unknown error when connecting to database." + => + "Erreur inconnue lors de la connexion à la base." + , + + "Unknown error when checking user table." + => + "Erreur inconnue lors de la vérification de la table utilisateur." + , + + "Found user table." + => + "Table utilisateur trouvée." + , + + "Error when creating user table." + => + "Erreur lors de la création de la table utilisateur." + , + + "User table created." + => + "Table utilisateur créée." + , + + "Error when initializing password." + => + "Erreur lors de l'initialisation du mot de passe." + , + + "Admin password initialized." + => + "Mot de passe administrateur initialisé." + , + + "choose admin password" + => + "choisir un mot de passe administrateur" + , + + "Unknown error when checking data table." + => + "Erreur inconnue lors de la vérification de la table des données." + , + + "Found data table." + => + "Table des données trouvée." + , + + "Error when creating data table." + => + "Erreur lors de la création de la table des données." + , + + "Data table created." + => + "Table des données créée." + , + + "exist but is not a directory" + => + "existe mais n'est pas un répertoire" + , + + "could not create directory" + => + "Impossible de créer le répertoire" + , + + "directory created" + => + "Répertoire créé" + , + + "could not write in directory" + => + "Impossible d'écrire dans le répertoire" + , + + "SYP is installed. You can now go to admin area" + => + "SYP est installé. Vous pouvez maintenant vous rendre dans la partie administration." + , + "SYP needs javascript. Please activate scripts in your browser." => "SYP a besoin de javascript pour fonctionner. Veuillez activer les scripts dans votre navigateur." @@ -33,12 +143,12 @@ "administration de SYP" , - "SYP is not correctly installed. Please read README.txt file and follow\n" . - " installation instructions." + "SYP is not correctly installed. Please follow README.txt instructions\n" . + " and go to wizard." => "SYP n'est pas correctement installé. Veuillez\n" . - " consulter le fichier README.txt et suivez les instructions\n" . - " d'installation." + " suivre les instructions du fichier README.txt et vous rendre\n" . + " sur la page du wizard." , "add a place" diff --git a/inc/i10n/updatelang.php b/inc/i10n/updatelang.php index 3133e84..04b12ec 100755 --- a/inc/i10n/updatelang.php +++ b/inc/i10n/updatelang.php @@ -7,7 +7,7 @@ if (!(isset ($argc)) || !(isset ($argv))) { } $ROOTDIR="../../"; -$SCRIPTS=array("admin"); // scripts in rootdir we need to link to +$SCRIPTS=array("admin", "index", "wizard"); // scripts in rootdir we need to link to function usage() { global $argv; diff --git a/inc/settings.php b/inc/settings.php index 8ec2d4b..68bc142 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -17,12 +17,6 @@ define ("DBNAME", "syp"); // tables prefix. This prefix will also be used as a prefix for cookie names. define ("DBPREFIX", "syp_"); -// admin password. It will be read from here during site installation. -// Then, it will be stored in database. So, if you need to change password -// once it's set, changing it here will not work; you'll need to change it -// in the database. -define ("ADMINPWD", ""); - // directory where images will be uploaded and stored. That directory needs // to be writeable by SYP. define ("UPLOADDIR", "upload"); diff --git a/inc/templates_admin.php b/inc/templates_admin.php index eda657d..ce7e3b4 100644 --- a/inc/templates_admin.php +++ b/inc/templates_admin.php @@ -28,8 +28,8 @@ if (!$usrtblexists || !$itemstblexists) { -

+

wizard.')?>

+ + + + + + <?php ptrans ('SYP wizard')?> + + + + +"); + } + function wiz_success ($message) { + printf ("

%s

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

%s

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

%s

", $message); + } + + if (version_compare (PHP_VERSION, '5.0.0', '<')) { + wiz_error (trans ("You need at least PHP version 5")); + } + + require_once ("./inc/settings.php"); + require_once ("./inc/db/mysql.php"); + + try { + $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); + } catch (Exception $e) { + switch ($e->getMessage ()) { + case anydbConnection::err_driver_unavailable: + wiz_error ($connection->getdbname() . ': ' . trans ('not supported')); + case anydbConnection::err_connection: + wiz_error (trans ('Could not connect to database.')); + case anydbConnection::err_unknown_database: + wiz_error (trans ('Database does not exist.')); + default: + wiz_error (trans ('Unknown error when connecting to database.')); + } + } + try { + $users_table_exists = $connection->users_table_exists (); + } catch(Exception $e) { + wiz_error (trans ('Unknown error when checking user table.')); + } + + if ($users_table_exists) { + wiz_success (trans ('Found user table.')); + } else { + if (isset($_POST ["password"])) { + try { + $connection->create_users_table (true); + } catch (Exception $e) { + wiz_error (trans ('Error when creating user table.')); + } + wiz_success (trans ('User table created.')); + try { + $connection->setpwd ("admin", $_POST ["password"]); + } catch (Exception $e) { + wiz_error (trans ('Error when initializing password.')); + } + wiz_success (trans ('Admin password initialized.')); + + } else { + print ('
+ + + +
'); + leave (); + } + + } + + try { + $items_table_exists = $connection->items_table_exists (); + } catch (Exception $e) { + wiz_error (trans ('Unknown error when checking data table.')); + } + if ($items_table_exists) { + wiz_success (trans ('Found data table.')); + } else { + try { + $connection->create_items_table (true); + } catch (Exception $e) { + wiz_error (trans ('Error when creating data table.')); + } + wiz_success (trans ('Data table created.')); + } + if (!is_dir (UPLOADDIR)) { + if (file_exists (UPLOADDIR)) { + wiz_error (UPLOADDIR . ": " . trans ('exist but is not a directory')); + } + if (!mkdir (UPLOADDIR)) { + wiz_error (UPLOADDIR . ": " . trans ('could not create directory')); + } else { + wiz_success (UPLOADDIR . ": " . trans ('directory created')); + } + } + if (!is_writeable (UPLOADDIR) || !is_executable (UPLOADDIR)) { + wiz_error (UPLOADDIR . ": " . trans ('could not write in directory')); + } + wiz_success (trans ('SYP is installed. You can now go to admin area')); +?> + + + diff --git a/wizard.en.php b/wizard.en.php new file mode 120000 index 0000000..d9bd4cf --- /dev/null +++ b/wizard.en.php @@ -0,0 +1 @@ +wizard.php \ No newline at end of file diff --git a/wizard.fr.php b/wizard.fr.php new file mode 120000 index 0000000..d9bd4cf --- /dev/null +++ b/wizard.fr.php @@ -0,0 +1 @@ +wizard.php \ No newline at end of file diff --git a/wizard.php b/wizard.php index 9710d8f..eca5098 100644 --- a/wizard.php +++ b/wizard.php @@ -1,108 +1,7 @@ - - - - - - SYP wizard - - - -%s

", $message); - } - function wiz_error ($message) { - exit (sprintf ("

%s

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

%s

", $message); - } - - if (version_compare (PHP_VERSION, '5.0.0', '<')) { - wiz_error ("Vous devez utiliser une version de PHP au moins égale à la version 5"); - } - - if (!function_exists ("exif_read_data")) { - wiz_warn ("Cette version de php ne supporte pas la lecture des données exif"); - } - require_once ("./inc/settings.php"); - require_once ("./inc/db/mysql.php"); - - try { - $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX); - } catch (Exception $e) { - switch ($e->getMessage ()) { - case anydbConnection::err_driver_unavailable: - wiz_error ('Support de ' . $connection->getdbname () . ' non détecté.'); - case anydbConnection::err_connection: - wiz_error ('Impossible de se connecter à la base de donnée.'); - case anydbConnection::err_unknown_database: - wiz_error ('La base de donnée n\'existe pas.'); - default: - wiz_error ('Erreur inconnue lors de la connexion à la base.'); - } - } - try { - $users_table_exists = $connection->users_table_exists (); - } catch(Exception $e) { - wiz_error ('Erreur inconnue lors de la vérification de la table utilisateur.'); - } - - if ($users_table_exists) { - wiz_success ('Table utilisateur trouvée.'); - } else { - try { - $connection->create_users_table (true); - } catch (Exception $e) { - wiz_error ('Erreur lors de la création de la table utilisateur.'); - } - wiz_success ('Table utilisateur crée.'); - try { - $connection->setpwd ("admin", ADMINPWD); - } catch (Exception $e) { - wiz_error ('Erreur lors de l\'initialisation du mot de passe.'); - } - wiz_success ('Mot de passe administrateur initialisé.'); - } - - try { - $items_table_exists = $connection->items_table_exists (); - } catch (Exception $e) { - wiz_error ('Erreur inconnue lors de la vérification de la table des données.'); - } - if ($items_table_exists) { - wiz_success ('Table utilisateur trouvée.'); - } else { - try { - $connection->create_items_table (true); - } catch (Exception $e) { - wiz_error ('Erreur lors de la création de la table des données.'); - } - wiz_success ('Table des données crée.'); - } - if (!is_dir (UPLOADDIR)) { - if (file_exists (UPLOADDIR)) { - wiz_error (sprintf ("%s existe et n'est pas un répertoire.", - UPLOADDIR)); - } - if (!mkdir (UPLOADDIR)) { - wiz_error (sprintf ("Impossible de créer le répertoire %s.", - UPLOADDIR)); - } else { - wiz_success (sprintf ('Répertoire %s crée.', UPLOADDIR)); - } - } - if (!is_writeable (UPLOADDIR) || !is_executable (UPLOADDIR)) { - wiz_error (sprintf ("Impossible d'écrire dans %s.", UPLOADDIR)); - } - wiz_success ('SYP est installé. Vous pouvez maintenant vous rendre dans la partie administration.'); + require ('inc/langutils.php'); + require ('inc/templates_wizard.php'); ?> - - - -- 2.39.2