仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ user/amftp/Controller/index.php 25.1 KB · 834 行 原始文件
Z zfhsh first commit 2 天前
1<?php
2/************************************************
3 * Amysql FTP - AMFTP 3.0
4 * amh.sh
5 * Update:2021-01-15
6 *
7 */
8
9class index extends AmysqlController
10{
11 public $amftp = null;
12 public $functions = null;
13
14 public $cache = false; // 是否缓存列表
15 public $default_order = 'asc'; // 默认排序类型
16 public $default_orderby = 'mtime'; // 默认排序字段
17
18 public $txt_code = array('php', 'js', 'jsp', 'asp', 'java', 'html', 'xml', 'xhtml', 'htm', 'txt', 'css', 'json', 'conf', 'c', 'cc', 'sh', 'h', 'm4', 'in', 'ac', 'guess', 'sub', 'sln', 'am', 'dot', 'sql', 'htaccess', 'ini', 'log', 'md', 'yml', 'py', 'python');
19 public $img_code = array('png', 'jpg', 'jpeg', 'gif', 'bmp');
20
21
22 // 基础引用
23 function amftp_base()
24 {
25 if (!$this -> amftp)
26 {
27 $this -> functions = $this -> _class('functions');
28 $this -> amftp = $this -> _class('amftp');
29 }
30 }
31
32 // 自动连接
33 function amftp_auto_connect()
34 {
35 if ($this -> amftp && !$this -> amftp -> amftp_ftp_connect && isset($_SESSION['ftp']['user']))
36 {
37 $_SESSION['ftp']['pasv'] = isset($_SESSION['ftp']['pasv']) ? $_SESSION['ftp']['pasv'] : false;
38 $this -> amftp -> am_ftp_connect($_SESSION['ftp']['ip'], $_SESSION['ftp']['port']);
39 $login_status = $this -> amftp -> am_ftp_login($_SESSION['ftp']['user'], $_SESSION['ftp']['pass'], $_SESSION['ftp']['pasv']);
40 if (!$login_status)
41 {
42 $this -> logout();
43 exit();
44 }
45 }
46 }
47
48 // 登录判断
49 function amftp_check_login()
50 {
51 // 切换用户退出
52 if(isset($_GET['ftp_user']) && isset($_SESSION['ftp']) && $_SESSION['ftp']['user'] != $_GET['ftp_user'])
53 unset($_SESSION['ftp']);
54
55 if (!isset($_SESSION['ftp']['user']))
56 {
57 $this -> amftp_login();
58 exit();
59 }
60 }
61
62
63
64 // 登录页面 *************************************************************************
65 function amftp_login()
66 {
67 $this -> amftp_base();
68
69 global $Config;
70 $notice = '';
71 if (isset($_POST['sbpostdl']))
72 {
73 $ftp_ip = $Config['OnlyLocal'] ? '127.0.0.1' : $_POST['ftp_ip'];
74 $ftp_port = $_POST['ftp_port'];
75 $ftp_user = $_POST['ftp_user'];
76 $ftp_pass = stripslashes($_POST['ftp_pass']);
77 $ftp_pasv = $_POST['ftp_pasv'];
78
79 if ($this -> amftp -> am_ftp_connect($ftp_ip, $ftp_port))
80 {
81 // 登录成功
82 if ($this -> amftp -> am_ftp_login($ftp_user, $ftp_pass, $ftp_pasv))
83 {
84 $_SESSION['ftp']['ip'] = $ftp_ip;
85 $_SESSION['ftp']['port'] = $ftp_port;
86 $_SESSION['ftp']['user'] = $ftp_user;
87 $_SESSION['ftp']['pass'] = $ftp_pass;
88 $_SESSION['ftp']['pasv'] = $ftp_pasv;
89 header('location:./index.php');
90 exit();
91 }
92 else
93 {
94 $notice = $ftp_ip . ' #用户 ' . $ftp_user . ' 登录失败。';
95 }
96 }
97 else
98 {
99 $notice = $ftp_ip . ' 无法响应。';
100 }
101 }
102 if($Config['OnlyLocal'])
103 $ftp_ip = '127.0.0.1';
104 else
105 {
106 $ftp_ip = functions::Gval('ftp_ip');
107 $ftp_ip = empty($ftp_ip) ? $_SERVER['SERVER_ADDR'] : $ftp_ip;
108 }
109 $this -> title = 'AMFTP 登录';
110 $this -> ftp_ip = $ftp_ip;
111 $this -> ftp_user = functions::Gval('ftp_user');
112 $this -> notice = $notice;
113 $this -> _view('amftp_login');
114 }
115
116
117 // 首页 *************************************************************************
118 function IndexAction()
119 {
120 $this -> amftp_check_login();
121 $this -> amftp_base();
122 $this -> amftp_auto_connect();
123
124
125 // 排序类型 & 排序字段
126 $_GET['order'] = $_SESSION['ftp']['order'] = isset($_GET['order']) ? $_GET['order'] : (isset($_SESSION['ftp']['order']) ? $_SESSION['ftp']['order'] : $this -> default_order);
127 $_GET['orderby'] = $_SESSION['ftp']['orderby'] = isset($_GET['orderby']) ? $_GET['orderby'] : (isset($_SESSION['ftp']['orderby']) ? $_SESSION['ftp']['orderby'] : $this -> default_orderby);
128 $pwd = isset($_GET['pwd']) ? trim($_GET['pwd'], '/') : '';
129 $pwd = !empty($pwd) ? '/'. $pwd . '/' : '/';
130 $_SESSION['ftp_pwd'] = $pwd;
131
132
133 // 显示目录 ********************************************
134 if (isset($_GET['show_dir']))
135 {
136 $show_dir = $_GET['show_dir'];
137 $file_list = $this -> amftp -> am_ftp_rawlist(str_replace(' ', '\ ', $show_dir));
138 foreach ($file_list as $key=>$val)
139 {
140 $row = $this -> functions -> Grawlistline($val);
141 if(!in_array($row['dirfilename'], array('.', '..')) && $row['dirorfile'] == 'd')
142 {
143 $row['charset'] = 'utf8';
144 if (!functions::is_utf8($row['dirfilename'])) // gbk
145 $row['dirfilename'] = iconv('GBK', 'UTF-8//IGNORE', $row['dirfilename']);
146 $dir_arr[] = $row['dirfilename'];
147 }
148 }
149
150 $back = dirname(rtrim($show_dir, '/'));
151 if(empty($back))
152 $back = '/';
153 exit(json_encode(array('back' => $back, 'dir' => $dir_arr)));
154 }
155 // 重命名 *****************************************
156 if (isset($_POST['old_name']))
157 {
158 $new_name = dirname($_POST['old_name']) . '/' . $_POST['new_name'];
159 if($this -> amftp -> am_ftp_rename(functions::UTF8TOGBK($_POST['old_name'], $_POST['charset']), $new_name))
160 echo $new_name;
161 exit();
162 }
163 // 文件上传 *****************************************
164 if (isset($_GET['amftp_pwd']))
165 {
166 // 上传临时目录
167 $tmp_upload = _ROOT . '/View/tmp_upload/' . md5($_GET['amftp_pwd'] . $_POST['name'] . $_POST['size']) . '/';
168 if(!functions::mkdirs($tmp_upload))
169 {
170 $tmp_upload = '/tmp/tmp_upload/' . md5($_GET['amftp_pwd'] . $_POST['name'] . $_POST['size']) . '/';
171 functions::mkdirs($tmp_upload);
172 }
173 if(isset($_GET['file_put']))
174 {
175 set_time_limit(0);
176 $chunk = isset($_POST['chunk']) ? (int)$_POST['chunk'] : 0;
177 if(move_uploaded_file($_FILES['file']['tmp_name'], $tmp_upload . $chunk))
178 {
179 if(!isset($_POST['chunk']) || (isset($_POST['chunk']) && $_POST['chunk'] == $_POST['chunks']-1)) // 全部块完成
180 {
181 $dir_file = scandir($tmp_upload);
182 $file_all = $tmp_upload . 'all';
183 sort($dir_file);
184 foreach ($dir_file as $key => $val)
185 {
186 if(!in_array($val, array('.', '..')))
187 {
188 $file_all_content = is_file($file_all) ? file_get_contents($file_all) : '';
189 file_put_contents($file_all, $file_all_content . file_get_contents($tmp_upload . $val));
190 unlink($tmp_upload . $val);
191 }
192 }
193 if(filesize($file_all) == $_POST['size'])
194 {
195 $this -> amftp -> am_ftp_chdir($_GET['amftp_pwd']);
196 if($this -> amftp -> am_ftp_put($_POST['name'], $file_all))
197 {
198 functions::rmdirs($tmp_upload);
199 exit(json_encode(array('status' => '1')));
200 }
201 }
202 exit(json_encode(array('status' => '0')));
203 }
204 echo json_encode(array('status' => '1'));
205 }
206 else
207 {
208 exit(json_encode(array('status' => '0')));
209 }
210 }
211 elseif(isset($_GET['file_check']))
212 {
213 $chunk = isset($_POST['chunk']) ? (int)$_POST['chunk'] : 0;
214 $bsize = $_POST['bsize'];
215 if(is_file($tmp_upload . $chunk) && filesize($tmp_upload . $chunk) == $bsize)
216 echo json_encode(array('status' => '1'));
217 else
218 exit(json_encode(array('status' => '0')));
219 }
220 exit();
221 }
222
223 // ****************************************************************************
224
225 $tmp_id = str_shuffle(rand(100000,999999).'abcdefg');
226 // 解压临时文件夹
227 $tmp_tar = _ROOT . '/View/tmp_tar/' . $tmp_id . '/';
228 if(!functions::mkdirs($tmp_tar))
229 {
230 $tmp_tar = '/tmp/tmp_tar/' . $tmp_id . '/';
231 functions::mkdirs($tmp_tar);
232 }
233
234 // 下载临时目录
235 $tmp_download = _ROOT . '/View/tmp_download/' . $tmp_id . '/';
236 if(!functions::mkdirs($tmp_download))
237 {
238 $tmp_download = '/tmp/tmp_download/' . $tmp_id . '/';
239 functions::mkdirs($tmp_download);
240 }
241
242
243 // 关闭session
244 if (!$this -> cache)
245 session_write_close();
246
247 // 新建 ****************************************************************************
248 if (isset($_POST['new']))
249 {
250 $new_type = (isset($_POST['new_type']) && $_POST['new_type'] == 'file') ? 'file' : 'dir';
251 $new_name = basename($_POST['new_name']);
252 if ($new_type == 'dir')
253 {
254 if($this -> amftp -> am_ftp_mkdir($pwd . $new_name))
255 {
256 $notice = '新建目录成功: ' . $new_name;
257 $notice_status = 'success';
258 }
259 else
260 {
261 $notice = '新建目录失败: ' . $new_name;
262 $notice_status = 'notice';
263 }
264 }
265 else
266 {
267 $new_file = $tmp_download . $new_name;
268 file_put_contents($new_file, '');
269 if (is_file($new_file))
270 {
271 if($this -> amftp -> am_ftp_put($pwd . $new_name, $new_file))
272 {
273 $notice = "新建文件成功: {$new_name}";
274 $notice_status = 'success';
275 }
276 else
277 {
278 $notice = "新建文件失败: {$new_name}";
279 $notice_status = 'notice';
280 }
281 }
282 }
283 }
284
285
286 // 设置权限 ****************************************************************************
287 if (isset($_POST['permissions']))
288 {
289 $p_sum = 0;
290 $permissions_val = $_POST['permissions_val'];
291 $recursion = (isset($_POST['recursion']) && $_POST['recursion'] == 'on') ? true : false;
292 if (is_array($_POST['select_item']['d']))
293 {
294 foreach ($_POST['select_item']['d'] as $key=>$val)
295 {
296 if($this -> amftp -> am_ftp_chmods($permissions_val, functions::UTF8TOGBK($val, $_POST['charset_item']['d'][$key]), $recursion))
297 ++$p_sum;
298 }
299 }
300
301 if (is_array($_POST['select_item']['-']))
302 {
303 foreach ($_POST['select_item']['-'] as $key=>$val)
304 {
305 if($this -> amftp -> am_ftp_chmod($permissions_val, functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key])))
306 ++$p_sum;
307 }
308 }
309
310 $notice = ($p_sum) ? '文件权限设置成功(' . $p_sum . '记录)' : '文件权限设置失败';
311 $notice_status = ($p_sum) ? 'success' : 'notice';
312 }
313
314 // 远程上传 ****************************************************************************
315 if (isset($_POST['remote_down']))
316 {
317 $remote_file = trim($_POST['remote_file'], '/');
318 $remote_arr = explode('://', $remote_file);
319 if(in_array($remote_arr[0], array('http','https')))
320 {
321 $new_name = basename($remote_file);
322 $new_file = $tmp_download . $new_name;
323 $rf = @fopen($remote_file, 'rb');
324 if ($rf)
325 {
326 $nf = @fopen($new_file, 'wb');
327 if ($nf)
328 {
329 while (!feof($rf))
330 fwrite($nf, fread($rf, 1024*8), 1024*8);
331 }
332 }
333 }
334 if (is_file($new_file))
335 {
336 if($this -> amftp -> am_ftp_put($pwd . $new_name, $new_file))
337 {
338 $notice = "远程上传保存成功: {$new_name}";
339 $notice_status = 'success';
340 }
341 else
342 {
343 $notice = "远程上传保存失败: {$new_name}";
344 $notice_status = 'notice';
345 }
346 }
347 else
348 {
349 $notice = '请确认远程文件是否可以访问。';
350 $notice_status = 'notice';
351 }
352 }
353
354
355 // 下载 ****************************************************************************
356 if (isset($_POST['download']))
357 {
358 $download = $this -> _class('download');
359 if (is_array($_POST['select_item']['-']))
360 {
361 foreach ($_POST['select_item']['-'] as $key=>$val)
362 {
363 $filename = $this -> amftp -> am_ftp_get($tmp_download, functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]));
364 $download -> download_file($filename, $val);
365 functions::rmdirs('./View/tmp_tar/' . $tmp_id . '/');
366 functions::rmdirs('/tmp/tmp_tar/' . $tmp_id . '/');
367 functions::rmdirs('./View/tmp_download/' . $tmp_id . '/');
368 functions::rmdirs('/tmp/tmp_download/' . $tmp_id . '/');
369 exit();
370 }
371 }
372 $notice = '无可下载项。请选择文件。';
373 $notice_status = 'notice';
374 }
375
376
377 // 删除 ****************************************************************************
378 if (isset($_POST['delete']))
379 {
380 if (is_array($_POST['select_item']['d']))
381 {
382 foreach ($_POST['select_item']['d'] as $key=>$val)
383 $status = $this -> amftp -> am_ftp_rmdir(functions::UTF8TOGBK($val, $_POST['charset_item']['d'][$key]));
384 }
385
386 if (is_array($_POST['select_item']['-']))
387 {
388 foreach ($_POST['select_item']['-'] as $key=>$val)
389 $status = $this -> amftp -> am_ftp_delete(functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]));
390 }
391
392 $notice = $status ? '文件删除成功' : '文件删除失败';
393 $notice_status = $status ? 'success' : 'notice';
394 }
395
396 // 解压与压缩 ***********************************************************************
397 if (isset($_POST['unzip']) || isset($_POST['zip']))
398 {
399 include(_Class . '/pclerror.lib.php');
400 include(_Class . '/pcltrace.lib.php');
401 include(_Class . '/pcltar.lib.php');
402 include(_Class . '/pclzip.lib.php');
403 include(_Class . '/archive.lib.php');
404
405
406 // 解压 *****************************************
407 if (isset($_POST['unzip']) && isset($_POST['select_item']['-']))
408 {
409 if (is_dir($tmp_tar))
410 {
411 foreach ($_POST['select_item']['-'] as $key=>$val)
412 {
413 $filename = $this -> amftp -> am_ftp_get($tmp_download, functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]));
414 if ($filename)
415 {
416 $file = fopen($filename, "rb");
417 $bin = fread($file, 2);
418 fclose($file);
419 $strInfo = @unpack("C2chars", $bin);
420 $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
421
422 // 解压 (8075-zip, 8297-rar, 31139-gz)
423 if ($typeCode == '8075') // zip
424 {
425 $zip = new PclZip($filename);
426 $zip -> extract(PCLZIP_OPT_PATH, $tmp_tar);
427 }
428 else
429 {
430 PclTarExtract($filename, $tmp_tar);
431 }
432
433 if (count(array_diff(scandir($tmp_tar), array('.', '..'))) > 0)
434 {
435 if($this -> amftp -> am_ftp_puts($pwd, $tmp_tar))
436 $notice_arr[] = $val;
437 }
438
439 }
440 }
441 }
442
443 $notice = is_array($notice_arr) ? '文件解压成功: ' . implode(',', $notice_arr) : '文件解压失败。';
444 $notice_status = is_array($notice_arr) ? 'success' : 'notice';
445 }
446
447
448 // 压缩 *****************************************
449 if (isset($_POST['zip']))
450 {
451 // 下载临时文件夹
452 $tag = date('Ymd-His', time()); // 最终目标标识
453 $tmp_tar = _ROOT . 'View/tmp_tar/' . $tmp_id . '/';
454 if(!functions::mkdirs($tmp_tar) || !functions::mkdirs($tmp_tar . $tag . '/'))
455 {
456 $tmp_tar = '/tmp/tmp_tar/' . $tmp_id . '/';
457 functions::mkdirs($tmp_tar);
458 functions::mkdirs($tmp_tar . $tag . '/');
459 }
460
461
462 if (is_dir($tmp_tar))
463 {
464 // 下载文件
465 if (isset($_POST['select_item']['d']))
466 {
467 foreach ($_POST['select_item']['d'] as $key=>$val)
468 $filename = $this -> amftp -> am_ftp_gets($tmp_tar, functions::UTF8TOGBK($val, $_POST['charset_item']['d'][$key]));
469 }
470
471 if (isset($_POST['select_item']['-']))
472 {
473 foreach ($_POST['select_item']['-'] as $key=>$val)
474 $filename = $this -> amftp -> am_ftp_get($tmp_tar . $pwd, functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]));
475 }
476
477 // 最终目标移动
478 $source = $tmp_tar . $pwd;
479 $target = $tmp_tar . $tag . '/';
480 $d = dir($source);
481 while(($entry=$d->read()) !== false)
482 {
483 if(is_dir($source.$entry))
484 {
485 if($entry != "." && $entry != ".." && $entry != $tag)
486 functions::moves("$source$entry/", "$target");
487 }
488 else
489 {
490 if(!rename("$source$entry","$target$entry"))
491 return false;
492 }
493 }
494
495
496 // 开始压缩
497 $target_name = $tmp_tar . $tag . '.' . $_POST['zip_type'];
498 if ($_POST['zip_type'] == 'zip')
499 {
500 $archive = new PclZip($target_name);
501 $archive->create($target, PCLZIP_OPT_REMOVE_PATH, $tmp_tar . $tag);
502 }
503 else
504 {
505 $gzip = new gzip_file($target_name);
506 $options = array('basedir' => $tmp_tar . $tag, 'overwrite' => 1, 'level' => 1);
507 $options['type'] = ($_POST['zip_type'] == 'tar') ? 'tar' : 'gzip';
508 $gzip->set_options($options);
509 $gzip->add_files(array('./*'));
510 $gzip->create_archive();
511 // PclTarCreate($target_name, $target, $_POST['zip_type'], '', $tmp_tar . $tag);
512 }
513
514 if (is_file($target_name))
515 {
516 if($this -> amftp -> am_ftp_put($pwd . $tag . '.' . $_POST['zip_type'], $target_name))
517 {
518 $notice = "文件压缩成功: {$tag}.{$_POST['zip_type']}";
519 $notice_status = 'success';
520 }
521 else
522 {
523 $notice = '文件压缩失败。';
524 $notice_status = 'notice';
525 }
526 }
527 }
528 }
529
530 }
531
532 // 文件移动 *****************************************
533 if (isset($_POST['move']))
534 {
535 $_pwd = $pwd;
536 // 移到到
537 $pwd = isset($_POST['move_pwd']) ? trim($_POST['move_pwd'], '/') : '';
538 $pwd = !empty($pwd) ? '/'. $pwd . '/' : '/';
539
540 $move_sum = 0;
541 if (isset($_POST['select_item']['d']))
542 {
543 foreach ($_POST['select_item']['d'] as $key=>$val)
544 {
545 $_val = functions::UTF8TOGBK($val, $_POST['charset_item']['d'][$key]);
546 $target = $pwd . basename($_val);
547 if (strpos($target. '/', $_val . '/') !== 0) // 禁止原地移动&移动至子级目录
548 {
549 if ($this -> amftp -> am_ftp_move($_val, $target))
550 ++$move_sum;
551 }
552 }
553 }
554 if (isset($_POST['select_item']['-']))
555 {
556 foreach ($_POST['select_item']['-'] as $key=>$val)
557 {
558 $_val = functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]);
559 if ($_val != $pwd . basename($_val))
560 {
561 if ($this -> amftp -> am_ftp_move($_val, $pwd . basename($_val)))
562 ++$move_sum;
563 }
564 }
565 }
566
567 $notice = ($move_sum) ? '文件移动成功。(' . $move_sum . '记录)' : '文件移动失败。';
568 $notice_status = ($move_sum) ? 'success' : 'notice';
569 $pwd = $_pwd;
570 }
571
572 // 文件复制 *****************************************
573 if (isset($_POST['copy']))
574 {
575 $_pwd = $pwd;
576 // 复制到
577 $pwd = isset($_POST['copy_pwd']) ? trim($_POST['copy_pwd'], '/') : '';
578 $pwd = !empty($pwd) ? '/'. $pwd . '/' : '/';
579
580 if($pwd != $_pwd)
581 {
582 if (is_dir($tmp_download))
583 {
584 $copy_sum = 0;
585 if (isset($_POST['select_item']['d']))
586 {
587 foreach ($_POST['select_item']['d'] as $key=>$val)
588 $filename = $this -> amftp -> am_ftp_gets($tmp_download, functions::UTF8TOGBK($val, $_POST['charset_item']['d'][$key]));
589 }
590
591 if (isset($_POST['select_item']['-']))
592 {
593 foreach ($_POST['select_item']['-'] as $key=>$val)
594 $filename = $this -> amftp -> am_ftp_get($tmp_download . $_pwd, functions::UTF8TOGBK($val, $_POST['charset_item']['-'][$key]));
595 }
596 if (count(array_diff(scandir($tmp_download . $_pwd), array('.', '..'))) > 0)
597 {
598 if($this -> amftp -> am_ftp_puts($pwd, $tmp_download . $_pwd))
599 ++$copy_sum;
600 }
601
602 $notice = ($copy_sum) ? '文件复制成功。' : '文件复制失败。';
603 $notice_status = ($copy_sum) ? 'success' : 'notice';
604 }
605 }
606 else
607 {
608 $notice = '不可复制到当前的目录。';
609 $notice_status = 'notice';
610 }
611 $pwd = $_pwd;
612 }
613
614
615 // 取得当前文件列表 *******************************************************************
616 if (isset($_SESSION['rawlist'][$pwd]) && !isset($_GET['reload']) && $this -> cache)
617 {
618 $am_ftp_rawlist_value = $_SESSION['rawlist'][$pwd];
619 }
620 else
621 {
622 $am_ftp_rawlist = $this -> amftp -> am_ftp_rawlist(str_replace(' ', '\ ', $pwd));
623
624 $am_ftp_rawlist_array = array();
625 foreach ($am_ftp_rawlist as $key=>$val)
626 {
627 $row = $this -> functions -> Grawlistline($val);
628 if(!in_array($row['dirfilename'], array('.', '..')))
629 {
630 $row['charset'] = 'utf8';
631 if (!functions::is_utf8($row['dirfilename'])) // gbk
632 {
633 $row['dirfilename'] = iconv('GBK', 'UTF-8//IGNORE', $row['dirfilename']);
634 $row['charset'] = 'gbk';
635 }
636 $row['file_type'] = (strpos($row['dirfilename'], '.') !== false ) ? end(explode('.', $row['dirfilename'])) : '?';
637 $row['can_open'] = ($row['dirorfile'] == 'd' || $row['file_type'] == '?' || in_array($row['file_type'], $this -> txt_code) || in_array($row['file_type'], $this -> img_code)) ? 'y' : 'n';
638 $row['ico'] = functions::Gicon($row['dirfilename'], $row['dirorfile']);
639 $row['size_text'] = functions::CountSize($row['size']);
640 $row['permissions_number'] = functions::GPNumber($row['permissions']);
641 $row['mtime'] = date('Y-m-d H:i:s', strtotime($row['mtime']));
642 $am_ftp_rawlist_array[] = $row;
643 }
644 }
645
646 // 列表排序
647 usort($am_ftp_rawlist_array, array('functions', 'orderby'));
648
649 // 目录位前面
650 foreach ($am_ftp_rawlist_array as $key=>$val)
651 $am_ftp_rawlist_array[$val['dirorfile']][] = $val;
652 foreach ($am_ftp_rawlist_array['-'] as $key=>$val)
653 $am_ftp_rawlist_array['d'][] = $val;
654
655 $am_ftp_rawlist_value = $am_ftp_rawlist_array['d'];
656 unset($am_ftp_rawlist_array);
657
658 if($this -> cache) $_SESSION['rawlist'][$pwd] = $am_ftp_rawlist_value;
659 }
660
661
662 // 删除临时目录(避免占用空间)
663 functions::rmdirs('./View/tmp_tar/' . $tmp_id . '/');
664 functions::rmdirs('/tmp/tmp_tar/' . $tmp_id . '/');
665 functions::rmdirs('./View/tmp_download/' . $tmp_id . '/');
666 functions::rmdirs('/tmp/tmp_download/' . $tmp_id . '/');
667
668
669 $this -> title = 'AMFTP:' . $pwd;
670 $this -> am_ftp_rawlist = $am_ftp_rawlist_value;
671 $this -> amftp_am_ftp_pwd = $pwd;
672 $this -> order = $order;
673 $this -> notice = $notice;
674 $this -> notice_status = $notice_status;
675 $this -> memory_limit = ini_get('memory_limit');
676 $this -> _view('amftp_index');
677 }
678
679
680 // 编辑文件
681 function file_edit()
682 {
683 $this -> amftp_check_login();
684 $this -> amftp_base();
685 $this -> amftp_auto_connect();
686
687 $pwd = $_GET['pwd'];
688 $file = $_GET['file'] = basename($_GET['file']);
689 $charset = $_GET['charset'];
690 if(strpos($file, '..') !== false || strpos($file, '/') !== false )
691 {
692 unset($_POST);
693 unset($_GET);
694 $this -> IndexAction();
695 exit();
696 }
697
698 $tmp_id = str_shuffle(rand(100000,999999).'abcdefg');
699 // 下载临时目录
700 $tmp_download = _ROOT . '/View/tmp_file/' . $tmp_id . '/';
701 if(!functions::mkdirs($tmp_download))
702 {
703 $tmp_download = '/tmp/tmp_file/' . $tmp_id . '/';
704 functions::mkdirs($tmp_download);
705 }
706
707 $file_type = (strpos($file, '.') !== false ) ? end(explode('.', $file)) : 'txt';
708 if (in_array($file_type, $this -> txt_code))
709 $file_type = 'txt';
710 elseif (in_array($file_type, $this -> img_code))
711 $file_type = 'img';
712
713
714 // 保存 ************************************
715 if (isset($_POST['file_content']))
716 {
717 $filename = $tmp_download . $file;
718 $file_content_save = $file_content = stripslashes($_POST['file_content']);
719 $character = $_POST['character'];
720 if(!empty($character))
721 {
722 if ($character != 'UTF-8')
723 {
724 $file_content_save = mb_convert_encoding($file_content, $character, 'UTF-8');
725 $file_content = mb_convert_encoding($file_content_save, 'UTF-8', $character);
726 }
727 file_put_contents($filename, $file_content_save);
728 }
729
730 if (is_file($filename))
731 {
732 if($this -> amftp -> am_ftp_put($pwd . $file, $filename))
733 echo 'success';
734 }
735 functions::rmdirs('./View/tmp_file/' . $tmp_id . '/');
736 functions::rmdirs('/tmp/tmp_file/' . $tmp_id . '/');
737 exit();
738 }
739 else
740 {
741 $filename = $this -> amftp -> am_ftp_get($tmp_download, $pwd . functions::UTF8TOGBK($file, $charset));
742 if ($filename)
743 {
744 $file_content = file_get_contents($filename);
745 if (isset($_GET['img']))
746 {
747 header('Content-type: image/jpeg');
748 echo $file_content;
749 functions::rmdirs('./View/tmp_file/' . $tmp_id . '/');
750 functions::rmdirs('/tmp/tmp_file/' . $tmp_id . '/');
751 exit();
752 }
753
754 $character = mb_detect_encoding($file_content, array('UTF-8',"EUC-CN",'BIG-5',"CP936"), true);
755 if (!empty($character) && $character != 'UTF-8')
756 $file_content = mb_convert_encoding($file_content, 'UTF-8', $character);
757 }
758 else
759 {
760 $file_type = '';
761 $notice = '文件读取失败';
762 $notice_status = 'notice';
763 }
764 }
765
766 functions::rmdirs('./View/tmp_file/' . $tmp_id . '/');
767 functions::rmdirs('/tmp/tmp_file/' . $tmp_id . '/');
768
769 $this -> title = '文件:' . $file;
770 $this -> amftp_am_ftp_pwd = $pwd;
771 $this -> file_content = $file_content;
772 $this -> file_type = $file_type;
773 $this -> file_ctype = functions::Gctype($file);
774 $this -> filename = $filename;
775 $this -> notice = $notice;
776 $this -> notice_status = $notice_status;
777 $this -> character = $character;
778 $this -> memory_limit = ini_get('memory_limit');
779 $this -> _view('amftp_file_edit');
780 }
781
782
783 // 删除临时目录 *************************************************************************
784 function rmtmp()
785 {
786 $this -> amftp_check_login();
787 $this -> amftp_base();
788 functions::rmdirs('./View/tmp_tar/');
789 functions::rmdirs('/tmp/tmp_tar/');
790 functions::rmdirs('./View/tmp_download/');
791 functions::rmdirs('/tmp/tmp_download/');
792 functions::rmdirs('./View/tmp_file/');
793 functions::rmdirs('/tmp/tmp_file/');
794 functions::rmdirs('./View/tmp_upload/');
795 functions::rmdirs('/tmp/tmp_upload/');
796 if ( (!is_dir('./View/tmp_tar/') && !is_dir('/tmp/tmp_tar/') ) &&
797 ( !is_dir('./View/tmp_download/') && !is_dir('/tmp/tmp_download/') ) &&
798 ( !is_dir('./View/tmp_upload/') && !is_dir('/tmp/tmp_upload/') ) &&
799 ( !is_dir('./View/tmp_file/') && !is_dir('/tmp/tmp_file/') ) )
800 {
801 $notice = '清除缓存成功';
802 $notice_status = 'success';
803 }
804 else
805 {
806 $notice = '清除缓存失败';
807 $notice_status = 'notice';
808 }
809
810 if (isset($_SERVER['HTTP_REFERER']))
811 {
812 $_SESSION['ftp']['back'] = $_SERVER['HTTP_REFERER'];
813 }
814 $this -> notice = $notice;
815 $this -> notice_status = $notice_status;
816 $this -> back = $_SESSION['ftp']['back'];
817 $this -> _view('amftp_rmtmp');
818 }
819
820 // 帮助 *************************************************************************
821 function help()
822 {
823 $this -> _view('amftp_help');
824 }
825
826
827 // 退出
828 function logout()
829 {
830 unset($_SESSION['ftp']);
831 $this -> IndexAction();
832 }
833
834}