public static function recordAccess_log($params) { $target_type = isset($params['target_type']) ? $params['target_type'] : 0; $target_id = isset($params['target_id']) ? $params['target_id'] : 0; $act_type = isset($params['act_type']) ? $params['act_type'] : 0; $note = isset($params['note']) ? $params['note'] : []; $status = isset($params['status']) ? $params['status'] : 1; $login_name = isset($params['login_name']) ? $params['login_name'] : ''; $get_params = \Yii::$app->request->get(); $post_params = \Yii::$app->request->post(); if (isset($get_params['passwd'])) { unset($get_params['passwd']); } if (isset($post_params['passwd'])) { unset($post_params['passwd']); } $access_log = new AdminAccessLog(); $access_log->target_type = $target_type; $access_log->act_type = $act_type; $access_log->login_name = $login_name; $access_log->target_id = $target_id; $access_log->refer_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $access_log->target_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $access_log->query_params = json_encode(array_merge($get_params, $post_params)); $access_log->ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $access_log->ip = UtilHelper::getClientIP(); $access_log->note = json_encode($note); $access_log->status = $status; $access_log->created_time = date("Y-m-d H:i:s"); $access_log->save(0); }
public static function addCspReport($content) { $json_content = @json_decode($content, true); $target = new AdCspReport(); $target->url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $target->ip = UtilHelper::getClientIP(); $target->report_content = $content; if ($json_content && isset($json_content['csp-report'])) { if (isset($json_content['csp-report']['blocked-uri'])) { $blocked_uri = parse_url($json_content['csp-report']['blocked-uri']); $tmp_port = isset($blocked_uri['port']) ? $blocked_uri['port'] : ''; $blocked_uri = $blocked_uri['host']; if ($tmp_port) { $blocked_uri .= ":{$tmp_port}"; } $target->blocked_uri = $blocked_uri; } if (isset($json_content['csp-report']['source-file'])) { $target->source_file = $json_content['csp-report']['source-file']; } } $target->ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $target->updated_time = date("Y-m-d H:i:s"); $target->created_time = date("Y-m-d H:i:s"); $target->save(0); }
public function actionIndex() { return "Hi Guest,IP:" . UtilHelper::getClientIP() . ",Time:" . date('Y-m-d H:i:s'); }
public function actionAdd() { $referer = trim($this->get("referer", "")); $screen = trim($this->get("screen", "")); $target_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; if ($target_url) { $blog_id = 0; preg_match("/\\/default\\/(\\d+)(.html)?/", $target_url, $matches); if ($matches && count($matches) >= 2) { $blog_id = $matches[1]; } $tmp_source = 'direct'; if ($referer) { $tmp_source = parse_url($referer, PHP_URL_HOST); if (stripos($tmp_source, "www.google.") !== false) { $tmp_source = "www.google.com"; } } $uuid = $this->getUUID(); $uuid = ltrim($uuid, "{"); $uuid = rtrim($uuid, "}"); $model_ac_log = new AccessLogs(); $model_ac_log->referer = $referer; $model_ac_log->target_url = $target_url; $model_ac_log->blog_id = $blog_id; $model_ac_log->source = $tmp_source ? $tmp_source : ''; $model_ac_log->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; if ($model_ac_log->user_agent) { $tmp_browser = new Browser($model_ac_log->user_agent); $tmp_os = new Os($model_ac_log->user_agent); $tmp_device = new Device($model_ac_log->user_agent); $model_ac_log->client_browser = $tmp_browser->getName() ? $tmp_browser->getName() : ''; $model_ac_log->client_browser_version = $tmp_browser->getVersion() ? $tmp_browser->getVersion() : ''; $model_ac_log->client_os = $tmp_os->getName() ? $tmp_os->getName() : ''; $model_ac_log->client_os_version = $tmp_os->getVersion() ? $tmp_os->getVersion() : ''; $model_ac_log->client_device = $tmp_device->getName() ? $tmp_device->getName() : ''; if ($model_ac_log->client_device == "unknown" && UtilHelper::isPC()) { $model_ac_log->client_device = "pc"; } } $model_ac_log->ip = UtilHelper::getClientIP(); $model_ac_log->uuid = $uuid; if ($screen) { list($client_width, $client_height) = explode("/", $screen); if ($client_width) { $model_ac_log->client_width = $client_width; } if ($client_height) { $model_ac_log->client_height = $client_height; } } $model_ac_log->created_time_min = date("Y-m-d H:i"); $model_ac_log->created_time = date("Y-m-d H:i:s"); $model_ac_log->save(); /*更新文章阅读量*/ if ($blog_id) { $blog_info = Posts::findOne(['id' => $blog_id]); if ($blog_info) { $blog_info->view_count += 1; $blog_info->update(0); } } } }