diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 87d462a..a31d88f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -113,14 +113,8 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf }); $routes->group('firewall', function ($routes) { $routes->get('/', 'FirewallController::index'); - $routes->get('create', 'FirewallController::create_form'); - $routes->post('create', 'FirewallController::create'); $routes->get('view/(:alphanum)', 'FirewallController::view/$1'); - $routes->get('delete/(:alphanum)', 'FirewallController::delete/$1'); - $routes->get('sync/(:alphanum)', 'FirewallController::sync/$1'); $routes->get('toggle/(:alphanum)/(:any)', 'FirewallController::toggle/$1/$2'); - $routes->post('batchjob', 'FirewallController::batcjob'); - $routes->post('batchjob_delete', 'FirewallController::batcjob_delete'); $routes->get('reload/(:alphanum)', 'FirewallController::reload/$1'); $routes->get('download/(:alpha)', 'FirewallController::download/$1'); }); diff --git a/app/Controllers/Admin/Cloudflare/FirewallController.php b/app/Controllers/Admin/Cloudflare/FirewallController.php index 42e7c05..2bcd13d 100644 --- a/app/Controllers/Admin/Cloudflare/FirewallController.php +++ b/app/Controllers/Admin/Cloudflare/FirewallController.php @@ -54,73 +54,16 @@ class FirewallController extends CloudflareController return $options; } //전송된 데이터 - protected function getFormData(string $field, array $formDatas): array - { - switch ($field) { - case 'hosts': - $formDatas[$field] = explode("\n", $this->request->getVar($field)); - if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { - throw new \Exception("호스트명이 정의되지 않았습니다."); - } - break; - default: - $formDatas = parent::getFormData($field, $formDatas); - break; - } - return $formDatas; - } private function init(string $action, array $fields = []): void { $this->action = $action; - $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, 'action', 'description', 'expression', 'ref', 'paused', 'updated_at', 'created_at']; + $this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, 'mode', 'description', 'expression', 'enabled', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->filter_fields = [$this->getModel()::PARENT, 'mode', 'paused']; + $this->filter_fields = [$this->getModel()::PARENT, 'mode', 'enabled']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); - $this->batchjob_fields = ['mode', 'paused']; - } - //생성 - public function create_form(): RedirectResponse|string - { - $this->init('create', [$this->getModel()::PARENT, 'action', 'description', 'expression', 'paused']); - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - //부모데이터 정의 - $parent_field = $this->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->create_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); - //부모데이터정의 - $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); - $this->entity = $this->getMyLibrary()->create( - $this->formDatas['mode'], - $this->formDatas['description'], - $this->formDatas['expression'], - $this->formDatas['paused'], - $this->formDatas['ref'] - ); - log_message("debug", message: "Firewall:{$this->entity->getTitle()} 생성 작업을 완료하였습니다."); - } - protected function create_process_result(): RedirectResponse|string - { - $this->init(__FUNCTION__); - return $this->view_process_result(); - } - public function create(): RedirectResponse|string - { - $this->init(__FUNCTION__, [$this->getModel()::PARENT, 'action', 'description', 'expression', 'paused']); - $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - return $this->create_procedure(); + $this->batchjob_fields = []; } //수정 (modify,toggle,batchjob사용) - public function modify_form(int $uid): RedirectResponse|string - { - $this->init('modify', [$this->getModel()::PARENT, 'action', 'description', 'expression', 'paused']); - return $this->modify_form_procedure($uid); - } protected function modify_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::modify_process($uid)하면 않됨 @@ -136,17 +79,6 @@ class FirewallController extends CloudflareController //Socket처리 $this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); } - public function modify(int $uid): RedirectResponse|string - { - $this->init(__FUNCTION__, [$this->getModel()::PARENT, 'action', 'description', 'expression', 'paused']); - return $this->modify_procedure($uid); - } - //일괄처리작업 - public function batcjob(): RedirectResponse - { - $this->init(__FUNCTION__); - return $this->batcjob_procedure(); - } //View //create_process_result에서 결과값을 entitys에 저장하고 호출하기때문에 아래와 같이 처리함 protected function view_process(mixed $uid): void @@ -174,20 +106,6 @@ class FirewallController extends CloudflareController $this->init(__FUNCTION__); return $this->view_procedure($uid); } - //삭제 - protected function delete_process(mixed $uid): void - { - //DB작업도 Socket에서 다 처리하므로 parent::delete_process($uid)하면 않됨 - //자신정보정의 - $this->entity = $this->getModel()->getEntityByPK($uid); - if ($this->entity === null) { - throw new \Exception("{$uid} 정보를 찾을수 없습니다."); - } - //부모데이터정의 - $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); - //Cloudflare 삭제 - $this->entity = $this->getMyLibrary()->delete($this->entity); - } // 리스트 protected function list_entitys_process(): array { @@ -229,23 +147,6 @@ class FirewallController extends CloudflareController $this->init(__FUNCTION__); return $this->download_procedure($output_type, $uid); } - //Sync작업 - protected function sync_process(string $uid): void - { - //자신정보정의 - $this->entity = $this->getModel()->getEntityByPK($uid); - if ($this->entity === null) { - throw new \Exception("{$uid} 정보를 찾을수 없습니다."); - } - //부모데이터정의 - $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); - //Socket처리 - $this->entity = $this->getMyLibrary()->sync($this->entity); - } - public function sync(string $uid): RedirectResponse - { - return $this->sync_procedure($uid); - } //reload Firewall By Zone protected function reload_process(mixed $uid): void { diff --git a/app/Entities/Cloudflare/FirewallEntity.php b/app/Entities/Cloudflare/FirewallEntity.php index 1dac62c..364e19d 100644 --- a/app/Entities/Cloudflare/FirewallEntity.php +++ b/app/Entities/Cloudflare/FirewallEntity.php @@ -9,7 +9,7 @@ class FirewallEntity extends CommonEntity { public function __toString() { - return "{$this->getPK()}|{$this->getParent()}|{$this->getTitle()}|{$this->attributes['host']}|{$this->attributes['content']}|{$this->attributes['proxied']}|{$this->attributes['fixed']}|{$this->attributes['locked']}"; + return "{$this->getPK()}|{$this->getParent()}|{$this->getTitle()}{$this->attributes['enabled']}"; } public function getPK(): string { @@ -28,4 +28,8 @@ class FirewallEntity extends CommonEntity { return $this->attributes[FirewallModel::PARENT]; } + public function getRulesetID(): string + { + return $this->attributes['rulesetid']; + } } diff --git a/app/Helpers/Cloudflare/FirewallHelper.php b/app/Helpers/Cloudflare/FirewallHelper.php index 8251dcd..8a5c604 100644 --- a/app/Helpers/Cloudflare/FirewallHelper.php +++ b/app/Helpers/Cloudflare/FirewallHelper.php @@ -34,17 +34,14 @@ class FirewallHelper extends MVCHelper case FirewallModel::TITLE: //host $form = form_input($field, $value, $extras); break; - case 'hosts': + case 'expression': $form = form_textarea($field, html_entity_decode($value), [ 'rows' => '5', ...$extras ]); break; - case 'expression': - $form = form_input($field, $value, ["placeholder" => "예)123.123.123.123", ...$extras]); - break; - case "action": - case "paused": + case "mode": + case "enabled": $form = form_dropdown($field, [ "" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택', ] + $viewDatas['field_options'][$field], $value, $extras); @@ -81,6 +78,17 @@ class FirewallHelper extends MVCHelper case FirewallModel::TITLE: $value = parent::getFieldView($field, $viewDatas, ['class' => "label_hosts", ...$extras]); break; + case 'expression': + // 값이 40자 이상인 경우 자르고 '...' 추가 + if (mb_strlen($value) > 40) { + $value = '' . + htmlspecialchars(mb_substr($value, 0, 40), ENT_QUOTES) . '...'; + $value .= ''; + } + break; + case 'mode': + $value = $viewDatas['field_options'][$field][$value]; + break; default: $value = parent::getFieldView($field, $viewDatas, $extras); break; @@ -90,31 +98,25 @@ class FirewallHelper extends MVCHelper public function getListRowColor($entity): string { - return $entity->paused != 'on' ? 'class="table-danger"' : ""; + return $entity->enabled != 'on' ? 'class="table-danger"' : ""; } public function getListButton(string $action, array $viewDatas, array $extras = []): string { switch ($action) { + case 'create': + $action = ""; + break; case 'modify': - $checkbox = ""; - if ($viewDatas['entity']->fixed != 'on') { - $pk = $viewDatas['entity']->getPK(); - $oldBatchJobUids = old("batchjob_uids") ?? []; - $oldBatchJobUids = is_array($oldBatchJobUids) ? $oldBatchJobUids : [$oldBatchJobUids]; - $checkbox = form_checkbox([ - "id" => "checkbox_uid_{$pk}", - "name" => "batchjob_uids[]", - "value" => $pk, - "class" => "batchjobuids_checkboxs", - "checked" => in_array($pk, $oldBatchJobUids) - ]); - } - $extras = ["target" => "_self", ...$extras]; - $action = $checkbox . anchor( - current_url() . "/sync/" . $viewDatas['entity']->getPK(), - $viewDatas['cnt'], - $extras - ); + $action = $viewDatas['cnt']; + break; + case 'delete': + $action = ""; + break; + case 'batchjob': + $action = ""; + break; + case 'batchjob_delete': + $action = ""; break; default: $action = parent::getListButton($action, $viewDatas, $extras); diff --git a/app/Helpers/Cloudflare/ZoneHelper.php b/app/Helpers/Cloudflare/ZoneHelper.php index cd3c879..a01b30c 100644 --- a/app/Helpers/Cloudflare/ZoneHelper.php +++ b/app/Helpers/Cloudflare/ZoneHelper.php @@ -91,14 +91,16 @@ class ZoneHelper extends MVCHelper $this->old_parent = $viewDatas['entity']->getParent(); break; case ZoneModel::TITLE: - $value = anchor( - base_url() . $viewDatas['uri_path'] . 'record/reload/' . $viewDatas['entity']->getPK(), - ICONS["RELOAD"], - [ - "class" => "btn btn-sm btn-primary btn-circle", - "target" => "_self" - ] - ) . " " . + $value = sprintf( + "
| %s %s | %s |
| %s %s |