diff --git a/app/Command/XCat.php b/app/Command/XCat.php index c735a2d8a..b85617d30 100644 --- a/app/Command/XCat.php +++ b/app/Command/XCat.php @@ -29,6 +29,8 @@ public function boot() return $this->install(); case("createAdmin"): return $this->createAdmin(); + case("initV2ray"): + return $this->initV2ray(); case("resetTraffic"): return $this->resetTraffic(); case("sendDiaryMail"): @@ -77,17 +79,42 @@ public function createAdmin() $user->invite_num = Config::get('inviteNum'); $user->ref_by = 0; $user->is_admin = 1; + $user->v2ray_uuid = Tools::genUUID(); + $user->v2ray_level = 2; + $user->v2ray_alter_id = 64; if ($user->save()) { echo "Successful/添加成功!"; + return true; } echo "添加失败"; + return false; } echo "cancel"; + return false; } + public function initV2ray() + { + try { + $users = User::all(); + foreach ($users as $user) { + if (strlen($user->v2ray_uuid) == 0) { + $user->v2ray_uuid = Tools::genUUID(); + $user->save(); + } + } + } catch (\Exception $e) { + echo $e->getMessage(); + + return false; + } + echo "完成!"; + return true; + } + public function resetTraffic() { try { @@ -97,8 +124,10 @@ public function resetTraffic() ]); } catch (\Exception $e) { echo $e->getMessage(); + return false; } + return "reset traffic successful"; } } \ No newline at end of file diff --git a/app/Controllers/Admin/NodeController.php b/app/Controllers/Admin/NodeController.php index 15f716f05..d223a320b 100644 --- a/app/Controllers/Admin/NodeController.php +++ b/app/Controllers/Admin/NodeController.php @@ -16,7 +16,16 @@ public function index($request, $response, $args) public function create($request, $response, $args) { $method = Node::getCustomerMethod(); - return $this->view()->assign('method', $method)->display('admin/node/create.tpl'); + $ssrmethod = Node::getSSRMethod(); + $protocol = Node::getProtocolMethod(); + $obfs = Node::getObfsMethod(); + $v2rayprotocol = Node::getV2rayProtocol(); + return $this->view()->assign('method', $method) + ->assign('ssrmethod', $ssrmethod) + ->assign('protocol', $protocol) + ->assign('obfs', $obfs) + ->assign('v2rayprotocol', $v2rayprotocol) + ->display('admin/node/create.tpl'); } public function add($request, $response, $args) @@ -26,11 +35,27 @@ public function add($request, $response, $args) $node->server = $request->getParam('server'); $node->method = $request->getParam('method'); $node->custom_method = $request->getParam('custom_method'); + $node->custom_rss = $request->getParam('custom_rss'); $node->traffic_rate = $request->getParam('rate'); $node->info = $request->getParam('info'); $node->type = $request->getParam('type'); $node->status = $request->getParam('status'); + $node->ss = $request->getParam('ss'); + $node->ssr = $request->getParam('ssr'); $node->sort = $request->getParam('sort'); + $node->protocol = $request->getParam('protocol'); + $node->protocol_param = $request->getParam('protocol_param'); + $node->obfs = $request->getParam('obfs'); + $node->obfs_param = $request->getParam('obfs_param'); + $node->ssr_port = $request->getParam('ssr_port'); + $node->add_port_only = $request->getParam('add_port_only'); + $node->add_method = $request->getParam('add_method'); + $node->add_passwd = $request->getParam('add_passwd'); + $node->v2ray = $request->getParam('v2ray'); + $node->v2ray_port = $request->getParam('v2ray_port'); + $node->v2ray_protocol = $request->getParam('v2ray_protocol'); + $node->v2ray_path = $request->getParam('v2ray_path'); + $node->v2ray_tls = $request->getParam('v2ray_tls'); if (!$node->save()) { $rs['ret'] = 0; $rs['msg'] = "添加失败"; @@ -49,7 +74,17 @@ public function edit($request, $response, $args) } $method = Node::getCustomerMethod(); - return $this->view()->assign('node', $node)->assign('method', $method)->display('admin/node/edit.tpl'); + $ssrmethod = Node::getSSRMethod(); + $protocol = Node::getProtocolMethod(); + $obfs = Node::getObfsMethod(); + $v2rayprotocol = Node::getV2rayProtocol(); + return $this->view()->assign('node', $node) + ->assign('method', $method) + ->assign('ssrmethod', $ssrmethod) + ->assign('protocol', $protocol) + ->assign('obfs', $obfs) + ->assign('v2rayprotocol', $v2rayprotocol) + ->display('admin/node/edit.tpl'); } public function update($request, $response, $args) @@ -61,11 +96,27 @@ public function update($request, $response, $args) $node->server = $request->getParam('server'); $node->method = $request->getParam('method'); $node->custom_method = $request->getParam('custom_method'); + $node->custom_rss = $request->getParam('custom_rss'); $node->traffic_rate = $request->getParam('rate'); $node->info = $request->getParam('info'); $node->type = $request->getParam('type'); $node->status = $request->getParam('status'); + $node->ss = $request->getParam('ss'); + $node->ssr = $request->getParam('ssr'); $node->sort = $request->getParam('sort'); + $node->protocol = $request->getParam('protocol'); + $node->protocol_param = $request->getParam('protocol_param'); + $node->obfs = $request->getParam('obfs'); + $node->obfs_param = $request->getParam('obfs_param'); + $node->ssr_port = $request->getParam('ssr_port'); + $node->add_port_only = $request->getParam('add_port_only'); + $node->add_method = $request->getParam('add_method'); + $node->add_passwd = $request->getParam('add_passwd'); + $node->v2ray = $request->getParam('v2ray'); + $node->v2ray_port = $request->getParam('v2ray_port'); + $node->v2ray_protocol = $request->getParam('v2ray_protocol'); + $node->v2ray_path = $request->getParam('v2ray_path'); + $node->v2ray_tls = $request->getParam('v2ray_tls'); if (!$node->save()) { $rs['ret'] = 0; $rs['msg'] = "修改失败"; diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 4402e2c01..b7be54b0d 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -3,8 +3,8 @@ namespace App\Controllers\Admin; use App\Controllers\AdminController; -use App\Models\User; use App\Models\Node; +use App\Models\User; use App\Utils\Hash; use App\Utils\Tools; @@ -29,7 +29,11 @@ public function edit($request, $response, $args) } $method = Node::getCustomerMethod(); - return $this->view()->assign('user', $user)->assign('method', $method)->display('admin/user/edit.tpl'); + $protocol = Node::getProtocolMethod(); + $obfs = Node::getObfsMethod(); + + return $this->view()->assign('user', $user)->assign('method', $method) + ->assign('protocol', $protocol)->assign('obfs', $obfs)->display('admin/user/edit.tpl'); } public function update($request, $response, $args) @@ -49,6 +53,12 @@ public function update($request, $response, $args) $user->transfer_enable = Tools::toGB($request->getParam('transfer_enable')); $user->invite_num = $request->getParam('invite_num'); $user->method = $request->getParam('method'); + $user->protocol = $request->getParam('protocol'); + $user->protocol_param = $request->getParam('protocol_param'); + $user->obfs = $request->getParam('obfs'); + $user->obfs_param = $request->getParam('obfs_param'); + $user->v2ray_level = $request->getParam('v2ray_level'); + $user->v2ray_alter_id = $request->getParam('v2ray_alter_id'); $user->enable = $request->getParam('enable'); $user->is_admin = $request->getParam('is_admin'); $user->ref_by = $request->getParam('ref_by'); @@ -62,6 +72,24 @@ public function update($request, $response, $args) return $response->getBody()->write(json_encode($rs)); } + public function updateV2rayUUID($request, $response, $args) + { + $id = $args['id']; + $user = User::find($id); + + $user->v2ray_uuid = Tools::genUUID(); + if (!$user->save()) { + $rs['ret'] = 0; + $rs['msg'] = "修改失败"; + + return $response->getBody()->write(json_encode($rs)); + } + $rs['ret'] = 1; + $rs['msg'] = "修改成功"; + + return $response->getBody()->write(json_encode($rs)); + } + public function delete($request, $response, $args) { $id = $args['id']; @@ -84,4 +112,4 @@ public function deleteGet($request, $response, $args) $newResponse = $response->withStatus(302)->withHeader('Location', '/admin/user'); return $newResponse; } -} \ No newline at end of file +} diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index fa0338fca..0631ab375 100755 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -127,6 +127,7 @@ public function updateConfig($request, $response, $args) $res['msg'] = "更新成功"; return $response->getBody()->write(json_encode($res)); } + public function cleanNodelog($request, $response, $args) { if($clean = NodeInfoLog::TRUNCATE()){ @@ -136,6 +137,7 @@ public function cleanNodelog($request, $response, $args) $res['ret'] = 0; return $response->getBody()->write(json_encode($res)); } + public function cleanOnlinelog($request, $response, $args) { if($clean = NodeOnlineLog::TRUNCATE()){ @@ -145,6 +147,7 @@ public function cleanOnlinelog($request, $response, $args) $res['ret'] = 0; return $response->getBody()->write(json_encode($res)); } + public function cleantrafficlog($request, $response, $args) { if($clean = TrafficLog::TRUNCATE()){ @@ -155,4 +158,8 @@ public function cleantrafficlog($request, $response, $args) return $response->getBody()->write(json_encode($res)); } + public function sysinfo($request, $response, $args) + { + return $this->view()->display('admin/sys.tpl'); + } } diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index f1e3d9559..d5e585da6 100755 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -163,6 +163,14 @@ public function registerHandle($request, $response, $args) $user->passwd = Tools::genRandomChar(6); $user->port = Tools::getLastPort() + 1; $user->t = 0; + $user->method = "aes-128-ctr"; + $user->protocol = "auth_aes128_md5"; + $user->protocol_param = ""; + $user->obfs = "tls1.2_ticket_auth"; + $user->obfs_param = "cloudfront.net"; + $user->v2ray_uuid = Tools::genUUID(); + $user->v2ray_level = 2; + $user->v2ray_alter_id = 64; $user->u = 0; $user->d = 0; $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic')); @@ -218,4 +226,4 @@ public function logout($request, $response, $args) return $this->redirect($response, '/auth/login'); } -} \ No newline at end of file +} diff --git a/app/Controllers/MuV2/NodeController.php b/app/Controllers/MuV2/NodeController.php index c032135c8..274c2bfec 100644 --- a/app/Controllers/MuV2/NodeController.php +++ b/app/Controllers/MuV2/NodeController.php @@ -9,6 +9,7 @@ use App\Models\NodeOnlineLog; use App\Models\TrafficLog; use App\Models\User; +use App\Services\V2rayGenerator; use App\Utils\Tools; class NodeController extends BaseController @@ -17,10 +18,21 @@ class NodeController extends BaseController public function users($request, $response, $args) { $users = User::all(); + $data = []; + foreach ($users as $user) { + $user->v2ray_user = [ + "uuid" => $user->v2ray_uuid, + "email" => sprintf("%s@sspanel.xyz", $user->v2ray_uuid), + "alter_id" => $user->v2ray_alter_id, + "level" => $user->v2ray_level, + ]; + array_push($data, $user); + } $res = [ - "msg" => "ok", - "data" => $users + 'msg' => 'ok', + 'data' => $data, ]; + return $this->echoJson($response, $res); } @@ -105,4 +117,21 @@ public function postTraffic($request, $response, $args) ]; return $this->echoJson($response, $res); } + + public function v2rayUsers($request, $response, $args) + { + $node = Node::find($args['id']); + $users = User::all(); + $v = new V2rayGenerator(); + $v->setPort($node->v2ray_port); + foreach ($users as $user) { + if ($user->enable == 0) { + continue; + } + $email = sprintf("%s@sspanel.io", $user->v2ray_uuid); + $v->addUser($user->v2ray_uuid, $user->v2ray_level, $user->v2ray_alter_id, $email); + } + + return $this->echoJson($response, $v->getArr()); + } } \ No newline at end of file diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index d700c1c11..df4370a52 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -12,6 +12,11 @@ use App\Utils\Hash; use App\Utils\Tools; +function safe_base64_encode($str) +{ + return strtr(rtrim(base64_encode($str), '='), '+/=', + '-_,'); +} /** * HomeController @@ -46,7 +51,9 @@ public function node($request, $response, $args) $msg = DbConfig::get('user-node'); $user = Auth::getUser(); $nodes = Node::where('type', 1)->orderBy('sort')->get(); - return $this->view()->assign('nodes', $nodes)->assign('user', $user)->assign('msg', $msg)->display('user/node.tpl'); + + return $this->view()->assign('nodes', $nodes)->assign('user', $user)->assign('msg', + $msg)->display('user/node.tpl'); } @@ -67,14 +74,175 @@ public function nodeInfo($request, $response, $args) } $json = json_encode($ary); $json_show = json_encode($ary, JSON_PRETTY_PRINT); - $ssurl = $ary['method'] . ":" . $ary['password'] . "@" . $ary['server'] . ":" . $ary['server_port']; - $ssqr = "ss://" . base64_encode($ssurl); + $ssurl = $ary['method'].":".$ary['password']."@".$ary['server'].":".$ary['server_port']; + $ssqr = "ss://".base64_encode($ssurl); - $surge_base = Config::get('baseUrl') . "/downloads/ProxyBase.conf"; + $surge_base = Config::get('baseUrl')."/downloads/ProxyBase.conf"; $surge_proxy = "#!PROXY-OVERRIDE:ProxyBase.conf\n"; $surge_proxy .= "[Proxy]\n"; - $surge_proxy .= "Proxy = custom," . $ary['server'] . "," . $ary['server_port'] . "," . $ary['method'] . "," . $ary['password'] . "," . Config::get('baseUrl') . "/downloads/SSEncrypt.module"; - return $this->view()->assign('json', $json)->assign('json_show', $json_show)->assign('ssqr', $ssqr)->assign('surge_base', $surge_base)->assign('surge_proxy', $surge_proxy)->display('user/nodeinfo.tpl'); + $surge_proxy .= "Proxy = custom,".$ary['server'].",".$ary['server_port'].",".$ary['method'].",".$ary['password'].",".Config::get('baseUrl')."/downloads/SSEncrypt.module"; + + $ss = $node->ss; + $ssr = $node->ssr && !$node->add_port_only; + $ssr_add = $node->ssr && $node->ssr_port != 0; + $v2ray = $node->v2ray; + if ($ssr) { + $aryr['server'] = $node->server; + $aryr['protocol'] = $node->protocol; + $aryr['protocol_param'] = $node->protocol_param; + $aryr['obfs'] = $node->obfs; + $aryr['obfs_param'] = $node->obfs_param; + if ($node->custom_rss) { + $aryr['protocol'] = $this->user->protocol; + $aryr['protocol_param'] = $this->user->protocol_param; + $aryr['obfs'] = $this->user->obfs; + $aryr['obfs_param'] = $this->user->obfs_param; + } + $aryr['server_port'] = $this->user->port; + $aryr['password'] = $this->user->passwd; + $aryr['method'] = $this->user->method; + $jsonr = json_encode($aryr); + $jsonr_show = json_encode($aryr, JSON_PRETTY_PRINT); + $ssrurl = $aryr['server'].":".$aryr['server_port'].":".$aryr['protocol'].":".$aryr['method'].":".$aryr['obfs'].":".safe_base64_encode($aryr['password']) + ."/?obfsparam=".safe_base64_encode($aryr['obfs_param'])."&protoparam=".safe_base64_encode($aryr['protocol_param'])."&udpport=1"; + $ssrqr = "ssr://".safe_base64_encode($ssrurl); + } + if ($ssr_add) { + $aryrd['server'] = $node->server; + $aryrd['server_port'] = $node->ssr_port; + $aryrd['password'] = $node->add_passwd; + $aryrd['method'] = $node->add_method; + $aryrd['protocol'] = $node->protocol; + $aryrd['protocol_param'] = strval($this->user->port).":".$this->user->passwd; + $aryrd['obfs'] = $node->obfs; + $aryrd['obfs_param'] = $node->obfs_param; + $jsonrd = json_encode($aryrd); + $jsonrd_show = json_encode($aryrd, JSON_PRETTY_PRINT); + $ssrdurl = $aryrd['server'].":".$aryrd['server_port'].":".$aryrd['protocol'].":".$aryrd['method'].":".$aryrd['obfs'].":".safe_base64_encode($aryrd['password']) + ."/?obfsparam=".safe_base64_encode($aryrd['obfs_param'])."&protoparam=".safe_base64_encode($aryrd['protocol_param'])."&udpport=1"; + $ssrdqr = "ssr://".safe_base64_encode($ssrdurl); + } + if(empty($this->user->v2ray_uuid)) $v2ray=false; + if ($v2ray) { + $arr = [ + "inbound" => [ + "port" => 1080, + "listen" => "127.0.0.1", + "protocol" => "socks", + "domainOverride" => ["tls", "http"], + "settings" => [ + "auth" => "noauth", + "udp" => false, + "ip" => "127.0.0.1", + ], + ], + "outbound" => [ + "protocol" => "vmess", + "settings" => [ + "vnext" => [ + [ + "address" => $node->server, + "port" => $node->v2ray_port, + "users" => [ + [ + "id" => $this->user->v2ray_uuid, + "alterId" => $this->user->v2ray_alter_id, + ], + ], + ], + ], + ], + "streamSettings" => [ + "network" => $node->v2ray_protocol + ] + ], + "inboundDetour" => [], + "outboundDetour" => [ + [ + "protocol" => "freedom", + "settings" => null, + "tag" => "direct", + ], + ], + "routing" => [ + "strategy" => "rules", + "settings" => [ + "rules" => [ + [ + "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", + ], + ], + ], + ], + ]; + $ng = [ + "add" => $node->server, + "aid" => $this->user->v2ray_alter_id, + "id" => $this->user->v2ray_uuid, + "net" => $node->v2ray_protocol, + "port" => $node->v2ray_port, + "v" => 2, + "ps" => $node->name, + ]; + if ($node->v2ray_protocol == 'ws') { + $arr['outbound']['streamSettings']['wsSettings'] = [ + 'path' => $node->v2ray_path, + ]; + $ng['path'] = $node->v2ray_path; + } + if ($node->v2ray_protocol == 'http') { + $arr['outbound']['streamSettings']['httpSettings'] = [ + 'path' => $node->v2ray_path, + ]; + $ng['path'] = $node->v2ray_path; + } + if ($node->v2ray_tls) { + $arr['outbound']['streamSettings']['security'] = 'tls'; + $ng['tls'] = 'tls'; + } + $jsonv = json_encode($arr); + $jsonv_show = json_encode($arr, JSON_PRETTY_PRINT); + $ngqr = "vmess://".base64_encode(json_encode($ng)); + $bfvqr = "bfv://{$node->server}:{$node->v2ray_port}/vmess/1?rtype=lanchina&dns=8.8.8.8&uid={$this->user->v2ray_uuid}&aid={$this->user->v2ray_alter_id}&sec=auto&tcp=header%3Dhttp%26req%3D#".str_replace('+','%20',urlencode($node->name)); + } + + $user = Auth::getUser(); + if ($user->enable) { + $temp = $this->view()->assign('ss', $ss)->assign('ssr', $ssr)->assign('ssr_add', $ssr_add)->assign('v2ray', $v2ray) + ->assign('json', $json)->assign('json_show', $json_show)->assign('ssqr', $ssqr) + ->assign('surge_base', $surge_base)->assign('surge_proxy', $surge_proxy); + if ($ssr) { + $temp = $temp->assign('jsonr', $jsonr)->assign('jsonr_show', $jsonr_show)->assign('ssrqr', $ssrqr); + } + if ($ssr_add) { + $temp = $temp->assign('jsonrd', $jsonrd)->assign('jsonrd_show', $jsonrd_show)->assign('ssrdqr', $ssrdqr); + } + if ($v2ray) { + $temp = $temp->assign('jsonv', $jsonv)->assign('jsonv_show', $jsonv_show)->assign('ngqr', $ngqr)->assign('bfvqr', $bfvqr); + } + + return $temp->display('user/nodeinfo.tpl'); + } else { + return $this->redirect($response, '/user'); + } } public function profile($request, $response, $args) @@ -85,7 +253,11 @@ public function profile($request, $response, $args) public function edit($request, $response, $args) { $method = Node::getCustomerMethod(); - return $this->view()->assign('method', $method)->display('user/edit.tpl'); + $protocol = Node::getProtocolMethod(); + $obfs = Node::getObfsMethod(); + + return $this->view()->assign('method', $method)->assign('protocol', $protocol)->assign('obfs', + $obfs)->display('user/edit.tpl'); } @@ -175,6 +347,68 @@ public function updateMethod($request, $response, $args) $method = strtolower($method); $user->updateMethod($method); $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateProtocol($request, $response, $args) + { + $user = Auth::getUser(); + $protocol = $request->getParam('protocol'); + $protocol = strtolower($protocol); + $user->updateProtocol($protocol); + $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateProtocolParam($request, $response, $args) + { + $user = Auth::getUser(); + $param = $request->getParam('protocol-param'); + $user->updateProtocolParam($param); + $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateObfs($request, $response, $args) + { + $user = Auth::getUser(); + $obfs = $request->getParam('obfs'); + $obfs = strtolower($obfs); + $user->updateObfs($obfs); + $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateObfsParam($request, $response, $args) + { + $user = Auth::getUser(); + $param = $request->getParam('obfs-param'); + $user->updateObfsParam($param); + $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateV2rayUUID($request, $response, $args) + { + $user = Auth::getUser(); + $user->updateV2rayUUID(); + $res['ret'] = 1; + + return $this->echoJson($response, $res); + } + + public function updateV2rayAlterID($request, $response, $args) + { + $user = Auth::getUser(); + $param = $request->getParam('v2ray-alterid'); + $user->updateV2rayAlterID($param); + $res['ret'] = 1; + return $this->echoJson($response, $res); } diff --git a/app/Models/Node.php b/app/Models/Node.php index efefa8571..50dfab906 100755 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -74,6 +74,36 @@ function getTrafficFromLogs() public static function getCustomerMethod() { return [ + "aes-128-gcm" => "aes-128-gcm", + "aes-192-gcm" => "aes-192-gcm", + "aes-256-gcm" => "aes-256-gcm", + "chacha20-ietf-poly1305" => "chacha20-ietf-poly1305", + "chacha20-ietf" => "chacha20-ietf", + "salsa20" => "salsa20", + "chacha20" => "chacha20", + "aes-128-cfb" => "aes-128-cfb", + "aes-192-cfb" => "aes-192-cfb", + "aes-256-cfb" => "aes-256-cfb", + "aes-128-ctr" => "aes-128-ctr", + "aes-192-ctr" => "aes-192-ctr", + "aes-256-ctr" => "aes-256-ctr", + "camellia-128-cfb" => "camellia-128-cfb", + "camellia-192-cfb" => "camellia-192-cfb", + "camellia-256-cfb" => "camellia-256-cfb", + "bf-cfb" => "bf-cfb", + "rc4-md5" => "rc4-md5", + "rc4" => "rc4", + "table" => "table", + "none" => "none", + ]; + } + + public static function getSSRMethod() + { + return [ + "none" => "none", + "table" => "table", + "rc4" => "rc4", "rc4-md5" => "rc4-md5", "aes-128-cfb" => "aes-128-cfb", "aes-192-cfb" => "aes-192-cfb", @@ -81,19 +111,54 @@ public static function getCustomerMethod() "aes-128-ctr" => "aes-128-ctr", "aes-192-ctr" => "aes-192-ctr", "aes-256-ctr" => "aes-256-ctr", - "des-cfb" => "des-cfb", "bf-cfb" => "bf-cfb", - "cast5-cfb" => "cast5-cfb", "camellia-128-cfb" => "camellia-128-cfb", "camellia-192-cfb" => "camellia-192-cfb", "camellia-256-cfb" => "camellia-256-cfb", "chacha20" => "chacha20", "salsa20" => "salsa20", "chacha20-ietf" => "chacha20-ietf", - "aes-128-gcm" => "aes-128-gcm", - "aes-192-gcm" => "aes-192-gcm", - "aes-256-gcm" => "aes-256-gcm", - "chacha20-ietf-poly1305" => "chacha20-ietf-poly1305", + ]; + } + + public static function getProtocolMethod() + { + return [ + "origin" => "origin", + "verify_sha1" => "verify_sha1", + "auth_sha1" => "auth_sha1", + "auth_sha1_v2" => "auth_sha1_v2", + "auth_sha1_v4" => "auth_sha1_v4", + "auth_aes128_sha1" => "auth_aes128_sha1", + "auth_aes128_md5" => "auth_aes128_md5", + "auth_chain_a" => "auth_chain_a", + "auth_chain_b" => "auth_chain_b", + "auth_chain_c" => "auth_chain_c", + "auth_chain_d" => "auth_chain_d", + "auth_chain_e" => "auth_chain_e", + "auth_chain_f" => "auth_chain_f" + ]; + } + + public static function getObfsMethod() + { + return [ + "plain" => "plain", + "http_simple" => "http_simple", + "http_post" => "http_post", + "random_head" => "random_head", + "tls1.2_ticket_auth" => "tls1.2_ticket_auth" + ]; + } + + public static function getV2rayProtocol() + { + return [ + "TCP" => "tcp", + "mKCP" => "kcp", + "WebSocket" => "ws", + "HTTP/2" => "http", + "DomainSocket" => "domainsocket", ]; } } diff --git a/app/Models/User.php b/app/Models/User.php index 6b330f99b..afdbc17cc 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -87,6 +87,42 @@ public function updateMethod($method) $this->save(); } + public function updateProtocol($protocol) + { + $this->protocol = $protocol; + $this->save(); + } + + public function updateProtocolParam($protocol_param) + { + $this->protocol_param = $protocol_param; + $this->save(); + } + + public function updateObfs($obfs) + { + $this->obfs = $obfs; + $this->save(); + } + + public function updateObfsParam($obfs_param) + { + $this->obfs_param = $obfs_param; + $this->save(); + } + + public function updateV2rayUUID() + { + $this->v2ray_uuid = Tools::genUUID(); + $this->save(); + } + + public function updateV2rayAlterID($alter_id) + { + $this->v2ray_alter_id = $alter_id; + $this->save(); + } + public function addInviteCode() { $uid = $this->attributes['id']; @@ -164,4 +200,13 @@ public function inviteCodes() return InviteCode::where('user_id', $uid)->get(); } + public function expireTime() + { + $expire = $this->attributes['expire_time']; + if ($expire === 0) { + return '永不过期'; + } else { + return date('Y-m-d', $expire); + } + } } diff --git a/app/Services/Auth.php b/app/Services/Auth.php index 60fb05db1..1e4b621e3 100755 --- a/app/Services/Auth.php +++ b/app/Services/Auth.php @@ -69,7 +69,8 @@ public static function getUser() public static function logout() { + Cookie::set(['sid' => ''],0); $sid = Cookie::get('sid'); self::getCache()->del($sid); } -} \ No newline at end of file +} diff --git a/app/Services/V2RayGenerator.php b/app/Services/V2RayGenerator.php new file mode 100644 index 000000000..b64f75e88 --- /dev/null +++ b/app/Services/V2RayGenerator.php @@ -0,0 +1,85 @@ + [ + "access" => "/var/log/access.log", + "error" => "/var/log/error.log", + "loglevel" => "warning" + ], + "inbound" => [ + "port" => 8300, + "protocol" => "vmess", + "settings" => [ + "clients" => [ + ] + ] + ], + "outbound" => [ + "protocol" => "freedom", + // "settings" => , + ], + "inboundDetour" => [], + "outboundDetour" => [ + [ + "protocol" => "blackhole", + // "settings" => [], + "tag" => "blocked" + ] + ], + "routing" => [ + "strategy" => "rules", + "settings" => [ + "rules" => [ + [ + "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" => "blocked" + ] + ] + ] + ] + ]; + public function addUser($uuid, $level, $alertId, $email) + { + $user = [ + "id" => $uuid, + "level" => $level, + "alterId" => $alertId, + "email" => $email + ]; + array_push($this->arr["inbound"]['settings']['clients'], $user); + } + public function setPort($port) + { + $this->arr['inbound']['port'] = $port; + } + public function getArr() + { + return $this->arr; + } + public function __construct() + { + $this->arr["outbound"]["settings"] = new EmptyClass(); + $this->arr["outboundDetour"][0]["settings"] = new EmptyClass(); + } +} \ No newline at end of file diff --git a/app/Utils/EmptyClass.php b/app/Utils/EmptyClass.php new file mode 100644 index 000000000..d5cac0900 --- /dev/null +++ b/app/Utils/EmptyClass.php @@ -0,0 +1,7 @@ +post('/password', 'App\Controllers\UserController:updatePassword'); $this->post('/sspwd', 'App\Controllers\UserController:updateSsPwd'); $this->post('/method', 'App\Controllers\UserController:updateMethod'); + $this->post('/protocol', 'App\Controllers\UserController:updateProtocol'); + $this->post('/protocol-param', 'App\Controllers\UserController:updateProtocolParam'); + $this->post('/obfs', 'App\Controllers\UserController:updateObfs'); + $this->post('/obfs-param', 'App\Controllers\UserController:updateObfsParam'); + $this->post('/v2ray-uuid', 'App\Controllers\UserController:updateV2rayUUID'); + $this->post('/v2ray-alterid', 'App\Controllers\UserController:updateV2rayAlterID'); $this->get('/sys', 'App\Controllers\UserController:sys'); $this->get('/trafficlog', 'App\Controllers\UserController:trafficLog'); $this->get('/trafficlog/{nid}', 'App\Controllers\UserController:trafficLog'); @@ -105,6 +111,7 @@ $this->get('/user', 'App\Controllers\Admin\UserController:index'); $this->get('/user/{id}/edit', 'App\Controllers\Admin\UserController:edit'); $this->put('/user/{id}', 'App\Controllers\Admin\UserController:update'); + $this->patch('/user/{id}/v2ray-uuid', 'App\Controllers\Admin\UserController:updateV2rayUUID'); $this->delete('/user/{id}', 'App\Controllers\Admin\UserController:delete'); $this->get('/user/{id}/delete', 'App\Controllers\Admin\UserController:deleteGet'); @@ -139,6 +146,7 @@ $this->get('/users', 'App\Controllers\MuV2\UserController:index'); $this->post('/users/{id}/traffic', 'App\Controllers\MuV2\UserController:addTraffic'); $this->get('/nodes/{id}/users', 'App\Controllers\MuV2\NodeController:users'); + $this->get('/nodes/{id}/v2rayUsers', 'App\Controllers\MuV2\NodeController:v2rayUsers'); $this->post('/nodes/{id}/online_count', 'App\Controllers\MuV2\NodeController:onlineUserLog'); $this->post('/nodes/{id}/info', 'App\Controllers\MuV2\NodeController:info'); $this->post('/nodes/{id}/traffic', 'App\Controllers\MuV2\NodeController:postTraffic'); diff --git a/bootstrap/app.php b/bootstrap/app.php index 8acf87ad0..1a9b01be7 100755 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -11,7 +11,7 @@ // BASE_PATH define('BASE_PATH', __DIR__ . '/../'); -define('VERSION', '3.4.6'); +define('VERSION', '3.5.1'); // Vendor Autoload require BASE_PATH . '/vendor/autoload.php'; diff --git a/db-testing.sql b/db-testing.sql index f5c52e4d0..bff765f4e 100644 --- a/db-testing.sql +++ b/db-testing.sql @@ -60,11 +60,27 @@ CREATE TABLE `ss_node` ( `server` varchar(128) NOT NULL, `method` varchar(64) NOT NULL, `custom_method` tinyint(1) NOT NULL DEFAULT '0', + `custom_rss` tinyint(1) NOT NULL DEFAULT '0', `traffic_rate` float NOT NULL DEFAULT '1', `info` varchar(128) NOT NULL, `status` varchar(128) NOT NULL, `offset` int(11) NOT NULL DEFAULT '0', `sort` int(3) NOT NULL, + `ss` tinyint(4) NOT NULL DEFAULT '0', + `ssr` tinyint(4) NOT NULL DEFAULT '0', + `protocol` varchar(64), + `protocol_param` varchar(128), + `obfs` varchar(64), + `obfs_param` varchar(128), + `ssr_port` int(11) NOT NULL DEFAULT '0', + `add_port_only` tinyint(1) NOT NULL DEFAULT '0', + `add_method` varchar(64), + `add_passwd` varchar(16), + `v2ray` tinyint(4) NOT NULL DEFAULT '0', + `v2ray_port` int(11) NOT NULL DEFAULT '8100', + `v2ray_protocol` varchar(64) NOT NULL DEFAULT 'tcp', + `v2ray_path` varchar(64) NOT NULL DEFAULT '/ray', + `v2ray_tls` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -116,7 +132,12 @@ CREATE TABLE `user` ( `transfer_enable` bigint(20) NOT NULL, `port` int(11) NOT NULL, `protocol` varchar(32) NOT NULL DEFAULT 'origin', + `protocol_param` varchar(128) NULL DEFAULT NULL, `obfs` varchar(32) NOT NULL DEFAULT 'plain', + `obfs_param` varchar(128) NULL DEFAULT NULL, + `v2ray_uuid` varchar(36) NULL DEFAULT '', + `v2ray_level` int(8) NOT NULL DEFAULT '2', + `v2ray_alter_id` int(8) NOT NULL DEFAULT '64', `switch` tinyint(4) NOT NULL DEFAULT '1', `enable` tinyint(4) NOT NULL DEFAULT '1', `type` tinyint(4) NOT NULL DEFAULT '1', diff --git a/db.sql b/db.sql index 0a08d7958..c354efd10 100644 --- a/db.sql +++ b/db.sql @@ -44,11 +44,27 @@ CREATE TABLE `ss_node` ( `server` varchar(128) NOT NULL, `method` varchar(64) NOT NULL, `custom_method` tinyint(1) NOT NULL DEFAULT '0', + `custom_rss` tinyint(1) NOT NULL DEFAULT '0', `traffic_rate` float NOT NULL DEFAULT '1', `info` varchar(128) NOT NULL, `status` varchar(128) NOT NULL, `offset` int(11) NOT NULL DEFAULT '0', `sort` int(3) NOT NULL, + `ss` tinyint(4) NOT NULL DEFAULT '0', + `ssr` tinyint(4) NOT NULL DEFAULT '0', + `protocol` varchar(64), + `protocol_param` varchar(128), + `obfs` varchar(64), + `obfs_param` varchar(128), + `ssr_port` int(11) NOT NULL DEFAULT '0', + `add_port_only` tinyint(1) NOT NULL DEFAULT '0', + `add_method` varchar(64), + `add_passwd` varchar(16), + `v2ray` tinyint(4) NOT NULL DEFAULT '0', + `v2ray_port` int(11) NOT NULL DEFAULT '8100', + `v2ray_protocol` varchar(64) NOT NULL DEFAULT 'tcp', + `v2ray_path` varchar(64) NOT NULL DEFAULT '/ray', + `v2ray_tls` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -98,7 +114,12 @@ CREATE TABLE `user` ( `transfer_enable` bigint(20) NOT NULL, `port` int(11) NOT NULL, `protocol` varchar(32) NOT NULL DEFAULT 'origin', + `protocol_param` varchar(128) NULL DEFAULT NULL, `obfs` varchar(32) NOT NULL DEFAULT 'plain', + `obfs_param` varchar(128) NULL DEFAULT NULL, + `v2ray_uuid` varchar(36) NULL DEFAULT '', + `v2ray_level` int(8) NOT NULL DEFAULT '2', + `v2ray_alter_id` int(8) NOT NULL DEFAULT '64', `switch` tinyint(4) NOT NULL DEFAULT '1', `enable` tinyint(4) NOT NULL DEFAULT '1', `type` tinyint(4) NOT NULL DEFAULT '1', diff --git a/resources/views/default/admin/node/create.tpl b/resources/views/default/admin/node/create.tpl index 4726cceaa..e6e108124 100755 --- a/resources/views/default/admin/node/create.tpl +++ b/resources/views/default/admin/node/create.tpl @@ -36,6 +36,42 @@