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