2007-08-28 10:18:04 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2007-11-26 09:49:33 +01:00
|
|
|
* Common code for DAVAdmin.
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
|
|
|
* @author Jan Dittberner <jan@dittberner.info>
|
|
|
|
* @version $Id$
|
|
|
|
* @license GPL
|
2007-11-26 09:49:33 +01:00
|
|
|
* @package DAVAdmin
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Jan Dittberner
|
|
|
|
*
|
2007-11-26 09:49:33 +01:00
|
|
|
* This file is part of DAVAdmin.
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
|
|
|
* 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-12-01 21:30:41 +01:00
|
|
|
/** Include the code shared between normal pages and AJAX. */
|
|
|
|
require_once("shared.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-12-02 22:13:47 +01:00
|
|
|
|
|
|
|
// negotiate the correct template_dir
|
|
|
|
if (is_dir(($dir = realpath(implode(DIRECTORY_SEPARATOR,
|
|
|
|
array($smarty->template_dir,
|
|
|
|
$_SESSION["language"])))))) {
|
|
|
|
$smarty->template_dir = $dir;
|
|
|
|
} else if (is_dir(($dir = realpath(implode(DIRECTORY_SEPARATOR,
|
|
|
|
array($smarty->template_dir,
|
|
|
|
substr($_SESSION["language"],
|
|
|
|
0, 2))))))) {
|
|
|
|
$smarty->template_dir = $dir;
|
|
|
|
} else {
|
|
|
|
_server_error(sprintf(_("Could not find one of the language directories!\n%s,\n%s"),
|
|
|
|
implode(DIRECTORY_SEPARATOR,
|
|
|
|
array($smarty->template_dir,
|
|
|
|
$_SESSION["language"])),
|
|
|
|
implode(DIRECTORY_SEPARATOR,
|
|
|
|
array($smarty->template_dir,
|
|
|
|
substr($_SESSION["language"], 0, 2)))));
|
|
|
|
}
|
|
|
|
$compile_dir = implode(DIRECTORY_SEPARATOR, array($davconfig['compile_dir'],
|
|
|
|
$_SESSION["language"]));
|
|
|
|
if (!is_dir($compile_dir)) {
|
|
|
|
mkdir($compile_dir);
|
|
|
|
}
|
|
|
|
$smarty->compile_dir = $compile_dir;
|
2007-08-28 10:18:04 +02:00
|
|
|
|
2007-12-02 23:11:59 +01:00
|
|
|
/**
|
|
|
|
* Handle invalid requests to the application. Execution stops here.
|
|
|
|
*/
|
2007-08-28 10:18:04 +02:00
|
|
|
function invalidCall() {
|
|
|
|
header("Content-Type: text/plain; charset=UTF-8");
|
2007-11-26 10:56:48 +01:00
|
|
|
print(_("Invalid call!"));
|
2007-08-28 10:18:04 +02:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-12-02 23:11:59 +01:00
|
|
|
/**
|
|
|
|
* Handle errors with an XML message. Execution stops here.
|
|
|
|
*
|
|
|
|
* @param string $errormsg error message
|
|
|
|
*/
|
2007-08-28 10:18:04 +02:00
|
|
|
function errorAsXml($errormsg) {
|
|
|
|
header("Content-Type: text/xml; charset=UTF-8");
|
|
|
|
$GLOBALS['smarty']->assign("errormsg", $errormsg);
|
|
|
|
$GLOBALS['smarty']->display("error.xml");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-12-02 23:11:59 +01:00
|
|
|
/**
|
|
|
|
* Handle errors with an HTML error page. Execution stops here.
|
|
|
|
*
|
|
|
|
* @param string $errormsg error msg
|
|
|
|
*/
|
2007-08-28 10:18:04 +02:00
|
|
|
function errorAsHtml($errormsg) {
|
|
|
|
header("Content-Type: text/html; charset=UTF-8");
|
|
|
|
$GLOBALS['smarty']->assign("errormsg", $errormsg);
|
|
|
|
$GLOBALS['smarty']->display("error.html");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2007-12-02 23:11:59 +01:00
|
|
|
/**
|
|
|
|
* Get the full path of relative directory name.
|
|
|
|
*
|
|
|
|
* @param string $dirname directory name relative to configured
|
|
|
|
* $davconfig['dav.dir']
|
|
|
|
* @return string fully qualified directory name
|
|
|
|
*/
|
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-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "digest.file"));
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['digest.file']) ||
|
|
|
|
!is_writable($davconfig['digest.file'])) {
|
|
|
|
array_push($errmsgs,
|
2007-11-26 10:56:48 +01:00
|
|
|
_("The specified digest file is not readable and writable."));
|
2007-11-22 00:00:58 +01:00
|
|
|
}
|
|
|
|
if (!isset($davconfig['group.file'])) {
|
2007-11-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "group.file"));
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['group.file']) ||
|
|
|
|
!is_writable($davconfig['group.file'])) {
|
|
|
|
array_push($errmsgs,
|
2007-11-26 10:56:48 +01:00
|
|
|
_("The specified group file is not readable and writable."));
|
2007-11-22 00:00:58 +01:00
|
|
|
}
|
|
|
|
if (!isset($davconfig['namemap.file'])) {
|
2007-11-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "namemap.file"));
|
2007-11-22 00:00:58 +01:00
|
|
|
} elseif (!is_readable($davconfig['namemap.file']) ||
|
|
|
|
!is_writable($davconfig['namemap.file'])) {
|
|
|
|
array_push($errmsgs,
|
2007-11-26 10:56:48 +01:00
|
|
|
_("The specified name mapping file is not readable and writable."));
|
2007-11-22 00:00:58 +01:00
|
|
|
}
|
|
|
|
if (!isset($davconfig['dav.dir'])) {
|
2007-11-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "dav.dir"));
|
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,
|
2007-11-26 10:56:48 +01:00
|
|
|
_("The specified DAV directory is no directory or not accessable."));
|
2007-11-22 00:00:58 +01:00
|
|
|
}
|
2007-11-22 08:41:30 +01:00
|
|
|
if (empty($davconfig['dav.realm'])) {
|
2007-11-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "dav.realm"));
|
2007-11-22 08:41:30 +01:00
|
|
|
}
|
|
|
|
if (empty($davconfig['dav.uri'])) {
|
2007-11-26 10:56:48 +01:00
|
|
|
array_push($errmsgs,
|
2007-11-30 22:25:52 +01:00
|
|
|
sprintf(_("%s is not defined."), "dav.uri"));
|
2007-11-22 08:41:30 +01:00
|
|
|
}
|
2007-11-22 00:00:58 +01:00
|
|
|
if (!empty($errmsgs)) {
|
|
|
|
errorAsHtml(implode("<br />", $errmsgs));
|
|
|
|
}
|
|
|
|
|
2007-12-02 23:11:59 +01:00
|
|
|
/**
|
|
|
|
* Compares two associative arrays of userdata by their username value.
|
|
|
|
*
|
|
|
|
* @param array &$user1 user data one
|
|
|
|
* @param array &$user2 user data two
|
|
|
|
* @return value of strcmp of the username values
|
|
|
|
*/
|
|
|
|
function cmp_by_usernames(&$user1, &$user2) {
|
2007-11-23 21:43:14 +01:00
|
|
|
return strcmp($user1['username'], $user2['username']);
|
|
|
|
}
|
|
|
|
|
2007-11-22 08:41:30 +01:00
|
|
|
$namemapdata = file_get_contents($davconfig['namemap.file']);
|
|
|
|
$namemap = json_decode($namemapdata, true);
|
2008-11-16 17:54:08 +01:00
|
|
|
if (is_array($namemap)) {
|
|
|
|
uasort($namemap, "cmp_by_usernames");
|
|
|
|
}
|
|
|
|
?>
|