From 8ce1c0ffb0fb62a9e07c71d59e77ef26a1371949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 3 Oct 2024 10:03:14 +0900 Subject: [PATCH] cfmgrv4 init...1 --- .../Admin/Cloudflare/AuthController.php | 4 +- .../Admin/Cloudflare/RecordController.php | 2 +- .../Admin/Cloudflare/ZoneController.php | 2 +- app/Controllers/Admin/MapurlController.php | 19 +- app/Controllers/Admin/UserController.php | 4 +- app/Controllers/MVController.php | 20 +- app/Helpers/Admin/Mapurl_helper.php | 28 + app/Models/CommonModel.php | 2 +- app/Views/admin/mapurl/remap_template.php | 15 + public/mapurl/index.html | 2692 +++++++++++++++++ 10 files changed, 2758 insertions(+), 30 deletions(-) create mode 100644 app/Views/admin/mapurl/remap_template.php create mode 100644 public/mapurl/index.html diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/AuthController.php index 2b1ebf9..b1cc7f8 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/AuthController.php @@ -41,7 +41,7 @@ class AuthController extends CloudflareController $this->init('create'); return $this->create_form_procedure(); } - public function create(): RedirectResponse + public function create(): RedirectResponse|string { $this->init(__FUNCTION__); return $this->create_procedure(); @@ -52,7 +52,7 @@ class AuthController extends CloudflareController $this->init('modify'); return $this->modify_form_procedure($uid); } - public function modify(string $uid): RedirectResponse + public function modify(string $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php index af74efb..990ae0c 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -95,7 +95,7 @@ class RecordController extends CloudflareController log_message("debug", "Record:{$entity->getTitle()} 생성 작업을 완료하였습니다."); } } - public function create(): RedirectResponse + public function create(): RedirectResponse|string { $this->init(__FUNCTION__); $this->create_validate($this->action, $this->fields); diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index ccfc155..cd2aeff 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -118,7 +118,7 @@ class ZoneController extends CloudflareController } } } - public function create(): RedirectResponse + public function create(): RedirectResponse|string { $this->init(__FUNCTION__); $this->create_validate($this->action, $this->fields); diff --git a/app/Controllers/Admin/MapurlController.php b/app/Controllers/Admin/MapurlController.php index c785d17..3a593dd 100644 --- a/app/Controllers/Admin/MapurlController.php +++ b/app/Controllers/Admin/MapurlController.php @@ -58,19 +58,8 @@ class MapurlController extends AdminController //모든 필요한 FormOption등 조기화작업 필요 $this->getModel()->where('status', DEFAULTS['STATUS']); $this->getModel()->orderBy('oldurl', 'ASC'); - //html의 case문 설정 - $urls = array(""); - foreach ($this->getModel()->getEntitys() as $entity) { - $temp_oldurl = sprintf("case '%s':", trim($entity->oldurl)); - //한글을 포함하고 있는지 체크 - if (preg_match("/[\xE0-\xFF][\x80-\xFF][\x80-\xFF]/", $entity->oldurl)) { - //도메인 URL 분리 - preg_match("/^(https?:\/\/)(.*)/", $entity->oldurl, $matches); - $temp_oldurl = sprintf("case '%s%s':\ncase '%s':", $matches[1], idn_to_ascii($matches[2]), trim($entity->oldurl)); - } - array_push($urls, sprintf("\t\t\t%s\n \t\t\twindow.location.href='%s';\n \t\tbreak;", $temp_oldurl, trim($entity->newurl))); - } - $remap_page = view($this->class_path . DIRECTORY_SEPARATOR . __FUNCTION__, ["urls" => $urls]); + $this->entitys = $this->getModel()->getEntitys(); + $remap_page = view($this->class_path . DIRECTORY_SEPARATOR . 'remap_template', ["viewDatas" => $this->getViewDatas()]); $remap_path = FCPATH . DIRECTORY_SEPARATOR . "mapurl"; //디렉토리 생성 여부 확인 if (!is_dir($remap_path)) { @@ -92,7 +81,7 @@ class MapurlController extends AdminController parent::create_process(); $this->remaping_process(); } - public function create(): RedirectResponse + public function create(): RedirectResponse|string { $this->init(__FUNCTION__); return $this->create_procedure(); @@ -109,7 +98,7 @@ class MapurlController extends AdminController parent::modify_process($uid); $this->remaping_process(); } - public function modify(string $uid): RedirectResponse + public function modify(string $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index d05e9d9..3d84cbb 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -90,7 +90,7 @@ class UserController extends AdminController $this->init('create'); return $this->create_form_procedure(); } - public function create(): RedirectResponse + public function create(): RedirectResponse|string { $this->init(__FUNCTION__); return $this->create_procedure(); @@ -123,7 +123,7 @@ class UserController extends AdminController $this->init('modify'); return $this->modify_form_procedure($uid); } - public function modify(string $uid): RedirectResponse + public function modify(string $uid): RedirectResponse|string { $this->init(__FUNCTION__); return $this->modify_procedure($uid); diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index 9a72980..a6ebef5 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -64,7 +64,7 @@ abstract class MVController extends CommonController //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 $this->validation = service('validation'); foreach ($fields as $field) { - $this->validation->setRule($field, $this->getModel()->getFieldRule($action, $field)); + $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); } if (!$this->validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( @@ -96,7 +96,7 @@ abstract class MVController extends CommonController $this->formDatas = $this->getFormDatas(); $this->entity = $this->getModel()->create(formDatas: $this->formDatas); } - final protected function create_procedure(): RedirectResponse + final protected function create_procedure(): RedirectResponse|string { //Transaction Start $this->getModel()->transStart(); @@ -104,8 +104,9 @@ abstract class MVController extends CommonController $this->create_process(); $this->getModel()->transCommit(); log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + // $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); + // return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + return alert_CommonHelper(__FUNCTION__ . " => 작업을 완료하였습니다.\n"); } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); @@ -120,7 +121,9 @@ abstract class MVController extends CommonController { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 $this->validation = service('validation'); - $this->validation->setRules($this->getModel()->getFieldRules($action, $fields)); + foreach ($fields as $field) { + $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); + } if (!$this->validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", @@ -162,7 +165,7 @@ abstract class MVController extends CommonController } $this->entity = $this->getModel()->modify($this->entity, $this->formDatas); } - final protected function modify_procedure(string $uid): RedirectResponse + final protected function modify_procedure(string $uid): RedirectResponse|string { //Transaction Start $this->getModel()->transStart(); @@ -170,8 +173,9 @@ abstract class MVController extends CommonController $this->modify_process($uid); $this->getModel()->transCommit(); log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + // $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); + // return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + return alert_CommonHelper(__FUNCTION__ . " => 작업을 완료하였습니다.\n"); } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); diff --git a/app/Helpers/Admin/Mapurl_helper.php b/app/Helpers/Admin/Mapurl_helper.php index af70b73..45010e4 100644 --- a/app/Helpers/Admin/Mapurl_helper.php +++ b/app/Helpers/Admin/Mapurl_helper.php @@ -98,3 +98,31 @@ function getListColumns_MapurlHelper(string $field, array $viewDatas, array $ext } return sprintf("%s", implode(" ", $extras), $label); } + +function getRemapPage_MapurlHelper(array $viewDatas): string +{ + $urls = []; + foreach ($viewDatas['entitys'] as $entity) { + //한글을 포함하고 있는지 체크 HTTP 나 HTTPS 와 도메인 분리해서 한글도메인을 Punycode로 변환 + if (preg_match("/[\xE0-\xFF][\x80-\xFF][\x80-\xFF]/", $entity->oldurl)) { + preg_match("/^(https?:\/\/)(.*)/", $entity->oldurl, $matches); + $oldurl = $matches[1] . idn_to_ascii($matches[2]); + } else { + $oldurl = trim($entity->oldurl); + } + $urls[] = sprintf( + "case '%s': window.location.href='%s'; break;", + $oldurl, + trim($entity->newurl) + ); + } + return sprintf(" + switch (window.location.origin) { + %s + default: + alert(window.location.origin + ' 지정되지 않은 URL입니다'); + history.go(-1); + break; + } + ", implode("\n", $urls)); +} diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 42d0f21..2137151 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -84,7 +84,7 @@ abstract class CommonModel extends Model $rule = $action == "create" ? "required" : "if_exist" . "|trim|string"; break; case "confirmpassword": - $rules["confirmpassword"] = $action == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]"; + $rule = $action == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]"; break; case "email": $rule = "if_exist|trim|valid_email"; diff --git a/app/Views/admin/mapurl/remap_template.php b/app/Views/admin/mapurl/remap_template.php new file mode 100644 index 0000000..d5d7349 --- /dev/null +++ b/app/Views/admin/mapurl/remap_template.php @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/public/mapurl/index.html b/public/mapurl/index.html new file mode 100644 index 0000000..d4161e8 --- /dev/null +++ b/public/mapurl/index.html @@ -0,0 +1,2692 @@ + + + + + + + + + + + + + +