/** * Receives a support request. */ public function supportAction() { /* Disable view renderer and layout. */ $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout()->disableLayout(); $params = $this->_request->getParams(); /* Try to detect bots auto-submitting the form. Two methods are currently * employed, making sure the user agent starts with 'Mozilla' & making sure * the honeypot field is not set. */ if (isset($params['botsfu']) && $params['botsfu'] != '' || (!isset($params['useragent']) || $params['useragent'] == '' || strpos(trim($params['useragent']), 'Mozilla/') !== 0)) { $this->_logger->warn('Rejecting support message from IP: ' . $this->_getRemoteIP() . ', name: ' . $params['name'] . ', email: ' . $params['email']); echo $this->view->json(array('success' => 'false')); return; } /* Make sure the fields are populated. */ if (!(isset($params['name']) && isset($params['email']) && isset($params['type']) && isset($params['purpose']) && isset($params['feedback']))) { echo $this->view->json(array('success' => 'false')); return; } $this->_logger->info('Received feedback email from ' . $params['name'] . ' (' . $params['email'] . '). ' . 'Feedback type: ' . $params['type'] . '. Purpose of user: '******'purpose'] . '. Feedback: ' . $params['feedback'] . '.'); $mail = new Sahara_Mail(); $mail->setFrom($params['email'], $params['name']); $mail->setSubject('Sahara feedback from ' . $params['name']); /* Feedback email body. */ $body = "#################################################################\n"; $body .= "## Sahara Feedback Received\n"; $body .= "#################################################################\n\n"; $body .= "Time: " . date('r') . "\n\n"; if ($cred = $this->_auth->getIdentity()) { $body .= "## Session Details\n"; $body .= "Credential: {$cred}\n"; try { $session = Sahara_Soap::getSchedServerQueuerClient()->isUserInQueue(array('userQName' => $this->_auth->getIdentity())); $body .= "In Queue: " . ($session->inQueue ? 'true' : 'false') . "\n"; $body .= "In Session: " . ($session->inSession ? 'true' : 'false') . "\n"; if ($session->inQueue) { $body .= "Queued resource ID: " . $session->queuedResouce->resourceID . "\n"; $body .= "Queued resource name: " . $session->queuedResouce->resourceName . "\n"; $body .= "Queued resource type: " . $session->queuedResouce->type . "\n"; } if ($session->inSession) { $body .= "Session resource ID: " . $session->assignedResource->resourceID . "\n"; $body .= "Session resource name: " . $session->assignedResource->resourceName . "\n"; $body .= "Session resource type: " . $session->assignedResource->type . "\n"; } } catch (Exception $ex) { $body .= "Exception when attempting to determine session status with message '" . $ex->getMessage() . "'.\n"; } $body .= "\n"; } $body .= "## Feedback Details\n"; $body .= "From: " . $params['name'] . " <" . $params['email'] . ">\n"; $body .= "Type: " . $params['type'] . "\n"; $body .= "Purpose: " . $params['purpose'] . "\n\n"; $body .= "Feedback:\n "; $body .= $params['feedback'] . "\n\n"; $body .= "## Diagnostics:\n"; $body .= "IP: " . $this->_getRemoteIP() . "\n"; $body .= "User Agent: " . urldecode($params['useragent']) . "\n"; $body .= "Java enabled: " . $params['javaenabled'] . "\n"; $body .= "UTC Offset: " . $params['utcoffset'] . "\n"; if (array_key_exists('navplugins', $params)) { $body .= "Plugins:\n"; $plugins = explode(';', urldecode($params['navplugins'])); foreach ($plugins as $p) { if (strpos($p, '=') === false) { continue; } list($name, $ver) = explode('=', $p, 2); $body .= " * {$name} => {$ver}\n"; } } $body .= "\n#################################################################\n"; $mail->setBody($body); $addresses = $this->_config->feedback->address; if ($addresses instanceof Zend_Config) { foreach ($addresses as $addr) { $mail->addTo($addr); } } else { $mail->addTo($addresses); } try { $mail->send(); } catch (Exception $ex) { $this->_logger->error('Failed to send feedback email. Error message: ' . $ex->getMessage() . ". Message body: {$body}"); } /* Tells validation engine that submission succeeded. */ echo $this->view->json(array('success' => 'true')); }
/** * Send error email to configured error handling reciepts. * * @param array $errors error details */ private function _sendErrorEmail($errors) { if ($this->_config->error->disableMessages) { return; } $request = $errors->request; $exception = $errors->exception; $mail = new Sahara_Mail(); $mail->setFrom($this->_config->email->from->address, $this->_config->email->from->name); $mail->setSubject('Sahara WI fatal error occurred at ' . date('r')); $body = "#################################################################\n"; $body .= "## Sahara Fatal Error\n"; $body .= "#################################################################\n\n"; $body .= "Time: " . date('r') . "\n"; $body .= "Request: " . $request->getRequestUri() . "\n"; $body .= "Params: "; foreach ($request->getParams() as $p => $v) { /* Don't provide the clear text credential. */ $len = strlen($v); if ($p == 'password') { $v = ''; for ($i = 0; $i < $len; $i++) { $v .= '*'; } } $body .= "{$p}={$v} "; } $body .= "\n\n"; /* ---- Error Information ---------------------------------------------*/ $body .= "#################################################################\n"; $body .= "## Error information\n"; $body .= "Type: " . $errors->type . "\n"; $body .= "Exception: " . get_class($exception) . "\n"; $body .= "Message: " . $exception->getMessage() . "\n"; $body .= "Code: " . $exception->getCode() . "\n"; $body .= "File: " . $exception->getFile() . "\n"; $body .= "Line: " . $exception->getLine() . "\n"; $body .= "Trace: \n"; $body .= $exception->getTraceAsString() . "\n\n"; /* ---- Session Information -------------------------------------------*/ if ($cred = Zend_Auth::getInstance()->getIdentity()) { $body .= "#################################################################\n"; $body .= "## Session information\n"; $body .= "Credential: {$cred}\n"; try { $session = Sahara_Soap::getSchedServerQueuerClient()->isUserInQueue(array('userQName' => Zend_Auth::getInstance()->getIdentity())); $body .= "In Queue: " . ($session->inQueue ? 'true' : 'false') . "\n"; $body .= "In Session: " . ($session->inSession ? 'true' : 'false') . "\n"; if ($session->inQueue) { $body .= "Queued resource ID: " . $session->queuedResouce->resourceID . "\n"; $body .= "Queued resource name: " . $session->queuedResouce->resourceName . "\n"; $body .= "Queued resource type: " . $session->queuedResouce->type . "\n"; } if ($session->inSession) { $body .= "Session resource ID: " . $session->assignedResource->resourceID . "\n"; $body .= "Session resource name: " . $session->assignedResource->resourceName . "\n"; $body .= "Session resource type: " . $session->assignedResource->type . "\n"; } } catch (Exception $ex) { $body .= "Exception when attempting to determine session status with message '" . $ex->getMessage() . "', code " . $ex->getCode() . ".\n"; } } else { $body .= "#################################################################\n"; $body .= "## No session information\n"; } $body .= "#################################################################\n\n"; $mail->setBody($body); $addresses = $this->_config->error->address; if ($addresses instanceof Zend_Config) { foreach ($addresses as $addr) { $mail->addTo($addr); } } else { $mail->addTo($addresses); } try { $mail->send(); } catch (Exception $ex) { /* Nothing much more we can do. */ } }