cfmgrv4 change validation

This commit is contained in:
최준흠 2025-02-14 14:12:20 +09:00
parent d5980adb1c
commit 5b19a6dbde
7 changed files with 144 additions and 131 deletions

View File

@ -21,36 +21,26 @@ $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes)
$routes->cli('expire/(:any)', 'Cloudflare::expire/$1');
});
});
$routes->get('/', 'Home::index');
$routes->group('/RSSFeed', function ($routes) {
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
$routes->get('/', 'Home::index');
$routes->group('utils', ['namespace' => 'App\Controllers\Utils'], function ($routes) {
$routes->group('RSSFeed', function ($routes) {
$routes->get('getITWorld', 'RSSFeedController::getITWorld');
});
$routes->group('/Webhook', function ($routes) {
$routes->post('Cloudflare', 'WebhookController::cloudflare');
});
$routes->group('/user', function ($routes) {
});
$routes->group('Webhook', function ($routes) {
$routes->post('cloudflare', 'WebhookController::cloudflare');
});
});
$routes->group('user', function ($routes) {
$routes->get('login', 'UserController::login_form');
$routes->post('login', 'UserController::login');
$routes->get('google_login', 'UserController::google_login');
$routes->get('logout', 'UserController::logout');
});
});
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
$routes->get('/', 'Home::index');
});
$routes->group('admin/mapurl', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
$routes->get('/', 'MapurlController::index');
$routes->get('create', 'MapurlController::create_form');
$routes->post('create', 'MapurlController::create');
$routes->get('modify/(:num)', 'MapurlController::modify_form/$1');
$routes->post('modify/(:num)', 'MapurlController::modify/$1');
$routes->get('view/(:num)', 'MapurlController::view/$1');
$routes->get('delete/(:num)', 'MapurlController::delete/$1');
$routes->get('toggle/(:num)/(:any)', 'MapurlController::toggle/$1/$2');
$routes->post('batchjob', 'MapurlController::batchjob');
$routes->post('batchjob_delete', 'MapurlController::batchjob_delete');
$routes->get('download/(:alpha)', 'MapurlController::download/$1');
});
$routes->group('admin/user', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master'], function ($routes) {
$routes->group('user', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master'], function ($routes) {
$routes->get('/', 'UserController::index', []);
$routes->get('create', 'UserController::create_form');
$routes->post('create', 'UserController::create');
@ -62,17 +52,30 @@ $routes->group('admin/user', ['namespace' => 'App\Controllers\Admin', 'filter' =
$routes->post('batchjob', 'UserController::batchjob');
$routes->post('batchjob_delete', 'UserController::batchjob_delete');
$routes->get('download/(:alpha)', 'UserController::download/$1');
});
$routes->group('admin/usersns', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master'], function ($routes) {
});
$routes->group('usersns', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master'], function ($routes) {
$routes->get('/', 'UserSNSController::index');
$routes->get('delete/(:num)', 'UserSNSController::delete/$1');
$routes->get('toggle/(:num)/(:any)', 'UserSNSController::toggle/$1/$2');
$routes->post('batchjob', 'UserSNSController::batchjob');
$routes->post('batchjob_delete', 'UserSNSController::batchjob_delete');
$routes->get('download/(:alpha)', 'UserSNSController::download/$1');
});
$routes->group('admin/cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
});
$routes->group('mapurl', ['namespace' => 'App\Controllers\Admin'], function ($routes) {
$routes->get('/', 'MapurlController::index');
$routes->get('create', 'MapurlController::create_form');
$routes->post('create', 'MapurlController::create');
$routes->get('modify/(:num)', 'MapurlController::modify_form/$1');
$routes->post('modify/(:num)', 'MapurlController::modify/$1');
$routes->get('view/(:num)', 'MapurlController::view/$1');
$routes->get('delete/(:num)', 'MapurlController::delete/$1');
$routes->get('toggle/(:num)/(:any)', 'MapurlController::toggle/$1/$2');
$routes->post('batchjob', 'MapurlController::batchjob');
$routes->post('batchjob_delete', 'MapurlController::batchjob_delete');
$routes->get('download/(:alpha)', 'MapurlController::download/$1');
});
$routes->group('cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
$routes->group('auth', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) {
$routes->get('/', 'AuthController::index');
$routes->get('create', 'AuthController::create_form');
$routes->post('create', 'AuthController::create');
@ -84,20 +87,20 @@ $routes->group('admin/cloudflare/auth', ['namespace' => 'App\Controllers\Admin\C
$routes->post('batchjob', 'AuthController::batchjob');
$routes->post('batchjob_delete', 'AuthController::batchjob_delete');
$routes->get('download/(:alpha)', 'AccountController::download/$1');
});
$routes->group('admin/cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
});
$routes->group('account', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) {
$routes->get('/', 'AccountController::index');
$routes->get('view/(:alphanum)', 'AccountController::view/$1');
$routes->get('reload/(:num)', 'AccountController::reload/$1');
$routes->get('download/(:alphanum)', 'AccountController::download/$1');
});
$routes->group('admin/cloudflare/auditlog', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
});
$routes->group('auditlog', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) {
$routes->get('/', 'AuditLogController::index');
$routes->get('view/(:any)', 'AuditLogController::view/$1');
$routes->get('reload/(:alphanum)', 'AuditLogController::reload/$1');
$routes->get('download/(:alphanum)', 'AuditLogController::download/$1');
});
$routes->group('admin/cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
});
$routes->group('zone', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) {
$routes->get('/', 'ZoneController::index');
$routes->get('create', 'ZoneController::create_form');
$routes->post('create', 'ZoneController::create');
@ -109,8 +112,8 @@ $routes->group('admin/cloudflare/zone', ['namespace' => 'App\Controllers\Admin\C
$routes->post('batchjob_delete', 'ZoneController::batchjob_delete');
$routes->get('reload/(:alphanum)', 'ZoneController::reload/$1');
$routes->get('download/(:alpha)', 'ZoneController::download/$1');
});
$routes->group('admin/cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
});
$routes->group('record', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) {
$routes->get('/', 'RecordController::index');
$routes->get('create', 'RecordController::create_form');
$routes->post('create', 'RecordController::create');
@ -122,11 +125,13 @@ $routes->group('admin/cloudflare/record', ['namespace' => 'App\Controllers\Admin
$routes->post('batchjob_delete', 'RecordController::batchjob_delete');
$routes->get('reload/(:alphanum)', 'RecordController::reload/$1');
$routes->get('download/(:alpha)', 'RecordController::download/$1');
});
$routes->group('admin/cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:firewall'], function ($routes) {
});
$routes->group('firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:firewall'], function ($routes) {
$routes->get('/', 'FirewallController::index');
$routes->get('view/(:alphanum)', 'FirewallController::view/$1');
$routes->get('toggle/(:alphanum)/(:any)', 'FirewallController::toggle/$1/$2');
$routes->get('reload/(:alphanum)', 'FirewallController::reload/$1');
$routes->get('download/(:alpha)', 'FirewallController::download/$1');
});
});
});

View File

@ -35,18 +35,17 @@ class UserController extends AdminController
}
return $this->service;
}
protected function setValidation(string $action, string $field, Validation $validation): Validation
protected function setValidation(string $action, string $field): void
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $this->getModel()->getFieldRule($action, $field));
$this->_validation->setRule("{$field}.*", $field, $this->getModel()->getFieldRule($action, $field));
break;
default:
$validation = parent::setValidation($field, $action, $validation);
parent::setValidation($action, $field);
break;
}
return $validation;
}
private function init(string $action, array $fields = []): void
{

View File

@ -14,6 +14,7 @@ use Psr\Log\LoggerInterface;
abstract class MVController extends CommonController
{
protected $_validation = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@ -22,22 +23,20 @@ abstract class MVController extends CommonController
abstract protected function getModel(): mixed;
abstract protected function getService(): mixed;
//Field별 Form Rule용
protected function setValidation(string $action, string $field, Validation $validation): Validation
protected function setValidation(string $action, string $field): void
{
switch ($field) {
default:
$validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field));
$this->_validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field));
break;
}
return $validation;
}
final protected function getValidation(string $action, array $fields): Validation
final protected function setValidations(string $action, array $fields): void
{
$validation = service('validation');
$this->_validation = service('validation');
foreach ($fields as $field) {
$validation = $this->setValidation($action, $field, $validation);
$this->setValidation($action, $field);
}
return $validation;
}
//Field별 Form Option용
protected function getFormFieldOption(string $field, array $options): array
@ -81,14 +80,14 @@ abstract class MVController extends CommonController
protected function create_validate(string $action, array $fields): array
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
$validation = $this->getValidation($action, $fields);
if (!$validation->withRequest($this->request)->run()) {
$this->setValidations($action, $fields);
if (!$this->_validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n",
$validation->getErrors()
$this->_validation->getErrors()
));
}
return $validation->getValidated();
return $this->_validation->getValidated();
}
protected function create_process(): void
{
@ -144,14 +143,15 @@ abstract class MVController extends CommonController
final protected function modify_validate(string $action, array $fields): array
{
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$validation = $this->getValidation($action, $fields);
if (!$validation->withRequest($this->request)->run()) {
$this->setValidations($action, $fields);
if (!$this->_validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n",
$validation->getErrors()
$this->_validation->getErrors()
));
}
return $validation->getValidated();
// dd((array)$this->_validation);
return $this->_validation->getValidated();
}
//modify,toggle,batchjob 공통사용
protected function modify_process(mixed $uid): void

View File

@ -1,8 +1,8 @@
<?php
namespace App\Controllers;
namespace App\Controllers\Utils;
use CodeIgniter\Controller;
use App\Controllers\CommonController;
class RSSFeedController extends CommonController
{

View File

@ -1,8 +1,8 @@
<?php
namespace App\Controllers;
namespace App\Controllers\Utils;
use CodeIgniter\Controller;
use App\Controllers\CommonController;
class WebhookController extends CommonController
{
@ -25,13 +25,19 @@ class WebhookController extends CommonController
];
// 파일 경로 설정
$filePath = WRITEPATH . 'webhook.txt';
$filePath = WRITEPATH . DIRECTORY_SEPARATOR . "webhook";
//디렉토리 생성 여부 확인
if (!is_dir($filePath)) {
mkdir($filePath, 0755, true);
}
$fullpath = $filePath . DIRECTORY_SEPARATOR . date('Y-m-d') . '.log';
// 데이터를 JSON 형식으로 변환하고 새 줄 문자 추가
$logEntry = json_encode($logData, JSON_PRETTY_PRINT) . "\n---\n";
// 파일에 데이터 추가
if (file_put_contents($filePath, $logEntry, FILE_APPEND) === false) {
if (file_put_contents($fullpath, $logEntry, FILE_APPEND) === false) {
return $this->response->setStatusCode(500)->setJSON([
'status' => 'error',
'message' => 'Failed to write to file'

View File

@ -28,6 +28,7 @@ class UserService extends CommonService
}
public function modify(UserEntity $entity, array $formDatas): UserEntity
{
// die(var_export($formDatas, true));
//암호를 입력하지 않았을시는 변경하기 않게 하기위함
if (isset($formDatas['passwd']) && $formDatas['passwd'] == "") {
unset($formDatas['passwd']);
@ -37,6 +38,7 @@ class UserService extends CommonService
if (isset($formDatas['role'])) {
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
}
// die(var_export($formDatas, true));
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void

View File

@ -19,7 +19,8 @@
"phpoffice/phpspreadsheet": "^1.27",
"symfony/css-selector": "^7.1",
"symfony/dom-crawler": "^7.1",
"tinymce/tinymce": "^7.3"
"tinymce/tinymce": "^7.3",
"twbs/bootstrap": "5.3.3"
},
"require-dev": {
"fakerphp/faker": "^1.9",