0) Header("Content-type: text/html; Charset=$charset\n\n"); else Header("Content-type: text/html\n\n"); } /*--LIB_header($title,$image,$help,$config,$nomodule,$nowebmin,$rightside,$header,$body)----- Output a page header with some title and image. The header may also include a link to help, and a link to the config page. The header will also have a link to the webmin index, and a link to the module menu if there is no config link. --------------------------------------------------------------------------------------------*/ function LIB_header($title=undef,$image=undef,$help=undef,$config=undef,$nomodule=undef, $nowebmin=undef,$rightside=undef,$header=undef,$body=undef){ global $gconfig; global $text; global $tconfig; global $remote_user; global $module_name; global $module_info; $num_args=func_num_args(); //number of arguments passed to the function /* foreach $l (&list_languages()) { $lang = $l if ($l->{'lang'} eq $current_lang); }*/ $charset=$force_charset ? $force_charset : "iso-8859-1"; LIB_PrintHeader($charset); echo"\n"; echo"\n"; if($charset){ echo"\n"; } $os_type = $gconfig[real_os_type] ? $gconfig[real_os_type] : $gconfig[os_type]; $os_version = $gconfig[real_os_version] ? $gconfig[real_os_version] : $gconfig[os_version]; $hostname=LIB_get_system_hostname(); $webmin_version=LIB_get_webmin_version(); //echo"os_type:$os_type,os_version:$os_version,hostname:$hostname,webmin_version:$webmin_version"; echo"\n"; if($num_args > 0){ //echo"gconfig[sysinfo]:$gconfig[sysinfo]
"; if ($gconfig[sysinfo] == 1) echo"$title: $remote_user on $hostname ($os_type $os_version)\n"; else echo"$title\n"; //echo"remote_user:$remote_user
"; if ($gconfig[sysinfo] == 0 && $remote_user) { $ssl_user=getenv("SSL_USER"); $local_user=getenv("LOCAL_USER"); if($ssl_user) $_user="(SSL certified)"; elseif($local_user) $_user="(Local user)"; else $_user=""; echo"\n"; } } //echo"tconfig[headhtml]:$tconfig[headhtml]
"; if ($tconfig[headhtml]) echo"$tconfig[headhtml]\n"; //echo"tconfig[headinclude]:$tconfig[headinclude]
"; if ($tconfig[headinclude]) { $file=$module_name ? "../$gconfig[theme]/$tconfig[headinclude]" : "$gconfig[theme]/$tconfig[headinclude]"; $INC=fopen($file,"r"); while(!feof($INC)){ $current_line=fgetss($INC,255); echo"$current_line"; } fclose($INC); /*EN perl open(INC, $module_name ? "../$gconfig[theme]/$tconfig[headinclude]" : "$gconfig[theme]/$tconfig[headinclude]"); while() { print; } close(INC);*/ } echo"\n"; if($tconfig[cs_page]) $bgcolor=$tconfig[cs_page]; elseif($gconfig[cs_page]) $bgcolor=$gconfig[cs_page]; else $bgcolor="ffffff"; if($tconfig[cs_link]) $link=$tconfig[cs_link]; elseif($gconfig[cs_link]) $link=$gconfig[cs_link]; else $link="0000ee"; if($tconfig[cs_text]) $_text=$tconfig[cs_text]; elseif($gconfig[cs_text]) $_text=$gconfig[cs_text]; else $_text="000000"; if($tconfig[bgimage]) $bgimage="background=$tconfig[bgimage]"; else $bgimage=""; echo"\n"; $hostname = LIB_get_system_hostname(); $version = LIB_get_webmin_version(); $prebody = $tconfig[prebody]; //echo"prebody:$prebody
"; /* if ($prebody) { $prebody =~ s/%HOSTNAME%/$hostname/g; $prebody =~ s/%VERSION%/$version/g; $prebody =~ s/%USER%/$remote_user/g; $prebody =~ s/%OS%/$os_type $os_version/g; print "$prebody\n"; }*/ //echo"tconfig[prebodyinclude]:$tconfig[prebodyinclude]
"; if ($tconfig[prebodyinclude]) { $file= $module_name ? "../$gconfig[theme]/$tconfig[prebodyinclude]" : "$gconfig[theme]/$tconfig[prebodyinclude]"; $INC=fopen($file,"r"); while(!feof($INC)){ $current_line=fgetss($INC,255); echo"$current_line"; } fclose($INC); } if ($num_args > 1) { echo"\n"; if ($gconfig[sysinfo] == 2 && $remote_user) { $ssl_user=getenv("SSL_USER"); $local_user=getenv("LOCAL_USER"); if($ssl_user) $_user="(SSL certified)"; elseif($local_user) $_user="(Local user)"; else $_user=""; echo"\n"; echo"\n"; } echo"\n"; ereg("s/ä/ä/g",$title); // $title =~ s/ä/ä/g; ereg("s/ö/ö/g",$title); //$title =~ s/ö/ö/g; ereg("s/ü/ü/g",$title); //$title =~ s/ü/ü/g; ereg("s/ / /g",$title); //$title =~ s/ / /g; if ($image!=undef) { echo"\n"; } /* elsif ($lang->{'titles'} && !$gconfig{'texttitles'} && !$tconfig{'texttitles'}) { print "\n"; } */ else { echo"\n"; } echo"
\n"; echo"$remote_user$_user logged into Webmin $version on \"$hostname\" ($os_type $os_version)
"; $http_webmin_server=getenv("HTTP_WEBMIN_SERVERS"); //echo"http_webmin_server:$http_webmin_server
"; if ($http_webmin_server) { echo"", "$text[header_servers]
\n"; } /* if (!nowebmin && !$tconfig[noindex]) { local %acl; &read_acl(undef, \%acl); local $mc = @{$acl{$base_remote_user}} == 1; if ($gconfig{'gotoone'} && $main::session_id && $mc == 1) { print "", "$text{'main_logout'}
"; } elsif ($gconfig{'gotoone'} && $mc == 1) { print "", "$text{'main_switch'}
"; } else { print "", "$text{'header_webmin'}
\n"; } } */ if ($nowebmin!=undef){ echo"$text[header_webmin]
\n"; } if ($nomodule!=undef) { echo"$text[header_module]
\n"; } if (is_array($help)) { echo LIB_hlink($text[header_help], $help[0], $help[1]),"
\n"; } elseif ($help!=undef) { echo LIB_hlink($text[header_help], $help),"
\n"; } if ($config!=undef) { $access = LIB_get_module_acl(); $mod_name = LIB_get_module_name(); if (!$access[noconfig]) { echo"", $text[header_config],"
\n"; } } echo"
", "\"$title\""; foreach $l (split(//, $title)) { $ll = ord($l); if ($ll > 127 && $lang->{'charset'}) { print "{'charset'}.gif alt=\"$l\" align=bottom>"; } elsif ($l eq " ") { print "\"\ \""; } else { print "\"$l\""; } } print "

$title

"; //echo $rightside; echo"
\n"; } } /*------------------------------------LIB_hlink($text,$page,$module)------------------------- Returns HTML for alink to help page. The first parameter is the test of the link and the second the name of the help page. --------------------------------------------------------------------------------------------*/ function LIB_hlink($text,$page,$module=undef){ $mod_name=LIB_get_module_name(); $mod=($module!=undef) ? $module : $mod_name; return "$text"; } /*------------------------------------LIB_get_system_hostname()--------------------------------- Returns the hostname of this system --------------------------------------------------------------------------------------------*/ function LIB_get_system_hostname(){ $hostname=`hostname`; //run a shell command return $hostname ; } /*------------------------------------LIB_get_webmin_version()--------------------------------- Returns the version of Webmin currently being run --------------------------------------------------------------------------------------------*/ function LIB_get_webmin_version(){ //$VERSION=fopen("../version","r") || VERSION=fopen("../version","r"); //flose($VERSION); return 0.91; } /*------------------------------------LIB_get_module_acl($user,$module)--------------------------------- Return an array containing acces control options for the given user --------------------------------------------------------------------------------------------*/ function LIB_get_module_acl($user=undef,$module=undef){ global $base_remote_user; global $remote_user; global $module_name; global $config_directory; global $gconfig; //associative array // $u=($user!=undef) ? $user : $base_remote_user; // $u=($user!=undef) ? $user : $remote_user; $u=($user!=undef) ? $user : "admin"; //admin par defaut //echo"user:$u
"; //echo"base_remote_user:$base_remote_user
"; $mod_name=LIB_get_module_name(); $m=($module!=undef) ? $module : $mod_name; //echo"module:$m:$module
"; $rv=LIB_read_file($module_name ? "../$m/"."defaultacl" : ".$m"."defaultacl"); if($gconfig["risk_$u"] && $m){ $rf=$gconfig["risk_u"].'.risk'; $rv=LIB_read_file($module_name ? "../$m/$rf" : "./$m/$rf"); $sf=$gconfig["skill_u"].'.skill'; $rv=LIB_read_file($module_name ? "../$m/$sf" : "./$m/$sf"); } else $rv=LIB_read_file("$config_directory/$m/$u.acl"); return $rv; } /*------------------------------------LIB_get_module_name()--------------------------------- Returns the name of the current module.This fonction is useful in php because if the script exemple.cgi is run module_name=/module_name/example.cgi. --------------------------------------------------------------------------------------------*/ function LIB_get_module_name(){ global $module_name; list($nul,$mod_name,$_nul)=split("/",$module_name); return $mod_name; } /*------------------------------------LIB_footer($page,$name)--------------------------------- Output a footer for returning to some page --------------------------------------------------------------------------------------------*/ function LIB_footer($page,$name){ //Global variables used in this function global $text; //$text is an associative array initialised in init_config global $module_info; //associative array global $module_name; $url=$page; if($url == "/"){ $url="/?cat=$module_info[category]"; } elseif($url == "" && $module_name){ $url=" ";//return to the last page } elseif( ereg("?",$url) || ereg($module_name,$url) ){ $url="/$module_name/$url"; } $link=LIB_text($text[main_return],$name); //$link=LIB_text($text[main_version],"32","33","34"); echo "\"<-\"\n"; echo "$link
\n"; } /*--------------------------------------LIB_read_file($file)---------------------------------- Fill an associative array with name=value pairs from a file --------------------------------------------------------------------------------------------*/ function LIB_read_file($file){ $delimiter="="; if(!$fp=fopen($file,"r")) return -1; while(!feof($fp)){ $current_line=fgetss($fp,255); $current_line=trim($current_line); //trim delete all space in the string, try chop() and ltrim() list($option,$value)=split($delimiter,$current_line); $assoc_array[$option]=$value; } fclose($fp); return $assoc_array; } /*-------------------------------------LIB_init_config()------------------------------------ set the following variables: $gconfig : Global configuration $config : module configuration $module_info $tconfig ------------------------------------------------------------------------------------------*/ function LIB_init_config(){ //Global variables used in this function global $config_directory; global $module_name; global $webmin_path; //Read the webmin global config file and fill the associative array $gconfig $GLOBALS["gconfig"]=LIB_read_file($config_directory."/config"); //Set PATH and LD_LIBRARY_PATH //if($gconfig[path]) putenv(PATH=$gconfig[path]); //if($gconfig[ld_env]) putenv($gconfig[ld_env]=gconfig[ld_path]); list($nul,$m,$_nul)=split("/",$module_name); $GLOBALS["config"]=LIB_read_file($config_directory."/".$m."/config"); $GLOBALS["module_info"]=LIB_read_file($webmin_path."/".$m."/module.info"); //Load language string into associative array named $text $GLOBALS["text"]=LIB_load_language(); $theme=LIB_check_key_array($GLOBALS["gconfig"],theme); if($theme){ $GLOBALS["tconfig"]=LIB_read_file($module_name ? "../$theme/config" :"$theme/config"); } // $key=LIB_array_to_keystring($GLOBALS["text"]); // $val=LIB_array_to_valstring($GLOBALS["text"]); // echo"
$key
$val
"; // echo"sans arg
"; // LIB_ReadParse(); // echo"avec gconfig
"; // LIB_ReadParse($GLOBALS["gconfig"]); //test_display_array($GLOBALS["gconfig"]); } /*----------------------LIB_check_key_array($assoc_array,$key)----------------------------- check if the key passed to the function exist,return the corresponding value else return 0 if(LIB_check_key_array($GLOBALS["gconfig"],theme)){ echo"existing key
"; } else echo"this key is not in this array
"; } ------------------------------------------------------------------------------------------*/ function LIB_check_key_array($assoc_array,$key){ //test_display_array($assoc_array); if($assoc_array[$key]) $rv=$assoc_array[$key]; else $rv=0; return $rv; } /*---------------------------LIB_ReadParse($assoc_array,$method)---------------------------- fills the given associative array with cgi paramaters, or uses the globals $in if none is given. ------------------------------------------------------------------------------------------*/ function LIB_ReadParse($assoc_array=undef,$method=undef){ if($assoc_array!=undef) $a=$assoc_array; else $a=$in; if($method!=undef) $meth=$methode; else $meth=getenv("REQUEST_METHOD"); test_display_array($a); echo"
meth:$meth
"; $z=getenv("CONTENT_LENGTH"); echo"CONTENT_LENGTH:$z
"; if($meth=='POST') read(STDIN, $in, getenv("CONTENT_LENGTH")); test_display_array($a); /* if(getenv("QUERY_STRING")){ if($in) }*/ } /*sub ReadParse { local $a = $_[0] ? $_[0] : \%in; local $i; local $meth = $_[1] ? $_[1] : $ENV{'REQUEST_METHOD'}; undef($in); if ($meth eq 'POST') { read(STDIN, $in, $ENV{'CONTENT_LENGTH'}); } if ($ENV{'QUERY_STRING'}) { if ($in) { $in .= "&".$ENV{'QUERY_STRING'}; } else { $in = $ENV{'QUERY_STRING'}; } } @in = split(/\&/, $in); foreach $i (@in) { local ($k, $v) = split(/=/, $i, 2); $k =~ s/\+/ /g; $k =~ s/%(..)/pack("c",hex($1))/ge; $v =~ s/\+/ /g; $v =~ s/%(..)/pack("c",hex($1))/ge; $a->{$k} = defined($a->{$k}) ? $a->{$k}."\0".$v : $v; } }*/ /*---------------------------LIB_redirect($url)---------------------------- Output headers to redirect the browser to some page ------------------------------------------------------------------------------------------*/ function LIB_redirect($url){ global $module_info; $server_port=getenv("SERVER_PORT"); $https=getenv("HTTPS"); $server_name=getenv("SERVER_NAME"); $script_name=getenv("SCRIPT_NAME "); if( ($server_port==443) && ($https=="ON")) $port=""; elseif( ($server_port==80) && ($https!="ON")) $port=""; else $port=$server_port; if($https=="ON") $prot="https"; else $prot="http"; if(ereg("http",$url) | ereg("https",$url) | ereg("ftp",$url) | ereg("gopher",$url)){ Header("Location: $url"); } elseif(ereg("/^\//",$url)){ Header("Location: $prot://$server_name:$port$url"); } elseif(ereg("/^(.*)\/[^\/]*$/",$sript_name)){ Header("Location: $prot://$server_name:$port$1/$url"); } elseif($url==""){//return to the current module category Header("Location: $prot://$server_name:$port/$url/?cat=$module_info[category]"); } else Header("Location: $prot://$server_name:$port/$url"); } /*---------------------------LIB_get_module_info($module)---------------------------- ------------------------------------------------------------------------------------------*/ function LIB_get_module_info($module){ } /*---------------------------LIB_load_language()---------------------------- Returns a hashtable mapping text codes to strings in the appropriate language ------------------------------------------------------------------------------------------*/ function LIB_load_language(){ //Global variables used in this module global $webmin_path; global $gconfig; global $module_name; //$a=$webmin_path.$module_name."lang/".$gconfig[lang]; //echo"$a
"; //fill the associative array $text with the correct language //firsty with general text codes: /path/to/webmin-0.91/lang/current_language $text=LIB_read_file($webmin_path."/lang/".$gconfig[lang]); //secondly with module text codes: /path/to/webmin-0.91/current_module/lang/current_language if($module_name){ $text_mod=LIB_read_file("lang/".$gconfig[lang]); //fill $text with the content of $text_mod while(list($key,$value)=each($text_mod)){ $text[$key]=$value; } } // test_display_array($text); return $text; } /*------------------------LIB_text($message,$substitute,$sub2,$sub3)-------------------------- Looks up the given message in the appropriate language translation file, replaces the text $1, $2 and so on with the rest of the parameters, and returns the result. I suppose there is only 3 substituted arguments passed to the function($1,$2,$3). If an other substituted argument is added, you should add one for this function. To check the number of substituted arguments open read this file: /path/to/webmin-0.91/lang/en ---------------------------------------------------------------------------------------------*/ function LIB_text($message,$substitute,$sub2=nul,$sub3=nul){ global $text; //$text is an associative array $rv=$message; $num_args=func_num_args(); //number of arguments passed to the function $args_list=func_get_args(); //$args_list is an associative array for($i=1;$i<$num_args;$i++){ $replace=func_get_arg($i); $rv=str_replace("\$$i",$replace,$rv); } return $rv; } /*-------------------------LIB_array_to_keystring($assoc_array)-------------------------------- Push all key of an array into a string Instead of passing an array from a script to an other one(it's not possible with php???), we could passed a string.So this function built a string with all key of this array ---------------------------------------------------------------------------------------------*/ function LIB_array_to_keystring($assoc_array){ $separator=" |#| "; while(list($key,$value)=each($assoc_array)){ if($key!="") $key_string=$key_string.$key.$separator; } return $key_string; } /*---------------------------LIB_array_to_valstring($assoc_array)-------------------------------- this function built a string with all value of an array ---------------------------------------------------------------------------------------------*/ function LIB_array_to_valstring($assoc_array){ $val_string=implode(" |#| ",$assoc_array); return $val_string; } /*---------------------------LIB_convert_str_to_array($keystr,$valstr)-------------------------------- This function built an associative array from 2 strings. I didn't used explose because keys become numbers. ---------------------------------------------------------------------------------------------*/ function LIB_convert_str_to_array($keystr,$valstr){ while(list($key,$value)=each($assoc_array)){ } } function test_display_array($a){ while(list($k,$v)=each($a)){ echo"$k:$v
"; } } ?>