cfmgrv4 add-webhook..1
This commit is contained in:
parent
0865382eb6
commit
c650737faa
@ -25,6 +25,9 @@ $routes->get('/', 'Home::index');
|
||||
$routes->group('/RSSFeed', function ($routes) {
|
||||
$routes->get('getITWorld', 'RSSFeedController::getITWorld');
|
||||
});
|
||||
$routes->group('/Webhook', function ($routes) {
|
||||
$routes->post('Cloudflare', 'WebhookController::cludflare');
|
||||
});
|
||||
$routes->group('/user', function ($routes) {
|
||||
$routes->get('login', 'UserController::login_form');
|
||||
$routes->post('login', 'UserController::login');
|
||||
|
||||
46
app/Controllers/WebhookController.php
Normal file
46
app/Controllers/WebhookController.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class WebhookController extends CommonController
|
||||
{
|
||||
public function cloudflare()
|
||||
{
|
||||
// POST 데이터 받기
|
||||
$jsonData = $this->request->getJSON();
|
||||
|
||||
if (empty($jsonData)) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid JSON data'
|
||||
]);
|
||||
}
|
||||
|
||||
// 현재 시간 추가
|
||||
$logData = [
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'data' => $jsonData
|
||||
];
|
||||
|
||||
// 파일 경로 설정
|
||||
$filePath = WRITEPATH . 'webhook.txt';
|
||||
|
||||
// 데이터를 JSON 형식으로 변환하고 새 줄 문자 추가
|
||||
$logEntry = json_encode($logData, JSON_PRETTY_PRINT) . "\n---\n";
|
||||
|
||||
// 파일에 데이터 추가
|
||||
if (file_put_contents($filePath, $logEntry, FILE_APPEND) === false) {
|
||||
return $this->response->setStatusCode(500)->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to write to file'
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Webhook data logged successfully'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user