This commit is contained in:
root 2019-12-10 09:53:34 +08:00
parent 80f902f7d0
commit 05e2ae94aa
3 changed files with 68 additions and 14 deletions

View File

@ -11,6 +11,10 @@ use App\Utils\Helper;
class AppController extends Controller
{
CONST CLIENT_CONFIG = '{"policy":{"levels":{"0":{"uplinkOnly":0}}},"dns":{"servers":["1.1.1.1"]},"outboundDetour":[{"protocol":"freedom","tag":"direct","settings":{}}],"inbound":{"listen":"0.0.0.0","port":31211,"protocol":"socks","settings":{"auth":"noauth","udp":true,"ip":"127.0.0.1"}},"inboundDetour":[{"listen":"0.0.0.0","allocate":{"strategy":"always","refresh":5,"concurrency":3},"port":31210,"protocol":"http","tag":"httpDetour","domainOverride":["http","tls"],"streamSettings":{},"settings":{"timeout":0}}],"routing":{"strategy":"rules","settings":{"domainStrategy":"IPIfNonMatch","rules":[{"port":"1-52","type":"field","outboundTag":"direct"},{"port":"54-79","type":"field","outboundTag":"direct"},{"port":"81-442","type":"field","outboundTag":"direct"},{"port":"444-65535","type":"field","outboundTag":"direct"},{"type":"field","ip":["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","::1/128","fc00::/7","fe80::/10"],"outboundTag":"direct"}]}},"outbound":{"sendThrough":"0.0.0.0","mux":{"enabled":false,"concurrency":8},"protocol":"vmess","settings":{"vnext":[{"address":"server","port":443,"users":[{"id":"uuid","alterId":2,"security":"auto","level":0}],"remark":"remark"}]},"streamSettings":{"network":"tcp","tcpSettings":{"header":{"type":"none"}},"security":"none","tlsSettings":{"allowInsecure":false},"kcpSettings":{"header":{"type":"none"},"mtu":1350,"congestion":false,"tti":20,"uplinkCapacity":5,"writeBufferSize":1,"readBufferSize":1,"downlinkCapacity":20},"wsSettings":{"path":"","headers":{"Host":"server.cc"}}}}}';
CONST SOCKS_PORT = 10010;
CONST HTTP_PORT = 10011;
public function data (Request $request) {
$user = $request->user;
$nodes = [];
@ -35,8 +39,57 @@ class AppController extends Controller
'u' => $user->u,
'd' => $user->d,
'transfer_enable' => $user->transfer_enable,
'expired_time' => $user->expired_at
'expired_time' => $user->expired_at,
'plan' => isset($user['plan']) ? $user['plan'] : false
]
]);
}
public function config (Request $request) {
if (empty($request->input('server_id'))) {
abort(500, '参数错误');
}
$user = $request->user;
if ($user->expired_at < time()) {
abort(500, '订阅计划已过期');
}
$server = Server::where('show', 1)
->where('id', $request->input('server_id'))
->first();
if (!$server) {
abort(500, '服务器不存在');
}
$json = json_decode(self::CLIENT_CONFIG);
//socks
$json->inbound->port = (int)self::SOCKS_PORT;
//http
$json->inboundDetour[0]->port = (int)self::HTTP_PORT;
//other
$json->outbound->settings->vnext[0]->address = (string)$server->host;
$json->outbound->settings->vnext[0]->port = (int)$server->port;
$json->outbound->settings->vnext[0]->users[0]->id = (string)$user->v2ray_uuid;
$json->outbound->settings->vnext[0]->users[0]->alterId = (int)$user->v2ray_alter_id;
$json->outbound->settings->vnext[0]->remark = (string)$server->name;
$json->outbound->streamSettings->network = $server->network;
if ($server->settings) {
switch ($server->network) {
case 'tcp': $json->outbound->streamSettings->tcpSettings = json_decode($server->settings);
break;
case 'kcp': $json->outbound->streamSettings->kcpSettings = json_decode($server->settings);
break;
case 'ws': $json->outbound->streamSettings->wsSettings = json_decode($server->settings);
break;
case 'http': $json->outbound->streamSettings->httpSettings = json_decode($server->settings);
break;
case 'domainsocket': $json->outbound->streamSettings->dsSettings = json_decode($server->settings);
break;
case 'quic': $json->outbound->streamSettings->quicSettings = json_decode($server->settings);
break;
}
}
if ($server->tls) {
$json->outbound->streamSettings->security = "tls";
}
die(json_encode($json, JSON_UNESCAPED_UNICODE));
}
}

View File

@ -96,32 +96,32 @@ class DeepbworkController extends Controller
$nodeId = $request->input('node_id');
$localPort = $request->input('local_port');
$server = Server::find($nodeId);
$jsonData = json_decode(self::SERVER_CONFIG);
$jsonData->inboundDetour[0]->port = (int)$localPort;
$jsonData->inbound->port = (int)$server->server_port;
$jsonData->inbound->streamSettings->network = $server->network;
$json = json_decode(self::SERVER_CONFIG);
$json->inboundDetour[0]->port = (int)$localPort;
$json->inbound->port = (int)$server->server_port;
$json->inbound->streamSettings->network = $server->network;
if ($server->settings) {
switch ($server->network) {
case 'tcp': $jsonData->inbound->streamSettings->tcpSettings = json_decode($server->settings);
case 'tcp': $json->inbound->streamSettings->tcpSettings = json_decode($server->settings);
break;
case 'kcp': $jsonData->inbound->streamSettings->kcpSettings = json_decode($server->settings);
case 'kcp': $json->inbound->streamSettings->kcpSettings = json_decode($server->settings);
break;
case 'ws': $jsonData->inbound->streamSettings->wsSettings = json_decode($server->settings);
case 'ws': $json->inbound->streamSettings->wsSettings = json_decode($server->settings);
break;
case 'http': $jsonData->inbound->streamSettings->httpSettings = json_decode($server->settings);
case 'http': $json->inbound->streamSettings->httpSettings = json_decode($server->settings);
break;
case 'domainsocket': $jsonData->inbound->streamSettings->dsSettings = json_decode($server->settings);
case 'domainsocket': $json->inbound->streamSettings->dsSettings = json_decode($server->settings);
break;
case 'quic': $jsonData->inbound->streamSettings->quicSettings = json_decode($server->settings);
case 'quic': $json->inbound->streamSettings->quicSettings = json_decode($server->settings);
break;
}
}
if ((int)$server->tls) {
$jsonData->inbound->streamSettings->security = "tls";
$json->inbound->streamSettings->security = "tls";
$tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");
$jsonData->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
$json->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
}
die(json_encode($jsonData, JSON_UNESCAPED_UNICODE));
die(json_encode($json, JSON_UNESCAPED_UNICODE));
}
}

View File

@ -104,6 +104,7 @@ Route::prefix('v1')
Route::get ('subscribe', 'ClientController@subscribe');
// App
Route::get ('app/data', 'AppController@data');
Route::get ('app/config', 'AppController@config');
});
// Server
Route::prefix('server')