added kill command in server console
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 13 Oct 2014 19:30:14 +0000 (22:30 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 13 Oct 2014 19:30:14 +0000 (22:30 +0300)
include/nxclapi.h
src/java/netxms-client-api/src/main/java/org/netxms/api/client/SessionNotification.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/console/ApplicationWorkbenchAdvisor.java
src/server/core/client.cpp
src/server/core/main.cpp
src/server/core/session.cpp
src/server/include/nms_core.h
webui/webapp/Core/src/org/netxms/ui/eclipse/console/ApplicationWorkbenchAdvisor.java

index f8d7d27..9c1867d 100644 (file)
@@ -418,6 +418,7 @@ enum
 #define NX_NOTIFY_ALARM_STATUS_FLOW_CHANGED  24
 #define NX_NOTIFY_FILE_LIST_CHANGED          25
 #define NX_NOTIFY_FILE_MONITORING_FAILED     26
+#define NX_NOTIFY_SESSION_KILLED             27
 
 /**
  * Request completion codes
index 36b7cb0..caa8bc4 100644 (file)
@@ -32,6 +32,7 @@ public class SessionNotification
        public static final int DBCON_STATUS_CHANGED = 1010;
        public static final int MAPPING_TABLE_UPDATED = 1019;
        public static final int MAPPING_TABLE_DELETED = 1020;
+   public static final int SESSION_KILLED = 1027;
        
        public static final int CUSTOM_MESSAGE = 2000;
        
index b01dbf4..93e8d71 100644 (file)
@@ -136,7 +136,8 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
                        public void notificationHandler(final SessionNotification n)
                        {
                                if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ||
-                                   (n.getCode() == SessionNotification.SERVER_SHUTDOWN))
+                                   (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || 
+                                   (n.getCode() == SessionNotification.SESSION_KILLED))
                                {
                                        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                                                @Override
@@ -145,8 +146,11 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
                        String productName = BrandingManager.getInstance().getProductName();
                      MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                                                Messages.get().ApplicationWorkbenchAdvisor_CommunicationError,
-                           ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName)
-                                 : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName))
+                           ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? 
+                                 String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName)
+                                 : ((n.getCode() == SessionNotification.SESSION_KILLED) ? 
+                                       "Communication session was terminated by system administrator"
+                                       : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName)))
                                  + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
                                                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
                                                }
index aebca93..0d21483 100644 (file)
@@ -323,14 +323,32 @@ void DumpClientSessions(CONSOLE_CTX pCtx)
 }
 
 /**
+ * Kill client session
+ */
+bool NXCORE_EXPORTABLE KillClientSession(int id)
+{
+   bool success = false;
+   RWLockReadLock(m_rwlockSessionListAccess, INFINITE);
+   for(int i = 0; i < MAX_CLIENT_SESSIONS; i++)
+   {
+      if ((m_pSessionList[i] != NULL) && (m_pSessionList[i]->getId() == id))
+      {
+         m_pSessionList[i]->kill();
+         success = true;
+         break;
+      }
+   }
+   RWLockUnlock(m_rwlockSessionListAccess);
+   return success;
+}
+
+/**
  * Enumerate active sessions
  */
 void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg)
 {
-   int i;
-
    RWLockReadLock(m_rwlockSessionListAccess, INFINITE);
-   for(i = 0; i < MAX_CLIENT_SESSIONS; i++)
+   for(int i = 0; i < MAX_CLIENT_SESSIONS; i++)
    {
       if (m_pSessionList[i] != NULL)
       {
index 9dd5da3..af65f6e 100644 (file)
@@ -1155,6 +1155,33 @@ int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx)
                        ConsolePrintf(pCtx, _T("Cannot exit from local server console\n"));
                }
        }
+       else if (IsCommand(_T("KILL"), szBuffer, 4))
+       {
+               pArg = ExtractWord(pArg, szBuffer);
+               if (szBuffer[0] != 0)
+               {
+         int id = _tcstol(szBuffer, &eptr, 10);
+         if (*eptr == 0)
+         {
+            if (KillClientSession(id))
+            {
+                       ConsolePrintf(pCtx, _T("Session killed\n"));
+            }
+            else
+            {
+                       ConsolePrintf(pCtx, _T("Invalid session ID\n"));
+            }
+         }
+         else
+         {
+                       ConsolePrintf(pCtx, _T("Invalid session ID\n"));
+         }
+               }
+               else
+               {
+                       ConsolePrintf(pCtx, _T("Session ID missing\n"));
+               }
+   }
        else if (IsCommand(_T("SET"), szBuffer, 3))
        {
                pArg = ExtractWord(pArg, szBuffer);
@@ -1730,6 +1757,7 @@ int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx)
                                _T("   down                      - Shutdown NetXMS server\n")
                                _T("   exec <script> [<params>]  - Executes NXSL script from script library\n")
                                _T("   exit                      - Exit from remote session\n")
+            _T("   kill <session>            - Kill client session\n")
                                _T("   get <variable>            - Get value of server configuration variable\n")
                                _T("   help                      - Display this help\n")
                                _T("   ldapsync                  - Synchronize ldap users with local user database\n")
index 3c260f5..faeb0cc 100644 (file)
@@ -2626,6 +2626,8 @@ void ClientSession::getConfigCLOB(CSCPMessage *pRequest)
  */
 void ClientSession::kill()
 {
+   notify(NX_NOTIFY_SESSION_KILLED);
+
    // We shutdown socket connection, which will cause
    // read thread to stop, and other threads will follow
    shutdown(m_hSocket, 2);
index a8c526f..3eec46a 100644 (file)
@@ -889,6 +889,7 @@ void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *,
 void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
 int GetSessionCount(bool withRoot = true);
 bool IsLoggedIn(UINT32 dwUserId);
+bool NXCORE_EXPORTABLE KillClientSession(int id);
 
 void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
 UINT32 GetLocalIpAddr();
index 850e864..da6a675 100644 (file)
@@ -215,7 +215,8 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
             public void notificationHandler(final SessionNotification n)
             {
                                if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ||
-                                   (n.getCode() == SessionNotification.SERVER_SHUTDOWN))
+                                   (n.getCode() == SessionNotification.SERVER_SHUTDOWN) ||
+                                   (n.getCode() == SessionNotification.SESSION_KILLED))
                {
                   display.asyncExec(new Runnable() {
                      @Override
@@ -225,8 +226,11 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
                         MessageDialog.openError(
                               PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                               Messages.get().ApplicationWorkbenchAdvisor_CommunicationError,
-                              ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName)
-                                    : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName))
+                              ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? 
+                                         String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName)
+                                      : ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ?
+                                        "Communication session was terminated by system administrator"
+                                       : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName)))
                                     + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
                         PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
                      }