cfmgrv4 init...1

This commit is contained in:
최준흠 2024-09-29 01:20:38 +09:00
parent 1a0e90d48c
commit 34c7833132
8 changed files with 124 additions and 70 deletions

View File

@ -99,6 +99,14 @@ class RecordController extends CloudflareController
$this->formDatas = $this->getFormDatas(); $this->formDatas = $this->getFormDatas();
//부모데이터 정의 //부모데이터 정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
$cnt = 1;
foreach ($this->formDatas['hosts'] as $host) {
//호스트명 형식확인
if (!isHost_CommonHelper($host)) {
throw new \Exception("{$this->_account_entity->getTitle()}{$cnt}번째 {$host} 호스트명 형식 오류");
}
$cnt++;
}
return $this->create_procedure(); return $this->create_procedure();
} }
//수정 //수정

View File

@ -94,11 +94,13 @@ class ZoneController extends CloudflareController
{ {
parent::create_process(); parent::create_process();
//Zone생성 //Zone생성
$cnt = 1;
$zone_entitys = []; $zone_entitys = [];
foreach ($this->formDatas['domains'] as $domain) { foreach ($this->formDatas['domains'] as $domain) {
$entity = $this->getMySocket()->create($domain); $entity = $this->getMySocket()->create($domain);
log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다."); log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다.");
$zone_entitys[] = $entity; $zone_entitys[] = $entity;
$cnt++;
} }
//Record생성 //Record생성
foreach ($zone_entitys as $zone_entity) { foreach ($zone_entitys as $zone_entity) {
@ -116,6 +118,32 @@ class ZoneController extends CloudflareController
$this->formDatas = $this->getFormDatas(); $this->formDatas = $this->getFormDatas();
//부모데이터 정의 //부모데이터 정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
//Type이 A형식일경우 IP형태인지 확인
if ($this->formDatas['type'] === 'A') {
if (!isIPAddress_CommonHelper($this->formDatas['content'], $this->formDatas['type'])) {
throw new \Exception("{$this->_account_entity->getTitle()}{$this->formDatas['type']}, {$this->formDatas['content']} 형식 오류[사설IP 않됨]");
}
}
$cnt = 1;
foreach ($this->formDatas['domains'] as $domain) {
//도메인명 형식확인
if (!isDomain_CommonHelper($domain)) {
throw new \Exception("{$this->_account_entity->getTitle()}{$cnt}번째 {$domain} 형식 오류");
}
//도메인명이 해당계정의 유일한 도메인인지 확인
if (!$this->getModel()->isUniqueDomain($this->_account_entity, $domain)) {
throw new \Exception("{$this->_account_entity->getTitle()}{$cnt}번째 {$domain}은 이미 등록된 도메인입니다.");
}
$cnt++;
}
$cnt = 1;
foreach ($this->formDatas['hosts'] as $host) {
//호스트명 형식확인
if (!isHost_CommonHelper($host)) {
throw new \Exception("{$this->_account_entity->getTitle()}{$cnt}번째 {$host} 호스트명 형식 오류");
}
$cnt++;
}
return $this->create_procedure(); return $this->create_procedure();
} }
// 리스트 // 리스트
@ -123,7 +151,7 @@ class ZoneController extends CloudflareController
{ {
$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->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'];
$this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
return $this->list_procedure(); return $this->list_procedure();

View File

@ -13,6 +13,7 @@ abstract class CommonController extends BaseController
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);
helper("common");
} }
final public function __get($name) final public function __get($name)
{ {

View File

@ -63,10 +63,10 @@ function getFieldView_RecordHelper(string $field, mixed $entity, array $viewData
current_url() . '/reload/' . $entity->getParent(), current_url() . '/reload/' . $entity->getParent(),
ICONS["RELOAD"], ICONS["RELOAD"],
[ [
"class" => "btn btn-sm btn-primary btn-circle fa fa-refresh", "class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self" "target" => "_self"
] ]
) . "<span class=\"label_zones\">{$viewDatas['field_options'][$field][$value]}</span>"; ) . " " . "<span class=\"label_zones\">{$viewDatas['field_options'][$field][$value]}</span>";
} }
break; break;
case RecordModel::TITLE: case RecordModel::TITLE:

View File

@ -2,48 +2,44 @@
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
function getFieldLabel_ZoneHelper(string $field, array $viewDatas, array $attributes = []): string function getFieldLabel_ZoneHelper(string $field, array $viewDatas, array $extras = []): string
{ {
switch ($field) { switch ($field) {
case ZoneModel::PARENT:
$extras = [...$extras, "class" => 'text-danger'];
break;
default: default:
if (strpos($viewDatas['field_rules'][$field], 'required') !== false) { if (strpos($viewDatas['field_rules'][$field], 'required') !== false) {
$attributes = ['style="color:red";']; $extras = [...$extras, "class" => 'text-danger'];
} }
$label = sprintf(
"<span %s>%s</span>",
implode(" ", $attributes),
lang("{$viewDatas['class_path']}.label.{$field}")
);
break; break;
} }
return $label; return form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras);
} }
//header.php에서 getFieldForm_Helper사용 //header.php에서 getFieldForm_Helper사용
function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas, array $attributes = []): string function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case ZoneModel::PARENT: case ZoneModel::PARENT:
$form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]); $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$extras, '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], [$extras]);
// foreach ($viewDatas['field_options'][$field] as $key => $label) { // foreach ($viewDatas['field_options'][$field] as $key => $label) {
// $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label; // $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label;
// } // }
// return implode("&nbsp;", $checkboxs); // return implode("&nbsp;", $checkboxs);
break; break;
case ZoneModel::TITLE: case ZoneModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)example.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]); $form = form_input($field, $value, ["placeholder" => "예)exmaple.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]);
break; break;
case 'domains':
case 'hosts': case 'hosts':
$form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '5']); $form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '5']);
break; break;
case "proxied":
case "development_mode": case "development_mode":
case "ipv6": case "ipv6":
case "security_level": 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, $extras);
break; break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
@ -55,11 +51,48 @@ function getFieldForm_ZoneHelper(string $field, mixed $value, array $viewDatas,
} }
return $form; return $form;
} // } //
function getFieldView_ZoneHelper(string $field, mixed $entity, array $viewDatas, array $extras = [])
function getFieldView_ZoneHelper(string $field, mixed $entity, array $viewDatas, array $attributes = [])
{ {
$value = $entity->$field ?: DEFAULTS['EMPTY']; $value = $entity->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case ZoneModel::PARENT:
if ($extras['old_account'] === $entity->getParent()) {
$value = "";
} else {
$value = anchor(
current_url() . '/reload/' . $entity->getParent(),
ICONS["RELOAD"],
[
"class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self"
]
) . " <span class=\"label_zones\">" .
preg_replace("/(\w+)@(.+)/", "$1", $viewDatas['field_options'][$field][$value])
. "</span>";
}
break;
case ZoneModel::TITLE:
$value = anchor(
current_url() . '/reload/' . $entity->getParent(),
ICONS["RELOAD"],
[
"class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self"
]
) . " " .
anchor(
current_url() . '/reload/' . $entity->getParent(),
ICONS["FLAG"],
[
"class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self"
]
) . " <span class=\"label_zones\">{$value}</span>";
break;
case 'name_servers':
case 'original_name_servers':
$value = str_replace(",", "<BR>", $value);
break;
case 'category_uid': case 'category_uid':
foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) { foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) {
foreach ($category_2depths as $key => $depth) { foreach ($category_2depths as $key => $depth) {
@ -74,62 +107,42 @@ function getFieldView_ZoneHelper(string $field, mixed $entity, array $viewDatas,
case 'sale': case 'sale':
$value = number_format(!$value ? 0 : $value) . ""; $value = number_format(!$value ? 0 : $value) . "";
break; break;
case 'content':
$value = html_entity_decode($value);
break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':
$value = $value ? date("Y-m-d", strtotime($value)) : ""; $value = $value ? date("Y-m-d", strtotime($value)) : "";
break; break;
default: default:
if (in_array($field, $viewDatas['filter_fields']) && $value) { if (in_array($field, $viewDatas['filter_fields']) && $value) {
$value = $viewDatas['field_options'][$field][$value]; $extras["onChange"] = sprintf(
}
break;
}
return $value;
} //
function getListHeaders_ZoneHelper(string $field, array $viewDatas, array $attributes = []): string
{
$label = getFieldLabel_ZoneHelper($field, $viewDatas, $attributes);
if ($field == $viewDatas['order_field']) {
$label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"];
}
$order_value = $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC";
$viewDatas['uri']->addQuery('order_field', $field);
$viewDatas['uri']->addQuery('order_value', $order_value);
$header = anchor((string)$viewDatas['uri'], $label);
switch ($field) {
case 'title':
$attributes = [...$attributes, "class=\"col-2\""];
break;
}
return sprintf("<th %s>%s</th>", implode(" ", $attributes), $header);
}
function getListColumns_ZoneHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []): string
{
switch ($field) {
case ZoneModel::TITLE:
$value = anchor(
current_url() . '/view/' . $entity->getPK(),
getFieldView_ZoneHelper($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', 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value',
current_url(), current_url(),
$entity->getPK(), $entity->getPK(),
$field, $field,
$field $field
); );
$value = getFieldForm_ZoneHelper($field, $entity, $viewDatas, $attributes); $value = getFieldForm_ZoneHelper($field, $entity->$field, $viewDatas, $extras);
} }
$value = getFieldView_ZoneHelper($field, $entity, $viewDatas);
break; break;
} }
return $value; return $value;
} //
function getListColumns_ZoneHelper(string $field, array $viewDatas, array $extras = []): string
{
$label = getFieldLabel_ZoneHelper($field, $viewDatas, $extras);
if ($field == $viewDatas['order_field']) {
$label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"];
}
$order_value = $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC";
$viewDatas['uri']->addQuery('order_field', $field);
$viewDatas['uri']->addQuery('order_value', $order_value);
$label = anchor((string)$viewDatas['uri'], $label);
switch ($field) {
case ZoneModel::PARENT:
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_zones'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Zones</buttion>";
break;
case ZoneModel::TITLE:
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_hosts'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Hosts</buttion>";
break;
}
return sprintf("<th %s>%s</th>", implode(" ", $extras), $label);
} }

View File

@ -87,9 +87,9 @@ class ZoneModel extends CommonModel
} }
//도메인이 이미 존재하는지 체크 //도메인이 이미 존재하는지 체크
public function isUniqueDomain(string $account_uid, string $domain): bool public function isUniqueDomain(AccountEntity $account_entity, string $domain): bool
{ {
$this->where(self::PARENT, $account_uid); $this->where(self::PARENT, $account_entity->getPK());
$this->where(self::TITLE, $domain); $this->where(self::TITLE, $domain);
return is_null($this->first()) ? true : false; return is_null($this->first()) ? true : false;
} }
@ -106,6 +106,8 @@ class ZoneModel extends CommonModel
public function setList_OrderBy(string $order = ""): void public function setList_OrderBy(string $order = ""): void
{ {
parent::setList_OrderBy($order); parent::setList_OrderBy($order);
$this->orderBy(self::TITLE . " ASC"); //Join을 해서 도메인부터 Sorting하기위함
$this->join('cloudflareaccount', "cloudflareaccount.uid=cloudflarezone.account_uid");
$this->orderBy("cloudflareaccount.title ASC");
} }
} }

View File

@ -75,7 +75,7 @@
<div class="container-fluid"> <div class="container-fluid">
<nav class="nav"></nav> <nav class="nav"></nav>
<nav id="index_create_form" class="nav justify-content-center"> <nav id="index_create_form" class="nav justify-content-center">
<?= $this->include('admin/cloudflare/record/create'); ?> <?= $this->include("{$viewDatas['class_path']}/create"); ?>
</nav> </nav>
<nav class="nav justify-content-end"></nav> <nav class="nav justify-content-end"></nav>
</div> </div>

View File

@ -31,13 +31,14 @@
<tr> <tr>
<th>번호</th> <th>번호</th>
<?php foreach ($viewDatas['fields'] as $field): ?> <?php foreach ($viewDatas['fields'] as $field): ?>
<?= getListHeaders_ZoneHelper($field, $viewDatas) ?> <?= getListColumns_ZoneHelper($field, $viewDatas) ?>
<?php endforeach ?> <?php endforeach ?>
<th>작업</th> <th>작업</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $cnt = 0 ?> <?php $cnt = 0 ?>
<?php $old_account = '' ?>
<?php foreach ($viewDatas['entitys'] as $entity): ?> <?php foreach ($viewDatas['entitys'] as $entity): ?>
<tr id="<?= $entity->getPK() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)"> <tr id="<?= $entity->getPK() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
<td class="text-center text-wrap"> <td class="text-center text-wrap">
@ -45,13 +46,14 @@
<?= anchor(current_url() . '/modify/' . $entity->getPK(), $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt), ["target" => "_self"]) ?> <?= anchor(current_url() . '/modify/' . $entity->getPK(), $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt), ["target" => "_self"]) ?>
</td> </td>
<?php foreach ($viewDatas['fields'] as $field): ?> <?php foreach ($viewDatas['fields'] as $field): ?>
<td><?= getListColumns_ZoneHelper($field, $entity, $viewDatas) ?></td> <td><?= getFieldView_ZoneHelper($field, $entity, $viewDatas, ['old_account' => $old_account]) ?></td>
<?php endforeach ?> <?php endforeach ?>
<td> <td>
<?= anchor(current_url() . '/delete/' . $entity->getPK(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> <?= anchor(current_url() . '/delete/' . $entity->getPK(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
</td> </td>
</tr> </tr>
<?php $cnt++ ?> <?php $cnt++ ?>
<?php $old_account = $entity->getParent(); ?>
<?php endforeach ?> <?php endforeach ?>
</tbody> </tbody>
</table> </table>
@ -73,7 +75,7 @@
<div class="container-fluid"> <div class="container-fluid">
<nav class="nav"></nav> <nav class="nav"></nav>
<nav id="index_create_form" class="nav justify-content-center"> <nav id="index_create_form" class="nav justify-content-center">
<?= $this->include('admin/cloudflare/zone/create'); ?> <?= $this->include("{$viewDatas['class_path']}/create"); ?>
</nav> </nav>
<nav class="nav justify-content-end"></nav> <nav class="nav justify-content-end"></nav>
</div> </div>