IMP_Compose::getHmac PHP Method

getHmac() public method

Generate HMAC hash used to validate data on a session expiration. Uses the unique compose cache ID of the expired message, the username, and the secret key of the server to generate a reproducible value that can be validated if session data doesn't exist.
public getHmac ( string $cacheid = null, string $user = null ) : string
$cacheid string The cache ID to use. If null, uses cache ID of the compose object.
$user string The user ID to use. If null, uses the current authenticated username.
return string The HMAC hash string.
    public function getHmac($cacheid = null, $user = null)
    {
        global $conf, $registry;
        return hash_hmac('sha1', (is_null($cacheid) ? $this->getCacheId() : $cacheid) . '|' . (is_null($user) ? $registry->getAuth() : $user), $conf['secret_key']);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Generates AJAX response task data from the queue.
  *
  * For compose autocomplete address error data (key: 'compose-addr'), an
  * array with keys as the autocomplete DOM element and the values as
  * arrays. The value arrays have keys as the autocomplete address ID, and
  * the value is a space-separated list of classnames to add.
  *
  * For compose attachment data (key: 'compose-atc'), an array of objects
  * with these properties:
  *   - icon: (string) Data url string containing icon information.
  *   - name: (string) The attachment name
  *   - num: (integer) The current attachment number
  *   - size: (string) The size of the attachment
  *   - type: (string) The MIME type of the attachment
  *   - view: (boolean) Link to attachment preivew page
  *
  * For compose cacheid data (key: 'compose'), an object with these
  * properties:
  *   - atclimit: (integer) If set, no further attachments are allowed.
  *   - cacheid: (string) Current cache ID of the compose message.
  *
  * For flag data (key: 'flag'), an array of objects with these properties:
  *   - add: (array) The list of flags that were added.
  *   - buids: (string) Indices of the messages that have changed (IMAP
  *            sequence string; mboxes are base64url encoded).
  *   - remove: (array) The list of flags that were removed.
  *   - replace: (array) Replace the flag list with these flags.
  *
  * For flag configuration data (key: 'flag-config'), an array containing
  * flag data. All flags returned in dynamic mode; only flags labeled below
  * as [sm] are returned in smartmobile mode:
  *   - a: (boolean) Indicates a flag that can be *a*ltered.
  *   - b: (string) Background color [sm].
  *   - c: (string) CSS class.
  *   - f: (string) Foreground color [sm].
  *   - i: (string) CSS icon [sm].
  *   - id: (string) Flag ID (IMAP flag id).
  *   - l: (string) Flag label [sm].
  *   - s: (boolean) Indicates a flag that can be *s*earched for [sm].
  *   - u: (boolean) Indicates a *u*ser flag.
  *
  * For mailbox data (key: 'mailbox'), an array with these keys:
  *   - a: (array) Mailboxes that were added (base64url encoded).
  *   - all: (integer) TODO
  *   - base: (string) TODO
  *   - c: (array) Mailboxes that were changed (base64url encoded).
  *   - d: (array) Mailboxes that were deleted (base64url encoded).
  *   - expand: (integer) Expand subfolders on load.
  *   - switch: (string) Load this mailbox (base64url encoded).
  *
  * For maillog data (key: 'maillog'), an object with these properties:
  *   - buid: (integer) BUID.
  *   - log: (array) List of log entries.
  *   - mbox: (string) Mailbox.
  *
  * For message preview data (key: 'message'), an object with these
  * properties:
  *   - buid: (integer) BUID.
  *   - data: (object) Message viewport data.
  *   - mbox: (string) Mailbox.
  *
  * For poll data (key: 'poll'), an array with keys as base64url encoded
  * mailbox names, values as the number of unseen messages.
  *
  * For quota data (key: 'quota'), an array with these keys:
  *   - m: (string) Quota message.
  *   - p: (integer) Quota percentage.
  *
  * @param IMP_Ajax_Application $ajax  The AJAX object.
  */
 public function add(IMP_Ajax_Application $ajax)
 {
     global $injector;
     /* Add autocomplete address error information. */
     if (!empty($this->_addr)) {
         $ajax->addTask('compose-addr', $this->_addr);
         $this->_addr = array();
     }
     /* Add compose attachment information. */
     if (!empty($this->_atc)) {
         $ajax->addTask('compose-atc', $this->_atc);
         $this->_atc = array();
     }
     /* Add compose information. */
     if (!is_null($this->_compose)) {
         $compose = new stdClass();
         if (!$this->_compose->additionalAttachmentsAllowed()) {
             $compose->atclimit = 1;
         }
         $compose->cacheid = $this->_compose->getCacheId();
         $compose->hmac = $this->_compose->getHmac();
         $ajax->addTask('compose', $compose);
         $this->_compose = null;
     }
     /* Add flag information. */
     if (!empty($this->_flag)) {
         $ajax->addTask('flag', array_unique($this->_flag, SORT_REGULAR));
         $this->_flag = array();
     }
     /* Add flag configuration. */
     switch ($this->_flagconfig) {
         case Horde_Registry::VIEW_DYNAMIC:
         case Horde_Registry::VIEW_SMARTMOBILE:
             $flags = array();
             foreach ($injector->getInstance('IMP_Flags')->getList() as $val) {
                 $tmp = array('b' => $val->bgdefault ? null : $val->bgcolor, 'f' => $val->fgcolor, 'id' => $val->id, 'l' => $val->label, 's' => intval($val instanceof IMP_Flag_Imap));
                 if ($this->_flagconfig === Horde_Registry::VIEW_DYNAMIC) {
                     $tmp += array('a' => $val->canset, 'c' => $val->css, 'i' => $val->css ? null : $val->cssicon, 'u' => intval($val instanceof IMP_Flag_User));
                 }
                 $flags[] = array_filter($tmp);
             }
             $ajax->addTask('flag-config', $flags);
             break;
     }
     /* Add folder tree information. */
     $this->_addFtreeInfo($ajax);
     /* Add maillog information. */
     $this->_addMaillogInfo($ajax);
     /* Add message information. */
     if (!empty($this->_messages)) {
         $ajax->addTask('message', $this->_messages);
         $this->_messages = array();
     }
     /* Add poll information. */
     $poll = $poll_list = array();
     if (!empty($this->_poll)) {
         foreach ($this->_poll as $val) {
             $poll_list[strval($val)] = 1;
         }
     }
     if (count($poll_list)) {
         $imap_ob = $injector->getInstance('IMP_Factory_Imap')->create();
         if ($imap_ob->init) {
             try {
                 foreach ($imap_ob->status(array_keys($poll_list), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
                     $poll[IMP_Mailbox::formTo($key)] = intval($val['unseen']);
                 }
             } catch (Exception $e) {
                 // Ignore errors in status() calls.
             }
         }
         if (!empty($poll)) {
             $ajax->addTask('poll', $poll);
             $this->_poll = array();
         }
     }
     /* Add quota information. */
     if ($this->_quota && ($quotadata = $injector->getInstance('IMP_Quota_Ui')->quota($this->_quota[0], $this->_quota[1]))) {
         $ajax->addTask('quota', array('m' => $quotadata['message'], 'p' => round($quotadata['percent']), 'l' => $quotadata['percent'] >= 90 ? 'alert' : ($quotadata['percent'] >= 75 ? 'warn' : '')));
         $this->_quota = false;
     }
 }