From 5cf542959060e4fd5f8d9dba94ab84835b0e861a Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 6 Apr 2019 01:18:13 +0200 Subject: [PATCH] Implement Autodiscover (#4) * Implement autodiscover --- conf/backend/config-autodiscover.php | 110 +++++++++++++++++++++++++++ conf/backend/config-carddav.php | 2 +- conf/backend/config-combined.php | 30 +++++--- conf/config.php | 2 +- conf/nginx.conf | 24 ++++++ scripts/_common.sh | 2 +- scripts/install | 19 +++-- scripts/upgrade | 24 +++--- 8 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 conf/backend/config-autodiscover.php diff --git a/conf/backend/config-autodiscover.php b/conf/backend/config-autodiscover.php new file mode 100644 index 0000000..f77939f --- /dev/null +++ b/conf/backend/config-autodiscover.php @@ -0,0 +1,110 @@ +. +* +* Consult LICENSE file for details +************************************************/ + +/********************************************************************************** + * Default settings + */ + + // Replace zpush.example.com with your z-push's host name and uncomment the line below. + // define('ZPUSH_HOST', 'zpush.example.com'); + + // Defines the default time zone, change e.g. to "Europe/London" if necessary + define('TIMEZONE', '__TIMEZONE__'); + + // Defines the base path on the server + define('BASE_PATH', dirname($_SERVER['SCRIPT_FILENAME']). '/'); + + /* + * 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); + + /* + * AutoDiscover requires the username to match either the email address + * or the local part of the email address. + * This is not always possible as the username might have a different + * schema than email address. Configure this parameter to match your + * username settings. + * @see https://wiki.z-hub.io/display/ZP/Configuring+Z-Push+Autodiscover#ConfiguringZ-PushAutodiscover-Configuration + * @see https://jira.z-hub.io/browse/ZP-1209 + * + * Possible values: + * AUTODISCOVER_LOGIN_EMAIL - uses the email address as provided when setting up the account + * AUTODISCOVER_LOGIN_NO_DOT - removes the '.' from email address: + * email: first.last@domain.com -> resulting username: firstlast + * AUTODISCOVER_LOGIN_F_NO_DOT_LAST - cuts the first part before '.' after the first letter and + * removes the '.' from email address: + * email: first.last@domain.com -> resulting username: flast + * AUTODISCOVER_LOGIN_F_DOT_LAST - cuts the part before '.' after the first letter and + * leaves the part after '.' as is: + * email: first.last@domain.com -> resulting username: f.last + */ + define('AUTODISCOVER_LOGIN_TYPE', AUTODISCOVER_LOGIN_EMAIL); + +/********************************************************************************** + * 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('LOGBACKEND', 'filelog'); + + define('LOGFILEDIR', '__FINAL_LOGPATH__/'); + define('LOGFILE', LOGFILEDIR . 'autodiscover.log'); + define('LOGERRORFILE', LOGFILEDIR . 'autodiscover-error.log'); + define('LOGLEVEL', LOGLEVEL_INFO); + 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 + */ + // the backend data provider + define('BACKEND_PROVIDER', '__BACKEND__'); diff --git a/conf/backend/config-carddav.php b/conf/backend/config-carddav.php index 95d1103..b291d2c 100644 --- a/conf/backend/config-carddav.php +++ b/conf/backend/config-carddav.php @@ -53,7 +53,7 @@ define('CARDDAV_PATH', '__BAIKALPATH__/card.php/addressbooks/%u/'); // %u: replaced with the username // %d: replaced with the domain // Add the trailing / -define('CARDDAV_DEFAULT_PATH', 'BAIKALPATH/card.php/addressbooks/%u/default'); +define('CARDDAV_DEFAULT_PATH', '__BAIKALPATH__/card.php/addressbooks/%u/default'); // Server path to the GAL addressbook. This addressbook is readonly and searchable by the user, but it will NOT be synced. // If you don't want GAL, comment it diff --git a/conf/backend/config-combined.php b/conf/backend/config-combined.php index 0efb4c0..24a3de7 100644 --- a/conf/backend/config-combined.php +++ b/conf/backend/config-combined.php @@ -47,10 +47,22 @@ class BackendCombinedConfig { 'i' => array( 'name' => 'BackendIMAP', ), + 'z' => array( + 'name' => 'BackendKopano', + ), + 'm' => array( + 'name' => 'BackendMaildir', + ), + 'v' => array( + 'name' => 'BackendVCardDir', + ), + 'l' => array( + 'name' => 'BackendLDAP', + ), 'd' => array( 'name' => 'BackendCardDAV', ), - 'l' => array( + 'c' => array( 'name' => 'BackendCalDAV', ), ), @@ -63,18 +75,18 @@ class BackendCombinedConfig { SYNC_FOLDER_TYPE_WASTEBASKET => 'i', SYNC_FOLDER_TYPE_SENTMAIL => 'i', SYNC_FOLDER_TYPE_OUTBOX => 'i', - SYNC_FOLDER_TYPE_TASK => 'l', - SYNC_FOLDER_TYPE_APPOINTMENT => 'l', + SYNC_FOLDER_TYPE_TASK => 'c', + SYNC_FOLDER_TYPE_APPOINTMENT => 'c', SYNC_FOLDER_TYPE_CONTACT => 'd', - SYNC_FOLDER_TYPE_NOTE => 'l', - SYNC_FOLDER_TYPE_JOURNAL => 'l', + SYNC_FOLDER_TYPE_NOTE => 'c', + SYNC_FOLDER_TYPE_JOURNAL => 'c', SYNC_FOLDER_TYPE_OTHER => 'i', SYNC_FOLDER_TYPE_USER_MAIL => 'i', - SYNC_FOLDER_TYPE_USER_APPOINTMENT => 'l', + SYNC_FOLDER_TYPE_USER_APPOINTMENT => 'c', SYNC_FOLDER_TYPE_USER_CONTACT => 'd', - SYNC_FOLDER_TYPE_USER_TASK => 'l', - SYNC_FOLDER_TYPE_USER_JOURNAL => 'l', - SYNC_FOLDER_TYPE_USER_NOTE => 'l', + SYNC_FOLDER_TYPE_USER_TASK => 'c', + SYNC_FOLDER_TYPE_USER_JOURNAL => 'c', + SYNC_FOLDER_TYPE_USER_NOTE => 'c', SYNC_FOLDER_TYPE_UNKNOWN => 'i', ), //creating a new folder in the root folder should create a folder in one backend diff --git a/conf/config.php b/conf/config.php index c0877a0..76a5e6f 100644 --- a/conf/config.php +++ b/conf/config.php @@ -50,7 +50,7 @@ * false - use the username only. * true - string the mobile sends as username, e.g. full email address (default). */ - define('USE_FULLEMAIL_FOR_LOGIN', true); + define('USE_FULLEMAIL_FOR_LOGIN', false); /********************************************************************************** * StateMachine setting diff --git a/conf/nginx.conf b/conf/nginx.conf index 35df35c..d7d078b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -21,3 +21,27 @@ location /Microsoft-Server-ActiveSync { # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } + +location /AutoDiscover/AutoDiscover.xml { + alias __FINALPATH__/autodiscover/autodiscover.php; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + include fastcgi_params; + fastcgi_param HTTPS on; + fastcgi_param SCRIPT_FILENAME $request_filename; +} + +location /Autodiscover/Autodiscover.xml { + alias __FINALPATH__/autodiscover/autodiscover.php; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + include fastcgi_params; + fastcgi_param HTTPS on; + fastcgi_param SCRIPT_FILENAME $request_filename; +} + +location /autodiscover/autodiscover.xml { + alias __FINALPATH__/autodiscover/autodiscover.php; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + include fastcgi_params; + fastcgi_param HTTPS on; + fastcgi_param SCRIPT_FILENAME $request_filename; +} \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index b4c32ea..1228e40 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="php-soap php5-imap libawl-php php5-xsl" +pkg_dependencies="php-soap php-imap libawl-php php-xsl php-curl libawl-php php-xml php-ldap php-cli php-mbstring php-memcached" #================================================= # PERSONAL HELPERS diff --git a/scripts/install b/scripts/install index 00e822c..ee244ab 100755 --- a/scripts/install +++ b/scripts/install @@ -100,24 +100,23 @@ ynh_print_info "Creating statedir and final_logpath..." mkdir -p $statedir chown -R www-data:www-data $statedir - mkdir -p $final_logpath chown -R www-data:www-data $final_logpath - #================================================= # MODIFY A CONFIG FILE #================================================= # Configuration ynh_replace_string __TIMEZONE__ $(cat /etc/timezone) ../conf/config.php +ynh_replace_string __TIMEZONE__ $(cat /etc/timezone) ../conf/backend/config-autodiscover.php ynh_replace_string __FINAL_LOGPATH__ $final_logpath ../conf/config.php +ynh_replace_string __FINAL_LOGPATH__ $final_logpath ../conf/backend/config-autodiscover.php # Storage of state_dir in /home/yunohost.app # This contains the sync status in between device and z-push ynh_replace_string __STATEDIR__ $statedir ../conf/config.php - # Enable caldav carddav support if yunohost app list --installed -f baikal | grep -q id ; then echo "Detected Baikal" @@ -127,10 +126,13 @@ if yunohost app list --installed -f baikal | grep -q id ; then # Configuration of backend ynh_replace_string __BACKEND__ BackendCombined ../conf/config.php + ynh_replace_string __BACKEND__ BackendCombined ../conf/backend/config-autodiscover.php # Configuration baikal - ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config*.php - ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config*.php + ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config-caldav.php + ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config-carddav.php + ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config-caldav.php + ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config-carddav.php ynh_replace_string __DOMAINTOCHANGE__ $domain ../conf/backend/config-imap.php ynh_replace_string __FLAGTOCHANGE__ true ../conf/backend/config-imap.php @@ -140,15 +142,18 @@ if yunohost app list --installed -f baikal | grep -q id ; then cp ../conf/backend/config-carddav.php $final_path/backend/carddav/config.php cp ../conf/backend/config-caldav.php $final_path/backend/caldav/config.php cp ../conf/backend/config-combined.php $final_path/backend/combined/config.php + cp ../conf/backend/config-autodiscover.php $final_path/autodiscover/config.php else # Configuration of backend ynh_replace_string __BACKEND__ BackendIMAP ../conf/config.php + ynh_replace_string __BACKEND__ BackendIMAP ../conf/backend/config-autodiscover.php # Copy config cp ../conf/config.php $final_path/config.php ynh_replace_string __DOMAINTOCHANGE__ $domain ../conf/backend/config-imap.php ynh_replace_string __FLAGTOCHANGE__ false ../conf/backend/config-imap.php cp ../conf/backend/config-imap.php $final_path/backend/imap/config.php + cp ../conf/backend/config-autodiscover.php $final_path/autodiscover/config.php fi #Copy XMLElement.php @@ -168,7 +173,6 @@ chown -R www-data: $final_path #================================================= ynh_print_info "Configuring log rotation..." - # Use logrotate to manage application logfile(s) ynh_use_logrotate @@ -178,7 +182,8 @@ ynh_use_logrotate ynh_print_info "Configuring SSOwat..." # Make app public -ynh_app_setting_set $app skipped_uris "/" +ynh_app_setting_set $app unprotected_uris "/" +ynh_app_setting_set $app skipped_regex "^[^/]*/[Aa]uto[Dd]iscover.*" #================================================= # RELOAD NGINX diff --git a/scripts/upgrade b/scripts/upgrade index f7abaca..83555d7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -86,7 +86,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -131,7 +130,9 @@ ynh_add_fpm_config # Configuration ynh_replace_string __TIMEZONE__ $(cat /etc/timezone) ../conf/config.php +ynh_replace_string __TIMEZONE__ $(cat /etc/timezone) ../conf/backend/config-autodiscover.php ynh_replace_string __FINAL_LOGPATH__ $final_logpath ../conf/config.php +ynh_replace_string __FINAL_LOGPATH__ $final_logpath ../conf/backend/config-autodiscover.php # Storage of state_dir in /home/yunohost.app # This contains the sync status in between device and z-push @@ -146,10 +147,13 @@ if yunohost app list --installed -f baikal | grep -q id ; then # Configuration of backend ynh_replace_string __BACKEND__ BackendCombined ../conf/config.php + ynh_replace_string __BACKEND__ BackendCombined ../conf/backend/config-autodiscover.php # Configuration baikal - ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config*.php - ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config*.php + ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config-caldav.php + ynh_replace_string __BAIKALDOMAIN__ $caldavdomain ../conf/backend/config-carddav.php + ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config-caldav.php + ynh_replace_string __BAIKALPATH__ $caldavpath ../conf/backend/config-carddav.php ynh_replace_string __DOMAINTOCHANGE__ $domain ../conf/backend/config-imap.php ynh_replace_string __FLAGTOCHANGE__ true ../conf/backend/config-imap.php @@ -159,15 +163,18 @@ if yunohost app list --installed -f baikal | grep -q id ; then cp ../conf/backend/config-carddav.php $final_path/backend/carddav/config.php cp ../conf/backend/config-caldav.php $final_path/backend/caldav/config.php cp ../conf/backend/config-combined.php $final_path/backend/combined/config.php + cp ../conf/backend/config-autodiscover.php $final_path/autodiscover/config.php else # Configuration of backend ynh_replace_string __BACKEND__ BackendIMAP ../conf/config.php + ynh_replace_string __BACKEND__ BackendIMAP ../conf/backend/config-autodiscover.php # Copy config cp ../conf/config.php $final_path/config.php ynh_replace_string __DOMAINTOCHANGE__ $domain ../conf/backend/config-imap.php ynh_replace_string __FLAGTOCHANGE__ false ../conf/backend/config-imap.php cp ../conf/backend/config-imap.php $final_path/backend/imap/config.php + cp ../conf/backend/config-autodiscover.php $final_path/autodiscover/config.php fi # Fixstates to avoid full resync of devices after version upgrades @@ -190,19 +197,14 @@ ynh_use_logrotate --non-append # Set permissions on app files chown -R www-data: $final_path - - - - - - - #================================================= # SETUP SSOWAT #================================================= ynh_print_info "Upgrading SSOwat configuration..." -ynh_app_setting_set $app skipped_uris "/" +# Make app public +ynh_app_setting_set $app unprotected_uris "/" +ynh_app_setting_set $app skipped_regex "^[^/]*/[Aa]uto[Dd]iscover.*" #================================================= # RELOAD NGINX