List.php
authorAlan Knowles <alan@akbkhome.com>
Mon, 12 Apr 2010 09:46:50 +0000 (17:46 +0800)
committerAlan Knowles <alan@akbkhome.com>
Mon, 12 Apr 2010 09:46:50 +0000 (17:46 +0800)
List.php [new file with mode: 0644]

diff --git a/List.php b/List.php
new file mode 100644 (file)
index 0000000..c2fe75f
--- /dev/null
+++ b/List.php
@@ -0,0 +1,77 @@
+<?php
+
+require_once 'Pman.php';
+class Pman_Ftp_List extends Pman
+{
+    function getAuth() {
+        
+        $au = $this->getAuthUser();
+        if (!$au) {
+             $this->jerr("Not authenticated", array('authFailure' => true));
+        }
+        $this->authUser = $au;
+        // check that it's a supplier!!!! 
+        
+        return true; 
+    }
+    var $root = '/home/ftp';
+    
+    function clean($f) {
+        
+        $root = $this->root;
+        
+        $base = isset($f) ? $f: '/' ;
+        $base = ltrim($base,'/');
+        $base = empty($base) ? '' : '/'. $base;
+        
+        $fp = $root . $base;
+        $rp  = realpath($fp);
+        // non hanlding of aliases.
+        //var_dump($fp); 
+        
+        if ($rp != $fp) {
+            $this->jerr("invalid path");
+        }
+        return $fp;
+        
+    }
+    
+    function get()
+    {
+        $root = $this->root;
+        
+        $type = !empty($_REQUEST['type']) && $_REQUEST['type'] == 'files' ? 'files' : 'dir';
+        
+        $fp = $this->clean(isset($_REQUEST['name']) ? $_REQUEST['name'] : '');
+        
+        $dh = opendir($fp);
+        $ret= array();
+        while(false !== ($f = readdir($dh))) {
+            if (!strlen($f) || $f[0] =='.') {
+                continue;
+            }
+            $ff = $fp.'/'.$f;
+            
+            //var_dump($ff);
+            $idr = is_dir($ff);
+            if ($type == 'dir' && !$idr) {
+                continue;
+            }
+            if ($type == 'files' && $idr) {
+                continue;
+            }
+            $s = (object) stat($ff);
+            $s->id = substr($ff, strlen($root));
+            $s->name = $f;
+            $s->leaf= false;
+            $s->mtime= date('Y-m-d H:i:s', $s->mtime);
+            $ret[$ff] = $s;
+        }
+        closedir($dh);
+        ksort($ret);
+        
+        $this->jdata(array_values($ret));
+        
+        
+    }
+}
\ No newline at end of file