Code

Added initial department migration step.
[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();
46   }
48   
49   function update_strings()
50   {
51     $this->s_title      = _("LDAP setup");
52     $this->s_title_long = _("LDAP connection setup");
53     $this->s_info       = _("This dialog performs the basic configuration of the LDAP connectivity for GOsa.");
54   }
55   
56   
57   function execute()
58   {
59     $smarty = get_smarty();
60     foreach($this->attributes as $attr){
61       $smarty->assign($attr,$this->$attr);
62     }
64     /* Assign connection status */
65     $smarty->assign("connection_status",$this->get_connection_status());
67     /* Handle namingContext detection */
68     $attr = @LDAP::get_naming_contexts($this->connection);
69     unset($attr['count']);
70     $smarty->assign("namingContexts",$attr);
71     $smarty->assign("namingContextsCount",count($attr));
72     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
74     /* Addign resolved users */
75     $smarty->assign("resolve_user",$this->resolve_user);
76     if($this->resolve_user){
77       $tmp = $this->resolve_user();
78       $smarty->assign("resolved_users",$tmp);
79       $smarty->assign("resolved_users_count",count($tmp));
80       $smarty->assign("resolve_filter",$this->resolve_filter);
81     }
82     return($smarty -> fetch (get_template_path("../setup/setup_ldap.tpl")));
83   }
85   function get_connection_status()
86   {
87     $this->connect_id = FALSE;
88     $this->bind_id    = FALSE;
90     @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
91     $this->connect_id = @ldap_connect($this->connection);
92       
93     @ldap_set_option($this->connect_id, LDAP_OPT_PROTOCOL_VERSION, 3);
94     $this->bind_id = @ldap_bind($this->connect_id, $this->admin, $this->password);
95     
96     if(!$this->bind_id){
97       $str = sprintf(_("Anonymous bind failed on server '%s'."),$this->connection); 
98       if(!empty($this->admin)){
99         $str = sprintf(_("Bind as user '%s' failed on server '%s'."),$this->admin,$this->connection);
100       }      
101       return("<font color='red'>".$str."</font>");
102     }else{
103       if(empty($this->admin)){
104         $str = sprintf(_("Anonymous bind on server '%s' succeeded. Please specify user and password."),$this->connection); 
105         return("<font color='blue'>".$str."</font>");
106       }else{
107         $str = sprintf(_("Bind as user '%s' on server '%s' succeeded."),$this->admin,$this->connection);
108         return("<font color='green'>".$str."</font>");
109       }      
110     }
111   }
113   
114   function resolve_user()
115   {
116     $filter  = $this->resolve_filter;
117     $ldap = new LDAP("","",$this->connection);
118     $ldap->cd($this->base);
119     $ldap->search("(&(objectClass=person)(|(uid=".$filter.")(cn=".$filter.")))");
120     $tmp = array();
121     while($attrs = $ldap->fetch()){
122       $tmp[base64_encode($attrs['dn'])]= @LDAP::fix($attrs['dn']);
123       natcasesort($tmp);
124     }
125     return($tmp);
126   }   
129   function save_object()
130   {
131     foreach($this->attributes as $attr){
132       if(isset($_POST[$attr])){
133         $this->$attr = $_POST[$attr];
134       }
135     }
137     if(isset($_POST['resolve_user_x'])){
138       $this->resolve_user = !$this->resolve_user;
139     }
140     if(isset($_POST['resolve_user'])){
141       $this->resolve_user = !$this->resolve_user;
142     }
143   
144     /* Hide backward forward button*/
145     $this->dialog = $this->resolve_user;
146  
147     if(isset($_POST['resolve_filter'])){
148       $this->resolve_filter = $_POST['resolve_filter'];
149     }
151     if(isset($_POST['use_selected_user'])){
153       if(isset($_POST['admin_to_use'])){
154         $this->admin = base64_decode($_POST['admin_to_use']);
155         $this->resolve_user = false;
156       }
157     }
159     $this->get_connection_status();
160     if($this->bind_id && !empty($this->admin)){
161       $this->is_completed =TRUE;
162     }else{
163       $this->is_completed =FALSE;
164     }
165   }
168 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
169 ?>