Beispiel #1
0
 /**
  * (non-PHPdoc)
  * @see \Bootstrap\Button::getHtml()
  */
 public function getHtml()
 {
     if (sizeof($this->params) > 0) {
         $this->data('params', base64_encode(\Koldy\Json::encode($this->params)));
     }
     return parent::getHtml();
 }
Beispiel #2
0
 /**
  * (non-PHPdoc)
  * @see \Bootstrap\HtmlElement::getHtml()
  */
 public function getHtml()
 {
     if ($this->searchEnabled) {
         $search = '<form class="form-inline x-remote-search-form" role="form">' . '<div class="form-group">' . '<label class="sr-only" for="search">Search</label>' . '<input type="search" class="form-control input-sm animate-width" id="search" placeholder="Search" style="width:80px;">' . '<button type="reset" class="btn btn-xs btn-link">' . \Bootstrap::icon('remove-circle') . '</button>' . '</div>' . '</form>';
         $this->panel->addHeaderElement($search);
     }
     if ($this->collapsible !== null) {
         $this->panel->collapsible($this->collapsible);
     }
     $footer = '<div class="row">' . '<div class="col-md-6 x-remote-table-info"></div>' . '<div class="col-md-6 x-remote-table-pagination text-right"></div>' . '</div>';
     $this->panel->footer($footer);
     $this->table->data('url', $this->url === null ? $_SERVER['REQUEST_URI'] : $this->url);
     $this->table->data('page', $this->startPage);
     $this->table->data('limit', 10);
     $this->table->data('field', $this->sortField === null ? $this->table->getPrimaryKey() : $this->sortField);
     $this->table->data('dir', $this->sortDirection);
     $this->table->data('extra-params', base64_encode(Json::encode($this->extraParams)));
     $this->panel->content($this->table);
     return $this->panel->getHtml();
 }
 public function getStackTraceAjax()
 {
     $params = Input::requireParams('id');
     $id = (int) $params->id;
     if ($id <= 0) {
         throw new Exception('Invalid ID');
     }
     $submit = Crash\Submit::fetchOne('id', $id);
     if ($submit === false) {
         throw new Exception('Can not find stack trace');
     }
     return Json::create(array('success' => true, 'stack_trace' => $submit->stack_trace));
 }
Beispiel #4
0
 public function __toString()
 {
     return \Koldy\Json::encode($this->getData());
 }
Beispiel #5
0
 /**
  * Process the request
  * @param string $os 'Android','iOS' or 'Windows'
  *
  * TODO: This logic shouldn't be in the model
  */
 public static function processRequest($os)
 {
     if (!isset($_POST['PACKAGE_NAME'])) {
         Log::warning('Package name is not set! UAS=' . Request::userAgent() . ' POST=' . Json::encode($_POST));
     }
     $time = time();
     $ip = $_SERVER['REMOTE_ADDR'];
     $host = gethostbyaddr($ip);
     $country = null;
     $provider = null;
     if ($host != $ip && strpos($host, '.') !== false) {
         $country = strtolower(substr($host, strrpos($host, '.') + 1));
         if (strlen($country) != 2) {
             $country = null;
         }
         $provider = \Provider::normalizeHostName($host);
     }
     Log::notice("Got request time={$time} host={$host} country={$country}");
     $values = array('created_at', 'package_name', 'app_version_code', 'app_version_name', 'brand', 'phone_model', 'product', 'stack_trace', 'android_version', 'file_path', 'total_mem_size', 'available_mem_size', 'user_comment', 'user_app_start_date', 'user_crash_date', 'installation_id', 'report_id', 'user_email');
     $data = array();
     $vals = $_POST;
     foreach ($values as $key) {
         $key = strtoupper($key);
         if (isset($vals[$key])) {
             $data[$key] = trim($vals[$key]);
             unset($vals[$key]);
         }
     }
     if (isset($data['user_email']) && ($data['user_email'] == 'N/A' || trim($data['user_email']) == '')) {
         $data['user_email'] = null;
     }
     $data['created_at'] = gmdate('Y-m-d H:i:s');
     $data['country'] = $country;
     $data['provider'] = $provider;
     $data['os'] = $os;
     $secureCount = 0;
     do {
         $submit = static::create($data);
         if ($submit === false) {
             Db::getAdapter()->close();
             Log::info("Failed to insert crash submit report for time={$time}, waiting 5 seconds");
             set_time_limit(60);
             sleep(5);
             Db::getAdapter()->reconnect();
             Log::info("Retry {$secureCount} insert crash submit report for time={$time}");
         }
     } while ($submit === false && $secureCount++ < 3);
     if ($submit !== false) {
         foreach ($vals as $metaName => $metaValue) {
             if ($metaValue !== null) {
                 $metaValue = trim($metaValue);
                 if (strlen($metaValue) > 0) {
                     $secureCount = 0;
                     do {
                         $dbMeta = $submit->insertMeta(strtolower($metaName), trim($metaValue));
                         if ($dbMeta === false) {
                             Db::getAdapter()->close();
                             Log::info("Failed to insert submit meta for meta={$metaName} time={$time}, waiting 5 seconds");
                             set_time_limit(60);
                             sleep(5);
                             Db::getAdapter()->reconnect();
                             Log::info("Retry {$secureCount} meta insert for meta={$metaName} time={$time}");
                         }
                     } while ($dbMeta === false && $secureCount++ < 2);
                 }
             }
         }
     }
     \Email\Trigger::processRequest($_POST);
     Log::notice("Done request time={$time}");
 }
 /**
  * I'm sure you sometimes want to show nice error to user! Well, if you call
  * Application::error(404), then it will end up here. This kind of errors are meant
  * only to show nice error to user. If you also want to log this or alert anyone that
  * this happened, then do that before calling Application::error() method.
  * 
  * @param int $code The HTTP error code
  * @param string $message Optional message that will be visible to user
  * @param \Exception $e Optional exception, if any. Be careful, you might not
  * want to show the exceptions to users, but you would like to show it to developers? Then
  * use Application::inDevelopment() and inProduction() methods.
  */
 public function error($code, $message = null, \Exception $e = null)
 {
     if (!headers_sent()) {
         switch ($code) {
             case 400:
                 header('HTTP/1.0 400 Bad Request', true, 400);
                 if ($message === null) {
                     $message = 'Bad request';
                 }
                 break;
             case 403:
                 header('HTTP/1.0 403 Forbidden', true, 403);
                 if ($message === null) {
                     $message = 'Forbidden';
                 }
                 break;
             case 404:
                 header('HTTP/1.0 404 Not Found', true, 404);
                 if ($message === null) {
                     $message = 'Page Not Found';
                 }
                 break;
             case 500:
                 header('HTTP/1.0 500 Internal Server Error', true, 500);
                 if ($message === null) {
                     $message = 'Internal Server Error';
                 }
                 break;
             case 503:
                 header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503);
                 header('Status: 503 Service Temporarily Unavailable');
                 header('Retry-After: 300');
                 // 300 seconds / 5 minutes
                 if ($message === null) {
                     $message = 'Service Temporarily Unavailable';
                 }
                 break;
         }
     }
     if ($message === null) {
         $message = 'Page Not Found';
     }
     if ($this->isAjax()) {
         $data = array('success' => false, 'type' => 'http', 'code' => $code, 'message' => $message, 'exception' => $e !== null && Application::inDevelopment() ? $e->getMessage() : null);
         Json::create($data)->flush();
     } else {
         $path = Application::getPublicPath("{$code}.php");
         if (file_exists($path)) {
             $exception = $e;
             include $path;
         } else {
             // i don't know how to handle this message now!?
             throw new Exception($message === null ? 'Error ' . $code : $message);
         }
     }
     exit(0);
 }