Commit ae15a777 authored by mku's avatar mku

ZP-519 #comment Basic autodiscover functionality

git-svn-id: https://z-push.org/svn/z-push/trunk@1896 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent f1bc4ca9
......@@ -52,11 +52,11 @@ include_once('../lib/interface/iexportchanges.php');
include_once('../lib/interface/iimportchanges.php');
include_once('../lib/interface/isearchprovider.php');
include_once('../lib/interface/istatemachine.php');
include_once('../config.php');
include_once('config.php');
class ZPushAutodiscover {
const ACCEPTABLERESPONSESCHEMA = 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006';
const MAXINPUTSIZE = 8192; // The autodiscover request shouldn't exceed that value
const MAXINPUTSIZE = 8192; // Bytes, the autodiscover request shouldn't exceed that value
private static $instance;
......@@ -140,21 +140,20 @@ class ZPushAutodiscover {
$xml = simplexml_load_string($input);
if (!isset($xml->Request->EMailAddress)) {
throw new ZPushException('Invalid input XML: no email address.');
throw new FatalException('Invalid input XML: no email address.');
}
if ($xml->Request->EMailAddress != $_SERVER['PHP_AUTH_USER']) {
throw new ZPushException('Autodiscover is supported only for the auth user.');
throw new FatalException('Autodiscover is supported only for the auth user.');
}
if (!isset($xml->Request->AcceptableResponseSchema)) {
throw new ZPushException('Invalid input XML: no AcceptableResponseSchema.');
throw new FatalException('Invalid input XML: no AcceptableResponseSchema.');
}
if ($xml->Request->AcceptableResponseSchema != ZPushAutodiscover::ACCEPTABLERESPONSESCHEMA) {
throw new ZPushException('Invalid input XML: not a mobilesync responseschema.');
throw new FatalException('Invalid input XML: not a mobilesync responseschema.');
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("loglevel:%d, wbxml:%d", LOGLEVEL, LOGLEVEL_WBXML));
if (LOGLEVEL >= LOGLEVEL_WBXML) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("ZPushAutodiscover->getIncomingXml() incoming XML data:%s%s", PHP_EOL, $xml->asXML()));
}
......@@ -171,14 +170,19 @@ class ZPushAutodiscover {
* @return string $username
*/
private function login($backend) {
// First try to logon using the complete email address.
// If that fails, try to logon using the local part.
$username = $_SERVER['PHP_AUTH_USER'];
// Determine the login name depending on the configuration: complete email address or
// the local part only.
if (USE_FULLEMAIL_FOR_LOGIN) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Using the complete email address for login."));
$username = $_SERVER['PHP_AUTH_USER'];
}
else{
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Using the username only for login."));
$username = Utils::GetLocalPartFromEmail($_SERVER['PHP_AUTH_USER']);
}
if($backend->Logon($username, "", $_SERVER['PHP_AUTH_PW']) == false) {
$username = Utils::GetLocalPartFromEmail($username);
if($backend->Logon($username, "", $_SERVER['PHP_AUTH_PW']) == false) {
throw new AuthenticationRequiredException("Access denied. Username or password incorrect");
}
throw new AuthenticationRequiredException("Access denied. Username or password incorrect.");
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAutodiscover->login() Using '%s' as the username.", $username));
return $username;
......
<?php
/***********************************************
* File : config.php
* Project : Z-Push
* Descr : Autodiscover configuration file
*
* Created : 30.07.2014
*
* Copyright 2007 - 2014 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation with the following additional
* term according to sec. 7:
*
* According to sec. 7 of the GNU Affero General Public License, version 3,
* the terms of the AGPL are supplemented with the following terms:
*
* "Zarafa" is a registered trademark of Zarafa B.V.
* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
* The licensing of the Program under the AGPL does not imply a trademark license.
* Therefore any rights, title and interest in our trademarks remain entirely with us.
*
* However, if you propagate an unmodified version of the Program you are
* allowed to use the term "Z-Push" to indicate that you distribute the Program.
* Furthermore you may use our trademarks where it is necessary to indicate
* the intended purpose of a product or service provided you use it in accordance
* with honest practices in industrial or commercial matters.
* If you want to propagate modified versions of the Program under the name "Z-Push",
* you may only do so if you have a written permission by Zarafa Deutschland GmbH
* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
/**********************************************************************************
* Default settings
*/
// Defines the base path on the server
define('BASE_PATH', dirname($_SERVER['SCRIPT_FILENAME']). '/');
// The Z-Push server location for the autodiscover response
define('SERVERURL', 'https://localhost/Microsoft-Server-ActiveSync');
/*
* Whether to use the complete email address as a login name
* (e.g. user@company.com) or the username only (user).
* Possible values:
* false - use the username only (default).
* true - use the complete email address.
*/
define('USE_FULLEMAIL_FOR_LOGIN', false);
/**********************************************************************************
* Logging settings
* Possible LOGLEVEL and LOGUSERLEVEL values are:
* LOGLEVEL_OFF - no logging
* LOGLEVEL_FATAL - log only critical errors
* LOGLEVEL_ERROR - logs events which might require corrective actions
* LOGLEVEL_WARN - might lead to an error or require corrective actions in the future
* LOGLEVEL_INFO - usually completed actions
* LOGLEVEL_DEBUG - debugging information, typically only meaningful to developers
* LOGLEVEL_WBXML - also prints the WBXML sent to/from the device
* LOGLEVEL_DEVICEID - also prints the device id for every log entry
* LOGLEVEL_WBXMLSTACK - also prints the contents of WBXML stack
*
* The verbosity increases from top to bottom. More verbose levels include less verbose
* ones, e.g. setting to LOGLEVEL_DEBUG will also output LOGLEVEL_FATAL, LOGLEVEL_ERROR,
* LOGLEVEL_WARN and LOGLEVEL_INFO level entries.
*/
define('LOGFILEDIR', '/var/log/z-push/');
define('LOGFILE', LOGFILEDIR . 'autodiscover.log');
define('LOGERRORFILE', LOGFILEDIR . 'autodiscover-error.log');
define('LOGLEVEL', LOGLEVEL_WBXML);
define('LOGAUTHFAIL', false);
// To save e.g. WBXML data only for selected users, add the usernames to the array
// The data will be saved into a dedicated file per user in the LOGFILEDIR
// Users have to be encapusulated in quotes, several users are comma separated, like:
// $specialLogUsers = array('info@domain.com', 'myusername');
define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
$specialLogUsers = array();
/**********************************************************************************
* Backend settings
*/
// the backend data provider
define('BACKEND_PROVIDER', '');
?>
\ No newline at end of file
......@@ -60,9 +60,6 @@
// This setting specifies the owner parameter in the certificate to look at.
define("CERTIFICATE_OWNER_PARAMETER", "SSL_CLIENT_S_DN_CN");
// The Z-Push server location for the autodiscover response
define('SERVERURL', 'https://localhost/Microsoft-Server-ActiveSync');
/**********************************************************************************
* Default FileStateMachine settings
*/
......
......@@ -289,6 +289,16 @@ interface IBackend {
* @return SyncObject $resolveRecipients
*/
public function ResolveRecipients($resolveRecipients);
/**
* Returns the display name of the user. Used by autodiscover.
*
* @param string $username The username
*
* @access public
* @return string
*/
public function GetUserFullname($username);
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment