From c632903c5c5a140b2f007f396dede8570c142d10 Mon Sep 17 00:00:00 2001 From: alireza x5 Date: Wed, 1 Feb 2023 13:17:06 +0330 Subject: [PATCH] Support for all panels --- src/Panel/Base.php | 201 +++++++++++++++++++++++++++++++++ src/Panel/FranzKafkaYu.php | 32 ++++++ src/Panel/HexaSoftwareTech.php | 31 +++++ src/Panel/NidukaAkalanka.php | 32 ++++++ src/Panel/Vaxilu.php | 32 ++++++ 5 files changed, 328 insertions(+) create mode 100644 src/Panel/Base.php create mode 100644 src/Panel/FranzKafkaYu.php create mode 100644 src/Panel/HexaSoftwareTech.php create mode 100644 src/Panel/NidukaAkalanka.php create mode 100644 src/Panel/Vaxilu.php diff --git a/src/Panel/Base.php b/src/Panel/Base.php new file mode 100644 index 0000000..d772b83 --- /dev/null +++ b/src/Panel/Base.php @@ -0,0 +1,201 @@ + '/login', + 'status' => '/server/status', + 'restartXrayService' => '/server/restartXrayService', + 'stopXrayService' => '/server/stopXrayService', + 'getXrayVersion' => '/server/getXrayVersion', + 'installXray' => 'server/installXray/{id}', + 'allSetting' => '/xui/setting/all', + 'updateSetting' => '/xui/setting/update', + 'updateUser' => '/xui/setting/updateUser', + 'listInbound' => '/xui/inbound/list', + 'inbound' => '/xui/inbound/get/{id}', + 'delInbound' => '/xui/inbound/del/{id}', + 'updateInbound' => '/xui/inbound/update/{id}', + 'addInbound' => '/xui/inbound/add', + ]; + protected $defaults = [ + 'sniffing' => [ + "enabled" => true, + "destOverride" => [ + "http", + "tls" + ] + ], + ]; + + public function __construct($url, $username, $password) + { + $this->url = $url; + $this->cookie = __DIR__ . DIRECTORY_SEPARATOR . "cookie.txt"; + $this->username = $username; + $this->password = $password; + } + + protected function curl($path, $body = [], $isPost = true) + { + $ch = curl_init(); + $options = [ + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_URL => $this->getUrl($path), + CURLOPT_POST => $isPost == true ? true : false, + CURLOPT_CUSTOMREQUEST => $isPost == true ? 'POST' : 'GET', + CURLOPT_POSTFIELDS => http_build_query($body), + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13', + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_COOKIEFILE => $this->getCookie(), + CURLOPT_COOKIEJAR => $this->getCookie(), + ]; + curl_setopt_array($ch, $options); + $StatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $res = curl_exec($ch); + return json_decode($res, true); + } + + protected function setId($id) + { + $this->id = $id; + return $this; + } + + protected function getId(): int + { + return $this->id; + } + + protected function getUrl($path): string + { + + if (isset($this->path[$path])) { + $urlPath = $this->path[$path]; + if ($path == 'inbound' || $path == 'delInbound' || $path == 'updateInbound' || $path == 'installXray') { + $urlPath = strtr($this->path[$path], ['{id}' => $this->getId()]); + } + return $this->url . $urlPath; + } + + return $this->url; + } + + public function setCookie($dir) + { + $this->cookie = $dir; + return $this; + } + + public function getCookie() + { + return $this->cookie; + } + + protected function initCookieFile() + { + if (!$this->checkCookieFile()) + file_put_contents($this->cookie, ''); + + return $this; + } + + protected function resetCookieFile() + { + unlink($this->cookie); + $this->initCookieFile(); + return $this; + } + + protected function checkCookieFile() + { + return file_exists($this->cookie); + } + + + protected function auth() + { + if (!$this->checkCookieFile()) { + $this->initCookieFile(); + $this->curl('login', ['username' => $this->username, 'password' => $this->password]); + } + return $this; + } + + protected function authForce() + { + $this->resetCookieFile(); + $this->curl('login', ['username' => $this->username, 'password' => $this->password]); + + return $this; + } + + + public function login($force = false) + { + if ($force == false) + $this->auth(); + else + $this->authForce(); + + return $this; + } + + public function status() + { + return $this->curl('status', [], true); + } + + public function getXrayVersion() + { + return $this->curl('getXrayVersion', [], true); + } + + public function installXray($version = 'v1.6.4') + { + $this->setId($version); + return $this->curl('installXray', compact('version'), true); + } + + public function restartXrayService() + { + return $this->curl('restartXrayService', [], true); + } + + public function stopXrayService() + { + return $this->curl('stopXrayService', [], true); + } + + public function startXrayService() + { + return $this->curl('restartXrayService', [], true); + } + + + public function listInbound() + { + return $this->curl('listInbound', [], true); + } + + public function allSetting() + { + return $this->curl('allSetting', [], true); + } + + + public function updateUser($oldUsername, $oldPassword, $newUsername, $newPassword) + { + return $this->curl('updateUser', compact('oldPassword', 'oldUsername', 'newPassword', 'newUsername'), true); + } + + public function removeInbound($id) + { + $this->setId($id); + return $this->curl('delInbound', [], true); + } +} \ No newline at end of file diff --git a/src/Panel/FranzKafkaYu.php b/src/Panel/FranzKafkaYu.php new file mode 100644 index 0000000..a21f09f --- /dev/null +++ b/src/Panel/FranzKafkaYu.php @@ -0,0 +1,32 @@ +curl('updateSetting', $com, true); + } + + public function addInbound($remark, $port, $protocol, $settings, $streamSettings, $autoreset = false, $ipalert = false, $iplimit = 0, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + return $this->curl('addInbound', compact('remark', 'port', 'protocol', 'settings', 'streamSettings', 'autoreset', 'ipalert', 'iplimit', 'sniffing', 'expiryTime', 'listen'), true); + } + + public function editInbound($enable, $id, $remark, $port, $protocol, $settings, $streamSettings, $autoreset = false, $ipalert = false, $iplimit = 0, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + $this->setId($id); + return $this->curl('updateInbound', compact('enable', 'remark', 'port', 'protocol', 'settings', 'streamSettings', 'autoreset', 'ipalert', 'iplimit', 'sniffing', 'expiryTime', 'listen'), true); + } +} \ No newline at end of file diff --git a/src/Panel/HexaSoftwareTech.php b/src/Panel/HexaSoftwareTech.php new file mode 100644 index 0000000..f5079f4 --- /dev/null +++ b/src/Panel/HexaSoftwareTech.php @@ -0,0 +1,31 @@ +curl('updateSetting', $com, true); + } + + public function addInbound($remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + return $this->curl('addInbound', compact('remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } + + public function editInbound($enable, $id, $remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + $this->setId($id); + return $this->curl('updateInbound', compact('enable', 'remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } +} \ No newline at end of file diff --git a/src/Panel/NidukaAkalanka.php b/src/Panel/NidukaAkalanka.php new file mode 100644 index 0000000..f90fae9 --- /dev/null +++ b/src/Panel/NidukaAkalanka.php @@ -0,0 +1,32 @@ +curl('updateSetting', $com, true); + } + + public function addInbound($remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + return $this->curl('addInbound', compact('remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } + + public function editInbound($enable, $id, $remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + $this->setId($id); + return $this->curl('updateInbound', compact('enable', 'remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } +} \ No newline at end of file diff --git a/src/Panel/Vaxilu.php b/src/Panel/Vaxilu.php new file mode 100644 index 0000000..8c70e58 --- /dev/null +++ b/src/Panel/Vaxilu.php @@ -0,0 +1,32 @@ +curl('updateSetting', $com, true); + } + + public function addInbound($remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + return $this->curl('addInbound', compact('remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } + + public function editInbound($enable, $id, $remark, $port, $protocol, $settings, $streamSettings, $sniffing = null, $expiryTime = 0, $listen = '') + { + $sniffing = $sniffing == null ? $this->defaults['sniffing'] : $sniffing; + $sniffing = json_encode($sniffing); + $settings = json_encode($settings); + $streamSettings = json_encode($streamSettings); + $this->setId($id); + return $this->curl('updateInbound', compact('enable', 'remark', 'port', 'protocol', 'settings', 'streamSettings', 'sniffing', 'expiryTime', 'listen'), true); + } +} \ No newline at end of file