cfmgrv4 init...5
This commit is contained in:
parent
60cf0c0f8a
commit
8c3067d8e8
@ -8,10 +8,12 @@ use App\Models\Cloudflare\AccountModel;
|
||||
class AccountHelper extends MVCHelper
|
||||
{
|
||||
public $old_parent = "";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
||||
@ -20,7 +22,7 @@ class AccountHelper extends MVCHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case AccountModel::PARENT:
|
||||
//기존 작성하던값old($field)가 있으면 그값을 넣고 없으면 부모값이 있으면 넣고 없으면 entiy가 있으면 그값을 넣고 없으면 디폴트값을 넣는다.
|
||||
// 기존 작성하던 값 old($field)가 있으면 그 값을 넣고 없으면 부모 값이 있으면 넣고 없으면 entity가 있으면 그 값을 넣고 없으면 디폴트 값을 넣는다.
|
||||
$value = $value ?: (isset($viewDatas[$field]) ? $viewDatas[$field] : (isset($viewDatas['entity']) ? $viewDatas['entity']->getParent() : DEFAULTS['EMPTY']));
|
||||
|
||||
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
|
||||
@ -44,7 +46,8 @@ class AccountHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
@ -105,7 +108,8 @@ class AccountHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
|
||||
@ -8,10 +8,12 @@ use App\Models\Cloudflare\RecordModel;
|
||||
class RecordHelper extends MVCHelper
|
||||
{
|
||||
public $old_parent = "";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
||||
@ -20,7 +22,7 @@ class RecordHelper extends MVCHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case RecordModel::PARENT:
|
||||
//기존 작성하던값old($field)가 있으면 그값을 넣고 없으면 부모값이 있으면 넣고 없으면 entiy가 있으면 그값을 넣고 없으면 디폴트값을 넣는다.
|
||||
// 기존 작성하던 값 old($field)가 있으면 그 값을 넣고 없으면 부모 값이 있으면 넣고 없으면 entity가 있으면 그 값을 넣고 없으면 디폴트 값을 넣는다.
|
||||
$value = $value ?: (isset($viewDatas[$field]) ? $viewDatas[$field] : (isset($viewDatas['entity']) ? $viewDatas['entity']->getParent() : DEFAULTS['EMPTY']));
|
||||
|
||||
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
|
||||
@ -31,7 +33,7 @@ class RecordHelper extends MVCHelper
|
||||
...array_diff_key($extras, ['class' => ''])
|
||||
]);
|
||||
break;
|
||||
case RecordModel::TITLE: //host
|
||||
case RecordModel::TITLE: // host
|
||||
$form = form_input($field, $value, $extras);
|
||||
break;
|
||||
case 'hosts':
|
||||
@ -57,7 +59,8 @@ class RecordHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
@ -116,25 +119,27 @@ class RecordHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getListRowColor($entity): string
|
||||
{
|
||||
return $entity->locked != 'on' ? 'class="table-danger"' : "";
|
||||
}
|
||||
|
||||
public function getListLabel(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$label = parent::getListLabel($field, $viewDatas, $extras);
|
||||
switch ($field) {
|
||||
case RecordModel::PARENT:
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_zones'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Domains</buttion>";
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_zones'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Domains</button>";
|
||||
break;
|
||||
case RecordModel::TITLE:
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_hosts'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Hosts</buttion>";
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_hosts'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Hosts</button>";
|
||||
break;
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
|
||||
@ -8,10 +8,12 @@ use App\Models\Cloudflare\ZoneModel;
|
||||
class ZoneHelper extends MVCHelper
|
||||
{
|
||||
public $old_parent = "";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
||||
@ -20,7 +22,7 @@ class ZoneHelper extends MVCHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case ZoneModel::PARENT:
|
||||
//기존 작성하던값old($field)가 있으면 그값을 넣고 없으면 부모값이 있으면 넣고 없으면 entiy가 있으면 그값을 넣고 없으면 디폴트값을 넣는다.
|
||||
// 기존 작성하던 값 old($field)가 있으면 그 값을 넣고 없으면 부모 값이 있으면 넣고 없으면 entity가 있으면 그 값을 넣고 없으면 디폴트 값을 넣는다.
|
||||
$value = $value ?: (isset($viewDatas[$field]) ? $viewDatas[$field] : (isset($viewDatas['entity']) ? $viewDatas['entity']->getParent() : DEFAULTS['EMPTY']));
|
||||
|
||||
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
|
||||
@ -68,7 +70,8 @@ class ZoneHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
}
|
||||
|
||||
function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
@ -158,21 +161,24 @@ class ZoneHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getListRowColor($entity): string
|
||||
{
|
||||
return $entity->status != 'active' ? 'class="table-danger"' : "";
|
||||
}
|
||||
|
||||
public function getListLabel(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$label = parent::getListLabel($field, $viewDatas, $extras);
|
||||
switch ($field) {
|
||||
case ZoneModel::TITLE:
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_zones'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Domains</buttion>";
|
||||
$label .= "<button onClick=\"getElementsByClassNameCopyToClipboard('label_zones'); return false;\" class=\"btn btn-sm btn-danger btn-circle\">Copy Domains</button>";
|
||||
break;
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
|
||||
@ -5,15 +5,18 @@ namespace App\Helpers;
|
||||
class CommonHelper
|
||||
{
|
||||
public function __construct() {}
|
||||
|
||||
final public function getRandomString($length = 10, $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
{
|
||||
return substr(str_shuffle($characters), 0, $length);
|
||||
}
|
||||
|
||||
final public function getPasswordString($length = 8)
|
||||
{
|
||||
return $this->getRandomString($length, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?");
|
||||
} //
|
||||
//byte값을 알아보기 쉽게 변환
|
||||
}
|
||||
|
||||
// byte값을 알아보기 쉽게 변환
|
||||
final public function getSizeForHuman($bytes)
|
||||
{
|
||||
$ext = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||
@ -22,8 +25,9 @@ class CommonHelper
|
||||
$bytes /= 1024;
|
||||
}
|
||||
return floor($bytes) . $ext[$unitCount];
|
||||
} //
|
||||
//Proxy등을 통하여 Client_IP가 알수없는경우 실제사용자의 IP를 가져오기 위한것
|
||||
}
|
||||
|
||||
// Proxy등을 통하여 Client_IP가 알수없는경우 실제사용자의 IP를 가져오기 위한것
|
||||
final public function getClientIP($clientIP = false)
|
||||
{
|
||||
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
@ -40,12 +44,14 @@ class CommonHelper
|
||||
$clientIP = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
return $clientIP;
|
||||
} //
|
||||
}
|
||||
|
||||
final public function isDomain(string $domain): bool
|
||||
{
|
||||
$parttern_validation = '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/';
|
||||
return preg_match("$parttern_validation", $domain);
|
||||
$pattern_validation = '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/';
|
||||
return preg_match($pattern_validation, $domain);
|
||||
}
|
||||
|
||||
final public function isIPAddress(string $ip, $type = false): bool
|
||||
{
|
||||
switch ($type) {
|
||||
@ -64,23 +70,27 @@ class CommonHelper
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
final public function isHost(string $host): bool
|
||||
{
|
||||
$parttern_validation = '/[a-zA-Z0-9\.\/\?\:@\*\-_=#]/';
|
||||
return preg_match($parttern_validation, $host);
|
||||
$pattern_validation = '/[a-zA-Z0-9\.\/\?\:@\*\-_=#]/';
|
||||
return preg_match($pattern_validation, $host);
|
||||
}
|
||||
//(EX:192.168.1.0 -> 192.168.001.000)
|
||||
|
||||
// (EX:192.168.1.0 -> 192.168.001.000)
|
||||
final public function convertIPV4toCIDR($cidr)
|
||||
{
|
||||
$temps = explode(".", $cidr);
|
||||
return sprintf("%03d.%03d.%03d.%03d", $temps[0], $temps[1], $temps[2], $temps[3]);
|
||||
} //
|
||||
//(EX:192.168.001.0000 -> 192.168.1.0)
|
||||
}
|
||||
|
||||
// (EX:192.168.001.0000 -> 192.168.1.0)
|
||||
final public function convertCIDRtoIPV4($ipv4)
|
||||
{
|
||||
$temps = explode(".", $ipv4);
|
||||
return sprintf("%d.%d.%d.%d", $temps[0], $temps[1], $temps[2], $temps[3]);
|
||||
} //
|
||||
}
|
||||
|
||||
final public function isMobile()
|
||||
{
|
||||
// Check the server headers to see if they're mobile friendly
|
||||
@ -107,7 +117,8 @@ class CommonHelper
|
||||
}
|
||||
// None of the above? Then it's probably not a mobile device.
|
||||
return false;
|
||||
} //
|
||||
}
|
||||
|
||||
final public function alert(string $msg, $url = null)
|
||||
{
|
||||
$msg = preg_replace("/\r/", "\\r", $msg);
|
||||
@ -127,5 +138,5 @@ class CommonHelper
|
||||
break;
|
||||
}
|
||||
return "<script type=\"text/javascript\">{$msg}</script>";
|
||||
} //
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ abstract class MVCHelper extends CommonHelper
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getFieldLabel(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($field) {
|
||||
@ -18,7 +19,8 @@ abstract class MVCHelper extends CommonHelper
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
//header.php에서 getFieldForm_Helper사용
|
||||
|
||||
// header.php에서 getFieldForm_Helper사용
|
||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
||||
@ -41,7 +43,8 @@ abstract class MVCHelper extends CommonHelper
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
@ -73,11 +76,13 @@ abstract class MVCHelper extends CommonHelper
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getListRowColor($entity): string
|
||||
{
|
||||
return $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger"' : "";
|
||||
}
|
||||
|
||||
public function getListLabel(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($field) {
|
||||
@ -95,6 +100,7 @@ abstract class MVCHelper extends CommonHelper
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
|
||||
@ -10,6 +10,7 @@ class MapurlHelper extends MVCHelper
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
||||
@ -28,7 +29,8 @@ class MapurlHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $form;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
@ -51,12 +53,13 @@ class MapurlHelper extends MVCHelper
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
} //
|
||||
}
|
||||
|
||||
public function getRemapPage(array $viewDatas): string
|
||||
{
|
||||
$urls = [];
|
||||
foreach ($viewDatas['entitys'] as $viewDatas['entity']) {
|
||||
//한글을 포함하고 있는지 체크 HTTP 나 HTTPS 와 도메인 분리해서 한글도메인을 Punycode로 변환
|
||||
// 한글을 포함하고 있는지 체크 HTTP 나 HTTPS 와 도메인 분리해서 한글도메인을 Punycode로 변환
|
||||
if (preg_match("/[\xE0-\xFF][\x80-\xFF][\x80-\xFF]/", $viewDatas['entity']->oldurl)) {
|
||||
preg_match("/^(https?:\/\/)(.*)/", $viewDatas['entity']->oldurl, $matches);
|
||||
$oldurl = $matches[1] . idn_to_ascii($matches[2]);
|
||||
|
||||
@ -49,19 +49,19 @@ abstract class CommonModel extends Model
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
abstract public function getTitleField(): string;
|
||||
|
||||
final public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
final public function getPKField(): string
|
||||
{
|
||||
return $this->primaryKey;
|
||||
}
|
||||
// final public function getFields(array $except_fields = []): array
|
||||
// {
|
||||
// return array_diff($this->allowedFields, $except_fields); //제외한 fields
|
||||
// }
|
||||
|
||||
public function getFieldRule(string $action, string $field): string
|
||||
{
|
||||
if (is_array($field)) {
|
||||
@ -69,13 +69,13 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
switch ($field) {
|
||||
case $this->getPKField():
|
||||
//수동입력인경우
|
||||
// 수동입력인 경우
|
||||
if (!$this->useAutoIncrement) {
|
||||
$rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
||||
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
||||
} else {
|
||||
$rule = "required|numeric";
|
||||
};
|
||||
}
|
||||
break;
|
||||
case $this->getTitleField():
|
||||
$rule = "required|string";
|
||||
@ -97,6 +97,7 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
|
||||
final public function getFieldRules(string $action, array $fields, $rules = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
@ -104,6 +105,7 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getFormFieldOption(string $field, array $options = []): array
|
||||
{
|
||||
switch ($field) {
|
||||
@ -116,20 +118,23 @@ abstract class CommonModel extends Model
|
||||
// dd($options);
|
||||
return $options;
|
||||
}
|
||||
|
||||
final public function getEntity(): array|object|null
|
||||
{
|
||||
return $this->asObject($this->returnType)->first();
|
||||
}
|
||||
|
||||
final public function getEntitys(): array
|
||||
{
|
||||
return $this->asObject($this->returnType)->findAll();
|
||||
}
|
||||
//create , modify 직전 작업용 작업
|
||||
|
||||
// create, modify 직전 작업용 작업
|
||||
protected function convertEntityData(string $field, array $formDatas): mixed
|
||||
{
|
||||
switch ($field) {
|
||||
case $this->getPKField():
|
||||
//$formDatas에 전달된 값이 없는경우
|
||||
// $formDatas에 전달된 값이 없는 경우
|
||||
if (!array_key_exists($field, $formDatas)) {
|
||||
$randomBytes = bin2hex(random_bytes(32));
|
||||
$value = sprintf(
|
||||
@ -144,7 +149,7 @@ abstract class CommonModel extends Model
|
||||
$value = $formDatas[$field];
|
||||
}
|
||||
break;
|
||||
case "editor": //content등 textarea를 사용한 Field
|
||||
case "editor": // content 등 textarea를 사용한 Field
|
||||
$value = htmlentities($formDatas[$field], ENT_QUOTES);
|
||||
break;
|
||||
default:
|
||||
@ -157,12 +162,12 @@ abstract class CommonModel extends Model
|
||||
private function save_process($entity): mixed
|
||||
{
|
||||
try {
|
||||
//최종 변경사항이 없으면
|
||||
// 최종 변경사항이 없으면
|
||||
if (!$entity->hasChanged()) {
|
||||
throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다.");
|
||||
}
|
||||
// log_message("debug", var_export($entity, true));
|
||||
// 최종 저장시 오류발생하면
|
||||
// 최종 저장 시 오류 발생하면
|
||||
if (!$this->save($entity)) {
|
||||
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
||||
}
|
||||
@ -179,16 +184,17 @@ abstract class CommonModel extends Model
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
final protected function create_process($entity, array $formDatas): mixed
|
||||
{
|
||||
//Field에 맞는 Validation Rule 재정의
|
||||
// Field에 맞는 Validation Rule 재정의
|
||||
$this->setValidationRules($this->getFieldRules('create', $this->allowedFields));
|
||||
//저장하기 전에 데이터 값 변경이 필요한 Field
|
||||
// 저장하기 전에 데이터 값 변경이 필요한 Field
|
||||
foreach (array_keys($formDatas) as $field) {
|
||||
$entity->$field = $this->convertEntityData($field, $formDatas);
|
||||
}
|
||||
$entity = $this->save_process($entity);
|
||||
//primaryKey가 자동입력이면
|
||||
// primaryKey가 자동입력이면
|
||||
if ($this->useAutoIncrement) {
|
||||
$pkField = $this->getPKField();
|
||||
$entity->$pkField = $this->getInsertID();
|
||||
@ -196,11 +202,12 @@ abstract class CommonModel extends Model
|
||||
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
||||
return $entity;
|
||||
}
|
||||
|
||||
final protected function modify_process($entity, array $formDatas): mixed
|
||||
{
|
||||
//Field에 맞는 Validation Rule 재정의
|
||||
// Field에 맞는 Validation Rule 재정의
|
||||
$this->setValidationRules($this->getFieldRules('modify', $this->allowedFields));
|
||||
//저장하기 전에 데이터 값 변경이 필요한 Field
|
||||
// 저장하기 전에 데이터 값 변경이 필요한 Field
|
||||
foreach (array_keys($formDatas) as $field) {
|
||||
$entity->$field = $this->convertEntityData($field, $formDatas);
|
||||
}
|
||||
@ -209,15 +216,17 @@ abstract class CommonModel extends Model
|
||||
return $entity;
|
||||
}
|
||||
|
||||
//List용
|
||||
// List용
|
||||
final public function setList_FieldFilter(string $field, int|string $value): void
|
||||
{
|
||||
$this->where($this->getTable() . '.' . $field, $value);
|
||||
}
|
||||
|
||||
public function setList_WordFilter(string $word, string $field = null): void
|
||||
{
|
||||
$this->like($this->getTable() . '.' . ($field ?? $this->getTitleField()), $word, 'both'); //befor , after , both
|
||||
$this->like($this->getTable() . '.' . ($field ?? $this->getTitleField()), $word, 'both'); // before, after, both
|
||||
}
|
||||
|
||||
final public function setList_DateFilter(string $start, string $end, $field = "created_at"): void
|
||||
{
|
||||
if ($start !== DEFAULTS['EMPTY']) {
|
||||
|
||||
@ -6,18 +6,23 @@ use App\Entities\UserEntity;
|
||||
use App\Models\UserModel;
|
||||
use App\Services\CommonService;
|
||||
use CodeIgniter\Session\Session;
|
||||
|
||||
// 참고:https://github.com/SyntaxPhoenix/iloclient
|
||||
class AuthService extends CommonService
|
||||
{
|
||||
private ?Session $_session = null;
|
||||
private ?UserModel $_model = null;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
final public function getSession(): Session
|
||||
{
|
||||
if ($this->_session == null) {
|
||||
if ($this->_session === null) {
|
||||
$this->_session = \Config\Services::session();
|
||||
}
|
||||
return $this->_session;
|
||||
}
|
||||
|
||||
final protected function getModel(): UserModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -25,29 +30,30 @@ class AuthService extends CommonService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
final public function getAuthInfo(string $key = ""): array|string
|
||||
{
|
||||
$authInfo = $this->getSession()->get(SESSION_NAMES['AUTH']);
|
||||
if ($key) {
|
||||
return isset($this->getSession()->get(SESSION_NAMES['AUTH'])[$key]) ? $this->getSession()->get(SESSION_NAMES['AUTH'])[$key] : "";
|
||||
return $authInfo[$key] ?? "";
|
||||
}
|
||||
return $this->getSession()->get(SESSION_NAMES['AUTH']);
|
||||
return $authInfo;
|
||||
}
|
||||
|
||||
final public function isLoggedIn(): bool
|
||||
{
|
||||
return $this->getSession()->has(SESSION_NAMES['ISLOGIN']);
|
||||
}
|
||||
|
||||
final public function isAccessRole(array $roles): bool
|
||||
{
|
||||
if ($this->getAuthInfo('role') === "") {
|
||||
return false;
|
||||
}
|
||||
$myRoles = explode(DEFAULTS['DELIMITER_ROLE'], $this->getAuthInfo('role'));
|
||||
// 교집합이 없으면 false
|
||||
if (empty(array_intersect($myRoles, $roles))) {
|
||||
$role = $this->getAuthInfo('role');
|
||||
if ($role === "") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
$myRoles = explode(DEFAULTS['DELIMITER_ROLE'], $role);
|
||||
// 교집합이 없으면 false
|
||||
return !empty(array_intersect($myRoles, $roles));
|
||||
}
|
||||
|
||||
final public function pushCurrentUrl(string $url): void
|
||||
|
||||
@ -8,11 +8,12 @@ use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
|
||||
class GoogleService extends AuthService
|
||||
{
|
||||
private $_mysocket = null;
|
||||
private $_mySocket = null;
|
||||
private string $_access_code = "";
|
||||
|
||||
public function __construct(mixed $mySocket)
|
||||
{
|
||||
$this->_mysocket = $mySocket;
|
||||
$this->_mySocket = $mySocket;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -24,12 +25,13 @@ class GoogleService extends AuthService
|
||||
$this->_mySocket->setToken($this->_access_code);
|
||||
return $this->_mySocket;
|
||||
}
|
||||
|
||||
public function checkUser(string $access_code): UserEntity
|
||||
{
|
||||
try {
|
||||
// Google 서비스 설정
|
||||
$userSNS_entity = $this->getMySocket($access_code)->getUserSNSEntity();
|
||||
//local db 사용와의 연결 확인
|
||||
// local db 사용와의 연결 확인
|
||||
$user_entity = $this->getModel()->getEntityByPK($userSNS_entity->getParent());
|
||||
if ($user_entity === null) {
|
||||
throw new PageNotFoundException("회원[{$userSNS_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다.");
|
||||
|
||||
@ -19,14 +19,17 @@ class LocalService extends AuthService
|
||||
if (!isset($formDatas['passwd']) || !$formDatas['passwd']) {
|
||||
throw new \Exception("암호를 입력해주세요!");
|
||||
}
|
||||
|
||||
$entity = $this->getModel()->getEntityByID($formDatas['id']);
|
||||
if (is_null($entity) || !isset($entity->passwd)) {
|
||||
throw new \Exception("사용자ID: {$formDatas['id']}가 존재하지 않습니다.");
|
||||
}
|
||||
|
||||
if (!password_verify($formDatas['passwd'], $entity->passwd)) {
|
||||
// log_message("error", "암호: {$formDatas['passwd']}, {$entity->passwd}");
|
||||
throw new \Exception("암호가 맞지 않습니다.");
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,12 +11,14 @@ class AccountService extends CloudflareService
|
||||
{
|
||||
private ?AuthEntity $_parent_entity = null;
|
||||
private ?AccountModel $_model = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "Account";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
private function getParentEntity(): AuthEntity
|
||||
{
|
||||
if ($this->_parent_entity === null) {
|
||||
@ -24,11 +26,13 @@ class AccountService extends CloudflareService
|
||||
}
|
||||
return $this->_parent_entity;
|
||||
}
|
||||
|
||||
private function setParentEntity(AuthEntity $parent_entity): void
|
||||
{
|
||||
$this->_parent_entity = $parent_entity;
|
||||
$this->setAuthEntity($this->getParentEntity());
|
||||
}
|
||||
|
||||
protected function getModel(): AccountModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -36,24 +40,28 @@ class AccountService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
public function create(AuthEntity $parent_entity, array $formDatas): AccountEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
return $this->getModel()->create($formDatas);
|
||||
}
|
||||
|
||||
public function modify(AuthEntity $parent_entity, AccountEntity $entity, array $formDatas): AccountEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
|
||||
public function delete(AuthEntity $parent_entity): void
|
||||
{
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
$this->getModel()->delete();
|
||||
}
|
||||
|
||||
//Result 형태
|
||||
// [
|
||||
// {"id":"078e88a7735965b661715af13031ecb0",
|
||||
@ -69,7 +77,7 @@ class AccountService extends CloudflareService
|
||||
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
||||
// ]
|
||||
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
protected function getArrayByResult(stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
$formDatas[AccountModel::PK] = $result->id;
|
||||
$formDatas[AccountModel::PARENT] = $this->getAuthEntity()->getPK();
|
||||
@ -86,26 +94,28 @@ class AccountService extends CloudflareService
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
log_message("notice", "\n----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리 시작-----------");
|
||||
$entitys = [];
|
||||
|
||||
$entities = [];
|
||||
try {
|
||||
$results = $this->reload_procedure("accounts");
|
||||
$total = count($results);
|
||||
|
||||
if ($total > 0) {
|
||||
$cnt = 1;
|
||||
foreach ($results as $result) {
|
||||
foreach ($results as $index => $result) {
|
||||
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
||||
log_message("error", "Account: result is not a stdClass:\n" . var_export($result, true) . "\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
$formDatas = $this->getArrayByResult($result);
|
||||
$entity = $this->getModel()->modify(new AccountEntity(), $formDatas);
|
||||
log_message("debug", "{$cnt}/{$total} => {$entity->getTitle()} Account 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entitys[$entity->getPK()] = $entity;
|
||||
$cnt++;
|
||||
log_message("debug", ($index + 1) . "/{$total} => {$entity->getTitle()} Account 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entities[$entity->getPK()] = $entity;
|
||||
}
|
||||
|
||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
||||
$this->getModel()->where(AccountModel::PARENT, $this->getParentEntity()->getPK());
|
||||
$this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys));
|
||||
$this->getModel()->whereNotIn(AccountModel::PK, array_keys($entities));
|
||||
$this->getModel()->delete();
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
}
|
||||
@ -113,7 +123,8 @@ class AccountService extends CloudflareService
|
||||
log_message("error", $e->getMessage());
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
log_message("notice", message: "\n-----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------");
|
||||
return $entitys;
|
||||
|
||||
log_message("notice", "\n-----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리[" . count($entities) . "개] 완료-----------");
|
||||
return $entities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,12 +12,14 @@ class AuditLogService extends CloudflareService
|
||||
private ?AuditLogModel $_model = null;
|
||||
private ?AccountModel $_accountModel = null;
|
||||
private ?ZoneModel $_zoneModel = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "AuditLog";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
protected function getModel(): AuditLogModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -25,6 +27,7 @@ class AuditLogService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
protected function getZoneModel(): ZoneModel
|
||||
{
|
||||
if ($this->_zoneModel === null) {
|
||||
@ -32,6 +35,7 @@ class AuditLogService extends CloudflareService
|
||||
}
|
||||
return $this->_zoneModel;
|
||||
}
|
||||
|
||||
protected function getAccountModel(): AccountModel
|
||||
{
|
||||
if ($this->_accountModel === null) {
|
||||
@ -43,10 +47,10 @@ class AuditLogService extends CloudflareService
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
$formDatas[AuditLogModel::PK] = $result->id;
|
||||
$formDatas[AuditLogModel::TITLE] = $result->action->type;
|
||||
$formDatas['action_info'] = isset($result->action->info) ? $result->action->info : "";
|
||||
$formDatas[AuditLogModel::TITLE] = $result->action->type;
|
||||
$formDatas['action_info'] = $result->action->info ?? "";
|
||||
$formDatas['actor'] = $result->actor->type;
|
||||
$formDatas['interface'] = isset($result->interface) ? $result->interface : "";
|
||||
$formDatas['interface'] = $result->interface ?? "";
|
||||
$formDatas['zone_name'] = $result->metadata->zone_name;
|
||||
$formDatas['meta'] = isset($result->metadata) ? var_export($result->metadata, true) : "";
|
||||
$formDatas['resource'] = isset($result->newValueJson) ? var_export($result->newValueJson, true) : "";
|
||||
@ -60,7 +64,7 @@ class AuditLogService extends CloudflareService
|
||||
{
|
||||
//Auditlog 신규등록
|
||||
$formDatas = $this->getArrayByResult($result);
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
|
||||
//auditlog의 domain에 해당하는 Zone이 존재하는지 확인
|
||||
$this->getZoneModel()->where('domain', $entity->getZoneName());
|
||||
@ -68,7 +72,7 @@ class AuditLogService extends CloudflareService
|
||||
if ($zone_entity !== null) {
|
||||
//해당 Zone만 Sync작업을 한다.
|
||||
$zone_service = new ZoneService();
|
||||
$zone_entity = $zone_service->sync($account_entity, $zone_entity);
|
||||
$zone_entity = $zone_service->sync($account_entity, $zone_entity);
|
||||
//해당 Zone의 Record reload작업한다
|
||||
$record_service = new RecordService();
|
||||
$record_service->reload($zone_entity);
|
||||
@ -78,6 +82,7 @@ class AuditLogService extends CloudflareService
|
||||
log_message("debug", "AuditLog Process의 {$zone_entity->getTitle()} Sync및 Record,Firewall Reload 처리작업");
|
||||
}
|
||||
}
|
||||
|
||||
public function reload(AccountEntity $account_entity): void
|
||||
{
|
||||
//Socket인증정보 정의
|
||||
@ -108,6 +113,6 @@ class AuditLogService extends CloudflareService
|
||||
log_message("error", $e->getMessage());
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
log_message("notice", message: "\n-----------Account {$account_entity->getTitle()}의 AuditLog 처리 완료-----------");
|
||||
log_message("notice", "\n-----------Account {$account_entity->getTitle()}의 AuditLog 처리 완료-----------");
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,12 +8,14 @@ use App\Models\Cloudflare\AuthModel;
|
||||
class AuthService extends CloudflareService
|
||||
{
|
||||
private ?AuthModel $_model = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "Auth";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
protected function getModel(): AuthModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -21,14 +23,17 @@ class AuthService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
public function create(array $formDatas): AuthEntity
|
||||
{
|
||||
return $this->getModel()->create($formDatas);
|
||||
}
|
||||
|
||||
public function modify(AuthEntity $entity, array $formDatas): AuthEntity
|
||||
{
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
$this->getModel()->delete();
|
||||
|
||||
@ -10,21 +10,25 @@ use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
abstract class CloudflareService extends CommonService
|
||||
{
|
||||
private $_mySockets = [];
|
||||
private $_auth_entity = null;
|
||||
private $_authModel = null;
|
||||
private array $_mySockets = [];
|
||||
private ?AuthEntity $_auth_entity = null;
|
||||
private ?AuthModel $_authModel = null;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->class_path = "Cloudflare/";
|
||||
}
|
||||
|
||||
final public function getMySocket(): CloudflareSocket
|
||||
{
|
||||
if (!isset($this->_mySockets[$this->getAuthEntity()->getPK()])) {
|
||||
$this->_mySockets[$this->getAuthEntity()->getPK()] = new CloudflareSocket($this->getAuthEntity());
|
||||
$authEntityPK = $this->getAuthEntity()->getPK();
|
||||
if (!isset($this->_mySockets[$authEntityPK])) {
|
||||
$this->_mySockets[$authEntityPK] = new CloudflareSocket($this->getAuthEntity());
|
||||
}
|
||||
return $this->_mySockets[$this->getAuthEntity()->getPK()];
|
||||
return $this->_mySockets[$authEntityPK];
|
||||
}
|
||||
|
||||
final protected function getAuthEntity(): AuthEntity
|
||||
{
|
||||
if ($this->_auth_entity === null) {
|
||||
@ -32,10 +36,12 @@ abstract class CloudflareService extends CommonService
|
||||
}
|
||||
return $this->_auth_entity;
|
||||
}
|
||||
|
||||
final protected function setAuthEntity(AuthEntity $auth_entity): void
|
||||
{
|
||||
$this->_auth_entity = $auth_entity;
|
||||
}
|
||||
|
||||
final protected function getAuthModel(): AuthModel
|
||||
{
|
||||
if ($this->_authModel === null) {
|
||||
@ -43,6 +49,7 @@ abstract class CloudflareService extends CommonService
|
||||
}
|
||||
return $this->_authModel;
|
||||
}
|
||||
|
||||
private function reload_page(string $uri, int $page, int $per_page = 50): ResponseInterface
|
||||
{
|
||||
$query = [
|
||||
@ -59,38 +66,37 @@ abstract class CloudflareService extends CommonService
|
||||
// log_message("debug", var_export($query, true));
|
||||
return $this->getMySocket()->get($uri, $query, $headers);
|
||||
}
|
||||
|
||||
final protected function reload_procedure(string $uri): array
|
||||
{
|
||||
$page = 1; //1부터 시작
|
||||
//한번에 가져올수 있는 갯수 (countfalre 5~50사이)
|
||||
$page = 1; // 1부터 시작
|
||||
$response = $this->reload_page($uri, $page);
|
||||
$body = json_decode($response->getBody());
|
||||
// log_message("debug", var_export($body, true));
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
log_message("error", "JSON 파싱 오류: " . json_last_error_msg());
|
||||
return [];
|
||||
}
|
||||
|
||||
$per_page = $body->result_info->per_page;
|
||||
$total_page = $body->result_info->total_pages;
|
||||
$total_count = $body->result_info->total_count;
|
||||
$results = [];
|
||||
foreach ($body->result as $result) {
|
||||
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
||||
log_message("error", "Cloudflare: result is not a stdClass:\n" . var_export($body, true) . "\n");
|
||||
} else {
|
||||
array_push($results, $result);
|
||||
}
|
||||
}
|
||||
$results = $this->process_results($body->result);
|
||||
|
||||
for ($i = $page + 1; $i <= $total_page; $i++) {
|
||||
// API 제한을 고려한 지연 추가
|
||||
// usleep(100000); // 0.1초 대기
|
||||
$response = $this->reload_page($uri, $i, $per_page);
|
||||
$body = json_decode($response->getBody());
|
||||
foreach ($body->result as $result) {
|
||||
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
||||
log_message("error", "Cloudflare: result is not a stdClass:\n" . var_export($body, true) . "\n");
|
||||
} else {
|
||||
array_push($results, $result);
|
||||
}
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
log_message("error", "JSON 파싱 오류: " . json_last_error_msg());
|
||||
continue;
|
||||
}
|
||||
|
||||
$results = array_merge($results, $this->process_results($body->result));
|
||||
log_message("notice", sprintf(
|
||||
"현재: page[%s/%s] , total_count:[%s] , results:[%s]",
|
||||
"현재: page[%s/%s], total_count:[%s], results:[%s]",
|
||||
$i,
|
||||
$total_page,
|
||||
$total_count,
|
||||
@ -99,4 +105,17 @@ abstract class CloudflareService extends CommonService
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function process_results(array $results): array
|
||||
{
|
||||
$processed_results = [];
|
||||
foreach ($results as $result) {
|
||||
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
||||
log_message("error", "Cloudflare: result is not a stdClass:\n" . var_export($result, true) . "\n");
|
||||
} else {
|
||||
$processed_results[] = $result;
|
||||
}
|
||||
}
|
||||
return $processed_results;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,12 +12,14 @@ class FirewallService extends CloudflareService
|
||||
private ?ZoneEntity $_parent_entity = null;
|
||||
private ?FirewallModel $_model = null;
|
||||
private ?AccountModel $_accountModel = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "Firewall";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
private function getParentEntity(): ZoneEntity
|
||||
{
|
||||
if ($this->_parent_entity === null) {
|
||||
@ -25,6 +27,7 @@ class FirewallService extends CloudflareService
|
||||
}
|
||||
return $this->_parent_entity;
|
||||
}
|
||||
|
||||
private function setParentEntity(ZoneEntity $parent_entity): void
|
||||
{
|
||||
$this->_parent_entity = $parent_entity;
|
||||
@ -38,6 +41,7 @@ class FirewallService extends CloudflareService
|
||||
}
|
||||
$this->setAuthEntity($auth_entity);
|
||||
}
|
||||
|
||||
protected function getModel(): FirewallModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -45,6 +49,7 @@ class FirewallService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
protected function getAccountModel(): AccountModel
|
||||
{
|
||||
if ($this->_accountModel === null) {
|
||||
@ -52,6 +57,7 @@ class FirewallService extends CloudflareService
|
||||
}
|
||||
return $this->_accountModel;
|
||||
}
|
||||
|
||||
protected function getArrayByResult(\stdClass $rule, array $formDatas = []): array
|
||||
{
|
||||
// log_message("debug", var_export($result, true));
|
||||
@ -66,6 +72,7 @@ class FirewallService extends CloudflareService
|
||||
// log_message("debug", print_r($formDatas, true));
|
||||
return $formDatas;
|
||||
}
|
||||
|
||||
public function modify(ZoneEntity $parent_entity, FirewallEntity $entity, array $formDatas): FirewallEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -90,32 +97,33 @@ class FirewallService extends CloudflareService
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
|
||||
//Reload
|
||||
public function reload(ZoneEntity $parent_entity): array
|
||||
{
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Firewall 처리 시작-----------");
|
||||
$entitys = [];
|
||||
$entities = [];
|
||||
try {
|
||||
$response = $this->getMySocket()->get("zones/{$this->getParentEntity()->getPK()}/rulesets/phases/http_request_firewall_custom/entrypoint");
|
||||
$body = json_decode($response->getBody());
|
||||
foreach ($body->result->rules as $rule) {
|
||||
if (!is_object(value: $rule) || get_class($rule) !== 'stdClass') {
|
||||
if (!is_object($rule) || get_class($rule) !== 'stdClass') {
|
||||
log_message("error", "Firewall: result is not a stdClass:\n" . var_export($rule, true) . "\n");
|
||||
} else {
|
||||
$formDatas = ['rulesetid' => $body->result->id];
|
||||
$formDatas = $this->getArrayByResult($rule, $formDatas);
|
||||
$entity = $this->getModel()->modify(new FirewallEntity(), $formDatas);
|
||||
log_message("debug", "{$entity->getTitle()} Firewall 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entitys[$entity->getPK()] = $entity;
|
||||
$entities[$entity->getPK()] = $entity;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
// throw new \Exception($e->getMessage());
|
||||
}
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Firewall처리[" . count($entitys) . "개] 완료-----------");
|
||||
return $entitys;
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Firewall처리[" . count($entities) . "개] 완료-----------");
|
||||
return $entities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,12 +12,14 @@ class RecordService extends CloudflareService
|
||||
private ?ZoneEntity $_parent_entity = null;
|
||||
private ?RecordModel $_model = null;
|
||||
private ?AccountModel $_accountModel = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "Record";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
private function getParentEntity(): ZoneEntity
|
||||
{
|
||||
if ($this->_parent_entity === null) {
|
||||
@ -25,6 +27,7 @@ class RecordService extends CloudflareService
|
||||
}
|
||||
return $this->_parent_entity;
|
||||
}
|
||||
|
||||
private function setParentEntity(ZoneEntity $parent_entity): void
|
||||
{
|
||||
$this->_parent_entity = $parent_entity;
|
||||
@ -38,6 +41,7 @@ class RecordService extends CloudflareService
|
||||
}
|
||||
$this->setAuthEntity($auth_entity);
|
||||
}
|
||||
|
||||
protected function getModel(): RecordModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -45,6 +49,7 @@ class RecordService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
protected function getAccountModel(): AccountModel
|
||||
{
|
||||
if ($this->_accountModel === null) {
|
||||
@ -52,11 +57,11 @@ class RecordService extends CloudflareService
|
||||
}
|
||||
return $this->_accountModel;
|
||||
}
|
||||
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
// log_message("debug", var_export($result, true));
|
||||
$formDatas[RecordModel::PK] = $result->id;
|
||||
// $formDatas[RecordModel::PARENT] = $result->zone_id;
|
||||
$formDatas[RecordModel::PARENT] = $this->getParentEntity()->getPK();
|
||||
$formDatas[RecordModel::TITLE] = $result->name;
|
||||
$formDatas['type'] = $result->type;
|
||||
@ -64,13 +69,13 @@ class RecordService extends CloudflareService
|
||||
$formDatas['ttl'] = (int) $result->ttl;
|
||||
$formDatas['proxiable'] = $result->proxiable ? "on" : "off";
|
||||
$formDatas['proxied'] = $result->proxied ? "on" : "off";
|
||||
// $formDatas['locked'] = isset($result->locked) && $result->locked ? "off" : "on";
|
||||
$formDatas['locked'] = "on";
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
$formDatas['created_at'] = $result->created_on;
|
||||
// log_message("debug", print_r($formDatas, true));
|
||||
return $formDatas;
|
||||
}
|
||||
|
||||
public function create(ZoneEntity $parent_entity, string $host, string $type, string $content, string $proxied): RecordEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -81,7 +86,7 @@ class RecordService extends CloudflareService
|
||||
'name' => $host,
|
||||
'type' => $type,
|
||||
'content' => $content,
|
||||
'proxied' => $proxied === 'on' ? true : false
|
||||
'proxied' => $proxied === 'on'
|
||||
];
|
||||
$response = $this->getMySocket()->post("zones/{$this->getParentEntity()->getPK()}/dns_records", $datas);
|
||||
$body = json_decode($response->getBody());
|
||||
@ -90,6 +95,7 @@ class RecordService extends CloudflareService
|
||||
log_message("debug", "Record:{$entity->getTitle()} 작업을 완료하였습니다.");
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function modify(ZoneEntity $parent_entity, RecordEntity $entity, array $formDatas): RecordEntity
|
||||
{
|
||||
//fixed 필드가 있고 값이 변경되었을때(toggle에서 fixed만 설정시사용)
|
||||
@ -104,10 +110,10 @@ class RecordService extends CloudflareService
|
||||
$this->setParentEntity($parent_entity);
|
||||
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
||||
$datas = [
|
||||
'type' => isset($formDatas['type']) ? $formDatas['type'] : $entity->type,
|
||||
'name' => isset($formDatas['host']) ? $formDatas['host'] : $entity->host,
|
||||
'content' => isset($formDatas['content']) ? $formDatas['content'] : $entity->content,
|
||||
'proxied' => $entity->proxied == 'on' ? true : false,
|
||||
'type' => $formDatas['type'] ?? $entity->type,
|
||||
'name' => $formDatas['host'] ?? $entity->host,
|
||||
'content' => $formDatas['content'] ?? $entity->content,
|
||||
'proxied' => $entity->proxied === 'on',
|
||||
'ttl' => intval($entity->ttl),
|
||||
];
|
||||
if (isset($formDatas['proxied'])) {
|
||||
@ -126,6 +132,7 @@ class RecordService extends CloudflareService
|
||||
// DB 수정
|
||||
return $this->getModel()->modify($entity, $this->getArrayByResult($body->result));
|
||||
}
|
||||
|
||||
public function delete(ZoneEntity $parent_entity, RecordEntity $entity): RecordEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -136,6 +143,7 @@ class RecordService extends CloudflareService
|
||||
log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function sync(ZoneEntity $parent_entity, RecordEntity $entity): RecordEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -163,32 +171,31 @@ class RecordService extends CloudflareService
|
||||
// $promise->wait();
|
||||
return $entity;
|
||||
}
|
||||
|
||||
//Reload
|
||||
public function reload(ZoneEntity $parent_entity): array
|
||||
{
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Record 처리 시작-----------");
|
||||
$entitys = [];
|
||||
$entities = [];
|
||||
try {
|
||||
$results = $this->reload_procedure("zones/{$this->getParentEntity()->getPK()}/dns_records");
|
||||
$total = count($results);
|
||||
if ($total > 0) {
|
||||
$cnt = 1;
|
||||
foreach ($results as $result) {
|
||||
foreach ($results as $index => $result) {
|
||||
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
||||
log_message("error", "Record: result is not a stdClass:\n" . var_export($result, true) . "\n");
|
||||
continue;
|
||||
}
|
||||
$formDatas = $this->getArrayByResult($result);
|
||||
$entity = $this->getModel()->modify(new RecordEntity(), $formDatas);
|
||||
log_message("debug", "{$cnt}/{$total} => {$entity->getTitle()} Record 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entitys[$entity->getPK()] = $entity;
|
||||
$cnt++;
|
||||
log_message("debug", ($index + 1) . "/{$total} => {$entity->getTitle()} Record 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entities[$entity->getPK()] = $entity;
|
||||
}
|
||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 DB삭제
|
||||
$this->getModel()->where(RecordModel::PARENT, $this->getParentEntity()->getPK());
|
||||
$this->getModel()->whereNotIn(RecordModel::PK, array_keys($entitys));
|
||||
$this->getModel()->whereNotIn(RecordModel::PK, array_keys($entities));
|
||||
$this->getModel()->delete();
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
}
|
||||
@ -196,7 +203,7 @@ class RecordService extends CloudflareService
|
||||
log_message("error", $e->getMessage());
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Record처리[" . count($entitys) . "개] 완료-----------");
|
||||
return $entitys;
|
||||
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Record처리[" . count($entities) . "개] 완료-----------");
|
||||
return $entities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,19 +10,21 @@ class ZoneService extends CloudflareService
|
||||
{
|
||||
private ?AccountEntity $_parent_entity = null;
|
||||
private ?ZoneModel $_model = null;
|
||||
private $_setting_fields = [
|
||||
private array $_setting_fields = [
|
||||
'development_mode' => 'off',
|
||||
'ipv6' => 'off',
|
||||
'security_level' => 'medium',
|
||||
'ssl' => 'flexible',
|
||||
'always_use_https' => 'off'
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->class_name = "Zone";
|
||||
parent::__construct();
|
||||
$this->class_path .= $this->class_name;
|
||||
}
|
||||
|
||||
private function getParentEntity(): AccountEntity
|
||||
{
|
||||
if ($this->_parent_entity === null) {
|
||||
@ -30,6 +32,7 @@ class ZoneService extends CloudflareService
|
||||
}
|
||||
return $this->_parent_entity;
|
||||
}
|
||||
|
||||
private function setParentEntity(AccountEntity $parent_entity): void
|
||||
{
|
||||
$this->_parent_entity = $parent_entity;
|
||||
@ -39,6 +42,7 @@ class ZoneService extends CloudflareService
|
||||
}
|
||||
$this->setAuthEntity($auth_entity);
|
||||
}
|
||||
|
||||
protected function getModel(): ZoneModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
@ -46,6 +50,7 @@ class ZoneService extends CloudflareService
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
// log_message("debug", var_export($result, true));
|
||||
@ -57,18 +62,12 @@ class ZoneService extends CloudflareService
|
||||
$formDatas['name_servers'] = 'none';
|
||||
if (isset($result->name_servers)) {
|
||||
$formDatas['name_servers'] = is_array($result->name_servers) ?
|
||||
implode(
|
||||
',',
|
||||
$result->name_servers
|
||||
) : $result->name_servers;
|
||||
implode(',', $result->name_servers) : $result->name_servers;
|
||||
}
|
||||
$formDatas['original_name_servers'] = 'none';
|
||||
if (isset($result->original_name_servers)) {
|
||||
$formDatas['original_name_servers'] = is_array($result->original_name_servers) ?
|
||||
implode(
|
||||
',',
|
||||
$result->original_name_servers
|
||||
) : $result->original_name_servers;
|
||||
implode(',', $result->original_name_servers) : $result->original_name_servers;
|
||||
}
|
||||
// $formDatas['updated_at'] = $result->modified_on;
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
@ -77,6 +76,7 @@ class ZoneService extends CloudflareService
|
||||
// log_message("debug", var_export($formDatas, true));
|
||||
return $formDatas;
|
||||
}
|
||||
|
||||
//Cfzone에서 가져온 값을 zone에 setting
|
||||
private function getCFSetting(string $uid, array $formDatas = []): array
|
||||
{
|
||||
@ -84,13 +84,14 @@ class ZoneService extends CloudflareService
|
||||
$body = json_decode($response->getBody());
|
||||
// log_message("debug", var_export($body, true));
|
||||
foreach ($body->result as $result) {
|
||||
if (in_array(needle: $result->id, haystack: array_keys($this->_setting_fields))) {
|
||||
if (in_array($result->id, array_keys($this->_setting_fields))) {
|
||||
$formDatas[($result->id === 'ssl') ? 'ssl_mode' : $result->id] = $result->value;
|
||||
}
|
||||
}
|
||||
// log_message("debug", var_export($cf, return: true));
|
||||
return $formDatas;
|
||||
}
|
||||
|
||||
private function setCFSetting(string $uid, string $field, string $value): string
|
||||
{
|
||||
$field = ($field === 'ssl_mode') ? 'ssl' : $field;
|
||||
@ -100,6 +101,7 @@ class ZoneService extends CloudflareService
|
||||
//최종 결과값은 body->result->id='필드명',body->result->value='on/off'이런식으로 받음
|
||||
return $body->result->value;
|
||||
}
|
||||
|
||||
public function create(AccountEntity $parent_entity, string $domain, bool $jump_start = false): ZoneEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -123,6 +125,7 @@ class ZoneService extends CloudflareService
|
||||
log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다.");
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function modify(AccountEntity $parent_entity, ZoneEntity $entity, array $formDatas): ZoneEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -135,6 +138,7 @@ class ZoneService extends CloudflareService
|
||||
//DB수정
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
|
||||
public function delete(AccountEntity $parent_entity, ZoneEntity $entity): ZoneEntity
|
||||
{
|
||||
//부모데이터정의
|
||||
@ -145,6 +149,7 @@ class ZoneService extends CloudflareService
|
||||
log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function sync(AccountEntity $parent_entity, ZoneEntity $entity): ZoneEntity
|
||||
{
|
||||
$this->setParentEntity($parent_entity);
|
||||
@ -158,6 +163,7 @@ class ZoneService extends CloudflareService
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function expire(AccountEntity $parent_entity, ZoneEntity $entity): ZoneEntity
|
||||
{
|
||||
$this->setParentEntity($parent_entity);
|
||||
@ -176,7 +182,7 @@ class ZoneService extends CloudflareService
|
||||
//부모데이터정의
|
||||
$this->setParentEntity($parent_entity);
|
||||
log_message("notice", "\n-----------Account {$this->getParentEntity()->getTitle()}의 Zone처리 시작-----------");
|
||||
$entitys = [];
|
||||
$entities = [];
|
||||
try {
|
||||
$results = $this->reload_procedure("zones");
|
||||
$cnt = 1;
|
||||
@ -192,15 +198,15 @@ class ZoneService extends CloudflareService
|
||||
$formDatas = $this->getCFSetting($formDatas[ZoneModel::PK], $formDatas);
|
||||
$entity = $this->getModel()->modify(new ZoneEntity(), $formDatas);
|
||||
log_message("debug", "{$cnt}/{$total} => {$entity->getTitle()} Zone 처리,[{$this->getMySocket()::$_request}]");
|
||||
$entitys[$entity->getPK()] = $entity;
|
||||
$entities[$entity->getPK()] = $entity;
|
||||
$cnt++;
|
||||
} else {
|
||||
log_message("error", "Zone is abnormal status:\n" . var_export($result, true) . "\n");
|
||||
}
|
||||
}
|
||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
||||
$this->getModel()->where(ZoneModel::PARENT, value: $this->getParentEntity()->getPK());
|
||||
$this->getModel()->whereNotIn(ZoneModel::PK, array_keys($entitys));
|
||||
$this->getModel()->where(ZoneModel::PARENT, $this->getParentEntity()->getPK());
|
||||
$this->getModel()->whereNotIn(ZoneModel::PK, array_keys($entities));
|
||||
$this->getModel()->delete();
|
||||
// log_message("debug", $this->getModel()->getLastQuery());
|
||||
}
|
||||
@ -208,7 +214,7 @@ class ZoneService extends CloudflareService
|
||||
log_message("error", $e->getMessage());
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
log_message("notice", "\n----------Account {$this->getParentEntity()->getTitle()}의 Zone 처리[" . count($entitys) . "개] 완료-----------");
|
||||
return $entitys;
|
||||
log_message("notice", "\n----------Account {$this->getParentEntity()->getTitle()}의 Zone 처리[" . count($entities) . "개] 완료-----------");
|
||||
return $entities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ trait FileTrait
|
||||
}
|
||||
}
|
||||
|
||||
final protected function isFileType_FileTrait(string $file_ext, $type = "img"): bool
|
||||
final protected function isFileType_FileTrait(string $file_ext, string $type = "img"): bool
|
||||
{
|
||||
switch ($type) {
|
||||
case "audio":
|
||||
@ -30,8 +30,8 @@ trait FileTrait
|
||||
return in_array($file_ext, $exts);
|
||||
}
|
||||
|
||||
//디렉토리에 속한 파일 List
|
||||
final protected function getFiles_FileTrait(string $path, string $type = "image"): array
|
||||
// 디렉토리에 속한 파일 List
|
||||
final protected function getFiles_FileTrait(string $path, string $type = "img"): array
|
||||
{
|
||||
// 디렉토리에서 파일 목록 가져오기
|
||||
$files = [];
|
||||
@ -45,7 +45,7 @@ trait FileTrait
|
||||
return $files;
|
||||
}
|
||||
|
||||
final protected function getUniqueName_FileTrait($path, $file_name)
|
||||
final protected function getUniqueName_FileTrait(string $path, string $file_name): string
|
||||
{
|
||||
$fileExtension = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
$fileBaseName = pathinfo($file_name, PATHINFO_FILENAME);
|
||||
|
||||
@ -14,15 +14,17 @@ trait ImageTrait
|
||||
{
|
||||
return imagesx($this->_image);
|
||||
}
|
||||
|
||||
// 이미지의 현재 높이를 반환하는 메소드
|
||||
final public function getHeight_ImageTrait()
|
||||
{
|
||||
return imagesy($this->_image);
|
||||
}
|
||||
|
||||
// 이미지 파일을 로드하는 메소드
|
||||
final public function load_ImageTrait($file)
|
||||
{
|
||||
$imageInfo = getimagesize($file);
|
||||
$imageInfo = getimagesize($file);
|
||||
$this->_imageType = $imageInfo[2];
|
||||
switch ($this->_imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
@ -37,8 +39,11 @@ trait ImageTrait
|
||||
case IMAGETYPE_WEBP:
|
||||
$this->_image = imagecreatefromwebp($file);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Unsupported image type: " . $this->_imageType);
|
||||
}
|
||||
}
|
||||
|
||||
// 이미지 크기를 지정된 너비, 높이로 변경하는 메소드
|
||||
final public function resize_ImageTrait($width, $height)
|
||||
{
|
||||
@ -57,25 +62,29 @@ trait ImageTrait
|
||||
);
|
||||
$this->_image = $newImage;
|
||||
}
|
||||
|
||||
// 이미지 비율을 유지하면서 크기를 조정하는 메소드
|
||||
final public function resizeToWidth_ImageTrait($width)
|
||||
{
|
||||
$ratio = $width / $this->getWidth_ImageTrait();
|
||||
$ratio = $width / $this->getWidth_ImageTrait();
|
||||
$height = $this->getHeight_ImageTrait() * $ratio;
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
|
||||
final public function resizeToHeight_ImageTrait($height)
|
||||
{
|
||||
$ratio = $height / $this->getHeight_ImageTrait();
|
||||
$width = $this->getWidth_ImageTrait() * $ratio;
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
|
||||
final public function scale($scale)
|
||||
{
|
||||
$width = $this->getWidth_ImageTrait() * ($scale / 100);
|
||||
$width = $this->getWidth_ImageTrait() * ($scale / 100);
|
||||
$height = $this->getHeight_ImageTrait() * ($scale / 100);
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
|
||||
// 이미지를 저장하는 메소드
|
||||
final public function save_ImageTrait($file, $imageType = IMAGETYPE_WEBP, $compression = 75)
|
||||
{
|
||||
@ -90,11 +99,13 @@ trait ImageTrait
|
||||
imagepng($this->_image, $file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
default:
|
||||
imagewebp($this->_image, $file, $compression);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Unsupported image type: " . $imageType);
|
||||
}
|
||||
}
|
||||
|
||||
// 메모리 해제를 위한 메소드
|
||||
final public function destroy_ImageTrait()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user