2007-08-28 10:18:04 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Common code for WebDAVAdmin.
|
|
|
|
*
|
|
|
|
* @author Jan Dittberner <jan@dittberner.info>
|
|
|
|
* @version $Id$
|
|
|
|
* @license GPL
|
|
|
|
* @package WebDAVAdmin
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Jan Dittberner
|
|
|
|
*
|
|
|
|
* This file is part of WebDAVAdmin.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-11-22 00:00:58 +01:00
|
|
|
if (!isset($_SERVER['DavAdminConfDir'])) {
|
|
|
|
header('HTTP/1.0 500 Internal Server Error');
|
|
|
|
header('Status: 500 Internal Server Error');
|
|
|
|
header('Content-Type: text/plain;charset=utf8');
|
|
|
|
print("The Server is not configured correctly. " .
|
|
|
|
"Please tell your Administrator to set the " .
|
|
|
|
"DavAdminConfDir environment variable.");
|
|
|
|
exit();
|
|
|
|
}
|
2007-08-28 10:18:04 +02:00
|
|
|
/** Include configuration information. */
|
2007-11-22 00:00:58 +01:00
|
|
|
require_once($_SERVER['DavAdminConfDir'] . '/config.inc.php');
|
2007-08-28 10:18:04 +02:00
|
|
|
|
|
|
|
/** DAV administrator group name. */
|
|
|
|
define(ADMIN_GROUP, 'davadmin');
|
|
|
|
|
|
|
|
/** Include the Smarty template engine. */
|
|
|
|
require_once("smarty/libs/Smarty.class.php");
|
|
|
|
|
|
|
|
/** Global Smarty template engine instance. */
|
|
|
|
$smarty = new Smarty();
|
2007-11-22 00:00:58 +01:00
|
|
|
$smarty->compile_dir = $davconfig['compile_dir'];
|
2007-08-28 10:18:04 +02:00
|
|
|
|
|
|
|
/** Handle invalid requests to the application. */
|
|
|
|
function invalidCall() {
|
|
|
|
header("Content-Type: text/plain; charset=UTF-8");
|
|
|
|
print("Ungültiger Aufruf!");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle errors with an XML message. */
|
|
|
|
function errorAsXml($errormsg) {
|
|
|
|
header("Content-Type: text/xml; charset=UTF-8");
|
|
|
|
$GLOBALS['smarty']->assign("errormsg", $errormsg);
|
|
|
|
$GLOBALS['smarty']->display("error.xml");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle errors with an HTML error page. */
|
|
|
|
function errorAsHtml($errormsg) {
|
|
|
|
header("Content-Type: text/html; charset=UTF-8");
|
|
|
|
$GLOBALS['smarty']->assign("errormsg", $errormsg);
|
|
|
|
$GLOBALS['smarty']->display("error.html");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-11-22 00:00:58 +01:00
|
|
|
function getFullPath($dirname) {
|
|
|
|
return $GLOBALS['davconfig']['dav.dir'] . DIRECTORY_SEPARATOR . $dirname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check configuration
|
|
|
|
$errmsgs = array();
|
|
|
|
if (!isset($davconfig['digest.file'])) {
|
2007-11-22 08:41:30 +01:00
|
|
|
array_push($errmsgs, 'digest.file is not defined.');
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['digest.file']) ||
|
|
|
|
!is_writable($davconfig['digest.file'])) {
|
|
|
|
array_push($errmsgs,
|
|
|
|
'The specified digest file is not readable and writable.');
|
|
|
|
}
|
|
|
|
if (!isset($davconfig['group.file'])) {
|
2007-11-22 08:41:30 +01:00
|
|
|
array_push($errmsgs, 'group.file is not defined.');
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['group.file']) ||
|
|
|
|
!is_writable($davconfig['group.file'])) {
|
|
|
|
array_push($errmsgs,
|
|
|
|
'The specified group file is not readable and writable.');
|
|
|
|
}
|
|
|
|
if (!isset($davconfig['namemap.file'])) {
|
2007-11-22 08:41:30 +01:00
|
|
|
array_push($errmsgs, 'namemap.file is not defined.');
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['namemap.file']) ||
|
|
|
|
!is_writable($davconfig['namemap.file'])) {
|
|
|
|
array_push($errmsgs,
|
|
|
|
'The specified name mapping file is not readable and writable.');
|
|
|
|
}
|
|
|
|
if (!isset($davconfig['dav.dir'])) {
|
2007-11-22 08:41:30 +01:00
|
|
|
array_push($errmsgs, 'dav.dir is not defined.');
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_dir($davconfig['dav.dir']) ||
|
|
|
|
!is_readable($davconfig['dav.dir']) ||
|
|
|
|
!is_writable($davconfig['dav.dir'])) {
|
|
|
|
array_push($errmsgs,
|
|
|
|
'The specified DAV directory is no directory or not accessable.');
|
|
|
|
}
|
2007-11-22 08:41:30 +01:00
|
|
|
if (empty($davconfig['dav.realm'])) {
|
|
|
|
array_push($errmsgs, 'dav.realm is not defined.');
|
|
|
|
}
|
|
|
|
if (empty($davconfig['dav.uri'])) {
|
|
|
|
array_push($errmsgs, 'dav.uri is not defined.');
|
|
|
|
}
|
2007-11-22 00:00:58 +01:00
|
|
|
if (!empty($errmsgs)) {
|
|
|
|
errorAsHtml(implode("<br />", $errmsgs));
|
|
|
|
}
|
|
|
|
|
2007-11-22 08:41:30 +01:00
|
|
|
$namemapdata = file_get_contents($davconfig['namemap.file']);
|
|
|
|
$namemap = json_decode($namemapdata, true);
|
2007-11-22 00:00:58 +01:00
|
|
|
if ($namemap === NULL) {
|
|
|
|
$namemap = array();
|
2007-08-28 10:18:04 +02:00
|
|
|
}
|
|
|
|
?>
|