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_TEMPLATE_DIR", "../contrib/");
24 define ("HELP_BASEDIR", "/home/cajus/");
26 /* Define globals for revision comparing */
27 $svn_path = '$HeadURL$';
28 $svn_revision = '$Revision$';
30 /* Include required files */
31 require_once ("class_ldap.inc");
32 require_once ("class_config.inc");
33 require_once ("class_userinfo.inc");
34 require_once ("class_plugin.inc");
35 require_once ("class_pluglist.inc");
36 require_once ("class_tabs.inc");
37 require_once ("class_mail-methods.inc");
38 require_once("class_password-methods.inc");
39 require_once ("functions_debug.inc");
41 /* Define constants for debugging */
42 define ("DEBUG_TRACE", 1);
43 define ("DEBUG_LDAP", 2);
44 define ("DEBUG_MYSQL", 4);
45 define ("DEBUG_SHELL", 8);
46 define ("DEBUG_POST", 16);
47 define ("DEBUG_SESSION",32);
48 define ("DEBUG_CONFIG", 64);
50 /* Rewrite german 'umlauts' and spanish 'accents'
51 to get better results */
52 $REWRITE= array( "ä" => "ae",
53 "ö" => "oe",
54 "ü" => "ue",
55 "Ä" => "Ae",
56 "Ö" => "Oe",
57 "Ü" => "Ue",
58 "ß" => "ss",
59 "á" => "a",
60 "é" => "e",
61 "í" => "i",
62 "ó" => "o",
63 "ú" => "u",
64 "Á" => "A",
65 "É" => "E",
66 "Í" => "I",
67 "Ó" => "O",
68 "Ú" => "U",
69 "ñ" => "ny",
70 "Ñ" => "Ny" );
73 /* Function to include all class_ files starting at a
74 given directory base */
75 function get_dir_list($folder= ".")
76 {
77 $currdir=getcwd();
78 if ($folder){
79 chdir("$folder");
80 }
82 $dh = opendir(".");
83 while(false !== ($file = readdir($dh))){
85 /* Recurse through all "common" directories */
86 if(is_dir($file) && $file!="." && $file!=".." && $file!="CVS"){
87 get_dir_list($file);
88 continue;
89 }
91 /* Include existing class_ files */
92 if (!is_dir($file) && preg_match("/^class_.*\.inc$/", $file)) {
93 require_once($file);
94 }
95 }
97 closedir($dh);
98 chdir($currdir);
99 }
102 /* Create seed with microseconds */
103 function make_seed() {
104 list($usec, $sec) = explode(' ', microtime());
105 return (float) $sec + ((float) $usec * 100000);
106 }
109 /* Debug level action */
110 function DEBUG($level, $line, $function, $file, $data, $info="")
111 {
112 if ($_SESSION['DEBUGLEVEL'] & $level){
113 $output= "DEBUG[$level] ";
114 if ($function != ""){
115 $output.= "($file:$function():$line) - $info: ";
116 } else {
117 $output.= "($file:$line) - $info: ";
118 }
119 echo $output;
120 if (is_array($data)){
121 print_a($data);
122 } else {
123 echo "'$data'";
124 }
125 echo "<br>";
126 }
127 }
130 /* Simple function to get browser language and convert it to
131 xx_XY needed by locales. Ignores sublanguages and weights. */
132 function get_browser_language()
133 {
134 global $BASE_DIR;
136 /* Get list of languages */
137 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
138 $lang= preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
139 $languages= split (',', $lang);
140 $languages[]= "C";
141 } else {
142 $languages= array("C");
143 }
145 /* Walk through languages and get first supported */
146 foreach ($languages as $val){
148 /* Strip off weight */
149 $lang= preg_replace("/;q=.*$/i", "", $val);
151 /* Simplify sub language handling */
152 $lang= preg_replace("/-.*$/", "", $lang);
154 /* Cancel loop if available in GOsa, or the last
155 entry has been reached */
156 if (is_dir("$BASE_DIR/locale/$lang")){
157 break;
158 }
159 }
161 return (strtolower($lang)."_".strtoupper($lang));
162 }
165 /* Rewrite ui object to another dn */
166 function change_ui_dn($dn, $newdn)
167 {
168 $ui= $_SESSION['ui'];
169 if ($ui->dn == $dn){
170 $ui->dn= $newdn;
171 $_SESSION['ui']= $ui;
172 }
173 }
176 /* Return theme path for specified file */
177 function get_template_path($filename= '', $plugin= FALSE, $path= "")
178 {
179 global $config, $BASE_DIR;
181 if (!@isset($config->data['MAIN']['THEME'])){
182 $theme= 'default';
183 } else {
184 $theme= $config->data['MAIN']['THEME'];
185 }
187 /* Return path for empty filename */
188 if ($filename == ''){
189 return ("themes/$theme/");
190 }
192 /* Return plugin dir or root directory? */
193 if ($plugin){
194 if ($path == ""){
195 $nf= preg_replace("!^".$BASE_DIR."/!", "", $_SESSION['plugin_dir']);
196 } else {
197 $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
198 }
199 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
200 return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
201 }
202 if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
203 return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
204 }
205 if ($path == ""){
206 return ($_SESSION['plugin_dir']."/$filename");
207 } else {
208 return ($path."/$filename");
209 }
210 } else {
211 if (file_exists("themes/$theme/$filename")){
212 return ("themes/$theme/$filename");
213 }
214 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
215 return ("$BASE_DIR/ihtml/themes/$theme/$filename");
216 }
217 if (file_exists("themes/default/$filename")){
218 return ("themes/default/$filename");
219 }
220 if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
221 return ("$BASE_DIR/ihtml/themes/default/$filename");
222 }
223 return ($filename);
224 }
225 }
228 function array_remove_entries($needles, $haystack)
229 {
230 $tmp= array();
232 /* Loop through entries to be removed */
233 foreach ($haystack as $entry){
234 if (!in_array($entry, $needles)){
235 $tmp[]= $entry;
236 }
237 }
239 return ($tmp);
240 }
243 function gosa_log ($message)
244 {
245 global $ui;
247 /* Preset to something reasonable */
248 $username= " unauthenticated";
250 /* Replace username if object is present */
251 if (isset($ui)){
252 if ($ui->username != ""){
253 $username= "[$ui->username]";
254 } else {
255 $username= "unknown";
256 }
257 }
259 syslog(LOG_INFO,"GOsa$username: $message");
260 }
263 function ldap_init ($server, $base, $binddn='', $pass='')
264 {
265 global $config;
267 $ldap = new LDAP ($binddn, $pass, $server, isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
268 isset($config->current['TLS']) && $config->current['TLS'] == "true");
270 /* Sadly we've no proper return values here. Use the error message instead. */
271 if (!preg_match("/Success/i", $ldap->error)){
272 print_red(sprintf(_("Error when connecting the LDAP. Server said '%s'."),
273 $ldap->get_error()));
274 echo $_SESSION['errors'];
276 /* Hard error. We'd like to use the LDAP, anyway... */
277 exit;
278 }
280 /* Preset connection base to $base and return to caller */
281 $ldap->cd ($base);
282 return $ldap;
283 }
286 function ldap_login_user ($username, $password)
287 {
288 global $config;
290 /* look through the entire ldap */
291 $ldap = $config->get_ldap_link();
292 if (!preg_match("/Success/i", $ldap->error)){
293 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
294 echo $_SESSION['errors'];
295 exit;
296 }
297 $ldap->cd($config->current['BASE']);
298 $ldap->search("(&(uid=$username)(objectClass=gosaAccount))", array("uid"));
300 /* get results, only a count of 1 is valid */
301 switch ($ldap->count()){
303 /* user not found */
304 case 0: return (NULL);
306 /* valid uniq user */
307 case 1:
308 break;
310 /* found more than one matching id */
311 default:
312 print_red(_("Username / UID is not unique. Please check your LDAP database."));
313 return (NULL);
314 }
316 /* LDAP schema is not case sensitive. Perform additional check. */
317 $attrs= $ldap->fetch();
318 if ($attrs['uid'][0] != $username){
319 return(NULL);
320 }
322 /* got user dn, fill acl's */
323 $ui= new userinfo($config, $ldap->getDN());
324 $ui->username= $username;
326 /* password check, bind as user with supplied password */
327 $ldap->disconnect();
328 $ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
329 isset($config->current['RECURSIVE']) &&
330 $config->current['RECURSIVE'] == "true",
331 isset($config->current['TLS'])
332 && $config->current['TLS'] == "true");
333 if (!preg_match("/Success/i", $ldap->error)){
334 return (NULL);
335 }
337 /* Username is set, load subtreeACL's now */
338 $ui->loadACL();
340 return ($ui);
341 }
344 function add_lock ($object, $user)
345 {
346 global $config;
348 /* Just a sanity check... */
349 if ($object == "" || $user == ""){
350 print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
351 return;
352 }
354 /* Check for existing entries in lock area */
355 $ldap= $config->get_ldap_link();
356 $ldap->cd ($config->current['CONFIG']);
357 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=$object))",
358 array("gosaUser"));
359 if (!preg_match("/Success/i", $ldap->error)){
360 print_red (sprintf(_("Can't set locking information in LDAP database. Please check the 'config' entry in gosa.conf! LDAP server says '%s'."), $ldap->get_error()));
361 return;
362 }
364 /* Add lock if none present */
365 if ($ldap->count() == 0){
366 $attrs= array();
367 $name= md5($object);
368 $ldap->cd("cn=$name,".$config->current['CONFIG']);
369 $attrs["objectClass"] = "gosaLockEntry";
370 $attrs["gosaUser"] = $user;
371 $attrs["gosaObject"] = $object;
372 $attrs["cn"] = "$name";
373 $ldap->add($attrs);
374 if (!preg_match("/Success/i", $ldap->error)){
375 print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
376 $ldap->get_error()));
377 return;
378 }
379 }
380 }
383 function del_lock ($object)
384 {
385 global $config;
387 /* Sanity check */
388 if ($object == ""){
389 return;
390 }
392 /* Check for existance and remove the entry */
393 $ldap= $config->get_ldap_link();
394 $ldap->cd ($config->current['CONFIG']);
395 $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=$object))", array("gosaObject"));
396 $attrs= $ldap->fetch();
397 if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){
398 $ldap->rmdir ($ldap->getDN());
400 if (!preg_match("/Success/i", $ldap->error)){
401 print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
402 $ldap->get_error()));
403 return;
404 }
405 }
406 }
409 function del_user_locks($userdn)
410 {
411 global $config;
413 /* Get LDAP ressources */
414 $ldap= $config->get_ldap_link();
415 $ldap->cd ($config->current['CONFIG']);
417 /* Remove all objects of this user, drop errors silently in this case. */
418 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
419 while ($attrs= $ldap->fetch()){
420 $ldap->rmdir($attrs['dn']);
421 }
422 }
425 function get_lock ($object)
426 {
427 global $config;
429 /* Sanity check */
430 if ($object == ""){
431 print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
432 return("");
433 }
435 /* Get LDAP link, check for presence of the lock entry */
436 $user= "";
437 $ldap= $config->get_ldap_link();
438 $ldap->cd ($config->current['CONFIG']);
439 $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=$object))", array("gosaUser"));
440 if (!preg_match("/Success/i", $ldap->error)){
441 print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
442 return("");
443 }
445 /* Check for broken locking information in LDAP */
446 if ($ldap->count() > 1){
448 /* Hmm. We're removing broken LDAP information here and issue a warning. */
449 print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
451 /* Clean up these references now... */
452 while ($attrs= $ldap->fetch()){
453 $ldap->rmdir($attrs['dn']);
454 }
456 return("");
458 } elseif ($ldap->count() == 1){
459 $attrs = $ldap->fetch();
460 $user= $attrs['gosaUser'][0];
461 }
463 return ($user);
464 }
467 function get_list2($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= array(), $flag= FALSE)
468 {
469 global $config;
471 /* Base the search on default base if not set */
472 $ldap= $config->get_ldap_link($flag);
473 if ($base == ""){
474 $ldap->cd ($config->current['BASE']);
475 } else {
476 $ldap->cd ($base);
477 }
479 /* Perform ONE or SUB scope searches? */
480 $ldap->ls ($filter);
482 /* Check for size limit exceeded messages for GUI feedback */
483 if (preg_match("/size limit/i", $ldap->error)){
484 $_SESSION['limit_exceeded']= TRUE;
485 } else {
486 $_SESSION['limit_exceeded']= FALSE;
487 }
488 $result= array();
491 /* Crawl through reslut entries and perform the migration to the
492 result array */
493 while($attrs = $ldap->fetch()) {
494 $dn= preg_replace("/[ ]*,[ ]*/", ",", $ldap->getDN());
495 foreach ($subtreeACL as $key => $value){
496 if (preg_match("/$key/", $dn)){
497 $attrs["dn"]= convert_department_dn($dn);
498 $result[]= $attrs;
499 break;
500 }
501 }
502 }
505 return ($result);
507 }
509 function get_list($subtreeACL, $filter, $subsearch= TRUE, $base="", $attrs= array(), $flag= FALSE)
510 {
511 global $config;
513 /* Base the search on default base if not set */
514 $ldap= $config->get_ldap_link($flag);
515 if ($base == ""){
516 $ldap->cd ($config->current['BASE']);
517 } else {
518 $ldap->cd ($base);
519 }
521 /* Perform ONE or SUB scope searches? */
522 if ($subsearch) {
523 $ldap->search ($filter, $attrs);
524 } else {
525 $ldap->ls ($filter);
526 }
528 /* Check for size limit exceeded messages for GUI feedback */
529 if (preg_match("/size limit/i", $ldap->error)){
530 $_SESSION['limit_exceeded']= TRUE;
531 } else {
532 $_SESSION['limit_exceeded']= FALSE;
533 }
535 /* Crawl through reslut entries and perform the migration to the
536 result array */
537 $result= array();
538 while($attrs = $ldap->fetch()) {
539 $dn= preg_replace("/[ ]*,[ ]*/", ",", $ldap->getDN());
540 foreach ($subtreeACL as $key => $value){
541 if (preg_match("/$key/", $dn)){
542 $attrs["dn"]= $dn;
543 $result[]= $attrs;
544 break;
545 }
546 }
547 }
549 return ($result);
550 }
553 function check_sizelimit()
554 {
555 /* Ignore dialog? */
556 if (isset($_SESSION['size_ignore']) && $_SESSION['size_ignore']){
557 return ("");
558 }
560 /* Eventually show dialog */
561 if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
562 $smarty= get_smarty();
563 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
564 $_SESSION['size_limit']));
565 $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).'">'));
566 return($smarty->fetch(get_template_path('sizelimit.tpl')));
567 }
569 return ("");
570 }
573 function print_sizelimit_warning()
574 {
575 if (isset($_SESSION['size_limit']) && $_SESSION['size_limit'] >= 10000000 ||
576 (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded'])){
577 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
578 } else {
579 $config= "";
580 }
581 if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
582 return ("("._("incomplete").") $config");
583 }
584 return ("");
585 }
588 function eval_sizelimit()
589 {
590 if (isset($_POST['set_size_action'])){
592 /* User wants new size limit? */
593 if (is_id($_POST['new_limit']) &&
594 isset($_POST['action']) && $_POST['action']=="newlimit"){
596 $_SESSION['size_limit']= validate($_POST['new_limit']);
597 $_SESSION['size_ignore']= FALSE;
598 }
600 /* User wants no limits? */
601 if (isset($_POST['action']) && $_POST['action']=="ignore"){
602 $_SESSION['size_limit']= 0;
603 $_SESSION['size_ignore']= TRUE;
604 }
606 /* User wants incomplete results */
607 if (isset($_POST['action']) && $_POST['action']=="limited"){
608 $_SESSION['size_ignore']= TRUE;
609 }
610 }
612 /* Allow fallback to dialog */
613 if (isset($_POST['edit_sizelimit'])){
614 $_SESSION['size_ignore']= FALSE;
615 }
616 }
619 function get_permissions ($dn, $subtreeACL)
620 {
621 global $config;
623 $base= $config->current['BASE'];
624 $tmp= "d,".$dn;
625 $sacl= array();
627 /* Sort subacl's for lenght to simplify matching
628 for subtrees */
629 foreach ($subtreeACL as $key => $value){
630 $sacl[$key]= strlen($key);
631 }
632 arsort ($sacl);
633 reset ($sacl);
635 /* Successively remove leading parts of the dn's until
636 it doesn't contain commas anymore */
637 while (preg_match('/,/', $tmp)){
638 $tmp= ltrim(strstr($tmp, ","), ",");
640 /* Check for acl that may apply */
641 foreach ($sacl as $key => $value){
642 if (preg_match("/$key$/", $tmp)){
643 return ($subtreeACL[$key]);
644 }
645 }
646 }
648 return array("");
649 }
652 function get_module_permission($acl_array, $module, $dn)
653 {
654 global $ui;
656 $final= "";
657 foreach($acl_array as $acl){
659 /* Check for selfflag (!) in ACL to determine if
660 the user is allowed to change parts of his/her
661 own account */
662 if (preg_match("/^!/", $acl)){
663 if ($dn != "" && $dn != $ui->dn){
665 /* No match for own DN, give up on this ACL */
666 continue;
668 } else {
670 /* Matches own DN, remove the selfflag */
671 $acl= preg_replace("/^!/", "", $acl);
673 }
674 }
676 /* Remove leading garbage */
677 $acl= preg_replace("/^:/", "", $acl);
679 /* Discover if we've access to the submodule by comparing
680 all allowed submodules specified in the ACL */
681 $tmp= split(",", $acl);
682 foreach ($tmp as $mod){
683 if (preg_match("/$module#/", $mod)){
684 $final= strstr($mod, "#")."#";
685 continue;
686 }
687 if (preg_match("/[^#]$module$/", $mod)){
688 return ("#all#");
689 }
690 if (preg_match("/^all$/", $mod)){
691 return ("#all#");
692 }
693 }
694 }
696 /* Return assembled ACL, or none */
697 if ($final != ""){
698 return (preg_replace('/##/', '#', $final));
699 }
701 /* Nothing matches - disable access for this object */
702 return ("#none#");
703 }
706 function get_userinfo()
707 {
708 global $ui;
710 return $ui;
711 }
714 function get_smarty()
715 {
716 global $smarty;
718 return $smarty;
719 }
722 function convert_department_dn($dn)
723 {
724 $dep= "";
726 /* Build a sub-directory style list of the tree level
727 specified in $dn */
728 foreach (split (",", $dn) as $val){
730 /* We're only interested in organizational units... */
731 if (preg_match ("/ou=/", $val)){
732 $dep= preg_replace("/ou=([^,]+)/", "\\1", $val)."/$dep";
733 }
735 /* ... and location objects */
736 if (preg_match ("/l=/", $val)){
737 $dep= preg_replace("/l=([^,]+)/", "\\1", $val)."/$dep";
738 }
739 }
741 /* Return and remove accidently trailing slashes */
742 return rtrim($dep, "/");
743 }
745 function convert_department_dn2($dn)
746 {
747 $dep= "";
749 /* Build a sub-directory style list of the tree level
750 specified in $dn */
751 $tmp = split (",", $dn);
753 $dep= preg_replace("%^.*/([^/]+)$%", "\\1", $tmp[0]);
756 /* Return and remove accidently trailing slashes */
757 $tmp = rtrim($dep, "/");
758 return $tmp;
759 }
762 function get_ou($name)
763 {
764 global $config;
766 $ou= $config->current[$name];
767 if ($ou != ""){
768 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
769 return "ou=$ou,";
770 } else {
771 return "$ou,";
772 }
773 } else {
774 return "";
775 }
776 }
779 function get_people_ou()
780 {
781 return (get_ou("PEOPLE"));
782 }
785 function get_groups_ou()
786 {
787 return (get_ou("GROUPS"));
788 }
791 function get_winstations_ou()
792 {
793 return (get_ou("WINSTATIONS"));
794 }
797 function get_base_from_people($dn)
798 {
799 global $config;
801 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/";
802 $base= preg_replace($pattern, '', $dn);
804 /* Set to base, if we're not on a correct subtree */
805 if (!isset($config->idepartments[$base])){
806 $base= $config->current['BASE'];
807 }
809 return ($base);
810 }
813 function get_departments($ignore_dn= "")
814 {
815 global $config;
817 /* Initialize result hash */
818 $result= array();
819 $result['/']= $config->current['BASE'];
821 /* Get list of department objects */
822 $ldap= $config->get_ldap_link();
823 $ldap->cd ($config->current['BASE']);
824 $ldap->search ("(objectClass=gosaDepartment)", array("ou"));
825 while ($attrs= $ldap->fetch()){
826 $dn= $ldap->getDN();
827 if ($dn == $ignore_dn){
828 continue;
829 }
830 $result[convert_department_dn($dn)]= $dn;
831 }
833 return ($result);
834 }
837 function chkacl($acl, $name)
838 {
839 /* Look for attribute in ACL */
840 if (preg_match("/#$name#/", $acl) || $acl == "#all#"){
841 return ("");
842 }
844 /* Optically disable html object for no match */
845 return (" disabled ");
846 }
849 function is_phone_nr($nr)
850 {
851 if ($nr == ""){
852 return (TRUE);
853 }
855 return preg_match ("/^[0-9 ()+*-]+$/", $nr);
856 }
859 function is_url($url)
860 {
861 if ($url == ""){
862 return (TRUE);
863 }
865 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
866 }
869 function is_dn($dn)
870 {
871 if ($dn == ""){
872 return (TRUE);
873 }
875 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
876 }
879 function is_uid($uid)
880 {
881 global $config;
883 if ($uid == ""){
884 return (TRUE);
885 }
887 /* STRICT adds spaces and case insenstivity to the uid check.
888 This is dangerous and should not be used. */
889 if (isset($config->current['STRICT']) && preg_match('/^no$/i', $config->current['STRICT'])){
890 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
891 } else {
892 return preg_match ("/^[a-z0-9_-]+$/", $uid);
893 }
894 }
897 function is_id($id)
898 {
899 if ($id == ""){
900 return (FALSE);
901 }
903 return preg_match ("/^[0-9]+$/", $id);
904 }
907 function is_path($path)
908 {
909 if ($path == ""){
910 return (TRUE);
911 }
912 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
913 return (FALSE);
914 }
916 return preg_match ("/\/.+$/", $path);
917 }
920 function is_email($address, $template= FALSE)
921 {
922 if ($address == ""){
923 return (TRUE);
924 }
925 if ($template){
926 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
927 $address);
928 } else {
929 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
930 $address);
931 }
932 }
935 function print_red()
936 {
937 /* Check number of arguments */
938 if (func_num_args() < 1){
939 return;
940 }
942 /* Get arguments, save string */
943 $array = func_get_args();
944 $string= $array[0];
946 /* Step through arguments */
947 for ($i= 1; $i<count($array); $i++){
948 $string= preg_replace ("/%s/", $array[$i], $string, 1);
949 }
951 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
952 the other case... */
953 if (isset($_SESSION['DEBUGLEVEL'])){
954 $_SESSION['errors'].= "<div align=\"left\" style=\"border-width:5px;".
955 "border-style:solid;border-color:red; background-color:black;".
956 "margin-bottom:10px; padding:8px;\"><table summary=''><tr><td><img alt=\"\" src=\"".
957 get_template_path('images/warning.png')."\"></td>".
958 "<td width=\"100%\" align=\"center\"><font color=\"#FFFFFF\">".
959 "<b style='font-size:16px;'>$string</b></font></td><td>".
960 "<img alt=\"\"src=\"".get_template_path('images/warning.png').
961 "\"></td></tr></table></div>\n";
962 } else {
963 echo "Error: $string\n";
964 }
965 }
968 function gen_locked_message($user, $dn)
969 {
970 global $plug, $config;
972 $_SESSION['dn']= $dn;
973 $ldap= $config->get_ldap_link();
974 $ldap->cat ($user);
975 $attrs= $ldap->fetch();
976 $uid= $attrs["uid"][0];
978 /* Prepare and show template */
979 $smarty= get_smarty();
980 $smarty->assign ("dn", $dn);
981 $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."), $dn, "<a href=\"main.php?plug=0&viewid=$uid\">$uid</a>"));
983 return ($smarty->fetch (get_template_path('islocked.tpl')));
984 }
987 function to_string ($value)
988 {
989 /* If this is an array, generate a text blob */
990 if (is_array($value)){
991 $ret= "";
992 foreach ($value as $line){
993 $ret.= $line."<br>\n";
994 }
995 return ($ret);
996 } else {
997 return ($value);
998 }
999 }
1002 function get_printer_list($cups_server)
1003 {
1004 global $config;
1006 $res= array();
1008 /* Use CUPS, if we've access to it */
1009 if (function_exists('cups_get_dest_list')){
1010 $dest_list= cups_get_dest_list ($cups_server);
1012 foreach ($dest_list as $prt){
1013 $attr= cups_get_printer_attributes ($cups_server, $prt->name);
1015 foreach ($attr as $prt_info){
1016 if ($prt_info->name == "printer-info"){
1017 $info= $prt_info->value;
1018 break;
1019 }
1020 }
1021 $res[$prt->name]= "$info [$prt->name]";
1022 }
1024 /* CUPS is not available, try lpstat as a replacement */
1025 } else {
1026 $ar = false;
1027 exec("lpstat -p", $ar);
1028 foreach($ar as $val){
1029 list($dummy, $printer, $rest)= split(' ', $val, 3);
1030 if (preg_match('/^[^@]+$/', $printer)){
1031 $res[$printer]= "$printer";
1032 }
1033 }
1034 }
1036 /* Merge in printers from LDAP */
1037 $ldap= $config->get_ldap_link();
1038 $ldap->cd ($config->current['BASE']);
1039 $ldap->search('(objectClass=gotoPrinter)', array('cn'));
1040 while ($attrs= $ldap->fetch()){
1041 $res[$attrs["cn"][0]]= $attrs["cn"][0];
1042 }
1044 return $res;
1045 }
1048 function sess_del ($var)
1049 {
1050 /* New style */
1051 unset ($_SESSION[$var]);
1053 /* ... work around, since the first one
1054 doesn't seem to work all the time */
1055 session_unregister ($var);
1056 }
1059 function show_errors($message)
1060 {
1061 $complete= "";
1063 /* Assemble the message array to a plain string */
1064 foreach ($message as $error){
1065 if ($complete == ""){
1066 $complete= $error;
1067 } else {
1068 $complete= "$error<br>$complete";
1069 }
1070 }
1072 /* Fill ERROR variable with nice error dialog */
1073 print_red($complete);
1074 }
1077 function show_ldap_error($message)
1078 {
1079 if (!preg_match("/Success/i", $message)){
1080 print_red (_("LDAP error:")." $message");
1081 return TRUE;
1082 } else {
1083 return FALSE;
1084 }
1085 }
1088 function rewrite($s)
1089 {
1090 global $REWRITE;
1092 foreach ($REWRITE as $key => $val){
1093 $s= preg_replace("/$key/", "$val", $s);
1094 }
1096 return ($s);
1097 }
1100 function dn2base($dn)
1101 {
1102 global $config;
1104 if (get_people_ou() != ""){
1105 $dn= preg_replace('/,'.get_people_ou().'/' , ',', $dn);
1106 }
1107 if (get_groups_ou() != ""){
1108 $dn= preg_replace('/,'.get_groups_ou().'/' , ',', $dn);
1109 }
1110 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1112 return ($base);
1113 }
1117 function check_command($cmdline)
1118 {
1119 $cmd= preg_replace("/ .*$/", "", $cmdline);
1121 /* Check if command exists in filesystem */
1122 if (!file_exists($cmd)){
1123 return (FALSE);
1124 }
1126 /* Check if command is executable */
1127 if (!is_executable($cmd)){
1128 return (FALSE);
1129 }
1131 return (TRUE);
1132 }
1135 function print_header($image, $headline, $info= "")
1136 {
1137 $display= "<div class=\"plugtop\">\n";
1138 $display.= " <img src=\"$image\" align=\"middle\" alt=\"*\"> $headline\n";
1139 $display.= "</div>\n";
1141 if ($info != ""){
1142 $display.= "<div class=\"pluginfo\">\n";
1143 $display.= "$info";
1144 $display.= "</div>\n";
1145 } else {
1146 $display.= "<div style=\"height:5px;\">\n";
1147 $display.= " ";
1148 $display.= "</div>\n";
1149 }
1151 return ($display);
1152 }
1155 function register_global($name, $object)
1156 {
1157 $_SESSION[$name]= $object;
1158 }
1161 function is_global($name)
1162 {
1163 return isset($_SESSION[$name]);
1164 }
1167 function get_global($name)
1168 {
1169 return $_SESSION[$name];
1170 }
1173 function range_selector($dcnt,$start,$range=25)
1174 {
1176 /* Entries shown left and right from the selected entry */
1177 $max_entries= 10;
1179 /* Initialize and take care that max_entries is even */
1180 $output="";
1181 if ($max_entries & 1){
1182 $max_entries++;
1183 }
1185 /* Prevent output to start or end out of range */
1186 if ($start < 0 ){
1187 $start= 0 ;
1188 }
1189 if ($start >= $dcnt){
1190 $start= $range * (int)(($dcnt / $range) + 0.5);
1191 }
1193 $numpages= (($dcnt / $range));
1194 if(((int)($numpages))!=($numpages)){
1195 $numpages = (int)$numpages + 1;
1196 }
1197 if (((int)$numpages) <= 1 ){
1198 return ("");
1199 }
1200 $ppage= (int)(($start / $range) + 0.5);
1203 /* Align selected page to +/- max_entries/2 */
1204 $begin= $ppage - $max_entries/2;
1205 $end= $ppage + $max_entries/2;
1207 /* Adjust begin/end, so that the selected value is somewhere in
1208 the middle and the size is max_entries if possible */
1209 if ($begin < 0){
1210 $end-= $begin + 1;
1211 $begin= 0;
1212 }
1213 if ($end > $numpages) {
1214 $end= $numpages;
1215 }
1216 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1217 $begin= $end - $max_entries;
1218 }
1220 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1222 /* Draw decrement */
1223 if ($start > 0 ) {
1224 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1225 (($start-$range))."\">".
1226 "<img alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1227 }
1229 /* Draw pages */
1230 for ($i= $begin; $i < $end; $i++) {
1231 if ($ppage == $i){
1232 $output.= "<a style=\"background-color:#D0D0D0;\" href=\"main.php?plug=".
1233 validate($_GET['plug'])."&start=".
1234 ($i*$range)."\"> ".($i+1)." </a>";
1235 } else {
1236 $output.= "<a href=\"main.php?plug=".validate($_GET['plug']).
1237 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1238 }
1239 }
1241 /* Draw increment */
1242 if($start < ($dcnt-$range)) {
1243 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1244 (($start+($range)))."\">".
1245 "<img alt=\"\" src=\"images/forward.png\" border=0 align=\"middle\"></a>";
1246 }
1248 $output.= "</div>";
1250 return($output);
1251 }
1254 function apply_filter()
1255 {
1256 $apply= "";
1258 $apply= ''.
1259 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1260 '<input type="submit" name="apply" value="'._("Apply").'"></td></tr></table>';
1262 return ($apply);
1263 }
1266 function back_to_main()
1267 {
1268 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1269 _("Back").'"></p><input type="hidden" name="ignore">';
1271 return ($string);
1272 }
1275 function normalize_netmask($netmask)
1276 {
1277 /* Check for notation of netmask */
1278 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1279 $num= (int)($netmask);
1280 $netmask= "";
1282 for ($byte= 0; $byte<4; $byte++){
1283 $result=0;
1285 for ($i= 7; $i>=0; $i--){
1286 if ($num-- > 0){
1287 $result+= pow(2,$i);
1288 }
1289 }
1291 $netmask.= $result.".";
1292 }
1294 return (preg_replace('/\.$/', '', $netmask));
1295 }
1297 return ($netmask);
1298 }
1301 function netmask_to_bits($netmask)
1302 {
1303 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1304 $res= 0;
1306 for ($n= 0; $n<4; $n++){
1307 $start= 255;
1308 $name= "nm$n";
1310 for ($i= 0; $i<8; $i++){
1311 if ($start == (int)($$name)){
1312 $res+= 8 - $i;
1313 break;
1314 }
1315 $start-= pow(2,$i);
1316 }
1317 }
1319 return ($res);
1320 }
1323 function recurse($rule, $variables)
1324 {
1325 $result= array();
1327 if (!count($variables)){
1328 return array($rule);
1329 }
1331 reset($variables);
1332 $key= key($variables);
1333 $val= current($variables);
1334 unset ($variables[$key]);
1336 foreach($val as $possibility){
1337 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1338 $result= array_merge($result, recurse($nrule, $variables));
1339 }
1341 return ($result);
1342 }
1345 function expand_id($rule, $attributes)
1346 {
1347 /* Check for id rule */
1348 if(preg_match('/^id(:|#)\d+$/',$rule)){
1349 return (array("\{$rule}"));
1350 }
1352 /* Check for clean attribute */
1353 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1354 $rule= preg_replace('/^%/', '', $rule);
1355 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1356 return (array($val));
1357 }
1359 /* Check for attribute with parameters */
1360 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1361 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1362 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1363 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1364 $start= preg_replace ('/-.*$/', '', $param);
1365 $stop = preg_replace ('/^[^-]+-/', '', $param);
1367 /* Assemble results */
1368 $result= array();
1369 for ($i= $start; $i<= $stop; $i++){
1370 $result[]= substr($val, 0, $i);
1371 }
1372 return ($result);
1373 }
1375 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1376 return (array($rule));
1377 }
1380 function gen_uids($rule, $attributes)
1381 {
1382 global $config;
1384 /* Search for keys and fill the variables array with all
1385 possible values for that key. */
1386 $part= "";
1387 $trigger= false;
1388 $stripped= "";
1389 $variables= array();
1391 for ($pos= 0; $pos < strlen($rule); $pos++){
1393 if ($rule[$pos] == "{" ){
1394 $trigger= true;
1395 $part= "";
1396 continue;
1397 }
1399 if ($rule[$pos] == "}" ){
1400 $variables[$pos]= expand_id($part, $attributes);
1401 $stripped.= "\{$pos}";
1402 $trigger= false;
1403 continue;
1404 }
1406 if ($trigger){
1407 $part.= $rule[$pos];
1408 } else {
1409 $stripped.= $rule[$pos];
1410 }
1411 }
1413 /* Recurse through all possible combinations */
1414 $proposed= recurse($stripped, $variables);
1416 /* Get list of used ID's */
1417 $used= array();
1418 $ldap= $config->get_ldap_link();
1419 $ldap->cd($config->current['BASE']);
1420 $ldap->search('(uid=*)');
1422 while($attrs= $ldap->fetch()){
1423 $used[]= $attrs['uid'][0];
1424 }
1426 /* Remove used uids and watch out for id tags */
1427 $ret= array();
1428 foreach($proposed as $uid){
1430 /* Check for id tag and modify uid if needed */
1431 if(preg_match('/\{id:\d+}/',$uid)){
1432 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1434 for ($i= 0; $i < pow(10,$size); $i++){
1435 $number= sprintf("%0".$size."d", $i);
1436 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1437 if (!in_array($res, $used)){
1438 $uid= $res;
1439 break;
1440 }
1441 }
1442 }
1444 if(preg_match('/\{id#\d+}/',$uid)){
1445 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1447 while (true){
1448 mt_srand((double) microtime()*1000000);
1449 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1450 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1451 if (!in_array($res, $used)){
1452 $uid= $res;
1453 break;
1454 }
1455 }
1456 }
1458 /* Don't assign used ones */
1459 if (!in_array($uid, $used)){
1460 $ret[]= $uid;
1461 }
1462 }
1464 return(array_unique($ret));
1465 }
1468 function array_search_r($needle, $key, $haystack){
1470 foreach($haystack as $index => $value){
1471 $match= 0;
1473 if (is_array($value)){
1474 $match= array_search_r($needle, $key, $value);
1475 }
1477 if ($index==$key && !is_array($value) && preg_match("/$needle/i", $value)){
1478 $match=1;
1479 }
1481 if ($match){
1482 return 1;
1483 }
1484 }
1486 return 0;
1487 }
1490 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1491 Need to convert... */
1492 function to_byte($value) {
1493 $value= strtolower(trim($value));
1495 if(!is_numeric(substr($value, -1))) {
1497 switch(substr($value, -1)) {
1498 case 'g':
1499 $mult= 1073741824;
1500 break;
1501 case 'm':
1502 $mult= 1048576;
1503 break;
1504 case 'k':
1505 $mult= 1024;
1506 break;
1507 }
1509 return ($mult * (int)substr($value, 0, -1));
1510 } else {
1511 return $value;
1512 }
1513 }
1516 function in_array_ics($value, $items)
1517 {
1518 if (!is_array($items)){
1519 return (FALSE);
1520 }
1522 foreach ($items as $item){
1523 if (strtolower($item) == strtolower($value)) {
1524 return (TRUE);
1525 }
1526 }
1528 return (FALSE);
1529 }
1532 function generate_alphabet($count= 10)
1533 {
1534 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1535 $alphabet= "";
1536 $c= 0;
1538 /* Fill cells with charaters */
1539 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1540 if ($c == 0){
1541 $alphabet.= "<tr>";
1542 }
1544 $ch = mb_substr($characters, $i, 1, "UTF8");
1545 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1546 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1548 if ($c++ == $count){
1549 $alphabet.= "</tr>";
1550 $c= 0;
1551 }
1552 }
1554 /* Fill remaining cells */
1555 while ($c++ <= $count){
1556 $alphabet.= "<td> </td>";
1557 }
1559 return ($alphabet);
1560 }
1563 function validate($string)
1564 {
1565 return (strip_tags(preg_replace('/\0/', '', $string)));
1566 }
1568 function get_gosa_version()
1569 {
1570 global $svn_revision, $svn_path;
1572 /* Extract informations */
1573 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1575 /* Release or development? */
1576 if (preg_match('%/gosa/trunk/%', $svn_path)){
1577 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1578 } else {
1579 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1580 return (sprintf(_("GOsa $release"), $revision));
1581 }
1582 }
1585 function rmdirRecursive($path, $followLinks=false) {
1586 $dir= opendir($path);
1587 while($entry= readdir($dir)) {
1588 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1589 unlink($path."/".$entry);
1590 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1591 rmdirRecursive($path."/".$entry);
1592 }
1593 }
1594 closedir($dir);
1595 return rmdir($path);
1596 }
1598 function scan_directory($path,$sort_desc=false)
1599 {
1600 $ret = false;
1602 /* is this a dir ? */
1603 if(is_dir($path)) {
1605 /* is this path a readable one */
1606 if(is_readable($path)){
1608 /* Get contents and write it into an array */
1609 $ret = array();
1611 $dir = opendir($path);
1613 /* Is this a correct result ?*/
1614 if($dir){
1615 while($fp = readdir($dir))
1616 $ret[]= $fp;
1617 }
1618 }
1619 }
1620 /* Sort array ascending , like scandir */
1621 sort($ret);
1623 /* Sort descending if parameter is sort_desc is set */
1624 if($sort_desc) {
1625 $ret = array_reverse($ret);
1626 }
1628 return($ret);
1629 }
1631 function clean_smarty_compile_dir($directory)
1632 {
1633 global $svn_revision;
1635 if(is_dir($directory) && is_readable($directory)) {
1636 // Set revision filename to REVISION
1637 $revision_file= $directory."/REVISION";
1639 /* Is there a stamp containing the current revision? */
1640 if(!file_exists($revision_file)) {
1641 // create revision file
1642 create_revision($revision_file, $svn_revision);
1643 } else {
1644 # check for "$config->...['CONFIG']/revision" and the
1645 # contents should match the revision number
1646 if(!compare_revision($revision_file, $svn_revision)){
1647 // If revision differs, clean compile directory
1648 foreach(scan_directory($directory) as $file) {
1649 if(($file==".")||($file=="..")) continue;
1650 if( is_file($directory."/".$file) &&
1651 is_writable($directory."/".$file)) {
1652 // delete file
1653 if(!unlink($directory."/".$file)) {
1654 print_red("File ".$directory."/".$file." could not be deleted.");
1655 // This should never be reached
1656 }
1657 } elseif(is_dir($directory."/".$file) &&
1658 is_writable($directory."/".$file)) {
1659 // Just recursively delete it
1660 rmdirRecursive($directory."/".$file);
1661 }
1662 }
1663 // We should now create a fresh revision file
1664 clean_smarty_compile_dir($directory);
1665 } else {
1666 // Revision matches, nothing to do
1667 }
1668 }
1669 } else {
1670 // Smarty compile dir is not accessible
1671 // (Smarty will warn about this)
1672 }
1673 }
1675 function create_revision($revision_file, $revision)
1676 {
1677 $result= false;
1679 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1680 if($fh= fopen($revision_file, "w")) {
1681 if(fwrite($fh, $revision)) {
1682 $result= true;
1683 }
1684 }
1685 fclose($fh);
1686 } else {
1687 print_red("Can not write to revision file");
1688 }
1690 return $result;
1691 }
1693 function compare_revision($revision_file, $revision)
1694 {
1695 // false means revision differs
1696 $result= false;
1698 if(file_exists($revision_file) && is_readable($revision_file)) {
1699 // Open file
1700 if($fh= fopen($revision_file, "r")) {
1701 // Compare File contents with current revision
1702 if($revision == fread($fh, filesize($revision_file))) {
1703 $result= true;
1704 }
1705 } else {
1706 print_red("Can not open revision file");
1707 }
1708 // Close file
1709 fclose($fh);
1710 }
1712 return $result;
1713 }
1715 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1716 {
1717 $str = ""; // Our return value will be saved in this var
1719 $color = dechex($percentage+150);
1720 $color2 = dechex(150 - $percentage);
1721 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1723 $progress = (int)(($percentage /100)*$width);
1725 /* Abort printing out percentage, if divs are to small */
1728 /* If theres a better solution for this, use it... */
1729 $str = "
1730 <div style=\" width:".($width)."px;
1731 height:".($height)."px;
1732 background-color:#000000;
1733 padding:1px;\">
1735 <div style=\" width:".($width)."px;
1736 background-color:#$bgcolor;
1737 height:".($height)."px;\">
1739 <div style=\" width:".$progress."px;
1740 height:".$height."px;
1741 background-color:#".$color2.$color2.$color."; \">";
1744 if(($height >10)&&($showvalue)){
1745 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
1746 <b>".$percentage."%</b>
1747 </font>";
1748 }
1750 $str.= "</div></div></div>";
1752 return($str);
1753 }
1756 function search_config($arr, $name, $return)
1757 {
1758 if (is_array($arr)){
1759 foreach ($arr as $a){
1760 if (isset($a['CLASS']) &&
1761 strtolower($a['CLASS']) == strtolower($name)){
1763 if (isset($a[$return])){
1764 return ($a[$return]);
1765 } else {
1766 return ("");
1767 }
1768 } else {
1769 $res= search_config ($a, $name, $return);
1770 if ($res != ""){
1771 return $res;
1772 }
1773 }
1774 }
1775 }
1776 return ("");
1777 }
1780 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1781 ?>