s_title = _("Ldap settings");
$this->s_title_long = _("Ldap connection setup");
$this->s_info = _("This dialog allows the basic configuration of GOsa's behaviour and properties in your main configuration.");
}
function execute()
{
$smarty = get_smarty();
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
}
/* Assign connection status */
$smarty->assign("connection_status",$this->get_connection_status());
/* Handle namingContext detection */
$attr = @LDAP::get_naming_contexts($this->connection);
unset($attr['count']);
$smarty->assign("namingContexts",$attr);
$smarty->assign("namingContextsCount",count($attr));
$smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
/* Addign resolved users */
$smarty->assign("resolve_user",$this->resolve_user);
if($this->resolve_user){
$tmp = $this->resolve_user();
$smarty->assign("resolved_users",$tmp);
$smarty->assign("resolved_users_count",count($tmp));
$smarty->assign("resolve_filter",$this->resolve_filter);
}
return($smarty -> fetch (get_template_path("../setup/setup_step4.tpl")));
}
function get_connection_status()
{
$this->connect_id = FALSE;
$this->bind_id = FALSE;
@ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$this->connect_id = @ldap_connect($this->connection);
@ldap_set_option($this->connect_id, LDAP_OPT_PROTOCOL_VERSION, 3);
$this->bind_id = @ldap_bind($this->connect_id, $this->admin, $this->password);
if(!$this->bind_id){
$str = sprintf(_("Anonymous bind failed on server '%s'."),$this->connection);
if(!empty($this->admin)){
$str = sprintf(_("Bind as user '%s' failed on server '%s'."),$this->admin,$this->connection);
}
return("".$str."");
}else{
if(empty($this->admin)){
$str = sprintf(_("Anonymous bind successful on server '%s'. Please specify user and password."),$this->connection);
return("".$str."");
}else{
$str = sprintf(_("Bind as user '%s' successful on server '%s'."),$this->admin,$this->connection);
return("".$str."");
}
}
}
function resolve_user()
{
$filter = $this->resolve_filter;
$ldap = new LDAP("","",$this->connection);
$ldap->cd($this->base);
$ldap->search("(&(objectClass=person)(|(uid=".$filter.")(cn=".$filter.")))");
$tmp = array();
while($attrs = $ldap->fetch()){
$tmp[$attrs['dn']]=$attrs['dn'];
natcasesort($tmp);
}
return($tmp);
}
function save_object()
{
foreach($this->attributes as $attr){
if(isset($_POST[$attr])){
$this->$attr = $_POST[$attr];
}
}
if(isset($_POST['resolve_user'])){
$this->resolve_user = !$this->resolve_user;
}
if(isset($_POST['resolve_filter'])){
$this->resolve_filter = $_POST['resolve_filter'];
}
if(isset($_POST['use_selected_user'])){
if(isset($_POST['admin_to_use'])){
$this->admin = $_POST['admin_to_use'];
$this->resolve_user = false;
}
}
if($this->bind_id){
$this->is_completed =TRUE;
}else{
$this->is_completed =FALSE;
}
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>