From 7d17676fd7d5fc5114465b0980ab4ea30a6b84de Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 11 Mar 2010 17:46:03 +1100 Subject: [PATCH] Enabled create_base --- doc/phpldapadmin-demo.conf | 8 +++++--- htdocs/create.php | 9 +++++---- htdocs/create_confirm.php | 7 ++++--- lib/AJAXTree.php | 1 + lib/HTMLTree.php | 29 +++++++++++++++-------------- lib/PageRender.php | 3 ++- lib/Template.php | 14 +++++++++++++- lib/TemplateRender.php | 36 ++++++++++++++++++++++++++++++++---- lib/ds_ldap_pla.php | 5 +++++ lib/functions.php | 5 +---- 10 files changed, 83 insertions(+), 34 deletions(-) diff --git a/doc/phpldapadmin-demo.conf b/doc/phpldapadmin-demo.conf index 91f8915..12085b3 100644 --- a/doc/phpldapadmin-demo.conf +++ b/doc/phpldapadmin-demo.conf @@ -1,4 +1,6 @@ include /etc/openldap/schema/uidpool.schema +include /etc/openldap/schema/sudo.schema +include /etc/openldap/schema/autofs.schema TLSCACertificateFile /etc/openldap/pla/ca-bundle.crt TLSCertificateFile /etc/openldap/pla/slapd.crt @@ -23,7 +25,7 @@ access to * authz-policy any -database bdb +database ldbm suffix "dc=example.com" rootdn "cn=Manager,dc=example.com" rootpw NotAllowed @@ -38,7 +40,7 @@ index uidNumber,gidNumber,loginShell eq,pres index uid,memberUid eq,pres,sub index nisMapName,nisMapEntry eq,pres,sub -database bdb +database ldbm suffix "dc=example,dc=com" rootdn "cn=Manager,dc=example,dc=com" rootpw NotAllowed @@ -53,7 +55,7 @@ index uidNumber,gidNumber,loginShell eq,pres index uid,memberUid eq,pres,sub index nisMapName,nisMapEntry eq,pres,sub -database bdb +database ldbm suffix "o=Simpsons" rootdn "cn=Manager,o=Simpsons" rootpw NotAllowed diff --git a/htdocs/create.php b/htdocs/create.php index e2dd673..c13c683 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -25,16 +25,17 @@ $request['page']->setContainer(get_request('container','REQUEST',true)); $request['page']->accept(); $request['template'] = $request['page']->getTemplate(); -if (! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) +if ((! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) && ! get_request('create_base')) error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php'); # Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... $tree = get_cached_item($app['server']->getIndex(),'tree'); -$request['container'] = $tree->getEntry($request['template']->getContainer()); -if (! $request['container']) - $tree->addEntry($request['template']->getContainer()); $request['container'] = $tree->getEntry($request['template']->getContainer()); +if (! $request['container'] && ! get_request('create_base')) { + $tree->addEntry($request['template']->getContainer()); + $request['container'] = $tree->getEntry($request['template']->getContainer()); +} # Check our RDN if (! count($request['template']->getRDNAttrs())) diff --git a/htdocs/create_confirm.php b/htdocs/create_confirm.php index 7f23f75..4356f8c 100644 --- a/htdocs/create_confirm.php +++ b/htdocs/create_confirm.php @@ -24,11 +24,12 @@ if (! $request['template']->getContainer() || ! $app['server']->dnExists($reques # Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... $tree = get_cached_item($app['server']->getIndex(),'tree'); -$request['container'] = $tree->getEntry($request['template']->getContainer()); -if (! $request['container']) - $tree->addEntry($request['template']->getContainer()); $request['container'] = $tree->getEntry($request['template']->getContainer()); +if (! $request['container']) { + $tree->addEntry($request['template']->getContainer()); + $request['container'] = $tree->getEntry($request['template']->getContainer()); +} # Check our RDN if (! count($request['template']->getRDNAttrs())) diff --git a/lib/AJAXTree.php b/lib/AJAXTree.php index fe9a733..f2652c0 100644 --- a/lib/AJAXTree.php +++ b/lib/AJAXTree.php @@ -211,6 +211,7 @@ class AJAXTree extends HTMLTree { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + parent::draw_javascript(); printf('',JSDIR); printf('',JSDIR); } diff --git a/lib/HTMLTree.php b/lib/HTMLTree.php index d42147a..7ebd3f6 100644 --- a/lib/HTMLTree.php +++ b/lib/HTMLTree.php @@ -28,6 +28,7 @@ class HTMLTree extends Tree { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + static $js_drawn = false; $server = $this->getServer(); echo ''; @@ -85,27 +86,28 @@ class HTMLTree extends Tree { */ foreach ($this->getBaseEntries() as $base) { if (! $base->isInLDAP()) { + $js_drawn = false; $javascript_id++; - printf('', + $rdn = split('=',get_rdn($base->getDN())); + printf('', IMGDIR,$this->getDepth()+3-3,pretty_print_dn($base->getDN())); - $this->javascript .= sprintf('',$javascript_id); + $this->javascript .= sprintf('',$server->getIndex(),$javascript_id); + $this->javascript .= '
'; + $this->javascript .= ''; $this->javascript .= sprintf('',$server->getIndex()); $this->javascript .= sprintf('',htmlspecialchars($server->getContainer($base->getDN()))); $this->javascript .= sprintf('',get_rdn($base->getDN())); + $this->javascript .= sprintf('',$rdn[0]); + $this->javascript .= sprintf('',$rdn[0],$rdn[1]); + $this->javascript .= ''; + $this->javascript .= ''; + $this->javascript .= '
'; $this->javascript .= sprintf(''); - printf('', - $this->getDepth()+3-3,_('This base entry does not exist.'),$javascript_id,_('Create it?')); - - echo '
%s
%s
%s%s
'; - - if (! $onlytree) - echo ''; - - echo ''; - return; + printf('%s %s', + $this->getDepth()+3-3,_('This base entry does not exist.'),$server->getIndex(),$javascript_id,_('Create it?')); } else { $this->draw_item($base->getDN(),-1); @@ -138,8 +140,6 @@ class HTMLTree extends Tree { echo ''; echo "\n\n"; - static $js_drawn = false; - if (! $js_drawn) { $this->draw_javascript(); $js_drawn = true; @@ -540,6 +540,7 @@ class HTMLTree extends Tree { echo "\n"; echo $this->javascript; echo "\n"; + $this->javascript = ''; } } diff --git a/lib/PageRender.php b/lib/PageRender.php index a17d1e0..53f8f94 100644 --- a/lib/PageRender.php +++ b/lib/PageRender.php @@ -501,7 +501,7 @@ class PageRender extends Visitor { debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); foreach ($this->template->getAttributes(true) as $attribute) - if ($attribute->hasbeenModified()) + if ($attribute->hasbeenModified()) { if ($attribute->getValues()) foreach ($attribute->getValues() as $index => $details) $this->draw('HiddenValue',$attribute,$index); @@ -509,6 +509,7 @@ class PageRender extends Visitor { # We are deleting this attribute, so we need to display an empty value else $this->draw('HiddenValue',$attribute,0); + } } /** diff --git a/lib/Template.php b/lib/Template.php index 39d1daf..5abf3ab 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -330,6 +330,13 @@ class Template extends xmlTemplate { unset($_REQUEST['new_values']['objectclass']); } + } elseif (get_request('create_base')) { + if (get_request('rdn')) { + $rdn = explode('=',get_request('rdn')); + $attribute = $this->addAttribute($rdn[0],array('values'=>array($rdn[1]))); + $attribute->setRDN(1); + } + } else { debug_dump_backtrace('No DN or CONTAINER?',1); } @@ -535,7 +542,8 @@ class Template extends xmlTemplate { # If this is the default creation template, we need to set some additional values if ($this->isType('default') && $this->getContext() == 'create') { # Load our schema, based on the objectclasses that may have already been defined. - $this->rebuildTemplateAttrs(); + if (! get_request('create_base')) + $this->rebuildTemplateAttrs(); # Set the RDN attribute $counter = 1; @@ -620,6 +628,10 @@ class Template extends xmlTemplate { # If DN is not set, our DN will be made from our RDN and Container. elseif ($this->getRDN() && $this->getContainer()) return sprintf('%s,%s',$this->getRDN(),$this->GetContainer()); + + # If container is not set, we're probably creating the base + elseif ($this->getRDN() && get_request('create_base')) + return $this->getRDN(); } /** diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php index bdf3b0d..0e16f31 100644 --- a/lib/TemplateRender.php +++ b/lib/TemplateRender.php @@ -439,6 +439,8 @@ class TemplateRender extends PageRender { return 'modification'; elseif ($this->container) return 'creation'; + elseif (get_request('create_base')) + return 'creation'; else debug_dump_backtrace(sprintf('Unknown mode for %s',__METHOD__),1); } @@ -677,7 +679,10 @@ class TemplateRender extends PageRender { # Title $this->drawTitle(); - $this->drawSubTitle(); + if (get_request('create_base')) + $this->drawSubTitle(sprintf('%s: %s',_('Creating Base DN'),$this->template->getDN())); + else + $this->drawSubTitle(); echo "\n"; # Menu @@ -1287,6 +1292,10 @@ class TemplateRender extends PageRender { echo ''; foreach ($this->template->getRDNAttrs() as $rdn) printf('',htmlspecialchars($rdn)); + + if (get_request('create_base')) + echo ''; + echo ''; } } @@ -1299,8 +1308,13 @@ class TemplateRender extends PageRender { echo ''; printf('%s',_('Container')); - printf('',htmlspecialchars($default_container)); - draw_chooser_link('entry_form','container'); + echo ''; + if (get_request('create_base')) + printf('%s',$default_container,htmlspecialchars($default_container)); + else { + printf('',htmlspecialchars($default_container)); + draw_chooser_link('entry_form','container'); + } echo ''; echo ''; } @@ -1395,6 +1409,17 @@ class TemplateRender extends PageRender { public function drawFormEnd() { if (DEBUGTMP) printf('%s
',__METHOD__); + # Include the RDN details to support creating the base + if (get_request('create_base')) { + if (get_request('rdn')) { + $rdn = explode('=',get_request('rdn')); + echo '
'; + printf('',$rdn[0],$rdn[1]); + printf('',$rdn[0]); + echo '
'; + } + } + echo ''; # Javascript @@ -1457,12 +1482,13 @@ class TemplateRender extends PageRender { if (($this->template->isType('default') && $this->template->getContext() == 'create' && $page == 1) || $page < $this->pagelast) { echo '
'; + echo '
'; } else { echo ''; echo '
'; - if ($_SESSION[APPCONFIG]->getValue('confirm','create')) + if ($_SESSION[APPCONFIG]->getValue('confirm','create') && ! get_request('create_base')) echo ''; else echo ''; @@ -1475,6 +1501,8 @@ class TemplateRender extends PageRender { printf('',$this->getServerID()); printf('',$this->template->getID()); printf('',$page+1); + if (get_request('create_base')) + echo ''; $this->drawHiddenAttributes(); diff --git a/lib/ds_ldap_pla.php b/lib/ds_ldap_pla.php index 749c9ef..925d877 100644 --- a/lib/ds_ldap_pla.php +++ b/lib/ds_ldap_pla.php @@ -337,6 +337,11 @@ class ldap_pla extends ldap { if ($result) { # Update the tree $tree = get_cached_item($this->index,'tree'); + + # If we created the base, delete it, then add it back + if (get_request('create_base')) + $tree->delEntry($dn); + $tree->addEntry($dn); set_cached_item($this->index,'tree','null',$tree); diff --git a/lib/functions.php b/lib/functions.php index 15de838..d09ef8c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1422,11 +1422,8 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu $query['filter'] = sprintf('(%s=*)',$attr); $search = $server->query($query,'auto_number'); - if (! count($search)) - return; - # Construct a list of used numbers - $autonum = array(); + $autonum = array(0); foreach ($search as $dn => $values) { $values = array_change_key_case($values);