cfmgrv4 init...3
This commit is contained in:
parent
aed58b77c0
commit
d7841a2317
@ -82,11 +82,11 @@ class ZoneController extends CloudflareController
|
||||
private function init(string $action, array $fields = []): void
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->fields = count($fields) ? $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 = count($fields) ? $fields : [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'ssl_mode', 'status', 'updated_at', 'created_at'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'plan', 'development_mode', 'ipv6', 'security_level'];
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'plan', 'development_mode', 'ipv6', 'security_level', 'ssl_mode'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = ['development_mode', 'ipv6', 'security_level'];
|
||||
$this->batchjob_fields = ['development_mode', 'ipv6', 'security_level', 'ssl_mode'];
|
||||
}
|
||||
//생성
|
||||
public function create_form(): RedirectResponse|string
|
||||
|
||||
@ -47,6 +47,7 @@ class ZoneHelper extends MVCHelper
|
||||
case "development_mode":
|
||||
case "ipv6":
|
||||
case "security_level":
|
||||
case "ssl_mode":
|
||||
case 'status':
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
|
||||
@ -11,6 +11,7 @@ return [
|
||||
'development_mode' => "개발모드",
|
||||
'ipv6' => "ipv6",
|
||||
'security_level' => "공격방어",
|
||||
'ssl_mode' => "SSL모드",
|
||||
'status' => "서비스",
|
||||
'updated_at' => "수정일",
|
||||
'created_at' => "작성일",
|
||||
@ -40,6 +41,12 @@ return [
|
||||
"low" => "low",
|
||||
"essentially_off" => "essentially_off",
|
||||
],
|
||||
"SSL_MODE" => [
|
||||
"off" => "off",
|
||||
"flexible" => "flexible",
|
||||
"full" => "full",
|
||||
"strict" => "strict",
|
||||
],
|
||||
"STATUS" => [
|
||||
"initializing" => "initializing",
|
||||
"pending" => "pending",
|
||||
|
||||
@ -46,6 +46,7 @@ class Record extends Cloudflare
|
||||
}
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
$formDatas['created_at'] = $result->created_on;
|
||||
// log_message("debug", var_export($result, return: true));
|
||||
return $formDatas;
|
||||
}
|
||||
public function create(string $host, string $type, string $content, string $proxied): RecordEntity
|
||||
|
||||
@ -55,6 +55,7 @@ class Zone extends Cloudflare
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
$formDatas['created_at'] = $result->created_on;
|
||||
$formDatas['plan'] = $result->plan->name;
|
||||
// log_message("debug", var_export($result, true));
|
||||
return $formDatas;
|
||||
}
|
||||
//Cfzone에서 가져온 값을 zone에 setting
|
||||
@ -68,12 +69,28 @@ class Zone extends Cloudflare
|
||||
throw new \Exception($message);
|
||||
}
|
||||
foreach ($cf->result as $cf) {
|
||||
if (in_array($cf->id, array_keys($this->_setting_fields))) {
|
||||
if (in_array($cf->id, haystack: array_keys($this->_setting_fields))) {
|
||||
$formDatas[$cf->id] = $cf->value;
|
||||
}
|
||||
}
|
||||
return $formDatas;
|
||||
}
|
||||
private function getCFSettingSSL(string $uid, array $formDatas = []): array
|
||||
{
|
||||
$cf = $this->getMySocket()->get('zones/' . $uid . '/settings/ssl');
|
||||
$cf = json_decode($cf->getBody());
|
||||
if (!$cf->success) {
|
||||
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
||||
log_message("error", $message);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
foreach ($cf->result as $cf) {
|
||||
$formDatas['ssl_mode'] = $cf->value;
|
||||
}
|
||||
// log_message("debug", var_export($cf, return: true));
|
||||
// exit;
|
||||
return $formDatas;
|
||||
}
|
||||
private function setCFSetting(string $uid, string $field, string $value): string
|
||||
{
|
||||
$datas = ['value' => $value];
|
||||
@ -87,6 +104,19 @@ class Zone extends Cloudflare
|
||||
//최종 결과값은 body->result->id='필드명',body->result->value='on/off'이런식으로 받음
|
||||
return $cf->result->value;
|
||||
}
|
||||
private function setCFSettingSSL(string $uid, string $field, string $value): string
|
||||
{
|
||||
$datas = ['value' => $value];
|
||||
$cf = $this->getMySocket()->patch('zones/' . $uid . '/settings/ssl' . $field, $datas);
|
||||
$cf = json_decode($cf->getBody());
|
||||
if (!$cf->success || $cf->result->id !== $field) {
|
||||
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nrequest:" . var_export($datas, true) . "\nresponse:" . var_export($cf, true);
|
||||
log_message("error", $message);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
//최종 결과값은 body->result->id='필드명',body->result->value='on/off'이런식으로 받음
|
||||
return $cf->result->value;
|
||||
}
|
||||
public function create(string $domain, bool $jump_start = false): ZoneEntity
|
||||
{
|
||||
//Socket용
|
||||
@ -115,8 +145,12 @@ class Zone extends Cloudflare
|
||||
{
|
||||
// throw new \Exception("zone:modify" . var_export($formDatas, true));
|
||||
foreach ($formDatas as $field => $value) {
|
||||
//modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level
|
||||
$formDatas[$field] = $this->setCFSetting($entity, $field, $value);
|
||||
if ($field === 'ssl_mode') {
|
||||
$formDatas[$field] = $this->setCFSettingSSL($entity, $field, $value);
|
||||
} else {
|
||||
//modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level
|
||||
$formDatas[$field] = $this->setCFSetting($entity, $field, $value);
|
||||
}
|
||||
}
|
||||
//DB수정
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
@ -147,6 +181,7 @@ class Zone extends Cloudflare
|
||||
}
|
||||
$formDatas = $this->getArrayByResult($cf->result);
|
||||
$formDatas = $this->getCFSetting($formDatas[ZoneModel::PK], $formDatas);
|
||||
$formDatas = $this->getCFSettingSSL($formDatas[ZoneModel::PK], $formDatas);
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
//Reload
|
||||
|
||||
Loading…
Reference in New Issue
Block a user