cfmgrv3 init...2
This commit is contained in:
parent
e6665d0305
commit
0570832555
@ -34,7 +34,7 @@ $routes->get('/', 'Home::index');
|
||||
$routes->get('/login', 'Common\AuthController::login');
|
||||
$routes->post('/signin', 'Common\AuthController::signin');
|
||||
$routes->get('/logout', 'Common\AuthController::logout');
|
||||
$routes->group('cli', ['namespace' => 'App\Controllers\CLI\Cloudflare'], function ($routes) {
|
||||
$routes->group('cli', ['namespace' => 'App\Controllers\CLI\Cloudflare\API'], function ($routes) {
|
||||
$routes->cli('cloudflare/auth', 'Auth::execute');
|
||||
$routes->cli('cloudflare/account/(:any)', 'Account::execute/$1');
|
||||
$routes->cli('cloudflare/zone/record/(:any)', 'Zone::record/$1');
|
||||
@ -46,7 +46,7 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou
|
||||
// authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함
|
||||
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) {
|
||||
$routes->get('/', 'Home::index');
|
||||
$routes->group('cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
|
||||
$routes->group('cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
|
||||
$routes->get('', 'AuthController::index');
|
||||
$routes->get('excel', 'AuthController::excel');
|
||||
$routes->get('insert', 'AuthController::insert_form');
|
||||
@ -59,13 +59,13 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->post('batchjob', 'AuthController::batchjob', ['filter' => 'authFilter:master,director,cloudflare']);
|
||||
$routes->get('reload/(:num)', 'AuthController::reload/$1');
|
||||
});
|
||||
$routes->group('cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
|
||||
$routes->group('cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
|
||||
$routes->get('', 'AccountController::index');
|
||||
$routes->get('excel', 'AccountController::excel');
|
||||
$routes->get('selectkey', 'AccountController::selectkey');
|
||||
$routes->get('reload/(:hash)', 'AccountController::reload/$1');
|
||||
});
|
||||
$routes->group('cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) {
|
||||
$routes->group('cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
|
||||
$routes->get('', 'ZoneController::index');
|
||||
$routes->post('insert', 'ZoneController::insert');
|
||||
$routes->get('excel', 'ZoneController::excel');
|
||||
@ -76,7 +76,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->get('sync/(:hash)', 'ZoneController::sync/$1');
|
||||
$routes->get('reload/(:hash)', 'ZoneController::reload/$1');
|
||||
});
|
||||
$routes->group('cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) {
|
||||
$routes->group('cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
|
||||
$routes->get('', 'RecordController::index');
|
||||
$routes->post('insert', 'RecordController::insert');
|
||||
$routes->get('excel', 'RecordController::excel');
|
||||
@ -86,7 +86,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->get('sync/(:hash)', 'RecordController::sync/$1');
|
||||
$routes->get('cdnToggle/(:hash)', 'RecordController::cdnToggle/$1');
|
||||
});
|
||||
$routes->group('cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare'], static function ($routes) {
|
||||
$routes->group('cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
|
||||
$routes->get('', 'FirewallController::index');
|
||||
$routes->get('excel', 'FirewallController::excel');
|
||||
$routes->get('toggle/(:hash)/(:hash)', 'FirewallController::toggle/$1/$2');
|
||||
|
||||
@ -11,8 +11,9 @@ class AdminController extends \App\Controllers\Common\CommonController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_viewPath = $this->_viewPath.'/admin';
|
||||
$this->_className .= 'Admin';
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['layout'] = LAYOUTS['admin'];
|
||||
$this->_viewDatas['title'] = "관리자페이지";
|
||||
$this->_viewDatas['title'] = "관리자";
|
||||
}
|
||||
}
|
||||
|
||||
100
app/Controllers/Admin/Cloudflare/API/APIController.php
Normal file
100
app/Controllers/Admin/Cloudflare/API/APIController.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Models\Cloudflare\API\AccountModel;
|
||||
use App\Models\Cloudflare\API\AuthModel;
|
||||
use App\Models\Cloudflare\API\ZoneModel;
|
||||
use App\Models\Cloudflare\API\RecordModel;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class APIController extends \App\Controllers\Admin\Cloudflare\CloudflareController
|
||||
{
|
||||
private $_authModel = null;
|
||||
private $_accountModel = null;
|
||||
private $_zoneModel = null;
|
||||
private $_recordModel = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className .= '/API';
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
}
|
||||
final protected function getAuthModel(): AuthModel
|
||||
{
|
||||
return is_null($this->_authModel) ? new AuthModel() : $this->_authModel;
|
||||
}
|
||||
final protected function getAccountModel(): AccountModel
|
||||
{
|
||||
return is_null($this->_accountModel) ? new AccountModel() : $this->_accountModel;
|
||||
}
|
||||
final protected function getZoneModel(): ZoneModel
|
||||
{
|
||||
return is_null($this->_zoneModel) ? new ZoneModel() : $this->_zoneModel;
|
||||
}
|
||||
final protected function getRecordModel(): RecordModel
|
||||
{
|
||||
return is_null($this->_recordModel) ? new RecordModel() : $this->_recordModel;
|
||||
}
|
||||
|
||||
//Zone입력
|
||||
final protected function insert_Zone(
|
||||
\App\Entities\Cloudflare\API\AccountEntity $account,
|
||||
string $domain
|
||||
): \App\Entities\Cloudflare\API\ZoneEntity {
|
||||
$fieldDatas = array('account_uid' => $account->getPrimaryKey(), 'domain' => $domain);
|
||||
$api = new \App\Libraries\Cloudflare\API\Zone($account);
|
||||
$zone = $api->insert($fieldDatas);
|
||||
if (!$this->getZoneModel()->save($zone)) {
|
||||
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery());
|
||||
Log::add("error", implode("\n", $this->getZoneModel()->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getZoneModel()->errors(), true));
|
||||
}
|
||||
Log::add("info", "Zone: {$zone->getTitle()} 등록");
|
||||
return $zone;
|
||||
}
|
||||
//Record입력
|
||||
final protected function insert_Host(
|
||||
\App\Entities\Cloudflare\API\ZoneEntity $zone,
|
||||
string $host,
|
||||
string $type,
|
||||
string $content,
|
||||
string $proxied
|
||||
): \App\Entities\Cloudflare\API\RecordEntity {
|
||||
$fieldDatas = array('zone_uid' => $zone->getPrimaryKey(), 'host' => $host);
|
||||
$fieldDatas['type'] = $type;
|
||||
$fieldDatas['content'] = $content;
|
||||
$fieldDatas['proxied'] = $proxied;
|
||||
|
||||
$api = new \App\Libraries\Cloudflare\API\Record($zone);
|
||||
$record = $api->insert($fieldDatas);
|
||||
$record->fixed = 'off'; //초기값
|
||||
if (!$this->getRecordModel()->save($record)) {
|
||||
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getRecordModel()->getLastQuery());
|
||||
Log::add("error", implode("\n", $this->getRecordModel()->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getRecordModel()->errors(), true));
|
||||
}
|
||||
Log::add("info", "Host: {$record->getTitle()} 등록");
|
||||
return $record;
|
||||
}
|
||||
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
final public function sync($uid)
|
||||
{
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$entity = $this->sync_process($entity);
|
||||
return alert_CommonHelper("{$this->_viewDatas['title']} " . __FUNCTION__ . " 완료하였습니다.", session()->get(RETURN_URL));
|
||||
} catch (\Exception $e) {
|
||||
return alert_CommonHelper($e->getMessage(), 'back');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use App\Models\Cloudflare\API\AccountModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AccountController extends CloudflareController
|
||||
class AccountController extends APIController
|
||||
{
|
||||
private $_auth_uids = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = $this->_className . '/Account';
|
||||
$this->_className .= '/Account';
|
||||
$this->_model = new AccountModel();
|
||||
$this->_defines = [
|
||||
'index' => [
|
||||
@ -26,8 +26,8 @@ class AccountController extends CloudflareController
|
||||
'fieldFilters' => ['auth_uid', 'type', 'status'],
|
||||
],
|
||||
];
|
||||
helper('Cloudflare/Account');
|
||||
$this->_viewPath = $this->_viewPath . '/account';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class AccountController extends CloudflareController
|
||||
if (is_null($this->_auth_uids)) {
|
||||
//모든 필요한 FormOption등 조기화작업 필요
|
||||
$this->_auth_uids = [DEFAULT_EMPTY => lang($this->_className . '.label.' . $field) . ' 선택'];
|
||||
foreach ($this->getAuthModel()->where('status', 'use')->orderBy('id', 'asc')->findAll() as $auth) {
|
||||
foreach ($this->getAuthModel()->orderBy('id', 'asc')->findAll() as $auth) {
|
||||
$this->_auth_uids[$auth['uid']] = $auth['id'];
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Models\Cloudflare\AuthModel;
|
||||
use App\Models\Cloudflare\API\AuthModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AuthController extends CloudflareController
|
||||
class AuthController extends APIController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = $this->_className . '/Auth';
|
||||
$this->_className .= '/Auth';
|
||||
$this->_model = new AuthModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
@ -48,8 +48,8 @@ class AuthController extends CloudflareController
|
||||
'fieldFilters' => ['status'],
|
||||
],
|
||||
];
|
||||
helper('Cloudflare/Auth');
|
||||
$this->_viewPath = $this->_viewPath . '/auth';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
}
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Models\Cloudflare\FirewallModel;
|
||||
use App\Models\Cloudflare\API\FirewallModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\Cloudflare\API\Firewall;
|
||||
|
||||
class FirewallController extends CloudflareController
|
||||
class FirewallController extends APIController
|
||||
{
|
||||
private $_zone_uids = null;
|
||||
private $_api = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = $this->_className . '/Firewall';
|
||||
$this->_className .= '/Firewall';
|
||||
$this->_model = new FirewallModel();
|
||||
$this->_defines = [
|
||||
'index' => [
|
||||
@ -27,10 +27,9 @@ class FirewallController extends CloudflareController
|
||||
'fieldFilters' => ['zone_uid', 'action', 'paused',],
|
||||
],
|
||||
];
|
||||
helper('Cloudflare/Firewall');
|
||||
$this->_viewPath = $this->_viewPath . '/firewall';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_api = new \App\Libraries\Cloudflare\API\Firewall();
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
@ -56,25 +55,29 @@ class FirewallController extends CloudflareController
|
||||
//Update관련
|
||||
protected function update_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::update_process($entity);
|
||||
}
|
||||
//Toggle관련
|
||||
protected function toggle_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::toggle_process($entity);
|
||||
}
|
||||
//Batchjob관련
|
||||
protected function batchjob_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::batchjob_process($entity);
|
||||
}
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
$entity = $this->_api->sync($entity);
|
||||
$api = new Firewall($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->sync($entity);
|
||||
return parent::sync_process($entity);
|
||||
}
|
||||
//Index관련
|
||||
@ -1,21 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Models\Cloudflare\RecordModel;
|
||||
use App\Models\Cloudflare\API\RecordModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\Cloudflare\API\Record;
|
||||
|
||||
class RecordController extends CloudflareController
|
||||
class RecordController extends APIController
|
||||
{
|
||||
private $_zone_uids = null;
|
||||
private $_api = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = $this->_className . '/Record';
|
||||
$this->_className .= '/Record';
|
||||
$this->_model = new RecordModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
@ -39,10 +39,9 @@ class RecordController extends CloudflareController
|
||||
'fieldFilters' => ['zone_uid', 'type', 'proxied', 'locked'],
|
||||
],
|
||||
];
|
||||
helper('Cloudflare/Record');
|
||||
$this->_viewPath = $this->_viewPath . '/record';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_api = new \App\Libraries\Cloudflare\API\Record();
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
@ -91,8 +90,9 @@ class RecordController extends CloudflareController
|
||||
protected function insert_process()
|
||||
{
|
||||
foreach ($this->_viewDatas['fieldDatas']['hosts'] as $host) {
|
||||
$zone = $this->getZoneModel()->gentEntity($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD]);
|
||||
$this->insert_Host(
|
||||
$this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD],
|
||||
$zone,
|
||||
$host,
|
||||
$this->_viewDatas['fieldDatas']['type'],
|
||||
$this->_viewDatas['fieldDatas']['content'],
|
||||
@ -104,31 +104,36 @@ class RecordController extends CloudflareController
|
||||
//Update관련
|
||||
protected function update_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::update_process($entity);
|
||||
}
|
||||
//Toggle관련
|
||||
protected function toggle_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::toggle_process($entity);
|
||||
}
|
||||
//Batchjob관련
|
||||
protected function batchjob_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::batchjob_process($entity);
|
||||
}
|
||||
//Delete 관련
|
||||
protected function delete_process($entity)
|
||||
{
|
||||
$this->_api->delete($entity);
|
||||
$api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$api->delete($entity);
|
||||
return parent::delete_process($entity);
|
||||
}
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
$entity = $this->_api->sync($entity);
|
||||
$api = new Record($this->getZoneModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->sync($entity);
|
||||
return parent::sync_process($entity);
|
||||
}
|
||||
//Index관련
|
||||
@ -143,7 +148,7 @@ class RecordController extends CloudflareController
|
||||
{
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$fixedRecordModel = new \App\Models\Cloudflare\FixedRecordModel();
|
||||
$fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel();
|
||||
if ($entity->fixed == 'on') {
|
||||
$entity->fixed = "off";
|
||||
$this->_model->save($entity);
|
||||
@ -1,21 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
use App\Models\Cloudflare\API\ZoneModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\Cloudflare\API\Zone;
|
||||
|
||||
class ZoneController extends CloudflareController
|
||||
class ZoneController extends APIController
|
||||
{
|
||||
private $_account_uids = null;
|
||||
private $_api = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = $this->_className . '/Zone';
|
||||
$this->_className .= '/Zone';
|
||||
$this->_model = new ZoneModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
@ -39,10 +39,9 @@ class ZoneController extends CloudflareController
|
||||
'fieldFilters' => ['account_uid', 'development_mode', 'ipv6', 'security_level', 'status'],
|
||||
],
|
||||
];
|
||||
helper('Cloudflare/Zone');
|
||||
$this->_viewPath = $this->_viewPath . '/zone';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
$this->_api = new \App\Libraries\Cloudflare\API\Zone();
|
||||
}
|
||||
|
||||
//Field별 Form Option용
|
||||
@ -103,10 +102,11 @@ class ZoneController extends CloudflareController
|
||||
protected function insert_process()
|
||||
{
|
||||
foreach ($this->_viewDatas['fieldDatas']['domains'] as $domain) {
|
||||
$zone = $this->insert_Zone($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD], $domain);
|
||||
$account = $this->getAccountModel()->gentEntity($this->_viewDatas['fieldDatas'][$this->_model::PARENT_FIELD]);
|
||||
$zone = $this->insert_Zone($account, $domain);
|
||||
foreach ($this->_viewDatas['fieldDatas']['hosts'] as $host) {
|
||||
$this->insert_Host(
|
||||
$zone->getPrimaryKey(),
|
||||
$zone,
|
||||
$host,
|
||||
$this->_viewDatas['fieldDatas']['type'],
|
||||
$this->_viewDatas['fieldDatas']['content'],
|
||||
@ -118,31 +118,36 @@ class ZoneController extends CloudflareController
|
||||
//Update관련
|
||||
protected function update_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::update_process($entity);
|
||||
}
|
||||
//Toggle관련
|
||||
protected function toggle_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::toggle_process($entity);
|
||||
}
|
||||
//Batchjob관련
|
||||
protected function batchjob_process($entity)
|
||||
{
|
||||
$entity = $this->_api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
$api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->update($entity, $this->_viewDatas['fieldDatas']);
|
||||
return parent::batchjob_process($entity);
|
||||
}
|
||||
//Delete 관련
|
||||
protected function delete_process($entity)
|
||||
{
|
||||
$this->_api->delete($entity);
|
||||
$api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData()));
|
||||
$api->delete($entity);
|
||||
return parent::delete_process($entity);
|
||||
}
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
$entity = $this->_api->sync($entity);
|
||||
$api = new Zone($this->getAccountModel()->gentEntity($entity->getParentFieldData()));
|
||||
$entity = $api->sync($entity);
|
||||
return parent::sync_process($entity);
|
||||
}
|
||||
//Index관련
|
||||
@ -2,97 +2,17 @@
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use App\Models\Cloudflare\AuthModel;
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
use App\Models\Cloudflare\RecordModel;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CloudflareController extends \App\Controllers\Admin\AdminController
|
||||
{
|
||||
private $_authModel = null;
|
||||
private $_accountModel = null;
|
||||
private $_zoneModel = null;
|
||||
private $_recordModel = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = 'Cloudflare';
|
||||
$this->_viewPath = $this->_viewPath . '/cloudflare';
|
||||
}
|
||||
final protected function getAuthModel(): AuthModel
|
||||
{
|
||||
return is_null($this->_authModel) ? new AuthModel() : $this->_authModel;
|
||||
}
|
||||
final protected function getAccountModel(): AccountModel
|
||||
{
|
||||
return is_null($this->_accountModel) ? new AccountModel() : $this->_accountModel;
|
||||
}
|
||||
final protected function getZoneModel(): ZoneModel
|
||||
{
|
||||
return is_null($this->_zoneModel) ? new ZoneModel() : $this->_zoneModel;
|
||||
}
|
||||
final protected function getRecordModel(): RecordModel
|
||||
{
|
||||
return is_null($this->_recordModel) ? new RecordModel() : $this->_recordModel;
|
||||
}
|
||||
|
||||
//Zone입력
|
||||
final protected function insert_Zone(string $account_uid, string $domain): \App\Entities\Cloudflare\ZoneEntity
|
||||
{
|
||||
$fieldDatas = array('account_uid' => $account_uid, 'domain' => $domain);
|
||||
$api = new \App\Libraries\Cloudflare\API\Zone();
|
||||
$zone = $api->insert($fieldDatas);
|
||||
if (!$this->getZoneModel()->save($zone)) {
|
||||
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery());
|
||||
Log::add("error", implode("\n", $this->getZoneModel()->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getZoneModel()->errors(), true));
|
||||
}
|
||||
Log::add("info", "Zone: {$zone->getTitle()} 등록");
|
||||
return $zone;
|
||||
}
|
||||
//Record입력
|
||||
final protected function insert_Host(
|
||||
string $zone_uid,
|
||||
string $host,
|
||||
string $type,
|
||||
string $content,
|
||||
string $proxied
|
||||
): \App\Entities\Cloudflare\RecordEntity {
|
||||
$fieldDatas = array('zone_uid' => $zone_uid, 'host' => $host);
|
||||
$fieldDatas['type'] = $type;
|
||||
$fieldDatas['content'] = $content;
|
||||
$fieldDatas['proxied'] = $proxied;
|
||||
|
||||
$api = new \App\Libraries\Cloudflare\API\Record();
|
||||
$record = $api->insert($fieldDatas);
|
||||
$record->fixed = 'off'; //초기값
|
||||
if (!$this->getRecordModel()->save($record)) {
|
||||
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getRecordModel()->getLastQuery());
|
||||
Log::add("error", implode("\n", $this->getRecordModel()->errors()));
|
||||
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getRecordModel()->errors(), true));
|
||||
}
|
||||
Log::add("info", "Host: {$record->getTitle()} 등록");
|
||||
return $record;
|
||||
}
|
||||
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
final public function sync($uid)
|
||||
{
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$entity = $this->sync_process($entity);
|
||||
return alert_CommonHelper("{$this->_viewDatas['title']} " . __FUNCTION__ . " 완료하였습니다.", session()->get(RETURN_URL));
|
||||
} catch (\Exception $e) {
|
||||
return alert_CommonHelper($e->getMessage(), 'back');
|
||||
}
|
||||
$this->_className .= '/Cloudflare';
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] .= "Cloudflare";
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ class LoggerController extends \App\Controllers\Admin\AdminController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = 'Logger';
|
||||
$this->_className .= '/Logger';
|
||||
$this->_model = new LoggerModel();
|
||||
$this->_defines = [
|
||||
'view' => [
|
||||
@ -33,11 +33,9 @@ class LoggerController extends \App\Controllers\Admin\AdminController
|
||||
'fieldFilters' => ['user_uid', 'status'],
|
||||
],
|
||||
];
|
||||
helper('Logger');
|
||||
$this->_viewPath = $this->_viewPath . '/logger';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
|
||||
//모든 필요한 FormOption등 조기화작업 필요
|
||||
}
|
||||
|
||||
private function getUserModel(): UserModel
|
||||
|
||||
@ -12,7 +12,7 @@ class MapurlController extends \App\Controllers\Admin\AdminController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = 'Mapurl';
|
||||
$this->_className .= '/Mapurl';
|
||||
$this->_model = new MapurlModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
@ -48,8 +48,8 @@ class MapurlController extends \App\Controllers\Admin\AdminController
|
||||
'fieldFilters' => ['status'],
|
||||
],
|
||||
];
|
||||
helper('Mapurl');
|
||||
$this->_viewPath = $this->_viewPath . '/mapurl';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
|
||||
//모든 필요한 FormOption등 조기화작업 필요
|
||||
|
||||
@ -12,7 +12,7 @@ class UserController extends \App\Controllers\Admin\AdminController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->_className = 'User';
|
||||
$this->_className .= '/User';
|
||||
$this->_model = new UserModel();
|
||||
$this->_defines = [
|
||||
'insert' => [
|
||||
@ -53,8 +53,8 @@ class UserController extends \App\Controllers\Admin\AdminController
|
||||
'fieldFilters' => ['role', 'status'],
|
||||
],
|
||||
];
|
||||
helper('User');
|
||||
$this->_viewPath = $this->_viewPath . '/user';
|
||||
helper($this->_className);
|
||||
$this->_viewPath = strtolower($this->_className);
|
||||
$this->_viewDatas['title'] = lang($this->_className . '.title');
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\Cloudflare;
|
||||
namespace App\Controllers\CLI\Cloudflare\API;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Cloudflare\AuthModel;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
use App\Models\Cloudflare\RecordModel;
|
||||
use App\Models\Cloudflare\API\AuthModel;
|
||||
use App\Models\Cloudflare\API\AccountModel;
|
||||
use App\Models\Cloudflare\API\ZoneModel;
|
||||
use App\Models\Cloudflare\API\RecordModel;
|
||||
|
||||
class Cloudflare extends BaseController
|
||||
class API extends BaseController
|
||||
{
|
||||
private $_authModel = null;
|
||||
private $_accountModel = null;
|
||||
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\Cloudflare;
|
||||
namespace App\Controllers\CLI\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Entities\Cloudflare\API\AccountEntity;
|
||||
|
||||
class Account extends Cloudflare
|
||||
class Account extends API
|
||||
{
|
||||
private function getAccounts(int $auth_uid): array
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\Cloudflare;
|
||||
namespace App\Controllers\CLI\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\AuthEntity;
|
||||
use App\Entities\Cloudflare\API\AuthEntity;
|
||||
|
||||
class Auth extends Cloudflare
|
||||
class Auth extends API
|
||||
{
|
||||
final public function execute()
|
||||
{
|
||||
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\Cloudflare;
|
||||
namespace App\Controllers\CLI\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Entities\Cloudflare\API\ZoneEntity;
|
||||
use App\Libraries\Log\Log;
|
||||
|
||||
class Zone extends Cloudflare
|
||||
class Zone extends API
|
||||
{
|
||||
private function getZones(string $account_uid): array
|
||||
{
|
||||
@ -33,7 +33,7 @@ class Zone extends Cloudflare
|
||||
$api->reload((int)$page_limit);
|
||||
}
|
||||
//CDN값 수정 못하는 고정 Record 처리
|
||||
$fixedRecordModel = new \App\Models\Cloudflare\FixedRecordModel();
|
||||
$fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel();
|
||||
$this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host"));
|
||||
echo __METHOD__ . "에서 Record Reload 완료\n";
|
||||
//transation 완료
|
||||
@ -21,7 +21,7 @@ class CommonController extends BaseController
|
||||
helper('Common');
|
||||
$this->_viewDatas = [
|
||||
'layout' => LAYOUTS['empty'],
|
||||
'title' => '공통페이지',
|
||||
'title' => '',
|
||||
'session' => session()
|
||||
];
|
||||
if (is_null(session()->get('uid'))) {
|
||||
|
||||
15
app/Entities/Cloudflare/API/APIEntity.php
Normal file
15
app/Entities/Cloudflare/API/APIEntity.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
abstract class APIEntity extends CommonEntity
|
||||
{
|
||||
abstract public function getParentField(): string;
|
||||
final public function getParentFieldData()
|
||||
{
|
||||
$field = $this->getParentField();
|
||||
return $this->$field;
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
use App\Entities\Cloudflare\CloudflareEntity;
|
||||
class AccountEntity extends CloudflareEntity
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class AccountEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey(){
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(){
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->attributes['title'];
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return "uid:{$this->attributes['uid']}|auth_uid:{$this->attributes['auth_uid']}|{$this->attributes['title']} | {$this->attributes['type']} | {$this->attributes['status']}";
|
||||
}
|
||||
public function getParentField():string{
|
||||
public function getParentField(): string
|
||||
{
|
||||
return "auth_uid";
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
use App\Entities\CommonEntity;
|
||||
class AuthEntity extends CommonEntity
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class AuthEntity extends \App\Entities\CommonEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey(){
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(){
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->attributes['id'];
|
||||
}
|
||||
public function getAuthId(){
|
||||
public function getAuthId()
|
||||
{
|
||||
return $this->attributes['id'];
|
||||
}
|
||||
public function getAuthKey(){
|
||||
public function getAuthKey()
|
||||
{
|
||||
return $this->attributes['authkey'];
|
||||
}
|
||||
|
||||
@ -1,25 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
use App\Entities\Cloudflare\CloudflareEntity;
|
||||
class FirewallEntity extends CloudflareEntity
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class FirewallEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey(){
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(){
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->attributes['description'];
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return "uid:{$this->attributes['uid']}|zone_uid:{$this->attributes['zone_uid']}|host:{$this->attributes['description']}|content:{$this->attributes['action']}";
|
||||
}
|
||||
public function getParentField():string{
|
||||
public function getParentField(): string
|
||||
{
|
||||
return "zone_uid";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\CloudflareEntity;
|
||||
|
||||
class RecordEntity extends CloudflareEntity
|
||||
class RecordEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
@ -1,25 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\CloudflareEntity;
|
||||
class ZoneEntity extends CloudflareEntity
|
||||
class ZoneEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey(){
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(){
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->attributes['domain'];
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return "uid:{$this->attributes['uid']}|account_uid:{$this->attributes['account_uid']}|domain:{$this->attributes['domain']}|{$this->attributes['development_mode']}|{$this->attributes['ipv6']}|{$this->attributes['security_level']}";
|
||||
}
|
||||
public function getParentField():string{
|
||||
public function getParentField(): string
|
||||
{
|
||||
return "account_uid";
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
abstract class CloudflareEntity extends CommonEntity
|
||||
{
|
||||
abstract public function getParentField():string;
|
||||
final public function getParentFieldData(){
|
||||
$field = $this->getParentField();
|
||||
return $this->$field;
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@ abstract class API
|
||||
}
|
||||
abstract public function getClassName();
|
||||
abstract protected function setAdapter();
|
||||
abstract protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\CloudflareEntity;
|
||||
abstract protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\APIEntity;
|
||||
abstract protected function getCFResults_List(int $page): array;
|
||||
final protected static function getRequestCount()
|
||||
{
|
||||
@ -32,9 +32,10 @@ abstract class API
|
||||
Log::add('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", CF_REQUEST_WAITTIME));
|
||||
}
|
||||
self::$_requestCount++;
|
||||
if ($this->_adapter instanceof \Cloudflare\API\Adapter\Guzzle) {
|
||||
if (is_null($this->_adapter)) {
|
||||
throw new \Exception("해당 Adapter가 없습니다.");
|
||||
}
|
||||
// throw new \Exception(var_export($this->_adapter, true));
|
||||
return $this->_adapter;
|
||||
}
|
||||
final public function getParent()
|
||||
|
||||
@ -2,16 +2,14 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
|
||||
class Account extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
private $_entity = null;
|
||||
public function __construct(\App\Entities\Cloudflare\AuthEntity $parent)
|
||||
public function __construct(\App\Entities\Cloudflare\API\AuthEntity $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
$this->_model = new \App\Models\Cloudflare\AccountModel();
|
||||
$this->_model = new \App\Models\Cloudflare\API\AccountModel();
|
||||
}
|
||||
protected function setAdapter()
|
||||
{
|
||||
@ -23,12 +21,13 @@ class Account extends API
|
||||
$this->getParent()->getAuthKey()
|
||||
);
|
||||
$this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey);
|
||||
// throw new \Exception(var_export($this->_adapter, true));
|
||||
}
|
||||
public function getClassName()
|
||||
{
|
||||
return 'Account';
|
||||
}
|
||||
protected function getEntityByResult(\stdClass $cfResult): AccountEntity
|
||||
protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\AccountEntity
|
||||
{
|
||||
// dd($cfResult);exit;
|
||||
// [
|
||||
@ -44,7 +43,7 @@ class Account extends API
|
||||
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
||||
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
||||
// ]
|
||||
$entity = is_null($this->_entity) ? new AccountEntity() : $this->_entity;
|
||||
$entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\AccountEntity() : $this->_entity;
|
||||
$entity->uid = $cfResult->id;
|
||||
$entity->auth_uid = $this->getParent()->getPrimaryKey();
|
||||
$entity->title = $cfResult->name;
|
||||
@ -55,7 +54,7 @@ class Account extends API
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function insert(array $fieldDatas): AccountEntity
|
||||
public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\AccountEntity
|
||||
{
|
||||
$options = [
|
||||
'name' => $fieldDatas['name'],
|
||||
|
||||
@ -2,36 +2,35 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\FirewallEntity;
|
||||
|
||||
class Firewall extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
private $_entity = null;
|
||||
public function __construct(\App\Entities\Cloudflare\ZoneEntity $parent)
|
||||
public function __construct(\App\Entities\Cloudflare\API\ZoneEntity $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
$this->_model = new \App\Models\Cloudflare\FirewallModel();
|
||||
$this->_model = new \App\Models\Cloudflare\API\FirewallModel();
|
||||
}
|
||||
final protected function setAdapter()
|
||||
{
|
||||
if (!is_null($this->_adapter)) {
|
||||
throw new \Exception("Adapter가 이미 지정되었습니다.");
|
||||
}
|
||||
$accountModel = new \App\Models\Cloudflare\AccountModel();
|
||||
$accountModel = new \App\Models\Cloudflare\API\AccountModel();
|
||||
$account = $accountModel->getEntity($this->getParent()->getParentFieldData());
|
||||
$authModel = new \App\Models\Cloudflare\AuthModel();
|
||||
$authModel = new \App\Models\Cloudflare\API\AuthModel();
|
||||
$auth = $authModel->getEntity($account->getParentFieldData());
|
||||
$apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey());
|
||||
$this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey);
|
||||
// throw new \Exception(var_export($this->_adapter, true));
|
||||
}
|
||||
public function getClassName()
|
||||
{
|
||||
return 'Firewall';
|
||||
}
|
||||
protected function getEntityByResult(\stdClass $cfResult): FirewallEntity
|
||||
protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\FirewallEntity
|
||||
{
|
||||
$entity = is_null($this->_entity) ? new FirewallEntity() : $this->_entity;
|
||||
$entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\FirewallEntity() : $this->_entity;
|
||||
$entity->uid = $cfResult->id;
|
||||
$entity->zone_uid = $this->getParent()->getPrimaryKey();
|
||||
$entity->description = $cfResult->description;
|
||||
@ -47,7 +46,7 @@ class Firewall extends API
|
||||
}
|
||||
|
||||
// public function insert(){ }
|
||||
public function update(FirewallEntity $entity, array $fieldDatas): FirewallEntity
|
||||
public function update(\App\Entities\Cloudflare\API\FirewallEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\FirewallEntity
|
||||
{
|
||||
$rule = array_merge(
|
||||
[
|
||||
@ -75,7 +74,7 @@ class Firewall extends API
|
||||
return $this->getEntityByResult($cfResult->result);
|
||||
}
|
||||
// public function delete(){ }
|
||||
public function sync(FirewallEntity $entity): FirewallEntity
|
||||
public function sync(\App\Entities\Cloudflare\API\FirewallEntity $entity): \App\Entities\Cloudflare\API\FirewallEntity
|
||||
{
|
||||
$cfResult = $this->getAdapter()->get('zones/' . $this->getParent()->getPrimaryKey() . '/firewall/rules/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
|
||||
@ -2,38 +2,36 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\RecordEntity;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
|
||||
class Record extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
private $_entity = null;
|
||||
public function __construct(\App\Entities\Cloudflare\ZoneEntity $parent)
|
||||
public function __construct(\App\Entities\Cloudflare\API\ZoneEntity $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
$this->_model = new \App\Models\Cloudflare\RecordModel();
|
||||
$this->_model = new \App\Models\Cloudflare\API\RecordModel();
|
||||
}
|
||||
final protected function setAdapter()
|
||||
{
|
||||
if (!is_null($this->_adapter)) {
|
||||
throw new \Exception("Adapter가 이미 지정되었습니다.");
|
||||
}
|
||||
$accountModel = new \App\Models\Cloudflare\AccountModel();
|
||||
$accountModel = new \App\Models\Cloudflare\API\AccountModel();
|
||||
$account = $accountModel->getEntity($this->getParent()->getParentFieldData());
|
||||
$authModel = new \App\Models\Cloudflare\AuthModel();
|
||||
$authModel = new \App\Models\Cloudflare\API\AuthModel();
|
||||
$auth = $authModel->getEntity($account->getParentFieldData());
|
||||
$apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey());
|
||||
$this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey);
|
||||
// throw new \Exception(var_export($this->_adapter, true));
|
||||
}
|
||||
public function getClassName()
|
||||
{
|
||||
return 'Record';
|
||||
}
|
||||
protected function getEntityByResult(\stdClass $cfResult): RecordEntity
|
||||
protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
// throw new \Exception(var_export($cfResult, true));
|
||||
$entity = is_null($this->_entity) ? new RecordEntity() : $this->_entity;
|
||||
$entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\RecordEntity() : $this->_entity;
|
||||
// throw new \Exception(var_export($cfResult, true));
|
||||
$entity->uid = $cfResult->id;
|
||||
$entity->zone_uid = $cfResult->zone_id;
|
||||
@ -50,7 +48,7 @@ class Record extends API
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function insert(array $fieldDatas): RecordEntity
|
||||
public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
||||
$options = [
|
||||
@ -67,7 +65,7 @@ class Record extends API
|
||||
}
|
||||
return $this->getEntityByResult($cfResult->result);
|
||||
}
|
||||
public function update(RecordEntity $entity, array $fieldDatas): RecordEntity
|
||||
public function update(\App\Entities\Cloudflare\API\RecordEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
||||
$options = [
|
||||
@ -87,15 +85,11 @@ class Record extends API
|
||||
}
|
||||
return $this->getEntityByResult($cfResult->result);
|
||||
}
|
||||
|
||||
public function deleteByZone(ZoneEntity $zone)
|
||||
public function deleteByZone()
|
||||
{
|
||||
$entitys = $this->_model->asObject(RecordEntity::class)->where($this->_model::PARENT_FIELD, $zone->getPrimaryKey())->findAll();
|
||||
foreach ($entitys as $entity) {
|
||||
$this->delete($entity);
|
||||
$this->_model->where($this->_model::PARENT_FIELD, $this->getParent()->getPrimaryKey())->delete();
|
||||
}
|
||||
}
|
||||
public function delete(RecordEntity $entity)
|
||||
public function delete(\App\Entities\Cloudflare\API\RecordEntity $entity)
|
||||
{
|
||||
$cfResult = $this->getAdapter()->delete('zones/' . $this->getParent()->getPrimaryKey() . '/dns_records/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
@ -103,7 +97,7 @@ class Record extends API
|
||||
throw new \Exception(var_export($cfResult, true));
|
||||
}
|
||||
}
|
||||
public function sync(RecordEntity $entity): RecordEntity
|
||||
public function sync(\App\Entities\Cloudflare\API\RecordEntity $entity): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
$cfResult = $this->getAdapter()->get('zones/' . $this->getParent()->getPrimaryKey() . '/dns_records/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
|
||||
@ -2,28 +2,27 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
|
||||
class Zone extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
private $_entity = null;
|
||||
private $_isGetSetting = true;
|
||||
public function __construct(\App\Entities\Cloudflare\AccountEntity $parent, bool $isGetSetting = true)
|
||||
public function __construct(\App\Entities\Cloudflare\API\AccountEntity $parent, bool $isGetSetting = true)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
$this->_isGetSetting = $isGetSetting;
|
||||
$this->_model = new \App\Models\Cloudflare\ZoneModel();
|
||||
$this->_model = new \App\Models\Cloudflare\API\ZoneModel();
|
||||
}
|
||||
final protected function setAdapter()
|
||||
{
|
||||
if (!is_null($this->_adapter)) {
|
||||
throw new \Exception("Adapter가 이미 지정되었습니다.");
|
||||
}
|
||||
$authModel = new \App\Models\Cloudflare\AuthModel();
|
||||
$authModel = new \App\Models\Cloudflare\API\AuthModel();
|
||||
$auth = $authModel->getEntity($this->getParent()->getParentFieldData());
|
||||
$apikey = new \Cloudflare\API\Auth\APIKey($auth->getAuthId(), $auth->getAuthKey());
|
||||
$this->_adapter = new \Cloudflare\API\Adapter\Guzzle($apikey);
|
||||
// throw new \Exception(var_export($this->_adapter, true));
|
||||
}
|
||||
public function getClassName()
|
||||
{
|
||||
@ -31,9 +30,9 @@ class Zone extends API
|
||||
}
|
||||
|
||||
//Cfzone에서 가져온 값을 zone에 setting
|
||||
protected function getEntityByResult(\stdClass $cfResult): ZoneEntity
|
||||
protected function getEntityByResult(\stdClass $cfResult): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
$entity = is_null($this->_entity) ? new ZoneEntity() : $this->_entity;
|
||||
$entity = is_null($this->_entity) ? new \App\Entities\Cloudflare\API\ZoneEntity() : $this->_entity;
|
||||
$entity->uid = $cfResult->id;
|
||||
$entity->account_uid = $cfResult->account->id;
|
||||
$entity->domain = $cfResult->name;
|
||||
@ -56,7 +55,7 @@ class Zone extends API
|
||||
}
|
||||
|
||||
//Cfzone에서 가져온 값을 zone에 setting
|
||||
final public function getCFSetting(ZoneEntity $entity): ZoneEntity
|
||||
final public function getCFSetting(\App\Entities\Cloudflare\API\ZoneEntity $entity): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
$cfResult = $this->getAdapter()->get('zones/' . $entity->getPrimaryKey() . '/settings/');
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
@ -79,7 +78,7 @@ class Zone extends API
|
||||
return $entity;
|
||||
}
|
||||
//Cfzone에 해당 키값 변경용
|
||||
final public function setCFSetting(ZoneEntity $entity, string $field, string $value): ZoneEntity
|
||||
final public function setCFSetting(\App\Entities\Cloudflare\API\ZoneEntity $entity, string $field, string $value): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
$cfResult = $this->getAdapter()->patch('zones/' . $entity->getPrimaryKey() . '/settings/' . $field, array('value' => $value));
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
@ -91,7 +90,7 @@ class Zone extends API
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function insert(array $fieldDatas): ZoneEntity
|
||||
public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
//도메인생성을 위해 Cloudflare에 전송
|
||||
$options = [
|
||||
@ -111,7 +110,7 @@ class Zone extends API
|
||||
$entity = $this->setCFSetting($entity, 'security_level', 'medium');
|
||||
return $entity;
|
||||
}
|
||||
public function update(ZoneEntity $entity, array $fieldDatas): ZoneEntity
|
||||
public function update(\App\Entities\Cloudflare\API\ZoneEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
//ipv6 , //development_mode , //security_level
|
||||
foreach ($fieldDatas as $field => $value) {
|
||||
@ -119,12 +118,11 @@ class Zone extends API
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
public function delete(ZoneEntity $entity)
|
||||
public function delete(\App\Entities\Cloudflare\API\ZoneEntity $entity)
|
||||
{
|
||||
//Zone에 해당하는 Record 삭제를 먼저한다.
|
||||
$api = new \App\Libraries\Cloudflare\API\Record($entity);
|
||||
$api->deleteByZone($entity);
|
||||
|
||||
$api->deleteByZone();
|
||||
//Zone 삭제
|
||||
$cfResult = $this->getAdapter()->delete('zones/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
@ -132,7 +130,7 @@ class Zone extends API
|
||||
throw new \Exception(var_export($cfResult, true));
|
||||
}
|
||||
}
|
||||
public function sync(ZoneEntity $entity): ZoneEntity
|
||||
public function sync(\App\Entities\Cloudflare\API\ZoneEntity $entity): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
$cfResult = $this->getAdapter()->get('zones/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Entities\Cloudflare\API\AccountEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class AccountModel extends Model
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\AuthEntity;
|
||||
use App\Entities\Cloudflare\API\AuthEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class AuthModel extends Model
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\FirewallEntity;
|
||||
use App\Entities\Cloudflare\API\FirewallEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class FirewallModel extends Model
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\RecordEntity;
|
||||
use App\Entities\Cloudflare\API\RecordEntity;
|
||||
use App\Libraries\Log\Log;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Entities\Cloudflare\API\ZoneEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ZoneModel extends Model
|
||||
Loading…
Reference in New Issue
Block a user