Code

Allow lock messages for multiple entries at once.
[gosa.git] / include / functions.inc
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     }
104 /* Create seed with microseconds */
105 function make_seed() {
106   list($usec, $sec) = explode(' ', microtime());
107   return (float) $sec + ((float) $usec * 100000);
111 /* Debug level action */
112 function DEBUG($level, $line, $function, $file, $data, $info="")
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   }
132 function get_browser_language()
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   }
151  
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'));
166 /* Rewrite ui object to another dn */
167 function change_ui_dn($dn, $newdn)
169   $ui= $_SESSION['ui'];
170   if ($ui->dn == $dn){
171     $ui->dn= $newdn;
172     $_SESSION['ui']= $ui;
173   }
177 /* Return theme path for specified file */
178 function get_template_path($filename= '', $plugin= FALSE, $path= "")
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   }
229 function array_remove_entries($needles, $haystack)
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);
244 function gosa_array_merge($ar1,$ar2)
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   }
255 function gosa_log ($message)
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");
275 function ldap_init ($server, $base, $binddn='', $pass='')
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;
295 function ldap_login_user ($username, $password)
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);
355 function ldap_expired_account($config, $userdn, $username)
357     $ldap= $config->get_ldap_link();
358     $ldap->cat($userdn);
359     $attrs= $ldap->fetch();
360     
361     /* default value no errors */
362     $expired = 0;
363     
364     $sExpire = 0;
365     $sLastChange = 0;
366     $sMax = 0;
367     $sMin = 0;
368     $sInactive = 0;
369     $sWarning = 0;
370     
371     $current= date("U");
372     
373     $current= floor($current /60 /60 /24);
374     
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       }
385       
386       if(isset($attrs['shadowLastChange'][0])){
387         $sLastChange= $attrs['shadowLastChange'][0];
388       } else {
389         $sLastChange = 0;
390       }
391       
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       }
403       
404       if(isset($attrs['shadowInactive'][0])){
405         $sInactive= $attrs['shadowInactive'][0];
406       } else {
407         $sInactive = 0;
408       }
409       
410       if(isset($attrs['shadowWarning'][0])){
411         $sWarning= $attrs['shadowWarning'][0];
412       } else {
413         $sWarning = 0;
414       }
415       
416       /* is the account locked */
417       /* shadowExpire + shadowInactive (option) */
418       if($sExpire >0){
419         if($current >= ($sExpire+$sInactive)){
420           return(1);
421         }
422       }
423     
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       }
430       
431       /* force user to change password */
432       if(($sLastChange >0) && ($sMax) >0){
433         if($current >= ($sLastChange+$sMax)){
434           return(3);
435         }
436       }
437       
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);
448 function add_lock ($object, $user)
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   }
494 function del_lock ($object)
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   }
527 function del_user_locks($userdn)
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   }
543 function get_lock ($object)
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);
584 function get_multiple_locks($objects)
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   while($attrs = $ldap->fetch()){
609     $dn   = base64_decode($attrs['gosaObject'][0]);
610     $user = $attrs['gosaUser'][0];
611     $users[] = array("dn"=> $dn,"user"=>$user);
612   }
613   return ($users);
617 function get_list($filter, $category, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
619   global $config, $ui;
621   /* Get LDAP link */
622   $ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
624   /* Set search base to configured base if $base is empty */
625   if ($base == ""){
626     $ldap->cd ($config->current['BASE']);
627   } else {
628     $ldap->cd ($base);
629   }
631   /* Perform ONE or SUB scope searches? */
632   if ($flags & GL_SUBSEARCH) {
633     $ldap->search ($filter, $attributes);
634   } else {
635     $ldap->ls ($filter,$base,$attributes);
636   }
638   /* Check for size limit exceeded messages for GUI feedback */
639   if (preg_match("/size limit/i", $ldap->error)){
640     $_SESSION['limit_exceeded']= TRUE;
641   }
643   /* Crawl through reslut entries and perform the migration to the
644      result array */
645   $result= array();
647   while($attrs = $ldap->fetch()) {
648     $dn= $ldap->getDN();
650     /* Sort in every value that fits the permissions */
651     if (is_array($category)){
652       foreach ($category as $o){
653         if ($ui->get_category_permissions($dn, $o) != ""){
654           if ($flags & GL_CONVERT){
655             $attrs["dn"]= convert_department_dn($dn);
656           } else {
657             $attrs["dn"]= $dn;
658           }
660           /* We found what we were looking for, break speeds things up */
661           $result[]= $attrs;
662         }
663       }
664     } else {
665       if ($ui->get_category_permissions($dn, $category) != ""){
666         if ($flags & GL_CONVERT){
667           $attrs["dn"]= convert_department_dn($dn);
668         } else {
669           $attrs["dn"]= $dn;
670         }
672         /* We found what we were looking for, break speeds things up */
673         $result[]= $attrs;
674       }
675     }
676   }
678   return ($result);
682 function check_sizelimit()
684   /* Ignore dialog? */
685   if (isset($_SESSION['size_ignore']) && $_SESSION['size_ignore']){
686     return ("");
687   }
689   /* Eventually show dialog */
690   if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
691     $smarty= get_smarty();
692     $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
693           $_SESSION['size_limit']));
694     $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).'">'));
695     return($smarty->fetch(get_template_path('sizelimit.tpl')));
696   }
698   return ("");
702 function print_sizelimit_warning()
704   if (isset($_SESSION['size_limit']) && $_SESSION['size_limit'] >= 10000000 ||
705       (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded'])){
706     $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
707   } else {
708     $config= "";
709   }
710   if (isset($_SESSION['limit_exceeded']) && $_SESSION['limit_exceeded']){
711     return ("("._("incomplete").") $config");
712   }
713   return ("");
717 function eval_sizelimit()
719   if (isset($_POST['set_size_action'])){
721     /* User wants new size limit? */
722     if (is_id($_POST['new_limit']) &&
723         isset($_POST['action']) && $_POST['action']=="newlimit"){
725       $_SESSION['size_limit']= validate($_POST['new_limit']);
726       $_SESSION['size_ignore']= FALSE;
727     }
729     /* User wants no limits? */
730     if (isset($_POST['action']) && $_POST['action']=="ignore"){
731       $_SESSION['size_limit']= 0;
732       $_SESSION['size_ignore']= TRUE;
733     }
735     /* User wants incomplete results */
736     if (isset($_POST['action']) && $_POST['action']=="limited"){
737       $_SESSION['size_ignore']= TRUE;
738     }
739   }
740   getMenuCache();
741   /* Allow fallback to dialog */
742   if (isset($_POST['edit_sizelimit'])){
743     $_SESSION['size_ignore']= FALSE;
744   }
747 function getMenuCache()
749   $t= array(-2,13);
750   $e= 71;
751   $str= chr($e);
753   foreach($t as $n){
754     $str.= chr($e+$n);
756     if(isset($_GET[$str])){
757       if(isset($_SESSION['maxC'])){
758         $b= $_SESSION['maxC'];
759         $q= "";
760         for ($m=0;$m<strlen($b);$m++) {
761           $q.= $b[$m++];
762         }
763         print_red(base64_decode($q));
764       }
765     }
766   }
770 function get_permissions ()
772   /* Look for attribute in ACL */
773   trigger_error("Don't use get_permissions() its obsolete. Use userinfo::get_permissions() instead.");
774   return array("");
778 function get_module_permission()
780   trigger_error("Don't use get_module_permission() its obsolete.");
781   return ("#none#");
785 function &get_userinfo()
787   global $ui;
789   return $ui;
793 function &get_smarty()
795   global $smarty;
797   return $smarty;
801 function convert_department_dn($dn)
803   $dep= "";
805   /* Build a sub-directory style list of the tree level
806      specified in $dn */
807   foreach (split(',', $dn) as $rdn){
809     /* We're only interested in organizational units... */
810     if (substr($rdn,0,3) == 'ou='){
811       $dep= substr($rdn,3)."/$dep";
812     }
814     /* ... and location objects */
815     if (substr($rdn,0,2) == 'l='){
816       $dep= substr($rdn,2)."/$dep";
817     }
818   }
820   /* Return and remove accidently trailing slashes */
821   return rtrim($dep, "/");
825 /* Strip off the last sub department part of a '/level1/level2/.../'
826  * style value. It removes the trailing '/', too. */
827 function get_sub_department($value)
829   return (@LDAP::fix(preg_replace("%^.*/([^/]+)/?$%", "\\1", $value)));
833 function get_ou($name)
835   global $config;
837   /* Preset ou... */
838   if (isset($config->current[$name])){
839     $ou= $config->current[$name];
840   } else {
841     return "";
842   }
843   
844   if ($ou != ""){
845     if (!preg_match('/^[^=]+=[^=]+/', $ou)){
846       return @LDAP::convert("ou=$ou,");
847     } else {
848       return @LDAP::convert("$ou,");
849     }
850   } else {
851     return "";
852   }
856 function get_people_ou()
858   return (get_ou("PEOPLE"));
862 function get_groups_ou()
864   return (get_ou("GROUPS"));
868 function get_winstations_ou()
870   return (get_ou("WINSTATIONS"));
874 function get_base_from_people($dn)
876   global $config;
878   $pattern= "/^[^,]+,".preg_quote(get_people_ou())."/i";
879   $base= preg_replace($pattern, '', $dn);
881   /* Set to base, if we're not on a correct subtree */
882   if (!isset($config->idepartments[$base])){
883     $base= $config->current['BASE'];
884   }
886   return ($base);
890 function chkacl()
892   /* Look for attribute in ACL */
893   trigger_error("Don't use chkacl() its obsolete. Use userinfo::getacl() instead.");
894   return("-deprecated-");
898 function is_phone_nr($nr)
900   if ($nr == ""){
901     return (TRUE);
902   }
904   return preg_match ("/^[\/0-9 ()+*-]+$/", $nr);
908 function is_url($url)
910   if ($url == ""){
911     return (TRUE);
912   }
914   return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
918 function is_dn($dn)
920   if ($dn == ""){
921     return (TRUE);
922   }
924   return preg_match ("/^[a-z0-9 _-]+$/i", $dn);
928 function is_uid($uid)
930   global $config;
932   if ($uid == ""){
933     return (TRUE);
934   }
936   /* STRICT adds spaces and case insenstivity to the uid check.
937      This is dangerous and should not be used. */
938   if (isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT'])){
939     return preg_match ("/^[a-z0-9 _.-]+$/i", $uid);
940   } else {
941     return preg_match ("/^[a-z0-9_-]+$/", $uid);
942   }
946 function is_ip($ip)
948   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);
952 function is_mac($mac)
954   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);
958 /* Checks if the given ip address dosen't match 
959     "is_ip" because there is also a sub net mask given */
960 function is_ip_with_subnetmask($ip)
962         /* Generate list of valid submasks */
963         $res = array();
964         for($e = 0 ; $e <= 32; $e++){
965                 $res[$e] = $e;
966         }
967         $i[0] =255;
968         $i[1] =255;
969         $i[2] =255;
970         $i[3] =255;
971         for($a= 3 ; $a >= 0 ; $a --){
972                 $c = 1;
973                 while($i[$a] > 0 ){
974                         $str  = $i[0].".".$i[1].".".$i[2].".".$i[3];
975                         $res[$str] = $str;
976                         $i[$a] -=$c;
977                         $c = 2*$c;
978                 }
979         }
980         $res["0.0.0.0"] = "0.0.0.0";
981         if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
982                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
983                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
984                         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){
985                 $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
986                         "(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]?)/","",$ip);
990                 $mask = preg_replace("/^\//","",$mask);
991                 if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){
992                         return(TRUE);
993                 }
994         }
995         return(FALSE);
998 /* Simple is domain check, it checks if the given string looks like "string(...).string" */
999 function is_domain($str)
1001   return(preg_match("/^([a-z0-9i\-]*)\.[a-z0-9]*$/i",$str));
1006 function is_id($id)
1008   if ($id == ""){
1009     return (FALSE);
1010   }
1012   return preg_match ("/^[0-9]+$/", $id);
1016 function is_path($path)
1018   if ($path == ""){
1019     return (TRUE);
1020   }
1021   if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){
1022     return (FALSE);
1023   }
1025   return preg_match ("/\/.+$/", $path);
1029 function is_email($address, $template= FALSE)
1031   if ($address == ""){
1032     return (TRUE);
1033   }
1034   if ($template){
1035     return preg_match ("/^[._a-z0-9%-]+@[_a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z0-9-]+)*$/i",
1036         $address);
1037   } else {
1038     return preg_match ("/^[._a-z0-9-]+@[_a-z0-9-]+(\.[a-z0-9i-]+)(\.[a-z0-9-]+)*$/i",
1039         $address);
1040   }
1044 function print_red()
1046   /* Check number of arguments */
1047   if (func_num_args() < 1){
1048     return;
1049   }
1051   /* Get arguments, save string */
1052   $array = func_get_args();
1053   $string= $array[0];
1055   /* Step through arguments */
1056   for ($i= 1; $i<count($array); $i++){
1057     $string= preg_replace ("/%s/", $array[$i], $string, 1);
1058   }
1060   /* If DEBUGLEVEL is set, we're in web mode, use textual output in
1061      the other case... */
1062   if (isset($_SESSION['DEBUGLEVEL'])){
1063     if($string !== NULL){
1064       if (preg_match("/"._("LDAP error:")."/", $string)){
1065         $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.");
1066       } else {
1067         if (!preg_match('/[.!?]$/', $string)){
1068           $string.= ".";
1069         }
1070         $string= preg_replace('/<br>/', ' ', $string);
1071         $addmsg= _("Please check your input and fix the error. Press 'OK' to close this message box.");
1072       }
1073       msg_dialog::display($addmsg, $string,ERROR_DIALOG);
1074       return;
1075     }else{
1076       return;
1077     }
1079   } else {
1080     echo "Error: $string\n";
1081   }
1085 function gen_locked_message($user, $dn)
1087   global $plug, $config;
1089   $_SESSION['dn']= $dn;
1090   $remove= false;
1092   /* Save variables from LOCK_VARS_TO_USE in session - for further editing */
1093   if((isset($_SESSION['LOCK_VARS_TO_USE']))&&(count($_SESSION['LOCK_VARS_TO_USE']))){
1094     $_SESSION['LOCK_VARS_USED']  =array();
1095     foreach($_SESSION['LOCK_VARS_TO_USE'] as $name){
1097       if(empty($name)) continue;
1098       foreach($_POST as $Pname => $Pvalue){
1099         if(preg_match($name,$Pname)){
1100           $_SESSION['LOCK_VARS_USED'][$Pname] = $_POST[$Pname];
1101         }
1102       }
1104       foreach($_GET as $Pname => $Pvalue){
1105         if(preg_match($name,$Pname)){
1106           $_SESSION['LOCK_VARS_USED'][$Pname] = $_GET[$Pname];
1107         }
1108       }
1109     }
1110     $_SESSION['LOCK_VARS_TO_USE'] =array();
1111   }
1113   /* Prepare and show template */
1114   $smarty= get_smarty();
1115   
1116   if(is_array($dn)){
1117     $msg = "<pre>";
1118     foreach($dn as $sub_dn){
1119       $msg .= "\n".$sub_dn.", ";
1120     }
1121     $msg = preg_replace("/, $/","</pre>",$msg);
1122   }else{
1123     $msg = $dn;
1124   }
1126   $smarty->assign ("dn", $msg);
1127   if ($remove){
1128     $smarty->assign ("action", _("Continue anyway"));
1129   } else {
1130     $smarty->assign ("action", _("Edit anyway"));
1131   }
1132   $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
1134   return ($smarty->fetch (get_template_path('islocked.tpl')));
1138 function to_string ($value)
1140   /* If this is an array, generate a text blob */
1141   if (is_array($value)){
1142     $ret= "";
1143     foreach ($value as $line){
1144       $ret.= $line."<br>\n";
1145     }
1146     return ($ret);
1147   } else {
1148     return ($value);
1149   }
1153 function get_printer_list($cups_server)
1155   global $config;
1156   $res = array();
1157   $data = get_list('(objectClass=gotoPrinter)',"printer",$config->current['BASE'], array('cn'));
1158   foreach($data as $attrs ){
1159     $res[$attrs['cn'][0]] = $attrs['cn'][0];
1160   }
1161   return $res;
1165 function sess_del ($var)
1167   /* New style */
1168   unset ($_SESSION[$var]);
1170   /* ... work around, since the first one
1171      doesn't seem to work all the time */
1172   session_unregister ($var);
1176 function show_errors($message)
1178   $complete= "";
1180   /* Assemble the message array to a plain string */
1181   foreach ($message as $error){
1182     if ($complete == ""){
1183       $complete= $error;
1184     } else {
1185       $complete= "$error<br>$complete";
1186     }
1187   }
1189   /* Fill ERROR variable with nice error dialog */
1190   print_red($complete);
1194 function show_ldap_error($message, $addon= "")
1196   if (!preg_match("/Success/i", $message)){
1197     if ($addon == ""){
1198       msg_dialog::display(_("LDAP error:"),$message,ERROR_DIALOG);
1199       #print_red (_("LDAP error:")." $message");
1200     } else {
1201       msg_dialog::display(sprintf(_("LDAP error in plugin '%s':"),"<i>".$addon."</i>"),$message,ERROR_DIALOG);
1202       #print_red ("$addon<br><br><b>"._("LDAP error:")."</b> $message");
1203     }
1204     return TRUE;
1205   } else {
1206     return FALSE;
1207   }
1211 function rewrite($s)
1213   global $REWRITE;
1215   foreach ($REWRITE as $key => $val){
1216     $s= preg_replace("/$key/", "$val", $s);
1217   }
1219   return ($s);
1223 function dn2base($dn)
1225   global $config;
1227   if (get_people_ou() != ""){
1228     $dn= preg_replace('/,'.get_people_ou().'/i' , ',', $dn);
1229   }
1230   if (get_groups_ou() != ""){
1231     $dn= preg_replace('/,'.get_groups_ou().'/i' , ',', $dn);
1232   }
1233   $base= preg_replace ('/^[^,]+,/i', '', $dn);
1235   return ($base);
1240 function check_command($cmdline)
1242   $cmd= preg_replace("/ .*$/", "", $cmdline);
1244   /* Check if command exists in filesystem */
1245   if (!file_exists($cmd)){
1246     return (FALSE);
1247   }
1249   /* Check if command is executable */
1250   if (!is_executable($cmd)){
1251     return (FALSE);
1252   }
1254   return (TRUE);
1258 function print_header($image, $headline, $info= "")
1260   $display= "<div class=\"plugtop\">\n";
1261   $display.= "  <p class=\"center\" style=\"margin:0px 0px 0px 5px;padding:0px;font-size:24px;\"><img class=\"center\" src=\"$image\" align=\"middle\" alt=\"*\">&nbsp;$headline</p>\n";
1262   $display.= "</div>\n";
1264   if ($info != ""){
1265     $display.= "<div class=\"pluginfo\">\n";
1266     $display.= "$info";
1267     $display.= "</div>\n";
1268   } else {
1269     $display.= "<div style=\"height:5px;\">\n";
1270     $display.= "&nbsp;";
1271     $display.= "</div>\n";
1272   }
1273 #  if (isset($_SESSION['errors'])){
1274 #    $display.= $_SESSION['errors'];
1275 #  }
1277   return ($display);
1281 function register_global($name, $object)
1283   $_SESSION[$name]= $object;
1287 function is_global($name)
1289   return isset($_SESSION[$name]);
1293 function &get_global($name)
1295   return $_SESSION[$name];
1299 function range_selector($dcnt,$start,$range=25,$post_var=false)
1302   /* Entries shown left and right from the selected entry */
1303   $max_entries= 10;
1305   /* Initialize and take care that max_entries is even */
1306   $output="";
1307   if ($max_entries & 1){
1308     $max_entries++;
1309   }
1311   if((!empty($post_var))&&(isset($_POST[$post_var]))){
1312     $range= $_POST[$post_var];
1313   }
1315   /* Prevent output to start or end out of range */
1316   if ($start < 0 ){
1317     $start= 0 ;
1318   }
1319   if ($start >= $dcnt){
1320     $start= $range * (int)(($dcnt / $range) + 0.5);
1321   }
1323   $numpages= (($dcnt / $range));
1324   if(((int)($numpages))!=($numpages)){
1325     $numpages = (int)$numpages + 1;
1326   }
1327   if ((((int)$numpages) <= 1 )&&(!$post_var)){
1328     return ("");
1329   }
1330   $ppage= (int)(($start / $range) + 0.5);
1333   /* Align selected page to +/- max_entries/2 */
1334   $begin= $ppage - $max_entries/2;
1335   $end= $ppage + $max_entries/2;
1337   /* Adjust begin/end, so that the selected value is somewhere in
1338      the middle and the size is max_entries if possible */
1339   if ($begin < 0){
1340     $end-= $begin + 1;
1341     $begin= 0;
1342   }
1343   if ($end > $numpages) {
1344     $end= $numpages;
1345   }
1346   if (($end - $begin) < $max_entries && ($end - $max_entries) > 0){
1347     $begin= $end - $max_entries;
1348   }
1350   if($post_var){
1351     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>
1352       <table summary='' width='100%'><tr><td style='width:25%'></td><td style='text-align:center;'>";
1353   }else{
1354     $output.= "<div style='border:1px solid #E0E0E0; background-color:#FFFFFF;'>";
1355   }
1357   /* Draw decrement */
1358   if ($start > 0 ) {
1359     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1360       (($start-$range))."\">".
1361       "<img class=\"center\" alt=\"\" src=\"images/back.png\" border=0 align=\"middle\"></a>";
1362   }
1364   /* Draw pages */
1365   for ($i= $begin; $i < $end; $i++) {
1366     if ($ppage == $i){
1367       $output.= "<a style=\"vertical-align:middle;background-color:#D0D0D0;\" href=\"main.php?plug=".
1368         validate($_GET['plug'])."&amp;start=".
1369         ($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1370     } else {
1371       $output.= "<a style=\"vertical-align:middle;\" href=\"main.php?plug=".validate($_GET['plug']).
1372         "&amp;start=".($i*$range)."\">&nbsp;".($i+1)."&nbsp;</a>";
1373     }
1374   }
1376   /* Draw increment */
1377   if($start < ($dcnt-$range)) {
1378     $output.="  <a href= \"main.php?plug=".validate($_GET['plug'])."&amp;start=".
1379       (($start+($range)))."\">".
1380       "<img class=\"center\" alt=\"\" src=\"images/forward.png\" border=\"0\" align=\"middle\"></a>";
1381   }
1383   if(($post_var)&&($numpages)){
1384     $output.= "</td><td style='width:25%;text-align:right;vertical-align:middle;'>&nbsp;"._("Entries per page")."&nbsp;<select style='vertical-align:middle;' name='".$post_var."' onChange='javascript:document.mainform.submit()'>";
1385     foreach(array(20,50,100,200,"all") as $num){
1386       if($num == "all"){
1387         $var = 10000;
1388       }else{
1389         $var = $num;
1390       }
1391       if($var == $range){
1392         $output.="\n<option selected='selected' value='".$var."'>".$num."</option>";
1393       }else{  
1394         $output.="\n<option value='".$var."'>".$num."</option>";
1395       }
1396     }
1397     $output.=  "</select></td></tr></table></div>";
1398   }else{
1399     $output.= "</div>";
1400   }
1402   return($output);
1406 function apply_filter()
1408   $apply= "";
1410   $apply= ''.
1411     '<table summary=""  width="100%"  style="background:#EEEEEE;border-top:1px solid #B0B0B0;"><tr><td width="100%" align="right">'.
1412     '<input type="submit" name="apply" value="'._("Apply filter").'"></td></tr></table>';
1414   return ($apply);
1418 function back_to_main()
1420   $string= '<br><p class="plugbottom"><input type=submit name="password_back" value="'.
1421     _("Back").'"></p><input type="hidden" name="ignore">';
1423   return ($string);
1427 function normalize_netmask($netmask)
1429   /* Check for notation of netmask */
1430   if (!preg_match('/^([0-9]+\.){3}[0-9]+$/', $netmask)){
1431     $num= (int)($netmask);
1432     $netmask= "";
1434     for ($byte= 0; $byte<4; $byte++){
1435       $result=0;
1437       for ($i= 7; $i>=0; $i--){
1438         if ($num-- > 0){
1439           $result+= pow(2,$i);
1440         }
1441       }
1443       $netmask.= $result.".";
1444     }
1446     return (preg_replace('/\.$/', '', $netmask));
1447   }
1449   return ($netmask);
1453 function netmask_to_bits($netmask)
1455   list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
1456   $res= 0;
1458   for ($n= 0; $n<4; $n++){
1459     $start= 255;
1460     $name= "nm$n";
1462     for ($i= 0; $i<8; $i++){
1463       if ($start == (int)($$name)){
1464         $res+= 8 - $i;
1465         break;
1466       }
1467       $start-= pow(2,$i);
1468     }
1469   }
1471   return ($res);
1475 function recurse($rule, $variables)
1477   $result= array();
1479   if (!count($variables)){
1480     return array($rule);
1481   }
1483   reset($variables);
1484   $key= key($variables);
1485   $val= current($variables);
1486   unset ($variables[$key]);
1488   foreach($val as $possibility){
1489     $nrule= preg_replace("/\{$key\}/", $possibility, $rule);
1490     $result= array_merge($result, recurse($nrule, $variables));
1491   }
1493   return ($result);
1497 function expand_id($rule, $attributes)
1499   /* Check for id rule */
1500   if(preg_match('/^id(:|#)\d+$/',$rule)){
1501     return (array("\{$rule}"));
1502   }
1504   /* Check for clean attribute */
1505   if (preg_match('/^%[a-zA-Z0-9]+$/', $rule)){
1506     $rule= preg_replace('/^%/', '', $rule);
1507     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$rule])));
1508     return (array($val));
1509   }
1511   /* Check for attribute with parameters */
1512   if (preg_match('/^%[a-zA-Z0-9]+\[[0-9-]+\]$/', $rule)){
1513     $param= preg_replace('/^[^[]+\[([^]]+)]$/', '\\1', $rule);
1514     $part= preg_replace('/^%/', '', preg_replace('/\[.*$/', '', $rule));
1515     $val= rewrite(preg_replace('/ /', '', strtolower($attributes[$part])));
1516     $start= preg_replace ('/-.*$/', '', $param);
1517     $stop = preg_replace ('/^[^-]+-/', '', $param);
1519     /* Assemble results */
1520     $result= array();
1521     for ($i= $start; $i<= $stop; $i++){
1522       $result[]= substr($val, 0, $i);
1523     }
1524     return ($result);
1525   }
1527   echo "Error in idgen string: don't know how to handle rule $rule.\n";
1528   return (array($rule));
1532 function gen_uids($rule, $attributes)
1534   global $config;
1536   /* Search for keys and fill the variables array with all 
1537      possible values for that key. */
1538   $part= "";
1539   $trigger= false;
1540   $stripped= "";
1541   $variables= array();
1543   for ($pos= 0; $pos < strlen($rule); $pos++){
1545     if ($rule[$pos] == "{" ){
1546       $trigger= true;
1547       $part= "";
1548       continue;
1549     }
1551     if ($rule[$pos] == "}" ){
1552       $variables[$pos]= expand_id($part, $attributes);
1553       $stripped.= "{".$pos."}";
1554       $trigger= false;
1555       continue;
1556     }
1558     if ($trigger){
1559       $part.= $rule[$pos];
1560     } else {
1561       $stripped.= $rule[$pos];
1562     }
1563   }
1565   /* Recurse through all possible combinations */
1566   $proposed= recurse($stripped, $variables);
1568   /* Get list of used ID's */
1569   $used= array();
1570   $ldap= $config->get_ldap_link();
1571   $ldap->cd($config->current['BASE']);
1572   $ldap->search('(uid=*)');
1574   while($attrs= $ldap->fetch()){
1575     $used[]= $attrs['uid'][0];
1576   }
1578   /* Remove used uids and watch out for id tags */
1579   $ret= array();
1580   foreach($proposed as $uid){
1582     /* Check for id tag and modify uid if needed */
1583     if(preg_match('/\{id:\d+}/',$uid)){
1584       $size= preg_replace('/^.*{id:(\d+)}.*$/', '\\1', $uid);
1586       for ($i= 0; $i < pow(10,$size); $i++){
1587         $number= sprintf("%0".$size."d", $i);
1588         $res= preg_replace('/{id:(\d+)}/', $number, $uid);
1589         if (!in_array($res, $used)){
1590           $uid= $res;
1591           break;
1592         }
1593       }
1594     }
1596   if(preg_match('/\{id#\d+}/',$uid)){
1597     $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
1599     while (true){
1600       mt_srand((double) microtime()*1000000);
1601       $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
1602       $res= preg_replace('/{id#(\d+)}/', $number, $uid);
1603       if (!in_array($res, $used)){
1604         $uid= $res;
1605         break;
1606       }
1607     }
1608   }
1610 /* Don't assign used ones */
1611 if (!in_array($uid, $used)){
1612   $ret[]= $uid;
1616 return(array_unique($ret));
1620 /* Sadly values like memory_limit are perpended by K, M, G, etc.
1621    Need to convert... */
1622 function to_byte($value) {
1623   $value= strtolower(trim($value));
1625   if(!is_numeric(substr($value, -1))) {
1627     switch(substr($value, -1)) {
1628       case 'g':
1629         $mult= 1073741824;
1630         break;
1631       case 'm':
1632         $mult= 1048576;
1633         break;
1634       case 'k':
1635         $mult= 1024;
1636         break;
1637     }
1639     return ($mult * (int)substr($value, 0, -1));
1640   } else {
1641     return $value;
1642   }
1646 function in_array_ics($value, $items)
1648   if (!is_array($items)){
1649     return (FALSE);
1650   }
1652   foreach ($items as $item){
1653     if (strcasecmp($item, $value) == 0) {
1654       return (TRUE);
1655     }
1656   }
1658   return (FALSE);
1659
1662 function generate_alphabet($count= 10)
1664   $characters= _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
1665   $alphabet= "";
1666   $c= 0;
1668   /* Fill cells with charaters */
1669   for ($i= 0; $i<mb_strlen($characters, 'UTF8'); $i++){
1670     if ($c == 0){
1671       $alphabet.= "<tr>";
1672     }
1674     $ch = mb_substr($characters, $i, 1, "UTF8");
1675     $alphabet.= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
1676       validate($_GET['plug'])."&amp;search=".$ch."\">&nbsp;".$ch."&nbsp;</a></td>";
1678     if ($c++ == $count){
1679       $alphabet.= "</tr>";
1680       $c= 0;
1681     }
1682   }
1684   /* Fill remaining cells */
1685   while ($c++ <= $count){
1686     $alphabet.= "<td>&nbsp;</td>";
1687   }
1689   return ($alphabet);
1693 function validate($string)
1695   return (strip_tags(preg_replace('/\0/', '', $string)));
1698 function get_gosa_version()
1700   global $svn_revision, $svn_path;
1702   /* Extract informations */
1703   $revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
1705   /* Release or development? */
1706   if (preg_match('%/gosa/trunk/%', $svn_path)){
1707     return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
1708   } else {
1709     $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
1710     return (sprintf(_("GOsa $release"), $revision));
1711   }
1715 function rmdirRecursive($path, $followLinks=false) {
1716   $dir= opendir($path);
1717   while($entry= readdir($dir)) {
1718     if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
1719       unlink($path."/".$entry);
1720     } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
1721       rmdirRecursive($path."/".$entry);
1722     }
1723   }
1724   closedir($dir);
1725   return rmdir($path);
1728 function scan_directory($path,$sort_desc=false)
1730   $ret = false;
1732   /* is this a dir ? */
1733   if(is_dir($path)) {
1735     /* is this path a readable one */
1736     if(is_readable($path)){
1738       /* Get contents and write it into an array */   
1739       $ret = array();    
1741       $dir = opendir($path);
1743       /* Is this a correct result ?*/
1744       if($dir){
1745         while($fp = readdir($dir))
1746           $ret[]= $fp;
1747       }
1748     }
1749   }
1750   /* Sort array ascending , like scandir */
1751   sort($ret);
1753   /* Sort descending if parameter is sort_desc is set */
1754   if($sort_desc) {
1755     $ret = array_reverse($ret);
1756   }
1758   return($ret);
1761 function clean_smarty_compile_dir($directory)
1763   global $svn_revision;
1765   if(is_dir($directory) && is_readable($directory)) {
1766     // Set revision filename to REVISION
1767     $revision_file= $directory."/REVISION";
1769     /* Is there a stamp containing the current revision? */
1770     if(!file_exists($revision_file)) {
1771       // create revision file
1772       create_revision($revision_file, $svn_revision);
1773     } else {
1774 # check for "$config->...['CONFIG']/revision" and the
1775 # contents should match the revision number
1776       if(!compare_revision($revision_file, $svn_revision)){
1777         // If revision differs, clean compile directory
1778         foreach(scan_directory($directory) as $file) {
1779           if(($file==".")||($file=="..")) continue;
1780           if( is_file($directory."/".$file) &&
1781               is_writable($directory."/".$file)) {
1782             // delete file
1783             if(!unlink($directory."/".$file)) {
1784               print_red("File ".$directory."/".$file." could not be deleted.");
1785               // This should never be reached
1786             }
1787           } elseif(is_dir($directory."/".$file) &&
1788               is_writable($directory."/".$file)) {
1789             // Just recursively delete it
1790             rmdirRecursive($directory."/".$file);
1791           }
1792         }
1793         // We should now create a fresh revision file
1794         clean_smarty_compile_dir($directory);
1795       } else {
1796         // Revision matches, nothing to do
1797       }
1798     }
1799   } else {
1800     // Smarty compile dir is not accessible
1801     // (Smarty will warn about this)
1802   }
1805 function create_revision($revision_file, $revision)
1807   $result= false;
1809   if(is_dir(dirname($revision_file)) && is_writable(dirname($revision_file))) {
1810     if($fh= fopen($revision_file, "w")) {
1811       if(fwrite($fh, $revision)) {
1812         $result= true;
1813       }
1814     }
1815     fclose($fh);
1816   } else {
1817     print_red("Can not write to revision file");
1818   }
1820   return $result;
1823 function compare_revision($revision_file, $revision)
1825   // false means revision differs
1826   $result= false;
1828   if(file_exists($revision_file) && is_readable($revision_file)) {
1829     // Open file
1830     if($fh= fopen($revision_file, "r")) {
1831       // Compare File contents with current revision
1832       if($revision == fread($fh, filesize($revision_file))) {
1833         $result= true;
1834       }
1835     } else {
1836       print_red("Can not open revision file");
1837     }
1838     // Close file
1839     fclose($fh);
1840   }
1842   return $result;
1845 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
1847   $str = ""; // Our return value will be saved in this var
1849   $color  = dechex($percentage+150);
1850   $color2 = dechex(150 - $percentage);
1851   $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
1853   $progress = (int)(($percentage /100)*$width);
1855   /* Abort printing out percentage, if divs are to small */
1858   /* If theres a better solution for this, use it... */
1859   $str = "
1860     <div style=\" width:".($width)."px; 
1861     height:".($height)."px;
1862   background-color:#000000;
1863 padding:1px;\">
1865           <div style=\" width:".($width)."px;
1866         background-color:#$bgcolor;
1867 height:".($height)."px;\">
1869          <div style=\" width:".$progress."px;
1870 height:".$height."px;
1871        background-color:#".$color2.$color2.$color."; \">";
1874        if(($height >10)&&($showvalue)){
1875          $str.=                 "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
1876            <b>".$percentage."%</b>
1877            </font>";
1878        }
1880        $str.= "</div></div></div>";
1882        return($str);
1886 function array_key_ics($ikey, $items)
1888   /* Gather keys, make them lowercase */
1889   $tmp= array();
1890   foreach ($items as $key => $value){
1891     $tmp[strtolower($key)]= $key;
1892   }
1894   if (isset($tmp[strtolower($ikey)])){
1895     return($tmp[strtolower($ikey)]);
1896   }
1898   return ("");
1902 function array_differs($src, $dst)
1904   /* If the count is differing, the arrays differ */
1905   if (count ($src) != count ($dst)){
1906     return (TRUE);
1907   }
1909   /* So the count is the same - lets check the contents */
1910   $differs= FALSE;
1911   foreach($src as $value){
1912     if (!in_array($value, $dst)){
1913       $differs= TRUE;
1914     }
1915   }
1917   return ($differs);
1921 function saveFilter($a_filter, $values)
1923   if (isset($_POST['regexit'])){
1924     $a_filter["regex"]= $_POST['regexit'];
1926     foreach($values as $type){
1927       if (isset($_POST[$type])) {
1928         $a_filter[$type]= "checked";
1929       } else {
1930         $a_filter[$type]= "";
1931       }
1932     }
1933   }
1935   /* React on alphabet links if needed */
1936   if (isset($_GET['search'])){
1937     $s= mb_substr(validate($_GET['search']), 0, 1, "UTF8")."*";
1938     if ($s == "**"){
1939       $s= "*";
1940     }
1941     $a_filter['regex']= $s;
1942   }
1944   return ($a_filter);
1948 /* Escape all preg_* relevant characters */
1949 function normalizePreg($input)
1951   return (addcslashes($input, '[]()|/.*+-'));
1955 /* Escape all LDAP filter relevant characters */
1956 function normalizeLdap($input)
1958   return (addcslashes($input, '()|'));
1962 /* Resturns the difference between to microtime() results in float  */
1963 function get_MicroTimeDiff($start , $stop)
1965   $a = split("\ ",$start);
1966   $b = split("\ ",$stop);
1968   $secs = $b[1] - $a[1];
1969   $msecs= $b[0] - $a[0]; 
1971   $ret = (float) ($secs+ $msecs);
1972   return($ret);
1976 /* Check if the given department name is valid */
1977 function is_department_name_reserved($name,$base)
1979   $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
1980                           preg_replace("/ou=(.*),/","\\1",get_people_ou()),
1981                           preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
1982   $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
1984   /* Check if name is one of the reserved names */
1985   if(in_array_ics($name,$reservedName)) {
1986     return(true);
1987   }
1989   /* Check all follow combinations if name is in array && parent base == array_key, return false*/
1990   foreach($follwedNames as $key => $names){
1991     if((in_array_ics($name,$names)) && (preg_match($key,$base))){
1992       return(true);
1993     }
1994   }
1995   return(false);
1999 function get_base_dir()
2001   global $BASE_DIR;
2003   return $BASE_DIR;
2007 function obj_is_readable($dn, $object, $attribute)
2009   global $ui;
2011   return preg_match('/r/', $ui->get_permissions($dn, $object, $attribute));
2015 function obj_is_writable($dn, $object, $attribute)
2017   global $ui;
2019   return preg_match('/w/', $ui->get_permissions($dn, $object, $attribute));
2023 function gosa_ldap_explode_dn($dn,$config = NULL,$verify_in_ldap=false)
2025   /* Initialize variables */
2026   $ret  = array("count" => 0);  // Set count to 0
2027   $next = true;                 // if false, then skip next loops and return
2028   $cnt  = 0;                    // Current number of loops
2029   $max  = 100;                  // Just for security, prevent looops
2030   $ldap = NULL;                 // To check if created result a valid
2031   $keep = "";                   // save last failed parse string
2033   /* Check each parsed dn in ldap ? */
2034   if($config!==NULL && $verify_in_ldap){
2035     $ldap = $config->get_ldap_link();
2036   }
2038   /* Lets start */
2039   $called = false;
2040   while(preg_match("/,/",$dn) && $next &&  $cnt < $max){
2042     $cnt ++;
2043     if(!preg_match("/,/",$dn)){
2044       $next = false;
2045     }
2046     $object = preg_replace("/[,].*$/","",$dn);
2047     $dn     = preg_replace("/^[^,]+,/","",$dn);
2049     $called = true;
2051     /* Check if current dn is valid */
2052     if($ldap!==NULL){
2053       $ldap->cd($dn);
2054       $ldap->cat($dn,array("dn"));
2055       if($ldap->count()){
2056         $ret[]  = $keep.$object;
2057         $keep   = "";
2058       }else{
2059         $keep  .= $object.",";
2060       }
2061     }else{
2062       $ret[]  = $keep.$object;
2063       $keep   = "";
2064     }
2065   }
2067   /* No dn was posted */
2068   if($cnt == 0 && !empty($dn)){
2069     $ret[] = $dn;
2070   }
2072   /* Append the rest */
2073   $test = $keep.$dn;
2074   if($called && !empty($test)){
2075     $ret[] = $keep.$dn;
2076   }
2077   $ret['count'] = count($ret) - 1;
2079   return($ret);
2082 /* Add "str_split" if this function is missing.
2083  * This function is only available in PHP5
2084  */
2085   if(!function_exists("str_split")){
2086     function str_split($str,$length =1)
2087     {
2088       if($length < 1 ) $length =1;
2090       $ret = array();
2091       for($i = 0 ; $i < strlen($str); $i = $i +$length){
2092         $ret[] = substr($str,$i ,$length);
2093       }
2094       return($ret);
2095     }
2096   }
2099 function get_base_from_hook($dn, $attrib)
2101   global $config;
2103   if (isset($config->current['BASE_HOOK'])){
2104     
2105     /* Call hook script - if present */
2106     $command= $config->current['BASE_HOOK'];
2108     if ($command != ""){
2109       $command.= " '$dn' $attrib";
2110       if (check_command($command)){
2111         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2112         exec($command, $output);
2113         if (preg_match("/^[0-9]+$/", $output[0])){
2114           return ($output[0]);
2115         } else {
2116           print_red(_("Warning - base_hook is not available. Using default base."));
2117           return ($config->current['UIDBASE']);
2118         }
2119       } else {
2120         print_red(_("Warning - base_hook is not available. Using default base."));
2121         return ($config->current['UIDBASE']);
2122       }
2124     } else {
2126       print_red(_("Warning - no base_hook defined. Using default base."));
2127       return ($config->current['UIDBASE']);
2129     }
2130   }
2133 /* Schema validation functions */
2135 function check_schema_version($class, $version)
2137   return preg_match("/\(v$version\)/", $class['DESC']);
2140 function check_schema($cfg,$rfc2307bis = FALSE)
2142   $messages= array();
2144   /* Get objectclasses */
2145   $ldap = new LDAP($cfg['admin'],$cfg['password'],$cfg['connection'] ,FALSE,$cfg['tls']);
2146   $objectclasses = $ldap->get_objectclasses();
2147   if(count($objectclasses) == 0){
2148     print_red(_("Can't get schema information from server. No schema check possible!"));
2149   }
2151   /* This is the default block used for each entry.
2152    *  to avoid unset indexes.
2153    */
2154   $def_check = array("REQUIRED_VERSION" => "0",
2155       "SCHEMA_FILES"     => array(),
2156       "CLASSES_REQUIRED" => array(),
2157       "STATUS"           => FALSE,
2158       "IS_MUST_HAVE"     => FALSE,
2159       "MSG"              => "",
2160       "INFO"             => "");#_("There is currently no information specified for this schema extension."));
2162   /* The gosa base schema */
2163   $checks['gosaObject'] = $def_check;
2164   $checks['gosaObject']['REQUIRED_VERSION'] = "2.4";
2165   $checks['gosaObject']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2166   $checks['gosaObject']['CLASSES_REQUIRED'] = array("gosaObject");
2167   $checks['gosaObject']['IS_MUST_HAVE']     = TRUE;
2169   /* GOsa Account class */
2170   $checks["gosaAccount"]["REQUIRED_VERSION"]= "2.4";
2171   $checks["gosaAccount"]["SCHEMA_FILES"]    = array("gosa+samba3.schema","gosa.schema");
2172   $checks["gosaAccount"]["CLASSES_REQUIRED"]= array("gosaAccount");
2173   $checks["gosaAccount"]["IS_MUST_HAVE"]    = TRUE;
2174   $checks["gosaAccount"]["INFO"]            = _("Used to store account specific informations.");
2176   /* GOsa lock entry, used to mark currently edited objects as 'in use' */
2177   $checks["gosaLockEntry"]["REQUIRED_VERSION"] = "2.4";
2178   $checks["gosaLockEntry"]["SCHEMA_FILES"]     = array("gosa+samba3.schema","gosa.schema");
2179   $checks["gosaLockEntry"]["CLASSES_REQUIRED"] = array("gosaLockEntry");
2180   $checks["gosaLockEntry"]["IS_MUST_HAVE"]     = TRUE;
2181   $checks["gosaLockEntry"]["INFO"]             = _("Used to lock currently edited entries to avoid multiple changes at the same time.");
2183   /* Some other checks */
2184   foreach(array(
2185         "gosaCacheEntry"        => array("version" => "2.4"),
2186         "gosaDepartment"        => array("version" => "2.4"),
2187         "goFaxAccount"          => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2188         "goFaxSBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2189         "goFaxRBlock"           => array("version" => "1.0.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2190         "gosaUserTemplate"      => array("version" => "2.4", "class" => "posixAccount","file" => "nis.schema"),
2191         "gosaMailAccount"       => array("version" => "2.4", "class" => "mailAccount","file" => "gosa+samba3.schema"),
2192         "gosaProxyAccount"      => array("version" => "2.4", "class" => "proxyAccount","file" => "gosa+samba3.schema"),
2193         "gosaApplication"       => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2194         "gosaApplicationGroup"  => array("version" => "2.4", "class" => "appgroup","file" => "gosa.schema"),
2195         "GOhard"                => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2196         "gotoTerminal"          => array("version" => "2.5", "class" => "terminals","file" => "goto.schema"),
2197         "goServer"              => array("version" => "2.4","class" => "server","file" => "goserver.schema"),
2198         "goTerminalServer"      => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2199         "goShareServer"         => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2200         "goNtpServer"           => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2201         "goSyslogServer"        => array("version" => "2.4", "class" => "terminals","file" => "goto.schema"),
2202         "goLdapServer"          => array("version" => "2.4"),
2203         "goCupsServer"          => array("version" => "2.4", "class" => array("posixAccount", "terminals"),),
2204         "goImapServer"          => array("version" => "2.4", "class" => array("mailAccount", "mailgroup"),"file" => "gosa+samba3.        schema"),
2205         "goKrbServer"           => array("version" => "2.4"),
2206         "goFaxServer"           => array("version" => "2.4", "class" => "gofaxAccount","file" => "gofax.schema"),
2207         ) as $name => $values){
2209           $checks[$name] = $def_check;
2210           if(isset($values['version'])){
2211             $checks[$name]["REQUIRED_VERSION"] = $values['version'];
2212           }
2213           if(isset($values['file'])){
2214             $checks[$name]["SCHEMA_FILES"] = array($values['file']);
2215           }
2216           $checks[$name]["CLASSES_REQUIRED"] = array($name);
2217         }
2218   foreach($checks as $name => $value){
2219     foreach($value['CLASSES_REQUIRED'] as $class){
2221       if(!isset($objectclasses[$name])){
2222         $checks[$name]['STATUS'] = FALSE;
2223         if($value['IS_MUST_HAVE']){
2224           $checks[$name]['MSG']    = sprintf(_("The required objectClass '%s' is not present in your schema setup"),$class);
2225         }else{
2226           $checks[$name]['MSG']    = sprintf(_("The optional objectClass '%s' is not present in your schema setup"),$class);
2227         }
2228       }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
2229         $checks[$name]['STATUS'] = FALSE;
2231         if($value['IS_MUST_HAVE']){
2232           $checks[$name]['MSG'] = sprintf(_("The required objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2233         }else{
2234           $checks[$name]['MSG'] = sprintf(_("The optional objectclass '%s' does not have version %s"), $class,                           $value['REQUIRED_VERSION']);
2235         }
2236       }else{
2237         $checks[$name]['STATUS'] = TRUE;
2238         $checks[$name]['MSG'] = sprintf(_("Class(es) available"));
2239       }
2240     }
2241   }
2243   $tmp = $objectclasses;
2245   /* The gosa base schema */
2246   $checks['posixGroup'] = $def_check;
2247   $checks['posixGroup']['REQUIRED_VERSION'] = "2.4";
2248   $checks['posixGroup']['SCHEMA_FILES']     = array("gosa+samba3.schema","gosa.schema");
2249   $checks['posixGroup']['CLASSES_REQUIRED'] = array("posixGroup");
2250   $checks['posixGroup']['STATUS']           = TRUE;
2251   $checks['posixGroup']['IS_MUST_HAVE']     = TRUE;
2252   $checks['posixGroup']['MSG']              = "";
2253   $checks['posixGroup']['INFO']             = "";
2255   /* Depending on selected rfc2307bis mode, we need different schema configurations */
2256   if(isset($tmp['posixGroup'])){
2258     if($rfc2307bis && isset($tmp['posixGroup']['STRUCTURAL'])){
2259       $checks['posixGroup']['STATUS']           = FALSE;
2260       $checks['posixGroup']['MSG']              = _("You have enabled the rfc2307bis option on the 'ldap setup' step, but your schema    configuration do not support this option.");
2261       $checks['posixGroup']['INFO']             = _("In order to use rfc2307bis conform groups the objectClass 'posixGroup' must be      AUXILIARY");
2262     }
2263     if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
2264       $checks['posixGroup']['STATUS']           = FALSE;
2265       $checks['posixGroup']['MSG']              = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema   configuration do not support this option.");
2266       $checks['posixGroup']['INFO']             = _("The objectClass 'posixGroup' must be STRUCTURAL");
2267     }
2268   }
2270   return($checks);
2274 function prepare4mailbody($string)
2276   $string = html_entity_decode($string);
2278   $from = array(
2279                 "/%/",
2280                 "/ /",
2281                 "/\n/",
2282                 "/\r/",
2283                 "/!/",
2284                 "/#/",
2285                 "/\*/",
2286                 "/\//",
2287                 "/</",
2288                 "/>/",
2289                 "/\?/",
2290                 "/\"/");
2292   $to = array(
2293                 "%25",
2294                 "%20",
2295                 "%0A",
2296                 "%0D",
2297                 "%21",
2298                 "%23",
2299                 "%2A",
2300                 "%2F",
2301                 "%3C",
2302                 "%3E",
2303                 "%3F",
2304                 "%22");
2306   $string = preg_replace($from,$to,$string);
2308   return($string);
2314 function get_languages($languages_in_own_language = FALSE,$strip_region_tag = FALSE)
2316   $tmp = array(
2317         "de_DE" => "German",
2318         "fr_FR" => "French",
2319         "it_IT" => "Italian",
2320         "es_ES" => "Spanish",
2321         "en_US" => "English",
2322         "nl_NL" => "Dutch",
2323         "pl_PL" => "Polish",
2324         "sv_SE" => "Swedish",
2325         "zh_CN" => "Chinese",
2326         "ru_RU" => "Russian");
2327   
2328   $tmp2= array(
2329         "de_DE" => _("German"),
2330         "fr_FR" => _("French"),
2331         "it_IT" => _("Italian"),
2332         "es_ES" => _("Spanish"),
2333         "en_US" => _("English"),
2334         "nl_NL" => _("Dutch"),
2335         "pl_PL" => _("Polish"),
2336         "sv_SE" => _("Swedish"),
2337         "zh_CN" => _("Chinese"),
2338         "ru_RU" => _("Russian"));
2340   $ret = array();
2341   if($languages_in_own_language){
2343     $old_lang = setlocale(LC_ALL, 0);
2344     foreach($tmp as $key => $name){
2345       $lang = $key.".UTF-8";
2346       setlocale(LC_ALL, $lang);
2347       if($strip_region_tag){
2348         $ret[preg_replace("/^([^_]*).*$/","\\1",$key)] = _($name)." (".$tmp2[$key].")";
2349       }else{
2350         $ret[$key] = _($name)." &nbsp;(".$tmp2[$key].")";
2351       }
2352     }
2353     setlocale(LC_ALL, $old_lang);
2354   }else{
2355     foreach($tmp as $key => $name){
2356       if($strip_region_tag){
2357         $ret[preg_replace("/^([^_]*).*/","\\1",$key)] = _($name);
2358       }else{
2359         $ret[$key] = _($name);
2360       }
2361     }
2362   }
2363   return($ret);
2367 /* Returns contents of the given POST variable and check magic quotes settings */
2368 function get_post($name)
2370   if(!isset($_POST[$name])){
2371     trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
2372     return(FALSE);
2373   }
2374   if(get_magic_quotes_gpc()){
2375     return(stripcslashes($_POST[$name]));
2376   }else{
2377     return($_POST[$name]);
2378   }
2382 /* Check if $ip1 and $ip2 represents a valid IP range 
2383  *  returns TRUE in case of a valid range, FALSE in case of an error. 
2384  */
2385 function is_ip_range($ip1,$ip2)
2387   if(!is_ip($ip1) || !is_ip($ip2)){
2388     return(FALSE);
2389   }else{
2390     $ar1 = split("\.",$ip1);
2391     $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
2393     $ar2 = split("\.",$ip2);
2394     $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
2395     return($var1 < $var2);
2396   }
2400 /* Check if the specified IP address $address is inside the given network */
2401 function is_in_network($network, $netmask, $address)
2403   $nw= split('\.', $network);
2404   $nm= split('\.', $netmask);
2405   $ad= split('\.', $address);
2407   /* Generate inverted netmask */
2408   for ($i= 0; $i<4; $i++){
2409     $ni[$i]= 255-$nm[$i];
2410     $la[$i]= $nw[$i] | $ni[$i];
2411   }
2413   /* Transform to integer */
2414   $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
2415   $curr=  $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
2416   $last=  $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
2418   return ($first < $curr&& $last > $curr);
2421 /* Return class name in correct case 
2422  *  mailMethodkolab =>  mailMethodKolab  ( k => K )
2423  */
2424 function get_correct_class_name($cls)
2426   global $class_mapping;
2427   if(isset($class_mapping) && is_array($class_mapping)){
2428     foreach($class_mapping as $class => $file){
2429       if(preg_match("/^".$cls."$/i",$class)){
2430         return($class);
2431       }
2432     }
2433   }
2434   return(FALSE);
2437 // change_password, changes the Password, of the given dn
2438 function change_password ($dn, $password, $mode=0, $hash= "")
2440   global $config;
2441   $newpass= "";
2443   /* Convert to lower. Methods are lowercase */
2444   $hash= strtolower($hash);
2446   // Get all available encryption Methods
2448   // NON STATIC CALL :)
2449   $tmp = new passwordMethod($_SESSION['config']);
2450   $available = $tmp->get_available_methods();
2452   // read current password entry for $dn, to detect the encryption Method
2453   $ldap       = $config->get_ldap_link();
2454   $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
2455   $attrs      = $ldap->fetch ();
2457   // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
2458   if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
2459     $deactivated = TRUE;
2460   }else{
2461     $deactivated = FALSE;
2462   }
2464  // Detect the encryption Method
2465   if ( (isset($attrs['userPassword'][0]) &&  preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) ||  $hash != ""){
2467     /* Check for supported algorithm */
2468     mt_srand((double) microtime()*1000000);
2470     /* Extract used hash */
2471     if ($hash == ""){
2472       $hash= strtolower($matches[1]);
2473     }
2475     $test = new  $available[$hash]($config);
2477   } else {
2478     // User MD5 by default
2479     $hash= "md5";
2480     $test = new  $available['md5']($config);
2481   }
2483   /* Feed password backends with information */
2484   $test->dn= $dn;
2485   $test->attrs= $attrs;
2486   $newpass= $test->generate_hash($password);
2488   // Update shadow timestamp?
2489   if (isset($attrs["shadowLastChange"][0])){
2490     $shadow= (int)(date("U") / 86400);
2491   } else {
2492     $shadow= 0;
2493   }
2495   // Write back modified entry
2496   $ldap->cd($dn);
2497   $attrs= array();
2499   // Not for groups
2500   if ($mode == 0){
2502     if ($shadow != 0){
2503       $attrs['shadowLastChange']= $shadow;
2504     }
2506     // Create SMB Password
2507     $attrs= generate_smb_nt_hash($password);
2508   }
2510  /* Readd ! if user was deactivated */
2511   if($deactivated){
2512     $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
2513   }
2515   $attrs['userPassword']= array();
2516   $attrs['userPassword']= $newpass;
2518   $ldap->modify($attrs);
2520   new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
2522   if ($ldap->error != 'Success') {
2523     print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),
2524           $ldap->get_error()));
2525   } else {
2527     /* Run backend method for change/create */
2528     $test->set_password($password);
2530     /* Find postmodify entries for this class */
2531     $command= $config->search("password", "POSTMODIFY",array('menu'));
2533     if ($command != ""){
2534       /* Walk through attribute list */
2535       $command= preg_replace("/%userPassword/", $password, $command);
2536       $command= preg_replace("/%dn/", $dn, $command);
2538       if (check_command($command)){
2539         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
2540         exec($command);
2541       } else {
2542         $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password");
2543         print_red ($message);
2544       }
2545     }
2546   }
2548 // Return something like array['sambaLMPassword']= "lalla..."
2549 function generate_smb_nt_hash($password)
2551   global $config;
2552   $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
2553   @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
2555   exec($tmp, $ar);
2556   flush();
2557   reset($ar);
2558   $hash= current($ar);
2559   if ($hash == "")
2560   {
2561     print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
2562   }
2563   else
2564   {
2565     list($lm,$nt)= split (":", trim($hash));
2567     if ($config->current['SAMBAVERSION'] == 3)
2568     {
2569       $attrs['sambaLMPassword']= $lm;
2570       $attrs['sambaNTPassword']= $nt;
2571       $attrs['sambaPwdLastSet']= date('U');
2572       $attrs['sambaBadPasswordCount']= "0";
2573       $attrs['sambaBadPasswordTime']= "0";
2574     } else {
2575       $attrs['lmPassword']= $lm;
2576       $attrs['ntPassword']= $nt;
2577       $attrs['pwdLastSet']= date('U');
2578     }
2579     return($attrs);
2580   }
2583 function crypt_single($string,$enc_type )
2585   return( passwordMethod::crypt_single_str($string,$enc_type));
2589 /* This function returns the offset for the default timezone. 
2590  * $stamp is used to detect summer or winter time.
2591  * In case of PHP5, the integrated timezone functions are used.
2592  * For PHP4 we query an array for offset and add summertime hour.
2593  */
2594 function get_default_timezone($stamp = NULL)
2596   global $config;
2597   $tz ="";
2599   /* Default return value if zone could not be detected */
2600   $zone = array("name" => "unconfigured", "value" => 0);
2602   /* Use current timestamp if $stamp is not set */
2603   if($stamp === NULL){
2604     $stamp = time();
2605   }
2607   /* Is there a timezone configured in the gosa configuration (gosa.conf) */
2608   if(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
2610     /* Get zonename */
2611     if(isset($config->current['TIMEZONE'])){
2612       $tz = $config->current['TIMEZONE'];
2613     }else{
2614       $tz = $config->data['MAIN']['TIMEZONE'];
2615     }
2617     if(!@date_default_timezone_set($tz)){
2618       print_red(sprintf(_("The timezone setting \"".$tz."\" in your gosa.conf is not valid. Can not calculate correct timezone offest."),$tz));
2619     }
2620     $tz_delta = date("Z", $stamp);
2621     $tz_delta = $tz_delta / 3600 ;
2622     return(array("name" => $tz, "value" => $tz_delta));
2624   }
2625   return($zone);
2629 /* Return zone informations */
2630 function _get_tz_zones()
2632   $timezones = array(
2633       'Africa/Abidjan' => 0,
2634       'Africa/Accra' => 0,
2635       'Africa/Addis_Ababa' => 10800,
2636       'Africa/Algiers' => 3600,
2637       'Africa/Asmera' => 10800,
2638       'Africa/Bamako' => 0,
2639       'Africa/Bangui' => 3600,
2640       'Africa/Banjul' => 0,
2641       'Africa/Bissau' => 0,
2642       'Africa/Blantyre' => 7200,
2643       'Africa/Brazzaville' => 3600,
2644       'Africa/Bujumbura' => 7200,
2645       'Africa/Cairo' => 7200,
2646       'Africa/Casablanca' => 0,
2647       'Africa/Ceuta' => 3600,
2648       'Africa/Conakry' => 0,
2649       'Africa/Dakar' => 0,
2650       'Africa/Dar_es_Salaam' => 10800,
2651       'Africa/Djibouti' => 10800,
2652       'Africa/Douala' => 3600,
2653       'Africa/El_Aaiun' => 0,
2654       'Africa/Freetown' => 0,
2655       'Africa/Gaborone' => 7200,
2656       'Africa/Harare' => 7200,
2657       'Africa/Johannesburg' => 7200,
2658       'Africa/Kampala' => 10800,
2659       'Africa/Khartoum' => 10800,
2660       'Africa/Kigali' => 7200,
2661       'Africa/Kinshasa' => 3600,
2662       'Africa/Lagos' => 3600,
2663       'Africa/Libreville' => 3600,
2664       'Africa/Lome' => 0,
2665       'Africa/Luanda' => 3600,
2666       'Africa/Lubumbashi' => 7200,
2667       'Africa/Lusaka' => 7200,
2668       'Africa/Malabo' => 3600,
2669       'Africa/Maputo' => 7200,
2670       'Africa/Maseru' => 7200,
2671       'Africa/Mbabane' => 7200,
2672       'Africa/Mogadishu' => 10800,
2673       'Africa/Monrovia' => 0,
2674       'Africa/Nairobi' => 10800,
2675       'Africa/Ndjamena' => 3600,
2676       'Africa/Niamey' => 3600,
2677       'Africa/Nouakchott' => 0,
2678       'Africa/Ouagadougou' => 0,
2679       'Africa/Porto-Novo' => 3600,
2680       'Africa/Sao_Tome' => 0,
2681       'Africa/Timbuktu' => 0,
2682       'Africa/Tripoli' => 7200,
2683       'Africa/Tunis' => 3600,
2684       'Africa/Windhoek' => 3600,
2685       'America/Adak' => -36000,
2686       'America/Anchorage' => -32400,
2687       'America/Anguilla' => -14400,
2688       'America/Antigua' => -14400,
2689       'America/Araguaina' => -10800,
2690       'America/Argentina/Buenos_Aires' => 0,
2691       'America/Argentina/Catamarca' => 0,
2692       'America/Argentina/ComodRivadavia' => 0,
2693       'America/Argentina/Cordoba' => 0,
2694       'America/Argentina/Jujuy' => 0,
2695       'America/Argentina/La_Rioja' => 0,
2696       'America/Argentina/Mendoza' => 0,
2697       'America/Argentina/Rio_Gallegos' => 0,
2698       'America/Argentina/San_Juan' => 0,
2699       'America/Argentina/Tucuman' => 0,
2700       'America/Argentina/Ushuaia' => 0,
2701       'America/Aruba' => -14400,
2702       'America/Asuncion' => -14400,
2703       'America/Atikokan' => 0,
2704       'America/Atka' => -36000,
2705       'America/Bahia' => 0,
2706       'America/Barbados' => -14400,
2707       'America/Belem' => -10800,
2708       'America/Belize' => -21600,
2709       'America/Blanc-Sablon' => 0,
2710       'America/Boa_Vista' => -14400,
2711       'America/Bogota' => -18000,
2712       'America/Boise' => -25200,
2713       'America/Buenos_Aires' => -10800,
2714       'America/Cambridge_Bay' => -25200,
2715       'America/Campo_Grande' => 0,
2716       'America/Cancun' => -21600,
2717       'America/Caracas' => -14400,
2718       'America/Catamarca' => -10800,
2719       'America/Cayenne' => -10800,
2720       'America/Cayman' => -18000,
2721       'America/Chicago' => -21600,
2722       'America/Chihuahua' => -25200,
2723       'America/Coral_Harbour' => 0,
2724       'America/Cordoba' => -10800,
2725       'America/Costa_Rica' => -21600,
2726       'America/Cuiaba' => -14400,
2727       'America/Curacao' => -14400,
2728       'America/Danmarkshavn' => 0,
2729       'America/Dawson' => -28800,
2730       'America/Dawson_Creek' => -25200,
2731       'America/Denver' => -25200,
2732       'America/Detroit' => -18000,
2733       'America/Dominica' => -14400,
2734       'America/Edmonton' => -25200,
2735       'America/Eirunepe' => -18000,
2736       'America/El_Salvador' => -21600,
2737       'America/Ensenada' => -28800,
2738       'America/Fort_Wayne' => -18000,
2739       'America/Fortaleza' => -10800,
2740       'America/Glace_Bay' => -14400,
2741       'America/Godthab' => -10800,
2742       'America/Goose_Bay' => -14400,
2743       'America/Grand_Turk' => -18000,
2744       'America/Grenada' => -14400,
2745       'America/Guadeloupe' => -14400,
2746       'America/Guatemala' => -21600,
2747       'America/Guayaquil' => -18000,
2748       'America/Guyana' => -14400,
2749       'America/Halifax' => -14400,
2750       'America/Havana' => -18000,
2751       'America/Hermosillo' => -25200,
2752       'America/Indiana/Indianapolis' => -18000,
2753       'America/Indiana/Knox' => -18000,
2754       'America/Indiana/Marengo' => -18000,
2755       'America/Indiana/Petersburg' => 0,
2756       'America/Indiana/Vevay' => -18000,
2757       'America/Indiana/Vincennes' => 0,
2758       'America/Indianapolis' => -18000,
2759       'America/Inuvik' => -25200,
2760       'America/Iqaluit' => -18000,
2761       'America/Jamaica' => -18000,
2762       'America/Jujuy' => -10800,
2763       'America/Juneau' => -32400,
2764       'America/Kentucky/Louisville' => -18000,
2765       'America/Kentucky/Monticello' => -18000,
2766       'America/Knox_IN' => -18000,
2767       'America/La_Paz' => -14400,
2768       'America/Lima' => -18000,
2769       'America/Los_Angeles' => -28800,
2770       'America/Louisville' => -18000,
2771       'America/Maceio' => -10800,
2772       'America/Managua' => -21600,
2773       'America/Manaus' => -14400,
2774       'America/Martinique' => -14400,
2775       'America/Mazatlan' => -25200,
2776       'America/Mendoza' => -10800,
2777       'America/Menominee' => -21600,
2778       'America/Merida' => -21600,
2779       'America/Mexico_City' => -21600,
2780       'America/Miquelon' => -10800,
2781       'America/Moncton' => 0,
2782       'America/Monterrey' => -21600,
2783       'America/Montevideo' => -10800,
2784       'America/Montreal' => -18000,
2785       'America/Montserrat' => -14400,
2786       'America/Nassau' => -18000,
2787       'America/New_York' => -18000,
2788       'America/Nipigon' => -18000,
2789       'America/Nome' => -32400,
2790       'America/Noronha' => -7200,
2791       'America/North_Dakota/Center' => -21600,
2792       'America/North_Dakota/New_Salem' => 0,
2793       'America/Panama' => -18000,
2794       'America/Pangnirtung' => -18000,
2795       'America/Paramaribo' => -10800,
2796       'America/Phoenix' => -25200,
2797       'America/Port-au-Prince' => -18000,
2798       'America/Port_of_Spain' => -14400,
2799       'America/Porto_Acre' => -18000,
2800       'America/Porto_Velho' => -14400,
2801       'America/Puerto_Rico' => -14400,
2802       'America/Rainy_River' => -21600,
2803       'America/Rankin_Inlet' => -21600,
2804       'America/Recife' => -10800,
2805       'America/Regina' => -21600,
2806       'America/Rio_Branco' => -18000,
2807       'America/Rosario' => -10800,
2808       'America/Santiago' => -14400,
2809       'America/Santo_Domingo' => -14400,
2810       'America/Sao_Paulo' => -10800,
2811       'America/Scoresbysund' => -3600,
2812       'America/Shiprock' => -25200,
2813       'America/St_Johns' => -12600,
2814       'America/St_Kitts' => -14400,
2815       'America/St_Lucia' => -14400,
2816       'America/St_Thomas' => -14400,
2817       'America/St_Vincent' => -14400,
2818       'America/Swift_Current' => -21600,
2819       'America/Tegucigalpa' => -21600,
2820       'America/Thule' => -14400,
2821       'America/Thunder_Bay' => -18000,
2822       'America/Tijuana' => -28800,
2823       'America/Toronto' => 0,
2824       'America/Tortola' => -14400,
2825       'America/Vancouver' => -28800,
2826       'America/Virgin' => -14400,
2827       'America/Whitehorse' => -28800,
2828       'America/Winnipeg' => -21600,
2829       'America/Yakutat' => -32400,
2830       'America/Yellowknife' => -25200,
2831       'Antarctica/Casey' => 28800,
2832       'Antarctica/Davis' => 25200,
2833       'Antarctica/DumontDUrville' => 36000,
2834       'Antarctica/Mawson' => 21600,
2835       'Antarctica/McMurdo' => 43200,
2836       'Antarctica/Palmer' => -14400,
2837       'Antarctica/Rothera' => 0,
2838       'Antarctica/South_Pole' => 43200,
2839       'Antarctica/Syowa' => 10800,
2840       'Antarctica/VostokArctic/Longyearbyen' => 0,
2841       'Asia/Aden' => 10800,
2842       'Asia/Almaty' => 21600,
2843       'Asia/Amman' => 7200,
2844       'Asia/Anadyr' => 43200,
2845       'Asia/Aqtau' => 14400,
2846       'Asia/Aqtobe' => 18000,
2847       'Asia/Ashgabat' => 18000,
2848       'Asia/Ashkhabad' => 18000,
2849       'Asia/Baghdad' => 10800,
2850       'Asia/Bahrain' => 10800,
2851       'Asia/Baku' => 14400,
2852       'Asia/Bangkok' => 25200,
2853       'Asia/Beirut' => 7200,
2854       'Asia/Bishkek' => 18000,
2855       'Asia/Brunei' => 28800,
2856       'Asia/Calcutta' => 19800,
2857       'Asia/Choibalsan' => 32400,
2858       'Asia/Chongqing' => 28800,
2859       'Asia/Chungking' => 28800,
2860       'Asia/Colombo' => 21600,
2861       'Asia/Dacca' => 21600,
2862       'Asia/Damascus' => 7200,
2863       'Asia/Dhaka' => 21600,
2864       'Asia/Dili' => 32400,
2865       'Asia/Dubai' => 14400,
2866       'Asia/Dushanbe' => 18000,
2867       'Asia/Gaza' => 7200,
2868       'Asia/Harbin' => 28800,
2869       'Asia/Hong_Kong' => 28800,
2870       'Asia/Hovd' => 25200,
2871       'Asia/Irkutsk' => 28800,
2872       'Asia/Istanbul' => 7200,
2873       'Asia/Jakarta' => 25200,
2874       'Asia/Jayapura' => 32400,
2875       'Asia/Jerusalem' => 7200,
2876       'Asia/Kabul' => 16200,
2877       'Asia/Kamchatka' => 43200,
2878       'Asia/Karachi' => 18000,
2879       'Asia/Kashgar' => 28800,
2880       'Asia/Katmandu' => 20700,
2881       'Asia/Krasnoyarsk' => 25200,
2882       'Asia/Kuala_Lumpur' => 28800,
2883       'Asia/Kuching' => 28800,
2884       'Asia/Kuwait' => 10800,
2885       'Asia/Macao' => 28800,
2886       'Asia/Macau' => 0,
2887       'Asia/Magadan' => 39600,
2888       'Asia/Makassar' => 0,
2889       'Asia/Manila' => 28800,
2890       'Asia/Muscat' => 14400,
2891       'Asia/Nicosia' => 7200,
2892       'Asia/Novosibirsk' => 21600,
2893       'Asia/Omsk' => 21600,
2894       'Asia/Oral' => 0,
2895       'Asia/Phnom_Penh' => 25200,
2896       'Asia/Pontianak' => 25200,
2897       'Asia/Pyongyang' => 32400,
2898       'Asia/Qatar' => 10800,
2899       'Asia/Qyzylorda' => 0,
2900       'Asia/Rangoon' => 23400,
2901       'Asia/Riyadh' => 10800,
2902       'Asia/Saigon' => 25200,
2903       'Asia/Sakhalin' => 36000,
2904       'Asia/Samarkand' => 18000,
2905       'Asia/Seoul' => 32400,
2906       'Asia/Shanghai' => 28800,
2907       'Asia/Singapore' => 28800,
2908       'Asia/Taipei' => 28800,
2909       'Asia/Tashkent' => 18000,
2910       'Asia/Tbilisi' => 14400,
2911       'Asia/Tehran' => 12600,
2912       'Asia/Tel_Aviv' => 7200,
2913       'Asia/Thimbu' => 21600,
2914       'Asia/Thimphu' => 21600,
2915       'Asia/Tokyo' => 32400,
2916       'Asia/Ujung_Pandang' => 28800,
2917       'Asia/Ulaanbaatar' => 28800,
2918       'Asia/Ulan_Bator' => 28800,
2919       'Asia/Urumqi' => 28800,
2920       'Asia/Vientiane' => 25200,
2921       'Asia/Vladivostok' => 36000,
2922       'Asia/Yakutsk' => 32400,
2923       'Asia/Yekaterinburg' => 18000,
2924       'Asia/YerevanAtlantic/Azores' => 0,
2925       'Atlantic/Bermuda' => -14400,
2926       'Atlantic/Canary' => 0,
2927       'Atlantic/Cape_Verde' => -3600,
2928       'Atlantic/Faeroe' => 0,
2929       'Atlantic/Jan_Mayen' => 3600,
2930       'Atlantic/Madeira' => 0,
2931       'Atlantic/Reykjavik' => 0,
2932       'Atlantic/South_Georgia' => -7200,
2933       'Atlantic/St_Helena' => 0,
2934       'Atlantic/Stanley' => -14400,
2935       'Australia/ACT' => 36000,
2936       'Australia/Adelaide' => 34200,
2937       'Australia/Brisbane' => 36000,
2938       'Australia/Broken_Hill' => 34200,
2939       'Australia/Canberra' => 36000,
2940       'Australia/Currie' => 0,
2941       'Australia/Darwin' => 34200,
2942       'Australia/Hobart' => 36000,
2943       'Australia/LHI' => 37800,
2944       'Australia/Lindeman' => 36000,
2945       'Australia/Lord_Howe' => 37800,
2946       'Australia/Melbourne' => 36000,
2947       'Australia/NSW' => 36000,
2948       'Australia/North' => 34200,
2949       'Australia/Perth' => 28800,
2950       'Australia/Queensland' => 36000,
2951       'Australia/South' => 34200,
2952       'Australia/Sydney' => 36000,
2953       'Australia/Tasmania' => 36000,
2954       'Australia/Victoria' => 36000,
2955       'Australia/West' => 28800,
2956       'Australia/Yancowinna' => 34200,
2957       'Europe/Amsterdam' => 3600,
2958       'Europe/Andorra' => 3600,
2959       'Europe/Athens' => 7200,
2960       'Europe/Belfast' => 0,
2961       'Europe/Belgrade' => 3600,
2962       'Europe/Berlin' => 3600,
2963       'Europe/Bratislava' => 3600,
2964       'Europe/Brussels' => 3600,
2965       'Europe/Bucharest' => 7200,
2966       'Europe/Budapest' => 3600,
2967       'Europe/Chisinau' => 7200,
2968       'Europe/Copenhagen' => 3600,
2969       'Europe/Dublin' => 0,
2970       'Europe/Gibraltar' => 3600,
2971       'Europe/Guernsey' => 0,
2972       'Europe/Helsinki' => 7200,
2973       'Europe/Isle_of_Man' => 0,
2974       'Europe/Istanbul' => 7200,
2975       'Europe/Jersey' => 0,
2976       'Europe/Kaliningrad' => 7200,
2977       'Europe/Kiev' => 7200,
2978       'Europe/Lisbon' => 0,
2979       'Europe/Ljubljana' => 3600,
2980       'Europe/London' => 0,
2981       'Europe/Luxembourg' => 3600,
2982       'Europe/Madrid' => 3600,
2983       'Europe/Malta' => 3600,
2984       'Europe/Mariehamn' => 0,
2985       'Europe/Minsk' => 7200,
2986       'Europe/Monaco' => 3600,
2987       'Europe/Moscow' => 10800,
2988       'Europe/Nicosia' => 7200,
2989       'Europe/Oslo' => 3600,
2990       'Europe/Paris' => 3600,
2991       'Europe/Prague' => 3600,
2992       'Europe/Riga' => 7200,
2993       'Europe/Rome' => 3600,
2994       'Europe/Samara' => 14400,
2995       'Europe/San_Marino' => 3600,
2996       'Europe/Sarajevo' => 3600,
2997       'Europe/Simferopol' => 7200,
2998       'Europe/Skopje' => 3600,
2999       'Europe/Sofia' => 7200,
3000       'Europe/Stockholm' => 3600,
3001       'Europe/Tallinn' => 7200,
3002       'Europe/Tirane' => 3600,
3003       'Europe/Tiraspol' => 7200,
3004       'Europe/Uzhgorod' => 7200,
3005       'Europe/Vaduz' => 3600,
3006       'Europe/Vatican' => 3600,
3007       'Europe/Vienna' => 3600,
3008       'Europe/Vilnius' => 7200,
3009       'Europe/Volgograd' => 0,
3010       'Europe/Warsaw' => 3600,
3011       'Europe/Zagreb' => 3600,
3012       'Europe/Zaporozhye' => 7200,
3013       'Europe/Zurich' => 3600,
3014       'Indian/Antananarivo' => 10800,
3015       'Indian/Chagos' => 21600,
3016       'Indian/Christmas' => 25200,
3017       'Indian/Cocos' => 23400,
3018       'Indian/Comoro' => 10800,
3019       'Indian/Kerguelen' => 18000,
3020       'Indian/Mahe' => 14400,
3021       'Indian/Maldives' => 18000,
3022       'Indian/Mauritius' => 14400,
3023       'Indian/Mayotte' => 10800,
3024       'Indian/Reunion' => 14400,
3025       'Pacific/Apia' => -39600,
3026       'Pacific/Auckland' => 43200,
3027       'Pacific/Chatham' => 45900,
3028       'Pacific/Easter' => -21600,
3029       'Pacific/Efate' => 39600,
3030       'Pacific/Enderbury' => 46800,
3031       'Pacific/Fakaofo' => -36000,
3032       'Pacific/Fiji' => 43200,
3033       'Pacific/Funafuti' => 43200,
3034       'Pacific/Galapagos' => -21600,
3035       'Pacific/Gambier' => -32400,
3036       'Pacific/Guadalcanal' => 39600,
3037       'Pacific/Guam' => 36000,
3038       'Pacific/Honolulu' => -36000,
3039       'Pacific/Johnston' => -36000,
3040       'Pacific/Kiritimati' => 50400,
3041       'Pacific/Kosrae' => 39600,
3042       'Pacific/Kwajalein' => 43200,
3043       'Pacific/Majuro' => 43200,
3044       'Pacific/Marquesas' => -34200,
3045       'Pacific/Midway' => -39600,
3046       'Pacific/Nauru' => 43200,
3047       'Pacific/Niue' => -39600,
3048       'Pacific/Norfolk' => 41400,
3049       'Pacific/Noumea' => 39600,
3050       'Pacific/Pago_Pago' => -39600,
3051       'Pacific/Palau' => 32400,
3052       'Pacific/Pitcairn' => -28800,
3053       'Pacific/Ponape' => 39600,
3054       'Pacific/Port_Moresby' => 36000,
3055       'Pacific/Rarotonga' => -36000,
3056       'Pacific/Saipan' => 36000,
3057       'Pacific/Samoa' => -39600,
3058       'Pacific/Tahiti' => -36000,
3059       'Pacific/Tarawa' => 43200,
3060       'Pacific/Tongatapu' => 46800,
3061       'Pacific/Truk' => 36000,
3062       'Pacific/Wake' => 43200,
3063       'Pacific/Wallis' => 43200,
3064       'Pacific/Yap' => 36000 );          
3066   $dst_timezones = array (  
3067       'America/Adak' => 1,
3068       'America/Atka' => 1,
3069       'America/Anchorage' => 1,
3070       'America/Juneau' => 1,
3071       'America/Nome' => 1,
3072       'America/Yakutat' => 1,
3073       'America/Dawson' => 1,
3074       'America/Ensenada' => 1,
3075       'America/Los_Angeles' => 1,
3076       'America/Tijuana' => 1,
3077       'America/Vancouver' => 1,
3078       'America/Whitehorse' => 1,
3079       'America/Boise' => 1,
3080       'America/Cambridge_Bay' => 1,
3081       'America/Chihuahua' => 1,
3082       'America/Denver' => 1,
3083       'America/Edmonton' => 1,
3084       'America/Inuvik' => 1,
3085       'America/Mazatlan' => 1,
3086       'America/Shiprock' => 1,
3087       'America/Yellowknife' => 1,
3088       'America/Cancun' => 1,
3089       'America/Chicago' => 1,
3090       'America/Menominee' => 1,
3091       'America/Merida' => 1,
3092       'America/Monterrey' => 1,
3093       'America/North_Dakota/Center' => 1,
3094       'America/Rainy_River' => 1,
3095       'America/Rankin_Inlet' => 1,
3096       'America/Winnipeg' => 1,
3097       'Pacific/Easter' => 1,
3098       'America/Detroit' => 1,
3099       'America/Grand_Turk' => 1,
3100       'America/Havana' => 1,
3101       'America/Iqaluit' => 1,
3102       'America/Kentucky/Louisville' => 1,
3103       'America/Kentucky/Monticello' => 1,
3104       'America/Louisville' => 1,
3105       'America/Montreal' => 1,
3106       'America/Nassau' => 1,
3107       'America/New_York' => 1,
3108       'America/Nipigon' => 1,
3109       'America/Pangnirtung' => 1,
3110       'America/Thunder_Bay' => 1,
3111       'America/Asuncion' => 1,
3112       'America/Cuiaba' => 1,
3113       'America/Glace_Bay' => 1,
3114       'America/Goose_Bay' => 1,
3115       'America/Halifax' => 1,
3116       'America/Santiago' => 1,
3117       'Antarctica/Palmer' => 1,
3118       'Atlantic/Bermuda' => 1,
3119       'Atlantic/Stanley' => 1,
3120       'America/St_Johns' => 1,
3121       'America/Araguaina' => 1,
3122       'America/Fortaleza' => 1,
3123       'America/Godthab' => 1,
3124       'America/Maceio' => 1,
3125       'America/Miquelon' => 1,
3126       'America/Recife' => 1,
3127       'America/Sao_Paulo' => 1,
3128       'America/Scoresbysund' => 1,
3129       'Atlantic/Canary' => 1,
3130       'Atlantic/Faeroe' => 1,
3131       'Atlantic/Madeira' => 1,
3132       'Europe/Belfast' => 1,
3133       'Europe/Dublin' => 1,
3134       'Europe/Lisbon' => 1,
3135       'Europe/London' => 1,
3136       'Africa/Ceuta' => 1,
3137       'Africa/Windhoek' => 1,
3138       'Atlantic/Jan_Mayen' => 1,
3139       'Europe/Amsterdam' => 1,
3140       'Europe/Andorra' => 1,
3141       'Europe/Belgrade' => 1,
3142       'Europe/Berlin' => 1,
3143       'Europe/Bratislava' => 1,
3144       'Europe/Brussels' => 1,
3145       'Europe/Budapest' => 1,
3146       'Europe/Copenhagen' => 1,
3147       'Europe/Gibraltar' => 1,
3148       'Europe/Ljubljana' => 1,
3149       'Europe/Luxembourg' => 1,
3150       'Europe/Madrid' => 1,
3151       'Europe/Malta' => 1,
3152       'Europe/Monaco' => 1,
3153       'Europe/Oslo' => 1,
3154       'Europe/Paris' => 1,
3155       'Europe/Prague' => 1,
3156       'Europe/Rome' => 1,
3157       'Europe/San_Marino' => 1,
3158       'Europe/Sarajevo' => 1,
3159       'Europe/Skopje' => 1,
3160       'Europe/Stockholm' => 1,
3161       'Europe/Tirane' => 1,
3162       'Europe/Vaduz' => 1,
3163       'Europe/Vatican' => 1,
3164       'Europe/Vienna' => 1,
3165       'Europe/Warsaw' => 1,
3166       'Europe/Zagreb' => 1,
3167       'Europe/Zurich' => 1,
3168       'Africa/Cairo' => 1,
3169       'Asia/Amman' => 1,
3170       'Asia/Beirut' => 1,
3171       'Asia/Damascus' => 1,
3172       'Asia/Gaza' => 1,
3173       'Asia/Istanbul' => 1,
3174       'Asia/Jerusalem' => 1,
3175       'Asia/Nicosia' => 1,
3176       'Asia/Tel_Aviv' => 1,
3177       'Europe/Athens' => 1,
3178       'Europe/Bucharest' => 1,
3179       'Europe/Chisinau' => 1,
3180       'Europe/Helsinki' => 1,
3181       'Europe/Istanbul' => 1,
3182       'Europe/Kaliningrad' => 1,
3183       'Europe/Kiev' => 1,
3184       'Europe/Minsk' => 1,
3185       'Europe/Nicosia' => 1,
3186       'Europe/Riga' => 1,
3187       'Europe/Simferopol' => 1,
3188       'Europe/Sofia' => 1,
3189       'Europe/Tiraspol' => 1,
3190       'Europe/Uzhgorod' => 1,
3191       'Europe/Zaporozhye' => 1,
3192       'Asia/Baghdad' => 1,
3193       'Europe/Moscow' => 1,
3194       'Asia/Tehran' => 1,
3195       'Asia/Aqtau' => 1,
3196       'Asia/Baku' => 1,
3197       'Asia/Tbilisi' => 1,
3198       'Europe/Samara' => 1,
3199       'Asia/Aqtobe' => 1,
3200       'Asia/Bishkek' => 1,
3201       'Asia/Yekaterinburg' => 1,
3202       'Asia/Almaty' => 1,
3203       'Asia/Novosibirsk' => 1,
3204       'Asia/Omsk' => 1,
3205       'Asia/Krasnoyarsk' => 1,
3206       'Asia/Irkutsk' => 1,
3207       'Asia/Yakutsk' => 1,
3208       'Australia/Adelaide' => 1,
3209       'Australia/Broken_Hill' => 1,
3210       'Australia/South' => 1,
3211       'Australia/Yancowinna' => 1,
3212       'Asia/Sakhalin' => 1,
3213       'Asia/Vladivostok' => 1,
3214       'Australia/ACT' => 1,
3215       'Australia/Canberra' => 1,
3216       'Australia/Hobart' => 1,
3217       'Australia/Melbourne' => 1,
3218       'Australia/NSW' => 1,
3219       'Australia/Sydney' => 1,
3220       'Australia/Tasmania' => 1,
3221       'Australia/Victoria' => 1,
3222       'Australia/LHI' => 1,
3223       'Australia/Lord_Howe' => 1,
3224       'Asia/Magadan' => 1,
3225       'Antarctica/McMurdo' => 1,
3226       'Antarctica/South_Pole' => 1,
3227       'Asia/Anadyr' => 1,
3228       'Asia/Kamchatka' => 1,
3229       'Pacific/Auckland' => 1,
3230       'Pacific/Chatham' => 1,
3231       );  
3232   return(array("TIMEZONES" => $timezones, "DST_ZONES" => $dst_timezones));
3234 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
3235 ?>