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