Enabled create_base

This commit is contained in:
Deon George 2010-03-11 17:46:03 +11:00
parent 1c467a6115
commit 7d17676fd7
10 changed files with 83 additions and 34 deletions

View File

@ -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

View File

@ -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()))

View File

@ -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()))

View File

@ -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('<script type="text/javascript" src="%slayersmenu-browser_detection.js"></script>',JSDIR);
printf('<script type="text/javascript" src="%sajax_tree.js"></script>',JSDIR);
}

View File

@ -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 '<table class="tree" border="0">';
@ -85,27 +86,28 @@ class HTMLTree extends Tree {
*/
foreach ($this->getBaseEntries() as $base) {
if (! $base->isInLDAP()) {
$js_drawn = false;
$javascript_id++;
printf('<tr><td class="spacer"></td><td class="spacer"></td><td><img src="%s/unknown.png" /></td><td colspan="%s">%s</td></tr>',
$rdn = split('=',get_rdn($base->getDN()));
printf('<tr><td class="spacer"></td><td class="spacer"></td><td><img src="%s/unknown.png" alt="" /></td><td colspan="%s">%s</td></tr>',
IMGDIR,$this->getDepth()+3-3,pretty_print_dn($base->getDN()));
$this->javascript .= sprintf('<form id="create_base_form_%s" method="post" action="cmd.php?cmd=template_engine">',$javascript_id);
$this->javascript .= sprintf('<form id="create_base_form_%s_%s" method="post" action="cmd.php">',$server->getIndex(),$javascript_id);
$this->javascript .= '<div>';
$this->javascript .= '<input type="hidden" name="cmd" value="template_engine" />';
$this->javascript .= sprintf('<input type="hidden" name="server_id" value="%s" />',$server->getIndex());
$this->javascript .= sprintf('<input type="hidden" name="container" value="%s" />',htmlspecialchars($server->getContainer($base->getDN())));
$this->javascript .= sprintf('<input type="hidden" name="rdn" value="%s" />',get_rdn($base->getDN()));
$this->javascript .= sprintf('<input type="hidden" name="rdn_attribute[]" value="%s" />',$rdn[0]);
$this->javascript .= sprintf('<input type="hidden" name="new_values[%s][]" value="%s" />',$rdn[0],$rdn[1]);
$this->javascript .= '<input type="hidden" name="template" value="none" />';
$this->javascript .= '<input type="hidden" name="create_base" value="true" />';
$this->javascript .= '</div>';
$this->javascript .= sprintf('</form>');
printf('<tr><td class="spacer"></td><td class="spacer"></td><td class="spacer"></td><td colspan="%s"><small>%s<a href="javascript:document.getElementById(\'create_base_form_%s\').submit()">%s</a></small></td></tr>',
$this->getDepth()+3-3,_('This base entry does not exist.'),$javascript_id,_('Create it?'));
echo '</table>';
if (! $onlytree)
echo '</div></td></tr>';
echo '</table>';
return;
printf('<tr><td class="spacer"></td><td class="spacer"></td><td class="spacer"></td><td colspan="%s"><small>%s <a href="javascript:document.getElementById(\'create_base_form_%s_%s\').submit()">%s</a></small></td></tr>',
$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 '</table>';
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 "<!-- Forms for javascript submit to call to create base_dns -->\n";
echo $this->javascript;
echo "<!-- The end of the forms for javascript submit to call to create base_dns -->\n";
$this->javascript = '';
}
}

View File

@ -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);
@ -510,6 +510,7 @@ class PageRender extends Visitor {
else
$this->draw('HiddenValue',$attribute,0);
}
}
/**
* Draw specific hidden attribute

View File

@ -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,6 +542,7 @@ 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.
if (! get_request('create_base'))
$this->rebuildTemplateAttrs();
# Set the RDN attribute
@ -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();
}
/**

View File

@ -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,6 +679,9 @@ class TemplateRender extends PageRender {
# Title
$this->drawTitle();
if (get_request('create_base'))
$this->drawSubTitle(sprintf('<b>%s</b>: %s',_('Creating Base DN'),$this->template->getDN()));
else
$this->drawSubTitle();
echo "\n";
@ -1287,6 +1292,10 @@ class TemplateRender extends PageRender {
echo '<tr><td colspan="2">';
foreach ($this->template->getRDNAttrs() as $rdn)
printf('<input type="hidden" name="rdn_attribute[]" value="%s" id="rdn_attribute"/>',htmlspecialchars($rdn));
if (get_request('create_base'))
echo '<input type="hidden" name="create_base" value="true" />';
echo '</td></tr>';
}
}
@ -1299,8 +1308,13 @@ class TemplateRender extends PageRender {
echo '<tr>';
printf('<td class="heading">%s</td>',_('Container'));
printf('<td><input type="text" name="container" size="40" value="%s" />',htmlspecialchars($default_container));
echo '<td>';
if (get_request('create_base'))
printf('%s<input type="hidden" name="container" size="40" value="%s" />',$default_container,htmlspecialchars($default_container));
else {
printf('<input type="text" name="container" size="40" value="%s" />',htmlspecialchars($default_container));
draw_chooser_link('entry_form','container');
}
echo '</td>';
echo '</tr>';
}
@ -1395,6 +1409,17 @@ class TemplateRender extends PageRender {
public function drawFormEnd() {
if (DEBUGTMP) printf('<font size=-2>%s</font><br />',__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 '<div>';
printf('<input type="hidden" name="new_values[%s][]" value="%s" />',$rdn[0],$rdn[1]);
printf('<input type="hidden" name="rdn_attribute[]" value="%s" />',$rdn[0]);
echo '</div>';
}
}
echo '</form>';
# Javascript
@ -1457,12 +1482,13 @@ class TemplateRender extends PageRender {
if (($this->template->isType('default') && $this->template->getContext() == 'create' && $page == 1) || $page < $this->pagelast) {
echo '<form action="cmd.php?cmd=template_engine" method="post" enctype="multipart/form-data" id="entry_form" onsubmit="return submitForm(this)">';
echo '<div>';
} else {
echo '<form action="cmd.php" method="post" enctype="multipart/form-data" id="entry_form" onsubmit="return submitForm(this)">';
echo '<div>';
if ($_SESSION[APPCONFIG]->getValue('confirm','create'))
if ($_SESSION[APPCONFIG]->getValue('confirm','create') && ! get_request('create_base'))
echo '<input type="hidden" name="cmd" value="create_confirm" />';
else
echo '<input type="hidden" name="cmd" value="create" />';
@ -1475,6 +1501,8 @@ class TemplateRender extends PageRender {
printf('<input type="hidden" name="server_id" value="%s" />',$this->getServerID());
printf('<input type="hidden" name="template" value="%s" />',$this->template->getID());
printf('<input type="hidden" name="page" value="%s" />',$page+1);
if (get_request('create_base'))
echo '<input type="hidden" name="create_base" value="true" />';
$this->drawHiddenAttributes();

View File

@ -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);

View File

@ -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);