Add ability to reset all activesync device policykeys at once.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jul 2010 15:35:43 +0000 (11:35 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jul 2010 15:35:43 +0000 (11:35 -0400)
Useful for chaning server policies, and forcing all devices to update to the new policy.
Also, add some notifications, and use Horde_Url::redirect();

framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php
framework/ActiveSync/lib/Horde/ActiveSync/State/File.php
framework/ActiveSync/lib/Horde/ActiveSync/State/History.php
horde/admin/activesync.php
horde/js/activesyncadmin.js

index dd7c84f..1f05d37 100644 (file)
@@ -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
index 31360cb..3b2a778 100644 (file)
@@ -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
index f404f8b..66e5432 100644 (file)
@@ -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
index 231c00b..e1a93c5 100644 (file)
@@ -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, '<input class="button" type="button" value="' . _("Reprovision All Devices") . '" id="reset" />' ));
 
 /* 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();
index bf82ea5..8102617 100644 (file)
@@ -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