- md5
- cc8fa4e19ddfde300cd6a93e27190c78
- sha1
- 7c4e2d96de86a8675f9fee7db97b3fb8048ea885
- sha256
- d0bbafe68b98c9c6d413e8cc173f39eb85da8a461294867a4963f297645feb72
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
<?php
/**
* @package Joomla.Installation
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.filesystem.file');
require_once JPATH_INSTALLATION . '/helpers/database.php';
/**
* Install Configuration model for the Joomla Core Installer.
*
* @package Joomla.Installation
* @since 3.0
*/
class InstallationModelConfiguration extends JModelLegacy
{
/**
* @return boolean
*
* @since 3.0
*/
public function setup($options)
{
// Get the options as an object for easier handling.
$options = JArrayHelper::toObject($options);
// Attempt to create the root user.
if (!$this->_createConfiguration($options))
{
return false;
}
// Attempt to create the root user.
if (!$this->_createRootUser($options))
{
return false;
}
return true;
}
/**
* Method to create the configuration file
*
* @param array $options
*
* @return boolean True on success
*
* @since 3.0
*/
function _createConfiguration($options)
{
// Create a new registry to build the configuration options.
$registry = new JRegistry;
/* Site Settings */
$registry->set('offline', $options->site_offline);
$registry->set('offline_message', JText::_('INSTL_STD_OFFLINE_MSG'));
$registry->set('display_offline_message', 1);
$registry->set('offline_image', '');
$registry->set('sitename', $options->site_name);
$registry->set('editor', 'tinymce');
$registry->set('captcha', '0');
$registry->set('list_limit', 20);
$registry->set('access', 1);
/* Debug Settings */
$registry->set('debug', 0);
$registry->set('debug_lang', 0);
/* Database Settings */
$registry->set('dbtype', $options->db_type);
$registry->set('host', $options->db_host);
$registry->set('user', $options->db_user);
$registry->set('password', $options->db_pass);
$registry->set('db', $options->db_name);
$registry->set('dbprefix', $options->db_prefix);
/* Server Settings */
$registry->set('live_site', '');
$registry->set('secret', JUserHelper::genRandomPassword(16));
$registry->set('gzip', 0);
$registry->set('error_reporting', 'default');
$registry->set('helpurl', 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}');
$registry->set('ftp_host', isset($options->ftp_host) ? $options->ftp_host : '');
$registry->set('ftp_port', isset($options->ftp_host) ? $options->ftp_port : '');
$registry->set('ftp_user', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_user)) ? $options->ftp_user : '');
$registry->set('ftp_pass', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_pass)) ? $options->ftp_pass : '');
$registry->set('ftp_root', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_root)) ? $options->ftp_root : '');
$registry->set('ftp_enable', isset($options->ftp_host) ? $options->ftp_enable : '');
/* Locale Settings */
$registry->set('offset', 'UTC');
/* Mail Settings */
$registry->set('mailer', 'mail');
$registry->set('mailfrom', $options->admin_email);
$registry->set('fromname', $options->site_name);
$registry->set('sendmail', '/usr/sbin/sendmail');
$registry->set('smtpauth', 0);
$registry->set('smtpuser', '');
$registry->set('smtppass', '');
$registry->set('smtphost', 'localhost');
$registry->set('smtpsecure', 'none');
$registry->set('smtpport', '25');
/* Cache Settings */
$registry->set('caching', 0);
$registry->set('cache_handler', 'file');
$registry->set('cachetime', 15);
/* Meta Settings */
$registry->set('MetaDesc', $options->site_metadesc);
$registry->set('MetaKeys', '');
$registry->set('MetaTitle', 1);
$registry->set('MetaAuthor', 1);
$registry->set('MetaVersion', 0);
$registry->set('robots', '');
/* SEO Settings */
$registry->set('sef', 1);
$registry->set('sef_rewrite', 0);
$registry->set('sef_suffix', 0);
$registry->set('unicodeslugs', 0);
/* Feed Settings */
$registry->set('feed_limit', 10);
$registry->set('log_path', JPATH_ROOT . '/logs');
$registry->set('tmp_path', JPATH_ROOT . '/tmp');
/* Session Setting */
$registry->set('lifetime', 15);
$registry->set('session_handler', 'database');
// Generate the configuration class string buffer.
$buffer = $registry->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
// Build the configuration file path.
$path = JPATH_CONFIGURATION . '/configuration.php';
// Determine if the configuration file path is writable.
if (file_exists($path))
{
$canWrite = is_writable($path);
}
else
{
$canWrite = is_writable(JPATH_CONFIGURATION . '/');
}
/*
* If the file exists but isn't writable OR if the file doesn't exist and the parent directory
* is not writable we need to use FTP
*/
$useFTP = false;
if ((file_exists($path) && !is_writable($path)) || (!file_exists($path) && !is_writable(dirname($path) . '/')))
{
$useFTP = true;
}
// Check for safe mode
if (ini_get('safe_mode'))
{
$useFTP = true;
}
// Enable/Disable override
if (!isset($options->ftpEnable) || ($options->ftpEnable != 1))
{
$useFTP = false;
}
if ($useFTP == true)
{
// Connect the FTP client
jimport('joomla.filesystem.path');
$ftp = JClientFtp::getInstance($options->ftp_host, $options->ftp_port);
$ftp->login($options->ftp_user, $options->ftp_pass);
// Translate path for the FTP account
$file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/');
// Use FTP write buffer to file
if (!$ftp->write($file, $buffer))
{
// Set the config string to the session.
$session = JFactory::getSession();
$session->set('setup.config', $buffer);
}
$ftp->quit();
}
else
{
if ($canWrite)
{
file_put_contents($path, $buffer);
$session = JFactory::getSession();
$session->set('setup.config', null);
}
else
{
// Set the config string to the session.
$session = JFactory::getSession();
$session->set('setup.config', $buffer);
}
}
return true;
}
/**
* Method to create the root user for the site
*
* @param array $options The session options
*
* @return boolean True on success
*
* @since 3.0
*/
private function _createRootUser($options)
{
// Get a database object.
try
{
$db = InstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
}
catch (RuntimeException $e)
{
$this->setError(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()));
}
// Create random salt/password for the admin user
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($options->admin_password, $salt);
$cryptpass = $crypt . ':' . $salt;
// Take the admin user id
JLoader::register('InstallationModelDatabase', JPATH_INSTALLATION . '/models/database.php');
$userId = InstallationModelDatabase::getUserId();
// We don't need the randUserId in the session any longer, let's remove it
InstallationModelDatabase::resetRandUserId();
// Create the admin user
date_default_timezone_set('UTC');
$installdate = date('Y-m-d H:i:s');
$nullDate = $db->getNullDate();
// Sqlsrv change
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('id') . ' = ' . $db->quote($userId));
$db->setQuery($query);
if ($db->loadResult())
{
$query = $db->getQuery(true);
$query->update($db->quoteName('#__users'));
$query->set($db->quoteName('name') . ' = ' . $db->quote('Super User'));
$query->set($db->quoteName('username') . ' = ' . $db->quote($options->admin_user));
$query->set($db->quoteName('email') . ' = ' . $db->quote($options->admin_email));
$query->set($db->quoteName('password') . ' = ' . $db->quote($cryptpass));
$query->set($db->quoteName('block') . ' = 0');
$query->set($db->quoteName('sendEmail') . ' = 1');
$query->set($db->quoteName('registerDate') . ' = ' . $db->quote($installdate));
$query->set($db->quoteName('lastvisitDate') . ' = ' . $db->quote($nullDate));
$query->set($db->quoteName('activation') . ' = ' . $db->quote('0'));
$query->set($db->quoteName('params') . ' = ' . $db->quote(''));
$query->where($db->quoteName('id') . ' = ' . $db->quote($userId));
}
else
{
$query = $db->getQuery(true);
$columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'),
$db->quoteName('email'), $db->quoteName('password'),
$db->quoteName('block'),
$db->quoteName('sendEmail'), $db->quoteName('registerDate'),
$db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
$query->insert('#__users', true);
$query->columns($columns);
$query->values(
$db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote($options->admin_user) . ', ' .
$db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' .
$db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' .
$db->quote('0') . ', ' . $db->quote('')
);
}
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
// Map the super admin to the Super Admin Group
$query = $db->getQuery(true);
$query->select($db->quoteName('user_id'));
$query->from($db->quoteName('#__user_usergroup_map'));
$query->where($db->quoteName('user_id') . ' = ' . $db->quote($userId));
$db->setQuery($query);
if ($db->loadResult())
{
$query = $db->getQuery(true);
$query->update($db->quoteName('#__user_usergroup_map'));
$query->set($db->quoteName('user_id') . ' = ' . $db->quote($userId));
$query->set($db->quoteName('group_id') . ' = 8');
}
else
{
$query = $db->getQuery(true);
$query->insert($db->quoteName('#__user_usergroup_map'), false);
$query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
$query->values($db->quote($userId) . ', ' . '8');
}
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
return true;
}
}
The same content is in 3 releases, Joomla 3.0.0 to 3.0.2. See them all, or every version of this file.