Xboard/app/Protocols/Shadowsocks.php

68 lines
1.8 KiB
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Protocols;
2025-01-21 01:57:54 -05:00
use App\Contracts\ProtocolInterface;
class Shadowsocks implements ProtocolInterface
2023-11-17 01:44:01 -05:00
{
2025-01-21 01:57:54 -05:00
public $flags = ['shadowsocks'];
2023-11-17 01:44:01 -05:00
private $servers;
private $user;
public function __construct($user, $servers)
{
$this->user = $user;
$this->servers = $servers;
}
2025-01-21 01:57:54 -05:00
public function getFlags(): array
{
return $this->flags;
}
2023-11-17 01:44:01 -05:00
public function handle()
{
$servers = $this->servers;
$user = $this->user;
$configs = [];
$subs = [];
$subs['servers'] = [];
$subs['bytes_used'] = '';
$subs['bytes_remaining'] = '';
$bytesUsed = $user['u'] + $user['d'];
$bytesRemaining = $user['transfer_enable'] - $bytesUsed;
foreach ($servers as $item) {
2025-01-21 01:57:54 -05:00
if (
$item['type'] === 'shadowsocks'
&& in_array(data_get($item, 'protocol_settings.cipher'), ['aes-128-gcm', 'aes-256-gcm', 'aes-192-gcm', 'chacha20-ietf-poly1305'])
2023-11-17 01:44:01 -05:00
) {
array_push($configs, self::SIP008($item, $user));
}
}
$subs['version'] = 1;
$subs['bytes_used'] = $bytesUsed;
$subs['bytes_remaining'] = $bytesRemaining;
$subs['servers'] = array_merge($subs['servers'] ? $subs['servers'] : [], $configs);
2025-01-21 01:57:54 -05:00
return json_encode($subs, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
2023-11-17 01:44:01 -05:00
}
public static function SIP008($server, $user)
{
$config = [
"id" => $server['id'],
"remarks" => $server['name'],
"server" => $server['host'],
"server_port" => $server['port'],
"password" => $user['uuid'],
2025-01-21 01:57:54 -05:00
"method" => data_get($server, 'protocol_settings.cipher')
2023-11-17 01:44:01 -05:00
];
return $config;
}
}