예제 #1
0
 /**
  * Denotes a check message that is a failure
  *
  * @param string $key The check being performed
  * @param string $title The failure message title.
  * @param string $message A detailed failure message.
  * @return boolean
  */
 protected function fail($key, $title = '', $message = '')
 {
     if (empty($title)) {
         $title = $this->install->lexicon('failed');
     }
     $msg = '<span class="notok">' . $title . '</span></p>';
     if (!empty($message)) {
         $msg .= '<p><strong>' . $message . '</strong></p>';
     }
     if (!isset($this->results[$key])) {
         $this->results[$key] = array();
     }
     if (!isset($this->results[$key]['msg'])) {
         $this->results[$key]['msg'] = '';
     }
     $this->results[$key]['msg'] .= $msg;
     $this->results[$key]['class'] = 'testFailed';
     if (!isset($this->results['fail'][$key])) {
         $this->results['fail'][$key] = array();
     }
     if (!isset($this->results['fail'][$key]['msg'])) {
         $this->results['fail'][$key]['msg'] = '';
     }
     $this->results['fail'][$key]['msg'] .= $msg;
     $this->results['fail'][$key]['class'] = 'testFailed';
     $this->results['fail'][$key]['title'] = $title;
     $this->results['fail'][$key]['message'] = $message;
     $this->success = false;
     return true;
 }
 /**
  * Writes the config file.
  *
  * @return boolean Returns true if successful; false otherwise.
  */
 public function writeConfig()
 {
     $written = false;
     $configTpl = MODX_CORE_PATH . 'docs/config.inc.tpl';
     $configFile = MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
     /**
      * Sanitize MySQL Password before writing to config, escaping '
      * I'm sure there's a better way to do this, but this works for now.
      * Otherwise, we risk fatal PHP errors if the entered Password
      * contains any single quotes as they would escape the string.
      * See GitHub issue 12502 for more information. https://github.com/modxcms/revolution/issues/12502
      */
     $this->install->settings->settings['database_password'] = addslashes($this->install->settings->settings['database_password']);
     $settings = $this->install->settings->fetch();
     $settings['last_install_time'] = time();
     $settings['site_id'] = uniqid('modx', true);
     /* make UUID if not set */
     if (empty($settings['uuid'])) {
         $settings['uuid'] = $this->install->generateUUID();
     }
     if (file_exists($configTpl)) {
         if ($tplHandle = @fopen($configTpl, 'rb')) {
             $content = @fread($tplHandle, filesize($configTpl));
             @fclose($tplHandle);
             if ($content) {
                 $replace = array();
                 while (list($key, $value) = each($settings)) {
                     if (is_scalar($value)) {
                         $replace['{' . $key . '}'] = "{$value}";
                     } elseif (is_array($value)) {
                         $replace['{' . $key . '}'] = var_export($value, true);
                     }
                 }
                 $content = str_replace(array_keys($replace), array_values($replace), $content);
                 if ($configHandle = @fopen($configFile, 'wb')) {
                     $written = @fwrite($configHandle, $content);
                     @fclose($configHandle);
                 }
             }
         }
     }
     $perms = $this->install->settings->get('new_file_permissions', sprintf("%04o", 0666 & 0666 - umask()));
     if (is_string($perms)) {
         $perms = octdec($perms);
     }
     $chmodSuccess = @chmod($configFile, $perms);
     if ($written) {
         $this->addResult(modInstallRunner::RESULT_SUCCESS, '<p class="ok">' . $this->install->lexicon('config_file_written') . '</p>');
     } else {
         $this->addResult(modInstallRunner::RESULT_FAILURE, '<p class="notok">' . $this->install->lexicon('config_file_err_w') . '</p>');
     }
     if ($chmodSuccess) {
         $this->addResult(modInstallRunner::RESULT_SUCCESS, '<p class="ok">' . $this->install->lexicon('config_file_perms_set') . '</p>');
     } else {
         $this->addResult(modInstallRunner::RESULT_WARNING, '<p>' . $this->install->lexicon('config_file_perms_notset') . '</p>');
     }
     return $written;
 }
 /**
  * Handles connector requests.
  *
  * @param string $action
  */
 public function handle($action = '')
 {
     if (empty($_REQUEST['action'])) {
         $this->error->failure('No processor specified!');
     }
     $this->action = $_REQUEST['action'];
     if ($this->action !== 'database/connection') {
         $this->install->loadDriver();
     }
     $f = MODX_SETUP_PATH . 'processors/' . $this->action . '.php';
     if (!file_exists($f)) {
         $this->error->failure('Could not load requested processor for action ' . $this->action . '.');
     }
     $install =& $this->install;
     $install->loadSettings();
     $error =& $this->error;
     if (!@(include $f)) {
         $this->error->failure('Could not load requested processor for action ' . $this->action . '.');
     }
 }
 /**
  * Loads the Smarty parser
  *
  * @param string $class
  * @param string $path The path to the parser
  * @return boolean True if successful.
  */
 public function loadParser($class = 'parser.modInstallSmarty', $path = '')
 {
     $loaded = false;
     $className = $this->install->loadClass($class, $path);
     if (empty($className)) {
         if (!@(include MODX_SETUP_PATH . 'provisioner/bootstrap.php')) {
             die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure all the files in the MODX setup package have been uploaded to your server.</p></body></html>');
         }
         $loaded = false;
     }
     $this->parser = new $className();
     return $loaded;
 }
 /**
  * Writes the config file.
  *
  * @return boolean Returns true if successful; false otherwise.
  */
 public function writeConfig()
 {
     $written = false;
     $configTpl = MODX_CORE_PATH . 'docs/config.inc.tpl';
     $configFile = MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
     $settings = $this->install->settings->fetch();
     $settings['last_install_time'] = time();
     $settings['site_id'] = uniqid('modx', true);
     /* make UUID if not set */
     if (empty($settings['uuid'])) {
         $settings['uuid'] = $this->install->generateUUID();
     }
     if (file_exists($configTpl)) {
         if ($tplHandle = @fopen($configTpl, 'rb')) {
             $content = @fread($tplHandle, filesize($configTpl));
             @fclose($tplHandle);
             if ($content) {
                 $replace = array();
                 while (list($key, $value) = each($settings)) {
                     if (is_scalar($value)) {
                         $replace['{' . $key . '}'] = "{$value}";
                     } elseif (is_array($value)) {
                         $replace['{' . $key . '}'] = var_export($value, true);
                     }
                 }
                 $content = str_replace(array_keys($replace), array_values($replace), $content);
                 if ($configHandle = @fopen($configFile, 'wb')) {
                     $written = @fwrite($configHandle, $content);
                     @fclose($configHandle);
                 }
             }
         }
     }
     $perms = $this->install->settings->get('new_file_permissions', sprintf("%04o", 0666 & 0666 - umask()));
     if (is_string($perms)) {
         $perms = octdec($perms);
     }
     $chmodSuccess = @chmod($configFile, $perms);
     if ($written) {
         $this->addResult(modInstallRunner::RESULT_SUCCESS, '<p class="ok">' . $this->install->lexicon('config_file_written') . '</p>');
     } else {
         $this->addResult(modInstallRunner::RESULT_FAILURE, '<p class="notok">' . $this->install->lexicon('config_file_err_w') . '</p>');
     }
     if ($chmodSuccess) {
         $this->addResult(modInstallRunner::RESULT_SUCCESS, '<p class="ok">' . $this->install->lexicon('config_file_perms_set') . '</p>');
     } else {
         $this->addResult(modInstallRunner::RESULT_WARNING, '<p>' . $this->install->lexicon('config_file_perms_notset') . '</p>');
     }
     return $written;
 }
 /**
  * Check database settings
  * @return void
  */
 public function checkDatabase()
 {
     $mode = $this->settings->get('installmode');
     /* get an instance of xPDO using the install settings */
     $xpdo = $this->install->getConnection($mode);
     if (!is_object($xpdo) || !$xpdo instanceof xPDO) {
         $this->end($this->install->lexicon('xpdo_err_ins'));
     }
     /* try to get a connection to the actual database */
     $dbExists = $xpdo->connect();
     if (!$dbExists) {
         if ($mode == modInstall::MODE_NEW && $xpdo->getManager()) {
             /* otherwise try to create the database */
             $dbExists = $xpdo->manager->createSourceContainer(array('dbname' => $this->settings->get('dbase'), 'host' => $this->settings->get('database_server')), $this->settings->get('database_user'), $this->settings->get('database_password'), array('charset' => $this->settings->get('database_connection_charset'), 'collation' => $this->settings->get('database_collation')));
             if (!$dbExists) {
                 $this->end($this->install->lexicon('db_err_create_database'));
             } else {
                 $xpdo = $this->install->getConnection($mode);
                 if (!is_object($xpdo) || !$xpdo instanceof xPDO) {
                     $this->end($this->install->lexicon('xpdo_err_ins'));
                 }
             }
         } elseif ($mode == modInstall::MODE_NEW) {
             $this->end($this->install->lexicon('db_err_connect_server'));
         }
     }
     if (!$xpdo->connect()) {
         $this->end($this->install->lexicon('db_err_connect'));
     }
     /* test table prefix */
     if ($mode == modInstall::MODE_NEW || $mode == modInstall::MODE_UPGRADE_REVO_ADVANCED) {
         $count = null;
         $database = $this->settings->get('dbase');
         $prefix = $this->settings->get('table_prefix');
         $stmt = $xpdo->query($this->install->driver->testTablePrefix($database, $prefix));
         if ($stmt) {
             $row = $stmt->fetch(PDO::FETCH_ASSOC);
             if ($row) {
                 $count = (int) $row['ct'];
             }
             $stmt->closeCursor();
         }
         if ($mode == modInstall::MODE_NEW && $count !== null) {
             $this->end($this->install->lexicon('test_table_prefix_inuse'));
         } elseif ($mode == modInstall::MODE_UPGRADE_REVO_ADVANCED && $count === null) {
             $this->end($this->install->lexicon('test_table_prefix_nf'));
         }
     }
 }
예제 #7
0
} else {
    define('MODX_SETUP_URL', '/');
}
/* session loop-back tester */
if (!$isCommandLine && (!isset($_GET['s']) || $_GET['s'] != 'set') && !isset($_SESSION['session_test'])) {
    $_SESSION['session_test'] = 1;
    echo "<html><head><title>Loading...</title><script>window.location.href='" . MODX_SETUP_URL . "?s=set';</script></head><body></body></html>";
    exit;
} elseif (!$isCommandLine && isset($_GET['s']) && $_GET['s'] == 'set' && !isset($_SESSION['session_test'])) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure your PHP session configuration is valid and working.</p></body></html>');
}
$setupPath = strtr(realpath(dirname(__FILE__)), '\\', '/') . '/';
define('MODX_SETUP_PATH', $setupPath);
$installPath = strtr(realpath(dirname(dirname(__FILE__))), '\\', '/') . '/';
define('MODX_INSTALL_PATH', $installPath);
if (!(include MODX_SETUP_PATH . 'includes/config.core.php')) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/config.core.php file is missing.</p></body></html>');
}
if (!(include MODX_SETUP_PATH . 'includes/modinstall.class.php')) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/modinstall.class.php file is missing.</p></body></html>');
}
$modInstall = new modInstall();
if ($modInstall->getService('lexicon', 'modInstallLexicon')) {
    $modInstall->lexicon->load('default');
}
$modInstall->findCore();
$modInstall->doPreloadChecks();
$requestClass = $isCommandLine ? 'request.modInstallCLIRequest' : 'request.modInstallRequest';
$modInstall->getService('request', $requestClass);
echo $modInstall->request->handle();
exit;
예제 #8
0
/* session loop-back tester */
if ((!isset($_GET['s']) || $_GET['s'] != 'set') && !isset($_SESSION['session_test'])) {
    $_SESSION['session_test']= 1;
    echo "<html><head><title>Loading...</title><script>window.location.href='" . MODX_SETUP_URL . "?s=set';</script></head><body></body></html>";
    exit ();
} elseif (isset($_GET['s']) && $_GET['s'] == 'set' && !isset($_SESSION['session_test'])) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure your PHP session configuration is valid and working.</p></body></html>');
}

$setupPath= strtr(realpath(dirname(__FILE__)), '\\', '/') . '/';
define('MODX_SETUP_PATH', $setupPath);
$installPath= strtr(realpath(dirname(dirname(__FILE__))), '\\', '/') . '/';
define('MODX_INSTALL_PATH', $installPath);

if (!include(MODX_SETUP_PATH . 'includes/config.core.php')) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/config.core.php file is missing.</p></body></html>');
}
if (!include(MODX_SETUP_PATH . 'includes/modinstall.class.php')) {
    die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/modinstall.class.php file is missing.</p></body></html>');
}
$modInstall = new modInstall();
if ($modInstall->loadLexicon()) {
    $modInstall->lexicon->load('default');
}
$modInstall->findCore();
$modInstall->doPreloadChecks();
$modInstall->loadRequestHandler();
$modInstall->request->loadParser();
echo $modInstall->request->handle();
exit();
예제 #9
0
<?php

/**
 * Handles AJAX requests
 *
 * @package setup
 */
/* do a little bit of environment cleanup if possible */
@ini_set('magic_quotes_runtime', 0);
@ini_set('magic_quotes_sybase', 0);
/* start session */
session_start();
/* set error reporting */
error_reporting(E_ALL & ~E_NOTICE);
$setupPath = strtr(realpath(dirname(dirname(__FILE__))), '\\', '/') . '/';
define('MODX_SETUP_PATH', $setupPath);
$installPath = strtr(realpath(dirname(dirname(dirname(__FILE__)))), '\\', '/') . '/';
define('MODX_INSTALL_PATH', $installPath);
if (!@(include MODX_SETUP_PATH . 'includes/config.core.php')) {
    die('Error loading core files!');
}
require_once MODX_CORE_PATH . 'xpdo/xpdo.class.php';
require_once MODX_SETUP_PATH . 'includes/modinstall.class.php';
$install = new modInstall();
$install->getService('lexicon', 'modInstallLexicon');
$install->lexicon->load('default');
$install->getService('request', 'request.modInstallConnectorRequest');
$install->request->handle();
@session_write_close();
exit;
예제 #10
0
<?php

/**
 * Handles AJAX requests
 *
 * @package setup
 */
/* do a little bit of environment cleanup if possible */
@ini_set('magic_quotes_runtime', 0);
@ini_set('magic_quotes_sybase', 0);
/* start session */
session_start();
/* set error reporting */
error_reporting(E_ALL & ~E_NOTICE);
$setupPath = strtr(realpath(dirname(dirname(__FILE__))), '\\', '/') . '/';
define('MODX_SETUP_PATH', $setupPath);
$installPath = strtr(realpath(dirname(dirname(dirname(__FILE__)))), '\\', '/') . '/';
define('MODX_INSTALL_PATH', $installPath);
if (!@(include MODX_SETUP_PATH . 'includes/config.core.php')) {
    die('Error loading core files!');
}
require_once MODX_CORE_PATH . 'xpdo/xpdo.class.php';
require_once MODX_SETUP_PATH . 'includes/modinstall.class.php';
$install = new modInstall();
$install->loadLexicon();
$install->lexicon->load('default');
$install->loadRequestHandler('modInstallConnector');
$install->request->handle();