Skip to content

Commit

Permalink
Merge branch 'master' of github.com:orvice/ss-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Jun 20, 2017
2 parents 3936798 + 3483691 commit e4039a6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 7 deletions.
33 changes: 30 additions & 3 deletions app/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Models\TrafficLog;
use App\Models\NodeInfoLog;
use App\Models\NodeOnlineLog;
use App\Models\User;
use App\Models\Node;
use App\Services\Analytics;
use App\Services\DbConfig;
use App\Utils\Tools;
Expand Down Expand Up @@ -67,9 +69,34 @@ public function trafficLog($request, $response, $args)
if (isset($request->getQueryParams()["page"])) {
$pageNum = $request->getQueryParams()["page"];
}
$logs = TrafficLog::orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
$logs->setPath('/admin/trafficlog');
return $this->view()->assign('logs', $logs)->display('admin/trafficlog.tpl');
$logs = TrafficLog::orderBy('id', 'desc');
if (isset($args['uid'])) {
if ($args['uid'] > 0) {
$logs->where('user_id', $args['uid']);
}
}
if (isset($args['nid'])) {
if ($args['nid'] > 0) {
$logs->where('node_id', $args['nid']);
}
}
$logs = $logs->paginate(15, ['*'], 'page', $pageNum);
$view = $this->view();
if (!isset($args['nid'])) {
$logs->setPath('/admin/trafficlog');
$view->assign('logs', $logs)->assign('seleUser', -1)->assign('seleNode', -1);
} elseif (!isset($args['uid'])){
$node = $args['nid'];
$logs->setPath("/admin/trafficlog/$node");
$view->assign('logs', $logs)->assign('seleUser', -1)->assign('seleNode', $node);
} else {
$node = $args['nid'];
$user = $args['uid'];
$logs->setPath("/admin/trafficlog/$node/$user");
$view->assign('logs', $logs)->assign('seleUser', $user)->assign('seleNode', $node);
}

return $view->assign('users', User::all())->assign('nodes', Node::all())->display('admin/trafficlog.tpl');
}

public function config($request, $response, $args)
Expand Down
13 changes: 10 additions & 3 deletions app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,15 @@ public function trafficLog($request, $response, $args)
if (isset($request->getQueryParams()["page"])) {
$pageNum = $request->getQueryParams()["page"];
}
$traffic = TrafficLog::where('user_id', $this->user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
$traffic->setPath('/user/trafficlog');
return $this->view()->assign('logs', $traffic)->display('user/trafficlog.tpl');
if (isset($args['nid']) && isset($args['nid']) > 0) {
$node = $args['nid'];
$traffic = TrafficLog::where('user_id', $this->user->id)->where('node_id', $node)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
$traffic->setPath("/user/trafficlog/$node");
return $this->view()->assign('logs', $traffic)->assign('seleNode', $node)->assign('nodes', Node::all())->display('user/trafficlog.tpl');
} else {
$traffic = TrafficLog::where('user_id', $this->user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
$traffic->setPath('/user/trafficlog');
return $this->view()->assign('logs', $traffic)->assign('seleNode', -1)->assign('nodes', Node::all())->display('user/trafficlog.tpl');
}
}
}
3 changes: 3 additions & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
$this->post('/method', 'App\Controllers\UserController:updateMethod');
$this->get('/sys', 'App\Controllers\UserController:sys');
$this->get('/trafficlog', 'App\Controllers\UserController:trafficLog');
$this->get('/trafficlog/{nid}', 'App\Controllers\UserController:trafficLog');
$this->get('/kill', 'App\Controllers\UserController:kill');
$this->post('/kill', 'App\Controllers\UserController:handleKill');
$this->get('/logout', 'App\Controllers\UserController:logout');
Expand Down Expand Up @@ -82,6 +83,8 @@
$this->get('/', 'App\Controllers\AdminController:index');
$this->get('/sys', 'App\Controllers\AdminController:sysinfo');
$this->get('/trafficlog', 'App\Controllers\AdminController:trafficLog');
$this->get('/trafficlog/{nid}', 'App\Controllers\AdminController:trafficLog');
$this->get('/trafficlog/{nid}/{uid}', 'App\Controllers\AdminController:trafficLog');
$this->get('/checkinlog', 'App\Controllers\AdminController:checkinLog');
$this->post('/cleannodelog', 'App\Controllers\AdminController:cleanNodelog');
$this->post('/cleanonlinelog', 'App\Controllers\AdminController:cleanOnlinelog');
Expand Down
32 changes: 32 additions & 0 deletions resources/views/default/admin/trafficlog.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@
</div>
<div class="row">
<div class="col-xs-12">
<div class="box form-inline">
<div class="form-group">
<label for="labelUser">用户</label>
<select id="search-user">
<option value="0">所有人</option>
{foreach $users as $user}
<option value="{$user->id}" {if $user->id==$seleUser}selected="selected"{/if}>
{$user->user_name}
</option>
{/foreach}
</select>
</div>
<div class="form-group">
<label for="labelNode">节点</label>
<select id="search-node">
<option value="0">所有节点</option>
{foreach $nodes as $node}
<option value="{$node->id}" {if $node->id==$seleNode}selected="selected"{/if}>
{$node->name}
</option>
{/foreach}
</select>
</div>
<button type="submit" class="btn btn-primary" id="log-search">搜索</button>
</div>
<div class="box">
<div class="box-body table-responsive no-padding">
{$logs->render()}
Expand Down Expand Up @@ -55,5 +80,12 @@

</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<script>
$(document).ready(function () {
$("#log-search").click(function () {
window.setTimeout("location.href='/admin/trafficlog/"+$("#search-node").val()+"/"+$("#search-user").val()+"'", 500);
})
})
</script>

{include file='user/footer.tpl'}
22 changes: 21 additions & 1 deletion resources/views/default/user/trafficlog.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
</div>
<div class="row">
<div class="col-xs-12">
<div class="box form-inline">
<div class="form-group">
<label for="labelNode">节点</label>
<select id="search-node">
<option value="0">所有节点</option>
{foreach $nodes as $node}
<option value="{$node->id}" {if $node->id==$seleNode}selected="selected"{/if}>
{$node->name}
</option>
{/foreach}
</select>
</div>
<button type="submit" class="btn btn-primary" id="log-search">搜索</button>
</div>
<div class="box">
<div class="box-body table-responsive no-padding">
{$logs->render()}
Expand Down Expand Up @@ -50,8 +64,14 @@
</div><!-- /.box -->
</div>
</div>

</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<script>
$(document).ready(function () {
$("#log-search").click(function () {
window.setTimeout("location.href='/user/trafficlog/"+$("#search-node").val()+"'", 500);
})
})
</script>

{include file='user/footer.tpl'}

0 comments on commit e4039a6

Please sign in to comment.