mirror of https://github.com/nextcloud/server.git
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.remotes/origin/stable
parent
a8fb310d79
commit
13ddf8100f
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -1,45 +1,14 @@
|
||||
$(document).ready(function() {
|
||||
//hide the advanced config
|
||||
$('#advanced_options').hide();
|
||||
$('#use_mysql').hide();
|
||||
$('label.sqlite').css('background-color', '#ddd');
|
||||
$('label.mysql').css('background-color', '#fff');
|
||||
|
||||
// Sets advanced_options link behaviour :
|
||||
$('#advanced_options_link').click(function() {
|
||||
$('#advanced').toggleClass('userLinkOn');
|
||||
$('#advanced_options').slideToggle(250);
|
||||
return false;
|
||||
// Hide the MySQL config div if needed :
|
||||
if(!$('#mysql').is(':checked')) {
|
||||
$('#use_mysql').hide();
|
||||
}
|
||||
|
||||
$('#sqlite').click(function() {
|
||||
$('#use_mysql').slideUp(250);
|
||||
});
|
||||
|
||||
$('#mysql').click(function() {
|
||||
$('#use_mysql').slideDown(250);
|
||||
$('label.sqlite').css('background-color', '#fff');
|
||||
$('label.mysql').css('background-color', '#ddd');
|
||||
});
|
||||
$('#sqlite').click(function() {
|
||||
$('#use_mysql').slideUp(250);
|
||||
$('label.sqlite').css('background-color', '#ddd');
|
||||
$('label.mysql').css('background-color', '#fff');
|
||||
});
|
||||
|
||||
// Hide and show input field values for login and installation form
|
||||
var textuser = 'username';
|
||||
var textpassword = 'password';
|
||||
var textadmin = 'admin username';
|
||||
var textdbuser = 'MySQL user';
|
||||
var textdbpass = 'password';
|
||||
var textdbname = 'database name';
|
||||
$('#user').focus(function() { if($(this).attr('value') == textuser) $(this).attr('value', ''); });
|
||||
$('#user').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textuser); });
|
||||
$('#password').focus(function() { if($(this).attr('value') == textpassword) $(this).attr('value', ''); });
|
||||
$('#password').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textpassword); });
|
||||
$('#admin').focus(function() { if($(this).attr('value') == textadmin) $(this).attr('value', ''); });
|
||||
$('#admin').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textadmin); });
|
||||
$('#dbuser').focus(function() { if($(this).attr('value') == textdbuser) $(this).attr('value', ''); });
|
||||
$('#dbuser').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textdbuser); });
|
||||
$('#dbpass').focus(function() { if($(this).attr('value') == textdbpass) $(this).attr('value', ''); });
|
||||
$('#dbpass').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textdbpass); });
|
||||
$('#dbname').focus(function() { if($(this).attr('value') == textdbname) $(this).attr('value', ''); });
|
||||
$('#dbname').blur(function() { if($(this).attr('value') == '') $(this).attr('value', textdbname); });
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,50 +1,59 @@
|
||||
<div id="login">
|
||||
<img src="<?php echo image_path('', 'owncloud-logo-medium-white.png'); ?>" alt="ownCloud" />
|
||||
<form action="#" method="post">
|
||||
<input type='hidden' name='install' value='true'/>
|
||||
<form action="index.php" method="post" id="setup_form">
|
||||
<input type="hidden" name="install" value="true" />
|
||||
<p class="intro">
|
||||
Welcome to <strong>ownCloud</strong>, your personnal cloud.<br />
|
||||
To finish the installation, please follow the 3 remaining steps below.
|
||||
</p>
|
||||
|
||||
<?php if(count($_['errors']) > 0): ?>
|
||||
<ul class="errors">
|
||||
<?php foreach($_['errors'] as $err): ?>
|
||||
<li><?php print $err; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
<fieldset>
|
||||
<input type="text" name="login" id="admin" value="admin username" />
|
||||
<input type="password" name="pass" id="password" value="password" />
|
||||
<legend><strong>STEP 1</strong> : Create an <strong>admin account.</strong></legend>
|
||||
<p><label for="adminlogin">Login :</label><input type="text" name="adminlogin" id="adminlogin" value="<?php print OC_HELPER::init_var('adminlogin'); ?>" /></p>
|
||||
<p><label for="adminpass">Password :</label><input type="password" name="adminpass" id="adminpass" value="<?php print OC_HELPER::init_var('adminpass'); ?>" /></p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><strong>STEP 2</strong> : Set where to store the data.</legend>
|
||||
<p><label for="directory">Data directory :</label><input type="text" name="directory" id="directory" value="<?php print OC_HELPER::init_var('directory', $_['directory']); ?>" /></p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><strong>STEP 3</strong> : Configure your database.</legend>
|
||||
<?php if($_['hasSQLite']): ?>
|
||||
<?php if(!$_['hasMySQL']): ?>
|
||||
<p>I will use a SQLite database. You have nothing to do !</p>
|
||||
<input type="hidden" id="dbtype" name="dbtype" value="sqlite" />
|
||||
<?php else: ?>
|
||||
<p><label class="sqlite" for="sqlite">SQLite </label><input type="radio" name="dbtype" value='sqlite' id="sqlite" <?php OC_HELPER::init_radio('dbtype', 'sqlite', 'sqlite'); ?>/></p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($_['hasMySQL']): ?>
|
||||
<?php if(!$_['hasSQLite']): ?>
|
||||
<legend><abbr title="to use SQLite instead, install it on your server">MySQL</abbr> Database</legend>
|
||||
<input type="text" name="dbuser" id="dbuser" value="MySQL user" />
|
||||
<input type="password" name="dbpass" id="dbpass" value="password" />
|
||||
<input type="text" name="dbname" id="dbname" value="database name" />
|
||||
<?php endif;?>
|
||||
</fieldset>
|
||||
<fieldset id="advanced">
|
||||
<legend><a id="advanced_options_link" href="">Advanced ▾</a></legend>
|
||||
<div id="advanced_options">
|
||||
<label>Data directory</label><input type="text" name="directory" value="<?php echo($_['datadir']);?>" />
|
||||
<?php if($_['hasMySQL'] and $_['hasSQLite']): ?>
|
||||
<input type="radio" name="dbtype" value='sqlite' id="sqlite" checked="checked" /><label class="sqlite" for="sqlite">SQLite</label>
|
||||
<input type="radio" name="dbtype" value='mysql' id="mysql"><label class="mysql" for="mysql">MySQL</label>
|
||||
<div id="use_mysql">
|
||||
<input type="text" name="dbuser" id="dbuser" value="MySQL user" />
|
||||
<input type="password" name="dbpass" id="dbpass" value="password" />
|
||||
<input type="text" name="dbname" id="dbname" value="database name" />
|
||||
<?php endif;?>
|
||||
<?php if($_['hasMySQL'] and !$_['hasSQLite']): ?>
|
||||
<input type="hidden" name="dbtype" value="mysql" />
|
||||
<?php endif;?>
|
||||
<?php if(!$_['hasMySQL'] and $_['hasSQLite']): ?>
|
||||
<input type="hidden" name="dbtype" value="sqlite" />
|
||||
<?php endif;?>
|
||||
<?php if($_['hasMySQL'] and $_['hasSQLite']): ?>
|
||||
<label>Database host</label><input type="text" name="dbhost" id="dbhost" value="localhost" />
|
||||
<label>Table prefix</label><input type="text" name="dbtableprefix" id="dbtableprefix" value="oc_" />
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<?php if($_['hasMySQL'] and !$_['hasSQLite']): ?>
|
||||
<label>Database host</label><input type="text" name="dbhost" id="dbhost" value="localhost" />
|
||||
<label>Table prefix</label><input type="text" name="dbtableprefix" id="dbtableprefix" value="oc_" />
|
||||
<?php endif;?>
|
||||
<p>I will use a MySQL database.</p>
|
||||
<input type="hidden" id="dbtype" name="dbtype" value="mysql" />
|
||||
<?php else: ?>
|
||||
<p><label class="mysql" for="mysql">MySQL </label><input type="radio" name="dbtype" value='mysql' id="mysql" <?php OC_HELPER::init_radio('dbtype', 'mysql', 'sqlite'); ?>/></p>
|
||||
<?php endif; ?>
|
||||
<div id="use_mysql">
|
||||
<p><label for="dbhost">Host :</label><input type="text" name="dbhost" id="dbhost" value="<?php print OC_HELPER::init_var('dbhost', 'localhost'); ?>" /></p>
|
||||
<p><label for="dbname">Database name :</label><input type="text" name="dbname" id="dbname" value="<?php print OC_HELPER::init_var('dbname'); ?>" /></p>
|
||||
<p><label for="dbtableprefix">Table prefix :</label><input type="text" name="dbtableprefix" id="dbtableprefix" value="<?php print OC_HELPER::init_var('dbtableprefix', 'oc_'); ?>" /></p>
|
||||
<p><label for="dbuser">MySQL user login :</label><input type="text" name="dbuser" id="dbuser" value="<?php print OC_HELPER::init_var('dbuser'); ?>" /></p>
|
||||
<p><label for="dbpass">MySQL user password :</label><input type="password" name="dbpass" id="dbpass" value="<?php print OC_HELPER::init_var('dbpass'); ?>" /></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<p class="submit"><input type="submit" value="Create" /></p>
|
||||
</fieldset>
|
||||
|
||||
<p class="submit"><input type="submit" value="Finish setup" /></p>
|
||||
</form>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue