summaryrefslogtreecommitdiffstats
path: root/lib/setup.php
diff options
context:
space:
mode:
authorFrançois Kubler <francois@kubler.org>2011-05-17 22:34:31 +0200
committerFrançois Kubler <francois@kubler.org>2011-05-17 22:34:31 +0200
commit13ddf8100f7b4aace962598a75aadbf228c4aaa7 (patch)
treee5d3e868bb4efaf0025b405b1d593a8abb92959e /lib/setup.php
parenta8fb310d79d604ec0e4235dcd40828c3feb3a3be (diff)
downloadnextcloud-server-13ddf8100f7b4aace962598a75aadbf228c4aaa7.tar.gz
nextcloud-server-13ddf8100f7b4aace962598a75aadbf228c4aaa7.zip
New installer.
* Forms have been revamped (CSS + javascript), * Process has been improved : errors are displayed on the form page, * Some changes in the index.php page so that everything related to installation is in lib/setup.php * Also added a small function in OC_HELPER class to set input values. All these should improve the installation process in terms of ergonomics. Well, I do hope so.
Diffstat (limited to 'lib/setup.php')
-rw-r--r--lib/setup.php204
1 files changed, 117 insertions, 87 deletions
diff --git a/lib/setup.php b/lib/setup.php
index 9b416c8c95e..d80408de988 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -1,145 +1,175 @@
<?php
-if(isset($_POST['install']) and $_POST['install']=='true'){
- $errors=OC_SETUP::install($_POST);
- if(count($errors)>0){
- OC_TEMPLATE::printGuestPage( "", "error", array( "errors" => $errors ));
- }else{
- header( "Location: $WEBROOT");
+$hasSQLite = is_callable('sqlite_open');
+$hasMySQL = is_callable('mysql_connect');
+$datadir = OC_CONFIG::getValue('datadir', $SERVERROOT.'/data');
+$opts = array(
+ 'hasSQLite' => $hasSQLite,
+ 'hasMySQL' => $hasMySQL,
+ 'directory' => $datadir,
+ 'errors' => array(),
+);
+
+if(isset($_POST['install']) AND $_POST['install']=='true') {
+ // We have to launch the installation process :
+ $e = OC_SETUP::install($_POST);
+ $errors = array('errors' => $e);
+
+ if(count($e) > 0) {
+ //OC_TEMPLATE::printGuestPage("", "error", array("errors" => $errors));
+ $options = array_merge($_POST, $opts, $errors);
+ OC_TEMPLATE::printGuestPage("", "installation", $options);
+ }
+ else {
+ header("Location: $WEBROOT");
exit();
}
}
+else {
+ OC_TEMPLATE::printGuestPage("", "installation", $opts);
+}
-class OC_SETUP{
- public static function install($options){
- $error=array();
- $dbtype=$options['dbtype'];
- if(empty($options['login'])){
- $error[]=array('error'=>'username not set');
- };
- if(empty($options['pass'])){
- $error[]=array('error'=>'password not set');
- };
- if(empty($options['directory'])){
- $error[]=array('error'=>'data directory not set');
- };
- if($dbtype=='mysql'){//mysql needs more config options
- if(empty($options['dbuser'])){
- $error[]=array('error'=>'database user not set');
- };
- if(empty($options['dbpass'])){
- $error[]=array('error'=>'database password not set');
- };
- if(empty($options['dbname'])){
- $error[]=array('error'=>'database name not set');
- };
- if(empty($options['dbhost'])){
- $error[]=array('error'=>'database host not set');
- };
- if(!isset($options['dbtableprefix'])){
- $error[]=array('error'=>'database table prefix not set');
- };
+class OC_SETUP {
+ public static function install($options) {
+ $error = array();
+ $dbtype = $options['dbtype'];
+
+ if(empty($options['adminlogin'])) {
+ $error[] = 'STEP 1 : admin login is not set.';
+ }
+ if(empty($options['adminpass'])) {
+ $error[] = 'STEP 1 : admin password is not set.';
+ }
+ if(empty($options['directory'])) {
+ $error[] = 'STEP 2 : data directory path is not set.';
+ }
+ if($dbtype=='mysql') { //mysql needs more config options
+ if(empty($options['dbuser'])) {
+ $error[] = 'STEP 3 : MySQL database user is not set.';
+ }
+ if(empty($options['dbpass'])) {
+ $error[] = 'STEP 3 : MySQL database password is not set.';
+ }
+ if(empty($options['dbname'])) {
+ $error[] = 'STEP 3 : MySQL database name is not set.';
+ }
+ if(empty($options['dbhost'])) {
+ $error[] = 'STEP 3 : MySQL database host is not set.';
+ }
+ if(!isset($options['dbtableprefix'])) {
+ $error[] = 'STEP 3 : MySQL database table prefix is not set.';
+ }
}
- if(count($error)==0){ //no errors, good
- $username=$options['login'];
- $password=$options['pass'];
- $datadir=$options['directory'];
+
+ if(count($error) == 0) { //no errors, good
+ $username = htmlspecialchars_decode($options['adminlogin']);
+ $password = htmlspecialchars_decode($options['adminpass']);
+ $datadir = htmlspecialchars_decode($options['directory']);
//write the config file
- OC_CONFIG::setValue('datadirectory',$datadir);
- OC_CONFIG::setValue('dbtype',$dbtype);
- if($dbtype=='mysql'){
- $dbuser=$options['dbuser'];
- $dbpass=$options['dbpass'];
- $dbname=$options['dbname'];
- $dbhost=$options['dbhost'];
- $dbtableprefix=$options['dbtableprefix'];
- OC_CONFIG::setValue('dbname',$dbname);
- OC_CONFIG::setValue('dbhost',$dbhost);
- OC_CONFIG::setValue('dbtableprefix',$dbtableprefix);
+ OC_CONFIG::setValue('datadirectory', $datadir);
+ OC_CONFIG::setValue('dbtype', $dbtype);
+ if($dbtype == 'mysql') {
+ $dbuser = $options['dbuser'];
+ $dbpass = $options['dbpass'];
+ $dbname = $options['dbname'];
+ $dbhost = $options['dbhost'];
+ $dbtableprefix = $options['dbtableprefix'];
+ OC_CONFIG::setValue('dbname', $dbname);
+ OC_CONFIG::setValue('dbhost', $dbhost);
+ OC_CONFIG::setValue('dbtableprefix', $dbtableprefix);
//check if the database user has admin right
- $connection=@mysql_connect($dbhost, $dbuser, $dbpass);
+ $connection = @mysql_connect($dbhost, $dbuser, $dbpass);
if(!$connection) {
- $error[]=array('error'=>'mysql username and/or password not valid','hint'=>'you need to enter either an existing account, or the administrative account if you wish to create a new user for ownCloud');
- }else{
- $query="SELECT user FROM mysql.user WHERE user='$dbuser'";//this should be enough to check for admin rights in mysql
- if(mysql_query($query,$connection)){
- self::createDBUser($username,$password,$connection);
+ $error[] = array(
+ 'error' => 'mysql username and/or password not valid',
+ 'hint' => 'you need to enter either an existing account, or the administrative account if you wish to create a new user for ownCloud'
+ );
+ }
+ else {
+ $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql
+ if(mysql_query($query, $connection)) {
+ self::createDBUser($username, $password, $connection);
//use the admin login data for the new database user
- OC_CONFIG::setValue('dbuser',$username);
- OC_CONFIG::setValue('dbpassword',$password);
+ OC_CONFIG::setValue('dbuser', $username);
+ OC_CONFIG::setValue('dbpassword', $password);
//create the database
- self::createDatabase($dbname,$username,$connection);
- }else{
- OC_CONFIG::setValue('dbuser',$dbuser);
- OC_CONFIG::setValue('dbpassword',$dbpass);
+ self::createDatabase($dbname, $username, $connection);
+ }
+ else {
+ OC_CONFIG::setValue('dbuser', $dbuser);
+ OC_CONFIG::setValue('dbpassword', $dbpass);
//create the database
- self::createDatabase($dbname,$dbuser,$connection);
+ self::createDatabase($dbname, $dbuser, $connection);
}
+
//fill the database if needed
$query="SELECT * FROM $dbname.{$dbtableprefix}users";
$result = mysql_query($query,$connection);
- if (!$result) {
+ if(!$result) {
OC_DB::createDbFromStructure('db_structure.xml');
}
mysql_close($connection);
}
- }else{
+ }
+ else {
//in case of sqlite, we can always fill the database
OC_DB::createDbFromStructure('db_structure.xml');
}
- if(count($error)==0){
+
+ if(count($error) == 0) {
//create the user and group
- OC_USER::createUser($username,$password);
+ OC_USER::createUser($username, $password);
OC_GROUP::createGroup('admin');
- OC_GROUP::addToGroup($username,'admin');
+ OC_GROUP::addToGroup($username, 'admin');
//create htaccess files for apache hosts
- self::createHtaccess();//TODO detect if apache is used
+ self::createHtaccess(); //TODO detect if apache is used
//and we are done
- OC_CONFIG::setValue('installed',true);
+ OC_CONFIG::setValue('installed', true);
}
}
+
return $error;
}
- public static function createDatabase($name,$user,$connection){
+ public static function createDatabase($name,$user,$connection) {
//we cant user OC_BD functions here because we need to connect as the administrative user.
- $query="CREATE DATABASE IF NOT EXISTS `$name`";
- $result = mysql_query($query,$connection);
- if (!$result) {
+ $query = "CREATE DATABASE IF NOT EXISTS `$name`";
+ $result = mysql_query($query, $connection);
+ if(!$result) {
$entry='DB Error: "'.mysql_error($connection).'"<br />';
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
- $result = mysql_query($query,$connection);//this query will fail if there aren't the right permissons, ignore the error
+ $result = mysql_query($query, $connection); //this query will fail if there aren't the right permissons, ignore the error
}
- private static function createDBUser($name,$password,$connection){
- //we need to create 2 accounts, one for global use and one for local user. if we don't speccify the local one,
- // the anonymous user would take precedence when there is one.
- $query="CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
- $result = mysql_query($query,$connection);
- $query="CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
- $result = mysql_query($query,$connection);
+ private static function createDBUser($name,$password,$connection) {
+ // we need to create 2 accounts, one for global use and one for local user. if we don't speccify the local one,
+ // the anonymous user would take precedence when there is one.
+ $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
+ $result = mysql_query($query, $connection);
+ $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
+ $result = mysql_query($query, $connection);
}
/**
* create .htaccess files for apache hosts
*/
- private static function createHtaccess(){
+ private static function createHtaccess() {
global $SERVERROOT;
global $WEBROOT;
- $content="ErrorDocument 404 /$WEBROOT/templates/404.php\n";
- @file_put_contents($SERVERROOT.'/.htaccess',$content); //supress errors in case we don't have permissions for it
+ $content = "ErrorDocument 404 /$WEBROOT/templates/404.php\n";
+ @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
- $content="deny from all";
- file_put_contents(OC_CONFIG::getValue('datadirectory',$SERVERROOT.'/data').'/.htaccess',$content);
+ $content = "deny from all";
+ file_put_contents(OC_CONFIG::getValue('datadirectory', $SERVERROOT.'/data').'/.htaccess', $content);
}
}