From fd5ed6acea2aae4b1961271f7e6991cb2a097135 Mon Sep 17 00:00:00 2001 From: Ronald Q Date: Fri, 4 Nov 2016 17:10:36 -0400 Subject: [PATCH] HOR-2230 create new workspace message in name with more than 30 characters fix in messages --- workflow/engine/bin/tasks/cliWorkspaces.php | 5 ++++ workflow/engine/classes/class.Installer.php | 19 +++++++------ workflow/engine/classes/class.wsTools.php | 28 +++++++++++++++---- workflow/engine/controllers/installer.php | 14 ++++++---- .../engine/templates/installer/newSite.js | 2 +- workflow/engine/templates/setup/newSite.js | 2 +- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index c15b79754..d1399771d 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -604,6 +604,11 @@ function run_workspace_restore($args, $opts) { G::verifyPath(PATH_DATA . 'upgrade', true); + if(isset($args[1]) && strlen($args[1])>=30){ + eprintln("Invalid workspace name, insert a maximum of 30 characters.", 'red'); + return; + } + if (strpos($filename, "/") === false && strpos($filename, '\\') === false) { $filename = PATH_DATA . "backups/$filename"; if (!file_exists($filename) && substr_compare($filename, ".tar", -4, 4, true) != 0) diff --git a/workflow/engine/classes/class.Installer.php b/workflow/engine/classes/class.Installer.php index 850710a92..0dab68cc4 100644 --- a/workflow/engine/classes/class.Installer.php +++ b/workflow/engine/classes/class.Installer.php @@ -139,6 +139,7 @@ class Installer $islocal = (strcmp(substr($this->options['database']['hostname'], 0, strlen('localhost')), 'localhost') === 0) || (strcmp(substr($this->options['database']['hostname'], 0, strlen('127.0.0.1')), '127.0.0.1') === 0); $this->wf_site_name = $wf = $this->options['advanced']['ao_db_wf']; + $this->wf_user_db = isset($this->options['advanced']['ao_user_wf'])?$this->options['advanced']['ao_user_wf']:uniqid('wf_'); $this->rbac_site_name = $rb = $this->options['advanced']['ao_db_rb']; $this->report_site_name = $rp = $this->options['advanced']['ao_db_rp']; @@ -156,7 +157,7 @@ class Installer if ($this->cc_status == 1) { $host = ($islocal) ? "localhost" : "%"; - $this->run_query("GRANT ALL PRIVILEGES ON `$wf`.* TO $wf@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user $wf on database $wf"); + $this->run_query("GRANT ALL PRIVILEGES ON `$wf`.* TO {$this->wf_user_db}@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$this->wf_user_db} on database $wf"); } /* Dump schema workflow && data */ @@ -182,12 +183,12 @@ class Installer $workspace = $this->options['name']; $endpoint = sprintf( - '%s://%s/sys%s/%s/%s/oauth2/grant', - $http, - $host, - $workspace, - $lang, - SYS_SKIN + '%s://%s/sys%s/%s/%s/oauth2/grant', + $http, + $host, + $workspace, + $lang, + SYS_SKIN ); // inserting the outh_client @@ -227,9 +228,9 @@ class Installer //Generate the db.php file $db_file = $path_site . 'db.php'; - $db_text = "options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_NAME', '" . $wf . "' );\n" . "define ('DB_USER', '" . (($this->cc_status == 1) ? $wf : $this->options['database']['username']) . "' );\n" . "define ('DB_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_RBAC_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_RBAC_NAME', '" . $rb . "' );\n" . "define ('DB_RBAC_USER', '" . (($this->cc_status == 1) ? $rb : $this->options['database']['username']) . "' );\n" . "define ('DB_RBAC_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_REPORT_NAME', '" . $rp . "' );\n" . "define ('DB_REPORT_USER', '" . (($this->cc_status == 1) ? $rp : $this->options['database']['username']) . "' );\n" . "define ('DB_REPORT_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n"; + $db_text = "options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_NAME', '" . $wf . "' );\n" . "define ('DB_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_RBAC_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_RBAC_NAME', '" . $rb . "' );\n" . "define ('DB_RBAC_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_RBAC_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_REPORT_NAME', '" . $rp . "' );\n" . "define ('DB_REPORT_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_REPORT_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n"; if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { - $db_text .= "define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG') && PARTNER_FLAG != '') ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG']:'false')) . ");\n"; + $db_text .= "define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG') && PARTNER_FLAG != '') ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG'] : 'false')) . ");\n"; if (defined('SYSTEM_NAME')) { $db_text .= " define ('SYSTEM_NAME', '" . SYSTEM_NAME . "');\n"; } diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index a141dad91..56d240a96 100644 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -233,9 +233,11 @@ class workspaceTools if ($this->onedb) { $dbInfo = $this->getDBInfo(); - $dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'wf_', 'DB_RBAC_USER' => 'wf_', 'DB_REPORT_NAME' => 'wf_', 'DB_REPORT_USER' => 'wf_'); + $dbPrefix = array('DB_NAME' => 'wf_', 'DB_RBAC_NAME' => 'wf_', 'DB_REPORT_NAME' => 'wf_'); + $dbPrefixUser = array('DB_USER' => 'wf_', 'DB_RBAC_USER' => 'wf_', 'DB_REPORT_USER' => 'wf_'); } else { - $dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'rb_', 'DB_RBAC_USER' => 'rb_', 'DB_REPORT_NAME' => 'rp_', 'DB_REPORT_USER' => 'rp_'); + $dbPrefix = array('DB_NAME' => 'wf_', 'DB_RBAC_NAME' => 'rb_', 'DB_REPORT_NAME' => 'rp_'); + $dbPrefixUser = array('DB_USER' => 'wf_', 'DB_RBAC_USER' => 'rb_', 'DB_REPORT_USER' => 'rp_'); } if (array_search($key, array('DB_HOST', 'DB_RBAC_HOST', 'DB_REPORT_HOST')) !== false) { @@ -261,6 +263,14 @@ class workspaceTools } $this->resetDBDiff[$value] = $dbName; $value = $dbName; + } elseif (array_key_exists($key, $dbPrefixUser)) { + if ($this->resetDBNames) { + $dbName = $this->dbGrantUser; + } else { + $dbName = $value; + } + $this->resetDBDiff['DB_USER'] = $dbName; + $value = $dbName; } return $matches[1] . $value . $matches[4]; } @@ -288,6 +298,10 @@ class workspaceTools $this->resetDBDiff = array(); $this->onedb = $onedb; $this->unify = $unify; + if ($resetDBNames) { + $this->dbGrantUser = uniqid('wf_'); + } + if (!$this->workspaceExists()) { throw new Exception("Could not find db.php in the workspace"); @@ -1716,8 +1730,10 @@ class workspaceTools foreach ($metadata->databases as $db) { if ($dbName != $newDBNames[$db->name]) { - $dbName = $newDBNames[$db->name]; - + $dbName = $dbUser = $newDBNames[$db->name]; + if(isset($newDBNames['DB_USER'])){ + $dbUser = $newDBNames['DB_USER']; + } if (mysql_select_db($dbName, $link)) { if (!$overwrite) { throw new Exception("Destination Database already exist (use -o to overwrite)"); @@ -1727,8 +1743,8 @@ class workspaceTools CLI::logging("+> Restoring database {$db->name} to $dbName\n"); $versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1; $workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine); - $workspace->createDBUser($dbName, $db->pass, "localhost", $dbName); - $workspace->createDBUser($dbName, $db->pass, "%", $dbName); + $workspace->createDBUser($dbUser, $db->pass, "localhost", $dbName); + $workspace->createDBUser($dbUser, $db->pass, "%", $dbName); } } diff --git a/workflow/engine/controllers/installer.php b/workflow/engine/controllers/installer.php index 59f018c44..70d4d0bc6 100644 --- a/workflow/engine/controllers/installer.php +++ b/workflow/engine/controllers/installer.php @@ -724,18 +724,20 @@ class Installer extends Controller // CREATE users and GRANT Privileges $wf_workpace = $wf; + $wfGrantUser = uniqid('wf_'); $rb_workpace = $wf; $rp_workpace = $wf; if (!$userLogged) { $wfPass = G::generate_password( 15 ); - $this->setGrantPrivilegesMySQL( $wf, $wfPass, $wf, $db_hostname ); - $this->setGrantPrivilegesMySQL( $rb, $wfPass, $wf, $db_hostname ); - $this->setGrantPrivilegesMySQL( $rp, $wfPass, $wf, $db_hostname ); + $this->setGrantPrivilegesMySQL( $wfGrantUser, $wfPass, $wf, $db_hostname ); + $this->setGrantPrivilegesMySQL( $wfGrantUser, $wfPass, $wf, $db_hostname ); + $this->setGrantPrivilegesMySQL( $wfGrantUser, $wfPass, $wf, $db_hostname ); } else { $wfPass = $db_password; $rbPass = $db_password; $rpPass = $db_password; $wf = $db_username; + $wfGrantUser = $db_username; $rb = $db_username; $rp = $db_username; } @@ -758,15 +760,15 @@ class Installer extends Controller $dbText .= sprintf( " define ('DB_ADAPTER', '%s' );\n", 'mysql' ); $dbText .= sprintf( " define ('DB_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_NAME', '%s' );\n", $wf_workpace ); - $dbText .= sprintf( " define ('DB_USER', '%s' );\n", $wf ); + $dbText .= sprintf( " define ('DB_USER', '%s' );\n", $wfGrantUser ); $dbText .= sprintf( " define ('DB_PASS', '%s' );\n", $wfPass ); $dbText .= sprintf( " define ('DB_RBAC_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_RBAC_NAME', '%s' );\n", $wf_workpace ); - $dbText .= sprintf( " define ('DB_RBAC_USER', '%s' );\n", $wf ); + $dbText .= sprintf( " define ('DB_RBAC_USER', '%s' );\n", $wfGrantUser ); $dbText .= sprintf( " define ('DB_RBAC_PASS', '%s' );\n", $wfPass ); $dbText .= sprintf( " define ('DB_REPORT_HOST', '%s' );\n", $db_host ); $dbText .= sprintf( " define ('DB_REPORT_NAME', '%s' );\n", $wf_workpace ); - $dbText .= sprintf( " define ('DB_REPORT_USER', '%s' );\n", $wf ); + $dbText .= sprintf( " define ('DB_REPORT_USER', '%s' );\n", $wfGrantUser ); $dbText .= sprintf( " define ('DB_REPORT_PASS', '%s' );\n", $wfPass ); if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) { diff --git a/workflow/engine/templates/installer/newSite.js b/workflow/engine/templates/installer/newSite.js index ecd403b07..134ad0820 100644 --- a/workflow/engine/templates/installer/newSite.js +++ b/workflow/engine/templates/installer/newSite.js @@ -308,7 +308,7 @@ Ext.onReady(function(){ xtype: 'textfield', fieldLabel: 'Workspace Name', value:'workflow', - maxLength: 29, + maxLength: 30, validator: function(v){ var t = /^[a-zA-Z_0-9]+$/; return t.test(v); diff --git a/workflow/engine/templates/setup/newSite.js b/workflow/engine/templates/setup/newSite.js index 680bef7b4..7306a1c56 100644 --- a/workflow/engine/templates/setup/newSite.js +++ b/workflow/engine/templates/setup/newSite.js @@ -13,7 +13,7 @@ Ext.onReady(function(){ xtype:'textfield', value:'sample', width: 200, - autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '13'}, + autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '30'}, allowBlank: false, listeners: { 'render': function(c) {