diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index db28f8aea..fa0338fca 100755 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -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; @@ -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) diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 386d5c303..d700c1c11 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -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'); + } } } diff --git a/app/routes.php b/app/routes.php index 66f420f3c..516c8e834 100755 --- a/app/routes.php +++ b/app/routes.php @@ -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'); @@ -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'); diff --git a/resources/views/default/admin/trafficlog.tpl b/resources/views/default/admin/trafficlog.tpl index c60e8ffba..6411f0168 100755 --- a/resources/views/default/admin/trafficlog.tpl +++ b/resources/views/default/admin/trafficlog.tpl @@ -22,6 +22,31 @@
+
+
+ + +
+
+ + +
+ +
{$logs->render()} @@ -55,5 +80,12 @@
+ {include file='user/footer.tpl'} \ No newline at end of file diff --git a/resources/views/default/user/trafficlog.tpl b/resources/views/default/user/trafficlog.tpl index 75cde3de7..7b426580b 100755 --- a/resources/views/default/user/trafficlog.tpl +++ b/resources/views/default/user/trafficlog.tpl @@ -22,6 +22,20 @@
+
+
+ + +
+ +
{$logs->render()} @@ -50,8 +64,14 @@
-
+ {include file='user/footer.tpl'} \ No newline at end of file