1 <?php
3 class configRegistry{
5 public $config = NULL;
6 public $properties = array();
7 public $ldapStoredProperties = array();
8 public $fileStoredProperties = array();
9 public $classToName = array();
11 public $status = 'none';
13 // Excludes property values defined in ldap
14 public $ignoreLdapProperties = FALSE;
16 // Contains all classes with plInfo
17 public $classesWithInfo = array();
18 public $pluginRequirements = array();
19 public $categoryToClass = array();
21 public $objectClasses = array();
23 public $detectedSchemaIssues = array();
24 public $schemaCheckFailed = FALSE;
25 public $schemaCheckFinished = FALSE;
26 public $pluginsDeactivated = array();
29 /*! \brief Constructs the config registry
30 * @param config The configuration object
31 * @return
32 */
33 function __construct($config)
34 {
35 $this->config = &$config;
37 // Detect classes that have a plInfo method
38 global $class_mapping;
39 foreach ($class_mapping as $cname => $path){
40 $cmethods = get_class_methods($cname);
41 if (is_array($cmethods) && in_array_ics('plInfo',$cmethods)){
43 // Get plugin definitions
44 $def = call_user_func(array($cname, 'plInfo'));;
46 // Register Post Events (postmodfiy,postcreate,postremove,checkhook)
47 if(count($def)){
48 $this->classesWithInfo[$cname] = $def;
49 }
50 }
51 }
53 // (Re)Load properties
54 $this->reload();
55 }
58 /*! \brief Checks whether the schema check was called in the current session or not.
59 * @return Boolean True if check was already called
60 */
61 function schemaCheckFinished()
62 {
63 return($this->schemaCheckFinished);
64 }
67 /*! \brief Starts the schema validation
68 * @param Boolean 'force' Force a re-check.
69 * @param Boolean 'disableIncompatiblePlugins' Disables of incompatible GOsa-plugins.
70 * @return Boolean True on success else FALSE
71 */
72 function validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE, $objectClassesToUse = array())
73 {
74 // Read objectClasses from ldap
75 if(count($objectClassesToUse)){
76 $this->setObjectClasses($objectClassesToUse);
77 }elseif(!count($this->objectClasses)){
78 $ldap = $this->config->get_ldap_link();
79 $ldap->cd($this->config->current['BASE']);
80 $this->setObjectClasses($ldap->get_objectclasses());
81 }
83 return($this->_validateSchemata($force, $disableIncompatiblePlugins));
84 }
87 /*! \brief Sets the list object classes to use while validation the schema. (See 'validateSchemata')
88 * This is called from the GOsa-Setup
89 * @param Array The list of object classes (usually LDAP::get_objectlclasses()).
90 * @return void
91 */
92 function setObjectClasses($ocs)
93 {
94 $this->objectClasses = $ocs;
95 }
98 /*! \brief Returns an array which contains all unresolved schemata requirements.
99 * @return Array An array containing all errors/issues
100 */
101 function getSchemaResults()
102 {
103 return($this->detectedSchemaIssues);
104 }
107 /*! \brief This method checks if the installed ldap-schemata matches the plugin requirements.
108 * @param Boolean 'force' Force a re-check.
109 * @param Boolean 'disableIncompatiblePlugins' Disables of incompatible GOsa-plugins.
110 * @return String
111 */
112 private function _validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE)
113 {
114 // We cannot check without readable schema info
115 if(!count($this->objectClasses)){
116 return(TRUE);
117 }
119 // Don't do things twice unless forced
120 if($this->schemaCheckFinished && !$force) return($this->schemaCheckFailed);
122 // Prepare result array
123 $this->detectedSchemaIssues = array();
124 $this->detectedSchemaIssues['missing'] = array();
125 $this->detectedSchemaIssues['versionMismatch'] = array();
127 // Clear last results
128 $this->pluginsDeactivated = array();
130 // Collect required schema infos
131 $this->pluginRequirements = array('ldapSchema' => array());
132 $this->categoryToClass = array();
133 foreach($this->classesWithInfo as $cname => $defs){
134 if(isset($defs['plRequirements'])){
135 $this->pluginRequirements[$cname] = $defs['plRequirements'];
136 }
137 }
139 // Check schema requirements now $missing = $invalid = array();
140 foreach($this->pluginRequirements as $cname => $requirements){
142 // Check LDAP schema requirements for this plugins
143 $failure = FALSE;
144 if(isset($requirements['ldapSchema'])){
145 foreach($requirements['ldapSchema'] as $oc => $version){
146 if(!$this->ocAvailable($oc)){
147 $this->detectedSchemaIssues['missing'][$oc] = $oc;
148 $this->schemaCheckFailed = TRUE;
149 $failure = TRUE;
150 }elseif(!empty($version)){
151 $currentVersion = $this->getObjectClassVersion($oc);
152 if(!empty($currentVersion) && !$this->ocVersionMatch($version, $currentVersion)){
153 if($currentVersion == -1){
154 $currentVersion = _("unknown");
155 }
156 $this->detectedSchemaIssues['versionMismatch'][$oc] =
157 sprintf(_("%s has version %s but %s is required!"), bold($oc),bold($currentVersion),bold($version));
158 $this->schemaCheckFailed = TRUE;
159 $failure = TRUE;
160 }
161 }
162 }
163 }
165 // Display corresponding plugins now
166 if($disableIncompatiblePlugins && $failure && isset($requirements['onFailureDisablePlugin'])){
167 foreach($requirements['onFailureDisablePlugin'] as $name){
168 $this->pluginsDeactivated[$name] = $name;
169 }
170 }
171 }
172 $this->schemaCheckFinished =TRUE;
173 session::un_set('plist');
174 return(!$this->schemaCheckFailed);
175 }
178 /*! \brief The function 'validateSchemata' may has disabled some GOsa-Plugins,
179 * the list of disabled plugins will be returned here.
180 * @return Array The list of plugins disabled by 'validateSchemata'
181 */
182 function getDisabledPlugins()
183 {
184 return($this->pluginsDeactivated);
185 }
188 /*! \brief Displays an error message with all issues detect during the schema validation.
189 */
190 function displayRequirementErrors()
191 {
192 $message = "";
193 if(count($this->detectedSchemaIssues['missing'])){
194 $message.= "<br>".
195 _("The following object classes are missing:").
196 "<div class='scrollContainer' style='height:100px'>".
197 msgPool::buildList(array_values($this->detectedSchemaIssues['missing'])).
198 "</div>";
199 }
200 if(count($this->detectedSchemaIssues['versionMismatch'])){
201 $message.= "<br>".
202 _("The following object classes are outdated:").
203 "<div class='scrollContainer' style='height:100px'>".
204 msgPool::buildList(array_values($this->detectedSchemaIssues['versionMismatch'])).
205 "</div>";
206 }
207 if($message != ""){
208 $message.= "<br>"._("Plugins that require one or more of the object classes above will be disabled until the object classes get updated.");
210 msg_dialog::display(_("Schema validation error"),$message, ERROR_DIALOG);
211 }
212 }
215 /*! \brief Checks to version strings (e.g. '>=v2.8' and '2.9')
216 * @param String The required version with operators (e.g. '>=2.8')
217 * @param String The version to match for withOUT operators (e.g. '2.9')
218 * @return Boolean True if version matches else false.
219 */
220 private function ocVersionMatch($required, $installed)
221 {
222 $operator = preg_replace('/^([=<>]*).*$/',"\\1",$required);
223 $required = preg_replace('/^[=<>]*(.*)$/',"\\1",$required);
224 return(version_compare($installed,$required, $operator));
225 }
228 /*! \brief Returns the currently installed version of a given object class.
229 * @param String The name of the objectClass to check for.
230 * @return String The version string of the objectClass (e.g. v2.7)
231 */
232 function getObjectClassVersion($oc)
233 {
234 if(!isset($this->objectClasses[$oc])){
235 return(NULL);
236 }else{
237 $version = -1; // unknown
238 if(preg_match("/(v[^)]*)/", $this->objectClasses[$oc]['DESC'])){
239 $version = preg_replace('/^.*\(v([^)]*)\).*$/',"\\1", $this->objectClasses[$oc]['DESC']);
240 }
241 }
242 return($version);
243 }
246 /*! \brief Check whether the given object class is available or not.
247 * @param String The name of the objectClass to check for (e.g. 'mailAccount')
248 * @return Boolean Returns TRUE if the class exists else FALSE.
249 */
250 function ocAvailable($name)
251 {
252 return(isset($this->objectClasses[$name]));
253 }
256 /*! \brief Re-loads the list of installed GOsa-Properties.
257 * @param Boolean $force If force is TRUE, the complete properties list is rebuild..
258 */
259 function reload($force = FALSE)
260 {
261 // Do not reload the properties everytime, once we have
262 // everything loaded and registrered skip the reload.
263 // Status is 'finished' once we had a ldap connection (logged in)
264 if(!$force && $this->status == 'finished') return;
266 // Reset everything
267 $this->ldapStoredProperties = array();
268 $this->fileStoredProperties = array();
269 $this->properties = array();
270 $this->mapByName = array();
272 if(!$this->config) return;
274 // Search for config flags defined in the config file (TAB section)
275 foreach($this->config->data['TABS'] as $tabname => $tabdefs){
276 foreach($tabdefs as $info){
278 // Check if the info is valid
279 if(isset($info['NAME']) && isset($info['CLASS'])){
281 // Check if there is nore than just the plugin definition
282 if(count($info) > 2){
283 foreach($info as $name => $value){
285 if(!in_array($name, array('CLASS','NAME'))){
286 $class= $info['CLASS'];
287 $this->fileStoredProperties[$class][strtolower($name)] = $value;
288 }
289 }
290 }
291 }
292 }
293 }
295 // Search for config flags defined in the config file (MENU section)
296 foreach($this->config->data['MENU'] as $section => $entries){
297 foreach($entries as $entry){
298 if(count($entry) > 2 && isset($entry['CLASS'])){
299 $class = $entry['CLASS'];
300 foreach($entry as $name => $value){
301 if(!in_array($name, array('CLASS','ACL'))){
302 $this->fileStoredProperties[strtolower($class)][strtolower($name)] = $value;
303 }
304 }
305 }
306 }
307 }
309 // Search for config flags defined in the config file (MAIN section)
310 foreach($this->config->data['MAIN'] as $name => $value){
311 $this->fileStoredProperties['core'][strtolower($name)] = $value;
312 }
314 // Search for config flags defined in the config file (Current LOCATION section)
315 if(isset($this->config->current)){
316 foreach($this->config->current as $name => $value){
317 $this->fileStoredProperties['core'][strtolower($name)] = $value;
318 }
319 }
321 // Skip searching for LDAP defined properties if 'ignoreLdapProperties' is set to 'true'
322 // in the config.
323 $this->ignoreLdapProperties = FALSE;
324 if(isset($this->fileStoredProperties['core'][strtolower('ignoreLdapProperties')]) &&
325 preg_match("/(true|on)/i", $this->fileStoredProperties['core'][strtolower('ignoreLdapProperties')])){
326 $this->ignoreLdapProperties = TRUE;
327 }
329 // Search for all config flags defined in the LDAP - BUT only if we ARE logged in.
330 if(!empty($this->config->current['CONFIG'])){
331 $ldap = $this->config->get_ldap_link();
332 $ldap->cd($this->config->current['CONFIG']);
333 $ldap->search('(&(objectClass=gosaConfig)(gosaSetting=*))', array('cn','gosaSetting'));
334 while($attrs = $ldap->fetch()){
335 $class = $attrs['cn'][0];
336 for($i=0; $i<$attrs['gosaSetting']['count']; $i++){
337 list($name,$value) = preg_split("/:/",$attrs['gosaSetting'][$i],2);
338 $this->ldapStoredProperties[$class][$name] = $value;
339 }
340 }
341 $this->status = 'finished';
342 }
344 // Register plugin properties.
345 foreach ($this->classesWithInfo as $cname => $def){
347 // Detect class name
348 $name = $cname;
349 $name = (isset($def['plShortName'])) ? $def['plShortName'] : $cname;
350 $name = (isset($def['plDescription'])) ? $def['plDescription'] : $cname;
352 // Register post events
353 $this->classToName[$cname] = $name;
354 $data = array('name' => 'postcreate','type' => 'command');
355 $this->register($cname, $data);
356 $data = array('name' => 'postremove','type' => 'command');
357 $this->register($cname, $data);
358 $data = array('name' => 'postmodify','type' => 'command');
359 $this->register($cname, $data);
360 $data = array('name' => 'check', 'type' => 'command');
361 $this->register($cname, $data);
363 // Register properties
364 if(isset($def['plProperties'])){
365 foreach($def['plProperties'] as $property){
366 $this->register($cname, $property);
367 }
368 }
369 }
370 }
373 /*! \brief Registers a GOsa-Property and thus makes it useable by GOsa and its plugins.
374 * @param String $class The name of the class/plugin that wants to register this property.
375 * @return Array $data An array containing all data set in plInfo['plProperty]
376 */
377 function register($class,$data)
378 {
379 $id = count($this->properties);
380 $this->properties[$id] = new gosaProperty($this,$class,$data);
381 $p = strtolower("{$class}::{$data['name']}");
382 $this->mapByName[$p] = $id;
383 }
386 /*! \brief Returns all registered properties.
387 * @return Array A list of all properties.
388 */
389 public function getAllProperties()
390 {
391 return($this->properties);
392 }
395 /*! \brief Checks whether a property exists or not.
396 * @param String $class The class name (e.g. 'core' or 'mailAccount')
397 * @param String $name The property name (e.g. 'sessionTimeout' or 'mailMethod')
398 * @return Boolean TRUE if it exists else FALSE.
399 */
400 function propertyExists($class,$name)
401 {
402 $p = strtolower("{$class}::{$name}");
403 return(isset($this->mapByName[$p]));
404 }
407 /*! \brief Returns the id of a registered property.
408 * @param String $class The class name (e.g. 'core' or 'mailAccount')
409 * @param String $name The property name (e.g. 'sessionTimeout' or 'mailMethod')
410 * @return Integer The id for the given property.
411 */
412 private function getId($class,$name)
413 {
414 $p = strtolower("{$class}::{$name}");
415 if(!isset($this->mapByName[$p])){
416 return(-1);
417 }
418 return($this->mapByName[$p]);
419 }
422 /*! \brief Returns a given property, if it exists.
423 * @param String $class The class name (e.g. 'core' or 'mailAccount')
424 * @param String $name The property name (e.g. 'sessionTimeout' or 'mailMethod')
425 * @return GOsaPropery The property or 'NULL' if it doesn't exists.
426 */
427 function getProperty($class,$name)
428 {
429 if($this->propertyExists($class,$name)){
430 return($this->properties[$this->getId($class,$name)]);
431 }
432 return(NULL);
433 }
436 /*! \brief Returns the value for a given property, if it exists.
437 * @param String $class The class name (e.g. 'core' or 'mailAccount')
438 * @param String $name The property name (e.g. 'sessionTimeout' or 'mailMethod')
439 * @return GOsaPropery The property value or an empty string if it doesn't exists.
440 */
441 function getPropertyValue($class,$name)
442 {
443 if($this->propertyExists($class,$name)){
444 $tmp = $this->getProperty($class,$name);
445 return($tmp->getValue());
446 }
447 return("");
448 }
451 /*! \brief Set a new value for a given property, if it exists.
452 * @param String $class The class name (e.g. 'core' or 'mailAccount')
453 * @param String $name The property name (e.g. 'sessionTimeout' or 'mailMethod')
454 * @return
455 */
456 function setPropertyValue($class,$name, $value)
457 {
458 if($this->propertyExists($class,$name)){
459 $tmp = $this->getProperty($class,$name);
460 return($tmp->setValue($value));
461 }
462 return("");
463 }
466 /*! \brief Save all temporary made property changes and thus make them useable/effective.
467 * @return Array Returns a list of plugins that have to be migrated before they can be saved.
468 */
469 function saveChanges()
470 {
471 $migrate = array();
472 foreach($this->properties as $prop){
474 // Is this property modified
475 if(in_array($prop->getStatus(),array('modified','removed'))){
477 // Check if we've to migrate something before we can make the changes effective.
478 if($prop->migrationRequired()){
479 $migrate[] = $prop;
480 }else{
481 $prop->save();
482 }
483 }
484 }
485 return($migrate);
486 }
487 }
490 class gosaProperty
491 {
492 protected $name = "";
493 protected $class = "";
494 protected $value = "";
495 protected $tmp_value = ""; // Used when modified but not saved
496 protected $type = "string";
497 protected $default = "";
498 protected $defaults = "";
499 protected $description = "";
500 protected $check = "";
501 protected $migrate = "";
502 protected $mandatory = FALSE;
503 protected $group = "default";
504 protected $parent = NULL;
505 protected $data = array();
507 protected $migrationClass = NULL;
509 /*! The current property status
510 * 'ldap' Property is stored in ldap
511 * 'file' Property is stored in the config file
512 * 'undefined' Property is currently not stored anywhere
513 * 'modified' Property has been modified (should be saved)
514 */
515 protected $status = 'undefined';
517 protected $attributes = array('name','type','default','description','check',
518 'migrate','mandatory','group','defaults');
523 function __construct($parent,$classname,$data)
524 {
525 // Set some basic infos
526 $this->parent = &$parent;
527 $this->class = $classname;
528 $this->data = $data;
530 // Get all relevant information from the data array (comes from plInfo)
531 foreach($this->attributes as $aName){
532 if(isset($data[$aName])){
533 $this->$aName = $data[$aName];
534 }
535 }
537 // Initialize with the current value
538 $this->_restoreCurrentValue();
540 }
542 function migrationRequired()
543 {
544 // Instantiate migration class
545 if(!empty($this->migrate) && $this->migrationClass == NULL){
546 if(!class_available($this->migrate)){
547 trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' class not found ({$this->migrate})!");
548 }else{
549 $class = $this->migrate;
550 $tmp = new $class($this->parent->config,$this);
551 if(! $tmp instanceof propertyMigration){
552 trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' doesn't implement propertyMigration!");
553 }else{
554 $this->migrationClass = $tmp;
555 }
556 }
557 }
558 if(empty($this->migrate) || $this->migrationClass == NULL){
559 return(FALSE);
560 }
561 return($this->migrationClass->checkForIssues());
562 }
564 function getMigrationClass()
565 {
566 return($this->migrationClass);
567 }
569 function check()
570 {
571 $val = $this->getValue(TRUE);
572 $return = TRUE;
573 if($this->mandatory && empty($val)){
574 $return = FALSE;
575 }
577 $check = $this->getCheck();
578 if(!empty($val) && !empty($check)){
579 $res = call_user_func(preg_split("/::/", $this->check),$messages=TRUE, $this->class,$this->name,$val, $this->type);
580 if(!$res){
581 $return = FALSE;
582 }
583 }
584 return($return);
585 }
587 static function isBool($message,$class,$name,$value, $type)
588 {
589 $match = in_array($value,array('true','false',''));
591 // Display the reason for failing this check.
592 if($message && ! $match){
593 msg_dialog::display(_("Warning"),
594 sprintf(_("The value '%s' specified for '%s:%s' is invalid. A bool value is required here!"),
595 bold($value),bold($class),bold($name)),
596 WARNING_DIALOG);
597 }
599 return($match);
600 }
602 static function isString($message,$class,$name,$value, $type)
603 {
604 $match = TRUE;
606 // Display the reason for failing this check.
607 if($message && ! $match){
608 msg_dialog::display(_("Warning"),
609 sprintf(_("The value '%s' specified for '%s:%s' is invalid. A string value is required here!"),
610 bold($value),bold($class),bold($name)),
611 WARNING_DIALOG);
612 }
614 return($match);
615 }
617 static function isInteger($message,$class,$name,$value, $type)
618 {
619 $match = is_numeric($value) && !preg_match("/[^0-9]/", $value);
621 // Display the reason for failing this check.
622 if($message && ! $match){
623 msg_dialog::display(_("Warning"),
624 sprintf(_("The value '%s' specified for '%s:%s' is invalid. A numeric value is required here!"),
625 bold($value),bold($class),bold($name)),
626 WARNING_DIALOG);
627 }
629 return($match);
630 }
632 static function isPath($message,$class,$name,$value, $type)
633 {
634 $match = preg_match("#^(/[^/]*/){1}#", $value);
636 // Display the reason for failing this check.
637 if($message && ! $match){
638 msg_dialog::display(_("Warning"),
639 sprintf(_("The path '%s' specified for '%s:%s' is invalid!"),
640 bold($value),bold($class),bold($name)),
641 WARNING_DIALOG);
642 }
644 return($match);
645 }
647 static function isReadablePath($message,$class,$name,$value, $type)
648 {
649 $match = !empty($value)&&is_dir($value)&&is_writeable($value);
651 // Display the reason for failing this check.
652 if($message && ! $match){
653 if(!is_dir($value)){
654 msg_dialog::display(_("Warning"),
655 sprintf(_("The folder '%s' specified for '%s:%s' does not exists!"),
656 bold($value),bold($class),bold($name)),
657 WARNING_DIALOG);
658 }elseif(!is_readable($value)){
659 msg_dialog::display(_("Warning"),
660 sprintf(_("The folder '%s' specified for '%s:%s' cannot be used for reading!"),
661 bold($value),bold($class),bold($name)),
662 WARNING_DIALOG);
663 }
664 }
666 return($match);
667 }
669 static function isWriteablePath($message,$class,$name,$value, $type)
670 {
671 $match = !empty($value)&&is_dir($value)&&is_writeable($value);
673 // Display the reason for failing this check.
674 if($message && ! $match){
675 if(!is_dir($value)){
676 msg_dialog::display(_("Warning"),
677 sprintf(_("The folder '%s' specified for '%s:%s' does not exists!"),
678 bold($value),bold($class),bold($name)),
679 WARNING_DIALOG);
680 }elseif(!is_writeable($value)){
681 msg_dialog::display(_("Warning"),
682 sprintf(_("The folder '%s' specified for '%s:%s' cannot be used for writing!"),
683 bold($value),bold($class),bold($name)),
684 WARNING_DIALOG);
685 }
686 }
688 return($match);
689 }
691 static function isReadableFile($message,$class,$name,$value, $type)
692 {
693 $match = !empty($value) && is_readable($value) && is_file($value);
695 // Display the reason for failing this check.
696 if($message && ! $match){
698 if(!is_file($value)){
699 msg_dialog::display(_("Warning"),
700 sprintf(_("The file '%s' specified for '%s:%s' does not exists!"),
701 bold($value),bold($class),bold($name)),
702 WARNING_DIALOG);
703 }elseif(!is_readable($value)){
704 msg_dialog::display(_("Warning"),
705 sprintf(_("The file '%s' specified for '%s:%s' cannot be read!"),
706 bold($value),bold($class),bold($name)),
707 WARNING_DIALOG);
708 }
709 }
711 return($match);
712 }
714 static function isCommand($message,$class,$name,$value, $type)
715 {
716 $match = TRUE;
718 // Display the reason for failing this check.
719 if($message && ! $match){
720 msg_dialog::display(_("Warning"),
721 sprintf(_("The command '%s' specified for '%s:%s' is invalid!"),
722 bold($value),bold($class),bold($name)),
723 WARNING_DIALOG);
724 }
726 return($match);
727 }
729 static function isDn($message,$class,$name,$value, $type)
730 {
731 $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=]*$/i", $value);
733 // Display the reason for failing this check.
734 if($message && ! $match){
735 msg_dialog::display(_("Warning"),
736 sprintf(_("The dn '%s' specified for '%s:%s' is invalid!"),
737 bold($value),bold($class),bold($name)),
738 WARNING_DIALOG);
739 }
741 return($match);
742 }
744 static function isRdn($message,$class,$name,$value, $type)
745 {
746 $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=,]*,?$/i", $value);
748 // Display the reason for failing this check.
749 if($message && ! $match){
750 msg_dialog::display(_("Warning"),
751 sprintf(_("The rdn '%s' specified for '%s:%s' is invalid!"),
752 bold($value),bold($class),bold($name)),
753 WARNING_DIALOG);
754 }
756 return($match);
757 }
759 private function _restoreCurrentValue()
760 {
761 // First check for values in the LDAP Database.
762 if(isset($this->parent->ldapStoredProperties[$this->class][$this->name])){
763 $this->setStatus('ldap');
764 $this->value = $this->parent->ldapStoredProperties[$this->class][$this->name];
765 return;
766 }
768 // Second check for values in the config file.
769 if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
770 $this->setStatus('file');
771 $this->value = $this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)];
772 return;
773 }
775 // If there still wasn't found anything then fallback to the default.
776 if($this->getStatus() == 'undefined'){
777 $this->value = $this->getDefault();
778 }
779 }
781 function getMigrate() { return($this->migrate); }
782 function getCheck() { return($this->check); }
783 function getName() { return($this->name); }
784 function getClass() { return($this->class); }
785 function getGroup() { return($this->group); }
786 function getType() { return($this->type); }
787 function getDescription() { return($this->description); }
788 function getDefault() { return($this->default); }
789 function getDefaults() { return($this->defaults); }
790 function getStatus() { return($this->status); }
791 function isMandatory() { return($this->mandatory); }
793 function setValue($str)
794 {
795 if(in_array($this->getStatus(), array('modified'))){
796 $this->tmp_value = $str;
797 }elseif($this->value != $str){
798 $this->setStatus('modified');
799 $this->tmp_value = $str;
800 }
801 }
803 function getValue($temporary = FALSE)
804 {
805 if($temporary){
806 if(in_array($this->getStatus(), array('modified','removed'))){
807 return($this->tmp_value);
808 }else{
809 return($this->value);
810 }
811 }else{
813 // Do not return ldap values if we've to ignore them.
814 if($this->parent->ignoreLdapProperties){
815 if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
816 return($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)]);
817 }else{
818 return($this->getDefault());
819 }
820 }else{
821 return($this->value);
822 }
823 }
824 }
826 function restoreDefault()
827 {
828 if(in_array($this->getStatus(),array('ldap'))){
829 $this->setStatus('removed');
831 // Second check for values in the config file.
832 if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
833 $this->tmp_value = $this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)];
834 }else{
835 $this->tmp_value = $this->getDefault();
836 }
837 }
838 }
840 function save()
841 {
842 if($this->getStatus() == 'modified'){
843 $ldap = $this->parent->config->get_ldap_link();
844 $ldap->cd($this->parent->config->current['BASE']);
845 $dn = "cn={$this->class},".$this->parent->config->current['CONFIG'];
846 $ldap->cat($dn);
847 if(!$ldap->count()){
848 $ldap->cd($dn);
849 $data = array(
850 'cn' => $this->class,
851 'objectClass' => array('top','gosaConfig'),
852 'gosaSetting' => $this->name.":".$this->tmp_value);
854 $ldap->add($data);
855 if(!$ldap->success()){
856 echo $ldap->get_error();
857 }
859 }else{
860 $attrs = $ldap->fetch();
861 $data = array();
862 $found = false;
863 if(isset($attrs['gosaSetting']['count'])){
864 for($i = 0;$i<$attrs['gosaSetting']['count']; $i ++){
865 $set = $attrs['gosaSetting'][$i];
866 if(preg_match("/^{$this->name}:/", $set)){
867 $set = "{$this->name}:{$this->tmp_value}";
868 $found = true;
869 }
870 $data['gosaSetting'][] = $set;
871 }
872 }
873 if(!$found) $data['gosaSetting'][] = "{$this->name}:{$this->tmp_value}";
874 $ldap->cd($dn);
875 $ldap->modify($data);
876 if(!$ldap->success()){
877 echo $ldap->get_error();
878 }
879 }
880 $this->value = $this->tmp_value;
881 $this->setStatus('ldap');
882 }elseif($this->getStatus() == 'removed'){
883 $ldap = $this->parent->config->get_ldap_link();
884 $ldap->cd($this->parent->config->current['BASE']);
885 $dn = "cn={$this->class},".$this->parent->config->current['CONFIG'];
886 $ldap->cat($dn);
887 $attrs = $ldap->fetch();
888 $data = array('gosaSetting' => array());
889 for($i = 0;$i<$attrs['gosaSetting']['count']; $i ++){
890 $set = $attrs['gosaSetting'][$i];
891 if(preg_match("/^{$this->name}:/", $set)){
892 continue;
893 }
894 $data['gosaSetting'][] = $set;
895 }
896 $ldap->cd($dn);
897 $ldap->modify($data);
898 if(!$ldap->success()){
899 echo $ldap->get_error();
900 }
901 $this->_restoreCurrentValue();
902 }
903 }
905 private function setStatus($state)
906 {
907 if(!in_array($state, array('ldap','file','undefined','modified','removed'))) {
908 trigger_error("Unknown property status given '{$state}' for {$this->class}:{$this->name}!");
909 }else{
910 $this->status = $state;
911 }
912 }
914 function isValid()
915 {
916 return(TRUE);
917 }
918 }
922 interface propertyMigration
923 {
924 function __construct($config,$property);
925 }
928 ?>