diff --git a/workflow/engine/bin/lurana-installer b/workflow/engine/bin/lurana-installer index 011cc46b0..de2131b08 100755 Binary files a/workflow/engine/bin/lurana-installer and b/workflow/engine/bin/lurana-installer differ diff --git a/workflow/engine/controllers/InstallerModule.php b/workflow/engine/controllers/InstallerModule.php index de52cde13..9216869b0 100644 --- a/workflow/engine/controllers/InstallerModule.php +++ b/workflow/engine/controllers/InstallerModule.php @@ -78,60 +78,10 @@ class InstallerModule extends Controller $this->includeExtJS('installer/installer_cards'); $this->includeExtJS('installer/main', false); - $this->setJSVar('licenseTxt', $licenseContent); - - $this->setJSVar('path_config', $this->path_config); - $this->setJSVar('path_languages', $this->path_languages); - $this->setJSVar('path_plugins', $this->path_plugins); - $this->setJSVar('path_xmlforms', $this->path_xmlforms); - $this->setJSVar('path_public', $this->path_public); - $this->setJSVar('path_shared', $this->path_shared); - $this->setJSVar('path_sep', $this->path_sep); - $this->setJSVar('path_translations', $this->path_translations); - $this->setJSVar('path_translationsMafe', $this->path_translationsMafe); - $this->setView('installer/main'); G::RenderPage('publish', 'extJs'); } - /** - * This function can be create a new workspace - * The user need permission PM_SETUP_ADVANCE for this action - * @return void - */ - public function newSite() - { - if (!$this->pmIsInstalled()) { - $textStep1 = G::LoadTranslation('ID_PROCESSMAKER_REQUIREMENTS_DESCRIPTION_STEP4_1'); - $textStep2 = G::LoadTranslation('ID_PROCESSMAKER_REQUIREMENTS_DESCRIPTION_STEP5'); - - $this->includeExtJS('installer/CardLayout', false); - $this->includeExtJS('installer/Wizard', false); - $this->includeExtJS('installer/Header', false); - $this->includeExtJS('installer/Card', false); - $this->includeExtJS('installer/newSite', false); - $this->setJSVar('textStep1', $textStep1); - $this->setJSVar('textStep2', $textStep2); - $this->setJSVar('DB_ADAPTER', DB_ADAPTER); - $aux = explode(':', DB_HOST); - $this->setJSVar('DB_HOST', $aux[0]); - $this->setJSVar('DB_PORT', isset($aux[1]) ? $aux[1] : '3306'); - $this->setJSVar('DB_NAME', 'workflow'); - $this->setJSVar('DB_USER', ''); - $this->setJSVar('DB_PASS', ''); - $this->setJSVar('pathConfig', PATH_CORE . 'config' . PATH_SEP); - $this->setJSVar('pathLanguages', PATH_LANGUAGECONT); - $this->setJSVar('pathPlugins', PATH_PLUGINS); - $this->setJSVar('pathXmlforms', PATH_XMLFORM); - $this->setJSVar('pathShared', PATH_DATA); - $this->setView('installer/newSite'); - - G::RenderPage('publish', 'extJs'); - } else { - $this->displayError(); - } - } - /** * Set config connection * @@ -473,45 +423,6 @@ class InstallerModule extends Controller return true; } - /** - * function to create a workspace - * in fact this function is calling appropriate functions for mysql - * need permission PM_SETUP_ADVANCE for this action - * @return stdClass information create a workspace. - */ - public function createWorkspace() - { - if (!$this->pmIsInstalled()) { - $pathSharedPartner = trim($_REQUEST['pathShared']); - if (file_exists(trim($pathSharedPartner, PATH_SEP) . PATH_SEP . 'partner.info')) { - $this->systemName = $this->getSystemName($pathSharedPartner); - $_REQUEST['PARTNER_FLAG'] = true; - } - $this->setResponseType('json'); - $info = new StdClass(); - try { - $info = $this->createMySQLWorkspace(); - } catch (Exception $e) { - $info->result = false; - $info->message = G::LoadTranslation('DBCONNECTIONS_MSGA'); - } - - return $info; - } else { - $this->displayError(); - } - } - - /** - * We check if processMaker is not installed - * - * @return boolean - */ - private function pmIsInstalled() - { - return file_exists(FILE_PATHS_INSTALLED); - } - /** * Display an error when processMaker is already installed * @@ -600,287 +511,6 @@ class InstallerModule extends Controller return true; } - /** - * set Grant Privileges for MySQL - * - * @param string $psUser - * @param string $psPassword - * @param string $psDatabase - * @param string $host - * - * @throws Exception - */ - private function setGrantPrivilegesMySQL($psUser, $psPassword, $psDatabase, $host) - { - try { - $host = $host === 'localhost' || $host === '127.0.0.1' ? 'localhost' : '%'; - - $query = "CREATE USER '$psUser'@'$host' IDENTIFIED WITH mysql_native_password BY '$psPassword'"; - DB::connection(self::CONNECTION_INSTALL) - ->statement($query); - - $query = "GRANT ALL PRIVILEGES ON `$psDatabase`.* TO '$psUser'@'$host' WITH GRANT OPTION"; - DB::connection(self::CONNECTION_INSTALL) - ->statement($query); - - $this->installLog($query); - - } catch (QueryException $e) { - $this->installLog(G::LoadTranslation('ID_MYSQL_ERROR', SYS_LANG, [$e->getMessage()])); - throw new Exception($e->getMessage()); - } - } - - /** - * Create a workspace in a MySQL database - * - * @return StdClass object - */ - public function createMySQLWorkspace() - { - $filter = new InputFilter(); - ini_set('max_execution_time', '0'); - $info = new StdClass(); - $info->result = false; - $info->message = ''; - $info->canRedirect = true; - - $db_hostname = trim($_REQUEST['db_hostname']); - - $db_port = trim($_REQUEST['db_port']); - $db_port = $filter->validateInput($db_port); - - $db_username = trim($_REQUEST['db_username']); - $db_username = $filter->validateInput($db_username); - - $db_password = urlencode(trim($_REQUEST['db_password'])); - $db_password = urldecode($filter->validateInput($db_password)); - - $wf = trim($_REQUEST['wfDatabase']); - - $workspace = trim($_REQUEST['workspace']); - - $pathShared = trim($_REQUEST['pathShared']); - - $adminPassword = trim($_REQUEST['adminPassword']); - $adminPassword = $filter->validateInput($adminPassword); - - $adminUsername = trim($_REQUEST['adminUsername']); - $adminUsername = $filter->validateInput($adminUsername); - - $deleteDB = $_REQUEST['deleteDB'] === 'true'; - - $userLogged = isset($_REQUEST['userLogged']) ? $_REQUEST['userLogged'] === 'true' : false; - $userLogged = $filter->validateInput($userLogged); - - if (substr($pathShared, -1) !== '/') { - $pathShared .= '/'; - } - - $this->installLog('-------------------------------------------'); - $this->installLog(G::LoadTranslation('ID_CREATING_WORKSPACE', SYS_LANG, [$workspace])); - - try { - $db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname; - - $envFile = PATH_CONFIG . 'env.ini'; - - $sysConf = System::getSystemConfiguration($envFile); - - $langUri = 'en'; - if (isset($sysConf['default_lang'])) { - $langUri = $sysConf['default_lang']; - } - - $skinUri = 'lurana'; - if (isset($sysConf['default_skin'])) { - $skinUri = $sysConf['default_skin']; - } - - $updatedConf['default_lang'] = $langUri; - $updatedConf['default_skin'] = $skinUri; - $info->uri = PATH_SEP . 'sys' . $_REQUEST['workspace'] . PATH_SEP . $langUri . PATH_SEP . $skinUri . PATH_SEP . 'login' . PATH_SEP . 'login'; - - $http = G::is_https() ? 'https' : 'http'; - $host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] !== '80' ? ':' . $_SERVER['SERVER_PORT'] : ''); - - $endpoint = sprintf( - '%s://%s/sys%s/%s/%s/oauth2/grant', - $http, - $host, - $workspace, - $langUri, - $skinUri - ); - - - $pythonCliExecutablePath = PATH_HOME . 'engine/bin/lurana-installer'; - - $command = [ - escapeshellarg($pythonCliExecutablePath), - 'start', - "--host=" . ($db_hostname . ':' . $db_port), - "--workspace=" . $wf, - "--user=" . $db_username, - "--pass=" . $db_password, - "--admin-username=" . $adminUsername, - "--admin-password=" . $adminPassword, - "--endpoint=" . escapeshellarg($endpoint), - "--path-shared=" . escapeshellarg($pathShared), - "--file-paths-installed=" . escapeshellarg(FILE_PATHS_INSTALLED), - "--path-gulliver=" . escapeshellarg(PATH_GULLIVER), - "--path-data=" . escapeshellarg(PATH_DATA) - ]; - - if ($deleteDB) { - $command[] = "--deleted-db"; - } - - if ($userLogged) { - $command[] = "--user-logged"; - } - - - $output = []; - $return_var = 0; - $command_string = implode(' ', $command); - - $this->installLog("Executing Python CLI (Alembic Only):\n" . $command_string); - exec($command_string, $output, $return_var); - - if ($return_var !== 0) { - $info->result = false; - $error_message = "Python CLI for Alembic failed:\n" . implode("\n", $output); - $info->message = $error_message; - $this->installLog($error_message); - } else { - $this->installLog("Python CLI (Alembic Only) completed successfully."); - } - - if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { - $this->setPartner(); - } - - $indexFileUpdated = true; - if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { - $this->buildParternExtras($adminUsername, $adminPassword, $_REQUEST['workspace'], $langUri, $skinUri); - } else { - try { - G::update_php_ini($envFile, $updatedConf); - } catch (Exception $e) { - $info->result = false; - $info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, [$envFile]); - $info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL'); - $this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, ['env.ini'])); - return $info; - } - - try { - // update the main index file - $indexFileUpdated = System::updateIndexFile(['lang' => 'en', 'skin' => $updatedConf['default_skin']]); - } catch (Exception $e) { - $info->result = false; - $info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, [PATH_HTML . "index.html."]); - $info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL'); - $this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, ['index.html'])); - return $info; - } - } - - $this->installLog(G::LoadTranslation('ID_INDEX_FILE_UPDATED', SYS_LANG, [$indexFileUpdated, $sysConf['default_lang'], $sysConf['default_skin']])); - $this->installLog(G::LoadTranslation('ID_INSTALL_SUCESS')); - - $info->result = true; - $info->message = G::LoadTranslation('ID_INSTALL_SUCESS'); - $info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, [$workspace]); - } catch (Exception $e) { - $info->canRedirect = false; - $info->result = false; - $info->message = $e->getMessage(); - } - return $info; - } - - public function getSystemName($siteShared) - { - $systemName = ''; - if (substr($siteShared, -1) != '/') { - $siteShared .= '/'; - } - - if (file_exists($siteShared . 'partner.info')) { - $dataInfo = parse_ini_file($siteShared . 'partner.info'); - if (isset($dataInfo['system_name'])) { - $systemName = trim($dataInfo['system_name']); - } - } - return $systemName; - } - - /** - * Get the Database engines list - * - * @return object - */ - public function getEngines() - { - $this->setResponseType('json'); - $engines = []; - if (function_exists('mysqli_query')) { - $engine = new stdclass(); - $engine->id = 'mysql'; - $engine->label = 'MySQL'; - $engines[] = $engine; - } - return $engines; - } - - public function checkDatabases() - { - $filter = new InputFilter(); - $this->setResponseType('json'); - $info = new stdclass(); - - $db_hostname = $filter->validateInput($_REQUEST['db_hostname']); - $db_username = $filter->validateInput($_REQUEST['db_username']); - $db_password = urlencode($_REQUEST['db_password']); - $db_password = urldecode($filter->validateInput($db_password)); - $db_port = $filter->validateInput($_REQUEST['db_port']); - - switch ($_REQUEST['db_engine']) { - case 'mysql': - $wfDatabase = $filter->validateInput($_REQUEST['wfDatabase'], 'nosql'); - - self::setNewConnection(self::CONNECTION_TEST_INSTALL, $db_hostname, $db_username, $db_password, '', $db_port); - $response = DB::connection(self::CONNECTION_TEST_INSTALL) - ->select("show databases like '$wfDatabase'"); - - $info->wfDatabaseExists = count($response) > 0; - break; - case 'sqlsrv': - $arguments = [ - 'UID' => $db_username, - 'PWD' => $db_password, - 'CharacterSet' => 'UTF-8', - 'Encrypt' => true, - 'TrustServerCertificate' => true - ]; - $link = @sqlsrv_connect($db_hostname, $arguments); - $wfDatabase = $filter->validateInput($_REQUEST['wfDatabase'], 'nosql'); - $query = "select * from sys.databases where name = '%s' "; - $query = $filter->preventSqlInjection($query, array($wfDatabase)); - $dataSet = @sqlsrv_query($link, $query); - $info->wfDatabaseExists = (@sqlsrv_num_rows($dataSet) > 0); - break; - default: - break; - } - - $info->errMessage = G::LoadTranslation('ID_DATABASE_EXISTS_OVERWRITE'); - - return $info; - } - /** * Privates functions section, non callable by http request */ @@ -928,255 +558,7 @@ class InstallerModule extends Controller } return $info; } - - /** - * This function define the partner behaviour when the PARTNER_FLAG is defined - * Execute to change of skin - * - * @return void - */ - private function setPartner() - { - if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { - // Execute sql for partner - $pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP; - if (G::verifyPath($pathMysqlPartner)) { - $filesSlq = glob($pathMysqlPartner . '*.sql'); - foreach ($filesSlq as $value) { - $this->mysqlFileQuery($value); - } - } - - // Execute to change of skin - $pathSkinPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'skin' . PATH_SEP; - if (G::verifyPath($pathSkinPartner)) { - $fileTar = glob($pathSkinPartner . '*.tar'); - foreach ($fileTar as $value) { - $dataFile = pathinfo($value); - $nameSkinTmp = $dataFile['filename']; - - $tar = new Archive_Tar($value); - - $pathSkinTmp = $pathSkinPartner . 'tmp' . PATH_SEP; - G::rm_dir($pathSkinTmp); - G::verifyPath($pathSkinTmp, true); - chmod($pathSkinTmp, 0777); - $tar->extract($pathSkinTmp); - - $pathSkinName = $pathSkinTmp . $nameSkinTmp . PATH_SEP; - chmod($pathSkinName, 0777); - G::verifyPath(PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp', true); - $skinClassic = PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp' . PATH_SEP; - - if (is_dir($pathSkinName)) { - $this->copyFile($pathSkinName, $skinClassic); - } - - G::rm_dir(PATH_CORE . 'skinEngine' . PATH_SEP . 'base'); - rename(PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp', PATH_CORE . 'skinEngine' . PATH_SEP . 'base'); - G::rm_dir(PATH_CORE . 'skinEngine' . PATH_SEP . 'tmp'); - - break; - } - } - } - } - - /** - * Copy a directory or file - * - * @param string $fromDir - * @param string $toDir - * @param integer $chmod - * - * @return void - */ - public function copyFile($fromDir, $toDir, $chmod = 0777) - { - $errors = []; - $messages = []; - - if (!is_writable($toDir)) { - $errors[] = 'target ' . $toDir . ' is not writable'; - } - if (!is_dir($toDir)) { - $errors[] = 'target ' . $toDir . ' is not a directory'; - } - if (!is_dir($fromDir)) { - $errors[] = 'source ' . $fromDir . ' is not a directory'; - } - if (!empty($errors)) { - return false; - } - - $exceptions = array('.', '..'); - $handle = opendir($fromDir); - while (false !== ($item = readdir($handle))) { - if (!in_array($item, $exceptions)) { - $from = str_replace('//', '/', $fromDir . '/' . $item); - $to = str_replace('//', '/', $toDir . '/' . $item); - if (is_file($from)) { - if (@copy($from, $to)) { - chmod($to, $chmod); - touch($to, filemtime($from)); - } - } - - if (is_dir($from)) { - if (@mkdir($to)) { - chmod($to, $chmod); - } - $this->copyFile($from, $to, $chmod); - } - } - } - - closedir($handle); - } - - /** - * Define build Pattern Extras related to: - * Upload translation .po file - * Upload skin file - * Upload plugin file - * - * @param string $username - * @param string $password - * @param string $workspace - * @param string $lang - * @param string $skinName - * - * @return void - */ - private function buildParternExtras($username, $password, $workspace, $lang, $skinName) - { - $filter = new InputFilter(); - ini_set('max_execution_time', '0'); - - $serv = 'http://'; - if (isset($_SERVER['HTTPS']) && !empty(trim($_SERVER['HTTPS']))) { - $serv = 'https://'; - } - $serv .= $_SERVER['SERVER_NAME']; - if (isset($_SERVER['SERVER_PORT']) && !empty(trim($_SERVER['SERVER_PORT']))) { - $serv .= ':' . $_SERVER['SERVER_PORT']; - } - - // create session - $cookiefile = sys_get_temp_dir() . PATH_SEP . 'curl-session'; - - $fp = fopen($cookiefile, "w"); - fclose($fp); - chmod($cookiefile, 0777); - - $user = urlencode($username); - $user = $filter->validateInput($user); - $pass = urlencode($password); - $pass = $filter->validateInput($pass); - $lang = urlencode($lang); - $lang = $filter->validateInput($lang); - - $ch = curl_init(); - - // set URL and other appropriate options - curl_setopt($ch, CURLOPT_URL, "$serv/sys{$workspace}/{$lang}/{$skinName}/login/authentication"); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, "form[USR_USERNAME]=$user&form[USR_PASSWORD]=$pass&form[USER_LANG]=$lang"); - curl_setopt($ch, CURLOPT_TIMEOUT, 90); - - $output = curl_exec($ch); - curl_close($ch); - - /** - * Upload translation .po file - */ - - $ch = curl_init(); - $postData = []; - // File to upload/post - - $postData['form[LANGUAGE_FILENAME]'] = "@" . PATH_CORE . "content/translations/processmaker.$lang.po"; - curl_setopt($ch, CURLOPT_URL, "$serv/sys{$workspace}/{$lang}/{$skinName}/setup/languages_Import"); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($ch, CURLOPT_TIMEOUT, 90); - - $output = curl_exec($ch); - curl_close($ch); - - /** - * Upload skin file - */ - - $ch = curl_init(); - $postData = []; - - $skins = glob(PATH_CORE . "data/partner/*.tar"); - if (count($skins) > 0) { - $skin = $skins[0]; - - $postData['overwrite_files'] = "on"; - $postData['workspace'] = "global"; - $postData['option'] = "standardupload"; - $postData['action'] = "importSkin"; - // File to upload/post - $postData['uploadedFile'] = "@" . $skin; - - curl_setopt($ch, CURLOPT_URL, "$serv/sys{$workspace}/{$lang}/{$skinName}/setup/skin_Ajax"); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($ch, CURLOPT_TIMEOUT, 90); - - $output = curl_exec($ch); - curl_close($ch); - } - - /** - * Upload plugin file - */ - - $ch = curl_init(); - $postData = []; - // resolv the plugin name - $plugins = glob(PATH_CORE . "plugins/*.tar"); - if (count($plugins) > 0) { - $pluginName = $plugins[0]; - - // File to upload/post - $postData['form[PLUGIN_FILENAME]'] = "@{$pluginName}"; - curl_setopt($ch, CURLOPT_URL, "$serv/sys{$workspace}/{$lang}/{$skinName}/setup/pluginsImportFile"); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($ch, CURLOPT_TIMEOUT, 90); - - $output = curl_exec($ch); - curl_close($ch); - } - } - + /** * Verify/create framework shared directory structure *