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 "mimetypeou" => "ou=mime,");
1041 /* Preset ou... */
1042 if (isset($config->current[$name])){
1043 $ou= $config->current[$name];
1044 } elseif (isset($map[$name])) {
1045 $ou = $map[$name];
1046 return($ou);
1047 } else {
1048 return "";
1049 }
1052 if ($ou != ""){
1053 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
1054 return @LDAP::convert("ou=$ou,");
1055 } else {
1056 return @LDAP::convert("$ou,");
1057 }
1058 } else {
1059 return "";
1060 }
1061 }
1064 function get_people_ou()
1065 {
1066 return (get_ou("PEOPLE"));
1067 }
1070 function get_groups_ou()
1071 {
1072 return (get_ou("GROUPS"));
1073 }
1076 function get_winstations_ou()
1077 {
1078 return (get_ou("WINSTATIONS"));
1079 }
1082 function get_base_from_people($dn)
1083 {
1084 global $config;
1086 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
1087 $base= preg_replace($pattern, '', $dn);
1089 /* Set to base, if we're not on a correct subtree */
1090 if (!isset($config->idepartments[$base])){
1091 $base= $config->current['BASE'];
1092 }
1094 return ($base);
1095 }
1098 function chkacl()
1099 {
1100 /* Look for attribute in ACL */
1101 trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
1102 return("-deprecated-");
1103 }
1106 function is_phone_nr($nr)
1107 {
1108 if ($nr == ""){
1109 return (TRUE);
1110 }
1112 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
1113 }
1115 function is_dns_name($str)
1116 {
1117 return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
1118 }
1120 function is_url($url)
1121 {
1122 if ($url == ""){
1123 return (TRUE);
1124 }
1126 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
1127 }
1130 function is_dn($dn)
1131 {
1132 if ($dn == ""){
1133 return (TRUE);
1134 }
1136 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
1137 }
1140 function strict_uid_mode()
1141 {
1142 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
1143 }
1146 function get_uid_regexp()
1147 {
1148 /* STRICT adds spaces and case insenstivity to the uid check.
1149 This is dangerous and should not be used. */
1150 if (strict_uid_mode()){
1151 return "^[a-z0-9_-]+$";
1152 } else {
1153 return "^[a-zA-Z0-9 _.-]+$";
1154 }
1155 }
1158 function is_uid($uid)
1159 {
1160 global $config;
1162 if ($uid == ""){
1163 return (TRUE);
1164 }
1166 /* STRICT adds spaces and case insenstivity to the uid check.
1167 This is dangerous and should not be used. */
1168 if (strict_uid_mode()){
1169 return preg_match ("/^[a-z0-9_-]+$/", $uid);
1170 } else {
1171 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
1172 }
1173 }
1176 function is_ip($ip)
1177 {
1178 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);
1179 }
1182 function is_mac($mac)
1183 {
1184 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);
1185 }
1188 /* Checks if the given ip address dosen't match
1189 "is_ip" because there is also a sub net mask given */
1190 function is_ip_with_subnetmask($ip)
1191 {
1192 /* Generate list of valid submasks */
1193 $res = array();
1194 for($e = 0 ; $e <= 32; $e++){
1195 $res[$e] = $e;
1196 }
1197 $i[0] =255;
1198 $i[1] =255;
1199 $i[2] =255;
1200 $i[3] =255;
1201 for($a= 3 ; $a >= 0 ; $a --){
1202 $c = 1;
1203 while($i[$a] > 0 ){
1204 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1205 $res[$str] = $str;
1206 $i[$a] -=$c;
1207 $c = 2*$c;
1208 }
1209 }
1210 $res["0.0.0.0"] = "0.0.0.0";
1211 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1212 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1213 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1214 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1215 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1216 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1217 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1218 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1220 $mask = preg_replace("/^\//","",$mask);
1221 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1222 return(TRUE);
1223 }
1224 }
1225 return(FALSE);
1226 }
1228 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1229 function is_domain($str)
1230 {
1231 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1232 }
1236 function is_id($id)
1237 {
1238 if ($id == ""){
1239 return (FALSE);
1240 }
1242 return preg_match ("/^[0-9]+$/", $id);
1243 }
1246 function is_path($path)
1247 {
1248 if ($path == ""){
1249 return (TRUE);
1250 }
1251 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1252 return (FALSE);
1253 }
1255 return preg_match ("/\/.+$/", $path);
1256 }
1259 function is_email($address, $template= FALSE)
1260 {
1261 if ($address == ""){
1262 return (TRUE);
1263 }
1264 if ($template){
1265 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1266 $address);
1267 } else {
1268 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1269 $address);
1270 }
1271 }
1274 function print_red()
1275 {
1276 /* Check number of arguments */
1277 if (func_num_args() < 1){
1278 return;
1279 }
1281 /* Get arguments, save string */
1282 $array = func_get_args();
1283 $string= $array[0];
1285 /* Step through arguments */
1286 for ($i= 1; $i<count($array); $i++){
1287 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1288 }
1290 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1291 the other case... */
1292 if (is_global('DEBUGLEVEL')){
1293 if($string !== NULL){
1294 if (preg_match("/"._("LDAP error:")."/", $string)){
1295 $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.");
1296 } else {
1297 if (!preg_match('/[.!?]$/', $string)){
1298 $string.= ".";
1299 }
1300 $string= preg_replace('/<br>/', ' ', $string);
1301 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1302 $addmsg = "";
1303 }
1304 if(empty($addmsg)){
1305 $addmsg = _("Error");
1306 }
1307 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1308 return;
1309 }else{
1310 return;
1311 }
1313 } else {
1314 echo "Error: $string\n";
1315 }
1316 }
1319 function gen_locked_message($user, $dn)
1320 {
1321 global $plug, $config;
1323 register_global('dn', $dn);
1324 $remove= false;
1326 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1327 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1329 $LOCK_VARS_USED = array();
1330 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1332 foreach($LOCK_VARS_TO_USE as $name){
1334 if(empty($name)){
1335 continue;
1336 }
1338 foreach($_POST as $Pname => $Pvalue){
1339 if(preg_match($name,$Pname)){
1340 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1341 }
1342 }
1344 foreach($_GET as $Pname => $Pvalue){
1345 if(preg_match($name,$Pname)){
1346 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1347 }
1348 }
1349 }
1350 register_global('LOCK_VARS_TO_USE',array());
1351 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1352 }
1354 /* Prepare and show template */
1355 $smarty= get_smarty();
1357 if(is_array($dn)){
1358 $msg = "<pre>";
1359 foreach($dn as $sub_dn){
1360 $msg .= "\n".$sub_dn.", ";
1361 }
1362 $msg = preg_replace("/, $/","</pre>",$msg);
1363 }else{
1364 $msg = $dn;
1365 }
1367 $smarty->assign ("dn", $msg);
1368 if ($remove){
1369 $smarty->assign ("action", _("Continue anyway"));
1370 } else {
1371 $smarty->assign ("action", _("Edit anyway"));
1372 }
1373 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1375 return ($smarty->fetch (get_template_path('islocked.tpl')));
1376 }
1379 function to_string ($value)
1380 {
1381 /* If this is an array, generate a text blob */
1382 if (is_array($value)){
1383 $ret= "";
1384 foreach ($value as $line){
1385 $ret.= $line."<br>\n";
1386 }
1387 return ($ret);
1388 } else {
1389 return ($value);
1390 }
1391 }
1394 function get_printer_list()
1395 {
1396 global $config;
1397 $res = array();
1398 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
1399 foreach($data as $attrs ){
1400 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1401 }
1402 return $res;
1403 }
1406 function sess_del ($var)
1407 {
1408 /* New style */
1409 unset($_SESSION[$var]);
1411 /* ... work around, since the first one
1412 doesn't seem to work all the time */
1413 session_unregister ($var);
1414 }
1417 function show_errors($message)
1418 {
1419 $complete= "";
1421 /* Assemble the message array to a plain string */
1422 foreach ($message as $error){
1423 if ($complete == ""){
1424 $complete= $error;
1425 } else {
1426 $complete= "$error<br>$complete";
1427 }
1428 }
1430 /* Fill ERROR variable with nice error dialog */
1431 print_red($complete);
1432 }
1435 function show_ldap_error($message, $addon= "")
1436 {
1437 if (!preg_match("/Success/i", $message)){
1438 if ($addon == ""){
1439 msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1440 } else {
1441 if(!preg_match("/No such object/i",$message)){
1442 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1443 }
1444 }
1445 return TRUE;
1446 } else {
1447 return FALSE;
1448 }
1449 }
1452 function rewrite($s)
1453 {
1454 global $REWRITE;
1456 foreach ($REWRITE as $key => $val){
1457 $s= preg_replace("/$key/", "$val", $s);
1458 }
1460 return ($s);
1461 }
1464 function dn2base($dn)
1465 {
1466 global $config;
1468 if (get_people_ou() != ""){
1469 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1470 }
1471 if (get_groups_ou() != ""){
1472 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1473 }
1474 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1476 return ($base);
1477 }
1481 function check_command($cmdline)
1482 {
1483 $cmd= preg_replace("/ .*$/", "", $cmdline);
1485 /* Check if command exists in filesystem */
1486 if (!file_exists($cmd)){
1487 return (FALSE);
1488 }
1490 /* Check if command is executable */
1491 if (!is_executable($cmd)){
1492 return (FALSE);
1493 }
1495 return (TRUE);
1496 }
1499 function print_header($image, $headline, $info= "")
1500 {
1501 $display= "<div class=\"plugtop\">\n";
1502 $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";
1503 $display.= "</div>\n";
1505 if ($info != ""){
1506 $display.= "<div class=\"pluginfo\">\n";
1507 $display.= "$info";
1508 $display.= "</div>\n";
1509 } else {
1510 $display.= "<div style=\"height:5px;\">\n";
1511 $display.= " ";
1512 $display.= "</div>\n";
1513 }
1514 return ($display);
1515 }
1518 function register_global($name, $object)
1519 {
1520 $_SESSION[$name]= $object;
1521 }
1524 function is_global($name)
1525 {
1526 return isset($_SESSION[$name]);
1527 }
1530 function &get_global($name)
1531 {
1532 return $_SESSION[$name];
1533 }
1536 function range_selector($dcnt,$start,$range=25,$post_var=false)
1537 {
1539 /* Entries shown left and right from the selected entry */
1540 $max_entries= 10;
1542 /* Initialize and take care that max_entries is even */
1543 $output="";
1544 if ($max_entries & 1){
1545 $max_entries++;
1546 }
1548 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1549 $range= $_POST[$post_var];
1550 }
1552 /* Prevent output to start or end out of range */
1553 if ($start < 0 ){
1554 $start= 0 ;
1555 }
1556 if ($start >= $dcnt){
1557 $start= $range * (int)(($dcnt / $range) + 0.5);
1558 }
1560 $numpages= (($dcnt / $range));
1561 if(((int)($numpages))!=($numpages)){
1562 $numpages = (int)$numpages + 1;
1563 }
1564 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1565 return ("");
1566 }
1567 $ppage= (int)(($start / $range) + 0.5);
1570 /* Align selected page to +/- max_entries/2 */
1571 $begin= $ppage - $max_entries/2;
1572 $end= $ppage + $max_entries/2;
1574 /* Adjust begin/end, so that the selected value is somewhere in
1575 the middle and the size is max_entries if possible */
1576 if ($begin < 0){
1577 $end-= $begin + 1;
1578 $begin= 0;
1579 }
1580 if ($end > $numpages) {
1581 $end= $numpages;
1582 }
1583 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1584 $begin= $end - $max_entries;
1585 }
1587 if($post_var){
1588 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1589 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1590 }else{
1591 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1592 }
1594 /* Draw decrement */
1595 if ($start > 0 ) {
1596 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1597 (($start-$range))."\">".
1598 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1599 }
1601 /* Draw pages */
1602 for ($i= $begin; $i < $end; $i++) {
1603 if ($ppage == $i){
1604 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1605 validate($_GET['plug'])."&start=".
1606 ($i*$range)."\"> ".($i+1)." </a>";
1607 } else {
1608 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1609 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1610 }
1611 }
1613 /* Draw increment */
1614 if($start < ($dcnt-$range)) {
1615 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1616 (($start+($range)))."\">".
1617 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1618 }
1620 if(($post_var)&&($numpages)){
1621 $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()'>";
1622 foreach(array(20,50,100,200,"all") as $num){
1623 if($num == "all"){
1624 $var = 10000;
1625 }else{
1626 $var = $num;
1627 }
1628 if($var == $range){
1629 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1630 }else{
1631 $output.="\n<option value='".$var."'>".$num."</option>";
1632 }
1633 }
1634 $output.= "</select></td></tr></table></div>";
1635 }else{
1636 $output.= "</div>";
1637 }
1639 return($output);
1640 }
1643 function apply_filter()
1644 {
1645 $apply= "";
1647 $apply= ''.
1648 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1649 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1651 return ($apply);
1652 }
1655 function back_to_main()
1656 {
1657 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1658 _("Back").'"></p><input type="hidden" name="ignore">';
1660 return ($string);
1661 }
1664 function normalize_netmask($netmask)
1665 {
1666 /* Check for notation of netmask */
1667 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1668 $num= (int)($netmask);
1669 $netmask= "";
1671 for ($byte= 0; $byte<4; $byte++){
1672 $result=0;
1674 for ($i= 7; $i>=0; $i--){
1675 if ($num-- > 0){
1676 $result+= pow(2,$i);
1677 }
1678 }
1680 $netmask.= $result.".";
1681 }
1683 return (preg_replace('/\.$/', '', $netmask));
1684 }
1686 return ($netmask);
1687 }
1690 function netmask_to_bits($netmask)
1691 {
1692 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1693 $res= 0;
1695 for ($n= 0; $n<4; $n++){
1696 $start= 255;
1697 $name= "nm$n";
1699 for ($i= 0; $i<8; $i++){
1700 if ($start == (int)($$name)){
1701 $res+= 8 - $i;
1702 break;
1703 }
1704 $start-= pow(2,$i);
1705 }
1706 }
1708 return ($res);
1709 }
1712 function recurse($rule, $variables)
1713 {
1714 $result= array();
1716 if (!count($variables)){
1717 return array($rule);
1718 }
1720 reset($variables);
1721 $key= key($variables);
1722 $val= current($variables);
1723 unset ($variables[$key]);
1725 foreach($val as $possibility){
1726 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1727 $result= array_merge($result, recurse($nrule, $variables));
1728 }
1730 return ($result);
1731 }
1734 function expand_id($rule, $attributes)
1735 {
1736 /* Check for id rule */
1737 if(preg_match('/^id(:|#)\d+$/',$rule)){
1738 return (array("\{$rule}"));
1739 }
1741 /* Check for clean attribute */
1742 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1743 $rule= preg_replace('/^%/', '', $rule);
1744 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1745 return (array($val));
1746 }
1748 /* Check for attribute with parameters */
1749 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1750 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1751 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1752 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1753 $start= preg_replace ('/-.*$/', '', $param);
1754 $stop = preg_replace ('/^[^-]+-/', '', $param);
1756 /* Assemble results */
1757 $result= array();
1758 for ($i= $start; $i<= $stop; $i++){
1759 $result[]= substr($val, 0, $i);
1760 }
1761 return ($result);
1762 }
1764 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1765 return (array($rule));
1766 }
1769 function gen_uids($rule, $attributes)
1770 {
1771 global $config;
1773 /* Search for keys and fill the variables array with all
1774 possible values for that key. */
1775 $part= "";
1776 $trigger= false;
1777 $stripped= "";
1778 $variables= array();
1780 for ($pos= 0; $pos < strlen($rule); $pos++){
1782 if ($rule[$pos] == "{" ){
1783 $trigger= true;
1784 $part= "";
1785 continue;
1786 }
1788 if ($rule[$pos] == "}" ){
1789 $variables[$pos]= expand_id($part, $attributes);
1790 $stripped.= "{".$pos."}";
1791 $trigger= false;
1792 continue;
1793 }
1795 if ($trigger){
1796 $part.= $rule[$pos];
1797 } else {
1798 $stripped.= $rule[$pos];
1799 }
1800 }
1802 /* Recurse through all possible combinations */
1803 $proposed= recurse($stripped, $variables);
1805 /* Get list of used ID's */
1806 $used= array();
1807 $ldap= $config->get_ldap_link();
1808 $ldap->cd($config->current['BASE']);
1809 $ldap->search('(uid=*)');
1811 while($attrs= $ldap->fetch()){
1812 $used[]= $attrs['uid'][0];
1813 }
1815 /* Remove used uids and watch out for id tags */
1816 $ret= array();
1817 foreach($proposed as $uid){
1819 /* Check for id tag and modify uid if needed */
1820 if(preg_match('/\{id:\d+}/',$uid)){
1821 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1823 for ($i= 0; $i < pow(10,$size); $i++){
1824 $number= sprintf("%0".$size."d", $i);
1825 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1826 if (!in_array($res, $used)){
1827 $uid= $res;
1828 break;
1829 }
1830 }
1831 }
1833 if(preg_match('/\{id#\d+}/',$uid)){
1834 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1836 while (true){
1837 mt_srand((double) microtime()*1000000);
1838 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1839 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1840 if (!in_array($res, $used)){
1841 $uid= $res;
1842 break;
1843 }
1844 }
1845 }
1847 /* Don't assign used ones */
1848 if (!in_array($uid, $used)){
1849 $ret[]= $uid;
1850 }
1851 }
1853 return(array_unique($ret));
1854 }
1857 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1858 Need to convert... */
1859 function to_byte($value) {
1860 $value= strtolower(trim($value));
1862 if(!is_numeric(substr($value, -1))) {
1864 switch(substr($value, -1)) {
1865 case 'g':
1866 $mult= 1073741824;
1867 break;
1868 case 'm':
1869 $mult= 1048576;
1870 break;
1871 case 'k':
1872 $mult= 1024;
1873 break;
1874 }
1876 return ($mult * (int)substr($value, 0, -1));
1877 } else {
1878 return $value;
1879 }
1880 }
1883 function in_array_ics($value, $items)
1884 {
1885 if (!is_array($items)){
1886 return (FALSE);
1887 }
1889 foreach ($items as $item){
1890 if (strcasecmp($item, $value) == 0) {
1891 return (TRUE);
1892 }
1893 }
1895 return (FALSE);
1896 }
1899 function generate_alphabet($count= 10)
1900 {
1901 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1902 $alphabet= "";
1903 $c= 0;
1905 /* Fill cells with charaters */
1906 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1907 if ($c == 0){
1908 $alphabet.= "<tr>";
1909 }
1911 $ch = mb_substr($characters, $i, 1, "UTF8");
1912 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1913 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1915 if ($c++ == $count){
1916 $alphabet.= "</tr>";
1917 $c= 0;
1918 }
1919 }
1921 /* Fill remaining cells */
1922 while ($c++ <= $count){
1923 $alphabet.= "<td> </td>";
1924 }
1926 return ($alphabet);
1927 }
1930 function validate($string)
1931 {
1932 return (strip_tags(preg_replace('/\0/', '', $string)));
1933 }
1935 function get_gosa_version()
1936 {
1937 global $svn_revision, $svn_path;
1939 /* Extract informations */
1940 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1942 /* Release or development? */
1943 if (preg_match('%/gosa/trunk/%', $svn_path)){
1944 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1945 } else {
1946 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1947 return (sprintf(_("GOsa $release"), $revision));
1948 }
1949 }
1952 function rmdirRecursive($path, $followLinks=false) {
1953 $dir= opendir($path);
1954 while($entry= readdir($dir)) {
1955 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1956 unlink($path."/".$entry);
1957 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1958 rmdirRecursive($path."/".$entry);
1959 }
1960 }
1961 closedir($dir);
1962 return rmdir($path);
1963 }
1965 function scan_directory($path,$sort_desc=false)
1966 {
1967 $ret = false;
1969 /* is this a dir ? */
1970 if(is_dir($path)) {
1972 /* is this path a readable one */
1973 if(is_readable($path)){
1975 /* Get contents and write it into an array */
1976 $ret = array();
1978 $dir = opendir($path);
1980 /* Is this a correct result ?*/
1981 if($dir){
1982 while($fp = readdir($dir))
1983 $ret[]= $fp;
1984 }
1985 }
1986 }
1987 /* Sort array ascending , like scandir */
1988 sort($ret);
1990 /* Sort descending if parameter is sort_desc is set */
1991 if($sort_desc) {
1992 $ret = array_reverse($ret);
1993 }
1995 return($ret);
1996 }
1998 function clean_smarty_compile_dir($directory)
1999 {
2000 global $svn_revision;
2002 if(is_dir($directory) && is_readable($directory)) {
2003 // Set revision filename to REVISION
2004 $revision_file= $directory."/REVISION";
2006 /* Is there a stamp containing the current revision? */
2007 if(!file_exists($revision_file)) {
2008 // create revision file
2009 create_revision($revision_file, $svn_revision);
2010 } else {
2011 # check for "$config->...['CONFIG']/revision" and the
2012 # contents should match the revision number
2013 if(!compare_revision($revision_file, $svn_revision)){
2014 // If revision differs, clean compile directory
2015 foreach(scan_directory($directory) as $file) {
2016 if(($file==".")||($file=="..")) continue;
2017 if( is_file($directory."/".$file) &&
2018 is_writable($directory."/".$file)) {
2019 // delete file
2020 if(!unlink($directory."/".$file)) {
2021 print_red("File ".$directory."/".$file." could not be deleted.");
2022 // This should never be reached
2023 }
2024 } elseif(is_dir($directory."/".$file) &&
2025 is_writable($directory."/".$file)) {
2026 // Just recursively delete it
2027 rmdirRecursive($directory."/".$file);
2028 }
2029 }
2030 // We should now create a fresh revision file
2031 clean_smarty_compile_dir($directory);
2032 } else {
2033 // Revision matches, nothing to do
2034 }
2035 }
2036 } else {
2037 // Smarty compile dir is not accessible
2038 // (Smarty will warn about this)
2039 }
2040 }
2042 function create_revision($revision_file, $revision)
2043 {
2044 $result= false;
2046 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
2047 if($fh= fopen($revision_file, "w")) {
2048 if(fwrite($fh, $revision)) {
2049 $result= true;
2050 }
2051 }
2052 fclose($fh);
2053 } else {
2054 print_red("Can not write to revision file");
2055 }
2057 return $result;
2058 }
2060 function compare_revision($revision_file, $revision)
2061 {
2062 // false means revision differs
2063 $result= false;
2065 if(file_exists($revision_file) && is_readable($revision_file)) {
2066 // Open file
2067 if($fh= fopen($revision_file, "r")) {
2068 // Compare File contents with current revision
2069 if($revision == fread($fh, filesize($revision_file))) {
2070 $result= true;
2071 }
2072 } else {
2073 print_red("Can not open revision file");
2074 }
2075 // Close file
2076 fclose($fh);
2077 }
2079 return $result;
2080 }
2082 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
2083 {
2084 $str = ""; // Our return value will be saved in this var
2086 $color = dechex($percentage+150);
2087 $color2 = dechex(150 - $percentage);
2088 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2090 $progress = (int)(($percentage /100)*$width);
2092 /* Abort printing out percentage, if divs are to small */
2095 /* If theres a better solution for this, use it... */
2096 $str = "
2097 <div style=\" width:".($width)."px;
2098 height:".($height)."px;
2099 background-color:#000000;
2100 padding:1px;\">
2102 <div style=\" width:".($width)."px;
2103 background-color:#$bgcolor;
2104 height:".($height)."px;\">
2106 <div style=\" width:".$progress."px;
2107 height:".$height."px;
2108 background-color:#".$color2.$color2.$color."; \">";
2111 if(($height >10)&&($showvalue)){
2112 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2113 <b>".$percentage."%</b>
2114 </font>";
2115 }
2117 $str.= "</div></div></div>";
2119 return($str);
2120 }
2123 function array_key_ics($ikey, $items)
2124 {
2125 /* Gather keys, make them lowercase */
2126 $tmp= array();
2127 foreach ($items as $key => $value){
2128 $tmp[strtolower($key)]= $key;
2129 }
2131 if (isset($tmp[strtolower($ikey)])){
2132 return($tmp[strtolower($ikey)]);
2133 }
2135 return ("");
2136 }
2139 function array_differs($src, $dst)
2140 {
2141 /* If the count is differing, the arrays differ */
2142 if (count ($src) != count ($dst)){
2143 return (TRUE);
2144 }
2146 /* So the count is the same - lets check the contents */
2147 $differs= FALSE;
2148 foreach($src as $value){
2149 if (!in_array($value, $dst)){
2150 $differs= TRUE;
2151 }
2152 }
2154 return ($differs);
2155 }
2158 function saveFilter($a_filter, $values)
2159 {
2160 if (isset($_POST['regexit'])){
2161 $a_filter["regex"]= $_POST['regexit'];
2163 foreach($values as $type){
2164 if (isset($_POST[$type])) {
2165 $a_filter[$type]= "checked";
2166 } else {
2167 $a_filter[$type]= "";
2168 }
2169 }
2170 }
2172 /* React on alphabet links if needed */
2173 if (isset($_GET['search'])){
2174 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2175 if ($s == "**"){
2176 $s= "*";
2177 }
2178 $a_filter['regex']= $s;
2179 }
2181 return ($a_filter);
2182 }
2185 /* Escape all preg_* relevant characters */
2186 function normalizePreg($input)
2187 {
2188 return (addcslashes($input, '[]()|/.*+-'));
2189 }
2192 /* Escape all LDAP filter relevant characters */
2193 function normalizeLdap($input)
2194 {
2195 return (addcslashes($input, '()|'));
2196 }
2199 /* Resturns the difference between to microtime() results in float */
2200 function get_MicroTimeDiff($start , $stop)
2201 {
2202 $a = split("\ ",$start);
2203 $b = split("\ ",$stop);
2205 $secs = $b[1] - $a[1];
2206 $msecs= $b[0] - $a[0];
2208 $ret = (float) ($secs+ $msecs);
2209 return($ret);
2210 }
2213 /* Check if the given department name is valid */
2214 function is_department_name_reserved($name,$base)
2215 {
2216 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2217 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2218 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2219 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2221 /* Check if name is one of the reserved names */
2222 if(in_array_ics($name,$reservedName)) {
2223 return(true);
2224 }
2226 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2227 foreach($follwedNames as $key => $names){
2228 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2229 return(true);
2230 }
2231 }
2232 return(false);
2233 }
2236 function get_base_dir()
2237 {
2238 global $BASE_DIR;
2240 return $BASE_DIR;
2241 }
2244 function obj_is_readable($dn, $object, $attribute)
2245 {
2246 global $ui;
2248 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2249 }
2252 function obj_is_writable($dn, $object, $attribute)
2253 {
2254 global $ui;
2256 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2257 }
2260 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2261 {
2262 /* Initialize variables */
2263 $ret = array("count" => 0); // Set count to 0
2264 $next = true; // if false, then skip next loops and return
2265 $cnt = 0; // Current number of loops
2266 $max = 100; // Just for security, prevent looops
2267 $ldap = NULL; // To check if created result a valid
2268 $keep = ""; // save last failed parse string
2270 /* Check each parsed dn in ldap ? */
2271 if($config!==NULL && $verify_in_ldap){
2272 $ldap = $config->get_ldap_link();
2273 }
2275 /* Lets start */
2276 $called = false;
2277 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2279 $cnt ++;
2280 if(!preg_match("/,/",$dn)){
2281 $next = false;
2282 }
2283 $object = preg_replace("/[,].*$/","",$dn);
2284 $dn = preg_replace("/^[^,]+,/","",$dn);
2286 $called = true;
2288 /* Check if current dn is valid */
2289 if($ldap!==NULL){
2290 $ldap->cd($dn);
2291 $ldap->cat($dn,array("dn"));
2292 if($ldap->count()){
2293 $ret[] = $keep.$object;
2294 $keep = "";
2295 }else{
2296 $keep .= $object.",";
2297 }
2298 }else{
2299 $ret[] = $keep.$object;
2300 $keep = "";
2301 }
2302 }
2304 /* No dn was posted */
2305 if($cnt == 0 && !empty($dn)){
2306 $ret[] = $dn;
2307 }
2309 /* Append the rest */
2310 $test = $keep.$dn;
2311 if($called && !empty($test)){
2312 $ret[] = $keep.$dn;
2313 }
2314 $ret['count'] = count($ret) - 1;
2316 return($ret);
2317 }
2319 /* Add "str_split" if this function is missing.
2320 * This function is only available in PHP5
2321 */
2322 if(!function_exists("str_split")){
2323 function str_split($str,$length =1)
2324 {
2325 if($length < 1 ) $length =1;
2327 $ret = array();
2328 for($i = 0 ; $i < strlen($str); $i = $i +$length){
2329 $ret[] = substr($str,$i ,$length);
2330 }
2331 return($ret);
2332 }
2333 }
2336 function get_base_from_hook($dn, $attrib)
2337 {
2338 global $config;
2340 if (isset($config->current['BASE_HOOK'])){
2342 /* Call hook script - if present */
2343 $command= $config->current['BASE_HOOK'];
2345 if ($command != ""){
2346 $command.= " '".LDAP::fix($dn)."' $attrib";
2347 if (check_command($command)){
2348 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2349 exec($command, $output);
2350 if (preg_match("/^[0-9]+$/", $output[0])){
2351 return ($output[0]);
2352 } else {
2353 print_red(_("Warning - base_hook is not available. Using default base."));
2354 return ($config->current['UIDBASE']);
2355 }
2356 } else {
2357 print_red(_("Warning - base_hook is not available. Using default base."));
2358 return ($config->current['UIDBASE']);
2359 }
2361 } else {
2363 print_red(_("Warning - no base_hook defined. Using default base."));
2364 return ($config->current['UIDBASE']);
2366 }
2367 }
2368 }
2370 /* Schema validation functions */
2372 function check_schema_version($class, $version)
2373 {
2374 return preg_match("/\(v$version\)/", $class['DESC']);
2375 }
2377 function check_schema($cfg,$rfc2307bis = FALSE)
2378 {
2379 $messages= array();
2381 /* Get objectclasses */
2382 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2383 $objectclasses = $ldap->get_objectclasses();
2384 if(count($objectclasses) == 0){
2385 print_red(_("Can't get schema information from server. No schema check possible!"));
2386 }
2388 /* This is the default block used for each entry.
2389 * to avoid unset indexes.
2390 */
2391 $def_check = array("REQUIRED_VERSION" => "0",
2392 "SCHEMA_FILES" => array(),
2393 "CLASSES_REQUIRED" => array(),
2394 "STATUS" => FALSE,
2395 "IS_MUST_HAVE" => FALSE,
2396 "MSG" => "",
2397 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2399 /* The gosa base schema */
2400 $checks['gosaObject'] = $def_check;
2401 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2402 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2403 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2404 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2406 /* GOsa Account class */
2407 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2408 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2409 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2410 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2411 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2413 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2414 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2415 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2416 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2417 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2418 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2420 /* Some other checks */
2421 foreach(array(
2422 "gosaCacheEntry" => array("version" => "2.4"),
2423 "gosaDepartment" => array("version" => "2.4"),
2424 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2425 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2426 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2427 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2428 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2429 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2430 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2431 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2432 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2433 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2434 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2435 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2436 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2437 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2438 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2439 "goLdapServer" => array("version" => "2.4"),
2440 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2441 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2442 "goKrbServer" => array("version" => "2.4"),
2443 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2444 ) as $name => $values){
2446 $checks[$name] = $def_check;
2447 if(isset($values['version'])){
2448 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2449 }
2450 if(isset($values['file'])){
2451 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2452 }
2453 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2454 }
2455 foreach($checks as $name => $value){
2456 foreach($value['CLASSES_REQUIRED'] as $class){
2458 if(!isset($objectclasses[$name])){
2459 $checks[$name]['STATUS'] = FALSE;
2460 if($value['IS_MUST_HAVE']){
2461 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2462 }else{
2463 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2464 }
2465 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2466 $checks[$name]['STATUS'] = FALSE;
2468 if($value['IS_MUST_HAVE']){
2469 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2470 }else{
2471 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2472 }
2473 }else{
2474 $checks[$name]['STATUS'] = TRUE;
2475 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2476 }
2477 }
2478 }
2480 $tmp = $objectclasses;
2482 /* The gosa base schema */
2483 $checks['posixGroup'] = $def_check;
2484 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2485 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2486 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2487 $checks['posixGroup']['STATUS'] = TRUE;
2488 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2489 $checks['posixGroup']['MSG'] = "";
2490 $checks['posixGroup']['INFO'] = "";
2492 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2493 if(isset($tmp['posixGroup'])){
2495 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2496 $checks['posixGroup']['STATUS'] = FALSE;
2497 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2498 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2499 }
2500 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2501 $checks['posixGroup']['STATUS'] = FALSE;
2502 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2503 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2504 }
2505 }
2507 return($checks);
2508 }
2513 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2514 {
2515 $tmp = array(
2516 "de_DE" => "German",
2517 "fr_FR" => "French",
2518 "it_IT" => "Italian",
2519 "es_ES" => "Spanish",
2520 "en_US" => "English",
2521 "nl_NL" => "Dutch",
2522 "pl_PL" => "Polish",
2523 "sv_SE" => "Swedish",
2524 "zh_CN" => "Chinese",
2525 "ru_RU" => "Russian");
2527 $tmp2= array(
2528 "de_DE" => _("German"),
2529 "fr_FR" => _("French"),
2530 "it_IT" => _("Italian"),
2531 "es_ES" => _("Spanish"),
2532 "en_US" => _("English"),
2533 "nl_NL" => _("Dutch"),
2534 "pl_PL" => _("Polish"),
2535 "sv_SE" => _("Swedish"),
2536 "zh_CN" => _("Chinese"),
2537 "ru_RU" => _("Russian"));
2539 $ret = array();
2540 if($languages_in_own_language){
2542 $old_lang = setlocale(LC_ALL, 0);
2543 foreach($tmp as $key => $name){
2544 $lang = $key.".UTF-8";
2545 setlocale(LC_ALL, $lang);
2546 if($strip_region_tag){
2547 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2548 }else{
2549 $ret[$key] = _($name)." (".$tmp2[$key].")";
2550 }
2551 }
2552 setlocale(LC_ALL, $old_lang);
2553 }else{
2554 foreach($tmp as $key => $name){
2555 if($strip_region_tag){
2556 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2557 }else{
2558 $ret[$key] = _($name);
2559 }
2560 }
2561 }
2562 return($ret);
2563 }
2566 /* Returns contents of the given POST variable and check magic quotes settings */
2567 function get_post($name)
2568 {
2569 if(!isset($_POST[$name])){
2570 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2571 return(FALSE);
2572 }
2573 if(get_magic_quotes_gpc()){
2574 return(stripcslashes($_POST[$name]));
2575 }else{
2576 return($_POST[$name]);
2577 }
2578 }
2581 /* Check if $ip1 and $ip2 represents a valid IP range
2582 * returns TRUE in case of a valid range, FALSE in case of an error.
2583 */
2584 function is_ip_range($ip1,$ip2)
2585 {
2586 if(!is_ip($ip1) || !is_ip($ip2)){
2587 return(FALSE);
2588 }else{
2589 $ar1 = split("\.",$ip1);
2590 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2592 $ar2 = split("\.",$ip2);
2593 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2594 return($var1 < $var2);
2595 }
2596 }
2599 /* Check if the specified IP address $address is inside the given network */
2600 function is_in_network($network, $netmask, $address)
2601 {
2602 $nw= split('\.', $network);
2603 $nm= split('\.', $netmask);
2604 $ad= split('\.', $address);
2606 /* Generate inverted netmask */
2607 for ($i= 0; $i<4; $i++){
2608 $ni[$i]= 255-$nm[$i];
2609 $la[$i]= $nw[$i] | $ni[$i];
2610 }
2612 /* Transform to integer */
2613 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2614 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2615 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2617 return ($first < $curr&& $last > $curr);
2618 }
2620 /* Return class name in correct case
2621 * mailMethodkolab => mailMethodKolab ( k => K )
2622 */
2623 function get_correct_class_name($cls)
2624 {
2625 global $class_mapping;
2626 if(isset($class_mapping) && is_array($class_mapping)){
2627 foreach($class_mapping as $class => $file){
2628 if(preg_match("/^".$cls."$/i",$class)){
2629 return($class);
2630 }
2631 }
2632 }
2633 return(FALSE);
2634 }
2636 // change_password, changes the Password, of the given dn
2637 function change_password ($dn, $password, $mode=0, $hash= "")
2638 {
2639 global $config;
2640 $newpass= "";
2642 /* Convert to lower. Methods are lowercase */
2643 $hash= strtolower($hash);
2645 // Get all available encryption Methods
2647 // NON STATIC CALL :)
2648 $tmp = new passwordMethod(get_global('config'));
2649 $available = $tmp->get_available_methods();
2651 // read current password entry for $dn, to detect the encryption Method
2652 $ldap = $config->get_ldap_link();
2653 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2654 $attrs = $ldap->fetch ();
2656 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2657 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2658 $deactivated = TRUE;
2659 }else{
2660 $deactivated = FALSE;
2661 }
2663 /* Is ensure that clear passwords will stay clear */
2664 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2665 $hash = "clear";
2666 }
2668 // Detect the encryption Method
2669 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2671 /* Check for supported algorithm */
2672 mt_srand((double) microtime()*1000000);
2674 /* Extract used hash */
2675 if ($hash == ""){
2676 $hash= strtolower($matches[1]);
2677 }
2679 $test = new $available[$hash]($config);
2681 } else {
2682 // User MD5 by default
2683 $hash= "md5";
2684 $test = new $available['md5']($config);
2685 }
2687 /* Feed password backends with information */
2688 $test->dn= $dn;
2689 $test->attrs= $attrs;
2690 $newpass= $test->generate_hash($password);
2692 // Update shadow timestamp?
2693 if (isset($attrs["shadowLastChange"][0])){
2694 $shadow= (int)(date("U") / 86400);
2695 } else {
2696 $shadow= 0;
2697 }
2699 // Write back modified entry
2700 $ldap->cd($dn);
2701 $attrs= array();
2703 // Not for groups
2704 if ($mode == 0){
2706 if ($shadow != 0){
2707 $attrs['shadowLastChange']= $shadow;
2708 }
2710 // Create SMB Password
2711 $attrs= generate_smb_nt_hash($password);
2712 }
2714 /* Readd ! if user was deactivated */
2715 if($deactivated){
2716 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2717 }
2719 $attrs['userPassword']= array();
2720 $attrs['userPassword']= $newpass;
2722 $ldap->modify($attrs);
2724 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2726 if ($ldap->error != 'Success') {
2727 print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2728 $ldap->get_error()));
2729 } else {
2731 /* Run backend method for change/create */
2732 $test->set_password($password);
2734 /* Find postmodify entries for this class */
2735 $command= $config->search("password", "POSTMODIFY",array('menu'));
2737 if ($command != ""){
2738 /* Walk through attribute list */
2739 $command= preg_replace("/%userPassword/", $password, $command);
2740 $command= preg_replace("/%dn/", $dn, $command);
2742 if (check_command($command)){
2743 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2744 exec($command);
2745 } else {
2746 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2747 print_red ($message);
2748 }
2749 }
2750 }
2751 }
2752 // Return something like array['sambaLMPassword']= "lalla..."
2753 function generate_smb_nt_hash($password)
2754 {
2755 global $config;
2756 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2757 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2759 exec($tmp, $ar);
2760 flush();
2761 reset($ar);
2762 $hash= current($ar);
2763 if ($hash == "")
2764 {
2765 print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2766 }
2767 else
2768 {
2769 list($lm,$nt)= split (":", trim($hash));
2771 if ($config->current['SAMBAVERSION'] == 3)
2772 {
2773 $attrs['sambaLMPassword']= $lm;
2774 $attrs['sambaNTPassword']= $nt;
2775 $attrs['sambaPwdLastSet']= date('U');
2776 $attrs['sambaBadPasswordCount']= "0";
2777 $attrs['sambaBadPasswordTime']= "0";
2778 } else {
2779 $attrs['lmPassword']= $lm;
2780 $attrs['ntPassword']= $nt;
2781 $attrs['pwdLastSet']= date('U');
2782 }
2783 return($attrs);
2784 }
2785 }
2787 function crypt_single($string,$enc_type )
2788 {
2789 return( passwordMethod::crypt_single_str($string,$enc_type));
2790 }
2793 function getEntryCSN($dn)
2794 {
2795 global $config;
2796 if(empty($dn) || !is_object($config)){
2797 return("");
2798 }
2800 /* Get attribute that we should use as serial number */
2801 if(isset($config->current['UNIQ_IDENTIFIER'])){
2802 $attr = $config->current['UNIQ_IDENTIFIER'];
2803 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2804 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2805 }
2806 if(!empty($attr)){
2807 $ldap = $config->get_ldap_link();
2808 $ldap->cat($dn,array($attr));
2809 $csn = $ldap->fetch();
2810 if(isset($csn[$attr][0])){
2811 return($csn[$attr][0]);
2812 }
2813 }
2814 return("");
2815 }
2817 /* This function returns the offset for the default timezone.
2818 * $stamp is used to detect summer or winter time.
2819 * In case of PHP5, the integrated timezone functions are used.
2820 * For PHP4 we query an array for offset and add summertime hour.
2821 */
2822 function get_default_timezone($stamp = NULL)
2823 {
2824 global $config;
2825 $tz ="";
2827 /* Default return value if zone could not be detected */
2828 $zone = array("name" => "unconfigured", "value" => 0);
2830 /* Use current timestamp if $stamp is not set */
2831 if($stamp === NULL){
2832 $stamp = time();
2833 }
2835 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2836 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2838 /* Get zonename */
2839 if(isset($config->current['TIMEZONE'])){
2840 $tz = $config->current['TIMEZONE'];
2841 }else{
2842 $tz = $config->data['MAIN']['TIMEZONE'];
2843 }
2845 if(!@date_default_timezone_set($tz)){
2846 print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2847 }
2848 $tz_delta = date("Z", $stamp);
2849 $tz_delta = $tz_delta / 3600 ;
2850 return(array("name" => $tz, "value" => $tz_delta));
2852 }
2853 return($zone);
2854 }
2857 /* Return zone informations */
2858 function _get_tz_zones()
2859 {
2860 $timezones = array(
2861 'Africa/Abidjan' => 0,
2862 'Africa/Accra' => 0,
2863 'Africa/Addis_Ababa' => 10800,
2864 'Africa/Algiers' => 3600,
2865 'Africa/Asmera' => 10800,
2866 'Africa/Bamako' => 0,
2867 'Africa/Bangui' => 3600,
2868 'Africa/Banjul' => 0,
2869 'Africa/Bissau' => 0,
2870 'Africa/Blantyre' => 7200,
2871 'Africa/Brazzaville' => 3600,
2872 'Africa/Bujumbura' => 7200,
2873 'Africa/Cairo' => 7200,
2874 'Africa/Casablanca' => 0,
2875 'Africa/Ceuta' => 3600,
2876 'Africa/Conakry' => 0,
2877 'Africa/Dakar' => 0,
2878 'Africa/Dar_es_Salaam' => 10800,
2879 'Africa/Djibouti' => 10800,
2880 'Africa/Douala' => 3600,
2881 'Africa/El_Aaiun' => 0,
2882 'Africa/Freetown' => 0,
2883 'Africa/Gaborone' => 7200,
2884 'Africa/Harare' => 7200,
2885 'Africa/Johannesburg' => 7200,
2886 'Africa/Kampala' => 10800,
2887 'Africa/Khartoum' => 10800,
2888 'Africa/Kigali' => 7200,
2889 'Africa/Kinshasa' => 3600,
2890 'Africa/Lagos' => 3600,
2891 'Africa/Libreville' => 3600,
2892 'Africa/Lome' => 0,
2893 'Africa/Luanda' => 3600,
2894 'Africa/Lubumbashi' => 7200,
2895 'Africa/Lusaka' => 7200,
2896 'Africa/Malabo' => 3600,
2897 'Africa/Maputo' => 7200,
2898 'Africa/Maseru' => 7200,
2899 'Africa/Mbabane' => 7200,
2900 'Africa/Mogadishu' => 10800,
2901 'Africa/Monrovia' => 0,
2902 'Africa/Nairobi' => 10800,
2903 'Africa/Ndjamena' => 3600,
2904 'Africa/Niamey' => 3600,
2905 'Africa/Nouakchott' => 0,
2906 'Africa/Ouagadougou' => 0,
2907 'Africa/Porto-Novo' => 3600,
2908 'Africa/Sao_Tome' => 0,
2909 'Africa/Timbuktu' => 0,
2910 'Africa/Tripoli' => 7200,
2911 'Africa/Tunis' => 3600,
2912 'Africa/Windhoek' => 3600,
2913 'America/Adak' => -36000,
2914 'America/Anchorage' => -32400,
2915 'America/Anguilla' => -14400,
2916 'America/Antigua' => -14400,
2917 'America/Araguaina' => -10800,
2918 'America/Argentina/Buenos_Aires' => 0,
2919 'America/Argentina/Catamarca' => 0,
2920 'America/Argentina/ComodRivadavia' => 0,
2921 'America/Argentina/Cordoba' => 0,
2922 'America/Argentina/Jujuy' => 0,
2923 'America/Argentina/La_Rioja' => 0,
2924 'America/Argentina/Mendoza' => 0,
2925 'America/Argentina/Rio_Gallegos' => 0,
2926 'America/Argentina/San_Juan' => 0,
2927 'America/Argentina/Tucuman' => 0,
2928 'America/Argentina/Ushuaia' => 0,
2929 'America/Aruba' => -14400,
2930 'America/Asuncion' => -14400,
2931 'America/Atikokan' => 0,
2932 'America/Atka' => -36000,
2933 'America/Bahia' => 0,
2934 'America/Barbados' => -14400,
2935 'America/Belem' => -10800,
2936 'America/Belize' => -21600,
2937 'America/Blanc-Sablon' => 0,
2938 'America/Boa_Vista' => -14400,
2939 'America/Bogota' => -18000,
2940 'America/Boise' => -25200,
2941 'America/Buenos_Aires' => -10800,
2942 'America/Cambridge_Bay' => -25200,
2943 'America/Campo_Grande' => 0,
2944 'America/Cancun' => -21600,
2945 'America/Caracas' => -14400,
2946 'America/Catamarca' => -10800,
2947 'America/Cayenne' => -10800,
2948 'America/Cayman' => -18000,
2949 'America/Chicago' => -21600,
2950 'America/Chihuahua' => -25200,
2951 'America/Coral_Harbour' => 0,
2952 'America/Cordoba' => -10800,
2953 'America/Costa_Rica' => -21600,
2954 'America/Cuiaba' => -14400,
2955 'America/Curacao' => -14400,
2956 'America/Danmarkshavn' => 0,
2957 'America/Dawson' => -28800,
2958 'America/Dawson_Creek' => -25200,
2959 'America/Denver' => -25200,
2960 'America/Detroit' => -18000,
2961 'America/Dominica' => -14400,
2962 'America/Edmonton' => -25200,
2963 'America/Eirunepe' => -18000,
2964 'America/El_Salvador' => -21600,
2965 'America/Ensenada' => -28800,
2966 'America/Fort_Wayne' => -18000,
2967 'America/Fortaleza' => -10800,
2968 'America/Glace_Bay' => -14400,
2969 'America/Godthab' => -10800,
2970 'America/Goose_Bay' => -14400,
2971 'America/Grand_Turk' => -18000,
2972 'America/Grenada' => -14400,
2973 'America/Guadeloupe' => -14400,
2974 'America/Guatemala' => -21600,
2975 'America/Guayaquil' => -18000,
2976 'America/Guyana' => -14400,
2977 'America/Halifax' => -14400,
2978 'America/Havana' => -18000,
2979 'America/Hermosillo' => -25200,
2980 'America/Indiana/Indianapolis' => -18000,
2981 'America/Indiana/Knox' => -18000,
2982 'America/Indiana/Marengo' => -18000,
2983 'America/Indiana/Petersburg' => 0,
2984 'America/Indiana/Vevay' => -18000,
2985 'America/Indiana/Vincennes' => 0,
2986 'America/Indianapolis' => -18000,
2987 'America/Inuvik' => -25200,
2988 'America/Iqaluit' => -18000,
2989 'America/Jamaica' => -18000,
2990 'America/Jujuy' => -10800,
2991 'America/Juneau' => -32400,
2992 'America/Kentucky/Louisville' => -18000,
2993 'America/Kentucky/Monticello' => -18000,
2994 'America/Knox_IN' => -18000,
2995 'America/La_Paz' => -14400,
2996 'America/Lima' => -18000,
2997 'America/Los_Angeles' => -28800,
2998 'America/Louisville' => -18000,
2999 'America/Maceio' => -10800,
3000 'America/Managua' => -21600,
3001 'America/Manaus' => -14400,
3002 'America/Martinique' => -14400,
3003 'America/Mazatlan' => -25200,
3004 'America/Mendoza' => -10800,
3005 'America/Menominee' => -21600,
3006 'America/Merida' => -21600,
3007 'America/Mexico_City' => -21600,
3008 'America/Miquelon' => -10800,
3009 'America/Moncton' => 0,
3010 'America/Monterrey' => -21600,
3011 'America/Montevideo' => -10800,
3012 'America/Montreal' => -18000,
3013 'America/Montserrat' => -14400,
3014 'America/Nassau' => -18000,
3015 'America/New_York' => -18000,
3016 'America/Nipigon' => -18000,
3017 'America/Nome' => -32400,
3018 'America/Noronha' => -7200,
3019 'America/North_Dakota/Center' => -21600,
3020 'America/North_Dakota/New_Salem' => 0,
3021 'America/Panama' => -18000,
3022 'America/Pangnirtung' => -18000,
3023 'America/Paramaribo' => -10800,
3024 'America/Phoenix' => -25200,
3025 'America/Port-au-Prince' => -18000,
3026 'America/Port_of_Spain' => -14400,
3027 'America/Porto_Acre' => -18000,
3028 'America/Porto_Velho' => -14400,
3029 'America/Puerto_Rico' => -14400,
3030 'America/Rainy_River' => -21600,
3031 'America/Rankin_Inlet' => -21600,
3032 'America/Recife' => -10800,
3033 'America/Regina' => -21600,
3034 'America/Rio_Branco' => -18000,
3035 'America/Rosario' => -10800,
3036 'America/Santiago' => -14400,
3037 'America/Santo_Domingo' => -14400,
3038 'America/Sao_Paulo' => -10800,
3039 'America/Scoresbysund' => -3600,
3040 'America/Shiprock' => -25200,
3041 'America/St_Johns' => -12600,
3042 'America/St_Kitts' => -14400,
3043 'America/St_Lucia' => -14400,
3044 'America/St_Thomas' => -14400,
3045 'America/St_Vincent' => -14400,
3046 'America/Swift_Current' => -21600,
3047 'America/Tegucigalpa' => -21600,
3048 'America/Thule' => -14400,
3049 'America/Thunder_Bay' => -18000,
3050 'America/Tijuana' => -28800,
3051 'America/Toronto' => 0,
3052 'America/Tortola' => -14400,
3053 'America/Vancouver' => -28800,
3054 'America/Virgin' => -14400,
3055 'America/Whitehorse' => -28800,
3056 'America/Winnipeg' => -21600,
3057 'America/Yakutat' => -32400,
3058 'America/Yellowknife' => -25200,
3059 'Antarctica/Casey' => 28800,
3060 'Antarctica/Davis' => 25200,
3061 'Antarctica/DumontDUrville' => 36000,
3062 'Antarctica/Mawson' => 21600,
3063 'Antarctica/McMurdo' => 43200,
3064 'Antarctica/Palmer' => -14400,
3065 'Antarctica/Rothera' => 0,
3066 'Antarctica/South_Pole' => 43200,
3067 'Antarctica/Syowa' => 10800,
3068 'Antarctica/VostokArctic/Longyearbyen' => 0,
3069 'Asia/Aden' => 10800,
3070 'Asia/Almaty' => 21600,
3071 'Asia/Amman' => 7200,
3072 'Asia/Anadyr' => 43200,
3073 'Asia/Aqtau' => 14400,
3074 'Asia/Aqtobe' => 18000,
3075 'Asia/Ashgabat' => 18000,
3076 'Asia/Ashkhabad' => 18000,
3077 'Asia/Baghdad' => 10800,
3078 'Asia/Bahrain' => 10800,
3079 'Asia/Baku' => 14400,
3080 'Asia/Bangkok' => 25200,
3081 'Asia/Beirut' => 7200,
3082 'Asia/Bishkek' => 18000,
3083 'Asia/Brunei' => 28800,
3084 'Asia/Calcutta' => 19800,
3085 'Asia/Choibalsan' => 32400,
3086 'Asia/Chongqing' => 28800,
3087 'Asia/Chungking' => 28800,
3088 'Asia/Colombo' => 21600,
3089 'Asia/Dacca' => 21600,
3090 'Asia/Damascus' => 7200,
3091 'Asia/Dhaka' => 21600,
3092 'Asia/Dili' => 32400,
3093 'Asia/Dubai' => 14400,
3094 'Asia/Dushanbe' => 18000,
3095 'Asia/Gaza' => 7200,
3096 'Asia/Harbin' => 28800,
3097 'Asia/Hong_Kong' => 28800,
3098 'Asia/Hovd' => 25200,
3099 'Asia/Irkutsk' => 28800,
3100 'Asia/Istanbul' => 7200,
3101 'Asia/Jakarta' => 25200,
3102 'Asia/Jayapura' => 32400,
3103 'Asia/Jerusalem' => 7200,
3104 'Asia/Kabul' => 16200,
3105 'Asia/Kamchatka' => 43200,
3106 'Asia/Karachi' => 18000,
3107 'Asia/Kashgar' => 28800,
3108 'Asia/Katmandu' => 20700,
3109 'Asia/Krasnoyarsk' => 25200,
3110 'Asia/Kuala_Lumpur' => 28800,
3111 'Asia/Kuching' => 28800,
3112 'Asia/Kuwait' => 10800,
3113 'Asia/Macao' => 28800,
3114 'Asia/Macau' => 0,
3115 'Asia/Magadan' => 39600,
3116 'Asia/Makassar' => 0,
3117 'Asia/Manila' => 28800,
3118 'Asia/Muscat' => 14400,
3119 'Asia/Nicosia' => 7200,
3120 'Asia/Novosibirsk' => 21600,
3121 'Asia/Omsk' => 21600,
3122 'Asia/Oral' => 0,
3123 'Asia/Phnom_Penh' => 25200,
3124 'Asia/Pontianak' => 25200,
3125 'Asia/Pyongyang' => 32400,
3126 'Asia/Qatar' => 10800,
3127 'Asia/Qyzylorda' => 0,
3128 'Asia/Rangoon' => 23400,
3129 'Asia/Riyadh' => 10800,
3130 'Asia/Saigon' => 25200,
3131 'Asia/Sakhalin' => 36000,
3132 'Asia/Samarkand' => 18000,
3133 'Asia/Seoul' => 32400,
3134 'Asia/Shanghai' => 28800,
3135 'Asia/Singapore' => 28800,
3136 'Asia/Taipei' => 28800,
3137 'Asia/Tashkent' => 18000,
3138 'Asia/Tbilisi' => 14400,
3139 'Asia/Tehran' => 12600,
3140 'Asia/Tel_Aviv' => 7200,
3141 'Asia/Thimbu' => 21600,
3142 'Asia/Thimphu' => 21600,
3143 'Asia/Tokyo' => 32400,
3144 'Asia/Ujung_Pandang' => 28800,
3145 'Asia/Ulaanbaatar' => 28800,
3146 'Asia/Ulan_Bator' => 28800,
3147 'Asia/Urumqi' => 28800,
3148 'Asia/Vientiane' => 25200,
3149 'Asia/Vladivostok' => 36000,
3150 'Asia/Yakutsk' => 32400,
3151 'Asia/Yekaterinburg' => 18000,
3152 'Asia/YerevanAtlantic/Azores' => 0,
3153 'Atlantic/Bermuda' => -14400,
3154 'Atlantic/Canary' => 0,
3155 'Atlantic/Cape_Verde' => -3600,
3156 'Atlantic/Faeroe' => 0,
3157 'Atlantic/Jan_Mayen' => 3600,
3158 'Atlantic/Madeira' => 0,
3159 'Atlantic/Reykjavik' => 0,
3160 'Atlantic/South_Georgia' => -7200,
3161 'Atlantic/St_Helena' => 0,
3162 'Atlantic/Stanley' => -14400,
3163 'Australia/ACT' => 36000,
3164 'Australia/Adelaide' => 34200,
3165 'Australia/Brisbane' => 36000,
3166 'Australia/Broken_Hill' => 34200,
3167 'Australia/Canberra' => 36000,
3168 'Australia/Currie' => 0,
3169 'Australia/Darwin' => 34200,
3170 'Australia/Hobart' => 36000,
3171 'Australia/LHI' => 37800,
3172 'Australia/Lindeman' => 36000,
3173 'Australia/Lord_Howe' => 37800,
3174 'Australia/Melbourne' => 36000,
3175 'Australia/NSW' => 36000,
3176 'Australia/North' => 34200,
3177 'Australia/Perth' => 28800,
3178 'Australia/Queensland' => 36000,
3179 'Australia/South' => 34200,
3180 'Australia/Sydney' => 36000,
3181 'Australia/Tasmania' => 36000,
3182 'Australia/Victoria' => 36000,
3183 'Australia/West' => 28800,
3184 'Australia/Yancowinna' => 34200,
3185 'Europe/Amsterdam' => 3600,
3186 'Europe/Andorra' => 3600,
3187 'Europe/Athens' => 7200,
3188 'Europe/Belfast' => 0,
3189 'Europe/Belgrade' => 3600,
3190 'Europe/Berlin' => 3600,
3191 'Europe/Bratislava' => 3600,
3192 'Europe/Brussels' => 3600,
3193 'Europe/Bucharest' => 7200,
3194 'Europe/Budapest' => 3600,
3195 'Europe/Chisinau' => 7200,
3196 'Europe/Copenhagen' => 3600,
3197 'Europe/Dublin' => 0,
3198 'Europe/Gibraltar' => 3600,
3199 'Europe/Guernsey' => 0,
3200 'Europe/Helsinki' => 7200,
3201 'Europe/Isle_of_Man' => 0,
3202 'Europe/Istanbul' => 7200,
3203 'Europe/Jersey' => 0,
3204 'Europe/Kaliningrad' => 7200,
3205 'Europe/Kiev' => 7200,
3206 'Europe/Lisbon' => 0,
3207 'Europe/Ljubljana' => 3600,
3208 'Europe/London' => 0,
3209 'Europe/Luxembourg' => 3600,
3210 'Europe/Madrid' => 3600,
3211 'Europe/Malta' => 3600,
3212 'Europe/Mariehamn' => 0,
3213 'Europe/Minsk' => 7200,
3214 'Europe/Monaco' => 3600,
3215 'Europe/Moscow' => 10800,
3216 'Europe/Nicosia' => 7200,
3217 'Europe/Oslo' => 3600,
3218 'Europe/Paris' => 3600,
3219 'Europe/Prague' => 3600,
3220 'Europe/Riga' => 7200,
3221 'Europe/Rome' => 3600,
3222 'Europe/Samara' => 14400,
3223 'Europe/San_Marino' => 3600,
3224 'Europe/Sarajevo' => 3600,
3225 'Europe/Simferopol' => 7200,
3226 'Europe/Skopje' => 3600,
3227 'Europe/Sofia' => 7200,
3228 'Europe/Stockholm' => 3600,
3229 'Europe/Tallinn' => 7200,
3230 'Europe/Tirane' => 3600,
3231 'Europe/Tiraspol' => 7200,
3232 'Europe/Uzhgorod' => 7200,
3233 'Europe/Vaduz' => 3600,
3234 'Europe/Vatican' => 3600,
3235 'Europe/Vienna' => 3600,
3236 'Europe/Vilnius' => 7200,
3237 'Europe/Volgograd' => 0,
3238 'Europe/Warsaw' => 3600,
3239 'Europe/Zagreb' => 3600,
3240 'Europe/Zaporozhye' => 7200,
3241 'Europe/Zurich' => 3600,
3242 'Indian/Antananarivo' => 10800,
3243 'Indian/Chagos' => 21600,
3244 'Indian/Christmas' => 25200,
3245 'Indian/Cocos' => 23400,
3246 'Indian/Comoro' => 10800,
3247 'Indian/Kerguelen' => 18000,
3248 'Indian/Mahe' => 14400,
3249 'Indian/Maldives' => 18000,
3250 'Indian/Mauritius' => 14400,
3251 'Indian/Mayotte' => 10800,
3252 'Indian/Reunion' => 14400,
3253 'Pacific/Apia' => -39600,
3254 'Pacific/Auckland' => 43200,
3255 'Pacific/Chatham' => 45900,
3256 'Pacific/Easter' => -21600,
3257 'Pacific/Efate' => 39600,
3258 'Pacific/Enderbury' => 46800,
3259 'Pacific/Fakaofo' => -36000,
3260 'Pacific/Fiji' => 43200,
3261 'Pacific/Funafuti' => 43200,
3262 'Pacific/Galapagos' => -21600,
3263 'Pacific/Gambier' => -32400,
3264 'Pacific/Guadalcanal' => 39600,
3265 'Pacific/Guam' => 36000,
3266 'Pacific/Honolulu' => -36000,
3267 'Pacific/Johnston' => -36000,
3268 'Pacific/Kiritimati' => 50400,
3269 'Pacific/Kosrae' => 39600,
3270 'Pacific/Kwajalein' => 43200,
3271 'Pacific/Majuro' => 43200,
3272 'Pacific/Marquesas' => -34200,
3273 'Pacific/Midway' => -39600,
3274 'Pacific/Nauru' => 43200,
3275 'Pacific/Niue' => -39600,
3276 'Pacific/Norfolk' => 41400,
3277 'Pacific/Noumea' => 39600,
3278 'Pacific/Pago_Pago' => -39600,
3279 'Pacific/Palau' => 32400,
3280 'Pacific/Pitcairn' => -28800,
3281 'Pacific/Ponape' => 39600,
3282 'Pacific/Port_Moresby' => 36000,
3283 'Pacific/Rarotonga' => -36000,
3284 'Pacific/Saipan' => 36000,
3285 'Pacific/Samoa' => -39600,
3286 'Pacific/Tahiti' => -36000,
3287 'Pacific/Tarawa' => 43200,
3288 'Pacific/Tongatapu' => 46800,
3289 'Pacific/Truk' => 36000,
3290 'Pacific/Wake' => 43200,
3291 'Pacific/Wallis' => 43200,
3292 'Pacific/Yap' => 36000 );
3294 $dst_timezones = array (
3295 'America/Adak' => 1,
3296 'America/Atka' => 1,
3297 'America/Anchorage' => 1,
3298 'America/Juneau' => 1,
3299 'America/Nome' => 1,
3300 'America/Yakutat' => 1,
3301 'America/Dawson' => 1,
3302 'America/Ensenada' => 1,
3303 'America/Los_Angeles' => 1,
3304 'America/Tijuana' => 1,
3305 'America/Vancouver' => 1,
3306 'America/Whitehorse' => 1,
3307 'America/Boise' => 1,
3308 'America/Cambridge_Bay' => 1,
3309 'America/Chihuahua' => 1,
3310 'America/Denver' => 1,
3311 'America/Edmonton' => 1,
3312 'America/Inuvik' => 1,
3313 'America/Mazatlan' => 1,
3314 'America/Shiprock' => 1,
3315 'America/Yellowknife' => 1,
3316 'America/Cancun' => 1,
3317 'America/Chicago' => 1,
3318 'America/Menominee' => 1,
3319 'America/Merida' => 1,
3320 'America/Monterrey' => 1,
3321 'America/North_Dakota/Center' => 1,
3322 'America/Rainy_River' => 1,
3323 'America/Rankin_Inlet' => 1,
3324 'America/Winnipeg' => 1,
3325 'Pacific/Easter' => 1,
3326 'America/Detroit' => 1,
3327 'America/Grand_Turk' => 1,
3328 'America/Havana' => 1,
3329 'America/Iqaluit' => 1,
3330 'America/Kentucky/Louisville' => 1,
3331 'America/Kentucky/Monticello' => 1,
3332 'America/Louisville' => 1,
3333 'America/Montreal' => 1,
3334 'America/Nassau' => 1,
3335 'America/New_York' => 1,
3336 'America/Nipigon' => 1,
3337 'America/Pangnirtung' => 1,
3338 'America/Thunder_Bay' => 1,
3339 'America/Asuncion' => 1,
3340 'America/Cuiaba' => 1,
3341 'America/Glace_Bay' => 1,
3342 'America/Goose_Bay' => 1,
3343 'America/Halifax' => 1,
3344 'America/Santiago' => 1,
3345 'Antarctica/Palmer' => 1,
3346 'Atlantic/Bermuda' => 1,
3347 'Atlantic/Stanley' => 1,
3348 'America/St_Johns' => 1,
3349 'America/Araguaina' => 1,
3350 'America/Fortaleza' => 1,
3351 'America/Godthab' => 1,
3352 'America/Maceio' => 1,
3353 'America/Miquelon' => 1,
3354 'America/Recife' => 1,
3355 'America/Sao_Paulo' => 1,
3356 'America/Scoresbysund' => 1,
3357 'Atlantic/Canary' => 1,
3358 'Atlantic/Faeroe' => 1,
3359 'Atlantic/Madeira' => 1,
3360 'Europe/Belfast' => 1,
3361 'Europe/Dublin' => 1,
3362 'Europe/Lisbon' => 1,
3363 'Europe/London' => 1,
3364 'Africa/Ceuta' => 1,
3365 'Africa/Windhoek' => 1,
3366 'Atlantic/Jan_Mayen' => 1,
3367 'Europe/Amsterdam' => 1,
3368 'Europe/Andorra' => 1,
3369 'Europe/Belgrade' => 1,
3370 'Europe/Berlin' => 1,
3371 'Europe/Bratislava' => 1,
3372 'Europe/Brussels' => 1,
3373 'Europe/Budapest' => 1,
3374 'Europe/Copenhagen' => 1,
3375 'Europe/Gibraltar' => 1,
3376 'Europe/Ljubljana' => 1,
3377 'Europe/Luxembourg' => 1,
3378 'Europe/Madrid' => 1,
3379 'Europe/Malta' => 1,
3380 'Europe/Monaco' => 1,
3381 'Europe/Oslo' => 1,
3382 'Europe/Paris' => 1,
3383 'Europe/Prague' => 1,
3384 'Europe/Rome' => 1,
3385 'Europe/San_Marino' => 1,
3386 'Europe/Sarajevo' => 1,
3387 'Europe/Skopje' => 1,
3388 'Europe/Stockholm' => 1,
3389 'Europe/Tirane' => 1,
3390 'Europe/Vaduz' => 1,
3391 'Europe/Vatican' => 1,
3392 'Europe/Vienna' => 1,
3393 'Europe/Warsaw' => 1,
3394 'Europe/Zagreb' => 1,
3395 'Europe/Zurich' => 1,
3396 'Africa/Cairo' => 1,
3397 'Asia/Amman' => 1,
3398 'Asia/Beirut' => 1,
3399 'Asia/Damascus' => 1,
3400 'Asia/Gaza' => 1,
3401 'Asia/Istanbul' => 1,
3402 'Asia/Jerusalem' => 1,
3403 'Asia/Nicosia' => 1,
3404 'Asia/Tel_Aviv' => 1,
3405 'Europe/Athens' => 1,
3406 'Europe/Bucharest' => 1,
3407 'Europe/Chisinau' => 1,
3408 'Europe/Helsinki' => 1,
3409 'Europe/Istanbul' => 1,
3410 'Europe/Kaliningrad' => 1,
3411 'Europe/Kiev' => 1,
3412 'Europe/Minsk' => 1,
3413 'Europe/Nicosia' => 1,
3414 'Europe/Riga' => 1,
3415 'Europe/Simferopol' => 1,
3416 'Europe/Sofia' => 1,
3417 'Europe/Tiraspol' => 1,
3418 'Europe/Uzhgorod' => 1,
3419 'Europe/Zaporozhye' => 1,
3420 'Asia/Baghdad' => 1,
3421 'Europe/Moscow' => 1,
3422 'Asia/Tehran' => 1,
3423 'Asia/Aqtau' => 1,
3424 'Asia/Baku' => 1,
3425 'Asia/Tbilisi' => 1,
3426 'Europe/Samara' => 1,
3427 'Asia/Aqtobe' => 1,
3428 'Asia/Bishkek' => 1,
3429 'Asia/Yekaterinburg' => 1,
3430 'Asia/Almaty' => 1,
3431 'Asia/Novosibirsk' => 1,
3432 'Asia/Omsk' => 1,
3433 'Asia/Krasnoyarsk' => 1,
3434 'Asia/Irkutsk' => 1,
3435 'Asia/Yakutsk' => 1,
3436 'Australia/Adelaide' => 1,
3437 'Australia/Broken_Hill' => 1,
3438 'Australia/South' => 1,
3439 'Australia/Yancowinna' => 1,
3440 'Asia/Sakhalin' => 1,
3441 'Asia/Vladivostok' => 1,
3442 'Australia/ACT' => 1,
3443 'Australia/Canberra' => 1,
3444 'Australia/Hobart' => 1,
3445 'Australia/Melbourne' => 1,
3446 'Australia/NSW' => 1,
3447 'Australia/Sydney' => 1,
3448 'Australia/Tasmania' => 1,
3449 'Australia/Victoria' => 1,
3450 'Australia/LHI' => 1,
3451 'Australia/Lord_Howe' => 1,
3452 'Asia/Magadan' => 1,
3453 'Antarctica/McMurdo' => 1,
3454 'Antarctica/South_Pole' => 1,
3455 'Asia/Anadyr' => 1,
3456 'Asia/Kamchatka' => 1,
3457 'Pacific/Auckland' => 1,
3458 'Pacific/Chatham' => 1,
3459 );
3460 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3461 }
3464 function display_error_page()
3465 {
3466 $smarty= get_smarty();
3467 $smarty->display(get_template_path('headers.tpl'));
3468 echo "<body>".msg_dialog::get_dialogs()."</body></html>";
3469 exit();
3470 }
3472 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3473 ?>