Пример #1
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);
 }
Пример #2
0
 public function actionCsp()
 {
     $date_from = $this->get("date_from", date("Y-m-d"));
     $date_to = $this->get("date_to", date("Y-m-d"));
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $query = AdCspReport::find();
     if ($date_from) {
         $query->andWhere(['>=', 'created_time', date("Y-m-d", strtotime($date_from))]);
     }
     if ($date_from) {
         $query->andWhere(['<=', 'created_time', date("Y-m-d 23:59:59", strtotime($date_to))]);
     }
     $total_count = $query->count();
     $offset = ($p - 1) * $this->page_size;
     $list = $query->orderBy(['id' => SORT_DESC])->offset($offset)->limit($this->page_size)->all();
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $this->page_size, "page" => $p, "display" => 10]);
     $data = [];
     if ($list) {
         $idx = 1;
         foreach ($list as $_item) {
             $data[] = ['idx' => $idx, 'created_time' => $_item['created_time'], 'blocked_uri' => $_item['blocked_uri'], 'source_file' => $_item['source_file']];
             $idx++;
         }
     }
     $search_conditions = ['date_from' => $date_from, 'date_to' => $date_to];
     return $this->render("csp", ["data" => $data, "page_info" => $page_info, 'search_conditions' => $search_conditions]);
 }