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