From 05708325558ca247e975b374ba76d864d31e8a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 19 Jun 2023 16:38:30 +0900 Subject: [PATCH] cfmgrv3 init...2 --- app/Config/Routes.php | 12 +-- app/Controllers/Admin/AdminController.php | 5 +- .../Admin/Cloudflare/API/APIController.php | 100 ++++++++++++++++++ .../{ => API}/AccountController.php | 14 +-- .../Cloudflare/{ => API}/AuthController.php | 12 +-- .../{ => API}/FirewallController.php | 27 ++--- .../Cloudflare/{ => API}/RecordController.php | 35 +++--- .../Cloudflare/{ => API}/ZoneController.php | 35 +++--- .../Admin/Cloudflare/CloudflareController.php | 94 ++-------------- app/Controllers/Admin/LoggerController.php | 8 +- app/Controllers/Admin/MapurlController.php | 6 +- app/Controllers/Admin/UserController.php | 6 +- .../{Cloudflare.php => API/API.php} | 12 +-- .../CLI/Cloudflare/{ => API}/Account.php | 6 +- .../CLI/Cloudflare/{ => API}/Auth.php | 6 +- .../CLI/Cloudflare/{ => API}/Zone.php | 8 +- app/Controllers/Common/CommonController.php | 2 +- app/Entities/Cloudflare/API/APIEntity.php | 15 +++ .../Cloudflare/{ => API}/AccountEntity.php | 17 +-- .../Cloudflare/{ => API}/AuthEntity.php | 18 ++-- .../Cloudflare/{ => API}/FirewallEntity.php | 16 +-- .../Cloudflare/{ => API}/RecordEntity.php | 6 +- .../Cloudflare/{ => API}/ZoneEntity.php | 14 +-- app/Entities/Cloudflare/CloudflareEntity.php | 14 --- .../Magictransit/AllowListEntity.php | 0 .../Cloudflare/API}/Account_helper.php | 0 .../Cloudflare/API}/Auth_helper.php | 0 .../Cloudflare/API}/Firewall_helper.php | 0 .../Cloudflare/API}/Record_helper.php | 0 .../Cloudflare/API}/Zone_helper.php | 0 .../Cloudflare}/Magictransit/Ddos_helper.php | 0 app/Helpers/{ => Admin}/Logger_helper.php | 0 app/Helpers/{ => Admin}/Mapurl_helper.php | 0 app/Helpers/{ => Admin}/User_helper.php | 0 .../Cloudflare/API}/Account.php | 0 .../Cloudflare/API}/Auth.php | 0 .../Cloudflare/API}/Firewall.php | 0 .../Cloudflare/API}/Record.php | 0 .../Cloudflare/API}/Zone.php | 0 .../Cloudflare/Magictransit/Ddos.php | 0 app/Language/en/{ => Admin}/Logger.php | 0 app/Language/en/{ => Admin}/Mapurl.php | 0 app/Language/en/{ => Admin}/User.php | 0 app/Language/en/{ => Admin}/Validation.php | 0 app/Libraries/Cloudflare/API/API.php | 5 +- app/Libraries/Cloudflare/API/Account.php | 13 ++- app/Libraries/Cloudflare/API/Firewall.php | 19 ++-- app/Libraries/Cloudflare/API/Record.php | 32 +++--- app/Libraries/Cloudflare/API/Zone.php | 28 +++-- .../Cloudflare/{ => API}/AccountModel.php | 4 +- app/Models/Cloudflare/{ => API}/AuthModel.php | 4 +- .../Cloudflare/{ => API}/FirewallModel.php | 4 +- .../Cloudflare/{ => API}/FixedRecordModel.php | 2 +- .../Cloudflare/{ => API}/RecordModel.php | 4 +- app/Models/Cloudflare/{ => API}/ZoneModel.php | 4 +- .../Magictransit/AllowListModel.php | 0 .../cloudflare/{ => api}/account/index.php | 0 .../admin/cloudflare/{ => api}/auth/index.php | 0 .../cloudflare/{ => api}/auth/insert.php | 0 .../cloudflare/{ => api}/auth/update.php | 0 .../admin/cloudflare/{ => api}/auth/view.php | 0 .../cloudflare/{ => api}/firewall/index.php | 0 .../cloudflare/{ => api}/record/index.php | 0 .../cloudflare/{ => api}/record/insert.php | 0 .../admin/cloudflare/{ => api}/zone/index.php | 0 .../cloudflare/{ => api}/zone/insert.php | 0 66 files changed, 320 insertions(+), 287 deletions(-) create mode 100644 app/Controllers/Admin/Cloudflare/API/APIController.php rename app/Controllers/Admin/Cloudflare/{ => API}/AccountController.php (83%) rename app/Controllers/Admin/Cloudflare/{ => API}/AuthController.php (92%) rename app/Controllers/Admin/Cloudflare/{ => API}/FirewallController.php (72%) rename app/Controllers/Admin/Cloudflare/{ => API}/RecordController.php (83%) rename app/Controllers/Admin/Cloudflare/{ => API}/ZoneController.php (85%) rename app/Controllers/CLI/Cloudflare/{Cloudflare.php => API/API.php} (73%) rename app/Controllers/CLI/Cloudflare/{ => API}/Account.php (92%) rename app/Controllers/CLI/Cloudflare/{ => API}/Auth.php (88%) rename app/Controllers/CLI/Cloudflare/{ => API}/Zone.php (93%) create mode 100644 app/Entities/Cloudflare/API/APIEntity.php rename app/Entities/Cloudflare/{ => API}/AccountEntity.php (67%) rename app/Entities/Cloudflare/{ => API}/AuthEntity.php (66%) rename app/Entities/Cloudflare/{ => API}/FirewallEntity.php (66%) rename app/Entities/Cloudflare/{ => API}/RecordEntity.php (85%) rename app/Entities/Cloudflare/{ => API}/ZoneEntity.php (70%) delete mode 100644 app/Entities/Cloudflare/CloudflareEntity.php rename app/Entities/{ => Cloudflare}/Magictransit/AllowListEntity.php (100%) rename app/Helpers/{Cloudflare => Admin/Cloudflare/API}/Account_helper.php (100%) rename app/Helpers/{Cloudflare => Admin/Cloudflare/API}/Auth_helper.php (100%) rename app/Helpers/{Cloudflare => Admin/Cloudflare/API}/Firewall_helper.php (100%) rename app/Helpers/{Cloudflare => Admin/Cloudflare/API}/Record_helper.php (100%) rename app/Helpers/{Cloudflare => Admin/Cloudflare/API}/Zone_helper.php (100%) rename app/Helpers/{ => Admin/Cloudflare}/Magictransit/Ddos_helper.php (100%) rename app/Helpers/{ => Admin}/Logger_helper.php (100%) rename app/Helpers/{ => Admin}/Mapurl_helper.php (100%) rename app/Helpers/{ => Admin}/User_helper.php (100%) rename app/Language/en/{Cloudflare => Admin/Cloudflare/API}/Account.php (100%) rename app/Language/en/{Cloudflare => Admin/Cloudflare/API}/Auth.php (100%) rename app/Language/en/{Cloudflare => Admin/Cloudflare/API}/Firewall.php (100%) rename app/Language/en/{Cloudflare => Admin/Cloudflare/API}/Record.php (100%) rename app/Language/en/{Cloudflare => Admin/Cloudflare/API}/Zone.php (100%) rename app/Language/en/{ => Admin}/Cloudflare/Magictransit/Ddos.php (100%) rename app/Language/en/{ => Admin}/Logger.php (100%) rename app/Language/en/{ => Admin}/Mapurl.php (100%) rename app/Language/en/{ => Admin}/User.php (100%) rename app/Language/en/{ => Admin}/Validation.php (100%) rename app/Models/Cloudflare/{ => API}/AccountModel.php (97%) rename app/Models/Cloudflare/{ => API}/AuthModel.php (96%) rename app/Models/Cloudflare/{ => API}/FirewallModel.php (97%) rename app/Models/Cloudflare/{ => API}/FixedRecordModel.php (97%) rename app/Models/Cloudflare/{ => API}/RecordModel.php (97%) rename app/Models/Cloudflare/{ => API}/ZoneModel.php (97%) rename app/Models/{ => Cloudflare}/Magictransit/AllowListModel.php (100%) rename app/Views/admin/cloudflare/{ => api}/account/index.php (100%) rename app/Views/admin/cloudflare/{ => api}/auth/index.php (100%) rename app/Views/admin/cloudflare/{ => api}/auth/insert.php (100%) rename app/Views/admin/cloudflare/{ => api}/auth/update.php (100%) rename app/Views/admin/cloudflare/{ => api}/auth/view.php (100%) rename app/Views/admin/cloudflare/{ => api}/firewall/index.php (100%) rename app/Views/admin/cloudflare/{ => api}/record/index.php (100%) rename app/Views/admin/cloudflare/{ => api}/record/insert.php (100%) rename app/Views/admin/cloudflare/{ => api}/zone/index.php (100%) rename app/Views/admin/cloudflare/{ => api}/zone/insert.php (100%) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 70c1847..e91f6f4 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -34,7 +34,7 @@ $routes->get('/', 'Home::index'); $routes->get('/login', 'Common\AuthController::login'); $routes->post('/signin', 'Common\AuthController::signin'); $routes->get('/logout', 'Common\AuthController::logout'); -$routes->group('cli', ['namespace' => 'App\Controllers\CLI\Cloudflare'], function ($routes) { +$routes->group('cli', ['namespace' => 'App\Controllers\CLI\Cloudflare\API'], function ($routes) { $routes->cli('cloudflare/auth', 'Auth::execute'); $routes->cli('cloudflare/account/(:any)', 'Account::execute/$1'); $routes->cli('cloudflare/zone/record/(:any)', 'Zone::record/$1'); @@ -46,7 +46,7 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) { $routes->get('/', 'Home::index'); - $routes->group('cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) { + $routes->group('cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) { $routes->get('', 'AuthController::index'); $routes->get('excel', 'AuthController::excel'); $routes->get('insert', 'AuthController::insert_form'); @@ -59,13 +59,13 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('batchjob', 'AuthController::batchjob', ['filter' => 'authFilter:master,director,cloudflare']); $routes->get('reload/(:num)', 'AuthController::reload/$1'); }); - $routes->group('cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) { + $routes->group('cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) { $routes->get('', 'AccountController::index'); $routes->get('excel', 'AccountController::excel'); $routes->get('selectkey', 'AccountController::selectkey'); $routes->get('reload/(:hash)', 'AccountController::reload/$1'); }); - $routes->group('cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) { + $routes->group('cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) { $routes->get('', 'ZoneController::index'); $routes->post('insert', 'ZoneController::insert'); $routes->get('excel', 'ZoneController::excel'); @@ -76,7 +76,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('sync/(:hash)', 'ZoneController::sync/$1'); $routes->get('reload/(:hash)', 'ZoneController::reload/$1'); }); - $routes->group('cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) { + $routes->group('cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) { $routes->get('', 'RecordController::index'); $routes->post('insert', 'RecordController::insert'); $routes->get('excel', 'RecordController::excel'); @@ -86,7 +86,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('sync/(:hash)', 'RecordController::sync/$1'); $routes->get('cdnToggle/(:hash)', 'RecordController::cdnToggle/$1'); }); - $routes->group('cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) { + $routes->group('cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) { $routes->get('', 'FirewallController::index'); $routes->get('excel', 'FirewallController::excel'); $routes->get('toggle/(:hash)/(:hash)', 'FirewallController::toggle/$1/$2'); diff --git a/app/Controllers/Admin/AdminController.php b/app/Controllers/Admin/AdminController.php index bf7efd3..6b6843c 100644 --- a/app/Controllers/Admin/AdminController.php +++ b/app/Controllers/Admin/AdminController.php @@ -11,8 +11,9 @@ class AdminController extends \App\Controllers\Common\CommonController public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - $this->_viewPath = $this->_viewPath.'/admin'; + $this->_className .= 'Admin'; + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['layout'] = LAYOUTS['admin']; - $this->_viewDatas['title'] = "관리자페이지"; + $this->_viewDatas['title'] = "관리자"; } } diff --git a/app/Controllers/Admin/Cloudflare/API/APIController.php b/app/Controllers/Admin/Cloudflare/API/APIController.php new file mode 100644 index 0000000..4fe11f7 --- /dev/null +++ b/app/Controllers/Admin/Cloudflare/API/APIController.php @@ -0,0 +1,100 @@ +_className .= '/API'; + $this->_viewPath = strtolower($this->_className); + } + final protected function getAuthModel(): AuthModel + { + return is_null($this->_authModel) ? new AuthModel() : $this->_authModel; + } + final protected function getAccountModel(): AccountModel + { + return is_null($this->_accountModel) ? new AccountModel() : $this->_accountModel; + } + final protected function getZoneModel(): ZoneModel + { + return is_null($this->_zoneModel) ? new ZoneModel() : $this->_zoneModel; + } + final protected function getRecordModel(): RecordModel + { + return is_null($this->_recordModel) ? new RecordModel() : $this->_recordModel; + } + + //Zone입력 + final protected function insert_Zone( + \App\Entities\Cloudflare\API\AccountEntity $account, + string $domain + ): \App\Entities\Cloudflare\API\ZoneEntity { + $fieldDatas = array('account_uid' => $account->getPrimaryKey(), 'domain' => $domain); + $api = new \App\Libraries\Cloudflare\API\Zone($account); + $zone = $api->insert($fieldDatas); + if (!$this->getZoneModel()->save($zone)) { + Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery()); + Log::add("error", implode("\n", $this->getZoneModel()->errors())); + throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getZoneModel()->errors(), true)); + } + Log::add("info", "Zone: {$zone->getTitle()} 등록"); + return $zone; + } + //Record입력 + final protected function insert_Host( + \App\Entities\Cloudflare\API\ZoneEntity $zone, + string $host, + string $type, + string $content, + string $proxied + ): \App\Entities\Cloudflare\API\RecordEntity { + $fieldDatas = array('zone_uid' => $zone->getPrimaryKey(), 'host' => $host); + $fieldDatas['type'] = $type; + $fieldDatas['content'] = $content; + $fieldDatas['proxied'] = $proxied; + + $api = new \App\Libraries\Cloudflare\API\Record($zone); + $record = $api->insert($fieldDatas); + $record->fixed = 'off'; //초기값 + if (!$this->getRecordModel()->save($record)) { + Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getRecordModel()->getLastQuery()); + Log::add("error", implode("\n", $this->getRecordModel()->errors())); + throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getRecordModel()->errors(), true)); + } + Log::add("info", "Host: {$record->getTitle()} 등록"); + return $record; + } + + //Sync관련 + protected function sync_process($entity) + { + return $entity; + } + final public function sync($uid) + { + try { + $entity = $this->_model->getEntity($uid); + $entity = $this->sync_process($entity); + return alert_CommonHelper("{$this->_viewDatas['title']} " . __FUNCTION__ . " 완료하였습니다.", session()->get(RETURN_URL)); + } catch (\Exception $e) { + return alert_CommonHelper($e->getMessage(), 'back'); + } + } +} diff --git a/app/Controllers/Admin/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/API/AccountController.php similarity index 83% rename from app/Controllers/Admin/Cloudflare/AccountController.php rename to app/Controllers/Admin/Cloudflare/API/AccountController.php index cca27da..a0f6cfd 100644 --- a/app/Controllers/Admin/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/API/AccountController.php @@ -1,19 +1,19 @@ _className = $this->_className . '/Account'; + $this->_className .= '/Account'; $this->_model = new AccountModel(); $this->_defines = [ 'index' => [ @@ -26,8 +26,8 @@ class AccountController extends CloudflareController 'fieldFilters' => ['auth_uid', 'type', 'status'], ], ]; - helper('Cloudflare/Account'); - $this->_viewPath = $this->_viewPath . '/account'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); } @@ -39,7 +39,7 @@ class AccountController extends CloudflareController if (is_null($this->_auth_uids)) { //모든 필요한 FormOption등 조기화작업 필요 $this->_auth_uids = [DEFAULT_EMPTY => lang($this->_className . '.label.' . $field) . ' 선택']; - foreach ($this->getAuthModel()->where('status', 'use')->orderBy('id', 'asc')->findAll() as $auth) { + foreach ($this->getAuthModel()->orderBy('id', 'asc')->findAll() as $auth) { $this->_auth_uids[$auth['uid']] = $auth['id']; } } diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/API/AuthController.php similarity index 92% rename from app/Controllers/Admin/Cloudflare/AuthController.php rename to app/Controllers/Admin/Cloudflare/API/AuthController.php index 9889b5c..4bce44d 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/API/AuthController.php @@ -1,18 +1,18 @@ _className = $this->_className . '/Auth'; + $this->_className .= '/Auth'; $this->_model = new AuthModel(); $this->_defines = [ 'insert' => [ @@ -48,8 +48,8 @@ class AuthController extends CloudflareController 'fieldFilters' => ['status'], ], ]; - helper('Cloudflare/Auth'); - $this->_viewPath = $this->_viewPath . '/auth'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); } diff --git a/app/Controllers/Admin/Cloudflare/FirewallController.php b/app/Controllers/Admin/Cloudflare/API/FirewallController.php similarity index 72% rename from app/Controllers/Admin/Cloudflare/FirewallController.php rename to app/Controllers/Admin/Cloudflare/API/FirewallController.php index 7face8c..3667dbb 100644 --- a/app/Controllers/Admin/Cloudflare/FirewallController.php +++ b/app/Controllers/Admin/Cloudflare/API/FirewallController.php @@ -1,20 +1,20 @@ _className = $this->_className . '/Firewall'; + $this->_className .= '/Firewall'; $this->_model = new FirewallModel(); $this->_defines = [ 'index' => [ @@ -27,10 +27,9 @@ class FirewallController extends CloudflareController 'fieldFilters' => ['zone_uid', 'action', 'paused',], ], ]; - helper('Cloudflare/Firewall'); - $this->_viewPath = $this->_viewPath . '/firewall'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_api = new \App\Libraries\Cloudflare\API\Firewall(); } //Field별 Form Option용 @@ -56,25 +55,29 @@ class FirewallController extends CloudflareController //Update관련 protected function update_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::update_process($entity); } //Toggle관련 protected function toggle_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::toggle_process($entity); } //Batchjob관련 protected function batchjob_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::batchjob_process($entity); } //Sync관련 protected function sync_process($entity) { - $entity = $this->_api->sync($entity); + $api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->sync($entity); return parent::sync_process($entity); } //Index관련 diff --git a/app/Controllers/Admin/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/API/RecordController.php similarity index 83% rename from app/Controllers/Admin/Cloudflare/RecordController.php rename to app/Controllers/Admin/Cloudflare/API/RecordController.php index ba6623c..de4ea4a 100644 --- a/app/Controllers/Admin/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/API/RecordController.php @@ -1,21 +1,21 @@ _className = $this->_className . '/Record'; + $this->_className .= '/Record'; $this->_model = new RecordModel(); $this->_defines = [ 'insert' => [ @@ -39,10 +39,9 @@ class RecordController extends CloudflareController 'fieldFilters' => ['zone_uid', 'type', 'proxied', 'locked'], ], ]; - helper('Cloudflare/Record'); - $this->_viewPath = $this->_viewPath . '/record'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_api = new \App\Libraries\Cloudflare\API\Record(); } //Field별 Form Option용 @@ -91,8 +90,9 @@ class RecordController extends CloudflareController protected function insert_process() { foreach ($this->_viewDatas['fieldDatas']['hosts'] as $host) { + $zone = $this->getZoneModel()->gentEntity($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD]); $this->insert_Host( - $this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD], + $zone, $host, $this->_viewDatas['fieldDatas']['type'], $this->_viewDatas['fieldDatas']['content'], @@ -104,31 +104,36 @@ class RecordController extends CloudflareController //Update관련 protected function update_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::update_process($entity); } //Toggle관련 protected function toggle_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::toggle_process($entity); } //Batchjob관련 protected function batchjob_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::batchjob_process($entity); } //Delete 관련 protected function delete_process($entity) { - $this->_api->delete($entity); + $api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $api->delete($entity); return parent::delete_process($entity); } //Sync관련 protected function sync_process($entity) { - $entity = $this->_api->sync($entity); + $api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->sync($entity); return parent::sync_process($entity); } //Index관련 @@ -143,7 +148,7 @@ class RecordController extends CloudflareController { try { $entity = $this->_model->getEntity($uid); - $fixedRecordModel = new \App\Models\Cloudflare\FixedRecordModel(); + $fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel(); if ($entity->fixed == 'on') { $entity->fixed = "off"; $this->_model->save($entity); diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/API/ZoneController.php similarity index 85% rename from app/Controllers/Admin/Cloudflare/ZoneController.php rename to app/Controllers/Admin/Cloudflare/API/ZoneController.php index 2a065f1..71b938e 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/API/ZoneController.php @@ -1,21 +1,21 @@ _className = $this->_className . '/Zone'; + $this->_className .= '/Zone'; $this->_model = new ZoneModel(); $this->_defines = [ 'insert' => [ @@ -39,10 +39,9 @@ class ZoneController extends CloudflareController 'fieldFilters' => ['account_uid', 'development_mode', 'ipv6', 'security_level', 'status'], ], ]; - helper('Cloudflare/Zone'); - $this->_viewPath = $this->_viewPath . '/zone'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); - $this->_api = new \App\Libraries\Cloudflare\API\Zone(); } //Field별 Form Option용 @@ -103,10 +102,11 @@ class ZoneController extends CloudflareController protected function insert_process() { foreach ($this->_viewDatas['fieldDatas']['domains'] as $domain) { - $zone = $this->insert_Zone($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD], $domain); + $account = $this->getAccountModel()->gentEntity($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD]); + $zone = $this->insert_Zone($account, $domain); foreach ($this->_viewDatas['fieldDatas']['hosts'] as $host) { $this->insert_Host( - $zone->getPrimaryKey(), + $zone, $host, $this->_viewDatas['fieldDatas']['type'], $this->_viewDatas['fieldDatas']['content'], @@ -118,31 +118,36 @@ class ZoneController extends CloudflareController //Update관련 protected function update_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::update_process($entity); } //Toggle관련 protected function toggle_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::toggle_process($entity); } //Batchjob관련 protected function batchjob_process($entity) { - $entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']); + $api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->update($entity, $this->_viewDatas['fieldDatas']); return parent::batchjob_process($entity); } //Delete 관련 protected function delete_process($entity) { - $this->_api->delete($entity); + $api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData())); + $api->delete($entity); return parent::delete_process($entity); } //Sync관련 protected function sync_process($entity) { - $entity = $this->_api->sync($entity); + $api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData())); + $entity = $api->sync($entity); return parent::sync_process($entity); } //Index관련 diff --git a/app/Controllers/Admin/Cloudflare/CloudflareController.php b/app/Controllers/Admin/Cloudflare/CloudflareController.php index a60bb18..518b91f 100644 --- a/app/Controllers/Admin/Cloudflare/CloudflareController.php +++ b/app/Controllers/Admin/Cloudflare/CloudflareController.php @@ -2,97 +2,17 @@ namespace App\Controllers\Admin\Cloudflare; -use App\Libraries\Log\Log; -use App\Models\Cloudflare\AccountModel; -use App\Models\Cloudflare\AuthModel; -use App\Models\Cloudflare\ZoneModel; -use App\Models\Cloudflare\RecordModel; - use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; class CloudflareController extends \App\Controllers\Admin\AdminController { - private $_authModel = null; - private $_accountModel = null; - private $_zoneModel = null; - private $_recordModel = null; - public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) - { - parent::initController($request, $response, $logger); - $this->_className = 'Cloudflare'; - $this->_viewPath = $this->_viewPath . '/cloudflare'; - } - final protected function getAuthModel(): AuthModel - { - return is_null($this->_authModel) ? new AuthModel() : $this->_authModel; - } - final protected function getAccountModel(): AccountModel - { - return is_null($this->_accountModel) ? new AccountModel() : $this->_accountModel; - } - final protected function getZoneModel(): ZoneModel - { - return is_null($this->_zoneModel) ? new ZoneModel() : $this->_zoneModel; - } - final protected function getRecordModel(): RecordModel - { - return is_null($this->_recordModel) ? new RecordModel() : $this->_recordModel; - } - - //Zone입력 - final protected function insert_Zone(string $account_uid, string $domain): \App\Entities\Cloudflare\ZoneEntity - { - $fieldDatas = array('account_uid' => $account_uid, 'domain' => $domain); - $api = new \App\Libraries\Cloudflare\API\Zone(); - $zone = $api->insert($fieldDatas); - if (!$this->getZoneModel()->save($zone)) { - Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery()); - Log::add("error", implode("\n", $this->getZoneModel()->errors())); - throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getZoneModel()->errors(), true)); - } - Log::add("info", "Zone: {$zone->getTitle()} 등록"); - return $zone; - } - //Record입력 - final protected function insert_Host( - string $zone_uid, - string $host, - string $type, - string $content, - string $proxied - ): \App\Entities\Cloudflare\RecordEntity { - $fieldDatas = array('zone_uid' => $zone_uid, 'host' => $host); - $fieldDatas['type'] = $type; - $fieldDatas['content'] = $content; - $fieldDatas['proxied'] = $proxied; - - $api = new \App\Libraries\Cloudflare\API\Record(); - $record = $api->insert($fieldDatas); - $record->fixed = 'off'; //초기값 - if (!$this->getRecordModel()->save($record)) { - Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getRecordModel()->getLastQuery()); - Log::add("error", implode("\n", $this->getRecordModel()->errors())); - throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getRecordModel()->errors(), true)); - } - Log::add("info", "Host: {$record->getTitle()} 등록"); - return $record; - } - - //Sync관련 - protected function sync_process($entity) - { - return $entity; - } - final public function sync($uid) - { - try { - $entity = $this->_model->getEntity($uid); - $entity = $this->sync_process($entity); - return alert_CommonHelper("{$this->_viewDatas['title']} " . __FUNCTION__ . " 완료하였습니다.", session()->get(RETURN_URL)); - } catch (\Exception $e) { - return alert_CommonHelper($e->getMessage(), 'back'); - } - } + public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) + { + parent::initController($request, $response, $logger); + $this->_className .= '/Cloudflare'; + $this->_viewPath = strtolower($this->_className); + $this->_viewDatas['title'] .= "Cloudflare"; + } } diff --git a/app/Controllers/Admin/LoggerController.php b/app/Controllers/Admin/LoggerController.php index 5308ea5..30cbf4b 100644 --- a/app/Controllers/Admin/LoggerController.php +++ b/app/Controllers/Admin/LoggerController.php @@ -15,7 +15,7 @@ class LoggerController extends \App\Controllers\Admin\AdminController public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - $this->_className = 'Logger'; + $this->_className .= '/Logger'; $this->_model = new LoggerModel(); $this->_defines = [ 'view' => [ @@ -33,11 +33,9 @@ class LoggerController extends \App\Controllers\Admin\AdminController 'fieldFilters' => ['user_uid', 'status'], ], ]; - helper('Logger'); - $this->_viewPath = $this->_viewPath . '/logger'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); - - //모든 필요한 FormOption등 조기화작업 필요 } private function getUserModel(): UserModel diff --git a/app/Controllers/Admin/MapurlController.php b/app/Controllers/Admin/MapurlController.php index c486c98..137edcd 100644 --- a/app/Controllers/Admin/MapurlController.php +++ b/app/Controllers/Admin/MapurlController.php @@ -12,7 +12,7 @@ class MapurlController extends \App\Controllers\Admin\AdminController public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - $this->_className = 'Mapurl'; + $this->_className .= '/Mapurl'; $this->_model = new MapurlModel(); $this->_defines = [ 'insert' => [ @@ -48,8 +48,8 @@ class MapurlController extends \App\Controllers\Admin\AdminController 'fieldFilters' => ['status'], ], ]; - helper('Mapurl'); - $this->_viewPath = $this->_viewPath . '/mapurl'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); //모든 필요한 FormOption등 조기화작업 필요 diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 4c12ed4..72c3950 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -12,7 +12,7 @@ class UserController extends \App\Controllers\Admin\AdminController public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); - $this->_className = 'User'; + $this->_className .= '/User'; $this->_model = new UserModel(); $this->_defines = [ 'insert' => [ @@ -53,8 +53,8 @@ class UserController extends \App\Controllers\Admin\AdminController 'fieldFilters' => ['role', 'status'], ], ]; - helper('User'); - $this->_viewPath = $this->_viewPath . '/user'; + helper($this->_className); + $this->_viewPath = strtolower($this->_className); $this->_viewDatas['title'] = lang($this->_className . '.title'); } diff --git a/app/Controllers/CLI/Cloudflare/Cloudflare.php b/app/Controllers/CLI/Cloudflare/API/API.php similarity index 73% rename from app/Controllers/CLI/Cloudflare/Cloudflare.php rename to app/Controllers/CLI/Cloudflare/API/API.php index 10cf50f..88ffa90 100644 --- a/app/Controllers/CLI/Cloudflare/Cloudflare.php +++ b/app/Controllers/CLI/Cloudflare/API/API.php @@ -1,14 +1,14 @@ reload((int)$page_limit); } //CDN값 수정 못하는 고정 Record 처리 - $fixedRecordModel = new \App\Models\Cloudflare\FixedRecordModel(); + $fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel(); $this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host")); echo __METHOD__ . "에서 Record Reload 완료\n"; //transation 완료 diff --git a/app/Controllers/Common/CommonController.php b/app/Controllers/Common/CommonController.php index 9b8de70..0fa4aa2 100644 --- a/app/Controllers/Common/CommonController.php +++ b/app/Controllers/Common/CommonController.php @@ -21,7 +21,7 @@ class CommonController extends BaseController helper('Common'); $this->_viewDatas = [ 'layout' => LAYOUTS['empty'], - 'title' => '공통페이지', + 'title' => '', 'session' => session() ]; if (is_null(session()->get('uid'))) { diff --git a/app/Entities/Cloudflare/API/APIEntity.php b/app/Entities/Cloudflare/API/APIEntity.php new file mode 100644 index 0000000..2d5a442 --- /dev/null +++ b/app/Entities/Cloudflare/API/APIEntity.php @@ -0,0 +1,15 @@ +getParentField(); + return $this->$field; + } +} diff --git a/app/Entities/Cloudflare/AccountEntity.php b/app/Entities/Cloudflare/API/AccountEntity.php similarity index 67% rename from app/Entities/Cloudflare/AccountEntity.php rename to app/Entities/Cloudflare/API/AccountEntity.php index f62b29a..e7fa5d6 100644 --- a/app/Entities/Cloudflare/AccountEntity.php +++ b/app/Entities/Cloudflare/API/AccountEntity.php @@ -1,24 +1,27 @@ attributes['uid']; } - public function getTitle(){ + public function getTitle() + { return $this->attributes['title']; } public function __toString() { return "uid:{$this->attributes['uid']}|auth_uid:{$this->attributes['auth_uid']}|{$this->attributes['title']} | {$this->attributes['type']} | {$this->attributes['status']}"; } - public function getParentField():string{ + public function getParentField(): string + { return "auth_uid"; } -} \ No newline at end of file +} diff --git a/app/Entities/Cloudflare/AuthEntity.php b/app/Entities/Cloudflare/API/AuthEntity.php similarity index 66% rename from app/Entities/Cloudflare/AuthEntity.php rename to app/Entities/Cloudflare/API/AuthEntity.php index 6906083..305e177 100644 --- a/app/Entities/Cloudflare/AuthEntity.php +++ b/app/Entities/Cloudflare/API/AuthEntity.php @@ -1,23 +1,27 @@ attributes['uid']; } - public function getTitle(){ + public function getTitle() + { return $this->attributes['id']; } - public function getAuthId(){ + public function getAuthId() + { return $this->attributes['id']; } - public function getAuthKey(){ + public function getAuthKey() + { return $this->attributes['authkey']; } diff --git a/app/Entities/Cloudflare/FirewallEntity.php b/app/Entities/Cloudflare/API/FirewallEntity.php similarity index 66% rename from app/Entities/Cloudflare/FirewallEntity.php rename to app/Entities/Cloudflare/API/FirewallEntity.php index 900a88f..d66057d 100644 --- a/app/Entities/Cloudflare/FirewallEntity.php +++ b/app/Entities/Cloudflare/API/FirewallEntity.php @@ -1,25 +1,27 @@ attributes['uid']; } - public function getTitle(){ + public function getTitle() + { return $this->attributes['description']; } public function __toString() { return "uid:{$this->attributes['uid']}|zone_uid:{$this->attributes['zone_uid']}|host:{$this->attributes['description']}|content:{$this->attributes['action']}"; } - public function getParentField():string{ + public function getParentField(): string + { return "zone_uid"; } - } diff --git a/app/Entities/Cloudflare/RecordEntity.php b/app/Entities/Cloudflare/API/RecordEntity.php similarity index 85% rename from app/Entities/Cloudflare/RecordEntity.php rename to app/Entities/Cloudflare/API/RecordEntity.php index c49541d..abf36b4 100644 --- a/app/Entities/Cloudflare/RecordEntity.php +++ b/app/Entities/Cloudflare/API/RecordEntity.php @@ -1,10 +1,8 @@ attributes['uid']; } - public function getTitle(){ + public function getTitle() + { return $this->attributes['domain']; } public function __toString() { return "uid:{$this->attributes['uid']}|account_uid:{$this->attributes['account_uid']}|domain:{$this->attributes['domain']}|{$this->attributes['development_mode']}|{$this->attributes['ipv6']}|{$this->attributes['security_level']}"; } - public function getParentField():string{ + public function getParentField(): string + { return "account_uid"; } } diff --git a/app/Entities/Cloudflare/CloudflareEntity.php b/app/Entities/Cloudflare/CloudflareEntity.php deleted file mode 100644 index 0ce3417..0000000 --- a/app/Entities/Cloudflare/CloudflareEntity.php +++ /dev/null @@ -1,14 +0,0 @@ -getParentField(); - return $this->$field; - } -} \ No newline at end of file diff --git a/app/Entities/Magictransit/AllowListEntity.php b/app/Entities/Cloudflare/Magictransit/AllowListEntity.php similarity index 100% rename from app/Entities/Magictransit/AllowListEntity.php rename to app/Entities/Cloudflare/Magictransit/AllowListEntity.php diff --git a/app/Helpers/Cloudflare/Account_helper.php b/app/Helpers/Admin/Cloudflare/API/Account_helper.php similarity index 100% rename from app/Helpers/Cloudflare/Account_helper.php rename to app/Helpers/Admin/Cloudflare/API/Account_helper.php diff --git a/app/Helpers/Cloudflare/Auth_helper.php b/app/Helpers/Admin/Cloudflare/API/Auth_helper.php similarity index 100% rename from app/Helpers/Cloudflare/Auth_helper.php rename to app/Helpers/Admin/Cloudflare/API/Auth_helper.php diff --git a/app/Helpers/Cloudflare/Firewall_helper.php b/app/Helpers/Admin/Cloudflare/API/Firewall_helper.php similarity index 100% rename from app/Helpers/Cloudflare/Firewall_helper.php rename to app/Helpers/Admin/Cloudflare/API/Firewall_helper.php diff --git a/app/Helpers/Cloudflare/Record_helper.php b/app/Helpers/Admin/Cloudflare/API/Record_helper.php similarity index 100% rename from app/Helpers/Cloudflare/Record_helper.php rename to app/Helpers/Admin/Cloudflare/API/Record_helper.php diff --git a/app/Helpers/Cloudflare/Zone_helper.php b/app/Helpers/Admin/Cloudflare/API/Zone_helper.php similarity index 100% rename from app/Helpers/Cloudflare/Zone_helper.php rename to app/Helpers/Admin/Cloudflare/API/Zone_helper.php diff --git a/app/Helpers/Magictransit/Ddos_helper.php b/app/Helpers/Admin/Cloudflare/Magictransit/Ddos_helper.php similarity index 100% rename from app/Helpers/Magictransit/Ddos_helper.php rename to app/Helpers/Admin/Cloudflare/Magictransit/Ddos_helper.php diff --git a/app/Helpers/Logger_helper.php b/app/Helpers/Admin/Logger_helper.php similarity index 100% rename from app/Helpers/Logger_helper.php rename to app/Helpers/Admin/Logger_helper.php diff --git a/app/Helpers/Mapurl_helper.php b/app/Helpers/Admin/Mapurl_helper.php similarity index 100% rename from app/Helpers/Mapurl_helper.php rename to app/Helpers/Admin/Mapurl_helper.php diff --git a/app/Helpers/User_helper.php b/app/Helpers/Admin/User_helper.php similarity index 100% rename from app/Helpers/User_helper.php rename to app/Helpers/Admin/User_helper.php diff --git a/app/Language/en/Cloudflare/Account.php b/app/Language/en/Admin/Cloudflare/API/Account.php similarity index 100% rename from app/Language/en/Cloudflare/Account.php rename to app/Language/en/Admin/Cloudflare/API/Account.php diff --git a/app/Language/en/Cloudflare/Auth.php b/app/Language/en/Admin/Cloudflare/API/Auth.php similarity index 100% rename from app/Language/en/Cloudflare/Auth.php rename to app/Language/en/Admin/Cloudflare/API/Auth.php diff --git a/app/Language/en/Cloudflare/Firewall.php b/app/Language/en/Admin/Cloudflare/API/Firewall.php similarity index 100% rename from app/Language/en/Cloudflare/Firewall.php rename to app/Language/en/Admin/Cloudflare/API/Firewall.php diff --git a/app/Language/en/Cloudflare/Record.php b/app/Language/en/Admin/Cloudflare/API/Record.php similarity index 100% rename from app/Language/en/Cloudflare/Record.php rename to app/Language/en/Admin/Cloudflare/API/Record.php diff --git a/app/Language/en/Cloudflare/Zone.php b/app/Language/en/Admin/Cloudflare/API/Zone.php similarity index 100% rename from app/Language/en/Cloudflare/Zone.php rename to app/Language/en/Admin/Cloudflare/API/Zone.php diff --git a/app/Language/en/Cloudflare/Magictransit/Ddos.php b/app/Language/en/Admin/Cloudflare/Magictransit/Ddos.php similarity index 100% rename from app/Language/en/Cloudflare/Magictransit/Ddos.php rename to app/Language/en/Admin/Cloudflare/Magictransit/Ddos.php diff --git a/app/Language/en/Logger.php b/app/Language/en/Admin/Logger.php similarity index 100% rename from app/Language/en/Logger.php rename to app/Language/en/Admin/Logger.php diff --git a/app/Language/en/Mapurl.php b/app/Language/en/Admin/Mapurl.php similarity index 100% rename from app/Language/en/Mapurl.php rename to app/Language/en/Admin/Mapurl.php diff --git a/app/Language/en/User.php b/app/Language/en/Admin/User.php similarity index 100% rename from app/Language/en/User.php rename to app/Language/en/Admin/User.php diff --git a/app/Language/en/Validation.php b/app/Language/en/Admin/Validation.php similarity index 100% rename from app/Language/en/Validation.php rename to app/Language/en/Admin/Validation.php diff --git a/app/Libraries/Cloudflare/API/API.php b/app/Libraries/Cloudflare/API/API.php index 12fd39c..4902654 100644 --- a/app/Libraries/Cloudflare/API/API.php +++ b/app/Libraries/Cloudflare/API/API.php @@ -17,7 +17,7 @@ abstract class API } abstract public function getClassName(); abstract protected function setAdapter(); - abstract protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\CloudflareEntity; + abstract protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\APIEntity; abstract protected function getCFResults_List(int $page): array; final protected static function getRequestCount() { @@ -32,9 +32,10 @@ abstract class API Log::add('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", CF_REQUEST_WAITTIME)); } self::$_requestCount++; - if ($this->_adapter instanceof \Cloudflare\API\Adapter\Guzzle) { + if (is_null($this->_adapter)) { throw new \Exception("해당 Adapter가 없습니다."); } + // throw new \Exception(var_export($this->_adapter, true)); return $this->_adapter; } final public function getParent() diff --git a/app/Libraries/Cloudflare/API/Account.php b/app/Libraries/Cloudflare/API/Account.php index 2ddc857..15baa11 100644 --- a/app/Libraries/Cloudflare/API/Account.php +++ b/app/Libraries/Cloudflare/API/Account.php @@ -2,16 +2,14 @@ namespace App\Libraries\Cloudflare\API; -use App\Entities\Cloudflare\AccountEntity; - class Account extends API { private $_endPoint = null; private $_entity = null; - public function __construct(\App\Entities\Cloudflare\AuthEntity $parent) + public function __construct(\App\Entities\Cloudflare\API\AuthEntity $parent) { parent::__construct($parent); - $this->_model = new \App\Models\Cloudflare\AccountModel(); + $this->_model = new \App\Models\Cloudflare\API\AccountModel(); } protected function setAdapter() { @@ -23,12 +21,13 @@ class Account extends API $this->getParent()->getAuthKey() ); $this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey); + // throw new \Exception(var_export($this->_adapter, true)); } public function getClassName() { return 'Account'; } - protected function getEntityByResult(\stdClass $cfResult): AccountEntity + protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\AccountEntity { // dd($cfResult);exit; // [ @@ -44,7 +43,7 @@ class Account extends API // "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}}, // "created_on":"2017-06-26T05:44:49.470184Z"} // ] - $entity = is_null($this->_entity) ? new AccountEntity() : $this->_entity; + $entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\AccountEntity() : $this->_entity; $entity->uid = $cfResult->id; $entity->auth_uid = $this->getParent()->getPrimaryKey(); $entity->title = $cfResult->name; @@ -55,7 +54,7 @@ class Account extends API return $entity; } - public function insert(array $fieldDatas): AccountEntity + public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\AccountEntity { $options = [ 'name' => $fieldDatas['name'], diff --git a/app/Libraries/Cloudflare/API/Firewall.php b/app/Libraries/Cloudflare/API/Firewall.php index 05df0aa..73f23a8 100644 --- a/app/Libraries/Cloudflare/API/Firewall.php +++ b/app/Libraries/Cloudflare/API/Firewall.php @@ -2,36 +2,35 @@ namespace App\Libraries\Cloudflare\API; -use App\Entities\Cloudflare\FirewallEntity; - class Firewall extends API { private $_endPoint = null; private $_entity = null; - public function __construct(\App\Entities\Cloudflare\ZoneEntity $parent) + public function __construct(\App\Entities\Cloudflare\API\ZoneEntity $parent) { parent::__construct($parent); - $this->_model = new \App\Models\Cloudflare\FirewallModel(); + $this->_model = new \App\Models\Cloudflare\API\FirewallModel(); } final protected function setAdapter() { if (!is_null($this->_adapter)) { throw new \Exception("Adapter가 이미 지정되었습니다."); } - $accountModel = new \App\Models\Cloudflare\AccountModel(); + $accountModel = new \App\Models\Cloudflare\API\AccountModel(); $account = $accountModel->getEntity($this->getParent()->getParentFieldData()); - $authModel = new \App\Models\Cloudflare\AuthModel(); + $authModel = new \App\Models\Cloudflare\API\AuthModel(); $auth = $authModel->getEntity($account->getParentFieldData()); $apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey()); $this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey); + // throw new \Exception(var_export($this->_adapter, true)); } public function getClassName() { return 'Firewall'; } - protected function getEntityByResult(\stdClass $cfResult): FirewallEntity + protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\FirewallEntity { - $entity = is_null($this->_entity) ? new FirewallEntity() : $this->_entity; + $entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\FirewallEntity() : $this->_entity; $entity->uid = $cfResult->id; $entity->zone_uid = $this->getParent()->getPrimaryKey(); $entity->description = $cfResult->description; @@ -47,7 +46,7 @@ class Firewall extends API } // public function insert(){ } - public function update(FirewallEntity $entity, array $fieldDatas): FirewallEntity + public function update(\App\Entities\Cloudflare\API\FirewallEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\FirewallEntity { $rule = array_merge( [ @@ -75,7 +74,7 @@ class Firewall extends API return $this->getEntityByResult($cfResult->result); } // public function delete(){ } - public function sync(FirewallEntity $entity): FirewallEntity + public function sync(\App\Entities\Cloudflare\API\FirewallEntity $entity): \App\Entities\Cloudflare\API\FirewallEntity { $cfResult = $this->getAdapter()->get('zones/' . $this->getParent()->getPrimaryKey() . '/firewall/rules/' . $entity->getPrimaryKey()); $cfResult = json_decode($cfResult->getBody()); diff --git a/app/Libraries/Cloudflare/API/Record.php b/app/Libraries/Cloudflare/API/Record.php index 578c763..5a377a2 100644 --- a/app/Libraries/Cloudflare/API/Record.php +++ b/app/Libraries/Cloudflare/API/Record.php @@ -2,38 +2,36 @@ namespace App\Libraries\Cloudflare\API; -use App\Entities\Cloudflare\RecordEntity; -use App\Entities\Cloudflare\ZoneEntity; - class Record extends API { private $_endPoint = null; private $_entity = null; - public function __construct(\App\Entities\Cloudflare\ZoneEntity $parent) + public function __construct(\App\Entities\Cloudflare\API\ZoneEntity $parent) { parent::__construct($parent); - $this->_model = new \App\Models\Cloudflare\RecordModel(); + $this->_model = new \App\Models\Cloudflare\API\RecordModel(); } final protected function setAdapter() { if (!is_null($this->_adapter)) { throw new \Exception("Adapter가 이미 지정되었습니다."); } - $accountModel = new \App\Models\Cloudflare\AccountModel(); + $accountModel = new \App\Models\Cloudflare\API\AccountModel(); $account = $accountModel->getEntity($this->getParent()->getParentFieldData()); - $authModel = new \App\Models\Cloudflare\AuthModel(); + $authModel = new \App\Models\Cloudflare\API\AuthModel(); $auth = $authModel->getEntity($account->getParentFieldData()); $apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey()); $this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey); + // throw new \Exception(var_export($this->_adapter, true)); } public function getClassName() { return 'Record'; } - protected function getEntityByResult(\stdClass $cfResult): RecordEntity + protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\RecordEntity { // throw new \Exception(var_export($cfResult, true)); - $entity = is_null($this->_entity) ? new RecordEntity() : $this->_entity; + $entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\RecordEntity() : $this->_entity; // throw new \Exception(var_export($cfResult, true)); $entity->uid = $cfResult->id; $entity->zone_uid = $cfResult->zone_id; @@ -50,7 +48,7 @@ class Record extends API return $entity; } - public function insert(array $fieldDatas): RecordEntity + public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\RecordEntity { //TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용 $options = [ @@ -67,7 +65,7 @@ class Record extends API } return $this->getEntityByResult($cfResult->result); } - public function update(RecordEntity $entity, array $fieldDatas): RecordEntity + public function update(\App\Entities\Cloudflare\API\RecordEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\RecordEntity { //TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용 $options = [ @@ -87,15 +85,11 @@ class Record extends API } return $this->getEntityByResult($cfResult->result); } - - public function deleteByZone(ZoneEntity $zone) + public function deleteByZone() { - $entitys = $this->_model->asObject(RecordEntity::class)->where($this->_model::PARENT_FIELD, $zone->getPrimaryKey())->findAll(); - foreach ($entitys as $entity) { - $this->delete($entity); - } + $this->_model->where($this->_model::PARENT_FIELD, $this->getParent()->getPrimaryKey())->delete(); } - public function delete(RecordEntity $entity) + public function delete(\App\Entities\Cloudflare\API\RecordEntity $entity) { $cfResult = $this->getAdapter()->delete('zones/' . $this->getParent()->getPrimaryKey() . '/dns_records/' . $entity->getPrimaryKey()); $cfResult = json_decode($cfResult->getBody()); @@ -103,7 +97,7 @@ class Record extends API throw new \Exception(var_export($cfResult, true)); } } - public function sync(RecordEntity $entity): RecordEntity + public function sync(\App\Entities\Cloudflare\API\RecordEntity $entity): \App\Entities\Cloudflare\API\RecordEntity { $cfResult = $this->getAdapter()->get('zones/' . $this->getParent()->getPrimaryKey() . '/dns_records/' . $entity->getPrimaryKey()); $cfResult = json_decode($cfResult->getBody()); diff --git a/app/Libraries/Cloudflare/API/Zone.php b/app/Libraries/Cloudflare/API/Zone.php index 8c1cb71..8e5d417 100644 --- a/app/Libraries/Cloudflare/API/Zone.php +++ b/app/Libraries/Cloudflare/API/Zone.php @@ -2,28 +2,27 @@ namespace App\Libraries\Cloudflare\API; -use App\Entities\Cloudflare\ZoneEntity; - class Zone extends API { private $_endPoint = null; private $_entity = null; private $_isGetSetting = true; - public function __construct(\App\Entities\Cloudflare\AccountEntity $parent, bool $isGetSetting = true) + public function __construct(\App\Entities\Cloudflare\API\AccountEntity $parent, bool $isGetSetting = true) { parent::__construct($parent); $this->_isGetSetting = $isGetSetting; - $this->_model = new \App\Models\Cloudflare\ZoneModel(); + $this->_model = new \App\Models\Cloudflare\API\ZoneModel(); } final protected function setAdapter() { if (!is_null($this->_adapter)) { throw new \Exception("Adapter가 이미 지정되었습니다."); } - $authModel = new \App\Models\Cloudflare\AuthModel(); + $authModel = new \App\Models\Cloudflare\API\AuthModel(); $auth = $authModel->getEntity($this->getParent()->getParentFieldData()); $apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey()); $this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey); + // throw new \Exception(var_export($this->_adapter, true)); } public function getClassName() { @@ -31,9 +30,9 @@ class Zone extends API } //Cfzone에서 가져온 값을 zone에 setting - protected function getEntityByResult(\stdClass $cfResult): ZoneEntity + protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\ZoneEntity { - $entity = is_null($this->_entity) ? new ZoneEntity() : $this->_entity; + $entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\ZoneEntity() : $this->_entity; $entity->uid = $cfResult->id; $entity->account_uid = $cfResult->account->id; $entity->domain = $cfResult->name; @@ -56,7 +55,7 @@ class Zone extends API } //Cfzone에서 가져온 값을 zone에 setting - final public function getCFSetting(ZoneEntity $entity): ZoneEntity + final public function getCFSetting(\App\Entities\Cloudflare\API\ZoneEntity $entity): \App\Entities\Cloudflare\API\ZoneEntity { $cfResult = $this->getAdapter()->get('zones/' . $entity->getPrimaryKey() . '/settings/'); $cfResult = json_decode($cfResult->getBody()); @@ -79,7 +78,7 @@ class Zone extends API return $entity; } //Cfzone에 해당 키값 변경용 - final public function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity + final public function setCFSetting(\App\Entities\Cloudflare\API\ZoneEntity $entity, string $field, string $value): \App\Entities\Cloudflare\API\ZoneEntity { $cfResult = $this->getAdapter()->patch('zones/' . $entity->getPrimaryKey() . '/settings/' . $field, array('value' => $value)); $cfResult = json_decode($cfResult->getBody()); @@ -91,7 +90,7 @@ class Zone extends API return $entity; } - public function insert(array $fieldDatas): ZoneEntity + public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\ZoneEntity { //도메인생성을 위해 Cloudflare에 전송 $options = [ @@ -111,7 +110,7 @@ class Zone extends API $entity = $this->setCFSetting($entity, 'security_level', 'medium'); return $entity; } - public function update(ZoneEntity $entity, array $fieldDatas): ZoneEntity + public function update(\App\Entities\Cloudflare\API\ZoneEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\ZoneEntity { //ipv6 , //development_mode , //security_level foreach ($fieldDatas as $field => $value) { @@ -119,12 +118,11 @@ class Zone extends API } return $entity; } - public function delete(ZoneEntity $entity) + public function delete(\App\Entities\Cloudflare\API\ZoneEntity $entity) { //Zone에 해당하는 Record 삭제를 먼저한다. $api = new \App\Libraries\Cloudflare\API\Record($entity); - $api->deleteByZone($entity); - + $api->deleteByZone(); //Zone 삭제 $cfResult = $this->getAdapter()->delete('zones/' . $entity->getPrimaryKey()); $cfResult = json_decode($cfResult->getBody()); @@ -132,7 +130,7 @@ class Zone extends API throw new \Exception(var_export($cfResult, true)); } } - public function sync(ZoneEntity $entity): ZoneEntity + public function sync(\App\Entities\Cloudflare\API\ZoneEntity $entity): \App\Entities\Cloudflare\API\ZoneEntity { $cfResult = $this->getAdapter()->get('zones/' . $entity->getPrimaryKey()); $cfResult = json_decode($cfResult->getBody()); diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/API/AccountModel.php similarity index 97% rename from app/Models/Cloudflare/AccountModel.php rename to app/Models/Cloudflare/API/AccountModel.php index 2fae7b4..903eed4 100644 --- a/app/Models/Cloudflare/AccountModel.php +++ b/app/Models/Cloudflare/API/AccountModel.php @@ -1,8 +1,8 @@