public function postDispatch() { parent::postDispatch(); $end_time = microtime(true); $request_time = $end_time - $this->_time_start; // Log request using a raw SQL query for higher performance. if (isset($_SERVER['CF-Connecting-IP'])) { $remote_ip = $_SERVER['CF-Connecting-IP']; } else { $remote_ip = $_SERVER['REMOTE_ADDR']; } $params = array_merge((array) $this->dispatcher->getParams(), (array) $this->request->getQuery()); // Insert into Influx $influx = $this->di->get('influx'); $influx->setDatabase('pvlive_analytics'); $influx->insert('api_calls', ['value' => 1, 'ip' => $remote_ip, 'client' => $this->getParam('client', 'general'), 'useragent' => $_SERVER['HTTP_USER_AGENT'], 'controller' => $this->dispatcher->getControllerName() . '/' . $this->dispatcher->getActionName(), 'parameters' => json_encode($params), 'referrer' => $_SERVER['HTTP_REFERER'], 'is_ajax' => $this->isAjax() ? '1' : '0', 'requesttime' => $request_time]); }
protected function preDispatch() { parent::preDispatch(); $this->forceSecure(); $user = $this->auth->getLoggedInUser(); // Compile list of visible stations. $all_stations = Station::fetchAll(); $stations = array(); foreach ($all_stations as $station) { if ($station->canManage($user)) { $stations[$station->id] = $station; } } $this->stations = $stations; $this->view->stations = $stations; // Assign a station if one is selected. if ($this->hasParam('station')) { $station_id = (int) $this->getParam('station'); if (isset($stations[$station_id])) { $this->station = $stations[$station_id]; $this->view->station = $this->station; $this->view->hide_title = true; } else { throw new \DF\Exception\PermissionDenied(); } } else { if (count($this->stations) == 1) { // Convenience auto-redirect for single-station admins. $this->redirectFromHere(array('station' => key($this->stations))); return false; } } // Force a redirect to the "Select" page if no station ID is specified. if (!$this->station) { throw new \DF\Exception\PermissionDenied(); } }
protected function preDispatch() { parent::preDispatch(); $this->forceSecure(); return true; }