Пример #1
0
 /**
  * Send e-mail report if system detected that e-mail should be sent
  * 
  * @return boolean|null true if mail was sent and null if mail shouldn't be sent
  */
 protected function sendEmailReport()
 {
     if ($this->emailReport === true && $this->config['email'] !== null) {
         $body = implode('', $this->messages);
         /* this doesn't have sense any more :::
         			$body .= "\n\n---------- debug_backtrace:\n";
         
         			foreach (debug_backtrace() as $r) {
         				if (isset($r['file']) && isset($r['line'])) {
         					$body .= "{$r['file']}:{$r['line']} ";
         				}
         
         				if (isset($r['function'])) {
         					$body .= "{$r['function']} ";
         				}
         
         				if (isset($r['args'])) {
         					$body .= implode(', ', $r['args']);
         				}
         
         				$body .= "\n";
         			}
         			*/
         $body .= "\n----------\n";
         $body .= sprintf("server: %s (%s)\n", Request::serverIp(), Request::hostName());
         if (PHP_SAPI != 'cli') {
             $body .= 'URI: ' . $_SERVER['REQUEST_METHOD'] . '=' . Application::getConfig('application', 'site_url') . Application::getUri() . "\n";
             $body .= sprintf("User IP: %s (%s)%s", Request::ip(), Request::host(), Request::hasProxy() ? sprintf(" via %s for %s\n", Request::proxySignature(), Request::httpXForwardedFor()) : "\n");
             $body .= sprintf("UAS: %s\n", isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'no user agent set');
         } else {
             $body .= 'CLI Name: ' . Application::getCliName() . "\n";
             $body .= 'CLI Script: ' . Application::getCliScript() . "\n";
             $params = Cli::getParameters();
             if (count($params) > 0) {
                 $body .= 'CLI Params: ' . print_r($params, true) . "\n";
             }
         }
         $body .= sprintf("Server load: %s\n", Server::getServerLoad());
         $peak = memory_get_peak_usage(true);
         $memoryLimit = ini_get('memory_limit');
         $body .= sprintf("Memory: %s; peak: %s; limit: %s; spent: %s%%\n", Convert::bytesToString(memory_get_usage(true)), Convert::bytesToString($peak), $memoryLimit, $memoryLimit !== false && $memoryLimit > 0 ? round($peak * 100 / Convert::stringToBytes($memoryLimit), 2) : 'null');
         $body .= sprintf("included files: %s\n", print_r(get_included_files(), true));
         $mail = Mail::create();
         $mail->from('alert@' . Request::hostName(), Request::hostName())->subject('Log report')->body($body);
         if (!is_array($this->config['email']) && strpos($this->config['email'], ',') !== false) {
             $this->config['email'] = explode(',', $this->config['email']);
         }
         if (is_array($this->config['email'])) {
             foreach ($this->config['email'] as $toEmail) {
                 $mail->to(trim($toEmail));
             }
         } else {
             $mail->to(trim($this->config['email']));
         }
         if (!$mail->send()) {
             $this->error("Can not send alert mail to {$this->config['email']}: {$mail->getError()}\n{$mail->getException()->getTraceAsString()}");
             return false;
         }
         return true;
     }
     return null;
 }
Пример #2
0
 /**
  * Do actual e-mail test by sending the e-mail to the given e-mail address
  * @return \Bootstrap\Response\Form
  */
 public function testEmailAjax()
 {
     $validator = Validator::create(array('to' => 'required|email'));
     if ($validator->failed()) {
         return BootstrapUI::formResponse()->failedOn($validator);
     }
     if (!Mail::isEnabled()) {
         return BootstrapUI::formResponse()->message('Mail sender is not enabled!');
     }
     $params = $validator->getParamsObj();
     $mail = Mail::create()->from('no-replay@' . Request::hostNameDomain(), Request::hostName())->to($params->to)->subject('Configuration test mail')->body("If you got this e-mail, then your mail configuration is just fine!\n\n" . Url::current());
     try {
         if ($mail->send()) {
             Log::info("Test e-mail is sent to {$params->to}");
             return BootstrapUI::formResponse()->message('Test e-mail is sent!');
         }
     } catch (Exception $e) {
         Log::info("Couldn\\'t send test e-mail to {$params->to}");
         Log::exception($e);
         // we'll log this if needed, just to make sure it won't be forgotten
         return BootstrapUI::formResponse()->failed('E-mail wasn\'t sent:<br/>' . $e->getMessage());
         // show user the actual error
     }
 }
Пример #3
0
 public static function processRequest(array $params)
 {
     $data = $params;
     $params = array();
     foreach ($data as $key => $value) {
         $params[strtolower($key)] = $value;
     }
     unset($data);
     $where = array();
     $bindings = null;
     if (isset($params['package_name']) && $params['package_name'] !== null && trim($params['package_name']) != '') {
         $where[] = '(package IS NULL OR package LIKE :package_name)';
         $bindings['package_name'] = "%{$params['package_name']}%";
     }
     if (isset($params['app_version_name']) && $params['app_version_name'] !== null && trim($params['app_version_name']) != '') {
         $where[] = '(package_version IS NULL OR package_version LIKE :package_version)';
         $bindings['package_version'] = "%{$params['app_version_name']}%";
     }
     if (isset($params['android_version']) && $params['android_version'] !== null && trim($params['android_version']) != '') {
         $where[] = '(os_version IS NULL OR os_version LIKE :os_version)';
         $bindings['os_version'] = "%{$params['android_version']}%";
     }
     if (isset($params['brand']) && $params['brand'] !== null && trim($params['brand']) != '') {
         $where[] = '(brand IS NULL OR brand LIKE :brand)';
         $bindings['brand'] = "%{$params['brand']}%";
     }
     if (isset($params['phone_model']) && $params['phone_model'] !== null && trim($params['phone_model']) != '') {
         $where[] = '(model IS NULL OR model LIKE :model)';
         $bindings['model'] = "%{$params['phone_model']}%";
     }
     if (isset($params['product']) && $params['product'] !== null && trim($params['product']) != '') {
         $where[] = '(product IS NULL OR product LIKE :product)';
         $bindings['product'] = "%{$params['product']}%";
     }
     if (isset($params['country']) && $params['country'] !== null && trim($params['country']) != '') {
         $where[] = '(country IS NULL OR country LIKE :country)';
         $bindings['country'] = "%{$params['country']}%";
     }
     if (sizeof($where) == 0) {
         return false;
     }
     $where = implode(' AND ', $where);
     $query = "\n\t\t\tSELECT\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tto_emails,\n\t\t\t\tlast_email,\n\t\t\t\temail_delay_minutes\n\t\t\tFROM\n\t\t\t\temail_trigger\n\t\t\tWHERE\n\t\t\t\t{$where}\n\t\t\t\tAND state = 'waiting'\n\t\t";
     $records = static::getAdapter()->query($query, $bindings);
     foreach ($records as $r) {
         $send = false;
         $now = gmdate('Y-m-d H:i:s');
         if ($r->last_email === null) {
             $send = true;
         } else {
             $then = new \DateTime($r->last_email);
             $then->modify("+{$r->email_delay_minutes} minute");
             // 				Log::debug("{$then->format('Y-m-d H:i:s')} < {$now}");
             if ($then->format('Y-m-d H:i:s') < $now) {
                 $send = true;
             }
         }
         if ($send) {
             static::update(array('state' => 'sending'), $r->id);
             $email = Mail::create();
             foreach (explode(',', $r->to_emails) as $address) {
                 $email->to($address);
             }
             $email->subject($r->name);
             $body = array("DATE AND TIME (GMT): {$now}");
             $body[] = "PACKAGE: {$params['package_name']} {$params['app_version_name']}";
             unset($params['package_name'], $params['app_version_name']);
             // first append one line data
             foreach ($params as $key => $value) {
                 $value = trim($value);
                 if ($value != '') {
                     if (strpos($value, "\n") === false) {
                         $body[] = strtoupper($key) . ": {$value}";
                         unset($params[$key]);
                     }
                 }
             }
             if (isset($params['stack_trace'])) {
                 $body[] = "STACK TRACE\n" . str_repeat('=', 30) . "\n" . $params['stack_trace'];
                 unset($params['stack_trace']);
             }
             // append multiple line data
             foreach ($params as $key => $value) {
                 $value = trim($value);
                 if ($value != '') {
                     $body[] = strtoupper($key) . "\n" . str_repeat('=', 30) . "\n" . $value;
                     unset($params[$key]);
                 }
             }
             $email->body(implode("\n\n", $body));
             $email->from('no-reply@' . Request::hostName());
             if ($email->send()) {
                 Log::notice("Sent e-mail alert '{$r->name}'");
                 static::update(array('last_email' => $now, 'last_update' => $now, 'state' => 'waiting'), $r->id);
             } else {
                 Log::error("Can not send e-mail alert '{$r->name}', sender returned false");
                 static::update(array('state' => 'waiting'), $r->id);
             }
         }
     }
 }