Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 #761

Open
wants to merge 19 commits into
base: rm
Choose a base branch
from
Open

V3 #761

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/Command/XCat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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 {
Expand All @@ -97,8 +124,10 @@ public function resetTraffic()
]);
} catch (\Exception $e) {
echo $e->getMessage();

return false;
}

return "reset traffic successful";
}
}
55 changes: 53 additions & 2 deletions app/Controllers/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'] = "添加失败";
Expand All @@ -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)
Expand All @@ -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'] = "修改失败";
Expand Down
34 changes: 31 additions & 3 deletions app/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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');
Expand All @@ -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'];
Expand All @@ -84,4 +112,4 @@ public function deleteGet($request, $response, $args)
$newResponse = $response->withStatus(302)->withHeader('Location', '/admin/user');
return $newResponse;
}
}
}
7 changes: 7 additions & 0 deletions app/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand All @@ -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()){
Expand All @@ -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()){
Expand All @@ -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');
}
}
10 changes: 9 additions & 1 deletion app/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -218,4 +226,4 @@ public function logout($request, $response, $args)
return $this->redirect($response, '/auth/login');
}

}
}
33 changes: 31 additions & 2 deletions app/Controllers/MuV2/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("%[email protected]", $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);
}

Expand Down Expand Up @@ -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("%[email protected]", $user->v2ray_uuid);
$v->addUser($user->v2ray_uuid, $user->v2ray_level, $user->v2ray_alter_id, $email);
}

return $this->echoJson($response, $v->getArr());
}
}
Loading