Code

Anonymous bind is not allowed.
[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   function Step_Schema()
33   {
34     $this->update_strings();
35   }
37   
38   function update_strings()
39   {
40     $this->s_title      = _("LDAP schema check");
41     $this->s_title_long = _("LDAP schema check");
42     $this->s_info       = _("Perform test on your curren LDAP schema");
43   }
45   
46   function execute()
47   {
48     $this->check_schema();
49     $failed_checks = 0 ; 
50     foreach($this->checked as $val) {
51       if(!$val['STATUS']){
52         $failed_checks ++;
53       }
54     }
56     if($failed_checks == 0){
57       $this->is_completed = TRUE;
58     }else{
59       $this->is_completed = FALSE;
60     }
62     $smarty = get_smarty();
63     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
64     $smarty->assign("schema_readable",$this->schema_readable);
65     $smarty->assign("enable_schema_check",$this->enable_schema_check);
66     $smarty->assign("checks",$this->checked);
67     $smarty->assign("not_checked",$this->not_checked);
68     $smarty->assign("failed_checks",$failed_checks);
69     return($smarty -> fetch (get_template_path("../setup/setup_schema.tpl")));
70   }
72   function check_schema_version($description, $version)
73   {
74     $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
75     return preg_match("/\(v$version\)/", $desc);
76   }
79   function save_object()
80   {
81     if(isset($_POST['step7_posted'])){
83       /* Get attributes */
84       foreach($this->attributes as $attr){
85         if(isset($_POST[$attr])){
86           $this->$attr = validate($_POST[$attr]);
87         }
88       }
89     }
90   }
93   function check_schema()
94   {
95     $cfg = $this->parent->captured_values;
96     $messages= array();
98     /* Get objectclasses */
99     $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
100     $objectclasses = $ldap->get_objectclasses();
101     if(count($objectclasses) == 0){
102       return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
103     }
105   
106     /* Which samba version do we use? */
107     if(isset($objectclasses['sambaSamAccount'])){
108       $this->samba_version = 3;
109     } elseif(isset($objectclasses['sambaAccount'])) {
110       $this->samba_version = 2;
111     }else{
112       $this->samba_version = 0;
113     }
115     /* This is the default block used for each entry. 
116      *  to avoid unset indexes. 
117      */
118     $def_check = array("REQUIRED_VERSION" => "0",
119                        "SCHEMA_FILES"     => array(),
120                        "CLASSES_REQUIRED" => array(),
121                        "STATUS"           => FALSE,
122                        "IS_MUST_HAVE"     => FALSE,
123                        "MSG"              => "",
124                        "INFO"             => "");#_("There is currently no information specified for this schema extension."));
127     /* The gosa base schema */
128     $checks['gosaObject'] = $def_check;
129     $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
130     $checks['gosaObject']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
131     $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
132     $checks['gosaObject']['IS_MUST_HAVE']     = TRUE;
134     /* GOsa Account class */
135     $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
136     $checks["gosaAccount"]["SCHEMA_FILES"]    = array("gosa+samba3.schema","gosa.schema");
137     $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
138     $checks["gosaAccount"]["IS_MUST_HAVE"]    = TRUE;
139     $checks["gosaAccount"]["INFO"]            = _("Used to store account specific informations.");
141     /* GOsa lock entry, used to mark currently edited objects as 'in use' */
142     $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
143     $checks["gosaLockEntry"]["SCHEMA_FILES"]     = array("gosa+samba3.schema","gosa.schema");
144     $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
145     $checks["gosaLockEntry"]["IS_MUST_HAVE"]     = TRUE;
146     $checks["gosaLockEntry"]["INFO"]             = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
148     /* Some other checks */
149     foreach(array(
150           "gosaCacheEntry"        => array("version" => "2.4"),
151           "gosaDepartment"        => array("version" => "2.4"),
152           "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
153           "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
154           "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
155           "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
156           "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
157           "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
158           "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
159           "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
160           "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
161           "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
162           "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
163           "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
164           "goShareServer"         => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
165           "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
166           "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
167           "goLdapServer"          => array("version" => "2.4"),
168           "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
169           "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
170           "goKrbServer"           => array("version" => "2.4"),
171           "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
172           ) as $name => $values){
174       $checks[$name] = $def_check;
175       if(isset($values['version'])){
176         $checks[$name]["REQUIRED_VERSION"] = $values['version'];
177       }
178       if(isset($values['file'])){
179         $checks[$name]["SCHEMA_FILES"] = array($values['file']);
180       }
181       $checks[$name]["CLASSES_REQUIRED"] = array($name);
182     }
184     foreach($checks as $name => $value){
185       foreach($value['CLASSES_REQUIRED'] as $class){
187         if(!isset($objectclasses[$name])){
188           $checks[$name]['STATUS'] = FALSE;
189           if($value['IS_MUST_HAVE']){
190             $checks[$name]['MSG']    = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
191           }else{
192             $checks[$name]['MSG']    = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
193           }
194         }elseif(!$this->check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
195           $checks[$name]['STATUS'] = FALSE;
197           if($value['IS_MUST_HAVE']){
198             $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
199           }else{
200             $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
201           }
202         }else{
203           $checks[$name]['STATUS'] = TRUE;
204           $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
205         }
206       }
207     }
208   
209     $tmp = $objectclasses;
211     /* Depending on selected rfc2307bis mode, we need different schema configurations */
212     $rfc2307bis = $this->parent->captured_values['rfc2307bis'];
213     $posixGroup = $tmp['posixGroup'];
214     $structural = preg_match("/STRUCTURAL/i",$posixGroup);
216     /* The gosa base schema */
217     $checks['posixGroup'] = $def_check;
218     $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
219     $checks['posixGroup']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
220     $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
221     $checks['posixGroup']['STATUS']           = TRUE;
222     $checks['posixGroup']['IS_MUST_HAVE']     = TRUE;
223     $checks['posixGroup']['MSG']              = "";
224     $checks['posixGroup']['INFO']             = "";
226     if($rfc2307bis && $structural){
227       $checks['posixGroup']['STATUS']           = FALSE;
228       $checks['posixGroup']['MSG']              = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
229       $checks['posixGroup']['INFO']             = _("In order to use rfc2307bis corform groups the objectClass 'posixGroup' must be AUXILIARY");
230     }
231     if(!$rfc2307bis && !$structural){
232       $checks['posixGroup']['STATUS']           = FALSE;
233       $checks['posixGroup']['MSG']              = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
234       $checks['posixGroup']['INFO']             = _("The objectClass 'posixGroup' must be STRUCTURAL");
235     }
238     $this->checked = $checks;
239   }
242 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
243 ?>