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