148c7df7d6146f91a0f45ea617b14ccd7f40c152
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 = 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 }
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 }
209 $this->checked = $checks;
210 $tmp = $objectclasses;
211 $not_checked = array();
212 foreach($tmp as $name => $val){
213 $desc = "no description.";
214 if(preg_match("/DESC/",$val)){
215 $desc = preg_replace("/^.*DESC[ ]*'/i","",$val) ;
216 $desc = preg_replace("/'.*$/i","",$desc) ;
217 }
218 $not_checked[$name] = $desc;
219 }
221 $this->not_checked = $not_checked;
222 }
223 }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>