Skip to content

Commit 6293a8e

Browse files
author
zhangjiangbin
committed
1.修正流量定时统计任务
2.可以自定义生成的端口范围了
1 parent a4528de commit 6293a8e

File tree

7 files changed

+72
-13
lines changed

7 files changed

+72
-13
lines changed

app/Console/Commands/AutoStatisticsUserDailyTrafficJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct()
2121

2222
public function handle()
2323
{
24-
$userList = User::get();
24+
$userList = User::where('status', '>=', 0)->where('enable', 1)->get();
2525
foreach ($userList as $user) {
2626
// 统计一次所有节点的总和
2727
$this->statisticsByNode($user->id);

app/Console/Commands/AutoStatisticsUserHourlyTrafficJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct()
2121

2222
public function handle()
2323
{
24-
$userList = User::get();
24+
$userList = User::where('status', '>=', 0)->where('enable', 1)->get();
2525
foreach ($userList as $user) {
2626
// 统计一次所有节点的总和
2727
$this->statisticsByNode($user->id);

app/Http/Controllers/BaseController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ public function systemConfig()
120120
// 获取一个随机端口
121121
public function getRandPort()
122122
{
123-
$port = mt_rand(10000, 40000);
124-
$deny_port = [17185, 28281];
123+
$config = $this->systemConfig();
124+
125+
$port = mt_rand($config['min_port'], $config['max_port']);
126+
$deny_port = [17185, 28281]; // 注意:生成的端口可能是服务器的SSH端口,需要编辑账号手动调整
125127

126128
$exists_port = User::query()->pluck('port')->toArray();
127129
if (in_array($port, $exists_port) || in_array($port, $deny_port)) {

resources/views/admin/system.blade.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
<span class="help-block"> 生成重置密码必备,示例:https://github.com </span>
8080
</div>
8181
</div>
82+
<div class="form-group">
83+
<label class="col-md-2 control-label">端口范围</label>
84+
<div class="col-md-2">
85+
<div class="input-group input-large input-daterange">
86+
<input type="text" class="form-control" name="min_port" value="{{$min_port}}" id="min_port">
87+
<span class="input-group-addon"> ~ </span>
88+
<input type="text" class="form-control" name="max_port" value="{{$max_port}}" id="max_port">
89+
</div>
90+
</div>
91+
</div>
8292
<div class="form-group">
8393
<label for="is_register" class="col-md-2 control-label">用户注册</label>
8494
<div class="col-md-6">
@@ -570,11 +580,11 @@
570580
var min_rand_score = $(this).val();
571581
572582
$.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'min_rand_score', value:min_rand_score}, function (ret) {
573-
if (ret.status == 'fail') {
574-
layer.msg(ret.message, {time:1000}, function() {
583+
layer.msg(ret.message, {time:1000}, function() {
584+
if (ret.status == 'fail') {
575585
window.location.reload();
576-
});
577-
}
586+
}
587+
});
578588
});
579589
});
580590
@@ -583,11 +593,54 @@
583593
var max_rand_score = $(this).val();
584594
585595
$.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'max_rand_score', value:max_rand_score}, function (ret) {
586-
if (ret.status == 'fail') {
587-
layer.msg(ret.message, {time:1000}, function() {
596+
layer.msg(ret.message, {time:1000}, function() {
597+
if (ret.status == 'fail') {
588598
window.location.reload();
589-
});
590-
}
599+
}
600+
});
601+
});
602+
});
603+
604+
// 设置最小端口
605+
$("#min_port").change(function () {
606+
var min_port = $(this).val();
607+
608+
if (parseInt(min_port) < 1000) {
609+
layer.msg('最小端口不能小于1000', {time:1000});
610+
return ;
611+
}
612+
613+
$.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'min_port', value:min_port}, function (ret) {
614+
layer.msg(ret.message, {time:1000}, function() {
615+
if (ret.status == 'fail') {
616+
window.location.reload();
617+
}
618+
});
619+
});
620+
});
621+
622+
// 设置最大端口
623+
$("#max_port").change(function () {
624+
var min_port = $("#min_port").val();
625+
var max_port = $(this).val();
626+
627+
// 最大端口必须大于最小端口
628+
if (parseInt(max_port) <= parseInt(min_port)) {
629+
layer.msg('必须大于最小端口', {time:1000});
630+
return ;
631+
}
632+
633+
if (parseInt(max_port) > 65535) {
634+
layer.msg('最大端口不能大于65535', {time:1000});
635+
return ;
636+
}
637+
638+
$.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'max_port', value:max_port}, function (ret) {
639+
layer.msg(ret.message, {time:1000}, function() {
640+
if (ret.status == 'fail') {
641+
window.location.reload();
642+
}
643+
});
591644
});
592645
});
593646

resources/views/admin/userList.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@
133133
</td>
134134
<td>
135135
<button type="button" class="btn btn-sm blue btn-outline" onclick="editUser('{{$user->id}}')">编辑</button>
136+
<!--<button type="button" class="btn btn-sm red btn-outline" onclick="delUser('{{$user->id}}')">删除</button>-->
136137
<button type="button" class="btn btn-sm green btn-outline" onclick="do_export('{{$user->id}}')">配置信息</button>
137138
<button type="button" class="btn btn-sm purple btn-outline" onclick="do_monitor('{{$user->id}}')">流量监控</button>
138139
<button type="button" class="btn btn-sm green-meadow btn-outline" onclick="resetTraffic('{{$user->id}}')">重置流量</button>
139-
<button type="button" class="btn btn-sm red btn-outline" onclick="delUser('{{$user->id}}')">删除</button>
140140
</td>
141141
</tr>
142142
@endforeach

sql/db.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ INSERT INTO `config` VALUES ('26', 'expire_days', 15);
268268
INSERT INTO `config` VALUES ('27', 'reset_traffic', 1);
269269
INSERT INTO `config` VALUES ('28', 'default_days', 7);
270270
INSERT INTO `config` VALUES ('29', 'subscribe_max', 3);
271+
INSERT INTO `config` VALUES ('30', 'min_port', 10000);
272+
INSERT INTO `config` VALUES ('31', 'max_port', 40000);
271273

272274

273275
-- ----------------------------

sql/update/20171101.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `config` VALUES ('30', 'min_port', 10000);
2+
INSERT INTO `config` VALUES ('31', 'max_port', 40000);

0 commit comments

Comments
 (0)