Commit deb24ded authored by Manfred Kutas's avatar Manfred Kutas

ZP-77 Changed loading of SyncProvisioning object. Added function to

Streamer to return variable names of mapping.

Released under the Affero GNU General Public License (AGPL) version 3.
parent ad071de1
......@@ -230,19 +230,15 @@ class DeviceManager {
}
$policyHash = SyncProvisioning::GetInstance()->GetPolicyHash();
if (empty($policyHash)) {
$policies = $this->getProvisioningPolicies();
SyncProvisioning::GetInstance()->Load($policies);
$policyHash = SyncProvisioning::GetInstance()->GetPolicyHash();
}
$policyHash = SyncProvisioning::GetObjectWithPolicies($this->getProvisioningPolicies())->GetPolicyHash();
$p = ( ($this->device->GetWipeStatus() != SYNC_PROVISION_RWSTATUS_NA && $policykey != $this->device->GetPolicyKey()) ||
(Request::WasPolicyKeySent() && $this->device->GetPolicyKey() == ASDevice::UNDEFINED) ||
$this->device->getPolicyhash() != $policyHash);
if (!$noDebug || $p)
ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->ProvisioningRequired('%s') saved device key '%s': %s", $policykey, $this->device->GetPolicyKey(), Utils::PrintAsString($p)));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->ProvisioningRequired('%s') saved device key '%s', policyHash '%s', saved device policy hash '%s' : %s",
$policykey, $this->device->GetPolicyKey(), $policyHash, $this->device->getPolicyhash(), Utils::PrintAsString($p)));
return $p;
}
......@@ -276,11 +272,8 @@ class DeviceManager {
* @return SyncProvisioning
*/
public function GetProvisioningObject() {
$p = SyncProvisioning::GetInstance();
$p = SyncProvisioning::GetObjectWithPolicies($this->getProvisioningPolicies());
$policies = $this->getProvisioningPolicies();
$p->Load($policies);
unset($policies);
// save policies' hash and name
$this->device->SetPolicyname($this->getPolicyName());
$this->device->SetPolicyhash($p->GetPolicyHash());
......
......@@ -12,7 +12,7 @@
*
* Created : 01.10.2007
*
* Copyright 2007 - 2015 Zarafa Deutschland GmbH
* 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,
......@@ -82,7 +82,7 @@ class Streamer implements Serializable {
/**
* Return the streamer mapping for this object
* Return the streamer mapping for this object
*
* @access public
*/
......@@ -421,6 +421,20 @@ class Streamer implements Serializable {
return true;
}
/**
* Returns SyncObject's streamer variable names.
*
* @access public
* @return multitype:array
*/
public function GetStreamerVars() {
$streamerVars = array();
foreach ($this->mapping as $v) {
$streamerVars[] = $v[self::STREAMER_VAR];
}
return $streamerVars;
}
/**----------------------------------------------------------------------------------------------------------
* Private methods for conversion
*/
......
......@@ -94,9 +94,6 @@ class SyncProvisioning extends SyncObject {
public $unapprovedinromapplist;
public $approvedapplist;
private static $instace;
private $policyHash;
function SyncProvisioning() {
$mapping = array (
SYNC_PROVISION_DEVPWENABLED => array ( self::STREAMER_VAR => "devpwenabled",
......@@ -239,23 +236,17 @@ class SyncProvisioning extends SyncObject {
}
public function Load($policies = array()) {
// always load default policies because there might be some policy missing in the policies.ini
$defaultPolicies = Utils::GetDefaultPolices();
// Join the policies. Loaded policies have precedence over default policies.
$finalPolicies = $policies + $defaultPolicies;
$objectsVars = get_object_vars($this);
foreach ($finalPolicies as $p=>$v) {
if (!array_key_exists($p, $objectsVars)) {
$this->LoadDefaultPolicies();
$streamerVars = $this->GetStreamerVars();
foreach ($policies as $p=>$v) {
if (!in_array($p, $streamerVars)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("Policy '%s' not supported by the device, ignoring", $p));
unset($finalPolicies[$p]);
continue;
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Policy '%s' enforced with: %s (%s)", $p, (is_array($v)) ? Utils::PrintAsString(implode(',', $v)) : Utils::PrintAsString($v), gettype($v)));
ZLog::Write(LOGLEVEL_WBXML, sprintf("Policy '%s' enforced with: %s (%s)", $p, (is_array($v)) ? Utils::PrintAsString(implode(',', $v)) : Utils::PrintAsString($v), gettype($v)));
$this->$p = (is_array($v) && empty($v)) ? array() : $v;
}
self::GetInstance()->SetPolicyHash(md5(serialize($finalPolicies)));
}
public function LoadDefaultPolicies() {
......@@ -307,18 +298,6 @@ class SyncProvisioning extends SyncObject {
$this->approvedapplist = array();
}
/**
* Sets the policy hash.
*
* @param string $hash
*
* @access public
* @return void
*/
public function SetPolicyHash($hash) {
$this->policyHash = $hash;
}
/**
* Returns the policy hash.
*
......@@ -326,7 +305,7 @@ class SyncProvisioning extends SyncObject {
* @return string
*/
public function GetPolicyHash() {
return $this->policyHash;
return md5(serialize($this));
}
/**
......@@ -335,11 +314,9 @@ class SyncProvisioning extends SyncObject {
* @access public
* @return SyncProvisioning
*/
public static function GetInstance() {
if (!self::$instace)
{
self::$instace = new SyncProvisioning();
}
return self::$instace;
public static function GetObjectWithPolicies($policies = array()) {
$p = new SyncProvisioning();
$p->Load($policies);
return $p;
}
}
......@@ -972,64 +972,6 @@ class Utils {
return sprintf ("%.{$precision}f %s", $pow, $units[$fBase]);
}
/**
* Returns the default policies.
*
* @access public
* @return array
*/
public static function GetDefaultPolices() {
return array(
//AS 12.0 and above properties
'devpwenabled' => 0,
'alphanumpwreq' => 0,
'devencenabled' => 0,
'pwrecoveryenabled' => 0,
'docbrowseenabled' => null,
'attenabled' => 1,
'mindevpwlenngth' => 4,
'maxinacttimedevlock' => 900,
'maxdevpwfailedattempts' => 8,
'maxattsize' => '',
'allowsimpledevpw' => 1,
'devpwexpiration' => 0,
'devpwhistory' => 0,
//AS 12.1 and above properties
'allowstoragecard' => 1,
'allowcam' => 1,
'reqdevenc' => 0,
'allowunsignedapps' => 1,
'allowunsigninstallpacks' => 1,
'mindevcomplexchars' => 3,
'allowwifi' => 1,
'allowtextmessaging' => 1,
'allowpopimapemail' => 1,
'allowbluetooth' => 2,
'allowirda' => 1,
'reqmansyncroam' => 0,
'allowdesktopsync' => 1,
'maxcalagefilter' => 0,
'allowhtmlemail' => 1,
'maxemailagefilter' => 0,
'maxemailbodytruncsize' => -1,
'maxemailhtmlbodytruncsize' => -1,
'reqsignedsmimemessages' => 0,
'reqencsmimemessages' => 0,
'reqsignedsmimealgorithm' => 0,
'reqencsmimealgorithm' => 0,
'allowsmimeencalgneg' => 2,
'allowsmimesoftcerts' => 1,
'allowbrowser' => 1,
'allowconsumeremail' => 1,
'allowremotedesk' => 1,
'allowinternetsharing' => 1,
'unapprovedinromapplist' => array(),
'approvedapplist' => array(),
);
}
}
// TODO Win1252/UTF8 functions are deprecated and will be removed sometime
......
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