示例#1
0
 /**
  * Apply the settings to the configuration.php file and the database
  *
  * @param   string  $folder     Folder containing the settings.php file
  *
  * @return  bool    I was able to write the configuration file?
  */
 public function applySettings($folder = '')
 {
     if (!$folder) {
         $folder = 'default';
     }
     // TODO Should we clean the folder path to avoid relative-paths exploits?
     $folder = trim($folder, " \t\n\r\v" . DIRECTORY_SEPARATOR);
     // Get the state variables and update the global configuration
     $stateVars = $this->getStateVariables($folder);
     // -- General settings
     $this->configModel->set('sitename', $stateVars->sitename, $folder);
     $this->configModel->set('site_mail', $stateVars->siteemail, $folder);
     $this->configModel->set('tmp_path', $stateVars->tmppath, $folder);
     // I have to save the old live_site and cookie domain value: if it was previously defined and now it's not
     // I have to comment some code inside the settings file
     $this->configModel->set('old_cookie_domain', $this->configModel->get('cookie_domain', '', $folder), $folder);
     $this->configModel->set('old_live_site', $this->configModel->get('live_site', '', $folder), $folder);
     $this->configModel->set('cookie_domain', $stateVars->cookiedomain, $folder);
     $this->configModel->set('live_site', $stateVars->livesite, $folder);
     // -- Database settings
     $connectionVars = $this->configModel->getDatabase($folder);
     $this->configModel->set('dbtype', $connectionVars->dbtype, $folder);
     $this->configModel->set('host', $connectionVars->dbhost, $folder);
     $this->configModel->set('user', $connectionVars->dbuser, $folder);
     $this->configModel->set('password', $connectionVars->dbpass, $folder);
     $this->configModel->set('db', $connectionVars->dbname, $folder);
     $this->configModel->set('dbprefix', $connectionVars->prefix, $folder);
     // -- Override the secret key
     $random = new AUtilsRandval();
     $this->configModel->set('drupal_private_key', str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($random->generate(55))), $folder);
     $this->configModel->set('cron_key', str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($random->generate(55))), $folder);
     $this->configModel->saveToSession();
     // Apply the Super Administrator changes
     $this->applySuperAdminChanges();
     // Get the wp-config.php file and try to save it
     if (!$this->configModel->writeConfig(APATH_SITE . '/sites/' . $folder . '/settings.php')) {
         return false;
     }
     return true;
 }
示例#2
0
 /**
  * Apply the settings to the configuration file and the database
  */
 public function applySettings()
 {
     // Get the state variables and update the global configuration
     $stateVars = $this->getStateVariables();
     // -- General settings
     $this->configModel->set('blogname', $stateVars->blogname);
     $this->configModel->set('blogdescription', $stateVars->blogdescription);
     $this->configModel->set('siteurl', $stateVars->siteurl);
     $this->configModel->set('homeurl', $stateVars->homeurl);
     // -- Database settings
     $connectionVars = $this->getDbConnectionVars();
     $this->configModel->set('dbtype', $connectionVars->dbtype);
     $this->configModel->set('dbhost', $connectionVars->dbhost);
     $this->configModel->set('dbuser', $connectionVars->dbuser);
     $this->configModel->set('dbpass', $connectionVars->dbpass);
     $this->configModel->set('dbname', $connectionVars->dbname);
     $this->configModel->set('dbprefix', $connectionVars->prefix);
     $this->configModel->set('dbcharset', $stateVars->dbcharset);
     $this->configModel->set('dbcollation', $stateVars->dbcollation);
     // -- Override the secret key
     $random = new AUtilsRandval();
     $this->configModel->set('auth_key', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('secure_auth_key', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('logged_in_key', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('nonce_key', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('auth_salt', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('secure_auth_salt', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('logged_in_salt', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->set('nonce_salt', substr(base64_encode($random->generate(64)), 0, 64));
     $this->configModel->saveToSession();
     // Sanity check
     if (!$stateVars->homeurl) {
         throw new Exception(AText::_('SETUP_HOMEURL_REQUIRED'));
     }
     if (!$stateVars->siteurl) {
         $this->configModel->set('siteurl', $stateVars->homeurl);
     }
     // Apply the Super Administrator changes
     $this->applySuperAdminChanges();
     // Get the wp-config.php file and try to save it
     if (!$this->configModel->writeConfig(APATH_SITE . '/wp-config.php')) {
         return false;
     }
     return true;
 }
示例#3
0
    /**
     * Creates the string that will be put inside the new configuration file.
     * This is a separate function so we can show the content if we're unable to write to the filesystem
     * and ask the user to manually do that.
     */
    public function getFileContents($file = null)
    {
        if (!$file) {
            $file = APATH_ROOT . '/sites/default/settings.php';
        }
        $out = file_get_contents($file);
        // First of all let's write the database info section
        $tokenizer = new AUtilsPhptokenizer($out);
        $key = $this->input->getCmd('substep', 'default');
        $dbDriver = $this->get('dbtype', null, $key);
        $dbDriver = strtolower($dbDriver);
        if (in_array($dbDriver, array('mysql', 'mysqli', 'pdomysql'))) {
            // There's only a "mysql" driver in Drupal
            $dbDriver = 'mysql';
        }
        $replace_db[] = <<<PHP
\$databases['default']['default'] = array(
      'driver' => '{$dbDriver}',
      'database' => '{$this->get('db', null, $key)}',
      'username' => '{$this->get('user', null, $key)}',
      'password' => '{$this->get('password', null, $key)}',
      'host' => '{$this->get('host', null, $key)}',
      'prefix' => '{$this->get('dbprefix', null, $key)}',
);
PHP;
        $skip = 0;
        $error = false;
        // In Drupal you can have several database configuration (one master + several slaves). Of course we can't modify
        // those info, too, so we're going to wipe out everything and use only the master configuration
        while (!$error) {
            try {
                // First time I really want to replace data, in the next loops I simply want to wipe out everything
                if ($replace_db) {
                    $replace = array_shift($replace_db);
                } else {
                    $replace = '';
                }
                $out = $tokenizer->replaceToken('T_VARIABLE', '$databases', $skip, $replace);
                $tokenizer->setCode($out);
                $info = $tokenizer->searchToken('T_VARIABLE', '$databases', $skip);
                $skip = $info['endLine'] + 1;
            } catch (RuntimeException $e) {
                $error = true;
            }
        }
        // Now let's try to change some other params stored inside the settings file
        $random = new AUtilsRandval();
        // New Salt
        $new_salt = '$drupal_hash_salt = \'' . substr(base64_encode($random->generate(43)), 0, 43) . '\';';
        $out = $tokenizer->replaceToken('T_VARIABLE', '$drupal_hash_salt', 0, $new_salt);
        $tokenizer->setCode($out);
        // --- Base Url
        $old_url = $this->get('old_live_site', null, $key);
        $new_url = $this->get('live_site', null, $key);
        // Previously there was a base url and now there isn't
        if ($old_url && !$new_url) {
            $out = $tokenizer->replaceToken('T_VARIABLE', '$base_url', 0, '# $base_url = \'\';');
        } elseif ($old_url && $new_url && $old_url != $new_url) {
            $out = $tokenizer->replaceToken('T_VARIABLE', '$base_url', 0, '$base_url = \'' . $new_url . '\';');
        } elseif (!$old_url && $new_url) {
            $out .= "\n" . '$base_url = \'' . $new_url . '\';';
        }
        $tokenizer->setCode($out);
        // --- Cookie domain
        $old_domain = $this->get('old_cookie_domain', null, $key);
        $new_domain = $this->get('cookie_domain', null, $key);
        // Previously there was a cookie domain and now there isn't
        if ($old_domain && !$new_domain) {
            $out = $tokenizer->replaceToken('T_VARIABLE', '$cookie_domain', 0, '# $cookie_domain = \'\';');
        } elseif ($old_domain && $new_domain && $old_domain != $new_domain) {
            $out = $tokenizer->replaceToken('T_VARIABLE', '$cookie_domain', 0, '$cookie_domain = \'' . $new_domain . '\';');
        } elseif (!$old_domain && $new_domain) {
            $out .= "\n" . '$cookie_domain = \'' . $new_domain . '\';';
        }
        return $out;
    }