From: Michael J. Rubinsky Date: Wed, 12 May 2010 18:27:02 +0000 (-0400) Subject: Add wipe and remove actions to the activesync adminstration screen X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0dec72b31cd515965182bb33edad467dff007db7;p=horde.git Add wipe and remove actions to the activesync adminstration screen --- diff --git a/horde/admin/activesync.php b/horde/admin/activesync.php index e67e63ad9..21bf97dcd 100644 --- a/horde/admin/activesync.php +++ b/horde/admin/activesync.php @@ -13,6 +13,35 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('admin' => true)); +/** Check for any actions **/ +$actionID = Horde_Util::getPost('actionID'); +if ($actionID) { + $deviceID = Horde_Util::getPost('deviceID'); + + /* Get the state machine */ + $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')); + + switch ($actionID) { + case 'wipe': + $stateMachine->setDeviceRWStatus($deviceID, Horde_ActiveSync::RWSTATUS_PENDING); + break; + + case 'cancelwipe': + $stateMachine->setDeviceRWStatus($deviceID, Horde_ActiveSync::RWSTATUS_OK); + break; + + case 'delete': + $stateMachine->removeState(null, $deviceID, Horde_Util::getPost('uid')); + break; + } + + header('Location: ' . Horde::selfUrl()); +} + +Horde::addScriptFile('activesyncadmin.js'); if (!empty($GLOBALS['conf']['activesync']['enabled'])) { $state_params = $GLOBALS['conf']['activesync']['state']['params']; $state_params['db'] = $GLOBALS['injector']->getInstance('Horde_Db_Adapter_Base'); @@ -26,43 +55,90 @@ $devices = $stateMachine->listDevices(); $title = _("ActiveSync Device Administration"); require HORDE_TEMPLATES . '/common-header.inc'; require HORDE_TEMPLATES . '/admin/menu.inc'; - +?> +
+ + + + Horde_Themes::img()); $base_node_params = $icondir + array('icon' => 'administration.png'); $device_node = $icondir + array('icon' => 'mobile.png'); $user_node = $icondir + array('icon' => 'user.png'); - $users = array(); $tree = Horde_Tree::factory('admin_devices', 'Javascript'); $tree->setOption(array('alternate' => true)); -$tree->setHeader(array(array('width' => '40%'), - array('width' => '10%', 'html' => 'last sync'), - array('html' => $spacer), - array('width' => '10%', 'html' => 'policy key'), - array('html' => $spacer), - array('width' => '10%', 'html' => 'remotewipe status'), - array('html' => $spacer), - array('width' => '15%' , 'html' => 'device id'),)); +$tree->setHeader(array( + array('width' => '20%'), + array('width' => '10%', 'html' => _("Last Sync Time")), + array('html' => $spacer), + array('width' => '10%', 'html' => _("Policy Key")), + array('html' => $spacer), + array('width' => '10%', 'html' => _("Status")), + array('html' => $spacer), + array('width' => '20%' , 'html' => _("Device ID")), + array('html' => $spacer), + array('width' => '15%', 'html' => _("Actions")) + )); $tree->addNode('root', null, _("Registered User Devices"), 0, true, $base_node_params); + +/* To hold the inline javascript */ +$js = array(); +$i = 0; + +/* Build the device entry */ foreach ($devices as $device) { $node_params = array(); if (array_search($device['device_user'], $users) === false) { $users[] = $device['device_user']; $tree->addNode($device['device_user'], 'root', $device['device_user'], 0, true, $user_node); } + + /* Load this device */ $stateMachine->loadDeviceInfo($device['device_id'], $device['device_user']); + + /* Parse the status */ + 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") . ''; + break; + default: + $status = $device['device_policykey'] ?_("Provisioned") : _("Not Provisioned"); + } + + /* Last sync time */ $ts = new Horde_Date($stateMachine->getLastSyncTimestamp($device['device_id'])); + + /* Build the action links */ + $actions = ''; + if ($device['device_policykey']) { + $actions .= ''; + $js[] = '$("wipe' . $i . '").observe("click", function() {HordeActiveSyncAdmin.requestRemoteWipe("' . $device['device_id'] . '");});'; + } elseif ($device['device_rwstatus'] == Horde_ActiveSync::RWSTATUS_PENDING) { + $actions .= ''; + $js[] = '$("cancel' . $i . '").observe("click", function() {HordeActiveSyncAdmin.cancelRemoteWipe("' . $device['device_id'] . '");});'; + } + $i++; + $actions .= ' '; + $js[] = '$("delete' . $i . '").observe("click", function() {HordeActiveSyncAdmin.removeDevice("' . $device['device_id'] . '", "' . $device['device_user'] . '");});'; + + /* Add it */ $tree->addNode($device['device_id'], $device['device_user'], $device['device_type']. ' | ' . $device['device_agent'], 0, true, $device_node + $node_params, - array($ts->format('r'), $spacer, $device['device_policykey'], $spacer, $device['device_rwstatus'], $spacer, $device['device_id'])); + array($ts->format('r'), $spacer, $device['device_policykey'], $spacer, $status, $spacer, $device['device_id'], $spacer, $actions)); } echo '

' . Horde::img('group.png') . ' ' . _("ActiveSync Devices") . '

'; $tree->renderTree(); - +echo '
'; +Horde::addInlineScript($js, 'load'); require HORDE_TEMPLATES . '/common-footer.inc'; diff --git a/horde/js/activesyncadmin.js b/horde/js/activesyncadmin.js new file mode 100644 index 000000000..bf82ea50b --- /dev/null +++ b/horde/js/activesyncadmin.js @@ -0,0 +1,27 @@ +/** + * 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 HordeActiveSyncAdmin = { + + requestRemoteWipe: function(device) { + document.forms.activesyncadmin.deviceID.value = device; + document.forms.activesyncadmin.actionID.value = 'wipe'; + document.forms.activesyncadmin.submit(); + }, + + cancelRemoteWipe: function(device) { + document.forms.activesyncadmin.deviceID.value = device; + document.forms.activesyncadmin.actionID.value = 'cancelwipe'; + document.forms.activesyncadmin.submit(); + }, + + removeDevice: function(device, user) { + document.forms.activesyncadmin.deviceID.value = device; + document.forms.activesyncadmin.uid.value = user; + document.forms.activesyncadmin.actionID.value = 'delete'; + document.forms.activesyncadmin.submit(); + } +} \ No newline at end of file