@@ -936,43 +936,187 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) {
936936
937937 // SSH Logins
938938 $scope . sshLogins = [ ] ;
939+ $scope . sshLoginsPaginated = [ ] ;
940+ $scope . sshLoginsCurrentPage = 1 ;
941+ $scope . sshLoginsPerPage = 10 ;
942+ $scope . sshLoginsGoToPage = 1 ;
939943 $scope . loadingSSHLogins = true ;
940944 $scope . errorSSHLogins = '' ;
945+
946+ $scope . getSSHLoginsTotalPages = function ( ) {
947+ return Math . ceil ( $scope . sshLogins . length / $scope . sshLoginsPerPage ) ;
948+ } ;
949+
950+ $scope . getSSHLoginsStart = function ( ) {
951+ if ( ! $scope . sshLogins || $scope . sshLogins . length === 0 ) {
952+ return 0 ;
953+ }
954+ return ( $scope . sshLoginsCurrentPage - 1 ) * $scope . sshLoginsPerPage + 1 ;
955+ } ;
956+
957+ $scope . getSSHLoginsEnd = function ( ) {
958+ if ( ! $scope . sshLogins || $scope . sshLogins . length === 0 ) {
959+ return 0 ;
960+ }
961+ var end = $scope . sshLoginsCurrentPage * $scope . sshLoginsPerPage ;
962+ return Math . min ( end , $scope . sshLogins . length ) ;
963+ } ;
964+
965+ $scope . updateSSHLoginsPaginated = function ( ) {
966+ if ( ! $scope . sshLogins || $scope . sshLogins . length === 0 ) {
967+ $scope . sshLoginsPaginated = [ ] ;
968+ console . log ( 'updateSSHLoginsPaginated: No data, cleared paginated array' ) ;
969+ return ;
970+ }
971+ var start = ( $scope . sshLoginsCurrentPage - 1 ) * $scope . sshLoginsPerPage ;
972+ var end = start + $scope . sshLoginsPerPage ;
973+ $scope . sshLoginsPaginated = $scope . sshLogins . slice ( start , end ) ;
974+ console . log ( 'updateSSHLoginsPaginated: start=' , start , 'end=' , end , 'total=' , $scope . sshLogins . length , 'paginated=' , $scope . sshLoginsPaginated . length ) ;
975+ } ;
976+
977+ $scope . sshLoginsPrevPage = function ( ) {
978+ if ( $scope . sshLoginsCurrentPage > 1 ) {
979+ $scope . sshLoginsCurrentPage -- ;
980+ $scope . updateSSHLoginsPaginated ( ) ;
981+ }
982+ } ;
983+
984+ $scope . sshLoginsNextPage = function ( ) {
985+ if ( $scope . sshLoginsCurrentPage < $scope . getSSHLoginsTotalPages ( ) ) {
986+ $scope . sshLoginsCurrentPage ++ ;
987+ $scope . updateSSHLoginsPaginated ( ) ;
988+ }
989+ } ;
990+
991+ $scope . sshLoginsGoToPageNumber = function ( ) {
992+ var page = parseInt ( $scope . sshLoginsGoToPage ) ;
993+ var totalPages = $scope . getSSHLoginsTotalPages ( ) ;
994+ if ( page >= 1 && page <= totalPages ) {
995+ $scope . sshLoginsCurrentPage = page ;
996+ $scope . updateSSHLoginsPaginated ( ) ;
997+ } else {
998+ $scope . sshLoginsGoToPage = $scope . sshLoginsCurrentPage ;
999+ }
1000+ } ;
1001+
9411002 $scope . refreshSSHLogins = function ( ) {
9421003 $scope . loadingSSHLogins = true ;
9431004 $http . get ( '/base/getRecentSSHLogins' ) . then ( function ( response ) {
9441005 $scope . loadingSSHLogins = false ;
945- if ( response . data && response . data . logins ) {
1006+ console . log ( 'SSH Logins response:' , response . data ) ;
1007+ if ( response . data && response . data . logins && Array . isArray ( response . data . logins ) ) {
9461008 $scope . sshLogins = response . data . logins ;
1009+ $scope . sshLoginsCurrentPage = 1 ;
1010+ $scope . sshLoginsGoToPage = 1 ;
1011+ console . log ( 'SSH Logins loaded:' , $scope . sshLogins . length , 'items' ) ;
1012+ $scope . updateSSHLoginsPaginated ( ) ;
1013+ console . log ( 'SSH Logins paginated:' , $scope . sshLoginsPaginated . length , 'items' ) ;
9471014 } else {
1015+ console . warn ( 'SSH Logins: No data or invalid format' , response . data ) ;
9481016 $scope . sshLogins = [ ] ;
1017+ $scope . sshLoginsPaginated = [ ] ;
9491018 }
9501019 } , function ( err ) {
9511020 $scope . loadingSSHLogins = false ;
1021+ console . error ( 'SSH Logins error:' , err ) ;
9521022 $scope . errorSSHLogins = 'Failed to load SSH logins.' ;
1023+ $scope . sshLogins = [ ] ;
1024+ $scope . sshLoginsPaginated = [ ] ;
9531025 } ) ;
9541026 } ;
9551027
9561028 // SSH Logs
9571029 $scope . sshLogs = [ ] ;
1030+ $scope . sshLogsPaginated = [ ] ;
1031+ $scope . sshLogsCurrentPage = 1 ;
1032+ $scope . sshLogsPerPage = 10 ;
1033+ $scope . sshLogsGoToPage = 1 ;
9581034 $scope . loadingSSHLogs = true ;
9591035 $scope . errorSSHLogs = '' ;
9601036 $scope . securityAlerts = [ ] ;
9611037 $scope . loadingSecurityAnalysis = false ;
1038+
1039+ $scope . getSSHLogsTotalPages = function ( ) {
1040+ return Math . ceil ( $scope . sshLogs . length / $scope . sshLogsPerPage ) ;
1041+ } ;
1042+
1043+ $scope . getSSHLogsStart = function ( ) {
1044+ if ( ! $scope . sshLogs || $scope . sshLogs . length === 0 ) {
1045+ return 0 ;
1046+ }
1047+ return ( $scope . sshLogsCurrentPage - 1 ) * $scope . sshLogsPerPage + 1 ;
1048+ } ;
1049+
1050+ $scope . getSSHLogsEnd = function ( ) {
1051+ if ( ! $scope . sshLogs || $scope . sshLogs . length === 0 ) {
1052+ return 0 ;
1053+ }
1054+ var end = $scope . sshLogsCurrentPage * $scope . sshLogsPerPage ;
1055+ return Math . min ( end , $scope . sshLogs . length ) ;
1056+ } ;
1057+
1058+ $scope . updateSSHLogsPaginated = function ( ) {
1059+ if ( ! $scope . sshLogs || $scope . sshLogs . length === 0 ) {
1060+ $scope . sshLogsPaginated = [ ] ;
1061+ console . log ( 'updateSSHLogsPaginated: No data, cleared paginated array' ) ;
1062+ return ;
1063+ }
1064+ var start = ( $scope . sshLogsCurrentPage - 1 ) * $scope . sshLogsPerPage ;
1065+ var end = start + $scope . sshLogsPerPage ;
1066+ $scope . sshLogsPaginated = $scope . sshLogs . slice ( start , end ) ;
1067+ console . log ( 'updateSSHLogsPaginated: start=' , start , 'end=' , end , 'total=' , $scope . sshLogs . length , 'paginated=' , $scope . sshLogsPaginated . length ) ;
1068+ } ;
1069+
1070+ $scope . sshLogsPrevPage = function ( ) {
1071+ if ( $scope . sshLogsCurrentPage > 1 ) {
1072+ $scope . sshLogsCurrentPage -- ;
1073+ $scope . updateSSHLogsPaginated ( ) ;
1074+ }
1075+ } ;
1076+
1077+ $scope . sshLogsNextPage = function ( ) {
1078+ if ( $scope . sshLogsCurrentPage < $scope . getSSHLogsTotalPages ( ) ) {
1079+ $scope . sshLogsCurrentPage ++ ;
1080+ $scope . updateSSHLogsPaginated ( ) ;
1081+ }
1082+ } ;
1083+
1084+ $scope . sshLogsGoToPageNumber = function ( ) {
1085+ var page = parseInt ( $scope . sshLogsGoToPage ) ;
1086+ var totalPages = $scope . getSSHLogsTotalPages ( ) ;
1087+ if ( page >= 1 && page <= totalPages ) {
1088+ $scope . sshLogsCurrentPage = page ;
1089+ $scope . updateSSHLogsPaginated ( ) ;
1090+ } else {
1091+ $scope . sshLogsGoToPage = $scope . sshLogsCurrentPage ;
1092+ }
1093+ } ;
1094+
9621095 $scope . refreshSSHLogs = function ( ) {
9631096 $scope . loadingSSHLogs = true ;
9641097 $http . get ( '/base/getRecentSSHLogs' ) . then ( function ( response ) {
9651098 $scope . loadingSSHLogs = false ;
966- if ( response . data && response . data . logs ) {
1099+ console . log ( 'SSH Logs response:' , response . data ) ;
1100+ if ( response . data && response . data . logs && Array . isArray ( response . data . logs ) ) {
9671101 $scope . sshLogs = response . data . logs ;
1102+ $scope . sshLogsCurrentPage = 1 ;
1103+ $scope . sshLogsGoToPage = 1 ;
1104+ console . log ( 'SSH Logs loaded:' , $scope . sshLogs . length , 'items' ) ;
1105+ $scope . updateSSHLogsPaginated ( ) ;
1106+ console . log ( 'SSH Logs paginated:' , $scope . sshLogsPaginated . length , 'items' ) ;
9681107 // Analyze logs for security issues
9691108 $scope . analyzeSSHSecurity ( ) ;
9701109 } else {
1110+ console . warn ( 'SSH Logs: No data or invalid format' , response . data ) ;
9711111 $scope . sshLogs = [ ] ;
1112+ $scope . sshLogsPaginated = [ ] ;
9721113 }
9731114 } , function ( err ) {
9741115 $scope . loadingSSHLogs = false ;
1116+ console . error ( 'SSH Logs error:' , err ) ;
9751117 $scope . errorSSHLogs = 'Failed to load SSH logs.' ;
1118+ $scope . sshLogs = [ ] ;
1119+ $scope . sshLogsPaginated = [ ] ;
9761120 } ) ;
9771121 } ;
9781122
@@ -1499,16 +1643,48 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) {
14991643 var match = login . raw . match ( / ( p t s \/ [ 0 - 9 ] + ) / ) ;
15001644 if ( match ) tty = match [ 1 ] ;
15011645 }
1502- $http . post ( '/base/getSSHUserActivity' , { user : login . user , tty : tty } ) . then ( function ( response ) {
1646+ console . log ( 'Fetching SSH activity for user:' , login . user , 'IP:' , login . ip , 'TTY:' , tty ) ;
1647+ $http . post ( '/base/getSSHUserActivity' , { user : login . user , tty : tty , ip : login . ip || '' } , {
1648+ timeout : 30000
1649+ } ) . then ( function ( response ) {
1650+ console . log ( 'SSH Activity response received:' , response ) ;
15031651 $scope . loadingSSHActivity = false ;
1504- if ( response . data ) {
1652+ if ( response . data && response . data . error ) {
1653+ console . error ( 'SSH Activity error:' , response . data . error ) ;
1654+ $scope . errorSSHActivity = response . data . error ;
1655+ $scope . sshActivity = { processes : [ ] , w : [ ] , shell_history : [ ] , geoip : { } , disk_usage : '' } ;
1656+ } else if ( response . data ) {
1657+ console . log ( 'SSH Activity data:' , response . data ) ;
15051658 $scope . sshActivity = response . data ;
1659+ $scope . errorSSHActivity = '' ;
15061660 } else {
1507- $scope . sshActivity = { processes : [ ] , w : [ ] } ;
1661+ console . warn ( 'SSH Activity: No data in response' ) ;
1662+ $scope . sshActivity = { processes : [ ] , w : [ ] , shell_history : [ ] , geoip : { } , disk_usage : '' } ;
1663+ $scope . errorSSHActivity = 'No data received from server.' ;
15081664 }
15091665 } , function ( err ) {
15101666 $scope . loadingSSHActivity = false ;
1511- $scope . errorSSHActivity = ( err . data && err . data . error ) ? err . data . error : 'Failed to fetch activity.' ;
1667+ console . error ( 'Error fetching SSH activity:' , err ) ;
1668+ console . error ( 'Error status:' , err . status ) ;
1669+ console . error ( 'Error data:' , err . data ) ;
1670+ if ( err . status === 0 ) {
1671+ $scope . errorSSHActivity = 'Network error: Unable to connect to server. Please check your connection.' ;
1672+ } else if ( err . status === - 1 ) {
1673+ $scope . errorSSHActivity = 'Request timeout. The server took too long to respond.' ;
1674+ } else if ( err . data && err . data . error ) {
1675+ $scope . errorSSHActivity = err . data . error ;
1676+ } else if ( err . data && err . data . errorMessage ) {
1677+ $scope . errorSSHActivity = err . data . errorMessage ;
1678+ } else if ( err . status === 403 ) {
1679+ $scope . errorSSHActivity = 'Access denied. Admin privileges required.' ;
1680+ } else if ( err . status === 400 ) {
1681+ $scope . errorSSHActivity = 'Invalid request. Please try again.' ;
1682+ } else if ( err . status === 500 ) {
1683+ $scope . errorSSHActivity = 'Server error. Please try again later.' ;
1684+ } else {
1685+ $scope . errorSSHActivity = 'Failed to fetch activity. Status: ' + ( err . status || 'Unknown' ) + '. Please check your connection and try again.' ;
1686+ }
1687+ $scope . sshActivity = { processes : [ ] , w : [ ] , shell_history : [ ] , geoip : { } , disk_usage : '' } ;
15121688 } ) ;
15131689 } ;
15141690
@@ -1526,4 +1702,79 @@ app.controller('dashboardStatsController', function ($scope, $http, $timeout) {
15261702 $scope . closeSSHActivityModal ( ) ;
15271703 }
15281704 } ;
1705+
1706+ // Kill a specific process
1707+ $scope . killProcess = function ( pid , user ) {
1708+ if ( ! confirm ( 'Are you sure you want to kill process ' + pid + '? This action cannot be undone.' ) ) {
1709+ return ;
1710+ }
1711+
1712+ console . log ( 'Killing process:' , pid , 'for user:' , user ) ;
1713+ $http . post ( '/base/killSSHProcess' , { pid : pid , user : user } , { timeout : 10000 } ) . then ( function ( response ) {
1714+ if ( response . data && response . data . success ) {
1715+ alert ( 'Process ' + pid + ' killed successfully.' ) ;
1716+ // Reload activity data
1717+ if ( $scope . sshActivityUser ) {
1718+ var login = { user : $scope . sshActivityUser , ip : '' , tty : '' } ;
1719+ $scope . viewSSHActivity ( login ) ;
1720+ }
1721+ } else if ( response . data && response . data . error ) {
1722+ alert ( 'Error: ' + response . data . error ) ;
1723+ } else {
1724+ alert ( 'Unknown error occurred.' ) ;
1725+ }
1726+ } , function ( err ) {
1727+ console . error ( 'Error killing process:' , err ) ;
1728+ var errorMsg = 'Failed to kill process. ' ;
1729+ if ( err . data && err . data . error ) {
1730+ errorMsg += err . data . error ;
1731+ } else if ( err . status === 403 ) {
1732+ errorMsg += 'Access denied.' ;
1733+ } else if ( err . status === 404 ) {
1734+ errorMsg += 'Process not found.' ;
1735+ } else {
1736+ errorMsg += 'Please try again.' ;
1737+ }
1738+ alert ( errorMsg ) ;
1739+ } ) ;
1740+ } ;
1741+
1742+ // Kill all sessions for a user
1743+ $scope . killSession = function ( user ) {
1744+ if ( ! confirm ( 'WARNING: This will force close ALL active sessions for user "' + user + '". This action cannot be undone.\n\nAre you sure you want to continue?' ) ) {
1745+ return ;
1746+ }
1747+
1748+ if ( ! confirm ( 'Final confirmation: Kill all sessions for user "' + user + '"?' ) ) {
1749+ return ;
1750+ }
1751+
1752+ console . log ( 'Killing session for user:' , user ) ;
1753+ $http . post ( '/base/killSSHSession' , { user : user } , { timeout : 10000 } ) . then ( function ( response ) {
1754+ if ( response . data && response . data . success ) {
1755+ alert ( 'All sessions for user ' + user + ' have been terminated successfully.' ) ;
1756+ // Close modal and refresh SSH logins
1757+ $scope . closeSSHActivityModal ( ) ;
1758+ // Refresh SSH logins list
1759+ if ( typeof $scope . loadSSHLogins === 'function' ) {
1760+ $scope . loadSSHLogins ( ) ;
1761+ }
1762+ } else if ( response . data && response . data . error ) {
1763+ alert ( 'Error: ' + response . data . error ) ;
1764+ } else {
1765+ alert ( 'Unknown error occurred.' ) ;
1766+ }
1767+ } , function ( err ) {
1768+ console . error ( 'Error killing session:' , err ) ;
1769+ var errorMsg = 'Failed to kill session. ' ;
1770+ if ( err . data && err . data . error ) {
1771+ errorMsg += err . data . error ;
1772+ } else if ( err . status === 403 ) {
1773+ errorMsg += 'Access denied.' ;
1774+ } else {
1775+ errorMsg += 'Please try again.' ;
1776+ }
1777+ alert ( errorMsg ) ;
1778+ } ) ;
1779+ } ;
15291780} ) ;
0 commit comments