cfmgrv4 init...4
This commit is contained in:
parent
62f6a86d53
commit
347c4a7e07
@ -37,19 +37,25 @@ class AuditLogController extends CloudflareController
|
||||
private function init(string $action, array $fields = []): void
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->fields = count($fields) ? $fields : [$this->getModel()::TITLE, 'actor', 'interface', 'zone_name', 'resource_type', 'resource_name', 'status', 'updated_at', 'created_at'];
|
||||
$this->fields = count($fields) ? $fields : ['zone_name', $this->getModel()::TITLE, 'action_info', 'actor', 'interface', 'status', 'updated_at', 'created_at'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = ['status'];
|
||||
$this->filter_fields = [];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = [];
|
||||
}
|
||||
//View
|
||||
public function view(string $uid): RedirectResponse|string
|
||||
{
|
||||
$this->init(__FUNCTION__, [$this->getModel()::TITLE, 'action_info', 'actor', 'interface', 'zone_id', 'zone_name', 'resource_id', 'resource_type', 'resource_name', 'status', 'updated_at', 'created_at']);
|
||||
$this->init(__FUNCTION__, ['zone_name', $this->getModel()::TITLE, 'actor', 'action_info', 'interface', 'meta', 'resource', 'status', 'updated_at', 'created_at']);
|
||||
return $this->view_procedure($uid);
|
||||
}
|
||||
// 리스트
|
||||
protected function list_entitys_process(): array
|
||||
{
|
||||
//기본Soring처리
|
||||
$this->getModel()->orderBy("created_at DESC,zone_name ASC");
|
||||
return parent::list_entitys_process();
|
||||
}
|
||||
public function index(): string
|
||||
{
|
||||
$this->init(__FUNCTION__);
|
||||
|
||||
@ -182,21 +182,8 @@ class RecordController extends CloudflareController
|
||||
//리스트
|
||||
protected function list_entitys_process(): array
|
||||
{
|
||||
$this->list_condition_process();
|
||||
//기본Soring처리
|
||||
$this->getModel()->orderBy(ZoneModel::TABLE . "." . ZoneModel::TITLE . " ASC ," . $this->getModel()::TITLE . " ASC");
|
||||
//Sorting 처리
|
||||
$this->order_field = $this->request->getVar('order_field') ?: DEFAULTS['EMPTY'];
|
||||
$this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY'];
|
||||
if ($this->order_field !== DEFAULTS['EMPTY'] && $this->order_value !== DEFAULTS['EMPTY']) {
|
||||
$this->getModel()->orderBy(sprintf(
|
||||
"%s.%s %s",
|
||||
$this->getModel()::TABLE,
|
||||
$this->order_field,
|
||||
$this->order_value
|
||||
));
|
||||
}
|
||||
$this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page);
|
||||
//Join을 해서 도메인부터 Sorting하기위함
|
||||
$this->getModel()->join(ZoneModel::TABLE, sprintf(
|
||||
"%s.%s=%s.%s",
|
||||
@ -205,9 +192,7 @@ class RecordController extends CloudflareController
|
||||
ZoneModel::TABLE,
|
||||
ZoneModel::PK
|
||||
));
|
||||
$entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll();
|
||||
log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entitys;
|
||||
return parent::list_entitys_process();
|
||||
}
|
||||
public function index(): string
|
||||
{
|
||||
|
||||
@ -226,22 +226,9 @@ class ZoneController extends CloudflareController
|
||||
// 리스트
|
||||
protected function list_entitys_process(): array
|
||||
{
|
||||
$this->list_condition_process();
|
||||
//기본Soring처리
|
||||
$this->getModel()->orderBy(orderBy: AccountModel::TABLE . "." . AccountModel::TITLE . " ASC ," . $this->getModel()::TITLE . " ASC");
|
||||
//Sorting 처리
|
||||
$this->order_field = $this->request->getVar('order_field') ?: DEFAULTS['EMPTY'];
|
||||
$this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY'];
|
||||
if ($this->order_field !== DEFAULTS['EMPTY'] && $this->order_value !== DEFAULTS['EMPTY']) {
|
||||
$this->getModel()->orderBy(sprintf(
|
||||
"%s.%s %s",
|
||||
$this->getModel()::TABLE,
|
||||
$this->order_field,
|
||||
$this->order_value
|
||||
));
|
||||
}
|
||||
$this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page);
|
||||
//Join을 해서 도메인부터 Sorting하기위함
|
||||
//Join을 해서 Account부터 Sorting하기위함
|
||||
$this->getModel()->join(AccountModel::TABLE, sprintf(
|
||||
"%s.%s=%s.%s",
|
||||
$this->getModel()::TABLE,
|
||||
@ -249,9 +236,7 @@ class ZoneController extends CloudflareController
|
||||
AccountModel::TABLE,
|
||||
AccountModel::PK
|
||||
));
|
||||
$entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll();
|
||||
log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entitys;
|
||||
return parent::list_entitys_process();
|
||||
}
|
||||
public function index(): string
|
||||
{
|
||||
|
||||
@ -386,7 +386,12 @@ abstract class MVController extends CommonController
|
||||
$this->order_field = $this->request->getVar('order_field') ?: DEFAULTS['EMPTY'];
|
||||
$this->order_value = $this->request->getVar('order_value') ?: DEFAULTS['EMPTY'];
|
||||
if ($this->order_field !== DEFAULTS['EMPTY'] && $this->order_value !== DEFAULTS['EMPTY']) {
|
||||
$this->getModel()->orderBy("{$this->order_field} {$this->order_value}");
|
||||
$this->getModel()->orderBy(sprintf(
|
||||
"%s.%s %s",
|
||||
$this->getModel()::TABLE,
|
||||
$this->order_field,
|
||||
$this->order_value
|
||||
));
|
||||
}
|
||||
$this->getModel()->limit($this->per_page, $this->page * $this->per_page - $this->per_page);
|
||||
$entitys = $this->getModel()->select($this->getModel()::TABLE . '.*')->findAll();
|
||||
|
||||
@ -25,17 +25,16 @@ ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_1 (id);
|
||||
ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_2 (authkey);
|
||||
|
||||
6. auditlog용 table추가
|
||||
DROP TABLE cloudflareauditlog;
|
||||
CREATE TABLE cloudflareauditlog (
|
||||
uid varchar(255) NOT NULL COMMENT 'id',
|
||||
action varchar(100) NOT NULL COMMENT 'action->type',
|
||||
action_info varchar(255) NULL COMMENT 'action->info',
|
||||
actor varchar(100) NOT NULL COMMENT 'actor->type',
|
||||
interface varchar(100) NULL COMMENT 'interface',
|
||||
zone_id varchar(100) NOT NULL COMMENT 'newValueJson->zone_id',
|
||||
zone_name varchar(100) NULL COMMENT 'newValueJson->zone_name',
|
||||
resource_id varchar(100) NOT NULL COMMENT 'newValueJson->id',
|
||||
resource_name varchar(100) NULL COMMENT 'newValueJson->name',
|
||||
resource_type varchar(50) NULL COMMENT 'newValueJson->type',
|
||||
meta text NULL COMMENT 'meta domain settings info',
|
||||
resource text NULL COMMENT 'newValueJson',
|
||||
status varchar(10) NOT NULL COMMENT 'action->result',
|
||||
updated_at timestamp NULL DEFAULT NULL,
|
||||
created_at timestamp NOT NULL COMMENT 'when',
|
||||
|
||||
@ -24,8 +24,8 @@ class AuditLogEntity extends CommonEntity
|
||||
$this->attributes[AuditLogModel::TITLE] = $title;
|
||||
}
|
||||
//Common Function
|
||||
public function getZoneID(): string
|
||||
public function getZoneName(): string
|
||||
{
|
||||
return $this->attributes['zone_id'];
|
||||
return $this->attributes['zone_name'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,9 +45,6 @@ class AuditLogHelper extends MVCHelper
|
||||
]
|
||||
);
|
||||
break;
|
||||
case 'status':
|
||||
$value = $viewDatas['field_options'][$field][$value];
|
||||
break;
|
||||
default:
|
||||
$value = parent::getFieldView($field, $viewDatas, $extras);
|
||||
break;
|
||||
|
||||
@ -7,17 +7,11 @@ return [
|
||||
'action_info' => "ActInfo",
|
||||
'actor' => "작업자",
|
||||
'interface' => "UI형식",
|
||||
'zone_id' => "도메인ID",
|
||||
'zone_name' => "도메인",
|
||||
'resource_id' => "자원ID",
|
||||
'resource_name' => "자원명",
|
||||
'resource_type' => "자원형식",
|
||||
'meta' => "meta정보",
|
||||
'resource' => "자원정보",
|
||||
'status' => "상태",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일",
|
||||
],
|
||||
"STATUS" => [
|
||||
"true" => "완료",
|
||||
"false" => "실패",
|
||||
],
|
||||
];
|
||||
|
||||
@ -15,7 +15,7 @@ class AuditLogModel extends CommonModel
|
||||
protected $primaryKey = self::PK;
|
||||
protected $useAutoIncrement = false;
|
||||
protected $returnType = AuditLogEntity::class; //object,array,entity명::class
|
||||
protected $allowedFields = [self::PK, self::TITLE, 'action_info', 'actor', 'interface', 'zone_id', 'zone_name', 'resource_id', 'resource_name', 'resource_type', 'status', 'updated_at', 'created_at'];
|
||||
protected $allowedFields = [self::PK, self::TITLE, 'action_info', 'actor', 'interface', 'zone_name', 'meta', 'resource', 'status', 'updated_at', 'created_at'];
|
||||
protected $useTimestamps = true;
|
||||
|
||||
public function __construct()
|
||||
@ -35,19 +35,17 @@ class AuditLogModel extends CommonModel
|
||||
break;
|
||||
case self::TITLE:
|
||||
case 'actor':
|
||||
case 'zone_id':
|
||||
case 'resource_id':
|
||||
case 'zone_name':
|
||||
case "status":
|
||||
$rule = "required|trim|string";
|
||||
break;
|
||||
case 'interface':
|
||||
case 'action_info':
|
||||
case 'zone_name':
|
||||
case 'resource_name':
|
||||
case 'resource_type':
|
||||
$rule = "if_exist|trim|string";
|
||||
$rule = "if_exist|string";
|
||||
break;
|
||||
case "status":
|
||||
$rule = "if_exist|in_list[true,false]";
|
||||
case 'meta':
|
||||
case 'resource':
|
||||
$rule = "if_exist";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFieldRule($action, $field);
|
||||
@ -55,16 +53,6 @@ class AuditLogModel extends CommonModel
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
public function getFormFieldInputOption(string $field, array $options = []): array
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
$this->orderBy(self::TITLE, 'asc');
|
||||
$options = parent::getFormFieldInputOption($field, $options);
|
||||
break;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
public function getEntityByPK(string $uid): null|AuditLogEntity
|
||||
{
|
||||
$this->where(self::PK, $uid);
|
||||
@ -90,6 +78,7 @@ class AuditLogModel extends CommonModel
|
||||
{
|
||||
parent::setList_WordFilter($word, $field);
|
||||
$this->orLike(self::TABLE . '.zone_name', $word, 'both');
|
||||
$this->orLike(self::TABLE . '.resource_name', $word, 'both');
|
||||
$this->orLike(self::TABLE . '.meta', $word, 'both');
|
||||
$this->orLike(self::TABLE . '.resource', $word, 'both');
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,14 +4,14 @@ namespace App\Services\Cloudflare;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Entities\Cloudflare\AuditLogEntity;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
use App\Models\Cloudflare\AuditLogModel;
|
||||
use stdClass;
|
||||
|
||||
class AuditLogService extends CloudflareService
|
||||
{
|
||||
private ?AuditLogModel $_model = null;
|
||||
private ?AccountModel $_accountModel = null;
|
||||
private ?ZoneModel $_zoneModel = null;
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "AuditLog";
|
||||
@ -25,12 +25,12 @@ class AuditLogService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
protected function getAccountModel(): AccountModel
|
||||
protected function getZoneModel(): ZoneModel
|
||||
{
|
||||
if ($this->_accountModel === null) {
|
||||
$this->_accountModel = new AccountModel();
|
||||
if ($this->_zoneModel === null) {
|
||||
$this->_zoneModel = new ZoneModel();
|
||||
}
|
||||
return $this->_accountModel;
|
||||
return $this->_zoneModel;
|
||||
}
|
||||
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
@ -40,11 +40,9 @@ class AuditLogService extends CloudflareService
|
||||
$formDatas['action_info'] = isset($result->action->info) ? $result->action->info : "";
|
||||
$formDatas['actor'] = $result->actor->type;
|
||||
$formDatas['interface'] = isset($result->interface) ? $result->interface : "";
|
||||
$formDatas['zone_id'] = $result->newValueJson->zone_id;
|
||||
$formDatas['zone_name'] = isset($result->newValueJson->zone_name) ? $result->newValueJson->zone_name : "";
|
||||
$formDatas['resource_id'] = $result->newValueJson->id;
|
||||
$formDatas['resource_name'] = isset($result->newValueJson->name) ? $result->newValueJson->name : "";
|
||||
$formDatas['resource_type'] = $result->newValueJson->type ? $result->newValueJson->type : "";
|
||||
$formDatas['zone_name'] = $result->metadata->zone_name;
|
||||
$formDatas['meta'] = isset($result->metadata) ? var_export($result->metadata, true) : "";
|
||||
$formDatas['resource'] = isset($result->newValueJson) ? var_export($result->newValueJson, true) : "";
|
||||
$formDatas['status'] = $result->action->result ? "true" : "false";
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
$formDatas['created_at'] = $result->when;
|
||||
@ -54,8 +52,8 @@ class AuditLogService extends CloudflareService
|
||||
private function auditlog_process(AuditLogEntity $entity): void
|
||||
{
|
||||
//해당 Zone을 Sync작업한다
|
||||
$zone_service = new ZoneService();
|
||||
$zone_entity = $zone_service->getEntityByPK($entity->getZoneID());
|
||||
$this->getZoneModel()->where('domain', $entity->getZoneName());
|
||||
$zone_entity = $this->getZoneModel()->getEntity();
|
||||
if ($zone_entity !== null) {
|
||||
// $zone_entity = $zone_service->sync($entity, $zone_entity);
|
||||
// //해당 Zone의 Record reload작업한다
|
||||
@ -80,19 +78,15 @@ class AuditLogService extends CloudflareService
|
||||
try {
|
||||
// 오늘 날짜의 ISO 8601 형식 문자열 생성
|
||||
$today = date('Y-m-d') . 'T00:00:00';
|
||||
$endpoint = sprintf("accounts/%s/audit_logs?since=%s", $account_entity->getPK(), $today);
|
||||
log_message("debug", "Auditlog Endpoint: " . $endpoint);
|
||||
$response = $this->getMySocket()->get($endpoint);
|
||||
$response = $this->getMySocket()->get("accounts/{$account_entity->getPK()}/audit_logs", ['since' => $today]);
|
||||
$body = json_decode($response->getBody());
|
||||
foreach ($body->result as $result) {
|
||||
if (isset($result->action->result) && $result->action->result && isset($result->newValueJson->zone_id) && isset($result->newValueJson->zone_name)) {
|
||||
// log_message("debug", var_export($result->newValueJson, true));
|
||||
$entity = $this->getModel()->getEntityByPK($result->id);
|
||||
if ($entity === null) {
|
||||
$formDatas = $this->getArrayByResult($result);
|
||||
$entity = $this->getModel()->modify(new AuditlogEntity(), $formDatas);
|
||||
$this->auditlog_process($entity);
|
||||
}
|
||||
if (isset($result->action->result) && $result->action->result && isset($result->metadata->zone_name)) {
|
||||
$formDatas = $this->getArrayByResult($result);
|
||||
$entity = $this->getModel()->modify(new AuditlogEntity(), $formDatas);
|
||||
$this->auditlog_process($entity);
|
||||
} else {
|
||||
log_message("debug", var_export($result, true));
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@ -46,11 +46,6 @@ class ZoneService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
public function getEntityByPK(string $uid): null|ZoneEntity
|
||||
{
|
||||
return $this->getModel()->getEntityByPK($uid);
|
||||
}
|
||||
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
// log_message("debug", var_export($result, true));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user