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