From 5938302012bca0573d12d8ab070a62b092618e03 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 26 Jul 2009 01:17:47 +1000 Subject: [PATCH] Fix the simple ACL configuration --- config/config.php.example | 79 +++++++++++++++++++++-------------- htdocs/add_value_form.php | 7 ---- htdocs/copy.php | 3 -- htdocs/create.php | 3 -- htdocs/create_confirm.php | 3 -- htdocs/delete.php | 3 -- htdocs/delete_attr.php | 3 -- htdocs/export.php | 3 -- htdocs/import.php | 3 -- htdocs/rdelete.php | 3 -- htdocs/rename.php | 3 -- htdocs/welcome.php | 21 ++-------- lib/HTMLTree.php | 13 ++++-- lib/PageRender.php | 2 +- lib/QueryRender.php | 2 +- lib/TemplateRender.php | 39 +++++++++-------- lib/config_default.php | 88 ++++++++------------------------------- lib/ds_ldap_pla.php | 27 +----------- lib/functions.php | 22 +++++++--- lib/page.php | 41 +++++++----------- 20 files changed, 134 insertions(+), 234 deletions(-) diff --git a/config/config.php.example b/config/config.php.example index 7a7fdff..55a5e3f 100644 --- a/config/config.php.example +++ b/config/config.php.example @@ -79,38 +79,55 @@ /* Command availability ; if you don't authorize a command the command links will not be shown and the command action will not be permitted. For better security, set also ACL in your ldap directory. */ - /* -$config->custom->commands['all'] = array( - 'home' => true, - 'external_links' => array('feature' => true, - 'forum' => true, - 'bug' => true, - 'donation' => true, - 'help' => true, - 'credits' => true), - 'purge' => true, - 'schema' => true, - 'import' => true, - 'export' => true, - 'logout' => true, - 'search' => array('simple_search' => true, - 'predefined_search' => true, - 'advanced_search' => true), - 'server_refresh' => true, - 'server_info' => true, - 'entry_refresh' => true, - 'entry_move' => true, - 'entry_internal_attributes_show' => true, - 'entry_delete' => array('simple_delete' => true, - 'mass_delete' => false), - 'entry_rename' => true, - 'entry_compare' => true, - 'entry_create' => true, - 'attribute_add' => true, - 'attribute_add_value' => true, - 'attribute_delete' => true, - 'attribute_delete_value' => true); +$config->custom->commands['cmd'] = array( + 'entry_internal_attributes_show' => true, + 'entry_refresh' => true, + 'oslinks' => true, + 'switch_template' => true + ); + +$config->custom->commands['script'] = array( + 'add_attr_form' => true, + 'add_oclass_form' => true, + 'add_value_form' => true, + 'collapse' => true, + 'compare' => true, + 'compare_form' => true, + 'copy' => true, + 'copy_form' => true, + 'create' => true, + 'create_confirm' => true, + 'delete' => true, + 'delete_attr' => true, + 'delete_form' => true, + 'draw_tree_node' => true, + 'expand' => true, + 'export' => true, + 'export_form' => true, + 'import' => true, + 'import_form' => true, + 'login' => true, + 'logout' => true, + 'login_form' => true, + 'mass_delete' => true, + 'mass_edit' => true, + 'mass_update' => true, + 'modify_member_form' => true, + 'monitor' => true, + 'purge_cache' => true, + 'query_engine' => true, + 'rename' => true, + 'rename_form' => true, + 'rdelete' => true, + 'refresh' => true, + 'schema' => true, + 'server_info' => true, + 'show_cache' => true, + 'template_engine' => true, + 'update_confirm' => true, + 'update' => true +); */ /*********************************************/ diff --git a/htdocs/add_value_form.php b/htdocs/add_value_form.php index e4b1685..7b98c7c 100644 --- a/htdocs/add_value_form.php +++ b/htdocs/add_value_form.php @@ -31,13 +31,6 @@ $request['template'] = $request['page']->getTemplate(); /* if ($request['attribute']->isReadOnly()) error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php'); - -# Check our permissions -if (! $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('add attribute value')),'error','index.php'); - -if (($request['attribute']->getValueCount() == 0) && ! $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('add attribute')),'error','index.php'); */ # Render the form diff --git a/htdocs/copy.php b/htdocs/copy.php index 5c98370..2769908 100644 --- a/htdocs/copy.php +++ b/htdocs/copy.php @@ -23,9 +23,6 @@ $ldap['SRC'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_src')); $ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst')); # Error checking -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_move')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('copy entry')),'error','index.php'); - if (! trim($request['dnDST'])) error(_('You left the destination DN blank.'),'error','index.php'); diff --git a/htdocs/create.php b/htdocs/create.php index 7d65d7f..f07767c 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -19,9 +19,6 @@ if (get_request('cancel','REQUEST')) { die(); } -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_create')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('create entry')),'error','index.php'); - $request = array(); $request['redirect'] = get_request('redirect','POST',false,false); diff --git a/htdocs/create_confirm.php b/htdocs/create_confirm.php index 1276126..763b4bb 100644 --- a/htdocs/create_confirm.php +++ b/htdocs/create_confirm.php @@ -13,9 +13,6 @@ require './common.php'; -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_create')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('create entry')),'error','index.php'); - $request = array(); $request['redirect'] = get_request('redirect','POST',false,false); diff --git a/htdocs/delete.php b/htdocs/delete.php index c2134d6..b40a137 100644 --- a/htdocs/delete.php +++ b/htdocs/delete.php @@ -20,9 +20,6 @@ $request['dn'] = get_request('dn','REQUEST',true); if (! $app['server']->dnExists($request['dn'])) error(sprintf('%s (%s)',_('No such entry.'),''.pretty_print_dn($request['dn']).''),'error','index.php'); -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete','simple_delete')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('delete entry')),'error','index.php'); - # Delete the entry. $result = $app['server']->delete($request['dn']); diff --git a/htdocs/delete_attr.php b/htdocs/delete_attr.php index 217de86..82c0a55 100644 --- a/htdocs/delete_attr.php +++ b/htdocs/delete_attr.php @@ -13,9 +13,6 @@ require './common.php'; -if (! $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('delete attribute')),'error','index.php'); - $request = array(); $request['dn'] = get_request('dn','REQUEST',true); $request['attr'] = get_request('attr','REQUEST',true); diff --git a/htdocs/export.php b/htdocs/export.php index c975097..cbb0081 100755 --- a/htdocs/export.php +++ b/htdocs/export.php @@ -14,9 +14,6 @@ require './common.php'; require LIBDIR.'export_functions.php'; -if (! $_SESSION[APPCONFIG]->isCommandAvailable('export')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('export')),'error','index.php'); - # Prevent script from bailing early for long search @set_time_limit(0); diff --git a/htdocs/import.php b/htdocs/import.php index 2ff5484..6e3b05b 100644 --- a/htdocs/import.php +++ b/htdocs/import.php @@ -14,9 +14,6 @@ require './common.php'; require LIBDIR.'import_functions.php'; -if (! $_SESSION[APPCONFIG]->isCommandAvailable('import')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('import')),'error','index.php'); - $request = array(); $request['importer'] = new Importer($app['server']->getIndex(),'LDIF'); $request['import'] = $request['importer']->getTemplate(); diff --git a/htdocs/rdelete.php b/htdocs/rdelete.php index 09ccb74..fe7826d 100644 --- a/htdocs/rdelete.php +++ b/htdocs/rdelete.php @@ -13,9 +13,6 @@ require './common.php'; -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete','simple_delete')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('delete entry')),'error','index.php'); - $request = array(); $request['dn'] = get_request('dn','REQUEST',true); diff --git a/htdocs/rename.php b/htdocs/rename.php index 68ec31a..883f13a 100644 --- a/htdocs/rename.php +++ b/htdocs/rename.php @@ -20,9 +20,6 @@ $request['rdnDST'] = get_request('new_rdn','REQUEST'); $request['container'] = $app['server']->getContainer($request['dnSRC']); # Error checking -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename')) - error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('rename entry')),'error','index.php'); - if (! $app['server']->isBranchRenameEnabled()) { # We search all children, not only the visible children in the tree $children = $app['server']->getContainerContents($request['dnSRC'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER); diff --git a/htdocs/welcome.php b/htdocs/welcome.php index 051d205..379e6ad 100644 --- a/htdocs/welcome.php +++ b/htdocs/welcome.php @@ -20,23 +20,10 @@ echo '

'; echo _('Use the menu to the left to navigate'); echo '

'; -$links = ''; - -if ($_SESSION[APPCONFIG]->isCommandAvailable('external_links','credits')) - $links .= sprintf('%s',get_href('credits'),_('Credits')); - -if ($_SESSION[APPCONFIG]->isCommandAvailable('external_links','help')) { - if ($links) $links .= ' | '; - $links .= sprintf('%s',get_href('documentation'),_('Documentation')); -} - -if ($_SESSION[APPCONFIG]->isCommandAvailable('external_links','donation')) { - if ($links) $links .= ' | '; - $links .= sprintf('%s',get_href('donate'),_('Donate')); -} - -if ($links) { - echo $links; +if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks')) { + printf('%s',get_href('credits'),_('Credits')); + printf(' | %s',get_href('documentation'),_('Documentation')); + printf(' | %s',get_href('donate'),_('Donate')); echo '

'; } diff --git a/lib/HTMLTree.php b/lib/HTMLTree.php index 72c8faa..69a9d83 100644 --- a/lib/HTMLTree.php +++ b/lib/HTMLTree.php @@ -207,6 +207,7 @@ class HTMLTree extends Tree { $menu['title'] = _('View schema for'); $menu['img'] = 'schema-big.png'; $menu['name'] = _('schema'); + break; case 'search': @@ -219,6 +220,7 @@ class HTMLTree extends Tree { $menu['title'] = _('Search'); $menu['img'] = 'search-big.png'; $menu['name'] = _('search'); + break; case 'refresh': @@ -232,6 +234,7 @@ class HTMLTree extends Tree { $menu['title'] = _('Refresh'); $menu['img'] = 'refresh-big.png'; $menu['name'] = _('refresh'); + break; case 'server_info': @@ -244,6 +247,7 @@ class HTMLTree extends Tree { $menu['title'] = _('Info'); $menu['img'] = 'info-big.png'; $menu['name'] = _('info'); + break; case 'monitor': @@ -260,10 +264,11 @@ class HTMLTree extends Tree { $menu['title'] = _('Monitor'); $menu['img'] = 'monitorserver-big.png'; $menu['name'] = _('monitor'); + break; case 'import': - if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','import') || $server->isReadOnly()) + if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','import_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','import') || $server->isReadOnly()) return ''; $menu['cmd'] = 'import_form'; @@ -272,10 +277,11 @@ class HTMLTree extends Tree { $menu['title'] = _('Import'); $menu['img'] = 'import-big.png'; $menu['name'] = _('import'); + break; case 'export': - if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) + if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) return ''; $menu['cmd'] = 'export_form'; @@ -284,10 +290,11 @@ class HTMLTree extends Tree { $menu['title'] = _('Export'); $menu['img'] = 'export-big.png'; $menu['name'] = _('export'); + break; case 'logout': - if (in_array($server->getAuthType(),array('config','http','proxy'))) + if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','logout') || in_array($server->getAuthType(),array('config','http','proxy'))) return ''; $href = sprintf('cmd.php?cmd=logout&server_id=%s',$server->getIndex()); diff --git a/lib/PageRender.php b/lib/PageRender.php index e2fef63..d2882f5 100644 --- a/lib/PageRender.php +++ b/lib/PageRender.php @@ -623,7 +623,7 @@ class PageRender extends Visitor { echo '
'; - if (! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete')) + if (! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr')) printf('Trash %s', $attribute->getName(),$attribute->getFriendlyName(),$i,IMGDIR,_('delete attribute')); diff --git a/lib/QueryRender.php b/lib/QueryRender.php index abd05b7..6fdc773 100644 --- a/lib/QueryRender.php +++ b/lib/QueryRender.php @@ -561,7 +561,7 @@ var deon=0; printf('%s: %s

(%s %s)
',_('Entries found'), number_format($results),$this->template->resultsdata[$base]['time'],_('seconds')); - if ($_SESSION[APPCONFIG]->isCommandAvailable('export')) { + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form')) { $href = htmlspecialchars(sprintf('cmd.php?cmd=export_form&server_id=%s&scope=%s&dn=%s&filter=%s&attributes=%s', $server->getIndex(),$this->template->resultsdata[$base]['scope'], $base,rawurlencode($this->template->resultsdata[$base]['filter']), diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php index ada90f1..8fb52ca 100644 --- a/lib/TemplateRender.php +++ b/lib/TemplateRender.php @@ -914,40 +914,43 @@ class TemplateRender extends PageRender { switch ($i) { case 'entryrefresh': - if ($_SESSION[APPCONFIG]->isCommandAvailable('entry_refresh')) + if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_refresh')) return $this->getMenuItemRefresh(); else return ''; case 'switchtemplate': - return $this->getMenuItemSwitchTemplate(); + if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','switch_template')) + return $this->getMenuItemSwitchTemplate(); + else + return ''; case 'entryexport': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export_form')) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) return $this->getMenuItemExportBase(); else return ''; case 'entrycopy': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','copy_form') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','copy_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','copy') && ! $this->template->isReadOnly()) return $this->getMenuItemMove(); else return ''; case 'showinternal': - if ($_SESSION[APPCONFIG]->isCommandAvailable('entry_internal_attributes_show')) + if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_internal_attributes_show')) return $this->getMenuItemInternalAttributes(); else return ''; case 'entrydelete': - if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) return $this->getMenuItemDelete(); else return ''; case 'entryrename': - if ($_SESSION[APPCONFIG]->isCommandAvailable('entry_rename') && ! $this->template->isReadOnly()) { + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','rename_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename') && ! $this->template->isReadOnly()) { # Check if any of the RDN's are read only. $rdnro = false; @@ -968,25 +971,25 @@ class TemplateRender extends PageRender { case 'msgdel': if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') - && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete') && ! $this->template->isReadOnly()) + && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) return array('',$this->getDeleteAttributeMessage()); else return ''; case 'entrycompare': - if ($_SESSION[APPCONFIG]->isCommandAvailable('entry_compare') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','compare_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','compare') && ! $this->template->isReadOnly()) return $this->getMenuItemCompare(); else return ''; case 'childcreate': - if ($_SESSION[APPCONFIG]->isCommandAvailable('entry_create') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','create') && ! $this->template->isReadOnly()) return $this->getMenuItemCreate(); else return ''; case 'addattr': - if ($_SESSION[APPCONFIG]->isCommandAvailable('attribute_add') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','add_attr_form') && ! $this->template->isReadOnly()) return $this->getMenuItemAddAttribute(); else return ''; @@ -1027,7 +1030,7 @@ class TemplateRender extends PageRender { if ($i == 'childview') return $this->getMenuItemShowChildren($children_count); - elseif ($i == 'childexport' && $_SESSION[APPCONFIG]->isCommandAvailable('export')) + elseif ($i == 'childexport' && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) return $this->getMenuItemExportSub(); else return ''; @@ -1036,7 +1039,7 @@ class TemplateRender extends PageRender { return ''; case 'msgschema': - if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') && $_SESSION[APPCONFIG]->isCommandAvailable('schema')) + if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') && $_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) return array('',$this->getViewSchemaMessage()); else return array(); @@ -1068,7 +1071,7 @@ class TemplateRender extends PageRender { protected function getDeleteAttributeMessage() { if (DEBUGTMP) printf('%s
',__METHOD__); - if ($_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete_value') && ! $this->template->isReadOnly()) + if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr') && ! $this->template->isReadOnly()) return sprintf($this->layout['hint'],_('Hint: To delete an attribute, empty the text field and click save.')); else return ''; @@ -1982,7 +1985,7 @@ function fillRec(id,value) { switch ($action) { case 'add': if ($attribute->isVisible() && ! $attribute->isReadOnly() - && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value')) { + && $_SESSION[APPCONFIG]->isCommandAvailable('script','add_value_form')) { if ($attribute->haveMoreValues()) return $this->get('AddValueMenuItem',$attribute); @@ -1993,8 +1996,7 @@ function fillRec(id,value) { case 'modify': if (in_array($attribute->getName(),arrayLower($_SESSION[APPCONFIG]->getValue('modify_member','groupattr')))) { if ($attribute->isVisible() && ! $attribute->isReadOnly() && ! $attribute->isRDN() - && ($_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value') - || $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete_value'))) + && $_SESSION[APPCONFIG]->isCommandAvailable('script','modify_member_form')) return $this->get('ModifyMemberMenuItem',$attribute); } @@ -2002,7 +2004,8 @@ function fillRec(id,value) { case 'rename': if ($attribute->isVisible() && $attribute->isRDN() && ! $attribute->isReadOnly() - && $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename')) + && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename_form') + && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename')) return $this->get('RenameMenuItem',$attribute); return ''; diff --git a/lib/config_default.php b/lib/config_default.php index 272ff93..6dfa3b1 100644 --- a/lib/config_default.php +++ b/lib/config_default.php @@ -290,6 +290,15 @@ class Config { * Define command availability ; if the value of a command is true, * the command will be available. */ + $this->default->commands['cmd'] = array( + 'desc'=>'Define command availability', + 'default'=> array( + 'entry_internal_attributes_show' => true, + 'entry_refresh' => true, + 'oslinks' => true, + 'switch_template' => true + )); + $this->default->commands['script'] = array( 'desc'=>'Define scripts availability', 'default'=> array( @@ -331,42 +340,7 @@ class Config { 'show_cache' => true, 'template_engine' => true, 'update_confirm' => true, - 'update' => true, - 'test' => true - )); - - $this->default->commands['all'] = array( - 'desc'=>'Define command availability', - 'default'=> array( - 'home' => true, - 'external_links' => array('feature' => true, - 'forum' => true, - 'bug' => true, - 'donation' => true, - 'help' => true, - 'credits' => true), - 'purge' => true, - 'schema' => true, - 'import' => true, - 'export' => true, - 'logout' => true, - 'search' => array('simple_search' => true, - 'predefined_search' => true, - 'advanced_search' => true), - 'server_refresh' => true, - 'server_info' => true, - 'entry_refresh' => true, - 'entry_move' => true, - 'entry_internal_attributes_show' => true, - 'entry_delete' => array('simple_delete' => true, - 'mass_delete' => false), - 'entry_rename' => true, - 'entry_compare' => true, - 'entry_create' => true, - 'attribute_add' => true, - 'attribute_add_value' => true, - 'attribute_delete' => true, - 'attribute_delete_value' => true + 'update' => true )); /** Aliases and Referrrals @@ -666,48 +640,20 @@ class Config { } /** - * The parameter number is variable. - * For example : isCommandAvailable('search','simple_search') + * Simple ACL to see if commands can be run */ - public function isCommandAvailable($index='all') { + public function isCommandAvailable($index='cmd') { $a = func_get_args(); - - if (! in_array($index,array('all','script'))) - $index = 'all'; - else - array_shift($a); - - if (count($a) == 1 && is_array($a[0])) - $a = $a[0]; - $i = 0; + array_shift($a); + $a = $a[0]; # Command availability list $cmd = $this->getValue('commands',$index); - # Search for the command - while ($i < count($a)) { - if (! is_array($cmd)) - return $cmd; + if (! is_string($a) || ! isset($cmd[$a])) + debug_dump(array('Unknown command '=>$a),1); - if (! isset($cmd[$a[$i]])) - return false; - - $cmd = $cmd[$a[$i]]; - $i++; - } - - # If this is a leaf command, return its availability - if (! is_array($cmd)) - return $cmd; - - # Else the command is available, if one of its sub-command is available - $a[] = ''; - foreach ($cmd as $c => $v) { - $a[$i] = $c; - if ($this->isCommandAvailable($a)) - return true; - } - return false; + return $cmd[$a]; } public function configDefinition($key,$index,$config) { diff --git a/lib/ds_ldap_pla.php b/lib/ds_ldap_pla.php index 620a734..e6c6cef 100644 --- a/lib/ds_ldap_pla.php +++ b/lib/ds_ldap_pla.php @@ -122,31 +122,6 @@ class ldap_pla extends ldap { } /** FUNCTIONS TO BE REWORKED BELOW HERE **/ - /** - * Returns true if the user has configured the specified server to enable mass deletion. - * - * Mass deletion is enabled in config.php this: - * - * $config->custom->commands['all'] = array('entry_delete' => array('mass_delete' => true)); - * - * Notice that mass deletes are not enabled on a per-server basis, but this - * function checks that the server is not in a read-only state as well. - * - * @return boolean - */ - function isMassDeleteEnabled() { - if (DEBUG_ENABLED) - debug_log('Entered with ()',17,__FILE__,__LINE__,__METHOD__); - - if ($this->connect(false) && $this->haveAuthInfo() && ! $this->isReadOnly() && - $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete', 'mass_delete')) - - return true; - - else - return false; - } - /** * Gets whether the admin has configured phpLDAPadmin to show the "Create New" link in the tree viewer. * @@ -166,7 +141,7 @@ class ldap_pla extends ldap { if (DEBUG_ENABLED) debug_log('Entered with ()',17,__FILE__,__LINE__,__METHOD__); - if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_create')) + if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','create')) return false; else return $this->getValue('appearance','show_create'); diff --git a/lib/functions.php b/lib/functions.php index 58fb60a..8c89f87 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -358,50 +358,60 @@ function cmd_control_pane($type) { return array( 'home'=>array( 'title'=>_('Home'), + 'enable'=>true, 'link'=>sprintf('href="index.php" title="%s"',_('Home')), 'image'=>sprintf('%s',IMGDIR,_('Home'))), 'purge'=>array( 'title'=>_('Purge caches'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('script','purge_cache'), 'link'=>sprintf('href="cmd.php?cmd=purge_cache" onclick="return displayAJ(\'BODY\',\'cmd=purge_cache\',\'%s\');" title="%s"', _('Clearing cache'),_('Purge caches')), 'image'=>sprintf('%s',IMGDIR,_('Purge caches'))), - 'appearance:hide_debug_info'=>array( + 'hide_debug_info'=>array( 'title'=>_('Show Cache'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('script','show_cache'), 'link'=>sprintf('href="cmd.php?cmd=show_cache" onclick="return displayAJ(\'BODY\',\'cmd=show_cache\',\'%s\');" title="%s"', _('Loading'),_('Show Cache'),_('Show Cache')), 'image'=>sprintf('%s',IMGDIR,_('Show Cache'))), ); + break; case 'top' : return array( - 'external_links:forum'=>array( + 'forum'=>array( 'title'=>_('Forum'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks'), 'link'=>sprintf('href="%s" title="%s" target="_blank"',get_href('forum'),_('Forum')), 'image'=>sprintf('%s',IMGDIR,_('Forum'))), - 'external_links:feature'=>array( + 'feature'=>array( 'title'=>_('Request feature'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks'), 'link'=>sprintf('href="%s" title="%s" target="_blank"',get_href('add_rfe'),_('Request feature')), 'image'=>sprintf('%s',IMGDIR,_('Request feature'))), - 'external_links:bug'=>array( + 'bug'=>array( 'title'=>_('Report a bug'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks'), 'link'=>sprintf('href="%s" title="%s" target="_blank"',get_href('add_bug'),_('Report a bug')), 'image'=>sprintf('%s',IMGDIR,_('Report a bug'))), - 'external_links:donation'=>array( + 'donation'=>array( 'title'=>_('Donate'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks'), 'link'=>sprintf('href="%s" title="%s" target="_blank"',get_href('donate'),_('Donate')), 'image'=>sprintf('%s',IMGDIR,_('Donate'))), - 'external_links:help'=>array( + 'help'=>array( 'title'=>_('Help'), + 'enable'=>$_SESSION[APPCONFIG]->isCommandAvailable('cmd','oslinks'), 'link'=>sprintf('href="%s" title="%s" target="_blank"',get_href('documentation'),_('Help')), 'image'=>sprintf('%s',IMGDIR,_('Help'))) ); + break; } } diff --git a/lib/page.php b/lib/page.php index 321b963..bc62cf8 100644 --- a/lib/page.php +++ b/lib/page.php @@ -154,24 +154,19 @@ class page { echo ''; $empty = true; if (function_exists('cmd_control_pane')) - foreach (cmd_control_pane('top') as $cmd => $cmddetails) { - $cmds = explode(':',$cmd); + foreach (cmd_control_pane('top') as $cmddetails) + if ((isset($cmddetails['enable']) && $cmddetails['enable']) || ! isset($cmddetails['enable'])) { + if (! $empty) + echo ' '; - if (defined('APPCONFIG') && isset($_SESSION[APPCONFIG]) && method_exists($_SESSION[APPCONFIG],'isCommandAvailable')) - if ($_SESSION[APPCONFIG]->isCommandAvailable('all',$cmds)) { - if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) { - if (! $empty) - echo ' '; + printf('%s',$cmddetails['link'],$cmddetails['image']); - printf('%s',$cmddetails['link'],$cmddetails['image']); - - $empty = false; - } - } - } + $empty = false; + } if ($empty) echo ' '; + echo ''; echo ''; echo ''; @@ -187,22 +182,16 @@ class page { $empty = true; if (function_exists('cmd_control_pane')) - foreach (cmd_control_pane('main') as $cmd => $cmddetails) { - $cmds = explode(':',$cmd); - - if (defined('APPCONFIG') && isset($_SESSION[APPCONFIG]) && method_exists($_SESSION[APPCONFIG],'isCommandAvailable')) - if ($_SESSION[APPCONFIG]->isCommandAvailable('all',$cmds)) { - if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) { - if (! $empty) + foreach (cmd_control_pane('main') as $cmddetails) + if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) { + if (! $empty) echo ' | '; - printf('%s',$cmddetails['link'], - $_SESSION[APPCONFIG]->getValue('appearance','control_icons') ? $cmddetails['image'] : $cmddetails['title']); + printf('%s',$cmddetails['link'], + $_SESSION[APPCONFIG]->getValue('appearance','control_icons') ? $cmddetails['image'] : $cmddetails['title']); - $empty = false; - } - } - } + $empty = false; + } echo ''; if ($empty)