Saturday, April 3, 2010
The Full WebDAV Server
Now that we've implemented the authentication method, we can add it to the code previously developed. The following listing shows the entire code as it should be pieced together.
The only thing you need to be wary of is that the user_exists() and get_user_hash() methods don't really exist - you must replace these with your own mechanism for looking up user details.
Additionally, I've omitted the Sabre_DAV_TemporaryFileFilterPlugin plug-in, but you can experiment with that if you want to.
Listing 10 The full WebDAV server (index.php)
setRealm($realm);
$auth->init();
// @todo
function user_exists($username)
{
return false;
}
// @todo
function get_user_hash($username)
{
return null;
}
// find user details for authentication
$username = $auth->getUsername();
if (!user_exists($username)) {
$auth->requireLogin();
echo "Authentication required";
exit;
}
$hash = get_user_hash($username);
// try and authenticate the user
if (!$auth->validateA1($hash)) {
$auth->requireLogin();
echo "Authentication required";
exit;
}
// create the WebDAV server
$tree = new Sabre_DAV_ObjectTree(
new Sabre_DAV_FS_Directory($path)
);
$server = new Sabre_DAV_Server($tree);
// add the browser plug-in
$server->addPlugin(
new Sabre_DAV_Browser_Plugin()
);
// add the locks plug-in
$backend = new Sabre_DAV_Locks_Backend_FS();
$server->addPlugin(
new Sabre_DAV_Locks_Plugin($backend)
);
// handle the request
$server->exec();
?>
Subscribe to:
Post Comments (Atom)











No comments:
Post a Comment