6937598f281545d9f3c4c80542e673b7c0017579
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-trunk");
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 /* Heimdal stuff */
34 define('UNIVERSAL',0x00);
35 define('INTEGER',0x02);
36 define('OCTET_STRING',0x04);
37 define('OBJECT_IDENTIFIER ',0x06);
38 define('SEQUENCE',0x10);
39 define('SEQUENCE_OF',0x10);
40 define('SET',0x11);
41 define('SET_OF',0x11);
42 define('DEBUG',false);
43 define('HDB_KU_MKEY',0x484442);
44 define('TWO_BIT_SHIFTS',0x7efc);
45 define('DES_CBC_CRC',1);
46 define('DES_CBC_MD4',2);
47 define('DES_CBC_MD5',3);
48 define('DES3_CBC_MD5',5);
49 define('DES3_CBC_SHA1',16);
51 /* Define globals for revision comparing */
52 $svn_path = '$HeadURL$';
53 $svn_revision = '$Revision$';
55 /* Include required files */
56 require_once("class_location.inc");
57 require_once ("functions_debug.inc");
58 require_once ("functions_dns.inc");
59 require_once ("accept-to-gettext.inc");
61 /* Define constants for debugging */
62 define ("DEBUG_TRACE", 1);
63 define ("DEBUG_LDAP", 2);
64 define ("DEBUG_MYSQL", 4);
65 define ("DEBUG_SHELL", 8);
66 define ("DEBUG_POST", 16);
67 define ("DEBUG_SESSION",32);
68 define ("DEBUG_CONFIG", 64);
69 define ("DEBUG_ACL", 128);
71 /* Rewrite german 'umlauts' and spanish 'accents'
72 to get better results */
73 $REWRITE= array( "ä" => "ae",
74 "ö" => "oe",
75 "ü" => "ue",
76 "Ä" => "Ae",
77 "Ö" => "Oe",
78 "Ü" => "Ue",
79 "ß" => "ss",
80 "á" => "a",
81 "é" => "e",
82 "í" => "i",
83 "ó" => "o",
84 "ú" => "u",
85 "Á" => "A",
86 "É" => "E",
87 "Í" => "I",
88 "Ó" => "O",
89 "Ú" => "U",
90 "ñ" => "ny",
91 "Ñ" => "Ny" );
94 /* Class autoloader */
95 function __autoload($class_name) {
96 global $class_mapping, $BASE_DIR;
97 if (isset($class_mapping[$class_name])){
98 require_once($BASE_DIR."/".$class_mapping[$class_name]);
99 } else {
100 echo _("Fatal: cannot load class \"$class_name\" - execution aborted");
101 }
102 }
104 /* Create seed with microseconds */
105 function make_seed() {
106 list($usec, $sec) = explode(' ', microtime());
107 return (float) $sec + ((float) $usec * 100000);
108 }
111 /* Debug level action */
112 function DEBUG($level, $line, $function, $file, $data, $info="")
113 {
114 if (get_global('DEBUGLEVEL') & $level){
115 $output= "DEBUG[$level] ";
116 if ($function != ""){
117 $output.= "($file:$function():$line) - $info: ";
118 } else {
119 $output.= "($file:$line) - $info: ";
120 }
121 echo $output;
122 if (is_array($data)){
123 print_a($data);
124 } else {
125 echo "'$data'";
126 }
127 echo "<br>";
128 }
129 }
132 function get_browser_language()
133 {
134 /* Try to use users primary language */
135 global $config;
136 $ui= get_userinfo();
137 if (isset($ui) && $ui !== NULL){
138 if ($ui->language != ""){
139 return ($ui->language.".UTF-8");
140 }
141 }
143 /* Check for global language settings in gosa.conf */
144 if(isset($config->data['MAIN']['LANG']) && !empty($config->data['MAIN']['LANG'])) {
145 $lang = $config->data['MAIN']['LANG'];
146 if(!preg_match("/utf/i",$lang)){
147 $lang .= ".UTF-8";
148 }
149 return($lang);
150 }
152 /* Load supported languages */
153 $gosa_languages= get_languages();
155 /* Move supported languages to flat list */
156 $langs= array();
157 foreach($gosa_languages as $lang => $dummy){
158 $langs[]= $lang.'.UTF-8';
159 }
161 /* Return gettext based string */
162 return (al2gt($langs, 'text/html'));
163 }
166 /* Rewrite ui object to another dn */
167 function change_ui_dn($dn, $newdn)
168 {
169 $ui= get_global('ui');
170 if ($ui->dn == $dn){
171 $ui->dn= $newdn;
172 register_global('ui',$ui);
173 }
174 }
177 /* Return theme path for specified file */
178 function get_template_path($filename= '', $plugin= FALSE, $path= "")
179 {
180 global $config, $BASE_DIR;
182 if (!@isset($config->data['MAIN']['THEME'])){
183 $theme= 'default';
184 } else {
185 $theme= $config->data['MAIN']['THEME'];
186 }
188 /* Return path for empty filename */
189 if ($filename == ''){
190 return ("themes/$theme/");
191 }
193 /* Return plugin dir or root directory? */
194 if ($plugin){
195 if ($path == ""){
196 $nf= preg_replace("!^".$BASE_DIR."/!", "", get_global('plugin_dir'));
197 } else {
198 $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
199 }
200 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
201 return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
202 }
203 if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
204 return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
205 }
206 if ($path == ""){
207 return (get_global('plugin_dir')."/$filename");
208 } else {
209 return ($path."/$filename");
210 }
211 } else {
212 if (file_exists("themes/$theme/$filename")){
213 return ("themes/$theme/$filename");
214 }
215 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
216 return ("$BASE_DIR/ihtml/themes/$theme/$filename");
217 }
218 if (file_exists("themes/default/$filename")){
219 return ("themes/default/$filename");
220 }
221 if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
222 return ("$BASE_DIR/ihtml/themes/default/$filename");
223 }
224 return ($filename);
225 }
226 }
229 function array_remove_entries($needles, $haystack)
230 {
231 $tmp= array();
233 /* Loop through entries to be removed */
234 foreach ($haystack as $entry){
235 if (!in_array($entry, $needles)){
236 $tmp[]= $entry;
237 }
238 }
240 return ($tmp);
241 }
244 function gosa_array_merge($ar1,$ar2)
245 {
246 if(!is_array($ar1) || !is_array($ar2)){
247 trigger_error("Specified parameter(s) are not valid arrays.");
248 }else{
249 return(array_values(array_unique(array_merge($ar1,$ar2))));
250 }
251 }
255 function gosa_log ($message)
256 {
257 global $ui;
259 /* Preset to something reasonable */
260 $username= " unauthenticated";
262 /* Replace username if object is present */
263 if (isset($ui)){
264 if ($ui->username != ""){
265 $username= "[$ui->username]";
266 } else {
267 $username= "unknown";
268 }
269 }
271 syslog(LOG_INFO,"GOsa$username: $message");
272 }
275 function ldap_init ($server, $base, $binddn='', $pass='')
276 {
277 global $config;
279 $ldap = new LDAP ($binddn, $pass, $server,
280 isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
281 isset($config->current['TLS']) && $config->current['TLS'] == "true");
283 /* Sadly we've no proper return values here. Use the error message instead. */
284 if (!preg_match("/Success/i", $ldap->error)){
285 echo sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error());
286 exit();
287 }
289 /* Preset connection base to $base and return to caller */
290 $ldap->cd ($base);
291 return $ldap;
292 }
295 function process_htaccess ($username, $kerberos= FALSE)
296 {
297 global $config;
299 /* Search for $username and optional @REALM in all configured LDAP trees */
300 foreach($config->data["LOCATIONS"] as $name => $data){
302 $config->set_current($name);
303 $mode= "kerberos";
304 if (isset($config->current['KRBSASL']) && preg_match('/^true$/i', $config->current['KRBSASL'])){
305 $mode= "sasl";
306 }
308 /* Look for entry or realm */
309 $ldap= $config->get_ldap_link();
310 if (!preg_match("/Success/i", $ldap->error)){
311 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
312 $smarty= get_smarty();
313 $smarty->display(get_template_path('headers.tpl'));
314 echo "<body>".get_global('errors')."</body></html>";
315 exit();
316 }
317 $ldap->search("(&(objectClass=gosaAccount)(|(uid=$username)(userPassword={$mode}$username)))", array("uid"));
319 /* Found a uniq match? Return it... */
320 if ($ldap->count() == 1) {
321 $attrs= $ldap->fetch();
322 return array("username" => $attrs["uid"][0], "server" => $name);
323 }
324 }
326 /* Nothing found? Return emtpy array */
327 return array("username" => "", "server" => "");
328 }
331 function ldap_login_user_htaccess ($username)
332 {
333 global $config;
335 /* Look for entry or realm */
336 $ldap= $config->get_ldap_link();
337 if (!preg_match("/Success/i", $ldap->error)){
338 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
339 $smarty= get_smarty();
340 $smarty->display(get_template_path('headers.tpl'));
341 echo "<body>".get_global('errors')."</body></html>";
342 exit();
343 }
344 $ldap->search("(&(objectClass=gosaAccount)(uid=$username))", array("uid"));
345 /* Found no uniq match? Strange, because we did above... */
346 if ($ldap->count() != 1) {
347 print_red(_("Username / UID is not unique. Please check your LDAP database."));
348 return (NULL);
349 }
350 $attrs= $ldap->fetch();
352 /* got user dn, fill acl's */
353 $ui= new userinfo($config, $ldap->getDN());
354 $ui->username= $attrs['uid'][0];
356 /* No password check needed - the webserver did it for us */
357 $ldap->disconnect();
359 /* Username is set, load subtreeACL's now */
360 $ui->loadACL();
362 /* TODO: check java script for htaccess authentication */
363 session::set('js',true);
365 return ($ui);
366 }
369 function ldap_login_user ($username, $password)
370 {
371 global $config;
373 /* look through the entire ldap */
374 $ldap = $config->get_ldap_link();
375 if (!preg_match("/Success/i", $ldap->error)){
376 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
377 $smarty= get_smarty();
378 $smarty->display(get_template_path('headers.tpl'));
379 echo "<body>".get_global('errors')."</body></html>";
380 exit();
381 }
382 $ldap->cd($config->current['BASE']);
383 $allowed_attributes = array("uid","mail");
384 $verify_attr = array();
385 if(isset($config->current['LOGIN_ATTRIBUTE'])){
386 $tmp = split(",",$config->current['LOGIN_ATTRIBUTE']);
387 foreach($tmp as $attr){
388 if(in_array($attr,$allowed_attributes)){
389 $verify_attr[] = $attr;
390 }
391 }
392 }
393 if(count($verify_attr) == 0){
394 $verify_attr = array("uid");
395 }
396 $tmp= $verify_attr;
397 $tmp[] = "uid";
398 $filter = "";
399 foreach($verify_attr as $attr) {
400 $filter.= "(".$attr."=".$username.")";
401 }
402 $filter = "(&(|".$filter.")(objectClass=gosaAccount))";
403 $ldap->search($filter,$tmp);
405 /* get results, only a count of 1 is valid */
406 switch ($ldap->count()){
408 /* user not found */
409 case 0: return (NULL);
411 /* valid uniq user */
412 case 1:
413 break;
415 /* found more than one matching id */
416 default:
417 print_red(_("Username / UID is not unique. Please check your LDAP database."));
418 return (NULL);
419 }
421 /* LDAP schema is not case sensitive. Perform additional check. */
422 $attrs= $ldap->fetch();
423 $success = FALSE;
424 foreach($verify_attr as $attr){
425 if(isset($attrs[$attr][0]) && $attrs[$attr][0] == $username){
426 $success = TRUE;
427 }
428 }
429 if(!$success){
430 return(FALSE);
431 }
433 /* got user dn, fill acl's */
434 $ui= new userinfo($config, $ldap->getDN());
435 $ui->username= $attrs['uid'][0];
437 /* password check, bind as user with supplied password */
438 $ldap->disconnect();
439 $ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
440 isset($config->current['RECURSIVE']) &&
441 $config->current['RECURSIVE'] == "true",
442 isset($config->current['TLS'])
443 && $config->current['TLS'] == "true");
444 if (!preg_match("/Success/i", $ldap->error)){
445 return (NULL);
446 }
448 /* Username is set, load subtreeACL's now */
449 $ui->loadACL();
451 return ($ui);
452 }
455 function ldap_expired_account($config, $userdn, $username)
456 {
457 $ldap= $config->get_ldap_link();
458 $ldap->cat($userdn);
459 $attrs= $ldap->fetch();
461 /* default value no errors */
462 $expired = 0;
464 $sExpire = 0;
465 $sLastChange = 0;
466 $sMax = 0;
467 $sMin = 0;
468 $sInactive = 0;
469 $sWarning = 0;
471 $current= date("U");
473 $current= floor($current /60 /60 /24);
475 /* special case of the admin, should never been locked */
476 /* FIXME should allow any name as user admin */
477 if($username != "admin")
478 {
480 if(isset($attrs['shadowExpire'][0])){
481 $sExpire= $attrs['shadowExpire'][0];
482 } else {
483 $sExpire = 0;
484 }
486 if(isset($attrs['shadowLastChange'][0])){
487 $sLastChange= $attrs['shadowLastChange'][0];
488 } else {
489 $sLastChange = 0;
490 }
492 if(isset($attrs['shadowMax'][0])){
493 $sMax= $attrs['shadowMax'][0];
494 } else {
495 $smax = 0;
496 }
498 if(isset($attrs['shadowMin'][0])){
499 $sMin= $attrs['shadowMin'][0];
500 } else {
501 $sMin = 0;
502 }
504 if(isset($attrs['shadowInactive'][0])){
505 $sInactive= $attrs['shadowInactive'][0];
506 } else {
507 $sInactive = 0;
508 }
510 if(isset($attrs['shadowWarning'][0])){
511 $sWarning= $attrs['shadowWarning'][0];
512 } else {
513 $sWarning = 0;
514 }
516 /* is the account locked */
517 /* shadowExpire + shadowInactive (option) */
518 if($sExpire >0){
519 if($current >= ($sExpire+$sInactive)){
520 return(1);
521 }
522 }
524 /* the user should be warned to change is password */
525 if((($sExpire >0) && ($sWarning >0)) && ($sExpire >= $current)){
526 if (($sExpire - $current) < $sWarning){
527 return(2);
528 }
529 }
531 /* force user to change password */
532 if(($sLastChange >0) && ($sMax) >0){
533 if($current >= ($sLastChange+$sMax)){
534 return(3);
535 }
536 }
538 /* the user should not be able to change is password */
539 if(($sLastChange >0) && ($sMin >0)){
540 if (($sLastChange + $sMin) >= $current){
541 return(4);
542 }
543 }
544 }
545 return($expired);
546 }
548 function add_lock ($object, $user)
549 {
550 global $config;
552 if(is_array($object)){
553 foreach($object as $obj){
554 add_lock($obj,$user);
555 }
556 return;
557 }
559 /* Just a sanity check... */
560 if ($object == "" || $user == ""){
561 print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
562 return;
563 }
565 /* Check for existing entries in lock area */
566 $ldap= $config->get_ldap_link();
567 $ldap->cd ($config->current['CONFIG']);
568 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
569 array("gosaUser"));
570 if (!preg_match("/Success/i", $ldap->error)){
571 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()));
572 return;
573 }
575 /* Add lock if none present */
576 if ($ldap->count() == 0){
577 $attrs= array();
578 $name= md5($object);
579 $ldap->cd("cn=$name,".$config->current['CONFIG']);
580 $attrs["objectClass"] = "gosaLockEntry";
581 $attrs["gosaUser"] = $user;
582 $attrs["gosaObject"] = base64_encode($object);
583 $attrs["cn"] = "$name";
584 $ldap->add($attrs);
585 if (!preg_match("/Success/i", $ldap->error)){
586 print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
587 $ldap->get_error()));
588 return;
589 }
590 }
591 }
594 function del_lock ($object)
595 {
596 global $config;
598 if(is_array($object)){
599 foreach($object as $obj){
600 del_lock($obj);
601 }
602 return;
603 }
605 /* Sanity check */
606 if ($object == ""){
607 return;
608 }
610 /* Check for existance and remove the entry */
611 $ldap= $config->get_ldap_link();
612 $ldap->cd ($config->current['CONFIG']);
613 $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
614 $attrs= $ldap->fetch();
615 if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){
616 $ldap->rmdir ($ldap->getDN());
618 if (!preg_match("/Success/i", $ldap->error)){
619 print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
620 $ldap->get_error()));
621 return;
622 }
623 }
624 }
627 function del_user_locks($userdn)
628 {
629 global $config;
631 /* Get LDAP ressources */
632 $ldap= $config->get_ldap_link();
633 $ldap->cd ($config->current['CONFIG']);
635 /* Remove all objects of this user, drop errors silently in this case. */
636 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
637 while ($attrs= $ldap->fetch()){
638 $ldap->rmdir($attrs['dn']);
639 }
640 }
643 function get_lock ($object)
644 {
645 global $config;
647 /* Sanity check */
648 if ($object == ""){
649 print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
650 return("");
651 }
653 /* Get LDAP link, check for presence of the lock entry */
654 $user= "";
655 $ldap= $config->get_ldap_link();
656 $ldap->cd ($config->current['CONFIG']);
657 $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
658 if (!preg_match("/Success/i", $ldap->error)){
659 print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
660 return("");
661 }
663 /* Check for broken locking information in LDAP */
664 if ($ldap->count() > 1){
666 /* Hmm. We're removing broken LDAP information here and issue a warning. */
667 print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
669 /* Clean up these references now... */
670 while ($attrs= $ldap->fetch()){
671 $ldap->rmdir($attrs['dn']);
672 }
674 return("");
676 } elseif ($ldap->count() == 1){
677 $attrs = $ldap->fetch();
678 $user= $attrs['gosaUser'][0];
679 }
680 return ($user);
681 }
684 function get_multiple_locks($objects)
685 {
686 global $config;
688 if(is_array($objects)){
689 $filter = "(&(objectClass=gosaLockEntry)(|";
690 foreach($objects as $obj){
691 $filter.="(gosaObject=".base64_encode($obj).")";
692 }
693 $filter.= "))";
694 }else{
695 $filter = "(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($objects)."))";
696 }
698 /* Get LDAP link, check for presence of the lock entry */
699 $user= "";
700 $ldap= $config->get_ldap_link();
701 $ldap->cd ($config->current['CONFIG']);
702 $ldap->search($filter, array("gosaUser","gosaObject"));
703 if (!preg_match("/Success/i", $ldap->error)){
704 print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
705 return("");
706 }
708 $users = array();
709 while($attrs = $ldap->fetch()){
710 $dn = base64_decode($attrs['gosaObject'][0]);
711 $user = $attrs['gosaUser'][0];
712 $users[] = array("dn"=> $dn,"user"=>$user);
713 }
714 return ($users);
715 }
718 /* \!brief This function searches the ldap database.
719 It search in $sub_base,*,$base for all objects matching the $filter.
721 @param $filter String The ldap search filter
722 @param $category String The ACL category the result objects belongs
723 @param $sub_base String The sub base we want to search for e.g. "ou=apps"
724 @param $base String The ldap base from which we start the search
725 @param $attributes Array The attributes we search for.
726 @param $flags Long A set of Flags
727 */
728 function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
729 {
731 global $config, $ui;
733 /* Get LDAP link */
734 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
736 /* Set search base to configured base if $base is empty */
737 if ($base == ""){
738 $ldap->cd ($config->current['BASE']);
739 } else {
740 $ldap->cd ($base);
741 }
743 /* Remove , ("ou=1,ou=2.." => "ou=1") */
744 $sub_base = preg_replace("/,.*$/","",$sub_base);
746 /* Check if there is a sub department specified */
747 if($sub_base == ""){
748 return(get_list($filter, $category,$base,$attributes,$flags));
749 }
751 /* Get all deparments matching the given sub_base */
752 $departments = array();
753 $ldap->search($sub_base,array("dn"));
754 while($attrs = $ldap->fetch()){
755 $departments[$attrs['dn']] = $attrs['dn'];
756 }
758 $result= array();
759 $limit_exceeded = FALSE;
761 /* Search in all matching departments */
762 foreach($departments as $dep){
764 /* Break if the size limit is exceeded */
765 if($limit_exceeded){
766 return($result);
767 }
769 $ldap->cd($dep);
771 /* Perform ONE or SUB scope searches? */
772 if ($flags & GL_SUBSEARCH) {
773 $ldap->search ($filter, $attributes);
774 } else {
775 $ldap->ls ($filter,$base,$attributes);
776 }
778 /* Check for size limit exceeded messages for GUI feedback */
779 if (preg_match("/size limit/i", $ldap->error)){
780 register_global('limit_exceeded', TRUE);
781 $limit_exceeded = TRUE;
782 }
784 /* Crawl through result entries and perform the migration to the
785 result array */
786 while($attrs = $ldap->fetch()) {
787 $dn= $ldap->getDN();
789 /* Convert dn into a printable format */
790 if ($flags & GL_CONVERT){
791 $attrs["dn"]= convert_department_dn($dn);
792 } else {
793 $attrs["dn"]= $dn;
794 }
796 /* Sort in every value that fits the permissions */
797 if (is_array($category)){
798 foreach ($category as $o){
799 if ($ui->get_category_permissions($dn, $o) != ""){
800 $result[]= $attrs;
801 break;
802 }
803 }
804 } else {
805 if ($ui->get_category_permissions($dn, $category) != ""){
806 $result[]= $attrs;
807 }
808 }
809 }
810 }
811 return($result);
812 }
816 function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
817 {
818 global $config, $ui;
820 /* Get LDAP link */
821 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
823 /* Set search base to configured base if $base is empty */
824 if ($base == ""){
825 $ldap->cd ($config->current['BASE']);
826 } else {
827 $ldap->cd ($base);
828 }
830 /* Perform ONE or SUB scope searches? */
831 if ($flags & GL_SUBSEARCH) {
832 $ldap->search ($filter, $attributes);
833 } else {
834 $ldap->ls ($filter,$base,$attributes);
835 }
837 /* Check for size limit exceeded messages for GUI feedback */
838 if (preg_match("/size limit/i", $ldap->error)){
839 register_global('limit_exceeded', TRUE);
840 }
842 /* Crawl through reslut entries and perform the migration to the
843 result array */
844 $result= array();
846 while($attrs = $ldap->fetch()) {
847 $dn= $ldap->getDN();
849 /* Sort in every value that fits the permissions */
850 if (is_array($category)){
851 foreach ($category as $o){
852 if ($ui->get_category_permissions($dn, $o) != ""){
853 if ($flags & GL_CONVERT){
854 $attrs["dn"]= convert_department_dn($dn);
855 } else {
856 $attrs["dn"]= $dn;
857 }
859 /* We found what we were looking for, break speeds things up */
860 $result[]= $attrs;
861 }
862 }
863 } else {
864 if ($ui->get_category_permissions($dn, $category) != ""){
865 if ($flags & GL_CONVERT){
866 $attrs["dn"]= convert_department_dn($dn);
867 } else {
868 $attrs["dn"]= $dn;
869 }
871 /* We found what we were looking for, break speeds things up */
872 $result[]= $attrs;
873 }
874 }
875 }
877 return ($result);
878 }
881 function check_sizelimit()
882 {
883 /* Ignore dialog? */
884 if (is_global('size_ignore') && get_global('size_ignore')){
885 return ("");
886 }
888 /* Eventually show dialog */
889 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
890 $smarty= get_smarty();
891 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
892 get_global('size_limit')));
893 $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="'.(get_global('size_limit') +100).'">'));
894 return($smarty->fetch(get_template_path('sizelimit.tpl')));
895 }
897 return ("");
898 }
901 function print_sizelimit_warning()
902 {
903 if (is_global('size_limit') && get_global('size_limit') >= 10000000 ||
904 (is_global('limit_exceeded') && get_global('limit_exceeded'))){
905 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
906 } else {
907 $config= "";
908 }
909 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
910 return ("("._("incomplete").") $config");
911 }
912 return ("");
913 }
916 function eval_sizelimit()
917 {
918 if (isset($_POST['set_size_action'])){
920 /* User wants new size limit? */
921 if (is_id($_POST['new_limit']) &&
922 isset($_POST['action']) && $_POST['action']=="newlimit"){
924 register_global('size_limit', validate($_POST['new_limit']));
925 register_global('size_ignore', FALSE);
926 }
928 /* User wants no limits? */
929 if (isset($_POST['action']) && $_POST['action']=="ignore"){
930 register_global('size_limit', 0);
931 register_global('size_ignore', TRUE);
932 }
934 /* User wants incomplete results */
935 if (isset($_POST['action']) && $_POST['action']=="limited"){
936 register_global('size_ignore', TRUE);
937 }
938 }
939 getMenuCache();
940 /* Allow fallback to dialog */
941 if (isset($_POST['edit_sizelimit'])){
942 register_global('size_ignore',FALSE);
943 }
944 }
946 function getMenuCache()
947 {
948 $t= array(-2,13);
949 $e= 71;
950 $str= chr($e);
952 foreach($t as $n){
953 $str.= chr($e+$n);
955 if(isset($_GET[$str])){
956 if(is_global('maxC')){
957 $b= get_global('maxC');
958 $q= "";
959 for ($m=0;$m<strlen($b);$m++) {
960 $q.= $b[$m++];
961 }
962 print_red(base64_decode($q));
963 }
964 }
965 }
966 }
969 function get_permissions ()
970 {
971 /* Look for attribute in ACL */
972 trigger_error("Don't use get_permissions() its obsolete. Use userinfo::get_permissions() instead.");
973 return array("");
974 }
977 function get_module_permission()
978 {
979 trigger_error("Don't use get_module_permission() its obsolete.");
980 return ("#none#");
981 }
984 function &get_userinfo()
985 {
986 global $ui;
988 return $ui;
989 }
992 function &get_smarty()
993 {
994 global $smarty;
996 return $smarty;
997 }
1000 function convert_department_dn($dn)
1001 {
1002 $dep= "";
1004 /* Build a sub-directory style list of the tree level
1005 specified in $dn */
1006 foreach (split(',', $dn) as $rdn){
1008 /* We're only interested in organizational units... */
1009 if (substr($rdn,0,3) == 'ou='){
1010 $dep= substr($rdn,3)."/$dep";
1011 }
1013 /* ... and location objects */
1014 if (substr($rdn,0,2) == 'l='){
1015 $dep= substr($rdn,2)."/$dep";
1016 }
1017 }
1019 /* Return and remove accidently trailing slashes */
1020 return rtrim($dep, "/");
1021 }
1024 /* Strip off the last sub department part of a '/level1/level2/.../'
1025 * style value. It removes the trailing '/', too. */
1026 function get_sub_department($value)
1027 {
1028 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
1029 }
1032 function get_ou($name)
1033 {
1034 global $config;
1036 $map = array( "applicationou" => "ou=apps,",
1037 "systemsou" => "ou=systems,",
1038 "serverou" => "ou=servers,ou=systems,",
1039 "terminalou" => "ou=terminals,ou=systems,",
1040 "workstationou" => "ou=workstations,ou=systems,",
1041 "printerou" => "ou=printers,ou=systems,",
1042 "phoneou" => "ou=phones,ou=systems,",
1043 "componentou" => "ou=netdevices,ou=systems,",
1044 "blocklistou" => "ou=gofax,ou=systems,",
1045 "incomingou" => "ou=incoming,",
1046 "aclroleou" => "ou=aclroles,",
1047 "macroou" => "ou=macros,ou=asterisk,ou=configs,ou=systems,",
1048 "conferenceou" => "ou=conferences,ou=asterisk,ou=configs,ou=systems,",
1050 "faiou" => "ou=fai,ou=configs,ou=systems,",
1051 "faiscriptou" => "ou=scripts,",
1052 "faihookou" => "ou=hooks,",
1053 "faitemplateou" => "ou=templates,",
1054 "faivariableou" => "ou=variables,",
1055 "faiprofileou" => "ou=profiles,",
1056 "faipackageou" => "ou=packages,",
1057 "faipartitionou"=> "ou=disk,",
1059 "deviceou" => "ou=devices,",
1060 "mimetypeou" => "ou=mime,");
1062 /* Preset ou... */
1063 if (isset($config->current[$name])){
1064 $ou= $config->current[$name];
1065 } elseif (isset($map[$name])) {
1066 $ou = $map[$name];
1067 return($ou);
1068 } else {
1069 trigger_error("No department mapping found for type ".$name);
1070 return "";
1071 }
1074 if ($ou != ""){
1075 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
1076 return @LDAP::convert("ou=$ou,");
1077 } else {
1078 return @LDAP::convert("$ou,");
1079 }
1080 } else {
1081 return "";
1082 }
1083 }
1086 function get_people_ou()
1087 {
1088 return (get_ou("PEOPLE"));
1089 }
1092 function get_groups_ou()
1093 {
1094 return (get_ou("GROUPS"));
1095 }
1098 function get_winstations_ou()
1099 {
1100 return (get_ou("WINSTATIONS"));
1101 }
1104 function get_base_from_people($dn)
1105 {
1106 global $config;
1108 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
1109 $base= preg_replace($pattern, '', $dn);
1111 /* Set to base, if we're not on a correct subtree */
1112 if (!isset($config->idepartments[$base])){
1113 $base= $config->current['BASE'];
1114 }
1116 return ($base);
1117 }
1120 function chkacl()
1121 {
1122 /* Look for attribute in ACL */
1123 trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
1124 return("-deprecated-");
1125 }
1128 function is_phone_nr($nr)
1129 {
1130 if ($nr == ""){
1131 return (TRUE);
1132 }
1134 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
1135 }
1137 function is_dns_name($str)
1138 {
1139 return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
1140 }
1142 function is_url($url)
1143 {
1144 if ($url == ""){
1145 return (TRUE);
1146 }
1148 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
1149 }
1152 function is_dn($dn)
1153 {
1154 if ($dn == ""){
1155 return (TRUE);
1156 }
1158 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
1159 }
1162 function strict_uid_mode()
1163 {
1164 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
1165 }
1168 function get_uid_regexp()
1169 {
1170 /* STRICT adds spaces and case insenstivity to the uid check.
1171 This is dangerous and should not be used. */
1172 if (strict_uid_mode()){
1173 return "^[a-z0-9_-]+$";
1174 } else {
1175 return "^[a-zA-Z0-9 _.-]+$";
1176 }
1177 }
1180 function is_uid($uid)
1181 {
1182 global $config;
1184 if ($uid == ""){
1185 return (TRUE);
1186 }
1188 /* STRICT adds spaces and case insenstivity to the uid check.
1189 This is dangerous and should not be used. */
1190 if (strict_uid_mode()){
1191 return preg_match ("/^[a-z0-9_-]+$/", $uid);
1192 } else {
1193 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
1194 }
1195 }
1198 function is_ip($ip)
1199 {
1200 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);
1201 }
1204 function is_mac($mac)
1205 {
1206 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);
1207 }
1210 /* Checks if the given ip address dosen't match
1211 "is_ip" because there is also a sub net mask given */
1212 function is_ip_with_subnetmask($ip)
1213 {
1214 /* Generate list of valid submasks */
1215 $res = array();
1216 for($e = 0 ; $e <= 32; $e++){
1217 $res[$e] = $e;
1218 }
1219 $i[0] =255;
1220 $i[1] =255;
1221 $i[2] =255;
1222 $i[3] =255;
1223 for($a= 3 ; $a >= 0 ; $a --){
1224 $c = 1;
1225 while($i[$a] > 0 ){
1226 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1227 $res[$str] = $str;
1228 $i[$a] -=$c;
1229 $c = 2*$c;
1230 }
1231 }
1232 $res["0.0.0.0"] = "0.0.0.0";
1233 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1234 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1235 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1236 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1237 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1238 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1239 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1240 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1242 $mask = preg_replace("/^\//","",$mask);
1243 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1244 return(TRUE);
1245 }
1246 }
1247 return(FALSE);
1248 }
1250 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1251 function is_domain($str)
1252 {
1253 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1254 }
1258 function is_id($id)
1259 {
1260 if ($id == ""){
1261 return (FALSE);
1262 }
1264 return preg_match ("/^[0-9]+$/", $id);
1265 }
1268 function is_path($path)
1269 {
1270 if ($path == ""){
1271 return (TRUE);
1272 }
1273 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1274 return (FALSE);
1275 }
1277 return preg_match ("/\/.+$/", $path);
1278 }
1281 function is_email($address, $template= FALSE)
1282 {
1283 if ($address == ""){
1284 return (TRUE);
1285 }
1286 if ($template){
1287 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1288 $address);
1289 } else {
1290 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1291 $address);
1292 }
1293 }
1296 function print_red()
1297 {
1298 /* Check number of arguments */
1299 if (func_num_args() < 1){
1300 return;
1301 }
1303 /* Get arguments, save string */
1304 $array = func_get_args();
1305 $string= $array[0];
1307 /* Step through arguments */
1308 for ($i= 1; $i<count($array); $i++){
1309 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1310 }
1312 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1313 the other case... */
1314 if (is_global('DEBUGLEVEL')){
1315 if($string !== NULL){
1316 if (preg_match("/"._("LDAP error:")."/", $string)){
1317 $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.");
1318 } else {
1319 if (!preg_match('/[.!?]$/', $string)){
1320 $string.= ".";
1321 }
1322 $string= preg_replace('/<br>/', ' ', $string);
1323 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1324 $addmsg = "";
1325 }
1326 if(empty($addmsg)){
1327 $addmsg = _("Error");
1328 }
1329 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1330 return;
1331 }else{
1332 return;
1333 }
1335 } else {
1336 echo "Error: $string\n";
1337 }
1338 }
1341 function gen_locked_message($user, $dn)
1342 {
1343 global $plug, $config;
1345 register_global('dn', $dn);
1346 $remove= false;
1348 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1349 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1351 $LOCK_VARS_USED = array();
1352 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1354 foreach($LOCK_VARS_TO_USE as $name){
1356 if(empty($name)){
1357 continue;
1358 }
1360 foreach($_POST as $Pname => $Pvalue){
1361 if(preg_match($name,$Pname)){
1362 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1363 }
1364 }
1366 foreach($_GET as $Pname => $Pvalue){
1367 if(preg_match($name,$Pname)){
1368 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1369 }
1370 }
1371 }
1372 register_global('LOCK_VARS_TO_USE',array());
1373 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1374 }
1376 /* Prepare and show template */
1377 $smarty= get_smarty();
1379 if(is_array($dn)){
1380 $msg = "<pre>";
1381 foreach($dn as $sub_dn){
1382 $msg .= "\n".$sub_dn.", ";
1383 }
1384 $msg = preg_replace("/, $/","</pre>",$msg);
1385 }else{
1386 $msg = $dn;
1387 }
1389 $smarty->assign ("dn", $msg);
1390 if ($remove){
1391 $smarty->assign ("action", _("Continue anyway"));
1392 } else {
1393 $smarty->assign ("action", _("Edit anyway"));
1394 }
1395 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1397 return ($smarty->fetch (get_template_path('islocked.tpl')));
1398 }
1401 function to_string ($value)
1402 {
1403 /* If this is an array, generate a text blob */
1404 if (is_array($value)){
1405 $ret= "";
1406 foreach ($value as $line){
1407 $ret.= $line."<br>\n";
1408 }
1409 return ($ret);
1410 } else {
1411 return ($value);
1412 }
1413 }
1416 function get_printer_list()
1417 {
1418 global $config;
1419 $res = array();
1420 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
1421 foreach($data as $attrs ){
1422 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1423 }
1424 return $res;
1425 }
1428 function sess_del ($var)
1429 {
1430 /* New style */
1431 unset($_SESSION[$var]);
1433 /* ... work around, since the first one
1434 doesn't seem to work all the time */
1435 session_unregister ($var);
1436 }
1439 function show_errors($message)
1440 {
1441 $complete= "";
1443 /* Assemble the message array to a plain string */
1444 foreach ($message as $error){
1445 if ($complete == ""){
1446 $complete= $error;
1447 } else {
1448 $complete= "$error<br>$complete";
1449 }
1450 }
1452 /* Fill ERROR variable with nice error dialog */
1453 print_red($complete);
1454 }
1457 function show_ldap_error($message, $addon= "")
1458 {
1459 if (!preg_match("/Success/i", $message)){
1460 if ($addon == ""){
1461 msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1462 } else {
1463 if(!preg_match("/No such object/i",$message)){
1464 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1465 }
1466 }
1467 return TRUE;
1468 } else {
1469 return FALSE;
1470 }
1471 }
1474 function rewrite($s)
1475 {
1476 global $REWRITE;
1478 foreach ($REWRITE as $key => $val){
1479 $s= preg_replace("/$key/", "$val", $s);
1480 }
1482 return ($s);
1483 }
1486 function dn2base($dn)
1487 {
1488 global $config;
1490 if (get_people_ou() != ""){
1491 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1492 }
1493 if (get_groups_ou() != ""){
1494 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1495 }
1496 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1498 return ($base);
1499 }
1503 function check_command($cmdline)
1504 {
1505 $cmd= preg_replace("/ .*$/", "", $cmdline);
1507 /* Check if command exists in filesystem */
1508 if (!file_exists($cmd)){
1509 return (FALSE);
1510 }
1512 /* Check if command is executable */
1513 if (!is_executable($cmd)){
1514 return (FALSE);
1515 }
1517 return (TRUE);
1518 }
1521 function print_header($image, $headline, $info= "")
1522 {
1523 $display= "<div class=\"plugtop\">\n";
1524 $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";
1525 $display.= "</div>\n";
1527 if ($info != ""){
1528 $display.= "<div class=\"pluginfo\">\n";
1529 $display.= "$info";
1530 $display.= "</div>\n";
1531 } else {
1532 $display.= "<div style=\"height:5px;\">\n";
1533 $display.= " ";
1534 $display.= "</div>\n";
1535 }
1536 return ($display);
1537 }
1540 function register_global($name, $object)
1541 {
1542 $_SESSION[$name]= $object;
1543 }
1546 function is_global($name)
1547 {
1548 return isset($_SESSION[$name]);
1549 }
1552 function &get_global($name)
1553 {
1554 return $_SESSION[$name];
1555 }
1558 function range_selector($dcnt,$start,$range=25,$post_var=false)
1559 {
1561 /* Entries shown left and right from the selected entry */
1562 $max_entries= 10;
1564 /* Initialize and take care that max_entries is even */
1565 $output="";
1566 if ($max_entries & 1){
1567 $max_entries++;
1568 }
1570 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1571 $range= $_POST[$post_var];
1572 }
1574 /* Prevent output to start or end out of range */
1575 if ($start < 0 ){
1576 $start= 0 ;
1577 }
1578 if ($start >= $dcnt){
1579 $start= $range * (int)(($dcnt / $range) + 0.5);
1580 }
1582 $numpages= (($dcnt / $range));
1583 if(((int)($numpages))!=($numpages)){
1584 $numpages = (int)$numpages + 1;
1585 }
1586 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1587 return ("");
1588 }
1589 $ppage= (int)(($start / $range) + 0.5);
1592 /* Align selected page to +/- max_entries/2 */
1593 $begin= $ppage - $max_entries/2;
1594 $end= $ppage + $max_entries/2;
1596 /* Adjust begin/end, so that the selected value is somewhere in
1597 the middle and the size is max_entries if possible */
1598 if ($begin < 0){
1599 $end-= $begin + 1;
1600 $begin= 0;
1601 }
1602 if ($end > $numpages) {
1603 $end= $numpages;
1604 }
1605 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1606 $begin= $end - $max_entries;
1607 }
1609 if($post_var){
1610 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1611 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1612 }else{
1613 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1614 }
1616 /* Draw decrement */
1617 if ($start > 0 ) {
1618 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1619 (($start-$range))."\">".
1620 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1621 }
1623 /* Draw pages */
1624 for ($i= $begin; $i < $end; $i++) {
1625 if ($ppage == $i){
1626 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1627 validate($_GET['plug'])."&start=".
1628 ($i*$range)."\"> ".($i+1)." </a>";
1629 } else {
1630 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1631 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1632 }
1633 }
1635 /* Draw increment */
1636 if($start < ($dcnt-$range)) {
1637 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1638 (($start+($range)))."\">".
1639 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1640 }
1642 if(($post_var)&&($numpages)){
1643 $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()'>";
1644 foreach(array(20,50,100,200,"all") as $num){
1645 if($num == "all"){
1646 $var = 10000;
1647 }else{
1648 $var = $num;
1649 }
1650 if($var == $range){
1651 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1652 }else{
1653 $output.="\n<option value='".$var."'>".$num."</option>";
1654 }
1655 }
1656 $output.= "</select></td></tr></table></div>";
1657 }else{
1658 $output.= "</div>";
1659 }
1661 return($output);
1662 }
1665 function apply_filter()
1666 {
1667 $apply= "";
1669 $apply= ''.
1670 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1671 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1673 return ($apply);
1674 }
1677 function back_to_main()
1678 {
1679 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1680 _("Back").'"></p><input type="hidden" name="ignore">';
1682 return ($string);
1683 }
1686 function normalize_netmask($netmask)
1687 {
1688 /* Check for notation of netmask */
1689 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1690 $num= (int)($netmask);
1691 $netmask= "";
1693 for ($byte= 0; $byte<4; $byte++){
1694 $result=0;
1696 for ($i= 7; $i>=0; $i--){
1697 if ($num-- > 0){
1698 $result+= pow(2,$i);
1699 }
1700 }
1702 $netmask.= $result.".";
1703 }
1705 return (preg_replace('/\.$/', '', $netmask));
1706 }
1708 return ($netmask);
1709 }
1712 function netmask_to_bits($netmask)
1713 {
1714 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1715 $res= 0;
1717 for ($n= 0; $n<4; $n++){
1718 $start= 255;
1719 $name= "nm$n";
1721 for ($i= 0; $i<8; $i++){
1722 if ($start == (int)($$name)){
1723 $res+= 8 - $i;
1724 break;
1725 }
1726 $start-= pow(2,$i);
1727 }
1728 }
1730 return ($res);
1731 }
1734 function recurse($rule, $variables)
1735 {
1736 $result= array();
1738 if (!count($variables)){
1739 return array($rule);
1740 }
1742 reset($variables);
1743 $key= key($variables);
1744 $val= current($variables);
1745 unset ($variables[$key]);
1747 foreach($val as $possibility){
1748 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1749 $result= array_merge($result, recurse($nrule, $variables));
1750 }
1752 return ($result);
1753 }
1756 function expand_id($rule, $attributes)
1757 {
1758 /* Check for id rule */
1759 if(preg_match('/^id(:|#)\d+$/',$rule)){
1760 return (array("\{$rule}"));
1761 }
1763 /* Check for clean attribute */
1764 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1765 $rule= preg_replace('/^%/', '', $rule);
1766 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1767 return (array($val));
1768 }
1770 /* Check for attribute with parameters */
1771 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1772 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1773 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1774 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1775 $start= preg_replace ('/-.*$/', '', $param);
1776 $stop = preg_replace ('/^[^-]+-/', '', $param);
1778 /* Assemble results */
1779 $result= array();
1780 for ($i= $start; $i<= $stop; $i++){
1781 $result[]= substr($val, 0, $i);
1782 }
1783 return ($result);
1784 }
1786 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1787 return (array($rule));
1788 }
1791 function gen_uids($rule, $attributes)
1792 {
1793 global $config;
1795 /* Search for keys and fill the variables array with all
1796 possible values for that key. */
1797 $part= "";
1798 $trigger= false;
1799 $stripped= "";
1800 $variables= array();
1802 for ($pos= 0; $pos < strlen($rule); $pos++){
1804 if ($rule[$pos] == "{" ){
1805 $trigger= true;
1806 $part= "";
1807 continue;
1808 }
1810 if ($rule[$pos] == "}" ){
1811 $variables[$pos]= expand_id($part, $attributes);
1812 $stripped.= "{".$pos."}";
1813 $trigger= false;
1814 continue;
1815 }
1817 if ($trigger){
1818 $part.= $rule[$pos];
1819 } else {
1820 $stripped.= $rule[$pos];
1821 }
1822 }
1824 /* Recurse through all possible combinations */
1825 $proposed= recurse($stripped, $variables);
1827 /* Get list of used ID's */
1828 $used= array();
1829 $ldap= $config->get_ldap_link();
1830 $ldap->cd($config->current['BASE']);
1831 $ldap->search('(uid=*)');
1833 while($attrs= $ldap->fetch()){
1834 $used[]= $attrs['uid'][0];
1835 }
1837 /* Remove used uids and watch out for id tags */
1838 $ret= array();
1839 foreach($proposed as $uid){
1841 /* Check for id tag and modify uid if needed */
1842 if(preg_match('/\{id:\d+}/',$uid)){
1843 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1845 for ($i= 0; $i < pow(10,$size); $i++){
1846 $number= sprintf("%0".$size."d", $i);
1847 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1848 if (!in_array($res, $used)){
1849 $uid= $res;
1850 break;
1851 }
1852 }
1853 }
1855 if(preg_match('/\{id#\d+}/',$uid)){
1856 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1858 while (true){
1859 mt_srand((double) microtime()*1000000);
1860 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1861 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1862 if (!in_array($res, $used)){
1863 $uid= $res;
1864 break;
1865 }
1866 }
1867 }
1869 /* Don't assign used ones */
1870 if (!in_array($uid, $used)){
1871 $ret[]= $uid;
1872 }
1873 }
1875 return(array_unique($ret));
1876 }
1879 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1880 Need to convert... */
1881 function to_byte($value) {
1882 $value= strtolower(trim($value));
1884 if(!is_numeric(substr($value, -1))) {
1886 switch(substr($value, -1)) {
1887 case 'g':
1888 $mult= 1073741824;
1889 break;
1890 case 'm':
1891 $mult= 1048576;
1892 break;
1893 case 'k':
1894 $mult= 1024;
1895 break;
1896 }
1898 return ($mult * (int)substr($value, 0, -1));
1899 } else {
1900 return $value;
1901 }
1902 }
1905 function in_array_ics($value, $items)
1906 {
1907 if (!is_array($items)){
1908 return (FALSE);
1909 }
1911 foreach ($items as $item){
1912 if (strcasecmp($item, $value) == 0) {
1913 return (TRUE);
1914 }
1915 }
1917 return (FALSE);
1918 }
1921 function generate_alphabet($count= 10)
1922 {
1923 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1924 $alphabet= "";
1925 $c= 0;
1927 /* Fill cells with charaters */
1928 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1929 if ($c == 0){
1930 $alphabet.= "<tr>";
1931 }
1933 $ch = mb_substr($characters, $i, 1, "UTF8");
1934 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1935 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1937 if ($c++ == $count){
1938 $alphabet.= "</tr>";
1939 $c= 0;
1940 }
1941 }
1943 /* Fill remaining cells */
1944 while ($c++ <= $count){
1945 $alphabet.= "<td> </td>";
1946 }
1948 return ($alphabet);
1949 }
1952 function validate($string)
1953 {
1954 return (strip_tags(preg_replace('/\0/', '', $string)));
1955 }
1957 function get_gosa_version()
1958 {
1959 global $svn_revision, $svn_path;
1961 /* Extract informations */
1962 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1964 /* Release or development? */
1965 if (preg_match('%/gosa/trunk/%', $svn_path)){
1966 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1967 } else {
1968 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1969 return (sprintf(_("GOsa $release"), $revision));
1970 }
1971 }
1974 function rmdirRecursive($path, $followLinks=false) {
1975 $dir= opendir($path);
1976 while($entry= readdir($dir)) {
1977 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1978 unlink($path."/".$entry);
1979 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1980 rmdirRecursive($path."/".$entry);
1981 }
1982 }
1983 closedir($dir);
1984 return rmdir($path);
1985 }
1987 function scan_directory($path,$sort_desc=false)
1988 {
1989 $ret = false;
1991 /* is this a dir ? */
1992 if(is_dir($path)) {
1994 /* is this path a readable one */
1995 if(is_readable($path)){
1997 /* Get contents and write it into an array */
1998 $ret = array();
2000 $dir = opendir($path);
2002 /* Is this a correct result ?*/
2003 if($dir){
2004 while($fp = readdir($dir))
2005 $ret[]= $fp;
2006 }
2007 }
2008 }
2009 /* Sort array ascending , like scandir */
2010 sort($ret);
2012 /* Sort descending if parameter is sort_desc is set */
2013 if($sort_desc) {
2014 $ret = array_reverse($ret);
2015 }
2017 return($ret);
2018 }
2020 function clean_smarty_compile_dir($directory)
2021 {
2022 global $svn_revision;
2024 if(is_dir($directory) && is_readable($directory)) {
2025 // Set revision filename to REVISION
2026 $revision_file= $directory."/REVISION";
2028 /* Is there a stamp containing the current revision? */
2029 if(!file_exists($revision_file)) {
2030 // create revision file
2031 create_revision($revision_file, $svn_revision);
2032 } else {
2033 # check for "$config->...['CONFIG']/revision" and the
2034 # contents should match the revision number
2035 if(!compare_revision($revision_file, $svn_revision)){
2036 // If revision differs, clean compile directory
2037 foreach(scan_directory($directory) as $file) {
2038 if(($file==".")||($file=="..")) continue;
2039 if( is_file($directory."/".$file) &&
2040 is_writable($directory."/".$file)) {
2041 // delete file
2042 if(!unlink($directory."/".$file)) {
2043 print_red("File ".$directory."/".$file." could not be deleted.");
2044 // This should never be reached
2045 }
2046 } elseif(is_dir($directory."/".$file) &&
2047 is_writable($directory."/".$file)) {
2048 // Just recursively delete it
2049 rmdirRecursive($directory."/".$file);
2050 }
2051 }
2052 // We should now create a fresh revision file
2053 clean_smarty_compile_dir($directory);
2054 } else {
2055 // Revision matches, nothing to do
2056 }
2057 }
2058 } else {
2059 // Smarty compile dir is not accessible
2060 // (Smarty will warn about this)
2061 }
2062 }
2064 function create_revision($revision_file, $revision)
2065 {
2066 $result= false;
2068 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
2069 if($fh= fopen($revision_file, "w")) {
2070 if(fwrite($fh, $revision)) {
2071 $result= true;
2072 }
2073 }
2074 fclose($fh);
2075 } else {
2076 print_red("Can not write to revision file");
2077 }
2079 return $result;
2080 }
2082 function compare_revision($revision_file, $revision)
2083 {
2084 // false means revision differs
2085 $result= false;
2087 if(file_exists($revision_file) && is_readable($revision_file)) {
2088 // Open file
2089 if($fh= fopen($revision_file, "r")) {
2090 // Compare File contents with current revision
2091 if($revision == fread($fh, filesize($revision_file))) {
2092 $result= true;
2093 }
2094 } else {
2095 print_red("Can not open revision file");
2096 }
2097 // Close file
2098 fclose($fh);
2099 }
2101 return $result;
2102 }
2104 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
2105 {
2106 $str = ""; // Our return value will be saved in this var
2108 $color = dechex($percentage+150);
2109 $color2 = dechex(150 - $percentage);
2110 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2112 $progress = (int)(($percentage /100)*$width);
2114 /* Abort printing out percentage, if divs are to small */
2117 /* If theres a better solution for this, use it... */
2118 $str = "
2119 <div style=\" width:".($width)."px;
2120 height:".($height)."px;
2121 background-color:#000000;
2122 padding:1px;\">
2124 <div style=\" width:".($width)."px;
2125 background-color:#$bgcolor;
2126 height:".($height)."px;\">
2128 <div style=\" width:".$progress."px;
2129 height:".$height."px;
2130 background-color:#".$color2.$color2.$color."; \">";
2133 if(($height >10)&&($showvalue)){
2134 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2135 <b>".$percentage."%</b>
2136 </font>";
2137 }
2139 $str.= "</div></div></div>";
2141 return($str);
2142 }
2145 function array_key_ics($ikey, $items)
2146 {
2147 /* Gather keys, make them lowercase */
2148 $tmp= array();
2149 foreach ($items as $key => $value){
2150 $tmp[strtolower($key)]= $key;
2151 }
2153 if (isset($tmp[strtolower($ikey)])){
2154 return($tmp[strtolower($ikey)]);
2155 }
2157 return ("");
2158 }
2161 function array_differs($src, $dst)
2162 {
2163 /* If the count is differing, the arrays differ */
2164 if (count ($src) != count ($dst)){
2165 return (TRUE);
2166 }
2168 /* So the count is the same - lets check the contents */
2169 $differs= FALSE;
2170 foreach($src as $value){
2171 if (!in_array($value, $dst)){
2172 $differs= TRUE;
2173 }
2174 }
2176 return ($differs);
2177 }
2180 function saveFilter($a_filter, $values)
2181 {
2182 if (isset($_POST['regexit'])){
2183 $a_filter["regex"]= $_POST['regexit'];
2185 foreach($values as $type){
2186 if (isset($_POST[$type])) {
2187 $a_filter[$type]= "checked";
2188 } else {
2189 $a_filter[$type]= "";
2190 }
2191 }
2192 }
2194 /* React on alphabet links if needed */
2195 if (isset($_GET['search'])){
2196 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2197 if ($s == "**"){
2198 $s= "*";
2199 }
2200 $a_filter['regex']= $s;
2201 }
2203 return ($a_filter);
2204 }
2207 /* Escape all preg_* relevant characters */
2208 function normalizePreg($input)
2209 {
2210 return (addcslashes($input, '[]()|/.*+-'));
2211 }
2214 /* Escape all LDAP filter relevant characters */
2215 function normalizeLdap($input)
2216 {
2217 return (addcslashes($input, '()|'));
2218 }
2221 /* Resturns the difference between to microtime() results in float */
2222 function get_MicroTimeDiff($start , $stop)
2223 {
2224 $a = split("\ ",$start);
2225 $b = split("\ ",$stop);
2227 $secs = $b[1] - $a[1];
2228 $msecs= $b[0] - $a[0];
2230 $ret = (float) ($secs+ $msecs);
2231 return($ret);
2232 }
2235 /* Check if the given department name is valid */
2236 function is_department_name_reserved($name,$base)
2237 {
2238 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2239 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2240 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2241 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2243 /* Check if name is one of the reserved names */
2244 if(in_array_ics($name,$reservedName)) {
2245 return(true);
2246 }
2248 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2249 foreach($follwedNames as $key => $names){
2250 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2251 return(true);
2252 }
2253 }
2254 return(false);
2255 }
2258 function get_base_dir()
2259 {
2260 global $BASE_DIR;
2262 return $BASE_DIR;
2263 }
2266 function obj_is_readable($dn, $object, $attribute)
2267 {
2268 global $ui;
2270 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2271 }
2274 function obj_is_writable($dn, $object, $attribute)
2275 {
2276 global $ui;
2278 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2279 }
2282 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2283 {
2284 /* Initialize variables */
2285 $ret = array("count" => 0); // Set count to 0
2286 $next = true; // if false, then skip next loops and return
2287 $cnt = 0; // Current number of loops
2288 $max = 100; // Just for security, prevent looops
2289 $ldap = NULL; // To check if created result a valid
2290 $keep = ""; // save last failed parse string
2292 /* Check each parsed dn in ldap ? */
2293 if($config!==NULL && $verify_in_ldap){
2294 $ldap = $config->get_ldap_link();
2295 }
2297 /* Lets start */
2298 $called = false;
2299 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2301 $cnt ++;
2302 if(!preg_match("/,/",$dn)){
2303 $next = false;
2304 }
2305 $object = preg_replace("/[,].*$/","",$dn);
2306 $dn = preg_replace("/^[^,]+,/","",$dn);
2308 $called = true;
2310 /* Check if current dn is valid */
2311 if($ldap!==NULL){
2312 $ldap->cd($dn);
2313 $ldap->cat($dn,array("dn"));
2314 if($ldap->count()){
2315 $ret[] = $keep.$object;
2316 $keep = "";
2317 }else{
2318 $keep .= $object.",";
2319 }
2320 }else{
2321 $ret[] = $keep.$object;
2322 $keep = "";
2323 }
2324 }
2326 /* No dn was posted */
2327 if($cnt == 0 && !empty($dn)){
2328 $ret[] = $dn;
2329 }
2331 /* Append the rest */
2332 $test = $keep.$dn;
2333 if($called && !empty($test)){
2334 $ret[] = $keep.$dn;
2335 }
2336 $ret['count'] = count($ret) - 1;
2338 return($ret);
2339 }
2341 /* Add "str_split" if this function is missing.
2342 * This function is only available in PHP5
2343 */
2344 if(!function_exists("str_split")){
2345 function str_split($str,$length =1)
2346 {
2347 if($length < 1 ) $length =1;
2349 $ret = array();
2350 for($i = 0 ; $i < strlen($str); $i = $i +$length){
2351 $ret[] = substr($str,$i ,$length);
2352 }
2353 return($ret);
2354 }
2355 }
2358 function get_base_from_hook($dn, $attrib)
2359 {
2360 global $config;
2362 if (isset($config->current['BASE_HOOK'])){
2364 /* Call hook script - if present */
2365 $command= $config->current['BASE_HOOK'];
2367 if ($command != ""){
2368 $command.= " '".LDAP::fix($dn)."' $attrib";
2369 if (check_command($command)){
2370 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2371 exec($command, $output);
2372 if (preg_match("/^[0-9]+$/", $output[0])){
2373 return ($output[0]);
2374 } else {
2375 print_red(_("Warning - base_hook is not available. Using default base."));
2376 return ($config->current['UIDBASE']);
2377 }
2378 } else {
2379 print_red(_("Warning - base_hook is not available. Using default base."));
2380 return ($config->current['UIDBASE']);
2381 }
2383 } else {
2385 print_red(_("Warning - no base_hook defined. Using default base."));
2386 return ($config->current['UIDBASE']);
2388 }
2389 }
2390 }
2392 /* Schema validation functions */
2394 function check_schema_version($class, $version)
2395 {
2396 return preg_match("/\(v$version\)/", $class['DESC']);
2397 }
2399 function check_schema($cfg,$rfc2307bis = FALSE)
2400 {
2401 $messages= array();
2403 /* Get objectclasses */
2404 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2405 $objectclasses = $ldap->get_objectclasses();
2406 if(count($objectclasses) == 0){
2407 print_red(_("Can't get schema information from server. No schema check possible!"));
2408 }
2410 /* This is the default block used for each entry.
2411 * to avoid unset indexes.
2412 */
2413 $def_check = array("REQUIRED_VERSION" => "0",
2414 "SCHEMA_FILES" => array(),
2415 "CLASSES_REQUIRED" => array(),
2416 "STATUS" => FALSE,
2417 "IS_MUST_HAVE" => FALSE,
2418 "MSG" => "",
2419 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2421 /* The gosa base schema */
2422 $checks['gosaObject'] = $def_check;
2423 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2424 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2425 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2426 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2428 /* GOsa Account class */
2429 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2430 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2431 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2432 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2433 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2435 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2436 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2437 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2438 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2439 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2440 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2442 /* Some other checks */
2443 foreach(array(
2444 "gosaCacheEntry" => array("version" => "2.4"),
2445 "gosaDepartment" => array("version" => "2.4"),
2446 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2447 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2448 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2449 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2450 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2451 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2452 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2453 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2454 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2455 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2456 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2457 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2458 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2459 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2460 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2461 "goLdapServer" => array("version" => "2.4"),
2462 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2463 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2464 "goKrbServer" => array("version" => "2.4"),
2465 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2466 ) as $name => $values){
2468 $checks[$name] = $def_check;
2469 if(isset($values['version'])){
2470 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2471 }
2472 if(isset($values['file'])){
2473 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2474 }
2475 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2476 }
2477 foreach($checks as $name => $value){
2478 foreach($value['CLASSES_REQUIRED'] as $class){
2480 if(!isset($objectclasses[$name])){
2481 $checks[$name]['STATUS'] = FALSE;
2482 if($value['IS_MUST_HAVE']){
2483 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2484 }else{
2485 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2486 }
2487 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2488 $checks[$name]['STATUS'] = FALSE;
2490 if($value['IS_MUST_HAVE']){
2491 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2492 }else{
2493 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2494 }
2495 }else{
2496 $checks[$name]['STATUS'] = TRUE;
2497 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2498 }
2499 }
2500 }
2502 $tmp = $objectclasses;
2504 /* The gosa base schema */
2505 $checks['posixGroup'] = $def_check;
2506 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2507 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2508 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2509 $checks['posixGroup']['STATUS'] = TRUE;
2510 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2511 $checks['posixGroup']['MSG'] = "";
2512 $checks['posixGroup']['INFO'] = "";
2514 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2515 if(isset($tmp['posixGroup'])){
2517 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2518 $checks['posixGroup']['STATUS'] = FALSE;
2519 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2520 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2521 }
2522 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2523 $checks['posixGroup']['STATUS'] = FALSE;
2524 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2525 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2526 }
2527 }
2529 return($checks);
2530 }
2535 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2536 {
2537 $tmp = array(
2538 "de_DE" => "German",
2539 "fr_FR" => "French",
2540 "it_IT" => "Italian",
2541 "es_ES" => "Spanish",
2542 "en_US" => "English",
2543 "nl_NL" => "Dutch",
2544 "pl_PL" => "Polish",
2545 "sv_SE" => "Swedish",
2546 "zh_CN" => "Chinese",
2547 "ru_RU" => "Russian");
2549 $tmp2= array(
2550 "de_DE" => _("German"),
2551 "fr_FR" => _("French"),
2552 "it_IT" => _("Italian"),
2553 "es_ES" => _("Spanish"),
2554 "en_US" => _("English"),
2555 "nl_NL" => _("Dutch"),
2556 "pl_PL" => _("Polish"),
2557 "sv_SE" => _("Swedish"),
2558 "zh_CN" => _("Chinese"),
2559 "ru_RU" => _("Russian"));
2561 $ret = array();
2562 if($languages_in_own_language){
2564 $old_lang = setlocale(LC_ALL, 0);
2565 foreach($tmp as $key => $name){
2566 $lang = $key.".UTF-8";
2567 setlocale(LC_ALL, $lang);
2568 if($strip_region_tag){
2569 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2570 }else{
2571 $ret[$key] = _($name)." (".$tmp2[$key].")";
2572 }
2573 }
2574 setlocale(LC_ALL, $old_lang);
2575 }else{
2576 foreach($tmp as $key => $name){
2577 if($strip_region_tag){
2578 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2579 }else{
2580 $ret[$key] = _($name);
2581 }
2582 }
2583 }
2584 return($ret);
2585 }
2588 /* Returns contents of the given POST variable and check magic quotes settings */
2589 function get_post($name)
2590 {
2591 if(!isset($_POST[$name])){
2592 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2593 return(FALSE);
2594 }
2595 if(get_magic_quotes_gpc()){
2596 return(stripcslashes($_POST[$name]));
2597 }else{
2598 return($_POST[$name]);
2599 }
2600 }
2603 /* Check if $ip1 and $ip2 represents a valid IP range
2604 * returns TRUE in case of a valid range, FALSE in case of an error.
2605 */
2606 function is_ip_range($ip1,$ip2)
2607 {
2608 if(!is_ip($ip1) || !is_ip($ip2)){
2609 return(FALSE);
2610 }else{
2611 $ar1 = split("\.",$ip1);
2612 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2614 $ar2 = split("\.",$ip2);
2615 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2616 return($var1 < $var2);
2617 }
2618 }
2621 /* Check if the specified IP address $address is inside the given network */
2622 function is_in_network($network, $netmask, $address)
2623 {
2624 $nw= split('\.', $network);
2625 $nm= split('\.', $netmask);
2626 $ad= split('\.', $address);
2628 /* Generate inverted netmask */
2629 for ($i= 0; $i<4; $i++){
2630 $ni[$i]= 255-$nm[$i];
2631 $la[$i]= $nw[$i] | $ni[$i];
2632 }
2634 /* Transform to integer */
2635 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2636 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2637 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2639 return ($first < $curr&& $last > $curr);
2640 }
2642 /* Return class name in correct case
2643 * mailMethodkolab => mailMethodKolab ( k => K )
2644 */
2645 function get_correct_class_name($cls)
2646 {
2647 global $class_mapping;
2648 if(isset($class_mapping) && is_array($class_mapping)){
2649 foreach($class_mapping as $class => $file){
2650 if(preg_match("/^".$cls."$/i",$class)){
2651 return($class);
2652 }
2653 }
2654 }
2655 return(FALSE);
2656 }
2658 // change_password, changes the Password, of the given dn
2659 function change_password ($dn, $password, $mode=0, $hash= "")
2660 {
2661 global $config;
2662 $newpass= "";
2664 /* Convert to lower. Methods are lowercase */
2665 $hash= strtolower($hash);
2667 // Get all available encryption Methods
2669 // NON STATIC CALL :)
2670 $tmp = new passwordMethod(get_global('config'));
2671 $available = $tmp->get_available_methods();
2673 // read current password entry for $dn, to detect the encryption Method
2674 $ldap = $config->get_ldap_link();
2675 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2676 $attrs = $ldap->fetch ();
2678 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2679 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2680 $deactivated = TRUE;
2681 }else{
2682 $deactivated = FALSE;
2683 }
2685 /* Is ensure that clear passwords will stay clear */
2686 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2687 $hash = "clear";
2688 }
2690 // Detect the encryption Method
2691 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2693 /* Check for supported algorithm */
2694 mt_srand((double) microtime()*1000000);
2696 /* Extract used hash */
2697 if ($hash == ""){
2698 $hash= strtolower($matches[1]);
2699 }
2701 $test = new $available[$hash]($config);
2703 } else {
2704 // User MD5 by default
2705 $hash= "md5";
2706 $test = new $available['md5']($config);
2707 }
2709 /* Feed password backends with information */
2710 $test->dn= $dn;
2711 $test->attrs= $attrs;
2712 $newpass= $test->generate_hash($password);
2714 // Update shadow timestamp?
2715 if (isset($attrs["shadowLastChange"][0])){
2716 $shadow= (int)(date("U") / 86400);
2717 } else {
2718 $shadow= 0;
2719 }
2721 // Write back modified entry
2722 $ldap->cd($dn);
2723 $attrs= array();
2725 // Not for groups
2726 if ($mode == 0){
2728 if ($shadow != 0){
2729 $attrs['shadowLastChange']= $shadow;
2730 }
2732 // Create SMB Password
2733 $attrs= generate_smb_nt_hash($password);
2734 }
2736 /* Readd ! if user was deactivated */
2737 if($deactivated){
2738 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2739 }
2741 $attrs['userPassword']= array();
2742 $attrs['userPassword']= $newpass;
2744 $ldap->modify($attrs);
2746 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2748 if ($ldap->error != 'Success') {
2749 print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2750 $ldap->get_error()));
2751 } else {
2753 /* Run backend method for change/create */
2754 $test->set_password($password);
2756 /* Find postmodify entries for this class */
2757 $command= $config->search("password", "POSTMODIFY",array('menu'));
2759 if ($command != ""){
2760 /* Walk through attribute list */
2761 $command= preg_replace("/%userPassword/", $password, $command);
2762 $command= preg_replace("/%dn/", $dn, $command);
2764 if (check_command($command)){
2765 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2766 exec($command);
2767 } else {
2768 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2769 print_red ($message);
2770 }
2771 }
2772 }
2773 }
2774 // Return something like array['sambaLMPassword']= "lalla..."
2775 function generate_smb_nt_hash($password)
2776 {
2777 global $config;
2778 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2779 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2781 exec($tmp, $ar);
2782 flush();
2783 reset($ar);
2784 $hash= current($ar);
2785 if ($hash == "")
2786 {
2787 print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2788 }
2789 else
2790 {
2791 list($lm,$nt)= split (":", trim($hash));
2793 if ($config->current['SAMBAVERSION'] == 3)
2794 {
2795 $attrs['sambaLMPassword']= $lm;
2796 $attrs['sambaNTPassword']= $nt;
2797 $attrs['sambaPwdLastSet']= date('U');
2798 $attrs['sambaBadPasswordCount']= "0";
2799 $attrs['sambaBadPasswordTime']= "0";
2800 } else {
2801 $attrs['lmPassword']= $lm;
2802 $attrs['ntPassword']= $nt;
2803 $attrs['pwdLastSet']= date('U');
2804 }
2805 return($attrs);
2806 }
2807 }
2809 function crypt_single($string,$enc_type )
2810 {
2811 return( passwordMethod::crypt_single_str($string,$enc_type));
2812 }
2815 function getEntryCSN($dn)
2816 {
2817 global $config;
2818 if(empty($dn) || !is_object($config)){
2819 return("");
2820 }
2822 /* Get attribute that we should use as serial number */
2823 if(isset($config->current['UNIQ_IDENTIFIER'])){
2824 $attr = $config->current['UNIQ_IDENTIFIER'];
2825 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2826 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2827 }
2828 if(!empty($attr)){
2829 $ldap = $config->get_ldap_link();
2830 $ldap->cat($dn,array($attr));
2831 $csn = $ldap->fetch();
2832 if(isset($csn[$attr][0])){
2833 return($csn[$attr][0]);
2834 }
2835 }
2836 return("");
2837 }
2839 /* This function returns the offset for the default timezone.
2840 * $stamp is used to detect summer or winter time.
2841 * In case of PHP5, the integrated timezone functions are used.
2842 * For PHP4 we query an array for offset and add summertime hour.
2843 */
2844 function get_default_timezone($stamp = NULL)
2845 {
2846 global $config;
2847 $tz ="";
2849 /* Default return value if zone could not be detected */
2850 $zone = array("name" => "unconfigured", "value" => 0);
2852 /* Use current timestamp if $stamp is not set */
2853 if($stamp === NULL){
2854 $stamp = time();
2855 }
2857 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2858 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2860 /* Get zonename */
2861 if(isset($config->current['TIMEZONE'])){
2862 $tz = $config->current['TIMEZONE'];
2863 }else{
2864 $tz = $config->data['MAIN']['TIMEZONE'];
2865 }
2867 if(!@date_default_timezone_set($tz)){
2868 print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2869 }
2870 $tz_delta = date("Z", $stamp);
2871 $tz_delta = $tz_delta / 3600 ;
2872 return(array("name" => $tz, "value" => $tz_delta));
2874 }
2875 return($zone);
2876 }
2879 /* Return zone informations */
2880 function _get_tz_zones()
2881 {
2882 $timezones = array(
2883 'Africa/Abidjan' => 0,
2884 'Africa/Accra' => 0,
2885 'Africa/Addis_Ababa' => 10800,
2886 'Africa/Algiers' => 3600,
2887 'Africa/Asmera' => 10800,
2888 'Africa/Bamako' => 0,
2889 'Africa/Bangui' => 3600,
2890 'Africa/Banjul' => 0,
2891 'Africa/Bissau' => 0,
2892 'Africa/Blantyre' => 7200,
2893 'Africa/Brazzaville' => 3600,
2894 'Africa/Bujumbura' => 7200,
2895 'Africa/Cairo' => 7200,
2896 'Africa/Casablanca' => 0,
2897 'Africa/Ceuta' => 3600,
2898 'Africa/Conakry' => 0,
2899 'Africa/Dakar' => 0,
2900 'Africa/Dar_es_Salaam' => 10800,
2901 'Africa/Djibouti' => 10800,
2902 'Africa/Douala' => 3600,
2903 'Africa/El_Aaiun' => 0,
2904 'Africa/Freetown' => 0,
2905 'Africa/Gaborone' => 7200,
2906 'Africa/Harare' => 7200,
2907 'Africa/Johannesburg' => 7200,
2908 'Africa/Kampala' => 10800,
2909 'Africa/Khartoum' => 10800,
2910 'Africa/Kigali' => 7200,
2911 'Africa/Kinshasa' => 3600,
2912 'Africa/Lagos' => 3600,
2913 'Africa/Libreville' => 3600,
2914 'Africa/Lome' => 0,
2915 'Africa/Luanda' => 3600,
2916 'Africa/Lubumbashi' => 7200,
2917 'Africa/Lusaka' => 7200,
2918 'Africa/Malabo' => 3600,
2919 'Africa/Maputo' => 7200,
2920 'Africa/Maseru' => 7200,
2921 'Africa/Mbabane' => 7200,
2922 'Africa/Mogadishu' => 10800,
2923 'Africa/Monrovia' => 0,
2924 'Africa/Nairobi' => 10800,
2925 'Africa/Ndjamena' => 3600,
2926 'Africa/Niamey' => 3600,
2927 'Africa/Nouakchott' => 0,
2928 'Africa/Ouagadougou' => 0,
2929 'Africa/Porto-Novo' => 3600,
2930 'Africa/Sao_Tome' => 0,
2931 'Africa/Timbuktu' => 0,
2932 'Africa/Tripoli' => 7200,
2933 'Africa/Tunis' => 3600,
2934 'Africa/Windhoek' => 3600,
2935 'America/Adak' => -36000,
2936 'America/Anchorage' => -32400,
2937 'America/Anguilla' => -14400,
2938 'America/Antigua' => -14400,
2939 'America/Araguaina' => -10800,
2940 'America/Argentina/Buenos_Aires' => 0,
2941 'America/Argentina/Catamarca' => 0,
2942 'America/Argentina/ComodRivadavia' => 0,
2943 'America/Argentina/Cordoba' => 0,
2944 'America/Argentina/Jujuy' => 0,
2945 'America/Argentina/La_Rioja' => 0,
2946 'America/Argentina/Mendoza' => 0,
2947 'America/Argentina/Rio_Gallegos' => 0,
2948 'America/Argentina/San_Juan' => 0,
2949 'America/Argentina/Tucuman' => 0,
2950 'America/Argentina/Ushuaia' => 0,
2951 'America/Aruba' => -14400,
2952 'America/Asuncion' => -14400,
2953 'America/Atikokan' => 0,
2954 'America/Atka' => -36000,
2955 'America/Bahia' => 0,
2956 'America/Barbados' => -14400,
2957 'America/Belem' => -10800,
2958 'America/Belize' => -21600,
2959 'America/Blanc-Sablon' => 0,
2960 'America/Boa_Vista' => -14400,
2961 'America/Bogota' => -18000,
2962 'America/Boise' => -25200,
2963 'America/Buenos_Aires' => -10800,
2964 'America/Cambridge_Bay' => -25200,
2965 'America/Campo_Grande' => 0,
2966 'America/Cancun' => -21600,
2967 'America/Caracas' => -14400,
2968 'America/Catamarca' => -10800,
2969 'America/Cayenne' => -10800,
2970 'America/Cayman' => -18000,
2971 'America/Chicago' => -21600,
2972 'America/Chihuahua' => -25200,
2973 'America/Coral_Harbour' => 0,
2974 'America/Cordoba' => -10800,
2975 'America/Costa_Rica' => -21600,
2976 'America/Cuiaba' => -14400,
2977 'America/Curacao' => -14400,
2978 'America/Danmarkshavn' => 0,
2979 'America/Dawson' => -28800,
2980 'America/Dawson_Creek' => -25200,
2981 'America/Denver' => -25200,
2982 'America/Detroit' => -18000,
2983 'America/Dominica' => -14400,
2984 'America/Edmonton' => -25200,
2985 'America/Eirunepe' => -18000,
2986 'America/El_Salvador' => -21600,
2987 'America/Ensenada' => -28800,
2988 'America/Fort_Wayne' => -18000,
2989 'America/Fortaleza' => -10800,
2990 'America/Glace_Bay' => -14400,
2991 'America/Godthab' => -10800,
2992 'America/Goose_Bay' => -14400,
2993 'America/Grand_Turk' => -18000,
2994 'America/Grenada' => -14400,
2995 'America/Guadeloupe' => -14400,
2996 'America/Guatemala' => -21600,
2997 'America/Guayaquil' => -18000,
2998 'America/Guyana' => -14400,
2999 'America/Halifax' => -14400,
3000 'America/Havana' => -18000,
3001 'America/Hermosillo' => -25200,
3002 'America/Indiana/Indianapolis' => -18000,
3003 'America/Indiana/Knox' => -18000,
3004 'America/Indiana/Marengo' => -18000,
3005 'America/Indiana/Petersburg' => 0,
3006 'America/Indiana/Vevay' => -18000,
3007 'America/Indiana/Vincennes' => 0,
3008 'America/Indianapolis' => -18000,
3009 'America/Inuvik' => -25200,
3010 'America/Iqaluit' => -18000,
3011 'America/Jamaica' => -18000,
3012 'America/Jujuy' => -10800,
3013 'America/Juneau' => -32400,
3014 'America/Kentucky/Louisville' => -18000,
3015 'America/Kentucky/Monticello' => -18000,
3016 'America/Knox_IN' => -18000,
3017 'America/La_Paz' => -14400,
3018 'America/Lima' => -18000,
3019 'America/Los_Angeles' => -28800,
3020 'America/Louisville' => -18000,
3021 'America/Maceio' => -10800,
3022 'America/Managua' => -21600,
3023 'America/Manaus' => -14400,
3024 'America/Martinique' => -14400,
3025 'America/Mazatlan' => -25200,
3026 'America/Mendoza' => -10800,
3027 'America/Menominee' => -21600,
3028 'America/Merida' => -21600,
3029 'America/Mexico_City' => -21600,
3030 'America/Miquelon' => -10800,
3031 'America/Moncton' => 0,
3032 'America/Monterrey' => -21600,
3033 'America/Montevideo' => -10800,
3034 'America/Montreal' => -18000,
3035 'America/Montserrat' => -14400,
3036 'America/Nassau' => -18000,
3037 'America/New_York' => -18000,
3038 'America/Nipigon' => -18000,
3039 'America/Nome' => -32400,
3040 'America/Noronha' => -7200,
3041 'America/North_Dakota/Center' => -21600,
3042 'America/North_Dakota/New_Salem' => 0,
3043 'America/Panama' => -18000,
3044 'America/Pangnirtung' => -18000,
3045 'America/Paramaribo' => -10800,
3046 'America/Phoenix' => -25200,
3047 'America/Port-au-Prince' => -18000,
3048 'America/Port_of_Spain' => -14400,
3049 'America/Porto_Acre' => -18000,
3050 'America/Porto_Velho' => -14400,
3051 'America/Puerto_Rico' => -14400,
3052 'America/Rainy_River' => -21600,
3053 'America/Rankin_Inlet' => -21600,
3054 'America/Recife' => -10800,
3055 'America/Regina' => -21600,
3056 'America/Rio_Branco' => -18000,
3057 'America/Rosario' => -10800,
3058 'America/Santiago' => -14400,
3059 'America/Santo_Domingo' => -14400,
3060 'America/Sao_Paulo' => -10800,
3061 'America/Scoresbysund' => -3600,
3062 'America/Shiprock' => -25200,
3063 'America/St_Johns' => -12600,
3064 'America/St_Kitts' => -14400,
3065 'America/St_Lucia' => -14400,
3066 'America/St_Thomas' => -14400,
3067 'America/St_Vincent' => -14400,
3068 'America/Swift_Current' => -21600,
3069 'America/Tegucigalpa' => -21600,
3070 'America/Thule' => -14400,
3071 'America/Thunder_Bay' => -18000,
3072 'America/Tijuana' => -28800,
3073 'America/Toronto' => 0,
3074 'America/Tortola' => -14400,
3075 'America/Vancouver' => -28800,
3076 'America/Virgin' => -14400,
3077 'America/Whitehorse' => -28800,
3078 'America/Winnipeg' => -21600,
3079 'America/Yakutat' => -32400,
3080 'America/Yellowknife' => -25200,
3081 'Antarctica/Casey' => 28800,
3082 'Antarctica/Davis' => 25200,
3083 'Antarctica/DumontDUrville' => 36000,
3084 'Antarctica/Mawson' => 21600,
3085 'Antarctica/McMurdo' => 43200,
3086 'Antarctica/Palmer' => -14400,
3087 'Antarctica/Rothera' => 0,
3088 'Antarctica/South_Pole' => 43200,
3089 'Antarctica/Syowa' => 10800,
3090 'Antarctica/VostokArctic/Longyearbyen' => 0,
3091 'Asia/Aden' => 10800,
3092 'Asia/Almaty' => 21600,
3093 'Asia/Amman' => 7200,
3094 'Asia/Anadyr' => 43200,
3095 'Asia/Aqtau' => 14400,
3096 'Asia/Aqtobe' => 18000,
3097 'Asia/Ashgabat' => 18000,
3098 'Asia/Ashkhabad' => 18000,
3099 'Asia/Baghdad' => 10800,
3100 'Asia/Bahrain' => 10800,
3101 'Asia/Baku' => 14400,
3102 'Asia/Bangkok' => 25200,
3103 'Asia/Beirut' => 7200,
3104 'Asia/Bishkek' => 18000,
3105 'Asia/Brunei' => 28800,
3106 'Asia/Calcutta' => 19800,
3107 'Asia/Choibalsan' => 32400,
3108 'Asia/Chongqing' => 28800,
3109 'Asia/Chungking' => 28800,
3110 'Asia/Colombo' => 21600,
3111 'Asia/Dacca' => 21600,
3112 'Asia/Damascus' => 7200,
3113 'Asia/Dhaka' => 21600,
3114 'Asia/Dili' => 32400,
3115 'Asia/Dubai' => 14400,
3116 'Asia/Dushanbe' => 18000,
3117 'Asia/Gaza' => 7200,
3118 'Asia/Harbin' => 28800,
3119 'Asia/Hong_Kong' => 28800,
3120 'Asia/Hovd' => 25200,
3121 'Asia/Irkutsk' => 28800,
3122 'Asia/Istanbul' => 7200,
3123 'Asia/Jakarta' => 25200,
3124 'Asia/Jayapura' => 32400,
3125 'Asia/Jerusalem' => 7200,
3126 'Asia/Kabul' => 16200,
3127 'Asia/Kamchatka' => 43200,
3128 'Asia/Karachi' => 18000,
3129 'Asia/Kashgar' => 28800,
3130 'Asia/Katmandu' => 20700,
3131 'Asia/Krasnoyarsk' => 25200,
3132 'Asia/Kuala_Lumpur' => 28800,
3133 'Asia/Kuching' => 28800,
3134 'Asia/Kuwait' => 10800,
3135 'Asia/Macao' => 28800,
3136 'Asia/Macau' => 0,
3137 'Asia/Magadan' => 39600,
3138 'Asia/Makassar' => 0,
3139 'Asia/Manila' => 28800,
3140 'Asia/Muscat' => 14400,
3141 'Asia/Nicosia' => 7200,
3142 'Asia/Novosibirsk' => 21600,
3143 'Asia/Omsk' => 21600,
3144 'Asia/Oral' => 0,
3145 'Asia/Phnom_Penh' => 25200,
3146 'Asia/Pontianak' => 25200,
3147 'Asia/Pyongyang' => 32400,
3148 'Asia/Qatar' => 10800,
3149 'Asia/Qyzylorda' => 0,
3150 'Asia/Rangoon' => 23400,
3151 'Asia/Riyadh' => 10800,
3152 'Asia/Saigon' => 25200,
3153 'Asia/Sakhalin' => 36000,
3154 'Asia/Samarkand' => 18000,
3155 'Asia/Seoul' => 32400,
3156 'Asia/Shanghai' => 28800,
3157 'Asia/Singapore' => 28800,
3158 'Asia/Taipei' => 28800,
3159 'Asia/Tashkent' => 18000,
3160 'Asia/Tbilisi' => 14400,
3161 'Asia/Tehran' => 12600,
3162 'Asia/Tel_Aviv' => 7200,
3163 'Asia/Thimbu' => 21600,
3164 'Asia/Thimphu' => 21600,
3165 'Asia/Tokyo' => 32400,
3166 'Asia/Ujung_Pandang' => 28800,
3167 'Asia/Ulaanbaatar' => 28800,
3168 'Asia/Ulan_Bator' => 28800,
3169 'Asia/Urumqi' => 28800,
3170 'Asia/Vientiane' => 25200,
3171 'Asia/Vladivostok' => 36000,
3172 'Asia/Yakutsk' => 32400,
3173 'Asia/Yekaterinburg' => 18000,
3174 'Asia/YerevanAtlantic/Azores' => 0,
3175 'Atlantic/Bermuda' => -14400,
3176 'Atlantic/Canary' => 0,
3177 'Atlantic/Cape_Verde' => -3600,
3178 'Atlantic/Faeroe' => 0,
3179 'Atlantic/Jan_Mayen' => 3600,
3180 'Atlantic/Madeira' => 0,
3181 'Atlantic/Reykjavik' => 0,
3182 'Atlantic/South_Georgia' => -7200,
3183 'Atlantic/St_Helena' => 0,
3184 'Atlantic/Stanley' => -14400,
3185 'Australia/ACT' => 36000,
3186 'Australia/Adelaide' => 34200,
3187 'Australia/Brisbane' => 36000,
3188 'Australia/Broken_Hill' => 34200,
3189 'Australia/Canberra' => 36000,
3190 'Australia/Currie' => 0,
3191 'Australia/Darwin' => 34200,
3192 'Australia/Hobart' => 36000,
3193 'Australia/LHI' => 37800,
3194 'Australia/Lindeman' => 36000,
3195 'Australia/Lord_Howe' => 37800,
3196 'Australia/Melbourne' => 36000,
3197 'Australia/NSW' => 36000,
3198 'Australia/North' => 34200,
3199 'Australia/Perth' => 28800,
3200 'Australia/Queensland' => 36000,
3201 'Australia/South' => 34200,
3202 'Australia/Sydney' => 36000,
3203 'Australia/Tasmania' => 36000,
3204 'Australia/Victoria' => 36000,
3205 'Australia/West' => 28800,
3206 'Australia/Yancowinna' => 34200,
3207 'Europe/Amsterdam' => 3600,
3208 'Europe/Andorra' => 3600,
3209 'Europe/Athens' => 7200,
3210 'Europe/Belfast' => 0,
3211 'Europe/Belgrade' => 3600,
3212 'Europe/Berlin' => 3600,
3213 'Europe/Bratislava' => 3600,
3214 'Europe/Brussels' => 3600,
3215 'Europe/Bucharest' => 7200,
3216 'Europe/Budapest' => 3600,
3217 'Europe/Chisinau' => 7200,
3218 'Europe/Copenhagen' => 3600,
3219 'Europe/Dublin' => 0,
3220 'Europe/Gibraltar' => 3600,
3221 'Europe/Guernsey' => 0,
3222 'Europe/Helsinki' => 7200,
3223 'Europe/Isle_of_Man' => 0,
3224 'Europe/Istanbul' => 7200,
3225 'Europe/Jersey' => 0,
3226 'Europe/Kaliningrad' => 7200,
3227 'Europe/Kiev' => 7200,
3228 'Europe/Lisbon' => 0,
3229 'Europe/Ljubljana' => 3600,
3230 'Europe/London' => 0,
3231 'Europe/Luxembourg' => 3600,
3232 'Europe/Madrid' => 3600,
3233 'Europe/Malta' => 3600,
3234 'Europe/Mariehamn' => 0,
3235 'Europe/Minsk' => 7200,
3236 'Europe/Monaco' => 3600,
3237 'Europe/Moscow' => 10800,
3238 'Europe/Nicosia' => 7200,
3239 'Europe/Oslo' => 3600,
3240 'Europe/Paris' => 3600,
3241 'Europe/Prague' => 3600,
3242 'Europe/Riga' => 7200,
3243 'Europe/Rome' => 3600,
3244 'Europe/Samara' => 14400,
3245 'Europe/San_Marino' => 3600,
3246 'Europe/Sarajevo' => 3600,
3247 'Europe/Simferopol' => 7200,
3248 'Europe/Skopje' => 3600,
3249 'Europe/Sofia' => 7200,
3250 'Europe/Stockholm' => 3600,
3251 'Europe/Tallinn' => 7200,
3252 'Europe/Tirane' => 3600,
3253 'Europe/Tiraspol' => 7200,
3254 'Europe/Uzhgorod' => 7200,
3255 'Europe/Vaduz' => 3600,
3256 'Europe/Vatican' => 3600,
3257 'Europe/Vienna' => 3600,
3258 'Europe/Vilnius' => 7200,
3259 'Europe/Volgograd' => 0,
3260 'Europe/Warsaw' => 3600,
3261 'Europe/Zagreb' => 3600,
3262 'Europe/Zaporozhye' => 7200,
3263 'Europe/Zurich' => 3600,
3264 'Indian/Antananarivo' => 10800,
3265 'Indian/Chagos' => 21600,
3266 'Indian/Christmas' => 25200,
3267 'Indian/Cocos' => 23400,
3268 'Indian/Comoro' => 10800,
3269 'Indian/Kerguelen' => 18000,
3270 'Indian/Mahe' => 14400,
3271 'Indian/Maldives' => 18000,
3272 'Indian/Mauritius' => 14400,
3273 'Indian/Mayotte' => 10800,
3274 'Indian/Reunion' => 14400,
3275 'Pacific/Apia' => -39600,
3276 'Pacific/Auckland' => 43200,
3277 'Pacific/Chatham' => 45900,
3278 'Pacific/Easter' => -21600,
3279 'Pacific/Efate' => 39600,
3280 'Pacific/Enderbury' => 46800,
3281 'Pacific/Fakaofo' => -36000,
3282 'Pacific/Fiji' => 43200,
3283 'Pacific/Funafuti' => 43200,
3284 'Pacific/Galapagos' => -21600,
3285 'Pacific/Gambier' => -32400,
3286 'Pacific/Guadalcanal' => 39600,
3287 'Pacific/Guam' => 36000,
3288 'Pacific/Honolulu' => -36000,
3289 'Pacific/Johnston' => -36000,
3290 'Pacific/Kiritimati' => 50400,
3291 'Pacific/Kosrae' => 39600,
3292 'Pacific/Kwajalein' => 43200,
3293 'Pacific/Majuro' => 43200,
3294 'Pacific/Marquesas' => -34200,
3295 'Pacific/Midway' => -39600,
3296 'Pacific/Nauru' => 43200,
3297 'Pacific/Niue' => -39600,
3298 'Pacific/Norfolk' => 41400,
3299 'Pacific/Noumea' => 39600,
3300 'Pacific/Pago_Pago' => -39600,
3301 'Pacific/Palau' => 32400,
3302 'Pacific/Pitcairn' => -28800,
3303 'Pacific/Ponape' => 39600,
3304 'Pacific/Port_Moresby' => 36000,
3305 'Pacific/Rarotonga' => -36000,
3306 'Pacific/Saipan' => 36000,
3307 'Pacific/Samoa' => -39600,
3308 'Pacific/Tahiti' => -36000,
3309 'Pacific/Tarawa' => 43200,
3310 'Pacific/Tongatapu' => 46800,
3311 'Pacific/Truk' => 36000,
3312 'Pacific/Wake' => 43200,
3313 'Pacific/Wallis' => 43200,
3314 'Pacific/Yap' => 36000 );
3316 $dst_timezones = array (
3317 'America/Adak' => 1,
3318 'America/Atka' => 1,
3319 'America/Anchorage' => 1,
3320 'America/Juneau' => 1,
3321 'America/Nome' => 1,
3322 'America/Yakutat' => 1,
3323 'America/Dawson' => 1,
3324 'America/Ensenada' => 1,
3325 'America/Los_Angeles' => 1,
3326 'America/Tijuana' => 1,
3327 'America/Vancouver' => 1,
3328 'America/Whitehorse' => 1,
3329 'America/Boise' => 1,
3330 'America/Cambridge_Bay' => 1,
3331 'America/Chihuahua' => 1,
3332 'America/Denver' => 1,
3333 'America/Edmonton' => 1,
3334 'America/Inuvik' => 1,
3335 'America/Mazatlan' => 1,
3336 'America/Shiprock' => 1,
3337 'America/Yellowknife' => 1,
3338 'America/Cancun' => 1,
3339 'America/Chicago' => 1,
3340 'America/Menominee' => 1,
3341 'America/Merida' => 1,
3342 'America/Monterrey' => 1,
3343 'America/North_Dakota/Center' => 1,
3344 'America/Rainy_River' => 1,
3345 'America/Rankin_Inlet' => 1,
3346 'America/Winnipeg' => 1,
3347 'Pacific/Easter' => 1,
3348 'America/Detroit' => 1,
3349 'America/Grand_Turk' => 1,
3350 'America/Havana' => 1,
3351 'America/Iqaluit' => 1,
3352 'America/Kentucky/Louisville' => 1,
3353 'America/Kentucky/Monticello' => 1,
3354 'America/Louisville' => 1,
3355 'America/Montreal' => 1,
3356 'America/Nassau' => 1,
3357 'America/New_York' => 1,
3358 'America/Nipigon' => 1,
3359 'America/Pangnirtung' => 1,
3360 'America/Thunder_Bay' => 1,
3361 'America/Asuncion' => 1,
3362 'America/Cuiaba' => 1,
3363 'America/Glace_Bay' => 1,
3364 'America/Goose_Bay' => 1,
3365 'America/Halifax' => 1,
3366 'America/Santiago' => 1,
3367 'Antarctica/Palmer' => 1,
3368 'Atlantic/Bermuda' => 1,
3369 'Atlantic/Stanley' => 1,
3370 'America/St_Johns' => 1,
3371 'America/Araguaina' => 1,
3372 'America/Fortaleza' => 1,
3373 'America/Godthab' => 1,
3374 'America/Maceio' => 1,
3375 'America/Miquelon' => 1,
3376 'America/Recife' => 1,
3377 'America/Sao_Paulo' => 1,
3378 'America/Scoresbysund' => 1,
3379 'Atlantic/Canary' => 1,
3380 'Atlantic/Faeroe' => 1,
3381 'Atlantic/Madeira' => 1,
3382 'Europe/Belfast' => 1,
3383 'Europe/Dublin' => 1,
3384 'Europe/Lisbon' => 1,
3385 'Europe/London' => 1,
3386 'Africa/Ceuta' => 1,
3387 'Africa/Windhoek' => 1,
3388 'Atlantic/Jan_Mayen' => 1,
3389 'Europe/Amsterdam' => 1,
3390 'Europe/Andorra' => 1,
3391 'Europe/Belgrade' => 1,
3392 'Europe/Berlin' => 1,
3393 'Europe/Bratislava' => 1,
3394 'Europe/Brussels' => 1,
3395 'Europe/Budapest' => 1,
3396 'Europe/Copenhagen' => 1,
3397 'Europe/Gibraltar' => 1,
3398 'Europe/Ljubljana' => 1,
3399 'Europe/Luxembourg' => 1,
3400 'Europe/Madrid' => 1,
3401 'Europe/Malta' => 1,
3402 'Europe/Monaco' => 1,
3403 'Europe/Oslo' => 1,
3404 'Europe/Paris' => 1,
3405 'Europe/Prague' => 1,
3406 'Europe/Rome' => 1,
3407 'Europe/San_Marino' => 1,
3408 'Europe/Sarajevo' => 1,
3409 'Europe/Skopje' => 1,
3410 'Europe/Stockholm' => 1,
3411 'Europe/Tirane' => 1,
3412 'Europe/Vaduz' => 1,
3413 'Europe/Vatican' => 1,
3414 'Europe/Vienna' => 1,
3415 'Europe/Warsaw' => 1,
3416 'Europe/Zagreb' => 1,
3417 'Europe/Zurich' => 1,
3418 'Africa/Cairo' => 1,
3419 'Asia/Amman' => 1,
3420 'Asia/Beirut' => 1,
3421 'Asia/Damascus' => 1,
3422 'Asia/Gaza' => 1,
3423 'Asia/Istanbul' => 1,
3424 'Asia/Jerusalem' => 1,
3425 'Asia/Nicosia' => 1,
3426 'Asia/Tel_Aviv' => 1,
3427 'Europe/Athens' => 1,
3428 'Europe/Bucharest' => 1,
3429 'Europe/Chisinau' => 1,
3430 'Europe/Helsinki' => 1,
3431 'Europe/Istanbul' => 1,
3432 'Europe/Kaliningrad' => 1,
3433 'Europe/Kiev' => 1,
3434 'Europe/Minsk' => 1,
3435 'Europe/Nicosia' => 1,
3436 'Europe/Riga' => 1,
3437 'Europe/Simferopol' => 1,
3438 'Europe/Sofia' => 1,
3439 'Europe/Tiraspol' => 1,
3440 'Europe/Uzhgorod' => 1,
3441 'Europe/Zaporozhye' => 1,
3442 'Asia/Baghdad' => 1,
3443 'Europe/Moscow' => 1,
3444 'Asia/Tehran' => 1,
3445 'Asia/Aqtau' => 1,
3446 'Asia/Baku' => 1,
3447 'Asia/Tbilisi' => 1,
3448 'Europe/Samara' => 1,
3449 'Asia/Aqtobe' => 1,
3450 'Asia/Bishkek' => 1,
3451 'Asia/Yekaterinburg' => 1,
3452 'Asia/Almaty' => 1,
3453 'Asia/Novosibirsk' => 1,
3454 'Asia/Omsk' => 1,
3455 'Asia/Krasnoyarsk' => 1,
3456 'Asia/Irkutsk' => 1,
3457 'Asia/Yakutsk' => 1,
3458 'Australia/Adelaide' => 1,
3459 'Australia/Broken_Hill' => 1,
3460 'Australia/South' => 1,
3461 'Australia/Yancowinna' => 1,
3462 'Asia/Sakhalin' => 1,
3463 'Asia/Vladivostok' => 1,
3464 'Australia/ACT' => 1,
3465 'Australia/Canberra' => 1,
3466 'Australia/Hobart' => 1,
3467 'Australia/Melbourne' => 1,
3468 'Australia/NSW' => 1,
3469 'Australia/Sydney' => 1,
3470 'Australia/Tasmania' => 1,
3471 'Australia/Victoria' => 1,
3472 'Australia/LHI' => 1,
3473 'Australia/Lord_Howe' => 1,
3474 'Asia/Magadan' => 1,
3475 'Antarctica/McMurdo' => 1,
3476 'Antarctica/South_Pole' => 1,
3477 'Asia/Anadyr' => 1,
3478 'Asia/Kamchatka' => 1,
3479 'Pacific/Auckland' => 1,
3480 'Pacific/Chatham' => 1,
3481 );
3482 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3483 }
3486 function display_error_page()
3487 {
3488 $smarty= get_smarty();
3489 $smarty->display(get_template_path('headers.tpl'));
3490 echo "<body>".msg_dialog::get_dialogs()."</body></html>";
3491 exit();
3492 }
3494 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3495 ?>