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 /* 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));
194 }
197 /* Rewrite ui object to another dn */
198 function change_ui_dn($dn, $newdn)
199 {
200 $ui= $_SESSION['ui'];
201 if ($ui->dn == $dn){
202 $ui->dn= $newdn;
203 $_SESSION['ui']= $ui;
204 }
205 }
208 /* Return theme path for specified file */
209 function get_template_path($filename= '', $plugin= FALSE, $path= "")
210 {
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 }
257 }
260 function array_remove_entries($needles, $haystack)
261 {
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);
272 }
275 function gosa_log ($message)
276 {
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");
292 }
295 function ldap_init ($server, $base, $binddn='', $pass='')
296 {
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;
312 }
315 function ldap_login_user ($username, $password)
316 {
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);
372 }
375 function ldap_expired_account($config, $userdn, $username)
376 {
377 //$this->config= $config;
378 $ldap= $config->get_ldap_link();
379 $ldap->cat($userdn);
380 $attrs= $ldap->fetch();
382 /* default value no errors */
383 $expired = 0;
385 $sExpire = 0;
386 $sLastChange = 0;
387 $sMax = 0;
388 $sMin = 0;
389 $sInactive = 0;
390 $sWarning = 0;
392 $current= date("U");
394 $current= floor($current /60 /60 /24);
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 }
407 if(isset($attrs['shadowLastChange'][0])){
408 $sLastChange= $attrs['shadowLastChange'][0];
409 } else {
410 $sLastChange = 0;
411 }
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 }
425 if(isset($attrs['shadowInactive'][0])){
426 $sInactive= $attrs['shadowInactive'][0];
427 } else {
428 $sInactive = 0;
429 }
431 if(isset($attrs['shadowWarning'][0])){
432 $sWarning= $attrs['shadowWarning'][0];
433 } else {
434 $sWarning = 0;
435 }
437 /* is the account locked */
438 /* shadowExpire + shadowInactive (option) */
439 if($sExpire >0){
440 if($current >= ($sExpire+$sInactive)){
441 return(1);
442 }
443 }
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 }
452 /* force user to change password */
453 if(($sLastChange >0) && ($sMax) >0){
454 if($current >= ($sLastChange+$sMax)){
455 return(3);
456 }
457 }
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);
467 }
469 function add_lock ($object, $user)
470 {
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 }
505 }
508 function del_lock ($object)
509 {
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 }
531 }
534 function del_user_locks($userdn)
535 {
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 }
547 }
550 function get_lock ($object)
551 {
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);
589 }
592 function get_list($filter, $subtreeACL, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
593 {
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);
647 }
650 function check_sizelimit()
651 {
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 ("");
667 }
670 function print_sizelimit_warning()
671 {
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 ("");
682 }
685 function eval_sizelimit()
686 {
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 }
713 }
715 function getMenuCache()
716 {
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 }
735 }
737 function get_permissions ($dn, $subtreeACL)
738 {
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("");
769 }
772 function get_module_permission($acl_array, $module, $dn)
773 {
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#");
823 }
826 function get_userinfo()
827 {
828 global $ui;
830 return $ui;
831 }
834 function get_smarty()
835 {
836 global $smarty;
838 return $smarty;
839 }
842 function convert_department_dn($dn)
843 {
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, "/");
863 }
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)
869 {
870 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
871 }
874 function get_ou($name)
875 {
876 global $config;
878 /* Preset ou... */
879 if (isset($config->current[$name])){
880 $ou= $config->current[$name];
881 } else {
882 return "";
883 }
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 }
894 }
897 function get_people_ou()
898 {
899 return (get_ou("PEOPLE"));
900 }
903 function get_groups_ou()
904 {
905 return (get_ou("GROUPS"));
906 }
909 function get_winstations_ou()
910 {
911 return (get_ou("WINSTATIONS"));
912 }
915 function get_base_from_people($dn)
916 {
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);
928 }
931 function chkacl($acl, $name)
932 {
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 ");
940 }
943 function is_phone_nr($nr)
944 {
945 if ($nr == ""){
946 return (TRUE);
947 }
949 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
950 }
953 function is_url($url)
954 {
955 if ($url == ""){
956 return (TRUE);
957 }
959 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
960 }
963 function is_dn($dn)
964 {
965 if ($dn == ""){
966 return (TRUE);
967 }
969 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
970 }
973 function is_uid($uid)
974 {
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 }
988 }
991 function is_ip($ip)
992 {
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);
994 }
997 function is_mac($mac)
998 {
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);
1000 }
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)
1006 {
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);
1041 }
1043 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1044 function is_domain($str)
1045 {
1046 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1047 }
1050 function is_id($id)
1051 {
1052 if ($id == ""){
1053 return (FALSE);
1054 }
1056 return preg_match ("/^[0-9]+$/", $id);
1057 }
1060 function is_path($path)
1061 {
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);
1070 }
1073 function is_email($address, $template= FALSE)
1074 {
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 }
1085 }
1088 function print_red()
1089 {
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){
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 }
1134 if(isset($_SESSION['errors']) && strlen($_SESSION['errors'])==0) {
1137 if(preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])){
1139 $_SESSION['errors'].= "
1140 <iframe id='e_layer3'
1141 style=\" position:absolute;
1142 width:100%;
1143 height:100%;
1144 top:0px;
1145 left:0px;
1146 border:none;
1147 display:block;
1148 allowtransparency='true';
1149 background-color: #FFFFFF;
1150 filter:chroma(color=#FFFFFF);
1151 z-index:0; \">
1152 </iframe>
1153 <div id='e_layer2'
1154 style=\"
1155 position: absolute;
1156 left: 0px;
1157 top: 0px;
1158 right:0px;
1159 bottom:0px;
1160 z-index:0;
1161 width:100%;
1162 height:100%;
1163 filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='images/opacity_black.png'); \">
1164 </div>";
1165 $hide = "hide(\"e_layer\");hide(\"e_layer2\");hide(\"e_layer3\");";
1166 }else{
1168 $_SESSION['errors'].= "
1169 <div id='e_layer2'
1170 style=\"
1171 position: absolute;
1172 left: 0px;
1173 top: 0px;
1174 right:0px;
1175 bottom:0px;
1176 z-index:0;
1177 background-image: url(images/opacity_black.png);\">
1178 </div>";
1179 $hide = "hide(\"e_layer\");hide(\"e_layer2\");";
1180 }
1182 $_SESSION['errors'].= "
1183 <div style='left:20%;right:20%;top:30%;".
1184 "background-color:white;padding:5px;border:5px solid red;z-index:150;".
1185 "position:absolute' id='e_layer'><table style='width:100%' summary='' border=0>".
1186 "<tr><td style='vertical-align:top;padding:10px'><img alt='' src='".
1187 get_template_path($img)."'></td>".
1188 "<td style='width:100%'><h1>"._("An error occurred while processing your request").
1189 "</h1><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
1190 (($_SESSION['js']==FALSE)?"type='submit'":"type='button' name='error_accept'").
1191 " style='width:80px' onClick='".$hide."'>".
1192 _("OK")."</button></td></tr></table></div>";
1193 }
1195 }else{
1196 return;
1197 }
1198 $_SESSION['errorsAlreadyPosted'][$string] = 1;
1200 }
1202 } else {
1203 echo "Error: $string\n";
1204 }
1205 $_SESSION['LastError'] = $string;
1206 }
1209 function gen_locked_message($user, $dn)
1210 {
1211 global $plug, $config;
1213 $_SESSION['dn']= $dn;
1214 $ldap= $config->get_ldap_link();
1215 $ldap->cat ($user, array('uid', 'cn'));
1216 $attrs= $ldap->fetch();
1218 /* Stop if we have no user here... */
1219 if (count($attrs)){
1220 $uid= $attrs["uid"][0];
1221 $cn= $attrs["cn"][0];
1222 } else {
1223 $uid= $attrs["uid"][0];
1224 $cn= $attrs["cn"][0];
1225 }
1227 $remove= false;
1229 if((isset($_SESSION['LOCK_VARS_TO_USE']))&&(count($_SESSION['LOCK_VARS_TO_USE']))){
1230 $_SESSION['LOCK_VARS_USED'] =array();
1231 foreach($_SESSION['LOCK_VARS_TO_USE'] as $name){
1233 if(empty($name)) continue;
1234 foreach($_POST as $Pname => $Pvalue){
1235 if(preg_match($name,$Pname)){
1236 $_SESSION['LOCK_VARS_USED'][$Pname] = $_POST[$Pname];
1237 }
1238 }
1240 foreach($_GET as $Pname => $Pvalue){
1241 if(preg_match($name,$Pname)){
1242 $_SESSION['LOCK_VARS_USED'][$Pname] = $_GET[$Pname];
1243 }
1244 }
1245 }
1246 $_SESSION['LOCK_VARS_TO_USE'] =array();
1247 }
1249 /* Prepare and show template */
1250 $smarty= get_smarty();
1251 $smarty->assign ("dn", $dn);
1252 if ($remove){
1253 $smarty->assign ("action", _("Continue anyway"));
1254 } else {
1255 $smarty->assign ("action", _("Edit anyway"));
1256 }
1257 $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>"));
1259 return ($smarty->fetch (get_template_path('islocked.tpl')));
1260 }
1263 function to_string ($value)
1264 {
1265 /* If this is an array, generate a text blob */
1266 if (is_array($value)){
1267 $ret= "";
1268 foreach ($value as $line){
1269 $ret.= $line."<br>\n";
1270 }
1271 return ($ret);
1272 } else {
1273 return ($value);
1274 }
1275 }
1278 function get_printer_list($cups_server)
1279 {
1280 global $config;
1282 $res= array();
1284 /* Use CUPS, if we've access to it */
1285 if (function_exists('cups_get_dest_list')){
1286 $dest_list= cups_get_dest_list ($cups_server);
1288 foreach ($dest_list as $prt){
1289 $attr= cups_get_printer_attributes ($cups_server, $prt->name);
1291 foreach ($attr as $prt_info){
1292 if ($prt_info->name == "printer-info"){
1293 $info= $prt_info->value;
1294 break;
1295 }
1296 }
1297 $res[$prt->name]= "$info [$prt->name]";
1298 }
1300 /* CUPS is not available, try lpstat as a replacement */
1301 } else {
1302 $ar = false;
1303 exec("lpstat -p", $ar);
1304 foreach($ar as $val){
1305 @list($dummy, $printer, $rest)= split(' ', $val, 3);
1306 if (preg_match('/^[^@]+$/', $printer)){
1307 $res[$printer]= "$printer";
1308 }
1309 }
1310 }
1312 /* Merge in printers from LDAP */
1313 $ldap= $config->get_ldap_link();
1314 $ldap->cd ($config->current['BASE']);
1315 $ui= get_userinfo();
1316 if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){
1317 $ldap->search('((objectClass=gotoPrinter)(gosaUnitTag='.$ui->gosaUnitTag.'))', array('cn'));
1318 } else {
1319 $ldap->search('(objectClass=gotoPrinter)', array('cn'));
1320 }
1321 while($attrs = $ldap->fetch()){
1322 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1323 }
1325 return $res;
1326 }
1329 function sess_del ($var)
1330 {
1331 /* New style */
1332 unset ($_SESSION[$var]);
1334 /* ... work around, since the first one
1335 doesn't seem to work all the time */
1336 session_unregister ($var);
1337 }
1340 function show_errors($message)
1341 {
1342 $complete= "";
1344 /* Assemble the message array to a plain string */
1345 foreach ($message as $error){
1346 if ($complete == ""){
1347 $complete= $error;
1348 } else {
1349 $complete= "$error<br>$complete";
1350 }
1351 }
1353 /* Fill ERROR variable with nice error dialog */
1354 print_red($complete);
1355 }
1358 function show_ldap_error($message, $addon= "")
1359 {
1360 if (!preg_match("/Success/i", $message)){
1361 if ($addon == ""){
1362 print_red (_("LDAP error: $message"));
1363 } else {
1364 print_red ("$addon<br><br><b>"._("LDAP error:")."</b> $message");
1365 }
1366 return TRUE;
1367 } else {
1368 return FALSE;
1369 }
1370 }
1373 function rewrite($s)
1374 {
1375 global $REWRITE;
1377 foreach ($REWRITE as $key => $val){
1378 $s= preg_replace("/$key/", "$val", $s);
1379 }
1381 return ($s);
1382 }
1385 function dn2base($dn)
1386 {
1387 global $config;
1389 if (get_people_ou() != ""){
1390 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1391 }
1392 if (get_groups_ou() != ""){
1393 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1394 }
1395 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1397 return ($base);
1398 }
1402 function check_command($cmdline)
1403 {
1404 $cmd= preg_replace("/ .*$/", "", $cmdline);
1406 /* Check if command exists in filesystem */
1407 if (!file_exists($cmd)){
1408 return (FALSE);
1409 }
1411 /* Check if command is executable */
1412 if (!is_executable($cmd)){
1413 return (FALSE);
1414 }
1416 return (TRUE);
1417 }
1420 function print_header($image, $headline, $info= "")
1421 {
1422 $display= "<div class=\"plugtop\">\n";
1423 $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";
1424 $display.= "</div>\n";
1426 if ($info != ""){
1427 $display.= "<div class=\"pluginfo\">\n";
1428 $display.= "$info";
1429 $display.= "</div>\n";
1430 } else {
1431 $display.= "<div style=\"height:5px;\">\n";
1432 $display.= " ";
1433 $display.= "</div>\n";
1434 }
1435 # if (isset($_SESSION['errors'])){
1436 # $display.= $_SESSION['errors'];
1437 # }
1439 return ($display);
1440 }
1443 function register_global($name, $object)
1444 {
1445 $_SESSION[$name]= $object;
1446 }
1449 function is_global($name)
1450 {
1451 return isset($_SESSION[$name]);
1452 }
1455 function get_global($name)
1456 {
1457 return $_SESSION[$name];
1458 }
1461 function range_selector($dcnt,$start,$range=25,$post_var=false)
1462 {
1464 /* Entries shown left and right from the selected entry */
1465 $max_entries= 10;
1467 /* Initialize and take care that max_entries is even */
1468 $output="";
1469 if ($max_entries & 1){
1470 $max_entries++;
1471 }
1473 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1474 $range= $_POST[$post_var];
1475 }
1477 /* Prevent output to start or end out of range */
1478 if ($start < 0 ){
1479 $start= 0 ;
1480 }
1481 if ($start >= $dcnt){
1482 $start= $range * (int)(($dcnt / $range) + 0.5);
1483 }
1485 $numpages= (($dcnt / $range));
1486 if(((int)($numpages))!=($numpages)){
1487 $numpages = (int)$numpages + 1;
1488 }
1489 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1490 return ("");
1491 }
1492 $ppage= (int)(($start / $range) + 0.5);
1495 /* Align selected page to +/- max_entries/2 */
1496 $begin= $ppage - $max_entries/2;
1497 $end= $ppage + $max_entries/2;
1499 /* Adjust begin/end, so that the selected value is somewhere in
1500 the middle and the size is max_entries if possible */
1501 if ($begin < 0){
1502 $end-= $begin + 1;
1503 $begin= 0;
1504 }
1505 if ($end > $numpages) {
1506 $end= $numpages;
1507 }
1508 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1509 $begin= $end - $max_entries;
1510 }
1512 if($post_var){
1513 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1514 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1515 }else{
1516 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1517 }
1519 /* Draw decrement */
1520 if ($start > 0 ) {
1521 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1522 (($start-$range))."\">".
1523 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1524 }
1526 /* Draw pages */
1527 for ($i= $begin; $i < $end; $i++) {
1528 if ($ppage == $i){
1529 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1530 validate($_GET['plug'])."&start=".
1531 ($i*$range)."\"> ".($i+1)." </a>";
1532 } else {
1533 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1534 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1535 }
1536 }
1538 /* Draw increment */
1539 if($start < ($dcnt-$range)) {
1540 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1541 (($start+($range)))."\">".
1542 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1543 }
1545 if(($post_var)&&($numpages)){
1546 $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()'>";
1547 foreach(array(20,50,100,200,"all") as $num){
1548 if($num == "all"){
1549 $var = 10000;
1550 }else{
1551 $var = $num;
1552 }
1553 if($var == $range){
1554 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1555 }else{
1556 $output.="\n<option value='".$var."'>".$num."</option>";
1557 }
1558 }
1559 $output.= "</select></td></tr></table></div>";
1560 }else{
1561 $output.= "</div>";
1562 }
1564 return($output);
1565 }
1568 function apply_filter()
1569 {
1570 $apply= "";
1572 $apply= ''.
1573 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1574 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1576 return ($apply);
1577 }
1580 function back_to_main()
1581 {
1582 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1583 _("Back").'"></p><input type="hidden" name="ignore">';
1585 return ($string);
1586 }
1589 function normalize_netmask($netmask)
1590 {
1591 /* Check for notation of netmask */
1592 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1593 $num= (int)($netmask);
1594 $netmask= "";
1596 for ($byte= 0; $byte<4; $byte++){
1597 $result=0;
1599 for ($i= 7; $i>=0; $i--){
1600 if ($num-- > 0){
1601 $result+= pow(2,$i);
1602 }
1603 }
1605 $netmask.= $result.".";
1606 }
1608 return (preg_replace('/\.$/', '', $netmask));
1609 }
1611 return ($netmask);
1612 }
1615 function netmask_to_bits($netmask)
1616 {
1617 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1618 $res= 0;
1620 for ($n= 0; $n<4; $n++){
1621 $start= 255;
1622 $name= "nm$n";
1624 for ($i= 0; $i<8; $i++){
1625 if ($start == (int)($$name)){
1626 $res+= 8 - $i;
1627 break;
1628 }
1629 $start-= pow(2,$i);
1630 }
1631 }
1633 return ($res);
1634 }
1637 function recurse($rule, $variables)
1638 {
1639 $result= array();
1641 if (!count($variables)){
1642 return array($rule);
1643 }
1645 reset($variables);
1646 $key= key($variables);
1647 $val= current($variables);
1648 unset ($variables[$key]);
1650 foreach($val as $possibility){
1651 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1652 $result= array_merge($result, recurse($nrule, $variables));
1653 }
1655 return ($result);
1656 }
1659 function expand_id($rule, $attributes)
1660 {
1661 /* Check for id rule */
1662 if(preg_match('/^id(:|#)\d+$/',$rule)){
1663 return (array("\{$rule}"));
1664 }
1666 /* Check for clean attribute */
1667 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1668 $rule= preg_replace('/^%/', '', $rule);
1669 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1670 return (array($val));
1671 }
1673 /* Check for attribute with parameters */
1674 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1675 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1676 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1677 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1678 $start= preg_replace ('/-.*$/', '', $param);
1679 $stop = preg_replace ('/^[^-]+-/', '', $param);
1681 /* Assemble results */
1682 $result= array();
1683 for ($i= $start; $i<= $stop; $i++){
1684 $result[]= substr($val, 0, $i);
1685 }
1686 return ($result);
1687 }
1689 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1690 return (array($rule));
1691 }
1694 function gen_uids($rule, $attributes)
1695 {
1696 global $config;
1698 /* Search for keys and fill the variables array with all
1699 possible values for that key. */
1700 $part= "";
1701 $trigger= false;
1702 $stripped= "";
1703 $variables= array();
1705 for ($pos= 0; $pos < strlen($rule); $pos++){
1707 if ($rule[$pos] == "{" ){
1708 $trigger= true;
1709 $part= "";
1710 continue;
1711 }
1713 if ($rule[$pos] == "}" ){
1714 $variables[$pos]= expand_id($part, $attributes);
1715 $stripped.= "\{$pos}";
1716 $trigger= false;
1717 continue;
1718 }
1720 if ($trigger){
1721 $part.= $rule[$pos];
1722 } else {
1723 $stripped.= $rule[$pos];
1724 }
1725 }
1727 /* Recurse through all possible combinations */
1728 $proposed= recurse($stripped, $variables);
1730 /* Get list of used ID's */
1731 $used= array();
1732 $ldap= $config->get_ldap_link();
1733 $ldap->cd($config->current['BASE']);
1734 $ldap->search('(uid=*)');
1736 while($attrs= $ldap->fetch()){
1737 $used[]= $attrs['uid'][0];
1738 }
1740 /* Remove used uids and watch out for id tags */
1741 $ret= array();
1742 foreach($proposed as $uid){
1744 /* Check for id tag and modify uid if needed */
1745 if(preg_match('/\{id:\d+}/',$uid)){
1746 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1748 for ($i= 0; $i < pow(10,$size); $i++){
1749 $number= sprintf("%0".$size."d", $i);
1750 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1751 if (!in_array($res, $used)){
1752 $uid= $res;
1753 break;
1754 }
1755 }
1756 }
1758 if(preg_match('/\{id#\d+}/',$uid)){
1759 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1761 while (true){
1762 mt_srand((double) microtime()*1000000);
1763 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1764 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1765 if (!in_array($res, $used)){
1766 $uid= $res;
1767 break;
1768 }
1769 }
1770 }
1772 /* Don't assign used ones */
1773 if (!in_array($uid, $used)){
1774 $ret[]= $uid;
1775 }
1776 }
1778 return(array_unique($ret));
1779 }
1782 function array_search_r($needle, $key, $haystack){
1784 foreach($haystack as $index => $value){
1785 $match= 0;
1787 if (is_array($value)){
1788 $match= array_search_r($needle, $key, $value);
1789 }
1791 if ($index==$key && !is_array($value) && preg_match("/$needle/i", $value)){
1792 $match=1;
1793 }
1795 if ($match){
1796 return 1;
1797 }
1798 }
1800 return 0;
1801 }
1804 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1805 Need to convert... */
1806 function to_byte($value) {
1807 $value= strtolower(trim($value));
1809 if(!is_numeric(substr($value, -1))) {
1811 switch(substr($value, -1)) {
1812 case 'g':
1813 $mult= 1073741824;
1814 break;
1815 case 'm':
1816 $mult= 1048576;
1817 break;
1818 case 'k':
1819 $mult= 1024;
1820 break;
1821 }
1823 return ($mult * (int)substr($value, 0, -1));
1824 } else {
1825 return $value;
1826 }
1827 }
1830 function in_array_ics($value, $items)
1831 {
1832 if (!is_array($items)){
1833 return (FALSE);
1834 }
1836 foreach ($items as $item){
1837 if (strtolower($item) == strtolower($value)) {
1838 return (TRUE);
1839 }
1840 }
1842 return (FALSE);
1843 }
1846 function generate_alphabet($count= 10)
1847 {
1848 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1849 $alphabet= "";
1850 $c= 0;
1852 /* Fill cells with charaters */
1853 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1854 if ($c == 0){
1855 $alphabet.= "<tr>";
1856 }
1858 $ch = mb_substr($characters, $i, 1, "UTF8");
1859 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1860 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1862 if ($c++ == $count){
1863 $alphabet.= "</tr>";
1864 $c= 0;
1865 }
1866 }
1868 /* Fill remaining cells */
1869 while ($c++ <= $count){
1870 $alphabet.= "<td> </td>";
1871 }
1873 return ($alphabet);
1874 }
1877 function validate($string)
1878 {
1879 return (strip_tags(preg_replace('/\0/', '', $string)));
1880 }
1882 function get_gosa_version()
1883 {
1884 global $svn_revision, $svn_path;
1886 /* Extract informations */
1887 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1889 /* Release or development? */
1890 if (preg_match('%/gosa/trunk/%', $svn_path)){
1891 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1892 } else {
1893 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1894 return (_("GOsa $release"));
1895 }
1896 }
1899 function rmdirRecursive($path, $followLinks=false) {
1900 $dir= opendir($path);
1901 while($entry= readdir($dir)) {
1902 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1903 unlink($path."/".$entry);
1904 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1905 rmdirRecursive($path."/".$entry);
1906 }
1907 }
1908 closedir($dir);
1909 return rmdir($path);
1910 }
1912 function scan_directory($path,$sort_desc=false)
1913 {
1914 $ret = false;
1916 /* is this a dir ? */
1917 if(is_dir($path)) {
1919 /* is this path a readable one */
1920 if(is_readable($path)){
1922 /* Get contents and write it into an array */
1923 $ret = array();
1925 $dir = opendir($path);
1927 /* Is this a correct result ?*/
1928 if($dir){
1929 while($fp = readdir($dir))
1930 $ret[]= $fp;
1931 }
1932 }
1933 }
1934 /* Sort array ascending , like scandir */
1935 sort($ret);
1937 /* Sort descending if parameter is sort_desc is set */
1938 if($sort_desc) {
1939 $ret = array_reverse($ret);
1940 }
1942 return($ret);
1943 }
1945 function clean_smarty_compile_dir($directory)
1946 {
1947 global $svn_revision;
1949 if(is_dir($directory) && is_readable($directory)) {
1950 // Set revision filename to REVISION
1951 $revision_file= $directory."/REVISION";
1953 /* Is there a stamp containing the current revision? */
1954 if(!file_exists($revision_file)) {
1955 // create revision file
1956 create_revision($revision_file, $svn_revision);
1957 } else {
1958 # check for "$config->...['CONFIG']/revision" and the
1959 # contents should match the revision number
1960 if(!compare_revision($revision_file, $svn_revision)){
1961 // If revision differs, clean compile directory
1962 foreach(scan_directory($directory) as $file) {
1963 if(($file==".")||($file=="..")) continue;
1964 if( is_file($directory."/".$file) &&
1965 is_writable($directory."/".$file)) {
1966 // delete file
1967 if(!unlink($directory."/".$file)) {
1968 print_red("File ".$directory."/".$file." could not be deleted.");
1969 // This should never be reached
1970 }
1971 } elseif(is_dir($directory."/".$file) &&
1972 is_writable($directory."/".$file)) {
1973 // Just recursively delete it
1974 rmdirRecursive($directory."/".$file);
1975 }
1976 }
1977 // We should now create a fresh revision file
1978 clean_smarty_compile_dir($directory);
1979 } else {
1980 // Revision matches, nothing to do
1981 }
1982 }
1983 } else {
1984 // Smarty compile dir is not accessible
1985 // (Smarty will warn about this)
1986 }
1987 }
1989 function create_revision($revision_file, $revision)
1990 {
1991 $result= false;
1993 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1994 if($fh= fopen($revision_file, "w")) {
1995 if(fwrite($fh, $revision)) {
1996 $result= true;
1997 }
1998 }
1999 fclose($fh);
2000 } else {
2001 print_red("Can not write to revision file");
2002 }
2004 return $result;
2005 }
2007 function compare_revision($revision_file, $revision)
2008 {
2009 // false means revision differs
2010 $result= false;
2012 if(file_exists($revision_file) && is_readable($revision_file)) {
2013 // Open file
2014 if($fh= fopen($revision_file, "r")) {
2015 // Compare File contents with current revision
2016 if($revision == fread($fh, filesize($revision_file))) {
2017 $result= true;
2018 }
2019 } else {
2020 print_red("Can not open revision file");
2021 }
2022 // Close file
2023 fclose($fh);
2024 }
2026 return $result;
2027 }
2029 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
2030 {
2031 $str = ""; // Our return value will be saved in this var
2033 $color = dechex($percentage+150);
2034 $color2 = dechex(150 - $percentage);
2035 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2037 $progress = (int)(($percentage /100)*$width);
2039 /* Abort printing out percentage, if divs are to small */
2042 /* If theres a better solution for this, use it... */
2043 $str = "
2044 <div style=\" width:".($width)."px;
2045 height:".($height)."px;
2046 background-color:#000000;
2047 padding:1px;\">
2049 <div style=\" width:".($width)."px;
2050 background-color:#$bgcolor;
2051 height:".($height)."px;\">
2053 <div style=\" width:".$progress."px;
2054 height:".$height."px;
2055 background-color:#".$color2.$color2.$color."; \">";
2058 if(($height >10)&&($showvalue)){
2059 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2060 <b>".$percentage."%</b>
2061 </font>";
2062 }
2064 $str.= "</div></div></div>";
2066 return($str);
2067 }
2070 function array_key_ics($ikey, $items)
2071 {
2072 /* Gather keys, make them lowercase */
2073 $tmp= array();
2074 foreach ($items as $key => $value){
2075 $tmp[strtolower($key)]= $key;
2076 }
2078 if (isset($tmp[strtolower($ikey)])){
2079 return($tmp[strtolower($ikey)]);
2080 }
2082 return ("");
2083 }
2086 function search_config($arr, $name, $return)
2087 {
2088 if (is_array($arr)){
2089 foreach ($arr as $a){
2090 if (isset($a['CLASS']) &&
2091 strtolower($a['CLASS']) == strtolower($name)){
2093 if (isset($a[$return])){
2094 return ($a[$return]);
2095 } else {
2096 return ("");
2097 }
2098 } else {
2099 $res= search_config ($a, $name, $return);
2100 if ($res != ""){
2101 return $res;
2102 }
2103 }
2104 }
2105 }
2106 return ("");
2107 }
2110 function array_differs($src, $dst)
2111 {
2112 /* If the count is differing, the arrays differ */
2113 if (count ($src) != count ($dst)){
2114 return (TRUE);
2115 }
2117 /* So the count is the same - lets check the contents */
2118 $differs= FALSE;
2119 foreach($src as $value){
2120 if (!in_array($value, $dst)){
2121 $differs= TRUE;
2122 }
2123 }
2125 return ($differs);
2126 }
2129 function saveFilter($a_filter, $values)
2130 {
2131 if (isset($_POST['regexit'])){
2132 $a_filter["regex"]= $_POST['regexit'];
2134 foreach($values as $type){
2135 if (isset($_POST[$type])) {
2136 $a_filter[$type]= "checked";
2137 } else {
2138 $a_filter[$type]= "";
2139 }
2140 }
2141 }
2143 /* React on alphabet links if needed */
2144 if (isset($_GET['search'])){
2145 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2146 if ($s == "**"){
2147 $s= "*";
2148 }
2149 $a_filter['regex']= $s;
2150 }
2152 return ($a_filter);
2153 }
2156 /* Escape all preg_* relevant characters */
2157 function normalizePreg($input)
2158 {
2159 return (addcslashes($input, '[]()|/.*+-'));
2160 }
2163 /* Escape all LDAP filter relevant characters */
2164 function normalizeLdap($input)
2165 {
2166 return (addcslashes($input, '()|'));
2167 }
2170 /* Resturns the difference between to microtime() results in float */
2171 function get_MicroTimeDiff($start , $stop)
2172 {
2173 $a = split("\ ",$start);
2174 $b = split("\ ",$stop);
2176 $secs = $b[1] - $a[1];
2177 $msecs= $b[0] - $a[0];
2179 $ret = (float) ($secs+ $msecs);
2180 return($ret);
2181 }
2184 /* Check if the given department name is valid */
2185 function is_department_name_reserved($name,$base)
2186 {
2187 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2188 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2189 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2190 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2192 /* Check if name is one of the reserved names */
2193 if(in_array_ics($name,$reservedName)) {
2194 return(true);
2195 }
2197 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2198 foreach($follwedNames as $key => $names){
2199 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2200 return(true);
2201 }
2202 }
2203 return(false);
2204 }
2207 function is_php4()
2208 {
2209 if (isset($_SESSION['PHP4COMPATIBLE'])){
2210 return true;
2211 }
2212 return (preg_match('/^4/', phpversion()));
2213 }
2216 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2217 {
2218 /* Initialize variables */
2219 $ret = array("count" => 0); // Set count to 0
2220 $next = true; // if false, then skip next loops and return
2221 $cnt = 0; // Current number of loops
2222 $max = 100; // Just for security, prevent looops
2223 $ldap = NULL; // To check if created result a valid
2224 $keep = ""; // save last failed parse string
2226 /* Check each parsed dn in ldap ? */
2227 if($config!=NULL && $verify_in_ldap){
2228 $ldap = $config->get_ldap_link();
2229 }
2231 /* Lets start */
2232 $called = false;
2233 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2235 $cnt ++;
2236 if(!preg_match("/,/",$dn)){
2237 $next = false;
2238 }
2239 $object = preg_replace("/[,].*$/","",$dn);
2240 $dn = preg_replace("/^[^,]+,/","",$dn);
2242 $called = true;
2244 /* Check if current dn is valid */
2245 if($ldap!=NULL){
2246 $ldap->cd($dn);
2247 $ldap->cat($dn,array("dn"));
2248 if($ldap->count()){
2249 $ret[] = $keep.$object;
2250 $keep = "";
2251 }else{
2252 $keep .= $object.",";
2253 }
2254 }else{
2255 $ret[] = $keep.$object;
2256 $keep = "";
2257 }
2258 }
2260 /* No dn was posted */
2261 if($cnt == 0 && !empty($dn)){
2262 $ret[] = $dn;
2263 }
2265 /* Append the rest */
2266 $test = $keep.$dn;
2267 if($called && !empty($test)){
2268 $ret[] = $keep.$dn;
2269 }
2270 $ret['count'] = count($ret) - 1;
2272 return($ret);
2273 }
2276 function get_base_from_hook($dn, $attrib)
2277 {
2278 global $config;
2280 if (isset($config->current['BASE_HOOK'])){
2282 /* Call hook script - if present */
2283 $command= $config->current['BASE_HOOK'];
2285 if ($command != ""){
2286 $command.= " '$dn' $attrib";
2287 if (check_command($command)){
2288 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2289 exec($command, $output);
2290 if (preg_match("/^[0-9]+$/", $output[0])){
2291 return ($output[0]);
2292 } else {
2293 print_red(_("Warning - base_hook is not available. Using default base."));
2294 return ($config->current['UIDBASE']);
2295 }
2296 } else {
2297 print_red(_("Warning - base_hook is not available. Using default base."));
2298 return ($config->current['UIDBASE']);
2299 }
2301 } else {
2303 print_red(_("Warning - no base_hook defined. Using default base."));
2304 return ($config->current['UIDBASE']);
2306 }
2307 }
2308 }
2310 /* Schema validation functions */
2312 function check_schema_version($class, $version)
2313 {
2314 return preg_match("/\(v$version\)/", $class['DESC']);
2315 }
2319 function check_schema($cfg,$rfc2307bis = FALSE)
2320 {
2322 $messages= array();
2324 /* Get objectclasses */
2325 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2326 $objectclasses = $ldap->get_objectclasses();
2327 if(count($objectclasses) == 0){
2328 print_red(_("Can't get schema information from server. No schema check possible!"));
2329 }
2331 /* This is the default block used for each entry.
2332 * to avoid unset indexes.
2333 */
2334 $def_check = array("REQUIRED_VERSION" => "0",
2335 "SCHEMA_FILES" => array(),
2336 "CLASSES_REQUIRED" => array(),
2337 "STATUS" => FALSE,
2338 "IS_MUST_HAVE" => FALSE,
2339 "MSG" => "",
2340 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2342 /* The gosa base schema */
2343 $checks['gosaObject'] = $def_check;
2344 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2345 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2346 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2347 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2349 /* GOsa Account class */
2350 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2351 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2352 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2353 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2354 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2356 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2357 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2358 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2359 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2360 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2361 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2363 /* Some other checks */
2364 foreach(array(
2365 "gosaCacheEntry" => array("version" => "2.4"),
2366 "gosaDepartment" => array("version" => "2.4"),
2367 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2368 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2369 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2370 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2371 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2372 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2373 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2374 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2375 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2376 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2377 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2378 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2379 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2380 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2381 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2382 "goLdapServer" => array("version" => "2.4"),
2383 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2384 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2385 "goKrbServer" => array("version" => "2.4"),
2386 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2387 ) as $name => $values){
2389 $checks[$name] = $def_check;
2390 if(isset($values['version'])){
2391 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2392 }
2393 if(isset($values['file'])){
2394 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2395 }
2396 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2397 }
2398 foreach($checks as $name => $value){
2399 foreach($value['CLASSES_REQUIRED'] as $class){
2401 if(!isset($objectclasses[$name])){
2402 $checks[$name]['STATUS'] = FALSE;
2403 if($value['IS_MUST_HAVE']){
2404 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2405 }else{
2406 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2407 }
2408 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2409 $checks[$name]['STATUS'] = FALSE;
2411 if($value['IS_MUST_HAVE']){
2412 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2413 }else{
2414 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2415 }
2416 }else{
2417 $checks[$name]['STATUS'] = TRUE;
2418 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2419 }
2420 }
2421 }
2423 $tmp = $objectclasses;
2426 /* The gosa base schema */
2427 $checks['posixGroup'] = $def_check;
2428 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2429 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2430 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2431 $checks['posixGroup']['STATUS'] = TRUE;
2432 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2433 $checks['posixGroup']['MSG'] = "";
2434 $checks['posixGroup']['INFO'] = "";
2436 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2437 if(isset($tmp['posixGroup'])){
2439 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2440 $checks['posixGroup']['STATUS'] = FALSE;
2441 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2442 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2443 }
2444 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2445 $checks['posixGroup']['STATUS'] = FALSE;
2446 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2447 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2448 }
2449 }
2451 return($checks);
2452 }
2455 function prepare4mailbody($string)
2456 {
2457 $string = html_entity_decode($string);
2459 $from = array(
2460 "/%/",
2461 "/ /",
2462 "/\n/",
2463 "/\r/",
2464 "/!/",
2465 "/#/",
2466 "/\*/",
2467 "/\//",
2468 "/</",
2469 "/>/",
2470 "/\?/",
2471 "/(\'|\")/");
2473 $to = array(
2474 "%25",
2475 "%20",
2476 "%0A",
2477 "%0D",
2478 "%21",
2479 "%23",
2480 "%2A",
2481 "%2F",
2482 "%3C",
2483 "%3E",
2484 "%3F",
2485 "%22");
2487 $string = preg_replace($from,$to,$string);
2489 return($string);
2490 }
2493 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
2494 ?>