Code

Added base detection button
[gosa.git] / setup / class_setupStep4.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 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       = "";
30   var $peopleou   = "ou=people,";
31   var $peopledn   = "cn";
32   var $groupou    = "ou=groups,";
33   var $uidbase    = 1000;
34   var $encryption = "crypt";
35   var $mail       = "kolab";
36   var $errors     = TRUE;
38   var $crypt_methods  = array();
39   var $mail_methods   = array();
41   var $connect_id = FALSE;
42   var $bind_id    = FALSE;
44   var $attributes = array("connection","location","admin","password","base","peopleou","peopledn","groupou",
45                           "uidbase","encryption","mail","errors");
47   function setup_step_4()
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     $tmp = @passwordMethod::get_available_methods_if_not_loaded();
53     $this->crypt_methods   = $tmp['name'];
54     $tmp = $this->get_available_mail_classes();
55     $this->mail_methods = $tmp['name'];
56   }
57   
58   function execute()
59   {
60     $smarty = get_smarty();
61     foreach($this->attributes as $attr){
62       $smarty->assign($attr,$this->$attr);
63     }
65     $smarty->assign("connection_established",$this->is_connection_established());
67     $smarty->assign("peopledns",array("uid","cn"));
68     $smarty->assign("crypt_methods",$this->crypt_methods);
69     $smarty->assign("mail_methods",$this->mail_methods);
71     return($smarty -> fetch (get_template_path("../setup/setup_step4.tpl")));
73   }
75   /* Returns the classnames auf the mail classes */
76   function get_available_mail_classes()
77   {
78     $dir = opendir( "../include");
79     $methods = array();
80     $suffix = "class_mail-methods-";
81     $lensuf = strlen($suffix);
82     $prefix = ".inc";
83     $lenpre = strlen($prefix);
84     $i = 0;
85     while (($file = readdir($dir)) !== false){
87       if(stristr($file,$suffix)) {
88         $lenfile = strlen($file);
89         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
90         $methods['file'][$i] = $file;
91         $methods[$i]['file'] = $file;
92         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
93         $i++;
94       }
95     }
96     return($methods); 
97   }
99   /* Check if specified server is reachable */
100   function is_connection_established()
101   {
103     @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
104     $cid = @ldap_connect($this->connection);
105       
106     $ds = @ldap_bind($cid, $this->admin, $this->password);
107     @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
108   }
110   
111   function try_to_get_base_automatically()
112   {
114     @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
115     $cid = @ldap_connect($this->connection);
117     $ds = @ldap_bind($cid);
118     @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
120     $sr=   ldap_search ($ds, NULL, "objectClass=*", array("namingContexts"));
121     $attr= ldap_get_entries($cid,$sr); 
122     echo ldap_error($cid);
123     print_a($attr);
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     /* Get base automatically */
136     if(isset($_POST['get_base'])){
137       $this->try_to_get_base_automatically();
138     }
139   }
142 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
143 ?>