Code

Moved rfc2307bis to ldap setup
[gosa.git] / setup / class_setupStep_Ldap.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
23 class Step_Ldap extends setup_step
24 {
25   var $connection = "ldap://localhost:389";
26   var $location   = "default";
27   var $admin      = "";
28   var $password   = "";
29   var $base       = "";
31   var $connect_id = FALSE;
32   var $bind_id    = FALSE;
34   var $resolve_filter = "*";
35   var $resolve_user   = FALSE;
36   var $tls            = FALSE;
38   var $rfc2307bis             = FALSE;
39   var $attributes = array("connection","location","admin","password","base","tls","rfc2307bis");
41   var $header_image= "images/proxy.png";
43   function Step_Ldap()
44   {
45     $this->update_strings();
47     
48   
49   }
51   
52   function update_strings()
53   {
54     $this->s_title      = _("LDAP setup");
55     $this->s_title_long = _("LDAP connection setup");
56     $this->s_info       = _("This dialog performs the basic configuration of the LDAP connectivity for GOsa.");
57   }
58   
59   
60   function execute()
61   {
62     $smarty = get_smarty();
63     foreach($this->attributes as $attr){
64       $smarty->assign($attr,$this->$attr);
65     }
67     /* Assign connection status */
68     $smarty->assign("connection_status",$this->get_connection_status());
70     /* Handle namingContext detection */
71     $attr = @LDAP::get_naming_contexts($this->connection);
72     unset($attr['count']);
73     $smarty->assign("namingContexts",$attr);
74     $smarty->assign("namingContextsCount",count($attr));
75     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
77     /* Addign resolved users */
78     $smarty->assign("resolve_user",$this->resolve_user);
79     if($this->resolve_user){
80       $tmp = $this->resolve_user();
81       $smarty->assign("resolved_users",$tmp);
82       $smarty->assign("resolved_users_count",count($tmp));
83       $smarty->assign("resolve_filter",$this->resolve_filter);
84     }
85     return($smarty -> fetch (get_template_path("../setup/setup_ldap.tpl")));
86   }
88   function get_connection_status()
89   {
90     $this->connect_id = FALSE;
91     $this->bind_id    = FALSE;
93     @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
94     $this->connect_id = @ldap_connect($this->connection);
95       
96     @ldap_set_option($this->connect_id, LDAP_OPT_PROTOCOL_VERSION, 3);
97     $this->bind_id = @ldap_bind($this->connect_id, $this->admin, $this->password);
98     
99     if(!$this->bind_id){
100       $str = sprintf(_("Anonymous bind failed on server '%s'."),$this->connection); 
101       if(!empty($this->admin)){
102         $str = sprintf(_("Bind as user '%s' failed on server '%s'."),$this->admin,$this->connection);
103       }      
104       return("<font color='red'>".$str."</font>");
105     }else{
106       if(empty($this->admin)){
107         $str = sprintf(_("Anonymous bind on server '%s' succeeded. Please specify user and password."),$this->connection); 
108         return("<font color='blue'>".$str."</font>");
109       }else{
110         $str = sprintf(_("Bind as user '%s' on server '%s' succeeded."),$this->admin,$this->connection);
111         return("<font color='green'>".$str."</font>");
112       }      
113     }
114   }
116   
117   function resolve_user()
118   {
119     $filter  = $this->resolve_filter;
120     $ldap = new LDAP("","",$this->connection);
121     $ldap->cd($this->base);
122     $ldap->search("(&(objectClass=person)(|(uid=".$filter.")(cn=".$filter.")))");
123     $tmp = array();
124     while($attrs = $ldap->fetch()){
125       $tmp[base64_encode($attrs['dn'])]= @LDAP::fix($attrs['dn']);
126       natcasesort($tmp);
127     }
128     return($tmp);
129   }   
132   function save_object()
133   {
134     foreach($this->attributes as $attr){
135       if(isset($_POST[$attr])){
136         $this->$attr = $_POST[$attr];
137       }
138     }
140     if(isset($_POST['resolve_user_x'])){
141       $this->resolve_user = !$this->resolve_user;
142     }
143     if(isset($_POST['resolve_user'])){
144       $this->resolve_user = !$this->resolve_user;
145     }
146   
147     /* Hide backward forward button*/
148     $this->dialog = $this->resolve_user;
149  
150     if(isset($_POST['resolve_filter'])){
151       $this->resolve_filter = $_POST['resolve_filter'];
152     }
154     if(isset($_POST['use_selected_user'])){
156       if(isset($_POST['admin_to_use'])){
157         $this->admin = base64_decode($_POST['admin_to_use']);
158         $this->resolve_user = false;
159       }
160     }
162     $this->get_connection_status();
163     if($this->bind_id){
164       $this->is_completed =TRUE;
165     }else{
166       $this->is_completed =FALSE;
167     }
168   }
171 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
172 ?>