From 6b2941dcdfd725b83a17389a5372b2a3b4707592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Wed, 21 Jun 2023 11:49:43 +0900 Subject: [PATCH] cfmgrv3 init..3 --- .../Cloudflare/API/FirewallController.php | 40 ++++++++++++---- .../Admin/Cloudflare/API/RecordController.php | 44 +++++++++++++----- .../Admin/Cloudflare/API/ZoneController.php | 46 +++++++++++++++++++ app/Controllers/Common/CommonController.php | 19 ++++---- app/Models/Cloudflare/API/FirewallModel.php | 14 ------ 5 files changed, 117 insertions(+), 46 deletions(-) diff --git a/app/Controllers/Admin/Cloudflare/API/FirewallController.php b/app/Controllers/Admin/Cloudflare/API/FirewallController.php index 1698806..2e5ab71 100644 --- a/app/Controllers/Admin/Cloudflare/API/FirewallController.php +++ b/app/Controllers/Admin/Cloudflare/API/FirewallController.php @@ -82,15 +82,40 @@ class FirewallController extends APIController $entity = $api->sync($entity); return parent::sync_process($entity); } - //Index관련 - protected function index_getRows(int $page = 0, int $per_page = 0): array + + //index 모델 전처리 + private function index_setCondition_builder($builder) + { + foreach ($this->_viewDatas['fieldFilters'] as $field) { + $value = $this->request->getVar($field) ? $this->request->getVar($field) : false; + if ($value) { + $builder->where("cloudflarefirewall.{$field}", $value); + } + } + $word = $this->request->getVar('word') ? $this->request->getVar('word') : ''; + if (isset($word) && $word !== '') { + $builder->like('cloudflarefirewall.description', $word, 'both'); //befor , after , both + } + $start = $this->request->getVar('start') ? $this->request->getVar('start') : ''; + $end = $this->request->getVar('end') ? $this->request->getVar('end') : ''; + if (isset($start) && $start !== '' && isset($end) && $end !== '') { + $builder->where('cloudflarerecord.created_at >=', $start); + $builder->where('cloudflarerecord.created_at <=', $end); + } + return $builder; + } + //Index관련 + protected function index_getRows_builder(int $page = 0, int $per_page = 0): array { - //모델 조건절 처리작업 - $this->index_setCondition(); //모델 Join $builder = $this->_model->builder(); $builder->select("cloudflarefirewall.*"); $builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid"); + //Totalcount 처리 + $this->index_setCondition(); + $this->_viewDatas['total_count'] = $this->_model->countAllResults(); + //Rows 처리 + $this->index_setCondition(); //OrderBy $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; $order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC'; @@ -98,11 +123,6 @@ class FirewallController extends APIController //Limit $builder->limit($per_page, $page * $per_page - $per_page); // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); - $rows = $builder->get()->getResultArray(); - // foreach ($builder->get()->getResultArray() as $row) { - // array_push($rows, new FirewallEntity($row)); - // } - // throw new \Exception(var_export($rows, true)); - return $rows; + return $builder->get()->getResultArray(); } } diff --git a/app/Controllers/Admin/Cloudflare/API/RecordController.php b/app/Controllers/Admin/Cloudflare/API/RecordController.php index 191d658..8066620 100644 --- a/app/Controllers/Admin/Cloudflare/API/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/API/RecordController.php @@ -137,15 +137,42 @@ class RecordController extends APIController $entity = $api->sync($entity); return parent::sync_process($entity); } - //Index관련 - protected function index_getRows(int $page = 0, int $per_page = 0): array + //index 모델 전처리 + private function index_setCondition_builder($builder) { - //모델 조건절 처리작업 - $this->index_setCondition(); - //모델 Join + foreach ($this->_viewDatas['fieldFilters'] as $field) { + $value = $this->request->getVar($field) ? $this->request->getVar($field) : false; + if ($value) { + $builder->where("cloudflarerecord.{$field}", $value); + } + } + $word = $this->request->getVar('word') ? $this->request->getVar('word') : ''; + if (isset($word) && $word !== '') { + $builder->like('cloudflarerecord.host', $word, 'before'); //befor , after , both + $builder->orWhere('cloudflarerecord.content', $word); + } + $start = $this->request->getVar('start') ? $this->request->getVar('start') : ''; + $end = $this->request->getVar('end') ? $this->request->getVar('end') : ''; + if (isset($start) && $start !== '' && isset($end) && $end !== '') { + $builder->where('cloudflarerecord.created_at >=', $start); + $builder->where('cloudflarerecord.created_at <=', $end); + } + return $builder; + } + //Index관련 + protected function index_getRows_builder(int $page = 0, int $per_page = 0): array + { + //Totalcount 처리 $builder = $this->_model->builder(); $builder->select("cloudflarerecord.*"); $builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid"); + $builder = $this->index_setCondition_builder($builder); + // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); + $this->_viewDatas['total_count'] = $builder->countAllResults(); + //Rows 처리 + $builder->select("cloudflarerecord.*"); + $builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid"); + $builder = $this->index_setCondition_builder($builder); //OrderBy $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; $order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC'; @@ -153,12 +180,7 @@ class RecordController extends APIController //Limit $builder->limit($per_page, $page * $per_page - $per_page); // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); - $rows = $builder->get()->getResultArray(); - // foreach ($builder->get()->getResultArray() as $row) { - // array_push($rows, new RecordEntity($row)); - // } - // throw new \Exception(var_export($rows, true)); - return $rows; + return $builder->get()->getResultArray(); } //CDN고정관련 final public function cdnToggle(string $uid) diff --git a/app/Controllers/Admin/Cloudflare/API/ZoneController.php b/app/Controllers/Admin/Cloudflare/API/ZoneController.php index a98415b..3382d1e 100644 --- a/app/Controllers/Admin/Cloudflare/API/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/API/ZoneController.php @@ -151,6 +151,52 @@ class ZoneController extends APIController $entity = $api->sync($entity); return parent::sync_process($entity); } + //index 모델 전처리 + private function index_setCondition_builder($builder) + { + foreach ($this->_viewDatas['fieldFilters'] as $field) { + $value = $this->request->getVar($field) ? $this->request->getVar($field) : false; + if ($value) { + $builder->where("cloudflarezone.{$field}", $value); + } + } + $word = $this->request->getVar('word') ? $this->request->getVar('word') : ''; + if (isset($word) && $word !== '') { + $builder->like('domain', $word, 'after'); //befor , after , both + $builder->orWhere('cloudflarerecord.content', $word, 'both'); //befor , after , both + } + $start = $this->request->getVar('start') ? $this->request->getVar('start') : ''; + $end = $this->request->getVar('end') ? $this->request->getVar('end') : ''; + if (isset($start) && $start !== '' && isset($end) && $end !== '') { + $builder->where('cloudflarezone.created_at >=', $start); + $builder->where('cloudflarezone.created_at <=', $end); + } + return $builder; + } + //Index관련 + protected function index_getRows_builder(int $page = 0, int $per_page = 0): array + { + //Totalcount 처리 + $builder = $this->_model->builder(); + $builder->select("cloudflarezone.*"); + $builder->join("cloudflarerecord", "cloudflarezone.uid = cloudflarerecord.zone_uid"); + $builder = $this->index_setCondition_builder($builder); + // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); + $this->_viewDatas['total_count'] = $builder->countAllResults(); + //Rows 처리 + $builder = $this->_model->builder(); + $builder->select("cloudflarezone.*"); + $builder->join("cloudflarerecord", "cloudflarezone.uid = cloudflarerecord.zone_uid"); + $builder = $this->index_setCondition_builder($builder); + //OrderBy + $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; + $order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC'; + $builder->orderBy("cloudflarezone.domain ASC, cloudflarezone.{$order_field} {$order_value}"); + //Limit + $builder->limit($per_page, $page * $per_page - $per_page); + // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); + return $builder->get()->getResultArray(); + } //Reload관련 final public function reload($uid) { diff --git a/app/Controllers/Common/CommonController.php b/app/Controllers/Common/CommonController.php index 80fad06..b1a660e 100644 --- a/app/Controllers/Common/CommonController.php +++ b/app/Controllers/Common/CommonController.php @@ -105,7 +105,7 @@ class CommonController extends BaseController //변경된 값 적용 $fieldDatas = array(); foreach ($this->_viewDatas['fields'] as $field) { - $fieldDatas[$field] = $this->request->getVar($field); + $fieldDatas[$field] = rtrim($this->request->getVar($field)); Log::add("info", "{$field} : {$fieldDatas[$field]}"); } $this->_viewDatas['fieldDatas'] = $fieldDatas; @@ -175,7 +175,7 @@ class CommonController extends BaseController //변경된 값 적용 $fieldDatas = array(); foreach ($this->_viewDatas['fields'] as $field) { - $fieldDatas[$field] = $this->request->getVar($field); + $fieldDatas[$field] = rtrim($this->request->getVar($field)); Log::add("info", "{$entity->getTitle()}의 {$field} : {$entity->$field}=>{$fieldDatas[$field]}"); $entity->$field = $fieldDatas[$field]; } @@ -438,7 +438,10 @@ class CommonController extends BaseController } protected function index_getRows(int $page = 0, int $per_page = 0): array { - //모델 조건절 처리작업 + //Totalcount 처리 + $this->index_setCondition(); + $this->_viewDatas['total_count'] = $this->_model->countAllResults(); + //Rows 처리 $this->index_setCondition(); //OrderBy $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; @@ -470,19 +473,13 @@ class CommonController extends BaseController } protected function index_process() { - //모델 조건절 처리작업 - $this->index_setCondition(); - //Totalcount 처리 - $total_count = $this->_model->countAllResults(); - $this->_viewDatas['total_count'] = $total_count; - //Log::add("debug",__METHOD__."에서 호출:".$this->_model->getLastQuery()); + //모델 처리 + $this->_viewDatas['rows'] = $this->index_getRows((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']); //줄수 처리용 $this->_viewDatas['pageOptions'] = array("" => "줄수선택"); for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { $this->_viewDatas['pageOptions'][$i] = $i; } - //모델 처리 - $this->_viewDatas['rows'] = $this->index_getRows((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']); //pagenation 처리 $this->_viewDatas['pagination'] = $this->index_getPagination(); } diff --git a/app/Models/Cloudflare/API/FirewallModel.php b/app/Models/Cloudflare/API/FirewallModel.php index fde75db..5a1d58d 100644 --- a/app/Models/Cloudflare/API/FirewallModel.php +++ b/app/Models/Cloudflare/API/FirewallModel.php @@ -68,23 +68,9 @@ class FirewallModel extends Model } //Index 검색용 - private function getFindWordByDomain($word): array - { - //Zone의 Domain에서 검색후 해당 검색어의 Firewall정보 출력용 - $query = $this->db()->table("cloudflarezone")->select("uid")->like("domain", $word, "both"); - // throw new \Exception($query->getCompiledSelect()); - $zone_uids = array(); - foreach ($query->get()->getResult() as $row) { - array_push($zone_uids, $row->uid); - } - // throw new \Exception(var_export($zone_uids, true)); - return $zone_uids; - } public function setIndexWordFilter(string $word) { $this->like("description", $word, "both"); //befor , after , both - // $this->orLike("filter_expression", $word, "both"); - $this->orWhereIn("zone_uid", $this->getFindWordByDomain($word)); } public function setIndexDateFilter($start, $end) {