cfmgrv4 init...2
This commit is contained in:
parent
b72373d323
commit
4b914ccb21
@ -59,12 +59,10 @@ class Cloudflare extends BaseController
|
|||||||
foreach ($auths as $auth) {
|
foreach ($auths as $auth) {
|
||||||
$accounts += $this->account_process($auth);
|
$accounts += $this->account_process($auth);
|
||||||
}
|
}
|
||||||
log_message("debug", "\n-------------총 Accounts:" . count($accounts) . "--------------------\n");
|
|
||||||
$zones = [];
|
$zones = [];
|
||||||
foreach ($accounts as $key => $account) {
|
foreach ($accounts as $key => $account) {
|
||||||
$zones += $this->zone_process($account);
|
$zones += $this->zone_process($account);
|
||||||
}
|
}
|
||||||
log_message("debug", "\n-------------총 Zones:" . count($zones) . "--------------------\n");
|
|
||||||
foreach ($zones as $key => $zone) {
|
foreach ($zones as $key => $zone) {
|
||||||
$this->record_process($zone);
|
$this->record_process($zone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,24 +51,25 @@ abstract class Cloudflare extends CommonLibrary
|
|||||||
private function reload_page(string $uri, int $page, int $per_page = 20): mixed
|
private function reload_page(string $uri, int $page, int $per_page = 20): mixed
|
||||||
{
|
{
|
||||||
$query = [
|
$query = [
|
||||||
'name' => '',
|
|
||||||
'status' => '',
|
|
||||||
'order' => 'name',
|
|
||||||
'direction' => 'asc',
|
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'cache_buster' => time(), // 캐시 무효화를 위한 파라미터 추가
|
'cache_buster' => uniqid(), // 매 요청마다 고유한 값 사용
|
||||||
|
];
|
||||||
|
// 요청 헤더에 캐시 제어 추가
|
||||||
|
$headers = [
|
||||||
|
'Cache-Control' => 'no-cache',
|
||||||
|
'Pragma' => 'no-cache',
|
||||||
];
|
];
|
||||||
// log_message("debug", var_export($query, true));
|
// log_message("debug", var_export($query, true));
|
||||||
$response = $this->getMySocket()->get($uri, $query);
|
$response = $this->getMySocket()->get($uri, $query, $headers);
|
||||||
$cf = json_decode($response->getBody());
|
$cf = json_decode($response->getBody());
|
||||||
if (!$cf->success) {
|
if (!$cf->success) {
|
||||||
$message = __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
$message = __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
||||||
log_message("error", $message);
|
log_message("error", $message);
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
log_message("debug", "Page {$page} response: " . var_export($cf->result_info, true));
|
// log_message("debug", "Page {$page} response: " . var_export($cf->result_info, true));
|
||||||
return $cf;
|
return $cf;
|
||||||
}
|
}
|
||||||
final protected function reload_procedure(string $uri): array
|
final protected function reload_procedure(string $uri): array
|
||||||
@ -79,7 +80,9 @@ abstract class Cloudflare extends CommonLibrary
|
|||||||
$per_page = $cf->result_info->per_page;
|
$per_page = $cf->result_info->per_page;
|
||||||
$total_page = $cf->result_info->total_pages;
|
$total_page = $cf->result_info->total_pages;
|
||||||
$results = $cf->result;
|
$results = $cf->result;
|
||||||
for ($i = $page + 1; $i < $total_page; $i++) {
|
for ($i = $page + 1; $i <= $total_page; $i++) {
|
||||||
|
// API 제한을 고려한 지연 추가
|
||||||
|
usleep(100000); // 0.1초 대기
|
||||||
$cf = $this->reload_page($uri, $i, $per_page);
|
$cf = $this->reload_page($uri, $i, $per_page);
|
||||||
$results = array_merge($results, $cf->result);
|
$results = array_merge($results, $cf->result);
|
||||||
log_message("debug", "현재: page[{$i}/{$total_page}] , result수[" . count($results) . "]");
|
log_message("debug", "현재: page[{$i}/{$total_page}] , result수[" . count($results) . "]");
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class Record extends Cloudflare
|
|||||||
private $_zone_entity = null;
|
private $_zone_entity = null;
|
||||||
public function __construct(ZoneEntity $zone_entity)
|
public function __construct(ZoneEntity $zone_entity)
|
||||||
{
|
{
|
||||||
$this->_zone_entity = $zone_entity;
|
$this->_zone_entity = $zone_entity;
|
||||||
$account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent());
|
$account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent());
|
||||||
if ($account_entity === null) {
|
if ($account_entity === null) {
|
||||||
throw new \Exception("해당 계정정보를 찾을수 없습니다.");
|
throw new \Exception("해당 계정정보를 찾을수 없습니다.");
|
||||||
@ -32,15 +32,15 @@ class Record extends Cloudflare
|
|||||||
}
|
}
|
||||||
public function getArrayByResult($result, array $formDatas = []): array
|
public function getArrayByResult($result, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
$formDatas[RecordModel::PK] = $result->id;
|
$formDatas[RecordModel::PK] = $result->id;
|
||||||
$formDatas[RecordModel::PARENT] = $result->zone_id;
|
$formDatas[RecordModel::PARENT] = $result->zone_id;
|
||||||
$formDatas[RecordModel::TITLE] = $result->name;
|
$formDatas[RecordModel::TITLE] = $result->name;
|
||||||
$formDatas['type'] = $result->type;
|
$formDatas['type'] = $result->type;
|
||||||
$formDatas['content'] = $result->content;
|
$formDatas['content'] = $result->content;
|
||||||
$formDatas['ttl'] = (int)$result->ttl;
|
$formDatas['ttl'] = (int) $result->ttl;
|
||||||
$formDatas['proxiable'] = $result->proxiable ? "on" : "off";
|
$formDatas['proxiable'] = $result->proxiable ? "on" : "off";
|
||||||
$formDatas['proxied'] = $result->proxied ? "on" : "off";
|
$formDatas['proxied'] = $result->proxied ? "on" : "off";
|
||||||
$formDatas['locked'] = "on";
|
$formDatas['locked'] = "on";
|
||||||
if (isset($result->locked) && $result->locked) {
|
if (isset($result->locked) && $result->locked) {
|
||||||
$formDatas['locked'] = "off";
|
$formDatas['locked'] = "off";
|
||||||
}
|
}
|
||||||
@ -53,8 +53,8 @@ class Record extends Cloudflare
|
|||||||
//Socket용
|
//Socket용
|
||||||
//호스트생성을 위해 Cloudflare에 전송
|
//호스트생성을 위해 Cloudflare에 전송
|
||||||
$datas = [
|
$datas = [
|
||||||
'name' => $host,
|
'name' => $host,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'proxied' => $proxied === 'on' ? true : false
|
'proxied' => $proxied === 'on' ? true : false
|
||||||
];
|
];
|
||||||
@ -73,19 +73,19 @@ class Record extends Cloudflare
|
|||||||
{
|
{
|
||||||
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
||||||
$datas = [
|
$datas = [
|
||||||
'type' => isset($formDatas['type']) ? $formDatas['type'] : $entity->type,
|
'type' => isset($formDatas['type']) ? $formDatas['type'] : $entity->type,
|
||||||
'name' => isset($formDatas['host']) ? $formDatas['host'] : $entity->host,
|
'name' => isset($formDatas['host']) ? $formDatas['host'] : $entity->host,
|
||||||
'content' => isset($formDatas['content']) ? $formDatas['content'] : $entity->content,
|
'content' => isset($formDatas['content']) ? $formDatas['content'] : $entity->content,
|
||||||
'proxied' => $entity->proxied == 'on' ? true : false,
|
'proxied' => $entity->proxied == 'on' ? true : false,
|
||||||
'ttl' => intval($entity->ttl),
|
'ttl' => intval($entity->ttl),
|
||||||
];
|
];
|
||||||
if (isset($formDatas['proxied'])) {
|
if (isset($formDatas['proxied'])) {
|
||||||
if ($formDatas['proxied'] === 'on') {
|
if ($formDatas['proxied'] === 'on') {
|
||||||
$datas['proxied'] = true;
|
$datas['proxied'] = true;
|
||||||
$datas['ttl'] = 1;
|
$datas['ttl'] = 1;
|
||||||
} else {
|
} else {
|
||||||
$datas['proxied'] = false;
|
$datas['proxied'] = false;
|
||||||
$datas['ttl'] = 120;
|
$datas['ttl'] = 120;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 인코딩된 JSON을 확인
|
// 인코딩된 JSON을 확인
|
||||||
|
|||||||
@ -30,10 +30,10 @@ class Zone extends Cloudflare
|
|||||||
}
|
}
|
||||||
protected function getArrayByResult($result, array $formDatas = []): array
|
protected function getArrayByResult($result, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
$formDatas[ZoneModel::PK] = $result->id;
|
$formDatas[ZoneModel::PK] = $result->id;
|
||||||
$formDatas[ZoneModel::PARENT] = $result->account->id;
|
$formDatas[ZoneModel::PARENT] = $result->account->id;
|
||||||
$formDatas[ZoneModel::TITLE] = $result->name;
|
$formDatas[ZoneModel::TITLE] = $result->name;
|
||||||
$formDatas['status'] = $result->status;
|
$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)) {
|
||||||
@ -54,7 +54,7 @@ class Zone extends Cloudflare
|
|||||||
// $formDatas['updated_at'] = $result->modified_on;
|
// $formDatas['updated_at'] = $result->modified_on;
|
||||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
$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;
|
||||||
}
|
}
|
||||||
//Cfzone에서 가져온 값을 zone에 setting
|
//Cfzone에서 가져온 값을 zone에 setting
|
||||||
@ -92,8 +92,8 @@ class Zone extends Cloudflare
|
|||||||
//Socket용
|
//Socket용
|
||||||
//도메인생성을 위해 Cloudflare에 전송
|
//도메인생성을 위해 Cloudflare에 전송
|
||||||
$datas = [
|
$datas = [
|
||||||
'accountId' => $this->_account_entity->getPK(),
|
'accountId' => $this->_account_entity->getPK(),
|
||||||
'name' => $domain,
|
'name' => $domain,
|
||||||
'jump_start' => $jump_start,
|
'jump_start' => $jump_start,
|
||||||
];
|
];
|
||||||
$cf = $this->getMySocket()->post('zones/', $datas);
|
$cf = $this->getMySocket()->post('zones/', $datas);
|
||||||
|
|||||||
@ -11,7 +11,7 @@ class CloudflareSocket extends MySocket
|
|||||||
private ?Client $_client = null;
|
private ?Client $_client = null;
|
||||||
public static int $_request = 0;
|
public static int $_request = 0;
|
||||||
private static int $_request_max = 1000;
|
private static int $_request_max = 1000;
|
||||||
private static int $_request_timewait = 30;
|
private static int $_request_timewait = 10;
|
||||||
private ?AuthEntity $_auth_entity = null;
|
private ?AuthEntity $_auth_entity = null;
|
||||||
public function __construct(AuthEntity $auth_entity)
|
public function __construct(AuthEntity $auth_entity)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -48,15 +48,15 @@ abstract class MySocket
|
|||||||
}
|
}
|
||||||
public function request(string $method, $uri = '', array $options = [], array $headers = []): ResponseInterface
|
public function request(string $method, $uri = '', array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])) {
|
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
|
||||||
throw new \InvalidArgumentException("{$method} => Request method must be GET, POST, PUT, PATCH, or DELETE");
|
throw new \InvalidArgumentException("{$method} => Request method must be get, post, put, patch, or delete");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$options = $this->getRequestOptions($method, $options, $headers);
|
$options = $this->getRequestOptions($method, $options, $headers);
|
||||||
log_message("debug", __FUNCTION__ .
|
// log_message("debug", __FUNCTION__ .
|
||||||
"=> 호출 Socket URL:{$uri}\n--------------\n" .
|
// "=> 호출 Socket URL:{$uri}\n--------------\n" .
|
||||||
var_export($options, true) .
|
// var_export($options, true) .
|
||||||
"\n--------------\n");
|
// "\n--------------\n");
|
||||||
$response = $this->getClient()->$method($uri, $options);
|
$response = $this->getClient()->$method($uri, $options);
|
||||||
} catch (RequestException $err) {
|
} catch (RequestException $err) {
|
||||||
throw ResponseException::fromRequestException($err);
|
throw ResponseException::fromRequestException($err);
|
||||||
@ -65,22 +65,22 @@ abstract class MySocket
|
|||||||
}
|
}
|
||||||
final public function get($uri, array $options = [], array $headers = []): ResponseInterface
|
final public function get($uri, array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->request('GET', $uri, $options, $headers);
|
return $this->request(__FUNCTION__, $uri, $options, $headers);
|
||||||
}
|
}
|
||||||
final public function post($uri, array $options = [], array $headers = []): ResponseInterface
|
final public function post($uri, array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->request('POST', $uri, $options, $headers);
|
return $this->request(__FUNCTION__, $uri, $options, $headers);
|
||||||
}
|
}
|
||||||
final public function put($uri, array $options = [], array $headers = []): ResponseInterface
|
final public function put($uri, array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->request('PUT', $uri, $options, $headers);
|
return $this->request(__FUNCTION__, $uri, $options, $headers);
|
||||||
}
|
}
|
||||||
final public function patch($uri, array $options = [], array $headers = []): ResponseInterface
|
final public function patch($uri, array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->request('PATCH', $uri, $options, $headers);
|
return $this->request(__FUNCTION__, $uri, $options, $headers);
|
||||||
}
|
}
|
||||||
public function delete($uri, array $options = [], array $headers = []): ResponseInterface
|
public function delete($uri, array $options = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->request('DELETE', $uri, $options, $headers);
|
return $this->request(__FUNCTION__, $uri, $options, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,8 @@ abstract class CommonModel extends Model
|
|||||||
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
||||||
} else {
|
} else {
|
||||||
$rule = "required|numeric";
|
$rule = "required|numeric";
|
||||||
};
|
}
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case $this->getTitleField():
|
case $this->getTitleField():
|
||||||
$rule = "required|string";
|
$rule = "required|string";
|
||||||
@ -132,7 +133,7 @@ abstract class CommonModel extends Model
|
|||||||
//$formDatas에 전달된 값이 없는경우
|
//$formDatas에 전달된 값이 없는경우
|
||||||
if (!array_key_exists($field, $formDatas)) {
|
if (!array_key_exists($field, $formDatas)) {
|
||||||
$randomBytes = bin2hex(random_bytes(32));
|
$randomBytes = bin2hex(random_bytes(32));
|
||||||
$value = sprintf(
|
$value = sprintf(
|
||||||
'%08s-%04s-%04x-%04x-%12s',
|
'%08s-%04s-%04x-%04x-%12s',
|
||||||
substr($randomBytes, 0, 8),
|
substr($randomBytes, 0, 8),
|
||||||
substr($randomBytes, 8, 4),
|
substr($randomBytes, 8, 4),
|
||||||
@ -166,7 +167,7 @@ abstract class CommonModel extends Model
|
|||||||
if (!$this->save($entity)) {
|
if (!$this->save($entity)) {
|
||||||
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
||||||
}
|
}
|
||||||
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
|
log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
|
||||||
return $entity;
|
return $entity;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
@ -189,7 +190,7 @@ abstract class CommonModel extends Model
|
|||||||
$entity = $this->save_process($entity);
|
$entity = $this->save_process($entity);
|
||||||
//primaryKey가 자동입력이면
|
//primaryKey가 자동입력이면
|
||||||
if ($this->useAutoIncrement) {
|
if ($this->useAutoIncrement) {
|
||||||
$pkField = $this->getPKField();
|
$pkField = $this->getPKField();
|
||||||
$entity->$pkField = $this->getInsertID();
|
$entity->$pkField = $this->getInsertID();
|
||||||
}
|
}
|
||||||
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user