Code

- fix for debian bug 535872
[gosa.git] / setup / class_setupStep_Schema.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_Schema extends setup_step
24 {
25   var $checked = array();
26   var $not_checked = array();
27   var $schema_readable  = FALSE;
28   var $attributes       = array("enable_schema_check","samba_version");
29   var $enable_schema_check = TRUE;
30   var $samba_version       = 3;
32   var $found_ocs = 0; 
33  
34   function Step_Schema()
35   {
36     $this->update_strings();
37   }
39   
40   function update_strings()
41   {
42     $this->s_title      = _("LDAP schema check");
43     $this->s_title_long = _("LDAP schema check");
44     $this->s_info       = _("Perform test on your current LDAP schema");
45   }
47   
48   function execute()
49   {
50     $this->check_schema();
51     $failed_checks = 0 ; 
52     foreach($this->checked as $val) {
53       if(!$val['STATUS']){
54         $failed_checks ++;
55       }
56     }
58     if($failed_checks == 0){
59       $this->is_completed = TRUE;
60     }else{
61       $this->is_completed = TRUE;
62     }
63     
64     /* Check if the database is already initialised.
65      * If the root object is missing we can't read any schema informations.
66      * In this case we should display a message.
67      */
68     $cv = $this->parent->captured_values;
70     /* Establish ldap connection */
71     $ldap = new LDAP($cv['admin'],
72         $cv['password'],
73         $cv['connection'],
74         FALSE,
75         $cv['tls']);
77     /* Check if root object exists */
78     $ldap->cd($cv['base']);
79     $ldap->set_size_limit(1);
80     $res = $ldap->search("(objectClass=*)");
81     $ldap->set_size_limit(0);
83     $smarty = get_smarty();
84     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
85     $smarty->assign("database_initialised", ($res == TRUE));
86     $smarty->assign("found_ocs", $this->found_ocs);
87     $smarty->assign("schema_readable",$this->schema_readable);
88     $smarty->assign("enable_schema_check",$this->enable_schema_check);
89     $smarty->assign("checks",$this->checked);
90     $smarty->assign("not_checked",$this->not_checked);
91     $smarty->assign("failed_checks",$failed_checks);
92     return($smarty -> fetch (get_template_path("../setup/setup_schema.tpl")));
93   }
95   function save_object()
96   {
97     if(isset($_POST['step7_posted'])){
99       /* Get attributes */
100       foreach($this->attributes as $attr){
101         if(isset($_POST[$attr])){
102           $this->$attr = validate($_POST[$attr]);
103         }
104       }
105     }
106   }
108   function check_schema()
109   {
110     $cfg = $this->parent->captured_values;
111     $rfc2307bis = $cfg['rfc2307bis'];
112     $this->checked = check_schema($cfg,$rfc2307bis);
114     /* Get objectclasses */
115     $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
116     $objectclasses = $ldap->get_objectclasses();
117     $this->found_ocs = count($objectclasses);
119     /* Which samba version do we use? */
120     if(isset($objectclasses['sambaSamAccount'])){
121       $this->samba_version = 3;
122     } elseif(isset($objectclasses['sambaAccount'])) {
123       $this->samba_version = 2;
124     }else{
125       $this->samba_version = 0;
126     }
127   }
130 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
131 ?>