Commit 2097efe0 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #316 in ZP/z-push from...

Merge pull request #316 in ZP/z-push from feature/ZP-998-implement-script-that-synchronizes to develop

* commit '30179b03': (23 commits)
  ZP-998 Gab2Contacts depends on z-push-common.
  ZP-1120 Link z-push-gab2contacts in /usr/sbin.
  ZP-1084 Rewrite Z-Push path for gab2contacts in rpm packages.
  ZP-1084 Sed needs to make an inline copy of the file instead of redirecting the output.
  ZP-1084 Set z-push path in gab2contacts script.
  ZP-1084 Make gab2contacts executable.
  ZP-1084 Create dir and exclude gab2contacts.
  ZP-1084 Introducing z-push-kopano-gab2contacts.
  ZP-1083 Fixed file encoding.
  ZP-1083 Updates headers and LICENSE, added TRADEMARKS (as ZP-1085).
  ZP-1083 Check if defines are defined before defining, request PR_EC_AB_HIDDEN from addressbook and ignore entry if it's set (as ZP-916).
  ZP-1083 Fixed sending error message to STD_ERROR and exiting with 1 (as ZP-1022).
  ZP-1083 Fixed sending error message to STD_ERROR and exiting with 1.
  ZP-998 Fixed example configurations strings.
  ZP-998 Removed space.
  ZP-998 Use elseif to be 0.0000001% faster.
  ZP-998 Remove unused $store in getExistingContacts().
  ZP-998 The custom hash property should live in the contact/address realm.
  ZP-998 Fixed names.
  ZP-998 Protected methods should start with a lowercase letter.
  ...
parents 6301cd03 30179b03
......@@ -66,6 +66,12 @@ Depends: ${misc:Depends}, php5-mapi | php7-mapi
Description: GAB sync for Kopano
Synchronizes a the global address book for the Kopano Outlook Extension
Package: z-push-kopano-gab2contacts
Architecture: all
Depends: ${misc:Depends}, z-push-common (= ${binary:Version}), php5-mapi | php7-mapi
Description: GAB sync into a contacts folder for Kopano
Synchronizes a the global address book into a contacts folder
Package: z-push-ipc-sharedmemory
Architecture: all
Depends: ${misc:Depends}, z-push-common (= ${binary:Version})
......
......@@ -22,8 +22,12 @@ override_dh_gencontrol:
override_dh_install:
mv src/* .
# set version number
sed -s "s/ZPUSHVERSION/${DEB_VERSION}/" build/version.php.in > version.php
# fix z-push directory in gab2contacts script
sed -i -s "s/PATH_TO_ZPUSH', '\.\.\/\.\.\/src\/')/PATH_TO_ZPUSH', '\/usr\/share\/z-push\/')/" tools/gab2contacts/gab2contacts.php
mv "config.php" "z-push.conf.php";
mkdir conftmp
......@@ -37,6 +41,7 @@ override_dh_install:
mv "backend/searchldap/config.php" "conftmp/galsearch-ldap.conf.php";
mv "backend/sqlstatemachine/config.php" "conftmp/state-sql.conf.php";
mv "tools/gab-sync/config.php" "conftmp/gabsync.conf.php";
mv "tools/gab2contacts/config.php" "conftmp/gab2contacts.conf.php";
mv "autodiscover/config.php" "conftmp/autodiscover.conf.php";
dh_install
......
conftmp/gab2contacts.conf.php /etc/z-push/
tools/gab2contacts /usr/share/z-push/tools/
etc/z-push/gab2contacts.conf.php usr/share/z-push/tools/gab2contacts/config.php
usr/share/z-push/tools/gab2contacts/gab2contacts.php /usr/sbin/z-push-gab2contacts
......@@ -134,6 +134,15 @@ Requires: php-mapi
%description -n %name-kopano-gabsync
Synchronizes a Kopano global address book
%package -n %name-kopano-gab2contacts
Summary: GAB sync into a contacts folder for Kopano
Group: Productivity/Networking/Email/Utilities
Requires: %name-common = %version
Requires: php-mapi
%description -n %name-kopano-gab2contacts
Synchronizes a Kopano global address book into a contacts folder
# IPC SHARED MEMORY
%package -n %name-ipc-sharedmemory
Summary: Z-Push ipc shared memory provider
......@@ -250,6 +259,7 @@ cp -a src/* "$b/%zpush_dir/"
rm -f "$b/%zpush_dir/"{INSTALL,LICENSE}
# COMMON
# set version number
sed -s "s/ZPUSHVERSION/%version/" build/version.php.in > "$b/%zpush_dir/version.php"
mkdir -p "$b/%_sysconfdir/z-push";
......@@ -294,11 +304,19 @@ ln -s "%_sysconfdir/z-push/ldap.conf.php" "$bdir/ldap/config.php";
mv "$bdir/kopano/config.php" "$cdir/kopano.conf.php";
ln -s "%_sysconfdir/z-push/kopano.conf.php" "$bdir/kopano/config.php";
# GAB-SYNC
mkdir -p "$b/%zpush_dir/tools"
cp -a tools/gab-sync "$b/%zpush_dir/tools/"
mv "$b/%zpush_dir/tools/gab-sync/config.php" "$cdir/gabsync.conf.php";
ln -s "%_sysconfdir/z-push/gabsync.conf.php" "$b/%zpush_dir/tools/gab-sync/config.php";
# GAB2CONTACTS
mkdir -p "$b/%zpush_dir/tools"
cp -a tools/gab2contacts "$b/%zpush_dir/tools/"
mv "$b/%zpush_dir/tools/gab2contacts/config.php" "$cdir/gab2contacts.conf.php";
ln -s "%_sysconfdir/z-push/gab2contacts.conf.php" "$b/%zpush_dir/tools/gab2contacts/config.php";
sed -i -s "s/PATH_TO_ZPUSH', '\.\.\/\.\.\/src\/')/PATH_TO_ZPUSH', '\/usr\/share\/z-push\/')/" "$b/%zpush_dir/tools/gab2contacts/gab2contacts.php"
# MEMCACHED
mv "$bdir/ipcmemcached/config.php" "$cdir/memcached.conf.php";
ln -s "%_sysconfdir/z-push/memcached.conf.php" "$bdir/ipcmemcached/config.php";
......@@ -372,6 +390,7 @@ install -Dpm 644 config/apache2/z-push-autodiscover.conf \
%exclude %zpush_dir/autodiscover
%exclude %zpush_dir/tools/migrate-filestates-to-db.php
%exclude %zpush_dir/tools/gab-sync
%exclude %zpush_dir/tools/gab2contacts
%zpush_dir/
%doc src/LICENSE
......@@ -476,6 +495,18 @@ install -Dpm 644 config/apache2/z-push-autodiscover.conf \
%config(noreplace) %attr(0640,root,apache) %_sysconfdir/z-push/gabsync.conf.php
%endif
%files -n %name-kopano-gab2contacts
%defattr(-, root, root)
%dir %zpush_dir/tools
%dir %zpush_dir/tools/gab2contacts
%zpush_dir/tools/gab2contacts/
%dir %_sysconfdir/z-push
%if 0%{?suse_version}
%config(noreplace) %attr(0640,root,www) %_sysconfdir/z-push/gab2contacts.conf.php
%else
%config(noreplace) %attr(0640,root,apache) %_sysconfdir/z-push/gab2contacts.conf.php
%endif
%files -n %name-kopano
# IPC-SHAREDMEMORY
......
This diff is collapsed.
Z-Push Trademark Policy
The word mark "Z-PUSH" (United States registered trademark 4196338) is owned
by Zarafa BV of the Netherlands. Under certain laws, Zarafa also may have
unregistered common law rights to this mark. We (Zarafa) use this mark to
promote and market this software (Z-Push). With regards to using this mark,
we provide the following trademark license.
Introduction
As we wish to encourage adoption of this software by the free software
community, we have drafted this trademark policy to ensure trademark law does
not block legitimate use of the software or the mark we apply to the software.
We have based our policy on the policy of The Document Foundation.
Our goal is to encourage widespread use of our mark by the community while
controlling that use in order to avoid confusion on the part of software users
and the general public, to maintain the value of the image and reputation of
the mark and to protect it from inappropriate or unauthorized use.
Any potential interpretation of this policy that contradicts this goal should be
regarded as a bug. Please let us know so we can fix this policy. The same
applies if a scenario exists in which the intended use of our mark is not
covered. We welcome your feedback.
General requirements
Our policy must balance two competing interests: we need to ensure that our
mark remains a reliable indicator of quality, source, and security; and we
desire to permit all community members, software distributors, and others with
whom we work to discuss our products and to accurately describe their
affiliation with us. In creating our mark policy, we seek to clarify the uses
of our Z-Push mark we consider legitimate and the uses we do not.
Our general requirements are that your use of our mark be non-confusing and
non-disparaging.
By non-confusing, we mean that people should always know whom they are dealing
with, and where the software they are downloading comes from. Websites and
software that are not created or produced by Z-Push should not imply, either
directly or by omission, that they are. For example, such an implication may
arise if a website or software bears no names or mark other than ours, or uses
our mark as the vastly most prominent name.
By non-disparaging, we mean that, outside the bounds of fair use and similar
exceptions in copyright, trademark and related laws, you cannot use our mark
as a vehicle for defaming us or sullying our reputation.
Specific permitted and non-permitted uses
You may use our mark without prior written permission (subject to the
following terms) for the following purposes:
1. To refer to the Z-Push software in substantially unmodified form.
"Substantially unmodified" means built from the source code provided by
the Z-Push project, possibly with minor modifications including but not
limited to: the enabling or disabling of certain features by default,
translations into other languages, changes required for compatibility with
a particular operating system distribution, the inclusion of bug-fix
patches, or the bundling of additional fonts, templates, artwork and
extensions.
2. To identify Z-Push as a distinct component of a software offering.
3. To factually refer to Z-Push itself, its products or its services.
4. To identify Z-Push as a dependency or necessary component of other software,
5. When referring to Z-Push software that is not substantially unmodified,
to say that such software is a "derivative of" or "based on" Z-Push.
6. More generally, to comply with any requirement of the GNU Affero GPL
version 3.
7. As part of the name of a product or service designed to work with Z-Push,
e.g. as in "Bob's add-ons for Z-Push" or "Bob's forum for Z-Push users",
so long as the name as a whole (via its other components) clearly and
unambiguously distinguishes the product from Z-Push, and the general
presentation of the product does not imply any official association or
identity with Z-Push.
You may not use our mark in the following ways:
1. In any way likely to cause confusion as to the identity of Z-Push, the
origin of its software, or the software's license;
2. In any way that indicates a greater degree of association between you
and Z-Push than actually exists;
3. In any way that implies a designated successor to our software (e.g.,
"Z-Push++" or "Z-Push 2020" are not permitted).
4. In any way that indicates that Z-Push favors one distribution, platform,
product, etc. over another.
Additional requirements for marketing
We encourage the use of our mark in marketing, and other publicity materials
related to Z-Push. Of course, any use of our mark is subject to the overarching
requirement that its use be non-confusing.
We have three specific requirements:
1. Proper Form: Our mark should be used in its exact form, neither
abbreviated nor combined with any other word or words. For the logo, you
can download copies in various formats on our website.
2. Symbol: If reasonably possible, the first or most prominent mention of
our registered Z-Push mark should be accompanied by a symbol indicating
that the mark is a registered trademark ("®").
3. Distinguishable: In at least the first reference, the mark should be set
apart from surrounding text, either by capitalizing it or by italicizing,
bolding or underlining it. In addition, a website may not copy the look
and feel of our websites. We do not want the visitor to your websites
to be confused about which entity he/she is dealing with.
The second and third requirements are waived in all contexts where such a mark
is not normally included: email, on-line discussion, non-graphical
advertisements (when permitted), and academic papers. We encourage the use of
the symbol whenever possible, but recognize that many non-commercial and
informal uses will omit it.
Additional requirements for merchandise using our mark
You may create and sell merchandise using the Z-Push mark without additional
permission provided that you use only unmodified graphics from the logo page on
our website. Please contact us if you would like to sell any other merchandise
containing the Z-Push mark.
Additional requirements for services related to our software
If you offer services primarily related to our software (such as support), you
may use our mark in describing and advertising your services relating to one
of our products, so long as you do not violate the guidelines for the use of
our mark or do anything that might mislead customers into thinking that either
your website, service, or product is an official Z-Push website, service, or
product, or that Z-Push has any direct relationship with your organization.
Miscellaneous provisions
We reserve the right to:
1. Determine compliance with this policy.
2. Modify this policy in ways consistent with its mission of protecting the
public, the community and the users, but always within the goal
mentioned above.
3. Grant exceptions to this policy, of any kind and for any reason
whatsoever, other clauses notwithstanding.
If you have questions about using our mark, or if you think you should be able
to use our mark for any purpose not allowed by this policy and would like
permission for that use, or for more information concerning our label program,
please contact us by emailing trademarks@zarafa.com (non-public).
This document is released under the the Creative Commons Attribution-ShareAlike
3.0 Unported License. It is based on work by The Document Foundation at
https://wiki.documentfoundation.org/TradeMark_Policy.
\ No newline at end of file
<?php
/***********************************************
* File : config.php
* Project : Z-Push - tools - GAB2Contacts
* Descr : Configuration file.
*
* Created : 20.07.2016
*
* Copyright 2016 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.
*
* 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
* ************************************************/
// The field to be hashed that is unique and never changes
// in the entire lifetime of the GAB entry.
define('HASHFIELD', 'account');
// ContactWorker implementation to be used
define('CONTACTWORKER', 'Kopano');
// Server connection settings
// Depending on your setup, it might be advisable to change the lines below to one defined with your
// default socket location.
// Normally "default:" points to the default setting ("file:///var/run/kopano/server.sock")
// Examples: define("SERVER", "default:");
// define("SERVER", "http://localhost:236/kopano");
// define("SERVER", "https://localhost:237/kopano");
// define("SERVER", "file:///var/run/kopano/server.sock");
// If you are using ZCP >= 7.2.0, set it to the zarafa location, e.g.
// define("SERVER", "http://localhost:236/zarafa");
// define("SERVER", "https://localhost:237/zarafa");
// define("SERVER", "file:///var/run/zarafad/server.sock");
// For ZCP versions prior to 7.2.0 the socket location is different (http(s) sockets are the same):
// define("SERVER", "file:///var/run/zarafa");
define('SERVER', 'default:');
define('USERNAME', 'SYSTEM');
define('PASSWORD', '');
define('CERTIFICATE', null);
define('CERTIFICATE_PASSWORD', null);
// The GAB to be used. This only needs to be set on a multi-tenant system.
// For standard installations, keep it at 'default'.
define('SOURCE_GAB', 'default');
// Store where the target contact folder is located.
// For the public folder, use SYSTEM.
// To use another store, use the same as USERNAME
// or another store where USERNAME has full access to.
define('CONTACT_FOLDERSTORE', 'SYSTEM');
// Set the target FolderId.
// You can find the id e.g. with the listfolders script of Kopano backend.
define('CONTACT_FOLDERID', '');
// Set the fileas (save as) order for contacts.
// Possible values are:
// SYNC_FILEAS_FIRSTLAST - fileas will be "Firstname Lastname"
// SYNC_FILEAS_LASTFIRST - fileas will be "Lastname, Firstname"
// SYNC_FILEAS_COMPANYONLY - fileas will be "Company"
// SYNC_FILEAS_COMPANYLAST - fileas will be "Company (Lastname, Firstname)"
// SYNC_FILEAS_COMPANYFIRST - fileas will be "Company (Firstname Lastname)"
// SYNC_FILEAS_LASTCOMPANY - fileas will be "Lastname, Firstname (Company)"
// SYNC_FILEAS_FIRSTCOMPANY - fileas will be "Firstname Lastname (Company)"
//
// The company-fileas will only be set if a contact has a company set. If one of
// company-fileas is selected and a contact doesn't have a company set, it will default
// to SYNC_FILEAS_FIRSTLAST or SYNC_FILEAS_LASTFIRST (depending on if last or first
// option is selected for company).
// If SYNC_FILEAS_COMPANYONLY is selected and company of the contact is not set
// SYNC_FILEAS_LASTFIRST will be used
define('FILEAS_ORDER', SYNC_FILEAS_LASTFIRST);
#!/usr/bin/env php
<?php
/***********************************************
* File : gab2contacts.php
* Project : Z-Push - tools - GAB2Contacts
* Descr : Copies the GAB into a contact folder and can be used to keep them updated.
*
* Created : 20.07.2016
*
* Copyright 2016 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.
*
* 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
* ************************************************/
// Path to the Z-Push directory relative to the gab2contacts script.
// The path set by default is as required for a GIT checkout.
define('PATH_TO_ZPUSH', '../../src/');
/************************************************
* MAIN
*/
define('BASE_PATH_CLI', dirname(__FILE__) ."/");
set_include_path(get_include_path() . PATH_SEPARATOR . BASE_PATH_CLI . PATH_SEPARATOR . PATH_TO_ZPUSH);
include_once("vendor/autoload.php");
if (!defined('CONTACT_CONFIG')) define('CONTACT_CONFIG', 'config.php');
include_once(CONTACT_CONFIG);
try {
GAB2ContactsCLI::CheckEnv();
GAB2ContactsCLI::CheckOptions();
if (! GAB2ContactsCLI::SureWhatToDo()) {
// show error message if available
if (GAB2ContactsCLI::GetErrorMessage())
fwrite(STDERR, GAB2ContactsCLI::GetErrorMessage() . PHP_EOL.PHP_EOL);
echo GAB2ContactsCLI::UsageInstructions();
exit(1);
}
else if (!GAB2ContactsCLI::SetupContactWorker()) {
fwrite(STDERR, GAB2ContactsCLI::GetErrorMessage() . PHP_EOL);
exit(1);
}
GAB2ContactsCLI::RunCommand();
}
catch (Exception $ex) {
fwrite(STDERR, get_class($ex) . ": ". $ex->getMessage() . PHP_EOL);
exit(1);
}
/************************************************
* GAB2Contacts CLI
*/
class GAB2ContactsCLI {
const COMMAND_SYNC = 1;
const COMMAND_DELETE = 2;
static private $contactWorker;
static private $command;
static private $sourceGAB;
static private $errormessage;
/**
* Returns usage instructions.
*
* @access public
* @return string
*/
static public function UsageInstructions() {
return "Usage:" .PHP_EOL.
"\tgab2contact.php -a ACTION [options]" .PHP_EOL.PHP_EOL.
"Parameters:" .PHP_EOL.
"\t-a sync | delete" .PHP_EOL.PHP_EOL.
"Actions:" .PHP_EOL.
"\tsync\t Synchronizes all data from the GAB to the target contact folder" .PHP_EOL.
"\tdelete\t Removes all previously created contacts in the target contact folder." .PHP_EOL.
PHP_EOL;
}
/**
* Setup of the ContactWorker implementation.
*
* @access public
* @return boolean
*/
static public function SetupContactWorker() {
$file = "lib/" .strtolower(CONTACTWORKER).".php";
include_once($file);
if (!class_exists(CONTACTWORKER)) {
self::$errormessage = "ContactWorker file loaded, but class '".CONTACTWORKER."' can not be found. Check your configuration or implementation.";
}
else {
self::$sourceGAB = @constant('SOURCE_GAB');
$s = @constant('CONTACTWORKER');
self::$contactWorker = new $s();
return true;
}
return false;
}
/**
* Checks the environment.
*
* @access public
* @return void
*/
static public function CheckEnv() {
if (php_sapi_name() != "cli")
self::$errormessage = "This script can only be called from the CLI.";
if (!function_exists("getopt"))
self::$errormessage = "PHP Function getopt not found. Please check your PHP version and settings.";
if (!defined('CONTACT_FOLDERID') || CONTACT_FOLDERID == "")
self::$errormessage = "No value set for 'CONTACT_FOLDERID'. Please check your configuration.";
}
/**
* Checks the options from the command line.
*
* @access public
* @return void
*/
static public function CheckOptions() {
if (self::$errormessage)
return;
$options = getopt("a:");
// get 'action'
$action = false;
if (isset($options['a']) && !empty($options['a']))
$action = strtolower(trim($options['a']));
elseif (isset($options['action']) && !empty($options['action']))
$action = strtolower(trim($options['action']));
// get a command for the requested action
switch ($action) {
// sync!
case "sync":
self::$command = self::COMMAND_SYNC;
break;
// delete
case "delete":
self::$command = self::COMMAND_DELETE;
break;
default:
self::UsageInstructions();
}
}
/**
* Indicates if the options from the command line
* could be processed correctly.
*
* @access public
* @return boolean
*/
static public function SureWhatToDo() {
return isset(self::$command);
}
/**
* Returns a errormessage of things which could have gone wrong.
*
* @access public
* @return string
*/
static public function GetErrorMessage() {
return (isset(self::$errormessage))?self::$errormessage:"";
}
/**
* Runs a command requested from an action of the command line.
*
* @access public
* @return void
*/
static public function RunCommand() {
switch(self::$command) {
case self::COMMAND_SYNC:
self::$contactWorker->Sync(self::$sourceGAB);
break;
case self::COMMAND_DELETE:
echo "Are you sure you want to remove all contacts of GAB folder in the target folder? [y/N]: ";
$confirm = strtolower(trim(fgets(STDIN)));
if ( $confirm === 'y' || $confirm === 'yes')
self::$contactWorker->Delete(self::$sourceGAB);
else
echo "Aborted!".PHP_EOL;
break;
}
echo PHP_EOL;
}
/**
* Returns the Worker object.
*
* @access public
* @return ContactWorker implementation
*/
static public function GetWorker() {
return self::$contactWorker;
}
}
\ No newline at end of file
<?php
/***********************************************
* File : contactworker.php
* Project : Z-Push - tools - GAB2Contacts
* Descr : Main contact synchronization class.
*
* Created : 20.07.2016
*
* Copyright 2016 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.
*
* 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
* ************************************************/
abstract class ContactWorker {
/**
* Constructor
*/
public function __construct() {
}
/**
* Performs the synchronization.
* - finds the correct GAB
* - gets all GAB entries
* - decides if it has to create/update/delete them
*
* @access public
* @return void
*/
public function Sync($sourceGAB = 'default') {
$targetFolderId = CONTACT_FOLDERID;
// gets a list of GABs
$gabs = $this->GetGABs();
if (empty($gabs) || $sourceGAB == 'default') {
// no multi-GABs, just go default
$this->doSync($targetFolderId, null, 'default');
}
else {
$found = false;
foreach($gabs as $gabName => $gabId) {
if (!$sourceGAB || $sourceGAB == $gabName || $sourceGAB == $gabId) {
$this->doSync($targetFolderId, $gabId, $gabName);
$found = true;
break;
}
}
if (!$found) {
$this->Terminate(sprintf("Specified GAB '%s' can not be found. Aborting.", $sourceGAB));
}
}
}
/**
* Clears all data from the hidden folder and removes it.
* This will cause a serverside clearing of all user gabs and a synchronization stop.
*
* @param string $targetGab A gab where the data should be cleared. If not set, it's 'default' or all.
*
* @access public
* @return void
*/
public function Delete($sourceGAB = 'default') {
$targetFolderId = CONTACT_FOLDERID;
// gets a list of GABs
$gabs = $this->GetGABs();
if (empty($gabs) || $sourceGAB == 'default') {
// no multi-GABs, just go default
$this->doDelete($targetFolderId, null, 'default');
}
else {
$found = false;
foreach($gabs as $gabName => $gabId) {
if (!$sourceGAB || $sourceGAB == $gabName || $sourceGAB == $gabId) {
$this->doDelete($gabId, $gabName);
$found = true;
break;
}
}
if (!$found) {
$this->Terminate(sprintf("Specified GAB '%s' can not be found. Aborting.", $sourceGAB));
}
}
}
/**
* Logs a message to the command line.
*
* @param string $msg the message
*
* @access protected
* @return void
*/
protected function Log($msg) {
echo $msg . PHP_EOL;
}
/**
* Writes a message to STDERR and terminates the script.
*
* @param string $msg the message
*
* @access protected
* @return void
*/
protected function Terminate($msg) {
fwrite(STDERR, $msg);
echo PHP_EOL.PHP_EOL;
exit(1);
}
/*********************************
* Abstract methods
*********************************/
/**
* Returns a list of Global Address Books with their names and ids.
*
* @access protected
* @return array
*/
protected abstract function getGABs();
/**
* Performs the actual synchronization for a single GAB.
*
* @param string $targetFolderId the id of the folder where the contacts should be stored.
* @param string $gabId the id of the gab to be synchronized. If not set (null) the default gab is synchronized.
* @param string $gabName the name of the gab to be synchronized. If not set (null) the default gab is synchronized.
*
* @access protected
* @return void
*/
protected abstract function doSync($targetFolderId, $gabId = null, $gabName = 'default');
/**
* Deletes all contacts that were created by the script before.
*
* @param string $targetFolderId the id of the folder where the contacts should be deleted.
* @param string $gabId the id of the gab to be synchronized. If not set (null) the default gab is synchronized.
* @param string $gabName the name of the gab to be synchronized. If not set (null) the default gab is synchronized.
*
* @access protected
* @return boolean
*/
protected abstract function doDelete($targetFolderId, $gabId = null, $gabName = 'default');
}
/**
* Overwrite ZLog class to provide basic logging.
* All debug messages are ignored, others are logged.
*/
class ZLog {
static public function Write($level, $msg, $truncate = false) {
if ($level < LOGLEVEL_INFO) {
GAB2ContactsCLI::GetWorker()->Log($msg);
}
}
}
This diff is collapsed.
<?php
/***********************************************
* File : synccontact.php
* Project : Z-Push
* Descr : A simplified version of Z-Pushs SyncContact object.
*
* Created : 05.09.2011
*
* Copyright 2007 - 2016 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.
*
* 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
************************************************/
class SyncContact {
// ContactObject variable MAPI Property Default LDAP parameter
public $accountname; // PR_ACCOUNT username
public $firstname; // PR_GIVEN_NAME givenName
public $lastname; // PR_SURNAME sn
public $officelocation; // PR_OFFICE_LOCATION physicalDeliveryOfficeName
public $companyname; // PR_COMPANY_NAME
public $jobtitle; // PR_TITLE title
public $email1address; // PR_SMTP_ADDRESS Email
public $businessphonenumber; // PR_BUSINESS_TELEPHONE_NUMBER
public $businessfaxnumber; // PR_PRIMARY_FAX_NUMBER Fax
public $businessstreet; // PR_POSTAL_ADDRESS postalAddress
public $businesspostalcode; // PR_BUSINESS_ADDRESS_POSTAL_CODE postalCode
public $businessstate; // PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE st
public $businesscity; // PR_BUSINESS_ADDRESS_CITY location
public $mobilephonenumber; // PR_MOBILE_TELEPHONE_NUMBER mobile
public $homephonenumber; // PR_HOME_TELEPHONE_NUMBER Telephone
public $pagernumber; // PR_BEEPER_TELEPHONE_NUMBER pager
public $picture; // PR_EMS_AB_THUMBNAIL_PHOTO jpegPhoto // needs to be set base64_encoded
public $customerid; // PR_ORGANIZATIONAL_ID_NUMBER employeeNumber
/* Not mappable GAB variables
*
* - PR_BUSINESS_ADDRESS_POST_OFFICE_BOX postBoxOffice
* - PR_INITIALS initials
* - PR_LANGUAGE preferredLanguage
*/
// hash of the object
public $hash;
// untouched SyncObject variables
public $anniversary;
public $assistantname;
public $assistnamephonenumber;
public $birthday;
public $body;
public $bodysize;
public $bodytruncated;
public $business2phonenumber;
public $businesscountry;
public $carphonenumber;
public $children;
public $email2address;
public $email3address;
public $fileas;
public $home2phonenumber;
public $homecity;
public $homecountry;
public $homepostalcode;
public $homestate;
public $homestreet;
public $homefaxnumber;
public $title;
public $middlename;
public $othercity;
public $othercountry;
public $otherpostalcode;
public $otherstate;
public $otherstreet;
public $radiophonenumber;
public $spouse;
public $suffix;
public $webpage;
public $yomicompanyname;
public $yomifirstname;
public $yomilastname;
public $rtf;
public $categories;
public $governmentid;
public $imaddress;
public $imaddress2;
public $imaddress3;
public $managername;
public $companymainphone;
public $nickname;
public $mms;
public $asbody;
/**
* Returns a hash of the data mapped from the GAB.
*
* @access public
* @return string
*/
public function GetHash() {
if (!isset($this->hash) || $this->hash == "") {
$this->hash = md5(serialize($this));
}
return $this->hash;
}
/**
* Returns the properties which have to be unset on the server.
*
* @access public
* @return array
*/
public function getUnsetVars() {
return array();
}
}
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