Source for file configuration.php

Documentation is available at configuration.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Installation
  4.  * @subpackage  Model
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC') or die;
  11.  
  12. /**
  13.  * Configuration setup model for the Joomla Core Installer.
  14.  *
  15.  * @package     Joomla.Installation
  16.  * @subpackage  Model
  17.  * @since       3.1
  18.  */
  19. {
  20.     /**
  21.      * Method to setup the configuration file
  22.      *
  23.      * @param   array  $options  The session options
  24.      *
  25.      * @return  boolean  True on success
  26.      *
  27.      * @since   3.1
  28.      */
  29.     public function setup($options)
  30.     {
  31.         // Get the options as an object for easier handling.
  32.         $options = JArrayHelper::toObject($options);
  33.  
  34.         // Attempt to create the root user.
  35.         if (!$this->_createConfiguration($options))
  36.         {
  37.             return false;
  38.         }
  39.  
  40.         // Attempt to create the root user.
  41.         if (!$this->_createRootUser($options))
  42.         {
  43.             return false;
  44.         }
  45.  
  46.         return true;
  47.     }
  48.  
  49.     /**
  50.      * Method to create the configuration file
  51.      *
  52.      * @param   array  $options  The session options
  53.      *
  54.      * @return  boolean  True on success
  55.      *
  56.      * @since   3.1
  57.      */
  58.     function _createConfiguration($options)
  59.     {
  60.         // Create a new registry to build the configuration options.
  61.         $registry = new JRegistry;
  62.  
  63.         /* Site Settings */
  64.         $registry->set('offline', $options->site_offline);
  65.         $registry->set('offline_message', JText::_('INSTL_STD_OFFLINE_MSG'));
  66.         $registry->set('display_offline_message', 1);
  67.         $registry->set('offline_image', '');
  68.         $registry->set('sitename', $options->site_name);
  69.         $registry->set('editor', 'tinymce');
  70.         $registry->set('captcha', '0');
  71.         $registry->set('list_limit', 20);
  72.         $registry->set('access', 1);
  73.  
  74.         /* Debug Settings */
  75.         $registry->set('debug', 0);
  76.         $registry->set('debug_lang', 0);
  77.  
  78.         /* Database Settings */
  79.         $registry->set('dbtype', $options->db_type);
  80.         $registry->set('host', $options->db_host);
  81.         $registry->set('user', $options->db_user);
  82.         $registry->set('password', $options->db_pass);
  83.         $registry->set('db', $options->db_name);
  84.         $registry->set('dbprefix', $options->db_prefix);
  85.  
  86.         /* Server Settings */
  87.         $registry->set('live_site', '');
  88.         $registry->set('secret', JUserHelper::genRandomPassword(16));
  89.         $registry->set('gzip', 0);
  90.         $registry->set('error_reporting', 'default');
  91.         $registry->set('helpurl', 'http://help.joomla.org/proxy/index.php?option=com_help&amp;keyref=Help{major}{minor}:{keyref}');
  92.         $registry->set('ftp_host', isset($options->ftp_host) ? $options->ftp_host : '');
  93.         $registry->set('ftp_port', isset($options->ftp_host) ? $options->ftp_port : '');
  94.         $registry->set('ftp_user', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_user)) ? $options->ftp_user : '');
  95.         $registry->set('ftp_pass', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_pass)) ? $options->ftp_pass : '');
  96.         $registry->set('ftp_root', (isset($options->ftp_save) && $options->ftp_save && isset($options->ftp_root)) ? $options->ftp_root : '');
  97.         $registry->set('ftp_enable', isset($options->ftp_host) ? $options->ftp_enable : '');
  98.  
  99.         /* Locale Settings */
  100.         $registry->set('offset', 'UTC');
  101.  
  102.         /* Mail Settings */
  103.         $registry->set('mailonline', 1);
  104.         $registry->set('mailer', 'mail');
  105.         $registry->set('mailfrom', $options->admin_email);
  106.         $registry->set('fromname', $options->site_name);
  107.         $registry->set('sendmail', '/usr/sbin/sendmail');
  108.         $registry->set('smtpauth', 0);
  109.         $registry->set('smtpuser', '');
  110.         $registry->set('smtppass', '');
  111.         $registry->set('smtphost', 'localhost');
  112.         $registry->set('smtpsecure', 'none');
  113.         $registry->set('smtpport', '25');
  114.  
  115.         /* Cache Settings */
  116.         $registry->set('caching', 0);
  117.         $registry->set('cache_handler', 'file');
  118.         $registry->set('cachetime', 15);
  119.  
  120.         /* Meta Settings */
  121.         $registry->set('MetaDesc', $options->site_metadesc);
  122.         $registry->set('MetaKeys', '');
  123.         $registry->set('MetaTitle', 1);
  124.         $registry->set('MetaAuthor', 1);
  125.         $registry->set('MetaVersion', 0);
  126.         $registry->set('robots', '');
  127.  
  128.         /* SEO Settings */
  129.         $registry->set('sef', 1);
  130.         $registry->set('sef_rewrite', 0);
  131.         $registry->set('sef_suffix', 0);
  132.         $registry->set('unicodeslugs', 0);
  133.  
  134.         /* Feed Settings */
  135.         $registry->set('feed_limit', 10);
  136.         $registry->set('log_path', JPATH_ROOT . '/logs');
  137.         $registry->set('tmp_path', JPATH_ROOT . '/tmp');
  138.  
  139.         /* Session Setting */
  140.         $registry->set('lifetime', 15);
  141.         $registry->set('session_handler', 'database');
  142.  
  143.         // Generate the configuration class string buffer.
  144.         $buffer = $registry->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
  145.  
  146.         // Build the configuration file path.
  147.         $path = JPATH_CONFIGURATION . '/configuration.php';
  148.  
  149.         // Determine if the configuration file path is writable.
  150.         if (file_exists($path))
  151.         {
  152.             $canWrite = is_writable($path);
  153.         }
  154.         else
  155.         {
  156.             $canWrite = is_writable(JPATH_CONFIGURATION . '/');
  157.         }
  158.  
  159.         /*
  160.          * If the file exists but isn't writable OR if the file doesn't exist and the parent directory
  161.          * is not writable we need to use FTP
  162.          */
  163.         $useFTP = false;
  164.  
  165.         if ((file_exists($path) && !is_writable($path)) || (!file_exists($path) && !is_writable(dirname($path) . '/')))
  166.         {
  167.             $useFTP = true;
  168.         }
  169.  
  170.         // Check for safe mode
  171.         if (ini_get('safe_mode'))
  172.         {
  173.             $useFTP = true;
  174.         }
  175.  
  176.         // Enable/Disable override
  177.         if (!isset($options->ftpEnable) || ($options->ftpEnable != 1))
  178.         {
  179.             $useFTP = false;
  180.         }
  181.  
  182.         if ($useFTP == true)
  183.         {
  184.             // Connect the FTP client
  185.             $ftp = JClientFtp::getInstance($options->ftp_host, $options->ftp_port);
  186.             $ftp->login($options->ftp_user, $options->ftp_pass);
  187.  
  188.             // Translate path for the FTP account
  189.             $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/');
  190.  
  191.             // Use FTP write buffer to file
  192.             if (!$ftp->write($file, $buffer))
  193.             {
  194.                 // Set the config string to the session.
  195.                 $session = JFactory::getSession();
  196.                 $session->set('setup.config', $buffer);
  197.             }
  198.  
  199.             $ftp->quit();
  200.         }
  201.         else
  202.         {
  203.             if ($canWrite)
  204.             {
  205.                 file_put_contents($path, $buffer);
  206.                 $session = JFactory::getSession();
  207.                 $session->set('setup.config', null);
  208.             }
  209.             else
  210.             {
  211.                 // Set the config string to the session.
  212.                 $session = JFactory::getSession();
  213.                 $session->set('setup.config', $buffer);
  214.             }
  215.         }
  216.  
  217.         return true;
  218.     }
  219.  
  220.     /**
  221.      * Method to create the root user for the site
  222.      *
  223.      * @param   object  $options  The session options
  224.      *
  225.      * @return  boolean  True on success
  226.      *
  227.      * @since   3.1
  228.      */
  229.     private function _createRootUser($options)
  230.     {
  231.         // Get the application
  232.         /* @var InstallationApplicationWeb $app */
  233.         $app = JFactory::getApplication();
  234.  
  235.         // Get a database object.
  236.         try
  237.         {
  238.             $db = InstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
  239.         }
  240.         catch (RuntimeException $e)
  241.         {
  242.             $app->enqueueMessage(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()), 'notice');
  243.  
  244.             return false;
  245.         }
  246.  
  247.         $useStrongPasswords = JCrypt::hasStrongPasswordSupport();
  248.  
  249.         if ($useStrongPasswords)
  250.         {
  251.             $cryptpass = JUserHelper::getCryptedPassword($options->admin_password);
  252.         }
  253.         else
  254.         {
  255.             $salt = JUserHelper::genRandomPassword(16);
  256.             //$cryptpass = JUserHelper::getCryptedPassword($options->admin_password, $salt, 'sha256') . ':' . $salt;
  257.             $cryptpass = JUserHelper::getCryptedPassword($options->admin_password, $salt, 'sha256');
  258.  
  259.         }
  260.  
  261.         // Take the admin user id
  262.         $userId = InstallationModelDatabase::getUserId();
  263.  
  264.         // We don't need the randUserId in the session any longer, let's remove it
  265.  
  266.         // Create the admin user
  267.         date_default_timezone_set('UTC');
  268.         $installdate = date('Y-m-d H:i:s');
  269.         $nullDate    = $db->getNullDate();
  270.  
  271.         // Sqlsrv change
  272.         $query = $db->getQuery(true)
  273.             ->select($db->quoteName('id'))
  274.             ->from($db->quoteName('#__users'))
  275.             ->where($db->quoteName('id') . ' = ' . $db->quote($userId));
  276.  
  277.         $db->setQuery($query);
  278.  
  279.         if ($db->loadResult())
  280.         {
  281.             $query->clear()
  282.                 ->update($db->quoteName('#__users'))
  283.                 ->set($db->quoteName('name') . ' = ' . $db->quote('Super User'))
  284.                 ->set($db->quoteName('username') . ' = ' . $db->quote($options->admin_user))
  285.                 ->set($db->quoteName('email') . ' = ' . $db->quote($options->admin_email))
  286.                 ->set($db->quoteName('password') . ' = ' . $db->quote($cryptpass))
  287.                 ->set($db->quoteName('block') . ' = 0')
  288.                 ->set($db->quoteName('sendEmail') . ' = 1')
  289.                 ->set($db->quoteName('registerDate') . ' = ' . $db->quote($installdate))
  290.                 ->set($db->quoteName('lastvisitDate') . ' = ' . $db->quote($nullDate))
  291.                 ->set($db->quoteName('activation') . ' = ' . $db->quote('0'))
  292.                 ->set($db->quoteName('params') . ' = ' . $db->quote(''))
  293.                 ->where($db->quoteName('id') . ' = ' . $db->quote($userId));
  294.         }
  295.         else
  296.         {
  297.             $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'),
  298.                             $db->quoteName('email'), $db->quoteName('password'),
  299.                             $db->quoteName('block'),
  300.                             $db->quoteName('sendEmail'), $db->quoteName('registerDate'),
  301.                             $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
  302.             $query->clear()
  303.                 ->insert('#__users', true)
  304.                 ->columns($columns)
  305.                 ->values(
  306.                 $db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote($options->admin_user) . ', ' .
  307.                 $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' .
  308.                 $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' .
  309.                 $db->quote('0') . ', ' . $db->quote('')
  310.             );
  311.         }
  312.  
  313.         $db->setQuery($query);
  314.  
  315.         try
  316.         {
  317.             $db->execute();
  318.         }
  319.         catch (RuntimeException $e)
  320.         {
  321.             $app->enqueueMessage($e->getMessage(), 'notice');
  322.             return false;
  323.         }
  324.  
  325.         // Map the super admin to the Super Admin Group
  326.         $query->clear()
  327.             ->select($db->quoteName('user_id'))
  328.             ->from($db->quoteName('#__user_usergroup_map'))
  329.             ->where($db->quoteName('user_id') . ' = ' . $db->quote($userId));
  330.  
  331.         $db->setQuery($query);
  332.  
  333.         if ($db->loadResult())
  334.         {
  335.             $query->clear()
  336.                 ->update($db->quoteName('#__user_usergroup_map'))
  337.                 ->set($db->quoteName('user_id') . ' = ' . $db->quote($userId))
  338.                 ->set($db->quoteName('group_id') . ' = 8');
  339.         }
  340.         else
  341.         {
  342.             $query->clear()
  343.                 ->insert($db->quoteName('#__user_usergroup_map'), false)
  344.                 ->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')))
  345.                 ->values($db->quote($userId) . ', 8');
  346.         }
  347.  
  348.         $db->setQuery($query);
  349.  
  350.         try
  351.         {
  352.             $db->execute();
  353.         }
  354.         catch (RuntimeException $e)
  355.         {
  356.             $app->enqueueMessage($e->getMessage(), 'notice');
  357.             return false;
  358.         }
  359.  
  360.         return true;
  361.     }
  362. }

Documentation generated on Tue, 19 Nov 2013 14:56:31 +0100 by phpDocumentor 1.4.3