View.php
[Pman.Ftp] / List.php
1 <?php
2
3 require_once 'Pman.php';
4 class Pman_Ftp_List extends Pman
5 {
6     function getAuth() {
7         
8         $au = $this->getAuthUser();
9         if (!$au) {
10              $this->jerr("Not authenticated", array('authFailure' => true));
11         }
12         $this->authUser = $au;
13         // check that it's a supplier!!!! 
14         
15         return true; 
16     }
17     var $root = '/home/ftp';
18     
19     function clean($f) {
20         
21         $root = $this->root;
22         
23         $base = isset($f) ? $f: '/' ;
24         $base = ltrim($base,'/');
25         $base = empty($base) ? '' : '/'. $base;
26         
27         $fp = $root . $base;
28         $rp  = realpath($fp);
29         // non hanlding of aliases.
30         //var_dump($fp); 
31         
32         if ($rp != $fp) {
33             $this->jerr("invalid path");
34         }
35         return $fp;
36         
37     }
38     
39     function get($base = '',  $opts = array())
40     {
41         $root = $this->root;
42         
43         $type = !empty($_REQUEST['type']) && $_REQUEST['type'] == 'files' ? 'files' : 'dir';
44         
45         $fp = $this->clean(isset($_REQUEST['name']) ? $_REQUEST['name'] : '');
46         
47         $dh = opendir($fp);
48         $ret= array();
49         
50          require_once 'File/MimeType.php';
51         $fm = new File_MimeType();
52       
53         
54         while(false !== ($f = readdir($dh))) {
55             if (!strlen($f) || $f[0] =='.') {
56                 continue;
57             }
58             $ff = $fp.'/'.$f;
59             
60             //var_dump($ff);
61             $idr = is_dir($ff);
62             if ($type == 'dir' && !$idr) {
63                 continue;
64             }
65             if ($type == 'files' && $idr) {
66                 continue;
67             }
68             $s = (object) stat($ff);
69             $s->id = substr($ff, strlen($root));
70             $s->name = $f;
71             $s->leaf= false;
72             $s->mtime= date('Y-m-d H:i:s', $s->mtime);
73             $s->mimetype = $fm->fromFilename($f);
74             $ret[$ff] = $s;
75         }
76         closedir($dh);
77         ksort($ret);
78         
79         $this->jdata(array_values($ret));
80         
81         
82     }
83 }