cf4e68d97b33c0aa2c4e50086f15033d67a1f5db
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 }
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 }
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 = TRUE;
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($class, $version)
73 {
74 return preg_match("/\(v$version\)/", $class['DESC']);
75 }
78 function save_object()
79 {
80 if(isset($_POST['step7_posted'])){
82 /* Get attributes */
83 foreach($this->attributes as $attr){
84 if(isset($_POST[$attr])){
85 $this->$attr = validate($_POST[$attr]);
86 }
87 }
88 }
89 }
92 function check_schema()
93 {
94 $cfg = $this->parent->captured_values;
95 $messages= array();
97 /* Get objectclasses */
98 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
99 $objectclasses = $ldap->get_objectclasses();
100 if(count($objectclasses) == 0){
101 print_red(_("Can't get schema information from server. No schema check possible!"));
102 }
105 /* Which samba version do we use? */
106 if(isset($objectclasses['sambaSamAccount'])){
107 $this->samba_version = 3;
108 } elseif(isset($objectclasses['sambaAccount'])) {
109 $this->samba_version = 2;
110 }else{
111 $this->samba_version = 0;
112 }
114 /* This is the default block used for each entry.
115 * to avoid unset indexes.
116 */
117 $def_check = array("REQUIRED_VERSION" => "0",
118 "SCHEMA_FILES" => array(),
119 "CLASSES_REQUIRED" => array(),
120 "STATUS" => FALSE,
121 "IS_MUST_HAVE" => FALSE,
122 "MSG" => "",
123 "INFO" => "");#_("There is currently no information specified for this schema extension."));
126 /* The gosa base schema */
127 $checks['gosaObject'] = $def_check;
128 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
129 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
130 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
131 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
133 /* GOsa Account class */
134 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
135 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
136 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
137 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
138 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
140 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
141 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
142 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
143 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
144 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
145 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
147 /* Some other checks */
148 foreach(array(
149 "gosaCacheEntry" => array("version" => "2.4"),
150 "gosaDepartment" => array("version" => "2.4"),
151 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
152 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
153 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
154 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
155 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
156 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
157 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
158 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
159 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
160 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
161 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
162 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
163 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
164 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
165 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
166 "goLdapServer" => array("version" => "2.4"),
167 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
168 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
169 "goKrbServer" => array("version" => "2.4"),
170 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
171 ) as $name => $values){
173 $checks[$name] = $def_check;
174 if(isset($values['version'])){
175 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
176 }
177 if(isset($values['file'])){
178 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
179 }
180 $checks[$name]["CLASSES_REQUIRED"] = array($name);
181 }
183 foreach($checks as $name => $value){
184 foreach($value['CLASSES_REQUIRED'] as $class){
186 if(!isset($objectclasses[$name])){
187 $checks[$name]['STATUS'] = FALSE;
188 if($value['IS_MUST_HAVE']){
189 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
190 }else{
191 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
192 }
193 }elseif(!$this->check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
194 $checks[$name]['STATUS'] = FALSE;
196 if($value['IS_MUST_HAVE']){
197 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
198 }else{
199 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
200 }
201 }else{
202 $checks[$name]['STATUS'] = TRUE;
203 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
204 }
205 }
206 }
208 $tmp = $objectclasses;
210 /* Depending on selected rfc2307bis mode, we need different schema configurations */
211 $rfc2307bis = $this->parent->captured_values['rfc2307bis'];
214 /* The gosa base schema */
215 $checks['posixGroup'] = $def_check;
216 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
217 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
218 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
219 $checks['posixGroup']['STATUS'] = TRUE;
220 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
221 $checks['posixGroup']['MSG'] = "";
222 $checks['posixGroup']['INFO'] = "";
224 if(isset($tmp['posixGroup'])){
225 $posixGroup = $tmp['posixGroup'];
226 $structural = preg_match("/STRUCTURAL/i",$posixGroup);
228 if($rfc2307bis && $structural){
229 $checks['posixGroup']['STATUS'] = FALSE;
230 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
231 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis corform groups the objectClass 'posixGroup' must be AUXILIARY");
232 }
233 if(!$rfc2307bis && !$structural){
234 $checks['posixGroup']['STATUS'] = FALSE;
235 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
236 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
237 }
238 }
240 $this->checked = $checks;
241 }
242 }
244 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
245 ?>