From: Michael J. Rubinsky Date: Sat, 1 May 2010 14:04:54 +0000 (-0400) Subject: Complete implementation of ActiveSync user device management. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8269eda25d9529726b3a65a36dc6950f5abc46ca;p=horde.git Complete implementation of ActiveSync user device management. Users can view device status, request a remote wipe of provisioned devices, remove partnerships, or reset all activesync data... --- diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php index 324eb0249..373390f5b 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php @@ -745,9 +745,18 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base $this->getDeviceInfo($devId); } - $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_rwstatus = ? WHERE device_id = ?'; + $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_rwstatus = ?'; + $values = array($status); + + if ($status == Horde_ActiveSync::RWSTATUS_PENDING) { + /* Need to clear the policykey to force a provision */ + $query .= ',device_policykey = ?'; + $values[] = 0; + } + $query .= ' WHERE device_id = ?'; + $values[] = $devId; try { - $this->_db->update($query, array($status, $devId)); + $this->_db->update($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -781,7 +790,7 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base try { $this->_db->delete($state_query, $values); $this->_db->delete($map_query, $values); - if ($device_query) { + if (!empty($device_query)) { $this->_db->delete($device_query, $values); } } catch (Horde_Db_Exception $e) { diff --git a/horde/js/activesyncprefs.js b/horde/js/activesyncprefs.js new file mode 100644 index 000000000..0b06328cb --- /dev/null +++ b/horde/js/activesyncprefs.js @@ -0,0 +1,26 @@ +/** + * Provides the javascript for managing activesync partner devices. + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + */ +var HordeActiveSyncPrefs = { + + requestRemoteWipe: function(device) { + $('wipeid').setValue(device); + document.forms.prefs.actionID = 'update_special'; + document.forms.prefs.submit(); + }, + + cancelRemoteWipe: function(device) { + $('cancelwipe').setValue(device); + document.forms.prefs.actionID = 'update_special'; + document.forms.prefs.submit(); + }, + + removeDevice: function(device) { + $('removedevice').setValue(device); + document.forms.prefs.actionID = 'update_special'; + document.forms.prefs.submit(); + } +} \ No newline at end of file diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index c02a5a498..33fc97633 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -401,10 +401,11 @@ class Horde_Prefs_Ui } else { return _("ActiveSync not activated."); } - + Horde::addScriptFile('activesyncprefs.js', 'horde'); $t = $GLOBALS['injector']->createInstance('Horde_Template'); $t->setOption('gettext', true); - $t->set('reset', $ui->selfUrl()->add('reset', 1)); + $selfurl = $ui->selfUrl(); + $t->set('reset', $selfurl->copy()->add('reset', 1)); $devices = $stateMachine->listDevices(Horde_Auth::getAuth()); $devs = array(); $i = 1; @@ -415,6 +416,7 @@ class Horde_Prefs_Ui switch ($device['device_rwstatus']) { case Horde_ActiveSync::RWSTATUS_PENDING: $status = '' . _("Wipe is pending") . ''; + $device['ispending'] = true; break; case Horde_ActiveSync::RWSTATUS_WIPED: $status = '' . _("Device is wiped") . ''; @@ -422,6 +424,8 @@ class Horde_Prefs_Ui default: $status = $device['device_policykey'] ?_("Provisioned") : _("Not Provisioned"); } + $device['wipe'] = $selfurl->copy()->add(array('wipe' => $device['device_id'])); + $device['remove'] = $selfurl->copy()->add(array('remove' => $device['device_id'])); $device['status'] = $status . '
' . _("Device id:") . $device['device_id'] . '
' . _("Policy Key:") . $device['device_policykey'] . '
' . _("User Agent:") . $device['device_agent']; $devs[] = $device; } @@ -564,21 +568,27 @@ class Horde_Prefs_Ui * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - protected function _updateActiveSyncManagement($ui) - { + protected function _updateActiveSyncManagement($ui) + { $state_params = $GLOBALS['conf']['activesync']['state']['params']; $state_params['db'] = $GLOBALS['injector']->getInstance('Horde_Db_Adapter_Base'); $stateMachine = new Horde_ActiveSync_State_History($state_params); $stateMachine->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger')); - if ($ui->vars->wipe) { - $stateMachine->setDeviceRWStatus($ui->vars->wipe, Horde_ActiveSync::RWSTATUS_PENDING); + if ($ui->vars->wipeid) { + $stateMachine->setDeviceRWStatus($ui->vars->wipeid, Horde_ActiveSync::RWSTATUS_PENDING); $GLOBALS['notification']->push(sprintf(_("A Remote Wipe for device id %s has been initiated. The device will be wiped during the next SYNC request."), $ui->vars->wipe)); + } elseif ($ui->vars->cancelwipe) { + $stateMachine->setDeviceRWStatus($ui->vars->cancelwipe, Horde_ActiveSync::RWSTATUS_OK); + $GLOBALS['notification']->push(sprintf(_("The Remote Wipe for device id %s has been cancelled."), $ui->vars->wipe)); } elseif ($ui->vars->reset) { $devices = $stateMachine->listDevices(Horde_Auth::getAuth()); foreach ($devices as $device) { $stateMachine->removeState(null, $device['device_id']); } $GLOBALS['notification']->push(_("All state removed for your devices. They will resynchronize next time they connect to the server.")); + } elseif ($ui->vars->removedevice) { + $stateMachine->removeState(null, $ui->vars->removedevice); } - } + } + } diff --git a/horde/templates/prefs/activesync.html b/horde/templates/prefs/activesync.html index e6fc2c251..364475c1a 100644 --- a/horde/templates/prefs/activesync.html +++ b/horde/templates/prefs/activesync.html @@ -6,21 +6,26 @@ Device Management + + - + - - - - - - +
Select for wipe Device Last Sync Time Status
Not Provisioned + + + + + + + +