From 2a76c828a07a5ed3e3c21f93b633bf9930b74024 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Fri, 28 Mar 2014 17:37:32 +0200 Subject: [PATCH 1/2] installer changes --- install/core/Installer.php | 183 ++++++++++------- .../core/{SystemTest.php => SystemHelper.php} | 140 +++++++++++-- install/core/actions/finish.php | 15 ++ install/core/actions/setPreferences.php | 2 +- install/core/actions/settingsTest.php | 24 ++- install/core/i18n/en_US.php | 51 ++++- install/core/init/records.php | 20 ++ install/core/tpl/errors.tpl | 11 +- install/core/tpl/finish.tpl | 7 + install/core/tpl/step3.tpl | 11 +- install/index.php | 18 +- install/js/install.js | 188 ++++++++++++------ 12 files changed, 489 insertions(+), 181 deletions(-) rename install/core/{SystemTest.php => SystemHelper.php} (56%) create mode 100644 install/core/init/records.php diff --git a/install/core/Installer.php b/install/core/Installer.php index 06ff5c3468..f43244f290 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -18,13 +18,16 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ +use Espo\Core\Utils\Util; class Installer { protected $app = null; - protected $i18n = null; + protected $i18n = null; + + protected $systemHelper = null; protected $isAuth = false; @@ -36,10 +39,10 @@ class Installer /** * Ajax Urls, pairs: url:directory (if bad permission) - * + * * @var array */ - protected $ajaxUrls = array( + protected $ajaxUrls = array( 'api/v1/Settings' => 'api', 'api/v1' => 'api', 'client/res/templates/login.tpl' => 'client/res/templates', @@ -53,9 +56,9 @@ class Installer 'weekStart', 'defaultCurrency' => array( 'currencyList', 'defaultCurrency', - ), - 'smtpSecurity', - 'language', + ), + 'smtpSecurity', + 'language', ); @@ -67,6 +70,9 @@ class Installer $user = $this->getEntityManager()->getEntity('User'); $this->app->getContainer()->setUser($user); + + require_once('install/core/SystemHelper.php'); + $this->systemHelper = new SystemHelper(); } protected function getEntityManager() @@ -74,17 +80,22 @@ class Installer return $this->app->getContainer()->get('entityManager'); } + protected function getSystemHelper() + { + return $this->systemHelper; + } + protected function auth() { if (!$this->isAuth) { $auth = new \Espo\Core\Utils\Auth($this->app->getContainer()); - $auth->useNoAuth(); + $auth->useNoAuth(); $this->isAuth = true; - } + } - return $this->isAuth; + return $this->isAuth; } public function isInstalled() @@ -101,7 +112,7 @@ class Installer protected function getI18n() { if (!isset($this->i18n)) { - $this->i18n = $this->app->getContainer()->get('i18n'); + $this->i18n = $this->app->getContainer()->get('i18n'); } return $this->i18n; @@ -112,16 +123,16 @@ class Installer $config = $this->app->getContainer()->get('config'); $languageList = $config->get('languageList'); - - $translated = $this->getI18n()->translate('language', 'options', 'Global', $languageList); + + $translated = $this->getI18n()->translate('language', 'options', 'Global', $languageList); return $translated; } /** - * Save data - * - * @param array $database + * Save data + * + * @param array $database * array ( * 'driver' => 'pdo_mysql', * 'host' => 'localhost', @@ -129,16 +140,19 @@ class Installer * 'user' => 'root', * 'password' => '', * ), - * @param string $language - * @return bool + * @param string $language + * @return bool */ public function saveData($database, $language) { $initData = include('install/core/init/config.php'); + $siteUrl = $this->getSystemHelper()->getBaseUrl(); + $data = array( - 'database' => $database, - 'language' => $language, + 'database' => $database, + 'language' => $language, + 'siteUrl' => $siteUrl, ); $data = array_merge($data, $initData); @@ -151,7 +165,7 @@ class Installer public function saveConfig($data) { $config = $this->app->getContainer()->get('config'); - + $result = $config->set($data); return $result; @@ -162,7 +176,7 @@ class Installer { try { $this->app->getContainer()->get('schema')->rebuild(); - } catch (\Exception $e) { + } catch (\Exception $e) { } @@ -176,44 +190,73 @@ class Installer return $this->saveConfig($preferences); } + protected function createRecords() + { + $records = include('install/core/init/records.php'); + + $result = true; + foreach ($records as $entityName => $recordList) { + foreach ($recordList as $data) { + $result &= $this->createRecord($entityName, $data); + } + } + + return $result; + } + + protected function createRecord($entityName, $data) + { + if (isset($data['id'])) { + + $entity = $this->getEntityManager()->getEntity($entityName, $data['id']); + + if (!isset($entity)) { + $pdo = $this->getEntityManager()->getPDO(); + + $sql = "SELECT id FROM `".Util::toUnderScore($entityName)."` WHERE `id` = '".$data['id']."'"; + $sth = $pdo->prepare($sql); + $sth->execute(); + + $deletedEntity = $sth->fetch(\PDO::FETCH_ASSOC); + + if ($deletedEntity) { + $sql = "UPDATE `".Util::toUnderScore($entityName)."` SET deleted = '0' WHERE `id` = '".$data['id']."'"; + $pdo->prepare($sql)->execute(); + + $entity = $this->getEntityManager()->getEntity($entityName, $data['id']); + } + } + } + + if (!isset($entity)) { + $entity = $this->getEntityManager()->getEntity($entityName); + } + + $entity->set($data); + + $id = $this->getEntityManager()->saveEntity($entity); + + return is_string($id); + } + + public function createUser($userName, $password) { $this->auth(); - $userId = '1'; + $user = array( + 'id' => '1', + 'userName' => $userName, + 'password' => md5($password), + 'lastName' => 'Admin', + 'isAdmin' => '1', + ); - $entity = $this->getEntityManager()->getEntity('User', $userId); + $result = $this->createRecord('User', $user); - if (!isset($entity)) { - $pdo = $this->getEntityManager()->getPDO(); + $result &= $this->createRecords(); - $sql = "SELECT id FROM `user` WHERE `id` = '".$userId."'"; - $sth = $pdo->prepare($sql); - $sth->execute(); - - $deletedUser = $sth->fetch(\PDO::FETCH_ASSOC); - - if ($deletedUser) { - $sql = "UPDATE `user` SET deleted = '0' WHERE `id` = '".$userId."'"; - $pdo->prepare($sql)->execute(); - - $entity = $this->getEntityManager()->getEntity('User', $userId); - } - } - - if (!isset($entity)) { - $entity = $this->getEntityManager()->getEntity('User'); - $entity->set('id', $userId); - } - - $entity->set('userName', $userName); - $entity->set('password', md5($password)); - $entity->set('lastName', 'Admin'); - $entity->set('isAdmin', '1'); - - $userId = $this->getEntityManager()->saveEntity($entity); - - return is_string($userId); + return $result; } public function isWritable() @@ -228,15 +271,15 @@ class Installer if (!file_exists($item)) { $item = $fileManager->getDirName($item); } - + if (file_exists($item) && !is_writable($item)) { $fileManager->getPermissionUtils()->setDefaultPermissions($item); if (!is_writable($item)) { $result = false; $this->writableListError[] = $item; - } - } + } + } } return $result; @@ -260,14 +303,14 @@ class Installer $uniqueList = array_unique($this->ajaxUrls); foreach ($uniqueList as $url => $path) { $result = $fileManager->getPermissionUtils()->chmod($path, $permission, true); - } - } else { + } + } else { if (isset($this->ajaxUrls[$url])) { - $path = $this->ajaxUrls[$url]; + $path = $this->ajaxUrls[$url]; $result = $fileManager->getPermissionUtils()->chmod($path, $permission, true); } - } - + } + return $result; } @@ -282,9 +325,9 @@ class Installer public function getSettingDefaults() { - $defaults = array(); + $defaults = array(); - $settingDefs = $this->app->getMetadata()->get('entityDefs.Settings.fields'); + $settingDefs = $this->app->getMetadata()->get('entityDefs.Settings.fields'); foreach ($this->settingList as $fieldName => $field) { @@ -292,19 +335,19 @@ class Installer $fieldDefaults = array(); foreach ($field as $subField) { if (isset($settingDefs[$subField])) { - $fieldDefaults = array_merge($fieldDefaults, $this->translateSetting($subField, $settingDefs[$subField])); + $fieldDefaults = array_merge($fieldDefaults, $this->translateSetting($subField, $settingDefs[$subField])); } } $defaults[$fieldName] = $fieldDefaults; } else if (isset($settingDefs[$field])) { - $defaults[$field] = $this->translateSetting($field, $settingDefs[$field]); + $defaults[$field] = $this->translateSetting($field, $settingDefs[$field]); } } if (isset($defaults['language'])) { - $defaults['language']['options'] = $this->getLanguageList(); + $defaults['language']['options'] = $this->getLanguageList(); } return $defaults; @@ -316,7 +359,7 @@ class Installer $optionLabel = $this->getI18n()->translate($name, 'options', 'Settings'); if ($optionLabel == $name) { - $optionLabel = $this->getI18n()->translate($name, 'options', 'Global'); + $optionLabel = $this->getI18n()->translate($name, 'options', 'Global'); } if ($optionLabel == $name) { @@ -326,9 +369,9 @@ class Installer } } - $settingDefs['options'] = $optionLabel; - } - + $settingDefs['options'] = $optionLabel; + } + return $settingDefs; } diff --git a/install/core/SystemTest.php b/install/core/SystemHelper.php similarity index 56% rename from install/core/SystemTest.php rename to install/core/SystemHelper.php index 893dd3f198..95ca7f1819 100644 --- a/install/core/SystemTest.php +++ b/install/core/SystemHelper.php @@ -18,28 +18,30 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ -class SystemTest +class SystemHelper { protected $requirements = array( 'phpVersion' => '5.4', - + 'exts' => array( 'json', 'mcrypt', ), ); - - + + protected $modRewriteUrl = '/api/v1/Metadata'; + + public function __construct() { - + } - - + + public function checkRequirements() { $result['success'] = true; @@ -57,14 +59,14 @@ class SystemTest } } } - + return $result; } - - function checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql') + + public function checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql') { $result['success'] = true; - + switch ($dbDriver) { case 'mysqli': $mysqli = new mysqli($hostName, $dbUserName, $dbUserPass, $dbName); @@ -77,36 +79,138 @@ class SystemTest $result['success'] = false; } break; - + case 'pdo_mysql': try { $dbh = new PDO("mysql:host={$hostName};dbname={$dbName}", $dbUserName, $dbUserPass); $dbh = null; } catch (PDOException $e) { - + $result['errors']['dbConnect']['errorCode'] = $e->getCode(); $result['errors']['dbConnect']['errorMsg'] = $e->getMessage(); $result['success'] = false; } break; } - + return $result; } - + public function checkModRewrite() { if ( function_exists('apache_get_modules') && in_array('mod_rewrite',apache_get_modules()) ) { return true; } elseif (isset($_SERVER['IIS_UrlRewriteModule'])) { - return true; + return true; } elseif (getenv('ESPO_MR')=='On' ) { return true; } elseif (isset($_SERVER['ESPO_MR'])) { return true; + } elseif ($this->checkModRewriteByUrl()) { + return true; } - + + return false; + } + + protected function checkModRewriteByUrl() + { + $url = $this->getBaseUrl().$this->modRewriteUrl; + + if (!$this->isCurl()) { + $httpCode = $this->getHttpCodeByCurl($url); + } + + $httpCode = $this->getHttpCodeByHeader($url); + + if ($httpCode != false && !empty($httpCode)) { + if ($httpCode == '200' || $httpCode == '401') { + return true; + } + } + return false; } + public function getModRewriteUrl() + { + return $this->modRewriteUrl; + } + + protected function getHttpCodeByCurl($url) + { + $ch = curl_init($url); + + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + if ($response != false && !empty($httpCode)) { + return $httpCode; + } + + return false; + } + + protected function getHttpCodeByHeader($url) + { + stream_context_set_default( + array( + 'http' => array( + 'timeout' => 3.0, + ) + ) + ); + $headers = get_headers($url); + + if ($headers != false) { + + preg_match('/HTTP.*([0-9]{3})/i', $headers[0], $match); + + return $httpCode = trim($match[1]); + } + + return false; + } + + protected function isCurl() + { + return function_exists('curl_version'); + } + + public function getBaseUrl() + { + $pageUrl = ($_SERVER["HTTPS"] == 'on') ? 'https://' : 'http://'; + + if ($_SERVER["SERVER_PORT"] != "80") { + $pageUrl .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; + } else { + $pageUrl .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; + } + + $baseUrl = str_ireplace('/install/index.php', '', $pageUrl); + + return $baseUrl; + } + + + /** + * Get web server name + * + * @return string Ex. "microsoft-iis", "nginx", "apache" + */ + public function getServerType() + { + $serverSoft = $_SERVER['SERVER_SOFTWARE']; + + preg_match('/^(.*)\//i', $serverSoft, $match); + $serverName = strtolower( trim($match[1]) ); + + return $serverName; + } + } diff --git a/install/core/actions/finish.php b/install/core/actions/finish.php index 9773f9362e..0307c00ab8 100644 --- a/install/core/actions/finish.php +++ b/install/core/actions/finish.php @@ -19,7 +19,22 @@ * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. ************************************************************************/ + + +$serverType = $systemHelper->getServerType(); +$rootDir = dirname(__FILE__); +$rootDir = preg_replace('/\/install\/core\/actions\/?/', '', $rootDir, 1); +$cronFile = $rootDir.'/cron.php'; +$phpBinDir = (defined("PHP_BINDIR"))? PHP_BINDIR.'/php' : 'php'; + +$cronHelp = (isset($langs['cronHelp'][$serverType]))? $langs['cronHelp'][$serverType] : $langs['cronHelp']['default']; +$cronHelp = str_replace('', $cronFile, $cronHelp); +$cronHelp = str_replace('', $phpBinDir, $cronHelp); +$cronTitle = (isset($langs['cronTitle'][$serverType]))? $langs['cronTitle'][$serverType] : $langs['cronTitle']['default']; + +$smarty->assign('cronTitle', $cronTitle); +$smarty->assign('cronHelp', $cronHelp); // clean session $installer->setSuccess(); session_unset(); \ No newline at end of file diff --git a/install/core/actions/setPreferences.php b/install/core/actions/setPreferences.php index 032f705bda..231a17c79a 100644 --- a/install/core/actions/setPreferences.php +++ b/install/core/actions/setPreferences.php @@ -28,7 +28,7 @@ if (!empty($_SESSION['install'])) {// required fields //['user-name']) && !empty 'dateFormat' => $_SESSION['install']['dateFormat'], 'timeFormat' => $_SESSION['install']['timeFormat'], 'timeZone' => $_SESSION['install']['timeZone'], - 'weekStart' => $_SESSION['install']['weekStart'], + 'weekStart' => (int)$_SESSION['install']['weekStart'], 'defaultCurrency' => $_SESSION['install']['defaultCurrency'], 'thousandSeparator' => $_SESSION['install']['thousandSeparator'], 'decimalMark' => $_SESSION['install']['decimalMark'], diff --git a/install/core/actions/settingsTest.php b/install/core/actions/settingsTest.php index 95e43a4c89..bb4c1fdfc0 100644 --- a/install/core/actions/settingsTest.php +++ b/install/core/actions/settingsTest.php @@ -18,38 +18,44 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ ob_start(); $result = array('success' => true, 'errors' => array()); -$res = $systemTest->checkRequirements(); +$res = $systemHelper->checkRequirements(); $result['success'] &= $res['success']; if (!empty($res['errors'])) { $result['errors'] = array_merge($result['errors'], $res['errors']); } -if (!$systemTest->checkModRewrite()) { +/*if (!$systemHelper->checkModRewrite()) { $result['success'] = false; - $result['errors']['modRewrite'] = 'Enable mod_rewrite in Apache server'; -} + $result['errors']['modRewrite'] = $langs['modRewriteHelp']['default']; + + $serverType = $systemHelper->getServerType(); + if (isset($langs['modRewriteHelp'][$serverType])) { + $result['errors']['modRewrite'] = $langs['modRewriteHelp'][$serverType]; + } +}*/ + if (!empty($_REQUEST['dbName']) && !empty($_REQUEST['hostName']) && !empty($_REQUEST['dbUserName'])) { $connect = false; - + $dbName = $_REQUEST['dbName']; $hostName = $_REQUEST['hostName']; $dbUserName = $_REQUEST['dbUserName']; $dbUserPass = $_REQUEST['dbUserPass']; $dbDriver = (!empty($_REQUEST['dbDriver']))? $_REQUEST['dbDriver'] : 'pdo_mysql'; - - $res = $systemTest->checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver); + + $res = $systemHelper->checkDbConnection($hostName, $dbUserName, $dbUserPass, $dbName, $dbDriver); $result['success'] &= $res['success']; if (!empty($res['errors'])) { $result['errors'] = array_merge($result['errors'], $res['errors']); } - + } ob_clean(); diff --git a/install/core/i18n/en_US.php b/install/core/i18n/en_US.php index cbad535fa6..50b550acf8 100644 --- a/install/core/i18n/en_US.php +++ b/install/core/i18n/en_US.php @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ return array( 'Main page title' => 'Welcome to EspoCRM', @@ -44,7 +44,7 @@ return array( 'Congratulation! Welcome to EspoCRM!' => 'Congratulation! EspoCRM has been successfully installed.', 'admin' => 'admin', 'localhost' => 'localhost', - + 'Locale' => 'Locale', 'Outbound Email Configuration' => 'Outbound Email Configuration', 'SMTP' => 'SMTP', @@ -60,7 +60,7 @@ return array( 'Default Currency' => 'Default Currency', 'Currency List' => 'Currency List', 'Language' => 'Language', - + 'smtpServer' => 'Server', 'smtpPort' => 'Port', 'smtpAuth' => 'Auth', @@ -68,8 +68,8 @@ return array( 'smtpUsername' => 'Username', 'emailAddress' => 'Email', 'smtpPassword' => 'Password', - - + + // messages 'Some errors occurred!' => 'Some errors occurred!', 'Supported php version >=' => 'Supported php version >=', @@ -90,11 +90,46 @@ return array( 'Permission denied' => 'Permission denied', 'Cannot write to files' => 'Cannot write to file(s)', 'Can not save settings' => 'Can not save settings', - + 'Cannot save preferences' => 'Cannot save preferences', + 'db driver' => array( 'mysqli' => 'MySQLi', 'pdo_mysql' => 'PDO MySQL', - ), + ), + + 'modRewriteHelp' => array( + 'apache' => 'Enable "mod_rewrite" in Apache server', + 'nginx' => 'Add this code to Nginx Host Config (inside "server" block):
+
+location /api/v1/ {
+    if (!-e $request_filename){
+        rewrite ^/api/v1/(.*)$ /api/v1/index.php last; break;
+    }
+}
+
+location / {
+    rewrite reset/?$ reset.html break;
+}
', + 'microsoft-iis' => 'Enable "URL Rewrite" Module in IIS server', + 'default' => 'Enable Rewrite Module in your server (e.g. mod_rewrite in Apache)', + ), + + 'cronTitle' => array( + 'apache' => 'To Setup Crontab:', + 'nginx' => 'To Setup Crontab:', + 'microsoft-iis' => 'To Setup Scheduled Task:', + 'default' => 'To Setup Cron job:', + ), + + 'cronHelp' => array( + 'apache' => 'Note: Add this line to the crontab file to run Espo Scheduled Jobs: +* * * * * -f > /dev/null 2>&1', + 'nginx' => 'Note: Add this line to Tasks to run Espo Scheduled Jobs: +* * * * * -f > /dev/null 2>&1', + 'microsoft-iis' => 'Note: Create a batch file with the following commands to run Espo Scheduled Jobs using Windows Scheduled Tasks: +.exe -f ', + 'default' => 'Run command ', + ), // controll 'Start' => 'Start', @@ -103,7 +138,7 @@ return array( 'Go to EspoCRM' => 'Go to EspoCRM', 'Re-check' => 'Re-check', 'Test settings' => 'Test Connection', - + // db errors '1049' => 'Unknown database', '2005' => 'Unknown MySQL server host', diff --git a/install/core/init/records.php b/install/core/init/records.php new file mode 100644 index 0000000000..2e5530b8ae --- /dev/null +++ b/install/core/init/records.php @@ -0,0 +1,20 @@ + array( + 0 => array( + 'name' => 'Case-to-Email auto-reply', + 'subject' => 'Case has been created', + 'body' => '

Hi {Person.name}

Case \'{Case.name}\' has been created with number \'{Case.number}\' and assigned to {User.name}.

', + 'isHtml ' => '1', + ), + ), + 'ScheduledJob' => array( + 0 => array( + 'name' => 'Check Inbound Emails', + 'job' => 'CheckInboundEmails', + 'status' => 'Active', + 'scheduling' => '/10 * * * *', + ), + ), +); \ No newline at end of file diff --git a/install/core/tpl/errors.tpl b/install/core/tpl/errors.tpl index 17cbe7f46d..3b99bc6629 100644 --- a/install/core/tpl/errors.tpl +++ b/install/core/tpl/errors.tpl @@ -20,10 +20,15 @@ {literal} $(function(){ {/literal} - var langs = {$langsJs}; - var ajaxUrls = {$ajaxUrls}; + var opt = { + action: 'errors', + langs: {$langsJs}, + ajaxUrls: {$ajaxUrls}, + modRewriteUrl: '{$modRewriteUrl}', + serverType: '{$serverType}' + } {literal} - var installScript = new InstallScript({action: 'errors', langs: langs, ajaxUrls: ajaxUrls}); + var installScript = new InstallScript(opt); }) {/literal} \ No newline at end of file diff --git a/install/core/tpl/finish.tpl b/install/core/tpl/finish.tpl index 3ac033f961..d98923e632 100644 --- a/install/core/tpl/finish.tpl +++ b/install/core/tpl/finish.tpl @@ -12,6 +12,13 @@ + +{if $cronHelp} + {$cronTitle} +
+{$cronHelp}
+
+{/if}
diff --git a/install/core/tpl/step3.tpl b/install/core/tpl/step3.tpl index 29a8a04568..26b27274fd 100644 --- a/install/core/tpl/step3.tpl +++ b/install/core/tpl/step3.tpl @@ -47,10 +47,15 @@ {literal} $(function(){ {/literal} - var langs = {$langsJs}; - var ajaxUrls = {$ajaxUrls}; + var opt = { + action: 'step3', + langs: {$langsJs}, + ajaxUrls: {$ajaxUrls}, + modRewriteUrl: '{$modRewriteUrl}', + serverType: '{$serverType}' + } {literal} - var installScript = new InstallScript({action: 'step3', langs: langs, ajaxUrls: ajaxUrls}); + var installScript = new InstallScript(opt); }) {/literal} \ No newline at end of file diff --git a/install/index.php b/install/index.php index f77b77a890..6efa772936 100644 --- a/install/index.php +++ b/install/index.php @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ error_reporting(0); session_start(); @@ -29,7 +29,7 @@ require_once ('install/vendor/smarty/libs/Smarty.class.php'); require_once 'core/Installer.php'; -require_once 'core/SystemTest.php'; +require_once 'core/SystemHelper.php'; $smarty = new Smarty(); $installer = new Installer(); @@ -73,7 +73,7 @@ if (file_exists('install/'.$langFileName)) { $smarty->assign("langs", $langs); $smarty->assign("langsJs", json_encode($langs)); -$systemTest = new SystemTest(); +$systemHelper = new SystemHelper(); // include actions and set tpl name $tplName = 'main.tpl'; @@ -84,20 +84,24 @@ $action = (!empty($_REQUEST['action']))? $_REQUEST['action'] : 'main'; switch ($action) { case 'main': $languageList = $installer->getLanguageList(); - $smarty->assign("languageList", $languageList); + $smarty->assign("languageList", $languageList); break; case 'step3': case 'errors': $ajaxUrls = $installer->getAjaxUrls(); - $smarty->assign("ajaxUrls", json_encode($ajaxUrls)); + $smarty->assign("ajaxUrls", json_encode($ajaxUrls)); + $modRewriteUrl = $systemHelper->getModRewriteUrl(); + $smarty->assign("modRewriteUrl", $modRewriteUrl); + $serverType = $systemHelper->getServerType(); + $smarty->assign("serverType", $serverType); break; case 'step4': case 'errors': $settingsDefaults = $installer->getSettingDefaults(); - $smarty->assign("settingsDefaults", $settingsDefaults); - break; + $smarty->assign("settingsDefaults", $settingsDefaults); + break; } $actionFile = $actionsDir.'/'.$action.'.php'; diff --git a/install/js/install.js b/install/js/install.js index 863314360f..81a1905c78 100644 --- a/install/js/install.js +++ b/install/js/install.js @@ -17,40 +17,52 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ var InstallScript = function(opt) { this.reChecking = false; - + if (typeof(opt.action) !== 'undefined') { var action = opt.action; this.action = action; this[action](); } - + if (typeof(opt.langs) !== 'undefined') { this.langs = opt.langs; } - + if (typeof(opt.ajaxUrls) !== 'undefined') { this.ajaxUrls = opt.ajaxUrls; } - + + if (typeof(opt.modRewriteUrl) !== 'undefined') { + this.modRewriteUrl = opt.modRewriteUrl; + } + + if (typeof(opt.serverType) !== 'undefined') { + this.serverType = opt.serverType; + } + this.connSett = {}; this.userSett = {}; this.firstUserPreferences = {}; this.checkActions = [ + { + 'action': 'checkModRewrite', + 'break': true, + }, { 'action': 'checkWritable', 'break': true, - }, + }, { 'action': 'applySett', 'break': true, - }, + }, { 'action': 'buildDatabse', 'break': true, - }, + }, { 'action': 'createUser', 'break': true, @@ -67,12 +79,12 @@ var InstallScript = function(opt) { InstallScript.prototype.main = function() { var self = this; var nextAction = 'step1'; - + $("#start").click(function(){ $(this).attr('disabled', 'disabled'); self.goTo(nextAction); }) - + $('[name="user-lang"]').change(function(){ self.goTo(self.action); }) @@ -82,16 +94,16 @@ InstallScript.prototype.step1 = function() { var self = this; var backAction = 'main'; var nextAction = 'step2'; - + $('#back').click(function(){ $(this).attr('disabled', 'disabled'); self.goTo(backAction); }) - + $("#next").click(function(){ $(this).attr('disabled', 'disabled'); var licenseAgree = $('#license-agree'); - + if (licenseAgree.length > 0 && !licenseAgree.is(':checked')) { $(this).removeAttr('disabled'); self.showMsg({msg: self.getLang('You must agree to the license agreement'), error: true}); @@ -106,12 +118,12 @@ InstallScript.prototype.step2 = function() { var self = this; var backAction = 'step1'; var nextAction = 'step3'; - + $('#back').click(function(){ $(this).attr('disabled', 'disabled'); self.goTo(backAction); }) - + $('#test-connection, #next').click(function(){ $(this).attr('disabled', 'disabled'); self.setConnSett(); @@ -120,7 +132,7 @@ InstallScript.prototype.step2 = function() { return; } self.showLoading(); - + var btn = $(this); self.checkSett({ success: function(data) { @@ -139,9 +151,9 @@ InstallScript.prototype.step2 = function() { $('#test-connection').removeAttr('disabled'); self.hideLoading(); }, // success END - + }) // checkSett END - + }) } @@ -149,12 +161,12 @@ InstallScript.prototype.step3 = function() { var self = this; var backAction = 'step2'; var nextAction = 'step4'; - + $('#back').click(function(){ $(this).attr('disabled', 'disabled'); self.goTo(backAction); }) - + $("#next").click(function(){ $(this).attr('disabled', 'disabled'); self.setUserSett(); @@ -162,7 +174,7 @@ InstallScript.prototype.step3 = function() { $(this).removeAttr('disabled'); return; } - + self.checkPass({ success: function(){ self.showLoading(); @@ -181,12 +193,12 @@ InstallScript.prototype.step4 = function() { var self = this; var backAction = 'step3'; var nextAction = 'finish'; - + $('#back').click(function(){ $(this).attr('disabled', 'disabled'); self.goTo(backAction); }) - + $("#next").click(function(){ $(this).attr('disabled', 'disabled'); self.setFirstUserPreferences(); @@ -195,7 +207,7 @@ InstallScript.prototype.step4 = function() { return; } var data = self.firstUserPreferences; - + data.action = 'setPreferences'; $.ajax({ url: "index.php", @@ -209,15 +221,15 @@ InstallScript.prototype.step4 = function() { } }) .fail(function(ajaxData){ - + }) - + }) } InstallScript.prototype.errors = function() { var self = this; - + this.reChecking = true; var nextAction = ''; $("#re-check").click(function(){ @@ -229,7 +241,7 @@ InstallScript.prototype.errors = function() { InstallScript.prototype.finish = function() { var self = this; - + var nextAction = ''; $("#start").click(function(){ self.goToEspo(); @@ -274,7 +286,7 @@ InstallScript.prototype.setFirstUserPreferences = function() { InstallScript.prototype.checkSett = function(opt) { var self = this; this.hideMsg(); - + var data = this.connSett; data.action = 'settingsTest'; $.ajax({ @@ -295,7 +307,7 @@ InstallScript.prototype.checkSett = function(opt) { if (typeof(errors.phpVersion) !== 'undefined') { msg += self.getLang('Supported php version >=')+' '+errors.phpVersion+rowDelim; } - + if (typeof(errors.exts) !== 'undefined') { var exts = errors.exts; var len = exts.length; @@ -305,11 +317,11 @@ InstallScript.prototype.checkSett = function(opt) { msg += temp+rowDelim; } } - + if (typeof(errors.modRewrite) !== 'undefined') { - msg += self.getLang('Enable mod_rewrite in Apache server')+rowDelim; + msg += errors.modRewrite+rowDelim; } - + if (typeof(errors.dbConnect) !== 'undefined') { if (typeof(errors.dbConnect.errorCode) !== 'undefined') { var temp = self.getLang(errors.dbConnect.errorCode); @@ -321,13 +333,13 @@ InstallScript.prototype.checkSett = function(opt) { msg += temp+rowDelim; } } - + if (msg == '') { msg = self.getLang('Some errors occurred!'); } self.showMsg({msg: msg, error: true}); } - + opt.success(data); }) .fail(function(){ @@ -351,8 +363,8 @@ InstallScript.prototype.validate = function() { case 'step4': fieldRequired = ['thousandSeparator', 'decimalMark', 'smtpUsername']; break; - - + + } var len = fieldRequired.length; for (var index = 0; index < len; index++) { @@ -361,13 +373,13 @@ InstallScript.prototype.validate = function() { if (elem.val() == '') { elem.parent().parent().addClass('has-error'); valid = false; - } + } else { elem.parent().parent().removeClass('has-error'); } } } - + return valid; } @@ -376,62 +388,62 @@ InstallScript.prototype.setForm = function(opt) { var formId = opt.formId || 'nav'; var action = opt.action || 'main'; var desc = opt.desc || ''; - + var actionField = $('', {'name': 'action', 'value': action, 'type': 'hidden'}); $('#'+formId).append(actionField); var descField = $('