/** * Validates any data provided to the stage. * * @access public * @return bool|Jaws_Error Returns either true on success, or a Jaws_Error * containing the reason for failure. */ function Validate() { if ($_SESSION['install']['predefined']) { return true; } $request = Jaws_Request::getInstance(); $postReq = $request->fetch(array('secure', 'customize'), 'post'); $_SESSION['secure'] = !empty($postReq['secure']); $_SESSION['customize'] = !empty($postReq['customize']); // try to entering to secure transformation mode if ($_SESSION['secure'] && (!isset($_SESSION['pub_key']) || empty($_SESSION['pub_key']))) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $pkey = Jaws_Crypt::Generate_RSA_KeyPair(512); if (!Jaws_Error::isError($pkey)) { $_SESSION['pub_key'] = $pkey['pub_key']; $_SESSION['pvt_key'] = $pkey['pvt_key']; } else { return new Jaws_Error(_t('INSTALL_AUTH_ERROR_RSA_KEY_GENERATION'), 0, JAWS_ERROR_WARNING); } } $key_file = INSTALL_PATH . 'key.txt'; if (file_exists($key_file)) { $key = trim(file_get_contents($key_file)); if ($key === $_SESSION['install']['Authentication']['key']) { _log(JAWS_LOG_DEBUG, "Input log and session key match"); return true; } _log(JAWS_LOG_DEBUG, "The key found doesn't match the one below, please check that you entered the key correctly"); return new Jaws_Error(_t('INSTALL_AUTH_ERROR_KEY_MATCH', 'key.txt'), 0, JAWS_ERROR_WARNING); } _log(JAWS_LOG_DEBUG, "Your key file was not found, please make sure you created it, and the web server is able to read it."); return new Jaws_Error(_t('INSTALL_AUTH_ERROR_KEY_FILE', 'key.txt'), 0, JAWS_ERROR_WARNING); }
/** * Builds the installer page. * * @access public * @return string A block of valid XHTML to display an introduction and form. */ function Display() { _log(JAWS_LOG_DEBUG, "Preparing configuration file"); $tpl = new Jaws_Template(false, false); $tpl->Load('display.html', 'stages/WriteConfig/templates'); $tpl->SetBlock('WriteConfig'); $config_path = JAWS_PATH . 'config' . DIRECTORY_SEPARATOR; $tpl->setVariable('lbl_info', _t('INSTALL_CONFIG_INFO')); $tpl->setVariable('lbl_solution', _t('INSTALL_CONFIG_SOLUTION')); $tpl->setVariable('lbl_solution_permission', _t('INSTALL_CONFIG_SOLUTION_PERMISSION', $config_path)); $tpl->setVariable('lbl_solution_upload', _t('INSTALL_CONFIG_SOLUTION_UPLOAD', $config_path . 'JawsConfig.php')); $tpl->SetVariable('lbl_loglevel', _t('INSTALL_CONFIG_LOGLEVEL')); $tpl->SetVariable('next', _t('GLOBAL_NEXT')); $request = Jaws_Request::getInstance(); $loglevel = $request->fetch('loglevel', 'post'); $loglevel = is_null($loglevel) ? JAWS_LOG_ERROR : (int) $loglevel; $_SESSION['install']['LogLevel'] = $loglevel; $tpl->SetVariable('config', $this->BuildConfig()); $log_levels_messages = $GLOBALS['log']->_Log_Priority_Str; array_unshift($log_levels_messages, 'LOG_DISABLED'); foreach ($log_levels_messages as $level => $title) { $tpl->SetBlock('WriteConfig/loglevel'); $tpl->setVariable('level', $level); $tpl->setVariable('title', $title); $tpl->SetVariable('selected', $level == $loglevel ? 'selected="selected"' : ''); $tpl->ParseBlock('WriteConfig/loglevel'); } $tpl->ParseBlock('WriteConfig'); return $tpl->Get(); }
/** * Does any actions required to finish the stage. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $paths = array('jaws_data', 'jaws_base_data', 'jaws_themes', 'jaws_base_themes', 'jaws_cache'); $request = Jaws_Request::getInstance(); $postedData = $request->fetch($paths, 'post'); $postedData = array_filter($postedData); foreach ($paths as $path) { if (isset($postedData[$path])) { $_SESSION[strtoupper($path)] = $postedData[$path]; } else { unset($_SESSION[strtoupper($path)]); } } return true; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $keys = array_keys($this->_Defaults); $keys[] = 'dbpass'; $request = Jaws_Request::getInstance(); $post = $request->fetch($keys, 'post'); $post['dbpass'] = $request->fetch('dbpass', 'post', false); $request->reset(); if (isset($_SESSION['upgrade']['data']['Database'])) { $post = $_SESSION['upgrade']['data']['Database'] + $post; } if ($_SESSION['secure']) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $JCrypt = Jaws_Crypt::getInstance(array('pvt_key' => $_SESSION['pvt_key'], 'pub_key' => $_SESSION['pub_key'])); if (!Jaws_Error::isError($JCrypt)) { $post['dbpass'] = $JCrypt->decrypt($post['dbpass']); } else { return $JCrypt; } } if (substr($post['prefix'], -1) == '_') { $prefix = $post['prefix']; } elseif (strlen($post['prefix']) > 0) { $prefix = $post['prefix'] . '_'; } else { $prefix = $post['prefix']; } if (!empty($post['path'])) { if (DIRECTORY_SEPARATOR != '/') { $post['path'] = str_replace('/', '\\', $post['path']); } if (substr($post['path'], -1) != DIRECTORY_SEPARATOR) { $post['path'] .= DIRECTORY_SEPARATOR; } } $_SESSION['upgrade']['Database'] = array('user' => trim($post['user']), 'password' => $post['dbpass'], 'isdba' => !empty($post['isdba']) ? 'true' : 'false', 'name' => trim($post['name']), 'path' => trim($post['path']), 'host' => trim($post['host']), 'port' => trim($post['port']), 'prefix' => $prefix, 'driver' => $post['driver']); // Connect to database require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['upgrade']['Database']); if (Jaws_Error::IsError($objDatabase)) { _log(JAWS_LOG_DEBUG, "There was a problem connecting to the database, please check the details and try again"); return new Jaws_Error(_t('UPGRADE_DB_RESPONSE_CONNECT_FAILED'), 0, JAWS_ERROR_WARNING); } _log(JAWS_LOG_DEBUG, "Checking current database"); $sql = "SELECT * FROM [[registry]]"; $result = Jaws_DB::getInstance()->queryRow($sql); if (Jaws_Error::isError($result)) { _log(JAWS_LOG_DEBUG, "Something wrong happened while checking the current database, error is:"); _log(JAWS_LOG_DEBUG, $result->getMessage()); return new Jaws_Error($result->getMessage(), 0, JAWS_ERROR_ERROR); } _log(JAWS_LOG_DEBUG, "Connected to " . $_SESSION['upgrade']['Database']['driver'] . " database driver successfully."); return true; }
/** * Makes all validations to FS and PHP installation * * @access public * @return boolean If everything looks OK, we return true otherwise a Jaws_Error */ function Validate() { $request = Jaws_Request::getInstance(); $use_log = $request->fetch('use_log', 'post'); //Set main session-log vars if (isset($use_log)) { $_SESSION['use_log'] = $use_log === 'yes' ? JAWS_LOG_DEBUG : false; } else { unset($_SESSION['use_log']); } _log(JAWS_LOG_DEBUG, "Validating install requirements..."); if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<') == 1) { $text = _t('INSTALL_REQ_RESPONSE_PHP_VERSION', MIN_PHP_VERSION); $type = JAWS_ERROR_ERROR; _log(JAWS_LOG_DEBUG, $text); return new Jaws_Error($text, 0, $type); } if (!$this->_check_path('config', 'r')) { $text = _t('INSTALL_REQ_RESPONSE_DIR_PERMISSION', 'config'); $type = JAWS_ERROR_ERROR; } if (!$this->_check_path(JAWS_DATA, 'rw', '')) { if (isset($text)) { $text = _t('INSTALL_REQ_RESPONSE_DIR_PERMISSION', _t('INSTALL_REQ_BAD')); } else { $text = _t('INSTALL_REQ_RESPONSE_DIR_PERMISSION', 'data'); } $type = JAWS_ERROR_ERROR; } if (isset($text)) { _log(JAWS_LOG_DEBUG, $text); return new Jaws_Error($text, 0, $type); } $modules = get_loaded_extensions(); $modules = array_map('strtolower', $modules); $db_state = false; foreach (array_keys($this->_db_drivers) as $ext) { $db_state = $db_state || in_array($ext, $modules); } if (!$db_state) { $text = _t('INSTALL_REQ_RESPONSE_EXTENSION', implode(' | ', array_keys($this->_db_drivers))); $type = JAWS_ERROR_ERROR; _log(JAWS_LOG_DEBUG, $text); return new Jaws_Error($text, 0, $type); } if (!in_array('xml', $modules)) { $text = _t('INSTALL_REQ_RESPONSE_EXTENSION', 'XML'); $type = JAWS_ERROR_ERROR; _log(JAWS_LOG_DEBUG, $text); return new Jaws_Error($text, 0, $type); } return true; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $keys = array_keys($this->_Fields); $request = Jaws_Request::getInstance(); $post = $request->fetch($keys, 'post'); if (isset($_SESSION['install']['data']['Settings'])) { $post = $_SESSION['install']['data']['Settings'] + $post; } _log(JAWS_LOG_DEBUG, "Setting up main settings (site name, description, languages, copyrights, etc"); $settings = array(); $settings['site_name'] = $post['site_name']; $settings['site_slogan'] = $post['site_slogan']; $settings['site_author'] = $_SESSION['install']['CreateUser']['nickname']; $settings['copyright'] = date('Y') . ', ' . $post['site_name']; $settings['site_language'] = $post['site_language']; $settings['admin_language'] = $post['site_language']; $settings['site_email'] = $_SESSION['install']['CreateUser']['email']; foreach ($settings as $key => $value) { if (in_array($key, array('site_language', 'admin_language'))) { $GLOBALS['app']->Registry->update($key, $value, true, 'Settings'); } else { $GLOBALS['app']->Registry->update($key, $value, false, 'Settings'); } } if (!empty($post['site_sample'])) { // install sample gadgets/data $this->InstallSampleSite(); } return true; }
// Initialize the logger $_SESSION['use_log'] = isset($_SESSION['use_log']) ? $_SESSION['use_log'] : false; $logger = array('method' => 'LogToFile', 'options' => array('file' => JAWS_DATA . 'logs/.install.log')); require JAWS_PATH . 'include/Jaws/Log.php'; $GLOBALS['log'] = new Jaws_Log($_SESSION['use_log'], $logger); $GLOBALS['log']->Start(); require_once JAWS_PATH . 'include/Jaws/Const.php'; require_once JAWS_PATH . 'include/Jaws/Error.php'; require_once JAWS_PATH . 'include/Jaws/Utils.php'; require_once JAWS_PATH . 'include/Jaws/Gadget.php'; if (!isset($_SESSION['install'])) { $_SESSION['install'] = array('stage' => 0, 'lastStage' => array()); } // Lets handle our requests require JAWS_PATH . 'include/Jaws/Request.php'; $request = Jaws_Request::getInstance(); $lang = $request->fetch('language', 'post'); if (isset($lang)) { $_SESSION['install']['language'] = urlencode($lang); } elseif (!isset($_SESSION['install']['language'])) { $_SESSION['install']['language'] = 'en'; } include_once JAWS_PATH . 'include/Jaws/Translate.php'; $objTranslate = Jaws_Translate::getInstance(false); if (isset($_SESSION['install']['language'])) { $objTranslate->SetLanguage($_SESSION['install']['language']); } $objTranslate->LoadTranslation('Global'); $objTranslate->LoadTranslation('Install', JAWS_COMPONENT_INSTALL); require_once 'stagelist.php'; require_once 'JawsInstaller.php';
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $keys = array_keys($this->_Defaults); $keys[] = 'dbpass'; $request = Jaws_Request::getInstance(); $post = $request->fetch($keys, 'post'); $post['dbpass'] = $request->fetch('dbpass', 'post', false); $request->reset(); if (isset($_SESSION['install']['data']['Database'])) { $post = $_SESSION['install']['data']['Database'] + $post; } if ($_SESSION['secure']) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $JCrypt = Jaws_Crypt::getInstance(array('pvt_key' => $_SESSION['pvt_key'], 'pub_key' => $_SESSION['pub_key'])); if (!Jaws_Error::isError($JCrypt)) { $post['dbpass'] = $JCrypt->decrypt($post['dbpass']); } else { return $JCrypt; } } if (substr($post['prefix'], -1) == '_') { $prefix = $post['prefix']; } elseif (strlen($post['prefix']) > 0) { $prefix = $post['prefix'] . '_'; } else { $prefix = $post['prefix']; } if (!empty($post['path'])) { if (DIRECTORY_SEPARATOR != '/') { $post['path'] = str_replace('/', '\\', $post['path']); } if (substr($post['path'], -1) != DIRECTORY_SEPARATOR) { $post['path'] .= DIRECTORY_SEPARATOR; } } $_SESSION['install']['Database'] = array('user' => trim($post['user']), 'password' => $post['dbpass'], 'isdba' => !empty($post['isdba']) ? 'true' : 'false', 'name' => trim($post['name']), 'path' => trim($post['path']), 'host' => trim($post['host']), 'port' => trim($post['port']), 'prefix' => $prefix, 'driver' => $post['driver']); // Connect to database require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['install']['Database']); if (Jaws_Error::IsError($objDatabase)) { _log(JAWS_LOG_DEBUG, "There was a problem connecting to the database."); return new Jaws_Error(_t('INSTALL_DB_RESPONSE_CONNECT_FAILED'), 0, JAWS_ERROR_WARNING); } $variables = array(); $variables['timestamp'] = Jaws_DB::getInstance()->date(); $result = Jaws_DB::getInstance()->installSchema('Resources/schema/schema.xml', $variables); _log(JAWS_LOG_DEBUG, "Installing core schema"); if (Jaws_Error::isError($result)) { _log(JAWS_LOG_DEBUG, $result->getMessage()); return $result; } // Create application require_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); $GLOBALS['app']->loadPreferences(array('language' => $_SESSION['install']['language']), false); Jaws_Translate::getInstance()->LoadTranslation('Install', JAWS_COMPONENT_INSTALL); // registry keys $result = $GLOBALS['app']->Registry->insertAll(array(array('version', JAWS_VERSION), array('gadgets_installed_items', ','), array('gadgets_disabled_items', ','), array('gadgets_autoload_items', ','), array('plugins_installed_items', ','))); if (Jaws_Error::isError($result)) { _log(JAWS_LOG_DEBUG, $result->getMessage()); } $gadgets = array('Settings', 'ControlPanel', 'Components', 'UrlMapper', 'Layout', 'Users', 'Policy'); foreach ($gadgets as $gadget) { $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { _log(JAWS_LOG_DEBUG, "There was a problem installing core gadget: " . $gadget); return $objGadget; } $installer = $objGadget->installer->load(); $result = $installer->InstallGadget(); if (Jaws_Error::IsError($result)) { _log(JAWS_LOG_DEBUG, "There was a problem installing core gadget: " . $gadget); return $result; } } return true; }
/** * Parses a QUERY URI and if its valid it extracts the values from * it and creates $_GET variables for each value. * * @access public * @return bool True on success, or False on failure */ function Parse() { if (!$this->_enabled && !is_array($this->_maps)) { return false; } $request = Jaws_Request::getInstance(); //If no path info is given but request method is post if (empty($this->_request_uri) && $_SERVER['REQUEST_METHOD'] == 'POST') { return true; } if (strpos($this->_request_uri, '=') !== false) { return true; } $params = explode('/', $this->_request_uri); $matched_but_ignored = false; foreach ($this->_maps as $gadget => $maps) { foreach ($maps as $map) { $use_custom = !$this->_custom_precedence; $has_custom = !empty($map['custom_map']); for ($i = 1; $i <= 2; $i++) { $use_custom = !$use_custom; if ($use_custom) { if (!$has_custom) { continue; } $route = $map['custom_map']; $regexp = $map['custom_regexp']; $custom = true; } else { $route = $map['map']; $regexp = $map['regexp']; $custom = false; } $url = $this->_request_uri; $ext = $map['extension']; $ext = $ext == '.' ? $this->_extension : $ext; if (substr($url, -strlen($ext)) == $ext) { $url = substr($url, 0, -strlen($ext)); } if (preg_match($regexp, $url, $matches) == 1) { if ($this->_restrict_multimap) { if ($this->_custom_precedence && $has_custom && !$custom) { $matched_but_ignored = true; continue; } if (!$this->_custom_precedence && $custom) { $matched_but_ignored = true; continue; } } // Gadget/Action $request->update('gadget', $gadget, 'get'); $request->update('action', $map['action'], 'get'); // Params if (isset($map['params']) && is_array($map['params'])) { foreach ($map['params'] as $key => $value) { $request->update($key, $value, 'get'); } } // Variables preg_match_all('#{(\\w+)}#si', $route, $matches_vars); if (is_array($matches_vars)) { array_shift($matches); foreach ($matches as $key => $value) { $request->update($matches_vars[1][$key], rawurldecode($value), 'get'); } } return true; } } // for } //foreach maps } // foreach gadgets if ($matched_but_ignored) { return false; } /** * OK, no alias and map found, so lets parse the path directly. * The first rule: it should have at least one value (the gadget name) */ $params_count = count($params); if ($params_count >= 1) { if (!$this->_restrict_multimap || !$this->_enabled || !isset($params[1]) || !isset($this->_actions_maps[$params[0]][$params[1]])) { $request->update('gadget', $params[0], 'get'); if (isset($params[1])) { $request->update('action', $params[1], 'get'); } /** * If we have a request via POST we should take those values, not the GET ones * However, I'm not pretty sure if we should allow gadget and action being passed * with /, cause officially (HTTP) you can't do that (params are passed via & not /) * * Next params following gadget/action should be parsed only if they come from a * GET request */ //Ok, next values should be formed in pairs $params = array_slice($params, 2); $params_count = count($params); if ($params_count % 2 == 0) { for ($i = 0; $i < $params_count; $i += 2) { $request->update($params[$i], $params[$i + 1], 'get'); } } return true; } } return false; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $request = Jaws_Request::getInstance(); $post = $request->fetch(array('username', 'email', 'nickname', 'password'), 'post'); if (isset($_SESSION['install']['data']['CreateUser'])) { $post = $_SESSION['install']['data']['CreateUser'] + $post; } if ($_SESSION['secure']) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $JCrypt = Jaws_Crypt::getInstance(array('pvt_key' => $_SESSION['pvt_key'], 'pub_key' => $_SESSION['pub_key'])); if (!Jaws_Error::isError($JCrypt)) { $post['password'] = $JCrypt->decrypt($post['password']); } else { return $JCrypt; } } $_SESSION['install']['CreateUser'] = array('username' => $post['username'], 'email' => $post['email'], 'nickname' => $post['nickname']); require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['install']['Database']); #if (Jaws_Error::IsError($objDatabase)) { # return new Jaws_Error("There was a problem connecting to the database, please check the details and try again.", 0, JAWS_ERROR_WARNING); #} require_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); $GLOBALS['app']->loadPreferences(array('language' => $_SESSION['install']['language']), false); Jaws_Translate::getInstance()->LoadTranslation('Install', JAWS_COMPONENT_INSTALL); require_once JAWS_PATH . 'include/Jaws/User.php'; $userModel = new Jaws_User(); $userInfo = $userModel->GetUser($post['username']); if (!Jaws_Error::IsError($userInfo)) { //username exists if (isset($userInfo['username'])) { _log(JAWS_LOG_DEBUG, "Update existing user"); $res = $userModel->UpdateUser($userInfo['id'], array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'])); } else { _log(JAWS_LOG_DEBUG, "Adding first/new admin user to Jaws"); $res = $userModel->AddUser(array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'], 'superadmin' => true)); } } else { $res = $userInfo; } if (Jaws_Error::IsError($res)) { _log(JAWS_LOG_DEBUG, "There was a problem while creating your user:"); _log(JAWS_LOG_DEBUG, $res->GetMessage()); return new Jaws_Error(_t('INSTALL_USER_RESPONSE_CREATE_FAILED'), 0, JAWS_ERROR_ERROR); } return true; }