mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 15:10:54 +00:00
Add: Trojan & VNet Webapi Bate (Warnning: untest in real test envirnment)
1. Add: Trojan & VNet Webapi Bate; 2. Redesign V2Ray Webapi; (Warnning: untest in real test envirnment) 1. 添加:Trojan & VNet Webapi Bate版本; 2. 重新设计了 V2Ray Webapi; (警告:Webapi 均为在真实环境下 与 对应后端进行交互!本API目前只完成了在Postman 的软件下开发)
This commit is contained in:
@@ -1,333 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2Ray;
|
||||
|
||||
use App\Components\Helpers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\NodeCertificate;
|
||||
use App\Models\Rule;
|
||||
use App\Models\RuleGroup;
|
||||
use App\Models\RuleGroupNode;
|
||||
use App\Models\RuleLog;
|
||||
use App\Models\SsNode;
|
||||
use App\Models\SsNodeInfo;
|
||||
use App\Models\SsNodeIp;
|
||||
use App\Models\SsNodeOnlineLog;
|
||||
use App\Models\User;
|
||||
use App\Models\UserTrafficLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Response;
|
||||
|
||||
class V1Controller extends Controller {
|
||||
// 获取节点信息
|
||||
public function getNodeInfo($id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$nodeTls = NodeCertificate::query()->whereId($node->server)->first();
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'id' => $node->id,
|
||||
'is_udp' => $node->is_udp,
|
||||
'client_limit' => $node->client_limit,
|
||||
'push_port' => $node->push_port,
|
||||
'secret' => $node->auth->secret,
|
||||
'key' => $nodeTls? $nodeTls->key : '',
|
||||
'pem' => $nodeTls? $nodeTls->pem : '',
|
||||
'v2_license' => Helpers::systemConfig()['v2ray_license'],
|
||||
'v2_alter_id' => $node->v2_alter_id,
|
||||
'v2_port' => $node->v2_port,
|
||||
'v2_method' => $node->v2_method,
|
||||
'v2_net' => $node->v2_net,
|
||||
'v2_type' => $node->v2_type,
|
||||
'v2_host' => $node->v2_host,
|
||||
'v2_path' => $node->v2_path,
|
||||
'v2_tls' => $node->v2_tls,
|
||||
'v2_tls_provider' => $node->tls_provider,
|
||||
],
|
||||
'message' => '获取节点信息成功'
|
||||
]);
|
||||
}
|
||||
|
||||
// 上报节点心跳信息
|
||||
public function setNodeStatus(Request $request, $id) {
|
||||
$cpu = intval($request->input('cpu')) / 100;
|
||||
$mem = intval($request->input('mem')) / 100;
|
||||
$disk = intval($request->input('disk')) / 100;
|
||||
|
||||
if(is_null($request->input('uptime'))){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点心跳信息失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
|
||||
$obj = new SsNodeInfo();
|
||||
$obj->node_id = $id;
|
||||
$obj->uptime = intval($request->input('uptime'));
|
||||
//$obj->load = $request->input('load');
|
||||
$obj->load = implode(' ', [$cpu, $mem, $disk]);
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => '',
|
||||
'message' => '上报节点心跳信息成功'
|
||||
]);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点心跳信息失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
|
||||
// 上报节点在线人数
|
||||
public function setNodeOnline(Request $request, $id) {
|
||||
$inputArray = $request->all();
|
||||
$onlineCount = 0;
|
||||
foreach($inputArray as $input){
|
||||
if(!array_key_exists('ip', $input) || !array_key_exists('uid', $input)){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点在线情况失败,请检查字段'
|
||||
]);
|
||||
}elseif(!isset($input['ip']) || !isset($input['uid'])){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点在线情况失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
|
||||
$obj = new SsNodeIp();
|
||||
$obj->node_id = $id;
|
||||
$obj->user_id = $input['uid'];
|
||||
$obj->ip = $input['ip'];
|
||||
$obj->port = User::find($input['uid'])->port;
|
||||
$obj->created_at = time();
|
||||
$obj->save();
|
||||
|
||||
if(!$obj->id){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点在线情况失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
$onlineCount++;
|
||||
}
|
||||
|
||||
$obj = new SsNodeOnlineLog();
|
||||
$obj->node_id = $id;
|
||||
$obj->online_user = $onlineCount;
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => '',
|
||||
'message' => '上报节点在线情况成功'
|
||||
]);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点在线情况失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取节点可用的用户列表
|
||||
public function getUserList(Request $request, $id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
|
||||
$data = [];
|
||||
foreach($users as $user){
|
||||
$new = [
|
||||
"uid" => $user->id,
|
||||
"vmess_uid" => $user->vmess_id,
|
||||
"speed_limit" => $user->speed_limit
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
|
||||
if($data){
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => $data,
|
||||
'message' => '获取用户列表成功',
|
||||
'updateTime' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '获取用户列表失败'
|
||||
]);
|
||||
}
|
||||
|
||||
// 上报用户流量日志
|
||||
public function setUserTraffic(Request $request, $id) {
|
||||
$inputArray = $request->all();
|
||||
|
||||
foreach($inputArray as $input){
|
||||
if(!array_key_exists('uid', $input)){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报用户流量日志失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
|
||||
$rate = SsNode::find($id)->traffic_rate;
|
||||
|
||||
$obj = new UserTrafficLog();
|
||||
$obj->user_id = intval($input['uid']);
|
||||
$obj->u = intval($input['upload']) * $rate;
|
||||
$obj->d = intval($input['download']) * $rate;
|
||||
$obj->node_id = $id;
|
||||
$obj->rate = $rate;
|
||||
$obj->traffic = flowAutoShow($obj->u + $obj->d);
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if(!$obj->id){
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报用户流量日志失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => '',
|
||||
'message' => '上报用户流量日志成功'
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取节点的审计规则
|
||||
public function getNodeRule($id) {
|
||||
$nodeRule = RuleGroupNode::whereNodeId($id)->first();
|
||||
$data = [];
|
||||
//节点未设置任何审计规则
|
||||
if($nodeRule){
|
||||
$ruleGroup = RuleGroup::query()->whereId($nodeRule->rule_group_id)->first();
|
||||
if($ruleGroup){
|
||||
$rules = explode(',', $ruleGroup->rules);
|
||||
foreach($rules as $ruleId){
|
||||
$rule = Rule::query()->whereId($ruleId)->first();
|
||||
if($rule){
|
||||
$new = [
|
||||
'id' => $rule->id,
|
||||
'type' => $rule->type_api_label,
|
||||
'pattern' => $rule->pattern
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'mode' => $ruleGroup->type? 'reject' : 'allow',
|
||||
'rules' => $data
|
||||
],
|
||||
'message' => '获取节点审计规则成功'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
//放行
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'mode' => 'all',
|
||||
'rules' => $data
|
||||
],
|
||||
'message' => '获取节点审计规则成功'
|
||||
]);
|
||||
}
|
||||
|
||||
// todo: test required
|
||||
// 上报用户触发的审计规则记录
|
||||
public function addRuleLog(Request $request, $id) {
|
||||
if($request->has(['uid', 'rule_id', 'reason'])){
|
||||
$obj = new RuleLog();
|
||||
$obj->user_id = $request->input(['uid']);
|
||||
$obj->node_id = $id;
|
||||
$obj->rule_id = $request->input(['rule_id']);
|
||||
$obj->reason = $request->input(['reason']);
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => '',
|
||||
'message' => '上报用户触发审计规则记录成功'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报用户触发审计规则记录失败'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// 上报节点伪装域名证书信息
|
||||
public function addCertificate(Request $request, $id) {
|
||||
if($request->has(['key', 'pem'])){
|
||||
$node = SsNode::find($id);
|
||||
$obj = new NodeCertificate();
|
||||
$obj->domain = $node->server;
|
||||
$obj->key = $request->input(['key']);
|
||||
$obj->pem = $request->input(['pem']);
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return Response::json([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => '',
|
||||
'message' => '上报节点伪装域名证书成功'
|
||||
]);
|
||||
}
|
||||
}
|
||||
return Response::json([
|
||||
'status' => 'fail',
|
||||
'code' => 400,
|
||||
'data' => '',
|
||||
'message' => '上报节点伪装域名证书失败,请检查字段'
|
||||
]);
|
||||
}
|
||||
}
|
||||
175
app/Http/Controllers/Api/WebApi/BaseController.php
Normal file
175
app/Http/Controllers/Api/WebApi/BaseController.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\WebApi;
|
||||
|
||||
use App\Models\Rule;
|
||||
use App\Models\RuleGroup;
|
||||
use App\Models\RuleGroupNode;
|
||||
use App\Models\RuleLog;
|
||||
use App\Models\SsNode;
|
||||
use App\Models\SsNodeInfo;
|
||||
use App\Models\SsNodeIp;
|
||||
use App\Models\SsNodeOnlineLog;
|
||||
use App\Models\User;
|
||||
use App\Models\UserTrafficLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Response;
|
||||
|
||||
class BaseController {
|
||||
// 上报节点心跳信息
|
||||
public function setNodeStatus(Request $request, $id) {
|
||||
$cpu = intval($request->input('cpu')) / 100;
|
||||
$mem = intval($request->input('mem')) / 100;
|
||||
$disk = intval($request->input('disk')) / 100;
|
||||
|
||||
if(is_null($request->input('uptime'))){
|
||||
return $this->returnData('上报节点心跳信息失败,请检查字段');
|
||||
}
|
||||
|
||||
$obj = new SsNodeInfo();
|
||||
$obj->node_id = $id;
|
||||
$obj->uptime = intval($request->input('uptime'));
|
||||
//$obj->load = $request->input('load');
|
||||
$obj->load = implode(' ', [$cpu, $mem, $disk]);
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return $this->returnData('上报节点心跳信息成功', 'success', 200);
|
||||
}
|
||||
|
||||
return $this->returnData('上报节点心跳信息失败,请检查字段');
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
public function returnData($message, $status = 'fail', $code = 400, $data = '', $addition = false) {
|
||||
$data = [
|
||||
'status' => $status,
|
||||
'code' => $code,
|
||||
'data' => $data,
|
||||
'message' => $message,
|
||||
];
|
||||
|
||||
if($addition){
|
||||
$data = array_merge($data, $addition);
|
||||
}
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
// 上报节点在线人数
|
||||
public function setNodeOnline(Request $request, $id) {
|
||||
$inputArray = $request->all();
|
||||
$onlineCount = 0;
|
||||
foreach($inputArray as $input){
|
||||
if(!array_key_exists('ip', $input) || !array_key_exists('uid', $input)){
|
||||
return $this->returnData('上报节点在线情况失败,请检查字段');
|
||||
}elseif(!isset($input['ip']) || !isset($input['uid'])){
|
||||
return $this->returnData('上报节点在线情况失败,请检查字段');
|
||||
}
|
||||
|
||||
$obj = new SsNodeIp();
|
||||
$obj->node_id = $id;
|
||||
$obj->user_id = $input['uid'];
|
||||
$obj->ip = $input['ip'];
|
||||
$obj->port = User::find($input['uid'])->port;
|
||||
$obj->created_at = time();
|
||||
$obj->save();
|
||||
|
||||
if(!$obj->id){
|
||||
return $this->returnData('上报节点在线情况失败,请检查字段');
|
||||
}
|
||||
$onlineCount++;
|
||||
}
|
||||
|
||||
$obj = new SsNodeOnlineLog();
|
||||
$obj->node_id = $id;
|
||||
$obj->online_user = $onlineCount;
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return $this->returnData('上报节点在线情况成功', 'success', 200);
|
||||
}
|
||||
|
||||
return $this->returnData('上报节点在线情况失败,请检查字段');
|
||||
}
|
||||
|
||||
// 上报用户流量日志
|
||||
public function setUserTraffic(Request $request, $id) {
|
||||
$inputArray = $request->all();
|
||||
|
||||
foreach($inputArray as $input){
|
||||
if(!array_key_exists('uid', $input)){
|
||||
return $this->returnData('上报用户流量日志失败,请检查字段');
|
||||
}
|
||||
|
||||
$rate = SsNode::find($id)->traffic_rate;
|
||||
|
||||
$obj = new UserTrafficLog();
|
||||
$obj->user_id = intval($input['uid']);
|
||||
$obj->u = intval($input['upload']) * $rate;
|
||||
$obj->d = intval($input['download']) * $rate;
|
||||
$obj->node_id = $id;
|
||||
$obj->rate = $rate;
|
||||
$obj->traffic = flowAutoShow($obj->u + $obj->d);
|
||||
$obj->log_time = time();
|
||||
$obj->save();
|
||||
|
||||
if(!$obj->id){
|
||||
return $this->returnData('上报用户流量日志失败,请检查字段');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->returnData('上报用户流量日志成功', 'success', 200);
|
||||
}
|
||||
|
||||
|
||||
// 获取节点的审计规则
|
||||
public function getNodeRule($id) {
|
||||
$nodeRule = RuleGroupNode::whereNodeId($id)->first();
|
||||
$data = [];
|
||||
//节点未设置任何审计规则
|
||||
if($nodeRule){
|
||||
$ruleGroup = RuleGroup::query()->whereId($nodeRule->rule_group_id)->first();
|
||||
if($ruleGroup){
|
||||
$rules = explode(',', $ruleGroup->rules);
|
||||
foreach($rules as $ruleId){
|
||||
$rule = Rule::query()->whereId($ruleId)->first();
|
||||
if($rule){
|
||||
$new = [
|
||||
'id' => $rule->id,
|
||||
'type' => $rule->type_api_label,
|
||||
'pattern' => $rule->pattern
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->returnData('获取节点审计规则成功', 'success', 200,
|
||||
['mode' => $ruleGroup->type? 'reject' : 'allow', 'rules' => $data]);
|
||||
}
|
||||
}
|
||||
|
||||
//放行
|
||||
return $this->returnData('获取节点审计规则成功', 'success', 200, ['mode' => 'all', 'rules' => $data]);
|
||||
}
|
||||
|
||||
// 上报用户触发的审计规则记录
|
||||
public function addRuleLog(Request $request, $id) {
|
||||
if($request->has(['uid', 'rule_id', 'reason'])){
|
||||
$obj = new RuleLog();
|
||||
$obj->user_id = $request->input('uid');
|
||||
$obj->node_id = $id;
|
||||
$obj->rule_id = $request->input('rule_id');
|
||||
$obj->reason = $request->input('reason');
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return $this->returnData('上报用户触发审计规则记录成功', 'success', 200);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->returnData('上报用户触发审计规则记录失败');
|
||||
}
|
||||
}
|
||||
48
app/Http/Controllers/Api/WebApi/TrojanController.php
Normal file
48
app/Http/Controllers/Api/WebApi/TrojanController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\WebApi;
|
||||
|
||||
use App\Components\Helpers;
|
||||
use App\Models\SsNode;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrojanController extends BaseController {
|
||||
// 获取节点信息
|
||||
public function getNodeInfo($id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
|
||||
return $this->returnData('获取节点信息成功', 'success', 200, [
|
||||
'id' => $node->id,
|
||||
'is_udp' => $node->is_udp? true : false,
|
||||
'speed_limit' => $node->speed_limit,
|
||||
'client_limit' => $node->client_limit,
|
||||
'push_port' => $node->push_port,
|
||||
'trojan_port' => $node->port,
|
||||
'secret' => $node->auth->secret,
|
||||
'license' => Helpers::systemConfig()['trojan_license'],
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取节点可用的用户列表
|
||||
public function getUserList(Request $request, $id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
|
||||
$data = [];
|
||||
|
||||
foreach($users as $user){
|
||||
$new = [
|
||||
'uid' => $user->id,
|
||||
'password' => str_replace('-', '', $user->vmess_id),
|
||||
'speed_limit' => $user->speed_limit
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
|
||||
if($data){
|
||||
return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
|
||||
}
|
||||
|
||||
return $this->returnData('获取用户列表失败');
|
||||
}
|
||||
}
|
||||
78
app/Http/Controllers/Api/WebApi/V2RayController.php
Normal file
78
app/Http/Controllers/Api/WebApi/V2RayController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\WebApi;
|
||||
|
||||
use App\Components\Helpers;
|
||||
use App\Models\NodeCertificate;
|
||||
use App\Models\SsNode;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class V2RayController extends BaseController {
|
||||
// 获取节点信息
|
||||
public function getNodeInfo($id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$nodeTls = NodeCertificate::query()->whereId($node->server)->first();
|
||||
|
||||
return $this->returnData('获取节点信息成功', 'success', 200, [
|
||||
'id' => $node->id,
|
||||
'is_udp' => $node->is_udp? true : false,
|
||||
'speed_limit' => $node->speed_limit,
|
||||
'client_limit' => $node->client_limit,
|
||||
'push_port' => $node->push_port,
|
||||
'secret' => $node->auth->secret,
|
||||
'key' => $nodeTls? $nodeTls->key : '',
|
||||
'pem' => $nodeTls? $nodeTls->pem : '',
|
||||
'v2_license' => Helpers::systemConfig()['v2ray_license'],
|
||||
'v2_alter_id' => $node->v2_alter_id,
|
||||
'v2_port' => $node->v2_port,
|
||||
'v2_method' => $node->v2_method,
|
||||
'v2_net' => $node->v2_net,
|
||||
'v2_type' => $node->v2_type,
|
||||
'v2_host' => $node->v2_host,
|
||||
'v2_path' => $node->v2_path,
|
||||
'v2_tls' => $node->v2_tls? true : false,
|
||||
'v2_tls_provider' => $node->tls_provider,
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取节点可用的用户列表
|
||||
public function getUserList(Request $request, $id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
|
||||
$data = [];
|
||||
|
||||
foreach($users as $user){
|
||||
$new = [
|
||||
'uid' => $user->id,
|
||||
'vmess_uid' => $user->vmess_id,
|
||||
'speed_limit' => $user->speed_limit
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
|
||||
if($data){
|
||||
return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
|
||||
}
|
||||
|
||||
return $this->returnData('获取用户列表失败');
|
||||
}
|
||||
|
||||
// 上报节点伪装域名证书信息
|
||||
public function addCertificate(Request $request, $id) {
|
||||
if($request->has(['key', 'pem'])){
|
||||
$node = SsNode::find($id);
|
||||
$obj = new NodeCertificate();
|
||||
$obj->domain = $node->server;
|
||||
$obj->key = $request->input('key');
|
||||
$obj->pem = $request->input('pem');
|
||||
$obj->save();
|
||||
|
||||
if($obj->id){
|
||||
return $this->returnData('上报节点伪装域名证书成功', 'success', 200);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->returnData('上报节点伪装域名证书失败,请检查字段');
|
||||
}
|
||||
}
|
||||
57
app/Http/Controllers/Api/WebApi/VNetController.php
Normal file
57
app/Http/Controllers/Api/WebApi/VNetController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\WebApi;
|
||||
|
||||
use App\Models\SsNode;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VNetController extends BaseController {
|
||||
// 获取节点信息
|
||||
public function getNodeInfo($id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
|
||||
return $this->returnData('获取节点信息成功', 'success', 200, [
|
||||
'id' => $node->id,
|
||||
'method' => $node->method,
|
||||
'protocol' => $node->protocol,
|
||||
'obfs' => $node->obfs,
|
||||
'obfs_param' => $node->obfs_param,
|
||||
'is_udp' => $node->is_udp,
|
||||
'speed_limit' => $node->speed_limit,
|
||||
'client_limit' => $node->client_limit,
|
||||
'single' => $node->single,
|
||||
'port' => $node->port,
|
||||
'passwd' => $node->passwd,
|
||||
'push_port' => $node->push_port,
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取节点可用的用户列表
|
||||
public function getUserList(Request $request, $id) {
|
||||
$node = SsNode::query()->whereId($id)->first();
|
||||
$users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
|
||||
$data = [];
|
||||
|
||||
foreach($users as $user){
|
||||
$new = [
|
||||
'uid' => $user->id,
|
||||
'port' => $user->port,
|
||||
'passwd' => $user->passwd,
|
||||
'method' => $user->method,
|
||||
'protocol' => $user->protocol,
|
||||
'obfs' => $user->obfs,
|
||||
'obfs_param' => $node->obfs_param,
|
||||
'speed_limit' => $user->speed_limit,
|
||||
'enable' => $user->enable
|
||||
];
|
||||
array_push($data, $new);
|
||||
}
|
||||
|
||||
if($data){
|
||||
return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
|
||||
}
|
||||
|
||||
return $this->returnData('获取用户列表失败');
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="tls_provider" class="col-md-3 col-form-label">TLS配置</label>
|
||||
<input type="text" class="form-control col-md-9" name="tls_provider" id="tls_provider" required/>
|
||||
<input type="text" class="form-control col-md-9" name="tls_provider" id="tls_provider"/>
|
||||
<div class="text-help offset-md-3"> 不同后端配置不同:
|
||||
<a href="https://github.com/Scyllaly/docs/wiki/tls" target="_blank">VNET-V2Ray</a> 、
|
||||
<a href="https://github.com/ColetteContreras/v2ray-poseidon/wiki/020-%E5%AF%B9%E6%8E%A5-VNetPanel-%E6%95%99%E7%A8%8B#%E9%85%8D%E7%BD%AE-tls-%E8%AF%81%E4%B9%A6" target="_blank">V2Ray-Poseidon</a>
|
||||
@@ -380,7 +380,7 @@
|
||||
<script type="text/javascript">
|
||||
const string = "{{strtolower(Str::random())}}";
|
||||
$(document).ready(function () {
|
||||
const v2_path = $('#v2_path');
|
||||
let v2_path = $('#v2_path');
|
||||
|
||||
@isset($node)
|
||||
|
||||
@@ -441,6 +441,7 @@
|
||||
@if($node->v2_tls)
|
||||
$('#v2_tls').click();
|
||||
@endif
|
||||
$('#tls_provider').val('{!! $node->tls_provider !!}');
|
||||
@endif
|
||||
|
||||
@if($node->is_relay)
|
||||
@@ -500,6 +501,7 @@
|
||||
v2_host: $('#v2_host').val(),
|
||||
v2_path: $('#v2_path').val(),
|
||||
v2_tls: document.getElementById("v2_tls").checked ? 1 : 0,
|
||||
tls_provider: $('#tls_provider').val(),
|
||||
is_relay: document.getElementById("is_relay").checked ? 1 : 0,
|
||||
relay_port: $('#relay_port').val(),
|
||||
relay_server: $('#relay_server').val(),
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
<?php
|
||||
// 后端WEBAPI
|
||||
Route::group(['namespace' => 'Api\WebApi', 'middleware' => ['webApi']], function() {
|
||||
// VNet后端WEBAPI V2版
|
||||
Route::group(['prefix' => 'vnet/v2'], function() {
|
||||
Route::get('node/{id}', 'VNetController@getNodeInfo'); // 获取节点信息
|
||||
Route::post('nodeStatus/{id}', 'BaseController@setNodeStatus'); // 上报节点心跳信息
|
||||
Route::post('nodeOnline/{id}', 'BaseController@setNodeOnline'); // 上报节点在线人数
|
||||
Route::get('userList/{id}', 'VNetController@getUserList'); // 获取节点可用的用户列表
|
||||
Route::post('userTraffic/{id}', 'BaseController@setUserTraffic'); // 上报用户流量日志
|
||||
Route::get('nodeRule/{id}', 'BaseController@getNodeRule'); // 获取节点的审计规则
|
||||
Route::post('trigger/{id}', 'BaseController@addRuleLog'); // 上报用户触发的审计规则记录
|
||||
});
|
||||
|
||||
// V2Ray后端WEBAPI V1版
|
||||
Route::group(['namespace' => 'Api\V2Ray', 'middleware' => ['webApi'], 'prefix' => 'v2ray/v1'], function () {
|
||||
Route::get('node/{id}', 'V1Controller@getNodeInfo'); // 获取节点信息
|
||||
Route::post('nodeStatus/{id}', 'V1Controller@setNodeStatus'); // 上报节点心跳信息
|
||||
Route::post('nodeOnline/{id}', 'V1Controller@setNodeOnline'); // 上报节点在线人数
|
||||
Route::get('userList/{id}', 'V1Controller@getUserList'); // 获取节点可用的用户列表
|
||||
Route::post('userTraffic/{id}', 'V1Controller@setUserTraffic'); // 上报用户流量日志
|
||||
Route::get('nodeRule/{id}', 'V1Controller@getNodeRule'); // 获取节点的审计规则
|
||||
Route::post('trigger/{id}', 'V1Controller@addRuleLog'); // 上报用户触发的审计规则记录
|
||||
Route::post('certificate/{id}', 'V1Controller@addCertificate'); // 上报节点伪装域名证书信息
|
||||
});
|
||||
// V2Ray后端WEBAPI V1版
|
||||
Route::group(['prefix' => 'v2ray/v1'], function() {
|
||||
Route::get('node/{id}', 'V2RayController@getNodeInfo'); // 获取节点信息
|
||||
Route::post('nodeStatus/{id}', 'BaseController@setNodeStatus'); // 上报节点心跳信息
|
||||
Route::post('nodeOnline/{id}', 'BaseController@setNodeOnline'); // 上报节点在线人数
|
||||
Route::get('userList/{id}', 'V2RayController@getUserList'); // 获取节点可用的用户列表
|
||||
Route::post('userTraffic/{id}', 'BaseController@setUserTraffic'); // 上报用户流量日志
|
||||
Route::get('nodeRule/{id}', 'BaseController@getNodeRule'); // 获取节点的审计规则
|
||||
Route::post('trigger/{id}', 'BaseController@addRuleLog'); // 上报用户触发的审计规则记录
|
||||
Route::post('certificate/{id}', 'V2RayController@addCertificate'); // 上报节点伪装域名证书信息
|
||||
});
|
||||
|
||||
// Trojan后端WEBAPI V1版
|
||||
Route::group(['prefix' => 'trojan/v1'], function() {
|
||||
Route::get('node/{id}', 'TrojanController@getNodeInfo'); // 获取节点信息
|
||||
Route::post('nodeStatus/{id}', 'BaseController@setNodeStatus'); // 上报节点心跳信息
|
||||
Route::post('nodeOnline/{id}', 'BaseController@setNodeOnline'); // 上报节点在线人数
|
||||
Route::get('userList/{id}', 'TrojanController@getUserList'); // 获取节点可用的用户列表
|
||||
Route::post('userTraffic/{id}', 'BaseController@setUserTraffic'); // 上报用户流量日志
|
||||
Route::get('nodeRule/{id}', 'BaseController@getNodeRule'); // 获取节点的审计规则
|
||||
Route::post('trigger/{id}', 'BaseController@addRuleLog'); // 上报用户触发的审计规则记录
|
||||
});
|
||||
|
||||
// Trojan后端WEBAPI V1版
|
||||
Route::group(['namespace' => 'Api\Trojan', 'middleware' => ['webApi'], 'prefix' => 'trojan/v1'], function () {
|
||||
Route::get('node/{id}', 'V1Controller@getNodeInfo'); // 获取节点信息
|
||||
Route::post('nodeStatus/{id}', 'V1Controller@setNodeStatus'); // 上报节点心跳信息
|
||||
Route::post('nodeOnline/{id}', 'V1Controller@setNodeOnline'); // 上报节点在线人数
|
||||
Route::get('userList/{id}', 'V1Controller@getUserList'); // 获取节点可用的用户列表
|
||||
Route::post('userTraffic/{id}', 'V1Controller@setUserTraffic'); // 上报用户流量日志
|
||||
Route::get('nodeRule/{id}', 'V1Controller@getNodeRule'); // 获取节点的审计规则
|
||||
Route::post('trigger/{id}', 'V1Controller@addRuleLog'); // 上报用户触发的审计规则记录
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user