cfmgrv4 init...1

This commit is contained in:
최준흠 2024-09-27 17:51:58 +09:00
parent 5c7aeb0625
commit 357080bb7a
30 changed files with 503 additions and 549 deletions

View File

@ -156,6 +156,7 @@ define("MESSENGERS", [
//아이콘 및 Sound관련 //아이콘 및 Sound관련
define('ICONS', [ define('ICONS', [
'LOGO' => '<img src="/images/logo/android-icon-48x48.png">', 'LOGO' => '<img src="/images/logo/android-icon-48x48.png">',
'MEMBER' => '<i class="bi bi-people"></i>',
'LOGIN' => '<i class="bi bi-shield-check"></i>', 'LOGIN' => '<i class="bi bi-shield-check"></i>',
'LOGOUT' => '<i class="bi bi-sign-stop-fill"></i>', 'LOGOUT' => '<i class="bi bi-sign-stop-fill"></i>',
'HOME' => '<i class="bi bi-house"></i>', 'HOME' => '<i class="bi bi-house"></i>',
@ -179,7 +180,10 @@ define('ICONS', [
'LEFT' => '<i class="bi bi-arrow-left"></i>', 'LEFT' => '<i class="bi bi-arrow-left"></i>',
'RIGHT' => '<i class="bi bi-arrow-right"></i>', 'RIGHT' => '<i class="bi bi-arrow-right"></i>',
'IMAGE_FILE' => '<i class="bi bi-file-earmark-image"></i>', 'IMAGE_FILE' => '<i class="bi bi-file-earmark-image"></i>',
'GOOGLE' => '<i class="fa-brands fa-google"></i>', 'GOOGLE' => '<i class="bi bi-google"></i>',
'CLOUD' => '<i class="bi bi-cloud"></i>',
'SIGNPOST' => '<i class="bi bi-signpost"></i>',
'SIGNPOST2' => '<i class="bi bi-signpost-2"></i>',
]); ]);
//배너관련 //배너관련
define('TOP_BANNER', [ define('TOP_BANNER', [

View File

@ -26,10 +26,12 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function ($rou
}); });
$routes->group('zone', function ($routes) { $routes->group('zone', function ($routes) {
$routes->get('/', 'ZoneController::index'); $routes->get('/', 'ZoneController::index');
$routes->post('create/(:uuid)', 'RecordController::create/$1'); $routes->get('create', 'ZoneController::create_form');
$routes->post('create/(:uuid)', 'ZoneController::create/$1');
}); });
$routes->group('record', function ($routes) { $routes->group('record', function ($routes) {
$routes->get('/', 'RecordController::index'); $routes->get('/', 'RecordController::index');
$routes->get('create', 'RecordController::create_form');
$routes->post('create/(:uuid)', 'RecordController::create/$1'); $routes->post('create/(:uuid)', 'RecordController::create/$1');
}); });
}); });

View File

@ -2,7 +2,7 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Libraries\MyCloudflare\Account; use App\Libraries\MySocket\Cloudflare\AccountSocket;
use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\AccountModel;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -11,8 +11,10 @@ use Psr\Log\LoggerInterface;
class AccountController extends CloudflareController class AccountController extends CloudflareController
{ {
private $_myLibrary = null; private $_mySocket = null;
private $_model = null; private $_model = null;
private $_email = "";
private $_auth_key = "";
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
@ -28,39 +30,55 @@ class AccountController extends CloudflareController
} }
return $this->_model; return $this->_model;
} }
final protected function getMyLibrary(): Account final protected function getMySocket(): AccountSocket
{ {
if ($this->_myLibrary === null) { if ($this->_mySocket === null) {
$this->_myLibrary = new Account(); $this->_mySocket = new AccountSocket($this->_email, $this->_auth_key);
} }
return $this->_myLibrary; return $this->_mySocket;
} }
//생성 //생성
protected function create_init(): void public function create_form(): RedirectResponse|string
{ {
$this->action = 'create';
$this->fields = ['id', 'authkey']; $this->fields = ['id', 'authkey'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->filter_fields = []; $this->filter_fields = [];
$this->field_rules = $this->getModel()->getFieldRules($this->fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->field_options = $this->getFormFieldOptions(); return $this->create_form_procedure();
$this->getModel()->setAction($this->action);
} }
protected function create_process(): void protected function create_process(): void
{ {
parent::create_process(); parent::create_process();
$this->getMyLibrary()->create($this->formDatas); $results = $this->getMySocket()->create();
$this->entitys = [];
foreach ($results as $result) {
$this->formDatas = $this->getMySocket()->getArrayByResult($result);
$entity = $this->getModel()->create($this->formDatas);
log_message("notice", "Account:" . __FUNCTION__ . "=> {$entity->getTitle()} 작업을 완료하였습니다.");
$this->entitys[] = $entity;
}
} }
//수정 public function create(): RedirectResponse
protected function modify_init(): void {} {
// 리스트 $this->fields = ['id', 'authkey'];
public function list_init(): void $this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
// $this->filter_fields = [];
// $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->create_validate();
$this->formDatas = $this->getFormDatas();
//Socket 인증용
$this->_email = $this->formDatas['id'];
$this->auth_key = $this->formDatas['authkey'];
return $this->create_procedure();
}
// 리스트
public function index(): string
{ {
$this->action = 'index';
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at']; $this->fields = [$this->getModel()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->filter_fields = ['type', 'status']; $this->filter_fields = ['type', 'status'];
$this->batchjob_fields = ['status']; $this->batchjob_fields = ['status'];
$this->field_rules = $this->getModel()->getFieldRules($this->fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->field_options = $this->getFormFieldOptions(); return $this->list_procedure();
$this->getModel()->setAction($this->action);
} }
} }

View File

@ -5,8 +5,8 @@ namespace App\Controllers\Admin\Cloudflare;
use App\Controllers\Admin\AdminController; use App\Controllers\Admin\AdminController;
use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\RecordModel;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -21,6 +21,7 @@ abstract class CloudflareController extends AdminController
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_path .= "Cloudflare/"; $this->class_path .= "Cloudflare/";
} }
abstract protected function getMySocket(): mixed;
final protected function getAccountModel(): AccountModel final protected function getAccountModel(): AccountModel
{ {
if ($this->_accountModel === null) { if ($this->_accountModel === null) {
@ -42,7 +43,19 @@ abstract class CloudflareController extends AdminController
} }
return $this->_recordModel; return $this->_recordModel;
} }
protected function modify_process_submit(): void final protected function reload_procedure(): RedirectResponse
{ {
try {
//Transaction Start
$this->getModel()->transStart();
$$this->getMySocket()->reload($this->getModel());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
}
} }
} }

View File

@ -2,7 +2,7 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Libraries\MyCloudflare\Record; use App\Libraries\MySocket\Cloudflare\RecordSocket;
use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\RecordModel;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -29,12 +29,12 @@ class RecordController extends CloudflareController
} }
return $this->_model; return $this->_model;
} }
final protected function getMyLibrary(): Record final protected function getMySocket(): RecordSocket
{ {
if ($this->_myLibrary === null) { if ($this->_mySocket === null) {
$this->_myLibrary = new Record($this->_account_entity, $this->_zone_entity); $this->_mySocket = new RecordSocket($this->_account_entity, $this->_zone_entity);
} }
return $this->_myLibrary; return $this->_mySocket;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -42,8 +42,8 @@ class RecordController extends CloudflareController
case $this->getModel()::PARENT: case $this->getModel()::PARENT:
$this->getZoneModel()->where('status', DEFAULTS['STATUS']); $this->getZoneModel()->where('status', DEFAULTS['STATUS']);
$options[$field] = [ $options[$field] = [
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', DEFAULTS['EMPTY'] => lang($this->class_path . '.label.' . $field) . ' 선택',
...$this->getZoneModel()->getFormFieldOption($field, $options), $this->getZoneModel()->getFormFieldOption($field, $options),
]; ];
break; break;
default: default:
@ -68,14 +68,14 @@ class RecordController extends CloudflareController
} }
return $formDatas; return $formDatas;
} }
protected function create_init(): void //생성
public function create_form(): RedirectResponse|string
{ {
$this->action = 'create';
$this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'hosts']; $this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'hosts'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied'];
$this->field_rules = $this->getModel()->getFieldRules($this->fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->field_options = $this->getFormFieldOptions(); return $this->create_form_procedure();
$this->getModel()->setAction($this->action);
} }
protected function create_validate(): void protected function create_validate(): void
{ {
@ -91,20 +91,45 @@ class RecordController extends CloudflareController
} }
//Record생성 //Record생성
foreach ($this->formDatas['hosts'] as $host) { foreach ($this->formDatas['hosts'] as $host) {
$this->getMyLibrary()->create($host, $this->formDatas); $result = $this->getMySocket()->create($host, [
'type' => $this->formDatas['type'],
'content' => $this->formDatas['content'],
'proxied' => $this->formDatas['proxied'],
]);
$formDatas = $this->getMySocket()->getArrayByResult($result);
$entity = $this->getRecordModel()->create($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
} }
} }
//수정 public function create(): RedirectResponse
protected function modify_init(): void {} {
// 리스트 $this->fields = [$this->getModel()::PARENT, 'type', 'content', 'proxied', 'hosts'];
public function list_init(): void $this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
// $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied'];
// $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->create_validate();
$this->formDatas = $this->getFormDatas();
//부모데이터 정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
return $this->create_procedure();
}
//수정
// 리스트
public function index(): string
{ {
$this->action = 'index';
$this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at']; $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'content', 'ttl', 'proxied', 'locked', 'updated_at', 'created_at'];
$this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied']; $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->batchjob_fields = ['proxied']; $this->batchjob_fields = ['proxied'];
$this->field_rules = $this->getModel()->getFieldRules($this->fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->field_options = $this->getFormFieldOptions(); return $this->list_procedure();
$this->getModel()->setAction($this->action); }
//reload
public function reload(string $zone_uid): RedirectResponse
{
//부모데이터 정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($zone_uid);
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent());
return $this->reload_procedure();
} }
} }

View File

@ -2,8 +2,8 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Libraries\MyCloudflare\Record; use App\Libraries\MySocket\Cloudflare\RecordSocket;
use App\Libraries\MyCloudflare\Zone; use App\Libraries\MySocket\Cloudflare\ZoneSocket;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -12,7 +12,7 @@ use Psr\Log\LoggerInterface;
class ZoneController extends CloudflareController class ZoneController extends CloudflareController
{ {
private $_myLibrary = null; private $_mySocket = null;
private $_account_entity = null; private $_account_entity = null;
private $_model = null; private $_model = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
@ -30,12 +30,12 @@ class ZoneController extends CloudflareController
} }
return $this->_model; return $this->_model;
} }
final protected function getMyLibrary(): Zone final protected function getMySocket(): ZoneSocket
{ {
if ($this->_myLibrary === null) { if ($this->_mySocket === null) {
$this->_myLibrary = new Zone($this->_account_entity); $this->_mySocket = new ZoneSocket($this->_account_entity);
} }
return $this->_myLibrary; return $this->_mySocket;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -43,8 +43,8 @@ class ZoneController extends CloudflareController
case $this->getModel()::PARENT: case $this->getModel()::PARENT:
$this->getAccountModel()->where('status', DEFAULTS['STATUS']); $this->getAccountModel()->where('status', DEFAULTS['STATUS']);
$options[$field] = [ $options[$field] = [
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', DEFAULTS['EMPTY'] => lang($this->class_path . '.label.' . $field) . ' 선택',
...$this->getAccountModel()->getFormFieldOption($field, $options), $this->getAccountModel()->getFormFieldOption($field, $options),
]; ];
break; break;
default: default:
@ -74,15 +74,7 @@ class ZoneController extends CloudflareController
} }
return $formDatas; return $formDatas;
} }
protected function create_init(): void //생성
{
$this->action = 'create';
$this->fields = [$this->$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied'];
$this->filter_fields = [$this->$this->getModel()::PARENT, 'type', 'proxied'];
$this->field_rules = $this->getModel()->getFieldRules($this->fields);
$this->field_options = $this->getFormFieldOptions();
$this->getModel()->setAction($this->action);
}
protected function create_validate(): void protected function create_validate(): void
{ {
//domains,hosts를 제외한 fields Valid처리 //domains,hosts를 제외한 fields Valid처리
@ -90,38 +82,85 @@ class ZoneController extends CloudflareController
} }
protected function create_process(): void protected function create_process(): void
{ {
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); parent::create_process();
if ($this->_account_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다.");
}
//Zone생성 //Zone생성
$zone_entitys = []; $zone_entitys = [];
foreach ($this->formDatas['domains'] as $domain) { foreach ($this->formDatas['domains'] as $domain) {
$zone_entitys[] = $this->getMyLibrary()->create($domain); //Storage용
$result = $this->getMySocket()->create($domain);
$formDatas = $this->getMySocket()->getArrayByResult($result);
$entity = $this->getModel()->create($formDatas);
//아래는 추가 셋팅 ipv6 TurnOFF , //Development mode TurnOFF
$entity = $this->getMySocket()->setCFSetting($entity, 'ipv6', 'off');
$entity = $this->getMySocket()->setCFSetting($entity, 'development_mode', 'off');
$entity = $this->getMySocket()->setCFSetting($entity, 'security_level', 'medium');
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
$zone_entitys[] = $entity;
} }
//Record생성 //Record생성
foreach ($zone_entitys as $zone_entity) { foreach ($zone_entitys as $zone_entity) {
$record = new Record($this->_account_entity, $zone_entity); $record = new RecordSocket($this->_account_entity, $zone_entity);
foreach ($this->formDatas['hosts'] as $host) { foreach ($this->formDatas['hosts'] as $host) {
$record->create($host, [ $result = $record->create($host, [
'type' => $this->formDatas['type'], 'type' => $this->formDatas['type'],
'content' => $this->formDatas['content'], 'content' => $this->formDatas['content'],
'proxied' => $this->formDatas['proxied'], 'proxied' => $this->formDatas['proxied'],
]); ]);
$formDatas = $record->getArrayByResult($result);
$entity = $this->getRecordModel()->create($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
} }
} }
} }
//수정 public function create(): RedirectResponse
protected function modify_init(): void {} {
// 리스트 $this->fields = [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied'];
public function list_init(): void $this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
// $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied'];
// $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->create_validate();
$this->formDatas = $this->getFormDatas();
//부모데이터 정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
return $this->create_procedure();
}
// //수정
// protected function modify_process(): void
// {
// $this->entity = $this->getMySocket()->modify($this->entity, $this->formDatas);
// }
// public function modify(string $uid): RedirectResponse
// {
// $this->entity = $this->getModel()->getEntityByPK($uid);
// if ($this->entity === null) {
// throw new \Exception("해당 정보를 찾을수 없습니다.");
// }
// //부모데이터 정의
// $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
// $this->fields = [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied'];
// $this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
// // $this->filter_fields = [$this->getModel()::PARENT, 'type', 'proxied'];
// // $this->field_options = $this->getFormFieldOptions($this->filter_fields);
// $this->modify_validate();
// $this->formDatas = $this->getFormDatas();
// return $this->create_procedure();
// }
// 리스트
public function index(): string
{ {
$this->action = 'index';
$this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level', 'status']; $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level', 'status'];
$this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level'];
$this->field_rules = $this->getModel()->getFieldRules($this->fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->field_options = $this->getFormFieldOptions(); return $this->list_procedure();
$this->getModel()->setAction($this->action); }
//reload
public function reload(string $account_uid): RedirectResponse
{
//부모데이터 정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($account_uid);
return $this->reload_procedure();
} }
} }

View File

@ -15,10 +15,6 @@ abstract class MVController extends CommonController
helper('common'); helper('common');
} }
abstract protected function getModel(): mixed; abstract protected function getModel(): mixed;
abstract protected function getMyLibrary(): mixed;
abstract protected function create_init(): void;
abstract protected function modify_init(): void;
abstract protected function list_init(): void;
//Field별 Form Option용 //Field별 Form Option용
protected function getFormFieldOption(string $field, array $options): array protected function getFormFieldOption(string $field, array $options): array
{ {
@ -33,9 +29,9 @@ abstract class MVController extends CommonController
} }
return $options; return $options;
} }
final protected function getFormFieldOptions(array $options = []): array final protected function getFormFieldOptions(array $fields, array $options = []): array
{ {
foreach ($this->filter_fields as $field) { foreach ($fields as $field) {
if (is_array($field)) { if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true));
} }
@ -60,23 +56,7 @@ abstract class MVController extends CommonController
} }
return $formDatas; return $formDatas;
} }
//전송된 데이터 재정의 private function validateFormDatas(array $fields): void
protected function convertFormData(string $field, array $formDatas): array
{
switch ($field) {
default:
break;
}
return $formDatas;
}
final protected function convertFormDatas(array $formDatas = []): array
{
foreach ($this->fields as $field) {
$formDatas = $this->convertFormData($field, $formDatas);
}
return $formDatas;
}
final protected function validateFormDatas(array $fields): void
{ {
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$this->validation = service('validation'); $this->validation = service('validation');
@ -89,12 +69,17 @@ abstract class MVController extends CommonController
} }
} }
// 생성 // 생성
protected function create_form_process(): void {} protected function create_validate(): void
public function create_form(): RedirectResponse|string {
$this->validateFormDatas($this->fields);
}
protected function create_form_process(): void
{
}
final protected function create_form_procedure(): RedirectResponse|string
{ {
try { try {
helper(['form']); helper(['form']);
$this->create_init();
$this->create_form_process(); $this->create_form_process();
$this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
@ -107,18 +92,12 @@ abstract class MVController extends CommonController
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage()); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage());
} }
} }
protected function create_validate(): void protected function create_process(): void
{ {
$this->validateFormDatas($this->fields);
} }
protected function create_process(): void {} final protected function create_procedure(): RedirectResponse
public function create(): RedirectResponse
{ {
try { try {
$this->create_init();
$this->create_validate();
$this->formDatas = $this->getFormDatas();
$this->formDatas = $this->convertFormDatas($this->formDatas);
//Transaction Start //Transaction Start
$this->getModel()->transStart(); $this->getModel()->transStart();
$this->create_process(); $this->create_process();
@ -137,18 +116,13 @@ abstract class MVController extends CommonController
{ {
$this->validateFormDatas($this->fields); $this->validateFormDatas($this->fields);
} }
protected function modify_form_process(): void {} protected function modify_form_process(): void
public function modify_form(): RedirectResponse|string {
}
final protected function modify_form_procedure(): RedirectResponse|string
{ {
try { try {
helper(['form']); helper(['form']);
$this->modify_init();
$this->formDatas = $this->getFormDatas();
//기존 데이터 가져오기
$this->entity = $this->getModel()->getEntityByPK($this->formDatas[$this->getModel()->getPKField()]);
if ($this->entity === null) {
throw new \Exception("해당 정보를 찾을수 없습니다.");
}
$this->modify_form_process(); $this->modify_form_process();
$this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
@ -161,19 +135,12 @@ abstract class MVController extends CommonController
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage()); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage());
} }
} }
protected function modify_process(): void {} protected function modify_process(): void
public function modify(): mixed {
}
final protected function modify_procedure(): RedirectResponse
{ {
try { try {
$this->modify_init();
$this->modify_validate();
$this->formDatas = $this->getFormDatas();
$this->formDatas = $this->convertFormDatas($this->formDatas);
//기존 데이터 가져오기
$this->entity = $this->getModel()->getEntityByPK($this->formDatas[$this->getModel()->getPKField()]);
if ($this->entity === null) {
throw new \Exception("해당 정보를 찾을수 없습니다.");
}
//Transaction Start //Transaction Start
$this->getModel()->transStart(); $this->getModel()->transStart();
$this->modify_process(); $this->modify_process();
@ -188,7 +155,7 @@ abstract class MVController extends CommonController
} }
} }
// 리스트 // 리스트
protected function list_condition($isTotalCount = false): void private function list_condition_process($isTotalCount = false): void
{ {
//조건절 처리 //조건절 처리
foreach ($this->filter_fields as $field) { foreach ($this->filter_fields as $field) {
@ -216,15 +183,15 @@ abstract class MVController extends CommonController
} }
} }
//Totalcount 처리 //Totalcount 처리
protected function list_total(): int private function list_total_process(): int
{ {
$this->list_condition(true); $this->list_condition_process(true);
$total_count = $this->getModel()->countAllResults(); $total_count = $this->getModel()->countAllResults();
// echo $this->getModel()->getLastQuery(); // echo $this->getModel()->getLastQuery();
return $total_count; return $total_count;
} }
//PageNation 처리 //PageNation 처리
protected function list_pagination($pager_group = 'default', int $segment = 0, $template = 'default_full'): string private function list_pagination_process($pager_group = 'default', int $segment = 0, $template = 'default_full'): string
{ {
//Page, Per_page필요부분 //Page, Per_page필요부분
$this->page = (int)$this->request->getVar('page') ?: 1; $this->page = (int)$this->request->getVar('page') ?: 1;
@ -252,9 +219,9 @@ abstract class MVController extends CommonController
$this->total_page = $pager->getPageCount($pager_group); $this->total_page = $pager->getPageCount($pager_group);
return $pager->links($pager_group, $template); return $pager->links($pager_group, $template);
} }
protected function list_entitys(): array private function list_entitys_process(): array
{ {
$this->list_condition(); $this->list_condition_process();
if ($this->page) { if ($this->page) {
$this->getModel()->limit( $this->getModel()->limit(
$this->per_page, $this->per_page,
@ -265,20 +232,19 @@ abstract class MVController extends CommonController
// echo $this->getModel()->getLastQuery(); // echo $this->getModel()->getLastQuery();
return $entitys; return $entitys;
} }
public function index(): string final protected function list_procedure(): string
{ {
try { try {
helper(['form']); helper(['form']);
$this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []];
$this->list_init();
//URL처리 //URL처리
$this->uri = $this->request->getUri(); $this->uri = $this->request->getUri();
//total 처리 //total 처리
$this->total_count = $this->list_total(); $this->total_count = $this->list_total_process();
//pagenation 처리 //pagenation 처리
$this->pagination = $this->list_pagination(); $this->pagination = $this->list_pagination_process();
//모델 처리 //모델 처리
$this->entitys = $this->list_entitys(); $this->entitys = $this->list_entitys_process();
//setting return_url to session flashdata //setting return_url to session flashdata
$this->session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); $this->session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: "");
return view( return view(

View File

@ -20,7 +20,7 @@ function getFieldForm_RecordHelper(string $field, mixed $value, array $viewDatas
{ {
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case 'user_uid': case 'zone_uid':
$form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]); $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]);
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]); // // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]);
// foreach ($viewDatas['field_options'][$field] as $key => $label) { // foreach ($viewDatas['field_options'][$field] as $key => $label) {
@ -29,20 +29,17 @@ function getFieldForm_RecordHelper(string $field, mixed $value, array $viewDatas
// return implode("&nbsp;", $checkboxs); // return implode("&nbsp;", $checkboxs);
break; break;
case 'content': case 'content':
case 'head': $form = form_input($field, $value, ["placeholder" => "예)123.123.123.123", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
case 'tail': break;
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '20', 'cols' => '100']); case 'hosts':
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '5']);
break; break;
case "type": case "type":
case "status": case "locked":
case "proxied":
case "proxiable":
$form = form_dropdown($field, $viewDatas['field_options'][$field], $value, $attributes); $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, $attributes);
break; break;
case 'id':
$form = form_input($field, $value, ["placeholder" => "예)sample@test.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'name':
$form = form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
$form = form_input($field, $value, ['class' => 'calender']); $form = form_input($field, $value, ['class' => 'calender']);

View File

@ -20,7 +20,7 @@ function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas,
{ {
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case 'user_uid': case 'account_uid':
$form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]); $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]);
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]); // // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]);
// foreach ($viewDatas['field_options'][$field] as $key => $label) { // foreach ($viewDatas['field_options'][$field] as $key => $label) {
@ -29,20 +29,20 @@ function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas,
// return implode("&nbsp;", $checkboxs); // return implode("&nbsp;", $checkboxs);
break; break;
case 'content': case 'content':
case 'head': $form = form_input($field, $value, ["placeholder" => "예)123.123.123.123", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
case 'tail': break;
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '20', 'cols' => '100']); case 'domains':
case 'hosts':
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '5']);
break; break;
case "type": case "type":
case "proxied":
case "development_mode":
case "ipv6":
case "security_level":
case "status": case "status":
$form = form_dropdown($field, $viewDatas['field_options'][$field], $value, $attributes); $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, $attributes);
break; break;
case 'id':
$form = form_input($field, $value, ["placeholder" => "예)sample@test.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'name':
$form = form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
$form = form_input($field, $value, ['class' => 'calender']); $form = form_input($field, $value, ['class' => 'calender']);

View File

@ -1,84 +0,0 @@
<?php
namespace App\Libraries\MyCloudflare;
use Cloudflare\API\Adapter\Guzzle;
use App\Models\Cloudflare\AccountModel;
use App\Libraries\MyCloudflare\MyCloudflare;
use App\Entities\Cloudflare\AccountEntity;
class Account extends MyCloudflare
{
private $_myStorage = null;
public function __construct(string $auth_key)
{
parent::__construct($auth_key);
}
final protected function getMyStorage(): AccountModel
{
if ($this->_myStorage === null) {
$this->_myStorage = new AccountModel();
}
return $this->_myStorage;
}
//Result 형태
// [
// {"id":"078e88a7735965b661715af13031ecb0",
// "name":"Cloudwin002@idcjp.jp's Auth",
// "type":"standard",
// "settings":{
// "enforce_twofactor":false,
// "api_access_enabled":null,
// "access_approval_expiry":null,
// "use_account_custom_ns_by_default":false
// },
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
// "created_on":"2017-06-26T05:44:49.470184Z"}
// ]
protected function getArrayByResult($result, array $formDatas = []): array
{
$formDatas[$this->getMyStorage()->getPKField()] = $result->id;
$formDatas[$this->getMyStorage()->getTitleField()] = $result->name;
$formDatas['type'] = $result->type;
$formDatas['status'] = 'use';
$formDatas['updated_at'] = $result->created_on;
$formDatas['created_at'] = $result->created_on;
return $formDatas;
}
// public function create(array $formDatas): AccountEntity
// {
// //Socket용
// $cf = $this->getMySocket()->request($formDatas['authkey'])
// ->post('accounts', [
// 'name' => $formDatas[$this->getMyStorage()->getTitleField()],
// 'type' => $formDatas['type'],
// ]);
// $cf = json_decode($cf->getBody());
// if (!$cf->success) {
// throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
// }
// //Storage용
// $formDatas = $this->getArrayByResult($cf->result, $formDatas);
// $entity = $this->getMyStorage()->create($formDatas);
// log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
// return $entity;
// }
public function create(array $formDatas): array
{
//Account의 경우 인증키를 가지고있고 생성할수 없으므로 get으로 읽은후 첫번째것을 사용하기로 함
$entitys = [];
foreach ($this->reload_cfs($this->getMySocket(), 'accounts') as $cf) {
$formDatas = $this->getArrayByResult($cf->result);
$entity = $this->$this->getMyStorage()->create($formDatas);
log_message("notice", "Account:" . __FUNCTION__ . "=> {$entity->getTitle()} 작업을 완료하였습니다.");
$entitys[] = $entity;
}
return $entitys;
}
protected function reload_entity($cf): AccountEntity
{
return $this->getMyStorage()->modify(new AccountEntity, $this->getArrayByResult($cf));
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace App\Libraries\MyCloudflare;
use Cloudflare\API\Adapter\Guzzle;
use App\Libraries\MySocket\CloudflareSocket;
use App\Libraries\CommonLibrary;
abstract class MyCloudflare extends CommonLibrary
{
private $_account_uid = "";
private $_mySocket = null;
protected function __construct(string $account_uid)
{
parent::__construct();
$this->_account_uid = $account_uid;
}
abstract protected function getArrayByResult($result, array $formDatas = []): array;
abstract protected function reload_entity($cf): mixed;
abstract protected function getMyStorage(): mixed;
final protected function getMySocket(): CloudflareSocket
{
if ($this->_mySocket === null) {
$this->_mySocket = new CloudflareSocket();
}
return $this->_mySocket;
}
//-----------------------필수항목-------------------//
final protected function reload_entitys(string $parent, array $cfs): array
{
$entity_uids = [];
if (count($cfs)) {
$cnt = 1;
foreach ($cfs as $cf) {
$entity = $this->reload_entity($cf);
$entity_uids[] = $entity->getPK();
log_message("debug", "{$cnt}번째: {$entity->getTitle()} 저장");
$cnt++;
}
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
$this->getMyStorage()->where($this->getMyStorage()::PARENT, $parent);
$this->getMyStorage()->whereNotIn($this->getMyStorage()->getPKField(), $entity_uids);
$this->getMyStorage()->delete();
}
return $entity_uids;
}
final protected function reload_cfs(Guzzle $request, $uri): array
{
$page = 1; //Page는 1부터 시작해야함
$perpage_max = getenv("cfmgr.request.perpage.max");
$cfs = [];
do {
$query = [
'page' => $page,
'per_page' => $perpage_max,
'match' => 'all',
];
$cf = $request->get($uri, $query);
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
}
$cfs = [$cfs, ...$cf->result];
//Loop 제한 : 한페이지에서 가져온 갯수가 perpage_max보다 적다는것은 더이상 다음페이지기 없으므로 0로 종료시키기 위함
$page = count($cf->result) < $perpage_max ? 0 : $page + 1;
} while (0 < $page);
return $cfs;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Libraries\MySocket\Cloudflare;
use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\AccountModel;
class AccountSocket extends CloudflareSocket
{
public function __construct(string $email, string $auth_key)
{
parent::__construct();
$this->setAdapter($email, $auth_key);
}
//Result 형태
// [
// {"id":"078e88a7735965b661715af13031ecb0",
// "name":"Cloudwin002@idcjp.jp's Auth",
// "type":"standard",
// "settings":{
// "enforce_twofactor":false,
// "api_access_enabled":null,
// "access_approval_expiry":null,
// "use_account_custom_ns_by_default":false
// },
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
// "created_on":"2017-06-26T05:44:49.470184Z"}
// ]
public function getArrayByResult($result, array $formDatas = []): array
{
$formDatas[AccountModel::PK] = $result->id;
$formDatas[AccountModel::TITLE] = $result->name;
$formDatas['type'] = $result->type;
$formDatas['status'] = 'use';
$formDatas['updated_at'] = date("Y-m-d H:i:s");
$formDatas['created_at'] = $result->created_on;
return $formDatas;
}
public function create(): array
{
return $this->reload_procedure('accounts');
}
}

View File

@ -1,55 +1,48 @@
<?php <?php
namespace App\Libraries\MyCloudflare; namespace App\Libraries\MySocket\Cloudflare;
use Cloudflare\API\Adapter\Guzzle;
use App\Models\Cloudflare\RecordModel;
use App\Libraries\MyCloudflare\MyCloudflare;
use App\Entities\Cloudflare\ZoneEntity;
use App\Entities\Cloudflare\RecordEntity;
use App\Entities\Cloudflare\AccountEntity; 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;
class Record extends MyCloudflare class RecordSocket extends CloudflareSocket
{ {
private $_myStorage = null; private $_myStorage = null;
private $_account_entity = null; private $_account_entity = null;
private $_zone_entity = null; private $_zone_entity = null;
public function __construct(AccountEntity $account_entity, ZoneEntity $zone_entity) public function __construct(AccountEntity $account_entity, ZoneEntity $zone_entity)
{ {
parent::__construct($this->_account_entity->getPK()); parent::__construct();
$this->_account_entity = $account_entity; $this->_account_entity = $account_entity;
$this->_zone_entity = $zone_entity; $this->_zone_entity = $zone_entity;
$this->setAdapter($account_entity->getID(), $account_entity->getAuthKey());
} }
final protected function getMyStorage(): RecordModel public function getArrayByResult($result, array $formDatas = []): array
{ {
if ($this->_myStorage === null) { $formDatas[RecordModel::PK] = $result->id;
$this->_myStorage = new RecordModel(); $formDatas[RecordModel::PARENT] = $result->zone_id;
} $formDatas[RecordModel::TITLE] = $result->name;
return $this->_myStorage; $formDatas['type'] = $result->type;
} $formDatas['content'] = $result->content;
protected function getArrayByResult($result, array $formDatas = []): array $formDatas['ttl'] = (int)$result->ttl;
{ $formDatas['proxiable'] = $result->proxiable ? "on" : "off";
$formDatas[$this->getMyStorage()->getPKField()] = $result->id; $formDatas['proxied'] = $result->proxied ? "on" : "off";
$formDatas[$this->getMyStorage()::PARENT] = $result->zone_id; $formDatas['locked'] = "on";
$formDatas[$this->getMyStorage()->getTitleField()] = $result->name;
$formDatas['type'] = $result->type;
$formDatas['content'] = $result->content;
$formDatas['ttl'] = (int)$result->ttl;
$formDatas['proxiable'] = $result->proxiable ? "on" : "off";
$formDatas['proxied'] = $result->proxied ? "on" : "off";
$formDatas['locked'] = "on";
if (isset($result->locked) && $result->locked) { if (isset($result->locked) && $result->locked) {
$formDatas['locked'] = "off"; $formDatas['locked'] = "off";
} }
// $formDatas['updated_at'] = $cfResult->modified_on; $formDatas['updated_at'] = date("Y-m-d H:i:s");
$formDatas['created_at'] = $result->created_on; $formDatas['created_at'] = $result->created_on;
return $formDatas; return $formDatas;
} }
public function create(string $host, array $formDatas): RecordEntity public function create(string $host, array $formDatas): mixed
{ {
//Socket용 //Socket용
//도메인생성을 위해 Cloudflare에 전송 //도메인생성을 위해 Cloudflare에 전송
$cf = $this->getRequest()->post('zones/' . $this->_zone_entity->getPK() . '/dns_records', [ $cf = $this->request()->post('zones/' . $this->_zone_entity->getPK() . '/dns_records', [
'name' => $host, 'name' => $host,
'type' => $formDatas['type'], 'type' => $formDatas['type'],
'content' => $formDatas['content'], 'content' => $formDatas['content'],
@ -59,11 +52,7 @@ class Record extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
//Storage용 return $cf->result;
$formDatas = $this->getArrayByResult($cf->result);
$entity = $this->$this->getMyStorage()->create($formDatas);
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity;
} }
public function modify(RecordEntity $entity, array $formDatas): RecordEntity public function modify(RecordEntity $entity, array $formDatas): RecordEntity
{ {
@ -83,7 +72,7 @@ class Record extends MyCloudflare
$datas['proxied'] = false; $datas['proxied'] = false;
$datas['ttl'] = 120; $datas['ttl'] = 120;
} }
$cf = $this->getRequest()->put('zones/' . $this->_zone_entity->getPK() . '/dns_records', $datas); $cf = $this->request()->put('zones/' . $this->_zone_entity->getPK() . '/dns_records', $datas);
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@ -93,7 +82,7 @@ class Record extends MyCloudflare
} }
public function delete(RecordEntity $entity): void public function delete(RecordEntity $entity): void
{ {
$cf = $this->getRequest()->delete('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK()); $cf = $this->request()->delete('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK());
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Record:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@ -102,24 +91,29 @@ class Record extends MyCloudflare
} }
public function sync(RecordEntity $entity): RecordEntity public function sync(RecordEntity $entity): RecordEntity
{ {
$cf = $this->getRequest()->get('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK()); $cf = $this->request()->get('zones/' . $this->_zone_entity->getPK() . '/dns_records/' . $entity->getPK());
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Record:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
$formDatas = $this->getArrayByResult($cf->result); return new RecordEntity($this->getArrayByResult($cf->result));
return $this->$this->getMyStorage()->create($formDatas);
} }
protected function reload_entity($cf): RecordEntity //Reload
public function reload(RecordModel $model): void
{ {
return $this->getMyStorage()->modify(new RecordEntity, $this->getArrayByResult($cf)); log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리 시작-----");
} $entity_uids = [];
public function reload(): void $results = $this->reload_procedure("zones/{$this->_zone_entity->getPK()}/dns_records");
{ foreach ($results as $result) {
$cfs = $this->reload_cfs($this->getRequest(), 'zones/' . $this->_zone_entity->getPK() . '/dns_records'); $formDatas = $this->getArrayByResult($result);
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리[" . count($cfs) . "개] 시작-----"); $entity = $model->modify($model->getEntity(), $formDatas);
$entitys = $this->reload_entitys($this->_zone_entity->getPK(), $cfs); $entity_uids[] = $entity->getPK();
log_message("notice", "-----{$this->_zone_entity->getTitle()} DB 처리[" . count($entitys) . "개] 완료-----"); }
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
$model->where($model::PARENT, $this->_zone_entity);
$model->whereNotIn($model::PK, $entity_uids);
$model->delete();
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리[" . count($results) . "개] 완료-----");
} }
} }

View File

@ -1,40 +1,28 @@
<?php <?php
namespace App\Libraries\MyCloudflare; namespace App\Libraries\MySocket\Cloudflare;
use App\Models\Cloudflare\ZoneModel;
use App\Libraries\MyCloudflare\MyCloudflare;
use App\Entities\Cloudflare\ZoneEntity;
use App\Entities\Cloudflare\AccountEntity; use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\ZoneEntity;
use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\ZoneModel;
use Cloudflare\API\Adapter\Guzzle; class ZoneSocket extends CloudflareSocket
class Zone extends MyCloudflare
{ {
private $_myStorage = null; private $_myStorage = null;
private $_account_entity = null; private $_account_entity = null;
public function __construct(AccountEntity $account_entity) public function __construct(AccountEntity $account_entity)
{ {
parent::__construct($this->_account_entity->getPK()); parent::__construct();
$this->_account_entity = $account_entity; $this->_account_entity = $account_entity;
$this->setAdapter($account_entity->getID(), $account_entity->getAuthKey());
} }
final protected function getMyStorage(): ZoneModel public function getArrayByResult($result, array $formDatas = []): array
{ {
if ($this->_myStorage === null) { $formDatas[ZoneModel::PK] = $result->id;
$this->_myStorage = new ZoneModel(); $formDatas[ZoneModel::PARENT] = $result->account->id;
} $formDatas[ZoneModel::TITLE] = $result->name;
return $this->_myStorage; $formDatas['status'] = $result->status;
}
final protected function getRequest(): Guzzle
{
return $this->getMySocket()->request($this->_account_uid);
}
protected function getArrayByResult($result, array $formDatas = []): array
{
$formDatas[$this->getMyStorage()->getPKField()] = $result->id;
$formDatas[$this->getMyStorage()::PARENT] = $result->account->id;
$formDatas[$this->getMyStorage()->getTitleField()] = $result->name;
$formDatas['status'] = $result->status;
//$formDatas['type'] = $result->type; // full 이게있는데 뭔지 잘모름 //$formDatas['type'] = $result->type; // full 이게있는데 뭔지 잘모름
$formDatas['name_servers'] = 'none'; $formDatas['name_servers'] = 'none';
if (isset($result->name_servers)) { if (isset($result->name_servers)) {
@ -52,7 +40,8 @@ class Zone extends MyCloudflare
$result->original_name_servers $result->original_name_servers
) : $result->original_name_servers; ) : $result->original_name_servers;
} }
$formDatas['updated_at'] = $result->modified_on; // $formDatas['updated_at'] = $result->modified_on;
$formDatas['updated_at'] = date("Y-m-d H:i:s");
$formDatas['created_at'] = $result->created_on; $formDatas['created_at'] = $result->created_on;
$formDatas['plan'] = $result->plan->name; $formDatas['plan'] = $result->plan->name;
return $formDatas; return $formDatas;
@ -60,7 +49,7 @@ class Zone extends MyCloudflare
//Cfzone에서 가져온 값을 zone에 setting //Cfzone에서 가져온 값을 zone에 setting
final public function getCFSetting(ZoneEntity $entity): ZoneEntity final public function getCFSetting(ZoneEntity $entity): ZoneEntity
{ {
$cf = $this->getRequest()->patch('zones/' . $entity->getPK() . '/settings/'); $cf = $this->request()->patch('zones/' . $entity->getPK() . '/settings/');
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@ -80,9 +69,9 @@ class Zone extends MyCloudflare
} }
return $entity; return $entity;
} }
final public function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity public function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity
{ {
$cf = $this->getRequest()->patch('zones/' . $entity->getPK() . '/settings/' . $field, array('value' => $value)); $cf = $this->request()->patch('zones/' . $entity->getPK() . '/settings/' . $field, array('value' => $value));
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success || $cf->result->id !== $field) { if (!$cf->success || $cf->result->id !== $field) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 {$field}->{$value} 변경실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 {$field}->{$value} 변경실패:\n" . var_export($cf, true));
@ -91,11 +80,11 @@ class Zone extends MyCloudflare
$entity->$field = $cf->result->value; $entity->$field = $cf->result->value;
return $entity; return $entity;
} }
public function create(string $domain, bool $jump_start = false): ZoneEntity public function create(string $domain, bool $jump_start = false): mixed
{ {
//Socket용 //Socket용
//도메인생성을 위해 Cloudflare에 전송 //도메인생성을 위해 Cloudflare에 전송
$cf = $this->getRequest()->post('zones/', [ $cf = $this->request()->post('zones/', [
'accountId' => $this->_account_entity->getPK(), 'accountId' => $this->_account_entity->getPK(),
'name' => $domain, 'name' => $domain,
'jump_start' => $jump_start, 'jump_start' => $jump_start,
@ -104,15 +93,7 @@ class Zone extends MyCloudflare
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
//Storage용 return $cf->result;
$formDatas = $this->getArrayByResult($cf->result);
$entity = $this->$this->getMyStorage()->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');
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
return $entity;
} }
public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity
{ {
@ -125,7 +106,7 @@ class Zone extends MyCloudflare
} }
public function delete(ZoneEntity $entity): void public function delete(ZoneEntity $entity): void
{ {
$cf = $this->getRequest()->delete('zones/' . $entity->getPK()); $cf = $this->request()->delete('zones/' . $entity->getPK());
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
@ -134,24 +115,29 @@ class Zone extends MyCloudflare
} }
public function sync(ZoneEntity $entity): ZoneEntity public function sync(ZoneEntity $entity): ZoneEntity
{ {
$cf = $this->getRequest()->get('zones/' . $entity->getPK()); $cf = $this->request()->get('zones/' . $entity->getPK());
$cf = json_decode($cf->getBody()); $cf = json_decode($cf->getBody());
if (!$cf->success) { if (!$cf->success) {
throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); throw new \Exception("Zone:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
} }
log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); log_message("notice", "Zone:" . __FUNCTION__ . "=> 작업을 완료하였습니다.");
$formDatas = $this->getArrayByResult($cf->result); return new ZoneEntity($this->getArrayByResult($cf->result));
return $this->$this->getMyStorage()->create($formDatas);
} }
protected function reload_entity($cf): ZoneEntity //Reload
public function reload(ZoneModel $model): void
{ {
return $this->getMyStorage()->modify(new ZoneEntity, $this->getArrayByResult($cf)); log_message("notice", "-----{$this->_account_entity->getTitle()} 처리 시작-----");
} $entity_uids = [];
public function reload(): void $results = $this->reload_procedure('zones');
{ foreach ($results as $result) {
$cfs = $this->reload_cfs($this->getRequest(), 'zones'); $formDatas = $this->getArrayByResult($result);
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리[" . count($cfs) . "개] 시작-----"); $entity = $model->modify($model->getEntity(), $formDatas);
$entitys = $this->reload_entitys($this->_account_entity->getPK(), $cfs); $entity_uids[] = $entity->getPK();
log_message("notice", "-----{$this->_account_entity->getTitle()} DB 처리[" . count($entitys) . "개] 완료-----"); }
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
$model->where($model::PARENT, $this->_account_entity);
$model->whereNotIn($model::PK, $entity_uids);
$model->delete();
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리[" . count($results) . "개] 완료-----");
} }
} }

View File

@ -5,41 +5,28 @@ namespace App\Libraries\MySocket;
use Cloudflare\API\Auth\APIKey; use Cloudflare\API\Auth\APIKey;
use Cloudflare\API\Adapter\Guzzle; use Cloudflare\API\Adapter\Guzzle;
use App\Models\Cloudflare\AccountModel;
use App\Libraries\CommonLibrary; use App\Libraries\CommonLibrary;
class CloudflareSocket extends CommonLibrary abstract class CloudflareSocket extends CommonLibrary
{ {
private static int $_request = 0; private static int $_request = 0;
private static int $_request_max = 100; private static int $_request_max = 100;
private static int $_request_timewait = 60; private static int $_request_timewait = 60;
private $_accountModel = null; private $_adapter = null;
private $_clients = []; protected function __construct()
public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->initAdapters();
self::$_request_max = getenv("cfmgr.request.max"); self::$_request_max = getenv("cfmgr.request.max");
} }
private function getAccountModel(): AccountModel abstract public function getArrayByResult($result, array $formDatas = []): array;
final protected function setAdapter(string $email, string $auth_key): void
{ {
if ($this->_accountModel === null) { $this->_adapter = new Guzzle(new APIKey($email, $auth_key));
$this->_accountModel = new AccountModel();
}
return $this->_accountModel;
} }
private function initAdapters(): void final public function request(): Guzzle
{ {
foreach ($this->getAccountModel()->getEntitys() as $entity) { if ($this->_adapter === null) {
$this->_clients[$entity->getPK()] = new Guzzle( throw new \Exception(+__FUNCTION__ . " => Adapter를 정의하지 않았습니다.");
new APIKey($entity->getTitle(), $entity->getAuthKey())
);
}
}
final public function request(string $key): Guzzle
{
if (!array_key_exists($key, $this->_clients)) {
throw new \Exception(+__FUNCTION__ . " => {$key}에 해당하는 Adapter를 찾을수 없습니다.");
} }
if (self::$_request >= self::$_request_max) { if (self::$_request >= self::$_request_max) {
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait)); log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
@ -48,6 +35,28 @@ class CloudflareSocket extends CommonLibrary
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait)); log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
} }
self::$_request++; self::$_request++;
return $this->_clients[$key]; return $this->_adapter;
}
final protected function reload_procedure($uri): array
{
$page = 1; //Page는 1부터 시작해야함
$perpage_max = getenv("cfmgr.request.perpage.max");
$results = [];
do {
$query = [
'page' => $page,
'per_page' => $perpage_max,
'match' => 'all',
];
$cf = $this->request()->get($uri, $query);
$cf = json_decode($cf->getBody());
if (!$cf->success) {
throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true));
}
$results[] = $cf->result;
//Loop 제한 : 한페이지에서 가져온 갯수가 perpage_max보다 적다는것은 더이상 다음페이지기 없으므로 0로 종료시키기 위함
$page = count($cf->result) < $perpage_max ? 0 : $page + 1;
} while (0 < $page);
return $results;
} }
} }

View File

@ -24,7 +24,7 @@ class AccountModel extends CommonModel
{ {
return self::TITLE; return self::TITLE;
} }
public function getFieldRule(string $field, array $rules): array public function getFieldRule(string $action, string $field, array $rules): array
{ {
switch ($field) { switch ($field) {
case self::TITLE: case self::TITLE:
@ -44,7 +44,7 @@ class AccountModel extends CommonModel
$rules[$field] = "if_exist|in_list[standard,enterprise]"; $rules[$field] = "if_exist|in_list[standard,enterprise]";
break; break;
default: default:
$rules = parent::getFieldRule($field, $rules); $rules = parent::getFieldRule($action, $field, $rules);
break; break;
} }
return $rules; return $rules;

View File

@ -27,11 +27,11 @@ class RecordModel extends CommonModel
{ {
return self::TITLE; return self::TITLE;
} }
public function getFieldRule(string $field, array $rules): array public function getFieldRule(string $action, string $field, array $rules): array
{ {
switch ($field) { switch ($field) {
case self::PARENT: 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}/]";; $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; break;
case self::TITLE: case self::TITLE:
case "content": case "content":
@ -50,7 +50,7 @@ class RecordModel extends CommonModel
$rules[$field] = "if_exist|in_list[on,off]"; $rules[$field] = "if_exist|in_list[on,off]";
break; break;
default: default:
$rules = parent::getFieldRule($field, $rules); $rules = parent::getFieldRule($action, $field, $rules);
break; break;
} }
return $rules; return $rules;

View File

@ -26,12 +26,11 @@ class ZoneModel extends CommonModel
{ {
return self::TITLE; return self::TITLE;
} }
public function getFieldRule(string $field, array $rules): array public function getFieldRule(string $action, string $field, array $rules): array
{ {
switch ($field) { switch ($field) {
case self::PARENT: 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}/]"; $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; break;
case self::TITLE: case self::TITLE:
case "plan": case "plan":
@ -46,7 +45,7 @@ class ZoneModel extends CommonModel
$rules[$field] = "if_exist|in_list[on,off]"; $rules[$field] = "if_exist|in_list[on,off]";
break; break;
default: default:
$rules = parent::getFieldRule($field, $rules); $rules = parent::getFieldRule($action, $field, $rules);
break; break;
} }
return $rules; return $rules;

View File

@ -45,7 +45,6 @@ abstract class CommonModel extends Model
protected $beforeDelete = []; protected $beforeDelete = [];
protected $afterDelete = []; protected $afterDelete = [];
private $_action = 'create';
protected function __construct() protected function __construct()
{ {
parent::__construct(); parent::__construct();
@ -55,19 +54,11 @@ abstract class CommonModel extends Model
{ {
return $this->primaryKey; return $this->primaryKey;
} }
final public function getAction(): string
{
return $this->_action;
}
final public function setAction(string $action): string
{
return $this->_action = $action;
}
// final public function getFields(array $except_fields = []): array // final public function getFields(array $except_fields = []): array
// { // {
// return array_diff($this->allowedFields, $except_fields); //제외한 fields // return array_diff($this->allowedFields, $except_fields); //제외한 fields
// } // }
public function getFieldRule(string $field, array $rules): array public function getFieldRule(string $action, string $field, array $rules): array
{ {
if (is_array($field)) { if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
@ -77,19 +68,20 @@ abstract class CommonModel extends Model
//수동입력인경우 //수동입력인경우
if (!$this->useAutoIncrement) { if (!$this->useAutoIncrement) {
$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}/]"; $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}/]";
$rules[$field] .= $this->getAction() == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
} else { } else {
$rules[$field] = "required|numeric"; $rules[$field] = "required|numeric";
}; }
;
break; break;
case $this->getTitleField(): case $this->getTitleField():
$rules[$field] = "required|string"; $rules[$field] = "required|string";
break; break;
case "passwd": case "passwd":
$rules[$field] = $this->getAction() == "create" ? "required" : "if_exist" . "|trim|string"; $rules[$field] = $action == "create" ? "required" : "if_exist" . "|trim|string";
break; break;
case "confirmpassword": case "confirmpassword":
$rules["confirmpassword"] = $this->getAction() == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]"; $rules["confirmpassword"] = $action == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]";
break; break;
case "email": case "email":
$rules[$field] = "if_exist|trim|valid_email"; $rules[$field] = "if_exist|trim|valid_email";
@ -111,13 +103,13 @@ abstract class CommonModel extends Model
} }
return $rules; return $rules;
} }
final public function getFieldRules(array $fields, array $rules = []): array final public function getFieldRules(string $action, array $fields, array $rules = []): array
{ {
foreach ($fields as $field) { foreach ($fields as $field) {
if (is_array($field)) { if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true)); throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true));
} }
$rules = $this->getFieldRule($field, $rules); $rules = $this->getFieldRule($action, $field, $rules);
} }
return $rules; return $rules;
} }
@ -194,8 +186,7 @@ abstract class CommonModel extends Model
final protected function create_process($entity, array $formDatas): mixed final protected function create_process($entity, array $formDatas): mixed
{ {
//Field에 맞는 Validation Rule 재정의 //Field에 맞는 Validation Rule 재정의
$this->setAction('create'); $this->setValidationRules($this->getFieldRules('create', $this->allowedFields));
$this->setValidationRules($this->getFieldRules($this->allowedFields));
//저장하기 전에 데이터 값 변경이 필요한 Field //저장하기 전에 데이터 값 변경이 필요한 Field
foreach (array_keys($formDatas) as $field) { foreach (array_keys($formDatas) as $field) {
$entity->$field = $this->convertEntityData($field, $formDatas); $entity->$field = $this->convertEntityData($field, $formDatas);
@ -212,8 +203,7 @@ abstract class CommonModel extends Model
final protected function modify_process($entity, array $formDatas): mixed final protected function modify_process($entity, array $formDatas): mixed
{ {
//Field에 맞는 Validation Rule 재정의 //Field에 맞는 Validation Rule 재정의
$this->setAction('modify'); $this->setValidationRules($this->getFieldRules('modify', $this->allowedFields));
$this->setValidationRules($this->getFieldRules($this->allowedFields));
//저장하기 전에 데이터 값 변경이 필요한 Field //저장하기 전에 데이터 값 변경이 필요한 Field
foreach (array_keys($formDatas) as $field) { foreach (array_keys($formDatas) as $field) {
$entity->$field = $this->convertEntityData($field, $formDatas); $entity->$field = $this->convertEntityData($field, $formDatas);

View File

@ -73,7 +73,7 @@
<div id="index_create_form"></div> <div id="index_create_form"></div>
</div> </div>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function () {
loadContentForm( loadContentForm(
"<?= base_url(strtolower($viewDatas["class_path"]) . "/create") ?>", "<?= base_url(strtolower($viewDatas["class_path"]) . "/create") ?>",
document.getElementById('index_create_form') document.getElementById('index_create_form')

View File

@ -1,19 +1,35 @@
<link href="/css/<?= $viewDatas['layout'] ?>/content.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/css/<?= $viewDatas['layout'] ?>/content.css" media="screen" rel="stylesheet" type="text/css" />
<?= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?> <?= form_open(current_url() . '/create', $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
<table class="form table table-bordered table-striped"> <table class="table table-bordered table-striped" style="width:400px; margin:0 auto;">
<?php foreach ($viewDatas['fields'] as $field): ?>
<tr>
<td class="label"><?= getFieldLabel_RecordHelper($field, $viewDatas) ?></td>
<td class="column">
<?= getFieldForm_RecordHelper($field, old($field), $viewDatas) ?>
<?= validation_show_error($field); ?>
</td>
</tr>
<?php endforeach; ?>
<tr> <tr>
<td valign="bottom" colspan="2"> <th style="text-align:center;">도메인</th>
<?= form_submit('', '입력', array("class" => "btn btn-outline btn-primary")); ?> <th style="text-align:center;">Type</th>
</td> <th style="text-align:center;">IP/내용</th>
<th style="text-align:center;">CDN기능</th>
<th colspan="2" style="text-align:center;">호스트명</th>
</tr> </tr>
<?= form_close(); ?> <tr>
</table> <td>
<?= getFieldForm_RecordHelper('zone_uid', isset($this->zone_uid) ?: old('zone_uid'), $viewDatas) ?>
<?= validation_show_error('zone_uid'); ?>
</td>
<td>
<?= form_dropdown('type', array_merge(["" => "Type 선택"], lang('Admin/Cloudflare/Record.TYPE')), old('type')) ?>
<?= validation_show_error('type'); ?>
</td>
<td>
<?= form_input('content', is_null(old('content')) ? DEFAULTS['EMPTY'] : old('content'), ["size" => 30]) ?>
<?= validation_show_error('content'); ?>
</td>
<td><?= form_dropdown('proxied', ["" => "CDN기능 선택", "on" => "사용", "off" => "사용 않함"], old('proxied')) ?>
<?= validation_show_error('proxied'); ?>
</td>
<td>
<?= form_textarea('hosts', is_null(old('hosts')) ? DEFAULTS['EMPTY'] : old('hosts'), ["cols" => 30, "rows" => 5]) ?>
<?= validation_show_error('hosts'); ?>
</td>
<td><input type="submit" value="추가" class="btn btn-sm btn-primary btn-circle" type="button" /></td>
</tr>
</table>
<?= form_close(); ?>
<?php if (session()->getFlashdata('error')): ?> <?= session()->getFlashdata('error') ?><?php endif ?>

View File

@ -69,15 +69,7 @@
</div> </div>
<div class="index_pagination"><?= $viewDatas['pagination'] ?></div> <div class="index_pagination"><?= $viewDatas['pagination'] ?></div>
<?= form_close() ?> <?= form_close() ?>
<div class="index_form"> <div id="index_create_form">
<div id="index_create_form"></div> <?= $this->include('admin/cloudflare/record/create'); ?>
</div> </div>
<script>
document.addEventListener('DOMContentLoaded', function() {
loadContentForm(
"<?= base_url(strtolower($viewDatas["class_path"]) . "/create") ?>",
document.getElementById('index_create_form')
);
});
</script>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -1,19 +1,44 @@
<link href="/css/<?= $viewDatas['layout'] ?>/content.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/css/<?= $viewDatas['layout'] ?>/content.css" media="screen" rel="stylesheet" type="text/css" />
<?= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?> <?= form_open(current_url() . '/create', $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
<table class="form table table-bordered table-striped"> <table class="table table-bordered table-striped" style="width:400px; margin:0 auto;">
<?php foreach ($viewDatas['fields'] as $field): ?>
<tr>
<td class="label"><?= getFieldLabel_ZoneHelper($field, $viewDatas) ?></td>
<td class="column">
<?= getFieldForm_ZoneHelper($field, old($field), $viewDatas) ?>
<?= validation_show_error($field); ?>
</td>
</tr>
<?php endforeach; ?>
<tr> <tr>
<td valign="bottom" colspan="2"> <th style="text-align:center;">계정정보</th>
<?= form_submit('', '입력', array("class" => "btn btn-outline btn-primary")); ?> <th style="text-align:center;">Type</th>
</td> <th style="text-align:center;">IP/내용</th>
<th style="text-align:center;">도메인명</th>
<th>CDN기능</th>
<th colspan="2" style="text-align:center;">호스트명</th>
</tr> </tr>
<?= form_close(); ?> <tr>
</table> <td>
<?= getFieldForm_ZoneHelper('account_uid', isset($this->account_uid) ?: old('account_uid'), $viewDatas) ?>
<?= validation_show_error('account_uid'); ?>
</td>
<td>
<?= form_dropdown('type', array_merge(["" => "Type 선택"], lang('Admin/Cloudflare/Record.TYPE')), old('type')) ?>
<?= validation_show_error('type'); ?>
</td>
<td>
<?= form_input('content', is_null(old('content')) ? DEFAULTS['EMPTY'] : old('content'), ["size" => 30]) ?>
<?= validation_show_error('content'); ?>
</td>
<td>
<?= form_textarea('domains', is_null(old('domains')) ? DEFAULTS['EMPTY'] : old('domains'), ["cols" => 30, "rows" => 5]) ?>
<?= validation_show_error('domains'); ?>
</td>
<td>
<?= form_dropdown('proxied', ["" => "CDN기능 선택", "on" => "사용", "off" => "사용 않함"], old('proxied')) ?>
<?= validation_show_error('proxied'); ?>
</td>
<td nowrap>
<?php foreach (explode(",", getenv("cfmgr.default.record.hosts")) as $host): ?>
<div style="text-align:left;">
<?= form_checkbox(["name" => "hosts[]", "value" => $host, "checked" => "checked"]); ?> <?= $host ?>
</div>
<?php endforeach; ?>
</td>
<td><input type="submit" value="추가" class="btn btn-sm btn-primary btn-circle" type="button" /></td>
</tr>
</table>
<?= form_close(); ?>
<?php if (session()->getFlashdata('error')): ?> <?= session()->getFlashdata('error') ?><?php endif ?>

View File

@ -69,15 +69,7 @@
</div> </div>
<div class="index_pagination"><?= $viewDatas['pagination'] ?></div> <div class="index_pagination"><?= $viewDatas['pagination'] ?></div>
<?= form_close() ?> <?= form_close() ?>
<div class="index_form"> <div id="index_create_form">
<div id="index_create_form"></div> <?= $this->include('admin/cloudflare/zone/create'); ?>
</div> </div>
<script>
document.addEventListener('DOMContentLoaded', function() {
loadContentForm(
"<?= base_url(strtolower($viewDatas["class_path"]) . "/create") ?>",
document.getElementById('index_create_form')
);
});
</script>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -7,8 +7,7 @@
<h2><a href=" /admin"><i class="fa fa-home"></i>Main</a></h2> <h2><a href=" /admin"><i class="fa fa-home"></i>Main</a></h2>
</div> </div>
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu/base'); ?> <?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu/base'); ?>
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu/site'); ?> <?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu/cloudflare'); ?>
<?= $this->include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu/shoppingmall'); ?>
</div> </div>
<div id="menu_button">메뉴열기</div> <div id="menu_button">메뉴열기</div>
</div> </div>

View File

@ -1,9 +1,9 @@
<div class="accordion-item"> <div class="accordion-item">
<h2><a href="/admin/user"></i>계정 관리</a></h2> <h2><a href="/admin/user"><?= ICONS['MEMBER'] ?>계정 관리</a></h2>
</div> </div>
<div class="accordion-item"> <div class="accordion-item">
<h2><a href="/admin/usersns"></i>SNS 계정 관리</a></h2> <h2><a href="/admin/usersns"><?= ICONS['GOOGLE'] ?>SNS 계정 관리</a></h2>
</div> </div>
<div class="accordion-item"> <div class="accordion-item">
<h2><a href="/admin/category">분류 관리</a></h2> <h2><a href="/admin/cloudflare/mapurl"><?= ICONS['FLAG'] ?>MapURL 관리</a></h2>
</div> </div>

View File

@ -0,0 +1,16 @@
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#flush-heading-Board" aria-expanded="false"
aria-controls="flush-heading-Board"><b><?= ICONS['CLOUD'] ?> Cloudflare API</b></button>
</h2>
<div id="flush-heading-Board" class="accordion-collapse collapse show" aria-labelledby="flush-heading-Board">
<div class="accordion-item">
<h2><a href="/admin/cloudflare/account"><?= ICONS['MEMBER'] ?>Account</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/cloudflare/zone"><?= ICONS['SIGNPOST2'] ?>Zone</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/cloudflare/record"><?= ICONS['SIGNPOST'] ?>Record</a></h2>
</div>
</div>

View File

@ -1,20 +0,0 @@
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#flush-heading-Shoppingmall" aria-expanded="false"
aria-controls="flush-heading-Shoppingmall"><b>상점관리</b></button>
</h2>
<div id="flush-heading-Shoppingmall" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-heading-Shoppingmall">
<div class="accordion-item">
<h2><a href="/admin/device">장비 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/product">상품 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/order">주문 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/billing">청구서 관리</a></h2>
</div>
</div>

View File

@ -31,8 +31,11 @@ div.layout > nav.tail {
padding: 10px; padding: 10px;
} }
div.layout > div.center > div.left_menu {
/* border-color: 1px solid red; */
}
div.layout > div.center > div.content { div.layout > div.center > div.content {
margin: 25px 0px 25px 25px; margin: 15px 15px 15px 25px;
} }
div.layout > div.center > div.content > div.header { div.layout > div.center > div.content > div.header {
/*content 헤더라인*/ /*content 헤더라인*/

View File

@ -14,7 +14,6 @@ table.form tbody tr td.column {
/*조건검색*/ /*조건검색*/
nav.index_top nav.condition { nav.index_top nav.condition {
max-width: 400px;
border-color: 1px solid red; border-color: 1px solid red;
} }
/*검색*/ /*검색*/
@ -100,7 +99,7 @@ div.index_pagination nav ul.pagination li a:hover {
border: 1px solid black; border: 1px solid black;
} }
div.index_form { div.index_form {
margin-top:30px; margin-top: 30px;
text-align: center; text-align: center;
/* border: 1px solid red; */ /* border: 1px solid red; */
} }