Controllers: Implement new HTTP class in development toggle
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
use App\Classes\Config;
|
use App\Classes\Config;
|
||||||
|
use App\Classes\Http\Http;
|
||||||
use App\Model\ConfigModel;
|
use App\Model\ConfigModel;
|
||||||
|
|
||||||
class CacheController extends PageController {
|
class CacheController extends PageController {
|
||||||
@@ -15,7 +16,7 @@ class CacheController extends PageController {
|
|||||||
parent::view();
|
parent::view();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function developmentAction(): void
|
public function toggleAction(): void
|
||||||
{
|
{
|
||||||
if (Config::c('CLOUDFLARE_ENABLED') != '1') {
|
if (Config::c('CLOUDFLARE_ENABLED') != '1') {
|
||||||
return;
|
return;
|
||||||
@@ -25,34 +26,24 @@ class CacheController extends PageController {
|
|||||||
$zone = Config::c('CLOUDFLARE_ZONE');
|
$zone = Config::c('CLOUDFLARE_ZONE');
|
||||||
|
|
||||||
$url = "https://api.cloudflare.com/client/v4/zones/$zone/settings/development_mode";
|
$url = "https://api.cloudflare.com/client/v4/zones/$zone/settings/development_mode";
|
||||||
$headers = [
|
|
||||||
"Authorization: Bearer $token",
|
|
||||||
"Content-Type: application/json"
|
|
||||||
];
|
|
||||||
|
|
||||||
$config = $this->getConfigValues();
|
$config = $this->getConfigValues();
|
||||||
$currentState = $config['CLOUDFLARE_DEVELOPMENT_MODE_ENABLED'];
|
$currentState = $config['CLOUDFLARE_DEVELOPMENT_MODE_ENABLED'];
|
||||||
|
|
||||||
$newState = $currentState == '1' ? 'off' : 'on';
|
$response = (new Http)->withToken($token)
|
||||||
$data = '{"value": "' . $newState . '"}';
|
->asJson()
|
||||||
|
->acceptJson()
|
||||||
|
->patch($url, [
|
||||||
|
'value' => $currentState == '1' ? 'off' : 'on',
|
||||||
|
]);
|
||||||
|
|
||||||
$curl = curl_init();
|
$this->saveConfigValues($response->body());
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
echo $response->body();
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
// curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
|
|
||||||
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
// $info = curl_getinfo($curl, CURLINFO_HEADER_OUT);
|
|
||||||
|
|
||||||
curl_close($curl);
|
|
||||||
|
|
||||||
$this->saveConfigValues($response);
|
|
||||||
|
|
||||||
echo $response;
|
|
||||||
// echo $info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------//
|
//-------------------------------------//
|
||||||
|
|||||||
+1
-1
@@ -238,7 +238,7 @@ $(document).ready(function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.get('/admin/toggle-development-mode').done(function(data)
|
$.get('/admin/cache/toggle').done(function(data)
|
||||||
{
|
{
|
||||||
const response = JSON.parse(data);
|
const response = JSON.parse(data);
|
||||||
if (response.success == false) {
|
if (response.success == false) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ return [
|
|||||||
['/admin', 'AdminController', '', ''],
|
['/admin', 'AdminController', '', ''],
|
||||||
['/admin/cache', 'CacheController', 'cache', ''],
|
['/admin/cache', 'CacheController', 'cache', ''],
|
||||||
['/admin/toggle', 'AdminController', 'toggle', ''],
|
['/admin/toggle', 'AdminController', 'toggle', ''],
|
||||||
['/admin/toggle-development-mode', 'CacheController', 'development', ''],
|
['/admin/cache/toggle', 'CacheController', 'toggle', ''],
|
||||||
['/admin/syntax-highlighting', 'AdminController', 'syntax', ''],
|
['/admin/syntax-highlighting', 'AdminController', 'syntax', ''],
|
||||||
['/test', 'TestController', '', ''],
|
['/test', 'TestController', '', ''],
|
||||||
// ["", "", "", ""],
|
// ["", "", "", ""],
|
||||||
|
|||||||
Reference in New Issue
Block a user