Code

Removed hint to 75%
[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'].= "
1136  <div  id='e_layer2'
1137                 style='
1138                       position: absolute;
1139                       left: 0px;
1140                       top: 0px;
1141                       right:0px;
1142                       bottom:0px;
1143                       z-index:149;
1144                       background-image: url(images/opacity_black_55.png);
1147           </div>
1148           <div style='left:20%;right:20%;top:30%;".
1149             "background-color:white;padding:5px;border:5px solid red;z-index:150;".
1150             "position:absolute' id='e_layer'><table style='width:100%' summary='' border=0>".
1151             "<tr><td style='vertical-align:top;padding:10px'><img alt='' src='".
1152             get_template_path($img)."'></td>".
1153             "<td style='width:100%'><h1>"._("An error occurred while processing your request").
1154             "</h1><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
1155             (($_SESSION['js']==FALSE)?"type='submit'":"type='button' name='error_accept'").
1156             " style='width:80px' onClick='hide(\"e_layer\");hide(\"e_layer2\");'>".
1157             _("OK")."</button></td></tr></table></div>";
1158         }
1160       }else{
1161         return;
1162       }
1163       $_SESSION['errorsAlreadyPosted'][$string] = 1;
1165     }
1167   } else {
1168     echo "Error: $string\n";
1169   }
1170   $_SESSION['LastError'] = $string; 
1174 function gen_locked_message($user, $dn)
1176   global $plug, $config;
1178   $_SESSION['dn']= $dn;
1179   $ldap= $config->get_ldap_link();
1180   $ldap->cat ($user, array('uid', 'cn'));
1181   $attrs= $ldap->fetch();
1183   /* Stop if we have no user here... */
1184   if (count($attrs)){
1185     $uid= $attrs["uid"][0];
1186     $cn= $attrs["cn"][0];
1187   } else {
1188     $uid= $attrs["uid"][0];
1189     $cn= $attrs["cn"][0];
1190   }
1191   
1192   $remove= false;
1194   if((isset($_SESSION['LOCK_VARS_TO_USE']))&&(count($_SESSION['LOCK_VARS_TO_USE']))){
1195     $_SESSION['LOCK_VARS_USED']  =array();
1196     foreach($_SESSION['LOCK_VARS_TO_USE'] as $name){
1198       if(empty($name)) continue;
1199       foreach($_POST as $Pname => $Pvalue){
1200         if(preg_match($name,$Pname)){
1201           $_SESSION['LOCK_VARS_USED'][$Pname] = $_POST[$Pname];
1202         }
1203       }
1205       foreach($_GET as $Pname => $Pvalue){
1206         if(preg_match($name,$Pname)){
1207           $_SESSION['LOCK_VARS_USED'][$Pname] = $_GET[$Pname];
1208         }
1209       }
1210     }
1211     $_SESSION['LOCK_VARS_TO_USE'] =array();
1212   }
1214   /* Prepare and show template */
1215   $smarty= get_smarty();
1216   $smarty->assign ("dn", $dn);
1217   if ($remove){
1218     $smarty->assign ("action", _("Continue anyway"));
1219   } else {
1220     $smarty->assign ("action", _("Edit anyway"));
1221   }
1222   $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>"));
1224   return ($smarty->fetch (get_template_path('islocked.tpl')));
1228 function to_string ($value)
1230   /* If this is an array, generate a text blob */
1231   if (is_array($value)){
1232     $ret= "";
1233     foreach ($value as $line){
1234       $ret.= $line."<br>\n";
1235     }
1236     return ($ret);
1237   } else {
1238     return ($value);
1239   }
1243 function get_printer_list($cups_server)
1245   global $config;
1247   $res= array();
1249   /* Use CUPS, if we've access to it */
1250   if (function_exists('cups_get_dest_list')){
1251     $dest_list= cups_get_dest_list ($cups_server);
1253     foreach ($dest_list as $prt){
1254       $attr= cups_get_printer_attributes ($cups_server, $prt->name);
1256       foreach ($attr as $prt_info){
1257         if ($prt_info->name == "printer-info"){
1258           $info= $prt_info->value;
1259           break;
1260         }
1261       }
1262       $res[$prt->name]= "$info [$prt->name]";
1263     }
1265     /* CUPS is not available, try lpstat as a replacement */
1266   } else {
1267     $ar = false;
1268     exec("lpstat -p", $ar);
1269     foreach($ar as $val){
1270       @list($dummy, $printer, $rest)= split(' ', $val, 3);
1271       if (preg_match('/^[^@]+$/', $printer)){
1272         $res[$printer]= "$printer";
1273       }
1274     }
1275   }
1277   /* Merge in printers from LDAP */
1278   $ldap= $config->get_ldap_link();
1279   $ldap->cd ($config->current['BASE']);
1280   $ui= get_userinfo();
1281   if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){   
1282     $ldap->search('((objectClass=gotoPrinter)(gosaUnitTag='.$ui->gosaUnitTag.'))', array('cn'));
1283   } else {
1284     $ldap->search('(objectClass=gotoPrinter)', array('cn'));
1285   }
1286   while($attrs = $ldap->fetch()){
1287     $res[$attrs['cn'][0]] = $attrs['cn'][0];
1288   }
1290   return $res;
1294 function sess_del ($var)
1296   /* New style */
1297   unset ($_SESSION[$var]);
1299   /* ... work around, since the first one
1300      doesn't seem to work all the time */
1301   session_unregister ($var);
1305 function show_errors($message)
1307   $complete= "";
1309   /* Assemble the message array to a plain string */
1310   foreach ($message as $error){
1311     if ($complete == ""){
1312       $complete= $error;
1313     } else {
1314       $complete= "$error<br>$complete";
1315     }
1316   }
1318   /* Fill ERROR variable with nice error dialog */
1319   print_red($complete);
1323 function show_ldap_error($message, $addon= "")
1325   if (!preg_match("/Success/i", $message)){
1326     if ($addon == ""){
1327       print_red (_("LDAP error: $message"));
1328     } else {
1329       print_red ("$addon<br><br><b>"._("LDAP error:")."</b> $message");
1330     }
1331     return TRUE;
1332   } else {
1333     return FALSE;
1334   }
1338 function rewrite($s)
1340   global $REWRITE;
1342   foreach ($REWRITE as $key => $val){
1343     $s= preg_replace("/$key/", "$val", $s);
1344   }
1346   return ($s);
1350 function dn2base($dn)
1352   global $config;
1354   if (get_people_ou() != ""){
1355     $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1356   }
1357   if (get_groups_ou() != ""){
1358     $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1359   }
1360   $base= preg_replace ('/^[^,]+,/i', '', $dn);
1362   return ($base);
1367 function check_command($cmdline)
1369   $cmd= preg_replace("/ .*$/", "", $cmdline);
1371   /* Check if command exists in filesystem */
1372   if (!file_exists($cmd)){
1373     return (FALSE);
1374   }
1376   /* Check if command is executable */
1377   if (!is_executable($cmd)){
1378     return (FALSE);
1379   }
1381   return (TRUE);
1385 function print_header($image, $headline, $info= "")
1387   $display= "<div class=\"plugtop\">\n";
1388   $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";
1389   $display.= "</div>\n";
1391   if ($info != ""){
1392     $display.= "<div class=\"pluginfo\">\n";
1393     $display.= "$info";
1394     $display.= "</div>\n";
1395   } else {
1396     $display.= "<div style=\"height:5px;\">\n";
1397     $display.= "&nbsp;";
1398     $display.= "</div>\n";
1399   }
1400   if (isset($_SESSION['errors'])){
1401     $display.= $_SESSION['errors'];
1402   }
1404   return ($display);
1408 function register_global($name, $object)
1410   $_SESSION[$name]= $object;
1414 function is_global($name)
1416   return isset($_SESSION[$name]);
1420 function get_global($name)
1422   return $_SESSION[$name];
1426 function range_selector($dcnt,$start,$range=25,$post_var=false)
1429   /* Entries shown left and right from the selected entry */
1430   $max_entries= 10;
1432   /* Initialize and take care that max_entries is even */
1433   $output="";
1434   if ($max_entries & 1){
1435     $max_entries++;
1436   }
1438   if((!empty($post_var))&&(isset($_POST[$post_var]))){
1439     $range= $_POST[$post_var];
1440   }
1442   /* Prevent output to start or end out of range */
1443   if ($start < 0 ){
1444     $start= 0 ;
1445   }
1446   if ($start >= $dcnt){
1447     $start= $range * (int)(($dcnt / $range) + 0.5);
1448   }
1450   $numpages= (($dcnt / $range));
1451   if(((int)($numpages))!=($numpages)){
1452     $numpages = (int)$numpages + 1;
1453   }
1454   if ((((int)$numpages) <= 1 )&&(!$post_var)){
1455     return ("");
1456   }
1457   $ppage= (int)(($start / $range) + 0.5);
1460   /* Align selected page to +/- max_entries/2 */
1461   $begin= $ppage - $max_entries/2;
1462   $end= $ppage + $max_entries/2;
1464   /* Adjust begin/end, so that the selected value is somewhere in
1465      the middle and the size is max_entries if possible */
1466   if ($begin < 0){
1467     $end-= $begin + 1;
1468     $begin= 0;
1469   }
1470   if ($end > $numpages) {
1471     $end= $numpages;
1472   }
1473   if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1474     $begin= $end - $max_entries;
1475   }
1477   if($post_var){
1478     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1479       <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1480   }else{
1481     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1482   }
1484   /* Draw decrement */
1485   if ($start > 0 ) {
1486     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1487       (($start-$range))."\">".
1488       "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1489   }
1491   /* Draw pages */
1492   for ($i= $begin; $i < $end; $i++) {
1493     if ($ppage == $i){
1494       $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1495         validate($_GET['plug'])."&amp;start=".
1496         ($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1497     } else {
1498       $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1499         "&amp;start=".($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1500     }
1501   }
1503   /* Draw increment */
1504   if($start < ($dcnt-$range)) {
1505     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1506       (($start+($range)))."\">".
1507       "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1508   }
1510   if(($post_var)&&($numpages)){
1511     $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()'>";
1512     foreach(array(20,50,100,200,"all") as $num){
1513       if($num == "all"){
1514         $var = 10000;
1515       }else{
1516         $var = $num;
1517       }
1518       if($var == $range){
1519         $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1520       }else{  
1521         $output.="\n<option value='".$var."'>".$num."</option>";
1522       }
1523     }
1524     $output.=  "</select></td></tr></table></div>";
1525   }else{
1526     $output.= "</div>";
1527   }
1529   return($output);
1533 function apply_filter()
1535   $apply= "";
1537   $apply= ''.
1538     '<table summary=""  width="100%"  style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1539     '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1541   return ($apply);
1545 function back_to_main()
1547   $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1548     _("Back").'"></p><input type="hidden" name="ignore">';
1550   return ($string);
1554 function normalize_netmask($netmask)
1556   /* Check for notation of netmask */
1557   if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1558     $num= (int)($netmask);
1559     $netmask= "";
1561     for ($byte= 0; $byte<4; $byte++){
1562       $result=0;
1564       for ($i= 7; $i>=0; $i--){
1565         if ($num-- > 0){
1566           $result+= pow(2,$i);
1567         }
1568       }
1570       $netmask.= $result.".";
1571     }
1573     return (preg_replace('/\.$/', '', $netmask));
1574   }
1576   return ($netmask);
1580 function netmask_to_bits($netmask)
1582   list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1583   $res= 0;
1585   for ($n= 0; $n<4; $n++){
1586     $start= 255;
1587     $name= "nm$n";
1589     for ($i= 0; $i<8; $i++){
1590       if ($start == (int)($$name)){
1591         $res+= 8 - $i;
1592         break;
1593       }
1594       $start-= pow(2,$i);
1595     }
1596   }
1598   return ($res);
1602 function recurse($rule, $variables)
1604   $result= array();
1606   if (!count($variables)){
1607     return array($rule);
1608   }
1610   reset($variables);
1611   $key= key($variables);
1612   $val= current($variables);
1613   unset ($variables[$key]);
1615   foreach($val as $possibility){
1616     $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1617     $result= array_merge($result, recurse($nrule, $variables));
1618   }
1620   return ($result);
1624 function expand_id($rule, $attributes)
1626   /* Check for id rule */
1627   if(preg_match('/^id(:|#)\d+$/',$rule)){
1628     return (array("\{$rule}"));
1629   }
1631   /* Check for clean attribute */
1632   if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1633     $rule= preg_replace('/^%/', '', $rule);
1634     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1635     return (array($val));
1636   }
1638   /* Check for attribute with parameters */
1639   if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1640     $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1641     $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1642     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1643     $start= preg_replace ('/-.*$/', '', $param);
1644     $stop = preg_replace ('/^[^-]+-/', '', $param);
1646     /* Assemble results */
1647     $result= array();
1648     for ($i= $start; $i<= $stop; $i++){
1649       $result[]= substr($val, 0, $i);
1650     }
1651     return ($result);
1652   }
1654   echo "Error in idgen string: don't know how to handle rule $rule.\n";
1655   return (array($rule));
1659 function gen_uids($rule, $attributes)
1661   global $config;
1663   /* Search for keys and fill the variables array with all 
1664      possible values for that key. */
1665   $part= "";
1666   $trigger= false;
1667   $stripped= "";
1668   $variables= array();
1670   for ($pos= 0; $pos < strlen($rule); $pos++){
1672     if ($rule[$pos] == "{" ){
1673       $trigger= true;
1674       $part= "";
1675       continue;
1676     }
1678     if ($rule[$pos] == "}" ){
1679       $variables[$pos]= expand_id($part, $attributes);
1680       $stripped.= "\{$pos}";
1681       $trigger= false;
1682       continue;
1683     }
1685     if ($trigger){
1686       $part.= $rule[$pos];
1687     } else {
1688       $stripped.= $rule[$pos];
1689     }
1690   }
1692   /* Recurse through all possible combinations */
1693   $proposed= recurse($stripped, $variables);
1695   /* Get list of used ID's */
1696   $used= array();
1697   $ldap= $config->get_ldap_link();
1698   $ldap->cd($config->current['BASE']);
1699   $ldap->search('(uid=*)');
1701   while($attrs= $ldap->fetch()){
1702     $used[]= $attrs['uid'][0];
1703   }
1705   /* Remove used uids and watch out for id tags */
1706   $ret= array();
1707   foreach($proposed as $uid){
1709     /* Check for id tag and modify uid if needed */
1710     if(preg_match('/\{id:\d+}/',$uid)){
1711       $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1713       for ($i= 0; $i < pow(10,$size); $i++){
1714         $number= sprintf("%0".$size."d", $i);
1715         $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1716         if (!in_array($res, $used)){
1717           $uid= $res;
1718           break;
1719         }
1720       }
1721     }
1723   if(preg_match('/\{id#\d+}/',$uid)){
1724     $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1726     while (true){
1727       mt_srand((double) microtime()*1000000);
1728       $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1729       $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1730       if (!in_array($res, $used)){
1731         $uid= $res;
1732         break;
1733       }
1734     }
1735   }
1737 /* Don't assign used ones */
1738 if (!in_array($uid, $used)){
1739   $ret[]= $uid;
1743 return(array_unique($ret));
1747 function array_search_r($needle, $key, $haystack){
1749   foreach($haystack as $index => $value){
1750     $match= 0;
1752     if (is_array($value)){
1753       $match= array_search_r($needle, $key, $value);
1754     }
1756     if ($index==$key && !is_array($value) && preg_match("/$needle/i", $value)){
1757       $match=1;
1758     }
1760     if ($match){
1761       return 1;
1762     }
1763   }
1765   return 0;
1766
1769 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1770    Need to convert... */
1771 function to_byte($value) {
1772   $value= strtolower(trim($value));
1774   if(!is_numeric(substr($value, -1))) {
1776     switch(substr($value, -1)) {
1777       case 'g':
1778         $mult= 1073741824;
1779         break;
1780       case 'm':
1781         $mult= 1048576;
1782         break;
1783       case 'k':
1784         $mult= 1024;
1785         break;
1786     }
1788     return ($mult * (int)substr($value, 0, -1));
1789   } else {
1790     return $value;
1791   }
1795 function in_array_ics($value, $items)
1797   if (!is_array($items)){
1798     return (FALSE);
1799   }
1801   foreach ($items as $item){
1802     if (strtolower($item) == strtolower($value)) {
1803       return (TRUE);
1804     }
1805   }
1807   return (FALSE);
1808
1811 function generate_alphabet($count= 10)
1813   $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1814   $alphabet= "";
1815   $c= 0;
1817   /* Fill cells with charaters */
1818   for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1819     if ($c == 0){
1820       $alphabet.= "<tr>";
1821     }
1823     $ch = mb_substr($characters, $i, 1, "UTF8");
1824     $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1825       validate($_GET['plug'])."&amp;search=".$ch."\">&nbsp;".$ch."&nbsp;</a></td>";
1827     if ($c++ == $count){
1828       $alphabet.= "</tr>";
1829       $c= 0;
1830     }
1831   }
1833   /* Fill remaining cells */
1834   while ($c++ <= $count){
1835     $alphabet.= "<td>&nbsp;</td>";
1836   }
1838   return ($alphabet);
1842 function validate($string)
1844   return (strip_tags(preg_replace('/\0/', '', $string)));
1847 function get_gosa_version()
1849   global $svn_revision, $svn_path;
1851   /* Extract informations */
1852   $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1854   /* Release or development? */
1855   if (preg_match('%/gosa/trunk/%', $svn_path)){
1856     return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1857   } else {
1858     $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1859     return (_("GOsa $release"));
1860   }
1864 function rmdirRecursive($path, $followLinks=false) {
1865   $dir= opendir($path);
1866   while($entry= readdir($dir)) {
1867     if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1868       unlink($path."/".$entry);
1869     } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1870       rmdirRecursive($path."/".$entry);
1871     }
1872   }
1873   closedir($dir);
1874   return rmdir($path);
1877 function scan_directory($path,$sort_desc=false)
1879   $ret = false;
1881   /* is this a dir ? */
1882   if(is_dir($path)) {
1884     /* is this path a readable one */
1885     if(is_readable($path)){
1887       /* Get contents and write it into an array */   
1888       $ret = array();    
1890       $dir = opendir($path);
1892       /* Is this a correct result ?*/
1893       if($dir){
1894         while($fp = readdir($dir))
1895           $ret[]= $fp;
1896       }
1897     }
1898   }
1899   /* Sort array ascending , like scandir */
1900   sort($ret);
1902   /* Sort descending if parameter is sort_desc is set */
1903   if($sort_desc) {
1904     $ret = array_reverse($ret);
1905   }
1907   return($ret);
1910 function clean_smarty_compile_dir($directory)
1912   global $svn_revision;
1914   if(is_dir($directory) && is_readable($directory)) {
1915     // Set revision filename to REVISION
1916     $revision_file= $directory."/REVISION";
1918     /* Is there a stamp containing the current revision? */
1919     if(!file_exists($revision_file)) {
1920       // create revision file
1921       create_revision($revision_file, $svn_revision);
1922     } else {
1923 # check for "$config->...['CONFIG']/revision" and the
1924 # contents should match the revision number
1925       if(!compare_revision($revision_file, $svn_revision)){
1926         // If revision differs, clean compile directory
1927         foreach(scan_directory($directory) as $file) {
1928           if(($file==".")||($file=="..")) continue;
1929           if( is_file($directory."/".$file) &&
1930               is_writable($directory."/".$file)) {
1931             // delete file
1932             if(!unlink($directory."/".$file)) {
1933               print_red("File ".$directory."/".$file." could not be deleted.");
1934               // This should never be reached
1935             }
1936           } elseif(is_dir($directory."/".$file) &&
1937               is_writable($directory."/".$file)) {
1938             // Just recursively delete it
1939             rmdirRecursive($directory."/".$file);
1940           }
1941         }
1942         // We should now create a fresh revision file
1943         clean_smarty_compile_dir($directory);
1944       } else {
1945         // Revision matches, nothing to do
1946       }
1947     }
1948   } else {
1949     // Smarty compile dir is not accessible
1950     // (Smarty will warn about this)
1951   }
1954 function create_revision($revision_file, $revision)
1956   $result= false;
1958   if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1959     if($fh= fopen($revision_file, "w")) {
1960       if(fwrite($fh, $revision)) {
1961         $result= true;
1962       }
1963     }
1964     fclose($fh);
1965   } else {
1966     print_red("Can not write to revision file");
1967   }
1969   return $result;
1972 function compare_revision($revision_file, $revision)
1974   // false means revision differs
1975   $result= false;
1977   if(file_exists($revision_file) && is_readable($revision_file)) {
1978     // Open file
1979     if($fh= fopen($revision_file, "r")) {
1980       // Compare File contents with current revision
1981       if($revision == fread($fh, filesize($revision_file))) {
1982         $result= true;
1983       }
1984     } else {
1985       print_red("Can not open revision file");
1986     }
1987     // Close file
1988     fclose($fh);
1989   }
1991   return $result;
1994 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1996   $str = ""; // Our return value will be saved in this var
1998   $color  = dechex($percentage+150);
1999   $color2 = dechex(150 - $percentage);
2000   $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2002   $progress = (int)(($percentage /100)*$width);
2004   /* Abort printing out percentage, if divs are to small */
2007   /* If theres a better solution for this, use it... */
2008   $str = "
2009     <div style=\" width:".($width)."px; 
2010     height:".($height)."px;
2011   background-color:#000000;
2012 padding:1px;\">
2014           <div style=\" width:".($width)."px;
2015         background-color:#$bgcolor;
2016 height:".($height)."px;\">
2018          <div style=\" width:".$progress."px;
2019 height:".$height."px;
2020        background-color:#".$color2.$color2.$color."; \">";
2023        if(($height >10)&&($showvalue)){
2024          $str.=                 "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2025            <b>".$percentage."%</b>
2026            </font>";
2027        }
2029        $str.= "</div></div></div>";
2031        return($str);
2035 function array_key_ics($ikey, $items)
2037   /* Gather keys, make them lowercase */
2038   $tmp= array();
2039   foreach ($items as $key => $value){
2040     $tmp[strtolower($key)]= $key;
2041   }
2043   if (isset($tmp[strtolower($ikey)])){
2044     return($tmp[strtolower($ikey)]);
2045   }
2047   return ("");
2051 function search_config($arr, $name, $return)
2053   if (is_array($arr)){
2054     foreach ($arr as $a){
2055       if (isset($a['CLASS']) &&
2056           strtolower($a['CLASS']) == strtolower($name)){
2058         if (isset($a[$return])){
2059           return ($a[$return]);
2060         } else {
2061           return ("");
2062         }
2063       } else {
2064         $res= search_config ($a, $name, $return);
2065         if ($res != ""){
2066           return $res;
2067         }
2068       }
2069     }
2070   }
2071   return ("");
2075 function array_differs($src, $dst)
2077   /* If the count is differing, the arrays differ */
2078   if (count ($src) != count ($dst)){
2079     return (TRUE);
2080   }
2082   /* So the count is the same - lets check the contents */
2083   $differs= FALSE;
2084   foreach($src as $value){
2085     if (!in_array($value, $dst)){
2086       $differs= TRUE;
2087     }
2088   }
2090   return ($differs);
2094 function saveFilter($a_filter, $values)
2096   if (isset($_POST['regexit'])){
2097     $a_filter["regex"]= $_POST['regexit'];
2099     foreach($values as $type){
2100       if (isset($_POST[$type])) {
2101         $a_filter[$type]= "checked";
2102       } else {
2103         $a_filter[$type]= "";
2104       }
2105     }
2106   }
2108   /* React on alphabet links if needed */
2109   if (isset($_GET['search'])){
2110     $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2111     if ($s == "**"){
2112       $s= "*";
2113     }
2114     $a_filter['regex']= $s;
2115   }
2117   return ($a_filter);
2121 /* Escape all preg_* relevant characters */
2122 function normalizePreg($input)
2124   return (addcslashes($input, '[]()|/.*+-'));
2128 /* Escape all LDAP filter relevant characters */
2129 function normalizeLdap($input)
2131   return (addcslashes($input, '()|'));
2135 /* Resturns the difference between to microtime() results in float  */
2136 function get_MicroTimeDiff($start , $stop)
2138   $a = split("\ ",$start);
2139   $b = split("\ ",$stop);
2141   $secs = $b[1] - $a[1];
2142   $msecs= $b[0] - $a[0]; 
2144   $ret = (float) ($secs+ $msecs);
2145   return($ret);
2149 /* Check if the given department name is valid */
2150 function is_department_name_reserved($name,$base)
2152   $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2153                           preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2154                           preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2155   $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2157   /* Check if name is one of the reserved names */
2158   if(in_array_ics($name,$reservedName)) {
2159     return(true);
2160   }
2162   /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2163   foreach($follwedNames as $key => $names){
2164     if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2165       return(true);
2166     }
2167   }
2168   return(false);
2172 function is_php4()
2174   if (isset($_SESSION['PHP4COMPATIBLE'])){
2175     return true;
2176   }
2177   return (preg_match('/^4/', phpversion()));
2181 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2183   /* Initialize variables */
2184   $ret  = array("count" => 0);  // Set count to 0
2185   $next = true;                 // if false, then skip next loops and return
2186   $cnt  = 0;                    // Current number of loops
2187   $max  = 100;                  // Just for security, prevent looops
2188   $ldap = NULL;                 // To check if created result a valid
2189   $keep = "";                   // save last failed parse string
2191   /* Check each parsed dn in ldap ? */
2192   if($config!=NULL && $verify_in_ldap){
2193     $ldap = $config->get_ldap_link();
2194   }
2196   /* Lets start */
2197   $called = false;
2198   while(preg_match("/,/",$dn) && $next &&  $cnt < $max){
2200     $cnt ++;
2201     if(!preg_match("/,/",$dn)){
2202       $next = false;
2203     }
2204     $object = preg_replace("/[,].*$/","",$dn);
2205     $dn     = preg_replace("/^[^,]+,/","",$dn);
2207     $called = true;
2209     /* Check if current dn is valid */
2210     if($ldap!=NULL){
2211       $ldap->cd($dn);
2212       $ldap->cat($dn,array("dn"));
2213       if($ldap->count()){
2214         $ret[]  = $keep.$object;
2215         $keep   = "";
2216       }else{
2217         $keep  .= $object.",";
2218       }
2219     }else{
2220       $ret[]  = $keep.$object;
2221       $keep   = "";
2222     }
2223   }
2225   /* No dn was posted */
2226   if($cnt == 0 && !empty($dn)){
2227     $ret[] = $dn;
2228   }
2230   /* Append the rest */
2231   $test = $keep.$dn;
2232   if($called && !empty($test)){
2233     $ret[] = $keep.$dn;
2234   }
2235   $ret['count'] = count($ret) - 1;
2237   return($ret);
2241 function get_base_from_hook($dn, $attrib)
2243   global $config;
2245   if (isset($config->current['BASE_HOOK'])){
2246     
2247     /* Call hook script - if present */
2248     $command= $config->current['BASE_HOOK'];
2250     if ($command != ""){
2251       $command.= " '$dn' $attrib";
2252       if (check_command($command)){
2253         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2254         exec($command, $output);
2255         if (preg_match("/^[0-9]+$/", $output[0])){
2256           return ($output[0]);
2257         } else {
2258           print_red(_("Warning - base_hook is not available. Using default base."));
2259           return ($config->current['UIDBASE']);
2260         }
2261       } else {
2262         print_red(_("Warning - base_hook is not available. Using default base."));
2263         return ($config->current['UIDBASE']);
2264       }
2266     } else {
2268       print_red(_("Warning - no base_hook defined. Using default base."));
2269       return ($config->current['UIDBASE']);
2271     }
2272   }
2275 /* Schema validation functions */
2277   function check_schema_version($class, $version)
2278   {
2279     return preg_match("/\(v$version\)/", $class['DESC']);
2280   }
2282   
2284   function check_schema($cfg,$rfc2307bis = FALSE)
2285   {
2287     $messages= array();
2289     /* Get objectclasses */
2290     $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2291     $objectclasses = $ldap->get_objectclasses();
2292     if(count($objectclasses) == 0){
2293       print_red(_("Can't get schema information from server. No schema check possible!"));
2294     }
2296     /* This is the default block used for each entry.
2297      *  to avoid unset indexes.
2298      */
2299     $def_check = array("REQUIRED_VERSION" => "0",
2300                        "SCHEMA_FILES"     => array(),
2301                        "CLASSES_REQUIRED" => array(),
2302                        "STATUS"           => FALSE,
2303                        "IS_MUST_HAVE"     => FALSE,
2304                        "MSG"              => "",
2305                        "INFO"             => "");#_("There is currently no information specified for this schema extension."));
2307  /* The gosa base schema */
2308     $checks['gosaObject'] = $def_check;
2309     $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2310     $checks['gosaObject']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2311     $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2312     $checks['gosaObject']['IS_MUST_HAVE']     = TRUE;
2314     /* GOsa Account class */
2315     $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2316     $checks["gosaAccount"]["SCHEMA_FILES"]    = array("gosa+samba3.schema","gosa.schema");
2317     $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2318     $checks["gosaAccount"]["IS_MUST_HAVE"]    = TRUE;
2319     $checks["gosaAccount"]["INFO"]            = _("Used to store account specific informations.");
2321     /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2322     $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2323     $checks["gosaLockEntry"]["SCHEMA_FILES"]     = array("gosa+samba3.schema","gosa.schema");
2324     $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2325     $checks["gosaLockEntry"]["IS_MUST_HAVE"]     = TRUE;
2326     $checks["gosaLockEntry"]["INFO"]             = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2328   /* Some other checks */
2329     foreach(array(
2330           "gosaCacheEntry"        => array("version" => "2.4"),
2331           "gosaDepartment"        => array("version" => "2.4"),
2332           "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2333           "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2334           "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2335           "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2336           "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2337           "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2338           "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2339           "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2340           "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2341           "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2342           "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2343           "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2344           "goShareServer"         => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2345           "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2346           "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2347           "goLdapServer"          => array("version" => "2.4"),
2348           "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2349           "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.        schema"),
2350           "goKrbServer"           => array("version" => "2.4"),
2351           "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2352           ) as $name => $values){
2354       $checks[$name] = $def_check;
2355       if(isset($values['version'])){
2356         $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2357       }
2358       if(isset($values['file'])){
2359         $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2360       }
2361       $checks[$name]["CLASSES_REQUIRED"] = array($name);
2362     }
2363    foreach($checks as $name => $value){
2364       foreach($value['CLASSES_REQUIRED'] as $class){
2366         if(!isset($objectclasses[$name])){
2367           $checks[$name]['STATUS'] = FALSE;
2368           if($value['IS_MUST_HAVE']){
2369             $checks[$name]['MSG']    = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2370           }else{
2371             $checks[$name]['MSG']    = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2372           }
2373         }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2374           $checks[$name]['STATUS'] = FALSE;
2376           if($value['IS_MUST_HAVE']){
2377             $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2378           }else{
2379             $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2380           }
2381         }else{
2382           $checks[$name]['STATUS'] = TRUE;
2383           $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2384         }
2385       }
2386     }
2388     $tmp = $objectclasses;
2391     /* The gosa base schema */
2392     $checks['posixGroup'] = $def_check;
2393     $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2394     $checks['posixGroup']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2395     $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2396     $checks['posixGroup']['STATUS']           = TRUE;
2397     $checks['posixGroup']['IS_MUST_HAVE']     = TRUE;
2398     $checks['posixGroup']['MSG']              = "";
2399     $checks['posixGroup']['INFO']             = "";
2401     /* Depending on selected rfc2307bis mode, we need different schema configurations */
2402     if(isset($tmp['posixGroup'])){
2404       if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2405         $checks['posixGroup']['STATUS']           = FALSE;
2406         $checks['posixGroup']['MSG']              = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema    configuration do not support this option.");
2407         $checks['posixGroup']['INFO']             = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be      AUXILIARY");
2408       }
2409       if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2410         $checks['posixGroup']['STATUS']           = FALSE;
2411         $checks['posixGroup']['MSG']              = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema   configuration do not support this option.");
2412         $checks['posixGroup']['INFO']             = _("The objectClass 'posixGroup' must be STRUCTURAL");
2413       }
2414     }
2416     return($checks);
2417   }
2422 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
2423 ?>