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