File manager - Edit - /home/jardides/www/Jardi-design/images/administrator/Setup.tar
Back
PostgreSQL.php 0000604 00000013270 15247161116 0007263 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bart Visscher <bartv@thisnet.nl> * @author eduardo <eduardo@vnexu.net> * @author Joas Schilling <coding@schilljs.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Setup; use OC\DatabaseException; use OC\DB\QueryBuilder\Literal; use OCP\IDBConnection; class PostgreSQL extends AbstractDatabase { public $dbprettyname = 'PostgreSQL'; public function setupDatabase($username) { try { $connection = $this->connect([ 'dbname' => 'postgres' ]); //check for roles creation rights in postgresql $builder = $connection->getQueryBuilder(); $builder->automaticTablePrefix(false); $query = $builder ->select('rolname') ->from('pg_roles') ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE'))) ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); try { $result = $query->execute(); $canCreateRoles = $result->rowCount() > 0; } catch (DatabaseException $e) { $canCreateRoles = false; } if ($canCreateRoles) { //use the admin login data for the new database user //add prefix to the postgresql user name to prevent collisions $this->dbUser = 'oc_' . strtolower($username); //create a new password so we don't need to store the admin config in the config file $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); $this->createDBUser($connection); } $this->config->setValues([ 'dbuser' => $this->dbUser, 'dbpassword' => $this->dbPassword, ]); //create the database $this->createDatabase($connection); $query = $connection->prepare("select count(*) FROM pg_class WHERE relname=? limit 1"); $query->execute([$this->tablePrefix . "users"]); $tablesSetup = $query->fetchColumn() > 0; // the connection to dbname=postgres is not needed anymore $connection->close(); } catch (\Exception $e) { $this->logger->logException($e); $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created'); $tablesSetup = false; $this->config->setValues([ 'dbuser' => $this->dbUser, 'dbpassword' => $this->dbPassword, ]); } // connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled $this->dbUser = $this->config->getValue('dbuser'); $this->dbPassword = $this->config->getValue('dbpassword'); $connection = $this->connect(); try { $connection->connect(); } catch (\Exception $e) { $this->logger->logException($e); throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), $this->trans->t('You need to enter details of an existing account.')); } if (!$tablesSetup) { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } } private function createDatabase(IDBConnection $connection) { if (!$this->databaseExists($connection)) { //The database does not exists... let's create it $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); try { $query->execute(); } catch (DatabaseException $e) { $this->logger->error('Error while trying to create database'); $this->logger->logException($e); } } else { $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); try { $query->execute(); } catch (DatabaseException $e) { $this->logger->error('Error while trying to restrict database permissions'); $this->logger->logException($e); } } } private function userExists(IDBConnection $connection) { $builder = $connection->getQueryBuilder(); $builder->automaticTablePrefix(false); $query = $builder->select('*') ->from('pg_roles') ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); $result = $query->execute(); return $result->rowCount() > 0; } private function databaseExists(IDBConnection $connection) { $builder = $connection->getQueryBuilder(); $builder->automaticTablePrefix(false); $query = $builder->select('datname') ->from('pg_database') ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName))); $result = $query->execute(); return $result->rowCount() > 0; } private function createDBUser(IDBConnection $connection) { $dbUser = $this->dbUser; try { $i = 1; while ($this->userExists($connection)) { $i++; $this->dbUser = $dbUser . $i; }; // create the user $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); $query->execute(); } catch (DatabaseException $e) { $this->logger->error('Error while trying to create database user'); $this->logger->logException($e); } } } AbstractDatabase.php 0000604 00000010624 15247161116 0010450 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bart Visscher <bartv@thisnet.nl> * @author Joas Schilling <coding@schilljs.com> * @author Manish Bisht <manish.bisht490@gmail.com> * @author Robin Appelman <robin@icewind.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Pulzer <t.pulzer@kniel.de> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Setup; use OC\DB\ConnectionFactory; use OC\SystemConfig; use OCP\IL10N; use OCP\ILogger; use OCP\Security\ISecureRandom; abstract class AbstractDatabase { /** @var IL10N */ protected $trans; /** @var string */ protected $dbDefinitionFile; /** @var string */ protected $dbUser; /** @var string */ protected $dbPassword; /** @var string */ protected $dbName; /** @var string */ protected $dbHost; /** @var string */ protected $dbPort; /** @var string */ protected $tablePrefix; /** @var SystemConfig */ protected $config; /** @var ILogger */ protected $logger; /** @var ISecureRandom */ protected $random; public function __construct(IL10N $trans, $dbDefinitionFile, SystemConfig $config, ILogger $logger, ISecureRandom $random) { $this->trans = $trans; $this->dbDefinitionFile = $dbDefinitionFile; $this->config = $config; $this->logger = $logger; $this->random = $random; } public function validate($config) { $errors = array(); if(empty($config['dbuser']) && empty($config['dbname'])) { $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); } else if(empty($config['dbuser'])) { $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); } else if(empty($config['dbname'])) { $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); } if(substr_count($config['dbname'], '.') >= 1) { $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname)); } return $errors; } public function initialize($config) { $dbUser = $config['dbuser']; $dbPass = $config['dbpass']; $dbName = $config['dbname']; $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; $this->config->setValues([ 'dbname' => $dbName, 'dbhost' => $dbHost, 'dbport' => $dbPort, 'dbtableprefix' => $dbTablePrefix, ]); $this->dbUser = $dbUser; $this->dbPassword = $dbPass; $this->dbName = $dbName; $this->dbHost = $dbHost; $this->dbPort = $dbPort; $this->tablePrefix = $dbTablePrefix; } /** * @param array $configOverwrite * @return \OC\DB\Connection */ protected function connect(array $configOverwrite = []) { $connectionParams = array( 'host' => $this->dbHost, 'user' => $this->dbUser, 'password' => $this->dbPassword, 'tablePrefix' => $this->tablePrefix, 'dbname' => $this->dbName ); // adding port support through installer if (!empty($this->dbPort)) { if (ctype_digit($this->dbPort)) { $connectionParams['port'] = $this->dbPort; } else { $connectionParams['unix_socket'] = $this->dbPort; } } else if (strpos($this->dbHost, ':')) { // Host variable may carry a port or socket. list($host, $portOrSocket) = explode(':', $this->dbHost, 2); if (ctype_digit($portOrSocket)) { $connectionParams['port'] = $portOrSocket; } else { $connectionParams['unix_socket'] = $portOrSocket; } $connectionParams['host'] = $host; } $connectionParams = array_merge($connectionParams, $configOverwrite); $cf = new ConnectionFactory($this->config); return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams); } /** * @param string $userName */ abstract public function setupDatabase($userName); } Sqlite.php 0000604 00000002634 15247161116 0006523 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bart Visscher <bartv@thisnet.nl> * @author Morris Jobke <hey@morrisjobke.de> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Setup; class Sqlite extends AbstractDatabase { public $dbprettyname = 'Sqlite'; public function validate($config) { return array(); } public function initialize($config) { } public function setupDatabase($username) { $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); //delete the old sqlite database first, might cause infinte loops otherwise if(file_exists("$datadir/owncloud.db")) { unlink("$datadir/owncloud.db"); } //in case of sqlite, we can always fill the database error_log("creating sqlite db"); \OC_DB::createDbFromStructure($this->dbDefinitionFile); } } MySQL.php 0000604 00000013014 15247161116 0006221 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Bart Visscher <bartv@thisnet.nl> * @author Joas Schilling <coding@schilljs.com> * @author Michael Göhler <somebody.here@gmx.de> * @author Robin McCorkell <robin@mccorkell.me.uk> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Stefan Weil <sw@weilnetz.de> * @author Thomas Müller <thomas.mueller@tmit.eu> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Setup; use OC\DB\MySqlTools; use OCP\IDBConnection; class MySQL extends AbstractDatabase { public $dbprettyname = 'MySQL/MariaDB'; public function setupDatabase($username) { //check if the database user has admin right $connection = $this->connect(['dbname' => null]); // detect mb4 $tools = new MySqlTools(); if ($tools->supports4ByteCharset($connection)) { $this->config->setValue('mysql.utf8mb4', true); $connection = $this->connect(['dbname' => null]); } $this->createSpecificUser($username, $connection); //create the database $this->createDatabase($connection); //fill the database if needed $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; $result = $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']); $row = $result->fetch(); if (!$row or $row['count(*)'] === '0') { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } } /** * @param \OC\DB\Connection $connection */ private function createDatabase($connection) { try{ $name = $this->dbName; $user = $this->dbUser; //we can't use OC_DB functions here because we need to connect as the administrative user. $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; $connection->executeUpdate($query); } catch (\Exception $ex) { $this->logger->error('Database creation failed: {error}', [ 'app' => 'mysql.setup', 'error' => $ex->getMessage() ]); return; } try { //this query will fail if there aren't the right permissions, ignore the error $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; $connection->executeUpdate($query); } catch (\Exception $ex) { $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges: {error}', [ 'app' => 'mysql.setup', 'error' => $ex->getMessage() ]); } } /** * @param IDBConnection $connection * @throws \OC\DatabaseSetupException */ private function createDBUser($connection) { try{ $name = $this->dbUser; $password = $this->dbPassword; // 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. $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; $connection->executeUpdate($query); $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $connection->executeUpdate($query); } catch (\Exception $ex){ $this->logger->error('Database User creation failed: {error}', [ 'app' => 'mysql.setup', 'error' => $ex->getMessage() ]); } } /** * @param $username * @param IDBConnection $connection * @return array */ private function createSpecificUser($username, $connection) { try { //user already specified in config $oldUser = $this->config->getValue('dbuser', false); //we don't have a dbuser specified in config if ($this->dbUser !== $oldUser) { //add prefix to the admin username to prevent collisions $adminUser = substr('oc_' . $username, 0, 16); $i = 1; while (true) { //this should be enough to check for admin rights in mysql $query = 'SELECT user FROM mysql.user WHERE user=?'; $result = $connection->executeQuery($query, [$adminUser]); //current dbuser has admin rights if ($result) { $data = $result->fetchAll(); //new dbuser does not exist if (count($data) === 0) { //use the admin login data for the new database user $this->dbUser = $adminUser; //create a random password so we don't need to store the admin password in the config file $this->dbPassword = $this->random->generate(30); $this->createDBUser($connection); break; } else { //repeat with different username $length = strlen((string)$i); $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; $i++; } } else { break; } }; } } catch (\Exception $ex) { $this->logger->info('Can not create a new MySQL user, will continue with the provided user: {error}', [ 'app' => 'mysql.setup', 'error' => $ex->getMessage() ]); } $this->config->setValues([ 'dbuser' => $this->dbUser, 'dbpassword' => $this->dbPassword, ]); } } OCI.php 0000604 00000025100 15247161116 0005665 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Andreas Fischer <bantu@owncloud.com> * @author Bart Visscher <bartv@thisnet.nl> * @author Joas Schilling <coding@schilljs.com> * @author Jörn Friedrich Dreyer <jfd@butonic.de> * @author Manish Bisht <manish.bisht490@gmail.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Pulzer <t.pulzer@kniel.de> * @author Victor Dubiniuk <dubiniuk@owncloud.com> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Setup; class OCI extends AbstractDatabase { public $dbprettyname = 'Oracle'; protected $dbtablespace; public function initialize($config) { parent::initialize($config); if (array_key_exists('dbtablespace', $config)) { $this->dbtablespace = $config['dbtablespace']; } else { $this->dbtablespace = 'USERS'; } // allow empty hostname for oracle $this->dbHost = $config['dbhost']; $this->config->setValues([ 'dbhost' => $this->dbHost, 'dbtablespace' => $this->dbtablespace, ]); } public function validate($config) { $errors = array(); if(empty($config['dbuser']) && empty($config['dbname'])) { $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); } else if(empty($config['dbuser'])) { $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); } else if(empty($config['dbname'])) { $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); } return $errors; } public function setupDatabase($username) { $e_host = addslashes($this->dbHost); // casting to int to avoid malicious input $e_port = (int)$this->dbPort; $e_dbname = addslashes($this->dbName); //check if the database user has admin right if ($e_host == '') { $easy_connect_string = $e_dbname; // use dbname as easy connect name } else { $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; } $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']); $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); if(!$connection) { $errorMessage = $this->getLastError(); if ($errorMessage) { throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'), $errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') .' ORACLE_SID='.getenv('ORACLE_SID') .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') .' NLS_LANG='.getenv('NLS_LANG') .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); } throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), 'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') .' ORACLE_SID='.getenv('ORACLE_SID') .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') .' NLS_LANG='.getenv('NLS_LANG') .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); } //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 = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } $result = oci_execute($stmt); if($result) { $row = oci_fetch_row($stmt); if ($row[0] > 0) { //use the admin login data for the new database user //add prefix to the oracle user name to prevent collisions $this->dbUser='oc_'.$username; //create a new password so we don't need to store the admin config in the config file $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); //oracle passwords are treated as identifiers: // must start with alphanumeric char // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. $this->dbPassword=substr($this->dbPassword, 0, 30); $this->createDBUser($connection); } } $this->config->setValues([ 'dbuser' => $this->dbUser, 'dbname' => $this->dbName, 'dbpassword' => $this->dbPassword, ]); //create the database not necessary, oracle implies user = schema //$this->createDatabase($this->dbname, $this->dbuser, $connection); //FIXME check tablespace exists: select * from user_tablespaces // the connection to dbname=oracle is not needed anymore oci_close($connection); // connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled $this->dbUser = $this->config->getValue('dbuser'); //$this->dbname = \OC_Config::getValue('dbname'); $this->dbPassword = $this->config->getValue('dbpassword'); $e_host = addslashes($this->dbHost); $e_dbname = addslashes($this->dbName); if ($e_host == '') { $easy_connect_string = $e_dbname; // use dbname as easy connect name } else { $easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname; } $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); if(!$connection) { throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), $this->trans->t('You need to enter details of an existing account.')); } $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; $stmt = oci_parse($connection, $query); $un = $this->tablePrefix.'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning( $entry, ['app' => 'setup.oci']); } $result = oci_execute($stmt); if($result) { $row = oci_fetch_row($stmt); } if(!$result or $row[0]==0) { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } } /** * @param resource $connection */ private function createDBUser($connection) { $name = $this->dbUser; $password = $this->dbPassword; $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } if(! oci_fetch_row($stmt)) { //user does not exists let's create it :) //password must start with alphabetic character in oracle $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } //oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } } else { // change password of the existing role $query = "ALTER USER :un IDENTIFIED BY :pw"; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } oci_bind_by_name($stmt, ':un', $name); oci_bind_by_name($stmt, ':pw', $password); $result = oci_execute($stmt); if(!$result) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } } // grant necessary roles $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } $result = oci_execute($stmt); if(!$result) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', array($query, $name, $password)) . '<br />'; $this->logger->warning($entry, ['app' => 'setup.oci']); } } /** * @param resource $connection * @return string */ protected function getLastError($connection = null) { if ($connection) { $error = oci_error($connection); } else { $error = oci_error(); } foreach (array('message', 'code') as $key) { if (isset($error[$key])) { return $error[$key]; } } return ''; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings