Skip to content

Commit

Permalink
update & optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezax5 committed May 28, 2023
1 parent e2bb91d commit d300a1b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
59 changes: 53 additions & 6 deletions src/Panel/Alireza0.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@ class Alireza0 extends Base
{
use Additions;

protected $path = [
'login' => '/login',
'status' => '/server/status',
'getConfigJson' => '/server/getConfigJson',
'getDb' => '/server/getDb',
'getNewX25519Cert' => '/server/getNewX25519Cert',
'restartXrayService' => '/server/restartXrayService',
'stopXrayService' => '/server/stopXrayService',
'getXrayVersion' => '/server/getXrayVersion',
'installXray' => '/server/installXray/{id}',
'logs' => '/server/logs',
'restartPanel' => '/setting/restartPanel',
'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',
'addClient' => '/xui/inbound/addClient/',
'delClient' => '/xui/inbound/delClient/{id}',
'resetClientTraffic' => '/xui/inbound/{id}/resetClientTraffic/{client}',
'updateClient' => '/xui/inbound/updateClient/{id}',
'clientIps' => '/xui/inbound/clientIps/{id}',
'clearClientIps' => '/xui/clearClientIps/{id}',
'api_list' => '/xui/API/inbounds/list/',
'api_get' => '/xui/API/inbounds/get/{id}',
'api_resetAllClientTraffics' => '/xui/API/inbounds/resetAllClientTraffics/{id}',
'api_delDepletedClients' => '/xui/API/inbounds/delDepletedClients/{id}',
'api_getClientTraffics' => '/xui/API/inbounds/getClientTraffics/{id}',
];
protected $endpointWithId = ['delInbound', 'inbound', 'updateInbound', 'installXray', 'updateClient', 'clientIps', 'clearClientIps', 'api_get', 'api_resetAllClientTraffics', 'api_delDepletedClients', 'api_getClientTraffics'];

public function updateSetting($webPort, $webCertFile, $webKeyFile, $webBasePath, $xrayTemplateConfig, bool $tgBotEnable = false, $tgExpireDiff = 0, $tgTrafficDiff = 0, $tgCpu = 0, string $tgBotToken = null, $tgBotChatId = null, $tgRunTime = '@daily', $tgBotBackup = false, $timeLocation = 'Asia/Tehran', $webListen = '')
{
$com = compact('webPort', 'webCertFile', 'webKeyFile', 'webBasePath', 'xrayTemplateConfig', 'tgBotEnable', 'tgExpireDiff', 'tgTrafficDiff', 'tgCpu', 'tgBotToken', 'tgBotChatId', 'tgRunTime', 'timeLocation', 'webListen', 'tgBotBackup');
Expand Down Expand Up @@ -313,6 +347,19 @@ public function resetClientTraffic($id, $client)
return $this->curl('resetClientTraffic');
}

public function resetClientTrafficByUuid($id, $uuid)
{
$list = $this->list(['id' => $id])[0];
$protocol = $list['protocol'];
$settings = json_decode($list["settings"], true);
$cIndex = $this->getClientIndex($settings['clients'], $uuid);
if ($cIndex === false)
return false;
$this->setId($id);
$this->setClient($settings['clients'][$cIndex]['email']);
return $this->curl('resetClientTraffic');
}

public function delClient($id, $client)
{
$this->setId($id);
Expand All @@ -334,25 +381,25 @@ public function logs()

public function getListsApi()
{
return $this->curl('apiMHSanaei_list', [], false);
return $this->curl('api_list', [], false);
}

public function getApi($id)
{
$this->setId($id);
return $this->curl('apiMHSanaei_get', [], false);
return $this->curl('api_get', [], false);
}

public function resetAllClientTrafficsApi($id)
{
$this->setId($id);
return $this->curl('apiMHSanaei_resetAllClientTraffics', []);
return $this->curl('api_resetAllClientTraffics', []);
}

public function delDepletedClientsApi($id)
{
$this->setId($id);
return $this->curl('apiMHSanaei_delDepletedClients', []);
return $this->curl('api_delDepletedClients', []);
}

public function delAllDepletedClientsApi()
Expand All @@ -374,10 +421,10 @@ public function getConfigJson()
public function getClientTraffics($email)
{
$this->setId($email);
return $this->curl('apiMHSanaei_getClientTraffics', []);
return $this->curl('api_getClientTraffics', []);
}

public function getNewX25519Cert($email)
public function getNewX25519Cert()
{
return $this->curl('getNewX25519Cert', []);
}
Expand Down
23 changes: 12 additions & 11 deletions src/Panel/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,19 @@ class Base
'updateClient' => '/xui/inbound/updateClient/{id}',
'clientIps' => '/xui/inbound/clientIps/{id}',
'clearClientIps' => '/xui/clearClientIps/{id}',
'apiMHSanaei_list' => '/xui/API/inbounds/list/',
'apiMHSanaei_get' => '/xui/API/inbounds/get/{id}',
'apiMHSanaei_resetAllClientTraffics' => '/xui/API/inbounds/resetAllClientTraffics/{id}',
'apiMHSanaei_delDepletedClients' => '/xui/API/inbounds/delDepletedClients/{id}',
'apiMHSanaei_getClientTraffics' => '/xui/API/inbounds/getClientTraffics/{id}',
];
protected $defaults = [
'sniffing' => [
"enabled" => true,
"destOverride" => [
"http",
"tls"
"tls",
"quic"
]
],
];
protected $endpointWithId = ['delInbound', 'inbound', 'updateInbound', 'installXray', 'updateClient', 'clientIps', 'clearClientIps'];
protected $endpointWithClient = ['resetClientTraffic', 'delClient'];

public function __construct($url, $username, $password)
{
Expand Down Expand Up @@ -110,17 +108,16 @@ protected function getUrl($path): string

if (isset($this->path[$path])) {
$urlPath = $this->path[$path];
$arrPath = ['delInbound', 'inbound', 'updateInbound', 'installXray', 'updateClient', 'clientIps', 'clearClientIps', 'apiMHSanaei_get', 'apiMHSanaei_resetAllClientTraffics', 'apiMHSanaei_delDepletedClients', 'apiMHSanaei_getClientTraffics'];
$arrPathWithClient = ['resetClientTraffic', 'delClient'];
if (in_array($path, $arrPath)) {
if (in_array($path, $this->endpointWithId)) {
$urlPath = strtr($this->path[$path], ['{id}' => $this->getId()]);
}
if (in_array($path, $arrPathWithClient)) {
if (in_array($path, $this->endpointWithClient)) {
$urlPath = strtr($this->path[$path], ['{id}' => $this->getId(), '{client}' => $this->getClient()]);
}
return $this->url . $urlPath;
}


return $this->url;
}

Expand All @@ -145,7 +142,9 @@ protected function initCookieFile()

protected function resetCookieFile()
{
unlink($this->cookie);
if ($this->checkCookieFile())
unlink($this->cookie);

$this->initCookieFile();
return $this;
}
Expand Down Expand Up @@ -299,6 +298,8 @@ public function editClientByEmailWithKey($inboundId, $clientEmail, $key, $value)
return false;
if (isset($settings['clients'][$cIndex][$key]))
$settings['clients'][$cIndex][$key] = $value;

print_r($settings['clients'][$cIndex][$key]);
$streamSettings = json_decode($list['streamSettings']);
$up = $list['up'];
$down = $list['down'];
Expand Down
15 changes: 14 additions & 1 deletion src/Panel/MHSanaei.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MHSanaei extends Base
'updateSetting' => '/panel/setting/update',
'updateUser' => '/panel/setting/updateUser',
];
protected $endpointWithId = ['delInbound', 'inbound', 'updateInbound', 'installXray', 'updateClient', 'clientIps', 'clearClientIps', 'api_get', 'api_resetAllClientTraffics', 'api_delDepletedClients', 'api_getClientTraffics'];

public function updateSetting($webPort, $webCertFile, $webKeyFile, $webBasePath, $xrayTemplateConfig, bool $tgBotEnable = false, $tgExpireDiff = 0, $tgTrafficDiff = 0, $tgCpu = 0, string $tgBotToken = null, $tgBotChatId = null, $tgRunTime = '@daily', $tgBotBackup = false, $tgLang = 'fa_IR', $secretEnable = false, $subEnable = false, $subListen = '', $subPort = '2096', $subPath = 'sub/', $subDomain = '', $subCertFile = '', $subKeyFile = '', $subUpdates = '12', $timeLocation = 'Asia/Tehran', $webListen = '')
{
Expand Down Expand Up @@ -350,6 +351,18 @@ public function resetClientTraffic($id, $client)
$this->setClient($client);
return $this->curl('resetClientTraffic');
}
public function resetClientTrafficByUuid($id, $uuid)
{
$list = $this->list(['id' => $id])[0];
$protocol = $list['protocol'];
$settings = json_decode($list["settings"], true);
$cIndex = $this->getClientIndex($settings['clients'], $uuid);
if ($cIndex === false)
return false;
$this->setId($id);
$this->setClient($settings['clients'][$cIndex]['email']);
return $this->curl('resetClientTraffic');
}

public function delClient($id, $client)
{
Expand Down Expand Up @@ -408,7 +421,7 @@ public function getClientTraffics($email)
return $this->curl('api_getClientTraffics', []);
}

public function getNewX25519Cert($email)
public function getNewX25519Cert()
{
return $this->curl('getNewX25519Cert', []);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Traits/Additions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public function editClientExpiryTimeByEmail($id, $email, $expiryTime = 0)
$expiryTime = $list['expiryTime'];
$listen = $list['listen'];
$total = $list['total'];


return $this->editInbound($enable, $id, $remark, $port, $protocol, $settings, $streamSettings, $total, $up, $down, $sniffing, $expiryTime, $listen);
}

Expand Down

0 comments on commit d300a1b

Please sign in to comment.