", implode(" ", $attributes), $header);
+}
+function getListColumns_AuthHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []): string
+{
+ switch ($field) {
+ case AuthModel::TITLE:
+ $value = anchor(
+ current_url() . '/view/' . $entity->getPK(),
+ getFieldView_AuthHelper($field, $entity, $viewDatas),
+ ["target" => "_self"]
+ );
+ break;
+ default:
+ if (in_array($field, $viewDatas['filter_fields'])) {
+ $attributes["onChange"] = sprintf(
+ 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value',
+ current_url(),
+ $entity->getPK(),
+ $field,
+ $field
+ );
+ $value = getFieldForm_AuthHelper($field, $entity, $viewDatas, $attributes);
+ }
+ $value = getFieldView_AuthHelper($field, $entity, $viewDatas);
+ break;
+ }
+ return $value;
+}
diff --git a/app/Helpers/Admin/Cloudflare/Record_helper.php b/app/Helpers/Admin/Cloudflare/Record_helper.php
index a6135e2..804f082 100644
--- a/app/Helpers/Admin/Cloudflare/Record_helper.php
+++ b/app/Helpers/Admin/Cloudflare/Record_helper.php
@@ -1,4 +1,7 @@
"select-field"]);
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]);
// foreach ($viewDatas['field_options'][$field] as $key => $label) {
@@ -28,7 +31,7 @@ function getFieldForm_RecordHelper(string $field, mixed $value, array $viewDatas
// }
// return implode(" ", $checkboxs);
break;
- case 'content':
+ case RecordModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)123.123.123.123", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'hosts':
@@ -69,13 +72,6 @@ function getFieldView_RecordHelper(string $field, mixed $entity, array $viewData
case 'sale':
$value = number_format(!$value ? 0 : $value) . "원";
break;
- case 'stock':
- case 'view_cnt':
- $value = number_format(!$value ? 0 : $value);
- break;
- case 'content':
- $value = html_entity_decode($value);
- break;
case 'updated_at':
case 'created_at':
$value = $value ? date("Y-m-d", strtotime($value)) : "";
@@ -109,8 +105,7 @@ function getListHeaders_RecordHelper(string $field, array $viewDatas, array $att
function getListColumns_RecordHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []): string
{
switch ($field) {
- case 'title':
- case 'name':
+ case RecordModel::TITLE:
$value = anchor(
current_url() . '/view/' . $entity->getPK(),
getFieldView_RecordHelper($field, $entity, $viewDatas),
diff --git a/app/Helpers/Admin/Cloudflare/Zone_helper.php b/app/Helpers/Admin/Cloudflare/Zone_helper.php
index 10a8955..2b73950 100644
--- a/app/Helpers/Admin/Cloudflare/Zone_helper.php
+++ b/app/Helpers/Admin/Cloudflare/Zone_helper.php
@@ -1,4 +1,7 @@
"select-field"]);
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]);
// foreach ($viewDatas['field_options'][$field] as $key => $label) {
@@ -28,14 +31,13 @@ function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas,
// }
// return implode(" ", $checkboxs);
break;
- case 'content':
- $form = form_input($field, $value, ["placeholder" => "예)123.123.123.123", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
+ case ZoneModel::TITLE:
+ $form = form_input($field, $value, ["placeholder" => "예)example.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'domains':
case 'hosts':
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '5']);
break;
- case "type":
case "proxied":
case "development_mode":
case "ipv6":
@@ -72,10 +74,6 @@ function getFieldView_ZoneHelper(string $field, mixed $entity, array $viewDatas,
case 'sale':
$value = number_format(!$value ? 0 : $value) . "원";
break;
- case 'stock':
- case 'view_cnt':
- $value = number_format(!$value ? 0 : $value);
- break;
case 'content':
$value = html_entity_decode($value);
break;
@@ -112,8 +110,7 @@ function getListHeaders_ZoneHelper(string $field, array $viewDatas, array $attri
function getListColumns_ZoneHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []): string
{
switch ($field) {
- case 'title':
- case 'name':
+ case ZoneModel::TITLE:
$value = anchor(
current_url() . '/view/' . $entity->getPK(),
getFieldView_ZoneHelper($field, $entity, $viewDatas),
diff --git a/app/Language/en/Admin/Cloudflare/Account.php b/app/Language/en/Admin/Cloudflare/Account.php
index 86f818c..12fd1ef 100644
--- a/app/Language/en/Admin/Cloudflare/Account.php
+++ b/app/Language/en/Admin/Cloudflare/Account.php
@@ -3,11 +3,8 @@ return [
'title' => "Account정보",
'label' => [
'uid' => "번호",
- 'id' => "인증ID",
- 'authkey' => "인증Key",
- 'oldkey' => "이전인증Key",
- 'title' => "인증명",
- 'type' => "인증방식",
+ 'title' => "계정명",
+ 'type' => "계정형식",
'status' => "상태",
'updated_at' => "수정일",
'created_at' => "작성일",
diff --git a/app/Language/en/Admin/Cloudflare/Auth.php b/app/Language/en/Admin/Cloudflare/Auth.php
new file mode 100644
index 0000000..b2e1aff
--- /dev/null
+++ b/app/Language/en/Admin/Cloudflare/Auth.php
@@ -0,0 +1,17 @@
+ "Auth정보",
+ 'label' => [
+ 'uid' => "번호",
+ 'id' => "인증ID",
+ 'authkey' => "인증Key",
+ 'oldkey' => "이전인증Key",
+ 'status' => "상태",
+ 'updated_at' => "수정일",
+ 'created_at' => "작성일",
+ ],
+ "STATUS" => [
+ "use" => "사용",
+ "unuse" => "사용않함",
+ ],
+];
diff --git a/app/Libraries/MySocket/Cloudflare/AccountSocket.php b/app/Libraries/MySocket/Cloudflare/AccountSocket.php
index 6db7ee5..9f161b9 100644
--- a/app/Libraries/MySocket/Cloudflare/AccountSocket.php
+++ b/app/Libraries/MySocket/Cloudflare/AccountSocket.php
@@ -2,15 +2,26 @@
namespace App\Libraries\MySocket\Cloudflare;
-use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\AccountModel;
+use App\Libraries\MySocket\CloudflareSocket;
+use App\Entities\Cloudflare\AuthEntity;
class AccountSocket extends CloudflareSocket
{
- public function __construct(string $email, string $auth_key)
+ private $_model = null;
+ private $_auth_entity = null;
+ public function __construct(AuthEntity $auth_entity)
{
- parent::__construct();
- $this->setAdapter($email, $auth_key);
+ $this->_auth_entity = $auth_entity;
+ parent::__construct($auth_entity);
+ }
+
+ protected function getModel(): AccountModel
+ {
+ if ($this->_model === null) {
+ $this->_model = new AccountModel();
+ }
+ return $this->_model;
}
//Result 형태
// [
@@ -36,8 +47,20 @@ class AccountSocket extends CloudflareSocket
$formDatas['created_at'] = $result->created_on;
return $formDatas;
}
- public function create(): array
+ public function reload(): void
{
- return $this->reload_procedure('accounts');
+ log_message("notice", "-----{$this->_auth_entity->getTitle()} 처리 시작-----");
+ $entity_uids = [];
+ $results = $this->reload_procedure("accounts");
+ foreach ($results as $result) {
+ $formDatas = $this->getArrayByResult($result);
+ $entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
+ $entity_uids[] = $entity->getPK();
+ }
+ //부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
+ $this->getModel()->where(AccountModel::PARENT, $this->_auth_entity);
+ $this->getModel()->whereNotIn(AccountModel::PK, $entity_uids);
+ $this->getModel()->delete();
+ log_message("notice", "-----{$this->_auth_entity->getTitle()} 처리[" . count($results) . "개] 완료-----");
}
}
diff --git a/app/Libraries/MySocket/Cloudflare/RecordSocket.php b/app/Libraries/MySocket/Cloudflare/RecordSocket.php
index 35b9b52..a242fc9 100644
--- a/app/Libraries/MySocket/Cloudflare/RecordSocket.php
+++ b/app/Libraries/MySocket/Cloudflare/RecordSocket.php
@@ -2,23 +2,35 @@
namespace App\Libraries\MySocket\Cloudflare;
-use App\Entities\Cloudflare\AccountEntity;
-use App\Entities\Cloudflare\RecordEntity;
-use App\Entities\Cloudflare\ZoneEntity;
-use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\RecordModel;
+use App\Libraries\MySocket\CloudflareSocket;
+use App\Entities\Cloudflare\ZoneEntity;
+use App\Entities\Cloudflare\RecordEntity;
+use App\Entities\Cloudflare\AuthEntity;
class RecordSocket extends CloudflareSocket
{
- private $_myStorage = null;
- private $_account_entity = null;
+ private $_model = null;
private $_zone_entity = null;
- public function __construct(AccountEntity $account_entity, ZoneEntity $zone_entity)
+ public function __construct(ZoneEntity $zone_entity)
{
- parent::__construct();
- $this->_account_entity = $account_entity;
$this->_zone_entity = $zone_entity;
- $this->setAdapter($account_entity->getID(), $account_entity->getAuthKey());
+ $account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent());
+ if ($account_entity === null) {
+ throw new \Exception("해당 계정정보를 찾을수 없습니다.");
+ }
+ $auth_entity = $this->getAuthModel()->getEntityByPK($account_entity->getParent());
+ if ($auth_entity === null) {
+ throw new \Exception("해당 계정정보를 찾을수 없습니다.");
+ }
+ parent::__construct($auth_entity);
+ }
+ protected function getModel(): RecordModel
+ {
+ if ($this->_model === null) {
+ $this->_model = new RecordModel();
+ }
+ return $this->_model;
}
public function getArrayByResult($result, array $formDatas = []): array
{
@@ -38,21 +50,22 @@ class RecordSocket extends CloudflareSocket
$formDatas['created_at'] = $result->created_on;
return $formDatas;
}
- public function create(string $host, array $formDatas): mixed
+ public function create(string $host, string $type, string $content, string $proxied): RecordEntity
{
//Socket용
//도메인생성을 위해 Cloudflare에 전송
- $cf = $this->request()->post('zones/' . $this->_zone_entity->getPK() . '/dns_records', [
+ $cf = $this->getClient()->post('zones/' . $this->_zone_entity->getPK() . '/dns_records', [
'name' => $host,
- 'type' => $formDatas['type'],
- 'content' => $formDatas['content'],
- 'proxied' => isset($formDatas['proxied']) && $formDatas['proxied'] === 'on' ? true : false
+ 'type' => $type,
+ 'content' => $content,
+ 'proxied' => $proxied === 'on' ? true : false
]);
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
}
- return $cf->result;
+ $formDatas = $this->getArrayByResult($cf->result);
+ return $this->getModel()->create($formDatas);
}
public function modify(RecordEntity $entity, array $formDatas): RecordEntity
{
@@ -72,7 +85,7 @@ class RecordSocket extends CloudflareSocket
$datas['proxied'] = false;
$datas['ttl'] = 120;
}
- $cf = $this->request()->put('zones/' . $this->_zone_entity->getPK() . '/dns_records', $datas);
+ $cf = $this->getClient()->put('zones/' . $this->_zone_entity->getPK() . '/dns_records', $datas);
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@@ -82,38 +95,51 @@ class RecordSocket extends CloudflareSocket
}
public function delete(RecordEntity $entity): void
{
- $cf = $this->request()->delete('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK());
+ $cf = $this->getClient()->delete('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK());
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
}
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
}
- public function sync(RecordEntity $entity): RecordEntity
+ public function sync(RecordEntity $entity): void
{
- $cf = $this->request()->get('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK());
- $cf = json_decode($cf->getBody());
- if (!$cf->success) {
- throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
- }
- log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
- return new RecordEntity($this->getArrayByResult($cf->result));
+ //Sync형태
+ // $cf = $this->getClient()->get("zones/{$this->_zone_entity->getPK()}/dns_records/" . $entity->getPK());
+ // $cf = json_decode($cf->getBody());
+ // if (!$cf->success) {
+ // throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
+ // }
+ // return new RecordEntity($this->getArrayByResult($cf->result));
+ //Async형태
+ $promise = $this->getClient()->getAsync("zones/{$this->_zone_entity->getPK()}/dns_records/{$entity->getPK()}");
+ $promise->then(
+ onFulfilled: function ($response) use ($entity): RecordEntity {
+ $record = json_decode($response->getBody(), true)['result'];
+ return $this->getModel()->modify($entity, $this->getArrayByResult($record));
+ },
+ onRejected: function ($error) {
+ log_message('error', 'Failed to fetch DNS records: ' . $error->getMessage());
+ // throw new \Exception('Failed to fetch DNS records: ' . $error->getMessage());
+ }
+ );
+ $promise->wait();
}
//Reload
- public function reload(RecordModel $model): void
+ public function reload(): void
{
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리 시작-----");
$entity_uids = [];
$results = $this->reload_procedure("zones/{$this->_zone_entity->getPK()}/dns_records");
foreach ($results as $result) {
$formDatas = $this->getArrayByResult($result);
- $entity = $model->modify($model->getEntity(), $formDatas);
+ $entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
$entity_uids[] = $entity->getPK();
}
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
- $model->where($model::PARENT, $this->_zone_entity);
- $model->whereNotIn($model::PK, $entity_uids);
- $model->delete();
+ $this->getModel()->where(RecordModel::PARENT, $this->_zone_entity);
+ $this->getModel()->whereNotIn(RecordModel::PK, $entity_uids);
+ $this->getModel()->delete();
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리[" . count($results) . "개] 완료-----");
}
}
diff --git a/app/Libraries/MySocket/Cloudflare/ZoneSocket.php b/app/Libraries/MySocket/Cloudflare/ZoneSocket.php
index d12c9ac..ed169f7 100644
--- a/app/Libraries/MySocket/Cloudflare/ZoneSocket.php
+++ b/app/Libraries/MySocket/Cloudflare/ZoneSocket.php
@@ -2,22 +2,33 @@
namespace App\Libraries\MySocket\Cloudflare;
-use App\Entities\Cloudflare\AccountEntity;
-use App\Entities\Cloudflare\ZoneEntity;
-use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\ZoneModel;
+use App\Libraries\MySocket\CloudflareSocket;
+use App\Entities\Cloudflare\ZoneEntity;
+use App\Entities\Cloudflare\AuthEntity;
+use App\Entities\Cloudflare\AccountEntity;
class ZoneSocket extends CloudflareSocket
{
- private $_myStorage = null;
+ private $_model = null;
private $_account_entity = null;
public function __construct(AccountEntity $account_entity)
{
- parent::__construct();
$this->_account_entity = $account_entity;
- $this->setAdapter($account_entity->getID(), $account_entity->getAuthKey());
+ $auth_entity = $this->getAuthModel()->getEntityByPK($this->_account_entity->getParent());
+ if ($auth_entity === null) {
+ throw new \Exception("해당 계정정보를 찾을수 없습니다.");
+ }
+ parent::__construct($auth_entity);
}
- public function getArrayByResult($result, array $formDatas = []): array
+ protected function getModel(): ZoneModel
+ {
+ if ($this->_model === null) {
+ $this->_model = new ZoneModel();
+ }
+ return $this->_model;
+ }
+ protected function getArrayByResult($result, array $formDatas = []): array
{
$formDatas[ZoneModel::PK] = $result->id;
$formDatas[ZoneModel::PARENT] = $result->account->id;
@@ -47,9 +58,9 @@ class ZoneSocket extends CloudflareSocket
return $formDatas;
}
//Cfzone에서 가져온 값을 zone에 setting
- final public function getCFSetting(ZoneEntity $entity): ZoneEntity
+ protected function getCFSetting(ZoneEntity $entity): ZoneEntity
{
- $cf = $this->request()->patch('zones/' . $entity->getPK() . '/settings/');
+ $cf = $this->getClient()->patch('zones/' . $entity->getPK() . '/settings/');
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@@ -69,9 +80,9 @@ class ZoneSocket extends CloudflareSocket
}
return $entity;
}
- public function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity
+ protected function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity
{
- $cf = $this->request()->patch('zones/' . $entity->getPK() . '/settings/' . $field, array('value' => $value));
+ $cf = $this->getClient()->patch('zones/' . $entity->getPK() . '/settings/' . $field, array('value' => $value));
$cf = json_decode($cf->getBody());
if (!$cf->success || $cf->result->id !== $field) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 {$field}->{$value} 변경실패:\n" . var_export($cf, true));
@@ -80,11 +91,11 @@ class ZoneSocket extends CloudflareSocket
$entity->$field = $cf->result->value;
return $entity;
}
- public function create(string $domain, bool $jump_start = false): mixed
+ public function create(string $domain, bool $jump_start = false): ZoneEntity
{
//Socket용
//도메인생성을 위해 Cloudflare에 전송
- $cf = $this->request()->post('zones/', [
+ $cf = $this->getClient()->post('zones/', [
'accountId' => $this->_account_entity->getPK(),
'name' => $domain,
'jump_start' => $jump_start,
@@ -93,7 +104,14 @@ class ZoneSocket extends CloudflareSocket
if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
}
- return $cf->result;
+ //Storage용
+ $formDatas = $this->getArrayByResult($cf->result);
+ $entity = $this->getModel()->create($formDatas);
+ //아래는 추가 셋팅 ipv6 TurnOFF , //Development mode TurnOFF
+ $entity = $this->setCFSetting($entity, 'ipv6', 'off');
+ $entity = $this->setCFSetting($entity, 'development_mode', 'off');
+ $entity = $this->setCFSetting($entity, 'security_level', 'medium');
+ return $entity;
}
public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity
{
@@ -106,7 +124,7 @@ class ZoneSocket extends CloudflareSocket
}
public function delete(ZoneEntity $entity): void
{
- $cf = $this->request()->delete('zones/' . $entity->getPK());
+ $cf = $this->getClient()->delete('zones/' . $entity->getPK());
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@@ -115,7 +133,7 @@ class ZoneSocket extends CloudflareSocket
}
public function sync(ZoneEntity $entity): ZoneEntity
{
- $cf = $this->request()->get('zones/' . $entity->getPK());
+ $cf = $this->getClient()->get('zones/' . $entity->getPK());
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@@ -124,20 +142,20 @@ class ZoneSocket extends CloudflareSocket
return new ZoneEntity($this->getArrayByResult($cf->result));
}
//Reload
- public function reload(ZoneModel $model): void
+ public function reload(): void
{
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리 시작-----");
$entity_uids = [];
$results = $this->reload_procedure('zones');
foreach ($results as $result) {
$formDatas = $this->getArrayByResult($result);
- $entity = $model->modify($model->getEntity(), $formDatas);
+ $entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
$entity_uids[] = $entity->getPK();
}
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
- $model->where($model::PARENT, $this->_account_entity);
- $model->whereNotIn($model::PK, $entity_uids);
- $model->delete();
+ $this->getModel()->where(ZoneModel::PARENT, $this->_account_entity);
+ $this->getModel()->whereNotIn(ZoneModel::PK, $entity_uids);
+ $this->getModel()->delete();
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리[" . count($results) . "개] 완료-----");
}
}
diff --git a/app/Libraries/MySocket/CloudflareSocket.php b/app/Libraries/MySocket/CloudflareSocket.php
index d592464..0bf1eb3 100644
--- a/app/Libraries/MySocket/CloudflareSocket.php
+++ b/app/Libraries/MySocket/CloudflareSocket.php
@@ -3,30 +3,54 @@
namespace App\Libraries\MySocket;
-use Cloudflare\API\Auth\APIKey;
-use Cloudflare\API\Adapter\Guzzle;
+use GuzzleHttp\Client;
+use App\Models\Cloudflare\AuthModel;
+use App\Models\Cloudflare\AccountModel;
use App\Libraries\CommonLibrary;
+use App\Entities\Cloudflare\AuthEntity;
abstract class CloudflareSocket extends CommonLibrary
{
private static int $_request = 0;
private static int $_request_max = 100;
private static int $_request_timewait = 60;
- private $_adapter = null;
- protected function __construct()
+ private $_authModel = null;
+ private $_accountModel = null;
+ private $_client = null;
+ private $_auth_entity = null;
+ protected function __construct(AuthEntity $auth_entity)
{
parent::__construct();
+ $this->_auth_entity = $auth_entity;
self::$_request_max = getenv("cfmgr.request.max");
}
- abstract public function getArrayByResult($result, array $formDatas = []): array;
- final protected function setAdapter(string $email, string $auth_key): void
+ abstract protected function getArrayByResult($result, array $formDatas = []): array;
+ final protected function getAuthModel(): AuthModel
{
- $this->_adapter = new Guzzle(new APIKey($email, $auth_key));
+ if ($this->_authModel === null) {
+ $this->_authModel = new AuthModel();
+ }
+ return $this->_authModel;
}
- final public function request(): Guzzle
+ final protected function getAccountModel(): AccountModel
{
- if ($this->_adapter === null) {
- throw new \Exception(+__FUNCTION__ . " => Adapter를 정의하지 않았습니다.");
+ if ($this->_accountModel === null) {
+ $this->_accountModel = new AccountModel();
+ }
+ return $this->_accountModel;
+ }
+ final protected function getClient(): Client
+ {
+ if ($this->_client === null) {
+ // Guzzle HTTP 클라이언트를 설정하면서 Cloudflare API 토큰 사용
+ $this->_client = new Client([
+ 'base_uri' => 'https://api.cloudflare.com/client/v4/',
+ 'headers' => [
+ 'X-Auth-Email' => $this->_auth_entity->getID(), // 인증 토큰 사용
+ 'X-Auth-Key' => $this->_auth_entity->getAuthKey(), // 인증 토큰 사용
+ 'Content-Type' => 'application/json',
+ ]
+ ]);
}
if (self::$_request >= self::$_request_max) {
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
@@ -35,8 +59,9 @@ abstract class CloudflareSocket extends CommonLibrary
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
}
self::$_request++;
- return $this->_adapter;
+ return $this->_client;
}
+
final protected function reload_procedure($uri): array
{
$page = 1; //Page는 1부터 시작해야함
@@ -48,7 +73,7 @@ abstract class CloudflareSocket extends CommonLibrary
'per_page' => $perpage_max,
'match' => 'all',
];
- $cf = $this->request()->get($uri, $query);
+ $cf = $this->getClient()->get($uri, $query);
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php
index 913bca7..edf51f6 100644
--- a/app/Models/Cloudflare/AccountModel.php
+++ b/app/Models/Cloudflare/AccountModel.php
@@ -2,19 +2,21 @@
namespace App\Models\Cloudflare;
-use App\Entities\Cloudflare\AccountEntity;
use App\Models\CommonModel;
+use App\Entities\Cloudflare\AuthEntity;
+use App\Entities\Cloudflare\AccountEntity;
class AccountModel extends CommonModel
{
const TABLE = "cloudflareaccount";
const PK = "uid";
const TITLE = "title";
+ const PARENT = "account_uid";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $useAutoIncrement = false;
protected $returnType = AccountEntity::class; //object,array,entity명::class
- protected $allowedFields = [self::PK, self::TITLE, 'authkey', 'oldkey', 'title', 'type', 'status', 'updated_at', 'created_at'];
+ protected $allowedFields = [self::PK, self::PARENT, self::TITLE, 'type', 'status', 'updated_at', 'created_at'];
protected $useTimestamps = true;
public function __construct()
{
@@ -27,18 +29,11 @@ class AccountModel extends CommonModel
public function getFieldRule(string $action, string $field, array $rules): array
{
switch ($field) {
- case self::TITLE:
- $rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]";
- break;
- case 'id':
- $rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]";
- break;
- case "authkey":
+ case self::PARENT:
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
- ;
break;
- case "oldkey":
- $rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
+ case self::TITLE:
+ $rules[$field] = "required|trim|string";
break;
case "type":
$rules[$field] = "if_exist|in_list[standard,enterprise]";
@@ -66,9 +61,14 @@ class AccountModel extends CommonModel
}
public function getEntityByID(string $id): null|AccountEntity
{
- $this->where('id', $id);
+ $this->where(self::TITLE, $id);
return $this->getEntity();
}
+ public function getEntitysByParent(AuthEntity $auth_entity)
+ {
+ $this->where(self::PARENT, $auth_entity->getPK());
+ return $this->getEntitys();
+ }
//create용
public function create(array $formDatas = []): AccountEntity
{
diff --git a/app/Models/Cloudflare/AuthModel.php b/app/Models/Cloudflare/AuthModel.php
new file mode 100644
index 0000000..0f27c84
--- /dev/null
+++ b/app/Models/Cloudflare/AuthModel.php
@@ -0,0 +1,75 @@
+orderBy(self::TITLE, 'asc');
+ $options = parent::getFormFieldOption($field, $options);
+ break;
+ }
+ return $options;
+ }
+ public function getEntityByPK(int $uid): null|AuthEntity
+ {
+ $this->where($this->getPKField(), $uid);
+ return $this->getEntity();
+ }
+ public function getEntityByID(string $id): null|AuthEntity
+ {
+ $this->where('id', $id);
+ return $this->getEntity();
+ }
+ //create용
+ public function create(array $formDatas = []): AuthEntity
+ {
+ return $this->create_process(new AuthEntity(), $formDatas);
+ }
+ //modify용
+ public function modify(AuthEntity $entity, array $formDatas): AuthEntity
+ {
+ return $this->modify_process($entity, $formDatas);
+ }
+}
diff --git a/app/Views/admin/cloudflare/account/index.php b/app/Views/admin/cloudflare/account/index.php
index ba262a2..07ba7a6 100644
--- a/app/Views/admin/cloudflare/account/index.php
+++ b/app/Views/admin/cloudflare/account/index.php
@@ -69,19 +69,4 @@
= $viewDatas['pagination'] ?>
= form_close() ?>
-
-
= $this->endSection() ?>
\ No newline at end of file
diff --git a/app/Views/admin/cloudflare/account/create.php b/app/Views/admin/cloudflare/auth/create.php
similarity index 80%
rename from app/Views/admin/cloudflare/account/create.php
rename to app/Views/admin/cloudflare/auth/create.php
index 5386d0a..14bbfd8 100644
--- a/app/Views/admin/cloudflare/account/create.php
+++ b/app/Views/admin/cloudflare/auth/create.php
@@ -3,9 +3,9 @@