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