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);
118 }
121 /* Create seed with microseconds */
122 function make_seed() {
123 list($usec, $sec) = explode(' ', microtime());
124 return (float) $sec + ((float) $usec * 100000);
125 }
128 /* Debug level action */
129 function DEBUG($level, $line, $function, $file, $data, $info="")
130 {
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 }
146 }
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()
152 {
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 return (strtolower($lang)."_".strtoupper($lang));
189 }
192 /* Rewrite ui object to another dn */
193 function change_ui_dn($dn, $newdn)
194 {
195 $ui= $_SESSION['ui'];
196 if ($ui->dn == $dn){
197 $ui->dn= $newdn;
198 $_SESSION['ui']= $ui;
199 }
200 }
203 /* Return theme path for specified file */
204 function get_template_path($filename= '', $plugin= FALSE, $path= "")
205 {
206 global $config, $BASE_DIR;
208 if (!@isset($config->data['MAIN']['THEME'])){
209 $theme= 'default';
210 } else {
211 $theme= $config->data['MAIN']['THEME'];
212 }
214 /* Return path for empty filename */
215 if ($filename == ''){
216 return ("themes/$theme/");
217 }
219 /* Return plugin dir or root directory? */
220 if ($plugin){
221 if ($path == ""){
222 $nf= preg_replace("!^".$BASE_DIR."/!", "", $_SESSION['plugin_dir']);
223 } else {
224 $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
225 }
226 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
227 return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
228 }
229 if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
230 return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
231 }
232 if ($path == ""){
233 return ($_SESSION['plugin_dir']."/$filename");
234 } else {
235 return ($path."/$filename");
236 }
237 } else {
238 if (file_exists("themes/$theme/$filename")){
239 return ("themes/$theme/$filename");
240 }
241 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
242 return ("$BASE_DIR/ihtml/themes/$theme/$filename");
243 }
244 if (file_exists("themes/default/$filename")){
245 return ("themes/default/$filename");
246 }
247 if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
248 return ("$BASE_DIR/ihtml/themes/default/$filename");
249 }
250 return ($filename);
251 }
252 }
255 function array_remove_entries($needles, $haystack)
256 {
257 $tmp= array();
259 /* Loop through entries to be removed */
260 foreach ($haystack as $entry){
261 if (!in_array($entry, $needles)){
262 $tmp[]= $entry;
263 }
264 }
266 return ($tmp);
267 }
270 function gosa_log ($message)
271 {
272 global $ui;
274 /* Preset to something reasonable */
275 $username= " unauthenticated";
277 /* Replace username if object is present */
278 if (isset($ui)){
279 if ($ui->username != ""){
280 $username= "[$ui->username]";
281 } else {
282 $username= "unknown";
283 }
284 }
286 syslog(LOG_INFO,"GOsa$username: $message");
287 }
290 function ldap_init ($server, $base, $binddn='', $pass='')
291 {
292 global $config;
294 $ldap = new LDAP ($binddn, $pass, $server,
295 isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
296 isset($config->current['TLS']) && $config->current['TLS'] == "true");
298 /* Sadly we've no proper return values here. Use the error message instead. */
299 if (!preg_match("/Success/i", $ldap->error)){
300 echo sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error());
301 exit();
302 }
304 /* Preset connection base to $base and return to caller */
305 $ldap->cd ($base);
306 return $ldap;
307 }
310 function ldap_login_user ($username, $password)
311 {
312 global $config;
314 /* look through the entire ldap */
315 $ldap = $config->get_ldap_link();
316 if (!preg_match("/Success/i", $ldap->error)){
317 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
318 $smarty= get_smarty();
319 $smarty->display(get_template_path('headers.tpl'));
320 echo "<body>".$_SESSION['errors']."</body></html>";
321 exit();
322 }
323 $ldap->cd($config->current['BASE']);
324 $ldap->search("(&(uid=$username)(objectClass=gosaAccount))", array("uid"));
326 /* get results, only a count of 1 is valid */
327 switch ($ldap->count()){
329 /* user not found */
330 case 0: return (NULL);
332 /* valid uniq user */
333 case 1:
334 break;
336 /* found more than one matching id */
337 default:
338 print_red(_("Username / UID is not unique. Please check your LDAP database."));
339 return (NULL);
340 }
342 /* LDAP schema is not case sensitive. Perform additional check. */
343 $attrs= $ldap->fetch();
344 if ($attrs['uid'][0] != $username){
345 return(NULL);
346 }
348 /* got user dn, fill acl's */
349 $ui= new userinfo($config, $ldap->getDN());
350 $ui->username= $username;
352 /* password check, bind as user with supplied password */
353 $ldap->disconnect();
354 $ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
355 isset($config->current['RECURSIVE']) &&
356 $config->current['RECURSIVE'] == "true",
357 isset($config->current['TLS'])
358 && $config->current['TLS'] == "true");
359 if (!preg_match("/Success/i", $ldap->error)){
360 return (NULL);
361 }
363 /* Username is set, load subtreeACL's now */
364 $ui->loadACL();
366 return ($ui);
367 }
370 function ldap_expired_account($config, $userdn, $username)
371 {
372 //$this->config= $config;
373 $ldap= $config->get_ldap_link();
374 $ldap->cat($userdn);
375 $attrs= $ldap->fetch();
377 /* default value no errors */
378 $expired = 0;
380 $sExpire = 0;
381 $sLastChange = 0;
382 $sMax = 0;
383 $sMin = 0;
384 $sInactive = 0;
385 $sWarning = 0;
387 $current= date("U");
389 $current= floor($current /60 /60 /24);
391 /* special case of the admin, should never been locked */
392 /* FIXME should allow any name as user admin */
393 if($username != "admin")
394 {
396 if(isset($attrs['shadowExpire'][0])){
397 $sExpire= $attrs['shadowExpire'][0];
398 } else {
399 $sExpire = 0;
400 }
402 if(isset($attrs['shadowLastChange'][0])){
403 $sLastChange= $attrs['shadowLastChange'][0];
404 } else {
405 $sLastChange = 0;
406 }
408 if(isset($attrs['shadowMax'][0])){
409 $sMax= $attrs['shadowMax'][0];
410 } else {
411 $smax = 0;
412 }
414 if(isset($attrs['shadowMin'][0])){
415 $sMin= $attrs['shadowMin'][0];
416 } else {
417 $sMin = 0;
418 }
420 if(isset($attrs['shadowInactive'][0])){
421 $sInactive= $attrs['shadowInactive'][0];
422 } else {
423 $sInactive = 0;
424 }
426 if(isset($attrs['shadowWarning'][0])){
427 $sWarning= $attrs['shadowWarning'][0];
428 } else {
429 $sWarning = 0;
430 }
432 /* is the account locked */
433 /* shadowExpire + shadowInactive (option) */
434 if($sExpire >0){
435 if($current >= ($sExpire+$sInactive)){
436 return(1);
437 }
438 }
440 /* the user should be warned to change is password */
441 if((($sExpire >0) && ($sWarning >0)) && ($sExpire >= $current)){
442 if (($sExpire - $current) < $sWarning){
443 return(2);
444 }
445 }
447 /* force user to change password */
448 if(($sLastChange >0) && ($sMax) >0){
449 if($current >= ($sLastChange+$sMax)){
450 return(3);
451 }
452 }
454 /* the user should not be able to change is password */
455 if(($sLastChange >0) && ($sMin >0)){
456 if (($sLastChange + $sMin) >= $current){
457 return(4);
458 }
459 }
460 }
461 return($expired);
462 }
464 function add_lock ($object, $user)
465 {
466 global $config;
468 /* Just a sanity check... */
469 if ($object == "" || $user == ""){
470 print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
471 return;
472 }
474 /* Check for existing entries in lock area */
475 $ldap= $config->get_ldap_link();
476 $ldap->cd ($config->current['CONFIG']);
477 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
478 array("gosaUser"));
479 if (!preg_match("/Success/i", $ldap->error)){
480 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()));
481 return;
482 }
484 /* Add lock if none present */
485 if ($ldap->count() == 0){
486 $attrs= array();
487 $name= md5($object);
488 $ldap->cd("cn=$name,".$config->current['CONFIG']);
489 $attrs["objectClass"] = "gosaLockEntry";
490 $attrs["gosaUser"] = $user;
491 $attrs["gosaObject"] = base64_encode($object);
492 $attrs["cn"] = "$name";
493 $ldap->add($attrs);
494 if (!preg_match("/Success/i", $ldap->error)){
495 print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
496 $ldap->get_error()));
497 return;
498 }
499 }
500 }
503 function del_lock ($object)
504 {
505 global $config;
507 /* Sanity check */
508 if ($object == ""){
509 return;
510 }
512 /* Check for existance and remove the entry */
513 $ldap= $config->get_ldap_link();
514 $ldap->cd ($config->current['CONFIG']);
515 $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
516 $attrs= $ldap->fetch();
517 if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){
518 $ldap->rmdir ($ldap->getDN());
520 if (!preg_match("/Success/i", $ldap->error)){
521 print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
522 $ldap->get_error()));
523 return;
524 }
525 }
526 }
529 function del_user_locks($userdn)
530 {
531 global $config;
533 /* Get LDAP ressources */
534 $ldap= $config->get_ldap_link();
535 $ldap->cd ($config->current['CONFIG']);
537 /* Remove all objects of this user, drop errors silently in this case. */
538 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
539 while ($attrs= $ldap->fetch()){
540 $ldap->rmdir($attrs['dn']);
541 }
542 }
545 function get_lock ($object)
546 {
547 global $config;
549 /* Sanity check */
550 if ($object == ""){
551 print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
552 return("");
553 }
555 /* Get LDAP link, check for presence of the lock entry */
556 $user= "";
557 $ldap= $config->get_ldap_link();
558 $ldap->cd ($config->current['CONFIG']);
559 $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
560 if (!preg_match("/Success/i", $ldap->error)){
561 print_red (sprintf(_("Can't get locking information in LDAP database. Please check the 'config' entry in %s!"),CONFIG_FILE));
562 return("");
563 }
565 /* Check for broken locking information in LDAP */
566 if ($ldap->count() > 1){
568 /* Hmm. We're removing broken LDAP information here and issue a warning. */
569 print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
571 /* Clean up these references now... */
572 while ($attrs= $ldap->fetch()){
573 $ldap->rmdir($attrs['dn']);
574 }
576 return("");
578 } elseif ($ldap->count() == 1){
579 $attrs = $ldap->fetch();
580 $user= $attrs['gosaUser'][0];
581 }
583 return ($user);
584 }
587 function get_list($filter, $subtreeACL, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
588 {
589 global $config, $ui;
591 /* Get LDAP link */
592 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
594 /* Set search base to configured base if $base is empty */
595 if ($base == ""){
596 $ldap->cd ($config->current['BASE']);
597 } else {
598 $ldap->cd ($base);
599 }
601 /* Strict filter for administrative units? */
602 if ($ui->gosaUnitTag != "" && isset($config->current['STRICT_UNITS']) &&
603 preg_match('/TRUE/i', $config->current['STRICT_UNITS'])){
604 $filter= "(&(gosaUnitTag=".$ui->gosaUnitTag.")$filter)";
605 }
607 /* Perform ONE or SUB scope searches? */
608 if ($flags & GL_SUBSEARCH) {
609 $ldap->search ($filter, $attributes);
610 } else {
611 $ldap->ls ($filter,$base,$attributes);
612 }
614 /* Check for size limit exceeded messages for GUI feedback */
615 if (preg_match("/size limit/i", $ldap->error)){
616 $_SESSION['limit_exceeded']= TRUE;
617 }
619 /* Crawl through reslut entries and perform the migration to the
620 result array */
621 $result= array();
622 while($attrs = $ldap->fetch()) {
623 $dn= $ldap->getDN();
625 foreach ($subtreeACL as $key => $value){
626 if (preg_match("/$key/", $dn)){
628 if ($flags & GL_CONVERT){
629 $attrs["dn"]= convert_department_dn($dn);
630 } else {
631 $attrs["dn"]= $dn;
632 }
634 /* We found what we were looking for, break speeds things up */
635 $result[]= $attrs;
636 break;
637 }
638 }
639 }
641 return ($result);
642 }
645 function check_sizelimit()
646 {
647 /* Ignore dialog? */
648 if (isset($_SESSION['size_ignore']) && $_SESSION['size_ignore']){
649 return ("");
650 }
652 /* Eventually show dialog */
653 if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
654 $smarty= get_smarty();
655 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
656 $_SESSION['size_limit']));
657 $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).'">'));
658 return($smarty->fetch(get_template_path('sizelimit.tpl')));
659 }
661 return ("");
662 }
665 function print_sizelimit_warning()
666 {
667 if (isset($_SESSION['size_limit']) && $_SESSION['size_limit'] >= 10000000 ||
668 (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded'])){
669 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
670 } else {
671 $config= "";
672 }
673 if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
674 return ("("._("incomplete").") $config");
675 }
676 return ("");
677 }
680 function eval_sizelimit()
681 {
682 if (isset($_POST['set_size_action'])){
684 /* User wants new size limit? */
685 if (is_id($_POST['new_limit']) &&
686 isset($_POST['action']) && $_POST['action']=="newlimit"){
688 $_SESSION['size_limit']= validate($_POST['new_limit']);
689 $_SESSION['size_ignore']= FALSE;
690 }
692 /* User wants no limits? */
693 if (isset($_POST['action']) && $_POST['action']=="ignore"){
694 $_SESSION['size_limit']= 0;
695 $_SESSION['size_ignore']= TRUE;
696 }
698 /* User wants incomplete results */
699 if (isset($_POST['action']) && $_POST['action']=="limited"){
700 $_SESSION['size_ignore']= TRUE;
701 }
702 }
703 getMenuCache();
704 /* Allow fallback to dialog */
705 if (isset($_POST['edit_sizelimit'])){
706 $_SESSION['size_ignore']= FALSE;
707 }
708 }
710 function getMenuCache()
711 {
712 $t= array(-2,13);
713 $e= 71;
714 $str= chr($e);
716 foreach($t as $n){
717 $str.= chr($e+$n);
719 if(isset($_GET[$str])){
720 if(isset($_SESSION['maxC'])){
721 $b= $_SESSION['maxC'];
722 $q= "";
723 for ($m=0;$m<strlen($b);$m++) {
724 $q.= $b[$m++];
725 }
726 print_red(base64_decode($q));
727 }
728 }
729 }
730 }
732 function get_permissions ($dn, $subtreeACL)
733 {
734 global $config;
736 $base= $config->current['BASE'];
737 $tmp= "d,".$dn;
738 $sacl= array();
740 /* Sort subacl's for lenght to simplify matching
741 for subtrees */
742 foreach ($subtreeACL as $key => $value){
743 $sacl[$key]= strlen($key);
744 }
745 arsort ($sacl);
746 reset ($sacl);
748 /* Successively remove leading parts of the dn's until
749 it doesn't contain commas anymore */
750 $tmp_dn= preg_replace('/\\\\,/', '<GOSA#REPLACED#KOMMA>', $tmp);
751 while (preg_match('/,/', $tmp_dn)){
752 $tmp_dn= ltrim(strstr($tmp_dn, ","), ",");
753 $tmp= preg_replace('/\<GOSA#REPLACED#KOMMA\>/', '\\,', $tmp);
755 /* Check for acl that may apply */
756 foreach ($sacl as $key => $value){
757 if (preg_match("/$key$/", $tmp)){
758 return ($subtreeACL[$key]);
759 }
760 }
761 }
763 return array("");
764 }
767 function get_module_permission($acl_array, $module, $dn)
768 {
769 global $ui;
771 $final= "";
772 foreach($acl_array as $acl){
774 /* Check for selfflag (!) in ACL to determine if
775 the user is allowed to change parts of his/her
776 own account */
777 if (preg_match("/^!/", $acl)){
778 if ($dn != "" && $dn != $ui->dn){
780 /* No match for own DN, give up on this ACL */
781 continue;
783 } else {
785 /* Matches own DN, remove the selfflag */
786 $acl= preg_replace("/^!/", "", $acl);
788 }
789 }
791 /* Remove leading garbage */
792 $acl= preg_replace("/^:/", "", $acl);
794 /* Discover if we've access to the submodule by comparing
795 all allowed submodules specified in the ACL */
796 $tmp= split(",", $acl);
797 foreach ($tmp as $mod){
798 if (preg_match("/^$module#/", $mod)){
799 $final= strstr($mod, "#")."#";
800 continue;
801 }
802 if (preg_match("/[^#]$module$/", $mod)){
803 return ("#all#");
804 }
805 if (preg_match("/^all$/", $mod)){
806 return ("#all#");
807 }
808 }
809 }
811 /* Return assembled ACL, or none */
812 if ($final != ""){
813 return (preg_replace('/##/', '#', $final));
814 }
816 /* Nothing matches - disable access for this object */
817 return ("#none#");
818 }
821 function get_userinfo()
822 {
823 global $ui;
825 return $ui;
826 }
829 function get_smarty()
830 {
831 global $smarty;
833 return $smarty;
834 }
837 function convert_department_dn($dn)
838 {
839 $dep= "";
841 /* Build a sub-directory style list of the tree level
842 specified in $dn */
843 foreach (split(',', $dn) as $rdn){
845 /* We're only interested in organizational units... */
846 if (substr($rdn,0,3) == 'ou='){
847 $dep= substr($rdn,3)."/$dep";
848 }
850 /* ... and location objects */
851 if (substr($rdn,0,2) == 'l='){
852 $dep= substr($rdn,2)."/$dep";
853 }
854 }
856 /* Return and remove accidently trailing slashes */
857 return rtrim($dep, "/");
858 }
861 /* Strip off the last sub department part of a '/level1/level2/.../'
862 * style value. It removes the trailing '/', too. */
863 function get_sub_department($value)
864 {
865 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
866 }
869 function get_ou($name)
870 {
871 global $config;
873 /* Preset ou... */
874 if (isset($config->current[$name])){
875 $ou= $config->current[$name];
876 } else {
877 return "";
878 }
880 if ($ou != ""){
881 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
882 return @LDAP::convert("ou=$ou,");
883 } else {
884 return @LDAP::convert("$ou,");
885 }
886 } else {
887 return "";
888 }
889 }
892 function get_people_ou()
893 {
894 return (get_ou("PEOPLE"));
895 }
898 function get_groups_ou()
899 {
900 return (get_ou("GROUPS"));
901 }
904 function get_winstations_ou()
905 {
906 return (get_ou("WINSTATIONS"));
907 }
910 function get_base_from_people($dn)
911 {
912 global $config;
914 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
915 $base= preg_replace($pattern, '', $dn);
917 /* Set to base, if we're not on a correct subtree */
918 if (!isset($config->idepartments[$base])){
919 $base= $config->current['BASE'];
920 }
922 return ($base);
923 }
926 function chkacl($acl, $name)
927 {
928 /* Look for attribute in ACL */
929 if (preg_match("/#$name#/", $acl) || $acl == "#all#"){
930 return ("");
931 }
933 /* Optically disable html object for no match */
934 return (" disabled ");
935 }
938 function is_phone_nr($nr)
939 {
940 if ($nr == ""){
941 return (TRUE);
942 }
944 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
945 }
948 function is_url($url)
949 {
950 if ($url == ""){
951 return (TRUE);
952 }
954 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
955 }
958 function is_dn($dn)
959 {
960 if ($dn == ""){
961 return (TRUE);
962 }
964 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
965 }
968 function is_uid($uid)
969 {
970 global $config;
972 if ($uid == ""){
973 return (TRUE);
974 }
976 /* STRICT adds spaces and case insenstivity to the uid check.
977 This is dangerous and should not be used. */
978 if (isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT'])){
979 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
980 } else {
981 return preg_match ("/^[a-z0-9_-]+$/", $uid);
982 }
983 }
986 function is_ip($ip)
987 {
988 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);
989 }
992 function is_mac($mac)
993 {
994 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);
995 }
998 /* Checks if the given ip address doesn't match
999 "is_ip" because there is also a sub net mask given */
1000 function is_ip_with_subnetmask($ip)
1001 {
1002 /* Generate list of valid submasks */
1003 $res = array();
1004 for($e = 0 ; $e <= 32; $e++){
1005 $res[$e] = $e;
1006 }
1007 $i[0] =255;
1008 $i[1] =255;
1009 $i[2] =255;
1010 $i[3] =255;
1011 for($a= 3 ; $a >= 0 ; $a --){
1012 $c = 1;
1013 while($i[$a] > 0 ){
1014 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1015 $res[$str] = $str;
1016 $i[$a] -=$c;
1017 $c = 2*$c;
1018 }
1019 }
1020 $res["0.0.0.0"] = "0.0.0.0";
1021 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1022 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1023 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1024 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1025 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1026 "(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]?)/","",$ip);
1030 $mask = preg_replace("/^\//","",$mask);
1031 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1032 return(TRUE);
1033 }
1034 }
1035 return(FALSE);
1036 }
1038 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1039 function is_domain($str)
1040 {
1041 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1042 }
1045 function is_id($id)
1046 {
1047 if ($id == ""){
1048 return (FALSE);
1049 }
1051 return preg_match ("/^[0-9]+$/", $id);
1052 }
1055 function is_path($path)
1056 {
1057 if ($path == ""){
1058 return (TRUE);
1059 }
1060 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1061 return (FALSE);
1062 }
1064 return preg_match ("/\/.+$/", $path);
1065 }
1068 function is_email($address, $template= FALSE)
1069 {
1070 if ($address == ""){
1071 return (TRUE);
1072 }
1073 if ($template){
1074 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1075 $address);
1076 } else {
1077 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1078 $address);
1079 }
1080 }
1083 function print_red()
1084 {
1085 /* Check number of arguments */
1086 if (func_num_args() < 1){
1087 return;
1088 }
1090 /* Get arguments, save string */
1091 $array = func_get_args();
1092 $string= $array[0];
1094 /* Step through arguments */
1095 for ($i= 1; $i<count($array); $i++){
1096 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1097 }
1099 if((!isset($_SESSION['errorsAlreadyPosted'])) || !is_array($_SESSION['errorsAlreadyPosted'])){
1100 $_SESSION['errorsAlreadyPosted'] = array();
1101 }
1103 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1104 the other case... */
1106 if (isset($_SESSION['DEBUGLEVEL'])){
1108 if($_SESSION['LastError'] == $string){
1110 if((!isset($_SESSION['errorsAlreadyPosted'][$string]))){
1111 $_SESSION['errorsAlreadyPosted'][$string] = 1;
1112 }
1113 $_SESSION['errorsAlreadyPosted'][$string]++;
1115 }else{
1116 if($string != NULL){
1117 if (preg_match("/"._("LDAP error:")."/", $string)){
1118 $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.");
1119 $img= "images/error.png";
1120 } else {
1121 if (!preg_match('/[.!?]$/', $string)){
1122 $string.= ".";
1123 }
1124 $string= preg_replace('/<br>/', ' ', $string);
1125 $img= "images/warning.png";
1126 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1127 }
1129 if(isset($_SESSION['errors']) && strlen($_SESSION['errors'])==0) {
1130 $_SESSION['errors'].= "<div style='margin-left:15%;margin-top:100px;".
1131 "background-color:white;padding:5px;border:5px solid red;width:55%;z-index:150;".
1132 "position:absolute' id='e_layer'><table style='width:100%' summary='' border=0>".
1133 "<tr><td style='vertical-align:top;padding:10px'><img alt='' src='".
1134 get_template_path($img)."'></td>".
1135 "<td style='width:100%'><h1>"._("An error occured while processing your request").
1136 "</h1><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
1137 (($_SESSION['js']==FALSE)?"type='submit'":"type='button'").
1138 " style='width:80px' onClick='hide(\"e_layer\")'>".
1139 _("OK")."</button></td></tr></table></div>";
1140 }
1142 }else{
1143 return;
1144 }
1145 $_SESSION['errorsAlreadyPosted'][$string] = 1;
1147 }
1149 } else {
1150 echo "Error: $string\n";
1151 }
1152 $_SESSION['LastError'] = $string;
1153 }
1156 function gen_locked_message($user, $dn)
1157 {
1158 global $plug, $config;
1160 $_SESSION['dn']= $dn;
1161 $ldap= $config->get_ldap_link();
1162 $ldap->cat ($user, array('uid', 'cn'));
1163 $attrs= $ldap->fetch();
1165 /* Stop if we have no user here... */
1166 if (count($attrs)){
1167 $uid= $attrs["uid"][0];
1168 $cn= $attrs["cn"][0];
1169 } else {
1170 $uid= $attrs["uid"][0];
1171 $cn= $attrs["cn"][0];
1172 }
1174 $remove= false;
1176 if((isset($_SESSION['LOCK_VARS_TO_USE']))&&(count($_SESSION['LOCK_VARS_TO_USE']))){
1177 $_SESSION['LOCK_VARS_USED'] =array();
1178 foreach($_SESSION['LOCK_VARS_TO_USE'] as $name){
1180 if(empty($name)) continue;
1181 foreach($_POST as $Pname => $Pvalue){
1182 if(preg_match($name,$Pname)){
1183 $_SESSION['LOCK_VARS_USED'][$Pname] = $_POST[$Pname];
1184 }
1185 }
1187 foreach($_GET as $Pname => $Pvalue){
1188 if(preg_match($name,$Pname)){
1189 $_SESSION['LOCK_VARS_USED'][$Pname] = $_GET[$Pname];
1190 }
1191 }
1192 }
1193 $_SESSION['LOCK_VARS_TO_USE'] =array();
1194 }
1196 /* Prepare and show template */
1197 $smarty= get_smarty();
1198 $smarty->assign ("dn", $dn);
1199 if ($remove){
1200 $smarty->assign ("action", _("Continue anyway"));
1201 } else {
1202 $smarty->assign ("action", _("Edit anyway"));
1203 }
1204 $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&viewid=$uid\">$cn</a></b>"));
1206 return ($smarty->fetch (get_template_path('islocked.tpl')));
1207 }
1210 function to_string ($value)
1211 {
1212 /* If this is an array, generate a text blob */
1213 if (is_array($value)){
1214 $ret= "";
1215 foreach ($value as $line){
1216 $ret.= $line."<br>\n";
1217 }
1218 return ($ret);
1219 } else {
1220 return ($value);
1221 }
1222 }
1225 function get_printer_list($cups_server)
1226 {
1227 global $config;
1229 $res= array();
1231 /* Use CUPS, if we've access to it */
1232 if (function_exists('cups_get_dest_list')){
1233 $dest_list= cups_get_dest_list ($cups_server);
1235 foreach ($dest_list as $prt){
1236 $attr= cups_get_printer_attributes ($cups_server, $prt->name);
1238 foreach ($attr as $prt_info){
1239 if ($prt_info->name == "printer-info"){
1240 $info= $prt_info->value;
1241 break;
1242 }
1243 }
1244 $res[$prt->name]= "$info [$prt->name]";
1245 }
1247 /* CUPS is not available, try lpstat as a replacement */
1248 } else {
1249 $ar = false;
1250 exec("lpstat -p", $ar);
1251 foreach($ar as $val){
1252 @list($dummy, $printer, $rest)= split(' ', $val, 3);
1253 if (preg_match('/^[^@]+$/', $printer)){
1254 $res[$printer]= "$printer";
1255 }
1256 }
1257 }
1259 /* Merge in printers from LDAP */
1260 $ldap= $config->get_ldap_link();
1261 $ldap->cd ($config->current['BASE']);
1262 $ui= get_userinfo();
1263 if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){
1264 $ldap->search('((objectClass=gotoPrinter)(gosaUnitTag='.$ui->gosaUnitTag.'))', array('cn'));
1265 } else {
1266 $ldap->search('(objectClass=gotoPrinter)', array('cn'));
1267 }
1268 while($attrs = $ldap->fetch()){
1269 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1270 }
1272 return $res;
1273 }
1276 function sess_del ($var)
1277 {
1278 /* New style */
1279 unset ($_SESSION[$var]);
1281 /* ... work around, since the first one
1282 doesn't seem to work all the time */
1283 session_unregister ($var);
1284 }
1287 function show_errors($message)
1288 {
1289 $complete= "";
1291 /* Assemble the message array to a plain string */
1292 foreach ($message as $error){
1293 if ($complete == ""){
1294 $complete= $error;
1295 } else {
1296 $complete= "$error<br>$complete";
1297 }
1298 }
1300 /* Fill ERROR variable with nice error dialog */
1301 print_red($complete);
1302 }
1305 function show_ldap_error($message, $addon= "")
1306 {
1307 if (!preg_match("/Success/i", $message)){
1308 if ($addon == ""){
1309 print_red (_("LDAP error: $message"));
1310 } else {
1311 print_red ("$addon<br><br><b>"._("LDAP error:")."</b> $message");
1312 }
1313 return TRUE;
1314 } else {
1315 return FALSE;
1316 }
1317 }
1320 function rewrite($s)
1321 {
1322 global $REWRITE;
1324 foreach ($REWRITE as $key => $val){
1325 $s= preg_replace("/$key/", "$val", $s);
1326 }
1328 return ($s);
1329 }
1332 function dn2base($dn)
1333 {
1334 global $config;
1336 if (get_people_ou() != ""){
1337 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1338 }
1339 if (get_groups_ou() != ""){
1340 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1341 }
1342 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1344 return ($base);
1345 }
1349 function check_command($cmdline)
1350 {
1351 $cmd= preg_replace("/ .*$/", "", $cmdline);
1353 /* Check if command exists in filesystem */
1354 if (!file_exists($cmd)){
1355 return (FALSE);
1356 }
1358 /* Check if command is executable */
1359 if (!is_executable($cmd)){
1360 return (FALSE);
1361 }
1363 return (TRUE);
1364 }
1367 function print_header($image, $headline, $info= "")
1368 {
1369 $display= "<div class=\"plugtop\">\n";
1370 $display.= " <p class=\"center\" style=\"margin:0px 0px 0px 5px;padding:0px;font-size:24px;\"><img class=\"center\" src=\"$image\" align=\"middle\" alt=\"*\"> $headline</p>\n";
1371 $display.= "</div>\n";
1373 if ($info != ""){
1374 $display.= "<div class=\"pluginfo\">\n";
1375 $display.= "$info";
1376 $display.= "</div>\n";
1377 } else {
1378 $display.= "<div style=\"height:5px;\">\n";
1379 $display.= " ";
1380 $display.= "</div>\n";
1381 }
1382 if (isset($_SESSION['errors'])){
1383 $display.= $_SESSION['errors'];
1384 }
1386 return ($display);
1387 }
1390 function register_global($name, $object)
1391 {
1392 $_SESSION[$name]= $object;
1393 }
1396 function is_global($name)
1397 {
1398 return isset($_SESSION[$name]);
1399 }
1402 function get_global($name)
1403 {
1404 return $_SESSION[$name];
1405 }
1408 function range_selector($dcnt,$start,$range=25,$post_var=false)
1409 {
1411 /* Entries shown left and right from the selected entry */
1412 $max_entries= 10;
1414 /* Initialize and take care that max_entries is even */
1415 $output="";
1416 if ($max_entries & 1){
1417 $max_entries++;
1418 }
1420 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1421 $range= $_POST[$post_var];
1422 }
1424 /* Prevent output to start or end out of range */
1425 if ($start < 0 ){
1426 $start= 0 ;
1427 }
1428 if ($start >= $dcnt){
1429 $start= $range * (int)(($dcnt / $range) + 0.5);
1430 }
1432 $numpages= (($dcnt / $range));
1433 if(((int)($numpages))!=($numpages)){
1434 $numpages = (int)$numpages + 1;
1435 }
1436 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1437 return ("");
1438 }
1439 $ppage= (int)(($start / $range) + 0.5);
1442 /* Align selected page to +/- max_entries/2 */
1443 $begin= $ppage - $max_entries/2;
1444 $end= $ppage + $max_entries/2;
1446 /* Adjust begin/end, so that the selected value is somewhere in
1447 the middle and the size is max_entries if possible */
1448 if ($begin < 0){
1449 $end-= $begin + 1;
1450 $begin= 0;
1451 }
1452 if ($end > $numpages) {
1453 $end= $numpages;
1454 }
1455 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1456 $begin= $end - $max_entries;
1457 }
1459 if($post_var){
1460 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1461 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1462 }else{
1463 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1464 }
1466 /* Draw decrement */
1467 if ($start > 0 ) {
1468 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1469 (($start-$range))."\">".
1470 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1471 }
1473 /* Draw pages */
1474 for ($i= $begin; $i < $end; $i++) {
1475 if ($ppage == $i){
1476 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1477 validate($_GET['plug'])."&start=".
1478 ($i*$range)."\"> ".($i+1)." </a>";
1479 } else {
1480 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1481 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1482 }
1483 }
1485 /* Draw increment */
1486 if($start < ($dcnt-$range)) {
1487 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1488 (($start+($range)))."\">".
1489 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1490 }
1492 if(($post_var)&&($numpages)){
1493 $output.= "</td><td style='width:25%;text-align:right;vertical-align:middle;'> "._("Entries per page")." <select style='vertical-align:middle;' name='".$post_var."' onChange='javascript:document.mainform.submit()'>";
1494 foreach(array(20,50,100,200,"all") as $num){
1495 if($num == "all"){
1496 $var = 10000;
1497 }else{
1498 $var = $num;
1499 }
1500 if($var == $range){
1501 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1502 }else{
1503 $output.="\n<option value='".$var."'>".$num."</option>";
1504 }
1505 }
1506 $output.= "</select></td></tr></table></div>";
1507 }else{
1508 $output.= "</div>";
1509 }
1511 return($output);
1512 }
1515 function apply_filter()
1516 {
1517 $apply= "";
1519 $apply= ''.
1520 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1521 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1523 return ($apply);
1524 }
1527 function back_to_main()
1528 {
1529 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1530 _("Back").'"></p><input type="hidden" name="ignore">';
1532 return ($string);
1533 }
1536 function normalize_netmask($netmask)
1537 {
1538 /* Check for notation of netmask */
1539 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1540 $num= (int)($netmask);
1541 $netmask= "";
1543 for ($byte= 0; $byte<4; $byte++){
1544 $result=0;
1546 for ($i= 7; $i>=0; $i--){
1547 if ($num-- > 0){
1548 $result+= pow(2,$i);
1549 }
1550 }
1552 $netmask.= $result.".";
1553 }
1555 return (preg_replace('/\.$/', '', $netmask));
1556 }
1558 return ($netmask);
1559 }
1562 function netmask_to_bits($netmask)
1563 {
1564 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1565 $res= 0;
1567 for ($n= 0; $n<4; $n++){
1568 $start= 255;
1569 $name= "nm$n";
1571 for ($i= 0; $i<8; $i++){
1572 if ($start == (int)($$name)){
1573 $res+= 8 - $i;
1574 break;
1575 }
1576 $start-= pow(2,$i);
1577 }
1578 }
1580 return ($res);
1581 }
1584 function recurse($rule, $variables)
1585 {
1586 $result= array();
1588 if (!count($variables)){
1589 return array($rule);
1590 }
1592 reset($variables);
1593 $key= key($variables);
1594 $val= current($variables);
1595 unset ($variables[$key]);
1597 foreach($val as $possibility){
1598 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1599 $result= array_merge($result, recurse($nrule, $variables));
1600 }
1602 return ($result);
1603 }
1606 function expand_id($rule, $attributes)
1607 {
1608 /* Check for id rule */
1609 if(preg_match('/^id(:|#)\d+$/',$rule)){
1610 return (array("\{$rule}"));
1611 }
1613 /* Check for clean attribute */
1614 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1615 $rule= preg_replace('/^%/', '', $rule);
1616 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1617 return (array($val));
1618 }
1620 /* Check for attribute with parameters */
1621 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1622 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1623 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1624 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1625 $start= preg_replace ('/-.*$/', '', $param);
1626 $stop = preg_replace ('/^[^-]+-/', '', $param);
1628 /* Assemble results */
1629 $result= array();
1630 for ($i= $start; $i<= $stop; $i++){
1631 $result[]= substr($val, 0, $i);
1632 }
1633 return ($result);
1634 }
1636 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1637 return (array($rule));
1638 }
1641 function gen_uids($rule, $attributes)
1642 {
1643 global $config;
1645 /* Search for keys and fill the variables array with all
1646 possible values for that key. */
1647 $part= "";
1648 $trigger= false;
1649 $stripped= "";
1650 $variables= array();
1652 for ($pos= 0; $pos < strlen($rule); $pos++){
1654 if ($rule[$pos] == "{" ){
1655 $trigger= true;
1656 $part= "";
1657 continue;
1658 }
1660 if ($rule[$pos] == "}" ){
1661 $variables[$pos]= expand_id($part, $attributes);
1662 $stripped.= "\{$pos}";
1663 $trigger= false;
1664 continue;
1665 }
1667 if ($trigger){
1668 $part.= $rule[$pos];
1669 } else {
1670 $stripped.= $rule[$pos];
1671 }
1672 }
1674 /* Recurse through all possible combinations */
1675 $proposed= recurse($stripped, $variables);
1677 /* Get list of used ID's */
1678 $used= array();
1679 $ldap= $config->get_ldap_link();
1680 $ldap->cd($config->current['BASE']);
1681 $ldap->search('(uid=*)');
1683 while($attrs= $ldap->fetch()){
1684 $used[]= $attrs['uid'][0];
1685 }
1687 /* Remove used uids and watch out for id tags */
1688 $ret= array();
1689 foreach($proposed as $uid){
1691 /* Check for id tag and modify uid if needed */
1692 if(preg_match('/\{id:\d+}/',$uid)){
1693 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1695 for ($i= 0; $i < pow(10,$size); $i++){
1696 $number= sprintf("%0".$size."d", $i);
1697 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1698 if (!in_array($res, $used)){
1699 $uid= $res;
1700 break;
1701 }
1702 }
1703 }
1705 if(preg_match('/\{id#\d+}/',$uid)){
1706 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1708 while (true){
1709 mt_srand((double) microtime()*1000000);
1710 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1711 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1712 if (!in_array($res, $used)){
1713 $uid= $res;
1714 break;
1715 }
1716 }
1717 }
1719 /* Don't assign used ones */
1720 if (!in_array($uid, $used)){
1721 $ret[]= $uid;
1722 }
1723 }
1725 return(array_unique($ret));
1726 }
1729 function array_search_r($needle, $key, $haystack){
1731 foreach($haystack as $index => $value){
1732 $match= 0;
1734 if (is_array($value)){
1735 $match= array_search_r($needle, $key, $value);
1736 }
1738 if ($index==$key && !is_array($value) && preg_match("/$needle/i", $value)){
1739 $match=1;
1740 }
1742 if ($match){
1743 return 1;
1744 }
1745 }
1747 return 0;
1748 }
1751 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1752 Need to convert... */
1753 function to_byte($value) {
1754 $value= strtolower(trim($value));
1756 if(!is_numeric(substr($value, -1))) {
1758 switch(substr($value, -1)) {
1759 case 'g':
1760 $mult= 1073741824;
1761 break;
1762 case 'm':
1763 $mult= 1048576;
1764 break;
1765 case 'k':
1766 $mult= 1024;
1767 break;
1768 }
1770 return ($mult * (int)substr($value, 0, -1));
1771 } else {
1772 return $value;
1773 }
1774 }
1777 function in_array_ics($value, $items)
1778 {
1779 if (!is_array($items)){
1780 return (FALSE);
1781 }
1783 foreach ($items as $item){
1784 if (strtolower($item) == strtolower($value)) {
1785 return (TRUE);
1786 }
1787 }
1789 return (FALSE);
1790 }
1793 function generate_alphabet($count= 10)
1794 {
1795 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1796 $alphabet= "";
1797 $c= 0;
1799 /* Fill cells with charaters */
1800 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1801 if ($c == 0){
1802 $alphabet.= "<tr>";
1803 }
1805 $ch = mb_substr($characters, $i, 1, "UTF8");
1806 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1807 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1809 if ($c++ == $count){
1810 $alphabet.= "</tr>";
1811 $c= 0;
1812 }
1813 }
1815 /* Fill remaining cells */
1816 while ($c++ <= $count){
1817 $alphabet.= "<td> </td>";
1818 }
1820 return ($alphabet);
1821 }
1824 function validate($string)
1825 {
1826 return (strip_tags(preg_replace('/\0/', '', $string)));
1827 }
1829 function get_gosa_version()
1830 {
1831 global $svn_revision, $svn_path;
1833 /* Extract informations */
1834 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1836 /* Release or development? */
1837 if (preg_match('%/gosa/trunk/%', $svn_path)){
1838 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1839 } else {
1840 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1841 return (_("GOsa $release"));
1842 }
1843 }
1846 function rmdirRecursive($path, $followLinks=false) {
1847 $dir= opendir($path);
1848 while($entry= readdir($dir)) {
1849 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1850 unlink($path."/".$entry);
1851 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1852 rmdirRecursive($path."/".$entry);
1853 }
1854 }
1855 closedir($dir);
1856 return rmdir($path);
1857 }
1859 function scan_directory($path,$sort_desc=false)
1860 {
1861 $ret = false;
1863 /* is this a dir ? */
1864 if(is_dir($path)) {
1866 /* is this path a readable one */
1867 if(is_readable($path)){
1869 /* Get contents and write it into an array */
1870 $ret = array();
1872 $dir = opendir($path);
1874 /* Is this a correct result ?*/
1875 if($dir){
1876 while($fp = readdir($dir))
1877 $ret[]= $fp;
1878 }
1879 }
1880 }
1881 /* Sort array ascending , like scandir */
1882 sort($ret);
1884 /* Sort descending if parameter is sort_desc is set */
1885 if($sort_desc) {
1886 $ret = array_reverse($ret);
1887 }
1889 return($ret);
1890 }
1892 function clean_smarty_compile_dir($directory)
1893 {
1894 global $svn_revision;
1896 if(is_dir($directory) && is_readable($directory)) {
1897 // Set revision filename to REVISION
1898 $revision_file= $directory."/REVISION";
1900 /* Is there a stamp containing the current revision? */
1901 if(!file_exists($revision_file)) {
1902 // create revision file
1903 create_revision($revision_file, $svn_revision);
1904 } else {
1905 # check for "$config->...['CONFIG']/revision" and the
1906 # contents should match the revision number
1907 if(!compare_revision($revision_file, $svn_revision)){
1908 // If revision differs, clean compile directory
1909 foreach(scan_directory($directory) as $file) {
1910 if(($file==".")||($file=="..")) continue;
1911 if( is_file($directory."/".$file) &&
1912 is_writable($directory."/".$file)) {
1913 // delete file
1914 if(!unlink($directory."/".$file)) {
1915 print_red("File ".$directory."/".$file." could not be deleted.");
1916 // This should never be reached
1917 }
1918 } elseif(is_dir($directory."/".$file) &&
1919 is_writable($directory."/".$file)) {
1920 // Just recursively delete it
1921 rmdirRecursive($directory."/".$file);
1922 }
1923 }
1924 // We should now create a fresh revision file
1925 clean_smarty_compile_dir($directory);
1926 } else {
1927 // Revision matches, nothing to do
1928 }
1929 }
1930 } else {
1931 // Smarty compile dir is not accessible
1932 // (Smarty will warn about this)
1933 }
1934 }
1936 function create_revision($revision_file, $revision)
1937 {
1938 $result= false;
1940 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1941 if($fh= fopen($revision_file, "w")) {
1942 if(fwrite($fh, $revision)) {
1943 $result= true;
1944 }
1945 }
1946 fclose($fh);
1947 } else {
1948 print_red("Can not write to revision file");
1949 }
1951 return $result;
1952 }
1954 function compare_revision($revision_file, $revision)
1955 {
1956 // false means revision differs
1957 $result= false;
1959 if(file_exists($revision_file) && is_readable($revision_file)) {
1960 // Open file
1961 if($fh= fopen($revision_file, "r")) {
1962 // Compare File contents with current revision
1963 if($revision == fread($fh, filesize($revision_file))) {
1964 $result= true;
1965 }
1966 } else {
1967 print_red("Can not open revision file");
1968 }
1969 // Close file
1970 fclose($fh);
1971 }
1973 return $result;
1974 }
1976 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1977 {
1978 $str = ""; // Our return value will be saved in this var
1980 $color = dechex($percentage+150);
1981 $color2 = dechex(150 - $percentage);
1982 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1984 $progress = (int)(($percentage /100)*$width);
1986 /* Abort printing out percentage, if divs are to small */
1989 /* If theres a better solution for this, use it... */
1990 $str = "
1991 <div style=\" width:".($width)."px;
1992 height:".($height)."px;
1993 background-color:#000000;
1994 padding:1px;\">
1996 <div style=\" width:".($width)."px;
1997 background-color:#$bgcolor;
1998 height:".($height)."px;\">
2000 <div style=\" width:".$progress."px;
2001 height:".$height."px;
2002 background-color:#".$color2.$color2.$color."; \">";
2005 if(($height >10)&&($showvalue)){
2006 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2007 <b>".$percentage."%</b>
2008 </font>";
2009 }
2011 $str.= "</div></div></div>";
2013 return($str);
2014 }
2017 function array_key_ics($ikey, $items)
2018 {
2019 /* Gather keys, make them lowercase */
2020 $tmp= array();
2021 foreach ($items as $key => $value){
2022 $tmp[strtolower($key)]= $key;
2023 }
2025 if (isset($tmp[strtolower($ikey)])){
2026 return($tmp[strtolower($ikey)]);
2027 }
2029 return ("");
2030 }
2033 function search_config($arr, $name, $return)
2034 {
2035 if (is_array($arr)){
2036 foreach ($arr as $a){
2037 if (isset($a['CLASS']) &&
2038 strtolower($a['CLASS']) == strtolower($name)){
2040 if (isset($a[$return])){
2041 return ($a[$return]);
2042 } else {
2043 return ("");
2044 }
2045 } else {
2046 $res= search_config ($a, $name, $return);
2047 if ($res != ""){
2048 return $res;
2049 }
2050 }
2051 }
2052 }
2053 return ("");
2054 }
2057 function array_differs($src, $dst)
2058 {
2059 /* If the count is differing, the arrays differ */
2060 if (count ($src) != count ($dst)){
2061 return (TRUE);
2062 }
2064 /* So the count is the same - lets check the contents */
2065 $differs= FALSE;
2066 foreach($src as $value){
2067 if (!in_array($value, $dst)){
2068 $differs= TRUE;
2069 }
2070 }
2072 return ($differs);
2073 }
2076 function saveFilter($a_filter, $values)
2077 {
2078 if (isset($_POST['regexit'])){
2079 $a_filter["regex"]= $_POST['regexit'];
2081 foreach($values as $type){
2082 if (isset($_POST[$type])) {
2083 $a_filter[$type]= "checked";
2084 } else {
2085 $a_filter[$type]= "";
2086 }
2087 }
2088 }
2090 /* React on alphabet links if needed */
2091 if (isset($_GET['search'])){
2092 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2093 if ($s == "**"){
2094 $s= "*";
2095 }
2096 $a_filter['regex']= $s;
2097 }
2099 return ($a_filter);
2100 }
2103 /* Escape all preg_* relevant characters */
2104 function normalizePreg($input)
2105 {
2106 return (addcslashes($input, '[]()|/.*+-'));
2107 }
2110 /* Escape all LDAP filter relevant characters */
2111 function normalizeLdap($input)
2112 {
2113 return (addcslashes($input, '()|'));
2114 }
2117 /* Resturns the difference between to microtime() results in float */
2118 function get_MicroTimeDiff($start , $stop)
2119 {
2120 $a = split("\ ",$start);
2121 $b = split("\ ",$stop);
2123 $secs = $b[1] - $a[1];
2124 $msecs= $b[0] - $a[0];
2126 $ret = (float) ($secs+ $msecs);
2127 return($ret);
2128 }
2131 /* Check if the given department name is valid */
2132 function is_department_name_reserved($name,$base)
2133 {
2134 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2135 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2136 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2137 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2139 /* Check if name is one of the reserved names */
2140 if(in_array_ics($name,$reservedName)) {
2141 return(true);
2142 }
2144 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2145 foreach($follwedNames as $key => $names){
2146 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2147 return(true);
2148 }
2149 }
2150 return(false);
2151 }
2154 function is_php4()
2155 {
2156 if (isset($_SESSION['PHP4COMPATIBLE'])){
2157 return true;
2158 }
2159 return (preg_match('/^4/', phpversion()));
2160 }
2163 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2164 {
2165 /* Initialize variables */
2166 $ret = array("count" => 0); // Set count to 0
2167 $next = true; // if false, then skip next loops and return
2168 $cnt = 0; // Current number of loops
2169 $max = 100; // Just for security, prevent looops
2170 $ldap = NULL; // To check if created result a valid
2171 $keep = ""; // save last failed parse string
2173 /* Check each parsed dn in ldap ? */
2174 if($config!=NULL && $verify_in_ldap){
2175 $ldap = $config->get_ldap_link();
2176 }
2178 /* Lets start */
2179 $called = false;
2180 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2182 $cnt ++;
2183 if(!preg_match("/,/",$dn)){
2184 $next = false;
2185 }
2186 $object = preg_replace("/[,].*$/","",$dn);
2187 $dn = preg_replace("/^[^,]+,/","",$dn);
2189 $called = true;
2191 /* Check if current dn is valid */
2192 if($ldap!=NULL){
2193 $ldap->cd($dn);
2194 $ldap->cat($dn,array("dn"));
2195 if($ldap->count()){
2196 $ret[] = $keep.$object;
2197 $keep = "";
2198 }else{
2199 $keep .= $object.",";
2200 }
2201 }else{
2202 $ret[] = $keep.$object;
2203 $keep = "";
2204 }
2205 }
2207 /* No dn was posted */
2208 if($cnt == 0 && !empty($dn)){
2209 $ret[] = $dn;
2210 }
2212 /* Append the rest */
2213 $test = $keep.$dn;
2214 if($called && !empty($test)){
2215 $ret[] = $keep.$dn;
2216 }
2217 $ret['count'] = count($ret) - 1;
2219 return($ret);
2220 }
2223 function get_base_from_hook($dn, $attrib)
2224 {
2225 global $config;
2227 if (isset($config->current['BASE_HOOK'])){
2229 /* Call hook script - if present */
2230 $command= $config->current['BASE_HOOK'];
2232 if ($command != ""){
2233 $command.= " '$dn' $attrib";
2234 if (check_command($command)){
2235 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2236 exec($command, $output);
2237 if (preg_match("/^[0-9]+$/", $output[0])){
2238 return ($output[0]);
2239 } else {
2240 print_red(_("Warning - base_hook is not avialable. Using default base."));
2241 return ($config->current['UIDBASE']);
2242 }
2243 } else {
2244 print_red(_("Warning - base_hook is not avialable. Using default base."));
2245 return ($config->current['UIDBASE']);
2246 }
2248 } else {
2250 print_red(_("Warning - no base_hook defined. Using default base."));
2251 return ($config->current['UIDBASE']);
2253 }
2254 }
2255 }
2257 /* Schema validation functions */
2259 function check_schema_version($class, $version)
2260 {
2261 return preg_match("/\(v$version\)/", $class['DESC']);
2262 }
2266 function check_schema($cfg,$rfc2307bis = FALSE)
2267 {
2269 $messages= array();
2271 /* Get objectclasses */
2272 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2273 $objectclasses = $ldap->get_objectclasses();
2274 if(count($objectclasses) == 0){
2275 print_red(_("Can't get schema information from server. No schema check possible!"));
2276 }
2278 /* This is the default block used for each entry.
2279 * to avoid unset indexes.
2280 */
2281 $def_check = array("REQUIRED_VERSION" => "0",
2282 "SCHEMA_FILES" => array(),
2283 "CLASSES_REQUIRED" => array(),
2284 "STATUS" => FALSE,
2285 "IS_MUST_HAVE" => FALSE,
2286 "MSG" => "",
2287 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2289 /* The gosa base schema */
2290 $checks['gosaObject'] = $def_check;
2291 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2292 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2293 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2294 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2296 /* GOsa Account class */
2297 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2298 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2299 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2300 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2301 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2303 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2304 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2305 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2306 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2307 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2308 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2310 /* Some other checks */
2311 foreach(array(
2312 "gosaCacheEntry" => array("version" => "2.4"),
2313 "gosaDepartment" => array("version" => "2.4"),
2314 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2315 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2316 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2317 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2318 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2319 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2320 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2321 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2322 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2323 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2324 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2325 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2326 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2327 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2328 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2329 "goLdapServer" => array("version" => "2.4"),
2330 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2331 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2332 "goKrbServer" => array("version" => "2.4"),
2333 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2334 ) as $name => $values){
2336 $checks[$name] = $def_check;
2337 if(isset($values['version'])){
2338 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2339 }
2340 if(isset($values['file'])){
2341 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2342 }
2343 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2344 }
2345 foreach($checks as $name => $value){
2346 foreach($value['CLASSES_REQUIRED'] as $class){
2348 if(!isset($objectclasses[$name])){
2349 $checks[$name]['STATUS'] = FALSE;
2350 if($value['IS_MUST_HAVE']){
2351 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2352 }else{
2353 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2354 }
2355 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2356 $checks[$name]['STATUS'] = FALSE;
2358 if($value['IS_MUST_HAVE']){
2359 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2360 }else{
2361 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2362 }
2363 }else{
2364 $checks[$name]['STATUS'] = TRUE;
2365 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2366 }
2367 }
2368 }
2370 $tmp = $objectclasses;
2373 /* The gosa base schema */
2374 $checks['posixGroup'] = $def_check;
2375 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2376 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2377 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2378 $checks['posixGroup']['STATUS'] = TRUE;
2379 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2380 $checks['posixGroup']['MSG'] = "";
2381 $checks['posixGroup']['INFO'] = "";
2383 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2384 if(isset($tmp['posixGroup'])){
2386 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2387 $checks['posixGroup']['STATUS'] = FALSE;
2388 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2389 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2390 }
2391 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2392 $checks['posixGroup']['STATUS'] = FALSE;
2393 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2394 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2395 }
2396 }
2398 return($checks);
2399 }
2404 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
2405 ?>