filesystem implementation

113 views
Skip to first unread message

Antonello Carlomagno

unread,
Apr 30, 2013, 9:02:38 AM4/30/13
to sabredav...@googlegroups.com
Hello,

I'm trying to create a webDAv file system
Each user must own folder in order to save own documents.

well,

the authentication works fine with mysql db, but I have problem to understand how to they work directory / file class.

looking the examples, I tried to create a server.php ...

the lines:

$publicDir = 'public';
$rootDirectory = new \MyCollection($publicDir);

All the users after login they see all directory tree ... if set $publicDir with 'public'.$userDir ... each user see only own directory tree.

it's correct ? I seem too simple ... or not ?

I have trouble with the syntax of PHP OOP ... I develop in Delphi (object pascal) and I struggle to understand .... but I am working hard. :-)

In attachment my test file server.php

thanks in advance
Antonello
server.php

Evert Pot

unread,
Apr 30, 2013, 9:10:20 AM4/30/13
to sabredav...@googlegroups.com

On Apr 30, 2013, at 2:02 PM, Antonello Carlomagno <anto...@carlomagno.net> wrote:

> Hello,
>
> I'm trying to create a webDAv file system
> Each user must own folder in order to save own documents.
>
> well,
>
> the authentication works fine with mysql db, but I have problem to understand how to they work directory / file class.
>
> looking the examples, I tried to create a server.php ...
>
> the lines:
>
> $publicDir = 'public';
> $rootDirectory = new \MyCollection($publicDir);
>
> All the users after login they see all directory tree ... if set $publicDir with 'public'.$userDir ... each user see only own directory tree.
>
> it's correct ? I seem too simple ... or not ?

If this is the behavior you are after, then I would say it's correct.

But it doesn't make sense to then use that \MyCollection class. It was intended as a simple example on how you to create new behavior in the tree, so since you are not actually changing anything from the the default behavior, you should use \Sabre\DAV\FS\Directory

> I have trouble with the syntax of PHP OOP ... I develop in Delphi (object pascal) and I struggle to understand .... but I am working hard. :-)

It will be incredibly hard for you to do any sort of customization if you don't have a full understanding of PHP's object model.

Evert

Antonello Carlomagno

unread,
Apr 30, 2013, 9:35:59 AM4/30/13
to sabredav...@googlegroups.com
the basic concepts are the same, I have to learn the syntax.

have instantiated the classes was to learn more about the PHP OOP.

So, if I have to assign a directory for each user, simply set the public dir for each user logged in?

Antonello

Evert Pot

unread,
Apr 30, 2013, 10:15:16 AM4/30/13
to sabredav...@googlegroups.com
On Apr 30, 2013, at 2:35 PM, Antonello Carlomagno <anto...@carlomagno.net> wrote:

> the basic concepts are the same, I have to learn the syntax.
>
> have instantiated the classes was to learn more about the PHP OOP.
>
> So, if I have to assign a directory for each user, simply set the public dir for each user logged in?

Well, this depends on how you want to go about it..

Do you want to only ever give access to a users own personal directory, or do you want to make users share the same namespace and potentially get access to each other's directories?

For option #1 I would subclass Sabre\DAV\FS\Directory and make sure that the $path property reflects the current users' directory, for option #2 I would subclass Sabre\DAV\Collection, override getChildren and return an instance of Sabre\DAV\FS\Directory for each user.

Evert

Antonello Carlomagno

unread,
Apr 30, 2013, 11:54:04 AM4/30/13
to sabredav...@googlegroups.com
ok,

we see if I understand ...

for #1 I subclass with: $rootDirectory = new
DAV\FS\Directory('public'.USERDIR);
and user seen only own folder.

for #2 If I want to manage a shared folders etc etc ... I start with my
last example that I have attached in first post.

it's correct ?


Il 30/04/13 16:15, Evert Pot ha scritto:

Evert Pot

unread,
Apr 30, 2013, 11:56:17 AM4/30/13
to sabredav...@googlegroups.com
On Apr 30, 2013, at 4:54 PM, Antonello Carlomagno <a.carl...@gmail.com> wrote:

> ok,
>
> we see if I understand ...
>
> for #1 I subclass with: $rootDirectory = new DAV\FS\Directory('public'.USERDIR);
> and user seen only own folder.

Yea kinda.. except you don't know which user is currently logged in when you create $rootDirectory, so you also have to handle this _inside_ the class.

>
> for #2 If I want to manage a shared folders etc etc ... I start with my last example that I have attached in first post.
>
> it's correct ?

Yea more or less. Right now the example from your post uses the filesystem to create a list of folders, but I'm guessing you would actually want to do database queries in getChildren to generate a list of folders dynamically.

Evert

Antonello Carlomagno

unread,
Apr 30, 2013, 12:09:14 PM4/30/13
to sabredav...@googlegroups.com
what do you mean __inside__ the class ? I have user authentication ?

but

after login, I can extract the user from Sabre\DAV\Auth class ?
or I create my own user authentication ... in order to set the
$rootDirectory ?

thanks for you help and your patience ...

if you come in Italy you have a dinner paid!


Il 30/04/13 17:56, Evert Pot ha scritto:

Evert Pot

unread,
Apr 30, 2013, 12:17:31 PM4/30/13
to sabredav...@googlegroups.com
On Apr 30, 2013, at 5:09 PM, Antonello Carlomagno <a.carl...@gmail.com> wrote:

> what do you mean __inside__ the class ? I have user authentication ?

I mean you need to subclass and override the functions that use ->path, and instead dynamically generate the value.

>
> but
>
> after login, I can extract the user from Sabre\DAV\Auth class ?
> or I create my own user authentication ... in order to set the $rootDirectory ?
>
> thanks for you help and your patience ...

The problem is that authentication happens _after_ you created Sabre\DAV\FS\Directory. So you don't know the user yet when you create this class.

You can extract the information, but you can only do this after all the objects have already been created. This is why you must subclass Sabre\DAV\FS\Directory and dynamically find the correct path.

> if you come in Italy you have a dinner paid!

I'll hold you to that! :P

Evert

Antonello Carlomagno

unread,
Apr 30, 2013, 12:26:36 PM4/30/13
to sabredav...@googlegroups.com
but If I subclass Sabre\DAV\FS\Directory ... is not the same thing ?

the authentication starts after $server->exec() ?

Antonello

Il 30/04/13 18:17, Evert Pot ha scritto:

Evert Pot

unread,
Apr 30, 2013, 12:31:10 PM4/30/13
to sabredav...@googlegroups.com
On Apr 30, 2013, at 5:26 PM, Antonello Carlomagno <a.carl...@gmail.com> wrote:

> but If I subclass Sabre\DAV\FS\Directory ... is not the same thing ?
>
> the authentication starts after $server->exec() ?

Yes.

How about giving it a shot, and see where you get stuck? That may be easier than my vague explanation. You should be able to figure out a great deal, just reading code and running it..

Evert

Antonello Carlomagno

unread,
Apr 30, 2013, 12:40:30 PM4/30/13
to sabredav...@googlegroups.com
you're right ... I begin to see the birds on my head!

this is my last file that works...  I have cleared all tries ...

the trouble is this line:  $rootDirectory = new DAV\FS\Directory('public');

How to change public with public/userdir ?

Antonello

<?php

use
    Sabre\DAV,Sabre\DAV\Auth;

require_once 'vendor/autoload.php';

$rootDirectory = new DAV\FS\Directory('public');

$server = new DAV\Server($rootDirectory);

$server->setBaseUri('/server.php/');
$pdo = new PDO('mysql:host=localhost;dbname=xxx', 'xxx', 'xxx');

$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

$authBackend = new Auth\Backend\PDO($pdo);

$authPlugin = new Auth\Plugin($authBackend,'SabreDAV');

$server->addPlugin($authPlugin);


$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);

$server->addPlugin($lockPlugin);

$browser = new \Sabre\DAV\Browser\Plugin();
$server->addPlugin($browser);


$tffp = new DAV\TemporaryFileFilterPlugin('tempdata');
$server->addPlugin($tffp);

$server->exec();



Il 30/04/13 18:31, Evert Pot ha scritto:

Evert Pot

unread,
Apr 30, 2013, 1:19:55 PM4/30/13
to sabredav...@googlegroups.com
On Apr 30, 2013, at 5:40 PM, Antonello Carlomagno <a.carl...@gmail.com> wrote:

> you're right ... I begin to see the birds on my head!
>
> this is my last file that works... I have cleared all tries ...
>
> the trouble is this line: $rootDirectory = new DAV\FS\Directory('public');
>
> How to change public with public/userdir ?

You can find out the current username by calling:

$authPlugin->getCurrentUser();

but you _must_ subclass DAV\FS\Directory first, pass the $authPlugin in the constructor and call $authPlugin->getCurrentUser() inside the class.

Evert

Antonello Carlomagno

unread,
May 3, 2013, 6:18:08 AM5/3/13
to sabredav...@googlegroups.com
hello,
I tried this in order to get username ... but I received the 500 error
from server ... Why?
I have extended the construct of Directory Class ... and I would to call
the authenticate method ...

where I wrong ?

my part of code.......

class MyDirectory extends DAV\Collection {
private $myPath;
function __construct($myPath) {
$this->myPath = $myPath;
}
}

$rootDirectory = new MyDirectory('public');
$server = new DAV\Server($rootDirectory);


antonello


Il 30/04/13 19:19, Evert Pot ha scritto:

Evert Pot

unread,
May 3, 2013, 6:37:54 AM5/3/13
to sabredav...@googlegroups.com
The error message for this should be extremely obvious..
> --
> You received this message because you are subscribed to the Google Groups "SabreDAV Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sabredav-discu...@googlegroups.com.
> To post to this group, send email to sabredav...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sabredav-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Antonello Carlomagno

unread,
May 3, 2013, 10:46:27 AM5/3/13
to sabredav...@googlegroups.com
Hi Evert,

I'm about to throw in the towel ...

in attachment there is my last server.php ...
the $this->userdir = $login->getCurrentUser() return empty string ....

I don't understand what is the object sequence ...

is there a possibility that I pay you for create a basic project of server ?


thanks
Antonello
server.php

Evert Pot

unread,
May 3, 2013, 10:54:52 AM5/3/13
to sabredav...@googlegroups.com
The problem is that you are calling getCurrentUser in the constructor, but the object is constructed before
$server->exec().

You need to defer calling getCurrentUser until the very last moment.

So, instead of using a private $path or $userDir property, you should add a method like 'getPath()' and make sure you call that everywhere instead of directly using $this->path

In that method, you construct the full path based on $this->login->getCurrentUser and whatever else.

Within getChild(), I don't think you need to construct a 'MyCollection' there. I think you can just create a default Sabre\DAV\FS\Directory. You only really need 'MyCollection' as the root node, if I understand your requirements correctly.

I don't really have time for any contract work at the moment. Your problems don't sound very difficult, so if there's anyone on this list with some SabreDAV + WebDAV experience and looking for a gig, contact Antonello :)

Evert

Antonello Carlomagno

unread,
May 3, 2013, 11:00:08 AM5/3/13
to sabredav...@googlegroups.com
thanks for all



Il 03/05/13 16:54, Evert Pot ha scritto:
Reply all
Reply to author
Forward
0 new messages