Changeset 209

Show
Ignore:
Timestamp:
02/14/07 16:30:10 (2 years ago)
Author:
ludo
Message:

lang detection fixes for phpwebmin (from r4017)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/webmin/lbs_common/debian/changelog

    r194 r209  
    1 webmin-lbs-common (1.4.11) stable; urgency=low 
     1webmin-lbs-common (1.4.12) stable; urgency=low 
    22 
    33  * New release. See SVN logs for details 
  • trunk/webmin/lbs_common/module.info

    r194 r209  
    55name=lbs_common 
    66depends=0.94 
    7 version=1.4.11 
     7version=1.4.12 
  • trunk/webmin/lbs_common/web-lib.php

    r110 r209  
    66# Translated from web-lib.pl. Compatible with php >= 4.2.0 
    77# 
    8 # Copyright (C) 2003 Free & ALter Soft, Linbox, Ludovic Drolez 
     8# Copyright (C) 2003-2007 Free & ALter Soft, Linbox, Ludovic Drolez 
    99# 
    1010# Distributed under the terms of the modified BSD license. 
     
    2424$base_remote_user = getenv("BASE_REMOTE_USER"); 
    2525$remote_user = getenv("REMOTE_USER"); 
    26 //__DATA__ 
    27  
    28  
    29 /*---------------------------lib_PrintHeader($charset)---------------------------- 
    30 Outputs the http header for HTML 
    31 */   
     26 
     27 
     28# --lib_PrintHeader($charset)---------------------------- 
     29# Outputs the http header for HTML   
    3230function lib_PrintHeader($charset){ 
    33   $num_args=func_num_args(); //number of arguments passed to the function 
    34   if($pragma_no_cache || $config[pragma_no_cache]) 
    35     Header("Pragma: no-cache\n"); 
    36   if($num_args>0) 
    37     header("Content-type: text/html; Charset=$charset\n\n"); 
    38   else Header("Content-type: text/html\n\n"); 
    39 
    40  
    41 /*--lib_header($title,$image,$help,$config,$nomodule,$nowebmin,$rightside,$header,$body)----- 
    42 Output a page header with some title and image. The header 
    43 may also include a link to help, and a link to the config 
    44 page.  The header will also have a link to the webmin index, 
    45 and a link to the module menu if there is no config link. 
    46 */ 
     31        $num_args=func_num_args(); //number of arguments passed to the function 
     32        if($pragma_no_cache || $config[pragma_no_cache]) 
     33                Header("Pragma: no-cache\n"); 
     34        if($num_args>0) 
     35                header("Content-type: text/html; Charset=$charset\n\n"); 
     36        else Header("Content-type: text/html\n\n"); 
     37
     38 
     39# --lib_header($title,$image,$help,$config,$nomodule,$nowebmin,$rightside,$header,$body)----- 
     40# Output a page header with some title and image. The header 
     41# may also include a link to help, and a link to the config 
     42# page.  The header will also have a link to the webmin index, 
     43# and a link to the module menu if there is no config link. 
    4744function lib_header($title=undef,$image=undef,$help=undef,$config=undef,$nomodule=undef, 
    4845                    $nowebmin=undef,$rightside=undef,$header=undef,$body=undef){ 
    49 global $gconfig; 
    50 global $text; 
    51 global $tconfig; 
    52 global $remote_user; 
    53 global $module_name; 
    54 global $module_info;  
     46       global $gconfig; 
     47       global $text; 
     48       global $tconfig; 
     49       global $remote_user; 
     50       global $module_name; 
     51       global $module_info;  
    5552 
    5653        $num_args=func_num_args(); //number of arguments passed to the function 
    5754      
    58         # trouver le nom de la module presante 
    5955        if($gconfig["lang"]=="en") 
    6056                $tit = substr($title, 0, strpos($title, " ")); 
     
    6359         
    6460        if (function_exists('theme_header')) { 
    65             if (theme_header($tit, $rightside))  
    66               return; 
     61               if (theme_header($tit, $rightside))  
     62                      return; 
    6763        } 
    6864    
     
    151147                $bgimage=""; 
    152148         
    153        # FIXME: vérifier que body n'est pas undef      
     149# FIXME: vérifier que body n'est pas undef     
    154150        echo "<body bgcolor=#$bgcolor link=#$link vlink=#$link text=#$_text $bgimage $tconfig[inbody] $body>\n"; 
    155151         
     
    184180                                $_user="(Local user)"; 
    185181                        else 
    186                         $_user=""; 
     182                               $_user=""; 
    187183                         
    188184                        echo "<td colspan=3 align=center>\n"; 
     
    219215                        if (!$access[noconfig]) { 
    220216                                echo"<a href=\"/config.cgi?$mod_name\">", 
    221                                 $text[header_config],"</a><br>\n"; 
     217                                       $text[header_config],"</a><br>\n"; 
    222218                        } 
    223219                } 
     
    242238                                        echo "<img src=/images/letters/$ll.gif alt=\"\&nbsp;\" align=bottom>"; 
    243239                                } else { 
    244                                   echo "<img src=/images/letters/$ll.gif alt=\"$l\" align=bottom>"; 
     240                                       echo "<img src=/images/letters/$ll.gif alt=\"$l\" align=bottom>"; 
    245241                                } 
    246242                        } 
     
    256252} 
    257253 
    258 /*------------------------------------lib_hlink($text,$page,$module)------------------------- 
    259 Returns HTML for alink to help page. The first parameter is the test of the  
    260 link and the second the name of the help page. 
    261 */ 
     254#-----lib_hlink($text,$page,$module)------------------------- 
     255# Returns HTML for alink to help page. The first parameter is the test of the  
     256# link and the second the name of the help page. 
    262257function lib_hlink($text,$page,$module=undef){ 
    263   $mod_name=lib_get_module_name(); 
    264   $mod=($module!=undef) ? $module : $mod_name; 
    265   return "<a onClick='window.open(\"/help.cgi/$mod/$page\", \"help\", \"toolbar=no,menubar=no,scrollbars=yes,width=400,height=300,resizable=yes\"); return false' href=\"/help.cgi/$mod/$page\">$text</a>"; 
    266 
    267  
    268 /*------------------------------------lib_get_system_hostname()--------------------------------- 
    269 Returns the hostname of this system 
    270 */ 
     258        $mod_name=lib_get_module_name(); 
     259        $mod=($module!=undef) ? $module : $mod_name; 
     260        return "<a onClick='window.open(\"/help.cgi/$mod/$page\", \"help\", \"toolbar=no,menubar=no,scrollbars=yes,width=400,height=300,resizable=yes\"); return false' href=\"/help.cgi/$mod/$page\">$text</a>"; 
     261
     262 
     263#------------------------------------lib_get_system_hostname()--------------------------------- 
     264# Returns the hostname of this system 
    271265function lib_get_system_hostname(){ 
    272   $hostname=`hostname`; //run a shell command 
    273   return $hostname ; 
    274 
    275  
    276 /*------------------------------------lib_get_webmin_version()--------------------------------- 
    277 Returns the version of Webmin currently being run 
    278 */ 
     266        $hostname=`hostname`; //run a shell command 
     267        return $hostname ; 
     268
     269 
     270#------------------------------------lib_get_webmin_version()--------------------------------- 
     271# Returns the version of Webmin currently being run 
    279272function lib_get_webmin_version(){ 
    280   //$VERSION=fopen("../version","r") || VERSION=fopen("../version","r"); 
    281      
    282   //flose($VERSION); 
    283   return 0.91; 
    284 
    285  
    286 /*------------------------------------lib_get_module_acl($user,$module)--------------------------------- 
    287 Return an array containing acces control options for the given user  
    288 */ 
     273        //$VERSION=fopen("../version","r") || VERSION=fopen("../version","r"); 
     274     
     275        //flose($VERSION); 
     276        return 0.91; 
     277
     278 
     279#------------------------------------lib_get_module_acl($user,$module)--------------------------------- 
     280# Return an array containing acces control options for the given user  
    289281function lib_get_module_acl($user=undef,$module=undef){ 
    290   global $base_remote_user; 
    291   global $remote_user; 
    292   global $module_name; 
    293   global $config_directory; 
    294   global $gconfig; //associative array 
    295      
    296   //    $u=($user!=undef) ? $user : $base_remote_user; 
    297   //    $u=($user!=undef) ? $user : $remote_user; 
    298   $u=($user!=undef) ? $user : "admin"; //admin par defaut              
    299   //echo"user:$u<br>"; 
    300   //echo"base_remote_user:$base_remote_user<br>"; 
    301   $mod_name=lib_get_module_name();     
    302   $m=($module!=undef) ? $module : $mod_name; 
    303   //echo"module:$m:$module<br>";     
    304   $rv=lib_read_file($module_name ? "../$m/"."defaultacl" : ".$m"."defaultacl"); 
    305   if($gconfig["risk_$u"] && $m){ 
    306     $rf=$gconfig["risk_u"].'.risk'; 
    307     $rv=lib_read_file($module_name ? "../$m/$rf" : "./$m/$rf"); 
    308     $sf=$gconfig["skill_u"].'.skill'; 
    309     $rv=lib_read_file($module_name ? "../$m/$sf" : "./$m/$sf"); 
    310  
    311   else $rv=lib_read_file("$config_directory/$m/$u.acl"); 
    312      
    313   return $rv; 
    314 } 
    315 /*------------------------------------lib_get_module_name()--------------------------------- 
    316 Returns the name of the current module.This fonction is useful in php because  
    317 if the script exemple.cgi is run module_name=/module_name/example.cgi. 
    318 */ 
     282       global $base_remote_user; 
     283       global $remote_user; 
     284       global $module_name; 
     285       global $config_directory; 
     286       global $gconfig; //associative array 
     287     
     288       //    $u=($user!=undef) ? $user : $base_remote_user; 
     289       //    $u=($user!=undef) ? $user : $remote_user; 
     290       $u=($user!=undef) ? $user : "admin"; //admin par defaut                 
     291       //echo"user:$u<br>"; 
     292       //echo"base_remote_user:$base_remote_user<br>"; 
     293       $mod_name=lib_get_module_name();     
     294       $m=($module!=undef) ? $module : $mod_name; 
     295       //echo"module:$m:$module<br>";     
     296       $rv=lib_read_file($module_name ? "../$m/"."defaultacl" : ".$m"."defaultacl"); 
     297       if($gconfig["risk_$u"] && $m){ 
     298               $rf=$gconfig["risk_u"].'.risk'; 
     299               $rv=lib_read_file($module_name ? "../$m/$rf" : "./$m/$rf"); 
     300               $sf=$gconfig["skill_u"].'.skill'; 
     301               $rv=lib_read_file($module_name ? "../$m/$sf" : "./$m/$sf"); 
     302       
     303       else $rv=lib_read_file("$config_directory/$m/$u.acl"); 
     304     
     305       return $rv; 
     306} 
     307 
     308#------------------------------------lib_get_module_name()--------------------------------- 
     309# Returns the name of the current module.This fonction is useful in php because  
     310# if the script exemple.cgi is run module_name=/module_name/example.cgi. 
    319311function lib_get_module_name(){ 
    320   global $module_name; 
    321   list($nul,$mod_name,$_nul)=split("/",$module_name); 
    322   return $mod_name; 
    323 
    324  
    325 /*------------------------------------lib_footer($page,$name)--------------------------------- 
    326 Output a footer for returning to some page 
    327 */ 
     312        global $module_name; 
     313        list($nul,$mod_name,$_nul)=split("/",$module_name); 
     314        return $mod_name; 
     315
     316 
     317#------------------------------------lib_footer($page,$name)--------------------------------- 
     318# Output a footer for returning to some page 
    328319function lib_footer($page,$name){ 
    329   //Global variables used in this function 
    330   global $text; //$text is an associative array initialised in init_config 
    331   global $module_info; //associative array 
    332   global $module_name; 
    333  
    334   if (function_exists('theme_footer')) { 
    335     if (theme_footer())  
    336         return;  
    337  
     320       //Global variables used in this function 
     321       global $text; //$text is an associative array initialised in init_config 
     322       global $module_info; //associative array 
     323       global $module_name; 
     324 
     325       if (function_exists('theme_footer')) { 
     326               if (theme_footer())  
     327                       return;  
     328       
    338329   
    339   $url=$page; 
    340   if($url == "/"){ 
    341     $url="/?cat=$module_info[category]"; 
    342   } 
    343   elseif($url == "" && $module_name){ 
    344     $url=" ";//return to the last page 
    345   } 
    346   elseif( ereg("?",$url) || ereg($module_name,$url) ){ 
    347     $url="/$module_name/$url"; 
    348   } 
    349      
    350   $link=lib_text("main_return",$name); 
    351  
    352   echo "<a href=\"$url\"><img alt=\"<-\" align=middle border=0 src=/images/left.gif></a>\n"; 
    353   echo "<a href=\"$url\">$link</a><br>\n"; 
    354 
    355  
    356  
    357 /*--------------------------------------lib_read_file($file)---------------------------------- 
    358 Fill an associative array with name=value pairs from a file 
    359 */ 
     330        $url=$page; 
     331        if($url == "/"){ 
     332                $url="/?cat=$module_info[category]"; 
     333        } 
     334        elseif($url == "" && $module_name){ 
     335                $url=" ";//return to the last page 
     336        } 
     337        elseif( ereg("?",$url) || ereg($module_name,$url) ){ 
     338                $url="/$module_name/$url"; 
     339        } 
     340     
     341        $link=lib_text("main_return",$name); 
     342 
     343        echo "<a href=\"$url\"><img alt=\"<-\" align=middle border=0 src=/images/left.gif></a>\n"; 
     344        echo "<a href=\"$url\">$link</a><br>\n"; 
     345
     346 
     347 
     348#--------------------------------------lib_read_file($file)---------------------------------- 
     349# Fill an associative array with name=value pairs from a file 
    360350function lib_read_file($file){ 
    361   $delimiter="="; 
    362   if(is_dir($file)) 
    363     return -1; 
    364   if (!file_exists($file)) 
    365           return -1; 
    366   if(!$fp=fopen($file,"r"))  
    367     return -1; 
    368   while(!feof($fp)){ 
    369     $current_line=fgets($fp,255); 
    370     $current_line=trim($current_line); 
    371     //trim delete all space in the string, try chop() and ltrim() 
    372      
    373     list($option,$value)=explode($delimiter,$current_line,2); 
    374     $assoc_array[$option]=$value; 
    375   } 
    376   fclose($fp); 
    377   return $assoc_array; 
    378 
    379 /*-------------------------------------lib_init_config()------------------------------------ 
    380 set the following variables: 
    381     $gconfig : Global configuration 
    382     $config : module configuration 
    383     $module_info 
    384     $tconfig 
    385     $tb - Background for table headers 
    386     $cb - Background for table bodies 
    387     $current_lang 
    388     global $link_css; 
    389      
    390 */      
     351        $delimiter="="; 
     352        if(is_dir($file)) 
     353                return -1; 
     354        if (!file_exists($file)) 
     355                return -1; 
     356        if(!$fp=fopen($file,"r"))  
     357                return -1; 
     358        while(!feof($fp)){ 
     359                $current_line=fgets($fp,255); 
     360                $current_line=trim($current_line); 
     361                //trim delete all space in the string, try chop() and ltrim() 
     362     
     363                list($option,$value)=explode($delimiter,$current_line,2); 
     364                $assoc_array[$option]=$value; 
     365        } 
     366        fclose($fp); 
     367        return $assoc_array; 
     368
     369 
     370#-------------------------------------lib_init_config()------------------------------------ 
     371# set the following variables: 
     372#    $gconfig : Global configuration 
     373#    $config : module configuration 
     374#    $module_info 
     375#    $tconfig 
     376#    $tb - Background for table headers 
     377#    $cb - Background for table bodies 
     378#    $current_lang 
     379#    global $link_css;      
    391380function lib_init_config(){ 
    392   //Global variables used in this function 
    393   global $config_directory; 
    394   global $module_name; 
    395   global $module_directory; 
    396   global $webmin_path; 
    397   global $cb, $tb; 
    398   global $current_lang; 
    399   global $gconfig, $tconfig; 
    400   global $link_css; 
     381       //Global variables used in this function 
     382       global $config_directory; 
     383       global $module_name; 
     384       global $module_directory; 
     385       global $webmin_path; 
     386       global $cb, $tb; 
     387       global $current_lang; 
     388       global $gconfig, $tconfig; 
     389       global $link_css; 
    401390   
    402   global $remote_user; 
    403   $link_css = "./tmpl/presentation.css"; 
    404  
    405   //Read the webmin global config file and fill the associative array $gconfig 
    406   $GLOBALS["gconfig"]=lib_read_file($config_directory."/config"); 
     391       global $remote_user; 
     392       $link_css = "./tmpl/presentation.css"; 
     393 
     394       //Read the webmin global config file and fill the associative array $gconfig 
     395       $GLOBALS["gconfig"]=lib_read_file($config_directory."/config"); 
    407396   
    408   //Set PATH and LD_LIBRARY_PATH 
    409   //if($gconfig[path]) putenv(PATH=$gconfig[path]); 
    410   //if($gconfig[ld_env]) putenv($gconfig[ld_env]=gconfig[ld_path]); 
    411  
    412   list($nul,$m,$_nul)=split("/",$module_name); 
    413   $GLOBALS["config"]=lib_read_file($config_directory."/".$m."/config"); 
     397       //Set PATH and LD_LIBRARY_PATH 
     398       //if($gconfig[path]) putenv(PATH=$gconfig[path]); 
     399       //if($gconfig[ld_env]) putenv($gconfig[ld_env]=gconfig[ld_path]); 
     400 
     401       list($nul,$m,$_nul)=split("/",$module_name); 
     402       $GLOBALS["config"]=lib_read_file($config_directory."/".$m."/config"); 
    414403   
    415   $GLOBALS["module_info"]=lib_read_file($webmin_path."/".$module_directory."/module.info"); 
    416   //Load language string into associative array named $text 
    417   $GLOBALS["text"]=lib_load_language(); 
    418      
    419   $theme=lib_check_key_array($GLOBALS["gconfig"],theme); 
    420  
    421   if($theme){ 
    422     $tconfig = lib_read_file($module_name ? $webmin_path . "/" . $theme . "/config" 
    423                                       : $webmin_path . "../" . $theme . "/config"); 
    424   } 
    425  
    426   // set default table colors 
    427   $tb = "bgcolor=#9999ff"; 
    428   if (isset ($gconfig['cs_header'])) $tb = "bgcolor=#".$gconfig['cs_header']; 
    429   if (isset ($tconfig['cs_header'])) $tb = "bgcolor=#".$tconfig['cs_header']; 
    430  
    431   $cb = "bgcolor=#cccccc"; 
    432   if (isset ($gconfig['cs_table'])) $cb = "bgcolor=#".$gconfig['cs_table']; 
    433   if (isset ($tconfig['cs_table'])) $cb = "bgcolor=#".$tconfig['cs_table']; 
    434  
    435   $current_lang = isset($gconfig["lang_$remote_user"]) ? $gconfig["lang_$remote_user"] :  
    436             (isset($gconfig["lang"]) ? $gconfig["lang"] : "en"); 
    437      
    438   // $key=lib_array_to_keystring($GLOBALS["text"]); 
    439   // $val=lib_array_to_valstring($GLOBALS["text"]); 
    440   // echo"<br>$key<br>$val<br>";     
    441  
    442   //    echo"sans arg<br>"; 
    443   //    lib_ReadParse(); 
    444   //    echo"avec gconfig<br>"; 
    445   //    lib_ReadParse($GLOBALS["gconfig"]); 
    446   //test_display_array($GLOBALS["gconfig"]);  
    447 
    448  
    449 /*----------------------lib_check_key_array($assoc_array,$key)----------------------------- 
    450 check if the key passed to the function exist,return the corresponding value else return 0   
    451 if(lib_check_key_array($GLOBALS["gconfig"],theme)){ 
    452         echo"existing key<br>";  
    453     } 
    454     else echo"this key is not in this array<br>"; 
    455 
    456 */      
     404        $GLOBALS["module_info"]=lib_read_file($webmin_path."/".$module_directory."/module.info"); 
     405     
     406        $theme=lib_check_key_array($GLOBALS["gconfig"],theme); 
     407 
     408        if($theme){ 
     409                $tconfig = lib_read_file($module_name ? $webmin_path . "/" . $theme . "/config" 
     410                                         : $webmin_path . "../" . $theme . "/config"); 
     411        } 
     412 
     413        // set default table colors 
     414        $tb = "bgcolor=#9999ff"; 
     415        if (isset ($gconfig['cs_header'])) $tb = "bgcolor=#".$gconfig['cs_header']; 
     416        if (isset ($tconfig['cs_header'])) $tb = "bgcolor=#".$tconfig['cs_header']; 
     417 
     418        $cb = "bgcolor=#cccccc"; 
     419        if (isset ($gconfig['cs_table'])) $cb = "bgcolor=#".$gconfig['cs_table']; 
     420        if (isset ($tconfig['cs_table'])) $cb = "bgcolor=#".$tconfig['cs_table']; 
     421 
     422        $current_lang = isset($gconfig["lang_$remote_user"]) ? $gconfig["lang_$remote_user"] :  
     423                (isset($gconfig["lang"]) ? $gconfig["lang"] : "en"); 
     424 
     425        // change the lang according to the browser settings 
     426        if ($gconfig{'acceptlang'}) { 
     427                $langs = (file("$webmin_path/lang_list.txt")); 
     428                foreach (preg_split("/,/", $_SERVER{'HTTP_ACCEPT_LANGUAGE'}) as $testlang) { 
     429                        if (preg_grep("/lang=$testlang/", $langs)) { 
     430                                $current_lang = $testlang; 
     431                                break; 
     432                        } 
     433                } 
     434        } 
     435 
     436        //Load language string into associative array named $text 
     437        $GLOBALS["text"] = lib_load_language(); 
     438     
     439
     440 
     441#----------------------lib_check_key_array($assoc_array,$key)----------------------------- 
     442# check if the key passed to the function exist,return the corresponding value else return 0   
     443# if(lib_check_key_array($GLOBALS["gconfig"],theme)){ 
     444#       echo"existing key<br>";  
     445#    } 
     446#    else echo"this key is not in this array<br>"; 
     447#} 
     448      
    457449function lib_check_key_array($assoc_array,$key){ 
    458   //test_display_array($assoc_array);   
    459   if($assoc_array[$key]) $rv=$assoc_array[$key]; 
    460   else $rv=0; 
    461   return $rv;  
    462 
    463  
    464 /*---------------------------lib_ReadParse($assoc_array,$method)---------------------------- 
    465 fills the given associative array with cgi paramaters, or uses the globals $in 
    466 if none is given. 
    467 */      
     450        //test_display_array($assoc_array);   
     451        if($assoc_array[$key]) $rv=$assoc_array[$key]; 
     452        else $rv=0; 
     453        return $rv;  
     454
     455 
     456#---------------------------lib_ReadParse($assoc_array,$method)---------------------------- 
     457# fills the given associative array with cgi paramaters, or uses the globals $in 
     458# if none is given.      
    468459function lib_ReadParse($assoc_array=undef,$method=undef){ 
    469460 
     
    493484        } 
    494485}*/ 
    495 /*---------------------------lib_redirect($url)---------------------------- 
    496 Output headers to redirect the browser to some page 
    497 */      
     486 
     487#---------------------------lib_redirect($url)---------------------------- 
     488# Output headers to redirect the browser to some page      
    498489function lib_redirect($url){ 
    499   global $module_info; 
    500   $server_port=getenv("SERVER_PORT"); 
    501   $https=getenv("HTTPS"); 
    502   $server_name=getenv("SERVER_NAME"); 
    503   $script_name=getenv("SCRIPT_NAME "); 
    504      
    505   if( ($server_port==443) && ($https=="ON")) $port=""; 
    506   elseif( ($server_port==80) && ($https!="ON")) $port=""; 
    507   else $port=$server_port;           
    508   if($https=="ON") $prot="https"; 
    509   else $prot="http"; 
    510      
    511   if(ereg("http",$url) | ereg("https",$url) | ereg("ftp",$url) | ereg("gopher",$url)){ 
    512     Header("Location: $url"); 
    513   } 
    514   elseif(ereg("/^\//",$url)){ 
    515     Header("Location: $prot://$server_name:$port$url"); 
    516   } 
    517   elseif(ereg("/^(.*)\/[^\/]*$/",$sript_name)){ 
    518     Header("Location: $prot://$server_name:$port$1/$url"); 
    519   } 
    520   elseif($url==""){//return to the current module category  
    521     Header("Location: $prot://$server_name:$port/$url/?cat=$module_info[category]"); 
    522   } 
    523   else Header("Location: $prot://$server_name:$port/$url");  
    524 
    525  
    526 /*---------------------------lib_get_module_info($module)---------------------------- 
    527  
    528 */      
     490        global $module_info; 
     491        $server_port=getenv("SERVER_PORT"); 
     492        $https=getenv("HTTPS"); 
     493        $server_name=getenv("SERVER_NAME"); 
     494        $script_name=getenv("SCRIPT_NAME "); 
     495     
     496        if( ($server_port==443) && ($https=="ON")) $port=""; 
     497        elseif( ($server_port==80) && ($https!="ON")) $port=""; 
     498        else $port=$server_port;             
     499        if($https=="ON") $prot="https"; 
     500        else $prot="http"; 
     501     
     502        if(ereg("http",$url) | ereg("https",$url) | ereg("ftp",$url) | ereg("gopher",$url)){ 
     503                Header("Location: $url"); 
     504        } 
     505        elseif(ereg("/^\//",$url)){ 
     506                Header("Location: $prot://$server_name:$port$url"); 
     507        } 
     508        elseif(ereg("/^(.*)\/[^\/]*$/",$sript_name)){ 
     509                Header("Location: $prot://$server_name:$port$1/$url"); 
     510        } 
     511        elseif($url==""){//return to the current module category  
     512                Header("Location: $prot://$server_name:$port/$url/?cat=$module_info[category]"); 
     513        } 
     514        else Header("Location: $prot://$server_name:$port/$url");  
     515
     516 
     517#---------------------------lib_get_module_info($module)----------------------------      
    529518function lib_get_module_info($module){ 
    530519 
    531520} 
    532521 
    533 /*---------------------------lib_load_language()---------------------------- 
    534 Returns a hashtable mapping text codes to strings in the appropriate language 
    535 */      
     522#---------------------------lib_load_language()---------------------------- 
     523# Returns a hashtable mapping text codes to strings in the appropriate language      
    536524function lib_load_language(){ 
    537525        //Global variables used in this module   
    538         global $webmin_path, $gconfig, $module_name, $remote_user, $module_directory
     526        global $webmin_path, $gconfig, $module_name, $remote_user, $module_directory, $current_lang
    539527         
    540528        // should we backport webmin's @lang_order_list to phpwebmin ?? 
    541         $lang = $gconfig[lang]; 
    542         if ( $gconfig["lang_".$remote_user] != "") 
    543                 $lang = $gconfig["lang_".$remote_user]; 
    544          
    545         //fill the associative array $text with the correct language 
    546         //firsty with general text codes: /path/to/webmin-0.91/lang/current_language 
    547         if (!$lang) { 
    548                 $lang="en"; 
    549                 $gconfig['lang']=$lang; 
    550         } 
    551  
    552  
    553         $text=lib_read_file($webmin_path."/lang/".$lang); 
    554  
    555         //secondly with module text codes: /path/to/webmin-0.91/current_module/lang/current_language 
    556         if($module_name){ 
    557                 $text_mod=lib_read_file(realpath($webmin_path . "/" . $module_directory . "/lang/".$lang)); 
     529        $lang = $current_lang;   
     530        $text = lib_read_file($webmin_path."/lang/".$lang); 
     531 
     532        //secondly with module text codes: /path/to/webmin/current_module/lang/current_language 
     533        if ($module_name) { 
     534                $text_mod = lib_read_file(realpath($webmin_path . "/" . $module_directory . "/lang/".$lang)); 
    558535         
    559536                //fill $text with the content of $text_mod 
     
    565542} 
    566543 
    567 /*------------------------lib_text($message,$substitute,$sub2,$sub3)-------------------------- 
    568 Looks up the given message in the appropriate language translation file, replaces 
    569 the text $1, $2 and so on with the rest of the parameters, and returns the result. 
    570 I suppose there is only 3 substituted arguments passed to the function($1,$2,$3). 
    571 If an other substituted argument is added, you should add one for this function. 
    572 To check the number of substituted arguments open read this file:  
    573 /path/to/webmin-0.91/lang/en      
    574 */      
     544#------------------------lib_text($message,$substitute,$sub2,$sub3)-------------------------- 
     545# Looks up the given message in the appropriate language translation file, replaces 
     546# the text $1, $2 and so on with the rest of the parameters, and returns the result. 
     547# I suppose there is only 3 substituted arguments passed to the function($1,$2,$3). 
     548# If an other substituted argument is added, you should add one for this function. 
     549# To check the number of substituted arguments open read this file:  
     550# /path/to/webmin/lang/en           
    575551function lib_text($message,$substitute,$sub2=nul,$sub3=nul){ 
    576   global $text; //$text is an associative array 
    577      
    578   $rv=$text[$message]; 
    579   $num_args=func_num_args(); //number of arguments passed to the function 
    580   $args_list=func_get_args(); //$args_list is an associative array 
    581      
    582   for($i=1;$i<$num_args;$i++){ 
    583     $replace=func_get_arg($i); 
    584     $rv=str_replace("\$$i",$replace,$rv); 
    585   } 
    586   return $rv; 
    587 
    588  
    589 /*-------------------------lib_array_to_keystring($assoc_array)-------------------------------- 
    590 Push all key of an array into a string Instead of passing an array from 
    591 a script to an other one(it's not possible with php???), we could passed 
    592 a string.So this function built a string with all key of this array 
    593 */ 
     552        global $text; //$text is an associative array 
     553     
     554        $rv=$text[$message]; 
     555        $num_args=func_num_args(); //number of arguments passed to the function 
     556        $args_list=func_get_args(); //$args_list is an associative array 
     557     
     558        for($i=1;$i<$num_args;$i++){ 
     559                $replace=func_get_arg($i); 
     560                $rv=str_replace("\$$i",$replace,$rv); 
     561        } 
     562        return $rv; 
     563
     564 
     565#-------------------------lib_array_to_keystring($assoc_array)-------------------------------- 
     566# Push all key of an array into a string Instead of passing an array from 
     567# a script to an other one(it's not possible with php???), we could passed 
     568# a string.So this function built a string with all key of this array 
    594569function lib_array_to_keystring($assoc_array){ 
    595   $separator=" |#| "; 
    596   while(list($key,$value)=each($assoc_array)){ 
    597     if($key!="") $key_string=$key_string.$key.$separator; 
    598   }     
    599   return $key_string; 
    600 } 
    601 /*---------------------------lib_array_to_valstring($assoc_array)-------------------------------- 
    602 this function built a string with all value of an array  
    603 */ 
     570       $separator=" |#| "; 
     571       while(list($key,$value)=each($assoc_array)){ 
     572               if($key!="") $key_string=$key_string.$key.$separator; 
     573       }     
     574       return $key_string; 
     575} 
     576 
     577#---------------------------lib_array_to_valstring($assoc_array)-------------------------------- 
     578# this function built a string with all value of an array  
    604579function lib_array_to_valstring($assoc_array){ 
    605   $val_string=implode(" |#| ",$assoc_array); 
    606   return $val_string; 
    607 } 
    608 /*---------------------------lib_convert_str_to_array($keystr,$valstr)-------------------------------- 
    609 This function built an associative array from 2 strings. 
    610 I didn't used explose because keys become numbers.    
    611 */ 
     580       $val_string=implode(" |#| ",$assoc_array); 
     581       return $val_string; 
     582} 
     583 
     584#---------------------------lib_convert_str_to_array($keystr,$valstr)-------------------------------- 
     585# This function built an associative array from 2 strings. 
     586# I didn't used explose because keys become numbers.    
    612587function lib_convert_str_to_array($keystr,$valstr){ 
    613   while(list($key,$value)=each($assoc_array)){ 
    614      
    615   } 
    616 
    617  
    618 /*--------------lib_read_env_file($file)---------------------------- 
    619 Reads a file of /bin/sh variable assignments in key=value or  
    620 key = "value" format into the given associative array. 
    621 */ 
     588        while(list($key,$value)=each($assoc_array)){ 
     589     
     590        } 
     591
     592 
     593#--------------lib_read_env_file($file)---------------------------- 
     594# Reads a file of /bin/sh variable assignments in key=value or  
     595# key = "value" format into the given associative array. 
    622596function lib_read_env_file($file)  
    623597{ 
    624   $arr = array(); 
    625  
    626   $fd = fopen($file, "r"); 
    627   if (!$fd) return($arr); 
    628   while (!feof ($fd)) { 
    629     $buffer = fgets($fd, 4096); 
    630     $buffer = preg_replace("/#.*$/","",$buffer); 
    631     if (preg_match('/([A-Za-z0-9_\.]+)\s*=\s*"(.*)"/', $buffer, $m) || 
    632         preg_match("/([A-Za-z0-9_\.]+)\s*=\s*'(.*)'/", $buffer, $m) || 
    633         preg_match("/([A-Za-z0-9_\.]+)\s*=\s*(.*)/", $buffer, $m))  
    634      
    635         $arr[$m[1]] = $m[2]; 
    636      
    637  
    638   fclose($fd); 
    639  
    640   return($arr); 
     598       $arr = array(); 
     599 
     600       $fd = fopen($file, "r"); 
     601       if (!$fd) return($arr); 
     602       while (!feof ($fd)) { 
     603               $buffer = fgets($fd, 4096); 
     604               $buffer = preg_replace("/#.*$/","",$buffer); 
     605               if (preg_match('/([A-Za-z0-9_\.]+)\s*=\s*"(.*)"/', $buffer, $m) || 
     606                   preg_match("/([A-Za-z0-9_\.]+)\s*=\s*'(.*)'/", $buffer, $m) || 
     607                   preg_match("/([A-Za-z0-9_\.]+)\s*=\s*(.*)/", $buffer, $m))  
     608                       
     609                               $arr[$m[1]] = $m[2]; 
     610                       
     611       
     612       fclose($fd); 
     613 
     614       return($arr); 
    641615} 
    642616 
    643617######################### NEW FUNCTIONS BELOW ########################## 
    644618 
     619#---------tmplInit($array) 
    645620# 
    646621# Set the default templates path according to language settings 
     
    656631function tmplInit($arr = array()) 
    657632{ 
    658   global $gconfig, $tb, $cb, $remote_user
    659  
    660   $l = $gconfig["lang"]; 
    661   // should we backport webmin's @lang_order_list to phpwebmin ?? 
    662   if ( $gconfig["lang_".$remote_user] != "") { 
    663     $l = $gconfig["lang_".$remote_user]
    664  
     633       global $gconfig, $tb, $cb, $remote_user, $current_lang
     634 
     635        $l = $current_lang;   
     636        $d = "./tmpl/$l"; 
     637       if (!is_dir($d) || $l == "") { 
     638               $d = "./tmpl/en"
     639       
    665640   
    666   $d = "./tmpl/$l"; 
    667   if (!is_dir($d) || $l == "") { 
    668     $d = "./tmpl/en"; 
    669   } 
    670    
    671   $tpl = new Template($d, "remove"); 
    672   $tpl->set_file($arr); 
    673   $tpl->set_var(array( 
    674                       "TB" => $tb, 
    675                       "CB" => $cb 
    676                       )); 
    677  
    678   return ($tpl); 
    679 
    680  
    681                                 
     641        $tpl = new Template($d, "remove"); 
     642        $tpl->set_file($arr); 
     643        $tpl->set_var(array( 
     644                            "TB" => $tb, 
     645                            "CB" => $cb 
     646                            )); 
     647 
     648        return ($tpl); 
     649}                               
    682650?>