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 }
105 /* Create seed with microseconds */
106 function make_seed() {
107 list($usec, $sec) = explode(' ', microtime());
108 return (float) $sec + ((float) $usec * 100000);
109 }
112 /* Debug level action */
113 function DEBUG($level, $line, $function, $file, $data, $info="")
114 {
115 if (get_global('DEBUGLEVEL') & $level){
116 $output= "DEBUG[$level] ";
117 if ($function != ""){
118 $output.= "($file:$function():$line) - $info: ";
119 } else {
120 $output.= "($file:$line) - $info: ";
121 }
122 echo $output;
123 if (is_array($data)){
124 print_a($data);
125 } else {
126 echo "'$data'";
127 }
128 echo "<br>";
129 }
130 }
133 function get_browser_language()
134 {
135 /* Try to use users primary language */
136 global $config;
137 $ui= get_userinfo();
138 if (isset($ui) && $ui !== NULL){
139 if ($ui->language != ""){
140 return ($ui->language.".UTF-8");
141 }
142 }
144 /* Check for global language settings in gosa.conf */
145 if(isset($config->data['MAIN']['LANG']) && !empty($config->data['MAIN']['LANG'])) {
146 $lang = $config->data['MAIN']['LANG'];
147 if(!preg_match("/utf/i",$lang)){
148 $lang .= ".UTF-8";
149 }
150 return($lang);
151 }
153 /* Load supported languages */
154 $gosa_languages= get_languages();
156 /* Move supported languages to flat list */
157 $langs= array();
158 foreach($gosa_languages as $lang => $dummy){
159 $langs[]= $lang.'.UTF-8';
160 }
162 /* Return gettext based string */
163 return (al2gt($langs, 'text/html'));
164 }
167 /* Rewrite ui object to another dn */
168 function change_ui_dn($dn, $newdn)
169 {
170 $ui= get_global('ui');
171 if ($ui->dn == $dn){
172 $ui->dn= $newdn;
173 register_global('ui',$ui);
174 }
175 }
178 /* Return theme path for specified file */
179 function get_template_path($filename= '', $plugin= FALSE, $path= "")
180 {
181 global $config, $BASE_DIR;
183 if (!@isset($config->data['MAIN']['THEME'])){
184 $theme= 'default';
185 } else {
186 $theme= $config->data['MAIN']['THEME'];
187 }
189 /* Return path for empty filename */
190 if ($filename == ''){
191 return ("themes/$theme/");
192 }
194 /* Return plugin dir or root directory? */
195 if ($plugin){
196 if ($path == ""){
197 $nf= preg_replace("!^".$BASE_DIR."/!", "", get_global('plugin_dir'));
198 } else {
199 $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
200 }
201 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$nf")){
202 return ("$BASE_DIR/ihtml/themes/$theme/$nf/$filename");
203 }
204 if (file_exists("$BASE_DIR/ihtml/themes/default/$nf")){
205 return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
206 }
207 if ($path == ""){
208 return (get_global('plugin_dir')."/$filename");
209 } else {
210 return ($path."/$filename");
211 }
212 } else {
213 if (file_exists("themes/$theme/$filename")){
214 return ("themes/$theme/$filename");
215 }
216 if (file_exists("$BASE_DIR/ihtml/themes/$theme/$filename")){
217 return ("$BASE_DIR/ihtml/themes/$theme/$filename");
218 }
219 if (file_exists("themes/default/$filename")){
220 return ("themes/default/$filename");
221 }
222 if (file_exists("$BASE_DIR/ihtml/themes/default/$filename")){
223 return ("$BASE_DIR/ihtml/themes/default/$filename");
224 }
225 return ($filename);
226 }
227 }
230 function array_remove_entries($needles, $haystack)
231 {
232 $tmp= array();
234 /* Loop through entries to be removed */
235 foreach ($haystack as $entry){
236 if (!in_array($entry, $needles)){
237 $tmp[]= $entry;
238 }
239 }
241 return ($tmp);
242 }
245 function gosa_array_merge($ar1,$ar2)
246 {
247 if(!is_array($ar1) || !is_array($ar2)){
248 trigger_error("Specified parameter(s) are not valid arrays.");
249 }else{
250 return(array_values(array_unique(array_merge($ar1,$ar2))));
251 }
252 }
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 msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
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 msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
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 msg_dialog::display(_("LDAP error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
348 return (NULL);
349 }
350 $attrs= $ldap->fetch();
352 /* got user dn, fill acl's */
353 $ui= new userinfo($config, $ldap->getDN());
354 $ui->username= $attrs['uid'][0];
356 /* No password check needed - the webserver did it for us */
357 $ldap->disconnect();
359 /* Username is set, load subtreeACL's now */
360 $ui->loadACL();
362 /* TODO: check java script for htaccess authentication */
363 session::set('js',true);
365 return ($ui);
366 }
369 function ldap_login_user ($username, $password)
370 {
371 global $config;
373 /* look through the entire ldap */
374 $ldap = $config->get_ldap_link();
375 if (!preg_match("/Success/i", $ldap->error)){
376 msg_dialog::display(_("LDAP error"), sprintf(_("User login failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
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 msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
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 }
549 function add_lock ($object, $user)
550 {
551 global $config;
553 if(is_array($object)){
554 foreach($object as $obj){
555 add_lock($obj,$user);
556 }
557 return;
558 }
560 /* Just a sanity check... */
561 if ($object == "" || $user == ""){
562 msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
563 return;
564 }
566 /* Check for existing entries in lock area */
567 $ldap= $config->get_ldap_link();
568 $ldap->cd ($config->current['CONFIG']);
569 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
570 array("gosaUser"));
571 if (!preg_match("/Success/i", $ldap->error)){
572 msg_dialog::display(_("Configuration error"), sprintf(_("Cannot create locking information in LDAP tree. Please contact your administrator!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
573 return;
574 }
576 /* Add lock if none present */
577 if ($ldap->count() == 0){
578 $attrs= array();
579 $name= md5($object);
580 $ldap->cd("cn=$name,".$config->current['CONFIG']);
581 $attrs["objectClass"] = "gosaLockEntry";
582 $attrs["gosaUser"] = $user;
583 $attrs["gosaObject"] = base64_encode($object);
584 $attrs["cn"] = "$name";
585 $ldap->add($attrs);
586 if (!preg_match("/Success/i", $ldap->error)){
587 msg_dialog::display(_("Internal error"), sprintf(_("Adding a lock failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
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 msg_dialog::display(_("LDAP error"), sprintf(_("Removing a lock failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
620 return;
621 }
622 }
623 }
626 function del_user_locks($userdn)
627 {
628 global $config;
630 /* Get LDAP ressources */
631 $ldap= $config->get_ldap_link();
632 $ldap->cd ($config->current['CONFIG']);
634 /* Remove all objects of this user, drop errors silently in this case. */
635 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
636 while ($attrs= $ldap->fetch()){
637 $ldap->rmdir($attrs['dn']);
638 }
639 }
642 function get_lock ($object)
643 {
644 global $config;
646 /* Sanity check */
647 if ($object == ""){
648 msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
649 return("");
650 }
652 /* Get LDAP link, check for presence of the lock entry */
653 $user= "";
654 $ldap= $config->get_ldap_link();
655 $ldap->cd ($config->current['CONFIG']);
656 $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
657 if (!preg_match("/Success/i", $ldap->error)){
658 msg_dialog::display(_("LDAP error"), sprintf(_("Cannot get locking information from LDAP tree!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
659 return("");
660 }
662 /* Check for broken locking information in LDAP */
663 if ($ldap->count() > 1){
665 /* Hmm. We're removing broken LDAP information here and issue a warning. */
666 msg_dialog::display(_("Warning"), _("Found multiple locks for object to be locked. This should not happen - cleaning up multiple references."), WARNING_DIALOG);
668 /* Clean up these references now... */
669 while ($attrs= $ldap->fetch()){
670 $ldap->rmdir($attrs['dn']);
671 }
673 return("");
675 } elseif ($ldap->count() == 1){
676 $attrs = $ldap->fetch();
677 $user= $attrs['gosaUser'][0];
678 }
679 return ($user);
680 }
683 function get_multiple_locks($objects)
684 {
685 global $config;
687 if(is_array($objects)){
688 $filter = "(&(objectClass=gosaLockEntry)(|";
689 foreach($objects as $obj){
690 $filter.="(gosaObject=".base64_encode($obj).")";
691 }
692 $filter.= "))";
693 }else{
694 $filter = "(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($objects)."))";
695 }
697 /* Get LDAP link, check for presence of the lock entry */
698 $user= "";
699 $ldap= $config->get_ldap_link();
700 $ldap->cd ($config->current['CONFIG']);
701 $ldap->search($filter, array("gosaUser","gosaObject"));
702 if (!preg_match("/Success/i", $ldap->error)){
703 msg_dialog::display(_("LDAP error"), sprintf(_("Cannot get locking information from LDAP tree!")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
704 return("");
705 }
707 $users = array();
708 while($attrs = $ldap->fetch()){
709 $dn = base64_decode($attrs['gosaObject'][0]);
710 $user = $attrs['gosaUser'][0];
711 $users[] = array("dn"=> $dn,"user"=>$user);
712 }
713 return ($users);
714 }
717 /* \!brief This function searches the ldap database.
718 It search in $sub_base,*,$base for all objects matching the $filter.
720 @param $filter String The ldap search filter
721 @param $category String The ACL category the result objects belongs
722 @param $sub_base String The sub base we want to search for e.g. "ou=apps"
723 @param $base String The ldap base from which we start the search
724 @param $attributes Array The attributes we search for.
725 @param $flags Long A set of Flags
726 */
727 function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
728 {
730 global $config, $ui;
732 /* Get LDAP link */
733 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
735 /* Set search base to configured base if $base is empty */
736 if ($base == ""){
737 $ldap->cd ($config->current['BASE']);
738 } else {
739 $ldap->cd ($base);
740 }
742 /* Remove , ("ou=1,ou=2.." => "ou=1") */
743 $sub_base = preg_replace("/,.*$/","",$sub_base);
745 /* Check if there is a sub department specified */
746 if($sub_base == ""){
747 return(get_list($filter, $category,$base,$attributes,$flags));
748 }
750 /* Get all deparments matching the given sub_base */
751 $departments = array();
752 $ldap->search($sub_base,array("dn"));
753 while($attrs = $ldap->fetch()){
754 $departments[$attrs['dn']] = $attrs['dn'];
755 }
757 $result= array();
758 $limit_exceeded = FALSE;
760 /* Search in all matching departments */
761 foreach($departments as $dep){
763 /* Break if the size limit is exceeded */
764 if($limit_exceeded){
765 return($result);
766 }
768 $ldap->cd($dep);
770 /* Perform ONE or SUB scope searches? */
771 if ($flags & GL_SUBSEARCH) {
772 $ldap->search ($filter, $attributes);
773 } else {
774 $ldap->ls ($filter,$base,$attributes);
775 }
777 /* Check for size limit exceeded messages for GUI feedback */
778 if (preg_match("/size limit/i", $ldap->error)){
779 register_global('limit_exceeded', TRUE);
780 $limit_exceeded = TRUE;
781 }
783 /* Crawl through result entries and perform the migration to the
784 result array */
785 while($attrs = $ldap->fetch()) {
786 $dn= $ldap->getDN();
788 /* Convert dn into a printable format */
789 if ($flags & GL_CONVERT){
790 $attrs["dn"]= convert_department_dn($dn);
791 } else {
792 $attrs["dn"]= $dn;
793 }
795 /* Sort in every value that fits the permissions */
796 if (is_array($category)){
797 foreach ($category as $o){
798 if ($ui->get_category_permissions($dn, $o) != ""){
799 $result[]= $attrs;
800 break;
801 }
802 }
803 } else {
804 if ($ui->get_category_permissions($dn, $category) != ""){
805 $result[]= $attrs;
806 }
807 }
808 }
809 }
810 return($result);
811 }
814 function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
815 {
816 global $config, $ui;
818 /* Get LDAP link */
819 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
821 /* Set search base to configured base if $base is empty */
822 if ($base == ""){
823 $ldap->cd ($config->current['BASE']);
824 } else {
825 $ldap->cd ($base);
826 }
828 /* Perform ONE or SUB scope searches? */
829 if ($flags & GL_SUBSEARCH) {
830 $ldap->search ($filter, $attributes);
831 } else {
832 $ldap->ls ($filter,$base,$attributes);
833 }
835 /* Check for size limit exceeded messages for GUI feedback */
836 if (preg_match("/size limit/i", $ldap->error)){
837 register_global('limit_exceeded', TRUE);
838 }
840 /* Crawl through reslut entries and perform the migration to the
841 result array */
842 $result= array();
844 while($attrs = $ldap->fetch()) {
845 $dn= $ldap->getDN();
847 /* Sort in every value that fits the permissions */
848 if (is_array($category)){
849 foreach ($category as $o){
850 if ($ui->get_category_permissions($dn, $o) != ""){
851 if ($flags & GL_CONVERT){
852 $attrs["dn"]= convert_department_dn($dn);
853 } else {
854 $attrs["dn"]= $dn;
855 }
857 /* We found what we were looking for, break speeds things up */
858 $result[]= $attrs;
859 }
860 }
861 } else {
862 if ($ui->get_category_permissions($dn, $category) != ""){
863 if ($flags & GL_CONVERT){
864 $attrs["dn"]= convert_department_dn($dn);
865 } else {
866 $attrs["dn"]= $dn;
867 }
869 /* We found what we were looking for, break speeds things up */
870 $result[]= $attrs;
871 }
872 }
873 }
875 return ($result);
876 }
879 function check_sizelimit()
880 {
881 /* Ignore dialog? */
882 if (is_global('size_ignore') && get_global('size_ignore')){
883 return ("");
884 }
886 /* Eventually show dialog */
887 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
888 $smarty= get_smarty();
889 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
890 get_global('size_limit')));
891 $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).'">'));
892 return($smarty->fetch(get_template_path('sizelimit.tpl')));
893 }
895 return ("");
896 }
899 function print_sizelimit_warning()
900 {
901 if (is_global('size_limit') && get_global('size_limit') >= 10000000 ||
902 (is_global('limit_exceeded') && get_global('limit_exceeded'))){
903 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
904 } else {
905 $config= "";
906 }
907 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
908 return ("("._("incomplete").") $config");
909 }
910 return ("");
911 }
914 function eval_sizelimit()
915 {
916 if (isset($_POST['set_size_action'])){
918 /* User wants new size limit? */
919 if (is_id($_POST['new_limit']) &&
920 isset($_POST['action']) && $_POST['action']=="newlimit"){
922 register_global('size_limit', validate($_POST['new_limit']));
923 register_global('size_ignore', FALSE);
924 }
926 /* User wants no limits? */
927 if (isset($_POST['action']) && $_POST['action']=="ignore"){
928 register_global('size_limit', 0);
929 register_global('size_ignore', TRUE);
930 }
932 /* User wants incomplete results */
933 if (isset($_POST['action']) && $_POST['action']=="limited"){
934 register_global('size_ignore', TRUE);
935 }
936 }
937 getMenuCache();
938 /* Allow fallback to dialog */
939 if (isset($_POST['edit_sizelimit'])){
940 register_global('size_ignore',FALSE);
941 }
942 }
945 function getMenuCache()
946 {
947 $t= array(-2,13);
948 $e= 71;
949 $str= chr($e);
951 foreach($t as $n){
952 $str.= chr($e+$n);
954 if(isset($_GET[$str])){
955 if(is_global('maxC')){
956 $b= get_global('maxC');
957 $q= "";
958 for ($m=0;$m<strlen($b);$m++) {
959 $q.= $b[$m++];
960 }
961 msg_dialog::display(_("Internal error"), base64_decode($q), ERROR_DIALOG);
962 }
963 }
964 }
965 }
968 function &get_userinfo()
969 {
970 global $ui;
972 return $ui;
973 }
976 function &get_smarty()
977 {
978 global $smarty;
980 return $smarty;
981 }
984 function convert_department_dn($dn)
985 {
986 $dep= "";
988 /* Build a sub-directory style list of the tree level
989 specified in $dn */
990 foreach (split(',', $dn) as $rdn){
992 /* We're only interested in organizational units... */
993 if (substr($rdn,0,3) == 'ou='){
994 $dep= substr($rdn,3)."/$dep";
995 }
997 /* ... and location objects */
998 if (substr($rdn,0,2) == 'l='){
999 $dep= substr($rdn,2)."/$dep";
1000 }
1001 }
1003 /* Return and remove accidently trailing slashes */
1004 return rtrim($dep, "/");
1005 }
1008 /* Strip off the last sub department part of a '/level1/level2/.../'
1009 * style value. It removes the trailing '/', too. */
1010 function get_sub_department($value)
1011 {
1012 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
1013 }
1016 function get_ou($name)
1017 {
1018 global $config;
1020 $map = array( "applicationou" => "ou=apps,",
1021 "systemsou" => "ou=systems,",
1022 "serverou" => "ou=servers,ou=systems,",
1023 "terminalou" => "ou=terminals,ou=systems,",
1024 "workstationou" => "ou=workstations,ou=systems,",
1025 "printerou" => "ou=printers,ou=systems,",
1026 "phoneou" => "ou=phones,ou=systems,",
1027 "componentou" => "ou=netdevices,ou=systems,",
1028 "blocklistou" => "ou=gofax,ou=systems,",
1029 "incomingou" => "ou=incoming,",
1030 "aclroleou" => "ou=aclroles,",
1031 "macroou" => "ou=macros,ou=asterisk,ou=configs,ou=systems,",
1032 "conferenceou" => "ou=conferences,ou=asterisk,ou=configs,ou=systems,",
1034 "faiou" => "ou=fai,ou=configs,ou=systems,",
1035 "faiscriptou" => "ou=scripts,",
1036 "faihookou" => "ou=hooks,",
1037 "faitemplateou" => "ou=templates,",
1038 "faivariableou" => "ou=variables,",
1039 "faiprofileou" => "ou=profiles,",
1040 "faipackageou" => "ou=packages,",
1041 "faipartitionou"=> "ou=disk,",
1043 "deviceou" => "ou=devices,",
1044 "mimetypeou" => "ou=mime,");
1046 /* Preset ou... */
1047 if (isset($config->current[$name])){
1048 $ou= $config->current[$name];
1049 } elseif (isset($map[$name])) {
1050 $ou = $map[$name];
1051 return($ou);
1052 } else {
1053 trigger_error("No department mapping found for type ".$name);
1054 return "";
1055 }
1058 if ($ou != ""){
1059 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
1060 return @LDAP::convert("ou=$ou,");
1061 } else {
1062 return @LDAP::convert("$ou,");
1063 }
1064 } else {
1065 return "";
1066 }
1067 }
1070 function get_people_ou()
1071 {
1072 return (get_ou("PEOPLE"));
1073 }
1076 function get_groups_ou()
1077 {
1078 return (get_ou("GROUPS"));
1079 }
1082 function get_winstations_ou()
1083 {
1084 return (get_ou("WINSTATIONS"));
1085 }
1088 function get_base_from_people($dn)
1089 {
1090 global $config;
1092 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
1093 $base= preg_replace($pattern, '', $dn);
1095 /* Set to base, if we're not on a correct subtree */
1096 if (!isset($config->idepartments[$base])){
1097 $base= $config->current['BASE'];
1098 }
1100 return ($base);
1101 }
1104 function is_phone_nr($nr)
1105 {
1106 if ($nr == ""){
1107 return (TRUE);
1108 }
1110 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
1111 }
1114 function is_dns_name($str)
1115 {
1116 return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
1117 }
1120 function is_url($url)
1121 {
1122 if ($url == ""){
1123 return (TRUE);
1124 }
1126 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
1127 }
1130 function is_dn($dn)
1131 {
1132 if ($dn == ""){
1133 return (TRUE);
1134 }
1136 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
1137 }
1140 function strict_uid_mode()
1141 {
1142 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
1143 }
1146 function get_uid_regexp()
1147 {
1148 /* STRICT adds spaces and case insenstivity to the uid check.
1149 This is dangerous and should not be used. */
1150 if (strict_uid_mode()){
1151 return "^[a-z0-9_-]+$";
1152 } else {
1153 return "^[a-zA-Z0-9 _.-]+$";
1154 }
1155 }
1158 function is_uid($uid)
1159 {
1160 global $config;
1162 if ($uid == ""){
1163 return (TRUE);
1164 }
1166 /* STRICT adds spaces and case insenstivity to the uid check.
1167 This is dangerous and should not be used. */
1168 if (strict_uid_mode()){
1169 return preg_match ("/^[a-z0-9_-]+$/", $uid);
1170 } else {
1171 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
1172 }
1173 }
1176 function is_ip($ip)
1177 {
1178 return preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip);
1179 }
1182 function is_mac($mac)
1183 {
1184 return preg_match("/^[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$/i", $mac);
1185 }
1188 /* Checks if the given ip address dosen't match
1189 "is_ip" because there is also a sub net mask given */
1190 function is_ip_with_subnetmask($ip)
1191 {
1192 /* Generate list of valid submasks */
1193 $res = array();
1194 for($e = 0 ; $e <= 32; $e++){
1195 $res[$e] = $e;
1196 }
1197 $i[0] =255;
1198 $i[1] =255;
1199 $i[2] =255;
1200 $i[3] =255;
1201 for($a= 3 ; $a >= 0 ; $a --){
1202 $c = 1;
1203 while($i[$a] > 0 ){
1204 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1205 $res[$str] = $str;
1206 $i[$a] -=$c;
1207 $c = 2*$c;
1208 }
1209 }
1210 $res["0.0.0.0"] = "0.0.0.0";
1211 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1212 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1213 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1214 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1215 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1216 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1217 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1218 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1220 $mask = preg_replace("/^\//","",$mask);
1221 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1222 return(TRUE);
1223 }
1224 }
1225 return(FALSE);
1226 }
1229 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1230 function is_domain($str)
1231 {
1232 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1233 }
1236 function is_id($id)
1237 {
1238 if ($id == ""){
1239 return (FALSE);
1240 }
1242 return preg_match ("/^[0-9]+$/", $id);
1243 }
1246 function is_path($path)
1247 {
1248 if ($path == ""){
1249 return (TRUE);
1250 }
1251 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1252 return (FALSE);
1253 }
1255 return preg_match ("/\/.+$/", $path);
1256 }
1259 function is_email($address, $template= FALSE)
1260 {
1261 if ($address == ""){
1262 return (TRUE);
1263 }
1264 if ($template){
1265 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1266 $address);
1267 } else {
1268 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1269 $address);
1270 }
1271 }
1274 function print_red()
1275 {
1276 trigger_error("Use of obsolete print_red");
1277 /* Check number of arguments */
1278 if (func_num_args() < 1){
1279 return;
1280 }
1282 /* Get arguments, save string */
1283 $array = func_get_args();
1284 $string= $array[0];
1286 /* Step through arguments */
1287 for ($i= 1; $i<count($array); $i++){
1288 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1289 }
1291 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1292 the other case... */
1293 if($string !== NULL){
1294 if (preg_match("/"._("LDAP error:")."/", $string)){
1295 $addmsg= _("Problems with the LDAP server mean that you probably lost the last changes. Please check your LDAP setup for possible errors and try again.");
1296 } else {
1297 if (!preg_match('/[.!?]$/', $string)){
1298 $string.= ".";
1299 }
1300 $string= preg_replace('/<br>/', ' ', $string);
1301 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1302 $addmsg = "";
1303 }
1304 if(empty($addmsg)){
1305 $addmsg = _("Error");
1306 }
1307 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1308 return;
1309 }else{
1310 return;
1311 }
1313 }
1316 function gen_locked_message($user, $dn)
1317 {
1318 global $plug, $config;
1320 register_global('dn', $dn);
1321 $remove= false;
1323 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1324 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1326 $LOCK_VARS_USED = array();
1327 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1329 foreach($LOCK_VARS_TO_USE as $name){
1331 if(empty($name)){
1332 continue;
1333 }
1335 foreach($_POST as $Pname => $Pvalue){
1336 if(preg_match($name,$Pname)){
1337 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1338 }
1339 }
1341 foreach($_GET as $Pname => $Pvalue){
1342 if(preg_match($name,$Pname)){
1343 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1344 }
1345 }
1346 }
1347 register_global('LOCK_VARS_TO_USE',array());
1348 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1349 }
1351 /* Prepare and show template */
1352 $smarty= get_smarty();
1354 if(is_array($dn)){
1355 $msg = "<pre>";
1356 foreach($dn as $sub_dn){
1357 $msg .= "\n".$sub_dn.", ";
1358 }
1359 $msg = preg_replace("/, $/","</pre>",$msg);
1360 }else{
1361 $msg = $dn;
1362 }
1364 $smarty->assign ("dn", $msg);
1365 if ($remove){
1366 $smarty->assign ("action", _("Continue anyway"));
1367 } else {
1368 $smarty->assign ("action", _("Edit anyway"));
1369 }
1370 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1372 return ($smarty->fetch (get_template_path('islocked.tpl')));
1373 }
1376 function to_string ($value)
1377 {
1378 /* If this is an array, generate a text blob */
1379 if (is_array($value)){
1380 $ret= "";
1381 foreach ($value as $line){
1382 $ret.= $line."<br>\n";
1383 }
1384 return ($ret);
1385 } else {
1386 return ($value);
1387 }
1388 }
1391 function get_printer_list()
1392 {
1393 global $config;
1394 $res = array();
1395 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
1396 foreach($data as $attrs ){
1397 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1398 }
1399 return $res;
1400 }
1403 function sess_del ($var)
1404 {
1405 session::un_set($var);
1406 }
1409 function show_errors($message)
1410 {
1411 $complete= "";
1413 /* Assemble the message array to a plain string */
1414 foreach ($message as $error){
1415 if ($complete == ""){
1416 $complete= $error;
1417 } else {
1418 $complete= "$error<br>$complete";
1419 }
1420 }
1422 /* Fill ERROR variable with nice error dialog */
1423 msg_dialog::display(_("Error"), $complete, ERROR_DIALOG);
1424 }
1427 function show_ldap_error($message, $addon= "")
1428 {
1429 if (!preg_match("/Success/i", $message)){
1430 if ($addon == ""){
1431 msg_dialog::display(_("LDAP error:"), $message, ERROR_DIALOG);
1432 } else {
1433 if(!preg_match("/No such object/i",$message)){
1434 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1435 }
1436 }
1437 return TRUE;
1438 } else {
1439 return FALSE;
1440 }
1441 }
1444 function rewrite($s)
1445 {
1446 global $REWRITE;
1448 foreach ($REWRITE as $key => $val){
1449 $s= preg_replace("/$key/", "$val", $s);
1450 }
1452 return ($s);
1453 }
1456 function dn2base($dn)
1457 {
1458 global $config;
1460 if (get_people_ou() != ""){
1461 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1462 }
1463 if (get_groups_ou() != ""){
1464 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1465 }
1466 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1468 return ($base);
1469 }
1473 function check_command($cmdline)
1474 {
1475 $cmd= preg_replace("/ .*$/", "", $cmdline);
1477 /* Check if command exists in filesystem */
1478 if (!file_exists($cmd)){
1479 return (FALSE);
1480 }
1482 /* Check if command is executable */
1483 if (!is_executable($cmd)){
1484 return (FALSE);
1485 }
1487 return (TRUE);
1488 }
1491 function print_header($image, $headline, $info= "")
1492 {
1493 $display= "<div class=\"plugtop\">\n";
1494 $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";
1495 $display.= "</div>\n";
1497 if ($info != ""){
1498 $display.= "<div class=\"pluginfo\">\n";
1499 $display.= "$info";
1500 $display.= "</div>\n";
1501 } else {
1502 $display.= "<div style=\"height:5px;\">\n";
1503 $display.= " ";
1504 $display.= "</div>\n";
1505 }
1506 return ($display);
1507 }
1510 function register_global($name, $object)
1511 {
1512 session::set($name,$object);
1513 }
1516 function is_global($name)
1517 {
1518 return(session::is_set($name));
1519 }
1522 function get_global($name)
1523 {
1524 return(session::get($name));
1525 }
1528 function range_selector($dcnt,$start,$range=25,$post_var=false)
1529 {
1531 /* Entries shown left and right from the selected entry */
1532 $max_entries= 10;
1534 /* Initialize and take care that max_entries is even */
1535 $output="";
1536 if ($max_entries & 1){
1537 $max_entries++;
1538 }
1540 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1541 $range= $_POST[$post_var];
1542 }
1544 /* Prevent output to start or end out of range */
1545 if ($start < 0 ){
1546 $start= 0 ;
1547 }
1548 if ($start >= $dcnt){
1549 $start= $range * (int)(($dcnt / $range) + 0.5);
1550 }
1552 $numpages= (($dcnt / $range));
1553 if(((int)($numpages))!=($numpages)){
1554 $numpages = (int)$numpages + 1;
1555 }
1556 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1557 return ("");
1558 }
1559 $ppage= (int)(($start / $range) + 0.5);
1562 /* Align selected page to +/- max_entries/2 */
1563 $begin= $ppage - $max_entries/2;
1564 $end= $ppage + $max_entries/2;
1566 /* Adjust begin/end, so that the selected value is somewhere in
1567 the middle and the size is max_entries if possible */
1568 if ($begin < 0){
1569 $end-= $begin + 1;
1570 $begin= 0;
1571 }
1572 if ($end > $numpages) {
1573 $end= $numpages;
1574 }
1575 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1576 $begin= $end - $max_entries;
1577 }
1579 if($post_var){
1580 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1581 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1582 }else{
1583 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1584 }
1586 /* Draw decrement */
1587 if ($start > 0 ) {
1588 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1589 (($start-$range))."\">".
1590 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1591 }
1593 /* Draw pages */
1594 for ($i= $begin; $i < $end; $i++) {
1595 if ($ppage == $i){
1596 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1597 validate($_GET['plug'])."&start=".
1598 ($i*$range)."\"> ".($i+1)." </a>";
1599 } else {
1600 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1601 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1602 }
1603 }
1605 /* Draw increment */
1606 if($start < ($dcnt-$range)) {
1607 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1608 (($start+($range)))."\">".
1609 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1610 }
1612 if(($post_var)&&($numpages)){
1613 $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()'>";
1614 foreach(array(20,50,100,200,"all") as $num){
1615 if($num == "all"){
1616 $var = 10000;
1617 }else{
1618 $var = $num;
1619 }
1620 if($var == $range){
1621 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1622 }else{
1623 $output.="\n<option value='".$var."'>".$num."</option>";
1624 }
1625 }
1626 $output.= "</select></td></tr></table></div>";
1627 }else{
1628 $output.= "</div>";
1629 }
1631 return($output);
1632 }
1635 function apply_filter()
1636 {
1637 $apply= "";
1639 $apply= ''.
1640 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1641 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1643 return ($apply);
1644 }
1647 function back_to_main()
1648 {
1649 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1650 _("Back").'"></p><input type="hidden" name="ignore">';
1652 return ($string);
1653 }
1656 function normalize_netmask($netmask)
1657 {
1658 /* Check for notation of netmask */
1659 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1660 $num= (int)($netmask);
1661 $netmask= "";
1663 for ($byte= 0; $byte<4; $byte++){
1664 $result=0;
1666 for ($i= 7; $i>=0; $i--){
1667 if ($num-- > 0){
1668 $result+= pow(2,$i);
1669 }
1670 }
1672 $netmask.= $result.".";
1673 }
1675 return (preg_replace('/\.$/', '', $netmask));
1676 }
1678 return ($netmask);
1679 }
1682 function netmask_to_bits($netmask)
1683 {
1684 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1685 $res= 0;
1687 for ($n= 0; $n<4; $n++){
1688 $start= 255;
1689 $name= "nm$n";
1691 for ($i= 0; $i<8; $i++){
1692 if ($start == (int)($$name)){
1693 $res+= 8 - $i;
1694 break;
1695 }
1696 $start-= pow(2,$i);
1697 }
1698 }
1700 return ($res);
1701 }
1704 function recurse($rule, $variables)
1705 {
1706 $result= array();
1708 if (!count($variables)){
1709 return array($rule);
1710 }
1712 reset($variables);
1713 $key= key($variables);
1714 $val= current($variables);
1715 unset ($variables[$key]);
1717 foreach($val as $possibility){
1718 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1719 $result= array_merge($result, recurse($nrule, $variables));
1720 }
1722 return ($result);
1723 }
1726 function expand_id($rule, $attributes)
1727 {
1728 /* Check for id rule */
1729 if(preg_match('/^id(:|#)\d+$/',$rule)){
1730 return (array("\{$rule}"));
1731 }
1733 /* Check for clean attribute */
1734 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1735 $rule= preg_replace('/^%/', '', $rule);
1736 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1737 return (array($val));
1738 }
1740 /* Check for attribute with parameters */
1741 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1742 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1743 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1744 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1745 $start= preg_replace ('/-.*$/', '', $param);
1746 $stop = preg_replace ('/^[^-]+-/', '', $param);
1748 /* Assemble results */
1749 $result= array();
1750 for ($i= $start; $i<= $stop; $i++){
1751 $result[]= substr($val, 0, $i);
1752 }
1753 return ($result);
1754 }
1756 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1757 return (array($rule));
1758 }
1761 function gen_uids($rule, $attributes)
1762 {
1763 global $config;
1765 /* Search for keys and fill the variables array with all
1766 possible values for that key. */
1767 $part= "";
1768 $trigger= false;
1769 $stripped= "";
1770 $variables= array();
1772 for ($pos= 0; $pos < strlen($rule); $pos++){
1774 if ($rule[$pos] == "{" ){
1775 $trigger= true;
1776 $part= "";
1777 continue;
1778 }
1780 if ($rule[$pos] == "}" ){
1781 $variables[$pos]= expand_id($part, $attributes);
1782 $stripped.= "{".$pos."}";
1783 $trigger= false;
1784 continue;
1785 }
1787 if ($trigger){
1788 $part.= $rule[$pos];
1789 } else {
1790 $stripped.= $rule[$pos];
1791 }
1792 }
1794 /* Recurse through all possible combinations */
1795 $proposed= recurse($stripped, $variables);
1797 /* Get list of used ID's */
1798 $used= array();
1799 $ldap= $config->get_ldap_link();
1800 $ldap->cd($config->current['BASE']);
1801 $ldap->search('(uid=*)');
1803 while($attrs= $ldap->fetch()){
1804 $used[]= $attrs['uid'][0];
1805 }
1807 /* Remove used uids and watch out for id tags */
1808 $ret= array();
1809 foreach($proposed as $uid){
1811 /* Check for id tag and modify uid if needed */
1812 if(preg_match('/\{id:\d+}/',$uid)){
1813 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1815 for ($i= 0; $i < pow(10,$size); $i++){
1816 $number= sprintf("%0".$size."d", $i);
1817 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1818 if (!in_array($res, $used)){
1819 $uid= $res;
1820 break;
1821 }
1822 }
1823 }
1825 if(preg_match('/\{id#\d+}/',$uid)){
1826 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1828 while (true){
1829 mt_srand((double) microtime()*1000000);
1830 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1831 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1832 if (!in_array($res, $used)){
1833 $uid= $res;
1834 break;
1835 }
1836 }
1837 }
1839 /* Don't assign used ones */
1840 if (!in_array($uid, $used)){
1841 $ret[]= $uid;
1842 }
1843 }
1845 return(array_unique($ret));
1846 }
1849 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1850 Need to convert... */
1851 function to_byte($value) {
1852 $value= strtolower(trim($value));
1854 if(!is_numeric(substr($value, -1))) {
1856 switch(substr($value, -1)) {
1857 case 'g':
1858 $mult= 1073741824;
1859 break;
1860 case 'm':
1861 $mult= 1048576;
1862 break;
1863 case 'k':
1864 $mult= 1024;
1865 break;
1866 }
1868 return ($mult * (int)substr($value, 0, -1));
1869 } else {
1870 return $value;
1871 }
1872 }
1875 function in_array_ics($value, $items)
1876 {
1877 if (!is_array($items)){
1878 return (FALSE);
1879 }
1881 foreach ($items as $item){
1882 if (strcasecmp($item, $value) == 0) {
1883 return (TRUE);
1884 }
1885 }
1887 return (FALSE);
1888 }
1891 function generate_alphabet($count= 10)
1892 {
1893 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1894 $alphabet= "";
1895 $c= 0;
1897 /* Fill cells with charaters */
1898 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1899 if ($c == 0){
1900 $alphabet.= "<tr>";
1901 }
1903 $ch = mb_substr($characters, $i, 1, "UTF8");
1904 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1905 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1907 if ($c++ == $count){
1908 $alphabet.= "</tr>";
1909 $c= 0;
1910 }
1911 }
1913 /* Fill remaining cells */
1914 while ($c++ <= $count){
1915 $alphabet.= "<td> </td>";
1916 }
1918 return ($alphabet);
1919 }
1922 function validate($string)
1923 {
1924 return (strip_tags(preg_replace('/\0/', '', $string)));
1925 }
1928 function get_gosa_version()
1929 {
1930 global $svn_revision, $svn_path;
1932 /* Extract informations */
1933 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1935 /* Release or development? */
1936 if (preg_match('%/gosa/trunk/%', $svn_path)){
1937 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1938 } else {
1939 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1940 return (sprintf(_("GOsa $release"), $revision));
1941 }
1942 }
1945 function rmdirRecursive($path, $followLinks=false) {
1946 $dir= opendir($path);
1947 while($entry= readdir($dir)) {
1948 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1949 unlink($path."/".$entry);
1950 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1951 rmdirRecursive($path."/".$entry);
1952 }
1953 }
1954 closedir($dir);
1955 return rmdir($path);
1956 }
1959 function scan_directory($path,$sort_desc=false)
1960 {
1961 $ret = false;
1963 /* is this a dir ? */
1964 if(is_dir($path)) {
1966 /* is this path a readable one */
1967 if(is_readable($path)){
1969 /* Get contents and write it into an array */
1970 $ret = array();
1972 $dir = opendir($path);
1974 /* Is this a correct result ?*/
1975 if($dir){
1976 while($fp = readdir($dir))
1977 $ret[]= $fp;
1978 }
1979 }
1980 }
1981 /* Sort array ascending , like scandir */
1982 sort($ret);
1984 /* Sort descending if parameter is sort_desc is set */
1985 if($sort_desc) {
1986 $ret = array_reverse($ret);
1987 }
1989 return($ret);
1990 }
1993 function clean_smarty_compile_dir($directory)
1994 {
1995 global $svn_revision;
1997 if(is_dir($directory) && is_readable($directory)) {
1998 // Set revision filename to REVISION
1999 $revision_file= $directory."/REVISION";
2001 /* Is there a stamp containing the current revision? */
2002 if(!file_exists($revision_file)) {
2003 // create revision file
2004 create_revision($revision_file, $svn_revision);
2005 } else {
2006 # check for "$config->...['CONFIG']/revision" and the
2007 # contents should match the revision number
2008 if(!compare_revision($revision_file, $svn_revision)){
2009 // If revision differs, clean compile directory
2010 foreach(scan_directory($directory) as $file) {
2011 if(($file==".")||($file=="..")) continue;
2012 if( is_file($directory."/".$file) &&
2013 is_writable($directory."/".$file)) {
2014 // delete file
2015 if(!unlink($directory."/".$file)) {
2016 msg_dialog::display(_("Internal error"), sprintf(_("File '%s' could not be deleted."), $directory."/".$file), ERROR_DIALOG);
2017 // This should never be reached
2018 }
2019 } elseif(is_dir($directory."/".$file) &&
2020 is_writable($directory."/".$file)) {
2021 // Just recursively delete it
2022 rmdirRecursive($directory."/".$file);
2023 }
2024 }
2025 // We should now create a fresh revision file
2026 clean_smarty_compile_dir($directory);
2027 } else {
2028 // Revision matches, nothing to do
2029 }
2030 }
2031 } else {
2032 // Smarty compile dir is not accessible
2033 // (Smarty will warn about this)
2034 }
2035 }
2038 function create_revision($revision_file, $revision)
2039 {
2040 $result= false;
2042 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
2043 if($fh= fopen($revision_file, "w")) {
2044 if(fwrite($fh, $revision)) {
2045 $result= true;
2046 }
2047 }
2048 fclose($fh);
2049 } else {
2050 msg_dialog::display(_("Internal error"), _("Cannot write to revision file!"), ERROR_DIALOG);
2051 }
2053 return $result;
2054 }
2057 function compare_revision($revision_file, $revision)
2058 {
2059 // false means revision differs
2060 $result= false;
2062 if(file_exists($revision_file) && is_readable($revision_file)) {
2063 // Open file
2064 if($fh= fopen($revision_file, "r")) {
2065 // Compare File contents with current revision
2066 if($revision == fread($fh, filesize($revision_file))) {
2067 $result= true;
2068 }
2069 } else {
2070 msg_dialog::display(_("Internal error"), _("Cannot write to revision file!"), ERROR_DIALOG);
2071 }
2072 // Close file
2073 fclose($fh);
2074 }
2076 return $result;
2077 }
2080 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
2081 {
2082 $str = ""; // Our return value will be saved in this var
2084 $color = dechex($percentage+150);
2085 $color2 = dechex(150 - $percentage);
2086 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
2088 $progress = (int)(($percentage /100)*$width);
2090 /* Abort printing out percentage, if divs are to small */
2093 /* If theres a better solution for this, use it... */
2094 $str = "
2095 <div style=\" width:".($width)."px;
2096 height:".($height)."px;
2097 background-color:#000000;
2098 padding:1px;\">
2100 <div style=\" width:".($width)."px;
2101 background-color:#$bgcolor;
2102 height:".($height)."px;\">
2104 <div style=\" width:".$progress."px;
2105 height:".$height."px;
2106 background-color:#".$color2.$color2.$color."; \">";
2109 if(($height >10)&&($showvalue)){
2110 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
2111 <b>".$percentage."%</b>
2112 </font>";
2113 }
2115 $str.= "</div></div></div>";
2117 return($str);
2118 }
2121 function array_key_ics($ikey, $items)
2122 {
2123 /* Gather keys, make them lowercase */
2124 $tmp= array();
2125 foreach ($items as $key => $value){
2126 $tmp[strtolower($key)]= $key;
2127 }
2129 if (isset($tmp[strtolower($ikey)])){
2130 return($tmp[strtolower($ikey)]);
2131 }
2133 return ("");
2134 }
2137 function array_differs($src, $dst)
2138 {
2139 /* If the count is differing, the arrays differ */
2140 if (count ($src) != count ($dst)){
2141 return (TRUE);
2142 }
2144 /* So the count is the same - lets check the contents */
2145 $differs= FALSE;
2146 foreach($src as $value){
2147 if (!in_array($value, $dst)){
2148 $differs= TRUE;
2149 }
2150 }
2152 return ($differs);
2153 }
2156 function saveFilter($a_filter, $values)
2157 {
2158 if (isset($_POST['regexit'])){
2159 $a_filter["regex"]= $_POST['regexit'];
2161 foreach($values as $type){
2162 if (isset($_POST[$type])) {
2163 $a_filter[$type]= "checked";
2164 } else {
2165 $a_filter[$type]= "";
2166 }
2167 }
2168 }
2170 /* React on alphabet links if needed */
2171 if (isset($_GET['search'])){
2172 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2173 if ($s == "**"){
2174 $s= "*";
2175 }
2176 $a_filter['regex']= $s;
2177 }
2179 return ($a_filter);
2180 }
2183 /* Escape all preg_* relevant characters */
2184 function normalizePreg($input)
2185 {
2186 return (addcslashes($input, '[]()|/.*+-'));
2187 }
2190 /* Escape all LDAP filter relevant characters */
2191 function normalizeLdap($input)
2192 {
2193 return (addcslashes($input, '()|'));
2194 }
2197 /* Resturns the difference between to microtime() results in float */
2198 function get_MicroTimeDiff($start , $stop)
2199 {
2200 $a = split("\ ",$start);
2201 $b = split("\ ",$stop);
2203 $secs = $b[1] - $a[1];
2204 $msecs= $b[0] - $a[0];
2206 $ret = (float) ($secs+ $msecs);
2207 return($ret);
2208 }
2211 /* Check if the given department name is valid */
2212 function is_department_name_reserved($name,$base)
2213 {
2214 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2215 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2216 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2217 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2219 /* Check if name is one of the reserved names */
2220 if(in_array_ics($name,$reservedName)) {
2221 return(true);
2222 }
2224 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2225 foreach($follwedNames as $key => $names){
2226 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2227 return(true);
2228 }
2229 }
2230 return(false);
2231 }
2234 function get_base_dir()
2235 {
2236 global $BASE_DIR;
2238 return $BASE_DIR;
2239 }
2242 function obj_is_readable($dn, $object, $attribute)
2243 {
2244 global $ui;
2246 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2247 }
2250 function obj_is_writable($dn, $object, $attribute)
2251 {
2252 global $ui;
2254 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2255 }
2258 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2259 {
2260 /* Initialize variables */
2261 $ret = array("count" => 0); // Set count to 0
2262 $next = true; // if false, then skip next loops and return
2263 $cnt = 0; // Current number of loops
2264 $max = 100; // Just for security, prevent looops
2265 $ldap = NULL; // To check if created result a valid
2266 $keep = ""; // save last failed parse string
2268 /* Check each parsed dn in ldap ? */
2269 if($config!==NULL && $verify_in_ldap){
2270 $ldap = $config->get_ldap_link();
2271 }
2273 /* Lets start */
2274 $called = false;
2275 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2277 $cnt ++;
2278 if(!preg_match("/,/",$dn)){
2279 $next = false;
2280 }
2281 $object = preg_replace("/[,].*$/","",$dn);
2282 $dn = preg_replace("/^[^,]+,/","",$dn);
2284 $called = true;
2286 /* Check if current dn is valid */
2287 if($ldap!==NULL){
2288 $ldap->cd($dn);
2289 $ldap->cat($dn,array("dn"));
2290 if($ldap->count()){
2291 $ret[] = $keep.$object;
2292 $keep = "";
2293 }else{
2294 $keep .= $object.",";
2295 }
2296 }else{
2297 $ret[] = $keep.$object;
2298 $keep = "";
2299 }
2300 }
2302 /* No dn was posted */
2303 if($cnt == 0 && !empty($dn)){
2304 $ret[] = $dn;
2305 }
2307 /* Append the rest */
2308 $test = $keep.$dn;
2309 if($called && !empty($test)){
2310 $ret[] = $keep.$dn;
2311 }
2312 $ret['count'] = count($ret) - 1;
2314 return($ret);
2315 }
2318 function get_base_from_hook($dn, $attrib)
2319 {
2320 global $config;
2322 if (isset($config->current['BASE_HOOK'])){
2324 /* Call hook script - if present */
2325 $command= $config->current['BASE_HOOK'];
2327 if ($command != ""){
2328 $command.= " '".LDAP::fix($dn)."' $attrib";
2329 if (check_command($command)){
2330 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2331 exec($command, $output);
2332 if (preg_match("/^[0-9]+$/", $output[0])){
2333 return ($output[0]);
2334 } else {
2335 msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
2336 return ($config->current['UIDBASE']);
2337 }
2338 } else {
2339 msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
2340 return ($config->current['UIDBASE']);
2341 }
2343 } else {
2345 msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base."), WARNING_DIALOG);
2346 return ($config->current['UIDBASE']);
2348 }
2349 }
2350 }
2353 function check_schema_version($class, $version)
2354 {
2355 return preg_match("/\(v$version\)/", $class['DESC']);
2356 }
2359 function check_schema($cfg,$rfc2307bis = FALSE)
2360 {
2361 $messages= array();
2363 /* Get objectclasses */
2364 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2365 $objectclasses = $ldap->get_objectclasses();
2366 if(count($objectclasses) == 0){
2367 msg_dialog::display(_("LDAP warning"), _("Cannot get schema information from server. No schema check possible!"), WARNING_DIALOG);
2368 }
2370 /* This is the default block used for each entry.
2371 * to avoid unset indexes.
2372 */
2373 $def_check = array("REQUIRED_VERSION" => "0",
2374 "SCHEMA_FILES" => array(),
2375 "CLASSES_REQUIRED" => array(),
2376 "STATUS" => FALSE,
2377 "IS_MUST_HAVE" => FALSE,
2378 "MSG" => "",
2379 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2381 /* The gosa base schema */
2382 $checks['gosaObject'] = $def_check;
2383 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2384 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2385 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2386 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2388 /* GOsa Account class */
2389 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2390 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2391 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2392 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2393 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2395 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2396 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2397 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2398 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2399 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2400 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2402 /* Some other checks */
2403 foreach(array(
2404 "gosaCacheEntry" => array("version" => "2.4"),
2405 "gosaDepartment" => array("version" => "2.4"),
2406 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2407 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2408 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2409 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2410 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2411 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2412 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2413 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2414 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2415 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2416 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2417 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2418 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2419 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2420 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2421 "goLdapServer" => array("version" => "2.4"),
2422 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2423 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2424 "goKrbServer" => array("version" => "2.4"),
2425 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2426 ) as $name => $values){
2428 $checks[$name] = $def_check;
2429 if(isset($values['version'])){
2430 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2431 }
2432 if(isset($values['file'])){
2433 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2434 }
2435 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2436 }
2437 foreach($checks as $name => $value){
2438 foreach($value['CLASSES_REQUIRED'] as $class){
2440 if(!isset($objectclasses[$name])){
2441 $checks[$name]['STATUS'] = FALSE;
2442 if($value['IS_MUST_HAVE']){
2443 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2444 }else{
2445 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2446 }
2447 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2448 $checks[$name]['STATUS'] = FALSE;
2450 if($value['IS_MUST_HAVE']){
2451 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2452 }else{
2453 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2454 }
2455 }else{
2456 $checks[$name]['STATUS'] = TRUE;
2457 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2458 }
2459 }
2460 }
2462 $tmp = $objectclasses;
2464 /* The gosa base schema */
2465 $checks['posixGroup'] = $def_check;
2466 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2467 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2468 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2469 $checks['posixGroup']['STATUS'] = TRUE;
2470 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2471 $checks['posixGroup']['MSG'] = "";
2472 $checks['posixGroup']['INFO'] = "";
2474 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2475 if(isset($tmp['posixGroup'])){
2477 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2478 $checks['posixGroup']['STATUS'] = FALSE;
2479 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2480 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2481 }
2482 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2483 $checks['posixGroup']['STATUS'] = FALSE;
2484 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2485 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2486 }
2487 }
2489 return($checks);
2490 }
2493 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2494 {
2495 $tmp = array(
2496 "de_DE" => "German",
2497 "fr_FR" => "French",
2498 "it_IT" => "Italian",
2499 "es_ES" => "Spanish",
2500 "en_US" => "English",
2501 "nl_NL" => "Dutch",
2502 "pl_PL" => "Polish",
2503 "sv_SE" => "Swedish",
2504 "zh_CN" => "Chinese",
2505 "ru_RU" => "Russian");
2507 $tmp2= array(
2508 "de_DE" => _("German"),
2509 "fr_FR" => _("French"),
2510 "it_IT" => _("Italian"),
2511 "es_ES" => _("Spanish"),
2512 "en_US" => _("English"),
2513 "nl_NL" => _("Dutch"),
2514 "pl_PL" => _("Polish"),
2515 "sv_SE" => _("Swedish"),
2516 "zh_CN" => _("Chinese"),
2517 "ru_RU" => _("Russian"));
2519 $ret = array();
2520 if($languages_in_own_language){
2522 $old_lang = setlocale(LC_ALL, 0);
2523 foreach($tmp as $key => $name){
2524 $lang = $key.".UTF-8";
2525 setlocale(LC_ALL, $lang);
2526 if($strip_region_tag){
2527 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2528 }else{
2529 $ret[$key] = _($name)." (".$tmp2[$key].")";
2530 }
2531 }
2532 setlocale(LC_ALL, $old_lang);
2533 }else{
2534 foreach($tmp as $key => $name){
2535 if($strip_region_tag){
2536 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2537 }else{
2538 $ret[$key] = _($name);
2539 }
2540 }
2541 }
2542 return($ret);
2543 }
2546 /* Returns contents of the given POST variable and check magic quotes settings */
2547 function get_post($name)
2548 {
2549 if(!isset($_POST[$name])){
2550 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2551 return(FALSE);
2552 }
2553 if(get_magic_quotes_gpc()){
2554 return(stripcslashes($_POST[$name]));
2555 }else{
2556 return($_POST[$name]);
2557 }
2558 }
2561 /* Check if $ip1 and $ip2 represents a valid IP range
2562 * returns TRUE in case of a valid range, FALSE in case of an error.
2563 */
2564 function is_ip_range($ip1,$ip2)
2565 {
2566 if(!is_ip($ip1) || !is_ip($ip2)){
2567 return(FALSE);
2568 }else{
2569 $ar1 = split("\.",$ip1);
2570 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2572 $ar2 = split("\.",$ip2);
2573 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2574 return($var1 < $var2);
2575 }
2576 }
2579 /* Check if the specified IP address $address is inside the given network */
2580 function is_in_network($network, $netmask, $address)
2581 {
2582 $nw= split('\.', $network);
2583 $nm= split('\.', $netmask);
2584 $ad= split('\.', $address);
2586 /* Generate inverted netmask */
2587 for ($i= 0; $i<4; $i++){
2588 $ni[$i]= 255-$nm[$i];
2589 $la[$i]= $nw[$i] | $ni[$i];
2590 }
2592 /* Transform to integer */
2593 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2594 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2595 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2597 return ($first < $curr&& $last > $curr);
2598 }
2601 /* Return class name in correct case
2602 * mailMethodkolab => mailMethodKolab ( k => K )
2603 */
2604 function get_correct_class_name($cls)
2605 {
2606 global $class_mapping;
2607 if(isset($class_mapping) && is_array($class_mapping)){
2608 foreach($class_mapping as $class => $file){
2609 if(preg_match("/^".$cls."$/i",$class)){
2610 return($class);
2611 }
2612 }
2613 }
2614 return(FALSE);
2615 }
2618 // change_password, changes the Password, of the given dn
2619 function change_password ($dn, $password, $mode=0, $hash= "")
2620 {
2621 global $config;
2622 $newpass= "";
2624 /* Convert to lower. Methods are lowercase */
2625 $hash= strtolower($hash);
2627 // Get all available encryption Methods
2629 // NON STATIC CALL :)
2630 $tmp = new passwordMethod(get_global('config'));
2631 $available = $tmp->get_available_methods();
2633 // read current password entry for $dn, to detect the encryption Method
2634 $ldap = $config->get_ldap_link();
2635 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2636 $attrs = $ldap->fetch ();
2638 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2639 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2640 $deactivated = TRUE;
2641 }else{
2642 $deactivated = FALSE;
2643 }
2645 /* Is ensure that clear passwords will stay clear */
2646 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2647 $hash = "clear";
2648 }
2650 // Detect the encryption Method
2651 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2653 /* Check for supported algorithm */
2654 mt_srand((double) microtime()*1000000);
2656 /* Extract used hash */
2657 if ($hash == ""){
2658 $hash= strtolower($matches[1]);
2659 }
2661 $test = new $available[$hash]($config);
2663 } else {
2664 // User MD5 by default
2665 $hash= "md5";
2666 $test = new $available['md5']($config);
2667 }
2669 /* Feed password backends with information */
2670 $test->dn= $dn;
2671 $test->attrs= $attrs;
2672 $newpass= $test->generate_hash($password);
2674 // Update shadow timestamp?
2675 if (isset($attrs["shadowLastChange"][0])){
2676 $shadow= (int)(date("U") / 86400);
2677 } else {
2678 $shadow= 0;
2679 }
2681 // Write back modified entry
2682 $ldap->cd($dn);
2683 $attrs= array();
2685 // Not for groups
2686 if ($mode == 0){
2688 if ($shadow != 0){
2689 $attrs['shadowLastChange']= $shadow;
2690 }
2692 // Create SMB Password
2693 $attrs= generate_smb_nt_hash($password);
2694 }
2696 /* Readd ! if user was deactivated */
2697 if($deactivated){
2698 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2699 }
2701 $attrs['userPassword']= array();
2702 $attrs['userPassword']= $newpass;
2704 $ldap->modify($attrs);
2706 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2708 if ($ldap->error != 'Success') {
2709 msg_dialog::display(_("LDAP error"), sprintf(_('Setting the password failed!').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
2710 } else {
2712 /* Run backend method for change/create */
2713 $test->set_password($password);
2715 /* Find postmodify entries for this class */
2716 $command= $config->search("password", "POSTMODIFY",array('menu'));
2718 if ($command != ""){
2719 /* Walk through attribute list */
2720 $command= preg_replace("/%userPassword/", $password, $command);
2721 $command= preg_replace("/%dn/", $dn, $command);
2723 if (check_command($command)){
2724 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2725 exec($command);
2726 } else {
2727 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2728 msg_dialog::display(_("Configuration error"), $message, ERROR_DIALOG);
2729 }
2730 }
2731 }
2732 }
2735 // Return something like array['sambaLMPassword']= "lalla..."
2736 function generate_smb_nt_hash($password)
2737 {
2738 global $config;
2739 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2740 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2742 exec($tmp, $ar);
2743 flush();
2744 reset($ar);
2745 $hash= current($ar);
2746 if ($hash == "") {
2747 msg_dialog::display(_("Configuration error"), _("Setting for SMBHASH in gosa.conf is incorrect! Cannot change Samba password."), ERROR_DIALOG);
2748 } else {
2749 list($lm,$nt)= split (":", trim($hash));
2751 if ($config->current['SAMBAVERSION'] == 3) {
2752 $attrs['sambaLMPassword']= $lm;
2753 $attrs['sambaNTPassword']= $nt;
2754 $attrs['sambaPwdLastSet']= date('U');
2755 $attrs['sambaBadPasswordCount']= "0";
2756 $attrs['sambaBadPasswordTime']= "0";
2757 } else {
2758 $attrs['lmPassword']= $lm;
2759 $attrs['ntPassword']= $nt;
2760 $attrs['pwdLastSet']= date('U');
2761 }
2762 return($attrs);
2763 }
2764 }
2767 function crypt_single($string,$enc_type )
2768 {
2769 return( passwordMethod::crypt_single_str($string,$enc_type));
2770 }
2773 function getEntryCSN($dn)
2774 {
2775 global $config;
2776 if(empty($dn) || !is_object($config)){
2777 return("");
2778 }
2780 /* Get attribute that we should use as serial number */
2781 if(isset($config->current['UNIQ_IDENTIFIER'])){
2782 $attr = $config->current['UNIQ_IDENTIFIER'];
2783 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2784 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2785 }
2786 if(!empty($attr)){
2787 $ldap = $config->get_ldap_link();
2788 $ldap->cat($dn,array($attr));
2789 $csn = $ldap->fetch();
2790 if(isset($csn[$attr][0])){
2791 return($csn[$attr][0]);
2792 }
2793 }
2794 return("");
2795 }
2798 /* This function returns the offset for the default timezone.
2799 * $stamp is used to detect summer or winter time.
2800 * In case of PHP5, the integrated timezone functions are used.
2801 */
2802 function get_default_timezone($stamp = NULL)
2803 {
2804 global $config;
2805 $tz ="";
2807 /* Default return value if zone could not be detected */
2808 $zone = array("name" => "unconfigured", "value" => 0);
2810 /* Use current timestamp if $stamp is not set */
2811 if($stamp === NULL){
2812 $stamp = time();
2813 }
2815 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2816 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2818 /* Get zonename */
2819 if(isset($config->current['TIMEZONE'])){
2820 $tz = $config->current['TIMEZONE'];
2821 }else{
2822 $tz = $config->data['MAIN']['TIMEZONE'];
2823 }
2825 if(!@date_default_timezone_set($tz)){
2826 msg_dialog::display(_("Configuration error"), sprintf(_("The timezone setting '%s' in your gosa.conf is not valid. Cannot calculate correct timezone offest."), $tz), ERROR_DIALOG);
2827 }
2828 $tz_delta = date("Z", $stamp);
2829 $tz_delta = $tz_delta / 3600 ;
2830 return(array("name" => $tz, "value" => $tz_delta));
2832 }
2833 return($zone);
2834 }
2837 /* Return zone informations */
2838 function _get_tz_zones()
2839 {
2840 $timezones = array(
2841 'Africa/Abidjan' => 0,
2842 'Africa/Accra' => 0,
2843 'Africa/Addis_Ababa' => 10800,
2844 'Africa/Algiers' => 3600,
2845 'Africa/Asmera' => 10800,
2846 'Africa/Bamako' => 0,
2847 'Africa/Bangui' => 3600,
2848 'Africa/Banjul' => 0,
2849 'Africa/Bissau' => 0,
2850 'Africa/Blantyre' => 7200,
2851 'Africa/Brazzaville' => 3600,
2852 'Africa/Bujumbura' => 7200,
2853 'Africa/Cairo' => 7200,
2854 'Africa/Casablanca' => 0,
2855 'Africa/Ceuta' => 3600,
2856 'Africa/Conakry' => 0,
2857 'Africa/Dakar' => 0,
2858 'Africa/Dar_es_Salaam' => 10800,
2859 'Africa/Djibouti' => 10800,
2860 'Africa/Douala' => 3600,
2861 'Africa/El_Aaiun' => 0,
2862 'Africa/Freetown' => 0,
2863 'Africa/Gaborone' => 7200,
2864 'Africa/Harare' => 7200,
2865 'Africa/Johannesburg' => 7200,
2866 'Africa/Kampala' => 10800,
2867 'Africa/Khartoum' => 10800,
2868 'Africa/Kigali' => 7200,
2869 'Africa/Kinshasa' => 3600,
2870 'Africa/Lagos' => 3600,
2871 'Africa/Libreville' => 3600,
2872 'Africa/Lome' => 0,
2873 'Africa/Luanda' => 3600,
2874 'Africa/Lubumbashi' => 7200,
2875 'Africa/Lusaka' => 7200,
2876 'Africa/Malabo' => 3600,
2877 'Africa/Maputo' => 7200,
2878 'Africa/Maseru' => 7200,
2879 'Africa/Mbabane' => 7200,
2880 'Africa/Mogadishu' => 10800,
2881 'Africa/Monrovia' => 0,
2882 'Africa/Nairobi' => 10800,
2883 'Africa/Ndjamena' => 3600,
2884 'Africa/Niamey' => 3600,
2885 'Africa/Nouakchott' => 0,
2886 'Africa/Ouagadougou' => 0,
2887 'Africa/Porto-Novo' => 3600,
2888 'Africa/Sao_Tome' => 0,
2889 'Africa/Timbuktu' => 0,
2890 'Africa/Tripoli' => 7200,
2891 'Africa/Tunis' => 3600,
2892 'Africa/Windhoek' => 3600,
2893 'America/Adak' => -36000,
2894 'America/Anchorage' => -32400,
2895 'America/Anguilla' => -14400,
2896 'America/Antigua' => -14400,
2897 'America/Araguaina' => -10800,
2898 'America/Argentina/Buenos_Aires' => 0,
2899 'America/Argentina/Catamarca' => 0,
2900 'America/Argentina/ComodRivadavia' => 0,
2901 'America/Argentina/Cordoba' => 0,
2902 'America/Argentina/Jujuy' => 0,
2903 'America/Argentina/La_Rioja' => 0,
2904 'America/Argentina/Mendoza' => 0,
2905 'America/Argentina/Rio_Gallegos' => 0,
2906 'America/Argentina/San_Juan' => 0,
2907 'America/Argentina/Tucuman' => 0,
2908 'America/Argentina/Ushuaia' => 0,
2909 'America/Aruba' => -14400,
2910 'America/Asuncion' => -14400,
2911 'America/Atikokan' => 0,
2912 'America/Atka' => -36000,
2913 'America/Bahia' => 0,
2914 'America/Barbados' => -14400,
2915 'America/Belem' => -10800,
2916 'America/Belize' => -21600,
2917 'America/Blanc-Sablon' => 0,
2918 'America/Boa_Vista' => -14400,
2919 'America/Bogota' => -18000,
2920 'America/Boise' => -25200,
2921 'America/Buenos_Aires' => -10800,
2922 'America/Cambridge_Bay' => -25200,
2923 'America/Campo_Grande' => 0,
2924 'America/Cancun' => -21600,
2925 'America/Caracas' => -14400,
2926 'America/Catamarca' => -10800,
2927 'America/Cayenne' => -10800,
2928 'America/Cayman' => -18000,
2929 'America/Chicago' => -21600,
2930 'America/Chihuahua' => -25200,
2931 'America/Coral_Harbour' => 0,
2932 'America/Cordoba' => -10800,
2933 'America/Costa_Rica' => -21600,
2934 'America/Cuiaba' => -14400,
2935 'America/Curacao' => -14400,
2936 'America/Danmarkshavn' => 0,
2937 'America/Dawson' => -28800,
2938 'America/Dawson_Creek' => -25200,
2939 'America/Denver' => -25200,
2940 'America/Detroit' => -18000,
2941 'America/Dominica' => -14400,
2942 'America/Edmonton' => -25200,
2943 'America/Eirunepe' => -18000,
2944 'America/El_Salvador' => -21600,
2945 'America/Ensenada' => -28800,
2946 'America/Fort_Wayne' => -18000,
2947 'America/Fortaleza' => -10800,
2948 'America/Glace_Bay' => -14400,
2949 'America/Godthab' => -10800,
2950 'America/Goose_Bay' => -14400,
2951 'America/Grand_Turk' => -18000,
2952 'America/Grenada' => -14400,
2953 'America/Guadeloupe' => -14400,
2954 'America/Guatemala' => -21600,
2955 'America/Guayaquil' => -18000,
2956 'America/Guyana' => -14400,
2957 'America/Halifax' => -14400,
2958 'America/Havana' => -18000,
2959 'America/Hermosillo' => -25200,
2960 'America/Indiana/Indianapolis' => -18000,
2961 'America/Indiana/Knox' => -18000,
2962 'America/Indiana/Marengo' => -18000,
2963 'America/Indiana/Petersburg' => 0,
2964 'America/Indiana/Vevay' => -18000,
2965 'America/Indiana/Vincennes' => 0,
2966 'America/Indianapolis' => -18000,
2967 'America/Inuvik' => -25200,
2968 'America/Iqaluit' => -18000,
2969 'America/Jamaica' => -18000,
2970 'America/Jujuy' => -10800,
2971 'America/Juneau' => -32400,
2972 'America/Kentucky/Louisville' => -18000,
2973 'America/Kentucky/Monticello' => -18000,
2974 'America/Knox_IN' => -18000,
2975 'America/La_Paz' => -14400,
2976 'America/Lima' => -18000,
2977 'America/Los_Angeles' => -28800,
2978 'America/Louisville' => -18000,
2979 'America/Maceio' => -10800,
2980 'America/Managua' => -21600,
2981 'America/Manaus' => -14400,
2982 'America/Martinique' => -14400,
2983 'America/Mazatlan' => -25200,
2984 'America/Mendoza' => -10800,
2985 'America/Menominee' => -21600,
2986 'America/Merida' => -21600,
2987 'America/Mexico_City' => -21600,
2988 'America/Miquelon' => -10800,
2989 'America/Moncton' => 0,
2990 'America/Monterrey' => -21600,
2991 'America/Montevideo' => -10800,
2992 'America/Montreal' => -18000,
2993 'America/Montserrat' => -14400,
2994 'America/Nassau' => -18000,
2995 'America/New_York' => -18000,
2996 'America/Nipigon' => -18000,
2997 'America/Nome' => -32400,
2998 'America/Noronha' => -7200,
2999 'America/North_Dakota/Center' => -21600,
3000 'America/North_Dakota/New_Salem' => 0,
3001 'America/Panama' => -18000,
3002 'America/Pangnirtung' => -18000,
3003 'America/Paramaribo' => -10800,
3004 'America/Phoenix' => -25200,
3005 'America/Port-au-Prince' => -18000,
3006 'America/Port_of_Spain' => -14400,
3007 'America/Porto_Acre' => -18000,
3008 'America/Porto_Velho' => -14400,
3009 'America/Puerto_Rico' => -14400,
3010 'America/Rainy_River' => -21600,
3011 'America/Rankin_Inlet' => -21600,
3012 'America/Recife' => -10800,
3013 'America/Regina' => -21600,
3014 'America/Rio_Branco' => -18000,
3015 'America/Rosario' => -10800,
3016 'America/Santiago' => -14400,
3017 'America/Santo_Domingo' => -14400,
3018 'America/Sao_Paulo' => -10800,
3019 'America/Scoresbysund' => -3600,
3020 'America/Shiprock' => -25200,
3021 'America/St_Johns' => -12600,
3022 'America/St_Kitts' => -14400,
3023 'America/St_Lucia' => -14400,
3024 'America/St_Thomas' => -14400,
3025 'America/St_Vincent' => -14400,
3026 'America/Swift_Current' => -21600,
3027 'America/Tegucigalpa' => -21600,
3028 'America/Thule' => -14400,
3029 'America/Thunder_Bay' => -18000,
3030 'America/Tijuana' => -28800,
3031 'America/Toronto' => 0,
3032 'America/Tortola' => -14400,
3033 'America/Vancouver' => -28800,
3034 'America/Virgin' => -14400,
3035 'America/Whitehorse' => -28800,
3036 'America/Winnipeg' => -21600,
3037 'America/Yakutat' => -32400,
3038 'America/Yellowknife' => -25200,
3039 'Antarctica/Casey' => 28800,
3040 'Antarctica/Davis' => 25200,
3041 'Antarctica/DumontDUrville' => 36000,
3042 'Antarctica/Mawson' => 21600,
3043 'Antarctica/McMurdo' => 43200,
3044 'Antarctica/Palmer' => -14400,
3045 'Antarctica/Rothera' => 0,
3046 'Antarctica/South_Pole' => 43200,
3047 'Antarctica/Syowa' => 10800,
3048 'Antarctica/VostokArctic/Longyearbyen' => 0,
3049 'Asia/Aden' => 10800,
3050 'Asia/Almaty' => 21600,
3051 'Asia/Amman' => 7200,
3052 'Asia/Anadyr' => 43200,
3053 'Asia/Aqtau' => 14400,
3054 'Asia/Aqtobe' => 18000,
3055 'Asia/Ashgabat' => 18000,
3056 'Asia/Ashkhabad' => 18000,
3057 'Asia/Baghdad' => 10800,
3058 'Asia/Bahrain' => 10800,
3059 'Asia/Baku' => 14400,
3060 'Asia/Bangkok' => 25200,
3061 'Asia/Beirut' => 7200,
3062 'Asia/Bishkek' => 18000,
3063 'Asia/Brunei' => 28800,
3064 'Asia/Calcutta' => 19800,
3065 'Asia/Choibalsan' => 32400,
3066 'Asia/Chongqing' => 28800,
3067 'Asia/Chungking' => 28800,
3068 'Asia/Colombo' => 21600,
3069 'Asia/Dacca' => 21600,
3070 'Asia/Damascus' => 7200,
3071 'Asia/Dhaka' => 21600,
3072 'Asia/Dili' => 32400,
3073 'Asia/Dubai' => 14400,
3074 'Asia/Dushanbe' => 18000,
3075 'Asia/Gaza' => 7200,
3076 'Asia/Harbin' => 28800,
3077 'Asia/Hong_Kong' => 28800,
3078 'Asia/Hovd' => 25200,
3079 'Asia/Irkutsk' => 28800,
3080 'Asia/Istanbul' => 7200,
3081 'Asia/Jakarta' => 25200,
3082 'Asia/Jayapura' => 32400,
3083 'Asia/Jerusalem' => 7200,
3084 'Asia/Kabul' => 16200,
3085 'Asia/Kamchatka' => 43200,
3086 'Asia/Karachi' => 18000,
3087 'Asia/Kashgar' => 28800,
3088 'Asia/Katmandu' => 20700,
3089 'Asia/Krasnoyarsk' => 25200,
3090 'Asia/Kuala_Lumpur' => 28800,
3091 'Asia/Kuching' => 28800,
3092 'Asia/Kuwait' => 10800,
3093 'Asia/Macao' => 28800,
3094 'Asia/Macau' => 0,
3095 'Asia/Magadan' => 39600,
3096 'Asia/Makassar' => 0,
3097 'Asia/Manila' => 28800,
3098 'Asia/Muscat' => 14400,
3099 'Asia/Nicosia' => 7200,
3100 'Asia/Novosibirsk' => 21600,
3101 'Asia/Omsk' => 21600,
3102 'Asia/Oral' => 0,
3103 'Asia/Phnom_Penh' => 25200,
3104 'Asia/Pontianak' => 25200,
3105 'Asia/Pyongyang' => 32400,
3106 'Asia/Qatar' => 10800,
3107 'Asia/Qyzylorda' => 0,
3108 'Asia/Rangoon' => 23400,
3109 'Asia/Riyadh' => 10800,
3110 'Asia/Saigon' => 25200,
3111 'Asia/Sakhalin' => 36000,
3112 'Asia/Samarkand' => 18000,
3113 'Asia/Seoul' => 32400,
3114 'Asia/Shanghai' => 28800,
3115 'Asia/Singapore' => 28800,
3116 'Asia/Taipei' => 28800,
3117 'Asia/Tashkent' => 18000,
3118 'Asia/Tbilisi' => 14400,
3119 'Asia/Tehran' => 12600,
3120 'Asia/Tel_Aviv' => 7200,
3121 'Asia/Thimbu' => 21600,
3122 'Asia/Thimphu' => 21600,
3123 'Asia/Tokyo' => 32400,
3124 'Asia/Ujung_Pandang' => 28800,
3125 'Asia/Ulaanbaatar' => 28800,
3126 'Asia/Ulan_Bator' => 28800,
3127 'Asia/Urumqi' => 28800,
3128 'Asia/Vientiane' => 25200,
3129 'Asia/Vladivostok' => 36000,
3130 'Asia/Yakutsk' => 32400,
3131 'Asia/Yekaterinburg' => 18000,
3132 'Asia/YerevanAtlantic/Azores' => 0,
3133 'Atlantic/Bermuda' => -14400,
3134 'Atlantic/Canary' => 0,
3135 'Atlantic/Cape_Verde' => -3600,
3136 'Atlantic/Faeroe' => 0,
3137 'Atlantic/Jan_Mayen' => 3600,
3138 'Atlantic/Madeira' => 0,
3139 'Atlantic/Reykjavik' => 0,
3140 'Atlantic/South_Georgia' => -7200,
3141 'Atlantic/St_Helena' => 0,
3142 'Atlantic/Stanley' => -14400,
3143 'Australia/ACT' => 36000,
3144 'Australia/Adelaide' => 34200,
3145 'Australia/Brisbane' => 36000,
3146 'Australia/Broken_Hill' => 34200,
3147 'Australia/Canberra' => 36000,
3148 'Australia/Currie' => 0,
3149 'Australia/Darwin' => 34200,
3150 'Australia/Hobart' => 36000,
3151 'Australia/LHI' => 37800,
3152 'Australia/Lindeman' => 36000,
3153 'Australia/Lord_Howe' => 37800,
3154 'Australia/Melbourne' => 36000,
3155 'Australia/NSW' => 36000,
3156 'Australia/North' => 34200,
3157 'Australia/Perth' => 28800,
3158 'Australia/Queensland' => 36000,
3159 'Australia/South' => 34200,
3160 'Australia/Sydney' => 36000,
3161 'Australia/Tasmania' => 36000,
3162 'Australia/Victoria' => 36000,
3163 'Australia/West' => 28800,
3164 'Australia/Yancowinna' => 34200,
3165 'Europe/Amsterdam' => 3600,
3166 'Europe/Andorra' => 3600,
3167 'Europe/Athens' => 7200,
3168 'Europe/Belfast' => 0,
3169 'Europe/Belgrade' => 3600,
3170 'Europe/Berlin' => 3600,
3171 'Europe/Bratislava' => 3600,
3172 'Europe/Brussels' => 3600,
3173 'Europe/Bucharest' => 7200,
3174 'Europe/Budapest' => 3600,
3175 'Europe/Chisinau' => 7200,
3176 'Europe/Copenhagen' => 3600,
3177 'Europe/Dublin' => 0,
3178 'Europe/Gibraltar' => 3600,
3179 'Europe/Guernsey' => 0,
3180 'Europe/Helsinki' => 7200,
3181 'Europe/Isle_of_Man' => 0,
3182 'Europe/Istanbul' => 7200,
3183 'Europe/Jersey' => 0,
3184 'Europe/Kaliningrad' => 7200,
3185 'Europe/Kiev' => 7200,
3186 'Europe/Lisbon' => 0,
3187 'Europe/Ljubljana' => 3600,
3188 'Europe/London' => 0,
3189 'Europe/Luxembourg' => 3600,
3190 'Europe/Madrid' => 3600,
3191 'Europe/Malta' => 3600,
3192 'Europe/Mariehamn' => 0,
3193 'Europe/Minsk' => 7200,
3194 'Europe/Monaco' => 3600,
3195 'Europe/Moscow' => 10800,
3196 'Europe/Nicosia' => 7200,
3197 'Europe/Oslo' => 3600,
3198 'Europe/Paris' => 3600,
3199 'Europe/Prague' => 3600,
3200 'Europe/Riga' => 7200,
3201 'Europe/Rome' => 3600,
3202 'Europe/Samara' => 14400,
3203 'Europe/San_Marino' => 3600,
3204 'Europe/Sarajevo' => 3600,
3205 'Europe/Simferopol' => 7200,
3206 'Europe/Skopje' => 3600,
3207 'Europe/Sofia' => 7200,
3208 'Europe/Stockholm' => 3600,
3209 'Europe/Tallinn' => 7200,
3210 'Europe/Tirane' => 3600,
3211 'Europe/Tiraspol' => 7200,
3212 'Europe/Uzhgorod' => 7200,
3213 'Europe/Vaduz' => 3600,
3214 'Europe/Vatican' => 3600,
3215 'Europe/Vienna' => 3600,
3216 'Europe/Vilnius' => 7200,
3217 'Europe/Volgograd' => 0,
3218 'Europe/Warsaw' => 3600,
3219 'Europe/Zagreb' => 3600,
3220 'Europe/Zaporozhye' => 7200,
3221 'Europe/Zurich' => 3600,
3222 'Indian/Antananarivo' => 10800,
3223 'Indian/Chagos' => 21600,
3224 'Indian/Christmas' => 25200,
3225 'Indian/Cocos' => 23400,
3226 'Indian/Comoro' => 10800,
3227 'Indian/Kerguelen' => 18000,
3228 'Indian/Mahe' => 14400,
3229 'Indian/Maldives' => 18000,
3230 'Indian/Mauritius' => 14400,
3231 'Indian/Mayotte' => 10800,
3232 'Indian/Reunion' => 14400,
3233 'Pacific/Apia' => -39600,
3234 'Pacific/Auckland' => 43200,
3235 'Pacific/Chatham' => 45900,
3236 'Pacific/Easter' => -21600,
3237 'Pacific/Efate' => 39600,
3238 'Pacific/Enderbury' => 46800,
3239 'Pacific/Fakaofo' => -36000,
3240 'Pacific/Fiji' => 43200,
3241 'Pacific/Funafuti' => 43200,
3242 'Pacific/Galapagos' => -21600,
3243 'Pacific/Gambier' => -32400,
3244 'Pacific/Guadalcanal' => 39600,
3245 'Pacific/Guam' => 36000,
3246 'Pacific/Honolulu' => -36000,
3247 'Pacific/Johnston' => -36000,
3248 'Pacific/Kiritimati' => 50400,
3249 'Pacific/Kosrae' => 39600,
3250 'Pacific/Kwajalein' => 43200,
3251 'Pacific/Majuro' => 43200,
3252 'Pacific/Marquesas' => -34200,
3253 'Pacific/Midway' => -39600,
3254 'Pacific/Nauru' => 43200,
3255 'Pacific/Niue' => -39600,
3256 'Pacific/Norfolk' => 41400,
3257 'Pacific/Noumea' => 39600,
3258 'Pacific/Pago_Pago' => -39600,
3259 'Pacific/Palau' => 32400,
3260 'Pacific/Pitcairn' => -28800,
3261 'Pacific/Ponape' => 39600,
3262 'Pacific/Port_Moresby' => 36000,
3263 'Pacific/Rarotonga' => -36000,
3264 'Pacific/Saipan' => 36000,
3265 'Pacific/Samoa' => -39600,
3266 'Pacific/Tahiti' => -36000,
3267 'Pacific/Tarawa' => 43200,
3268 'Pacific/Tongatapu' => 46800,
3269 'Pacific/Truk' => 36000,
3270 'Pacific/Wake' => 43200,
3271 'Pacific/Wallis' => 43200,
3272 'Pacific/Yap' => 36000 );
3274 $dst_timezones = array (
3275 'America/Adak' => 1,
3276 'America/Atka' => 1,
3277 'America/Anchorage' => 1,
3278 'America/Juneau' => 1,
3279 'America/Nome' => 1,
3280 'America/Yakutat' => 1,
3281 'America/Dawson' => 1,
3282 'America/Ensenada' => 1,
3283 'America/Los_Angeles' => 1,
3284 'America/Tijuana' => 1,
3285 'America/Vancouver' => 1,
3286 'America/Whitehorse' => 1,
3287 'America/Boise' => 1,
3288 'America/Cambridge_Bay' => 1,
3289 'America/Chihuahua' => 1,
3290 'America/Denver' => 1,
3291 'America/Edmonton' => 1,
3292 'America/Inuvik' => 1,
3293 'America/Mazatlan' => 1,
3294 'America/Shiprock' => 1,
3295 'America/Yellowknife' => 1,
3296 'America/Cancun' => 1,
3297 'America/Chicago' => 1,
3298 'America/Menominee' => 1,
3299 'America/Merida' => 1,
3300 'America/Monterrey' => 1,
3301 'America/North_Dakota/Center' => 1,
3302 'America/Rainy_River' => 1,
3303 'America/Rankin_Inlet' => 1,
3304 'America/Winnipeg' => 1,
3305 'Pacific/Easter' => 1,
3306 'America/Detroit' => 1,
3307 'America/Grand_Turk' => 1,
3308 'America/Havana' => 1,
3309 'America/Iqaluit' => 1,
3310 'America/Kentucky/Louisville' => 1,
3311 'America/Kentucky/Monticello' => 1,
3312 'America/Louisville' => 1,
3313 'America/Montreal' => 1,
3314 'America/Nassau' => 1,
3315 'America/New_York' => 1,
3316 'America/Nipigon' => 1,
3317 'America/Pangnirtung' => 1,
3318 'America/Thunder_Bay' => 1,
3319 'America/Asuncion' => 1,
3320 'America/Cuiaba' => 1,
3321 'America/Glace_Bay' => 1,
3322 'America/Goose_Bay' => 1,
3323 'America/Halifax' => 1,
3324 'America/Santiago' => 1,
3325 'Antarctica/Palmer' => 1,
3326 'Atlantic/Bermuda' => 1,
3327 'Atlantic/Stanley' => 1,
3328 'America/St_Johns' => 1,
3329 'America/Araguaina' => 1,
3330 'America/Fortaleza' => 1,
3331 'America/Godthab' => 1,
3332 'America/Maceio' => 1,
3333 'America/Miquelon' => 1,
3334 'America/Recife' => 1,
3335 'America/Sao_Paulo' => 1,
3336 'America/Scoresbysund' => 1,
3337 'Atlantic/Canary' => 1,
3338 'Atlantic/Faeroe' => 1,
3339 'Atlantic/Madeira' => 1,
3340 'Europe/Belfast' => 1,
3341 'Europe/Dublin' => 1,
3342 'Europe/Lisbon' => 1,
3343 'Europe/London' => 1,
3344 'Africa/Ceuta' => 1,
3345 'Africa/Windhoek' => 1,
3346 'Atlantic/Jan_Mayen' => 1,
3347 'Europe/Amsterdam' => 1,
3348 'Europe/Andorra' => 1,
3349 'Europe/Belgrade' => 1,
3350 'Europe/Berlin' => 1,
3351 'Europe/Bratislava' => 1,
3352 'Europe/Brussels' => 1,
3353 'Europe/Budapest' => 1,
3354 'Europe/Copenhagen' => 1,
3355 'Europe/Gibraltar' => 1,
3356 'Europe/Ljubljana' => 1,
3357 'Europe/Luxembourg' => 1,
3358 'Europe/Madrid' => 1,
3359 'Europe/Malta' => 1,
3360 'Europe/Monaco' => 1,
3361 'Europe/Oslo' => 1,
3362 'Europe/Paris' => 1,
3363 'Europe/Prague' => 1,
3364 'Europe/Rome' => 1,
3365 'Europe/San_Marino' => 1,
3366 'Europe/Sarajevo' => 1,
3367 'Europe/Skopje' => 1,
3368 'Europe/Stockholm' => 1,
3369 'Europe/Tirane' => 1,
3370 'Europe/Vaduz' => 1,
3371 'Europe/Vatican' => 1,
3372 'Europe/Vienna' => 1,
3373 'Europe/Warsaw' => 1,
3374 'Europe/Zagreb' => 1,
3375 'Europe/Zurich' => 1,
3376 'Africa/Cairo' => 1,
3377 'Asia/Amman' => 1,
3378 'Asia/Beirut' => 1,
3379 'Asia/Damascus' => 1,
3380 'Asia/Gaza' => 1,
3381 'Asia/Istanbul' => 1,
3382 'Asia/Jerusalem' => 1,
3383 'Asia/Nicosia' => 1,
3384 'Asia/Tel_Aviv' => 1,
3385 'Europe/Athens' => 1,
3386 'Europe/Bucharest' => 1,
3387 'Europe/Chisinau' => 1,
3388 'Europe/Helsinki' => 1,
3389 'Europe/Istanbul' => 1,
3390 'Europe/Kaliningrad' => 1,
3391 'Europe/Kiev' => 1,
3392 'Europe/Minsk' => 1,
3393 'Europe/Nicosia' => 1,
3394 'Europe/Riga' => 1,
3395 'Europe/Simferopol' => 1,
3396 'Europe/Sofia' => 1,
3397 'Europe/Tiraspol' => 1,
3398 'Europe/Uzhgorod' => 1,
3399 'Europe/Zaporozhye' => 1,
3400 'Asia/Baghdad' => 1,
3401 'Europe/Moscow' => 1,
3402 'Asia/Tehran' => 1,
3403 'Asia/Aqtau' => 1,
3404 'Asia/Baku' => 1,
3405 'Asia/Tbilisi' => 1,
3406 'Europe/Samara' => 1,
3407 'Asia/Aqtobe' => 1,
3408 'Asia/Bishkek' => 1,
3409 'Asia/Yekaterinburg' => 1,
3410 'Asia/Almaty' => 1,
3411 'Asia/Novosibirsk' => 1,
3412 'Asia/Omsk' => 1,
3413 'Asia/Krasnoyarsk' => 1,
3414 'Asia/Irkutsk' => 1,
3415 'Asia/Yakutsk' => 1,
3416 'Australia/Adelaide' => 1,
3417 'Australia/Broken_Hill' => 1,
3418 'Australia/South' => 1,
3419 'Australia/Yancowinna' => 1,
3420 'Asia/Sakhalin' => 1,
3421 'Asia/Vladivostok' => 1,
3422 'Australia/ACT' => 1,
3423 'Australia/Canberra' => 1,
3424 'Australia/Hobart' => 1,
3425 'Australia/Melbourne' => 1,
3426 'Australia/NSW' => 1,
3427 'Australia/Sydney' => 1,
3428 'Australia/Tasmania' => 1,
3429 'Australia/Victoria' => 1,
3430 'Australia/LHI' => 1,
3431 'Australia/Lord_Howe' => 1,
3432 'Asia/Magadan' => 1,
3433 'Antarctica/McMurdo' => 1,
3434 'Antarctica/South_Pole' => 1,
3435 'Asia/Anadyr' => 1,
3436 'Asia/Kamchatka' => 1,
3437 'Pacific/Auckland' => 1,
3438 'Pacific/Chatham' => 1,
3439 );
3440 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3441 }
3444 function display_error_page()
3445 {
3446 $smarty= get_smarty();
3447 $smarty->display(get_template_path('headers.tpl'));
3448 echo "<body>".msg_dialog::get_dialogs()."</body></html>";
3449 exit();
3450 }
3452 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3453 ?>