Automation init...3
This commit is contained in:
parent
21b8633a3a
commit
7501b95498
@ -30,14 +30,14 @@ $routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], functi
|
||||
$routes->cli('check_level', 'UserController::check_level');
|
||||
$routes->cli('check_level/(:alpha)', 'UserController::check_level/$1');
|
||||
});
|
||||
$routes->group('crawler', function ($routes) {
|
||||
$routes->cli('yamap/(:any)', 'CrawlerController::yamap/$1');
|
||||
$routes->cli('yamap/(:any)/(:any)', 'CrawlerController::yamap/$1/$2');
|
||||
$routes->cli('yamoon/(:any)', 'CrawlerController::yamoon/$1');
|
||||
$routes->cli('yamoon/(:any)/(:any)', 'CrawlerController::yamoon/$1/$2');
|
||||
$routes->cli('sir/(:any)', 'CrawlerController::sir/$1');
|
||||
$routes->cli('sir/(:any)/(:any)', 'CrawlerController::sir/$1/$2');
|
||||
$routes->cli('inven/(:any)', 'CrawlerController::inven/$1');
|
||||
$routes->cli('inven/(:any)/(:any)', 'CrawlerController::inven/$1/$2');
|
||||
$routes->group('crawler', ['namespace' => 'App\Controllers\Mangboard\Crawler'], function ($routes) {
|
||||
$routes->cli('yamap/(:any)', 'YamapCrawler::execute/$1');
|
||||
$routes->cli('yamap/(:any)/(:any)', 'YamapCrawler::execute/$1/$2');
|
||||
$routes->cli('yamoon/(:any)', 'YamoonCrawler::execute/$1');
|
||||
$routes->cli('yamoon/(:any)/(:any)', 'YamoonCrawler::execute/$1/$2');
|
||||
$routes->cli('sir/(:any)', 'SirCrawler::execute/$1');
|
||||
$routes->cli('sir/(:any)/(:any)', 'SirCrawler::execute/$1/$2');
|
||||
$routes->cli('inven/(:any)', 'InvenCrawler::execute/$1');
|
||||
$routes->cli('inven/(:any)/(:any)', 'InvenCrawler::execute/$1/$2');
|
||||
});
|
||||
});
|
||||
|
||||
58
app/Controllers/AuthController.php
Normal file
58
app/Controllers/AuthController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Entities\UserEntity;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class AuthController extends CommonController
|
||||
{
|
||||
public function login()
|
||||
{
|
||||
helper(['form']);
|
||||
$viewDatas = [
|
||||
'layout' => LAYOUTS['empty'],
|
||||
'title' => '로그인',
|
||||
'forms' => [
|
||||
'attributes' => ['action' => 'post', 'class' => 'row g-3'],
|
||||
'hiddens' => [RETURN_URL => session()->get(RETURN_URL)],
|
||||
]
|
||||
];
|
||||
return view('auth/login', $viewDatas);
|
||||
}
|
||||
|
||||
public function signin()
|
||||
{
|
||||
$id = $this->request->getVar('id');
|
||||
$passwd = $this->request->getVar('passwd');
|
||||
$model = new UserModel();
|
||||
$user = $model->asObject(UserEntity::class)->where('id', $id)->first();
|
||||
if (is_null($user) || !isset($user->passwd)) {
|
||||
session()->setFlashdata('error', "사용자ID: {$id}가 존재하지 않습니다.");
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
if (password_verify($passwd, $user->passwd)) {
|
||||
//Session에 Login 정보전달
|
||||
$authData = [
|
||||
'uid' => $user->uid,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'role' => $user->role,
|
||||
ISLOGIN => true
|
||||
];
|
||||
session()->set($authData);
|
||||
return redirect()->to($this->request->getVar(RETURN_URL) ? $this->request->getVar(RETURN_URL) : "/");
|
||||
} else {
|
||||
session()->setFlashdata('error', '암호가 맞지 않습니다.');
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
//Session에 Login 정보 삭제
|
||||
session()->set([ISLOGIN => false]);
|
||||
session_destroy();
|
||||
return redirect()->route('/');
|
||||
}
|
||||
}
|
||||
67
app/Controllers/Cloudflare/AccountController.php
Normal file
67
app/Controllers/Cloudflare/AccountController.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use App\Libraries\MySocket\Cloudflare\AccountSocket;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
|
||||
use App\Traits\AuthTrait;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AccountController extends CommonController
|
||||
{
|
||||
use AuthTrait;
|
||||
private $_mySocket = null;
|
||||
private $_model = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->session = $this->loginCheck_AuthTrait();
|
||||
}
|
||||
final public function getMySocket(string $email, $api_key): AccountSocket
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new AccountSocket($email, $api_key);
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
final public function getModel(): AccountModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
$this->_model = new AccountModel();
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
public function create(string $email, $api_key, array $formDatas = [])
|
||||
{
|
||||
//전송
|
||||
$result = $this->getMySocket($email, $api_key)->create($email);
|
||||
//답변형태
|
||||
// [
|
||||
// {"id":"078e88a7735965b661715af13031ecb0",
|
||||
// "name":"Cloudwin002@idcjp.jp's Account",
|
||||
// "type":"standard",
|
||||
// "settings":{
|
||||
// "enforce_twofactor":false,
|
||||
// "api_access_enabled":null,
|
||||
// "access_approval_expiry":null,
|
||||
// "use_account_custom_ns_by_default":false
|
||||
// },
|
||||
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
||||
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
||||
// ]
|
||||
$formDatas[$this->getModel()->getTitleField()] = $email;
|
||||
$formDatas['key'] = $api_key;
|
||||
$formDatas[$this->getModel()->PK()] = $result->id;
|
||||
$formDatas[$this->getModel()->getTitleField()] = $result->name;
|
||||
$formDatas['type'] = $result->type;
|
||||
$formDatas['status'] = 'use';
|
||||
$formDatas['updated_at'] = $result->created_on;
|
||||
$formDatas['created_at'] = $result->created_on;
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
log_message("notice", __FUNCTION__ . "=> {$entity->getTitle()} 생성을 완료하였습니다.");
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,6 @@ use App\Controllers\BaseController;
|
||||
abstract class CommonController extends BaseController
|
||||
{
|
||||
private $_options = [];
|
||||
|
||||
final public function __get($name)
|
||||
{
|
||||
if (!array_key_exists($name, $this->_options)) {
|
||||
@ -20,4 +19,65 @@ abstract class CommonController extends BaseController
|
||||
{
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
|
||||
//전송된 값 검증 및 임시저장
|
||||
final public function getFormFieldDatas(array $fields, array $fieldRules, array $formDatas = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$formDatas[$field] = rtrim($this->request->getVar($field));
|
||||
log_message("debug", "{$field} : {$formDatas[$field]}");
|
||||
}
|
||||
//변경할 값 확인
|
||||
if (!$this->validate($fieldRules)) {
|
||||
throw new \Exception("데이터 검증 오류발생\n" . implode("\n", $this->validator->getErrors()));
|
||||
}
|
||||
return $formDatas;
|
||||
}
|
||||
//Field별 Form Option용
|
||||
protected function getFormFieldOption(string $field, array $options): array
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
$temps = lang($this->_className . '.' . strtoupper($field));
|
||||
if (!is_array($temps)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 {$field}의 데이터가 array가 아닙니다.\n" . var_export($temps, true));
|
||||
}
|
||||
$options[$field] = [
|
||||
["" => lang($this->_className . '.label.' . $field) . ' 선택'],
|
||||
lang($this->_className . '.' . strtoupper($field))
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
//Field별 Form Option용
|
||||
final public function getFormFieldOptions(array $fields, array $options = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
if (is_array($field)) {
|
||||
throw new \Exception(__FUNCTION__ . "에서 field가 array 입니다.\n" . var_export($field, true));
|
||||
}
|
||||
$options = $this->getFormFieldOption($field, $options);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
protected function getFormFieldRule(string $field, array $rules): array
|
||||
{
|
||||
if (is_array($field)) {
|
||||
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
|
||||
}
|
||||
switch ($field) {
|
||||
default:
|
||||
$rules[$field] = $this->_model->getFieldRule($field, $rules);;
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
final public function getFormFieldRules(array $fields, array $rules = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$rules = $this->getFormFieldRule($field, $rules);
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
175
app/Controllers/Mangboard/Crawler/InvenCrawler.php
Normal file
175
app/Controllers/Mangboard/Crawler/InvenCrawler.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard\Crawler;
|
||||
|
||||
use App\Controllers\Mangboard\CrawlerController;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class InvenCrawler extends CrawlerController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
final protected function getHost(): string
|
||||
{
|
||||
return getenv("inven.host.url");
|
||||
}
|
||||
protected function getUrlByMediaType(Crawler $node, string $media_type, string $attr): null|string
|
||||
{
|
||||
switch ($media_type) {
|
||||
case 'video':
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
//그래도 null이면 data-src로 추출해본다.
|
||||
$attributes = $node->extract(['data-src']);
|
||||
if (count($attributes)) {
|
||||
$url = $attributes[0];
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
default:
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
break;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
//작성내용
|
||||
// <div class="articleContent">
|
||||
// <div id="imageCollectDiv" class="contentBody">
|
||||
// <!-- ============== CONTENT ============== -->
|
||||
// <div id="powerbbsContent">
|
||||
// <div id="BBSImageHolderTop" style="text-align:center;">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1620925350.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1587803007.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1134295360.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1481352611.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1878651605.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 850 / 1063;" loading="lazy" />
|
||||
// <br><br>
|
||||
// </div>
|
||||
// <div>^^</div>
|
||||
// </div>
|
||||
// <!-- ============== End CONTENT ============== -->
|
||||
// </div>
|
||||
protected function detail_content_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
$selector = $this->getSelector($response, getenv("inven.view.content.tag"));
|
||||
$formDatas = [];
|
||||
$formDatas['image_path'] = "";
|
||||
$formDatas['content'] = $selector->html();
|
||||
//File DB 및 Board DB 등록작업등
|
||||
$this->getBoardModel()->createByCrawler(
|
||||
$this->getBoardsEntity(),
|
||||
$this->getUserEntity(),
|
||||
$cnt,
|
||||
$listInfo,
|
||||
[],
|
||||
$formDatas
|
||||
);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
protected function detail_download_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
$selector = $this->getSelector($response, getenv("inven.view.content.tag"));
|
||||
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "img", "src");
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "video", "src", $media_urls);
|
||||
if ($this->isDebug) {
|
||||
throw new \Exception(sprintf(
|
||||
"\n--------------%s Debug--------------\n%s%s\n---------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
var_export($listInfo, true),
|
||||
var_export($media_urls, true)
|
||||
));
|
||||
} else {
|
||||
// Image 나 Video 소스들의 url을 가져와서 실제 다운받는 처리
|
||||
$storages = $this->media_process($media_urls);
|
||||
if (!count($storages)) {
|
||||
throw new \Exception("등록할 자료가 없습니다.");
|
||||
}
|
||||
$this->backend_process($cnt, $listInfo, $storages);
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
//리스트내용
|
||||
// <div class="board-list">
|
||||
// <table>
|
||||
// <tr class="lgtm">
|
||||
// <td class="num"><span>1589</span></td>
|
||||
// <td class="tit">
|
||||
// <div class="text-wrap">
|
||||
// <div>
|
||||
// <span class="user-icon">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/06/12/icon/i1237935053.jpg" alt="유저 아이콘" loading="lazy">
|
||||
// </span>
|
||||
// <a class="subject-link" href="https://www.inven.co.kr/board/party/5951/1589">
|
||||
// <span class="board_name">[사진&움짤]</span>스테이씨 윤
|
||||
// </a>
|
||||
// </div>
|
||||
// <span data-opinion-bbs-comeidx="5951" data-opinion-bbs-uid="1589" data-opinion-bbs-opi="1" class="con-comment">[1]</span>
|
||||
// <span class="con-icon board-img photo">사진</span>
|
||||
// </div>
|
||||
// </td>
|
||||
// <td class="user">
|
||||
// <img src="https://static.inven.co.kr/image_2011/member/level/1202/lv32.gif" alt="레벨 아이콘">
|
||||
// <span class="layerNickName" onclick="layerNickName('배수민', 'pbNickNameHandler'); ">배수민</span>
|
||||
// </td>
|
||||
// <td class="date">09-15</td>
|
||||
// <td class="view">1,502</td>
|
||||
// <td class="reco">1</td>
|
||||
// </tr>
|
||||
// </table>
|
||||
// </div>
|
||||
public function execute(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
try {
|
||||
//추가옵션
|
||||
$this->isDebug = in_array('debug', $params);
|
||||
$this->isCopy = in_array('copy', $params);
|
||||
$this->setBoardName($board_name);
|
||||
$this->login_process($user_id);
|
||||
//실행
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("inven.view.test.url.{$this->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("inven.list.url.{$this->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("inven.list.tag.{$this->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$hit = $node->filter(getenv("inven.list.item.hit.tag"))->text();
|
||||
$date = date("Y") . "-" . $node->filter(getenv("inven.list.item.date.tag"))->text();
|
||||
$nickname = $node->filter(getenv("inven.list.item.nickname.tag"))->text();
|
||||
//작성자가 "관리자"가 아닌 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
|
||||
$link_node = $node->filter(getenv("inven.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->text();
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("inven.list.max_limit.{$this->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
141
app/Controllers/Mangboard/Crawler/YamapCrawler.php
Normal file
141
app/Controllers/Mangboard/Crawler/YamapCrawler.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard\Crawler;
|
||||
|
||||
use App\Controllers\Mangboard\CrawlerController;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class YamapCrawler extends CrawlerController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
final protected function getHost(): string
|
||||
{
|
||||
return getenv("yamap.host.url");
|
||||
}
|
||||
protected function detail_content_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
$selector = $this->getSelector($response, getenv("yamap.view.content.tag"));
|
||||
$formDatas = [];
|
||||
$formDatas['image_path'] = "";
|
||||
$formDatas['content'] = $selector->html();
|
||||
//File DB 및 Board DB 등록작업등
|
||||
$this->getBoardModel()->createByCrawler(
|
||||
$this->getBoardsEntity(),
|
||||
$this->getUserEntity(),
|
||||
$cnt,
|
||||
$listInfo,
|
||||
[],
|
||||
$formDatas
|
||||
);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
protected function detail_download_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
$selector = $this->getSelector($response, getenv("yamap.view.content.tag"));
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "img", "src");
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "video", "src", $media_urls);
|
||||
if ($this->isDebug) {
|
||||
throw new \Exception(sprintf(
|
||||
"\n--------------%s Debug--------------\n%s%s\n---------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
var_export($listInfo, true),
|
||||
var_export($media_urls, true)
|
||||
));
|
||||
} else {
|
||||
// Image 나 Video 소스들의 url을 가져와서 실제 다운받는 처리
|
||||
$storages = $this->media_process($media_urls);
|
||||
if (!count($storages)) {
|
||||
throw new \Exception("등록할 자료가 없습니다.");
|
||||
}
|
||||
$this->backend_process($cnt, $listInfo, $storages);
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
//리스트내용
|
||||
// <div class="panel panel-default">
|
||||
// <div class="text-center panel-heading-local-title text-bold">요즘 패션</div>
|
||||
// <div style="margin:5px 10px;">
|
||||
// <span class="pull-left dropdown">
|
||||
// 괴강고귀
|
||||
// </span>
|
||||
// <span class="pull-right">
|
||||
// | 추천 (14) | 조회 (432)
|
||||
// </span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="hr-xs-xs">
|
||||
// <span>
|
||||
// <a href="javascript:void(0);" id="incfont"><i class="fa fa-plus fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" id="decfont"><i class="fa fa-minus fa-fw margin-left-5" aria-hidden="true"></i></a>
|
||||
// </span>
|
||||
// <span class="pull-right">2024-09-14 01:53:45
|
||||
// </span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="margin-top-5 margin-bottom-20">
|
||||
// <div class="fr-view margin-bottom-30" id="read-content" style="word-break:break-all;">
|
||||
// <p><img title="" class="cloudzoom" data-cloudzoom="zoomImage:'/newboard/yamoonfreeboard/uploads/humor/mceu_86177012011726246415487.jpg'" class="fr-fic fr-dii" src="/newboard/yamoonfreeboard/uploads/humor/mceu_86177012011726246415487.jpg" alt=""></p>
|
||||
// <p> </p>
|
||||
// </div>
|
||||
// </div>
|
||||
// <div class="margin-10">
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://twitter.com/intent/tweet?text='+encodeURIComponent(document.title)+'%20-%20'+encodeURIComponent(document.URL), 'twittersharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-twitter-square fa-lg ya-tooltip" title="트위터 공유하기"></i></a>
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(document.URL)+'&t='+encodeURIComponent(document.title), 'facebooksharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-facebook-square fa-lg ya-tooltip" title="페이스북 공유하기"></i></a>
|
||||
// </div>
|
||||
// <div id="freesubframe"></div>
|
||||
// </div>
|
||||
public function execute(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
try {
|
||||
//추가옵션
|
||||
$this->isDebug = in_array('debug', $params);
|
||||
$this->isCopy = in_array('copy', $params);
|
||||
$this->setBoardName($board_name);
|
||||
$this->login_process($user_id);
|
||||
//실행
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("yamap.view.test.url.{$this->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("yamap.list.url.{$this->getBoardName()}"));
|
||||
$selector = $this->getSelector($response, getenv("inven.list.tag.{$this->getBoardName()}"));
|
||||
$selector->filter(getenv("yamap.list.item.tag"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$hit = $node->filter(getenv("yamap.list.item.hit.tag"))->text();
|
||||
$date = date("Y") . "-" . $node->filter(getenv("yamap.list.item.date.tag"))->text();
|
||||
$nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text();
|
||||
//작성자가 "관리자"가 아닌 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
|
||||
$link_node = $node->filter(getenv("yamap.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->text();
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("yamap.list.max_limit.{$this->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,16 +3,81 @@
|
||||
namespace App\Controllers\Mangboard;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyCrawler\Mangboard\InvenCrawler;
|
||||
use App\Libraries\MyCrawler\Mangboard\SirCrawler;
|
||||
use App\Libraries\MyCrawler\Mangboard\YamapCrawler;
|
||||
use App\Libraries\MyCrawler\Mangboard\YamoonCrawler;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\MyStorage\MangboardStorage;
|
||||
use App\Models\Mangboard\BoardModel;
|
||||
use App\Models\Mangboard\BoardsModel;
|
||||
use App\Models\Mangboard\UserModel;
|
||||
use App\Traits\FileTrait;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class CrawlerController extends CommonController
|
||||
abstract class CrawlerController extends CommonController
|
||||
{
|
||||
private $_userModel = null;
|
||||
use FileTrait;
|
||||
private $_mySocket = null;
|
||||
private $_board_model = null;
|
||||
private $_user_model = null;
|
||||
private $_user_entity = null;
|
||||
private $_boards_entity = null;
|
||||
private $_board_name = "";
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
abstract protected function detail_content_process(int $cnt, array $listInfo): array;
|
||||
abstract protected function detail_download_process(int $cnt, array $listInfo): array;
|
||||
abstract protected function getHost(): string;
|
||||
final protected function getBoardName(): string
|
||||
{
|
||||
return $this->_board_name;
|
||||
}
|
||||
final protected function setBoardName(string $board_name): void
|
||||
{
|
||||
$this->_board_name = $board_name;
|
||||
}
|
||||
final protected function getUserEntity(): UserEntity
|
||||
{
|
||||
return $this->_user_entity;
|
||||
}
|
||||
final protected function setUserEntity(UserEntity $user_entity): void
|
||||
{
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
//-----------------------필수항목-------------------//
|
||||
final protected function getMySocket()
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new WebSocket($this->getHost());
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
final protected function createMyStorage(): MangboardStorage
|
||||
{
|
||||
return new MangboardStorage($this->getBoardName(), $this->getUserEntity());
|
||||
}
|
||||
final protected function getBoardsEntity(): BoardsEntity
|
||||
{
|
||||
if ($this->_boards_entity === null) {
|
||||
$boardsModel = new BoardsModel();
|
||||
$this->_boards_entity = $boardsModel->getEntityByID($this->getBoardName());
|
||||
if ($this->_boards_entity === null) {
|
||||
throw new \Exception(__FUNCTION__ . "=> {$this->getBoardName()}에 해당 Board 정보가 존재하지 않습니다.");
|
||||
}
|
||||
}
|
||||
return $this->_boards_entity;
|
||||
}
|
||||
final protected function getBoardModel(): BoardModel
|
||||
{
|
||||
if ($this->_board_model === null) {
|
||||
$this->_board_model = new BoardModel("mb_" . $this->getBoardName());
|
||||
}
|
||||
return $this->_board_model;
|
||||
}
|
||||
public function getUserModel(): UserModel
|
||||
{
|
||||
if ($this->_user_model === null) {
|
||||
@ -20,14 +85,13 @@ class CrawlerController extends CommonController
|
||||
}
|
||||
return $this->_user_model;
|
||||
}
|
||||
public function login(string $id = ""): bool|UserEntity
|
||||
protected function login_process(string $user_id = null): void
|
||||
{
|
||||
$host = getenv("mangboard.host.url");
|
||||
$id = $id == "" ? getenv("mangboard.login.default.id") : $id;
|
||||
$password = getenv("mangboard.login.default.password");
|
||||
$user_entity = $this->getUserModel()->getEntityByID($id);
|
||||
$user_id = $user_id ?? getenv("mangboard.login.default.id");
|
||||
$password = getenv("mangboard.login.default.password");
|
||||
$this->setUserEntity($this->getUserModel()->getEntityByID($user_id));
|
||||
// $response = $this->getWebLibrary($host)->getResponse(
|
||||
// $host . getenv("mangboard.login.url"),
|
||||
// getenv("mangboard.host.url") . getenv("mangboard.login.url"),
|
||||
// "post",
|
||||
// [
|
||||
// 'form_params' => [
|
||||
@ -44,71 +108,177 @@ class CrawlerController extends CommonController
|
||||
// } else {
|
||||
// throw new \Exception("연결실패:" . $response->getStatusCode());
|
||||
// }
|
||||
log_message("notice", "{$id}로 로그인 성공");
|
||||
return $user_entity;
|
||||
log_message("notice", "{$user_id}로 로그인 성공");
|
||||
}
|
||||
public function yamap(string $board_name, ...$params): string
|
||||
|
||||
final protected function getSelector(string $content, string $tag): Crawler
|
||||
{
|
||||
try {
|
||||
//1. 사이트 로그인 처리
|
||||
$user_entity = $this->login(in_array('id', $params) ? $params['id'] : "");
|
||||
//2. 필요한 로그인한 사용자정보,Socket,Storage 정의후 Crawler에게 전달.
|
||||
$crawler = new YamapCrawler(getenv('yamap.host.url'), $board_name, $user_entity);
|
||||
$crawler->isDebug = in_array('debug', $params);
|
||||
$crawler->isCopy = in_array('copy', $params);
|
||||
$crawler->execute();
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
$crawler = new Crawler($content);
|
||||
if ($this->isDebug) {
|
||||
log_message("debug", __FUNCTION__ . "=> " . $tag);
|
||||
}
|
||||
$crawler->filter($tag);
|
||||
if ($this->isDebug) {
|
||||
log_message("debug", sprintf(
|
||||
"\n------------%s HTML-------------\n%s\n-----------------------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$crawler->filter($tag)->html()
|
||||
));
|
||||
}
|
||||
return $crawler->filter($tag);
|
||||
}
|
||||
public function yamoon(string $board_name, ...$params): string
|
||||
protected function changeURLByCrawler(string $url): string
|
||||
{
|
||||
try {
|
||||
//1. 사이트 로그인 처리
|
||||
$user_entity = $this->login(in_array('id', $params) ? $params['id'] : "");
|
||||
//2. 필요한 로그인한 사용자정보,Socket,Storage 정의후 Crawler에게 전달.
|
||||
$crawler = new YamoonCrawler(getenv("yamoon.host.url"), $board_name, $user_entity);
|
||||
$crawler->isDebug = in_array('debug', $params);
|
||||
$crawler->isCopy = in_array('copy', $params);
|
||||
$crawler->execute();
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
return preg_match('/^[^?]+/', $url, $matches) ? $matches[0] : null;
|
||||
}
|
||||
public function sir(string $board_name, ...$params): string
|
||||
protected function getUrlByMediaType(Crawler $node, string $media_tag, string $attr): null|string
|
||||
{
|
||||
try {
|
||||
//1. 사이트 로그인 처리
|
||||
$user_entity = $this->login(in_array('id', $params) ? $params['id'] : "");
|
||||
//2. 필요한 로그인한 사용자정보,Socket,Storage 정의후 Crawler에게 전달.
|
||||
$crawler = new SirCrawler(getenv("sir.host.url"), $board_name, $user_entity);
|
||||
$crawler->isDebug = in_array('debug', $params);
|
||||
$crawler->isCopy = in_array('copy', $params);
|
||||
$crawler->execute();
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
switch ($media_tag) {
|
||||
case 'video':
|
||||
try {
|
||||
$url = $node->attr($attr); //<video src="test.mp4"></video> 또는 <video data-src="test.mp4"></video>
|
||||
} catch (\Exception) {
|
||||
$url = $node->children()->attr("src"); //<video><source src="test.mp4"></source</video>
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
default:
|
||||
$url = $node->attr($attr);
|
||||
break;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
public function inven(string $board_name, ...$params): string
|
||||
protected function getUrlsByMediaType(Crawler $selector, string $media_tag, string $attr, array $urls = []): array
|
||||
{
|
||||
try {
|
||||
//1. 사이트 로그인 처리
|
||||
$user_entity = $this->login(in_array('id', $params) ? $params['id'] : "");
|
||||
//2. 필요한 로그인한 사용자정보,Socket,Storage 정의후 Crawler에게 전달.
|
||||
$crawler = new InvenCrawler(getenv("inven.host.url"), $board_name, $user_entity);
|
||||
$crawler->isDebug = in_array('debug', $params);
|
||||
$crawler->isCopy = in_array('copy', $params);
|
||||
$crawler->execute();
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
log_message("notice", "-----------" . __FUNCTION__ . "=> {$media_tag} 작업시작--------");
|
||||
$urls[$media_tag] = [];
|
||||
$selector->filter($media_tag)->each(
|
||||
function (Crawler $node) use (&$media_tag, &$attr, &$urls): void {
|
||||
$url = $this->getUrlByMediaType($node, $media_tag, $attr);
|
||||
if ($url !== null && preg_match('/^[^?]+/', $url, $matches)) {
|
||||
$urls[$media_tag][] = $this->changeURLByCrawler($matches[0]);
|
||||
} else {
|
||||
log_message("debug", __FUNCTION__ . "-> {$media_tag}:{$attr}\n");
|
||||
//Node 모든 속성은 DOMElement 변환 후 반환가능
|
||||
$domNode = $node->getNode(0);
|
||||
if ($domNode->hasAttributes()) {
|
||||
foreach ($domNode->attributes as $attr) {
|
||||
log_message("debug", "{$attr->nodeName} = {$attr->nodeValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
log_message("notice", "-----------" . __FUNCTION__ . "=> {$media_tag} 작업완료--------");
|
||||
return $urls;
|
||||
}
|
||||
private function media_save(int $file_sequence, string $media_tag, string $file_name, string $content): mixed
|
||||
{
|
||||
log_message("debug", __FUNCTION__ . " 원본파일 {$file_name} 작업 시작");
|
||||
$storage = $this->createMyStorage();
|
||||
$storage->setOriginName($file_name);
|
||||
$storage->setOriginContent($content);
|
||||
$storage->setOriginMediaTag($media_tag);
|
||||
$storage->setOriginSequence($file_sequence);
|
||||
return $storage->save();
|
||||
}
|
||||
//Yamap ViewPage의 이미지나영상데이터가 있으면 Dodownload 한다.
|
||||
private function media_download(string $media_tag, string $url): array
|
||||
{
|
||||
$file_names = explode('/', $url);
|
||||
if (!is_array($file_names) || !count($file_names)) {
|
||||
throw new \Exception("URL이 파일명 형식이 아닙니다 : " . $this->getMySocket()->getHost() . $url);
|
||||
}
|
||||
$file_name = array_pop($file_names);
|
||||
$temps = explode(".", $file_name);
|
||||
$file_ext = array_pop($temps);
|
||||
if (!$this->isFileType_FileTrait($file_ext, $media_tag)) {
|
||||
throw new \Exception("파일명 형식이 {$media_tag}가 아닙니다");
|
||||
}
|
||||
$content = $this->getMySocket()->getContent($url);
|
||||
log_message("notice", "{$file_name} 파일이 다운로드되었습니다!");
|
||||
return array($file_name, $content);
|
||||
}
|
||||
final protected function media_process(array $media_urls): array
|
||||
{
|
||||
$file_sequence = 1;
|
||||
$storages = []; //CreateBoard에서 사용을 위해 DetailPage마다 초기화
|
||||
foreach ($media_urls as $media_tag => $urls) {
|
||||
$total = count($urls);
|
||||
foreach ($urls as $url) {
|
||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째/총:{$total} MediaType->{$media_tag} 작업 시작");
|
||||
try {
|
||||
list($file_name, $content) = $this->media_download($media_tag, $url);
|
||||
$storage = $this->media_save($file_sequence, $media_tag, $file_name, $content);
|
||||
log_message("debug", __FUNCTION__ . " {$file_sequence}번째/총:{$total} 결과=>" . $storage->getOriginName());
|
||||
$storages[] = $storage;
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s MediaType->%s {$file_sequence}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$media_tag,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째/총:{$total} MediaType->{$media_tag} 작업 완료");
|
||||
$file_sequence++;
|
||||
}
|
||||
}
|
||||
return $storages;
|
||||
}
|
||||
protected function backend_process(int $cnt, array $listInfo, array $storages)
|
||||
{
|
||||
//File DB 및 Board DB 등록작업등
|
||||
$board_entity = $this->getBoardModel()->createByCrawler(
|
||||
$this->getBoardsEntity(),
|
||||
$this->getUserEntity(),
|
||||
$cnt,
|
||||
$listInfo,
|
||||
$storages
|
||||
);
|
||||
foreach ($storages as $storage) {
|
||||
try {
|
||||
$storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable());
|
||||
} catch (\Exception $e) {
|
||||
log_message("notice", sprintf(
|
||||
"\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$storage->getOriginName(),
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
protected function list_process(int $max_limit, array $listInfos): void
|
||||
{
|
||||
//Limit가 0이면 $listInfos 갯수만큼 다하고, LIMIT 갯수 혹은 item의 갯수중 작은수만큼 한다.
|
||||
$max_limit = !$max_limit || count($listInfos) <= $max_limit ? count($listInfos) : $max_limit;
|
||||
$total = count($listInfos);
|
||||
$i = 1;
|
||||
foreach ($listInfos as $listInfo) {
|
||||
if ($i <= $max_limit) {
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작");
|
||||
try {
|
||||
if ($this->isCopy) {
|
||||
$listInfo = $this->detail_content_process($i, $listInfo);
|
||||
} else {
|
||||
//listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다.
|
||||
$listInfo = $this->detail_download_process($i, $listInfo);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s {$i}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업완료.");
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
15
app/Entities/Cloudflare/APIEntity.php
Normal file
15
app/Entities/Cloudflare/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;
|
||||
}
|
||||
}
|
||||
30
app/Entities/Cloudflare/AccountEntity.php
Normal file
30
app/Entities/Cloudflare/AccountEntity.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
class AccountEntity extends CommonEntity
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getTitle()}|{$this->getKey()}|{$this->attributes['type']}|{$this->attributes['status']}";
|
||||
}
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes['email'];
|
||||
}
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->attributes['email'] = $title;
|
||||
}
|
||||
//Common Function
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->attributes['key'];
|
||||
}
|
||||
}
|
||||
27
app/Entities/Cloudflare/FirewallEntity.php
Normal file
27
app/Entities/Cloudflare/FirewallEntity.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class FirewallEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
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
|
||||
{
|
||||
return "zone_uid";
|
||||
}
|
||||
}
|
||||
27
app/Entities/Cloudflare/RecordEntity.php
Normal file
27
app/Entities/Cloudflare/RecordEntity.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class RecordEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle()
|
||||
{
|
||||
return "{$this->attributes['host']}-{$this->attributes['content']}";
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return "uid:{$this->attributes['uid']}|zone_uid:{$this->attributes['zone_uid']}|host:{$this->attributes['host']}|content:{$this->attributes['content']}|proxied:{$this->attributes['proxied']}|fixed:{$this->attributes['fixed']}|locked:{$this->attributes['locked']}";
|
||||
}
|
||||
public function getParentField(): string
|
||||
{
|
||||
return "zone_uid";
|
||||
}
|
||||
}
|
||||
27
app/Entities/Cloudflare/ZoneEntity.php
Normal file
27
app/Entities/Cloudflare/ZoneEntity.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare\API;
|
||||
|
||||
class ZoneEntity extends APIEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
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
|
||||
{
|
||||
return "account_uid";
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,7 @@ abstract class CommonEntity extends Entity
|
||||
}
|
||||
|
||||
abstract public function __toString();
|
||||
abstract public function getPK();
|
||||
abstract public function getTitle();
|
||||
abstract public function setTitle(string $tile): void;
|
||||
}
|
||||
|
||||
@ -10,6 +10,10 @@ class UserEntity extends CommonEntity
|
||||
{
|
||||
return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getLevel()}/{$this->getPoint()}";
|
||||
}
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes['_name'];
|
||||
@ -20,10 +24,6 @@ class UserEntity extends CommonEntity
|
||||
}
|
||||
//Common Function
|
||||
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getID(): string
|
||||
{
|
||||
return $this->attributes['id'];
|
||||
|
||||
@ -2,79 +2,9 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare;
|
||||
|
||||
use App\Libraries\Cloudflare\CloudflareLibrary;
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Libraries\MySocket\CloudflareSocket;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use Cloudflare\API\Adapter\Guzzle;
|
||||
|
||||
class Account extends CloudflareLibrary
|
||||
{
|
||||
private $_endPoint = null;
|
||||
private $_entity = null;
|
||||
public function __construct(\App\Entities\Cloudflare\API\AuthEntity $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
$this->_model = new \App\Models\Cloudflare\API\AccountModel();
|
||||
}
|
||||
protected function setAdapter()
|
||||
{
|
||||
if (!is_null($this->_adapter)) {
|
||||
throw new \Exception("Adapter가 이미 지정되었습니다.");
|
||||
}
|
||||
$apikey = new \Cloudflare\API\Auth\APIKey(
|
||||
$this->getParent()->getAuthId(),
|
||||
$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): \App\Entities\Cloudflare\API\AccountEntity
|
||||
{
|
||||
// dd($cfResult);exit;
|
||||
// [
|
||||
// {"id":"078e88a7735965b661715af13031ecb0",
|
||||
// "name":"Cloudwin002@idcjp.jp's Account",
|
||||
// "type":"standard",
|
||||
// "settings":{
|
||||
// "enforce_twofactor":false,
|
||||
// "api_access_enabled":null,
|
||||
// "access_approval_expiry":null,
|
||||
// "use_account_custom_ns_by_default":false
|
||||
// },
|
||||
// "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 \App\Entities\Cloudflare\API\AccountEntity() : $this->_entity;
|
||||
$entity->uid = $cfResult->id;
|
||||
$entity->auth_uid = $this->getParent()->getPrimaryKey();
|
||||
$entity->title = $cfResult->name;
|
||||
$entity->type = $cfResult->type;
|
||||
$entity->status = $this->getParent()->status;
|
||||
$entity->updated_at = $cfResult->created_on;
|
||||
$entity->created_at = $cfResult->created_on;
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function insert(array $fieldDatas): \App\Entities\Cloudflare\API\AccountEntity
|
||||
{
|
||||
$options = [
|
||||
'name' => $fieldDatas['name'],
|
||||
'type' => isset($fieldDatas['type']) ? $fieldDatas['type'] : 'standard',
|
||||
];
|
||||
$cfResult = $this->getAdapter()->post('accounts', $options);
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
if (!$cfResult->success) {
|
||||
throw new \Exception(var_export($cfResult, true));
|
||||
}
|
||||
$entity = $this->getEntityByResult($cfResult->result);
|
||||
Log::add("warning", "Account API: {$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.");
|
||||
return $entity;
|
||||
}
|
||||
protected function getCFResults_List(int $page): array
|
||||
{
|
||||
$this->_endPoint = is_null($this->_endPoint) ? new \Cloudflare\API\Endpoints\Accounts($this->getAdapter()) : $this->_endPoint;
|
||||
return $this->_endPoint->listAccounts($page, CF_ADAPTER_PERPAGE_MAX)->result;
|
||||
}
|
||||
}
|
||||
class Account extends CommonLibrary {}
|
||||
|
||||
@ -3,161 +3,7 @@
|
||||
namespace App\Libraries\MyCrawler\Mangboard;
|
||||
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyCrawler\MangboardCrawler;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class InvenCrawler extends MangboardCrawler
|
||||
{
|
||||
public function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($host, $board_name, $user_entity);
|
||||
}
|
||||
protected function getUrlByMediaType(Crawler $node, string $media_type, string $attr): null|string
|
||||
{
|
||||
switch ($media_type) {
|
||||
case 'video':
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
//그래도 null이면 data-src로 추출해본다.
|
||||
$attributes = $node->extract(['data-src']);
|
||||
if (count($attributes)) {
|
||||
$url = $attributes[0];
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
default:
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
break;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
//작성내용
|
||||
// <div class="articleContent">
|
||||
// <div id="imageCollectDiv" class="contentBody">
|
||||
// <!-- ============== CONTENT ============== -->
|
||||
// <div id="powerbbsContent">
|
||||
// <div id="BBSImageHolderTop" style="text-align:center;">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1620925350.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1587803007.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1134295360.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1481352611.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1878651605.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 850 / 1063;" loading="lazy" />
|
||||
// <br><br>
|
||||
// </div>
|
||||
// <div>^^</div>
|
||||
// </div>
|
||||
// <!-- ============== End CONTENT ============== -->
|
||||
// </div>
|
||||
protected function detail_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
$selector = $this->getSelector($response, getenv("inven.view.content.tag"));
|
||||
if ($this->isCopy) {
|
||||
$formDatas = [];
|
||||
$formDatas['image_path'] = "";
|
||||
$formDatas['content'] = $selector->html();
|
||||
//File DB 및 Board DB 등록작업등
|
||||
$this->getBoardModel()->createByCrawler(
|
||||
$this->getBoardsEntity(),
|
||||
$this->getUserEntity(),
|
||||
$cnt,
|
||||
$listInfo,
|
||||
[],
|
||||
$formDatas
|
||||
);
|
||||
} else {
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "img", "src");
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "video", "src", $media_urls);
|
||||
if ($this->isDebug) {
|
||||
throw new \Exception(sprintf(
|
||||
"\n--------------%s Debug--------------\n%s%s\n---------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
var_export($listInfo, true),
|
||||
var_export($media_urls, true)
|
||||
));
|
||||
} else {
|
||||
// Image 나 Video 소스들의 url을 가져와서 실제 다운받는 처리
|
||||
$storages = $this->media_process($media_urls);
|
||||
if (!count($storages)) {
|
||||
throw new \Exception("등록할 자료가 없습니다.");
|
||||
}
|
||||
$this->backend_process($cnt, $listInfo, $storages);
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
protected function copy_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
return $listInfo;
|
||||
}
|
||||
//리스트내용
|
||||
// <div class="board-list">
|
||||
// <table>
|
||||
// <tr class="lgtm">
|
||||
// <td class="num"><span>1589</span></td>
|
||||
// <td class="tit">
|
||||
// <div class="text-wrap">
|
||||
// <div>
|
||||
// <span class="user-icon">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/06/12/icon/i1237935053.jpg" alt="유저 아이콘" loading="lazy">
|
||||
// </span>
|
||||
// <a class="subject-link" href="https://www.inven.co.kr/board/party/5951/1589">
|
||||
// <span class="board_name">[사진&움짤]</span>스테이씨 윤
|
||||
// </a>
|
||||
// </div>
|
||||
// <span data-opinion-bbs-comeidx="5951" data-opinion-bbs-uid="1589" data-opinion-bbs-opi="1" class="con-comment">[1]</span>
|
||||
// <span class="con-icon board-img photo">사진</span>
|
||||
// </div>
|
||||
// </td>
|
||||
// <td class="user">
|
||||
// <img src="https://static.inven.co.kr/image_2011/member/level/1202/lv32.gif" alt="레벨 아이콘">
|
||||
// <span class="layerNickName" onclick="layerNickName('배수민', 'pbNickNameHandler'); ">배수민</span>
|
||||
// </td>
|
||||
// <td class="date">09-15</td>
|
||||
// <td class="view">1,502</td>
|
||||
// <td class="reco">1</td>
|
||||
// </tr>
|
||||
// </table>
|
||||
// </div>
|
||||
public function execute(): void
|
||||
{
|
||||
try {
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("inven.view.test.url.{$this->getBoardName()}");
|
||||
$this->detail_process(1, $listInfo);
|
||||
log_message("notice", __FUNCTION__ . "=> DEBUG 게시물 {$listInfo['detail_url']} 작업종료");
|
||||
} else {
|
||||
$listInfos = [];
|
||||
$response = $this->getMySocket()->getContent(getenv("inven.list.url.{$this->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("inven.list.tag.{$this->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$hit = $node->filter(getenv("inven.list.item.hit.tag"))->text();
|
||||
$date = date("Y") . "-" . $node->filter(getenv("inven.list.item.date.tag"))->text();
|
||||
$nickname = $node->filter(getenv("inven.list.item.nickname.tag"))->text();
|
||||
//작성자가 "관리자"가 아닌 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
|
||||
$link_node = $node->filter(getenv("inven.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->text();
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||
}
|
||||
);
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("inven.list.max_limit.{$this->getBoardName()}")), $listInfos);
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
class InvenCrawler extends MangboardCrawler {}
|
||||
|
||||
@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler\Mangboard;
|
||||
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyCrawler\MyCrawler;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\MyStorage\MangboardStorage;
|
||||
use App\Models\Mangboard\BoardModel;
|
||||
use App\Models\Mangboard\BoardsModel;
|
||||
|
||||
abstract class MangboardCrawler extends MyCrawler
|
||||
{
|
||||
private $_mySocket = null;
|
||||
private $_host = "";
|
||||
private $_board_name = "";
|
||||
private $_board_model = null;
|
||||
private $_boards_entity = null;
|
||||
private $_user_entity = null;
|
||||
protected function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_host = $host;
|
||||
$this->_board_name = $board_name;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
abstract protected function detail_process(int $cnt, array $listInfo): array;
|
||||
abstract public function execute(): void;
|
||||
final protected function getMySocket()
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new WebSocket($this->_host);
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
final protected function createMyStorage()
|
||||
{
|
||||
return new MangboardStorage($this->getBoardName(), $this->getUserEntity());
|
||||
}
|
||||
final protected function getBoardModel(): BoardModel
|
||||
{
|
||||
if ($this->_board_model === null) {
|
||||
$this->_board_model = new BoardModel("mb_" . $this->getBoardName());
|
||||
}
|
||||
return $this->_board_model;
|
||||
}
|
||||
final protected function getBoardName(): string
|
||||
{
|
||||
return $this->_board_name;
|
||||
}
|
||||
final protected function getBoardsEntity(): BoardsEntity
|
||||
{
|
||||
if ($this->_boards_entity === null) {
|
||||
$boardsModel = new BoardsModel();
|
||||
$this->_boards_entity = $boardsModel->getEntityByID($this->getBoardName());
|
||||
if ($this->_boards_entity === null) {
|
||||
throw new \Exception(__FUNCTION__ . "=> {$this->getBoardName()}에 해당 Board 정보가 존재하지 않습니다.");
|
||||
}
|
||||
}
|
||||
return $this->_boards_entity;
|
||||
}
|
||||
final protected function getUserEntity(): UserEntity
|
||||
{
|
||||
return $this->_user_entity;
|
||||
}
|
||||
protected function backend_process(int $cnt, array $listInfo, array $storages)
|
||||
{
|
||||
//File DB 및 Board DB 등록작업등
|
||||
$board_entity = $this->getBoardModel()->createByCrawler(
|
||||
$this->getBoardsEntity(),
|
||||
$this->getUserEntity(),
|
||||
$cnt,
|
||||
$listInfo,
|
||||
$storages
|
||||
);
|
||||
foreach ($storages as $storage) {
|
||||
try {
|
||||
$storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable());
|
||||
} catch (\Exception $e) {
|
||||
log_message("notice", sprintf(
|
||||
"\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$storage->getOriginName(),
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
protected function list_process(int $max_limit, array $listInfos): void
|
||||
{
|
||||
//Limit가 0이면 $listInfos 갯수만큼 다하고, LIMIT 갯수 혹은 item의 갯수중 작은수만큼 한다.
|
||||
$max_limit = !$max_limit || count($listInfos) <= $max_limit ? count($listInfos) : $max_limit;
|
||||
$total = count($listInfos);
|
||||
$i = 1;
|
||||
foreach ($listInfos as $listInfo) {
|
||||
if ($i <= $max_limit) {
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작");
|
||||
try {
|
||||
//listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다.
|
||||
$listInfo = $this->detail_process($i, $listInfo);
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s {$i}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업완료.");
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
namespace App\Libraries\MyCrawler\Mangboard;
|
||||
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\MyCrawler\MangboardCrawler;
|
||||
use DateTime;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Libraries\MyCrawler\Mangboard;
|
||||
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyCrawler\MangboardCrawler;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class YamapCrawler extends MangboardCrawler
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Libraries\MyCrawler\Mangboard;
|
||||
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyCrawler\MangboardCrawler;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class YamoonCrawler extends MangboardCrawler
|
||||
|
||||
@ -129,6 +129,7 @@ abstract class MyCrawler extends CommonLibrary
|
||||
$file_sequence++;
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . "=> 게시물 {$url} 작업종료");
|
||||
return $storages;
|
||||
}
|
||||
}
|
||||
|
||||
30
app/Libraries/MySocket/Cloudflare/AccountSocket.php
Normal file
30
app/Libraries/MySocket/Cloudflare/AccountSocket.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MySocket\Cloudflare;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Libraries\MySocket\CloudflareSocket;
|
||||
use Cloudflare\API\Auth\APIKey;
|
||||
|
||||
class AccountSocket extends CloudflareSocket
|
||||
{
|
||||
public function __construct(string $email, string $api_key)
|
||||
{
|
||||
parent::__construct($email, $api_key);
|
||||
}
|
||||
|
||||
final public function create(string $name, string $type = "standard")
|
||||
{
|
||||
$datas = [
|
||||
'name' => $name . "'s Account",
|
||||
'type' => $type,
|
||||
];
|
||||
$result = $this->getClient()->post("accounts", $datas);
|
||||
$result = json_decode($result->getBody());
|
||||
if (!$result->success) {
|
||||
throw new \Exception(var_export($result, true));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
39
app/Libraries/MySocket/CloudflareSocket.php
Normal file
39
app/Libraries/MySocket/CloudflareSocket.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MySocket;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use Cloudflare\API\Adapter\Guzzle;
|
||||
use Cloudflare\API\Auth\APIKey;
|
||||
|
||||
class CloudflareSocket extends CommonLibrary
|
||||
{
|
||||
private static int $_request = 0;
|
||||
private static int $_request_max = 100;
|
||||
private static int $_request_timewait = 60;
|
||||
private $_client = null;
|
||||
public function __construct(string $email, string $api_key)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_email = $email;
|
||||
$this->_api_key = $api_key;
|
||||
self::$_request_max = getenv("cfmgr.request.max");
|
||||
}
|
||||
final public function getClient(): Guzzle
|
||||
{
|
||||
if ($this->_client === null) {
|
||||
$this->_client = new Guzzle(
|
||||
$this->_client = new APIKey($this->_email, $this->_api_key)
|
||||
);
|
||||
}
|
||||
if (self::$_request >= self::$_request_max) {
|
||||
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
|
||||
sleep(intval(getenv("cf.mgr.request.time.wait")));
|
||||
self::$_request = 0;
|
||||
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
|
||||
}
|
||||
self::$_request++;
|
||||
return $this->_client;
|
||||
}
|
||||
}
|
||||
@ -1,30 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MySocket\Web;
|
||||
namespace App\Libraries\MySocket;
|
||||
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\CommonLibrary;
|
||||
|
||||
class GoogleSocket extends WebSocket
|
||||
class GoogleSocket extends CommonLibrary
|
||||
{
|
||||
private $_client = null;
|
||||
private $_session = null;
|
||||
private $_access_code = "";
|
||||
public function __construct(string $host)
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($host);
|
||||
parent::__construct();
|
||||
$this->_session = \Config\Services::session();
|
||||
}
|
||||
|
||||
//Override
|
||||
public function getClient()
|
||||
public function getClient(): Google_Client
|
||||
{
|
||||
if (is_null($this->_client)) {
|
||||
// $this->_client = new \Google_Client();
|
||||
// $this->_client->setClientId(getenv("socket.google.client.id"));
|
||||
// $this->_client->setClientSecret(getenv("socket.google.client.key"));
|
||||
// $this->_client->setRedirectUri(base_url() . getenv("socket.google.client.callback_url"));
|
||||
// $this->_client->addScope('email');
|
||||
// $this->_client->addScope('profile');
|
||||
$this->_client = new Google_Client();
|
||||
$this->_client->setClientId(getenv("socket.google.client.id"));
|
||||
$this->_client->setClientSecret(getenv("socket.google.client.key"));
|
||||
$this->_client->setRedirectUri(base_url() . getenv("socket.google.client.callback_url"));
|
||||
$this->_client->addScope('email');
|
||||
$this->_client->addScope('profile');
|
||||
}
|
||||
return $this->_client;
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MySocket;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
|
||||
abstract class MySocket extends CommonLibrary
|
||||
{
|
||||
private $_host = null;
|
||||
protected function __construct(string $host)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_host = $host;
|
||||
}
|
||||
abstract public function getClient();
|
||||
final public function getHost(): string
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MySocket\Web;
|
||||
|
||||
use Cloudflare\API\Auth\APIKey;
|
||||
use Cloudflare\API\Adapter\Guzzle;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
|
||||
class CloudflareSocket extends WebSocket
|
||||
{
|
||||
private static int $_request_count = 1;
|
||||
private static int $_request_max = 100;
|
||||
private static int $_request_timewait = 60;
|
||||
private $_api_email = "";
|
||||
private $_api_key = "";
|
||||
private $_client = null;
|
||||
public function __construct(string $host, string $api_email, string $api_key)
|
||||
{
|
||||
parent::__construct($host);
|
||||
$this->_api_email = $api_email;
|
||||
$this->_api_key = $api_key;
|
||||
}
|
||||
|
||||
//Override
|
||||
public function getClient()
|
||||
{
|
||||
if (is_null($this->_client)) {
|
||||
$apikey = new APIKey($this->_api_email, $this->_api_key);
|
||||
$this->_client = new Guzzle($apikey);
|
||||
self::$_request_max = intval(getenv("cfmgr.request.max"));
|
||||
self::$_request_timewait = intval(getenv("cfmgr.request.timewait"));
|
||||
}
|
||||
if (self::$_request_max <= self::$_request_count) {
|
||||
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
|
||||
sleep(intval(getenv("cf.mgr.request.time.wait")));
|
||||
self::$_request_count = 0;
|
||||
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
|
||||
}
|
||||
self::$_request_count++;
|
||||
return $this->_client;
|
||||
}
|
||||
}
|
||||
@ -2,19 +2,26 @@
|
||||
|
||||
namespace App\Libraries\MySocket;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use GuzzleHttp\Cookie\CookieJar;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class WebSocket extends MySocket
|
||||
class WebSocket extends CommonLibrary
|
||||
{
|
||||
private $_host = null;
|
||||
private $_client = null;
|
||||
private $_cookieJar = null;
|
||||
public function __construct(string $host)
|
||||
{
|
||||
parent::__construct($host);
|
||||
parent::__construct();
|
||||
$this->_host = $host;
|
||||
}
|
||||
final public function getHost(): string
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
public function getClient()
|
||||
final public function getClient(): Client
|
||||
{
|
||||
if ($this->_client === null) {
|
||||
$this->_client = new Client(['verify' => getenv("socket.web.ssl.verify") == "true" ? true : false]);
|
||||
|
||||
@ -2,15 +2,19 @@
|
||||
|
||||
namespace App\Libraries\MyStorage;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Traits\FileTrait;
|
||||
|
||||
class FileStorage extends MyStorage
|
||||
class FileStorage extends CommonLibrary
|
||||
{
|
||||
use FileTrait;
|
||||
private $_path = "";
|
||||
private $_originName = "";
|
||||
private $_originContent = "";
|
||||
private $_originMediaTag = "";
|
||||
private $_originSequence = "";
|
||||
private $_mimeType = "";
|
||||
private $_fileSize = 0;
|
||||
private $_fileSequence = 0;
|
||||
private $_imageLibrary = null;
|
||||
public function __construct(string $path)
|
||||
{
|
||||
@ -35,7 +39,38 @@ class FileStorage extends MyStorage
|
||||
{
|
||||
return "uploads";
|
||||
}
|
||||
|
||||
final public function getOriginName(): string
|
||||
{
|
||||
return $this->_originName;
|
||||
}
|
||||
final public function setOriginName(string $originName): void
|
||||
{
|
||||
$this->_originName = $originName;
|
||||
}
|
||||
final public function getOriginContent(): string
|
||||
{
|
||||
return $this->_originContent;
|
||||
}
|
||||
final public function setOriginContent(string $originContent): void
|
||||
{
|
||||
$this->_originContent = $originContent;
|
||||
}
|
||||
final public function getOriginMediaTag(): string
|
||||
{
|
||||
return $this->_originMediaTag;
|
||||
}
|
||||
final public function setOriginMediaTag(string $originMediaTag): void
|
||||
{
|
||||
$this->_originMediaTag = $originMediaTag;
|
||||
}
|
||||
final public function getOriginSequence(): int
|
||||
{
|
||||
return $this->_originSequence;
|
||||
}
|
||||
final public function setOriginSequence(int $originSequence): void
|
||||
{
|
||||
$this->_originSequence = $originSequence;
|
||||
}
|
||||
final public function getMimeType(): string
|
||||
{
|
||||
return $this->_mimeType;
|
||||
@ -44,11 +79,6 @@ class FileStorage extends MyStorage
|
||||
{
|
||||
return $this->_fileSize;
|
||||
}
|
||||
final public function getFileSequence(): int
|
||||
{
|
||||
return $this->_fileSequence;
|
||||
}
|
||||
|
||||
public function save(): static
|
||||
{
|
||||
// log_message("notice", __FUNCTION__ . " 원본파일 {$this->getOriginName()} 작업 시작 2");
|
||||
|
||||
@ -42,7 +42,7 @@ class MangboardStorage extends FileStorage
|
||||
final public function getHTMLTag(string $content = ""): string
|
||||
{
|
||||
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
|
||||
switch ($this->getOrintginType()) {
|
||||
switch ($this->getOriginMediaTag()) {
|
||||
case "img":
|
||||
$content = sprintf(
|
||||
"<img src=\"%s/%s/%s\" alt=\"%s\">",
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyStorage;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
|
||||
abstract class MyStorage extends CommonLibrary
|
||||
{
|
||||
private $_originName = "";
|
||||
private $_originContent = "";
|
||||
private $_originType = "";
|
||||
private $_originSequence = "";
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
abstract public function save(): static;
|
||||
final public function getOriginName(): string
|
||||
{
|
||||
return $this->_originName;
|
||||
}
|
||||
final public function setOriginName(string $originName): void
|
||||
{
|
||||
$this->_originName = $originName;
|
||||
}
|
||||
final public function getOriginContent(): string
|
||||
{
|
||||
return $this->_originContent;
|
||||
}
|
||||
final public function setOriginContent(string $originContent): void
|
||||
{
|
||||
$this->_originContent = $originContent;
|
||||
}
|
||||
|
||||
final public function getOrintginType(): string
|
||||
{
|
||||
return $this->_originType;
|
||||
}
|
||||
final public function setOriginType(string $originType): void
|
||||
{
|
||||
$this->_originType = $originType;
|
||||
}
|
||||
final public function getOriginSequence(): int
|
||||
{
|
||||
return $this->_originSequence;
|
||||
}
|
||||
final public function setOriginSequence(int $originSequence): void
|
||||
{
|
||||
$this->_originSequence = $originSequence;
|
||||
}
|
||||
}
|
||||
62
app/Models/Cloudflare/AccountModel.php
Normal file
62
app/Models/Cloudflare/AccountModel.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use CodeIgniter\Model;
|
||||
use stdClass;
|
||||
|
||||
class AccountModel extends Model
|
||||
{
|
||||
protected $table = 'cloudflareaccount';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $returnType = AccountEntity::class; //object,array,entity명::class
|
||||
protected $allowedFields = ['uid', 'email', 'key', 'oldkey', 'type', 'status', 'updated_at', 'created_at'];
|
||||
protected $useTimestamps = true;
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'email';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
{
|
||||
switch ($field) {
|
||||
case "email":
|
||||
$rules[$field] = "required|valid_emailvalid_email|is_unique[account.email]";
|
||||
break;
|
||||
case "key":
|
||||
$rules[$field] = "required|trim|smin_length[10]|max_length[200]";
|
||||
break;
|
||||
case "oldkey":
|
||||
$rules[$field] = "if_exist|trim|smin_length[10]|max_length[200]";
|
||||
break;
|
||||
case "type":
|
||||
$rules[$field] = "if_exist|trim|string";
|
||||
break;
|
||||
default:
|
||||
$rules = parent::getFieldRule($field, $rules);
|
||||
break;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
public function getEntityByPK(int $uid): null | AccountEntity
|
||||
{
|
||||
$this->where($this->getPKField(), $uid);
|
||||
return $this->getEntity();
|
||||
}
|
||||
public function getEntityByID(string $id): null | AccountEntity
|
||||
{
|
||||
$this->where($this->getTitleField(), $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
//create용
|
||||
public function create(array $formDatas = []): AccountEntity
|
||||
{
|
||||
return $this->create_process(new AccountEntity(), $formDatas);
|
||||
}
|
||||
//modify용
|
||||
public function modify(AccountEntity $entity, array $formDatas): AccountEntity
|
||||
{
|
||||
return $this->modify_process($entity, $formDatas);
|
||||
}
|
||||
}
|
||||
93
app/Models/Cloudflare/FirewallModel.php
Normal file
93
app/Models/Cloudflare/FirewallModel.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\API\ZoneEntity;
|
||||
use App\Entities\Cloudflare\API\FirewallEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class FirewallModel extends Model
|
||||
{
|
||||
const PARENT_FIELD = "zone_uid";
|
||||
protected $DBGroup = "default";
|
||||
protected $table = "cloudflarefirewall";
|
||||
protected $primaryKey = "uid";
|
||||
protected $useAutoIncrement = false;
|
||||
protected $insertID = 0;
|
||||
protected $returnType = "array"; //object,array,entity명::class
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = ["uid", "zone_uid", "description", "filter_id", "filter_expression", "filter_paused", "paused", "action", "updated_at", "crated_at"];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = "datetime";
|
||||
protected $createdField = "created_at";
|
||||
protected $updatedField = "updated_at";
|
||||
protected $deletedField = "deleted_at";
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
"uid" => "if_exist|min_length[10]|max_length[200]",
|
||||
"zone_uid" => "if_exist|min_length[10]|max_length[200]",
|
||||
"description" => "if_exist|string",
|
||||
"filter_id" => "if_exist|min_length[10]|max_length[200]",
|
||||
"filter_expression" => "if_exist|string",
|
||||
"filter_paused" => "if_exist|in_list[on,off]",
|
||||
"paused" => "if_exist|in_list[on,off]",
|
||||
"action" => "if_exist|string",
|
||||
"updated_at" => "if_exist|valid_date",
|
||||
"created_at" => "if_exist|valid_date",
|
||||
];
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = true;
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = [];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = [];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getEntity(string $uid): FirewallEntity
|
||||
{
|
||||
$entity = $this->asObject(FirewallEntity::class)->where("uid", $uid)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
public function getEntitys(array $wheres)
|
||||
{
|
||||
return $this->asObject(FirewallEntity::class)->where($wheres)->findAll();
|
||||
}
|
||||
public function getEntitysByZone(ZoneEntity $zone)
|
||||
{
|
||||
return $this->getEntitys([self::PARENT_FIELD, $zone->getPrimaryKey()]);
|
||||
}
|
||||
|
||||
//Index 검색용
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
$this->like("description", $word, "both"); //befor , after , both
|
||||
}
|
||||
public function setIndexDateFilter($start, $end)
|
||||
{
|
||||
$this->where("created_at >=", $start);
|
||||
$this->where("created_at <=", $end);
|
||||
}
|
||||
public function setIndexOrderBy($field, $order = "ASC")
|
||||
{
|
||||
$this->orderBy("zone_uid ASC, description ASC, {$field} {$order}");
|
||||
}
|
||||
}
|
||||
115
app/Models/Cloudflare/RecordModel.php
Normal file
115
app/Models/Cloudflare/RecordModel.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\API\ZoneEntity;
|
||||
use App\Entities\Cloudflare\API\RecordEntity;
|
||||
use App\Libraries\Log\Log;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class RecordModel extends Model
|
||||
{
|
||||
const PARENT_FIELD = "zone_uid";
|
||||
protected $DBGroup = 'default';
|
||||
protected $table = 'cloudflarerecord';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = false;
|
||||
protected $insertID = 0;
|
||||
protected $returnType = 'array'; //object,array,entity명::class
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = ['uid', 'zone_uid', 'type', 'host', 'content', 'ttl', 'proxiable', 'proxied', 'fixed', 'locked', 'updated_at', 'crated_at'];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'zone_uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'host' => 'if_exist|string',
|
||||
'content' => 'if_exist|string',
|
||||
'type' => 'if_exist|string',
|
||||
'ttl' => 'if_exist|numeric',
|
||||
'proxiable' => 'if_exist|in_list[on,off]',
|
||||
'proxied' => 'if_exist|in_list[on,off]',
|
||||
'fixed' => 'if_exist|in_list[on,off]',
|
||||
'locked' => 'if_exist|in_list[on,off]',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = true;
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = [];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = [];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getEntity(string $uid): RecordEntity
|
||||
{
|
||||
$entity = $this->asObject(RecordEntity::class)->where('uid', $uid)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
public function getEntitys(array $wheres)
|
||||
{
|
||||
return $this->asObject(RecordEntity::class)->where($wheres)->findAll();
|
||||
}
|
||||
public function getEntitysByZone(ZoneEntity $zone)
|
||||
{
|
||||
return $this->getEntitys([self::PARENT_FIELD => $zone->getPrimaryKey()]);
|
||||
}
|
||||
|
||||
//Index 검색어용
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
$this->like('host', $word, 'before'); //befor , after , both
|
||||
$this->orWhere('content', $word);
|
||||
}
|
||||
public function setIndexDateFilter($start, $end)
|
||||
{
|
||||
$this->where('created_at >=', $start);
|
||||
$this->where('created_at <=', $end);
|
||||
}
|
||||
public function setIndexOrderBy($field, $order = 'ASC')
|
||||
{
|
||||
$this->orderBy("zone_uid ASC, host ASC, {$field} {$order}");
|
||||
}
|
||||
|
||||
//도메인이 이미 존재하는지 체크
|
||||
public function isUniqueHost($zone_uid, string $host, string $content): bool
|
||||
{
|
||||
$this->where('zone_uid', $zone_uid);
|
||||
$this->where('host', $host);
|
||||
$this->where('content', $content);
|
||||
return is_null($this->first()) ? true : false;
|
||||
}
|
||||
|
||||
//CDN값 수정 못하는 고정 Record 처리
|
||||
public function setFixedCDNRecord(array $hosts)
|
||||
{
|
||||
if (count($hosts)) {
|
||||
$this->whereIn('host', $hosts)->set(['fixed' => 'on'])->update();
|
||||
Log::add("notice", "-----set fixed Records " . implode(",", $hosts) . "처리 완료-----");
|
||||
}
|
||||
}
|
||||
}
|
||||
101
app/Models/Cloudflare/ZoneModel.php
Normal file
101
app/Models/Cloudflare/ZoneModel.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare\API;
|
||||
|
||||
use App\Entities\Cloudflare\API\ZoneEntity;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ZoneModel extends Model
|
||||
{
|
||||
const PARENT_FIELD = "account_uid";
|
||||
protected $DBGroup = 'default';
|
||||
protected $table = 'cloudflarezone';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $useAutoIncrement = false;
|
||||
protected $insertID = 0;
|
||||
protected $returnType = 'array'; //object,array,entity명::class
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = ['uid', 'account_uid', 'uid', 'domain', 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'crated_at'];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
protected $deletedField = 'deleted_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'account_uid' => 'if_exist|min_length[10]|max_length[200]',
|
||||
'domain' => 'if_exist|string',
|
||||
'name_servers' => 'if_exist|string',
|
||||
'plan' => 'if_exist|string',
|
||||
'development_mode' => 'if_exist|in_list[on,off]',
|
||||
'ipv6' => 'if_exist|in_list[on,off]',
|
||||
'security_level' => 'if_exist|string',
|
||||
'status' => 'if_exist|string',
|
||||
'updated_at' => 'if_exist|valid_date',
|
||||
'created_at' => 'if_exist|valid_date',
|
||||
];
|
||||
// 'security_level' => 'if_exist|in_list[essentially_off,low,medium,under_attack]',
|
||||
// 'status' => 'if_exist|in_list[active,pending]',
|
||||
protected $validationMessages = [];
|
||||
protected $skipValidation = true;
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
// Callbacks
|
||||
protected $allowCallbacks = true;
|
||||
protected $beforeInsert = [];
|
||||
protected $afterInsert = [];
|
||||
protected $beforeUpdate = [];
|
||||
protected $afterUpdate = [];
|
||||
protected $beforeFind = [];
|
||||
protected $afterFind = [];
|
||||
protected $beforeDelete = [];
|
||||
protected $afterDelete = [];
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getEntity(string $uid): ZoneEntity
|
||||
{
|
||||
$entity = $this->asObject(ZoneEntity::class)->where('uid', $uid)->first();
|
||||
if (is_null($entity)) {
|
||||
throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
public function getEntitys(array $wheres)
|
||||
{
|
||||
return $this->asObject(ZoneEntity::class)->where($wheres)->findAll();
|
||||
}
|
||||
|
||||
//Index 검색용
|
||||
public function setIndexWordFilter(string $word)
|
||||
{
|
||||
$subquery = $this->db->table('cloudflarerecord')->select('zone_uid')->like('content', $word, 'both');
|
||||
$this->like('domain', $word, 'both'); //befor , after , both
|
||||
$this->orWhereIn('uid', $subquery);
|
||||
}
|
||||
public function setIndexDateFilter($start, $end)
|
||||
{
|
||||
$this->where('created_at >=', $start);
|
||||
$this->where('created_at <=', $end);
|
||||
}
|
||||
public function setIndexOrderBy($field, $order = 'ASC')
|
||||
{
|
||||
$this->orderBy("domain ASC, {$field} {$order}");
|
||||
}
|
||||
|
||||
//도메인이 이미 존재하는지 체크
|
||||
public function isUniqueDomain(string $account_uid, string $domain): bool
|
||||
{
|
||||
$this->where('account_uid', $account_uid);
|
||||
$this->where('domain', $domain);
|
||||
return is_null($this->first()) ? true : false;
|
||||
}
|
||||
}
|
||||
@ -83,15 +83,11 @@ abstract class CommonModel extends Model
|
||||
);
|
||||
return $allowedFields;
|
||||
}
|
||||
final public function getFieldRules(array $fields, array $rules = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$rules = $this->getFieldRule($field, $rules);
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
{
|
||||
if (is_array($field)) {
|
||||
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
|
||||
}
|
||||
switch ($field) {
|
||||
case $this->getPKField():
|
||||
//수동입력인경우
|
||||
@ -117,6 +113,9 @@ abstract class CommonModel extends Model
|
||||
case 'image':
|
||||
$rules[$field] = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
|
||||
break;
|
||||
case "status":
|
||||
$rules[$field] = "if_exist|in_list[use,unuse]";
|
||||
break;
|
||||
case "updated_at":
|
||||
case "created_at":
|
||||
case "deleted_at":
|
||||
@ -128,7 +127,13 @@ abstract class CommonModel extends Model
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
final public function getFieldRules(array $fields, array $rules = []): array
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$rules = $this->getFieldRule($field, $rules);
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
final public function getEntity(): array|object|null
|
||||
{
|
||||
return $this->asObject($this->returnType)->first();
|
||||
|
||||
@ -133,7 +133,7 @@ class BoardModel extends CommonModel
|
||||
}
|
||||
public function getEntityByID(string $id): null | BoardEntity
|
||||
{
|
||||
$this->where('user_id', $id);
|
||||
$this->where($this->getTitleField(), $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ class BoardsModel extends CommonModel
|
||||
}
|
||||
public function getTitleField(): string
|
||||
{
|
||||
return 'title';
|
||||
return 'board_name';
|
||||
}
|
||||
public function getFieldRule(string $field, array $rules): array
|
||||
{
|
||||
@ -124,9 +124,9 @@ class BoardsModel extends CommonModel
|
||||
$this->where($this->getPKField(), $uid);
|
||||
return $this->getEntity();
|
||||
}
|
||||
public function getEntityByID(string $board_name): null | BoardsEntity
|
||||
public function getEntityByID(string $id): null | BoardsEntity
|
||||
{
|
||||
$this->where('board_name', $board_name);
|
||||
$this->where($this->getTitleField(), $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
|
||||
@ -101,7 +101,7 @@ class FileModel extends CommonModel
|
||||
}
|
||||
public function getEntityByID(string $id): null | FileEntity
|
||||
{
|
||||
$this->where('user_id', $id);
|
||||
$this->where($this->getTitleField(), $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user