Code

Added new checkbox that allows to leave the lang attribute empty
[gosa.git] / setup / class_setupStep7.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_7 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 $display_type     = "failed";
30   var $enable_schema_check = TRUE;
31   var $samba_version       = 3;
33   function setup_step_7()
34   {
35     $this->update_strings();
36   }
38   
39   function update_strings()
40   {
41     $this->s_title      = _("Ldap schema check");
42     $this->s_title_long = _("Ldap schema check");
43     $this->s_info       = _("This dialog checks your ldap schema setup");
44   }
46   
47   function execute()
48   {
49     $this->check_schema();
50     $failed_checks = 0 ; 
51     foreach($this->checked as $val) {
52       if(!$val['STATUS']){
53         $failed_checks ++;
54       }
55     }
57     if($failed_checks == 0){
58       $this->is_completed = TRUE;
59     }else{
60       $this->is_completed = FALSE;
61     }
63     $smarty = get_smarty();
64     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
65     $smarty->assign("display_type",$this->display_type);
66     $smarty->assign("schema_readable",$this->schema_readable);
67     $smarty->assign("enable_schema_check",$this->enable_schema_check);
68     $smarty->assign("checks",$this->checked);
69     $smarty->assign("not_checked",$this->not_checked);
70     $smarty->assign("failed_checks",$failed_checks);
71     return($smarty -> fetch (get_template_path("../setup/setup_step7.tpl")));
72   }
74   function check_schema_version($description, $version)
75   {
76     $desc= preg_replace("/^.* DESC\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $description);
77     return preg_match("/\(v$version\)/", $desc);
78   }
81   function save_object()
82   {
83     if(isset($_POST['step7_posted'])){
85       /* Get diplay method */
86       if(isset($_POST['display_type']) && in_array($_POST['display_type'],array("failed","checked","all"))){
87         $this->display_type = $_POST['display_type'];
88       }
90       /* Get attributes */
91       foreach($this->attributes as $attr){
92         if(isset($_POST[$attr])){
93           $this->$attr = validate($_POST[$attr]);
94         }
95       }
96     }
97   }
100   function check_schema()
101   {
102     $cfg = $this->parent->captured_values;
103     $messages= array();
105     /* Get objectclasses */
106     $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
107     $objectclasses = $ldap->get_objectclasses();
108     if(count($objectclasses) == 0){
109       return (array(array("msg" => _("Can't get schema information from server. No schema check possible!"), "status" => FALSE)));
110     }
112   
113     /* Which samba version do we use? */
114     if(isset($objectclasses['sambaSamAccount'])){
115       $this->samba_version = 3;
116     } elseif(isset($objectclasses['sambaAccount'])) {
117       $this->samba_version = 2;
118     }else{
119       $this->samba_version = 0;
120     }
122     /* This is the default block used for each entry. 
123      *  to avoid unset indexes. 
124      */
125     $def_check = array("REQUIRED_VERSION" => "0",
126                        "SCHEMA_FILES"     => array(),
127                        "CLASSES_REQUIRED" => array(),
128                        "STATUS"           => FALSE,
129                        "IS_MUST_HAVE"     => FALSE,
130                        "MSG"              => "",
131                        "INFO"             => "");#_("There is currently no information specified for this schema extension."));
134     /* The gosa base schema */
135     $checks['gosaObject'] = $def_check;
136     $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
137     $checks['gosaObject']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
138     $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
139     $checks['gosaObject']['IS_MUST_HAVE']     = TRUE;
141     /* GOsa Account class */
142     $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
143     $checks["gosaAccount"]["SCHEMA_FILES"]    = array("gosa+samba3.schema","gosa.schema");
144     $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
145     $checks["gosaAccount"]["IS_MUST_HAVE"]    = TRUE;
146     $checks["gosaAccount"]["INFO"]            = _("Used to store account specific informations.");
148     /* GOsa lock entry, used to mark currently edited objects as 'in use' */
149     $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
150     $checks["gosaLockEntry"]["SCHEMA_FILES"]     = array("gosa+samba3.schema","gosa.schema");
151     $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
152     $checks["gosaLockEntry"]["IS_MUST_HAVE"]     = TRUE;
153     $checks["gosaLockEntry"]["INFO"]             = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
155     /* Some other checks */
156     foreach(array(
157           "gosaCacheEntry"        => array("version" => "2.4"),
158           "gosaDepartment"        => array("version" => "2.4"),
159           "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
160           "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
161           "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
162           "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
163           "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
164           "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
165           "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
166           "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
167           "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
168           "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
169           "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
170           "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
171           "goShareServer"         => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
172           "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
173           "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
174           "goLdapServer"          => array("version" => "2.4"),
175           "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
176           "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.schema"),
177           "goKrbServer"           => array("version" => "2.4"),
178           "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
179           ) as $name => $values){
181       $checks[$name] = $def_check;
182       if(isset($values['version'])){
183         $checks[$name]["REQUIRED_VERSION"] = $values['version'];
184       }
185       if(isset($values['file'])){
186         $checks[$name]["SCHEMA_FILES"] = array($values['file']);
187       }
188       $checks[$name]["CLASSES_REQUIRED"] = array($name);
189     }
191     foreach($checks as $name => $value){
192       foreach($value['CLASSES_REQUIRED'] as $class){
194         if(!isset($objectclasses[$name])){
195           $checks[$name]['STATUS'] = FALSE;
196           if($value['IS_MUST_HAVE']){
197             $checks[$name]['MSG']    = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
198           }else{
199             $checks[$name]['MSG']    = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
200           }
201         }elseif(!$this->check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
202           $checks[$name]['STATUS'] = FALSE;
204           if($value['IS_MUST_HAVE']){
205             $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
206           }else{
207             $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
208           }
209         }else{
210           $checks[$name]['STATUS'] = TRUE;
211           $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
212         }
213       }
214     }
215   
216     $this->checked = $checks;
217     $tmp = $objectclasses;
218     $not_checked = array();
219     foreach($tmp as $name => $val){
220       $desc = "no description.";
221       if(preg_match("/DESC/",$val)){ 
222         $desc = preg_replace("/^.*DESC[ ]*'/i","",$val) ;
223         $desc = preg_replace("/'.*$/i","",$desc) ;
224       }  
225       $not_checked[$name] = $desc;
226     }
228     $this->not_checked = $not_checked;  
229   }
232 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
233 ?>