From 862303712a43f93d8adec384c8149a1345ea0f98 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 31 Jul 2010 11:35:43 -0400 Subject: [PATCH] Add ability to reset all activesync device policykeys at once. Useful for chaning server policies, and forcing all devices to update to the new policy. Also, add some notifications, and use Horde_Url::redirect(); --- .../ActiveSync/lib/Horde/ActiveSync/State/Base.php | 10 ++++++++++ .../ActiveSync/lib/Horde/ActiveSync/State/File.php | 13 ++++++++++++ .../lib/Horde/ActiveSync/State/History.php | 18 +++++++++++++++++ horde/admin/activesync.php | 23 ++++++++++++++++++++-- horde/js/activesyncadmin.js | 6 ++++++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php index dd7c84fb3..1f05d37ea 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php @@ -541,6 +541,16 @@ abstract class Horde_ActiveSync_State_Base abstract public function setPolicyKey($devId, $key); /** + * Reset ALL device policy keys. Used when server policies have changed + * and you want to force ALL devices to pick up the changes. This will + * cause all devices that support provisioning to be reprovisioned. + * + * @throws Horde_ActiveSync_Exception + * + */ + abstract public function resetAllPolicyKeys(); + + /** * Set a new remotewipe status for the device * * @param string $devid diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php index 31360cb04..3b2a778de 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php @@ -512,6 +512,19 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base } /** + * Reset ALL device policy keys. Used when server policies have changed + * and you want to force ALL devices to pick up the changes. This will + * cause all devices that support provisioning to be reprovisioned. + * + * @throws Horde_ActiveSync_Exception + * + */ + public function resetAllPolicyKeys() + { + throw new Horde_ActiveSync_Exception('Not Implemented'); + } + + /** * Set a new remotewipe status for the device * * @param string $devId diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php index f404f8b9e..66e54328d 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php @@ -773,6 +773,24 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base } /** + * Reset ALL device policy keys. Used when server policies have changed + * and you want to force ALL devices to pick up the changes. This will + * cause all devices that support provisioning to be reprovisioned. + * + * @throws Horde_ActiveSync_Exception + * + */ + public function resetAllPolicyKeys() + { + $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_policykey = 0'; + try { + $this->_db->update($query); + } catch (Horde_Db_Exception $e) { + throw new Horde_ActiveSync_Exception($e); + } + } + + /** * Set a new remotewipe status for the device * * @param string $devid diff --git a/horde/admin/activesync.php b/horde/admin/activesync.php index 231c00b36..e1a93c5aa 100644 --- a/horde/admin/activesync.php +++ b/horde/admin/activesync.php @@ -28,18 +28,26 @@ if ($actionID = Horde_Util::getPost('actionID')) { switch ($actionID) { case 'wipe': $stateMachine->setDeviceRWStatus($deviceID, Horde_ActiveSync::RWSTATUS_PENDING); + $GLOBALS['notification']->push(_("A device wipe has been requested. Device will be wiped on next syncronization attempt."), 'horde.success'); break; case 'cancelwipe': $stateMachine->setDeviceRWStatus($deviceID, Horde_ActiveSync::RWSTATUS_OK); + $GLOBALS['notification']->push(_("Device wipe successfully canceled."), 'horde.success'); break; case 'delete': $stateMachine->removeState(null, $deviceID, Horde_Util::getPost('uid')); + $GLOBALS['notification']->push(_("Device successfully removed."), 'horde.success'); + break; + + case 'reset': + $stateMachine->resetAllPolicyKeys(); + $GLOBALS['notification']->push(_("All policy keys successfully reset."), 'horde.success'); break; } - header('Location: ' . Horde::selfUrl()); + Horde::selfUrl()->redirect(); } Horde::addScriptFile('activesyncadmin.js'); @@ -75,12 +83,23 @@ $tree->setHeader(array( array('html' => $spacer), array('width' => '10%', 'html' => _("Actions")) )); -$tree->addNode('root', null, _("Registered User Devices"), 0, true, $base_node_params); + +/* Root tree node, and reprovision button */ +$tree->addNode('root', + null, + _("Registered User Devices"), + 0, + true, + $base_node_params, + array('--', $spacer, '--', $spacer, '--', $spacer, '--', $spacer, '' )); /* To hold the inline javascript */ $js = array(); $i = 0; +/* Observe the reprovision button */ +$js[] = '$("reset").observe("click", function() {HordeActiveSyncAdmin.reprovision();});'; + /* Build the device entry */ foreach ($devices as $device) { $node_params = array(); diff --git a/horde/js/activesyncadmin.js b/horde/js/activesyncadmin.js index bf82ea50b..8102617e5 100644 --- a/horde/js/activesyncadmin.js +++ b/horde/js/activesyncadmin.js @@ -23,5 +23,11 @@ var HordeActiveSyncAdmin = { document.forms.activesyncadmin.uid.value = user; document.forms.activesyncadmin.actionID.value = 'delete'; document.forms.activesyncadmin.submit(); + }, + + reprovision: function() { + document.forms.activesyncadmin.actionID.value = 'reset'; + document.forms.activesyncadmin.submit(); } + } \ No newline at end of file -- 2.11.0