File manager - Edit - /usr/local/cpanel/base/frontend/jupiter/cpguard/classes/api.class.php
Back
<?php class Api { private $user = NULL; private $api_url = 'https://localhost:9098/api/local.php'; public ?int $curl_status = null; public function __construct($current_user) { $this->user = $current_user; } public function request($action, $data = []) { // The data you want to process $payload = [ 'method' => $action, 'user' => $this->user, 'data' => $data ]; // Path to your compiled Go binary $binaryPath = '/opt/cpguard/app/cpg-bridge'; $descriptors = [ 0 => ['pipe', 'r'], // STDIN 1 => ['pipe', 'w'], // STDOUT 2 => ['pipe', 'w'] // STDERR ]; $process = proc_open($binaryPath, $descriptors, $pipes); if (is_resource($process)) { fwrite($pipes[0], json_encode($payload)); fclose($pipes[0]); $response = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $exitCode = proc_close($process); if ($exitCode === 0) { $response = json_decode($response, true); if (isset($response['response'])) { return $response['response']; } else { throw new Exception("API response error"); } } } throw new Exception("Failed to communicate with API" . (isset($exitCode) ? ": E$exitCode" : "")); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings