cfmgrv4 init...2

This commit is contained in:
최준흠 2024-10-12 09:38:32 +09:00
parent b72373d323
commit 4b914ccb21
7 changed files with 50 additions and 48 deletions

View File

@ -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);
} }

View File

@ -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) . "]");

View File

@ -37,7 +37,7 @@ class Record extends Cloudflare
$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";

View File

@ -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)
{ {

View File

@ -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);
} }
} }

View File

@ -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";
@ -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(