Skip to content

Commit

Permalink
v2ray support
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Nov 19, 2017
1 parent dc57308 commit d98a490
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 208 deletions.
3 changes: 3 additions & 0 deletions app/Controllers/Api/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public function createUser(Request $request, $response, $args)
$user->invite_num = db_config(self::DefaultInviteNum, 10);
$user->reg_ip = Http::getClientIP();
$user->ref_by = $c->user_id;
$user->v2ray_uuid = Tools::genUUID();
$user->v2ray_alter_id = config('v2ray.alter_id');
$user->v2ray_level = config('v2ray.level');

if ($user->save()) {
$c->delete();
Expand Down
20 changes: 20 additions & 0 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\TrafficLog;
use App\Models\User;
use App\Utils\Tools;
use App\Services\V2rayGenerator;

class NodeController extends BaseController
{
Expand Down Expand Up @@ -109,4 +110,23 @@ 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());
}
}
10 changes: 10 additions & 0 deletions app/Models/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class Node extends Model
{
protected $table = 'ss_node';

/**
*
* @var array
*/
protected $casts = [
'ss_enable' => 'boolean',
'v2ray_enable' => 'boolean',
'https_enable' => 'boolean',
];

public function getLastNodeInfoLog()
{
$id = $this->attributes['id'];
Expand Down
95 changes: 95 additions & 0 deletions app/Services/V2rayGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php


namespace App\Services;


use App\Utils\EmptyClass;

class V2rayGenerator
{

private $arr = [
"log" => [
"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();
}
}
10 changes: 10 additions & 0 deletions app/Utils/EmptyClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


namespace App\Utils;


class EmptyClass
{

}
37 changes: 37 additions & 0 deletions databases/2017_11_19_205437_update_ss_node_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
* Migration auto-generated by Sequel Pro Laravel Export
* @see https://github.com/cviebrock/sequel-pro-laravel-export
*/
class UpdateSsNodeTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('ss_node', function (Blueprint $table) {
$table->integer('ss_enable')->default(1);
$table->integer('v2ray_enable')->default(0);
$table->integer('https_enable')->default(0);
$table->integer('v2ray_port')->default(8100);
$table->string('v2ray_protocol')->default("tcp");
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
2 changes: 1 addition & 1 deletion public/assets/js/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/home.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions resources/lang/en/ss.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@
'obfs-protocol' => 'obfs Protocol',
'obfs-plugin' => 'obfs Plugin',
'obfs_param' => "obfs Param",

// V2ray
'v2ray' => 'V2ray',
'v2ray-protocol' => 'V2ray Protocol',
'v2ray-port' => 'V2ray Port',
'v2ray-uuid' => 'V2ray UUID',
'v2ray-alter-id' => 'V2ray alterId',
];
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
$this->post('/nodes/{id}/online_count', 'App\Controllers\MuV2\NodeController:onlineUserLog');
$this->post('/nodes/{id}/info', 'App\Controllers\MuV2\NodeController:info');
$this->get('/nodes/{id}/users', 'App\Controllers\MuV2\NodeController:users');
$this->get('/nodes/{id}/v2rayUsers', 'App\Controllers\MuV2\NodeController:v2rayUsers');
$this->post('/nodes/{id}/traffic', 'App\Controllers\MuV2\NodeController:postTraffic');
})->add(new Mu());

Expand All @@ -122,6 +123,7 @@
$this->post('/nodes/{id}/online_count', 'App\Controllers\MuV2\NodeController:onlineUserLog');
$this->post('/nodes/{id}/info', 'App\Controllers\MuV2\NodeController:info');
$this->get('/nodes/{id}/users', 'App\Controllers\MuV2\NodeController:users');
$this->get('/nodes/{id}/v2rayUsers', 'App\Controllers\MuV2\NodeController:v2rayUsers');
$this->post('/nodes/{id}/traffic', 'App\Controllers\MuV2\NodeController:postTraffic');
})->add(new Mu());

Loading

0 comments on commit d98a490

Please sign in to comment.