From 5e6bdf1b24e28e050e222086f43ac2bb96d42ccb Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Tue, 2 Jul 2013 23:58:26 +0530 Subject: [PATCH 01/31] Display menu items according to the user group configuration --- libraries/Menu.class.php | 104 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 8e1f9bce55..d74a56c6bb 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -99,17 +99,113 @@ class PMA_Menu { $tabs = array(); $url_params = array('db' => $this->_db); + $level = ''; + if (strlen($this->_table)) { $tabs = $this->_getTableTabs(); $url_params['table'] = $this->_table; + $level = 'table'; } else if (strlen($this->_db)) { $tabs = $this->_getDbTabs(); + $level = 'db'; } else { $tabs = $this->_getServerTabs(); + $level = 'server'; + } + + $allowedTabs = $this->_getAllowedTabs($level); + foreach ($tabs as $key => $value) { + if (! in_array($key, $allowedTabs)) { + unset($tabs[$key]); + } } return PMA_Util::getHtmlTabs($tabs, $url_params, 'topmenu', true); } + /** + * Returns a list of allowed tabs for the current user for the given level + * + * @param string $level 'server', 'db' or 'table' level + * + * @return array list of allowed tabs + */ + private function _getAllowedTabs($level) + { + $tabList = array( + 'server' => array( + 'databases', + 'sql', + 'status', + 'rights', + 'export', + 'import', + 'settings', + 'binlog', + 'replication', + 'vars', + 'charset', + 'plugins', + 'engine' + ), + 'db' => array( + 'structure', + 'sql', + 'search', + 'qbe', + 'export', + 'import', + 'operation', + 'privileges', + 'routines', + 'events', + 'triggers', + 'tracking', + 'designer' + ), + 'table' => array( + 'browse', + 'structure', + 'sql', + 'search', + 'insert', + 'export', + 'import', + 'operation', + 'tracking', + 'triggers' + ) + ); + + $allowedTabs = $tabList[$level]; + + if (strlen($GLOBALS['cfg']['Server']['pmadb']) + && strlen($GLOBALS['cfg']['Server']['users']) + && strlen($GLOBALS['cfg']['Server']['usergroups']) + ) { + $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']); + $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']); + + $sql_query = "SELECT * FROM " . $groupTable + . " WHERE `usergroup` = (SELECT usergroup FROM " + . $userTable . " WHERE `username` = '" + . $GLOBALS['cfg']['Server']['user'] . "')"; + + $result = PMA_queryAsControlUser($sql_query, false); + if ($result) { + $row = $GLOBALS['dbi']->fetchAssoc($result); + foreach ($allowedTabs as $key => $tab) { + $colName = $level . '_' . $tab; + if (isset($row[$colName]) && $row[$colName] == 'N') { + unset($allowedTabs[$key]); + } + } + } + } + return $allowedTabs; + } + /** * Returns the breadcrumbs as HTML * @@ -144,7 +240,7 @@ class PMA_Menu $GLOBALS['cfg']['TabsMode'], array('icons', 'both') ) - ) { + ) { $retval .= PMA_Util::getImage( 's_host.png', '', @@ -165,7 +261,7 @@ class PMA_Menu $GLOBALS['cfg']['TabsMode'], array('icons', 'both') ) - ) { + ) { $retval .= PMA_Util::getImage( 's_db.png', '', @@ -191,7 +287,7 @@ class PMA_Menu $GLOBALS['cfg']['TabsMode'], array('icons', 'both') ) - ) { + ) { $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png'; $retval .= PMA_Util::getImage( $icon, @@ -447,7 +543,7 @@ class PMA_Menu $is_superuser = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser(); $binary_logs = null; if (isset($GLOBALS['dbi']) - && (! defined('PMA_DRIZZLE') + && (! defined('PMA_DRIZZLE') || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE) ) ) { From 52619dde8d343868a79a98f8c65325bd414f7f9d Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 4 Jul 2013 10:12:28 +0530 Subject: [PATCH 02/31] SQL to create table for configurable menus --- examples/create_tables.sql | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/examples/create_tables.sql b/examples/create_tables.sql index c3a62a20af..52bc1abb73 100644 --- a/examples/create_tables.sql +++ b/examples/create_tables.sql @@ -239,3 +239,66 @@ CREATE TABLE IF NOT EXISTS `pma__userconfig` ( ) ENGINE=MyISAM COMMENT='User preferences storage for phpMyAdmin' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `pma__users` +-- + +CREATE TABLE IF NOT EXISTS `pma__users` ( + `username` varchar(64) NOT NULL, + `usergroup` varchar(64) NOT NULL, + PRIMARY KEY (`username`,`usergroup`) +) + ENGINE=MyISAM COMMENT='Users and their assignments to user groups' + DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `pma__user_groups` +-- + +CREATE TABLE IF NOT EXISTS `pma__user_groups` ( + `usergroup` varchar(64) NOT NULL, + `server_databases` enum('Y','N') NOT NULL DEFAULT 'N', + `server_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `server_status` enum('Y','N') NOT NULL DEFAULT 'N', + `server_rights` enum('Y','N') NOT NULL DEFAULT 'N', + `server_export` enum('Y','N') NOT NULL DEFAULT 'N', + `server_import` enum('Y','N') NOT NULL DEFAULT 'N', + `server_settings` enum('Y','N') NOT NULL DEFAULT 'N', + `server_binlog` enum('Y','N') NOT NULL DEFAULT 'N', + `server_replication` enum('Y','N') NOT NULL DEFAULT 'N', + `server_vars` enum('Y','N') NOT NULL DEFAULT 'N', + `server_charset` enum('Y','N') NOT NULL DEFAULT 'N', + `server_plugins` enum('Y','N') NOT NULL DEFAULT 'N', + `server_engine` enum('Y','N') NOT NULL DEFAULT 'N', + `db_structure` enum('Y','N') NOT NULL DEFAULT 'N', + `db_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `db_search` enum('Y','N') NOT NULL DEFAULT 'N', + `db_qbe` enum('Y','N') NOT NULL DEFAULT 'N', + `db_export` enum('Y','N') NOT NULL DEFAULT 'N', + `db_import` enum('Y','N') NOT NULL DEFAULT 'N', + `db_operation` enum('Y','N') NOT NULL DEFAULT 'N', + `db_privileges` enum('Y','N') NOT NULL DEFAULT 'N', + `db_routines` enum('Y','N') NOT NULL DEFAULT 'N', + `db_events` enum('Y','N') NOT NULL DEFAULT 'N', + `db_triggers` enum('Y','N') NOT NULL DEFAULT 'N', + `db_tracking` enum('Y','N') NOT NULL DEFAULT 'N', + `db_designer` enum('Y','N') NOT NULL DEFAULT 'N', + `table_browse` enum('Y','N') NOT NULL DEFAULT 'N', + `table_structure` enum('Y','N') NOT NULL DEFAULT 'N', + `table_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `table_search` enum('Y','N') NOT NULL DEFAULT 'N', + `table_insert` enum('Y','N') NOT NULL DEFAULT 'N', + `table_export` enum('Y','N') NOT NULL DEFAULT 'N', + `table_import` enum('Y','N') NOT NULL DEFAULT 'N', + `table_operation` enum('Y','N') NOT NULL DEFAULT 'N', + `table_tracking` enum('Y','N') NOT NULL DEFAULT 'N', + `table_triggers` enum('Y','N') NOT NULL DEFAULT 'N', + PRIMARY KEY (`usergroup`) +) + ENGINE=MyISAM COMMENT='User groups with configured menu items' + DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; From 57e563f00a0437c6804ab4c640ff005a6231bb13 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 4 Jul 2013 10:13:05 +0530 Subject: [PATCH 03/31] Add new tables to sample config file --- config.sample.inc.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.sample.inc.php b/config.sample.inc.php index 37a2f099b5..9f7dfcbe53 100644 --- a/config.sample.inc.php +++ b/config.sample.inc.php @@ -59,6 +59,8 @@ $cfg['Servers'][$i]['AllowNoPassword'] = false; // $cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords'; // $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; // $cfg['Servers'][$i]['recent'] = 'pma__recent'; +// $cfg['Servers'][$i]['users'] = 'pma__users'; +// $cfg['Servers'][$i]['usergroups'] = 'pma__user_groups'; /* Contrib / Swekey authentication */ // $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf'; From 0cc34a19cb1e846cd30cc5a52a47139afca8b4a5 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 00:20:09 +0530 Subject: [PATCH 04/31] SQL to generate tables for configurable menus feature for Drizzle --- examples/create_tables_drizzle.sql | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/examples/create_tables_drizzle.sql b/examples/create_tables_drizzle.sql index 21c24ca2bc..49a5407deb 100644 --- a/examples/create_tables_drizzle.sql +++ b/examples/create_tables_drizzle.sql @@ -226,3 +226,66 @@ CREATE TABLE IF NOT EXISTS `pma__userconfig` ( ) ENGINE=InnoDB COMMENT='User preferences storage for phpMyAdmin' COLLATE utf8_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `pma__users` +-- + +CREATE TABLE IF NOT EXISTS `pma__users` ( + `username` varchar(64) NOT NULL, + `usergroup` varchar(64) NOT NULL, + PRIMARY KEY (`username`,`usergroup`) +) + ENGINE=MyISAM COMMENT='Users and their assignments to user groups' + COLLATE utf8_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `pma__user_groups` +-- + +CREATE TABLE IF NOT EXISTS `pma__user_groups` ( + `usergroup` varchar(64) NOT NULL, + `server_databases` enum('Y','N') NOT NULL DEFAULT 'N', + `server_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `server_status` enum('Y','N') NOT NULL DEFAULT 'N', + `server_rights` enum('Y','N') NOT NULL DEFAULT 'N', + `server_export` enum('Y','N') NOT NULL DEFAULT 'N', + `server_import` enum('Y','N') NOT NULL DEFAULT 'N', + `server_settings` enum('Y','N') NOT NULL DEFAULT 'N', + `server_binlog` enum('Y','N') NOT NULL DEFAULT 'N', + `server_replication` enum('Y','N') NOT NULL DEFAULT 'N', + `server_vars` enum('Y','N') NOT NULL DEFAULT 'N', + `server_charset` enum('Y','N') NOT NULL DEFAULT 'N', + `server_plugins` enum('Y','N') NOT NULL DEFAULT 'N', + `server_engine` enum('Y','N') NOT NULL DEFAULT 'N', + `db_structure` enum('Y','N') NOT NULL DEFAULT 'N', + `db_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `db_search` enum('Y','N') NOT NULL DEFAULT 'N', + `db_qbe` enum('Y','N') NOT NULL DEFAULT 'N', + `db_export` enum('Y','N') NOT NULL DEFAULT 'N', + `db_import` enum('Y','N') NOT NULL DEFAULT 'N', + `db_operation` enum('Y','N') NOT NULL DEFAULT 'N', + `db_privileges` enum('Y','N') NOT NULL DEFAULT 'N', + `db_routines` enum('Y','N') NOT NULL DEFAULT 'N', + `db_events` enum('Y','N') NOT NULL DEFAULT 'N', + `db_triggers` enum('Y','N') NOT NULL DEFAULT 'N', + `db_tracking` enum('Y','N') NOT NULL DEFAULT 'N', + `db_designer` enum('Y','N') NOT NULL DEFAULT 'N', + `table_browse` enum('Y','N') NOT NULL DEFAULT 'N', + `table_structure` enum('Y','N') NOT NULL DEFAULT 'N', + `table_sql` enum('Y','N') NOT NULL DEFAULT 'N', + `table_search` enum('Y','N') NOT NULL DEFAULT 'N', + `table_insert` enum('Y','N') NOT NULL DEFAULT 'N', + `table_export` enum('Y','N') NOT NULL DEFAULT 'N', + `table_import` enum('Y','N') NOT NULL DEFAULT 'N', + `table_operation` enum('Y','N') NOT NULL DEFAULT 'N', + `table_tracking` enum('Y','N') NOT NULL DEFAULT 'N', + `table_triggers` enum('Y','N') NOT NULL DEFAULT 'N', + PRIMARY KEY (`usergroup`) +) + ENGINE=MyISAM COMMENT='User groups with configured menu items' + COLLATE utf8_bin; From e4f52e7d4c41ea638d6b469246aee7a00ed77ae1 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 10:28:22 +0530 Subject: [PATCH 05/31] Use empty to avoid notices --- libraries/Menu.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index d74a56c6bb..0de3c69319 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -178,9 +178,9 @@ class PMA_Menu $allowedTabs = $tabList[$level]; - if (strlen($GLOBALS['cfg']['Server']['pmadb']) - && strlen($GLOBALS['cfg']['Server']['users']) - && strlen($GLOBALS['cfg']['Server']['usergroups']) + if (! empty($GLOBALS['cfg']['Server']['pmadb']) + && ! empty($GLOBALS['cfg']['Server']['users']) + && ! empty($GLOBALS['cfg']['Server']['usergroups']) ) { $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']); From d25583a23e052c1b52a1bf1a1ff2857f3121772e Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 11:56:54 +0530 Subject: [PATCH 06/31] Add new tables as configurations --- libraries/config.default.php | 18 ++++++++++++++++++ libraries/config/messages.inc.php | 4 ++++ libraries/config/setup.forms.php | 2 ++ 3 files changed, 24 insertions(+) diff --git a/libraries/config.default.php b/libraries/config.default.php index 39ba514a95..e8d2130565 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -402,6 +402,24 @@ $cfg['Servers'][$i]['tracking'] = ''; */ $cfg['Servers'][$i]['userconfig'] = ''; +/** + * table to store users and their assignment to user groups + * - leave blank to disable configurable menus feature + * SUGGESTED: 'pma__users' + * + * @global string $cfg['Servers'][$i]['users'] + */ +$cfg['Servers'][$i]['users'] = ''; + +/** + * table to store allowed menu items for each user group + * - leave blank to disable configurable menus feature + * SUGGESTED: 'pma__usergroups' + * + * @global string $cfg['Servers'][$i]['usergroups'] + */ +$cfg['Servers'][$i]['usergroups'] = ''; + /** * Maximum number of records saved in $cfg['Servers'][$i]['table_uiprefs'] table. * diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index e419953d86..d0db72b4b7 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -450,6 +450,10 @@ $strConfigServers_tracking_version_auto_create_desc = __('Whether the tracking m $strConfigServers_tracking_version_auto_create_name = __('Automatically create versions'); $strConfigServers_userconfig_desc = __('Leave blank for no user preferences storage in database, suggested: [kbd]pma__userconfig[/kbd]'); $strConfigServers_userconfig_name = __('User preferences storage table'); +$strConfigServers_users_desc = __('Leave blank to disable configurable menus feature, suggested: [kbd]pma__users[/kbd]'); +$strConfigServers_users_name = __('Users table'); +$strConfigServers_usergroups_desc = __('Leave blank to disable configurable menus feature, suggested: [kbd]pma__usergroups[/kbd]'); +$strConfigServers_usergroups_name = __('User groups table'); $strConfigServers_user_desc = __('Leave empty if not using config auth'); $strConfigServers_user_name = __('User for config auth'); $strConfigServers_verbose_desc = __('A user-friendly description of this server. Leave blank to display the hostname instead.'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index d2f5e4d6c6..da81bd0a55 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -70,6 +70,8 @@ $forms['Servers']['Server_pmadb'] = array('Servers' => array(1 => array( 'bookmarktable' => 'pma__bookmark', 'relation' => 'pma__relation', 'userconfig' => 'pma__userconfig', + 'users' => 'pma__users', + 'usergroups' => 'pma__usergroups', 'table_info' => 'pma__table_info', 'column_info' => 'pma__column_info', 'history' => 'pma__history', From 3ed92c5ca0ce024a1a909146e8b212f43f046c49 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 11:57:46 +0530 Subject: [PATCH 07/31] Update examples with new configurations --- config.sample.inc.php | 2 +- examples/config.manyhosts.inc.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config.sample.inc.php b/config.sample.inc.php index 9f7dfcbe53..7c40fb40e3 100644 --- a/config.sample.inc.php +++ b/config.sample.inc.php @@ -60,7 +60,7 @@ $cfg['Servers'][$i]['AllowNoPassword'] = false; // $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; // $cfg['Servers'][$i]['recent'] = 'pma__recent'; // $cfg['Servers'][$i]['users'] = 'pma__users'; -// $cfg['Servers'][$i]['usergroups'] = 'pma__user_groups'; +// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; /* Contrib / Swekey authentication */ // $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf'; diff --git a/examples/config.manyhosts.inc.php b/examples/config.manyhosts.inc.php index 1395ecc3d0..b9165355ee 100644 --- a/examples/config.manyhosts.inc.php +++ b/examples/config.manyhosts.inc.php @@ -45,4 +45,6 @@ foreach ($hosts as $host) { $cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $cfg['Servers'][$i]['recent'] = 'pma__recent'; + $cfg['Servers'][$i]['users'] = 'pma__users'; + $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; } From 1a86073cb27922cc889807ae2f01ac084c22f800 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:05:46 +0530 Subject: [PATCH 08/31] Warn about missing tables for configurable menus feature --- libraries/relation.lib.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index b684161a42..a6009d85ef 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -248,6 +248,23 @@ function PMA_getRelationsParamDiagnostic($cfgRelation) 'userconfigwork', $messages ); + $retval .= PMA_getDiagMessageForParameter( + 'users', + isset($cfgRelation['users']), + $messages, + 'users' + ); + $retval .= PMA_getDiagMessageForParameter( + 'usergroups', + isset($cfgRelation['usergroups']), + $messages, + 'usergroups' + ); + $retval .= PMA_getDiagMessageForFeature( + __('Configurable menus'), + 'menuswork', + $messages + ); $retval .= '' . "\n"; $retval .= '

' . __('Quick steps to setup advanced features:') . '

'; @@ -360,6 +377,7 @@ function PMA_checkRelationsParam() $cfgRelation['trackingwork'] = false; $cfgRelation['designerwork'] = false; $cfgRelation['userconfigwork'] = false; + $cfgRelation['menuswork'] = false; $cfgRelation['allworks'] = false; $cfgRelation['user'] = null; $cfgRelation['db'] = null; @@ -423,6 +441,10 @@ function PMA_checkRelationsParam() $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { $cfgRelation['userconfig'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { + $cfgRelation['users'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { + $cfgRelation['usergroups'] = $curr_table[0]; } } // end while $GLOBALS['dbi']->freeResult($tab_rs); @@ -430,7 +452,7 @@ function PMA_checkRelationsParam() if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; if (isset($cfgRelation['table_info'])) { - $cfgRelation['displaywork'] = true; + $cfgRelation['displaywork'] = true; } } @@ -473,12 +495,17 @@ function PMA_checkRelationsParam() $cfgRelation['bookmarkwork'] = true; } + if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) { + $cfgRelation['menuswork'] = true; + } + if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] && $cfgRelation['recentwork'] && $cfgRelation['uiprefswork'] && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork'] + && $cfgRelation['menuswork'] ) { $cfgRelation['allworks'] = true; } From a74c9a065b0716e1da1b4aa0af449e304867f55f Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:08:26 +0530 Subject: [PATCH 09/31] Fix alignment --- libraries/relation.lib.php | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index a6009d85ef..c3b83c3d40 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -364,23 +364,23 @@ function PMA_getDiagMessageForParameter($parameter, */ function PMA_checkRelationsParam() { - $cfgRelation = array(); - $cfgRelation['relwork'] = false; - $cfgRelation['displaywork'] = false; - $cfgRelation['bookmarkwork']= false; - $cfgRelation['pdfwork'] = false; - $cfgRelation['commwork'] = false; - $cfgRelation['mimework'] = false; - $cfgRelation['historywork'] = false; - $cfgRelation['recentwork'] = false; - $cfgRelation['uiprefswork'] = false; - $cfgRelation['trackingwork'] = false; - $cfgRelation['designerwork'] = false; + $cfgRelation = array(); + $cfgRelation['relwork'] = false; + $cfgRelation['displaywork'] = false; + $cfgRelation['bookmarkwork'] = false; + $cfgRelation['pdfwork'] = false; + $cfgRelation['commwork'] = false; + $cfgRelation['mimework'] = false; + $cfgRelation['historywork'] = false; + $cfgRelation['recentwork'] = false; + $cfgRelation['uiprefswork'] = false; + $cfgRelation['trackingwork'] = false; + $cfgRelation['designerwork'] = false; $cfgRelation['userconfigwork'] = false; - $cfgRelation['menuswork'] = false; - $cfgRelation['allworks'] = false; - $cfgRelation['user'] = null; - $cfgRelation['db'] = null; + $cfgRelation['menuswork'] = false; + $cfgRelation['allworks'] = false; + $cfgRelation['user'] = null; + $cfgRelation['db'] = null; if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) @@ -426,25 +426,25 @@ function PMA_checkRelationsParam() } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_coords']) { - $cfgRelation['designer_coords'] = $curr_table[0]; + $cfgRelation['designer_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { - $cfgRelation['column_info'] = $curr_table[0]; + $cfgRelation['column_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { - $cfgRelation['history'] = $curr_table[0]; + $cfgRelation['history'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { - $cfgRelation['recent'] = $curr_table[0]; + $cfgRelation['recent'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { - $cfgRelation['table_uiprefs'] = $curr_table[0]; + $cfgRelation['table_uiprefs'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { - $cfgRelation['tracking'] = $curr_table[0]; + $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { - $cfgRelation['userconfig'] = $curr_table[0]; + $cfgRelation['userconfig'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) { - $cfgRelation['users'] = $curr_table[0]; + $cfgRelation['users'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) { - $cfgRelation['usergroups'] = $curr_table[0]; + $cfgRelation['usergroups'] = $curr_table[0]; } } // end while $GLOBALS['dbi']->freeResult($tab_rs); From 027117c94a9fd3609ce0c1f4c5fd39726e107199 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:24:37 +0530 Subject: [PATCH 10/31] Document new configurations --- doc/config.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/config.rst b/doc/config.rst index 5b9657c8c7..54fa34fe5d 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -649,6 +649,29 @@ Server connection settings * put the table name in :config:option:`$cfg['Servers'][$i]['table\_uiprefs']` (e.g. ``pma__table_uiprefs``) +.. _configurablemenus: +.. config:option:: $cfg['Servers'][$i]['users'] + + :type: string + :default: ``''`` + +.. config:option:: $cfg['Servers'][$i]['usergroups'] + + :type: string + :default: ``''`` + + Since release 4.1.0 you can create different user groups with menu items + attached to them. Users can be assigned to these groups and the logged in + user would only see menu items configured to the usergroup he is assigned to. + To do this it needs two tables "usergroups" (storing allowed menu items for each + user group) and "users" (storing users and their assignments to user groups). + + To allow the usage of this functionality: + + * set up :config:option:`$cfg['Servers'][$i]['pmadb']` and the phpMyAdmin configuration storage + * put the correct table names in + :config:option:`$cfg['Servers'][$i]['users']` (e.g. ``pma__users``) and + :config:option:`$cfg['Servers'][$i]['usergroups']` (e.g. ``pma__usergroups``) .. _tracking: .. config:option:: $cfg['Servers'][$i]['tracking'] From 160e2cb8d8beca6b77918b4ace9ba96571d1bdf5 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:28:18 +0530 Subject: [PATCH 11/31] Fix checkstyle errors --- libraries/Menu.class.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 0de3c69319..10cb5e24ef 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -226,21 +226,13 @@ class PMA_Menu $item = ''; - if (in_array( - $GLOBALS['cfg']['TabsMode'], - array('text', 'both') - ) - ) { + if (in_array($GLOBALS['cfg']['TabsMode'], array('text', 'both'))) { $item .= '%4$s: '; } $item .= '%3$s'; $retval .= "
"; $retval .= "
"; - if (in_array( - $GLOBALS['cfg']['TabsMode'], - array('icons', 'both') - ) - ) { + if (in_array($GLOBALS['cfg']['TabsMode'], array('icons', 'both'))) { $retval .= PMA_Util::getImage( 's_host.png', '', @@ -257,11 +249,7 @@ class PMA_Menu if (strlen($this->_db)) { $retval .= $separator; - if (in_array( - $GLOBALS['cfg']['TabsMode'], - array('icons', 'both') - ) - ) { + if (in_array($GLOBALS['cfg']['TabsMode'], array('icons', 'both'))) { $retval .= PMA_Util::getImage( 's_db.png', '', @@ -283,11 +271,7 @@ class PMA_Menu include './libraries/tbl_info.inc.php'; $retval .= $separator; - if (in_array( - $GLOBALS['cfg']['TabsMode'], - array('icons', 'both') - ) - ) { + if (in_array($GLOBALS['cfg']['TabsMode'], array('icons', 'both'))) { $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png'; $retval .= PMA_Util::getImage( $icon, From 7cfdbc03ec443fa22007bc9e2833157a186f7efb Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:32:01 +0530 Subject: [PATCH 12/31] Fix checkstyle errors --- libraries/Menu.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 10cb5e24ef..66e71ebb68 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -526,11 +526,9 @@ class PMA_Menu { $is_superuser = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser(); $binary_logs = null; - if (isset($GLOBALS['dbi']) - && (! defined('PMA_DRIZZLE') - || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE) - ) - ) { + $notDrizzle = ! defined('PMA_DRIZZLE') + || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE); + if (isset($GLOBALS['dbi']) && $notDrizzle) { $binary_logs = $GLOBALS['dbi']->fetchResult( 'SHOW MASTER LOGS', 'Log_name', From b30a6be291cd4cf6e7c12ed73b664f65389812a7 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 5 Jul 2013 12:43:24 +0530 Subject: [PATCH 13/31] Use consistent table names --- examples/create_tables.sql | 4 ++-- examples/create_tables_drizzle.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/create_tables.sql b/examples/create_tables.sql index 52bc1abb73..c1309760e4 100644 --- a/examples/create_tables.sql +++ b/examples/create_tables.sql @@ -257,10 +257,10 @@ CREATE TABLE IF NOT EXISTS `pma__users` ( -- -------------------------------------------------------- -- --- Table structure for table `pma__user_groups` +-- Table structure for table `pma__usergroups` -- -CREATE TABLE IF NOT EXISTS `pma__user_groups` ( +CREATE TABLE IF NOT EXISTS `pma__usergroups` ( `usergroup` varchar(64) NOT NULL, `server_databases` enum('Y','N') NOT NULL DEFAULT 'N', `server_sql` enum('Y','N') NOT NULL DEFAULT 'N', diff --git a/examples/create_tables_drizzle.sql b/examples/create_tables_drizzle.sql index 49a5407deb..e469e2294f 100644 --- a/examples/create_tables_drizzle.sql +++ b/examples/create_tables_drizzle.sql @@ -244,10 +244,10 @@ CREATE TABLE IF NOT EXISTS `pma__users` ( -- -------------------------------------------------------- -- --- Table structure for table `pma__user_groups` +-- Table structure for table `pma__usergroups` -- -CREATE TABLE IF NOT EXISTS `pma__user_groups` ( +CREATE TABLE IF NOT EXISTS `pma__usergroups` ( `usergroup` varchar(64) NOT NULL, `server_databases` enum('Y','N') NOT NULL DEFAULT 'N', `server_sql` enum('Y','N') NOT NULL DEFAULT 'N', From 08cd261856538ec6e5c5504a59034adda1f8c149 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Mon, 8 Jul 2013 01:20:31 +0530 Subject: [PATCH 14/31] Allow setting user groups when creating and editing users --- libraries/Menu.class.php | 5 +- libraries/server_privileges.lib.php | 109 +++++++++++++++++++++++++++- server_privileges.php | 13 ++++ 3 files changed, 119 insertions(+), 8 deletions(-) diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 66e71ebb68..4f378d9b1b 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -178,10 +178,7 @@ class PMA_Menu $allowedTabs = $tabList[$level]; - if (! empty($GLOBALS['cfg']['Server']['pmadb']) - && ! empty($GLOBALS['cfg']['Server']['users']) - && ! empty($GLOBALS['cfg']['Server']['usergroups']) - ) { + if ($GLOBALS['cfgRelation']['menuswork']) { $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']); $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 7b8dc0fad2..585948d576 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -361,6 +361,97 @@ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname) ." AND `Db` = '" . PMA_Util::unescapeMysqlWildcards($db) . "'" ." AND `Table_name` = '" . PMA_Util::sqlAddSlashes($table) . "';"; } + +/** + * Displays a dropdown to select the user group + * with menu items configured to each of them. + * + * @param boolean $submit wheather to display the submit button or not + * + * @return string html to select the user group + */ +function PMA_getHtmlToChoseUserGroup($submit = false) +{ + $html_output = '
'; + $html_output .= '' . __('User group') . ''; + + $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']); + $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']); + + $userGroups = array(); + $sql_query = "SELECT `usergroup` FROM " . $groupTable; + $result = PMA_queryAsControlUser($sql_query, false); + if ($result) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { + $userGroups[] = $row[0]; + } + } + $GLOBALS['dbi']->freeResult($result); + + $userGroup = ''; + if (isset($GLOBALS['username'])) { + $sql_query = "SELECT `usergroup` FROM " . $userTable + . " WHERE `username` = '" . $GLOBALS['username'] . "'"; + $userGroup = $GLOBALS['dbi']->fetchValue( + $sql_query, 0, 0, $GLOBALS['controllink'] + ); + } + + $html_output .= __('User group') . ': '; + $html_output .= ''; + $html_output .= '
'; + + if ($submit) { + $html_output .= ''; + } + return $html_output; +} + +/** + * Sets the user group from request values + * + * @param string $username username + * @param string $userGroup user group to set + * + * @return void + */ +function PMA_setUserGroup($username, $userGroup) +{ + $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) + . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']); + + $sql_query = "SELECT `usergroup` FROM " . $userTable + . " WHERE `username` = '" . $username . "'"; + $oldUserGroup = $GLOBALS['dbi']->fetchValue( + $sql_query, 0, 0, $GLOBALS['controllink'] + ); + + if ($oldUserGroup === false) { + $upd_query = "INSERT INTO " . $userTable . "(`username`, `usergroup`)" + . " VALUES ('" . $username . "', '" . $userGroup. "')"; + } else if ($oldUserGroup != $userGroup) { + $upd_query = "UPDATE " . $userTable . " SET `usergroup`='" . $userGroup + . "' WHERE `username`='" . $username . "'"; + } + if (isset($upd_query)) { + PMA_queryAsControlUser($upd_query); + } +} + /** * Displays the privileges form table * @@ -1472,6 +1563,9 @@ function PMA_getHtmlForAddUser($dbname) } $html_output .= '' . "\n"; + if ($GLOBALS['cfgRelation']['menuswork']) { + $html_output .= PMA_getHtmlToChoseUserGroup(); + } $html_output .= PMA_getHtmlToDisplayPrivilegesTable('*', '*', false); $html_output .= '