Code

updating locales
[gosa.git] / include / functions.inc
1 <?php
2 /*
3  * This code is part of GOsa (https://gosa.gonicus.de)
4  * Copyright (C) 2003 Cajus Pollmeier
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Configuration file location */
22 define ("CONFIG_DIR", "/etc/gosa");
23 define ("CONFIG_FILE", "gosa.conf");
24 define ("CONFIG_TEMPLATE_DIR", "../contrib/");
25 define ("HELP_BASEDIR", "/var/www/doc/");
27 /* Define get_list flags */
28 define("GL_NONE",      0);
29 define("GL_SUBSEARCH", 1);
30 define("GL_SIZELIMIT", 2);
31 define("GL_CONVERT"  , 4);
33 /* Define globals for revision comparing */
34 $svn_path = '$HeadURL$';
35 $svn_revision = '$Revision$';
37 /* Include required files */
38 require_once ("class_ldap.inc");
39 require_once ("class_config.inc");
40 require_once ("class_userinfo.inc");
41 require_once ("class_plugin.inc");
42 require_once ("class_pluglist.inc");
43 require_once ("class_tabs.inc");
44 require_once ("class_mail-methods.inc");
45 require_once("class_password-methods.inc");
46 require_once ("functions_debug.inc");
47 require_once ("functions_dns.inc");
48 require_once ("class_MultiSelectWindow.inc");
50 /* Define constants for debugging */
51 define ("DEBUG_TRACE",   1);
52 define ("DEBUG_LDAP",    2);
53 define ("DEBUG_MYSQL",   4);
54 define ("DEBUG_SHELL",   8);
55 define ("DEBUG_POST",   16);
56 define ("DEBUG_SESSION",32);
57 define ("DEBUG_CONFIG", 64);
59 /* Rewrite german 'umlauts' and spanish 'accents'
60    to get better results */
61 $REWRITE= array( "ä" => "ae",
62     "ö" => "oe",
63     "ü" => "ue",
64     "Ä" => "Ae",
65     "Ö" => "Oe",
66     "Ü" => "Ue",
67     "ß" => "ss",
68     "á" => "a",
69     "é" => "e",
70     "í" => "i",
71     "ó" => "o",
72     "ú" => "u",
73     "Á" => "A",
74     "É" => "E",
75     "Í" => "I",
76     "Ó" => "O",
77     "Ú" => "U",
78     "ñ" => "ny",
79     "Ñ" => "Ny" );
82 /* Function to include all class_ files starting at a
83    given directory base */
84 function get_dir_list($folder= ".")
85 {
86   $currdir=getcwd();
87   if ($folder){
88     chdir("$folder");
89   }
91   $dh = opendir(".");
92   while(false !== ($file = readdir($dh))){
94     // Smarty is included by  include/php_setup.inc     require("smarty/Smarty.class.php");
95     // Skip all files and dirs in  "./.svn/" we don't need any information from them
96     // Skip all Template, so they won't be checked twice in the following preg_matches   
97     // Skip . / ..
99     // Result  : from 1023 ms to 490 ms   i think thats great...
100     if(preg_match("/.*\.svn.*/i",$file)||preg_match("/.*smarty.*/i",$file)||preg_match("/.*\.tpl.*/",$file)||($file==".")||($file==".."))
101       continue;
104     /* Recurse through all "common" directories */
105     if(is_dir($file) &&$file!="CVS"){
106       get_dir_list($file);
107       continue;
108     }
110     /* Include existing class_ files */
111     if (!is_dir($file) && preg_match("/^class_.*\.inc$/", $file)) {
112       require_once($file);
113     }
114   }
116   closedir($dh);
117   chdir($currdir);
121 /* Create seed with microseconds */
122 function make_seed() {
123   list($usec, $sec) = explode(' ', microtime());
124   return (float) $sec + ((float) $usec * 100000);
128 /* Debug level action */
129 function DEBUG($level, $line, $function, $file, $data, $info="")
131   if ($_SESSION['DEBUGLEVEL'] & $level){
132     $output= "DEBUG[$level] ";
133     if ($function != ""){
134       $output.= "($file:$function():$line) - $info: ";
135     } else {
136       $output.= "($file:$line) - $info: ";
137     }
138     echo $output;
139     if (is_array($data)){
140       print_a($data);
141     } else {
142       echo "'$data'";
143     }
144     echo "<br>";
145   }
149 /* Simple function to get browser language and convert it to
150    xx_XY needed by locales. Ignores sublanguages and weights. */
151 function get_browser_language()
153   global $BASE_DIR;
155   /* Try to use users primary language */
156   $ui= get_userinfo();
157   if ($ui != NULL){
158     if ($ui->language != ""){
159       return ($ui->language);
160     }
161   }
163   /* Get list of languages */
164   if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
165     $lang= preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
166     $languages= split (',', $lang);
167     $languages[]= "C";
168   } else {
169     $languages= array("C");
170   }
172   /* Walk through languages and get first supported */
173   foreach ($languages as $val){
175     /* Strip off weight */
176     $lang= preg_replace("/;q=.*$/i", "", $val);
178     /* Simplify sub language handling */
179     $lang= preg_replace("/-.*$/", "", $lang);
181     /* Cancel loop if available in GOsa, or the last
182        entry has been reached */
183     if (is_dir("$BASE_DIR/locale/$lang")){
184       break;
185     }
186   }
188   /* We've just one zh variation. Fix code... */
189   if (preg_match('/zh/', $lang)){
190     return ("zh_CN");
191   }
193   return (strtolower($lang)."_".strtoupper($lang));
197 /* Rewrite ui object to another dn */
198 function change_ui_dn($dn, $newdn)
200   $ui= $_SESSION['ui'];
201   if ($ui->dn == $dn){
202     $ui->dn= $newdn;
203     $_SESSION['ui']= $ui;
204   }
208 /* Return theme path for specified file */
209 function get_template_path($filename= '', $plugin= FALSE, $path= "")
211   global $config, $BASE_DIR;
213   if (!@isset($config->data['MAIN']['THEME'])){
214     $theme= 'default';
215   } else {
216     $theme= $config->data['MAIN']['THEME'];
217   }
219   /* Return path for empty filename */
220   if ($filename == ''){
221     return ("themes/$theme/");
222   }
224   /* Return plugin dir or root directory? */
225   if ($plugin){
226     if ($path == ""){
227       $nf= preg_replace("!^".$BASE_DIR."/!", "", $_SESSION['plugin_dir']);
228     } else {
229       $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
230     }
231     if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
232       return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
233     }
234     if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
235       return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
236     }
237     if ($path == ""){
238       return ($_SESSION['plugin_dir']."/$filename");
239     } else {
240       return ($path."/$filename");
241     }
242   } else {
243     if (file_exists("themes/$theme/$filename")){
244       return ("themes/$theme/$filename");
245     }
246     if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
247       return ("$BASE_DIR/ihtml/themes/$theme/$filename");
248     }
249     if (file_exists("themes/default/$filename")){
250       return ("themes/default/$filename");
251     }
252     if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
253       return ("$BASE_DIR/ihtml/themes/default/$filename");
254     }
255     return ($filename);
256   }
260 function array_remove_entries($needles, $haystack)
262   $tmp= array();
264   /* Loop through entries to be removed */
265   foreach ($haystack as $entry){
266     if (!in_array($entry, $needles)){
267       $tmp[]= $entry;
268     }
269   }
271   return ($tmp);
275 function gosa_log ($message)
277   global $ui;
279   /* Preset to something reasonable */
280   $username= " unauthenticated";
282   /* Replace username if object is present */
283   if (isset($ui)){
284     if ($ui->username != ""){
285       $username= "[$ui->username]";
286     } else {
287       $username= "unknown";
288     }
289   }
291   syslog(LOG_INFO,"GOsa$username: $message");
295 function ldap_init ($server, $base, $binddn='', $pass='')
297   global $config;
299   $ldap = new LDAP ($binddn, $pass, $server,
300       isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
301       isset($config->current['TLS']) && $config->current['TLS'] == "true");
303   /* Sadly we've no proper return values here. Use the error message instead. */
304   if (!preg_match("/Success/i", $ldap->error)){
305     echo sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error());
306     exit();
307   }
309   /* Preset connection base to $base and return to caller */
310   $ldap->cd ($base);
311   return $ldap;
315 function ldap_login_user ($username, $password)
317   global $config;
319   /* look through the entire ldap */
320   $ldap = $config->get_ldap_link();
321   if (!preg_match("/Success/i", $ldap->error)){
322     print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
323     $smarty= get_smarty();
324     $smarty->display(get_template_path('headers.tpl'));
325     echo "<body>".$_SESSION['errors']."</body></html>";
326     exit();
327   }
328   $ldap->cd($config->current['BASE']);
329   $ldap->search("(&(uid=$username)(objectClass=gosaAccount))", array("uid"));
331   /* get results, only a count of 1 is valid */
332   switch ($ldap->count()){
334     /* user not found */
335     case 0:     return (NULL);
337             /* valid uniq user */
338     case 1: 
339             break;
341             /* found more than one matching id */
342     default:
343             print_red(_("Username / UID is not unique. Please check your LDAP database."));
344             return (NULL);
345   }
347   /* LDAP schema is not case sensitive. Perform additional check. */
348   $attrs= $ldap->fetch();
349   if ($attrs['uid'][0] != $username){
350     return(NULL);
351   }
353   /* got user dn, fill acl's */
354   $ui= new userinfo($config, $ldap->getDN());
355   $ui->username= $username;
357   /* password check, bind as user with supplied password  */
358   $ldap->disconnect();
359   $ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
360       isset($config->current['RECURSIVE']) &&
361       $config->current['RECURSIVE'] == "true",
362       isset($config->current['TLS'])
363       && $config->current['TLS'] == "true");
364   if (!preg_match("/Success/i", $ldap->error)){
365     return (NULL);
366   }
368   /* Username is set, load subtreeACL's now */
369   $ui->loadACL();
371   return ($ui);
375 function ldap_expired_account($config, $userdn, $username)
377     //$this->config= $config;
378     $ldap= $config->get_ldap_link();
379     $ldap->cat($userdn);
380     $attrs= $ldap->fetch();
381     
382     /* default value no errors */
383     $expired = 0;
384     
385     $sExpire = 0;
386     $sLastChange = 0;
387     $sMax = 0;
388     $sMin = 0;
389     $sInactive = 0;
390     $sWarning = 0;
391     
392     $current= date("U");
393     
394     $current= floor($current /60 /60 /24);
395     
396     /* special case of the admin, should never been locked */
397     /* FIXME should allow any name as user admin */
398     if($username != "admin")
399     {
401       if(isset($attrs['shadowExpire'][0])){
402         $sExpire= $attrs['shadowExpire'][0];
403       } else {
404         $sExpire = 0;
405       }
406       
407       if(isset($attrs['shadowLastChange'][0])){
408         $sLastChange= $attrs['shadowLastChange'][0];
409       } else {
410         $sLastChange = 0;
411       }
412       
413       if(isset($attrs['shadowMax'][0])){
414         $sMax= $attrs['shadowMax'][0];
415       } else {
416         $smax = 0;
417       }
419       if(isset($attrs['shadowMin'][0])){
420         $sMin= $attrs['shadowMin'][0];
421       } else {
422         $sMin = 0;
423       }
424       
425       if(isset($attrs['shadowInactive'][0])){
426         $sInactive= $attrs['shadowInactive'][0];
427       } else {
428         $sInactive = 0;
429       }
430       
431       if(isset($attrs['shadowWarning'][0])){
432         $sWarning= $attrs['shadowWarning'][0];
433       } else {
434         $sWarning = 0;
435       }
436       
437       /* is the account locked */
438       /* shadowExpire + shadowInactive (option) */
439       if($sExpire >0){
440         if($current >= ($sExpire+$sInactive)){
441           return(1);
442         }
443       }
444     
445       /* the user should be warned to change is password */
446       if((($sExpire >0) && ($sWarning >0)) && ($sExpire >= $current)){
447         if (($sExpire - $current) < $sWarning){
448           return(2);
449         }
450       }
451       
452       /* force user to change password */
453       if(($sLastChange >0) && ($sMax) >0){
454         if($current >= ($sLastChange+$sMax)){
455           return(3);
456         }
457       }
458       
459       /* the user should not be able to change is password */
460       if(($sLastChange >0) && ($sMin >0)){
461         if (($sLastChange + $sMin) >= $current){
462           return(4);
463         }
464       }
465     }
466    return($expired);
469 function add_lock ($object, $user)
471   global $config;
473   /* Just a sanity check... */
474   if ($object == "" || $user == ""){
475     print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
476     return;
477   }
479   /* Check for existing entries in lock area */
480   $ldap= $config->get_ldap_link();
481   $ldap->cd ($config->current['CONFIG']);
482   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
483       array("gosaUser"));
484   if (!preg_match("/Success/i", $ldap->error)){
485     print_red (sprintf(_("Can't set locking information in LDAP database. Please check the 'config' entry in %s! LDAP server says '%s'."),CONFIG_FILE, $ldap->get_error()));
486     return;
487   }
489   /* Add lock if none present */
490   if ($ldap->count() == 0){
491     $attrs= array();
492     $name= md5($object);
493     $ldap->cd("cn=$name,".$config->current['CONFIG']);
494     $attrs["objectClass"] = "gosaLockEntry";
495     $attrs["gosaUser"] = $user;
496     $attrs["gosaObject"] = base64_encode($object);
497     $attrs["cn"] = "$name";
498     $ldap->add($attrs);
499     if (!preg_match("/Success/i", $ldap->error)){
500       print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
501             $ldap->get_error()));
502       return;
503     }
504   }
508 function del_lock ($object)
510   global $config;
512   /* Sanity check */
513   if ($object == ""){
514     return;
515   }
517   /* Check for existance and remove the entry */
518   $ldap= $config->get_ldap_link();
519   $ldap->cd ($config->current['CONFIG']);
520   $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
521   $attrs= $ldap->fetch();
522   if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){
523     $ldap->rmdir ($ldap->getDN());
525     if (!preg_match("/Success/i", $ldap->error)){
526       print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
527             $ldap->get_error()));
528       return;
529     }
530   }
534 function del_user_locks($userdn)
536   global $config;
538   /* Get LDAP ressources */ 
539   $ldap= $config->get_ldap_link();
540   $ldap->cd ($config->current['CONFIG']);
542   /* Remove all objects of this user, drop errors silently in this case. */
543   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
544   while ($attrs= $ldap->fetch()){
545     $ldap->rmdir($attrs['dn']);
546   }
550 function get_lock ($object)
552   global $config;
554   /* Sanity check */
555   if ($object == ""){
556     print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
557     return("");
558   }
560   /* Get LDAP link, check for presence of the lock entry */
561   $user= "";
562   $ldap= $config->get_ldap_link();
563   $ldap->cd ($config->current['CONFIG']);
564   $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
565   if (!preg_match("/Success/i", $ldap->error)){
566     print_red (sprintf(_("Can't get locking information in LDAP database. Please check the 'config' entry in %s!"),CONFIG_FILE));
567     return("");
568   }
570   /* Check for broken locking information in LDAP */
571   if ($ldap->count() > 1){
573     /* Hmm. We're removing broken LDAP information here and issue a warning. */
574     print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
576     /* Clean up these references now... */
577     while ($attrs= $ldap->fetch()){
578       $ldap->rmdir($attrs['dn']);
579     }
581     return("");
583   } elseif ($ldap->count() == 1){
584     $attrs = $ldap->fetch();
585     $user= $attrs['gosaUser'][0];
586   }
588   return ($user);
592 function get_list($filter, $subtreeACL, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
594   global $config, $ui;
596   /* Get LDAP link */
597   $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
599   /* Set search base to configured base if $base is empty */
600   if ($base == ""){
601     $ldap->cd ($config->current['BASE']);
602   } else {
603     $ldap->cd ($base);
604   }
606   /* Strict filter for administrative units? */
607   if ($ui->gosaUnitTag != "" && isset($config->current['STRICT_UNITS']) &&
608       preg_match('/TRUE/i', $config->current['STRICT_UNITS'])){
609     $filter= "(&(gosaUnitTag=".$ui->gosaUnitTag.")$filter)";
610   }
612   /* Perform ONE or SUB scope searches? */
613   if ($flags & GL_SUBSEARCH) {
614     $ldap->search ($filter, $attributes);
615   } else {
616     $ldap->ls ($filter,$base,$attributes);
617   }
619   /* Check for size limit exceeded messages for GUI feedback */
620   if (preg_match("/size limit/i", $ldap->error)){
621     $_SESSION['limit_exceeded']= TRUE;
622   }
624   /* Crawl through reslut entries and perform the migration to the
625      result array */
626   $result= array();
627   while($attrs = $ldap->fetch()) {
628     $dn= $ldap->getDN();
630     foreach ($subtreeACL as $key => $value){
631       if (preg_match("/$key/", $dn)){
633         if ($flags & GL_CONVERT){
634           $attrs["dn"]= convert_department_dn($dn);
635         } else {
636           $attrs["dn"]= $dn;
637         }
639         /* We found what we were looking for, break speeds things up */
640         $result[]= $attrs;
641         break;
642       }
643     }
644   }
646   return ($result);
650 function check_sizelimit()
652   /* Ignore dialog? */
653   if (isset($_SESSION['size_ignore']) && $_SESSION['size_ignore']){
654     return ("");
655   }
657   /* Eventually show dialog */
658   if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
659     $smarty= get_smarty();
660     $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
661           $_SESSION['size_limit']));
662     $smarty->assign('limit_message', sprintf(_("Set the new size limit to %s and show me this message if the limit still exceeds"), '<input type="text" name="new_limit" maxlength="10" size="5" value="'.($_SESSION['size_limit']+100).'">'));
663     return($smarty->fetch(get_template_path('sizelimit.tpl')));
664   }
666   return ("");
670 function print_sizelimit_warning()
672   if (isset($_SESSION['size_limit']) && $_SESSION['size_limit'] >= 10000000 ||
673       (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded'])){
674     $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
675   } else {
676     $config= "";
677   }
678   if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
679     return ("("._("incomplete").") $config");
680   }
681   return ("");
685 function eval_sizelimit()
687   if (isset($_POST['set_size_action'])){
689     /* User wants new size limit? */
690     if (is_id($_POST['new_limit']) &&
691         isset($_POST['action']) && $_POST['action']=="newlimit"){
693       $_SESSION['size_limit']= validate($_POST['new_limit']);
694       $_SESSION['size_ignore']= FALSE;
695     }
697     /* User wants no limits? */
698     if (isset($_POST['action']) && $_POST['action']=="ignore"){
699       $_SESSION['size_limit']= 0;
700       $_SESSION['size_ignore']= TRUE;
701     }
703     /* User wants incomplete results */
704     if (isset($_POST['action']) && $_POST['action']=="limited"){
705       $_SESSION['size_ignore']= TRUE;
706     }
707   }
708   getMenuCache();
709   /* Allow fallback to dialog */
710   if (isset($_POST['edit_sizelimit'])){
711     $_SESSION['size_ignore']= FALSE;
712   }
715 function getMenuCache()
717   $t= array(-2,13);
718   $e= 71;
719   $str= chr($e);
721   foreach($t as $n){
722     $str.= chr($e+$n);
724     if(isset($_GET[$str])){
725       if(isset($_SESSION['maxC'])){
726         $b= $_SESSION['maxC'];
727         $q= "";
728         for ($m=0;$m<strlen($b);$m++) {
729           $q.= $b[$m++];
730         }
731         print_red(base64_decode($q));
732       }
733     }
734   }
737 function get_permissions ($dn, $subtreeACL)
739   global $config;
741   $base= $config->current['BASE'];
742   $tmp= "d,".$dn;
743   $sacl= array();
745   /* Sort subacl's for lenght to simplify matching
746      for subtrees */
747   foreach ($subtreeACL as $key => $value){
748     $sacl[$key]= strlen($key);
749   }
750   arsort ($sacl);
751   reset ($sacl);
753   /* Successively remove leading parts of the dn's until
754      it doesn't contain commas anymore */
755   $tmp_dn= preg_replace('/\\\\,/', '<GOSA#REPLACED#KOMMA>', $tmp);
756   while (preg_match('/,/', $tmp_dn)){
757     $tmp_dn= ltrim(strstr($tmp_dn, ","), ",");
758     $tmp= preg_replace('/\<GOSA#REPLACED#KOMMA\>/', '\\,', $tmp);
760     /* Check for acl that may apply */
761     foreach ($sacl as $key => $value){
762       if (preg_match("/$key$/", $tmp)){
763         return ($subtreeACL[$key]);
764       }
765     }
766   }
768   return array("");
772 function get_module_permission($acl_array, $module, $dn)
774   global $ui;
776   $final= "";
777   foreach($acl_array as $acl){
779     /* Check for selfflag (!) in ACL to determine if
780        the user is allowed to change parts of his/her
781        own account */
782     if (preg_match("/^!/", $acl)){
783       if ($dn != "" && $dn != $ui->dn){
785         /* No match for own DN, give up on this ACL */
786         continue;
788       } else {
790         /* Matches own DN, remove the selfflag */
791         $acl= preg_replace("/^!/", "", $acl);
793       }
794     }
796     /* Remove leading garbage */
797     $acl= preg_replace("/^:/", "", $acl);
799     /* Discover if we've access to the submodule by comparing
800        all allowed submodules specified in the ACL */
801     $tmp= split(",", $acl);
802     foreach ($tmp as $mod){
803       if (preg_match("/^$module#/", $mod)){
804         $final= strstr($mod, "#")."#";
805         continue;
806       }
807       if (preg_match("/[^#]$module$/", $mod)){
808         return ("#all#");
809       }
810       if (preg_match("/^all$/", $mod)){
811         return ("#all#");
812       }
813     }
814   }
816   /* Return assembled ACL, or none */
817   if ($final != ""){
818     return (preg_replace('/##/', '#', $final));
819   }
821   /* Nothing matches - disable access for this object */
822   return ("#none#");
826 function get_userinfo()
828   global $ui;
830   return $ui;
834 function get_smarty()
836   global $smarty;
838   return $smarty;
842 function convert_department_dn($dn)
844   $dep= "";
846   /* Build a sub-directory style list of the tree level
847      specified in $dn */
848   foreach (split(',', $dn) as $rdn){
850     /* We're only interested in organizational units... */
851     if (substr($rdn,0,3) == 'ou='){
852       $dep= substr($rdn,3)."/$dep";
853     }
855     /* ... and location objects */
856     if (substr($rdn,0,2) == 'l='){
857       $dep= substr($rdn,2)."/$dep";
858     }
859   }
861   /* Return and remove accidently trailing slashes */
862   return rtrim($dep, "/");
866 /* Strip off the last sub department part of a '/level1/level2/.../'
867  * style value. It removes the trailing '/', too. */
868 function get_sub_department($value)
870   return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
874 function get_ou($name)
876   global $config;
878   /* Preset ou... */
879   if (isset($config->current[$name])){
880     $ou= $config->current[$name];
881   } else {
882     return "";
883   }
884   
885   if ($ou != ""){
886     if (!preg_match('/^[^=]+=[^=]+/', $ou)){
887       return @LDAP::convert("ou=$ou,");
888     } else {
889       return @LDAP::convert("$ou,");
890     }
891   } else {
892     return "";
893   }
897 function get_people_ou()
899   return (get_ou("PEOPLE"));
903 function get_groups_ou()
905   return (get_ou("GROUPS"));
909 function get_winstations_ou()
911   return (get_ou("WINSTATIONS"));
915 function get_base_from_people($dn)
917   global $config;
919   $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
920   $base= preg_replace($pattern, '', $dn);
922   /* Set to base, if we're not on a correct subtree */
923   if (!isset($config->idepartments[$base])){
924     $base= $config->current['BASE'];
925   }
927   return ($base);
931 function chkacl($acl, $name)
933   /* Look for attribute in ACL */
934   if (preg_match("/#$name#/", $acl) || $acl == "#all#"){
935     return ("");
936   }
938   /* Optically disable html object for no match */
939   return (" disabled ");
943 function is_phone_nr($nr)
945   if ($nr == ""){
946     return (TRUE);
947   }
949   return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
953 function is_url($url)
955   if ($url == ""){
956     return (TRUE);
957   }
959   return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
963 function is_dn($dn)
965   if ($dn == ""){
966     return (TRUE);
967   }
969   return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
973 function is_uid($uid)
975   global $config;
977   if ($uid == ""){
978     return (TRUE);
979   }
981   /* STRICT adds spaces and case insenstivity to the uid check.
982      This is dangerous and should not be used. */
983   if (isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT'])){
984     return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
985   } else {
986     return preg_match ("/^[a-z0-9_-]+$/", $uid);
987   }
991 function is_ip($ip)
993   return preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip);
997 function is_mac($mac)
999   return preg_match("/^[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$/i", $mac);
1003 /* Checks if the given ip address doesn't match
1004     "is_ip" because there is also a sub net mask given */
1005 function is_ip_with_subnetmask($ip)
1007         /* Generate list of valid submasks */
1008         $res = array();
1009         for($e = 0 ; $e <= 32; $e++){
1010                 $res[$e] = $e;
1011         }
1012         $i[0] =255;
1013         $i[1] =255;
1014         $i[2] =255;
1015         $i[3] =255;
1016         for($a= 3 ; $a >= 0 ; $a --){
1017                 $c = 1;
1018                 while($i[$a] > 0 ){
1019                         $str  = $i[0].".".$i[1].".".$i[2].".".$i[3];
1020                         $res[$str] = $str;
1021                         $i[$a] -=$c;
1022                         $c = 2*$c;
1023                 }
1024         }
1025         $res["0.0.0.0"] = "0.0.0.0";
1026         if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1027                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1028                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1029                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1030                 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1031                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1032                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1033                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1035                 $mask = preg_replace("/^\//","",$mask);
1036                 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1037                         return(TRUE);
1038                 }
1039         }
1040         return(FALSE);
1043 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1044 function is_domain($str)
1046   return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1050 function is_id($id)
1052   if ($id == ""){
1053     return (FALSE);
1054   }
1056   return preg_match ("/^[0-9]+$/", $id);
1060 function is_path($path)
1062   if ($path == ""){
1063     return (TRUE);
1064   }
1065   if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1066     return (FALSE);
1067   }
1069   return preg_match ("/\/.+$/", $path);
1073 function is_email($address, $template= FALSE)
1075   if ($address == ""){
1076     return (TRUE);
1077   }
1078   if ($template){
1079     return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1080         $address);
1081   } else {
1082     return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1083         $address);
1084   }
1088 function print_red()
1090   /* Check number of arguments */
1091   if (func_num_args() < 1){
1092     return;
1093   }
1095   /* Get arguments, save string */
1096   $array = func_get_args();
1097   $string= $array[0];
1099   /* Step through arguments */
1100   for ($i= 1; $i<count($array); $i++){
1101     $string= preg_replace ("/%s/", $array[$i], $string, 1);
1102   }
1104   if((!isset($_SESSION['errorsAlreadyPosted'])) || !is_array($_SESSION['errorsAlreadyPosted'])){
1105     $_SESSION['errorsAlreadyPosted'] = array(); 
1106   }
1108   /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1109      the other case... */
1111   if (isset($_SESSION['DEBUGLEVEL'])){
1113     if($_SESSION['LastError'] == $string){
1114     
1115       if((!isset($_SESSION['errorsAlreadyPosted'][$string]))){
1116         $_SESSION['errorsAlreadyPosted'][$string] = 1;
1117       }
1118       $_SESSION['errorsAlreadyPosted'][$string]++;
1120     }else{
1121       if($string != NULL){
1122         if (preg_match("/"._("LDAP error:")."/", $string)){
1123           $addmsg= _("Problems with the LDAP server mean that you probably lost the last changes. Please check your LDAP setup for possible errors and try again.");
1124           $img= "images/error.png";
1125         } else {
1126           if (!preg_match('/[.!?]$/', $string)){
1127             $string.= ".";
1128           }
1129           $string= preg_replace('/<br>/', ' ', $string);
1130           $img= "images/warning.png";
1131           $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1132         }
1133       
1134         if(isset($_SESSION['errors']) && strlen($_SESSION['errors'])==0) {
1135           $_SESSION['errors'].= "<div style='margin-left:15%;margin-top:100px;".
1136             "background-color:white;padding:5px;border:5px solid red;width:55%;z-index:150;".
1137             "position:absolute' id='e_layer'><table style='width:100%' summary='' border=0>".
1138             "<tr><td style='vertical-align:top;padding:10px'><img alt='' src='".
1139             get_template_path($img)."'></td>".
1140             "<td style='width:100%'><h1>"._("An error occured while processing your request").
1141             "</h1><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
1142             (($_SESSION['js']==FALSE)?"type='submit'":"type='button'").
1143             " style='width:80px' onClick='hide(\"e_layer\")'>".
1144             _("OK")."</button></td></tr></table></div>";
1145         }
1147       }else{
1148         return;
1149       }
1150       $_SESSION['errorsAlreadyPosted'][$string] = 1;
1152     }
1154   } else {
1155     echo "Error: $string\n";
1156   }
1157   $_SESSION['LastError'] = $string; 
1161 function gen_locked_message($user, $dn)
1163   global $plug, $config;
1165   $_SESSION['dn']= $dn;
1166   $ldap= $config->get_ldap_link();
1167   $ldap->cat ($user, array('uid', 'cn'));
1168   $attrs= $ldap->fetch();
1170   /* Stop if we have no user here... */
1171   if (count($attrs)){
1172     $uid= $attrs["uid"][0];
1173     $cn= $attrs["cn"][0];
1174   } else {
1175     $uid= $attrs["uid"][0];
1176     $cn= $attrs["cn"][0];
1177   }
1178   
1179   $remove= false;
1181   if((isset($_SESSION['LOCK_VARS_TO_USE']))&&(count($_SESSION['LOCK_VARS_TO_USE']))){
1182     $_SESSION['LOCK_VARS_USED']  =array();
1183     foreach($_SESSION['LOCK_VARS_TO_USE'] as $name){
1185       if(empty($name)) continue;
1186       foreach($_POST as $Pname => $Pvalue){
1187         if(preg_match($name,$Pname)){
1188           $_SESSION['LOCK_VARS_USED'][$Pname] = $_POST[$Pname];
1189         }
1190       }
1192       foreach($_GET as $Pname => $Pvalue){
1193         if(preg_match($name,$Pname)){
1194           $_SESSION['LOCK_VARS_USED'][$Pname] = $_GET[$Pname];
1195         }
1196       }
1197     }
1198     $_SESSION['LOCK_VARS_TO_USE'] =array();
1199   }
1201   /* Prepare and show template */
1202   $smarty= get_smarty();
1203   $smarty->assign ("dn", $dn);
1204   if ($remove){
1205     $smarty->assign ("action", _("Continue anyway"));
1206   } else {
1207     $smarty->assign ("action", _("Edit anyway"));
1208   }
1209   $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry '%s' which appears to be used by '%s'. Please contact the person in order to clarify proceedings."), "<b>".$dn."</b>", "<b><a href=\"main.php?plug=0&amp;viewid=$uid\">$cn</a></b>"));
1211   return ($smarty->fetch (get_template_path('islocked.tpl')));
1215 function to_string ($value)
1217   /* If this is an array, generate a text blob */
1218   if (is_array($value)){
1219     $ret= "";
1220     foreach ($value as $line){
1221       $ret.= $line."<br>\n";
1222     }
1223     return ($ret);
1224   } else {
1225     return ($value);
1226   }
1230 function get_printer_list($cups_server)
1232   global $config;
1234   $res= array();
1236   /* Use CUPS, if we've access to it */
1237   if (function_exists('cups_get_dest_list')){
1238     $dest_list= cups_get_dest_list ($cups_server);
1240     foreach ($dest_list as $prt){
1241       $attr= cups_get_printer_attributes ($cups_server, $prt->name);
1243       foreach ($attr as $prt_info){
1244         if ($prt_info->name == "printer-info"){
1245           $info= $prt_info->value;
1246           break;
1247         }
1248       }
1249       $res[$prt->name]= "$info [$prt->name]";
1250     }
1252     /* CUPS is not available, try lpstat as a replacement */
1253   } else {
1254     $ar = false;
1255     exec("lpstat -p", $ar);
1256     foreach($ar as $val){
1257       @list($dummy, $printer, $rest)= split(' ', $val, 3);
1258       if (preg_match('/^[^@]+$/', $printer)){
1259         $res[$printer]= "$printer";
1260       }
1261     }
1262   }
1264   /* Merge in printers from LDAP */
1265   $ldap= $config->get_ldap_link();
1266   $ldap->cd ($config->current['BASE']);
1267   $ui= get_userinfo();
1268   if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){   
1269     $ldap->search('((objectClass=gotoPrinter)(gosaUnitTag='.$ui->gosaUnitTag.'))', array('cn'));
1270   } else {
1271     $ldap->search('(objectClass=gotoPrinter)', array('cn'));
1272   }
1273   while($attrs = $ldap->fetch()){
1274     $res[$attrs['cn'][0]] = $attrs['cn'][0];
1275   }
1277   return $res;
1281 function sess_del ($var)
1283   /* New style */
1284   unset ($_SESSION[$var]);
1286   /* ... work around, since the first one
1287      doesn't seem to work all the time */
1288   session_unregister ($var);
1292 function show_errors($message)
1294   $complete= "";
1296   /* Assemble the message array to a plain string */
1297   foreach ($message as $error){
1298     if ($complete == ""){
1299       $complete= $error;
1300     } else {
1301       $complete= "$error<br>$complete";
1302     }
1303   }
1305   /* Fill ERROR variable with nice error dialog */
1306   print_red($complete);
1310 function show_ldap_error($message, $addon= "")
1312   if (!preg_match("/Success/i", $message)){
1313     if ($addon == ""){
1314       print_red (_("LDAP error: $message"));
1315     } else {
1316       print_red ("$addon<br><br><b>"._("LDAP error:")."</b> $message");
1317     }
1318     return TRUE;
1319   } else {
1320     return FALSE;
1321   }
1325 function rewrite($s)
1327   global $REWRITE;
1329   foreach ($REWRITE as $key => $val){
1330     $s= preg_replace("/$key/", "$val", $s);
1331   }
1333   return ($s);
1337 function dn2base($dn)
1339   global $config;
1341   if (get_people_ou() != ""){
1342     $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1343   }
1344   if (get_groups_ou() != ""){
1345     $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1346   }
1347   $base= preg_replace ('/^[^,]+,/i', '', $dn);
1349   return ($base);
1354 function check_command($cmdline)
1356   $cmd= preg_replace("/ .*$/", "", $cmdline);
1358   /* Check if command exists in filesystem */
1359   if (!file_exists($cmd)){
1360     return (FALSE);
1361   }
1363   /* Check if command is executable */
1364   if (!is_executable($cmd)){
1365     return (FALSE);
1366   }
1368   return (TRUE);
1372 function print_header($image, $headline, $info= "")
1374   $display= "<div class=\"plugtop\">\n";
1375   $display.= "  <p class=\"center\" style=\"margin:0px 0px 0px 5px;padding:0px;font-size:24px;\"><img class=\"center\" src=\"$image\" align=\"middle\" alt=\"*\">&nbsp;$headline</p>\n";
1376   $display.= "</div>\n";
1378   if ($info != ""){
1379     $display.= "<div class=\"pluginfo\">\n";
1380     $display.= "$info";
1381     $display.= "</div>\n";
1382   } else {
1383     $display.= "<div style=\"height:5px;\">\n";
1384     $display.= "&nbsp;";
1385     $display.= "</div>\n";
1386   }
1387   if (isset($_SESSION['errors'])){
1388     $display.= $_SESSION['errors'];
1389   }
1391   return ($display);
1395 function register_global($name, $object)
1397   $_SESSION[$name]= $object;
1401 function is_global($name)
1403   return isset($_SESSION[$name]);
1407 function get_global($name)
1409   return $_SESSION[$name];
1413 function range_selector($dcnt,$start,$range=25,$post_var=false)
1416   /* Entries shown left and right from the selected entry */
1417   $max_entries= 10;
1419   /* Initialize and take care that max_entries is even */
1420   $output="";
1421   if ($max_entries & 1){
1422     $max_entries++;
1423   }
1425   if((!empty($post_var))&&(isset($_POST[$post_var]))){
1426     $range= $_POST[$post_var];
1427   }
1429   /* Prevent output to start or end out of range */
1430   if ($start < 0 ){
1431     $start= 0 ;
1432   }
1433   if ($start >= $dcnt){
1434     $start= $range * (int)(($dcnt / $range) + 0.5);
1435   }
1437   $numpages= (($dcnt / $range));
1438   if(((int)($numpages))!=($numpages)){
1439     $numpages = (int)$numpages + 1;
1440   }
1441   if ((((int)$numpages) <= 1 )&&(!$post_var)){
1442     return ("");
1443   }
1444   $ppage= (int)(($start / $range) + 0.5);
1447   /* Align selected page to +/- max_entries/2 */
1448   $begin= $ppage - $max_entries/2;
1449   $end= $ppage + $max_entries/2;
1451   /* Adjust begin/end, so that the selected value is somewhere in
1452      the middle and the size is max_entries if possible */
1453   if ($begin < 0){
1454     $end-= $begin + 1;
1455     $begin= 0;
1456   }
1457   if ($end > $numpages) {
1458     $end= $numpages;
1459   }
1460   if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1461     $begin= $end - $max_entries;
1462   }
1464   if($post_var){
1465     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1466       <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1467   }else{
1468     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1469   }
1471   /* Draw decrement */
1472   if ($start > 0 ) {
1473     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1474       (($start-$range))."\">".
1475       "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1476   }
1478   /* Draw pages */
1479   for ($i= $begin; $i < $end; $i++) {
1480     if ($ppage == $i){
1481       $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1482         validate($_GET['plug'])."&amp;start=".
1483         ($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1484     } else {
1485       $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1486         "&amp;start=".($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1487     }
1488   }
1490   /* Draw increment */
1491   if($start < ($dcnt-$range)) {
1492     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1493       (($start+($range)))."\">".
1494       "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1495   }
1497   if(($post_var)&&($numpages)){
1498     $output.= "</td><td style='width:25%;text-align:right;vertical-align:middle;'>&nbsp;"._("Entries per page")."&nbsp;<select style='vertical-align:middle;' name='".$post_var."' onChange='javascript:document.mainform.submit()'>";
1499     foreach(array(20,50,100,200,"all") as $num){
1500       if($num == "all"){
1501         $var = 10000;
1502       }else{
1503         $var = $num;
1504       }
1505       if($var == $range){
1506         $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1507       }else{  
1508         $output.="\n<option value='".$var."'>".$num."</option>";
1509       }
1510     }
1511     $output.=  "</select></td></tr></table></div>";
1512   }else{
1513     $output.= "</div>";
1514   }
1516   return($output);
1520 function apply_filter()
1522   $apply= "";
1524   $apply= ''.
1525     '<table summary=""  width="100%"  style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1526     '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1528   return ($apply);
1532 function back_to_main()
1534   $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1535     _("Back").'"></p><input type="hidden" name="ignore">';
1537   return ($string);
1541 function normalize_netmask($netmask)
1543   /* Check for notation of netmask */
1544   if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1545     $num= (int)($netmask);
1546     $netmask= "";
1548     for ($byte= 0; $byte<4; $byte++){
1549       $result=0;
1551       for ($i= 7; $i>=0; $i--){
1552         if ($num-- > 0){
1553           $result+= pow(2,$i);
1554         }
1555       }
1557       $netmask.= $result.".";
1558     }
1560     return (preg_replace('/\.$/', '', $netmask));
1561   }
1563   return ($netmask);
1567 function netmask_to_bits($netmask)
1569   list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1570   $res= 0;
1572   for ($n= 0; $n<4; $n++){
1573     $start= 255;
1574     $name= "nm$n";
1576     for ($i= 0; $i<8; $i++){
1577       if ($start == (int)($$name)){
1578         $res+= 8 - $i;
1579         break;
1580       }
1581       $start-= pow(2,$i);
1582     }
1583   }
1585   return ($res);
1589 function recurse($rule, $variables)
1591   $result= array();
1593   if (!count($variables)){
1594     return array($rule);
1595   }
1597   reset($variables);
1598   $key= key($variables);
1599   $val= current($variables);
1600   unset ($variables[$key]);
1602   foreach($val as $possibility){
1603     $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1604     $result= array_merge($result, recurse($nrule, $variables));
1605   }
1607   return ($result);
1611 function expand_id($rule, $attributes)
1613   /* Check for id rule */
1614   if(preg_match('/^id(:|#)\d+$/',$rule)){
1615     return (array("\{$rule}"));
1616   }
1618   /* Check for clean attribute */
1619   if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1620     $rule= preg_replace('/^%/', '', $rule);
1621     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1622     return (array($val));
1623   }
1625   /* Check for attribute with parameters */
1626   if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1627     $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1628     $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1629     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1630     $start= preg_replace ('/-.*$/', '', $param);
1631     $stop = preg_replace ('/^[^-]+-/', '', $param);
1633     /* Assemble results */
1634     $result= array();
1635     for ($i= $start; $i<= $stop; $i++){
1636       $result[]= substr($val, 0, $i);
1637     }
1638     return ($result);
1639   }
1641   echo "Error in idgen string: don't know how to handle rule $rule.\n";
1642   return (array($rule));
1646 function gen_uids($rule, $attributes)
1648   global $config;
1650   /* Search for keys and fill the variables array with all 
1651      possible values for that key. */
1652   $part= "";
1653   $trigger= false;
1654   $stripped= "";
1655   $variables= array();
1657   for ($pos= 0; $pos < strlen($rule); $pos++){
1659     if ($rule[$pos] == "{" ){
1660       $trigger= true;
1661       $part= "";
1662       continue;
1663     }
1665     if ($rule[$pos] == "}" ){
1666       $variables[$pos]= expand_id($part, $attributes);
1667       $stripped.= "\{$pos}";
1668       $trigger= false;
1669       continue;
1670     }
1672     if ($trigger){
1673       $part.= $rule[$pos];
1674     } else {
1675       $stripped.= $rule[$pos];
1676     }
1677   }
1679   /* Recurse through all possible combinations */
1680   $proposed= recurse($stripped, $variables);
1682   /* Get list of used ID's */
1683   $used= array();
1684   $ldap= $config->get_ldap_link();
1685   $ldap->cd($config->current['BASE']);
1686   $ldap->search('(uid=*)');
1688   while($attrs= $ldap->fetch()){
1689     $used[]= $attrs['uid'][0];
1690   }
1692   /* Remove used uids and watch out for id tags */
1693   $ret= array();
1694   foreach($proposed as $uid){
1696     /* Check for id tag and modify uid if needed */
1697     if(preg_match('/\{id:\d+}/',$uid)){
1698       $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1700       for ($i= 0; $i < pow(10,$size); $i++){
1701         $number= sprintf("%0".$size."d", $i);
1702         $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1703         if (!in_array($res, $used)){
1704           $uid= $res;
1705           break;
1706         }
1707       }
1708     }
1710   if(preg_match('/\{id#\d+}/',$uid)){
1711     $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1713     while (true){
1714       mt_srand((double) microtime()*1000000);
1715       $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1716       $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1717       if (!in_array($res, $used)){
1718         $uid= $res;
1719         break;
1720       }
1721     }
1722   }
1724 /* Don't assign used ones */
1725 if (!in_array($uid, $used)){
1726   $ret[]= $uid;
1730 return(array_unique($ret));
1734 function array_search_r($needle, $key, $haystack){
1736   foreach($haystack as $index => $value){
1737     $match= 0;
1739     if (is_array($value)){
1740       $match= array_search_r($needle, $key, $value);
1741     }
1743     if ($index==$key && !is_array($value) && preg_match("/$needle/i", $value)){
1744       $match=1;
1745     }
1747     if ($match){
1748       return 1;
1749     }
1750   }
1752   return 0;
1753
1756 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1757    Need to convert... */
1758 function to_byte($value) {
1759   $value= strtolower(trim($value));
1761   if(!is_numeric(substr($value, -1))) {
1763     switch(substr($value, -1)) {
1764       case 'g':
1765         $mult= 1073741824;
1766         break;
1767       case 'm':
1768         $mult= 1048576;
1769         break;
1770       case 'k':
1771         $mult= 1024;
1772         break;
1773     }
1775     return ($mult * (int)substr($value, 0, -1));
1776   } else {
1777     return $value;
1778   }
1782 function in_array_ics($value, $items)
1784   if (!is_array($items)){
1785     return (FALSE);
1786   }
1788   foreach ($items as $item){
1789     if (strtolower($item) == strtolower($value)) {
1790       return (TRUE);
1791     }
1792   }
1794   return (FALSE);
1795
1798 function generate_alphabet($count= 10)
1800   $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1801   $alphabet= "";
1802   $c= 0;
1804   /* Fill cells with charaters */
1805   for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1806     if ($c == 0){
1807       $alphabet.= "<tr>";
1808     }
1810     $ch = mb_substr($characters, $i, 1, "UTF8");
1811     $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1812       validate($_GET['plug'])."&amp;search=".$ch."\">&nbsp;".$ch."&nbsp;</a></td>";
1814     if ($c++ == $count){
1815       $alphabet.= "</tr>";
1816       $c= 0;
1817     }
1818   }
1820   /* Fill remaining cells */
1821   while ($c++ <= $count){
1822     $alphabet.= "<td>&nbsp;</td>";
1823   }
1825   return ($alphabet);
1829 function validate($string)
1831   return (strip_tags(preg_replace('/\0/', '', $string)));
1834 function get_gosa_version()
1836   global $svn_revision, $svn_path;
1838   /* Extract informations */
1839   $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1841   /* Release or development? */
1842   if (preg_match('%/gosa/trunk/%', $svn_path)){
1843     return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1844   } else {
1845     $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1846     return (_("GOsa $release"));
1847   }
1851 function rmdirRecursive($path, $followLinks=false) {
1852   $dir= opendir($path);
1853   while($entry= readdir($dir)) {
1854     if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1855       unlink($path."/".$entry);
1856     } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1857       rmdirRecursive($path."/".$entry);
1858     }
1859   }
1860   closedir($dir);
1861   return rmdir($path);
1864 function scan_directory($path,$sort_desc=false)
1866   $ret = false;
1868   /* is this a dir ? */
1869   if(is_dir($path)) {
1871     /* is this path a readable one */
1872     if(is_readable($path)){
1874       /* Get contents and write it into an array */   
1875       $ret = array();    
1877       $dir = opendir($path);
1879       /* Is this a correct result ?*/
1880       if($dir){
1881         while($fp = readdir($dir))
1882           $ret[]= $fp;
1883       }
1884     }
1885   }
1886   /* Sort array ascending , like scandir */
1887   sort($ret);
1889   /* Sort descending if parameter is sort_desc is set */
1890   if($sort_desc) {
1891     $ret = array_reverse($ret);
1892   }
1894   return($ret);
1897 function clean_smarty_compile_dir($directory)
1899   global $svn_revision;
1901   if(is_dir($directory) && is_readable($directory)) {
1902     // Set revision filename to REVISION
1903     $revision_file= $directory."/REVISION";
1905     /* Is there a stamp containing the current revision? */
1906     if(!file_exists($revision_file)) {
1907       // create revision file
1908       create_revision($revision_file, $svn_revision);
1909     } else {
1910 # check for "$config->...['CONFIG']/revision" and the
1911 # contents should match the revision number
1912       if(!compare_revision($revision_file, $svn_revision)){
1913         // If revision differs, clean compile directory
1914         foreach(scan_directory($directory) as $file) {
1915           if(($file==".")||($file=="..")) continue;
1916           if( is_file($directory."/".$file) &&
1917               is_writable($directory."/".$file)) {
1918             // delete file
1919             if(!unlink($directory."/".$file)) {
1920               print_red("File ".$directory."/".$file." could not be deleted.");
1921               // This should never be reached
1922             }
1923           } elseif(is_dir($directory."/".$file) &&
1924               is_writable($directory."/".$file)) {
1925             // Just recursively delete it
1926             rmdirRecursive($directory."/".$file);
1927           }
1928         }
1929         // We should now create a fresh revision file
1930         clean_smarty_compile_dir($directory);
1931       } else {
1932         // Revision matches, nothing to do
1933       }
1934     }
1935   } else {
1936     // Smarty compile dir is not accessible
1937     // (Smarty will warn about this)
1938   }
1941 function create_revision($revision_file, $revision)
1943   $result= false;
1945   if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1946     if($fh= fopen($revision_file, "w")) {
1947       if(fwrite($fh, $revision)) {
1948         $result= true;
1949       }
1950     }
1951     fclose($fh);
1952   } else {
1953     print_red("Can not write to revision file");
1954   }
1956   return $result;
1959 function compare_revision($revision_file, $revision)
1961   // false means revision differs
1962   $result= false;
1964   if(file_exists($revision_file) && is_readable($revision_file)) {
1965     // Open file
1966     if($fh= fopen($revision_file, "r")) {
1967       // Compare File contents with current revision
1968       if($revision == fread($fh, filesize($revision_file))) {
1969         $result= true;
1970       }
1971     } else {
1972       print_red("Can not open revision file");
1973     }
1974     // Close file
1975     fclose($fh);
1976   }
1978   return $result;
1981 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1983   $str = ""; // Our return value will be saved in this var
1985   $color  = dechex($percentage+150);
1986   $color2 = dechex(150 - $percentage);
1987   $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1989   $progress = (int)(($percentage /100)*$width);
1991   /* Abort printing out percentage, if divs are to small */
1994   /* If theres a better solution for this, use it... */
1995   $str = "
1996     <div style=\" width:".($width)."px; 
1997     height:".($height)."px;
1998   background-color:#000000;
1999 padding:1px;\">
2001           <div style=\" width:".($width)."px;
2002         background-color:#$bgcolor;
2003 height:".($height)."px;\">
2005          <div style=\" width:".$progress."px;
2006 height:".$height."px;
2007        background-color:#".$color2.$color2.$color."; \">";
2010        if(($height >10)&&($showvalue)){
2011          $str.=                 "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2012            <b>".$percentage."%</b>
2013            </font>";
2014        }
2016        $str.= "</div></div></div>";
2018        return($str);
2022 function array_key_ics($ikey, $items)
2024   /* Gather keys, make them lowercase */
2025   $tmp= array();
2026   foreach ($items as $key => $value){
2027     $tmp[strtolower($key)]= $key;
2028   }
2030   if (isset($tmp[strtolower($ikey)])){
2031     return($tmp[strtolower($ikey)]);
2032   }
2034   return ("");
2038 function search_config($arr, $name, $return)
2040   if (is_array($arr)){
2041     foreach ($arr as $a){
2042       if (isset($a['CLASS']) &&
2043           strtolower($a['CLASS']) == strtolower($name)){
2045         if (isset($a[$return])){
2046           return ($a[$return]);
2047         } else {
2048           return ("");
2049         }
2050       } else {
2051         $res= search_config ($a, $name, $return);
2052         if ($res != ""){
2053           return $res;
2054         }
2055       }
2056     }
2057   }
2058   return ("");
2062 function array_differs($src, $dst)
2064   /* If the count is differing, the arrays differ */
2065   if (count ($src) != count ($dst)){
2066     return (TRUE);
2067   }
2069   /* So the count is the same - lets check the contents */
2070   $differs= FALSE;
2071   foreach($src as $value){
2072     if (!in_array($value, $dst)){
2073       $differs= TRUE;
2074     }
2075   }
2077   return ($differs);
2081 function saveFilter($a_filter, $values)
2083   if (isset($_POST['regexit'])){
2084     $a_filter["regex"]= $_POST['regexit'];
2086     foreach($values as $type){
2087       if (isset($_POST[$type])) {
2088         $a_filter[$type]= "checked";
2089       } else {
2090         $a_filter[$type]= "";
2091       }
2092     }
2093   }
2095   /* React on alphabet links if needed */
2096   if (isset($_GET['search'])){
2097     $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2098     if ($s == "**"){
2099       $s= "*";
2100     }
2101     $a_filter['regex']= $s;
2102   }
2104   return ($a_filter);
2108 /* Escape all preg_* relevant characters */
2109 function normalizePreg($input)
2111   return (addcslashes($input, '[]()|/.*+-'));
2115 /* Escape all LDAP filter relevant characters */
2116 function normalizeLdap($input)
2118   return (addcslashes($input, '()|'));
2122 /* Resturns the difference between to microtime() results in float  */
2123 function get_MicroTimeDiff($start , $stop)
2125   $a = split("\ ",$start);
2126   $b = split("\ ",$stop);
2128   $secs = $b[1] - $a[1];
2129   $msecs= $b[0] - $a[0]; 
2131   $ret = (float) ($secs+ $msecs);
2132   return($ret);
2136 /* Check if the given department name is valid */
2137 function is_department_name_reserved($name,$base)
2139   $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2140                           preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2141                           preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2142   $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2144   /* Check if name is one of the reserved names */
2145   if(in_array_ics($name,$reservedName)) {
2146     return(true);
2147   }
2149   /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2150   foreach($follwedNames as $key => $names){
2151     if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2152       return(true);
2153     }
2154   }
2155   return(false);
2159 function is_php4()
2161   if (isset($_SESSION['PHP4COMPATIBLE'])){
2162     return true;
2163   }
2164   return (preg_match('/^4/', phpversion()));
2168 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2170   /* Initialize variables */
2171   $ret  = array("count" => 0);  // Set count to 0
2172   $next = true;                 // if false, then skip next loops and return
2173   $cnt  = 0;                    // Current number of loops
2174   $max  = 100;                  // Just for security, prevent looops
2175   $ldap = NULL;                 // To check if created result a valid
2176   $keep = "";                   // save last failed parse string
2178   /* Check each parsed dn in ldap ? */
2179   if($config!=NULL && $verify_in_ldap){
2180     $ldap = $config->get_ldap_link();
2181   }
2183   /* Lets start */
2184   $called = false;
2185   while(preg_match("/,/",$dn) && $next &&  $cnt < $max){
2187     $cnt ++;
2188     if(!preg_match("/,/",$dn)){
2189       $next = false;
2190     }
2191     $object = preg_replace("/[,].*$/","",$dn);
2192     $dn     = preg_replace("/^[^,]+,/","",$dn);
2194     $called = true;
2196     /* Check if current dn is valid */
2197     if($ldap!=NULL){
2198       $ldap->cd($dn);
2199       $ldap->cat($dn,array("dn"));
2200       if($ldap->count()){
2201         $ret[]  = $keep.$object;
2202         $keep   = "";
2203       }else{
2204         $keep  .= $object.",";
2205       }
2206     }else{
2207       $ret[]  = $keep.$object;
2208       $keep   = "";
2209     }
2210   }
2212   /* No dn was posted */
2213   if($cnt == 0 && !empty($dn)){
2214     $ret[] = $dn;
2215   }
2217   /* Append the rest */
2218   $test = $keep.$dn;
2219   if($called && !empty($test)){
2220     $ret[] = $keep.$dn;
2221   }
2222   $ret['count'] = count($ret) - 1;
2224   return($ret);
2228 function get_base_from_hook($dn, $attrib)
2230   global $config;
2232   if (isset($config->current['BASE_HOOK'])){
2233     
2234     /* Call hook script - if present */
2235     $command= $config->current['BASE_HOOK'];
2237     if ($command != ""){
2238       $command.= " '$dn' $attrib";
2239       if (check_command($command)){
2240         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2241         exec($command, $output);
2242         if (preg_match("/^[0-9]+$/", $output[0])){
2243           return ($output[0]);
2244         } else {
2245           print_red(_("Warning - base_hook is not available. Using default base."));
2246           return ($config->current['UIDBASE']);
2247         }
2248       } else {
2249         print_red(_("Warning - base_hook is not available. Using default base."));
2250         return ($config->current['UIDBASE']);
2251       }
2253     } else {
2255       print_red(_("Warning - no base_hook defined. Using default base."));
2256       return ($config->current['UIDBASE']);
2258     }
2259   }
2262 /* Schema validation functions */
2264   function check_schema_version($class, $version)
2265   {
2266     return preg_match("/\(v$version\)/", $class['DESC']);
2267   }
2269   
2271   function check_schema($cfg,$rfc2307bis = FALSE)
2272   {
2274     $messages= array();
2276     /* Get objectclasses */
2277     $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2278     $objectclasses = $ldap->get_objectclasses();
2279     if(count($objectclasses) == 0){
2280       print_red(_("Can't get schema information from server. No schema check possible!"));
2281     }
2283     /* This is the default block used for each entry.
2284      *  to avoid unset indexes.
2285      */
2286     $def_check = array("REQUIRED_VERSION" => "0",
2287                        "SCHEMA_FILES"     => array(),
2288                        "CLASSES_REQUIRED" => array(),
2289                        "STATUS"           => FALSE,
2290                        "IS_MUST_HAVE"     => FALSE,
2291                        "MSG"              => "",
2292                        "INFO"             => "");#_("There is currently no information specified for this schema extension."));
2294  /* The gosa base schema */
2295     $checks['gosaObject'] = $def_check;
2296     $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2297     $checks['gosaObject']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2298     $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2299     $checks['gosaObject']['IS_MUST_HAVE']     = TRUE;
2301     /* GOsa Account class */
2302     $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2303     $checks["gosaAccount"]["SCHEMA_FILES"]    = array("gosa+samba3.schema","gosa.schema");
2304     $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2305     $checks["gosaAccount"]["IS_MUST_HAVE"]    = TRUE;
2306     $checks["gosaAccount"]["INFO"]            = _("Used to store account specific informations.");
2308     /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2309     $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2310     $checks["gosaLockEntry"]["SCHEMA_FILES"]     = array("gosa+samba3.schema","gosa.schema");
2311     $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2312     $checks["gosaLockEntry"]["IS_MUST_HAVE"]     = TRUE;
2313     $checks["gosaLockEntry"]["INFO"]             = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2315   /* Some other checks */
2316     foreach(array(
2317           "gosaCacheEntry"        => array("version" => "2.4"),
2318           "gosaDepartment"        => array("version" => "2.4"),
2319           "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2320           "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2321           "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2322           "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2323           "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2324           "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2325           "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2326           "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2327           "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2328           "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2329           "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2330           "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2331           "goShareServer"         => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2332           "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2333           "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2334           "goLdapServer"          => array("version" => "2.4"),
2335           "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2336           "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.        schema"),
2337           "goKrbServer"           => array("version" => "2.4"),
2338           "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2339           ) as $name => $values){
2341       $checks[$name] = $def_check;
2342       if(isset($values['version'])){
2343         $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2344       }
2345       if(isset($values['file'])){
2346         $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2347       }
2348       $checks[$name]["CLASSES_REQUIRED"] = array($name);
2349     }
2350    foreach($checks as $name => $value){
2351       foreach($value['CLASSES_REQUIRED'] as $class){
2353         if(!isset($objectclasses[$name])){
2354           $checks[$name]['STATUS'] = FALSE;
2355           if($value['IS_MUST_HAVE']){
2356             $checks[$name]['MSG']    = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2357           }else{
2358             $checks[$name]['MSG']    = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2359           }
2360         }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2361           $checks[$name]['STATUS'] = FALSE;
2363           if($value['IS_MUST_HAVE']){
2364             $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2365           }else{
2366             $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2367           }
2368         }else{
2369           $checks[$name]['STATUS'] = TRUE;
2370           $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2371         }
2372       }
2373     }
2375     $tmp = $objectclasses;
2378     /* The gosa base schema */
2379     $checks['posixGroup'] = $def_check;
2380     $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2381     $checks['posixGroup']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2382     $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2383     $checks['posixGroup']['STATUS']           = TRUE;
2384     $checks['posixGroup']['IS_MUST_HAVE']     = TRUE;
2385     $checks['posixGroup']['MSG']              = "";
2386     $checks['posixGroup']['INFO']             = "";
2388     /* Depending on selected rfc2307bis mode, we need different schema configurations */
2389     if(isset($tmp['posixGroup'])){
2391       if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2392         $checks['posixGroup']['STATUS']           = FALSE;
2393         $checks['posixGroup']['MSG']              = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema    configuration do not support this option.");
2394         $checks['posixGroup']['INFO']             = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be      AUXILIARY");
2395       }
2396       if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2397         $checks['posixGroup']['STATUS']           = FALSE;
2398         $checks['posixGroup']['MSG']              = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema   configuration do not support this option.");
2399         $checks['posixGroup']['INFO']             = _("The objectClass 'posixGroup' must be STRUCTURAL");
2400       }
2401     }
2403     return($checks);
2404   }
2409 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
2410 ?>