Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…panel into malio
  • Loading branch information
Malio committed May 28, 2020
2 parents d7d536c + 8043684 commit 28213af
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 167 deletions.
6 changes: 6 additions & 0 deletions app/Command/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use App\Models\UnblockIp;
use Exception;
use RuntimeException;
use Ramsey\Uuid\Uuid;

class Job
{
Expand Down Expand Up @@ -610,6 +611,11 @@ public static function CheckJob()

$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
Expand Down
5 changes: 4 additions & 1 deletion app/Controllers/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function ajax($request, $response, $args)
});

$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) {
Expand Down Expand Up @@ -322,6 +322,9 @@ public function ajax($request, $response, $args)
case 13:
$sort = 'Shadowsocks - V2Ray-Plugin';
break;
case 14:
$sort = 'Trojan';
break;
default:
$sort = '系统保留';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public static function getSubinfo($user, $int = 0)
'surge3' => '?surge=3',
'surge4' => '?surge=4',
'surfboard' => '?surfboard=1',
'quantumult' => '?quantumult=' . $int,
'quantumult' => '?quantumult=1' . $int,
'quantumult_v2' => '?list=quantumult',
'quantumult_sub' => '?quantumult=2',
'quantumult_conf' => '?quantumult=3',
Expand Down
13 changes: 8 additions & 5 deletions app/Controllers/Mod_Mu/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,26 @@ static function ($query1) use ($node) {

$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', 'sha224uuid');

$users = array();

foreach ($users_raw as $user_raw) {
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();
$user_raw = Tools::keyFilter($user_raw, $key_list);
$users[] = $user_raw;
} else if (Config::get('keep_connect') === true) {
$user_raw = Tools::keyFilter($user_raw, $key_list);
// 流量耗尽用户限速至 1Mbps
$user_raw = Tools::keyFilter($user_raw, $key_list);
$user_raw->uuid = $user_raw->getUuid();
$user_raw->node_speedlimit = 1;
$users[] = $user_raw;
}
}


$res = [
'ret' => 1,
Expand Down
9 changes: 7 additions & 2 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function node($request, $response, $args)
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;
Expand All @@ -504,7 +504,7 @@ public function node($request, $response, $args)
// 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;
Expand Down Expand Up @@ -731,6 +731,11 @@ public function nodeInfo($request, $response, $args)
return $this->view()->assign('node', $node)->assign('user', $user)->assign('mu', $mu)->assign('relay_rule_id', $relay_rule_id)->registerClass('URL', URL::class)->display('user/nodeinfo.tpl');
}
break;
case 14:
if ((($user->class >= $node->node_class && ($user->node_group == $node->node_group || $node->node_group == 0)) || $user->is_admin) && ($node->node_bandwidth_limit == 0 || $node->node_bandwidth < $node->node_bandwidth_limit)) {
return $this->view()->assign('node', $node)->assign('user', $user)->registerClass('URL', URL::class)->display('user/nodeinfo.tpl');
}
break;
default:
echo '微笑';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Bought.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function shop()
*/
public function used_days()
{
return (int) ((time() - $this->datetime) / 86400);
return (int) ((strtotime(date('Y-m-d')) - $this->datetime) / 86400);
}

/*
Expand Down
10 changes: 5 additions & 5 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use App\Utils\QQWry;
use App\Utils\Radius;
use App\Utils\URL;
use Ramsey\Uuid\Uuid;
use App\Models\DetectLog;
use App\Models\DetectBanLog;

Expand Down Expand Up @@ -140,10 +139,11 @@ public function addInviteCode()

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'];
}

/*
Expand Down
1 change: 0 additions & 1 deletion app/Services/Gateway/TomatoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public function getPurchaseHTML()
}
}
});
setTimeout(f, 1000);
});
</script>
';
Expand Down
1 change: 0 additions & 1 deletion app/Services/Gateway/flyfoxpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public function getPurchaseHTML()
}
}
});
setTimeout(f, 1000);
});
</script>
';
Expand Down
35 changes: 35 additions & 0 deletions app/Utils/AppURI.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static function getSurgeURI($item, $version)
: '');
$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;
}
Expand Down Expand Up @@ -145,6 +148,12 @@ public static function getQuantumultXURI($item)
}
$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;
}
Expand Down Expand Up @@ -267,6 +276,16 @@ public static function getClashURI($item, $ssr_support = false)
}
}
break;
case 'trojan':
$return = [
'name' => $item['remark'],
'type' => 'trojan',
'server' => $item['address'],
'port' => $item['port'],
'password' => $item['passwd'],
'sni' => $item['host']
];
break;
}
return $return;
}
Expand Down Expand Up @@ -344,6 +363,10 @@ public static function getShadowrocketURI($item)
}
$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;
}
Expand Down Expand Up @@ -481,4 +504,16 @@ public static function getSSJSON($item)
}
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;
}
}
71 changes: 69 additions & 2 deletions app/Utils/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,12 @@ public static function getNew_AllItems($user, $Rule)
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) {
Expand Down Expand Up @@ -296,7 +299,7 @@ static function ($query) use ($user) {
$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) {
Expand Down Expand Up @@ -359,6 +362,17 @@ static function ($query) use ($user) {
}
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) {
Expand Down Expand Up @@ -442,6 +456,59 @@ static function ($query) use ($user) {
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 = '';
Expand Down
14 changes: 0 additions & 14 deletions config/.config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,20 +336,6 @@
],
];

#tomatopay番茄云支付
#使用教程:https://swapidc.fanqieui.com/?t/329.html tg群 https://t.me/fanqiepay
$_ENV['tomatopay'] = [
'wxpay'=>[
'mchid' => '', // 商户号
'account' => '', //您在番茄云支付的登录邮箱
'token' => "" // 安全验证码
],
'alipay'=>[
'mchid' => '', // 商户号
'account' => '', //您在番茄云支付的登录邮箱
'token' => "" // 安全验证码
],
];

# flyfox
$_ENV['flyfoxpay'] = [
Expand Down
1 change: 1 addition & 0 deletions resources/views/malio/admin/node/create.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions resources/views/malio/admin/node/edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/malio/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
</div>
<div class="col-4 col-md-2 text-center">
<div class="h2 font-weight-bold">{$malio_config['index_statistics_1_data']}</div>
<div class="text-uppercase font-weight-bold ls-2 text-primary">{$i18n->get('servers')}</div>
<div class="text-uppercase font-weight-bold ls-2 text-primary">{$i18n->get('index-servers')}</div>
</div>
<div class="col-4 col-md-2 text-center">
<div class="h2 font-weight-bold">{$malio_config['index_statistics_2_data']}</div>
Expand Down
Loading

0 comments on commit 28213af

Please sign in to comment.