2010-12-07 22:22:48 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
2010-12-17 21:25:40 +00:00
|
|
|
/**
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
|
|
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2010-12-17 22:46:14 +00:00
|
|
|
require_once(MODPATH . "webdav/vendor/Sabre/autoload.php");
|
2010-12-07 22:22:48 +00:00
|
|
|
|
2010-12-17 21:25:40 +00:00
|
|
|
class WebDAV_Controller extends Controller {
|
2010-12-17 22:46:14 +00:00
|
|
|
public function gallery() {
|
2010-12-17 22:53:33 +00:00
|
|
|
$root = new Gallery3_DAV_Album("");
|
2010-12-17 21:25:40 +00:00
|
|
|
$tree = new Gallery3_DAV_Tree($root);
|
2010-12-07 22:22:48 +00:00
|
|
|
|
2010-12-15 01:09:47 +00:00
|
|
|
// Skip the lock plugin for now, we don't want Finder to get write support for the time being.
|
2010-12-17 21:25:40 +00:00
|
|
|
// $lock_backend = new Sabre_DAV_Locks_Backend_FS(TMPPATH . "sabredav");
|
|
|
|
// $lock = new Sabre_DAV_Locks_Plugin($lock_backend);
|
|
|
|
$filter = new Sabre_DAV_TemporaryFileFilterPlugin(TMPPATH . "sabredav");
|
|
|
|
|
2010-12-07 22:22:48 +00:00
|
|
|
$server = new Sabre_DAV_Server($tree);
|
2010-12-17 22:46:14 +00:00
|
|
|
$server->setBaseUri(url::site("webdav/gallery"));
|
2010-12-17 21:25:40 +00:00
|
|
|
// $server->addPlugin($lock);
|
|
|
|
$server->addPlugin($filter);
|
|
|
|
|
|
|
|
if ($this->_authenticate()) {
|
|
|
|
$server->exec();
|
|
|
|
}
|
2010-12-07 22:22:48 +00:00
|
|
|
}
|
2010-12-17 21:25:40 +00:00
|
|
|
|
|
|
|
private function _authenticate() {
|
|
|
|
$auth = new Sabre_HTTP_BasicAuth();
|
|
|
|
$auth->setRealm(item::root()->title);
|
|
|
|
$authResult = $auth->getUserPass();
|
|
|
|
list($username, $password) = $authResult;
|
|
|
|
|
|
|
|
if (!$username || !$password) {
|
|
|
|
$auth->requireLogin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = identity::lookup_user_by_name($username);
|
|
|
|
if (empty($user) || !identity::is_correct_password($user, $password)) {
|
|
|
|
$auth->requireLogin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
identity::set_active_user($user);
|
|
|
|
return true;
|
2010-12-07 22:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|