title = lang("{$this->getService()->getClassPath()}.title"); $this->helper = new RecordHelper(); $this->isMyLog = env("mylog.cloudflare.record.use") == "true"; //MyLogService 사용여부 } protected function getService(): RecordService { if ($this->service === null) { $this->service = new RecordService(); } return $this->service; } protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { case $this->getService()->getModel()::PARENT: // $this->getZoneModel()->where('status', 'active'); $options[$field] = $this->getZoneModel()->getFormFieldOption($field); // echo $this->getAccountModel()->getLastQuery(); // dd($options); break; default: $options = parent::getFormFieldOption($field, $options); break; } return $options; } //생성 public function create_form(): RedirectResponse|string { $this->init('create', [$this->getService()->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']); $this->field_rules = $this->getService()->getModel()->getFieldRules($this->action, $this->fields); //부모데이터 정의 $parent_field = $this->getService()->getModel()::PARENT; $this->$parent_field = $this->request->getVar($parent_field) ?: DEFAULTS["EMPTY"]; return $this->create_form_procedure(); } protected function create_process(): void { //DB작업도 Socket에서 다 처리하므로 parent::create_process()하면 않됨 $this->formDatas = $this->create_validate($this->action, $this->fields); //Type이 A형식일경우 IP형태인지 확인 if ($this->formDatas['type'] === 'A') { if (!$this->helper->isIPAddress($this->formDatas['content'], $this->formDatas['type'])) { throw new \Exception("{$this->formDatas['type']}, {$this->formDatas['content']} 형식 오류[사설IP 않됨]"); } } //호스트명 형식확인 $hosts = explode("\n", $this->formDatas['hosts']); if (!is_array($hosts) || !count($hosts)) { throw new \Exception("호스트명이 정의되지 않았습니다."); } $cnt = 1; foreach ($hosts as $host) { if (!$this->helper->isHost($host)) { throw new \Exception("입력하신 {$cnt}번째 : [{$host}]는 호스트명 입력형식에 맞지 않습니다."); } $cnt++; } //Socket처리 //부모데이터정의 $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->formDatas[$this->getService()->getModel()::PARENT]); if ($this->_zone_entity === null) { throw new \Exception("Zone: [{$this->formDatas[$this->getService()->getModel()::PARENT]}] 정보를 찾을수 없습니다."); } $entitys = []; foreach ($hosts as $host) { $entity = $this->getService()->create( $this->_zone_entity, $host, $this->formDatas['type'], $this->formDatas['content'], $this->formDatas['proxied'] ); $entitys[] = $entity; } $this->entitys = $entitys; } protected function create_process_result($message): RedirectResponse|string { $this->init(__FUNCTION__); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return view( strtolower($this->view_path . $this->getService()->getClassPath() . "/create_result"), data: ['viewDatas' => $this->getViewDatas()] ); } public function create(): RedirectResponse|string { $this->init(__FUNCTION__, [$this->getService()->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']); $this->field_rules = $this->getService()->getModel()->getFieldRules($this->action, $this->fields); return $this->create_procedure(); } //수정 (modify,toggle,batchjob사용) protected function modify_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::modify_process($uid)하면 않됨 $this->formDatas = $this->modify_validate($this->action, $this->fields); //자신정보정의 $this->entity = $this->getService()->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } //부모데이터정의 $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); if ($this->_zone_entity === null) { throw new \Exception("Zone: [{$this->entity->getParent()}] 정보를 찾을수 없습니다."); } //Socket처리 $this->entity = $this->getService()->modify($this->_zone_entity, $this->entity, $this->formDatas); } //단일필드작업 public function toggle(mixed $uid, string $field): RedirectResponse { return $this->toggle_procedure($uid, $field); } //일괄처리작업 public function batchjob(): RedirectResponse { $this->init(__FUNCTION__); return $this->batchjob_procedure(); } //View //create_process_result에서 결과값을 entitys에 저장하고 호출하기때문에 아래와 같이 처리함 public function view(string $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->view_procedure($uid); } //삭제 protected function delete_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::delete_process($uid)하면 않됨 //자신정보정의 $this->entity = $this->getService()->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } //부모데이터정의 $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); if ($this->_zone_entity === null) { throw new \Exception("Zone: [{$this->entity->getParent()}] 정보를 찾을수 없습니다."); } //Cloudflare 삭제 $this->entity = $this->getService()->delete($this->_zone_entity, $this->entity); } //리스트 protected function list_entitys_process(): array { //기본Soring처리 $this->getService()->getModel()->orderBy(ZoneModel::TABLE . "." . ZoneModel::TITLE . " ASC ," . $this->getService()->getModel()::TITLE . " ASC"); //Join을 해서 도메인부터 Sorting하기위함 $this->getService()->getModel()->join(ZoneModel::TABLE, sprintf( "%s.%s=%s.%s", $this->getService()->getModel()::TABLE, $this->getService()->getModel()::PARENT, ZoneModel::TABLE, ZoneModel::PK )); return parent::list_entitys_process(); } public function index(): string { $this->init(__FUNCTION__); return $this->list_procedure(); } // Download public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } //Sync작업 protected function sync_process(string $uid): void { //자신정보정의 $this->entity = $this->getService()->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } //부모데이터정의 $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); if ($this->_zone_entity === null) { throw new \Exception("Zone: [{$this->entity->getParent()}] 정보를 찾을수 없습니다."); } //Socket처리 $this->entity = $this->getService()->sync($this->_zone_entity, $this->entity); } public function sync(string $uid): RedirectResponse { return $this->sync_procedure($uid); } //reload Record By Zone protected function reload_process(mixed $uid): void { //부모데이터정의 $this->_zone_entity = $this->getZoneModel()->getEntityByPK($uid); if ($this->_zone_entity === null) { throw new \Exception("Zone: [{$uid}] 정보를 찾을수 없습니다."); } $this->getService()->reload($this->_zone_entity); } public function reload(string $uid): RedirectResponse { return $this->reload_procedure($uid); } }