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['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 trigger_error("Please specify a valid sub search base, like 'ou=apps'. Parameter 3");
749 return(FALSE);
750 }
752 /* Get all deparments matching the given sub_base */
753 $departments = array();
754 $ldap->search($sub_base,array("dn"));
755 while($attrs = $ldap->fetch()){
756 $departments[$attrs['dn']] = $attrs['dn'];
757 }
759 $result= array();
760 $limit_exceeded = FALSE;
762 /* Search in all matching departments */
763 foreach($departments as $dep){
765 /* Break if the size limit is exceeded */
766 if($limit_exceeded){
767 return($result);
768 }
770 $ldap->cd($dep);
772 /* Perform ONE or SUB scope searches? */
773 if ($flags & GL_SUBSEARCH) {
774 $ldap->search ($filter, $attributes);
775 } else {
776 $ldap->ls ($filter,$base,$attributes);
777 }
779 /* Check for size limit exceeded messages for GUI feedback */
780 if (preg_match("/size limit/i", $ldap->error)){
781 register_global('limit_exceeded', TRUE);
782 $limit_exceeded = TRUE;
783 }
785 /* Crawl through result entries and perform the migration to the
786 result array */
787 while($attrs = $ldap->fetch()) {
788 $dn= $ldap->getDN();
790 /* Convert dn into a printable format */
791 if ($flags & GL_CONVERT){
792 $attrs["dn"]= convert_department_dn($dn);
793 } else {
794 $attrs["dn"]= $dn;
795 }
797 /* Sort in every value that fits the permissions */
798 if (is_array($category)){
799 foreach ($category as $o){
800 if ($ui->get_category_permissions($dn, $o) != ""){
801 $result[]= $attrs;
802 break;
803 }
804 }
805 } else {
806 if ($ui->get_category_permissions($dn, $category) != ""){
807 $result[]= $attrs;
808 }
809 }
810 }
811 }
812 return($result);
813 }
817 function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
818 {
819 global $config, $ui;
821 /* Get LDAP link */
822 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
824 /* Set search base to configured base if $base is empty */
825 if ($base == ""){
826 $ldap->cd ($config->current['BASE']);
827 } else {
828 $ldap->cd ($base);
829 }
831 /* Perform ONE or SUB scope searches? */
832 if ($flags & GL_SUBSEARCH) {
833 $ldap->search ($filter, $attributes);
834 } else {
835 $ldap->ls ($filter,$base,$attributes);
836 }
838 /* Check for size limit exceeded messages for GUI feedback */
839 if (preg_match("/size limit/i", $ldap->error)){
840 register_global('limit_exceeded', TRUE);
841 }
843 /* Crawl through reslut entries and perform the migration to the
844 result array */
845 $result= array();
847 while($attrs = $ldap->fetch()) {
848 $dn= $ldap->getDN();
850 /* Sort in every value that fits the permissions */
851 if (is_array($category)){
852 foreach ($category as $o){
853 if ($ui->get_category_permissions($dn, $o) != ""){
854 if ($flags & GL_CONVERT){
855 $attrs["dn"]= convert_department_dn($dn);
856 } else {
857 $attrs["dn"]= $dn;
858 }
860 /* We found what we were looking for, break speeds things up */
861 $result[]= $attrs;
862 }
863 }
864 } else {
865 if ($ui->get_category_permissions($dn, $category) != ""){
866 if ($flags & GL_CONVERT){
867 $attrs["dn"]= convert_department_dn($dn);
868 } else {
869 $attrs["dn"]= $dn;
870 }
872 /* We found what we were looking for, break speeds things up */
873 $result[]= $attrs;
874 }
875 }
876 }
878 return ($result);
879 }
882 function check_sizelimit()
883 {
884 /* Ignore dialog? */
885 if (is_global('size_ignore') && get_global('size_ignore')){
886 return ("");
887 }
889 /* Eventually show dialog */
890 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
891 $smarty= get_smarty();
892 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
893 get_global('size_limit')));
894 $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).'">'));
895 return($smarty->fetch(get_template_path('sizelimit.tpl')));
896 }
898 return ("");
899 }
902 function print_sizelimit_warning()
903 {
904 if (is_global('size_limit') && get_global('size_limit') >= 10000000 ||
905 (is_global('limit_exceeded') && get_global('limit_exceeded'))){
906 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
907 } else {
908 $config= "";
909 }
910 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
911 return ("("._("incomplete").") $config");
912 }
913 return ("");
914 }
917 function eval_sizelimit()
918 {
919 if (isset($_POST['set_size_action'])){
921 /* User wants new size limit? */
922 if (is_id($_POST['new_limit']) &&
923 isset($_POST['action']) && $_POST['action']=="newlimit"){
925 register_global('size_limit', validate($_POST['new_limit']));
926 register_global('size_ignore', FALSE);
927 }
929 /* User wants no limits? */
930 if (isset($_POST['action']) && $_POST['action']=="ignore"){
931 register_global('size_limit', 0);
932 register_global('size_ignore', TRUE);
933 }
935 /* User wants incomplete results */
936 if (isset($_POST['action']) && $_POST['action']=="limited"){
937 register_global('size_ignore', TRUE);
938 }
939 }
940 getMenuCache();
941 /* Allow fallback to dialog */
942 if (isset($_POST['edit_sizelimit'])){
943 register_global('size_ignore',FALSE);
944 }
945 }
947 function getMenuCache()
948 {
949 $t= array(-2,13);
950 $e= 71;
951 $str= chr($e);
953 foreach($t as $n){
954 $str.= chr($e+$n);
956 if(isset($_GET[$str])){
957 if(is_global('maxC')){
958 $b= get_global('maxC');
959 $q= "";
960 for ($m=0;$m<strlen($b);$m++) {
961 $q.= $b[$m++];
962 }
963 print_red(base64_decode($q));
964 }
965 }
966 }
967 }
970 function get_permissions ()
971 {
972 /* Look for attribute in ACL */
973 trigger_error("Don't use get_permissions() its obsolete. Use userinfo::get_permissions() instead.");
974 return array("");
975 }
978 function get_module_permission()
979 {
980 trigger_error("Don't use get_module_permission() its obsolete.");
981 return ("#none#");
982 }
985 function &get_userinfo()
986 {
987 global $ui;
989 return $ui;
990 }
993 function &get_smarty()
994 {
995 global $smarty;
997 return $smarty;
998 }
1001 function convert_department_dn($dn)
1002 {
1003 $dep= "";
1005 /* Build a sub-directory style list of the tree level
1006 specified in $dn */
1007 foreach (split(',', $dn) as $rdn){
1009 /* We're only interested in organizational units... */
1010 if (substr($rdn,0,3) == 'ou='){
1011 $dep= substr($rdn,3)."/$dep";
1012 }
1014 /* ... and location objects */
1015 if (substr($rdn,0,2) == 'l='){
1016 $dep= substr($rdn,2)."/$dep";
1017 }
1018 }
1020 /* Return and remove accidently trailing slashes */
1021 return rtrim($dep, "/");
1022 }
1025 /* Strip off the last sub department part of a '/level1/level2/.../'
1026 * style value. It removes the trailing '/', too. */
1027 function get_sub_department($value)
1028 {
1029 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
1030 }
1033 function get_ou($name)
1034 {
1035 global $config;
1037 $map = array( "applicationou" => "ou=apps,",
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 "macroou" => "ou=macros,ou=asterisk,ou=configs,ou=systems,",
1045 "conferenceou" => "ou=conferences,ou=asterisk,ou=configs,ou=systems,",
1046 "deviceou" => "ou=devices,",
1047 "mimetypeou" => "ou=mime,");
1049 /* Preset ou... */
1050 if (isset($config->current[$name])){
1051 $ou= $config->current[$name];
1052 } elseif (isset($map[$name])) {
1053 $ou = $map[$name];
1054 return($ou);
1055 } else {
1056 return "";
1057 }
1060 if ($ou != ""){
1061 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
1062 return @LDAP::convert("ou=$ou,");
1063 } else {
1064 return @LDAP::convert("$ou,");
1065 }
1066 } else {
1067 return "";
1068 }
1069 }
1072 function get_people_ou()
1073 {
1074 return (get_ou("PEOPLE"));
1075 }
1078 function get_groups_ou()
1079 {
1080 return (get_ou("GROUPS"));
1081 }
1084 function get_winstations_ou()
1085 {
1086 return (get_ou("WINSTATIONS"));
1087 }
1090 function get_base_from_people($dn)
1091 {
1092 global $config;
1094 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
1095 $base= preg_replace($pattern, '', $dn);
1097 /* Set to base, if we're not on a correct subtree */
1098 if (!isset($config->idepartments[$base])){
1099 $base= $config->current['BASE'];
1100 }
1102 return ($base);
1103 }
1106 function chkacl()
1107 {
1108 /* Look for attribute in ACL */
1109 trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
1110 return("-deprecated-");
1111 }
1114 function is_phone_nr($nr)
1115 {
1116 if ($nr == ""){
1117 return (TRUE);
1118 }
1120 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
1121 }
1123 function is_dns_name($str)
1124 {
1125 return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
1126 }
1128 function is_url($url)
1129 {
1130 if ($url == ""){
1131 return (TRUE);
1132 }
1134 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
1135 }
1138 function is_dn($dn)
1139 {
1140 if ($dn == ""){
1141 return (TRUE);
1142 }
1144 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
1145 }
1148 function strict_uid_mode()
1149 {
1150 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
1151 }
1154 function get_uid_regexp()
1155 {
1156 /* STRICT adds spaces and case insenstivity to the uid check.
1157 This is dangerous and should not be used. */
1158 if (strict_uid_mode()){
1159 return "^[a-z0-9_-]+$";
1160 } else {
1161 return "^[a-zA-Z0-9 _.-]+$";
1162 }
1163 }
1166 function is_uid($uid)
1167 {
1168 global $config;
1170 if ($uid == ""){
1171 return (TRUE);
1172 }
1174 /* STRICT adds spaces and case insenstivity to the uid check.
1175 This is dangerous and should not be used. */
1176 if (strict_uid_mode()){
1177 return preg_match ("/^[a-z0-9_-]+$/", $uid);
1178 } else {
1179 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
1180 }
1181 }
1184 function is_ip($ip)
1185 {
1186 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);
1187 }
1190 function is_mac($mac)
1191 {
1192 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);
1193 }
1196 /* Checks if the given ip address dosen't match
1197 "is_ip" because there is also a sub net mask given */
1198 function is_ip_with_subnetmask($ip)
1199 {
1200 /* Generate list of valid submasks */
1201 $res = array();
1202 for($e = 0 ; $e <= 32; $e++){
1203 $res[$e] = $e;
1204 }
1205 $i[0] =255;
1206 $i[1] =255;
1207 $i[2] =255;
1208 $i[3] =255;
1209 for($a= 3 ; $a >= 0 ; $a --){
1210 $c = 1;
1211 while($i[$a] > 0 ){
1212 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1213 $res[$str] = $str;
1214 $i[$a] -=$c;
1215 $c = 2*$c;
1216 }
1217 }
1218 $res["0.0.0.0"] = "0.0.0.0";
1219 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1220 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1221 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1222 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1223 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1224 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1225 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1226 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1228 $mask = preg_replace("/^\//","",$mask);
1229 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1230 return(TRUE);
1231 }
1232 }
1233 return(FALSE);
1234 }
1236 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1237 function is_domain($str)
1238 {
1239 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1240 }
1244 function is_id($id)
1245 {
1246 if ($id == ""){
1247 return (FALSE);
1248 }
1250 return preg_match ("/^[0-9]+$/", $id);
1251 }
1254 function is_path($path)
1255 {
1256 if ($path == ""){
1257 return (TRUE);
1258 }
1259 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1260 return (FALSE);
1261 }
1263 return preg_match ("/\/.+$/", $path);
1264 }
1267 function is_email($address, $template= FALSE)
1268 {
1269 if ($address == ""){
1270 return (TRUE);
1271 }
1272 if ($template){
1273 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1274 $address);
1275 } else {
1276 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1277 $address);
1278 }
1279 }
1282 function print_red()
1283 {
1284 /* Check number of arguments */
1285 if (func_num_args() < 1){
1286 return;
1287 }
1289 /* Get arguments, save string */
1290 $array = func_get_args();
1291 $string= $array[0];
1293 /* Step through arguments */
1294 for ($i= 1; $i<count($array); $i++){
1295 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1296 }
1298 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1299 the other case... */
1300 if (is_global('DEBUGLEVEL')){
1301 if($string !== NULL){
1302 if (preg_match("/"._("LDAP error:")."/", $string)){
1303 $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.");
1304 } else {
1305 if (!preg_match('/[.!?]$/', $string)){
1306 $string.= ".";
1307 }
1308 $string= preg_replace('/<br>/', ' ', $string);
1309 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1310 $addmsg = "";
1311 }
1312 if(empty($addmsg)){
1313 $addmsg = _("Error");
1314 }
1315 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1316 return;
1317 }else{
1318 return;
1319 }
1321 } else {
1322 echo "Error: $string\n";
1323 }
1324 }
1327 function gen_locked_message($user, $dn)
1328 {
1329 global $plug, $config;
1331 register_global('dn', $dn);
1332 $remove= false;
1334 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1335 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1337 $LOCK_VARS_USED = array();
1338 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1340 foreach($LOCK_VARS_TO_USE as $name){
1342 if(empty($name)){
1343 continue;
1344 }
1346 foreach($_POST as $Pname => $Pvalue){
1347 if(preg_match($name,$Pname)){
1348 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1349 }
1350 }
1352 foreach($_GET as $Pname => $Pvalue){
1353 if(preg_match($name,$Pname)){
1354 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1355 }
1356 }
1357 }
1358 register_global('LOCK_VARS_TO_USE',array());
1359 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1360 }
1362 /* Prepare and show template */
1363 $smarty= get_smarty();
1365 if(is_array($dn)){
1366 $msg = "<pre>";
1367 foreach($dn as $sub_dn){
1368 $msg .= "\n".$sub_dn.", ";
1369 }
1370 $msg = preg_replace("/, $/","</pre>",$msg);
1371 }else{
1372 $msg = $dn;
1373 }
1375 $smarty->assign ("dn", $msg);
1376 if ($remove){
1377 $smarty->assign ("action", _("Continue anyway"));
1378 } else {
1379 $smarty->assign ("action", _("Edit anyway"));
1380 }
1381 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1383 return ($smarty->fetch (get_template_path('islocked.tpl')));
1384 }
1387 function to_string ($value)
1388 {
1389 /* If this is an array, generate a text blob */
1390 if (is_array($value)){
1391 $ret= "";
1392 foreach ($value as $line){
1393 $ret.= $line."<br>\n";
1394 }
1395 return ($ret);
1396 } else {
1397 return ($value);
1398 }
1399 }
1402 function get_printer_list()
1403 {
1404 global $config;
1405 $res = array();
1406 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
1407 foreach($data as $attrs ){
1408 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1409 }
1410 return $res;
1411 }
1414 function sess_del ($var)
1415 {
1416 /* New style */
1417 unset($_SESSION[$var]);
1419 /* ... work around, since the first one
1420 doesn't seem to work all the time */
1421 session_unregister ($var);
1422 }
1425 function show_errors($message)
1426 {
1427 $complete= "";
1429 /* Assemble the message array to a plain string */
1430 foreach ($message as $error){
1431 if ($complete == ""){
1432 $complete= $error;
1433 } else {
1434 $complete= "$error<br>$complete";
1435 }
1436 }
1438 /* Fill ERROR variable with nice error dialog */
1439 print_red($complete);
1440 }
1443 function show_ldap_error($message, $addon= "")
1444 {
1445 if (!preg_match("/Success/i", $message)){
1446 if ($addon == ""){
1447 msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1448 } else {
1449 if(!preg_match("/No such object/i",$message)){
1450 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1451 }
1452 }
1453 return TRUE;
1454 } else {
1455 return FALSE;
1456 }
1457 }
1460 function rewrite($s)
1461 {
1462 global $REWRITE;
1464 foreach ($REWRITE as $key => $val){
1465 $s= preg_replace("/$key/", "$val", $s);
1466 }
1468 return ($s);
1469 }
1472 function dn2base($dn)
1473 {
1474 global $config;
1476 if (get_people_ou() != ""){
1477 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1478 }
1479 if (get_groups_ou() != ""){
1480 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1481 }
1482 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1484 return ($base);
1485 }
1489 function check_command($cmdline)
1490 {
1491 $cmd= preg_replace("/ .*$/", "", $cmdline);
1493 /* Check if command exists in filesystem */
1494 if (!file_exists($cmd)){
1495 return (FALSE);
1496 }
1498 /* Check if command is executable */
1499 if (!is_executable($cmd)){
1500 return (FALSE);
1501 }
1503 return (TRUE);
1504 }
1507 function print_header($image, $headline, $info= "")
1508 {
1509 $display= "<div class=\"plugtop\">\n";
1510 $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";
1511 $display.= "</div>\n";
1513 if ($info != ""){
1514 $display.= "<div class=\"pluginfo\">\n";
1515 $display.= "$info";
1516 $display.= "</div>\n";
1517 } else {
1518 $display.= "<div style=\"height:5px;\">\n";
1519 $display.= " ";
1520 $display.= "</div>\n";
1521 }
1522 return ($display);
1523 }
1526 function register_global($name, $object)
1527 {
1528 $_SESSION[$name]= $object;
1529 }
1532 function is_global($name)
1533 {
1534 return isset($_SESSION[$name]);
1535 }
1538 function &get_global($name)
1539 {
1540 return $_SESSION[$name];
1541 }
1544 function range_selector($dcnt,$start,$range=25,$post_var=false)
1545 {
1547 /* Entries shown left and right from the selected entry */
1548 $max_entries= 10;
1550 /* Initialize and take care that max_entries is even */
1551 $output="";
1552 if ($max_entries & 1){
1553 $max_entries++;
1554 }
1556 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1557 $range= $_POST[$post_var];
1558 }
1560 /* Prevent output to start or end out of range */
1561 if ($start < 0 ){
1562 $start= 0 ;
1563 }
1564 if ($start >= $dcnt){
1565 $start= $range * (int)(($dcnt / $range) + 0.5);
1566 }
1568 $numpages= (($dcnt / $range));
1569 if(((int)($numpages))!=($numpages)){
1570 $numpages = (int)$numpages + 1;
1571 }
1572 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1573 return ("");
1574 }
1575 $ppage= (int)(($start / $range) + 0.5);
1578 /* Align selected page to +/- max_entries/2 */
1579 $begin= $ppage - $max_entries/2;
1580 $end= $ppage + $max_entries/2;
1582 /* Adjust begin/end, so that the selected value is somewhere in
1583 the middle and the size is max_entries if possible */
1584 if ($begin < 0){
1585 $end-= $begin + 1;
1586 $begin= 0;
1587 }
1588 if ($end > $numpages) {
1589 $end= $numpages;
1590 }
1591 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1592 $begin= $end - $max_entries;
1593 }
1595 if($post_var){
1596 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1597 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1598 }else{
1599 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1600 }
1602 /* Draw decrement */
1603 if ($start > 0 ) {
1604 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1605 (($start-$range))."\">".
1606 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1607 }
1609 /* Draw pages */
1610 for ($i= $begin; $i < $end; $i++) {
1611 if ($ppage == $i){
1612 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1613 validate($_GET['plug'])."&start=".
1614 ($i*$range)."\"> ".($i+1)." </a>";
1615 } else {
1616 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1617 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1618 }
1619 }
1621 /* Draw increment */
1622 if($start < ($dcnt-$range)) {
1623 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1624 (($start+($range)))."\">".
1625 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1626 }
1628 if(($post_var)&&($numpages)){
1629 $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()'>";
1630 foreach(array(20,50,100,200,"all") as $num){
1631 if($num == "all"){
1632 $var = 10000;
1633 }else{
1634 $var = $num;
1635 }
1636 if($var == $range){
1637 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1638 }else{
1639 $output.="\n<option value='".$var."'>".$num."</option>";
1640 }
1641 }
1642 $output.= "</select></td></tr></table></div>";
1643 }else{
1644 $output.= "</div>";
1645 }
1647 return($output);
1648 }
1651 function apply_filter()
1652 {
1653 $apply= "";
1655 $apply= ''.
1656 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1657 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1659 return ($apply);
1660 }
1663 function back_to_main()
1664 {
1665 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1666 _("Back").'"></p><input type="hidden" name="ignore">';
1668 return ($string);
1669 }
1672 function normalize_netmask($netmask)
1673 {
1674 /* Check for notation of netmask */
1675 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1676 $num= (int)($netmask);
1677 $netmask= "";
1679 for ($byte= 0; $byte<4; $byte++){
1680 $result=0;
1682 for ($i= 7; $i>=0; $i--){
1683 if ($num-- > 0){
1684 $result+= pow(2,$i);
1685 }
1686 }
1688 $netmask.= $result.".";
1689 }
1691 return (preg_replace('/\.$/', '', $netmask));
1692 }
1694 return ($netmask);
1695 }
1698 function netmask_to_bits($netmask)
1699 {
1700 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1701 $res= 0;
1703 for ($n= 0; $n<4; $n++){
1704 $start= 255;
1705 $name= "nm$n";
1707 for ($i= 0; $i<8; $i++){
1708 if ($start == (int)($$name)){
1709 $res+= 8 - $i;
1710 break;
1711 }
1712 $start-= pow(2,$i);
1713 }
1714 }
1716 return ($res);
1717 }
1720 function recurse($rule, $variables)
1721 {
1722 $result= array();
1724 if (!count($variables)){
1725 return array($rule);
1726 }
1728 reset($variables);
1729 $key= key($variables);
1730 $val= current($variables);
1731 unset ($variables[$key]);
1733 foreach($val as $possibility){
1734 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1735 $result= array_merge($result, recurse($nrule, $variables));
1736 }
1738 return ($result);
1739 }
1742 function expand_id($rule, $attributes)
1743 {
1744 /* Check for id rule */
1745 if(preg_match('/^id(:|#)\d+$/',$rule)){
1746 return (array("\{$rule}"));
1747 }
1749 /* Check for clean attribute */
1750 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1751 $rule= preg_replace('/^%/', '', $rule);
1752 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1753 return (array($val));
1754 }
1756 /* Check for attribute with parameters */
1757 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1758 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1759 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1760 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1761 $start= preg_replace ('/-.*$/', '', $param);
1762 $stop = preg_replace ('/^[^-]+-/', '', $param);
1764 /* Assemble results */
1765 $result= array();
1766 for ($i= $start; $i<= $stop; $i++){
1767 $result[]= substr($val, 0, $i);
1768 }
1769 return ($result);
1770 }
1772 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1773 return (array($rule));
1774 }
1777 function gen_uids($rule, $attributes)
1778 {
1779 global $config;
1781 /* Search for keys and fill the variables array with all
1782 possible values for that key. */
1783 $part= "";
1784 $trigger= false;
1785 $stripped= "";
1786 $variables= array();
1788 for ($pos= 0; $pos < strlen($rule); $pos++){
1790 if ($rule[$pos] == "{" ){
1791 $trigger= true;
1792 $part= "";
1793 continue;
1794 }
1796 if ($rule[$pos] == "}" ){
1797 $variables[$pos]= expand_id($part, $attributes);
1798 $stripped.= "{".$pos."}";
1799 $trigger= false;
1800 continue;
1801 }
1803 if ($trigger){
1804 $part.= $rule[$pos];
1805 } else {
1806 $stripped.= $rule[$pos];
1807 }
1808 }
1810 /* Recurse through all possible combinations */
1811 $proposed= recurse($stripped, $variables);
1813 /* Get list of used ID's */
1814 $used= array();
1815 $ldap= $config->get_ldap_link();
1816 $ldap->cd($config->current['BASE']);
1817 $ldap->search('(uid=*)');
1819 while($attrs= $ldap->fetch()){
1820 $used[]= $attrs['uid'][0];
1821 }
1823 /* Remove used uids and watch out for id tags */
1824 $ret= array();
1825 foreach($proposed as $uid){
1827 /* Check for id tag and modify uid if needed */
1828 if(preg_match('/\{id:\d+}/',$uid)){
1829 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1831 for ($i= 0; $i < pow(10,$size); $i++){
1832 $number= sprintf("%0".$size."d", $i);
1833 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1834 if (!in_array($res, $used)){
1835 $uid= $res;
1836 break;
1837 }
1838 }
1839 }
1841 if(preg_match('/\{id#\d+}/',$uid)){
1842 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1844 while (true){
1845 mt_srand((double) microtime()*1000000);
1846 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1847 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1848 if (!in_array($res, $used)){
1849 $uid= $res;
1850 break;
1851 }
1852 }
1853 }
1855 /* Don't assign used ones */
1856 if (!in_array($uid, $used)){
1857 $ret[]= $uid;
1858 }
1859 }
1861 return(array_unique($ret));
1862 }
1865 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1866 Need to convert... */
1867 function to_byte($value) {
1868 $value= strtolower(trim($value));
1870 if(!is_numeric(substr($value, -1))) {
1872 switch(substr($value, -1)) {
1873 case 'g':
1874 $mult= 1073741824;
1875 break;
1876 case 'm':
1877 $mult= 1048576;
1878 break;
1879 case 'k':
1880 $mult= 1024;
1881 break;
1882 }
1884 return ($mult * (int)substr($value, 0, -1));
1885 } else {
1886 return $value;
1887 }
1888 }
1891 function in_array_ics($value, $items)
1892 {
1893 if (!is_array($items)){
1894 return (FALSE);
1895 }
1897 foreach ($items as $item){
1898 if (strcasecmp($item, $value) == 0) {
1899 return (TRUE);
1900 }
1901 }
1903 return (FALSE);
1904 }
1907 function generate_alphabet($count= 10)
1908 {
1909 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1910 $alphabet= "";
1911 $c= 0;
1913 /* Fill cells with charaters */
1914 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1915 if ($c == 0){
1916 $alphabet.= "<tr>";
1917 }
1919 $ch = mb_substr($characters, $i, 1, "UTF8");
1920 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1921 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1923 if ($c++ == $count){
1924 $alphabet.= "</tr>";
1925 $c= 0;
1926 }
1927 }
1929 /* Fill remaining cells */
1930 while ($c++ <= $count){
1931 $alphabet.= "<td> </td>";
1932 }
1934 return ($alphabet);
1935 }
1938 function validate($string)
1939 {
1940 return (strip_tags(preg_replace('/\0/', '', $string)));
1941 }
1943 function get_gosa_version()
1944 {
1945 global $svn_revision, $svn_path;
1947 /* Extract informations */
1948 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1950 /* Release or development? */
1951 if (preg_match('%/gosa/trunk/%', $svn_path)){
1952 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1953 } else {
1954 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1955 return (sprintf(_("GOsa $release"), $revision));
1956 }
1957 }
1960 function rmdirRecursive($path, $followLinks=false) {
1961 $dir= opendir($path);
1962 while($entry= readdir($dir)) {
1963 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1964 unlink($path."/".$entry);
1965 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1966 rmdirRecursive($path."/".$entry);
1967 }
1968 }
1969 closedir($dir);
1970 return rmdir($path);
1971 }
1973 function scan_directory($path,$sort_desc=false)
1974 {
1975 $ret = false;
1977 /* is this a dir ? */
1978 if(is_dir($path)) {
1980 /* is this path a readable one */
1981 if(is_readable($path)){
1983 /* Get contents and write it into an array */
1984 $ret = array();
1986 $dir = opendir($path);
1988 /* Is this a correct result ?*/
1989 if($dir){
1990 while($fp = readdir($dir))
1991 $ret[]= $fp;
1992 }
1993 }
1994 }
1995 /* Sort array ascending , like scandir */
1996 sort($ret);
1998 /* Sort descending if parameter is sort_desc is set */
1999 if($sort_desc) {
2000 $ret = array_reverse($ret);
2001 }
2003 return($ret);
2004 }
2006 function clean_smarty_compile_dir($directory)
2007 {
2008 global $svn_revision;
2010 if(is_dir($directory) && is_readable($directory)) {
2011 // Set revision filename to REVISION
2012 $revision_file= $directory."/REVISION";
2014 /* Is there a stamp containing the current revision? */
2015 if(!file_exists($revision_file)) {
2016 // create revision file
2017 create_revision($revision_file, $svn_revision);
2018 } else {
2019 # check for "$config->...['CONFIG']/revision" and the
2020 # contents should match the revision number
2021 if(!compare_revision($revision_file, $svn_revision)){
2022 // If revision differs, clean compile directory
2023 foreach(scan_directory($directory) as $file) {
2024 if(($file==".")||($file=="..")) continue;
2025 if( is_file($directory."/".$file) &&
2026 is_writable($directory."/".$file)) {
2027 // delete file
2028 if(!unlink($directory."/".$file)) {
2029 print_red("File ".$directory."/".$file." could not be deleted.");
2030 // This should never be reached
2031 }
2032 } elseif(is_dir($directory."/".$file) &&
2033 is_writable($directory."/".$file)) {
2034 // Just recursively delete it
2035 rmdirRecursive($directory."/".$file);
2036 }
2037 }
2038 // We should now create a fresh revision file
2039 clean_smarty_compile_dir($directory);
2040 } else {
2041 // Revision matches, nothing to do
2042 }
2043 }
2044 } else {
2045 // Smarty compile dir is not accessible
2046 // (Smarty will warn about this)
2047 }
2048 }
2050 function create_revision($revision_file, $revision)
2051 {
2052 $result= false;
2054 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
2055 if($fh= fopen($revision_file, "w")) {
2056 if(fwrite($fh, $revision)) {
2057 $result= true;
2058 }
2059 }
2060 fclose($fh);
2061 } else {
2062 print_red("Can not write to revision file");
2063 }
2065 return $result;
2066 }
2068 function compare_revision($revision_file, $revision)
2069 {
2070 // false means revision differs
2071 $result= false;
2073 if(file_exists($revision_file) && is_readable($revision_file)) {
2074 // Open file
2075 if($fh= fopen($revision_file, "r")) {
2076 // Compare File contents with current revision
2077 if($revision == fread($fh, filesize($revision_file))) {
2078 $result= true;
2079 }
2080 } else {
2081 print_red("Can not open revision file");
2082 }
2083 // Close file
2084 fclose($fh);
2085 }
2087 return $result;
2088 }
2090 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
2091 {
2092 $str = ""; // Our return value will be saved in this var
2094 $color = dechex($percentage+150);
2095 $color2 = dechex(150 - $percentage);
2096 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2098 $progress = (int)(($percentage /100)*$width);
2100 /* Abort printing out percentage, if divs are to small */
2103 /* If theres a better solution for this, use it... */
2104 $str = "
2105 <div style=\" width:".($width)."px;
2106 height:".($height)."px;
2107 background-color:#000000;
2108 padding:1px;\">
2110 <div style=\" width:".($width)."px;
2111 background-color:#$bgcolor;
2112 height:".($height)."px;\">
2114 <div style=\" width:".$progress."px;
2115 height:".$height."px;
2116 background-color:#".$color2.$color2.$color."; \">";
2119 if(($height >10)&&($showvalue)){
2120 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2121 <b>".$percentage."%</b>
2122 </font>";
2123 }
2125 $str.= "</div></div></div>";
2127 return($str);
2128 }
2131 function array_key_ics($ikey, $items)
2132 {
2133 /* Gather keys, make them lowercase */
2134 $tmp= array();
2135 foreach ($items as $key => $value){
2136 $tmp[strtolower($key)]= $key;
2137 }
2139 if (isset($tmp[strtolower($ikey)])){
2140 return($tmp[strtolower($ikey)]);
2141 }
2143 return ("");
2144 }
2147 function array_differs($src, $dst)
2148 {
2149 /* If the count is differing, the arrays differ */
2150 if (count ($src) != count ($dst)){
2151 return (TRUE);
2152 }
2154 /* So the count is the same - lets check the contents */
2155 $differs= FALSE;
2156 foreach($src as $value){
2157 if (!in_array($value, $dst)){
2158 $differs= TRUE;
2159 }
2160 }
2162 return ($differs);
2163 }
2166 function saveFilter($a_filter, $values)
2167 {
2168 if (isset($_POST['regexit'])){
2169 $a_filter["regex"]= $_POST['regexit'];
2171 foreach($values as $type){
2172 if (isset($_POST[$type])) {
2173 $a_filter[$type]= "checked";
2174 } else {
2175 $a_filter[$type]= "";
2176 }
2177 }
2178 }
2180 /* React on alphabet links if needed */
2181 if (isset($_GET['search'])){
2182 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2183 if ($s == "**"){
2184 $s= "*";
2185 }
2186 $a_filter['regex']= $s;
2187 }
2189 return ($a_filter);
2190 }
2193 /* Escape all preg_* relevant characters */
2194 function normalizePreg($input)
2195 {
2196 return (addcslashes($input, '[]()|/.*+-'));
2197 }
2200 /* Escape all LDAP filter relevant characters */
2201 function normalizeLdap($input)
2202 {
2203 return (addcslashes($input, '()|'));
2204 }
2207 /* Resturns the difference between to microtime() results in float */
2208 function get_MicroTimeDiff($start , $stop)
2209 {
2210 $a = split("\ ",$start);
2211 $b = split("\ ",$stop);
2213 $secs = $b[1] - $a[1];
2214 $msecs= $b[0] - $a[0];
2216 $ret = (float) ($secs+ $msecs);
2217 return($ret);
2218 }
2221 /* Check if the given department name is valid */
2222 function is_department_name_reserved($name,$base)
2223 {
2224 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2225 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2226 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2227 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2229 /* Check if name is one of the reserved names */
2230 if(in_array_ics($name,$reservedName)) {
2231 return(true);
2232 }
2234 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2235 foreach($follwedNames as $key => $names){
2236 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2237 return(true);
2238 }
2239 }
2240 return(false);
2241 }
2244 function get_base_dir()
2245 {
2246 global $BASE_DIR;
2248 return $BASE_DIR;
2249 }
2252 function obj_is_readable($dn, $object, $attribute)
2253 {
2254 global $ui;
2256 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2257 }
2260 function obj_is_writable($dn, $object, $attribute)
2261 {
2262 global $ui;
2264 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2265 }
2268 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2269 {
2270 /* Initialize variables */
2271 $ret = array("count" => 0); // Set count to 0
2272 $next = true; // if false, then skip next loops and return
2273 $cnt = 0; // Current number of loops
2274 $max = 100; // Just for security, prevent looops
2275 $ldap = NULL; // To check if created result a valid
2276 $keep = ""; // save last failed parse string
2278 /* Check each parsed dn in ldap ? */
2279 if($config!==NULL && $verify_in_ldap){
2280 $ldap = $config->get_ldap_link();
2281 }
2283 /* Lets start */
2284 $called = false;
2285 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2287 $cnt ++;
2288 if(!preg_match("/,/",$dn)){
2289 $next = false;
2290 }
2291 $object = preg_replace("/[,].*$/","",$dn);
2292 $dn = preg_replace("/^[^,]+,/","",$dn);
2294 $called = true;
2296 /* Check if current dn is valid */
2297 if($ldap!==NULL){
2298 $ldap->cd($dn);
2299 $ldap->cat($dn,array("dn"));
2300 if($ldap->count()){
2301 $ret[] = $keep.$object;
2302 $keep = "";
2303 }else{
2304 $keep .= $object.",";
2305 }
2306 }else{
2307 $ret[] = $keep.$object;
2308 $keep = "";
2309 }
2310 }
2312 /* No dn was posted */
2313 if($cnt == 0 && !empty($dn)){
2314 $ret[] = $dn;
2315 }
2317 /* Append the rest */
2318 $test = $keep.$dn;
2319 if($called && !empty($test)){
2320 $ret[] = $keep.$dn;
2321 }
2322 $ret['count'] = count($ret) - 1;
2324 return($ret);
2325 }
2327 /* Add "str_split" if this function is missing.
2328 * This function is only available in PHP5
2329 */
2330 if(!function_exists("str_split")){
2331 function str_split($str,$length =1)
2332 {
2333 if($length < 1 ) $length =1;
2335 $ret = array();
2336 for($i = 0 ; $i < strlen($str); $i = $i +$length){
2337 $ret[] = substr($str,$i ,$length);
2338 }
2339 return($ret);
2340 }
2341 }
2344 function get_base_from_hook($dn, $attrib)
2345 {
2346 global $config;
2348 if (isset($config->current['BASE_HOOK'])){
2350 /* Call hook script - if present */
2351 $command= $config->current['BASE_HOOK'];
2353 if ($command != ""){
2354 $command.= " '".LDAP::fix($dn)."' $attrib";
2355 if (check_command($command)){
2356 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2357 exec($command, $output);
2358 if (preg_match("/^[0-9]+$/", $output[0])){
2359 return ($output[0]);
2360 } else {
2361 print_red(_("Warning - base_hook is not available. Using default base."));
2362 return ($config->current['UIDBASE']);
2363 }
2364 } else {
2365 print_red(_("Warning - base_hook is not available. Using default base."));
2366 return ($config->current['UIDBASE']);
2367 }
2369 } else {
2371 print_red(_("Warning - no base_hook defined. Using default base."));
2372 return ($config->current['UIDBASE']);
2374 }
2375 }
2376 }
2378 /* Schema validation functions */
2380 function check_schema_version($class, $version)
2381 {
2382 return preg_match("/\(v$version\)/", $class['DESC']);
2383 }
2385 function check_schema($cfg,$rfc2307bis = FALSE)
2386 {
2387 $messages= array();
2389 /* Get objectclasses */
2390 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2391 $objectclasses = $ldap->get_objectclasses();
2392 if(count($objectclasses) == 0){
2393 print_red(_("Can't get schema information from server. No schema check possible!"));
2394 }
2396 /* This is the default block used for each entry.
2397 * to avoid unset indexes.
2398 */
2399 $def_check = array("REQUIRED_VERSION" => "0",
2400 "SCHEMA_FILES" => array(),
2401 "CLASSES_REQUIRED" => array(),
2402 "STATUS" => FALSE,
2403 "IS_MUST_HAVE" => FALSE,
2404 "MSG" => "",
2405 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2407 /* The gosa base schema */
2408 $checks['gosaObject'] = $def_check;
2409 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2410 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2411 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2412 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2414 /* GOsa Account class */
2415 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2416 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2417 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2418 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2419 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2421 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2422 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2423 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2424 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2425 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2426 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2428 /* Some other checks */
2429 foreach(array(
2430 "gosaCacheEntry" => array("version" => "2.4"),
2431 "gosaDepartment" => array("version" => "2.4"),
2432 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2433 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2434 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2435 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2436 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2437 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2438 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2439 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2440 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2441 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2442 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2443 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2444 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2445 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2446 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2447 "goLdapServer" => array("version" => "2.4"),
2448 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2449 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2450 "goKrbServer" => array("version" => "2.4"),
2451 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2452 ) as $name => $values){
2454 $checks[$name] = $def_check;
2455 if(isset($values['version'])){
2456 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2457 }
2458 if(isset($values['file'])){
2459 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2460 }
2461 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2462 }
2463 foreach($checks as $name => $value){
2464 foreach($value['CLASSES_REQUIRED'] as $class){
2466 if(!isset($objectclasses[$name])){
2467 $checks[$name]['STATUS'] = FALSE;
2468 if($value['IS_MUST_HAVE']){
2469 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2470 }else{
2471 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2472 }
2473 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2474 $checks[$name]['STATUS'] = FALSE;
2476 if($value['IS_MUST_HAVE']){
2477 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2478 }else{
2479 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2480 }
2481 }else{
2482 $checks[$name]['STATUS'] = TRUE;
2483 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2484 }
2485 }
2486 }
2488 $tmp = $objectclasses;
2490 /* The gosa base schema */
2491 $checks['posixGroup'] = $def_check;
2492 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2493 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2494 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2495 $checks['posixGroup']['STATUS'] = TRUE;
2496 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2497 $checks['posixGroup']['MSG'] = "";
2498 $checks['posixGroup']['INFO'] = "";
2500 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2501 if(isset($tmp['posixGroup'])){
2503 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2504 $checks['posixGroup']['STATUS'] = FALSE;
2505 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2506 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2507 }
2508 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2509 $checks['posixGroup']['STATUS'] = FALSE;
2510 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2511 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2512 }
2513 }
2515 return($checks);
2516 }
2521 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2522 {
2523 $tmp = array(
2524 "de_DE" => "German",
2525 "fr_FR" => "French",
2526 "it_IT" => "Italian",
2527 "es_ES" => "Spanish",
2528 "en_US" => "English",
2529 "nl_NL" => "Dutch",
2530 "pl_PL" => "Polish",
2531 "sv_SE" => "Swedish",
2532 "zh_CN" => "Chinese",
2533 "ru_RU" => "Russian");
2535 $tmp2= array(
2536 "de_DE" => _("German"),
2537 "fr_FR" => _("French"),
2538 "it_IT" => _("Italian"),
2539 "es_ES" => _("Spanish"),
2540 "en_US" => _("English"),
2541 "nl_NL" => _("Dutch"),
2542 "pl_PL" => _("Polish"),
2543 "sv_SE" => _("Swedish"),
2544 "zh_CN" => _("Chinese"),
2545 "ru_RU" => _("Russian"));
2547 $ret = array();
2548 if($languages_in_own_language){
2550 $old_lang = setlocale(LC_ALL, 0);
2551 foreach($tmp as $key => $name){
2552 $lang = $key.".UTF-8";
2553 setlocale(LC_ALL, $lang);
2554 if($strip_region_tag){
2555 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2556 }else{
2557 $ret[$key] = _($name)." (".$tmp2[$key].")";
2558 }
2559 }
2560 setlocale(LC_ALL, $old_lang);
2561 }else{
2562 foreach($tmp as $key => $name){
2563 if($strip_region_tag){
2564 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2565 }else{
2566 $ret[$key] = _($name);
2567 }
2568 }
2569 }
2570 return($ret);
2571 }
2574 /* Returns contents of the given POST variable and check magic quotes settings */
2575 function get_post($name)
2576 {
2577 if(!isset($_POST[$name])){
2578 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2579 return(FALSE);
2580 }
2581 if(get_magic_quotes_gpc()){
2582 return(stripcslashes($_POST[$name]));
2583 }else{
2584 return($_POST[$name]);
2585 }
2586 }
2589 /* Check if $ip1 and $ip2 represents a valid IP range
2590 * returns TRUE in case of a valid range, FALSE in case of an error.
2591 */
2592 function is_ip_range($ip1,$ip2)
2593 {
2594 if(!is_ip($ip1) || !is_ip($ip2)){
2595 return(FALSE);
2596 }else{
2597 $ar1 = split("\.",$ip1);
2598 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2600 $ar2 = split("\.",$ip2);
2601 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2602 return($var1 < $var2);
2603 }
2604 }
2607 /* Check if the specified IP address $address is inside the given network */
2608 function is_in_network($network, $netmask, $address)
2609 {
2610 $nw= split('\.', $network);
2611 $nm= split('\.', $netmask);
2612 $ad= split('\.', $address);
2614 /* Generate inverted netmask */
2615 for ($i= 0; $i<4; $i++){
2616 $ni[$i]= 255-$nm[$i];
2617 $la[$i]= $nw[$i] | $ni[$i];
2618 }
2620 /* Transform to integer */
2621 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2622 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2623 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2625 return ($first < $curr&& $last > $curr);
2626 }
2628 /* Return class name in correct case
2629 * mailMethodkolab => mailMethodKolab ( k => K )
2630 */
2631 function get_correct_class_name($cls)
2632 {
2633 global $class_mapping;
2634 if(isset($class_mapping) && is_array($class_mapping)){
2635 foreach($class_mapping as $class => $file){
2636 if(preg_match("/^".$cls."$/i",$class)){
2637 return($class);
2638 }
2639 }
2640 }
2641 return(FALSE);
2642 }
2644 // change_password, changes the Password, of the given dn
2645 function change_password ($dn, $password, $mode=0, $hash= "")
2646 {
2647 global $config;
2648 $newpass= "";
2650 /* Convert to lower. Methods are lowercase */
2651 $hash= strtolower($hash);
2653 // Get all available encryption Methods
2655 // NON STATIC CALL :)
2656 $tmp = new passwordMethod(get_global('config'));
2657 $available = $tmp->get_available_methods();
2659 // read current password entry for $dn, to detect the encryption Method
2660 $ldap = $config->get_ldap_link();
2661 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2662 $attrs = $ldap->fetch ();
2664 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2665 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2666 $deactivated = TRUE;
2667 }else{
2668 $deactivated = FALSE;
2669 }
2671 /* Is ensure that clear passwords will stay clear */
2672 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2673 $hash = "clear";
2674 }
2676 // Detect the encryption Method
2677 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2679 /* Check for supported algorithm */
2680 mt_srand((double) microtime()*1000000);
2682 /* Extract used hash */
2683 if ($hash == ""){
2684 $hash= strtolower($matches[1]);
2685 }
2687 $test = new $available[$hash]($config);
2689 } else {
2690 // User MD5 by default
2691 $hash= "md5";
2692 $test = new $available['md5']($config);
2693 }
2695 /* Feed password backends with information */
2696 $test->dn= $dn;
2697 $test->attrs= $attrs;
2698 $newpass= $test->generate_hash($password);
2700 // Update shadow timestamp?
2701 if (isset($attrs["shadowLastChange"][0])){
2702 $shadow= (int)(date("U") / 86400);
2703 } else {
2704 $shadow= 0;
2705 }
2707 // Write back modified entry
2708 $ldap->cd($dn);
2709 $attrs= array();
2711 // Not for groups
2712 if ($mode == 0){
2714 if ($shadow != 0){
2715 $attrs['shadowLastChange']= $shadow;
2716 }
2718 // Create SMB Password
2719 $attrs= generate_smb_nt_hash($password);
2720 }
2722 /* Readd ! if user was deactivated */
2723 if($deactivated){
2724 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2725 }
2727 $attrs['userPassword']= array();
2728 $attrs['userPassword']= $newpass;
2730 $ldap->modify($attrs);
2732 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2734 if ($ldap->error != 'Success') {
2735 print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2736 $ldap->get_error()));
2737 } else {
2739 /* Run backend method for change/create */
2740 $test->set_password($password);
2742 /* Find postmodify entries for this class */
2743 $command= $config->search("password", "POSTMODIFY",array('menu'));
2745 if ($command != ""){
2746 /* Walk through attribute list */
2747 $command= preg_replace("/%userPassword/", $password, $command);
2748 $command= preg_replace("/%dn/", $dn, $command);
2750 if (check_command($command)){
2751 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2752 exec($command);
2753 } else {
2754 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2755 print_red ($message);
2756 }
2757 }
2758 }
2759 }
2760 // Return something like array['sambaLMPassword']= "lalla..."
2761 function generate_smb_nt_hash($password)
2762 {
2763 global $config;
2764 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2765 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2767 exec($tmp, $ar);
2768 flush();
2769 reset($ar);
2770 $hash= current($ar);
2771 if ($hash == "")
2772 {
2773 print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2774 }
2775 else
2776 {
2777 list($lm,$nt)= split (":", trim($hash));
2779 if ($config->current['SAMBAVERSION'] == 3)
2780 {
2781 $attrs['sambaLMPassword']= $lm;
2782 $attrs['sambaNTPassword']= $nt;
2783 $attrs['sambaPwdLastSet']= date('U');
2784 $attrs['sambaBadPasswordCount']= "0";
2785 $attrs['sambaBadPasswordTime']= "0";
2786 } else {
2787 $attrs['lmPassword']= $lm;
2788 $attrs['ntPassword']= $nt;
2789 $attrs['pwdLastSet']= date('U');
2790 }
2791 return($attrs);
2792 }
2793 }
2795 function crypt_single($string,$enc_type )
2796 {
2797 return( passwordMethod::crypt_single_str($string,$enc_type));
2798 }
2801 function getEntryCSN($dn)
2802 {
2803 global $config;
2804 if(empty($dn) || !is_object($config)){
2805 return("");
2806 }
2808 /* Get attribute that we should use as serial number */
2809 if(isset($config->current['UNIQ_IDENTIFIER'])){
2810 $attr = $config->current['UNIQ_IDENTIFIER'];
2811 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2812 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2813 }
2814 if(!empty($attr)){
2815 $ldap = $config->get_ldap_link();
2816 $ldap->cat($dn,array($attr));
2817 $csn = $ldap->fetch();
2818 if(isset($csn[$attr][0])){
2819 return($csn[$attr][0]);
2820 }
2821 }
2822 return("");
2823 }
2825 /* This function returns the offset for the default timezone.
2826 * $stamp is used to detect summer or winter time.
2827 * In case of PHP5, the integrated timezone functions are used.
2828 * For PHP4 we query an array for offset and add summertime hour.
2829 */
2830 function get_default_timezone($stamp = NULL)
2831 {
2832 global $config;
2833 $tz ="";
2835 /* Default return value if zone could not be detected */
2836 $zone = array("name" => "unconfigured", "value" => 0);
2838 /* Use current timestamp if $stamp is not set */
2839 if($stamp === NULL){
2840 $stamp = time();
2841 }
2843 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2844 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2846 /* Get zonename */
2847 if(isset($config->current['TIMEZONE'])){
2848 $tz = $config->current['TIMEZONE'];
2849 }else{
2850 $tz = $config->data['MAIN']['TIMEZONE'];
2851 }
2853 if(!@date_default_timezone_set($tz)){
2854 print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2855 }
2856 $tz_delta = date("Z", $stamp);
2857 $tz_delta = $tz_delta / 3600 ;
2858 return(array("name" => $tz, "value" => $tz_delta));
2860 }
2861 return($zone);
2862 }
2865 /* Return zone informations */
2866 function _get_tz_zones()
2867 {
2868 $timezones = array(
2869 'Africa/Abidjan' => 0,
2870 'Africa/Accra' => 0,
2871 'Africa/Addis_Ababa' => 10800,
2872 'Africa/Algiers' => 3600,
2873 'Africa/Asmera' => 10800,
2874 'Africa/Bamako' => 0,
2875 'Africa/Bangui' => 3600,
2876 'Africa/Banjul' => 0,
2877 'Africa/Bissau' => 0,
2878 'Africa/Blantyre' => 7200,
2879 'Africa/Brazzaville' => 3600,
2880 'Africa/Bujumbura' => 7200,
2881 'Africa/Cairo' => 7200,
2882 'Africa/Casablanca' => 0,
2883 'Africa/Ceuta' => 3600,
2884 'Africa/Conakry' => 0,
2885 'Africa/Dakar' => 0,
2886 'Africa/Dar_es_Salaam' => 10800,
2887 'Africa/Djibouti' => 10800,
2888 'Africa/Douala' => 3600,
2889 'Africa/El_Aaiun' => 0,
2890 'Africa/Freetown' => 0,
2891 'Africa/Gaborone' => 7200,
2892 'Africa/Harare' => 7200,
2893 'Africa/Johannesburg' => 7200,
2894 'Africa/Kampala' => 10800,
2895 'Africa/Khartoum' => 10800,
2896 'Africa/Kigali' => 7200,
2897 'Africa/Kinshasa' => 3600,
2898 'Africa/Lagos' => 3600,
2899 'Africa/Libreville' => 3600,
2900 'Africa/Lome' => 0,
2901 'Africa/Luanda' => 3600,
2902 'Africa/Lubumbashi' => 7200,
2903 'Africa/Lusaka' => 7200,
2904 'Africa/Malabo' => 3600,
2905 'Africa/Maputo' => 7200,
2906 'Africa/Maseru' => 7200,
2907 'Africa/Mbabane' => 7200,
2908 'Africa/Mogadishu' => 10800,
2909 'Africa/Monrovia' => 0,
2910 'Africa/Nairobi' => 10800,
2911 'Africa/Ndjamena' => 3600,
2912 'Africa/Niamey' => 3600,
2913 'Africa/Nouakchott' => 0,
2914 'Africa/Ouagadougou' => 0,
2915 'Africa/Porto-Novo' => 3600,
2916 'Africa/Sao_Tome' => 0,
2917 'Africa/Timbuktu' => 0,
2918 'Africa/Tripoli' => 7200,
2919 'Africa/Tunis' => 3600,
2920 'Africa/Windhoek' => 3600,
2921 'America/Adak' => -36000,
2922 'America/Anchorage' => -32400,
2923 'America/Anguilla' => -14400,
2924 'America/Antigua' => -14400,
2925 'America/Araguaina' => -10800,
2926 'America/Argentina/Buenos_Aires' => 0,
2927 'America/Argentina/Catamarca' => 0,
2928 'America/Argentina/ComodRivadavia' => 0,
2929 'America/Argentina/Cordoba' => 0,
2930 'America/Argentina/Jujuy' => 0,
2931 'America/Argentina/La_Rioja' => 0,
2932 'America/Argentina/Mendoza' => 0,
2933 'America/Argentina/Rio_Gallegos' => 0,
2934 'America/Argentina/San_Juan' => 0,
2935 'America/Argentina/Tucuman' => 0,
2936 'America/Argentina/Ushuaia' => 0,
2937 'America/Aruba' => -14400,
2938 'America/Asuncion' => -14400,
2939 'America/Atikokan' => 0,
2940 'America/Atka' => -36000,
2941 'America/Bahia' => 0,
2942 'America/Barbados' => -14400,
2943 'America/Belem' => -10800,
2944 'America/Belize' => -21600,
2945 'America/Blanc-Sablon' => 0,
2946 'America/Boa_Vista' => -14400,
2947 'America/Bogota' => -18000,
2948 'America/Boise' => -25200,
2949 'America/Buenos_Aires' => -10800,
2950 'America/Cambridge_Bay' => -25200,
2951 'America/Campo_Grande' => 0,
2952 'America/Cancun' => -21600,
2953 'America/Caracas' => -14400,
2954 'America/Catamarca' => -10800,
2955 'America/Cayenne' => -10800,
2956 'America/Cayman' => -18000,
2957 'America/Chicago' => -21600,
2958 'America/Chihuahua' => -25200,
2959 'America/Coral_Harbour' => 0,
2960 'America/Cordoba' => -10800,
2961 'America/Costa_Rica' => -21600,
2962 'America/Cuiaba' => -14400,
2963 'America/Curacao' => -14400,
2964 'America/Danmarkshavn' => 0,
2965 'America/Dawson' => -28800,
2966 'America/Dawson_Creek' => -25200,
2967 'America/Denver' => -25200,
2968 'America/Detroit' => -18000,
2969 'America/Dominica' => -14400,
2970 'America/Edmonton' => -25200,
2971 'America/Eirunepe' => -18000,
2972 'America/El_Salvador' => -21600,
2973 'America/Ensenada' => -28800,
2974 'America/Fort_Wayne' => -18000,
2975 'America/Fortaleza' => -10800,
2976 'America/Glace_Bay' => -14400,
2977 'America/Godthab' => -10800,
2978 'America/Goose_Bay' => -14400,
2979 'America/Grand_Turk' => -18000,
2980 'America/Grenada' => -14400,
2981 'America/Guadeloupe' => -14400,
2982 'America/Guatemala' => -21600,
2983 'America/Guayaquil' => -18000,
2984 'America/Guyana' => -14400,
2985 'America/Halifax' => -14400,
2986 'America/Havana' => -18000,
2987 'America/Hermosillo' => -25200,
2988 'America/Indiana/Indianapolis' => -18000,
2989 'America/Indiana/Knox' => -18000,
2990 'America/Indiana/Marengo' => -18000,
2991 'America/Indiana/Petersburg' => 0,
2992 'America/Indiana/Vevay' => -18000,
2993 'America/Indiana/Vincennes' => 0,
2994 'America/Indianapolis' => -18000,
2995 'America/Inuvik' => -25200,
2996 'America/Iqaluit' => -18000,
2997 'America/Jamaica' => -18000,
2998 'America/Jujuy' => -10800,
2999 'America/Juneau' => -32400,
3000 'America/Kentucky/Louisville' => -18000,
3001 'America/Kentucky/Monticello' => -18000,
3002 'America/Knox_IN' => -18000,
3003 'America/La_Paz' => -14400,
3004 'America/Lima' => -18000,
3005 'America/Los_Angeles' => -28800,
3006 'America/Louisville' => -18000,
3007 'America/Maceio' => -10800,
3008 'America/Managua' => -21600,
3009 'America/Manaus' => -14400,
3010 'America/Martinique' => -14400,
3011 'America/Mazatlan' => -25200,
3012 'America/Mendoza' => -10800,
3013 'America/Menominee' => -21600,
3014 'America/Merida' => -21600,
3015 'America/Mexico_City' => -21600,
3016 'America/Miquelon' => -10800,
3017 'America/Moncton' => 0,
3018 'America/Monterrey' => -21600,
3019 'America/Montevideo' => -10800,
3020 'America/Montreal' => -18000,
3021 'America/Montserrat' => -14400,
3022 'America/Nassau' => -18000,
3023 'America/New_York' => -18000,
3024 'America/Nipigon' => -18000,
3025 'America/Nome' => -32400,
3026 'America/Noronha' => -7200,
3027 'America/North_Dakota/Center' => -21600,
3028 'America/North_Dakota/New_Salem' => 0,
3029 'America/Panama' => -18000,
3030 'America/Pangnirtung' => -18000,
3031 'America/Paramaribo' => -10800,
3032 'America/Phoenix' => -25200,
3033 'America/Port-au-Prince' => -18000,
3034 'America/Port_of_Spain' => -14400,
3035 'America/Porto_Acre' => -18000,
3036 'America/Porto_Velho' => -14400,
3037 'America/Puerto_Rico' => -14400,
3038 'America/Rainy_River' => -21600,
3039 'America/Rankin_Inlet' => -21600,
3040 'America/Recife' => -10800,
3041 'America/Regina' => -21600,
3042 'America/Rio_Branco' => -18000,
3043 'America/Rosario' => -10800,
3044 'America/Santiago' => -14400,
3045 'America/Santo_Domingo' => -14400,
3046 'America/Sao_Paulo' => -10800,
3047 'America/Scoresbysund' => -3600,
3048 'America/Shiprock' => -25200,
3049 'America/St_Johns' => -12600,
3050 'America/St_Kitts' => -14400,
3051 'America/St_Lucia' => -14400,
3052 'America/St_Thomas' => -14400,
3053 'America/St_Vincent' => -14400,
3054 'America/Swift_Current' => -21600,
3055 'America/Tegucigalpa' => -21600,
3056 'America/Thule' => -14400,
3057 'America/Thunder_Bay' => -18000,
3058 'America/Tijuana' => -28800,
3059 'America/Toronto' => 0,
3060 'America/Tortola' => -14400,
3061 'America/Vancouver' => -28800,
3062 'America/Virgin' => -14400,
3063 'America/Whitehorse' => -28800,
3064 'America/Winnipeg' => -21600,
3065 'America/Yakutat' => -32400,
3066 'America/Yellowknife' => -25200,
3067 'Antarctica/Casey' => 28800,
3068 'Antarctica/Davis' => 25200,
3069 'Antarctica/DumontDUrville' => 36000,
3070 'Antarctica/Mawson' => 21600,
3071 'Antarctica/McMurdo' => 43200,
3072 'Antarctica/Palmer' => -14400,
3073 'Antarctica/Rothera' => 0,
3074 'Antarctica/South_Pole' => 43200,
3075 'Antarctica/Syowa' => 10800,
3076 'Antarctica/VostokArctic/Longyearbyen' => 0,
3077 'Asia/Aden' => 10800,
3078 'Asia/Almaty' => 21600,
3079 'Asia/Amman' => 7200,
3080 'Asia/Anadyr' => 43200,
3081 'Asia/Aqtau' => 14400,
3082 'Asia/Aqtobe' => 18000,
3083 'Asia/Ashgabat' => 18000,
3084 'Asia/Ashkhabad' => 18000,
3085 'Asia/Baghdad' => 10800,
3086 'Asia/Bahrain' => 10800,
3087 'Asia/Baku' => 14400,
3088 'Asia/Bangkok' => 25200,
3089 'Asia/Beirut' => 7200,
3090 'Asia/Bishkek' => 18000,
3091 'Asia/Brunei' => 28800,
3092 'Asia/Calcutta' => 19800,
3093 'Asia/Choibalsan' => 32400,
3094 'Asia/Chongqing' => 28800,
3095 'Asia/Chungking' => 28800,
3096 'Asia/Colombo' => 21600,
3097 'Asia/Dacca' => 21600,
3098 'Asia/Damascus' => 7200,
3099 'Asia/Dhaka' => 21600,
3100 'Asia/Dili' => 32400,
3101 'Asia/Dubai' => 14400,
3102 'Asia/Dushanbe' => 18000,
3103 'Asia/Gaza' => 7200,
3104 'Asia/Harbin' => 28800,
3105 'Asia/Hong_Kong' => 28800,
3106 'Asia/Hovd' => 25200,
3107 'Asia/Irkutsk' => 28800,
3108 'Asia/Istanbul' => 7200,
3109 'Asia/Jakarta' => 25200,
3110 'Asia/Jayapura' => 32400,
3111 'Asia/Jerusalem' => 7200,
3112 'Asia/Kabul' => 16200,
3113 'Asia/Kamchatka' => 43200,
3114 'Asia/Karachi' => 18000,
3115 'Asia/Kashgar' => 28800,
3116 'Asia/Katmandu' => 20700,
3117 'Asia/Krasnoyarsk' => 25200,
3118 'Asia/Kuala_Lumpur' => 28800,
3119 'Asia/Kuching' => 28800,
3120 'Asia/Kuwait' => 10800,
3121 'Asia/Macao' => 28800,
3122 'Asia/Macau' => 0,
3123 'Asia/Magadan' => 39600,
3124 'Asia/Makassar' => 0,
3125 'Asia/Manila' => 28800,
3126 'Asia/Muscat' => 14400,
3127 'Asia/Nicosia' => 7200,
3128 'Asia/Novosibirsk' => 21600,
3129 'Asia/Omsk' => 21600,
3130 'Asia/Oral' => 0,
3131 'Asia/Phnom_Penh' => 25200,
3132 'Asia/Pontianak' => 25200,
3133 'Asia/Pyongyang' => 32400,
3134 'Asia/Qatar' => 10800,
3135 'Asia/Qyzylorda' => 0,
3136 'Asia/Rangoon' => 23400,
3137 'Asia/Riyadh' => 10800,
3138 'Asia/Saigon' => 25200,
3139 'Asia/Sakhalin' => 36000,
3140 'Asia/Samarkand' => 18000,
3141 'Asia/Seoul' => 32400,
3142 'Asia/Shanghai' => 28800,
3143 'Asia/Singapore' => 28800,
3144 'Asia/Taipei' => 28800,
3145 'Asia/Tashkent' => 18000,
3146 'Asia/Tbilisi' => 14400,
3147 'Asia/Tehran' => 12600,
3148 'Asia/Tel_Aviv' => 7200,
3149 'Asia/Thimbu' => 21600,
3150 'Asia/Thimphu' => 21600,
3151 'Asia/Tokyo' => 32400,
3152 'Asia/Ujung_Pandang' => 28800,
3153 'Asia/Ulaanbaatar' => 28800,
3154 'Asia/Ulan_Bator' => 28800,
3155 'Asia/Urumqi' => 28800,
3156 'Asia/Vientiane' => 25200,
3157 'Asia/Vladivostok' => 36000,
3158 'Asia/Yakutsk' => 32400,
3159 'Asia/Yekaterinburg' => 18000,
3160 'Asia/YerevanAtlantic/Azores' => 0,
3161 'Atlantic/Bermuda' => -14400,
3162 'Atlantic/Canary' => 0,
3163 'Atlantic/Cape_Verde' => -3600,
3164 'Atlantic/Faeroe' => 0,
3165 'Atlantic/Jan_Mayen' => 3600,
3166 'Atlantic/Madeira' => 0,
3167 'Atlantic/Reykjavik' => 0,
3168 'Atlantic/South_Georgia' => -7200,
3169 'Atlantic/St_Helena' => 0,
3170 'Atlantic/Stanley' => -14400,
3171 'Australia/ACT' => 36000,
3172 'Australia/Adelaide' => 34200,
3173 'Australia/Brisbane' => 36000,
3174 'Australia/Broken_Hill' => 34200,
3175 'Australia/Canberra' => 36000,
3176 'Australia/Currie' => 0,
3177 'Australia/Darwin' => 34200,
3178 'Australia/Hobart' => 36000,
3179 'Australia/LHI' => 37800,
3180 'Australia/Lindeman' => 36000,
3181 'Australia/Lord_Howe' => 37800,
3182 'Australia/Melbourne' => 36000,
3183 'Australia/NSW' => 36000,
3184 'Australia/North' => 34200,
3185 'Australia/Perth' => 28800,
3186 'Australia/Queensland' => 36000,
3187 'Australia/South' => 34200,
3188 'Australia/Sydney' => 36000,
3189 'Australia/Tasmania' => 36000,
3190 'Australia/Victoria' => 36000,
3191 'Australia/West' => 28800,
3192 'Australia/Yancowinna' => 34200,
3193 'Europe/Amsterdam' => 3600,
3194 'Europe/Andorra' => 3600,
3195 'Europe/Athens' => 7200,
3196 'Europe/Belfast' => 0,
3197 'Europe/Belgrade' => 3600,
3198 'Europe/Berlin' => 3600,
3199 'Europe/Bratislava' => 3600,
3200 'Europe/Brussels' => 3600,
3201 'Europe/Bucharest' => 7200,
3202 'Europe/Budapest' => 3600,
3203 'Europe/Chisinau' => 7200,
3204 'Europe/Copenhagen' => 3600,
3205 'Europe/Dublin' => 0,
3206 'Europe/Gibraltar' => 3600,
3207 'Europe/Guernsey' => 0,
3208 'Europe/Helsinki' => 7200,
3209 'Europe/Isle_of_Man' => 0,
3210 'Europe/Istanbul' => 7200,
3211 'Europe/Jersey' => 0,
3212 'Europe/Kaliningrad' => 7200,
3213 'Europe/Kiev' => 7200,
3214 'Europe/Lisbon' => 0,
3215 'Europe/Ljubljana' => 3600,
3216 'Europe/London' => 0,
3217 'Europe/Luxembourg' => 3600,
3218 'Europe/Madrid' => 3600,
3219 'Europe/Malta' => 3600,
3220 'Europe/Mariehamn' => 0,
3221 'Europe/Minsk' => 7200,
3222 'Europe/Monaco' => 3600,
3223 'Europe/Moscow' => 10800,
3224 'Europe/Nicosia' => 7200,
3225 'Europe/Oslo' => 3600,
3226 'Europe/Paris' => 3600,
3227 'Europe/Prague' => 3600,
3228 'Europe/Riga' => 7200,
3229 'Europe/Rome' => 3600,
3230 'Europe/Samara' => 14400,
3231 'Europe/San_Marino' => 3600,
3232 'Europe/Sarajevo' => 3600,
3233 'Europe/Simferopol' => 7200,
3234 'Europe/Skopje' => 3600,
3235 'Europe/Sofia' => 7200,
3236 'Europe/Stockholm' => 3600,
3237 'Europe/Tallinn' => 7200,
3238 'Europe/Tirane' => 3600,
3239 'Europe/Tiraspol' => 7200,
3240 'Europe/Uzhgorod' => 7200,
3241 'Europe/Vaduz' => 3600,
3242 'Europe/Vatican' => 3600,
3243 'Europe/Vienna' => 3600,
3244 'Europe/Vilnius' => 7200,
3245 'Europe/Volgograd' => 0,
3246 'Europe/Warsaw' => 3600,
3247 'Europe/Zagreb' => 3600,
3248 'Europe/Zaporozhye' => 7200,
3249 'Europe/Zurich' => 3600,
3250 'Indian/Antananarivo' => 10800,
3251 'Indian/Chagos' => 21600,
3252 'Indian/Christmas' => 25200,
3253 'Indian/Cocos' => 23400,
3254 'Indian/Comoro' => 10800,
3255 'Indian/Kerguelen' => 18000,
3256 'Indian/Mahe' => 14400,
3257 'Indian/Maldives' => 18000,
3258 'Indian/Mauritius' => 14400,
3259 'Indian/Mayotte' => 10800,
3260 'Indian/Reunion' => 14400,
3261 'Pacific/Apia' => -39600,
3262 'Pacific/Auckland' => 43200,
3263 'Pacific/Chatham' => 45900,
3264 'Pacific/Easter' => -21600,
3265 'Pacific/Efate' => 39600,
3266 'Pacific/Enderbury' => 46800,
3267 'Pacific/Fakaofo' => -36000,
3268 'Pacific/Fiji' => 43200,
3269 'Pacific/Funafuti' => 43200,
3270 'Pacific/Galapagos' => -21600,
3271 'Pacific/Gambier' => -32400,
3272 'Pacific/Guadalcanal' => 39600,
3273 'Pacific/Guam' => 36000,
3274 'Pacific/Honolulu' => -36000,
3275 'Pacific/Johnston' => -36000,
3276 'Pacific/Kiritimati' => 50400,
3277 'Pacific/Kosrae' => 39600,
3278 'Pacific/Kwajalein' => 43200,
3279 'Pacific/Majuro' => 43200,
3280 'Pacific/Marquesas' => -34200,
3281 'Pacific/Midway' => -39600,
3282 'Pacific/Nauru' => 43200,
3283 'Pacific/Niue' => -39600,
3284 'Pacific/Norfolk' => 41400,
3285 'Pacific/Noumea' => 39600,
3286 'Pacific/Pago_Pago' => -39600,
3287 'Pacific/Palau' => 32400,
3288 'Pacific/Pitcairn' => -28800,
3289 'Pacific/Ponape' => 39600,
3290 'Pacific/Port_Moresby' => 36000,
3291 'Pacific/Rarotonga' => -36000,
3292 'Pacific/Saipan' => 36000,
3293 'Pacific/Samoa' => -39600,
3294 'Pacific/Tahiti' => -36000,
3295 'Pacific/Tarawa' => 43200,
3296 'Pacific/Tongatapu' => 46800,
3297 'Pacific/Truk' => 36000,
3298 'Pacific/Wake' => 43200,
3299 'Pacific/Wallis' => 43200,
3300 'Pacific/Yap' => 36000 );
3302 $dst_timezones = array (
3303 'America/Adak' => 1,
3304 'America/Atka' => 1,
3305 'America/Anchorage' => 1,
3306 'America/Juneau' => 1,
3307 'America/Nome' => 1,
3308 'America/Yakutat' => 1,
3309 'America/Dawson' => 1,
3310 'America/Ensenada' => 1,
3311 'America/Los_Angeles' => 1,
3312 'America/Tijuana' => 1,
3313 'America/Vancouver' => 1,
3314 'America/Whitehorse' => 1,
3315 'America/Boise' => 1,
3316 'America/Cambridge_Bay' => 1,
3317 'America/Chihuahua' => 1,
3318 'America/Denver' => 1,
3319 'America/Edmonton' => 1,
3320 'America/Inuvik' => 1,
3321 'America/Mazatlan' => 1,
3322 'America/Shiprock' => 1,
3323 'America/Yellowknife' => 1,
3324 'America/Cancun' => 1,
3325 'America/Chicago' => 1,
3326 'America/Menominee' => 1,
3327 'America/Merida' => 1,
3328 'America/Monterrey' => 1,
3329 'America/North_Dakota/Center' => 1,
3330 'America/Rainy_River' => 1,
3331 'America/Rankin_Inlet' => 1,
3332 'America/Winnipeg' => 1,
3333 'Pacific/Easter' => 1,
3334 'America/Detroit' => 1,
3335 'America/Grand_Turk' => 1,
3336 'America/Havana' => 1,
3337 'America/Iqaluit' => 1,
3338 'America/Kentucky/Louisville' => 1,
3339 'America/Kentucky/Monticello' => 1,
3340 'America/Louisville' => 1,
3341 'America/Montreal' => 1,
3342 'America/Nassau' => 1,
3343 'America/New_York' => 1,
3344 'America/Nipigon' => 1,
3345 'America/Pangnirtung' => 1,
3346 'America/Thunder_Bay' => 1,
3347 'America/Asuncion' => 1,
3348 'America/Cuiaba' => 1,
3349 'America/Glace_Bay' => 1,
3350 'America/Goose_Bay' => 1,
3351 'America/Halifax' => 1,
3352 'America/Santiago' => 1,
3353 'Antarctica/Palmer' => 1,
3354 'Atlantic/Bermuda' => 1,
3355 'Atlantic/Stanley' => 1,
3356 'America/St_Johns' => 1,
3357 'America/Araguaina' => 1,
3358 'America/Fortaleza' => 1,
3359 'America/Godthab' => 1,
3360 'America/Maceio' => 1,
3361 'America/Miquelon' => 1,
3362 'America/Recife' => 1,
3363 'America/Sao_Paulo' => 1,
3364 'America/Scoresbysund' => 1,
3365 'Atlantic/Canary' => 1,
3366 'Atlantic/Faeroe' => 1,
3367 'Atlantic/Madeira' => 1,
3368 'Europe/Belfast' => 1,
3369 'Europe/Dublin' => 1,
3370 'Europe/Lisbon' => 1,
3371 'Europe/London' => 1,
3372 'Africa/Ceuta' => 1,
3373 'Africa/Windhoek' => 1,
3374 'Atlantic/Jan_Mayen' => 1,
3375 'Europe/Amsterdam' => 1,
3376 'Europe/Andorra' => 1,
3377 'Europe/Belgrade' => 1,
3378 'Europe/Berlin' => 1,
3379 'Europe/Bratislava' => 1,
3380 'Europe/Brussels' => 1,
3381 'Europe/Budapest' => 1,
3382 'Europe/Copenhagen' => 1,
3383 'Europe/Gibraltar' => 1,
3384 'Europe/Ljubljana' => 1,
3385 'Europe/Luxembourg' => 1,
3386 'Europe/Madrid' => 1,
3387 'Europe/Malta' => 1,
3388 'Europe/Monaco' => 1,
3389 'Europe/Oslo' => 1,
3390 'Europe/Paris' => 1,
3391 'Europe/Prague' => 1,
3392 'Europe/Rome' => 1,
3393 'Europe/San_Marino' => 1,
3394 'Europe/Sarajevo' => 1,
3395 'Europe/Skopje' => 1,
3396 'Europe/Stockholm' => 1,
3397 'Europe/Tirane' => 1,
3398 'Europe/Vaduz' => 1,
3399 'Europe/Vatican' => 1,
3400 'Europe/Vienna' => 1,
3401 'Europe/Warsaw' => 1,
3402 'Europe/Zagreb' => 1,
3403 'Europe/Zurich' => 1,
3404 'Africa/Cairo' => 1,
3405 'Asia/Amman' => 1,
3406 'Asia/Beirut' => 1,
3407 'Asia/Damascus' => 1,
3408 'Asia/Gaza' => 1,
3409 'Asia/Istanbul' => 1,
3410 'Asia/Jerusalem' => 1,
3411 'Asia/Nicosia' => 1,
3412 'Asia/Tel_Aviv' => 1,
3413 'Europe/Athens' => 1,
3414 'Europe/Bucharest' => 1,
3415 'Europe/Chisinau' => 1,
3416 'Europe/Helsinki' => 1,
3417 'Europe/Istanbul' => 1,
3418 'Europe/Kaliningrad' => 1,
3419 'Europe/Kiev' => 1,
3420 'Europe/Minsk' => 1,
3421 'Europe/Nicosia' => 1,
3422 'Europe/Riga' => 1,
3423 'Europe/Simferopol' => 1,
3424 'Europe/Sofia' => 1,
3425 'Europe/Tiraspol' => 1,
3426 'Europe/Uzhgorod' => 1,
3427 'Europe/Zaporozhye' => 1,
3428 'Asia/Baghdad' => 1,
3429 'Europe/Moscow' => 1,
3430 'Asia/Tehran' => 1,
3431 'Asia/Aqtau' => 1,
3432 'Asia/Baku' => 1,
3433 'Asia/Tbilisi' => 1,
3434 'Europe/Samara' => 1,
3435 'Asia/Aqtobe' => 1,
3436 'Asia/Bishkek' => 1,
3437 'Asia/Yekaterinburg' => 1,
3438 'Asia/Almaty' => 1,
3439 'Asia/Novosibirsk' => 1,
3440 'Asia/Omsk' => 1,
3441 'Asia/Krasnoyarsk' => 1,
3442 'Asia/Irkutsk' => 1,
3443 'Asia/Yakutsk' => 1,
3444 'Australia/Adelaide' => 1,
3445 'Australia/Broken_Hill' => 1,
3446 'Australia/South' => 1,
3447 'Australia/Yancowinna' => 1,
3448 'Asia/Sakhalin' => 1,
3449 'Asia/Vladivostok' => 1,
3450 'Australia/ACT' => 1,
3451 'Australia/Canberra' => 1,
3452 'Australia/Hobart' => 1,
3453 'Australia/Melbourne' => 1,
3454 'Australia/NSW' => 1,
3455 'Australia/Sydney' => 1,
3456 'Australia/Tasmania' => 1,
3457 'Australia/Victoria' => 1,
3458 'Australia/LHI' => 1,
3459 'Australia/Lord_Howe' => 1,
3460 'Asia/Magadan' => 1,
3461 'Antarctica/McMurdo' => 1,
3462 'Antarctica/South_Pole' => 1,
3463 'Asia/Anadyr' => 1,
3464 'Asia/Kamchatka' => 1,
3465 'Pacific/Auckland' => 1,
3466 'Pacific/Chatham' => 1,
3467 );
3468 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3469 }
3472 function display_error_page()
3473 {
3474 $smarty= get_smarty();
3475 $smarty->display(get_template_path('headers.tpl'));
3476 echo "<body>".msg_dialog::get_dialogs()."</body></html>";
3477 exit();
3478 }
3480 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3481 ?>