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