From ff80c95c446919b37e5d64485c2897d163abe73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 15 Oct 2024 17:53:21 +0900 Subject: [PATCH] cfmgrv4 init...2 --- app/Config/Routes.php | 5 + .../Admin/Cloudflare/AccountController.php | 4 +- .../Admin/Cloudflare/AuthController.php | 12 +- .../Admin/Cloudflare/RecordController.php | 85 ++++++++------ .../Admin/Cloudflare/ZoneController.php | 105 ++++++++++++------ app/Controllers/Admin/MapurlController.php | 16 ++- app/Controllers/Admin/UserController.php | 12 +- app/Controllers/Admin/UserSNSController.php | 6 +- app/Controllers/MVController.php | 91 +++++++++------ app/Helpers/Cloudflare/RecordHelper.php | 13 +++ app/Helpers/Cloudflare/ZoneHelper.php | 2 +- app/Helpers/CommonHelper.php | 2 +- app/Language/en/Cloudflare/Record.php | 1 - app/Models/Cloudflare/RecordModel.php | 5 +- app/Models/Cloudflare/ZoneModel.php | 16 ++- app/Views/admin/cloudflare/record/view.php | 10 +- app/Views/admin/cloudflare/zone/create.php | 33 ++++++ app/Views/admin/cloudflare/zone/view.php | 38 +++---- app/Views/{front => admin}/view.php | 4 +- app/Views/front/create.php | 35 ------ app/Views/front/index.php | 57 ---------- app/Views/front/login.php | 27 ----- app/Views/front/modify.php | 34 ------ 23 files changed, 306 insertions(+), 307 deletions(-) create mode 100644 app/Views/admin/cloudflare/zone/create.php rename app/Views/{front => admin}/view.php (89%) delete mode 100644 app/Views/front/create.php delete mode 100644 app/Views/front/index.php delete mode 100644 app/Views/front/login.php delete mode 100644 app/Views/front/modify.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 17c681f..a1a8275 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,6 +33,7 @@ $routes->group('admin/mapurl', ['namespace' => 'App\Controllers\Admin', 'filter' $routes->post('create', 'MapurlController::create'); $routes->get('modify/(:num)', 'MapurlController::modify_form/$1'); $routes->post('modify/(:num)', 'MapurlController::modify/$1'); + $routes->get('view/(:num)', 'MapurlController::view/$1'); $routes->get('delete/(:num)', 'MapurlController::delete/$1'); $routes->get('toggle/(:num)/(:any)', 'MapurlController::toggle/$1/$2'); $routes->post('batchjob', 'MapurlController::batcjob'); @@ -44,6 +45,7 @@ $routes->group('admin/user', ['namespace' => 'App\Controllers\Admin', 'filter' = $routes->post('create', 'UserController::create'); $routes->get('modify/(:num)', 'UserController::modify_form/$1'); $routes->post('modify/(:num)', 'UserController::modify/$1'); + $routes->get('view/(:num)', 'UserController::view/$1'); $routes->get('delete/(:num)', 'UserController::delete/$1'); $routes->get('toggle/(:num)/(:any)', 'UserController::toggle/$1/$2'); $routes->post('batchjob', 'UserController::batcjob'); @@ -63,6 +65,7 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf $routes->get('create', 'AuthController::create_form'); $routes->post('create', 'AuthController::create'); $routes->get('modify/(:num)', 'AuthController::modify_form/$1'); + $routes->get('view/(:num)', 'AuthController::view/$1'); $routes->get('delete/(:num)', 'AuthController::delete/$1'); $routes->get('toggle/(:num)/(:any)', 'AuthController::toggle/$1/$2'); $routes->post('batchjob', 'AuthController::batcjob'); @@ -77,6 +80,7 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf $routes->get('/', 'ZoneController::index'); $routes->get('create', 'ZoneController::create_form'); $routes->post('create', 'ZoneController::create'); + $routes->get('view/(:alphanum)', 'ZoneController::view/$1'); $routes->get('delete/(:alphanum)', 'ZoneController::delete/$1'); $routes->get('sync/(:alphanum)', 'ZoneController::sync/$1'); $routes->get('toggle/(:alphanum)/(:any)', 'ZoneController::toggle/$1/$2'); @@ -88,6 +92,7 @@ $routes->group('admin/cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudf $routes->get('/', 'RecordController::index'); $routes->get('create', 'RecordController::create_form'); $routes->post('create', 'RecordController::create'); + $routes->get('view/(:alphanum)', 'RecordController::view/$1'); $routes->get('delete/(:alphanum)', 'RecordController::delete/$1'); $routes->get('sync/(:alphanum)', 'RecordController::sync/$1'); $routes->get('toggle/(:alphanum)/(:any)', 'RecordController::toggle/$1/$2'); diff --git a/app/Controllers/Admin/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/AccountController.php index 5c33c94..079988b 100644 --- a/app/Controllers/Admin/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/AccountController.php @@ -65,7 +65,7 @@ class AccountController extends CloudflareController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'status', 'updated_at', 'created_at']; @@ -78,7 +78,7 @@ class AccountController extends CloudflareController //reload Account By Auth protected function reload_process(mixed $uid): void { - $this->_auth_entity = $this->getAuthModel()->getEntityByPK(intval($uid)); + $this->_auth_entity = $this->getAuthModel()->getEntityByPK($uid); if ($this->_auth_entity === null) { throw new \Exception("Auth: {$uid} 정보를 찾을수 없습니다."); } diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/AuthController.php index f07bbf5..63605c3 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/AuthController.php @@ -48,12 +48,12 @@ class AuthController extends CloudflareController return $this->create_procedure(); } //수정 - public function modify_form(string $uid): RedirectResponse|string + public function modify_form(int $uid): RedirectResponse|string { $this->init('modify'); return $this->modify_form_procedure($uid); } - public function modify(string $uid): RedirectResponse|string + public function modify(int $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); @@ -66,6 +66,12 @@ class AuthController extends CloudflareController $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->batcjob_procedure(); } + //View + public function view(int $uid): RedirectResponse|string + { + $this->init(__FUNCTION__); + return $this->view_procedure($uid); + } // 리스트 public function index(): string { @@ -78,7 +84,7 @@ class AuthController extends CloudflareController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at']; diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php index 484ae54..57773b9 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -72,7 +72,7 @@ class RecordController extends CloudflareController private function init(string $action): void { $this->action = $action; - $this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'hosts']; + $this->fields = [$this->getModel()::PARENT, 'hosts', 'type', 'content', 'proxied']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); @@ -90,6 +90,10 @@ class RecordController extends CloudflareController //hosts를 제외한 fields Valid처리 parent::create_validate($action, array_diff($fields, ['hosts'])); } + private function setEntitys(array $entitys): void + { + $this->entitys = $entitys; + } protected function create_process(): void { //DB작업도 Socket에서 다 처리하므로 parent::create_process()하면 않됨 @@ -102,7 +106,7 @@ class RecordController extends CloudflareController foreach ($this->formDatas['hosts'] as $host) { //호스트명 형식확인 if (!$this->helper->isHost($host)) { - throw new \Exception("{$this->_zone_entity->getTitle()}의 {$cnt}번째 {$host} 호스트명 형식 오류"); + throw new \Exception("{$host} 호스트명 형식 오류"); } $cnt++; } @@ -118,16 +122,15 @@ class RecordController extends CloudflareController log_message("debug", message: "Record:{$entity->getTitle()} 생성 작업을 완료하였습니다."); $entitys[] = $entity; } - $this->entitys = $entitys; + $this->setEntitys($entitys); // 새로운 메서드를 사용하여 entitys 설정 } - protected function create_result(): string + protected function create_process_result(): RedirectResponse|string { - $this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'host']; + $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - return view( - $this->view_path . strtolower($this->class_path) . "/view", - data: ['viewDatas' => $this->getViewDatas()] - ); + $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); + return $this->view_process_result(); } public function create(): RedirectResponse|string { @@ -135,7 +138,7 @@ class RecordController extends CloudflareController return $this->create_procedure(); } //수정 (modify,toggle,batchjob사용) - protected function modify_process(string $uid): void + protected function modify_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::modify_process($uid)하면 않됨 $this->modify_validate($this->action, $this->fields); @@ -158,13 +161,6 @@ class RecordController extends CloudflareController $this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); } } - protected function modify_result(): string - { - return view( - $this->view_path . strtolower($this->class_path) . "/view", - data: ['viewDatas' => $this->getViewDatas()] - ); - } //일괄처리작업 public function batcjob(): RedirectResponse { @@ -173,25 +169,33 @@ class RecordController extends CloudflareController $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->batcjob_procedure(); } - //Sync작업 - protected function sync_process(string $uid): void + //View + protected function view_process(mixed $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); + //해당 Zone의 모든 Record를 가져오기 + $this->getModel()->where($this->getModel()::PARENT, $uid); + $this->entitys = $this->getModel()->getEntitys(); } - public function sync(string $uid): RedirectResponse + protected function view_process_result(): string { - return $this->sync_procedure($uid); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return view( + strtolower($this->view_path . $this->class_path . "/view"), + data: ['viewDatas' => $this->getViewDatas()] + ); + } + public function view(string $uid): RedirectResponse|string + { + $this->action = __FUNCTION__; + $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied', 'fixed']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); + return $this->view_procedure($uid); } //삭제 - protected function delete_process(string $uid): void + protected function delete_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::delete_process($uid)하면 않됨 //자신정보정의 @@ -245,7 +249,7 @@ class RecordController extends CloudflareController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; @@ -255,6 +259,23 @@ class RecordController extends CloudflareController $this->batchjob_fields = ['proxied']; 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 Record By Zone protected function reload_process(mixed $uid): void { diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index 841510f..8c3a411 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -69,7 +69,7 @@ class ZoneController extends CloudflareController } break; case 'hosts': - $formDatas[$field] = $this->request->getVar($field); + $formDatas[$field] = explode("\n", $this->request->getVar($field)); if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { throw new \Exception("호스트명이 정의되지 않았습니다"); } @@ -101,6 +101,10 @@ class ZoneController extends CloudflareController //domains,hosts를 제외한 fields Valid처리 parent::create_validate($action, array_diff($fields, ['domains', 'hosts'])); } + private function setEntitys(array $entitys): void + { + $this->entitys = $entitys; + } protected function create_process(): void { //DB작업도 Socket에서 다 처리하므로 parent::create_process()하면 않됨 @@ -112,18 +116,18 @@ class ZoneController extends CloudflareController //Type이 A형식일경우 IP형태인지 확인 if ($this->formDatas['type'] === 'A') { if (!$this->helper->isIPAddress($this->formDatas['content'], $this->formDatas['type'])) { - throw new \Exception("{$this->_account_entity->getTitle()}의 {$this->formDatas['type']}, {$this->formDatas['content']} 형식 오류[사설IP 않됨]"); + throw new \Exception("{$this->formDatas['type']}, {$this->formDatas['content']} 형식 오류[사설IP 않됨]"); } } $cnt = 1; foreach ($this->formDatas['domains'] as $domain) { //도메인명 형식확인 if (!$this->helper->isDomain($domain)) { - throw new \Exception("{$this->_account_entity->getTitle()}의 {$cnt}번째 {$domain} 형식 오류"); + throw new \Exception("{$domain} 형식 오류"); } //도메인명이 해당계정의 유일한 도메인인지 확인 if (!$this->getModel()->isUniqueDomain($this->_account_entity, $domain)) { - throw new \Exception("{$this->_account_entity->getTitle()}의 {$cnt}번째 {$domain}은 이미 등록된 도메인입니다."); + throw new \Exception("{$domain}은 이미 등록된 도메인입니다."); } $cnt++; } @@ -131,7 +135,7 @@ class ZoneController extends CloudflareController foreach ($this->formDatas['hosts'] as $host) { //호스트명 형식확인 if (!$this->helper->isHost($host)) { - throw new \Exception("{$this->_account_entity->getTitle()}의 {$cnt}번째 {$host} 호스트명 형식 오류"); + throw new \Exception("{$host} 호스트명 형식 오류"); } $cnt++; } @@ -146,7 +150,7 @@ class ZoneController extends CloudflareController $cnt++; } //Record생성 - $this->entitys = []; + $entitys = []; foreach ($zone_entitys as $zone_entity) { $record = new Record($zone_entity); $record_entitys = []; @@ -161,15 +165,17 @@ class ZoneController extends CloudflareController $record_entitys[] = $entity; } $zone_entity->records = $record_entitys; - $this->entitys[] = $zone_entity; + $entitys[] = $zone_entity; } + $this->setEntitys($entitys); } - protected function create_result(): string + protected function create_process_result(): RedirectResponse|string { - return view( - $this->view_path . strtolower($this->class_path) . DIRECTORY_SEPARATOR . "view", - data: ['viewDatas' => $this->getViewDatas()] - ); + $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); + return $this->view_process_result(); } public function create(): RedirectResponse|string { @@ -177,7 +183,7 @@ class ZoneController extends CloudflareController return $this->create_procedure(); } //수정 (modify,toggle,batchjob사용) - protected function modify_process(string $uid): void + protected function modify_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::modify_process($uid)하면 않됨 $this->modify_validate($this->action, $this->fields); @@ -192,13 +198,6 @@ class ZoneController extends CloudflareController //Socket처리 $this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); } - protected function modify_result(): string - { - return view( - $this->view_path . strtolower($this->class_path) . DIRECTORY_SEPARATOR . "view", - data: ['viewDatas' => $this->getViewDatas()] - ); - } //일괄처리작업 public function batcjob(): RedirectResponse { @@ -207,25 +206,38 @@ class ZoneController extends CloudflareController $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->batcjob_procedure(); } - //Sync작업 - protected function sync_process(mixed $uid): void + //View + protected function view_process(mixed $uid): void { - //자신정보정의 - $this->entity = $this->getModel()->getEntityByPK($uid); - if ($this->entity === null) { - throw new \Exception("{$uid} 정보를 찾을수 없습니다."); + //해당 Account의 모든 Zone를 가져오기 + $this->getModel()->where($this->getModel()::PARENT, $uid); + $entitys = $this->getModel()->getEntitys(); + foreach ($entitys as $entity) { + $this->getRecordModel()->where($this->getRecordModel()::PARENT, $entity->getPK()); + $entity->records = $this->getRecordModel()->getEntitys(); } - //부모데이터정의 - $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); - //Socket처리 - $this->entity = $this->getMyLibrary()->sync($this->entity); + $this->entitys = $entitys; } - public function sync(string $uid): RedirectResponse + protected function view_process_result(): string { - return $this->sync_procedure($uid); + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return view( + strtolower($this->view_path . $this->class_path . "/view"), + data: ['viewDatas' => $this->getViewDatas()] + ); + } + public function view(string $uid): RedirectResponse|string + { + $this->action = __FUNCTION__; + $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; + $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); + $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level']; + $this->field_options = $this->getFormFieldOptions($this->filter_fields); + return $this->view_procedure($uid); } //삭제 - protected function delete_process(string $uid): void + protected function delete_process(mixed $uid): void { //DB작업도 Socket에서 다 처리하므로 parent::delete_process($uid)하면 않됨 //자신정보정의 @@ -233,9 +245,15 @@ class ZoneController extends CloudflareController if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } + //Record부터 삭제필요 + $this->getRecordModel()->where($this->getRecordModel()::PARENT, $this->entity->getPK()); + foreach ($this->getRecordModel()->getEntitys() as $record_entity) { + $record = new Record($this->entity); + $record->delete($record_entity); + } + //Zone 삭제 //부모데이터정의 $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); - //Cloudflare 삭제 $this->entity = $this->getMyLibrary()->delete($this->entity); } // 리스트 @@ -279,7 +297,7 @@ class ZoneController extends CloudflareController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; @@ -289,6 +307,23 @@ class ZoneController extends CloudflareController $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; return $this->download_procedure($output_type, $uid); } + //Sync작업 + protected function sync_process(mixed $uid): void + { + //자신정보정의 + $this->entity = $this->getModel()->getEntityByPK($uid); + if ($this->entity === null) { + throw new \Exception("{$uid} 정보를 찾을수 없습니다."); + } + //부모데이터정의 + $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); + //Socket처리 + $this->entity = $this->getMyLibrary()->sync($this->entity); + } + public function sync(string $uid): RedirectResponse + { + return $this->sync_procedure($uid); + } //reload Zone By Account protected function reload_process(mixed $uid): void { diff --git a/app/Controllers/Admin/MapurlController.php b/app/Controllers/Admin/MapurlController.php index 6dfa708..f142260 100644 --- a/app/Controllers/Admin/MapurlController.php +++ b/app/Controllers/Admin/MapurlController.php @@ -89,18 +89,18 @@ class MapurlController extends AdminController return $this->create_procedure(); } //수정 - public function modify_form(string $uid): RedirectResponse|string + public function modify_form(int $uid): RedirectResponse|string { $this->init('modify'); return $this->modify_form_procedure($uid); } //(modify,toggle,batchjob사용) - protected function modify_process(string $uid): void + protected function modify_process(mixed $uid): void { parent::modify_process($uid); $this->remaping_process(); } - public function modify(string $uid): RedirectResponse|string + public function modify(int $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); @@ -113,8 +113,14 @@ class MapurlController extends AdminController $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->batcjob_procedure(); } + //View + public function view(int $uid): RedirectResponse|string + { + $this->init(__FUNCTION__); + return $this->view_procedure($uid); + } //삭제 - protected function delete_process(string $uid): void + protected function delete_process(mixed $uid): void { parent::delete_process($uid); $this->remaping_process(); @@ -132,7 +138,7 @@ class MapurlController extends AdminController } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 460ec22..5b4769f 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -100,12 +100,12 @@ class UserController extends AdminController return $this->create_procedure(); } //수정 - public function modify_form(string $uid): RedirectResponse|string + public function modify_form(int $uid): RedirectResponse|string { $this->init('modify'); return $this->modify_form_procedure($uid); } - public function modify(string $uid): RedirectResponse|string + public function modify(int $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); @@ -118,6 +118,12 @@ class UserController extends AdminController $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); return $this->batcjob_procedure(); } + //View + public function view(int $uid): RedirectResponse|string + { + $this->init(__FUNCTION__); + return $this->view_procedure($uid); + } // 리스트 public function index(): string { @@ -130,7 +136,7 @@ class UserController extends AdminController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'status']; diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index 3d32551..477dd40 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -74,12 +74,12 @@ class UserSNSController extends AdminController $this->field_options = $this->getFormFieldOptions($this->filter_fields); } //수정 - public function modify_form(string $uid): RedirectResponse|string + public function modify_form(int $uid): RedirectResponse|string { $this->init('modify'); return $this->modify_form_procedure($uid); } - public function modify(string $uid): RedirectResponse|string + public function modify(int $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); @@ -104,7 +104,7 @@ class UserSNSController extends AdminController return $this->list_procedure(); } // Download - public function download(string $output_type, $uid = false): DownloadResponse|string + public function download(string $output_type, mixed $uid = false): DownloadResponse|string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::PARENT, 'site', 'id', $this->getModel()::TITLE, 'email', 'status']; diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 6a8e85b..666bfa5 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -77,9 +77,7 @@ abstract class MVController extends CommonController return $formDatas; } // 생성 - protected function create_form_process(): void - { - } + protected function create_form_process(): void {} final protected function create_form_procedure(): RedirectResponse|string { try { @@ -112,12 +110,10 @@ abstract class MVController extends CommonController $this->formDatas = $this->getFormDatas(); $this->entity = $this->getModel()->create(formDatas: $this->formDatas); } - protected function create_result(): string + protected function create_process_result(): RedirectResponse|string { - return view( - $this->view_path . "view", - data: ['viewDatas' => $this->getViewDatas()] - ); + $url = strtolower(base_url() . $this->uri_path . "/" . $this->class_path . "/view/" . $this->entity->getPK()); + return redirect()->to($url)->with('error', $this->message); } final protected function create_procedure(): RedirectResponse|string { @@ -128,7 +124,8 @@ abstract class MVController extends CommonController $this->create_process(); $this->getModel()->transCommit(); $this->message = "{$this->class_name} : 생성작업이 완료되었습니다."; - return $this->create_result(); + log_message("notice", $this->message); + return $this->create_process_result(); } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); @@ -137,14 +134,14 @@ abstract class MVController extends CommonController } } // 수정 - protected function modify_form_process(string $uid): void + protected function modify_form_process(mixed $uid): void { - $this->entity = $this->getModel()->getEntityByPK(intval($uid)); + $this->entity = $this->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("해당 정보를 찾을수 없습니다."); } } - final protected function modify_form_procedure(string $uid): RedirectResponse|string + final protected function modify_form_procedure(mixed $uid): RedirectResponse|string { try { helper(['form']); @@ -170,7 +167,7 @@ abstract class MVController extends CommonController )); } } - protected function modify_process(string $uid): void + protected function modify_process(mixed $uid): void { $this->modify_validate($this->action, $this->fields); $this->formDatas = $this->getFormDatas(); @@ -181,14 +178,12 @@ abstract class MVController extends CommonController } $this->entity = $this->getModel()->modify($this->entity, $this->formDatas); } - protected function modify_result(): string + protected function modify_process_result(): RedirectResponse|string { - return view( - $this->view_path . "view", - data: ['viewDatas' => $this->getViewDatas()] - ); + $url = strtolower(base_url() . $this->uri_path . "/" . $this->class_path . "/view/" . $this->entity->getPK()); + return redirect()->to($url)->with('error', $this->message); } - final protected function modify_procedure(string $uid): RedirectResponse|string + final protected function modify_procedure(mixed $uid): RedirectResponse|string { //Transaction Start $this->getModel()->transStart(); @@ -197,7 +192,8 @@ abstract class MVController extends CommonController $this->modify_process($uid); $this->getModel()->transCommit(); $this->message = "{$this->class_name} : 수정작업이 완료되었습니다."; - return $this->modify_result(); + log_message("notice", $this->message); + return $this->modify_process_result(); } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); @@ -206,7 +202,7 @@ abstract class MVController extends CommonController } } //일괄처리작업 - final protected function batcjob_procedure(): RedirectResponse + final protected function batcjob_procedure(): RedirectResponse|string { //Transaction Start $this->getModel()->transStart(); @@ -219,8 +215,9 @@ abstract class MVController extends CommonController foreach (explode(",", $uids) as $uid) { $this->modify_process($uid); } + $this->getModel()->transCommit(); $this->message = "{$this->class_name} : 일괄처리작업이 완료되었습니다."; - log_message("notice", __FUNCTION__ . $this->message); + log_message("notice", $this->message); // 이전 URL로 리다이렉트 return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); } catch (\Exception $e) { @@ -231,7 +228,7 @@ abstract class MVController extends CommonController } } //단일필드작업 - final public function toggle(string $uid, string $field): RedirectResponse + final public function toggle(mixed $uid, string $field): RedirectResponse { //Transaction Start $this->getModel()->transStart(); @@ -239,9 +236,9 @@ abstract class MVController extends CommonController $this->action = __FUNCTION__; $this->fields = [$field]; $this->modify_process($uid); - $this->message = "{$this->class_name} : Toggle 수정작업이 완료되었습니다."; $this->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . $this->message); + $this->message = "{$this->class_name} : 단일필드작업이 완료되었습니다."; + log_message("notice", $this->message); // 이전 URL로 리다이렉트 return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); } catch (\Exception $e) { @@ -251,25 +248,53 @@ abstract class MVController extends CommonController return redirect()->back()->with('error', __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); } } - //삭제 - protected function delete_process(string $uid): void + //View + protected function view_process(mixed $uid): void { //자신정보정의 - $this->entity = $this->getModel()->getEntityByPK(intval($uid)); + $this->entity = $this->getModel()->getEntityByPK($uid); + if ($this->entity === null) { + throw new \Exception("해당 정보를 찾을수 없습니다."); + } + } + protected function view_process_result(): string + { + helper(['form']); + $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; + return view( + $this->view_path . "view", + data: ['viewDatas' => $this->getViewDatas()] + ); + } + final protected function view_procedure(mixed $uid): RedirectResponse|string + { + try { + $this->view_process($uid); + return $this->view_process_result(); + } catch (\Exception $e) { + log_message("error", $e->getMessage()); + return redirect()->back()->with('error', $e->getMessage()); + } + } + //삭제 + protected function delete_process(mixed $uid): void + { + //자신정보정의 + $this->entity = $this->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } $this->entity = $this->getModel()->delete($this->entity->getPK()); } - final public function delete(string $uid): RedirectResponse + final public function delete(mixed $uid): RedirectResponse { //Transaction Start $this->getModel()->transStart(); try { $this->delete_process($uid); - $this->message = "{$this->class_name} : 삭제작업이 완료되었습니다."; $this->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . $this->message); + $this->message = "{$this->class_name} : 삭제작업이 완료되었습니다."; + log_message("notice", $this->message); // 이전 URL로 리다이렉트 return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); } catch (\Exception $e) { @@ -406,7 +431,7 @@ abstract class MVController extends CommonController return array($full_path, $file_name); } //File Download관련 - final protected function download_procedure(string $output_type, $uid = false): DownloadResponse|RedirectResponse + final protected function download_procedure(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse { try { helper(['form']); @@ -431,7 +456,7 @@ abstract class MVController extends CommonController if (!$uid) { throw new \Exception("{$output_type}은 반드시 uid의 값이 필요합니다."); } - $this->entity = $this->getModel()->getEntityByPK(intval($uid)); + $this->entity = $this->getModel()->getEntityByPK($uid); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } diff --git a/app/Helpers/Cloudflare/RecordHelper.php b/app/Helpers/Cloudflare/RecordHelper.php index f37fbf1..f841980 100644 --- a/app/Helpers/Cloudflare/RecordHelper.php +++ b/app/Helpers/Cloudflare/RecordHelper.php @@ -12,6 +12,19 @@ class RecordHelper extends CommonHelper { parent::__construct(); } + public function getFieldLabel(string $field, array $viewDatas, array $extras = []): string + { + switch ($field) { + case 'hosts': + $extras = ["class" => 'text-danger', ...$extras]; + $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras); + break; + default: + $label = parent::getFieldLabel($field, $viewDatas, $extras); + break; + } + return $label; + } public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string { $value = $value ?: DEFAULTS['EMPTY']; diff --git a/app/Helpers/Cloudflare/ZoneHelper.php b/app/Helpers/Cloudflare/ZoneHelper.php index 01ef77b..ad09981 100644 --- a/app/Helpers/Cloudflare/ZoneHelper.php +++ b/app/Helpers/Cloudflare/ZoneHelper.php @@ -32,7 +32,7 @@ class ZoneHelper extends CommonHelper $form = form_textarea($field, $value, ['rows' => '5', ...$extras]); break; case 'hosts': - $form = form_textarea($field, $value == DEFAULTS['EMPTY'] ? "@\n*\nm\nwww" : $value, [ + $form = form_textarea($field, $value == DEFAULTS['EMPTY'] ? "*\nm\nwww" : $value, [ 'rows' => '5', ...$extras ]); diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index e90d524..a079b4e 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -134,7 +134,7 @@ abstract class CommonHelper switch ($field) { default: if (strpos($viewDatas['field_rules'][$field], 'required') !== false) { - $extras = ["class" => 'text-danger', ...$extras]; + $extras = ["class" => "text-danger ", ...$extras]; } $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras); break; diff --git a/app/Language/en/Cloudflare/Record.php b/app/Language/en/Cloudflare/Record.php index d616a57..3d77653 100644 --- a/app/Language/en/Cloudflare/Record.php +++ b/app/Language/en/Cloudflare/Record.php @@ -19,7 +19,6 @@ return [ "ZONE_UID" => [], "TYPE" => [ 'A' => 'A', - 'AAAA' => 'AAAA(ipv6)', 'CNAME' => 'CNAME', 'NS' => 'NS', 'MX' => 'MX', diff --git a/app/Models/Cloudflare/RecordModel.php b/app/Models/Cloudflare/RecordModel.php index ecab865..559b56d 100644 --- a/app/Models/Cloudflare/RecordModel.php +++ b/app/Models/Cloudflare/RecordModel.php @@ -42,7 +42,7 @@ class RecordModel extends CommonModel $rule = "required|trim|string"; break; case "type": - $rule = "required|in_list[A,AAAA,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]"; + $rule = "required|in_list[A,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]"; break; case "ttl": $rule = "if_exist|numeric"; @@ -55,6 +55,9 @@ class RecordModel extends CommonModel case "locked": $rule = "if_exist|in_list[on,off]"; break; + case "hosts": //create form에서 사용 + $rule = "required|string"; + break; default: $rule = parent::getFieldRule($action, $field); break; diff --git a/app/Models/Cloudflare/ZoneModel.php b/app/Models/Cloudflare/ZoneModel.php index b85e05a..16cbcec 100644 --- a/app/Models/Cloudflare/ZoneModel.php +++ b/app/Models/Cloudflare/ZoneModel.php @@ -51,6 +51,21 @@ class ZoneModel extends CommonModel case "status": $rule = "if_exist|in_list[active,pending,moved]"; break; + case "domains": //create form에서 사용 + $rule = "required|string"; + break; + case "hosts": //create form에서 사용 + $rule = "required|string"; + break; + case "type": //create form에서 사용 + $rule = "required|in_list[A,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]"; + break; + case "content": //create form에서 사용 + $rule = "required|trim|string"; + break; + case "proxied": //create form에서 사용 + $rule = "required|in_list[on,off]"; + break; default: $rule = parent::getFieldRule($action, $field); break; @@ -105,7 +120,6 @@ class ZoneModel extends CommonModel { //Record의 content(IP검색)을 하기위함 //Join 방식사용 - $this->select(self::TABLE . '.*')->distinct(); $this->join(RecordModel::TABLE, sprintf( "%s.%s=%s.%s", self::TABLE, diff --git a/app/Views/admin/cloudflare/record/view.php b/app/Views/admin/cloudflare/record/view.php index fa66ae6..835c0cb 100644 --- a/app/Views/admin/cloudflare/record/view.php +++ b/app/Views/admin/cloudflare/record/view.php @@ -5,28 +5,20 @@
- - - - - - -
번호 getFieldLabel($field, $viewDatas) ?>
getFieldView($field, $viewDatas) ?>
-
-
+ {$viewDatas['message']}
" : '' ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/cloudflare/zone/create.php b/app/Views/admin/cloudflare/zone/create.php new file mode 100644 index 0000000..a275e72 --- /dev/null +++ b/app/Views/admin/cloudflare/zone/create.php @@ -0,0 +1,33 @@ +extend(LAYOUTS[$viewDatas['layout']]['path']) ?> +section('content') ?> +
+ +
+ + + + + + + + + + + + + + records): ?> + + + + + +
getFieldLabel($field, $viewDatas) ?>
getFieldView($field, $viewDatas) ?>
+ records as $record): ?> +
getTitle() ?>
+ +
+ {$viewDatas['message']}
" : '' ?> +
+ +endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/cloudflare/zone/view.php b/app/Views/admin/cloudflare/zone/view.php index eaf86ae..a275e72 100644 --- a/app/Views/admin/cloudflare/zone/view.php +++ b/app/Views/admin/cloudflare/zone/view.php @@ -4,36 +4,30 @@
+ + + + + - - - + - - - - - - - - - - + records): ?> + + + + - - -
getFieldLabel($field, $viewDatas) ?>
번호getFieldLabel($field, $viewDatas) ?>getFieldView($field, $viewDatas) ?>
getFieldView($field, $viewDatas, $viewDatas) ?>
- records as $record): ?> - getTitle() ?> - -
+ records as $record): ?> +
getTitle() ?>
+ +
-
-
+ {$viewDatas['message']}
" : '' ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/front/view.php b/app/Views/admin/view.php similarity index 89% rename from app/Views/front/view.php rename to app/Views/admin/view.php index ecb2f51..e6c3ba4 100644 --- a/app/Views/front/view.php +++ b/app/Views/admin/view.php @@ -9,14 +9,14 @@ getFieldLabel($field, $viewDatas) ?> - getFieldView($field, $viewDatas, $viewDatas) ?> + getFieldView($field, $viewDatas) ?> -
+
diff --git a/app/Views/front/create.php b/app/Views/front/create.php deleted file mode 100644 index 9ae9eff..0000000 --- a/app/Views/front/create.php +++ /dev/null @@ -1,35 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -
- - -
- - - - - - - - - - - - -
getFieldLabel($field, $viewDatas) ?> - "form-control"]; - if (strpos($viewDatas['field_rules'][$field], 'required') !== false) { - $extras = ["required" => "", ...$extras]; - } - ?> - getFieldForm($field, old($field), $viewDatas, $extras) ?> -
-
- "btn btn-outline btn-primary")); ?> -
- -
-
- -endSection() ?> \ No newline at end of file diff --git a/app/Views/front/index.php b/app/Views/front/index.php deleted file mode 100644 index 300cb1e..0000000 --- a/app/Views/front/index.php +++ /dev/null @@ -1,57 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -
include(LAYOUTS[$viewDatas['layout']]['path'] . '/top'); ?>
-
-
include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
-
- include("templates/{$viewDatas['layout']}/index_header"); ?> -
- - -
- include("templates/{$viewDatas['layout']}/index_content_top"); ?> - - - - - - - - - - - - - - getListRowColor($entity) ?>> - - - - - - - - - - - -
번호getListLabel($field, $viewDatas) ?>작업
- getListButton('modify', $viewDatas) ?> - getFieldView($field, $viewDatas) ?> - getListButton('delete', $viewDatas) ?> -
- include("templates/{$viewDatas['layout']}/index_content_batchjob"); ?> -
-
-
include("templates/common/modal_fetch"); ?>
- - -
- -
-
-
- include(LAYOUTS[$viewDatas['layout']]['path'] . '/bottom'); ?> -
-endSection() ?> \ No newline at end of file diff --git a/app/Views/front/login.php b/app/Views/front/login.php deleted file mode 100644 index f77b94d..0000000 --- a/app/Views/front/login.php +++ /dev/null @@ -1,27 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -
-
-
- - -
-
- endSection() ?> \ No newline at end of file diff --git a/app/Views/front/modify.php b/app/Views/front/modify.php deleted file mode 100644 index 18f05b1..0000000 --- a/app/Views/front/modify.php +++ /dev/null @@ -1,34 +0,0 @@ -extend(LAYOUTS[$viewDatas['layout']]['path']) ?> -section('content') ?> -
- - 'action_form', ...$viewDatas['forms']['attributes']], $viewDatas['forms']['hiddens']) ?> -
- - - - - - - - - - - - -
getFieldLabel($field, $viewDatas) ?> - 'form-control']; - if (strpos($viewDatas['field_rules'][$field], 'required') !== false) { - $extras = ["required" => "", ...$extras]; - } - ?> - getFieldForm($field, old($field) ?? $viewDatas['entity']->$field, $viewDatas, $extras) ?> -
-
- "btn btn-outline btn-primary"]) ?> -
- -
-
-endSection() ?> \ No newline at end of file