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