--- /dev/null
+<?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