Commit 75c887bf authored by Manfred Kutas's avatar Manfred Kutas

ZP-904 Fixed logging in autodiscover. Include autodiscover config

instead of general Z-Push config. Added static CheckConfig() function
for autodiscover.

Released under the Affero GNU General Public License (AGPL) version 3.
parent ed03030e
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
************************************************/ ************************************************/
require_once '../vendor/autoload.php'; require_once '../vendor/autoload.php';
require_once '../config.php'; require_once 'config.php';
class ZPushAutodiscover { class ZPushAutodiscover {
const ACCEPTABLERESPONSESCHEMAMOBILESYNC = 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006'; const ACCEPTABLERESPONSESCHEMAMOBILESYNC = 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006';
...@@ -59,6 +59,7 @@ class ZPushAutodiscover { ...@@ -59,6 +59,7 @@ class ZPushAutodiscover {
* @return void * @return void
*/ */
public static function DoZPushAutodiscover() { public static function DoZPushAutodiscover() {
self::CheckConfig();
ZLog::Write(LOGLEVEL_DEBUG, '-------- Start ZPushAutodiscover'); ZLog::Write(LOGLEVEL_DEBUG, '-------- Start ZPushAutodiscover');
ZLog::Write(LOGLEVEL_INFO, sprintf("Z-Push version='%s'", @constant('ZPUSH_VERSION'))); ZLog::Write(LOGLEVEL_INFO, sprintf("Z-Push version='%s'", @constant('ZPUSH_VERSION')));
// TODO use filterevilinput? // TODO use filterevilinput?
...@@ -86,10 +87,6 @@ class ZPushAutodiscover { ...@@ -86,10 +87,6 @@ class ZPushAutodiscover {
* @return void * @return void
*/ */
public function DoAutodiscover() { public function DoAutodiscover() {
if (!defined('REAL_BASE_PATH')) {
define('REAL_BASE_PATH', str_replace('autodiscover/', '', BASE_PATH));
}
set_include_path(get_include_path() . PATH_SEPARATOR . REAL_BASE_PATH);
$response = ""; $response = "";
try { try {
...@@ -255,16 +252,78 @@ class ZPushAutodiscover { ...@@ -255,16 +252,78 @@ class ZPushAutodiscover {
ZLog::Write(LOGLEVEL_WARN, sprintf("The backend was not able to find attribute '%s' of the user. Fall back to the default value.", $attrib)); ZLog::Write(LOGLEVEL_WARN, sprintf("The backend was not able to find attribute '%s' of the user. Fall back to the default value.", $attrib));
return false; return false;
} }
}
// set time zone public static function CheckConfig() {
// code contributed by Robert Scheck (rsc) if (!defined('REAL_BASE_PATH')) {
if(defined('TIMEZONE') ? constant('TIMEZONE') : false) { define('REAL_BASE_PATH', str_replace('autodiscover/', '', BASE_PATH));
if (! @date_default_timezone_set(TIMEZONE)) }
throw new FatalMisconfigurationException(sprintf("The configured TIMEZONE '%s' is not valid. Please check supported timezones at http://www.php.net/manual/en/timezones.php", constant('TIMEZONE'))); set_include_path(get_include_path() . PATH_SEPARATOR . REAL_BASE_PATH);
}
else if(!ini_get('date.timezone')) { // set time zone
date_default_timezone_set('Europe/Amsterdam'); // code contributed by Robert Scheck (rsc)
if(defined('TIMEZONE') ? constant('TIMEZONE') : false) {
if (! @date_default_timezone_set(TIMEZONE))
throw new FatalMisconfigurationException(sprintf("The configured TIMEZONE '%s' is not valid. Please check supported timezones at http://www.php.net/manual/en/timezones.php", constant('TIMEZONE')));
}
else if(!ini_get('date.timezone')) {
date_default_timezone_set('Europe/Amsterdam');
}
if (!defined('LOGBACKEND')) {
define('LOGBACKEND', 'filelog');
}
if (strtolower(LOGBACKEND) == 'syslog') {
define('LOGBACKEND_CLASS', 'Syslog');
if (!defined('LOG_SYSLOG_FACILITY')) {
define('LOG_SYSLOG_FACILITY', LOG_LOCAL0);
}
if (!defined('LOG_SYSLOG_HOST')) {
define('LOG_SYSLOG_HOST', false);
}
if (!defined('LOG_SYSLOG_PORT')) {
define('LOG_SYSLOG_PORT', 514);
}
if (!defined('LOG_SYSLOG_PROGRAM')) {
define('LOG_SYSLOG_PROGRAM', 'z-push-autodiscover');
}
if (!is_numeric(LOG_SYSLOG_PORT)) {
throw new FatalMisconfigurationException("The LOG_SYSLOG_PORT must a be a number.");
}
if (LOG_SYSLOG_HOST && LOG_SYSLOG_PORT <= 0) {
throw new FatalMisconfigurationException("LOG_SYSLOG_HOST is defined but the LOG_SYSLOG_PORT does not seem to be valid.");
}
}
elseif (strtolower(LOGBACKEND) == 'filelog') {
define('LOGBACKEND_CLASS', 'FileLog');
if (!defined('LOGFILEDIR'))
throw new FatalMisconfigurationException("The LOGFILEDIR is not configured. Check if the config.php file is in place.");
if (substr(LOGFILEDIR, -1,1) != "/")
throw new FatalMisconfigurationException("The LOGFILEDIR should terminate with a '/'");
if (!file_exists(LOGFILEDIR))
throw new FatalMisconfigurationException("The configured LOGFILEDIR does not exist or can not be accessed.");
if ((!file_exists(LOGFILE) && !touch(LOGFILE)) || !is_writable(LOGFILE))
throw new FatalMisconfigurationException("The configured LOGFILE can not be modified.");
if ((!file_exists(LOGERRORFILE) && !touch(LOGERRORFILE)) || !is_writable(LOGERRORFILE))
throw new FatalMisconfigurationException("The configured LOGERRORFILE can not be modified.");
// check ownership on the (eventually) just created files
Utils::FixFileOwner(LOGFILE);
Utils::FixFileOwner(LOGERRORFILE);
}
else {
define('LOGBACKEND_CLASS', LOGBACKEND);
}
} }
}
ZPushAutodiscover::DoZPushAutodiscover(); ZPushAutodiscover::DoZPushAutodiscover();
...@@ -79,11 +79,25 @@ ...@@ -79,11 +79,25 @@
* ones, e.g. setting to LOGLEVEL_DEBUG will also output LOGLEVEL_FATAL, LOGLEVEL_ERROR, * ones, e.g. setting to LOGLEVEL_DEBUG will also output LOGLEVEL_FATAL, LOGLEVEL_ERROR,
* LOGLEVEL_WARN and LOGLEVEL_INFO level entries. * LOGLEVEL_WARN and LOGLEVEL_INFO level entries.
*/ */
define('LOGBACKEND', 'filelog');
define('LOGFILEDIR', '/var/log/z-push/'); define('LOGFILEDIR', '/var/log/z-push/');
define('LOGFILE', LOGFILEDIR . 'autodiscover.log'); define('LOGFILE', LOGFILEDIR . 'autodiscover.log');
define('LOGERRORFILE', LOGFILEDIR . 'autodiscover-error.log'); define('LOGERRORFILE', LOGFILEDIR . 'autodiscover-error.log');
define('LOGLEVEL', LOGLEVEL_INFO); define('LOGLEVEL', LOGLEVEL_INFO);
define('LOGUSERLEVEL', LOGLEVEL); define('LOGUSERLEVEL', LOGLEVEL);
$specialLogUsers = array();
// Syslog settings
// false will log to local syslog, otherwise put the remote syslog IP here
define('LOG_SYSLOG_HOST', false);
// Syslog port
define('LOG_SYSLOG_PORT', 514);
// Program showed in the syslog. Useful if you have more than one instance login to the same syslog
define('LOG_SYSLOG_PROGRAM', 'z-push-autodiscover');
// Syslog facility - use LOG_USER when running on Windows
define('LOG_SYSLOG_FACILITY', LOG_LOCAL0);
/********************************************************************************** /**********************************************************************************
* Backend settings * Backend settings
*/ */
......
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