Support Trojan

QuickEdition(No-js-Encryption)
孔雀 7 years ago
parent 493d0232aa
commit af2a7d2a41
No known key found for this signature in database
GPG Key ID: 94D7D8B64A106B8E

@ -36,6 +36,7 @@ use App\Models\Token;
use App\Models\UnblockIp;
use Exception;
use RuntimeException;
use Ramsey\Uuid\Uuid;
class Job
{
@ -610,6 +611,11 @@ class Job
$users = User::all();
foreach ($users as $user) {
$user->uuid = Uuid::uuid3(
Uuid::NAMESPACE_DNS,
strval($user->id) . '|' . $user->passwd
)->toString();
$user->save();
if (($user->transfer_enable <= $user->u + $user->d || $user->enable == 0 || (strtotime($user->expire_in) < time() && strtotime($user->expire_in) > 644447105)) && RadiusBan::where(
'userid',
$user->id

@ -281,7 +281,7 @@ class NodeController extends AdminController
});
$datatables->edit('outaddress', static function ($data) {
return (in_array($data['sort'], [0, 10, 11, 12, 13]) ? explode(';', $data['server'])[0] : '');
return (in_array($data['sort'], [0, 10, 11, 12, 13, 14]) ? explode(';', $data['server'])[0] : '');
});
$datatables->edit('node_bandwidth', static function ($data) {
@ -322,6 +322,9 @@ class NodeController extends AdminController
case 13:
$sort = 'Shadowsocks - V2Ray-Plugin';
break;
case 14:
$sort = 'Trojan';
break;
default:
$sort = '系统保留';
}

@ -131,19 +131,20 @@ class UserController extends BaseController
$key_list = array('email', 'method', 'obfs', 'obfs_param', 'protocol', 'protocol_param',
'forbidden_ip', 'forbidden_port', 'node_speedlimit', 'disconnect_ip',
'is_multi_user', 'id', 'port', 'passwd', 'u', 'd', 'node_connector');
'is_multi_user', 'id', 'port', 'passwd', 'u', 'd', 'node_connector',
'sort', 'uuid');
$users = array();
foreach ($users_raw as $user_raw) {
$user_raw = Tools::keyFilter($user_raw, $key_list);
if ($node->sort == 14) {
$user_raw->sha224uuid = hash('sha224', $user_raw->uuid);
}
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
$user_raw = Tools::keyFilter($user_raw, $key_list);
$user_raw->uuid = $user_raw->getUuid();
$users[] = $user_raw;
} else if (Config::get('keep_connect') === true) {
// 流量耗尽用户限速至 1Mbps
$user_raw = Tools::keyFilter($user_raw, $key_list);
$user_raw->uuid = $user_raw->getUuid();
$user_raw->node_speedlimit = 1;
$users[] = $user_raw;
}

@ -492,7 +492,7 @@ class UserController extends BaseController
if ($log['node_id'] != $node->id) {
continue;
}
if (in_array($sort, array(0, 7, 8, 10, 11, 12, 13))) {
if (in_array($sort, array(0, 7, 8, 10, 11, 12, 13, 14))) {
$array_node['online_user'] = $log['online_user'];
} else {
$array_node['online_user'] = -1;
@ -504,7 +504,7 @@ class UserController extends BaseController
// 0: new node; -1: offline; 1: online
$node_heartbeat = $node->node_heartbeat + 300;
$array_node['online'] = -1;
if (!in_array($sort, array(0, 7, 8, 10, 11, 12, 13)) || $node_heartbeat == 300) {
if (!in_array($sort, array(0, 7, 8, 10, 11, 12, 13, 14)) || $node_heartbeat == 300) {
$array_node['online'] = 0;
} elseif ($node_heartbeat > time()) {
$array_node['online'] = 1;

@ -13,7 +13,6 @@ use App\Utils\GA;
use App\Utils\QQWry;
use App\Utils\Radius;
use App\Utils\URL;
use Ramsey\Uuid\Uuid;
use App\Models\DetectLog;
use App\Models\DetectBanLog;
@ -140,10 +139,11 @@ class User extends Model
public function getUuid()
{
return Uuid::uuid3(
Uuid::NAMESPACE_DNS,
$this->attributes['id'] . '|' . $this->attributes['passwd']
)->toString();
// return Uuid::uuid3(
// Uuid::NAMESPACE_DNS,
// $this->attributes['id'] . '|' . $this->attributes['passwd']
// )->toString();
return $this->attributes['uuid'];
}
/*

@ -38,6 +38,9 @@ class AppURI
: '');
$return = $item['remark'] . ' = vmess, ' . $item['add'] . ', ' . $item['port'] . ', username = ' . $item['id'] . $ws . $tls;
break;
case 'trojan':
$return = ($item['remark'] . ' = trojan, ' . $item['address'] . ', ' . $item['port'] . ', password=' . $item['passwd']) . ", sni=" . $item['host'];
break;
}
break;
}
@ -145,6 +148,12 @@ class AppURI
}
$return .= (', tag=' . $item['remark']);
break;
case 'trojan':
// ;trojan=example.com:443, password=pwd, over-tls=true, tls-verification=true, fast-open=false, udp-relay=false, tag=trojan-tls-01
$return = ('trojan=' . $item['address'] . ':' . $item['port'] . ', password=' . $item['passwd'] . ', tls-host=' . $item['host']);
$return .= ', over-tls=true, tls-verification=true';
$return .= (', tag=' . $item['remark']);
break;
}
return $return;
}
@ -267,6 +276,16 @@ class AppURI
}
}
break;
case 'trojan':
$return = [
'name' => $item['remark'],
'type' => 'trojan',
'server' => $item['address'],
'port' => $item['port'],
'password' => $item['passwd'],
'sni' => $item['host']
];
break;
}
return $return;
}
@ -344,6 +363,10 @@ class AppURI
}
$return = ('vmess://' . Tools::base64_url_encode('chacha20-poly1305:' . $item['id'] . '@' . $item['add'] . ':' . $item['port']) . '?remarks=' . rawurlencode($item['remark']) . $obfs . $tls);
break;
case 'trojan':
$return = ('trojan://' . $item['passwd'] . '@' . $item['address'] . ':' . $item['port']);
$return .= ('?peer=' . $item['host'] . '#' . rawurlencode($item['remark']));
break;
}
return $return;
}
@ -481,4 +504,16 @@ class AppURI
}
return $return;
}
public static function getTrojanURI(array $item)
{
$return = null;
switch ($item['type']) {
case 'trojan':
$return = ('trojan://' . $item['passwd'] . '@' . $item['address'] . ':' . $item['port']);
$return .= ('?peer=' . $item['host'] . '#' . rawurlencode($item['remark']));
break;
}
return $return;
}
}

@ -265,9 +265,12 @@ class URL
case 'vmess':
$sort = [11, 12];
break;
case 'trojan':
$sort = [14];
break;
default:
$Rule['type'] = 'all';
$sort = [0, 10, 11, 12, 13];
$sort = [0, 10, 11, 12, 13, 14];
break;
}
if ($user->is_admin) {
@ -296,7 +299,7 @@ class URL
$nodes = $node_query->orderBy('name')->get();
}
$return_array = array();
if ($is_mu != 0 && $Rule['type'] != 'vmess') {
if ($is_mu != 0 && $Rule['type'] != 'vmess' && $Rule['type'] != 'trojan') {
$mu_node_query = Node::query();
$mu_node_query->where('sort', 9)->where('type', '1');
if ($user->is_admin) {
@ -359,6 +362,17 @@ class URL
}
continue;
}
if (in_array($node->sort, [14]) && (($Rule['type'] == 'all' && $x == 0) || ($Rule['type'] == 'trojan'))) {
// Trojan
$item = self::getTrojanItem($user, $node, $emoji);
if ($item != null) {
$find = (isset($Rule['content']['regex']) && $Rule['content']['regex'] != '' ? ConfController::getMatchProxy($item, ['content' => ['regex' => $Rule['content']['regex']]]) : true);
if ($find) {
$return_array[] = $item;
}
}
continue;
}
if (in_array($node->sort, [0, 10]) && $node->mu_only != 1 && ($is_mu == 0 || ($is_mu != 0 && Config::get('mergeSub') === true))) {
// 节点非只启用单端口 && 只获取普通端口
if ($node->sort == 10) {
@ -442,6 +456,59 @@ class URL
return $return_array;
}
/**
* 获取 Trojan 全部节点
*
* @param User $user 用户
* @param bool $emoji
*
* @return array
*/
public static function getAllTrojan($user, $emoji = false)
{
$return_array = array();
$nodes = Node::where('sort', 14)
->where('type', '1')
->orderBy('name')
->get();
foreach ($nodes as $node) {
$item = self::getTrojanItem($user, $node, $emoji);
if ($item != null) {
$return_array[] = $item;
}
}
return $return_array;
}
/**
* Trojan 节点
*
* @param User $user 用户
* @param Node $node
* @param bool $emoji
*
* @return array
*/
public static function getTrojanItem($user, $node, $emoji = false)
{
$server = explode(';', $node->server);
$opt = [];
if (isset($server[1])) {
$opt = self::parse_args($server[1]);
}
$item['remark'] = ($emoji == true ? Tools::addEmoji($node->name) : $node->name);
$item['type'] = 'trojan';
$item['address'] = $server[0];
$item['port'] = (isset($opt['port']) ? (int) $opt['port'] : 443);
$item['passwd'] = $user->uuid;
$item['host'] = $item['address'];
if (isset($opt['host'])) {
$item['host'] = $opt['host'];
}
return $item;
}
public static function getAllUrl($user, $is_mu, $is_ss = 0, $getV2rayPlugin = 1)
{
$return_url = '';

@ -112,6 +112,7 @@
<option value="11">V2Ray</option>
<option value="12">V2Ray 中转</option>
<option value="13">Shadowsocks V2Ray-Plugin</option>
<option value="14">Trojan</option>
</select>
</div>
</div>

@ -119,6 +119,7 @@
<option value="13" {if $node->sort==13}selected{/if}>Shadowsocks
V2Ray-Plugin
</option>
<option value="14" {if $node->sort==14}selected{/if}>Trojan</option>
</select>
</div>
</div>

@ -79,7 +79,7 @@
{$region = substr($node['name'],0,6)}
<img alt="image" class="mr-3 rounded-circle" width="50" src="/theme/malio/assets/modules/flag-icon-css/flags/1x1/{if $malio_config['flag_mode']=='node-name'}{if $flags[$region] != ''}{$flags[$region]}{else}un{/if}{else}{$node['status']}{/if}.svg">
<div class="media-body">
<div class="media-title node-status {if $node['online']=='1'}node-is-online{else}node-is-offline{/if}">{current(explode(" - ", $node['name']))}</div>
<div class="media-title node-status {if $node['online']=='1' or $node['sort'] == 14}node-is-online{else}node-is-offline{/if}">{current(explode(" - ", $node['name']))}</div>
<div class=" text-job text-muted">{$node['info']}</div>
</div>
<div class="media-items">

@ -64,7 +64,11 @@
<div id="app">
<div class="main-wrapper">
<ul class="nav nav-tabs" id="myTab" role="tablist">
{if (in_array("ssr",$malio_config['support_sub_type']))}
{if $node->sort == 14}
<li class="nav-item">
<a class="nav-link" id="trojan-tab" data-toggle="tab" href="#trojan" role="tab" aria-controls="trojan" aria-selected="true">Trojan</a>
</li>
{elseif (in_array("ssr",$malio_config['support_sub_type']))}
{if $node->mu_only != 1}
<li class="nav-item">
<a class="nav-link active" id="ssr-tab" data-toggle="tab" href="#ssr" role="tab" aria-controls="ssr" aria-selected="true">ShadowsocksR</a>
@ -91,6 +95,32 @@
{/if}
</ul>
<div class="tab-content" id="myTabContent">
{if $node->sort == 14}
<div class="tab-pane fade active show" id="trojan" role="tabpanel" aria-labelledby="trojan-tab">
<div class="row mt-2">
<div class="col-12 col-sm-3 col-md-3">
<ul class="nav nav-pills flex-column" id="myTab4" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="trojan-info-tab" data-toggle="tab" href="#trojan-info" role="tab" aria-controls="trojan-info" aria-selected="true">信息</a>
</li>
</ul>
</div>
<div class="col-12 col-sm-9 col-md-9">
<div class="tab-content no-padding" id="myTab2Content">
<div class="tab-pane fade active show" id="trojan-info" role="tabpanel" aria-labelledby="trojan-info-tab">
{$sort14Node = URL::getTrojanItem($user, $node, false)}
<p>服务器地址:<code class="card-tag tag-blue">{$sort14Node['address']}</code></p>
<p>服务器端口:<code class="card-tag tag-volcano">{$sort14Node['port']}</code></p>
<p>密码:<code class="card-tag tag-geekblue">{$sort14Node['passwd']}</code></p>
{if $sort14Node['host'] != $sort14Node['address']}
<p>HOST&PEER:<code class="card-tag tag-green">{$sort14Node['host']}</code></p>
{/if}
</div>
</div>
</div>
</div>
</div>
{elseif in_array("ssr",$malio_config['support_sub_type']) }
<div class="tab-pane fade {if $node->mu_only != 1}active show{/if}" id="ssr" role="tabpanel" aria-labelledby="ssr-tab">
<div class="row mt-2">
{if URL::SSRCanConnect($user, $mu)}
@ -364,6 +394,7 @@
</div>
{/foreach}
</div>
{/if}
</div>
</div>
@ -422,4 +453,4 @@
</body>
</html>
</html>

Loading…
Cancel
Save