mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Client\Protocols;
|
||
|
|
||
|
class Shadowsocks
|
||
|
{
|
||
|
public $flag = 'shadowsocks';
|
||
|
private $servers;
|
||
|
private $user;
|
||
|
|
||
|
public function __construct($user, $servers)
|
||
|
{
|
||
|
$this->user = $user;
|
||
|
$this->servers = $servers;
|
||
|
}
|
||
|
|
||
|
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) {
|
||
|
if ($item['type'] === 'shadowsocks') {
|
||
|
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);
|
||
|
|
||
|
return json_encode($subs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
||
|
}
|
||
|
|
||
|
public static function SIP008($server, $user)
|
||
|
{
|
||
|
$config = [
|
||
|
"id" => $server['id'],
|
||
|
"remarks" => $server['name'],
|
||
|
"server" => $server['host'],
|
||
|
"server_port" => $server['port'],
|
||
|
"password" => $user['uuid'],
|
||
|
"method" => $server['cipher']
|
||
|
];
|
||
|
return $config;
|
||
|
}
|
||
|
}
|