| 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. |
|---|
| 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 |
|---|
| 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. |
|---|
| 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 |
|---|
| 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; |
|---|
| 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"); |
|---|
| 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 | |
|---|
| 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)---------------------------- |
|---|
| 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)); |
|---|
| 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 |
|---|
| 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 |
|---|
| 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); |
|---|