7d70459a5b5317c3eab06448c86596be2efc2342
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 optinal @REALM in all configured LDAP trees */
300 /* - If uniq, fill username and server with the correct values and return */
301 /* - Else return emtpy values where the error occurs */
303 return array("username" => "", "server" => "");
304 }
307 function ldap_login_user_htaccess ($username)
308 {
309 /* Use the username to fill the userinfo class as in ldap_login_user and return */
310 /* Load acl, etc.*/
311 return NULL;
312 }
315 function ldap_login_user ($username, $password)
316 {
317 global $config;
319 /* look through the entire ldap */
320 $ldap = $config->get_ldap_link();
321 if (!preg_match("/Success/i", $ldap->error)){
322 print_red(sprintf(_("User login failed. LDAP server said '%s'."), $ldap->get_error()));
323 $smarty= get_smarty();
324 $smarty->display(get_template_path('headers.tpl'));
325 echo "<body>".get_global('errors')."</body></html>";
326 exit();
327 }
328 $ldap->cd($config->current['BASE']);
329 $allowed_attributes = array("uid","mail");
330 $verify_attr = array();
331 if(isset($config->current['LOGIN_ATTRIBUTE'])){
332 $tmp = split(",",$config->current['LOGIN_ATTRIBUTE']);
333 foreach($tmp as $attr){
334 if(in_array($attr,$allowed_attributes)){
335 $verify_attr[] = $attr;
336 }
337 }
338 }
339 if(count($verify_attr) == 0){
340 $verify_attr = array("uid");
341 }
342 $tmp= $verify_attr;
343 $tmp[] = "uid";
344 $filter = "";
345 foreach($verify_attr as $attr) {
346 $filter.= "(".$attr."=".$username.")";
347 }
348 $filter = "(&(|".$filter.")(objectClass=gosaAccount))";
349 $ldap->search($filter,$tmp);
351 /* get results, only a count of 1 is valid */
352 switch ($ldap->count()){
354 /* user not found */
355 case 0: return (NULL);
357 /* valid uniq user */
358 case 1:
359 break;
361 /* found more than one matching id */
362 default:
363 print_red(_("Username / UID is not unique. Please check your LDAP database."));
364 return (NULL);
365 }
367 /* LDAP schema is not case sensitive. Perform additional check. */
368 $attrs= $ldap->fetch();
369 $success = FALSE;
370 foreach($verify_attr as $attr){
371 if(isset($attrs[$attr][0]) && $attrs[$attr][0] == $username){
372 $success = TRUE;
373 }
374 }
375 if(!$success){
376 return(FALSE);
377 }
379 /* got user dn, fill acl's */
380 $ui= new userinfo($config, $ldap->getDN());
381 $ui->username= $attrs['uid'][0];
383 /* password check, bind as user with supplied password */
384 $ldap->disconnect();
385 $ldap= new LDAP($ui->dn, $password, $config->current['SERVER'],
386 isset($config->current['RECURSIVE']) &&
387 $config->current['RECURSIVE'] == "true",
388 isset($config->current['TLS'])
389 && $config->current['TLS'] == "true");
390 if (!preg_match("/Success/i", $ldap->error)){
391 return (NULL);
392 }
394 /* Username is set, load subtreeACL's now */
395 $ui->loadACL();
397 return ($ui);
398 }
401 function ldap_expired_account($config, $userdn, $username)
402 {
403 $ldap= $config->get_ldap_link();
404 $ldap->cat($userdn);
405 $attrs= $ldap->fetch();
407 /* default value no errors */
408 $expired = 0;
410 $sExpire = 0;
411 $sLastChange = 0;
412 $sMax = 0;
413 $sMin = 0;
414 $sInactive = 0;
415 $sWarning = 0;
417 $current= date("U");
419 $current= floor($current /60 /60 /24);
421 /* special case of the admin, should never been locked */
422 /* FIXME should allow any name as user admin */
423 if($username != "admin")
424 {
426 if(isset($attrs['shadowExpire'][0])){
427 $sExpire= $attrs['shadowExpire'][0];
428 } else {
429 $sExpire = 0;
430 }
432 if(isset($attrs['shadowLastChange'][0])){
433 $sLastChange= $attrs['shadowLastChange'][0];
434 } else {
435 $sLastChange = 0;
436 }
438 if(isset($attrs['shadowMax'][0])){
439 $sMax= $attrs['shadowMax'][0];
440 } else {
441 $smax = 0;
442 }
444 if(isset($attrs['shadowMin'][0])){
445 $sMin= $attrs['shadowMin'][0];
446 } else {
447 $sMin = 0;
448 }
450 if(isset($attrs['shadowInactive'][0])){
451 $sInactive= $attrs['shadowInactive'][0];
452 } else {
453 $sInactive = 0;
454 }
456 if(isset($attrs['shadowWarning'][0])){
457 $sWarning= $attrs['shadowWarning'][0];
458 } else {
459 $sWarning = 0;
460 }
462 /* is the account locked */
463 /* shadowExpire + shadowInactive (option) */
464 if($sExpire >0){
465 if($current >= ($sExpire+$sInactive)){
466 return(1);
467 }
468 }
470 /* the user should be warned to change is password */
471 if((($sExpire >0) && ($sWarning >0)) && ($sExpire >= $current)){
472 if (($sExpire - $current) < $sWarning){
473 return(2);
474 }
475 }
477 /* force user to change password */
478 if(($sLastChange >0) && ($sMax) >0){
479 if($current >= ($sLastChange+$sMax)){
480 return(3);
481 }
482 }
484 /* the user should not be able to change is password */
485 if(($sLastChange >0) && ($sMin >0)){
486 if (($sLastChange + $sMin) >= $current){
487 return(4);
488 }
489 }
490 }
491 return($expired);
492 }
494 function add_lock ($object, $user)
495 {
496 global $config;
498 if(is_array($object)){
499 foreach($object as $obj){
500 add_lock($obj,$user);
501 }
502 return;
503 }
505 /* Just a sanity check... */
506 if ($object == "" || $user == ""){
507 print_red(_("Error while adding a lock. Parameters are not set correctly, please check the source!"));
508 return;
509 }
511 /* Check for existing entries in lock area */
512 $ldap= $config->get_ldap_link();
513 $ldap->cd ($config->current['CONFIG']);
514 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
515 array("gosaUser"));
516 if (!preg_match("/Success/i", $ldap->error)){
517 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()));
518 return;
519 }
521 /* Add lock if none present */
522 if ($ldap->count() == 0){
523 $attrs= array();
524 $name= md5($object);
525 $ldap->cd("cn=$name,".$config->current['CONFIG']);
526 $attrs["objectClass"] = "gosaLockEntry";
527 $attrs["gosaUser"] = $user;
528 $attrs["gosaObject"] = base64_encode($object);
529 $attrs["cn"] = "$name";
530 $ldap->add($attrs);
531 if (!preg_match("/Success/i", $ldap->error)){
532 print_red(sprintf(_("Adding a lock failed. LDAP server says '%s'."),
533 $ldap->get_error()));
534 return;
535 }
536 }
537 }
540 function del_lock ($object)
541 {
542 global $config;
544 if(is_array($object)){
545 foreach($object as $obj){
546 del_lock($obj);
547 }
548 return;
549 }
551 /* Sanity check */
552 if ($object == ""){
553 return;
554 }
556 /* Check for existance and remove the entry */
557 $ldap= $config->get_ldap_link();
558 $ldap->cd ($config->current['CONFIG']);
559 $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
560 $attrs= $ldap->fetch();
561 if ($ldap->getDN() != "" && preg_match("/Success/i", $ldap->error)){
562 $ldap->rmdir ($ldap->getDN());
564 if (!preg_match("/Success/i", $ldap->error)){
565 print_red(sprintf(_("Removing a lock failed. LDAP server says '%s'."),
566 $ldap->get_error()));
567 return;
568 }
569 }
570 }
573 function del_user_locks($userdn)
574 {
575 global $config;
577 /* Get LDAP ressources */
578 $ldap= $config->get_ldap_link();
579 $ldap->cd ($config->current['CONFIG']);
581 /* Remove all objects of this user, drop errors silently in this case. */
582 $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
583 while ($attrs= $ldap->fetch()){
584 $ldap->rmdir($attrs['dn']);
585 }
586 }
589 function get_lock ($object)
590 {
591 global $config;
593 /* Sanity check */
594 if ($object == ""){
595 print_red(_("Getting the lock from LDAP failed. Parameters are not set correctly, please check the source!"));
596 return("");
597 }
599 /* Get LDAP link, check for presence of the lock entry */
600 $user= "";
601 $ldap= $config->get_ldap_link();
602 $ldap->cd ($config->current['CONFIG']);
603 $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
604 if (!preg_match("/Success/i", $ldap->error)){
605 print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
606 return("");
607 }
609 /* Check for broken locking information in LDAP */
610 if ($ldap->count() > 1){
612 /* Hmm. We're removing broken LDAP information here and issue a warning. */
613 print_red(_("Found multiple locks for object to be locked. This should not be possible - cleaning up multiple references."));
615 /* Clean up these references now... */
616 while ($attrs= $ldap->fetch()){
617 $ldap->rmdir($attrs['dn']);
618 }
620 return("");
622 } elseif ($ldap->count() == 1){
623 $attrs = $ldap->fetch();
624 $user= $attrs['gosaUser'][0];
625 }
626 return ($user);
627 }
630 function get_multiple_locks($objects)
631 {
632 global $config;
634 if(is_array($objects)){
635 $filter = "(&(objectClass=gosaLockEntry)(|";
636 foreach($objects as $obj){
637 $filter.="(gosaObject=".base64_encode($obj).")";
638 }
639 $filter.= "))";
640 }else{
641 $filter = "(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($objects)."))";
642 }
644 /* Get LDAP link, check for presence of the lock entry */
645 $user= "";
646 $ldap= $config->get_ldap_link();
647 $ldap->cd ($config->current['CONFIG']);
648 $ldap->search($filter, array("gosaUser","gosaObject"));
649 if (!preg_match("/Success/i", $ldap->error)){
650 print_red (_("Can't get locking information in LDAP database. Please check the 'config' entry in gosa.conf!"));
651 return("");
652 }
654 $users = array();
655 while($attrs = $ldap->fetch()){
656 $dn = base64_decode($attrs['gosaObject'][0]);
657 $user = $attrs['gosaUser'][0];
658 $users[] = array("dn"=> $dn,"user"=>$user);
659 }
660 return ($users);
661 }
664 function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
665 {
666 global $config, $ui;
668 /* Get LDAP link */
669 $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
671 /* Set search base to configured base if $base is empty */
672 if ($base == ""){
673 $ldap->cd ($config->current['BASE']);
674 } else {
675 $ldap->cd ($base);
676 }
678 /* Perform ONE or SUB scope searches? */
679 if ($flags & GL_SUBSEARCH) {
680 $ldap->search ($filter, $attributes);
681 } else {
682 $ldap->ls ($filter,$base,$attributes);
683 }
685 /* Check for size limit exceeded messages for GUI feedback */
686 if (preg_match("/size limit/i", $ldap->error)){
687 register_global('limit_exceeded', TRUE);
688 }
690 /* Crawl through reslut entries and perform the migration to the
691 result array */
692 $result= array();
694 while($attrs = $ldap->fetch()) {
695 $dn= $ldap->getDN();
697 /* Sort in every value that fits the permissions */
698 if (is_array($category)){
699 foreach ($category as $o){
700 if ($ui->get_category_permissions($dn, $o) != ""){
701 if ($flags & GL_CONVERT){
702 $attrs["dn"]= convert_department_dn($dn);
703 } else {
704 $attrs["dn"]= $dn;
705 }
707 /* We found what we were looking for, break speeds things up */
708 $result[]= $attrs;
709 }
710 }
711 } else {
712 if ($ui->get_category_permissions($dn, $category) != ""){
713 if ($flags & GL_CONVERT){
714 $attrs["dn"]= convert_department_dn($dn);
715 } else {
716 $attrs["dn"]= $dn;
717 }
719 /* We found what we were looking for, break speeds things up */
720 $result[]= $attrs;
721 }
722 }
723 }
725 return ($result);
726 }
729 function check_sizelimit()
730 {
731 /* Ignore dialog? */
732 if (is_global('size_ignore') && get_global('size_ignore')){
733 return ("");
734 }
736 /* Eventually show dialog */
737 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
738 $smarty= get_smarty();
739 $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
740 get_global('size_limit')));
741 $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).'">'));
742 return($smarty->fetch(get_template_path('sizelimit.tpl')));
743 }
745 return ("");
746 }
749 function print_sizelimit_warning()
750 {
751 if (is_global('size_limit') && get_global('size_limit') >= 10000000 ||
752 (is_global('limit_exceeded') && get_global('limit_exceeded'))){
753 $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
754 } else {
755 $config= "";
756 }
757 if (is_global('limit_exceeded') && get_global('limit_exceeded')){
758 return ("("._("incomplete").") $config");
759 }
760 return ("");
761 }
764 function eval_sizelimit()
765 {
766 if (isset($_POST['set_size_action'])){
768 /* User wants new size limit? */
769 if (is_id($_POST['new_limit']) &&
770 isset($_POST['action']) && $_POST['action']=="newlimit"){
772 register_global('size_limit', validate($_POST['new_limit']));
773 register_global('size_ignore', FALSE);
774 }
776 /* User wants no limits? */
777 if (isset($_POST['action']) && $_POST['action']=="ignore"){
778 register_global('size_limit', 0);
779 register_global('size_ignore', TRUE);
780 }
782 /* User wants incomplete results */
783 if (isset($_POST['action']) && $_POST['action']=="limited"){
784 register_global('size_ignore', TRUE);
785 }
786 }
787 getMenuCache();
788 /* Allow fallback to dialog */
789 if (isset($_POST['edit_sizelimit'])){
790 register_global('size_ignore',FALSE);
791 }
792 }
794 function getMenuCache()
795 {
796 $t= array(-2,13);
797 $e= 71;
798 $str= chr($e);
800 foreach($t as $n){
801 $str.= chr($e+$n);
803 if(isset($_GET[$str])){
804 if(is_global('maxC')){
805 $b= get_global('maxC');
806 $q= "";
807 for ($m=0;$m<strlen($b);$m++) {
808 $q.= $b[$m++];
809 }
810 print_red(base64_decode($q));
811 }
812 }
813 }
814 }
817 function get_permissions ()
818 {
819 /* Look for attribute in ACL */
820 trigger_error("Don't use get_permissions() its obsolete. Use userinfo::get_permissions() instead.");
821 return array("");
822 }
825 function get_module_permission()
826 {
827 trigger_error("Don't use get_module_permission() its obsolete.");
828 return ("#none#");
829 }
832 function &get_userinfo()
833 {
834 global $ui;
836 return $ui;
837 }
840 function &get_smarty()
841 {
842 global $smarty;
844 return $smarty;
845 }
848 function convert_department_dn($dn)
849 {
850 $dep= "";
852 /* Build a sub-directory style list of the tree level
853 specified in $dn */
854 foreach (split(',', $dn) as $rdn){
856 /* We're only interested in organizational units... */
857 if (substr($rdn,0,3) == 'ou='){
858 $dep= substr($rdn,3)."/$dep";
859 }
861 /* ... and location objects */
862 if (substr($rdn,0,2) == 'l='){
863 $dep= substr($rdn,2)."/$dep";
864 }
865 }
867 /* Return and remove accidently trailing slashes */
868 return rtrim($dep, "/");
869 }
872 /* Strip off the last sub department part of a '/level1/level2/.../'
873 * style value. It removes the trailing '/', too. */
874 function get_sub_department($value)
875 {
876 return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
877 }
880 function get_ou($name)
881 {
882 global $config;
884 /* Preset ou... */
885 if (isset($config->current[$name])){
886 $ou= $config->current[$name];
887 } else {
888 return "";
889 }
891 if ($ou != ""){
892 if (!preg_match('/^[^=]+=[^=]+/', $ou)){
893 return @LDAP::convert("ou=$ou,");
894 } else {
895 return @LDAP::convert("$ou,");
896 }
897 } else {
898 return "";
899 }
900 }
903 function get_people_ou()
904 {
905 return (get_ou("PEOPLE"));
906 }
909 function get_groups_ou()
910 {
911 return (get_ou("GROUPS"));
912 }
915 function get_winstations_ou()
916 {
917 return (get_ou("WINSTATIONS"));
918 }
921 function get_base_from_people($dn)
922 {
923 global $config;
925 $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
926 $base= preg_replace($pattern, '', $dn);
928 /* Set to base, if we're not on a correct subtree */
929 if (!isset($config->idepartments[$base])){
930 $base= $config->current['BASE'];
931 }
933 return ($base);
934 }
937 function chkacl()
938 {
939 /* Look for attribute in ACL */
940 trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
941 return("-deprecated-");
942 }
945 function is_phone_nr($nr)
946 {
947 if ($nr == ""){
948 return (TRUE);
949 }
951 return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
952 }
954 function is_dns_name($str)
955 {
956 return(preg_match("/^[a-z0-9\.\-]*$/i",$str));
957 }
959 function is_url($url)
960 {
961 if ($url == ""){
962 return (TRUE);
963 }
965 return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
966 }
969 function is_dn($dn)
970 {
971 if ($dn == ""){
972 return (TRUE);
973 }
975 return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
976 }
979 function strict_uid_mode()
980 {
981 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
982 }
985 function get_uid_regexp()
986 {
987 /* STRICT adds spaces and case insenstivity to the uid check.
988 This is dangerous and should not be used. */
989 if (strict_uid_mode()){
990 return "^[a-z0-9_-]+$";
991 } else {
992 return "^[a-zA-Z0-9 _.-]+$";
993 }
994 }
997 function is_uid($uid)
998 {
999 global $config;
1001 if ($uid == ""){
1002 return (TRUE);
1003 }
1005 /* STRICT adds spaces and case insenstivity to the uid check.
1006 This is dangerous and should not be used. */
1007 if (strict_uid_mode()){
1008 return preg_match ("/^[a-z0-9_-]+$/", $uid);
1009 } else {
1010 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
1011 }
1012 }
1015 function is_ip($ip)
1016 {
1017 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);
1018 }
1021 function is_mac($mac)
1022 {
1023 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);
1024 }
1027 /* Checks if the given ip address dosen't match
1028 "is_ip" because there is also a sub net mask given */
1029 function is_ip_with_subnetmask($ip)
1030 {
1031 /* Generate list of valid submasks */
1032 $res = array();
1033 for($e = 0 ; $e <= 32; $e++){
1034 $res[$e] = $e;
1035 }
1036 $i[0] =255;
1037 $i[1] =255;
1038 $i[2] =255;
1039 $i[3] =255;
1040 for($a= 3 ; $a >= 0 ; $a --){
1041 $c = 1;
1042 while($i[$a] > 0 ){
1043 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1044 $res[$str] = $str;
1045 $i[$a] -=$c;
1046 $c = 2*$c;
1047 }
1048 }
1049 $res["0.0.0.0"] = "0.0.0.0";
1050 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1051 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1052 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1053 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1054 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1055 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1056 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1057 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1059 $mask = preg_replace("/^\//","",$mask);
1060 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1061 return(TRUE);
1062 }
1063 }
1064 return(FALSE);
1065 }
1067 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1068 function is_domain($str)
1069 {
1070 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1071 }
1075 function is_id($id)
1076 {
1077 if ($id == ""){
1078 return (FALSE);
1079 }
1081 return preg_match ("/^[0-9]+$/", $id);
1082 }
1085 function is_path($path)
1086 {
1087 if ($path == ""){
1088 return (TRUE);
1089 }
1090 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1091 return (FALSE);
1092 }
1094 return preg_match ("/\/.+$/", $path);
1095 }
1098 function is_email($address, $template= FALSE)
1099 {
1100 if ($address == ""){
1101 return (TRUE);
1102 }
1103 if ($template){
1104 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1105 $address);
1106 } else {
1107 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1108 $address);
1109 }
1110 }
1113 function print_red()
1114 {
1115 /* Check number of arguments */
1116 if (func_num_args() < 1){
1117 return;
1118 }
1120 /* Get arguments, save string */
1121 $array = func_get_args();
1122 $string= $array[0];
1124 /* Step through arguments */
1125 for ($i= 1; $i<count($array); $i++){
1126 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1127 }
1129 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1130 the other case... */
1131 if (is_global('DEBUGLEVEL')){
1132 if($string !== NULL){
1133 if (preg_match("/"._("LDAP error:")."/", $string)){
1134 $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.");
1135 } else {
1136 if (!preg_match('/[.!?]$/', $string)){
1137 $string.= ".";
1138 }
1139 $string= preg_replace('/<br>/', ' ', $string);
1140 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1141 $addmsg = "";
1142 }
1143 if(empty($addmsg)){
1144 $addmsg = _("Error");
1145 }
1146 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1147 return;
1148 }else{
1149 return;
1150 }
1152 } else {
1153 echo "Error: $string\n";
1154 }
1155 }
1158 function gen_locked_message($user, $dn)
1159 {
1160 global $plug, $config;
1162 register_global('dn', $dn);
1163 $remove= false;
1165 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1166 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1168 $LOCK_VARS_USED = array();
1169 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1171 foreach($LOCK_VARS_TO_USE as $name){
1173 if(empty($name)){
1174 continue;
1175 }
1177 foreach($_POST as $Pname => $Pvalue){
1178 if(preg_match($name,$Pname)){
1179 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1180 }
1181 }
1183 foreach($_GET as $Pname => $Pvalue){
1184 if(preg_match($name,$Pname)){
1185 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1186 }
1187 }
1188 }
1189 register_global('LOCK_VARS_TO_USE',array());
1190 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1191 }
1193 /* Prepare and show template */
1194 $smarty= get_smarty();
1196 if(is_array($dn)){
1197 $msg = "<pre>";
1198 foreach($dn as $sub_dn){
1199 $msg .= "\n".$sub_dn.", ";
1200 }
1201 $msg = preg_replace("/, $/","</pre>",$msg);
1202 }else{
1203 $msg = $dn;
1204 }
1206 $smarty->assign ("dn", $msg);
1207 if ($remove){
1208 $smarty->assign ("action", _("Continue anyway"));
1209 } else {
1210 $smarty->assign ("action", _("Edit anyway"));
1211 }
1212 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1214 return ($smarty->fetch (get_template_path('islocked.tpl')));
1215 }
1218 function to_string ($value)
1219 {
1220 /* If this is an array, generate a text blob */
1221 if (is_array($value)){
1222 $ret= "";
1223 foreach ($value as $line){
1224 $ret.= $line."<br>\n";
1225 }
1226 return ($ret);
1227 } else {
1228 return ($value);
1229 }
1230 }
1233 function get_printer_list()
1234 {
1235 global $config;
1236 $res = array();
1237 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'), GL_SUBSEARCH);
1238 foreach($data as $attrs ){
1239 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1240 }
1241 return $res;
1242 }
1245 function sess_del ($var)
1246 {
1247 /* New style */
1248 unset($_SESSION[$var]);
1250 /* ... work around, since the first one
1251 doesn't seem to work all the time */
1252 session_unregister ($var);
1253 }
1256 function show_errors($message)
1257 {
1258 $complete= "";
1260 /* Assemble the message array to a plain string */
1261 foreach ($message as $error){
1262 if ($complete == ""){
1263 $complete= $error;
1264 } else {
1265 $complete= "$error<br>$complete";
1266 }
1267 }
1269 /* Fill ERROR variable with nice error dialog */
1270 print_red($complete);
1271 }
1274 function show_ldap_error($message, $addon= "")
1275 {
1276 if (!preg_match("/Success/i", $message)){
1277 if ($addon == ""){
1278 msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1279 } else {
1280 if(!preg_match("/No such object/i",$message)){
1281 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1282 }
1283 }
1284 return TRUE;
1285 } else {
1286 return FALSE;
1287 }
1288 }
1291 function rewrite($s)
1292 {
1293 global $REWRITE;
1295 foreach ($REWRITE as $key => $val){
1296 $s= preg_replace("/$key/", "$val", $s);
1297 }
1299 return ($s);
1300 }
1303 function dn2base($dn)
1304 {
1305 global $config;
1307 if (get_people_ou() != ""){
1308 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1309 }
1310 if (get_groups_ou() != ""){
1311 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1312 }
1313 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1315 return ($base);
1316 }
1320 function check_command($cmdline)
1321 {
1322 $cmd= preg_replace("/ .*$/", "", $cmdline);
1324 /* Check if command exists in filesystem */
1325 if (!file_exists($cmd)){
1326 return (FALSE);
1327 }
1329 /* Check if command is executable */
1330 if (!is_executable($cmd)){
1331 return (FALSE);
1332 }
1334 return (TRUE);
1335 }
1338 function print_header($image, $headline, $info= "")
1339 {
1340 $display= "<div class=\"plugtop\">\n";
1341 $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";
1342 $display.= "</div>\n";
1344 if ($info != ""){
1345 $display.= "<div class=\"pluginfo\">\n";
1346 $display.= "$info";
1347 $display.= "</div>\n";
1348 } else {
1349 $display.= "<div style=\"height:5px;\">\n";
1350 $display.= " ";
1351 $display.= "</div>\n";
1352 }
1353 return ($display);
1354 }
1357 function register_global($name, $object)
1358 {
1359 $_SESSION[$name]= $object;
1360 }
1363 function is_global($name)
1364 {
1365 return isset($_SESSION[$name]);
1366 }
1369 function &get_global($name)
1370 {
1371 return $_SESSION[$name];
1372 }
1375 function range_selector($dcnt,$start,$range=25,$post_var=false)
1376 {
1378 /* Entries shown left and right from the selected entry */
1379 $max_entries= 10;
1381 /* Initialize and take care that max_entries is even */
1382 $output="";
1383 if ($max_entries & 1){
1384 $max_entries++;
1385 }
1387 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1388 $range= $_POST[$post_var];
1389 }
1391 /* Prevent output to start or end out of range */
1392 if ($start < 0 ){
1393 $start= 0 ;
1394 }
1395 if ($start >= $dcnt){
1396 $start= $range * (int)(($dcnt / $range) + 0.5);
1397 }
1399 $numpages= (($dcnt / $range));
1400 if(((int)($numpages))!=($numpages)){
1401 $numpages = (int)$numpages + 1;
1402 }
1403 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1404 return ("");
1405 }
1406 $ppage= (int)(($start / $range) + 0.5);
1409 /* Align selected page to +/- max_entries/2 */
1410 $begin= $ppage - $max_entries/2;
1411 $end= $ppage + $max_entries/2;
1413 /* Adjust begin/end, so that the selected value is somewhere in
1414 the middle and the size is max_entries if possible */
1415 if ($begin < 0){
1416 $end-= $begin + 1;
1417 $begin= 0;
1418 }
1419 if ($end > $numpages) {
1420 $end= $numpages;
1421 }
1422 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1423 $begin= $end - $max_entries;
1424 }
1426 if($post_var){
1427 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1428 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1429 }else{
1430 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1431 }
1433 /* Draw decrement */
1434 if ($start > 0 ) {
1435 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1436 (($start-$range))."\">".
1437 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1438 }
1440 /* Draw pages */
1441 for ($i= $begin; $i < $end; $i++) {
1442 if ($ppage == $i){
1443 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1444 validate($_GET['plug'])."&start=".
1445 ($i*$range)."\"> ".($i+1)." </a>";
1446 } else {
1447 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1448 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1449 }
1450 }
1452 /* Draw increment */
1453 if($start < ($dcnt-$range)) {
1454 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1455 (($start+($range)))."\">".
1456 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1457 }
1459 if(($post_var)&&($numpages)){
1460 $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()'>";
1461 foreach(array(20,50,100,200,"all") as $num){
1462 if($num == "all"){
1463 $var = 10000;
1464 }else{
1465 $var = $num;
1466 }
1467 if($var == $range){
1468 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1469 }else{
1470 $output.="\n<option value='".$var."'>".$num."</option>";
1471 }
1472 }
1473 $output.= "</select></td></tr></table></div>";
1474 }else{
1475 $output.= "</div>";
1476 }
1478 return($output);
1479 }
1482 function apply_filter()
1483 {
1484 $apply= "";
1486 $apply= ''.
1487 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1488 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1490 return ($apply);
1491 }
1494 function back_to_main()
1495 {
1496 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1497 _("Back").'"></p><input type="hidden" name="ignore">';
1499 return ($string);
1500 }
1503 function normalize_netmask($netmask)
1504 {
1505 /* Check for notation of netmask */
1506 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1507 $num= (int)($netmask);
1508 $netmask= "";
1510 for ($byte= 0; $byte<4; $byte++){
1511 $result=0;
1513 for ($i= 7; $i>=0; $i--){
1514 if ($num-- > 0){
1515 $result+= pow(2,$i);
1516 }
1517 }
1519 $netmask.= $result.".";
1520 }
1522 return (preg_replace('/\.$/', '', $netmask));
1523 }
1525 return ($netmask);
1526 }
1529 function netmask_to_bits($netmask)
1530 {
1531 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1532 $res= 0;
1534 for ($n= 0; $n<4; $n++){
1535 $start= 255;
1536 $name= "nm$n";
1538 for ($i= 0; $i<8; $i++){
1539 if ($start == (int)($$name)){
1540 $res+= 8 - $i;
1541 break;
1542 }
1543 $start-= pow(2,$i);
1544 }
1545 }
1547 return ($res);
1548 }
1551 function recurse($rule, $variables)
1552 {
1553 $result= array();
1555 if (!count($variables)){
1556 return array($rule);
1557 }
1559 reset($variables);
1560 $key= key($variables);
1561 $val= current($variables);
1562 unset ($variables[$key]);
1564 foreach($val as $possibility){
1565 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1566 $result= array_merge($result, recurse($nrule, $variables));
1567 }
1569 return ($result);
1570 }
1573 function expand_id($rule, $attributes)
1574 {
1575 /* Check for id rule */
1576 if(preg_match('/^id(:|#)\d+$/',$rule)){
1577 return (array("\{$rule}"));
1578 }
1580 /* Check for clean attribute */
1581 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1582 $rule= preg_replace('/^%/', '', $rule);
1583 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1584 return (array($val));
1585 }
1587 /* Check for attribute with parameters */
1588 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1589 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1590 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1591 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1592 $start= preg_replace ('/-.*$/', '', $param);
1593 $stop = preg_replace ('/^[^-]+-/', '', $param);
1595 /* Assemble results */
1596 $result= array();
1597 for ($i= $start; $i<= $stop; $i++){
1598 $result[]= substr($val, 0, $i);
1599 }
1600 return ($result);
1601 }
1603 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1604 return (array($rule));
1605 }
1608 function gen_uids($rule, $attributes)
1609 {
1610 global $config;
1612 /* Search for keys and fill the variables array with all
1613 possible values for that key. */
1614 $part= "";
1615 $trigger= false;
1616 $stripped= "";
1617 $variables= array();
1619 for ($pos= 0; $pos < strlen($rule); $pos++){
1621 if ($rule[$pos] == "{" ){
1622 $trigger= true;
1623 $part= "";
1624 continue;
1625 }
1627 if ($rule[$pos] == "}" ){
1628 $variables[$pos]= expand_id($part, $attributes);
1629 $stripped.= "{".$pos."}";
1630 $trigger= false;
1631 continue;
1632 }
1634 if ($trigger){
1635 $part.= $rule[$pos];
1636 } else {
1637 $stripped.= $rule[$pos];
1638 }
1639 }
1641 /* Recurse through all possible combinations */
1642 $proposed= recurse($stripped, $variables);
1644 /* Get list of used ID's */
1645 $used= array();
1646 $ldap= $config->get_ldap_link();
1647 $ldap->cd($config->current['BASE']);
1648 $ldap->search('(uid=*)');
1650 while($attrs= $ldap->fetch()){
1651 $used[]= $attrs['uid'][0];
1652 }
1654 /* Remove used uids and watch out for id tags */
1655 $ret= array();
1656 foreach($proposed as $uid){
1658 /* Check for id tag and modify uid if needed */
1659 if(preg_match('/\{id:\d+}/',$uid)){
1660 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1662 for ($i= 0; $i < pow(10,$size); $i++){
1663 $number= sprintf("%0".$size."d", $i);
1664 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1665 if (!in_array($res, $used)){
1666 $uid= $res;
1667 break;
1668 }
1669 }
1670 }
1672 if(preg_match('/\{id#\d+}/',$uid)){
1673 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1675 while (true){
1676 mt_srand((double) microtime()*1000000);
1677 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1678 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1679 if (!in_array($res, $used)){
1680 $uid= $res;
1681 break;
1682 }
1683 }
1684 }
1686 /* Don't assign used ones */
1687 if (!in_array($uid, $used)){
1688 $ret[]= $uid;
1689 }
1690 }
1692 return(array_unique($ret));
1693 }
1696 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1697 Need to convert... */
1698 function to_byte($value) {
1699 $value= strtolower(trim($value));
1701 if(!is_numeric(substr($value, -1))) {
1703 switch(substr($value, -1)) {
1704 case 'g':
1705 $mult= 1073741824;
1706 break;
1707 case 'm':
1708 $mult= 1048576;
1709 break;
1710 case 'k':
1711 $mult= 1024;
1712 break;
1713 }
1715 return ($mult * (int)substr($value, 0, -1));
1716 } else {
1717 return $value;
1718 }
1719 }
1722 function in_array_ics($value, $items)
1723 {
1724 if (!is_array($items)){
1725 return (FALSE);
1726 }
1728 foreach ($items as $item){
1729 if (strcasecmp($item, $value) == 0) {
1730 return (TRUE);
1731 }
1732 }
1734 return (FALSE);
1735 }
1738 function generate_alphabet($count= 10)
1739 {
1740 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1741 $alphabet= "";
1742 $c= 0;
1744 /* Fill cells with charaters */
1745 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1746 if ($c == 0){
1747 $alphabet.= "<tr>";
1748 }
1750 $ch = mb_substr($characters, $i, 1, "UTF8");
1751 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1752 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1754 if ($c++ == $count){
1755 $alphabet.= "</tr>";
1756 $c= 0;
1757 }
1758 }
1760 /* Fill remaining cells */
1761 while ($c++ <= $count){
1762 $alphabet.= "<td> </td>";
1763 }
1765 return ($alphabet);
1766 }
1769 function validate($string)
1770 {
1771 return (strip_tags(preg_replace('/\0/', '', $string)));
1772 }
1774 function get_gosa_version()
1775 {
1776 global $svn_revision, $svn_path;
1778 /* Extract informations */
1779 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1781 /* Release or development? */
1782 if (preg_match('%/gosa/trunk/%', $svn_path)){
1783 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1784 } else {
1785 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1786 return (sprintf(_("GOsa $release"), $revision));
1787 }
1788 }
1791 function rmdirRecursive($path, $followLinks=false) {
1792 $dir= opendir($path);
1793 while($entry= readdir($dir)) {
1794 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1795 unlink($path."/".$entry);
1796 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1797 rmdirRecursive($path."/".$entry);
1798 }
1799 }
1800 closedir($dir);
1801 return rmdir($path);
1802 }
1804 function scan_directory($path,$sort_desc=false)
1805 {
1806 $ret = false;
1808 /* is this a dir ? */
1809 if(is_dir($path)) {
1811 /* is this path a readable one */
1812 if(is_readable($path)){
1814 /* Get contents and write it into an array */
1815 $ret = array();
1817 $dir = opendir($path);
1819 /* Is this a correct result ?*/
1820 if($dir){
1821 while($fp = readdir($dir))
1822 $ret[]= $fp;
1823 }
1824 }
1825 }
1826 /* Sort array ascending , like scandir */
1827 sort($ret);
1829 /* Sort descending if parameter is sort_desc is set */
1830 if($sort_desc) {
1831 $ret = array_reverse($ret);
1832 }
1834 return($ret);
1835 }
1837 function clean_smarty_compile_dir($directory)
1838 {
1839 global $svn_revision;
1841 if(is_dir($directory) && is_readable($directory)) {
1842 // Set revision filename to REVISION
1843 $revision_file= $directory."/REVISION";
1845 /* Is there a stamp containing the current revision? */
1846 if(!file_exists($revision_file)) {
1847 // create revision file
1848 create_revision($revision_file, $svn_revision);
1849 } else {
1850 # check for "$config->...['CONFIG']/revision" and the
1851 # contents should match the revision number
1852 if(!compare_revision($revision_file, $svn_revision)){
1853 // If revision differs, clean compile directory
1854 foreach(scan_directory($directory) as $file) {
1855 if(($file==".")||($file=="..")) continue;
1856 if( is_file($directory."/".$file) &&
1857 is_writable($directory."/".$file)) {
1858 // delete file
1859 if(!unlink($directory."/".$file)) {
1860 print_red("File ".$directory."/".$file." could not be deleted.");
1861 // This should never be reached
1862 }
1863 } elseif(is_dir($directory."/".$file) &&
1864 is_writable($directory."/".$file)) {
1865 // Just recursively delete it
1866 rmdirRecursive($directory."/".$file);
1867 }
1868 }
1869 // We should now create a fresh revision file
1870 clean_smarty_compile_dir($directory);
1871 } else {
1872 // Revision matches, nothing to do
1873 }
1874 }
1875 } else {
1876 // Smarty compile dir is not accessible
1877 // (Smarty will warn about this)
1878 }
1879 }
1881 function create_revision($revision_file, $revision)
1882 {
1883 $result= false;
1885 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1886 if($fh= fopen($revision_file, "w")) {
1887 if(fwrite($fh, $revision)) {
1888 $result= true;
1889 }
1890 }
1891 fclose($fh);
1892 } else {
1893 print_red("Can not write to revision file");
1894 }
1896 return $result;
1897 }
1899 function compare_revision($revision_file, $revision)
1900 {
1901 // false means revision differs
1902 $result= false;
1904 if(file_exists($revision_file) && is_readable($revision_file)) {
1905 // Open file
1906 if($fh= fopen($revision_file, "r")) {
1907 // Compare File contents with current revision
1908 if($revision == fread($fh, filesize($revision_file))) {
1909 $result= true;
1910 }
1911 } else {
1912 print_red("Can not open revision file");
1913 }
1914 // Close file
1915 fclose($fh);
1916 }
1918 return $result;
1919 }
1921 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1922 {
1923 $str = ""; // Our return value will be saved in this var
1925 $color = dechex($percentage+150);
1926 $color2 = dechex(150 - $percentage);
1927 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1929 $progress = (int)(($percentage /100)*$width);
1931 /* Abort printing out percentage, if divs are to small */
1934 /* If theres a better solution for this, use it... */
1935 $str = "
1936 <div style=\" width:".($width)."px;
1937 height:".($height)."px;
1938 background-color:#000000;
1939 padding:1px;\">
1941 <div style=\" width:".($width)."px;
1942 background-color:#$bgcolor;
1943 height:".($height)."px;\">
1945 <div style=\" width:".$progress."px;
1946 height:".$height."px;
1947 background-color:#".$color2.$color2.$color."; \">";
1950 if(($height >10)&&($showvalue)){
1951 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
1952 <b>".$percentage."%</b>
1953 </font>";
1954 }
1956 $str.= "</div></div></div>";
1958 return($str);
1959 }
1962 function array_key_ics($ikey, $items)
1963 {
1964 /* Gather keys, make them lowercase */
1965 $tmp= array();
1966 foreach ($items as $key => $value){
1967 $tmp[strtolower($key)]= $key;
1968 }
1970 if (isset($tmp[strtolower($ikey)])){
1971 return($tmp[strtolower($ikey)]);
1972 }
1974 return ("");
1975 }
1978 function array_differs($src, $dst)
1979 {
1980 /* If the count is differing, the arrays differ */
1981 if (count ($src) != count ($dst)){
1982 return (TRUE);
1983 }
1985 /* So the count is the same - lets check the contents */
1986 $differs= FALSE;
1987 foreach($src as $value){
1988 if (!in_array($value, $dst)){
1989 $differs= TRUE;
1990 }
1991 }
1993 return ($differs);
1994 }
1997 function saveFilter($a_filter, $values)
1998 {
1999 if (isset($_POST['regexit'])){
2000 $a_filter["regex"]= $_POST['regexit'];
2002 foreach($values as $type){
2003 if (isset($_POST[$type])) {
2004 $a_filter[$type]= "checked";
2005 } else {
2006 $a_filter[$type]= "";
2007 }
2008 }
2009 }
2011 /* React on alphabet links if needed */
2012 if (isset($_GET['search'])){
2013 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
2014 if ($s == "**"){
2015 $s= "*";
2016 }
2017 $a_filter['regex']= $s;
2018 }
2020 return ($a_filter);
2021 }
2024 /* Escape all preg_* relevant characters */
2025 function normalizePreg($input)
2026 {
2027 return (addcslashes($input, '[]()|/.*+-'));
2028 }
2031 /* Escape all LDAP filter relevant characters */
2032 function normalizeLdap($input)
2033 {
2034 return (addcslashes($input, '()|'));
2035 }
2038 /* Resturns the difference between to microtime() results in float */
2039 function get_MicroTimeDiff($start , $stop)
2040 {
2041 $a = split("\ ",$start);
2042 $b = split("\ ",$stop);
2044 $secs = $b[1] - $a[1];
2045 $msecs= $b[0] - $a[0];
2047 $ret = (float) ($secs+ $msecs);
2048 return($ret);
2049 }
2052 /* Check if the given department name is valid */
2053 function is_department_name_reserved($name,$base)
2054 {
2055 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2056 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2057 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2058 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2060 /* Check if name is one of the reserved names */
2061 if(in_array_ics($name,$reservedName)) {
2062 return(true);
2063 }
2065 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2066 foreach($follwedNames as $key => $names){
2067 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2068 return(true);
2069 }
2070 }
2071 return(false);
2072 }
2075 function get_base_dir()
2076 {
2077 global $BASE_DIR;
2079 return $BASE_DIR;
2080 }
2083 function obj_is_readable($dn, $object, $attribute)
2084 {
2085 global $ui;
2087 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2088 }
2091 function obj_is_writable($dn, $object, $attribute)
2092 {
2093 global $ui;
2095 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2096 }
2099 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2100 {
2101 /* Initialize variables */
2102 $ret = array("count" => 0); // Set count to 0
2103 $next = true; // if false, then skip next loops and return
2104 $cnt = 0; // Current number of loops
2105 $max = 100; // Just for security, prevent looops
2106 $ldap = NULL; // To check if created result a valid
2107 $keep = ""; // save last failed parse string
2109 /* Check each parsed dn in ldap ? */
2110 if($config!==NULL && $verify_in_ldap){
2111 $ldap = $config->get_ldap_link();
2112 }
2114 /* Lets start */
2115 $called = false;
2116 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2118 $cnt ++;
2119 if(!preg_match("/,/",$dn)){
2120 $next = false;
2121 }
2122 $object = preg_replace("/[,].*$/","",$dn);
2123 $dn = preg_replace("/^[^,]+,/","",$dn);
2125 $called = true;
2127 /* Check if current dn is valid */
2128 if($ldap!==NULL){
2129 $ldap->cd($dn);
2130 $ldap->cat($dn,array("dn"));
2131 if($ldap->count()){
2132 $ret[] = $keep.$object;
2133 $keep = "";
2134 }else{
2135 $keep .= $object.",";
2136 }
2137 }else{
2138 $ret[] = $keep.$object;
2139 $keep = "";
2140 }
2141 }
2143 /* No dn was posted */
2144 if($cnt == 0 && !empty($dn)){
2145 $ret[] = $dn;
2146 }
2148 /* Append the rest */
2149 $test = $keep.$dn;
2150 if($called && !empty($test)){
2151 $ret[] = $keep.$dn;
2152 }
2153 $ret['count'] = count($ret) - 1;
2155 return($ret);
2156 }
2158 /* Add "str_split" if this function is missing.
2159 * This function is only available in PHP5
2160 */
2161 if(!function_exists("str_split")){
2162 function str_split($str,$length =1)
2163 {
2164 if($length < 1 ) $length =1;
2166 $ret = array();
2167 for($i = 0 ; $i < strlen($str); $i = $i +$length){
2168 $ret[] = substr($str,$i ,$length);
2169 }
2170 return($ret);
2171 }
2172 }
2175 function get_base_from_hook($dn, $attrib)
2176 {
2177 global $config;
2179 if (isset($config->current['BASE_HOOK'])){
2181 /* Call hook script - if present */
2182 $command= $config->current['BASE_HOOK'];
2184 if ($command != ""){
2185 $command.= " '".LDAP::fix($dn)."' $attrib";
2186 if (check_command($command)){
2187 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2188 exec($command, $output);
2189 if (preg_match("/^[0-9]+$/", $output[0])){
2190 return ($output[0]);
2191 } else {
2192 print_red(_("Warning - base_hook is not available. Using default base."));
2193 return ($config->current['UIDBASE']);
2194 }
2195 } else {
2196 print_red(_("Warning - base_hook is not available. Using default base."));
2197 return ($config->current['UIDBASE']);
2198 }
2200 } else {
2202 print_red(_("Warning - no base_hook defined. Using default base."));
2203 return ($config->current['UIDBASE']);
2205 }
2206 }
2207 }
2209 /* Schema validation functions */
2211 function check_schema_version($class, $version)
2212 {
2213 return preg_match("/\(v$version\)/", $class['DESC']);
2214 }
2216 function check_schema($cfg,$rfc2307bis = FALSE)
2217 {
2218 $messages= array();
2220 /* Get objectclasses */
2221 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2222 $objectclasses = $ldap->get_objectclasses();
2223 if(count($objectclasses) == 0){
2224 print_red(_("Can't get schema information from server. No schema check possible!"));
2225 }
2227 /* This is the default block used for each entry.
2228 * to avoid unset indexes.
2229 */
2230 $def_check = array("REQUIRED_VERSION" => "0",
2231 "SCHEMA_FILES" => array(),
2232 "CLASSES_REQUIRED" => array(),
2233 "STATUS" => FALSE,
2234 "IS_MUST_HAVE" => FALSE,
2235 "MSG" => "",
2236 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2238 /* The gosa base schema */
2239 $checks['gosaObject'] = $def_check;
2240 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2241 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2242 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2243 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2245 /* GOsa Account class */
2246 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2247 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2248 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2249 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2250 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2252 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2253 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2254 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2255 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2256 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2257 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2259 /* Some other checks */
2260 foreach(array(
2261 "gosaCacheEntry" => array("version" => "2.4"),
2262 "gosaDepartment" => array("version" => "2.4"),
2263 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2264 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2265 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2266 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2267 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2268 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2269 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2270 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2271 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2272 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2273 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2274 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2275 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2276 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2277 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2278 "goLdapServer" => array("version" => "2.4"),
2279 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2280 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2281 "goKrbServer" => array("version" => "2.4"),
2282 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2283 ) as $name => $values){
2285 $checks[$name] = $def_check;
2286 if(isset($values['version'])){
2287 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2288 }
2289 if(isset($values['file'])){
2290 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2291 }
2292 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2293 }
2294 foreach($checks as $name => $value){
2295 foreach($value['CLASSES_REQUIRED'] as $class){
2297 if(!isset($objectclasses[$name])){
2298 $checks[$name]['STATUS'] = FALSE;
2299 if($value['IS_MUST_HAVE']){
2300 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2301 }else{
2302 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2303 }
2304 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2305 $checks[$name]['STATUS'] = FALSE;
2307 if($value['IS_MUST_HAVE']){
2308 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2309 }else{
2310 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2311 }
2312 }else{
2313 $checks[$name]['STATUS'] = TRUE;
2314 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2315 }
2316 }
2317 }
2319 $tmp = $objectclasses;
2321 /* The gosa base schema */
2322 $checks['posixGroup'] = $def_check;
2323 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2324 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2325 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2326 $checks['posixGroup']['STATUS'] = TRUE;
2327 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2328 $checks['posixGroup']['MSG'] = "";
2329 $checks['posixGroup']['INFO'] = "";
2331 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2332 if(isset($tmp['posixGroup'])){
2334 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2335 $checks['posixGroup']['STATUS'] = FALSE;
2336 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2337 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2338 }
2339 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2340 $checks['posixGroup']['STATUS'] = FALSE;
2341 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2342 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2343 }
2344 }
2346 return($checks);
2347 }
2352 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2353 {
2354 $tmp = array(
2355 "de_DE" => "German",
2356 "fr_FR" => "French",
2357 "it_IT" => "Italian",
2358 "es_ES" => "Spanish",
2359 "en_US" => "English",
2360 "nl_NL" => "Dutch",
2361 "pl_PL" => "Polish",
2362 "sv_SE" => "Swedish",
2363 "zh_CN" => "Chinese",
2364 "ru_RU" => "Russian");
2366 $tmp2= array(
2367 "de_DE" => _("German"),
2368 "fr_FR" => _("French"),
2369 "it_IT" => _("Italian"),
2370 "es_ES" => _("Spanish"),
2371 "en_US" => _("English"),
2372 "nl_NL" => _("Dutch"),
2373 "pl_PL" => _("Polish"),
2374 "sv_SE" => _("Swedish"),
2375 "zh_CN" => _("Chinese"),
2376 "ru_RU" => _("Russian"));
2378 $ret = array();
2379 if($languages_in_own_language){
2381 $old_lang = setlocale(LC_ALL, 0);
2382 foreach($tmp as $key => $name){
2383 $lang = $key.".UTF-8";
2384 setlocale(LC_ALL, $lang);
2385 if($strip_region_tag){
2386 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2387 }else{
2388 $ret[$key] = _($name)." (".$tmp2[$key].")";
2389 }
2390 }
2391 setlocale(LC_ALL, $old_lang);
2392 }else{
2393 foreach($tmp as $key => $name){
2394 if($strip_region_tag){
2395 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2396 }else{
2397 $ret[$key] = _($name);
2398 }
2399 }
2400 }
2401 return($ret);
2402 }
2405 /* Returns contents of the given POST variable and check magic quotes settings */
2406 function get_post($name)
2407 {
2408 if(!isset($_POST[$name])){
2409 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2410 return(FALSE);
2411 }
2412 if(get_magic_quotes_gpc()){
2413 return(stripcslashes($_POST[$name]));
2414 }else{
2415 return($_POST[$name]);
2416 }
2417 }
2420 /* Check if $ip1 and $ip2 represents a valid IP range
2421 * returns TRUE in case of a valid range, FALSE in case of an error.
2422 */
2423 function is_ip_range($ip1,$ip2)
2424 {
2425 if(!is_ip($ip1) || !is_ip($ip2)){
2426 return(FALSE);
2427 }else{
2428 $ar1 = split("\.",$ip1);
2429 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2431 $ar2 = split("\.",$ip2);
2432 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2433 return($var1 < $var2);
2434 }
2435 }
2438 /* Check if the specified IP address $address is inside the given network */
2439 function is_in_network($network, $netmask, $address)
2440 {
2441 $nw= split('\.', $network);
2442 $nm= split('\.', $netmask);
2443 $ad= split('\.', $address);
2445 /* Generate inverted netmask */
2446 for ($i= 0; $i<4; $i++){
2447 $ni[$i]= 255-$nm[$i];
2448 $la[$i]= $nw[$i] | $ni[$i];
2449 }
2451 /* Transform to integer */
2452 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2453 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2454 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2456 return ($first < $curr&& $last > $curr);
2457 }
2459 /* Return class name in correct case
2460 * mailMethodkolab => mailMethodKolab ( k => K )
2461 */
2462 function get_correct_class_name($cls)
2463 {
2464 global $class_mapping;
2465 if(isset($class_mapping) && is_array($class_mapping)){
2466 foreach($class_mapping as $class => $file){
2467 if(preg_match("/^".$cls."$/i",$class)){
2468 return($class);
2469 }
2470 }
2471 }
2472 return(FALSE);
2473 }
2475 // change_password, changes the Password, of the given dn
2476 function change_password ($dn, $password, $mode=0, $hash= "")
2477 {
2478 global $config;
2479 $newpass= "";
2481 /* Convert to lower. Methods are lowercase */
2482 $hash= strtolower($hash);
2484 // Get all available encryption Methods
2486 // NON STATIC CALL :)
2487 $tmp = new passwordMethod(get_global('config'));
2488 $available = $tmp->get_available_methods();
2490 // read current password entry for $dn, to detect the encryption Method
2491 $ldap = $config->get_ldap_link();
2492 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2493 $attrs = $ldap->fetch ();
2495 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2496 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2497 $deactivated = TRUE;
2498 }else{
2499 $deactivated = FALSE;
2500 }
2502 /* Is ensure that clear passwords will stay clear */
2503 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2504 $hash = "clear";
2505 }
2507 // Detect the encryption Method
2508 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2510 /* Check for supported algorithm */
2511 mt_srand((double) microtime()*1000000);
2513 /* Extract used hash */
2514 if ($hash == ""){
2515 $hash= strtolower($matches[1]);
2516 }
2518 $test = new $available[$hash]($config);
2520 } else {
2521 // User MD5 by default
2522 $hash= "md5";
2523 $test = new $available['md5']($config);
2524 }
2526 /* Feed password backends with information */
2527 $test->dn= $dn;
2528 $test->attrs= $attrs;
2529 $newpass= $test->generate_hash($password);
2531 // Update shadow timestamp?
2532 if (isset($attrs["shadowLastChange"][0])){
2533 $shadow= (int)(date("U") / 86400);
2534 } else {
2535 $shadow= 0;
2536 }
2538 // Write back modified entry
2539 $ldap->cd($dn);
2540 $attrs= array();
2542 // Not for groups
2543 if ($mode == 0){
2545 if ($shadow != 0){
2546 $attrs['shadowLastChange']= $shadow;
2547 }
2549 // Create SMB Password
2550 $attrs= generate_smb_nt_hash($password);
2551 }
2553 /* Readd ! if user was deactivated */
2554 if($deactivated){
2555 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2556 }
2558 $attrs['userPassword']= array();
2559 $attrs['userPassword']= $newpass;
2561 $ldap->modify($attrs);
2563 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2565 if ($ldap->error != 'Success') {
2566 print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2567 $ldap->get_error()));
2568 } else {
2570 /* Run backend method for change/create */
2571 $test->set_password($password);
2573 /* Find postmodify entries for this class */
2574 $command= $config->search("password", "POSTMODIFY",array('menu'));
2576 if ($command != ""){
2577 /* Walk through attribute list */
2578 $command= preg_replace("/%userPassword/", $password, $command);
2579 $command= preg_replace("/%dn/", $dn, $command);
2581 if (check_command($command)){
2582 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2583 exec($command);
2584 } else {
2585 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2586 print_red ($message);
2587 }
2588 }
2589 }
2590 }
2591 // Return something like array['sambaLMPassword']= "lalla..."
2592 function generate_smb_nt_hash($password)
2593 {
2594 global $config;
2595 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2596 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2598 exec($tmp, $ar);
2599 flush();
2600 reset($ar);
2601 $hash= current($ar);
2602 if ($hash == "")
2603 {
2604 print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2605 }
2606 else
2607 {
2608 list($lm,$nt)= split (":", trim($hash));
2610 if ($config->current['SAMBAVERSION'] == 3)
2611 {
2612 $attrs['sambaLMPassword']= $lm;
2613 $attrs['sambaNTPassword']= $nt;
2614 $attrs['sambaPwdLastSet']= date('U');
2615 $attrs['sambaBadPasswordCount']= "0";
2616 $attrs['sambaBadPasswordTime']= "0";
2617 } else {
2618 $attrs['lmPassword']= $lm;
2619 $attrs['ntPassword']= $nt;
2620 $attrs['pwdLastSet']= date('U');
2621 }
2622 return($attrs);
2623 }
2624 }
2626 function crypt_single($string,$enc_type )
2627 {
2628 return( passwordMethod::crypt_single_str($string,$enc_type));
2629 }
2632 function getEntryCSN($dn)
2633 {
2634 global $config;
2635 if(empty($dn) || !is_object($config)){
2636 return("");
2637 }
2639 /* Get attribute that we should use as serial number */
2640 if(isset($config->current['UNIQ_IDENTIFIER'])){
2641 $attr = $config->current['UNIQ_IDENTIFIER'];
2642 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2643 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2644 }
2645 if(!empty($attr)){
2646 $ldap = $config->get_ldap_link();
2647 $ldap->cat($dn,array($attr));
2648 $csn = $ldap->fetch();
2649 if(isset($csn[$attr][0])){
2650 return($csn[$attr][0]);
2651 }
2652 }
2653 return("");
2654 }
2656 /* This function returns the offset for the default timezone.
2657 * $stamp is used to detect summer or winter time.
2658 * In case of PHP5, the integrated timezone functions are used.
2659 * For PHP4 we query an array for offset and add summertime hour.
2660 */
2661 function get_default_timezone($stamp = NULL)
2662 {
2663 global $config;
2664 $tz ="";
2666 /* Default return value if zone could not be detected */
2667 $zone = array("name" => "unconfigured", "value" => 0);
2669 /* Use current timestamp if $stamp is not set */
2670 if($stamp === NULL){
2671 $stamp = time();
2672 }
2674 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2675 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2677 /* Get zonename */
2678 if(isset($config->current['TIMEZONE'])){
2679 $tz = $config->current['TIMEZONE'];
2680 }else{
2681 $tz = $config->data['MAIN']['TIMEZONE'];
2682 }
2684 if(!@date_default_timezone_set($tz)){
2685 print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2686 }
2687 $tz_delta = date("Z", $stamp);
2688 $tz_delta = $tz_delta / 3600 ;
2689 return(array("name" => $tz, "value" => $tz_delta));
2691 }
2692 return($zone);
2693 }
2696 /* Return zone informations */
2697 function _get_tz_zones()
2698 {
2699 $timezones = array(
2700 'Africa/Abidjan' => 0,
2701 'Africa/Accra' => 0,
2702 'Africa/Addis_Ababa' => 10800,
2703 'Africa/Algiers' => 3600,
2704 'Africa/Asmera' => 10800,
2705 'Africa/Bamako' => 0,
2706 'Africa/Bangui' => 3600,
2707 'Africa/Banjul' => 0,
2708 'Africa/Bissau' => 0,
2709 'Africa/Blantyre' => 7200,
2710 'Africa/Brazzaville' => 3600,
2711 'Africa/Bujumbura' => 7200,
2712 'Africa/Cairo' => 7200,
2713 'Africa/Casablanca' => 0,
2714 'Africa/Ceuta' => 3600,
2715 'Africa/Conakry' => 0,
2716 'Africa/Dakar' => 0,
2717 'Africa/Dar_es_Salaam' => 10800,
2718 'Africa/Djibouti' => 10800,
2719 'Africa/Douala' => 3600,
2720 'Africa/El_Aaiun' => 0,
2721 'Africa/Freetown' => 0,
2722 'Africa/Gaborone' => 7200,
2723 'Africa/Harare' => 7200,
2724 'Africa/Johannesburg' => 7200,
2725 'Africa/Kampala' => 10800,
2726 'Africa/Khartoum' => 10800,
2727 'Africa/Kigali' => 7200,
2728 'Africa/Kinshasa' => 3600,
2729 'Africa/Lagos' => 3600,
2730 'Africa/Libreville' => 3600,
2731 'Africa/Lome' => 0,
2732 'Africa/Luanda' => 3600,
2733 'Africa/Lubumbashi' => 7200,
2734 'Africa/Lusaka' => 7200,
2735 'Africa/Malabo' => 3600,
2736 'Africa/Maputo' => 7200,
2737 'Africa/Maseru' => 7200,
2738 'Africa/Mbabane' => 7200,
2739 'Africa/Mogadishu' => 10800,
2740 'Africa/Monrovia' => 0,
2741 'Africa/Nairobi' => 10800,
2742 'Africa/Ndjamena' => 3600,
2743 'Africa/Niamey' => 3600,
2744 'Africa/Nouakchott' => 0,
2745 'Africa/Ouagadougou' => 0,
2746 'Africa/Porto-Novo' => 3600,
2747 'Africa/Sao_Tome' => 0,
2748 'Africa/Timbuktu' => 0,
2749 'Africa/Tripoli' => 7200,
2750 'Africa/Tunis' => 3600,
2751 'Africa/Windhoek' => 3600,
2752 'America/Adak' => -36000,
2753 'America/Anchorage' => -32400,
2754 'America/Anguilla' => -14400,
2755 'America/Antigua' => -14400,
2756 'America/Araguaina' => -10800,
2757 'America/Argentina/Buenos_Aires' => 0,
2758 'America/Argentina/Catamarca' => 0,
2759 'America/Argentina/ComodRivadavia' => 0,
2760 'America/Argentina/Cordoba' => 0,
2761 'America/Argentina/Jujuy' => 0,
2762 'America/Argentina/La_Rioja' => 0,
2763 'America/Argentina/Mendoza' => 0,
2764 'America/Argentina/Rio_Gallegos' => 0,
2765 'America/Argentina/San_Juan' => 0,
2766 'America/Argentina/Tucuman' => 0,
2767 'America/Argentina/Ushuaia' => 0,
2768 'America/Aruba' => -14400,
2769 'America/Asuncion' => -14400,
2770 'America/Atikokan' => 0,
2771 'America/Atka' => -36000,
2772 'America/Bahia' => 0,
2773 'America/Barbados' => -14400,
2774 'America/Belem' => -10800,
2775 'America/Belize' => -21600,
2776 'America/Blanc-Sablon' => 0,
2777 'America/Boa_Vista' => -14400,
2778 'America/Bogota' => -18000,
2779 'America/Boise' => -25200,
2780 'America/Buenos_Aires' => -10800,
2781 'America/Cambridge_Bay' => -25200,
2782 'America/Campo_Grande' => 0,
2783 'America/Cancun' => -21600,
2784 'America/Caracas' => -14400,
2785 'America/Catamarca' => -10800,
2786 'America/Cayenne' => -10800,
2787 'America/Cayman' => -18000,
2788 'America/Chicago' => -21600,
2789 'America/Chihuahua' => -25200,
2790 'America/Coral_Harbour' => 0,
2791 'America/Cordoba' => -10800,
2792 'America/Costa_Rica' => -21600,
2793 'America/Cuiaba' => -14400,
2794 'America/Curacao' => -14400,
2795 'America/Danmarkshavn' => 0,
2796 'America/Dawson' => -28800,
2797 'America/Dawson_Creek' => -25200,
2798 'America/Denver' => -25200,
2799 'America/Detroit' => -18000,
2800 'America/Dominica' => -14400,
2801 'America/Edmonton' => -25200,
2802 'America/Eirunepe' => -18000,
2803 'America/El_Salvador' => -21600,
2804 'America/Ensenada' => -28800,
2805 'America/Fort_Wayne' => -18000,
2806 'America/Fortaleza' => -10800,
2807 'America/Glace_Bay' => -14400,
2808 'America/Godthab' => -10800,
2809 'America/Goose_Bay' => -14400,
2810 'America/Grand_Turk' => -18000,
2811 'America/Grenada' => -14400,
2812 'America/Guadeloupe' => -14400,
2813 'America/Guatemala' => -21600,
2814 'America/Guayaquil' => -18000,
2815 'America/Guyana' => -14400,
2816 'America/Halifax' => -14400,
2817 'America/Havana' => -18000,
2818 'America/Hermosillo' => -25200,
2819 'America/Indiana/Indianapolis' => -18000,
2820 'America/Indiana/Knox' => -18000,
2821 'America/Indiana/Marengo' => -18000,
2822 'America/Indiana/Petersburg' => 0,
2823 'America/Indiana/Vevay' => -18000,
2824 'America/Indiana/Vincennes' => 0,
2825 'America/Indianapolis' => -18000,
2826 'America/Inuvik' => -25200,
2827 'America/Iqaluit' => -18000,
2828 'America/Jamaica' => -18000,
2829 'America/Jujuy' => -10800,
2830 'America/Juneau' => -32400,
2831 'America/Kentucky/Louisville' => -18000,
2832 'America/Kentucky/Monticello' => -18000,
2833 'America/Knox_IN' => -18000,
2834 'America/La_Paz' => -14400,
2835 'America/Lima' => -18000,
2836 'America/Los_Angeles' => -28800,
2837 'America/Louisville' => -18000,
2838 'America/Maceio' => -10800,
2839 'America/Managua' => -21600,
2840 'America/Manaus' => -14400,
2841 'America/Martinique' => -14400,
2842 'America/Mazatlan' => -25200,
2843 'America/Mendoza' => -10800,
2844 'America/Menominee' => -21600,
2845 'America/Merida' => -21600,
2846 'America/Mexico_City' => -21600,
2847 'America/Miquelon' => -10800,
2848 'America/Moncton' => 0,
2849 'America/Monterrey' => -21600,
2850 'America/Montevideo' => -10800,
2851 'America/Montreal' => -18000,
2852 'America/Montserrat' => -14400,
2853 'America/Nassau' => -18000,
2854 'America/New_York' => -18000,
2855 'America/Nipigon' => -18000,
2856 'America/Nome' => -32400,
2857 'America/Noronha' => -7200,
2858 'America/North_Dakota/Center' => -21600,
2859 'America/North_Dakota/New_Salem' => 0,
2860 'America/Panama' => -18000,
2861 'America/Pangnirtung' => -18000,
2862 'America/Paramaribo' => -10800,
2863 'America/Phoenix' => -25200,
2864 'America/Port-au-Prince' => -18000,
2865 'America/Port_of_Spain' => -14400,
2866 'America/Porto_Acre' => -18000,
2867 'America/Porto_Velho' => -14400,
2868 'America/Puerto_Rico' => -14400,
2869 'America/Rainy_River' => -21600,
2870 'America/Rankin_Inlet' => -21600,
2871 'America/Recife' => -10800,
2872 'America/Regina' => -21600,
2873 'America/Rio_Branco' => -18000,
2874 'America/Rosario' => -10800,
2875 'America/Santiago' => -14400,
2876 'America/Santo_Domingo' => -14400,
2877 'America/Sao_Paulo' => -10800,
2878 'America/Scoresbysund' => -3600,
2879 'America/Shiprock' => -25200,
2880 'America/St_Johns' => -12600,
2881 'America/St_Kitts' => -14400,
2882 'America/St_Lucia' => -14400,
2883 'America/St_Thomas' => -14400,
2884 'America/St_Vincent' => -14400,
2885 'America/Swift_Current' => -21600,
2886 'America/Tegucigalpa' => -21600,
2887 'America/Thule' => -14400,
2888 'America/Thunder_Bay' => -18000,
2889 'America/Tijuana' => -28800,
2890 'America/Toronto' => 0,
2891 'America/Tortola' => -14400,
2892 'America/Vancouver' => -28800,
2893 'America/Virgin' => -14400,
2894 'America/Whitehorse' => -28800,
2895 'America/Winnipeg' => -21600,
2896 'America/Yakutat' => -32400,
2897 'America/Yellowknife' => -25200,
2898 'Antarctica/Casey' => 28800,
2899 'Antarctica/Davis' => 25200,
2900 'Antarctica/DumontDUrville' => 36000,
2901 'Antarctica/Mawson' => 21600,
2902 'Antarctica/McMurdo' => 43200,
2903 'Antarctica/Palmer' => -14400,
2904 'Antarctica/Rothera' => 0,
2905 'Antarctica/South_Pole' => 43200,
2906 'Antarctica/Syowa' => 10800,
2907 'Antarctica/VostokArctic/Longyearbyen' => 0,
2908 'Asia/Aden' => 10800,
2909 'Asia/Almaty' => 21600,
2910 'Asia/Amman' => 7200,
2911 'Asia/Anadyr' => 43200,
2912 'Asia/Aqtau' => 14400,
2913 'Asia/Aqtobe' => 18000,
2914 'Asia/Ashgabat' => 18000,
2915 'Asia/Ashkhabad' => 18000,
2916 'Asia/Baghdad' => 10800,
2917 'Asia/Bahrain' => 10800,
2918 'Asia/Baku' => 14400,
2919 'Asia/Bangkok' => 25200,
2920 'Asia/Beirut' => 7200,
2921 'Asia/Bishkek' => 18000,
2922 'Asia/Brunei' => 28800,
2923 'Asia/Calcutta' => 19800,
2924 'Asia/Choibalsan' => 32400,
2925 'Asia/Chongqing' => 28800,
2926 'Asia/Chungking' => 28800,
2927 'Asia/Colombo' => 21600,
2928 'Asia/Dacca' => 21600,
2929 'Asia/Damascus' => 7200,
2930 'Asia/Dhaka' => 21600,
2931 'Asia/Dili' => 32400,
2932 'Asia/Dubai' => 14400,
2933 'Asia/Dushanbe' => 18000,
2934 'Asia/Gaza' => 7200,
2935 'Asia/Harbin' => 28800,
2936 'Asia/Hong_Kong' => 28800,
2937 'Asia/Hovd' => 25200,
2938 'Asia/Irkutsk' => 28800,
2939 'Asia/Istanbul' => 7200,
2940 'Asia/Jakarta' => 25200,
2941 'Asia/Jayapura' => 32400,
2942 'Asia/Jerusalem' => 7200,
2943 'Asia/Kabul' => 16200,
2944 'Asia/Kamchatka' => 43200,
2945 'Asia/Karachi' => 18000,
2946 'Asia/Kashgar' => 28800,
2947 'Asia/Katmandu' => 20700,
2948 'Asia/Krasnoyarsk' => 25200,
2949 'Asia/Kuala_Lumpur' => 28800,
2950 'Asia/Kuching' => 28800,
2951 'Asia/Kuwait' => 10800,
2952 'Asia/Macao' => 28800,
2953 'Asia/Macau' => 0,
2954 'Asia/Magadan' => 39600,
2955 'Asia/Makassar' => 0,
2956 'Asia/Manila' => 28800,
2957 'Asia/Muscat' => 14400,
2958 'Asia/Nicosia' => 7200,
2959 'Asia/Novosibirsk' => 21600,
2960 'Asia/Omsk' => 21600,
2961 'Asia/Oral' => 0,
2962 'Asia/Phnom_Penh' => 25200,
2963 'Asia/Pontianak' => 25200,
2964 'Asia/Pyongyang' => 32400,
2965 'Asia/Qatar' => 10800,
2966 'Asia/Qyzylorda' => 0,
2967 'Asia/Rangoon' => 23400,
2968 'Asia/Riyadh' => 10800,
2969 'Asia/Saigon' => 25200,
2970 'Asia/Sakhalin' => 36000,
2971 'Asia/Samarkand' => 18000,
2972 'Asia/Seoul' => 32400,
2973 'Asia/Shanghai' => 28800,
2974 'Asia/Singapore' => 28800,
2975 'Asia/Taipei' => 28800,
2976 'Asia/Tashkent' => 18000,
2977 'Asia/Tbilisi' => 14400,
2978 'Asia/Tehran' => 12600,
2979 'Asia/Tel_Aviv' => 7200,
2980 'Asia/Thimbu' => 21600,
2981 'Asia/Thimphu' => 21600,
2982 'Asia/Tokyo' => 32400,
2983 'Asia/Ujung_Pandang' => 28800,
2984 'Asia/Ulaanbaatar' => 28800,
2985 'Asia/Ulan_Bator' => 28800,
2986 'Asia/Urumqi' => 28800,
2987 'Asia/Vientiane' => 25200,
2988 'Asia/Vladivostok' => 36000,
2989 'Asia/Yakutsk' => 32400,
2990 'Asia/Yekaterinburg' => 18000,
2991 'Asia/YerevanAtlantic/Azores' => 0,
2992 'Atlantic/Bermuda' => -14400,
2993 'Atlantic/Canary' => 0,
2994 'Atlantic/Cape_Verde' => -3600,
2995 'Atlantic/Faeroe' => 0,
2996 'Atlantic/Jan_Mayen' => 3600,
2997 'Atlantic/Madeira' => 0,
2998 'Atlantic/Reykjavik' => 0,
2999 'Atlantic/South_Georgia' => -7200,
3000 'Atlantic/St_Helena' => 0,
3001 'Atlantic/Stanley' => -14400,
3002 'Australia/ACT' => 36000,
3003 'Australia/Adelaide' => 34200,
3004 'Australia/Brisbane' => 36000,
3005 'Australia/Broken_Hill' => 34200,
3006 'Australia/Canberra' => 36000,
3007 'Australia/Currie' => 0,
3008 'Australia/Darwin' => 34200,
3009 'Australia/Hobart' => 36000,
3010 'Australia/LHI' => 37800,
3011 'Australia/Lindeman' => 36000,
3012 'Australia/Lord_Howe' => 37800,
3013 'Australia/Melbourne' => 36000,
3014 'Australia/NSW' => 36000,
3015 'Australia/North' => 34200,
3016 'Australia/Perth' => 28800,
3017 'Australia/Queensland' => 36000,
3018 'Australia/South' => 34200,
3019 'Australia/Sydney' => 36000,
3020 'Australia/Tasmania' => 36000,
3021 'Australia/Victoria' => 36000,
3022 'Australia/West' => 28800,
3023 'Australia/Yancowinna' => 34200,
3024 'Europe/Amsterdam' => 3600,
3025 'Europe/Andorra' => 3600,
3026 'Europe/Athens' => 7200,
3027 'Europe/Belfast' => 0,
3028 'Europe/Belgrade' => 3600,
3029 'Europe/Berlin' => 3600,
3030 'Europe/Bratislava' => 3600,
3031 'Europe/Brussels' => 3600,
3032 'Europe/Bucharest' => 7200,
3033 'Europe/Budapest' => 3600,
3034 'Europe/Chisinau' => 7200,
3035 'Europe/Copenhagen' => 3600,
3036 'Europe/Dublin' => 0,
3037 'Europe/Gibraltar' => 3600,
3038 'Europe/Guernsey' => 0,
3039 'Europe/Helsinki' => 7200,
3040 'Europe/Isle_of_Man' => 0,
3041 'Europe/Istanbul' => 7200,
3042 'Europe/Jersey' => 0,
3043 'Europe/Kaliningrad' => 7200,
3044 'Europe/Kiev' => 7200,
3045 'Europe/Lisbon' => 0,
3046 'Europe/Ljubljana' => 3600,
3047 'Europe/London' => 0,
3048 'Europe/Luxembourg' => 3600,
3049 'Europe/Madrid' => 3600,
3050 'Europe/Malta' => 3600,
3051 'Europe/Mariehamn' => 0,
3052 'Europe/Minsk' => 7200,
3053 'Europe/Monaco' => 3600,
3054 'Europe/Moscow' => 10800,
3055 'Europe/Nicosia' => 7200,
3056 'Europe/Oslo' => 3600,
3057 'Europe/Paris' => 3600,
3058 'Europe/Prague' => 3600,
3059 'Europe/Riga' => 7200,
3060 'Europe/Rome' => 3600,
3061 'Europe/Samara' => 14400,
3062 'Europe/San_Marino' => 3600,
3063 'Europe/Sarajevo' => 3600,
3064 'Europe/Simferopol' => 7200,
3065 'Europe/Skopje' => 3600,
3066 'Europe/Sofia' => 7200,
3067 'Europe/Stockholm' => 3600,
3068 'Europe/Tallinn' => 7200,
3069 'Europe/Tirane' => 3600,
3070 'Europe/Tiraspol' => 7200,
3071 'Europe/Uzhgorod' => 7200,
3072 'Europe/Vaduz' => 3600,
3073 'Europe/Vatican' => 3600,
3074 'Europe/Vienna' => 3600,
3075 'Europe/Vilnius' => 7200,
3076 'Europe/Volgograd' => 0,
3077 'Europe/Warsaw' => 3600,
3078 'Europe/Zagreb' => 3600,
3079 'Europe/Zaporozhye' => 7200,
3080 'Europe/Zurich' => 3600,
3081 'Indian/Antananarivo' => 10800,
3082 'Indian/Chagos' => 21600,
3083 'Indian/Christmas' => 25200,
3084 'Indian/Cocos' => 23400,
3085 'Indian/Comoro' => 10800,
3086 'Indian/Kerguelen' => 18000,
3087 'Indian/Mahe' => 14400,
3088 'Indian/Maldives' => 18000,
3089 'Indian/Mauritius' => 14400,
3090 'Indian/Mayotte' => 10800,
3091 'Indian/Reunion' => 14400,
3092 'Pacific/Apia' => -39600,
3093 'Pacific/Auckland' => 43200,
3094 'Pacific/Chatham' => 45900,
3095 'Pacific/Easter' => -21600,
3096 'Pacific/Efate' => 39600,
3097 'Pacific/Enderbury' => 46800,
3098 'Pacific/Fakaofo' => -36000,
3099 'Pacific/Fiji' => 43200,
3100 'Pacific/Funafuti' => 43200,
3101 'Pacific/Galapagos' => -21600,
3102 'Pacific/Gambier' => -32400,
3103 'Pacific/Guadalcanal' => 39600,
3104 'Pacific/Guam' => 36000,
3105 'Pacific/Honolulu' => -36000,
3106 'Pacific/Johnston' => -36000,
3107 'Pacific/Kiritimati' => 50400,
3108 'Pacific/Kosrae' => 39600,
3109 'Pacific/Kwajalein' => 43200,
3110 'Pacific/Majuro' => 43200,
3111 'Pacific/Marquesas' => -34200,
3112 'Pacific/Midway' => -39600,
3113 'Pacific/Nauru' => 43200,
3114 'Pacific/Niue' => -39600,
3115 'Pacific/Norfolk' => 41400,
3116 'Pacific/Noumea' => 39600,
3117 'Pacific/Pago_Pago' => -39600,
3118 'Pacific/Palau' => 32400,
3119 'Pacific/Pitcairn' => -28800,
3120 'Pacific/Ponape' => 39600,
3121 'Pacific/Port_Moresby' => 36000,
3122 'Pacific/Rarotonga' => -36000,
3123 'Pacific/Saipan' => 36000,
3124 'Pacific/Samoa' => -39600,
3125 'Pacific/Tahiti' => -36000,
3126 'Pacific/Tarawa' => 43200,
3127 'Pacific/Tongatapu' => 46800,
3128 'Pacific/Truk' => 36000,
3129 'Pacific/Wake' => 43200,
3130 'Pacific/Wallis' => 43200,
3131 'Pacific/Yap' => 36000 );
3133 $dst_timezones = array (
3134 'America/Adak' => 1,
3135 'America/Atka' => 1,
3136 'America/Anchorage' => 1,
3137 'America/Juneau' => 1,
3138 'America/Nome' => 1,
3139 'America/Yakutat' => 1,
3140 'America/Dawson' => 1,
3141 'America/Ensenada' => 1,
3142 'America/Los_Angeles' => 1,
3143 'America/Tijuana' => 1,
3144 'America/Vancouver' => 1,
3145 'America/Whitehorse' => 1,
3146 'America/Boise' => 1,
3147 'America/Cambridge_Bay' => 1,
3148 'America/Chihuahua' => 1,
3149 'America/Denver' => 1,
3150 'America/Edmonton' => 1,
3151 'America/Inuvik' => 1,
3152 'America/Mazatlan' => 1,
3153 'America/Shiprock' => 1,
3154 'America/Yellowknife' => 1,
3155 'America/Cancun' => 1,
3156 'America/Chicago' => 1,
3157 'America/Menominee' => 1,
3158 'America/Merida' => 1,
3159 'America/Monterrey' => 1,
3160 'America/North_Dakota/Center' => 1,
3161 'America/Rainy_River' => 1,
3162 'America/Rankin_Inlet' => 1,
3163 'America/Winnipeg' => 1,
3164 'Pacific/Easter' => 1,
3165 'America/Detroit' => 1,
3166 'America/Grand_Turk' => 1,
3167 'America/Havana' => 1,
3168 'America/Iqaluit' => 1,
3169 'America/Kentucky/Louisville' => 1,
3170 'America/Kentucky/Monticello' => 1,
3171 'America/Louisville' => 1,
3172 'America/Montreal' => 1,
3173 'America/Nassau' => 1,
3174 'America/New_York' => 1,
3175 'America/Nipigon' => 1,
3176 'America/Pangnirtung' => 1,
3177 'America/Thunder_Bay' => 1,
3178 'America/Asuncion' => 1,
3179 'America/Cuiaba' => 1,
3180 'America/Glace_Bay' => 1,
3181 'America/Goose_Bay' => 1,
3182 'America/Halifax' => 1,
3183 'America/Santiago' => 1,
3184 'Antarctica/Palmer' => 1,
3185 'Atlantic/Bermuda' => 1,
3186 'Atlantic/Stanley' => 1,
3187 'America/St_Johns' => 1,
3188 'America/Araguaina' => 1,
3189 'America/Fortaleza' => 1,
3190 'America/Godthab' => 1,
3191 'America/Maceio' => 1,
3192 'America/Miquelon' => 1,
3193 'America/Recife' => 1,
3194 'America/Sao_Paulo' => 1,
3195 'America/Scoresbysund' => 1,
3196 'Atlantic/Canary' => 1,
3197 'Atlantic/Faeroe' => 1,
3198 'Atlantic/Madeira' => 1,
3199 'Europe/Belfast' => 1,
3200 'Europe/Dublin' => 1,
3201 'Europe/Lisbon' => 1,
3202 'Europe/London' => 1,
3203 'Africa/Ceuta' => 1,
3204 'Africa/Windhoek' => 1,
3205 'Atlantic/Jan_Mayen' => 1,
3206 'Europe/Amsterdam' => 1,
3207 'Europe/Andorra' => 1,
3208 'Europe/Belgrade' => 1,
3209 'Europe/Berlin' => 1,
3210 'Europe/Bratislava' => 1,
3211 'Europe/Brussels' => 1,
3212 'Europe/Budapest' => 1,
3213 'Europe/Copenhagen' => 1,
3214 'Europe/Gibraltar' => 1,
3215 'Europe/Ljubljana' => 1,
3216 'Europe/Luxembourg' => 1,
3217 'Europe/Madrid' => 1,
3218 'Europe/Malta' => 1,
3219 'Europe/Monaco' => 1,
3220 'Europe/Oslo' => 1,
3221 'Europe/Paris' => 1,
3222 'Europe/Prague' => 1,
3223 'Europe/Rome' => 1,
3224 'Europe/San_Marino' => 1,
3225 'Europe/Sarajevo' => 1,
3226 'Europe/Skopje' => 1,
3227 'Europe/Stockholm' => 1,
3228 'Europe/Tirane' => 1,
3229 'Europe/Vaduz' => 1,
3230 'Europe/Vatican' => 1,
3231 'Europe/Vienna' => 1,
3232 'Europe/Warsaw' => 1,
3233 'Europe/Zagreb' => 1,
3234 'Europe/Zurich' => 1,
3235 'Africa/Cairo' => 1,
3236 'Asia/Amman' => 1,
3237 'Asia/Beirut' => 1,
3238 'Asia/Damascus' => 1,
3239 'Asia/Gaza' => 1,
3240 'Asia/Istanbul' => 1,
3241 'Asia/Jerusalem' => 1,
3242 'Asia/Nicosia' => 1,
3243 'Asia/Tel_Aviv' => 1,
3244 'Europe/Athens' => 1,
3245 'Europe/Bucharest' => 1,
3246 'Europe/Chisinau' => 1,
3247 'Europe/Helsinki' => 1,
3248 'Europe/Istanbul' => 1,
3249 'Europe/Kaliningrad' => 1,
3250 'Europe/Kiev' => 1,
3251 'Europe/Minsk' => 1,
3252 'Europe/Nicosia' => 1,
3253 'Europe/Riga' => 1,
3254 'Europe/Simferopol' => 1,
3255 'Europe/Sofia' => 1,
3256 'Europe/Tiraspol' => 1,
3257 'Europe/Uzhgorod' => 1,
3258 'Europe/Zaporozhye' => 1,
3259 'Asia/Baghdad' => 1,
3260 'Europe/Moscow' => 1,
3261 'Asia/Tehran' => 1,
3262 'Asia/Aqtau' => 1,
3263 'Asia/Baku' => 1,
3264 'Asia/Tbilisi' => 1,
3265 'Europe/Samara' => 1,
3266 'Asia/Aqtobe' => 1,
3267 'Asia/Bishkek' => 1,
3268 'Asia/Yekaterinburg' => 1,
3269 'Asia/Almaty' => 1,
3270 'Asia/Novosibirsk' => 1,
3271 'Asia/Omsk' => 1,
3272 'Asia/Krasnoyarsk' => 1,
3273 'Asia/Irkutsk' => 1,
3274 'Asia/Yakutsk' => 1,
3275 'Australia/Adelaide' => 1,
3276 'Australia/Broken_Hill' => 1,
3277 'Australia/South' => 1,
3278 'Australia/Yancowinna' => 1,
3279 'Asia/Sakhalin' => 1,
3280 'Asia/Vladivostok' => 1,
3281 'Australia/ACT' => 1,
3282 'Australia/Canberra' => 1,
3283 'Australia/Hobart' => 1,
3284 'Australia/Melbourne' => 1,
3285 'Australia/NSW' => 1,
3286 'Australia/Sydney' => 1,
3287 'Australia/Tasmania' => 1,
3288 'Australia/Victoria' => 1,
3289 'Australia/LHI' => 1,
3290 'Australia/Lord_Howe' => 1,
3291 'Asia/Magadan' => 1,
3292 'Antarctica/McMurdo' => 1,
3293 'Antarctica/South_Pole' => 1,
3294 'Asia/Anadyr' => 1,
3295 'Asia/Kamchatka' => 1,
3296 'Pacific/Auckland' => 1,
3297 'Pacific/Chatham' => 1,
3298 );
3299 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3300 }
3301 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3302 ?>