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 strict_uid_mode()
960 {
961 return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
962 }
965 function get_uid_regexp()
966 {
967 /* STRICT adds spaces and case insenstivity to the uid check.
968 This is dangerous and should not be used. */
969 if (strict_uid_mode()){
970 return "^[a-z0-9_-]+$";
971 } else {
972 return "^[a-zA-Z0-9 _.-]+$";
973 }
974 }
977 function is_uid($uid)
978 {
979 global $config;
981 if ($uid == ""){
982 return (TRUE);
983 }
985 /* STRICT adds spaces and case insenstivity to the uid check.
986 This is dangerous and should not be used. */
987 if (strict_uid_mode()){
988 return preg_match ("/^[a-z0-9_-]+$/", $uid);
989 } else {
990 return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
991 }
992 }
995 function is_ip($ip)
996 {
997 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);
998 }
1001 function is_mac($mac)
1002 {
1003 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);
1004 }
1007 /* Checks if the given ip address dosen't match
1008 "is_ip" because there is also a sub net mask given */
1009 function is_ip_with_subnetmask($ip)
1010 {
1011 /* Generate list of valid submasks */
1012 $res = array();
1013 for($e = 0 ; $e <= 32; $e++){
1014 $res[$e] = $e;
1015 }
1016 $i[0] =255;
1017 $i[1] =255;
1018 $i[2] =255;
1019 $i[3] =255;
1020 for($a= 3 ; $a >= 0 ; $a --){
1021 $c = 1;
1022 while($i[$a] > 0 ){
1023 $str = $i[0].".".$i[1].".".$i[2].".".$i[3];
1024 $res[$str] = $str;
1025 $i[$a] -=$c;
1026 $c = 2*$c;
1027 }
1028 }
1029 $res["0.0.0.0"] = "0.0.0.0";
1030 if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1031 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1032 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1033 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
1034 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1035 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1036 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
1037 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip);
1039 $mask = preg_replace("/^\//","",$mask);
1040 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
1041 return(TRUE);
1042 }
1043 }
1044 return(FALSE);
1045 }
1047 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
1048 function is_domain($str)
1049 {
1050 return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1051 }
1055 function is_id($id)
1056 {
1057 if ($id == ""){
1058 return (FALSE);
1059 }
1061 return preg_match ("/^[0-9]+$/", $id);
1062 }
1065 function is_path($path)
1066 {
1067 if ($path == ""){
1068 return (TRUE);
1069 }
1070 if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1071 return (FALSE);
1072 }
1074 return preg_match ("/\/.+$/", $path);
1075 }
1078 function is_email($address, $template= FALSE)
1079 {
1080 if ($address == ""){
1081 return (TRUE);
1082 }
1083 if ($template){
1084 return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1085 $address);
1086 } else {
1087 return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1088 $address);
1089 }
1090 }
1093 function print_red()
1094 {
1095 /* Check number of arguments */
1096 if (func_num_args() < 1){
1097 return;
1098 }
1100 /* Get arguments, save string */
1101 $array = func_get_args();
1102 $string= $array[0];
1104 /* Step through arguments */
1105 for ($i= 1; $i<count($array); $i++){
1106 $string= preg_replace ("/%s/", $array[$i], $string, 1);
1107 }
1109 /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1110 the other case... */
1111 if (is_global('DEBUGLEVEL')){
1112 if($string !== NULL){
1113 if (preg_match("/"._("LDAP error:")."/", $string)){
1114 $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.");
1115 } else {
1116 if (!preg_match('/[.!?]$/', $string)){
1117 $string.= ".";
1118 }
1119 $string= preg_replace('/<br>/', ' ', $string);
1120 $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1121 $addmsg = "";
1122 }
1123 if(empty($addmsg)){
1124 $addmsg = _("Error");
1125 }
1126 msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1127 return;
1128 }else{
1129 return;
1130 }
1132 } else {
1133 echo "Error: $string\n";
1134 }
1135 }
1138 function gen_locked_message($user, $dn)
1139 {
1140 global $plug, $config;
1142 register_global('dn', $dn);
1143 $remove= false;
1145 /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1146 if( is_global('LOCK_VARS_TO_USE') && count(get_global('LOCK_VARS_TO_USE'))){
1148 $LOCK_VARS_USED = array();
1149 $LOCK_VARS_TO_USE = get_global('LOCK_VARS_TO_USE');
1151 foreach($LOCK_VARS_TO_USE as $name){
1153 if(empty($name)){
1154 continue;
1155 }
1157 foreach($_POST as $Pname => $Pvalue){
1158 if(preg_match($name,$Pname)){
1159 $LOCK_VARS_USED[$Pname] = $_POST[$Pname];
1160 }
1161 }
1163 foreach($_GET as $Pname => $Pvalue){
1164 if(preg_match($name,$Pname)){
1165 $LOCK_VARS_USED[$Pname] = $_GET[$Pname];
1166 }
1167 }
1168 }
1169 register_global('LOCK_VARS_TO_USE',array());
1170 register_global('LOCK_VARS_USED' , $LOCK_VARS_USED);
1171 }
1173 /* Prepare and show template */
1174 $smarty= get_smarty();
1176 if(is_array($dn)){
1177 $msg = "<pre>";
1178 foreach($dn as $sub_dn){
1179 $msg .= "\n".$sub_dn.", ";
1180 }
1181 $msg = preg_replace("/, $/","</pre>",$msg);
1182 }else{
1183 $msg = $dn;
1184 }
1186 $smarty->assign ("dn", $msg);
1187 if ($remove){
1188 $smarty->assign ("action", _("Continue anyway"));
1189 } else {
1190 $smarty->assign ("action", _("Edit anyway"));
1191 }
1192 $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1194 return ($smarty->fetch (get_template_path('islocked.tpl')));
1195 }
1198 function to_string ($value)
1199 {
1200 /* If this is an array, generate a text blob */
1201 if (is_array($value)){
1202 $ret= "";
1203 foreach ($value as $line){
1204 $ret.= $line."<br>\n";
1205 }
1206 return ($ret);
1207 } else {
1208 return ($value);
1209 }
1210 }
1213 function get_printer_list($cups_server)
1214 {
1215 global $config;
1216 $res = array();
1217 $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'));
1218 foreach($data as $attrs ){
1219 $res[$attrs['cn'][0]] = $attrs['cn'][0];
1220 }
1221 return $res;
1222 }
1225 function sess_del ($var)
1226 {
1227 /* New style */
1228 unset($_SESSION[$var]);
1230 /* ... work around, since the first one
1231 doesn't seem to work all the time */
1232 session_unregister ($var);
1233 }
1236 function show_errors($message)
1237 {
1238 $complete= "";
1240 /* Assemble the message array to a plain string */
1241 foreach ($message as $error){
1242 if ($complete == ""){
1243 $complete= $error;
1244 } else {
1245 $complete= "$error<br>$complete";
1246 }
1247 }
1249 /* Fill ERROR variable with nice error dialog */
1250 print_red($complete);
1251 }
1254 function show_ldap_error($message, $addon= "")
1255 {
1256 if (!preg_match("/Success/i", $message)){
1257 if ($addon == ""){
1258 msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1259 } else {
1260 if(!preg_match("/No such object/i",$message)){
1261 msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1262 }
1263 }
1264 return TRUE;
1265 } else {
1266 return FALSE;
1267 }
1268 }
1271 function rewrite($s)
1272 {
1273 global $REWRITE;
1275 foreach ($REWRITE as $key => $val){
1276 $s= preg_replace("/$key/", "$val", $s);
1277 }
1279 return ($s);
1280 }
1283 function dn2base($dn)
1284 {
1285 global $config;
1287 if (get_people_ou() != ""){
1288 $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1289 }
1290 if (get_groups_ou() != ""){
1291 $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1292 }
1293 $base= preg_replace ('/^[^,]+,/i', '', $dn);
1295 return ($base);
1296 }
1300 function check_command($cmdline)
1301 {
1302 $cmd= preg_replace("/ .*$/", "", $cmdline);
1304 /* Check if command exists in filesystem */
1305 if (!file_exists($cmd)){
1306 return (FALSE);
1307 }
1309 /* Check if command is executable */
1310 if (!is_executable($cmd)){
1311 return (FALSE);
1312 }
1314 return (TRUE);
1315 }
1318 function print_header($image, $headline, $info= "")
1319 {
1320 $display= "<div class=\"plugtop\">\n";
1321 $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";
1322 $display.= "</div>\n";
1324 if ($info != ""){
1325 $display.= "<div class=\"pluginfo\">\n";
1326 $display.= "$info";
1327 $display.= "</div>\n";
1328 } else {
1329 $display.= "<div style=\"height:5px;\">\n";
1330 $display.= " ";
1331 $display.= "</div>\n";
1332 }
1333 return ($display);
1334 }
1337 function register_global($name, $object)
1338 {
1339 $_SESSION[$name]= $object;
1340 }
1343 function is_global($name)
1344 {
1345 return isset($_SESSION[$name]);
1346 }
1349 function &get_global($name)
1350 {
1351 return $_SESSION[$name];
1352 }
1355 function range_selector($dcnt,$start,$range=25,$post_var=false)
1356 {
1358 /* Entries shown left and right from the selected entry */
1359 $max_entries= 10;
1361 /* Initialize and take care that max_entries is even */
1362 $output="";
1363 if ($max_entries & 1){
1364 $max_entries++;
1365 }
1367 if((!empty($post_var))&&(isset($_POST[$post_var]))){
1368 $range= $_POST[$post_var];
1369 }
1371 /* Prevent output to start or end out of range */
1372 if ($start < 0 ){
1373 $start= 0 ;
1374 }
1375 if ($start >= $dcnt){
1376 $start= $range * (int)(($dcnt / $range) + 0.5);
1377 }
1379 $numpages= (($dcnt / $range));
1380 if(((int)($numpages))!=($numpages)){
1381 $numpages = (int)$numpages + 1;
1382 }
1383 if ((((int)$numpages) <= 1 )&&(!$post_var)){
1384 return ("");
1385 }
1386 $ppage= (int)(($start / $range) + 0.5);
1389 /* Align selected page to +/- max_entries/2 */
1390 $begin= $ppage - $max_entries/2;
1391 $end= $ppage + $max_entries/2;
1393 /* Adjust begin/end, so that the selected value is somewhere in
1394 the middle and the size is max_entries if possible */
1395 if ($begin < 0){
1396 $end-= $begin + 1;
1397 $begin= 0;
1398 }
1399 if ($end > $numpages) {
1400 $end= $numpages;
1401 }
1402 if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1403 $begin= $end - $max_entries;
1404 }
1406 if($post_var){
1407 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1408 <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1409 }else{
1410 $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1411 }
1413 /* Draw decrement */
1414 if ($start > 0 ) {
1415 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1416 (($start-$range))."\">".
1417 "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1418 }
1420 /* Draw pages */
1421 for ($i= $begin; $i < $end; $i++) {
1422 if ($ppage == $i){
1423 $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1424 validate($_GET['plug'])."&start=".
1425 ($i*$range)."\"> ".($i+1)." </a>";
1426 } else {
1427 $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1428 "&start=".($i*$range)."\"> ".($i+1)." </a>";
1429 }
1430 }
1432 /* Draw increment */
1433 if($start < ($dcnt-$range)) {
1434 $output.=" <a href= \"main.php?plug=".validate($_GET['plug'])."&start=".
1435 (($start+($range)))."\">".
1436 "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1437 }
1439 if(($post_var)&&($numpages)){
1440 $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()'>";
1441 foreach(array(20,50,100,200,"all") as $num){
1442 if($num == "all"){
1443 $var = 10000;
1444 }else{
1445 $var = $num;
1446 }
1447 if($var == $range){
1448 $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1449 }else{
1450 $output.="\n<option value='".$var."'>".$num."</option>";
1451 }
1452 }
1453 $output.= "</select></td></tr></table></div>";
1454 }else{
1455 $output.= "</div>";
1456 }
1458 return($output);
1459 }
1462 function apply_filter()
1463 {
1464 $apply= "";
1466 $apply= ''.
1467 '<table summary="" width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1468 '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1470 return ($apply);
1471 }
1474 function back_to_main()
1475 {
1476 $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1477 _("Back").'"></p><input type="hidden" name="ignore">';
1479 return ($string);
1480 }
1483 function normalize_netmask($netmask)
1484 {
1485 /* Check for notation of netmask */
1486 if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1487 $num= (int)($netmask);
1488 $netmask= "";
1490 for ($byte= 0; $byte<4; $byte++){
1491 $result=0;
1493 for ($i= 7; $i>=0; $i--){
1494 if ($num-- > 0){
1495 $result+= pow(2,$i);
1496 }
1497 }
1499 $netmask.= $result.".";
1500 }
1502 return (preg_replace('/\.$/', '', $netmask));
1503 }
1505 return ($netmask);
1506 }
1509 function netmask_to_bits($netmask)
1510 {
1511 list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1512 $res= 0;
1514 for ($n= 0; $n<4; $n++){
1515 $start= 255;
1516 $name= "nm$n";
1518 for ($i= 0; $i<8; $i++){
1519 if ($start == (int)($$name)){
1520 $res+= 8 - $i;
1521 break;
1522 }
1523 $start-= pow(2,$i);
1524 }
1525 }
1527 return ($res);
1528 }
1531 function recurse($rule, $variables)
1532 {
1533 $result= array();
1535 if (!count($variables)){
1536 return array($rule);
1537 }
1539 reset($variables);
1540 $key= key($variables);
1541 $val= current($variables);
1542 unset ($variables[$key]);
1544 foreach($val as $possibility){
1545 $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1546 $result= array_merge($result, recurse($nrule, $variables));
1547 }
1549 return ($result);
1550 }
1553 function expand_id($rule, $attributes)
1554 {
1555 /* Check for id rule */
1556 if(preg_match('/^id(:|#)\d+$/',$rule)){
1557 return (array("\{$rule}"));
1558 }
1560 /* Check for clean attribute */
1561 if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1562 $rule= preg_replace('/^%/', '', $rule);
1563 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1564 return (array($val));
1565 }
1567 /* Check for attribute with parameters */
1568 if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1569 $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1570 $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1571 $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1572 $start= preg_replace ('/-.*$/', '', $param);
1573 $stop = preg_replace ('/^[^-]+-/', '', $param);
1575 /* Assemble results */
1576 $result= array();
1577 for ($i= $start; $i<= $stop; $i++){
1578 $result[]= substr($val, 0, $i);
1579 }
1580 return ($result);
1581 }
1583 echo "Error in idgen string: don't know how to handle rule $rule.\n";
1584 return (array($rule));
1585 }
1588 function gen_uids($rule, $attributes)
1589 {
1590 global $config;
1592 /* Search for keys and fill the variables array with all
1593 possible values for that key. */
1594 $part= "";
1595 $trigger= false;
1596 $stripped= "";
1597 $variables= array();
1599 for ($pos= 0; $pos < strlen($rule); $pos++){
1601 if ($rule[$pos] == "{" ){
1602 $trigger= true;
1603 $part= "";
1604 continue;
1605 }
1607 if ($rule[$pos] == "}" ){
1608 $variables[$pos]= expand_id($part, $attributes);
1609 $stripped.= "{".$pos."}";
1610 $trigger= false;
1611 continue;
1612 }
1614 if ($trigger){
1615 $part.= $rule[$pos];
1616 } else {
1617 $stripped.= $rule[$pos];
1618 }
1619 }
1621 /* Recurse through all possible combinations */
1622 $proposed= recurse($stripped, $variables);
1624 /* Get list of used ID's */
1625 $used= array();
1626 $ldap= $config->get_ldap_link();
1627 $ldap->cd($config->current['BASE']);
1628 $ldap->search('(uid=*)');
1630 while($attrs= $ldap->fetch()){
1631 $used[]= $attrs['uid'][0];
1632 }
1634 /* Remove used uids and watch out for id tags */
1635 $ret= array();
1636 foreach($proposed as $uid){
1638 /* Check for id tag and modify uid if needed */
1639 if(preg_match('/\{id:\d+}/',$uid)){
1640 $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1642 for ($i= 0; $i < pow(10,$size); $i++){
1643 $number= sprintf("%0".$size."d", $i);
1644 $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1645 if (!in_array($res, $used)){
1646 $uid= $res;
1647 break;
1648 }
1649 }
1650 }
1652 if(preg_match('/\{id#\d+}/',$uid)){
1653 $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1655 while (true){
1656 mt_srand((double) microtime()*1000000);
1657 $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1658 $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1659 if (!in_array($res, $used)){
1660 $uid= $res;
1661 break;
1662 }
1663 }
1664 }
1666 /* Don't assign used ones */
1667 if (!in_array($uid, $used)){
1668 $ret[]= $uid;
1669 }
1670 }
1672 return(array_unique($ret));
1673 }
1676 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1677 Need to convert... */
1678 function to_byte($value) {
1679 $value= strtolower(trim($value));
1681 if(!is_numeric(substr($value, -1))) {
1683 switch(substr($value, -1)) {
1684 case 'g':
1685 $mult= 1073741824;
1686 break;
1687 case 'm':
1688 $mult= 1048576;
1689 break;
1690 case 'k':
1691 $mult= 1024;
1692 break;
1693 }
1695 return ($mult * (int)substr($value, 0, -1));
1696 } else {
1697 return $value;
1698 }
1699 }
1702 function in_array_ics($value, $items)
1703 {
1704 if (!is_array($items)){
1705 return (FALSE);
1706 }
1708 foreach ($items as $item){
1709 if (strcasecmp($item, $value) == 0) {
1710 return (TRUE);
1711 }
1712 }
1714 return (FALSE);
1715 }
1718 function generate_alphabet($count= 10)
1719 {
1720 $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1721 $alphabet= "";
1722 $c= 0;
1724 /* Fill cells with charaters */
1725 for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1726 if ($c == 0){
1727 $alphabet.= "<tr>";
1728 }
1730 $ch = mb_substr($characters, $i, 1, "UTF8");
1731 $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1732 validate($_GET['plug'])."&search=".$ch."\"> ".$ch." </a></td>";
1734 if ($c++ == $count){
1735 $alphabet.= "</tr>";
1736 $c= 0;
1737 }
1738 }
1740 /* Fill remaining cells */
1741 while ($c++ <= $count){
1742 $alphabet.= "<td> </td>";
1743 }
1745 return ($alphabet);
1746 }
1749 function validate($string)
1750 {
1751 return (strip_tags(preg_replace('/\0/', '', $string)));
1752 }
1754 function get_gosa_version()
1755 {
1756 global $svn_revision, $svn_path;
1758 /* Extract informations */
1759 $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1761 /* Release or development? */
1762 if (preg_match('%/gosa/trunk/%', $svn_path)){
1763 return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1764 } else {
1765 $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1766 return (sprintf(_("GOsa $release"), $revision));
1767 }
1768 }
1771 function rmdirRecursive($path, $followLinks=false) {
1772 $dir= opendir($path);
1773 while($entry= readdir($dir)) {
1774 if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1775 unlink($path."/".$entry);
1776 } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1777 rmdirRecursive($path."/".$entry);
1778 }
1779 }
1780 closedir($dir);
1781 return rmdir($path);
1782 }
1784 function scan_directory($path,$sort_desc=false)
1785 {
1786 $ret = false;
1788 /* is this a dir ? */
1789 if(is_dir($path)) {
1791 /* is this path a readable one */
1792 if(is_readable($path)){
1794 /* Get contents and write it into an array */
1795 $ret = array();
1797 $dir = opendir($path);
1799 /* Is this a correct result ?*/
1800 if($dir){
1801 while($fp = readdir($dir))
1802 $ret[]= $fp;
1803 }
1804 }
1805 }
1806 /* Sort array ascending , like scandir */
1807 sort($ret);
1809 /* Sort descending if parameter is sort_desc is set */
1810 if($sort_desc) {
1811 $ret = array_reverse($ret);
1812 }
1814 return($ret);
1815 }
1817 function clean_smarty_compile_dir($directory)
1818 {
1819 global $svn_revision;
1821 if(is_dir($directory) && is_readable($directory)) {
1822 // Set revision filename to REVISION
1823 $revision_file= $directory."/REVISION";
1825 /* Is there a stamp containing the current revision? */
1826 if(!file_exists($revision_file)) {
1827 // create revision file
1828 create_revision($revision_file, $svn_revision);
1829 } else {
1830 # check for "$config->...['CONFIG']/revision" and the
1831 # contents should match the revision number
1832 if(!compare_revision($revision_file, $svn_revision)){
1833 // If revision differs, clean compile directory
1834 foreach(scan_directory($directory) as $file) {
1835 if(($file==".")||($file=="..")) continue;
1836 if( is_file($directory."/".$file) &&
1837 is_writable($directory."/".$file)) {
1838 // delete file
1839 if(!unlink($directory."/".$file)) {
1840 print_red("File ".$directory."/".$file." could not be deleted.");
1841 // This should never be reached
1842 }
1843 } elseif(is_dir($directory."/".$file) &&
1844 is_writable($directory."/".$file)) {
1845 // Just recursively delete it
1846 rmdirRecursive($directory."/".$file);
1847 }
1848 }
1849 // We should now create a fresh revision file
1850 clean_smarty_compile_dir($directory);
1851 } else {
1852 // Revision matches, nothing to do
1853 }
1854 }
1855 } else {
1856 // Smarty compile dir is not accessible
1857 // (Smarty will warn about this)
1858 }
1859 }
1861 function create_revision($revision_file, $revision)
1862 {
1863 $result= false;
1865 if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1866 if($fh= fopen($revision_file, "w")) {
1867 if(fwrite($fh, $revision)) {
1868 $result= true;
1869 }
1870 }
1871 fclose($fh);
1872 } else {
1873 print_red("Can not write to revision file");
1874 }
1876 return $result;
1877 }
1879 function compare_revision($revision_file, $revision)
1880 {
1881 // false means revision differs
1882 $result= false;
1884 if(file_exists($revision_file) && is_readable($revision_file)) {
1885 // Open file
1886 if($fh= fopen($revision_file, "r")) {
1887 // Compare File contents with current revision
1888 if($revision == fread($fh, filesize($revision_file))) {
1889 $result= true;
1890 }
1891 } else {
1892 print_red("Can not open revision file");
1893 }
1894 // Close file
1895 fclose($fh);
1896 }
1898 return $result;
1899 }
1901 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1902 {
1903 $str = ""; // Our return value will be saved in this var
1905 $color = dechex($percentage+150);
1906 $color2 = dechex(150 - $percentage);
1907 $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1909 $progress = (int)(($percentage /100)*$width);
1911 /* Abort printing out percentage, if divs are to small */
1914 /* If theres a better solution for this, use it... */
1915 $str = "
1916 <div style=\" width:".($width)."px;
1917 height:".($height)."px;
1918 background-color:#000000;
1919 padding:1px;\">
1921 <div style=\" width:".($width)."px;
1922 background-color:#$bgcolor;
1923 height:".($height)."px;\">
1925 <div style=\" width:".$progress."px;
1926 height:".$height."px;
1927 background-color:#".$color2.$color2.$color."; \">";
1930 if(($height >10)&&($showvalue)){
1931 $str.= "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
1932 <b>".$percentage."%</b>
1933 </font>";
1934 }
1936 $str.= "</div></div></div>";
1938 return($str);
1939 }
1942 function array_key_ics($ikey, $items)
1943 {
1944 /* Gather keys, make them lowercase */
1945 $tmp= array();
1946 foreach ($items as $key => $value){
1947 $tmp[strtolower($key)]= $key;
1948 }
1950 if (isset($tmp[strtolower($ikey)])){
1951 return($tmp[strtolower($ikey)]);
1952 }
1954 return ("");
1955 }
1958 function array_differs($src, $dst)
1959 {
1960 /* If the count is differing, the arrays differ */
1961 if (count ($src) != count ($dst)){
1962 return (TRUE);
1963 }
1965 /* So the count is the same - lets check the contents */
1966 $differs= FALSE;
1967 foreach($src as $value){
1968 if (!in_array($value, $dst)){
1969 $differs= TRUE;
1970 }
1971 }
1973 return ($differs);
1974 }
1977 function saveFilter($a_filter, $values)
1978 {
1979 if (isset($_POST['regexit'])){
1980 $a_filter["regex"]= $_POST['regexit'];
1982 foreach($values as $type){
1983 if (isset($_POST[$type])) {
1984 $a_filter[$type]= "checked";
1985 } else {
1986 $a_filter[$type]= "";
1987 }
1988 }
1989 }
1991 /* React on alphabet links if needed */
1992 if (isset($_GET['search'])){
1993 $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
1994 if ($s == "**"){
1995 $s= "*";
1996 }
1997 $a_filter['regex']= $s;
1998 }
2000 return ($a_filter);
2001 }
2004 /* Escape all preg_* relevant characters */
2005 function normalizePreg($input)
2006 {
2007 return (addcslashes($input, '[]()|/.*+-'));
2008 }
2011 /* Escape all LDAP filter relevant characters */
2012 function normalizeLdap($input)
2013 {
2014 return (addcslashes($input, '()|'));
2015 }
2018 /* Resturns the difference between to microtime() results in float */
2019 function get_MicroTimeDiff($start , $stop)
2020 {
2021 $a = split("\ ",$start);
2022 $b = split("\ ",$stop);
2024 $secs = $b[1] - $a[1];
2025 $msecs= $b[0] - $a[0];
2027 $ret = (float) ($secs+ $msecs);
2028 return($ret);
2029 }
2032 /* Check if the given department name is valid */
2033 function is_department_name_reserved($name,$base)
2034 {
2035 $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
2036 preg_replace("/ou=(.*),/","\\1",get_people_ou()),
2037 preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
2038 $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
2040 /* Check if name is one of the reserved names */
2041 if(in_array_ics($name,$reservedName)) {
2042 return(true);
2043 }
2045 /* Check all follow combinations if name is in array && parent base == array_key, return false*/
2046 foreach($follwedNames as $key => $names){
2047 if((in_array_ics($name,$names)) && (preg_match($key,$base))){
2048 return(true);
2049 }
2050 }
2051 return(false);
2052 }
2055 function get_base_dir()
2056 {
2057 global $BASE_DIR;
2059 return $BASE_DIR;
2060 }
2063 function obj_is_readable($dn, $object, $attribute)
2064 {
2065 global $ui;
2067 return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2068 }
2071 function obj_is_writable($dn, $object, $attribute)
2072 {
2073 global $ui;
2075 return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2076 }
2079 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2080 {
2081 /* Initialize variables */
2082 $ret = array("count" => 0); // Set count to 0
2083 $next = true; // if false, then skip next loops and return
2084 $cnt = 0; // Current number of loops
2085 $max = 100; // Just for security, prevent looops
2086 $ldap = NULL; // To check if created result a valid
2087 $keep = ""; // save last failed parse string
2089 /* Check each parsed dn in ldap ? */
2090 if($config!==NULL && $verify_in_ldap){
2091 $ldap = $config->get_ldap_link();
2092 }
2094 /* Lets start */
2095 $called = false;
2096 while(preg_match("/,/",$dn) && $next && $cnt < $max){
2098 $cnt ++;
2099 if(!preg_match("/,/",$dn)){
2100 $next = false;
2101 }
2102 $object = preg_replace("/[,].*$/","",$dn);
2103 $dn = preg_replace("/^[^,]+,/","",$dn);
2105 $called = true;
2107 /* Check if current dn is valid */
2108 if($ldap!==NULL){
2109 $ldap->cd($dn);
2110 $ldap->cat($dn,array("dn"));
2111 if($ldap->count()){
2112 $ret[] = $keep.$object;
2113 $keep = "";
2114 }else{
2115 $keep .= $object.",";
2116 }
2117 }else{
2118 $ret[] = $keep.$object;
2119 $keep = "";
2120 }
2121 }
2123 /* No dn was posted */
2124 if($cnt == 0 && !empty($dn)){
2125 $ret[] = $dn;
2126 }
2128 /* Append the rest */
2129 $test = $keep.$dn;
2130 if($called && !empty($test)){
2131 $ret[] = $keep.$dn;
2132 }
2133 $ret['count'] = count($ret) - 1;
2135 return($ret);
2136 }
2138 /* Add "str_split" if this function is missing.
2139 * This function is only available in PHP5
2140 */
2141 if(!function_exists("str_split")){
2142 function str_split($str,$length =1)
2143 {
2144 if($length < 1 ) $length =1;
2146 $ret = array();
2147 for($i = 0 ; $i < strlen($str); $i = $i +$length){
2148 $ret[] = substr($str,$i ,$length);
2149 }
2150 return($ret);
2151 }
2152 }
2155 function get_base_from_hook($dn, $attrib)
2156 {
2157 global $config;
2159 if (isset($config->current['BASE_HOOK'])){
2161 /* Call hook script - if present */
2162 $command= $config->current['BASE_HOOK'];
2164 if ($command != ""){
2165 $command.= " '".LDAP::fix($dn)."' $attrib";
2166 if (check_command($command)){
2167 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2168 exec($command, $output);
2169 if (preg_match("/^[0-9]+$/", $output[0])){
2170 return ($output[0]);
2171 } else {
2172 print_red(_("Warning - base_hook is not available. Using default base."));
2173 return ($config->current['UIDBASE']);
2174 }
2175 } else {
2176 print_red(_("Warning - base_hook is not available. Using default base."));
2177 return ($config->current['UIDBASE']);
2178 }
2180 } else {
2182 print_red(_("Warning - no base_hook defined. Using default base."));
2183 return ($config->current['UIDBASE']);
2185 }
2186 }
2187 }
2189 /* Schema validation functions */
2191 function check_schema_version($class, $version)
2192 {
2193 return preg_match("/\(v$version\)/", $class['DESC']);
2194 }
2196 function check_schema($cfg,$rfc2307bis = FALSE)
2197 {
2198 $messages= array();
2200 /* Get objectclasses */
2201 $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2202 $objectclasses = $ldap->get_objectclasses();
2203 if(count($objectclasses) == 0){
2204 print_red(_("Can't get schema information from server. No schema check possible!"));
2205 }
2207 /* This is the default block used for each entry.
2208 * to avoid unset indexes.
2209 */
2210 $def_check = array("REQUIRED_VERSION" => "0",
2211 "SCHEMA_FILES" => array(),
2212 "CLASSES_REQUIRED" => array(),
2213 "STATUS" => FALSE,
2214 "IS_MUST_HAVE" => FALSE,
2215 "MSG" => "",
2216 "INFO" => "");#_("There is currently no information specified for this schema extension."));
2218 /* The gosa base schema */
2219 $checks['gosaObject'] = $def_check;
2220 $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2221 $checks['gosaObject']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2222 $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2223 $checks['gosaObject']['IS_MUST_HAVE'] = TRUE;
2225 /* GOsa Account class */
2226 $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2227 $checks["gosaAccount"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2228 $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2229 $checks["gosaAccount"]["IS_MUST_HAVE"] = TRUE;
2230 $checks["gosaAccount"]["INFO"] = _("Used to store account specific informations.");
2232 /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2233 $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2234 $checks["gosaLockEntry"]["SCHEMA_FILES"] = array("gosa+samba3.schema","gosa.schema");
2235 $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2236 $checks["gosaLockEntry"]["IS_MUST_HAVE"] = TRUE;
2237 $checks["gosaLockEntry"]["INFO"] = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2239 /* Some other checks */
2240 foreach(array(
2241 "gosaCacheEntry" => array("version" => "2.4"),
2242 "gosaDepartment" => array("version" => "2.4"),
2243 "goFaxAccount" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2244 "goFaxSBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2245 "goFaxRBlock" => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2246 "gosaUserTemplate" => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2247 "gosaMailAccount" => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2248 "gosaProxyAccount" => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2249 "gosaApplication" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2250 "gosaApplicationGroup" => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2251 "GOhard" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2252 "gotoTerminal" => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2253 "goServer" => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2254 "goTerminalServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2255 "goShareServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2256 "goNtpServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2257 "goSyslogServer" => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2258 "goLdapServer" => array("version" => "2.4"),
2259 "goCupsServer" => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2260 "goImapServer" => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3. schema"),
2261 "goKrbServer" => array("version" => "2.4"),
2262 "goFaxServer" => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2263 ) as $name => $values){
2265 $checks[$name] = $def_check;
2266 if(isset($values['version'])){
2267 $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2268 }
2269 if(isset($values['file'])){
2270 $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2271 }
2272 $checks[$name]["CLASSES_REQUIRED"] = array($name);
2273 }
2274 foreach($checks as $name => $value){
2275 foreach($value['CLASSES_REQUIRED'] as $class){
2277 if(!isset($objectclasses[$name])){
2278 $checks[$name]['STATUS'] = FALSE;
2279 if($value['IS_MUST_HAVE']){
2280 $checks[$name]['MSG'] = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2281 }else{
2282 $checks[$name]['MSG'] = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2283 }
2284 }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2285 $checks[$name]['STATUS'] = FALSE;
2287 if($value['IS_MUST_HAVE']){
2288 $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2289 }else{
2290 $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class, $value['REQUIRED_VERSION']);
2291 }
2292 }else{
2293 $checks[$name]['STATUS'] = TRUE;
2294 $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2295 }
2296 }
2297 }
2299 $tmp = $objectclasses;
2301 /* The gosa base schema */
2302 $checks['posixGroup'] = $def_check;
2303 $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2304 $checks['posixGroup']['SCHEMA_FILES'] = array("gosa+samba3.schema","gosa.schema");
2305 $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2306 $checks['posixGroup']['STATUS'] = TRUE;
2307 $checks['posixGroup']['IS_MUST_HAVE'] = TRUE;
2308 $checks['posixGroup']['MSG'] = "";
2309 $checks['posixGroup']['INFO'] = "";
2311 /* Depending on selected rfc2307bis mode, we need different schema configurations */
2312 if(isset($tmp['posixGroup'])){
2314 if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2315 $checks['posixGroup']['STATUS'] = FALSE;
2316 $checks['posixGroup']['MSG'] = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2317 $checks['posixGroup']['INFO'] = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be AUXILIARY");
2318 }
2319 if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2320 $checks['posixGroup']['STATUS'] = FALSE;
2321 $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
2322 $checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
2323 }
2324 }
2326 return($checks);
2327 }
2330 function prepare4mailbody($string)
2331 {
2332 $string = html_entity_decode($string);
2334 $from = array(
2335 "/%/",
2336 "/ /",
2337 "/\n/",
2338 "/\r/",
2339 "/!/",
2340 "/#/",
2341 "/\*/",
2342 "/\//",
2343 "/</",
2344 "/>/",
2345 "/\?/",
2346 "/\"/");
2348 $to = array(
2349 "%25",
2350 "%20",
2351 "%0A",
2352 "%0D",
2353 "%21",
2354 "%23",
2355 "%2A",
2356 "%2F",
2357 "%3C",
2358 "%3E",
2359 "%3F",
2360 "%22");
2362 $string = preg_replace($from,$to,$string);
2364 return($string);
2365 }
2370 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2371 {
2372 $tmp = array(
2373 "de_DE" => "German",
2374 "fr_FR" => "French",
2375 "it_IT" => "Italian",
2376 "es_ES" => "Spanish",
2377 "en_US" => "English",
2378 "nl_NL" => "Dutch",
2379 "pl_PL" => "Polish",
2380 "sv_SE" => "Swedish",
2381 "zh_CN" => "Chinese",
2382 "ru_RU" => "Russian");
2384 $tmp2= array(
2385 "de_DE" => _("German"),
2386 "fr_FR" => _("French"),
2387 "it_IT" => _("Italian"),
2388 "es_ES" => _("Spanish"),
2389 "en_US" => _("English"),
2390 "nl_NL" => _("Dutch"),
2391 "pl_PL" => _("Polish"),
2392 "sv_SE" => _("Swedish"),
2393 "zh_CN" => _("Chinese"),
2394 "ru_RU" => _("Russian"));
2396 $ret = array();
2397 if($languages_in_own_language){
2399 $old_lang = setlocale(LC_ALL, 0);
2400 foreach($tmp as $key => $name){
2401 $lang = $key.".UTF-8";
2402 setlocale(LC_ALL, $lang);
2403 if($strip_region_tag){
2404 $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2405 }else{
2406 $ret[$key] = _($name)." (".$tmp2[$key].")";
2407 }
2408 }
2409 setlocale(LC_ALL, $old_lang);
2410 }else{
2411 foreach($tmp as $key => $name){
2412 if($strip_region_tag){
2413 $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2414 }else{
2415 $ret[$key] = _($name);
2416 }
2417 }
2418 }
2419 return($ret);
2420 }
2423 /* Returns contents of the given POST variable and check magic quotes settings */
2424 function get_post($name)
2425 {
2426 if(!isset($_POST[$name])){
2427 trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2428 return(FALSE);
2429 }
2430 if(get_magic_quotes_gpc()){
2431 return(stripcslashes($_POST[$name]));
2432 }else{
2433 return($_POST[$name]);
2434 }
2435 }
2438 /* Check if $ip1 and $ip2 represents a valid IP range
2439 * returns TRUE in case of a valid range, FALSE in case of an error.
2440 */
2441 function is_ip_range($ip1,$ip2)
2442 {
2443 if(!is_ip($ip1) || !is_ip($ip2)){
2444 return(FALSE);
2445 }else{
2446 $ar1 = split("\.",$ip1);
2447 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2449 $ar2 = split("\.",$ip2);
2450 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2451 return($var1 < $var2);
2452 }
2453 }
2456 /* Check if the specified IP address $address is inside the given network */
2457 function is_in_network($network, $netmask, $address)
2458 {
2459 $nw= split('\.', $network);
2460 $nm= split('\.', $netmask);
2461 $ad= split('\.', $address);
2463 /* Generate inverted netmask */
2464 for ($i= 0; $i<4; $i++){
2465 $ni[$i]= 255-$nm[$i];
2466 $la[$i]= $nw[$i] | $ni[$i];
2467 }
2469 /* Transform to integer */
2470 $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2471 $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2472 $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2474 return ($first < $curr&& $last > $curr);
2475 }
2477 /* Return class name in correct case
2478 * mailMethodkolab => mailMethodKolab ( k => K )
2479 */
2480 function get_correct_class_name($cls)
2481 {
2482 global $class_mapping;
2483 if(isset($class_mapping) && is_array($class_mapping)){
2484 foreach($class_mapping as $class => $file){
2485 if(preg_match("/^".$cls."$/i",$class)){
2486 return($class);
2487 }
2488 }
2489 }
2490 return(FALSE);
2491 }
2493 // change_password, changes the Password, of the given dn
2494 function change_password ($dn, $password, $mode=0, $hash= "")
2495 {
2496 global $config;
2497 $newpass= "";
2499 /* Convert to lower. Methods are lowercase */
2500 $hash= strtolower($hash);
2502 // Get all available encryption Methods
2504 // NON STATIC CALL :)
2505 $tmp = new passwordMethod(get_global('config'));
2506 $available = $tmp->get_available_methods();
2508 // read current password entry for $dn, to detect the encryption Method
2509 $ldap = $config->get_ldap_link();
2510 $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2511 $attrs = $ldap->fetch ();
2513 // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2514 if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2515 $deactivated = TRUE;
2516 }else{
2517 $deactivated = FALSE;
2518 }
2520 /* Is ensure that clear passwords will stay clear */
2521 if($hash == "" && isset($attrs['userPassword'][0]) && !preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0])){
2522 $hash = "clear";
2523 }
2525 // Detect the encryption Method
2526 if ( (isset($attrs['userPassword'][0]) && preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) || $hash != ""){
2528 /* Check for supported algorithm */
2529 mt_srand((double) microtime()*1000000);
2531 /* Extract used hash */
2532 if ($hash == ""){
2533 $hash= strtolower($matches[1]);
2534 }
2536 $test = new $available[$hash]($config);
2538 } else {
2539 // User MD5 by default
2540 $hash= "md5";
2541 $test = new $available['md5']($config);
2542 }
2544 /* Feed password backends with information */
2545 $test->dn= $dn;
2546 $test->attrs= $attrs;
2547 $newpass= $test->generate_hash($password);
2549 // Update shadow timestamp?
2550 if (isset($attrs["shadowLastChange"][0])){
2551 $shadow= (int)(date("U") / 86400);
2552 } else {
2553 $shadow= 0;
2554 }
2556 // Write back modified entry
2557 $ldap->cd($dn);
2558 $attrs= array();
2560 // Not for groups
2561 if ($mode == 0){
2563 if ($shadow != 0){
2564 $attrs['shadowLastChange']= $shadow;
2565 }
2567 // Create SMB Password
2568 $attrs= generate_smb_nt_hash($password);
2569 }
2571 /* Readd ! if user was deactivated */
2572 if($deactivated){
2573 $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2574 }
2576 $attrs['userPassword']= array();
2577 $attrs['userPassword']= $newpass;
2579 $ldap->modify($attrs);
2581 new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2583 if ($ldap->error != 'Success') {
2584 print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2585 $ldap->get_error()));
2586 } else {
2588 /* Run backend method for change/create */
2589 $test->set_password($password);
2591 /* Find postmodify entries for this class */
2592 $command= $config->search("password", "POSTMODIFY",array('menu'));
2594 if ($command != ""){
2595 /* Walk through attribute list */
2596 $command= preg_replace("/%userPassword/", $password, $command);
2597 $command= preg_replace("/%dn/", $dn, $command);
2599 if (check_command($command)){
2600 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2601 exec($command);
2602 } else {
2603 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2604 print_red ($message);
2605 }
2606 }
2607 }
2608 }
2609 // Return something like array['sambaLMPassword']= "lalla..."
2610 function generate_smb_nt_hash($password)
2611 {
2612 global $config;
2613 $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2614 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2616 exec($tmp, $ar);
2617 flush();
2618 reset($ar);
2619 $hash= current($ar);
2620 if ($hash == "")
2621 {
2622 print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2623 }
2624 else
2625 {
2626 list($lm,$nt)= split (":", trim($hash));
2628 if ($config->current['SAMBAVERSION'] == 3)
2629 {
2630 $attrs['sambaLMPassword']= $lm;
2631 $attrs['sambaNTPassword']= $nt;
2632 $attrs['sambaPwdLastSet']= date('U');
2633 $attrs['sambaBadPasswordCount']= "0";
2634 $attrs['sambaBadPasswordTime']= "0";
2635 } else {
2636 $attrs['lmPassword']= $lm;
2637 $attrs['ntPassword']= $nt;
2638 $attrs['pwdLastSet']= date('U');
2639 }
2640 return($attrs);
2641 }
2642 }
2644 function crypt_single($string,$enc_type )
2645 {
2646 return( passwordMethod::crypt_single_str($string,$enc_type));
2647 }
2650 function getEntryCSN($dn)
2651 {
2652 global $config;
2653 if(empty($dn) || !is_object($config)){
2654 return("");
2655 }
2657 /* Get attribute that we should use as serial number */
2658 if(isset($config->current['UNIQ_IDENTIFIER'])){
2659 $attr = $config->current['UNIQ_IDENTIFIER'];
2660 }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
2661 $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
2662 }
2663 if(!empty($attr)){
2664 $ldap = $config->get_ldap_link();
2665 $ldap->cat($dn,array($attr));
2666 $csn = $ldap->fetch();
2667 if(isset($csn[$attr][0])){
2668 return($csn[$attr][0]);
2669 }
2670 }
2671 return("");
2672 }
2674 /* This function returns the offset for the default timezone.
2675 * $stamp is used to detect summer or winter time.
2676 * In case of PHP5, the integrated timezone functions are used.
2677 * For PHP4 we query an array for offset and add summertime hour.
2678 */
2679 function get_default_timezone($stamp = NULL)
2680 {
2681 global $config;
2682 $tz ="";
2684 /* Default return value if zone could not be detected */
2685 $zone = array("name" => "unconfigured", "value" => 0);
2687 /* Use current timestamp if $stamp is not set */
2688 if($stamp === NULL){
2689 $stamp = time();
2690 }
2692 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2693 if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2695 /* Get zonename */
2696 if(isset($config->current['TIMEZONE'])){
2697 $tz = $config->current['TIMEZONE'];
2698 }else{
2699 $tz = $config->data['MAIN']['TIMEZONE'];
2700 }
2702 if(!@date_default_timezone_set($tz)){
2703 print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2704 }
2705 $tz_delta = date("Z", $stamp);
2706 $tz_delta = $tz_delta / 3600 ;
2707 return(array("name" => $tz, "value" => $tz_delta));
2709 }
2710 return($zone);
2711 }
2714 /* Return zone informations */
2715 function _get_tz_zones()
2716 {
2717 $timezones = array(
2718 'Africa/Abidjan' => 0,
2719 'Africa/Accra' => 0,
2720 'Africa/Addis_Ababa' => 10800,
2721 'Africa/Algiers' => 3600,
2722 'Africa/Asmera' => 10800,
2723 'Africa/Bamako' => 0,
2724 'Africa/Bangui' => 3600,
2725 'Africa/Banjul' => 0,
2726 'Africa/Bissau' => 0,
2727 'Africa/Blantyre' => 7200,
2728 'Africa/Brazzaville' => 3600,
2729 'Africa/Bujumbura' => 7200,
2730 'Africa/Cairo' => 7200,
2731 'Africa/Casablanca' => 0,
2732 'Africa/Ceuta' => 3600,
2733 'Africa/Conakry' => 0,
2734 'Africa/Dakar' => 0,
2735 'Africa/Dar_es_Salaam' => 10800,
2736 'Africa/Djibouti' => 10800,
2737 'Africa/Douala' => 3600,
2738 'Africa/El_Aaiun' => 0,
2739 'Africa/Freetown' => 0,
2740 'Africa/Gaborone' => 7200,
2741 'Africa/Harare' => 7200,
2742 'Africa/Johannesburg' => 7200,
2743 'Africa/Kampala' => 10800,
2744 'Africa/Khartoum' => 10800,
2745 'Africa/Kigali' => 7200,
2746 'Africa/Kinshasa' => 3600,
2747 'Africa/Lagos' => 3600,
2748 'Africa/Libreville' => 3600,
2749 'Africa/Lome' => 0,
2750 'Africa/Luanda' => 3600,
2751 'Africa/Lubumbashi' => 7200,
2752 'Africa/Lusaka' => 7200,
2753 'Africa/Malabo' => 3600,
2754 'Africa/Maputo' => 7200,
2755 'Africa/Maseru' => 7200,
2756 'Africa/Mbabane' => 7200,
2757 'Africa/Mogadishu' => 10800,
2758 'Africa/Monrovia' => 0,
2759 'Africa/Nairobi' => 10800,
2760 'Africa/Ndjamena' => 3600,
2761 'Africa/Niamey' => 3600,
2762 'Africa/Nouakchott' => 0,
2763 'Africa/Ouagadougou' => 0,
2764 'Africa/Porto-Novo' => 3600,
2765 'Africa/Sao_Tome' => 0,
2766 'Africa/Timbuktu' => 0,
2767 'Africa/Tripoli' => 7200,
2768 'Africa/Tunis' => 3600,
2769 'Africa/Windhoek' => 3600,
2770 'America/Adak' => -36000,
2771 'America/Anchorage' => -32400,
2772 'America/Anguilla' => -14400,
2773 'America/Antigua' => -14400,
2774 'America/Araguaina' => -10800,
2775 'America/Argentina/Buenos_Aires' => 0,
2776 'America/Argentina/Catamarca' => 0,
2777 'America/Argentina/ComodRivadavia' => 0,
2778 'America/Argentina/Cordoba' => 0,
2779 'America/Argentina/Jujuy' => 0,
2780 'America/Argentina/La_Rioja' => 0,
2781 'America/Argentina/Mendoza' => 0,
2782 'America/Argentina/Rio_Gallegos' => 0,
2783 'America/Argentina/San_Juan' => 0,
2784 'America/Argentina/Tucuman' => 0,
2785 'America/Argentina/Ushuaia' => 0,
2786 'America/Aruba' => -14400,
2787 'America/Asuncion' => -14400,
2788 'America/Atikokan' => 0,
2789 'America/Atka' => -36000,
2790 'America/Bahia' => 0,
2791 'America/Barbados' => -14400,
2792 'America/Belem' => -10800,
2793 'America/Belize' => -21600,
2794 'America/Blanc-Sablon' => 0,
2795 'America/Boa_Vista' => -14400,
2796 'America/Bogota' => -18000,
2797 'America/Boise' => -25200,
2798 'America/Buenos_Aires' => -10800,
2799 'America/Cambridge_Bay' => -25200,
2800 'America/Campo_Grande' => 0,
2801 'America/Cancun' => -21600,
2802 'America/Caracas' => -14400,
2803 'America/Catamarca' => -10800,
2804 'America/Cayenne' => -10800,
2805 'America/Cayman' => -18000,
2806 'America/Chicago' => -21600,
2807 'America/Chihuahua' => -25200,
2808 'America/Coral_Harbour' => 0,
2809 'America/Cordoba' => -10800,
2810 'America/Costa_Rica' => -21600,
2811 'America/Cuiaba' => -14400,
2812 'America/Curacao' => -14400,
2813 'America/Danmarkshavn' => 0,
2814 'America/Dawson' => -28800,
2815 'America/Dawson_Creek' => -25200,
2816 'America/Denver' => -25200,
2817 'America/Detroit' => -18000,
2818 'America/Dominica' => -14400,
2819 'America/Edmonton' => -25200,
2820 'America/Eirunepe' => -18000,
2821 'America/El_Salvador' => -21600,
2822 'America/Ensenada' => -28800,
2823 'America/Fort_Wayne' => -18000,
2824 'America/Fortaleza' => -10800,
2825 'America/Glace_Bay' => -14400,
2826 'America/Godthab' => -10800,
2827 'America/Goose_Bay' => -14400,
2828 'America/Grand_Turk' => -18000,
2829 'America/Grenada' => -14400,
2830 'America/Guadeloupe' => -14400,
2831 'America/Guatemala' => -21600,
2832 'America/Guayaquil' => -18000,
2833 'America/Guyana' => -14400,
2834 'America/Halifax' => -14400,
2835 'America/Havana' => -18000,
2836 'America/Hermosillo' => -25200,
2837 'America/Indiana/Indianapolis' => -18000,
2838 'America/Indiana/Knox' => -18000,
2839 'America/Indiana/Marengo' => -18000,
2840 'America/Indiana/Petersburg' => 0,
2841 'America/Indiana/Vevay' => -18000,
2842 'America/Indiana/Vincennes' => 0,
2843 'America/Indianapolis' => -18000,
2844 'America/Inuvik' => -25200,
2845 'America/Iqaluit' => -18000,
2846 'America/Jamaica' => -18000,
2847 'America/Jujuy' => -10800,
2848 'America/Juneau' => -32400,
2849 'America/Kentucky/Louisville' => -18000,
2850 'America/Kentucky/Monticello' => -18000,
2851 'America/Knox_IN' => -18000,
2852 'America/La_Paz' => -14400,
2853 'America/Lima' => -18000,
2854 'America/Los_Angeles' => -28800,
2855 'America/Louisville' => -18000,
2856 'America/Maceio' => -10800,
2857 'America/Managua' => -21600,
2858 'America/Manaus' => -14400,
2859 'America/Martinique' => -14400,
2860 'America/Mazatlan' => -25200,
2861 'America/Mendoza' => -10800,
2862 'America/Menominee' => -21600,
2863 'America/Merida' => -21600,
2864 'America/Mexico_City' => -21600,
2865 'America/Miquelon' => -10800,
2866 'America/Moncton' => 0,
2867 'America/Monterrey' => -21600,
2868 'America/Montevideo' => -10800,
2869 'America/Montreal' => -18000,
2870 'America/Montserrat' => -14400,
2871 'America/Nassau' => -18000,
2872 'America/New_York' => -18000,
2873 'America/Nipigon' => -18000,
2874 'America/Nome' => -32400,
2875 'America/Noronha' => -7200,
2876 'America/North_Dakota/Center' => -21600,
2877 'America/North_Dakota/New_Salem' => 0,
2878 'America/Panama' => -18000,
2879 'America/Pangnirtung' => -18000,
2880 'America/Paramaribo' => -10800,
2881 'America/Phoenix' => -25200,
2882 'America/Port-au-Prince' => -18000,
2883 'America/Port_of_Spain' => -14400,
2884 'America/Porto_Acre' => -18000,
2885 'America/Porto_Velho' => -14400,
2886 'America/Puerto_Rico' => -14400,
2887 'America/Rainy_River' => -21600,
2888 'America/Rankin_Inlet' => -21600,
2889 'America/Recife' => -10800,
2890 'America/Regina' => -21600,
2891 'America/Rio_Branco' => -18000,
2892 'America/Rosario' => -10800,
2893 'America/Santiago' => -14400,
2894 'America/Santo_Domingo' => -14400,
2895 'America/Sao_Paulo' => -10800,
2896 'America/Scoresbysund' => -3600,
2897 'America/Shiprock' => -25200,
2898 'America/St_Johns' => -12600,
2899 'America/St_Kitts' => -14400,
2900 'America/St_Lucia' => -14400,
2901 'America/St_Thomas' => -14400,
2902 'America/St_Vincent' => -14400,
2903 'America/Swift_Current' => -21600,
2904 'America/Tegucigalpa' => -21600,
2905 'America/Thule' => -14400,
2906 'America/Thunder_Bay' => -18000,
2907 'America/Tijuana' => -28800,
2908 'America/Toronto' => 0,
2909 'America/Tortola' => -14400,
2910 'America/Vancouver' => -28800,
2911 'America/Virgin' => -14400,
2912 'America/Whitehorse' => -28800,
2913 'America/Winnipeg' => -21600,
2914 'America/Yakutat' => -32400,
2915 'America/Yellowknife' => -25200,
2916 'Antarctica/Casey' => 28800,
2917 'Antarctica/Davis' => 25200,
2918 'Antarctica/DumontDUrville' => 36000,
2919 'Antarctica/Mawson' => 21600,
2920 'Antarctica/McMurdo' => 43200,
2921 'Antarctica/Palmer' => -14400,
2922 'Antarctica/Rothera' => 0,
2923 'Antarctica/South_Pole' => 43200,
2924 'Antarctica/Syowa' => 10800,
2925 'Antarctica/VostokArctic/Longyearbyen' => 0,
2926 'Asia/Aden' => 10800,
2927 'Asia/Almaty' => 21600,
2928 'Asia/Amman' => 7200,
2929 'Asia/Anadyr' => 43200,
2930 'Asia/Aqtau' => 14400,
2931 'Asia/Aqtobe' => 18000,
2932 'Asia/Ashgabat' => 18000,
2933 'Asia/Ashkhabad' => 18000,
2934 'Asia/Baghdad' => 10800,
2935 'Asia/Bahrain' => 10800,
2936 'Asia/Baku' => 14400,
2937 'Asia/Bangkok' => 25200,
2938 'Asia/Beirut' => 7200,
2939 'Asia/Bishkek' => 18000,
2940 'Asia/Brunei' => 28800,
2941 'Asia/Calcutta' => 19800,
2942 'Asia/Choibalsan' => 32400,
2943 'Asia/Chongqing' => 28800,
2944 'Asia/Chungking' => 28800,
2945 'Asia/Colombo' => 21600,
2946 'Asia/Dacca' => 21600,
2947 'Asia/Damascus' => 7200,
2948 'Asia/Dhaka' => 21600,
2949 'Asia/Dili' => 32400,
2950 'Asia/Dubai' => 14400,
2951 'Asia/Dushanbe' => 18000,
2952 'Asia/Gaza' => 7200,
2953 'Asia/Harbin' => 28800,
2954 'Asia/Hong_Kong' => 28800,
2955 'Asia/Hovd' => 25200,
2956 'Asia/Irkutsk' => 28800,
2957 'Asia/Istanbul' => 7200,
2958 'Asia/Jakarta' => 25200,
2959 'Asia/Jayapura' => 32400,
2960 'Asia/Jerusalem' => 7200,
2961 'Asia/Kabul' => 16200,
2962 'Asia/Kamchatka' => 43200,
2963 'Asia/Karachi' => 18000,
2964 'Asia/Kashgar' => 28800,
2965 'Asia/Katmandu' => 20700,
2966 'Asia/Krasnoyarsk' => 25200,
2967 'Asia/Kuala_Lumpur' => 28800,
2968 'Asia/Kuching' => 28800,
2969 'Asia/Kuwait' => 10800,
2970 'Asia/Macao' => 28800,
2971 'Asia/Macau' => 0,
2972 'Asia/Magadan' => 39600,
2973 'Asia/Makassar' => 0,
2974 'Asia/Manila' => 28800,
2975 'Asia/Muscat' => 14400,
2976 'Asia/Nicosia' => 7200,
2977 'Asia/Novosibirsk' => 21600,
2978 'Asia/Omsk' => 21600,
2979 'Asia/Oral' => 0,
2980 'Asia/Phnom_Penh' => 25200,
2981 'Asia/Pontianak' => 25200,
2982 'Asia/Pyongyang' => 32400,
2983 'Asia/Qatar' => 10800,
2984 'Asia/Qyzylorda' => 0,
2985 'Asia/Rangoon' => 23400,
2986 'Asia/Riyadh' => 10800,
2987 'Asia/Saigon' => 25200,
2988 'Asia/Sakhalin' => 36000,
2989 'Asia/Samarkand' => 18000,
2990 'Asia/Seoul' => 32400,
2991 'Asia/Shanghai' => 28800,
2992 'Asia/Singapore' => 28800,
2993 'Asia/Taipei' => 28800,
2994 'Asia/Tashkent' => 18000,
2995 'Asia/Tbilisi' => 14400,
2996 'Asia/Tehran' => 12600,
2997 'Asia/Tel_Aviv' => 7200,
2998 'Asia/Thimbu' => 21600,
2999 'Asia/Thimphu' => 21600,
3000 'Asia/Tokyo' => 32400,
3001 'Asia/Ujung_Pandang' => 28800,
3002 'Asia/Ulaanbaatar' => 28800,
3003 'Asia/Ulan_Bator' => 28800,
3004 'Asia/Urumqi' => 28800,
3005 'Asia/Vientiane' => 25200,
3006 'Asia/Vladivostok' => 36000,
3007 'Asia/Yakutsk' => 32400,
3008 'Asia/Yekaterinburg' => 18000,
3009 'Asia/YerevanAtlantic/Azores' => 0,
3010 'Atlantic/Bermuda' => -14400,
3011 'Atlantic/Canary' => 0,
3012 'Atlantic/Cape_Verde' => -3600,
3013 'Atlantic/Faeroe' => 0,
3014 'Atlantic/Jan_Mayen' => 3600,
3015 'Atlantic/Madeira' => 0,
3016 'Atlantic/Reykjavik' => 0,
3017 'Atlantic/South_Georgia' => -7200,
3018 'Atlantic/St_Helena' => 0,
3019 'Atlantic/Stanley' => -14400,
3020 'Australia/ACT' => 36000,
3021 'Australia/Adelaide' => 34200,
3022 'Australia/Brisbane' => 36000,
3023 'Australia/Broken_Hill' => 34200,
3024 'Australia/Canberra' => 36000,
3025 'Australia/Currie' => 0,
3026 'Australia/Darwin' => 34200,
3027 'Australia/Hobart' => 36000,
3028 'Australia/LHI' => 37800,
3029 'Australia/Lindeman' => 36000,
3030 'Australia/Lord_Howe' => 37800,
3031 'Australia/Melbourne' => 36000,
3032 'Australia/NSW' => 36000,
3033 'Australia/North' => 34200,
3034 'Australia/Perth' => 28800,
3035 'Australia/Queensland' => 36000,
3036 'Australia/South' => 34200,
3037 'Australia/Sydney' => 36000,
3038 'Australia/Tasmania' => 36000,
3039 'Australia/Victoria' => 36000,
3040 'Australia/West' => 28800,
3041 'Australia/Yancowinna' => 34200,
3042 'Europe/Amsterdam' => 3600,
3043 'Europe/Andorra' => 3600,
3044 'Europe/Athens' => 7200,
3045 'Europe/Belfast' => 0,
3046 'Europe/Belgrade' => 3600,
3047 'Europe/Berlin' => 3600,
3048 'Europe/Bratislava' => 3600,
3049 'Europe/Brussels' => 3600,
3050 'Europe/Bucharest' => 7200,
3051 'Europe/Budapest' => 3600,
3052 'Europe/Chisinau' => 7200,
3053 'Europe/Copenhagen' => 3600,
3054 'Europe/Dublin' => 0,
3055 'Europe/Gibraltar' => 3600,
3056 'Europe/Guernsey' => 0,
3057 'Europe/Helsinki' => 7200,
3058 'Europe/Isle_of_Man' => 0,
3059 'Europe/Istanbul' => 7200,
3060 'Europe/Jersey' => 0,
3061 'Europe/Kaliningrad' => 7200,
3062 'Europe/Kiev' => 7200,
3063 'Europe/Lisbon' => 0,
3064 'Europe/Ljubljana' => 3600,
3065 'Europe/London' => 0,
3066 'Europe/Luxembourg' => 3600,
3067 'Europe/Madrid' => 3600,
3068 'Europe/Malta' => 3600,
3069 'Europe/Mariehamn' => 0,
3070 'Europe/Minsk' => 7200,
3071 'Europe/Monaco' => 3600,
3072 'Europe/Moscow' => 10800,
3073 'Europe/Nicosia' => 7200,
3074 'Europe/Oslo' => 3600,
3075 'Europe/Paris' => 3600,
3076 'Europe/Prague' => 3600,
3077 'Europe/Riga' => 7200,
3078 'Europe/Rome' => 3600,
3079 'Europe/Samara' => 14400,
3080 'Europe/San_Marino' => 3600,
3081 'Europe/Sarajevo' => 3600,
3082 'Europe/Simferopol' => 7200,
3083 'Europe/Skopje' => 3600,
3084 'Europe/Sofia' => 7200,
3085 'Europe/Stockholm' => 3600,
3086 'Europe/Tallinn' => 7200,
3087 'Europe/Tirane' => 3600,
3088 'Europe/Tiraspol' => 7200,
3089 'Europe/Uzhgorod' => 7200,
3090 'Europe/Vaduz' => 3600,
3091 'Europe/Vatican' => 3600,
3092 'Europe/Vienna' => 3600,
3093 'Europe/Vilnius' => 7200,
3094 'Europe/Volgograd' => 0,
3095 'Europe/Warsaw' => 3600,
3096 'Europe/Zagreb' => 3600,
3097 'Europe/Zaporozhye' => 7200,
3098 'Europe/Zurich' => 3600,
3099 'Indian/Antananarivo' => 10800,
3100 'Indian/Chagos' => 21600,
3101 'Indian/Christmas' => 25200,
3102 'Indian/Cocos' => 23400,
3103 'Indian/Comoro' => 10800,
3104 'Indian/Kerguelen' => 18000,
3105 'Indian/Mahe' => 14400,
3106 'Indian/Maldives' => 18000,
3107 'Indian/Mauritius' => 14400,
3108 'Indian/Mayotte' => 10800,
3109 'Indian/Reunion' => 14400,
3110 'Pacific/Apia' => -39600,
3111 'Pacific/Auckland' => 43200,
3112 'Pacific/Chatham' => 45900,
3113 'Pacific/Easter' => -21600,
3114 'Pacific/Efate' => 39600,
3115 'Pacific/Enderbury' => 46800,
3116 'Pacific/Fakaofo' => -36000,
3117 'Pacific/Fiji' => 43200,
3118 'Pacific/Funafuti' => 43200,
3119 'Pacific/Galapagos' => -21600,
3120 'Pacific/Gambier' => -32400,
3121 'Pacific/Guadalcanal' => 39600,
3122 'Pacific/Guam' => 36000,
3123 'Pacific/Honolulu' => -36000,
3124 'Pacific/Johnston' => -36000,
3125 'Pacific/Kiritimati' => 50400,
3126 'Pacific/Kosrae' => 39600,
3127 'Pacific/Kwajalein' => 43200,
3128 'Pacific/Majuro' => 43200,
3129 'Pacific/Marquesas' => -34200,
3130 'Pacific/Midway' => -39600,
3131 'Pacific/Nauru' => 43200,
3132 'Pacific/Niue' => -39600,
3133 'Pacific/Norfolk' => 41400,
3134 'Pacific/Noumea' => 39600,
3135 'Pacific/Pago_Pago' => -39600,
3136 'Pacific/Palau' => 32400,
3137 'Pacific/Pitcairn' => -28800,
3138 'Pacific/Ponape' => 39600,
3139 'Pacific/Port_Moresby' => 36000,
3140 'Pacific/Rarotonga' => -36000,
3141 'Pacific/Saipan' => 36000,
3142 'Pacific/Samoa' => -39600,
3143 'Pacific/Tahiti' => -36000,
3144 'Pacific/Tarawa' => 43200,
3145 'Pacific/Tongatapu' => 46800,
3146 'Pacific/Truk' => 36000,
3147 'Pacific/Wake' => 43200,
3148 'Pacific/Wallis' => 43200,
3149 'Pacific/Yap' => 36000 );
3151 $dst_timezones = array (
3152 'America/Adak' => 1,
3153 'America/Atka' => 1,
3154 'America/Anchorage' => 1,
3155 'America/Juneau' => 1,
3156 'America/Nome' => 1,
3157 'America/Yakutat' => 1,
3158 'America/Dawson' => 1,
3159 'America/Ensenada' => 1,
3160 'America/Los_Angeles' => 1,
3161 'America/Tijuana' => 1,
3162 'America/Vancouver' => 1,
3163 'America/Whitehorse' => 1,
3164 'America/Boise' => 1,
3165 'America/Cambridge_Bay' => 1,
3166 'America/Chihuahua' => 1,
3167 'America/Denver' => 1,
3168 'America/Edmonton' => 1,
3169 'America/Inuvik' => 1,
3170 'America/Mazatlan' => 1,
3171 'America/Shiprock' => 1,
3172 'America/Yellowknife' => 1,
3173 'America/Cancun' => 1,
3174 'America/Chicago' => 1,
3175 'America/Menominee' => 1,
3176 'America/Merida' => 1,
3177 'America/Monterrey' => 1,
3178 'America/North_Dakota/Center' => 1,
3179 'America/Rainy_River' => 1,
3180 'America/Rankin_Inlet' => 1,
3181 'America/Winnipeg' => 1,
3182 'Pacific/Easter' => 1,
3183 'America/Detroit' => 1,
3184 'America/Grand_Turk' => 1,
3185 'America/Havana' => 1,
3186 'America/Iqaluit' => 1,
3187 'America/Kentucky/Louisville' => 1,
3188 'America/Kentucky/Monticello' => 1,
3189 'America/Louisville' => 1,
3190 'America/Montreal' => 1,
3191 'America/Nassau' => 1,
3192 'America/New_York' => 1,
3193 'America/Nipigon' => 1,
3194 'America/Pangnirtung' => 1,
3195 'America/Thunder_Bay' => 1,
3196 'America/Asuncion' => 1,
3197 'America/Cuiaba' => 1,
3198 'America/Glace_Bay' => 1,
3199 'America/Goose_Bay' => 1,
3200 'America/Halifax' => 1,
3201 'America/Santiago' => 1,
3202 'Antarctica/Palmer' => 1,
3203 'Atlantic/Bermuda' => 1,
3204 'Atlantic/Stanley' => 1,
3205 'America/St_Johns' => 1,
3206 'America/Araguaina' => 1,
3207 'America/Fortaleza' => 1,
3208 'America/Godthab' => 1,
3209 'America/Maceio' => 1,
3210 'America/Miquelon' => 1,
3211 'America/Recife' => 1,
3212 'America/Sao_Paulo' => 1,
3213 'America/Scoresbysund' => 1,
3214 'Atlantic/Canary' => 1,
3215 'Atlantic/Faeroe' => 1,
3216 'Atlantic/Madeira' => 1,
3217 'Europe/Belfast' => 1,
3218 'Europe/Dublin' => 1,
3219 'Europe/Lisbon' => 1,
3220 'Europe/London' => 1,
3221 'Africa/Ceuta' => 1,
3222 'Africa/Windhoek' => 1,
3223 'Atlantic/Jan_Mayen' => 1,
3224 'Europe/Amsterdam' => 1,
3225 'Europe/Andorra' => 1,
3226 'Europe/Belgrade' => 1,
3227 'Europe/Berlin' => 1,
3228 'Europe/Bratislava' => 1,
3229 'Europe/Brussels' => 1,
3230 'Europe/Budapest' => 1,
3231 'Europe/Copenhagen' => 1,
3232 'Europe/Gibraltar' => 1,
3233 'Europe/Ljubljana' => 1,
3234 'Europe/Luxembourg' => 1,
3235 'Europe/Madrid' => 1,
3236 'Europe/Malta' => 1,
3237 'Europe/Monaco' => 1,
3238 'Europe/Oslo' => 1,
3239 'Europe/Paris' => 1,
3240 'Europe/Prague' => 1,
3241 'Europe/Rome' => 1,
3242 'Europe/San_Marino' => 1,
3243 'Europe/Sarajevo' => 1,
3244 'Europe/Skopje' => 1,
3245 'Europe/Stockholm' => 1,
3246 'Europe/Tirane' => 1,
3247 'Europe/Vaduz' => 1,
3248 'Europe/Vatican' => 1,
3249 'Europe/Vienna' => 1,
3250 'Europe/Warsaw' => 1,
3251 'Europe/Zagreb' => 1,
3252 'Europe/Zurich' => 1,
3253 'Africa/Cairo' => 1,
3254 'Asia/Amman' => 1,
3255 'Asia/Beirut' => 1,
3256 'Asia/Damascus' => 1,
3257 'Asia/Gaza' => 1,
3258 'Asia/Istanbul' => 1,
3259 'Asia/Jerusalem' => 1,
3260 'Asia/Nicosia' => 1,
3261 'Asia/Tel_Aviv' => 1,
3262 'Europe/Athens' => 1,
3263 'Europe/Bucharest' => 1,
3264 'Europe/Chisinau' => 1,
3265 'Europe/Helsinki' => 1,
3266 'Europe/Istanbul' => 1,
3267 'Europe/Kaliningrad' => 1,
3268 'Europe/Kiev' => 1,
3269 'Europe/Minsk' => 1,
3270 'Europe/Nicosia' => 1,
3271 'Europe/Riga' => 1,
3272 'Europe/Simferopol' => 1,
3273 'Europe/Sofia' => 1,
3274 'Europe/Tiraspol' => 1,
3275 'Europe/Uzhgorod' => 1,
3276 'Europe/Zaporozhye' => 1,
3277 'Asia/Baghdad' => 1,
3278 'Europe/Moscow' => 1,
3279 'Asia/Tehran' => 1,
3280 'Asia/Aqtau' => 1,
3281 'Asia/Baku' => 1,
3282 'Asia/Tbilisi' => 1,
3283 'Europe/Samara' => 1,
3284 'Asia/Aqtobe' => 1,
3285 'Asia/Bishkek' => 1,
3286 'Asia/Yekaterinburg' => 1,
3287 'Asia/Almaty' => 1,
3288 'Asia/Novosibirsk' => 1,
3289 'Asia/Omsk' => 1,
3290 'Asia/Krasnoyarsk' => 1,
3291 'Asia/Irkutsk' => 1,
3292 'Asia/Yakutsk' => 1,
3293 'Australia/Adelaide' => 1,
3294 'Australia/Broken_Hill' => 1,
3295 'Australia/South' => 1,
3296 'Australia/Yancowinna' => 1,
3297 'Asia/Sakhalin' => 1,
3298 'Asia/Vladivostok' => 1,
3299 'Australia/ACT' => 1,
3300 'Australia/Canberra' => 1,
3301 'Australia/Hobart' => 1,
3302 'Australia/Melbourne' => 1,
3303 'Australia/NSW' => 1,
3304 'Australia/Sydney' => 1,
3305 'Australia/Tasmania' => 1,
3306 'Australia/Victoria' => 1,
3307 'Australia/LHI' => 1,
3308 'Australia/Lord_Howe' => 1,
3309 'Asia/Magadan' => 1,
3310 'Antarctica/McMurdo' => 1,
3311 'Antarctica/South_Pole' => 1,
3312 'Asia/Anadyr' => 1,
3313 'Asia/Kamchatka' => 1,
3314 'Pacific/Auckland' => 1,
3315 'Pacific/Chatham' => 1,
3316 );
3317 return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3318 }
3319 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3320 ?>