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 setup_step_4 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 $attributes = array("connection","location","admin","password","base","tls");
40 function setup_step_4()
41 {
42 $this->s_title = _("Ldap settings");
43 $this->s_title_long = _("Ldap connection setup");
44 $this->s_info = _("This dialog allows the basic configuration of GOsa's behaviour and properties in your main configuration.");
45 }
47 function execute()
48 {
49 $smarty = get_smarty();
50 foreach($this->attributes as $attr){
51 $smarty->assign($attr,$this->$attr);
52 }
54 /* Assign connection status */
55 $smarty->assign("connection_status",$this->get_connection_status());
57 /* Handle namingContext detection */
58 $attr = @LDAP::get_naming_contexts($this->connection);
59 unset($attr['count']);
60 $smarty->assign("namingContexts",$attr);
61 $smarty->assign("namingContextsCount",count($attr));
62 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
64 /* Addign resolved users */
65 $smarty->assign("resolve_user",$this->resolve_user);
66 if($this->resolve_user){
67 $tmp = $this->resolve_user();
68 $smarty->assign("resolved_users",$tmp);
69 $smarty->assign("resolved_users_count",count($tmp));
70 $smarty->assign("resolve_filter",$this->resolve_filter);
71 }
72 return($smarty -> fetch (get_template_path("../setup/setup_step4.tpl")));
73 }
75 function get_connection_status()
76 {
77 $this->connect_id = FALSE;
78 $this->bind_id = FALSE;
80 @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
81 $this->connect_id = @ldap_connect($this->connection);
83 @ldap_set_option($this->connect_id, LDAP_OPT_PROTOCOL_VERSION, 3);
84 $this->bind_id = @ldap_bind($this->connect_id, $this->admin, $this->password);
86 if(!$this->bind_id){
87 $str = sprintf(_("Anonymous bind failed on server '%s'."),$this->connection);
88 if(!empty($this->admin)){
89 $str = sprintf(_("Bind as user '%s' failed on server '%s'."),$this->admin,$this->connection);
90 }
91 return("<font color='red'>".$str."</font>");
92 }else{
93 if(empty($this->admin)){
94 $str = sprintf(_("Anonymous bind successful on server '%s'. Please specify user and password."),$this->connection);
95 return("<font color='blue'>".$str."</font>");
96 }else{
97 $str = sprintf(_("Bind as user '%s' successful on server '%s'."),$this->admin,$this->connection);
98 return("<font color='green'>".$str."</font>");
99 }
100 }
101 }
104 function resolve_user()
105 {
106 $filter = $this->resolve_filter;
107 $ldap = new LDAP("","",$this->connection);
108 $ldap->cd($this->base);
109 $ldap->search("(&(objectClass=person)(|(uid=".$filter.")(cn=".$filter.")))");
110 $tmp = array();
111 while($attrs = $ldap->fetch()){
112 $tmp[$attrs['dn']]=$attrs['dn'];
113 natcasesort($tmp);
114 }
115 return($tmp);
116 }
119 function save_object()
120 {
121 foreach($this->attributes as $attr){
122 if(isset($_POST[$attr])){
123 $this->$attr = $_POST[$attr];
124 }
125 }
127 if(isset($_POST['resolve_user'])){
128 $this->resolve_user = !$this->resolve_user;
129 }
131 if(isset($_POST['resolve_filter'])){
132 $this->resolve_filter = $_POST['resolve_filter'];
133 }
135 if(isset($_POST['use_selected_user'])){
137 if(isset($_POST['admin_to_use'])){
138 $this->admin = $_POST['admin_to_use'];
139 $this->resolve_user = false;
140 }
141 }
143 if($this->bind_id){
144 $this->is_completed =TRUE;
145 }else{
146 $this->is_completed =FALSE;
147 }
148 }
149 }
151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
152 ?>