Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Mueller <thomas.mueller@tmit.eu>2013-02-12 03:32:38 +0400
committerThomas Mueller <thomas.mueller@tmit.eu>2013-02-12 03:32:38 +0400
commit76b31f870cf78aa8882761d954554fecb92e6211 (patch)
tree9c89430fe00983e94cc8864a12cd05242741d4c3 /lib/setup.php
parent0c31c3cc3a928e8ca9272d32d68163c0700697ea (diff)
parentfb23ac3ce2e0b3f002f036e55e516b672f088dc0 (diff)
Merge branch 'master' into master-sqlserver
Diffstat (limited to 'lib/setup.php')
-rw-r--r--lib/setup.php142
1 files changed, 91 insertions, 51 deletions
diff --git a/lib/setup.php b/lib/setup.php
index 3efad79cfad..893e0121ffa 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -19,18 +19,25 @@ class DatabaseSetupException extends Exception
}
class OC_Setup {
+
+ public static function getTrans(){
+ return OC_L10N::get('lib');
+ }
+
public static function install($options) {
+ $l = self::getTrans();
+
$error = array();
$dbtype = $options['dbtype'];
if(empty($options['adminlogin'])) {
- $error[] = 'Set an admin username.';
+ $error[] = $l->t('Set an admin username.');
}
if(empty($options['adminpass'])) {
- $error[] = 'Set an admin password.';
+ $error[] = $l->t('Set an admin password.');
}
if(empty($options['directory'])) {
- $error[] = 'Specify a data folder.';
+ $error[] = $l->t('Specify a data folder.');
}
if($dbtype == 'mysql' or $dbtype == 'pgsql' or $dbtype == 'oci' or $dbtype == 'mssql') { //mysql and postgresql needs more config options
@@ -45,16 +52,16 @@ class OC_Setup {
if(empty($options['dbuser'])) {
- $error[] = "$dbprettyname enter the database username.";
+ $error[] = $l->t("%s enter the database username.", array($dbprettyname));
}
if(empty($options['dbname'])) {
- $error[] = "$dbprettyname enter the database name.";
+ $error[] = $l->t("%s enter the database name.", array($dbprettyname));
}
if(substr_count($options['dbname'], '.') >= 1) {
- $error[] = "$dbprettyname you may not use dots in the database name";
+ $error[] = $l->t("%s you may not use dots in the database name", array($dbprettyname));
}
if($dbtype != 'oci' && empty($options['dbhost'])) {
- $error[] = "$dbprettyname set the database host.";
+ $error[] = $l->t("%s set the database host.", array($dbprettyname));
}
}
@@ -118,8 +125,8 @@ class OC_Setup {
self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
} catch (Exception $e) {
$error[] = array(
- 'error' => 'PostgreSQL username and/or password not valid',
- 'hint' => 'You need to enter either an existing account or the administrator.'
+ 'error' => $l->t('PostgreSQL username and/or password not valid'),
+ 'hint' => $l->t('You need to enter either an existing account or the administrator.')
);
return $error;
}
@@ -141,8 +148,8 @@ class OC_Setup {
self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
} catch (Exception $e) {
$error[] = array(
- 'error' => 'Oracle username and/or password not valid',
- 'hint' => 'You need to enter either an existing account or the administrator.'
+ 'error' => $l->t('Oracle username and/or password not valid'),
+ 'hint' => $l->t('You need to enter either an existing account or the administrator.')
);
return $error;
}
@@ -215,9 +222,11 @@ class OC_Setup {
private static function setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) {
//check if the database user has admin right
+ $l = self::getTrans();
$connection = @mysql_connect($dbhost, $dbuser, $dbpass);
if(!$connection) {
- throw new DatabaseSetupException('MySQL username and/or password not valid','You need to enter either an existing account or the administrator.');
+ throw new DatabaseSetupException($l->t('MySQL username and/or password not valid'),
+ $l->t('You need to enter either an existing account or the administrator.'));
}
$oldUser=OC_Config::getValue('dbuser', false);
@@ -264,11 +273,12 @@ class OC_Setup {
private static function createMySQLDatabase($name, $user, $connection) {
//we cant use OC_BD functions here because we need to connect as the administrative user.
+ $l = self::getTrans();
$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 />';
+ $entry = $l->t('DB Error: "%s"', array(mysql_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
@@ -278,15 +288,18 @@ class OC_Setup {
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 specify the local one,
// the anonymous user would take precedence when there is one.
+ $l = self::getTrans();
$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
- throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'localhost' already exists","Delete this user from MySQL.");
+ throw new DatabaseSetupException($l->t("MySQL user '%s'@'localhost' exists already.",
+ array($name)), $l->t("Drop this user from MySQL", array($name)));
}
$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
- throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'%' already exists","Delete this user from MySQL.");
+ throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)),
+ $l->t("Drop this user from MySQL."));
}
}
@@ -294,12 +307,13 @@ class OC_Setup {
$e_host = addslashes($dbhost);
$e_user = addslashes($dbuser);
$e_password = addslashes($dbpass);
+ $l = self::getTrans();
//check if the database user has admin rights
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
$connection = @pg_connect($connection_string);
if(!$connection) {
- throw new Exception('PostgreSQL username and/or password not valid');
+ throw new Exception($l->t('PostgreSQL username and/or password not valid'));
}
$e_user = pg_escape_string($dbuser);
//check for roles creation rights in postgresql
@@ -344,7 +358,7 @@ class OC_Setup {
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
$connection = @pg_connect($connection_string);
if(!$connection) {
- throw new Exception('PostgreSQL username and/or password not valid');
+ throw new Exception($l->t('PostgreSQL username and/or password not valid'));
}
$query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
$result = pg_query($connection, $query);
@@ -357,14 +371,16 @@ class OC_Setup {
}
private static function pg_createDatabase($name, $user, $connection) {
+
//we cant use OC_BD functions here because we need to connect as the administrative user.
+ $l = self::getTrans();
$e_name = pg_escape_string($name);
$e_user = pg_escape_string($user);
$query = "select datname from pg_database where datname = '$e_name'";
$result = pg_query($connection, $query);
if(!$result) {
- $entry='DB Error: "'.pg_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
if(! pg_fetch_row($result)) {
@@ -372,8 +388,8 @@ class OC_Setup {
$query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\"";
$result = pg_query($connection, $query);
if(!$result) {
- $entry='DB Error: "'.pg_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
else {
@@ -384,13 +400,14 @@ class OC_Setup {
}
private static function pg_createDBUser($name, $password, $connection) {
+ $l = self::getTrans();
$e_name = pg_escape_string($name);
$e_password = pg_escape_string($password);
$query = "select * from pg_roles where rolname='$e_name';";
$result = pg_query($connection, $query);
if(!$result) {
- $entry='DB Error: "'.pg_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
@@ -399,8 +416,8 @@ class OC_Setup {
$query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';";
$result = pg_query($connection, $query);
if(!$result) {
- $entry='DB Error: "'.pg_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
}
@@ -408,14 +425,15 @@ class OC_Setup {
$query = "ALTER ROLE \"$e_name\" WITH PASSWORD '$e_password';";
$result = pg_query($connection, $query);
if(!$result) {
- $entry='DB Error: "'.pg_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
}
}
private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username) {
+ $l = self::getTrans();
$e_host = addslashes($dbhost);
$e_dbname = addslashes($dbname);
//check if the database user has admin right
@@ -427,15 +445,15 @@ class OC_Setup {
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
if(!$connection) {
$e = oci_error();
- throw new Exception('Oracle username and/or password not valid');
+ throw new Exception($l->t('Oracle username and/or password not valid'));
}
//check for roles creation rights in oracle
$query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
$stmt = oci_parse($connection, $query);
if (!$stmt) {
- $entry='DB Error: "'.oci_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
$result = oci_execute($stmt);
@@ -493,15 +511,15 @@ class OC_Setup {
}
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
if(!$connection) {
- throw new Exception('Oracle username and/or password not valid');
+ throw new Exception($l->t('Oracle username and/or password not valid'));
}
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
$stmt = oci_parse($connection, $query);
$un = $dbtableprefix.'users';
oci_bind_by_name($stmt, ':un', $un);
if (!$stmt) {
- $entry='DB Error: "'.oci_last_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
$result = oci_execute($stmt);
@@ -522,19 +540,19 @@ class OC_Setup {
* @param resource $connection
*/
private static function oci_createDBUser($name, $password, $tablespace, $connection) {
-
+ $l = self::getTrans();
$query = "SELECT * FROM all_users WHERE USERNAME = :un";
$stmt = oci_parse($connection, $query);
if (!$stmt) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
oci_bind_by_name($stmt, ':un', $name);
$result = oci_execute($stmt);
if(!$result) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
@@ -544,31 +562,32 @@ class OC_Setup {
$query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace
$stmt = oci_parse($connection, $query);
if (!$stmt) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
//oci_bind_by_name($stmt, ':un', $name);
$result = oci_execute($stmt);
if(!$result) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
+ array($query, $name, $password)) . '<br />';
echo($entry);
}
} else { // change password of the existing role
$query = "ALTER USER :un IDENTIFIED BY :pw";
$stmt = oci_parse($connection, $query);
if (!$stmt) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
oci_bind_by_name($stmt, ':un', $name);
oci_bind_by_name($stmt, ':pw', $password);
$result = oci_execute($stmt);
if(!$result) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
}
@@ -576,14 +595,15 @@ class OC_Setup {
$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
$stmt = oci_parse($connection, $query);
if (!$stmt) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
echo($entry);
}
$result = oci_execute($stmt);
if(!$result) {
- $entry='DB Error: "'.oci_error($connection).'"<br />';
- $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
+ $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
+ $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
+ array($query, $name, $password)) . '<br />';
echo($entry);
}
}
@@ -807,4 +827,24 @@ class OC_Setup {
file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
}
+
+ /**
+ * @brief Post installation checks
+ */
+ public static function postSetupCheck($params) {
+ // setup was successful -> webdav testing now
+ $l = self::getTrans();
+ if (OC_Util::isWebDAVWorking()) {
+ header("Location: ".OC::$WEBROOT.'/');
+ } else {
+
+ $error = $l->t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.');
+ $hint = $l->t('Please double check the <a href=\'%s\'>installation guides</a>.', 'http://doc.owncloud.org/server/5.0/admin_manual/installation.html');
+
+ $tmpl = new OC_Template('', 'error', 'guest');
+ $tmpl->assign('errors', array(1 => array('error' => $error, 'hint' => $hint)), false);
+ $tmpl->printPage();
+ exit();
+ }
+ }
}