cfmgr init...3
This commit is contained in:
parent
7faee4c993
commit
819fce450e
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\API\FirewallEntity;
|
||||
use App\Models\Cloudflare\API\FirewallModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
@ -81,4 +82,27 @@ 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
|
||||
{
|
||||
//모델 조건절 처리작업
|
||||
$this->index_setCondition();
|
||||
//모델 Join
|
||||
$builder = $this->_model->builder();
|
||||
$builder->select("cloudflarefirewall.*");
|
||||
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid");
|
||||
//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, description ASC, {$order_field} {$order_value}");
|
||||
//Limit
|
||||
$builder->limit($per_page, $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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +137,29 @@ 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
|
||||
{
|
||||
//모델 조건절 처리작업
|
||||
$this->index_setCondition();
|
||||
//모델 Join
|
||||
$builder = $this->_model->builder();
|
||||
$builder->select("cloudflarerecord.*");
|
||||
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid");
|
||||
//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, host ASC, {$order_field} {$order_value}");
|
||||
//Limit
|
||||
$builder->limit($per_page, $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;
|
||||
}
|
||||
//CDN고정관련
|
||||
final public function cdnToggle(string $uid)
|
||||
{
|
||||
|
||||
@ -419,7 +419,7 @@ class CommonController extends BaseController
|
||||
$this->_viewDatas['uri'] = $this->request->getUri();
|
||||
}
|
||||
//index 모델 전처리
|
||||
private function index_setCondition()
|
||||
protected function index_setCondition()
|
||||
{
|
||||
foreach ($this->_viewDatas['fieldFilters'] as $field) {
|
||||
$value = $this->request->getVar($field) ? $this->request->getVar($field) : false;
|
||||
@ -432,12 +432,12 @@ class CommonController extends BaseController
|
||||
$this->_model->setIndexWordFilter($word);
|
||||
}
|
||||
$start = $this->request->getVar('start') ? $this->request->getVar('start') : '';
|
||||
$start = $this->request->getVar('end') ? $this->request->getVar('end') : '';
|
||||
$end = $this->request->getVar('end') ? $this->request->getVar('end') : '';
|
||||
if (isset($start) && $start !== '' && isset($end) && $end !== '') {
|
||||
$this->_model->setIndexDateFilter($start, $end);
|
||||
}
|
||||
}
|
||||
private function index_getRows(int $page = 0, int $per_page = 0): array
|
||||
protected function index_getRows(int $page = 0, int $per_page = 0): array
|
||||
{
|
||||
//모델 조건절 처리작업
|
||||
$this->index_setCondition();
|
||||
@ -445,8 +445,9 @@ class CommonController extends BaseController
|
||||
$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';
|
||||
$this->_model->setIndexOrderBy($order_field, $order_value);
|
||||
//Limit
|
||||
$rows = $per_page ? $this->_model->findAll($per_page, $page * $per_page - $per_page) : $this->_model->findAll();
|
||||
Log::add("debug", __METHOD__ . "에서 호출[{$per_page}:{$page}=>{$page}*{$per_page}-{$per_page}]\n" . $this->_model->getLastQuery());
|
||||
log_message("debug", __METHOD__ . "에서 호출[{$per_page}:{$page}=>{$page}*{$per_page}-{$per_page}]\n" . $this->_model->getLastQuery());
|
||||
return $rows;
|
||||
}
|
||||
private function index_getPagination($pager_group = 'default', int $segment = 0, $template = 'bootstrap_full'): string
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'title' => "Record정보",
|
||||
'title' => "Firewall정보",
|
||||
'label' => [
|
||||
'uid' => "번호",
|
||||
'zone_uid' => "도메인",
|
||||
@ -13,21 +13,20 @@ return [
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일"
|
||||
],
|
||||
"ZONE_UID" => [
|
||||
],
|
||||
"ZONE_UID" => [],
|
||||
"ACTION" => [
|
||||
"block" => "block",
|
||||
"allow" => "allow",
|
||||
"challenge" => "challenge",
|
||||
"js_challenge" => "js_challenge",
|
||||
"log" => "log",
|
||||
"allow" => "allow",
|
||||
"challenge" => "challenge",
|
||||
"js_challenge" => "js_challenge",
|
||||
"log" => "log",
|
||||
],
|
||||
"FILTER_PAUSED" => [
|
||||
"on" => "사용중",
|
||||
"off" => "사용않함",
|
||||
"off" => "사용않함",
|
||||
],
|
||||
"PAUSED" => [
|
||||
"on" => "사용중",
|
||||
"off" => "사용않함",
|
||||
],
|
||||
"off" => "사용않함",
|
||||
],
|
||||
];
|
||||
|
||||
@ -8,35 +8,35 @@ use CodeIgniter\Model;
|
||||
class FirewallModel extends Model
|
||||
{
|
||||
const PARENT_FIELD = "zone_uid";
|
||||
protected $DBGroup = 'default';
|
||||
protected $table = 'cloudflarefirewall';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $DBGroup = "default";
|
||||
protected $table = "cloudflarefirewall";
|
||||
protected $primaryKey = "uid";
|
||||
protected $useAutoIncrement = false;
|
||||
protected $insertID = 0;
|
||||
protected $returnType = 'array'; //object,array,entity명::class
|
||||
protected $returnType = "array"; //object,array,entity명::class
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = ['uid', 'zone_uid', 'description', 'filter_id', 'filter_expression', 'filter_paused', 'paused', 'action', 'updated_at', 'crated_at'];
|
||||
protected $allowedFields = ["uid", "zone_uid", "description", "filter_id", "filter_expression", "filter_paused", "paused", "action", "updated_at", "crated_at"];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
protected $dateFormat = "datetime";
|
||||
protected $createdField = "created_at";
|
||||
protected $updatedField = "updated_at";
|
||||
protected $deletedField = "deleted_at";
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'zone_uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'description' => 'if_exist|string',
|
||||
'filter_id' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'filter_expression' => 'if_exist|string',
|
||||
'filter_paused' => 'if_exist|in_list[on,off]',
|
||||
'paused' => 'if_exist|in_list[on,off]',
|
||||
'action' => 'if_exist|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
"uid" => "if_exist|min_length[10]|max_length[200]",
|
||||
"zone_uid" => "if_exist|min_length[10]|max_length[200]",
|
||||
"description" => "if_exist|string",
|
||||
"filter_id" => "if_exist|min_length[10]|max_length[200]",
|
||||
"filter_expression" => "if_exist|string",
|
||||
"filter_paused" => "if_exist|in_list[on,off]",
|
||||
"paused" => "if_exist|in_list[on,off]",
|
||||
"action" => "if_exist|string",
|
||||
"updated_at" => "if_exist|valid_date",
|
||||
"created_at" => "if_exist|valid_date",
|
||||
];
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = true;
|
||||
@ -60,7 +60,7 @@ class FirewallModel extends Model
|
||||
|
||||
public function getEntity(string $uid): null|FirewallEntity
|
||||
{
|
||||
$entity = $this->asObject(FirewallEntity::class)->where('uid', $uid)->first();
|
||||
$entity = $this->asObject(FirewallEntity::class)->where("uid", $uid)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
|
||||
}
|
||||
@ -68,17 +68,30 @@ 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->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)
|
||||
{
|
||||
$this->where('created_at >=', $start);
|
||||
$this->where('created_at <=', $end);
|
||||
$this->where("created_at >=", $start);
|
||||
$this->where("created_at <=", $end);
|
||||
}
|
||||
public function setIndexOrderBy($field, $order = 'ASC')
|
||||
public function setIndexOrderBy($field, $order = "ASC")
|
||||
{
|
||||
$this->orderBy("zone_uid ASC, description ASC, {$field} {$order}");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user