remove a lot of extraneous debugging now that most of this stuff basically works

This commit is contained in:
friendica 2014-01-09 13:54:18 -08:00
parent c6b9e44353
commit ca570f97e0

View File

@ -15,16 +15,16 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
private $os_path = ''; private $os_path = '';
function __construct($ext_path,&$auth_plugin) { function __construct($ext_path,&$auth_plugin) {
logger('RedDirectory::__construct() ' . $ext_path); logger('RedDirectory::__construct() ' . $ext_path, LOGGER_DEBUG);
$this->ext_path = $ext_path; $this->ext_path = $ext_path;
$this->red_path = ((strpos($ext_path,'/cloud') === 0) ? substr($ext_path,6) : $ext_path); $this->red_path = ((strpos($ext_path,'/cloud') === 0) ? substr($ext_path,6) : $ext_path);
if(! $this->red_path) if(! $this->red_path)
$this->red_path = '/'; $this->red_path = '/';
$this->auth = $auth_plugin; $this->auth = $auth_plugin;
// logger('Red_Directory: ' . print_r($this,true));
$this->folder_hash = ''; $this->folder_hash = '';
$this->getDir(); $this->getDir();
if($this->auth->browser) if($this->auth->browser)
$this->auth->browser->set_writeable(); $this->auth->browser->set_writeable();
@ -32,8 +32,6 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
function getChildren() { function getChildren() {
logger('RedDirectory::getChildren : ' . print_r($this,true));
if(get_config('system','block_public') && (! $this->auth->channel_id) && (! $this->auth->observer)) { if(get_config('system','block_public') && (! $this->auth->channel_id) && (! $this->auth->observer)) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
return; return;
@ -51,9 +49,8 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
function getChild($name) { function getChild($name) {
logger('RedDirectory::getChild : ' . $name, LOGGER_DATA);
logger('RedDirectory::getChild : ' . $name);
logger('RedDirectory::getChild : ' . print_r($this,true));
if(get_config('system','block_public') && (! $this->auth->channel_id) && (! $this->auth->observer)) { if(get_config('system','block_public') && (! $this->auth->channel_id) && (! $this->auth->observer)) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
@ -70,17 +67,15 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
} }
$x = RedFileData($this->ext_path . '/' . $name, $this->auth); $x = RedFileData($this->ext_path . '/' . $name, $this->auth);
logger('RedFileData returns: ' . print_r($x,true));
if($x) if($x)
return $x; return $x;
throw new DAV\Exception\NotFound('The file with name: ' . $name . ' could not be found'); throw new DAV\Exception\NotFound('The file with name: ' . $name . ' could not be found');
} }
function getName() { function getName() {
logger('RedDirectory::getName : ' . print_r($this,true)); logger('RedDirectory::getName returns: ' . basename($this->red_path), LOGGER_DATA);
logger('RedDirectory::getName returns: ' . basename($this->red_path));
return (basename($this->red_path)); return (basename($this->red_path));
} }
@ -88,9 +83,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
function createFile($name,$data = null) { function createFile($name,$data = null) {
logger('RedDirectory::createFile : ' . $name); logger('RedDirectory::createFile : ' . $name, LOGGER_DEBUG);
logger('RedDirectory::createFile : ' . print_r($this,true));
if(! $this->auth->owner_id) { if(! $this->auth->owner_id) {
logger('createFile: permission denied'); logger('createFile: permission denied');
@ -108,10 +101,17 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
$c = q("select * from channel where channel_id = %d limit 1", $c = q("select * from channel where channel_id = %d limit 1",
intval($this->auth->channel_id) intval($this->auth->owner_id)
); );
if(! $c) {
logger('createFile: no channel');
throw new DAV\Exception\Forbidden('Permission denied.');
return;
}
$filesize = 0; $filesize = 0;
$hash = random_string(); $hash = random_string();
@ -171,7 +171,7 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
function createDirectory($name) { function createDirectory($name) {
logger('RedDirectory::createDirectory: ' . $name); logger('RedDirectory::createDirectory: ' . $name, LOGGER_DEBUG);
if((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) { if((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
@ -184,37 +184,31 @@ class RedDirectory extends DAV\Node implements DAV\ICollection {
if($r) { if($r) {
$result = attach_mkdir($r[0],$this->auth->observer,array('filename' => $name,'folder' => $this->folder_hash)); $result = attach_mkdir($r[0],$this->auth->observer,array('filename' => $name,'folder' => $this->folder_hash));
if(! $result['success'])
logger('RedDirectory::createDirectory: ' . print_r($result,true)); logger('RedDirectory::createDirectory: ' . print_r($result,true), LOGGER_DEBUG);
} }
} }
function childExists($name) { function childExists($name) {
logger('RedDirectory::childExists : ' . print_r($this->auth,true));
if($this->red_path === '/' && $name === 'cloud') { if($this->red_path === '/' && $name === 'cloud') {
logger('RedDirectory::childExists /cloud: true'); logger('RedDirectory::childExists /cloud: true', LOGGER_DATA);
return true; return true;
} }
$x = RedFileData($this->ext_path . '/' . $name, $this->auth,true); $x = RedFileData($this->ext_path . '/' . $name, $this->auth,true);
logger('RedFileData returns: ' . print_r($x,true)); logger('RedFileData returns: ' . print_r($x,true), LOGGER_DATA);
if($x) if($x)
return true; return true;
return false; return false;
} }
function getDir() { function getDir() {
logger('getDir: ' . $this->ext_path, LOGGER_DEBUG);
logger('getDir: ' . $this->ext_path);
$file = $this->ext_path; $file = $this->ext_path;
$x = strpos($file,'/cloud'); $x = strpos($file,'/cloud');
if($x === false) if($x === false)
return; return;
@ -290,24 +284,23 @@ class RedFile extends DAV\Node implements DAV\IFile {
private $name; private $name;
function __construct($name, $data, &$auth) { function __construct($name, $data, &$auth) {
logger('RedFile::_construct: ' . $name);
$this->name = $name; $this->name = $name;
$this->data = $data; $this->data = $data;
$this->auth = $auth; $this->auth = $auth;
logger('RedFile::_construct: ' . print_r($this->data,true)); logger('RedFile::_construct: ' . print_r($this->data,true), LOGGER_DATA);
} }
function getName() { function getName() {
logger('RedFile::getName: ' . basename($this->name)); logger('RedFile::getName: ' . basename($this->name), LOGGER_DEBUG);
return basename($this->name); return basename($this->name);
} }
function setName($newName) { function setName($newName) {
logger('RedFile::setName: ' . basename($this->name) . ' -> ' . $newName); logger('RedFile::setName: ' . basename($this->name) . ' -> ' . $newName, LOGGER_DEBUG);
if((! $newName) || (! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) { if((! $newName) || (! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
@ -325,7 +318,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
function put($data) { function put($data) {
logger('RedFile::put: ' . basename($this->name)); logger('RedFile::put: ' . basename($this->name), LOGGER_DEBUG);
$r = q("select flags, data from attach where hash = '%s' and uid = %d limit 1", $r = q("select flags, data from attach where hash = '%s' and uid = %d limit 1",
@ -380,7 +373,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
function get() { function get() {
logger('RedFile::get: ' . basename($this->name)); logger('RedFile::get: ' . basename($this->name), LOGGER_DEBUG);
$r = q("select data, flags from attach where hash = '%s' and uid = %d limit 1", $r = q("select data, flags from attach where hash = '%s' and uid = %d limit 1",
dbesc($this->data['hash']), dbesc($this->data['hash']),
@ -397,9 +390,7 @@ class RedFile extends DAV\Node implements DAV\IFile {
} }
function getETag() { function getETag() {
logger('RedFile::getETag: ' . basename($this->name));
return $this->data['hash']; return $this->data['hash'];
} }
@ -414,13 +405,11 @@ class RedFile extends DAV\Node implements DAV\IFile {
function getLastModified() { function getLastModified() {
logger('RedFile::getLastModified: ' . basename($this->name));
return $this->data['edited']; return $this->data['edited'];
} }
function delete() { function delete() {
if((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) { if((! $this->auth->owner_id) || (! perm_is_allowed($this->auth->owner_id,$this->auth->observer,'write_storage'))) {
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
return; return;
@ -460,9 +449,6 @@ function RedCollectionData($file,&$auth) {
$file = substr($file,6); $file = substr($file,6);
} }
logger('RedCollectionData: ' . $file);
if((! $file) || ($file === '/')) { if((! $file) || ($file === '/')) {
return RedChannelList($auth); return RedChannelList($auth);
} }
@ -479,8 +465,6 @@ logger('RedCollectionData: ' . $file);
dbesc($channel_name) dbesc($channel_name)
); );
logger('dbg1: ' . print_r($r,true));
if(! $r) if(! $r)
return null; return null;
@ -532,7 +516,7 @@ logger('dbg1: ' . print_r($r,true));
} }
} }
logger('dbg2: ' . print_r($r,true)); // This should no longer be needed since we just returned errors for paths not found
if($path !== '/' . $file) { if($path !== '/' . $file) {
logger("RedCollectionData: Path mismatch: $path !== /$file"); logger("RedCollectionData: Path mismatch: $path !== /$file");
@ -546,8 +530,6 @@ logger('dbg1: ' . print_r($r,true));
intval($channel_id) intval($channel_id)
); );
logger('dbg2: ' . print_r($r,true));
foreach($r as $rr) { foreach($r as $rr) {
if($rr['flags'] & ATTACH_FLAG_DIR) if($rr['flags'] & ATTACH_FLAG_DIR)
$ret[] = new RedDirectory('/cloud' . $path . '/' . $rr['filename'],$auth); $ret[] = new RedDirectory('/cloud' . $path . '/' . $rr['filename'],$auth);
@ -561,7 +543,7 @@ logger('dbg2: ' . print_r($r,true));
function RedFileData($file, &$auth,$test = false) { function RedFileData($file, &$auth,$test = false) {
logger('RedFileData:' . $file . (($test) ? ' (test mode) ' : '')); logger('RedFileData:' . $file . (($test) ? ' (test mode) ' : ''), LOGGER_DEBUG);
$x = strpos($file,'/cloud'); $x = strpos($file,'/cloud');
@ -569,8 +551,6 @@ logger('RedFileData:' . $file . (($test) ? ' (test mode) ' : ''));
$file = substr($file,6); $file = substr($file,6);
} }
logger('RedFileData2: ' . $file);
if((! $file) || ($file === '/')) { if((! $file) || ($file === '/')) {
return RedDirectory('/',$auth); return RedDirectory('/',$auth);
@ -578,14 +558,11 @@ logger('RedFileData2: ' . $file);
$file = trim($file,'/'); $file = trim($file,'/');
logger('file=' . $file);
$path_arr = explode('/', $file); $path_arr = explode('/', $file);
if(! $path_arr) if(! $path_arr)
return null; return null;
logger("file = $file - path = " . print_r($path_arr,true));
$channel_name = $path_arr[0]; $channel_name = $path_arr[0];
@ -594,8 +571,6 @@ logger('file=' . $file);
dbesc($channel_name) dbesc($channel_name)
); );
logger('dbg0: ' . print_r($r,true));
if(! $r) if(! $r)
return null; return null;
@ -607,9 +582,7 @@ logger('file=' . $file);
$permission_error = false; $permission_error = false;
$folder = ''; $folder = '';
//dbg(1);
require_once('include/security.php'); require_once('include/security.php');
$perms = permissions_sql($channel_id); $perms = permissions_sql($channel_id);
@ -617,15 +590,12 @@ logger('file=' . $file);
$errors = false; $errors = false;
for($x = 1; $x < count($path_arr); $x ++) { for($x = 1; $x < count($path_arr); $x ++) {
dbg(1);
$r = q("select id, hash, filename, flags from attach where folder = '%s' and filename = '%s' and uid = %d and (flags & %d) $perms", $r = q("select id, hash, filename, flags from attach where folder = '%s' and filename = '%s' and uid = %d and (flags & %d) $perms",
dbesc($folder), dbesc($folder),
dbesc($path_arr[$x]), dbesc($path_arr[$x]),
intval($channel_id), intval($channel_id),
intval(ATTACH_FLAG_DIR) intval(ATTACH_FLAG_DIR)
); );
dbg(0);
logger('dbg1: ' . print_r($r,true));
if($r && ( $r[0]['flags'] & ATTACH_FLAG_DIR)) { if($r && ( $r[0]['flags'] & ATTACH_FLAG_DIR)) {
$folder = $r[0]['hash']; $folder = $r[0]['hash'];
@ -656,8 +626,6 @@ dbg(0);
} }
logger('dbg1: ' . print_r($r,true));
if($path === '/' . $file) { if($path === '/' . $file) {
if($test) if($test)
return true; return true;
@ -666,13 +634,13 @@ dbg(0);
} }
if($errors) { if($errors) {
logger('RedFileData: not found');
if($test) if($test)
return false; return false;
if($permission_error) { if($permission_error) {
logger('RedFileData: permission error'); logger('RedFileData: permission error');
throw new DAV\Exception\Forbidden('Permission denied.'); throw new DAV\Exception\Forbidden('Permission denied.');
} }
logger('RedFileData: not found');
return; return;
} }
@ -769,17 +737,14 @@ class RedBrowser extends DAV\Browser\Plugin {
function set_writeable() { function set_writeable() {
logger('RedBrowser: ' . print_r($this->auth,true));
if(! $this->auth->owner_id) if(! $this->auth->owner_id)
$this->enablePost = false; $this->enablePost = false;
if(! perm_is_allowed($this->auth->owner_id, get_observer_hash(), 'write_storage')) if(! perm_is_allowed($this->auth->owner_id, get_observer_hash(), 'write_storage'))
$this->enablePost = false; $this->enablePost = false;
else else
$this->enablePost = true; $this->enablePost = true;
} }
} }