implemented all repository related functions in server and Java API
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 19:18:37 +0000 (22:18 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 12 May 2016 19:18:37 +0000 (22:18 +0300)
16 files changed:
include/nxcldefs.h
src/java/client/netxms-base/src/main/java/org/netxms/base/NXCPCodes.java
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/constants/UserAccessRights.java
src/java/client/netxms-client/src/main/java/org/netxms/client/market/Repository.java
src/java/netxms-eclipse/FileManager/src/org/netxms/ui/eclipse/filemanager/views/helpers/ViewAgentFilesProvider.java
src/java/netxms-eclipse/ServerConfig/META-INF/MANIFEST.MF
src/java/netxms-eclipse/ServerConfig/plugin.xml
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/Activator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ExportFileBuilder.java
src/libnetxms/nxcp.cpp
src/server/core/Makefile.am
src/server/core/audit.cpp
src/server/core/market.cpp [new file with mode: 0644]
src/server/core/session.cpp
src/server/include/nms_core.h

index 35463be..5ddd8bc 100644 (file)
@@ -580,44 +580,46 @@ enum SessionState
  */
 #ifndef NETXMS_CUSTOM_USER_RIGHTS
 
-#define SYSTEM_ACCESS_MANAGE_USERS          _ULL(0x000000001)
-#define SYSTEM_ACCESS_SERVER_CONFIG         _ULL(0x000000002)
-#define SYSTEM_ACCESS_CONFIGURE_TRAPS       _ULL(0x000000004)
-#define SYSTEM_ACCESS_MANAGE_SESSIONS       _ULL(0x000000008)
-#define SYSTEM_ACCESS_VIEW_EVENT_DB         _ULL(0x000000010)
-#define SYSTEM_ACCESS_EDIT_EVENT_DB         _ULL(0x000000020)
-#define SYSTEM_ACCESS_EPP                   _ULL(0x000000040)
-#define SYSTEM_ACCESS_MANAGE_ACTIONS        _ULL(0x000000080)
-#define SYSTEM_ACCESS_DELETE_ALARMS         _ULL(0x000000100)
-#define SYSTEM_ACCESS_MANAGE_PACKAGES       _ULL(0x000000200)
-#define SYSTEM_ACCESS_VIEW_EVENT_LOG        _ULL(0x000000400)
-#define SYSTEM_ACCESS_MANAGE_TOOLS          _ULL(0x000000800)
-#define SYSTEM_ACCESS_MANAGE_SCRIPTS        _ULL(0x000001000)
-#define SYSTEM_ACCESS_VIEW_TRAP_LOG         _ULL(0x000002000)
-#define SYSTEM_ACCESS_VIEW_AUDIT_LOG        _ULL(0x000004000)
-#define SYSTEM_ACCESS_MANAGE_AGENT_CFG      _ULL(0x000008000)
-#define SYSTEM_ACCESS_MANAGE_SITUATIONS     _ULL(0x000010000)
-#define SYSTEM_ACCESS_SEND_SMS              _ULL(0x000020000)
-#define SYSTEM_ACCESS_MOBILE_DEVICE_LOGIN   _ULL(0x000040000)
-#define SYSTEM_ACCESS_REGISTER_AGENTS       _ULL(0x000080000)
-#define SYSTEM_ACCESS_READ_SERVER_FILES     _ULL(0x000100000)
-#define SYSTEM_ACCESS_SERVER_CONSOLE        _ULL(0x000200000)
-#define SYSTEM_ACCESS_MANAGE_SERVER_FILES   _ULL(0x000400000)
-#define SYSTEM_ACCESS_MANAGE_MAPPING_TBLS   _ULL(0x000800000)
-#define SYSTEM_ACCESS_MANAGE_SUMMARY_TBLS   _ULL(0x001000000)
-#define SYSTEM_ACCESS_REPORTING_SERVER      _ULL(0x002000000)
-#define SYSTEM_ACCESS_XMPP_COMMANDS         _ULL(0x004000000)
-#define SYSTEM_ACCESS_MANAGE_IMAGE_LIB      _ULL(0x008000000)
-#define SYSTEM_ACCESS_UNLINK_ISSUES         _ULL(0x010000000)
-#define SYSTEM_ACCESS_VIEW_SYSLOG           _ULL(0x020000000)
-#define SYSTEM_ACCESS_USER_SCHEDULED_TASKS  _ULL(0x040000000)
-#define SYSTEM_ACCESS_OWN_SCHEDULED_TASKS   _ULL(0x080000000)
-#define SYSTEM_ACCESS_ALL_SCHEDULED_TASKS   _ULL(0x100000000)
-#define SYSTEM_ACCESS_SCHEDULE_SCRIPT       _ULL(0x200000000)
-#define SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD  _ULL(0x400000000)
-#define SYSTEM_ACCESS_SCHEDULE_MAINTENANCE  _ULL(0x800000000)
-
-#define SYSTEM_ACCESS_FULL                  _ULL(0xFFFFFFFFF)
+#define SYSTEM_ACCESS_MANAGE_USERS          _ULL(0x000000000001)
+#define SYSTEM_ACCESS_SERVER_CONFIG         _ULL(0x000000000002)
+#define SYSTEM_ACCESS_CONFIGURE_TRAPS       _ULL(0x000000000004)
+#define SYSTEM_ACCESS_MANAGE_SESSIONS       _ULL(0x000000000008)
+#define SYSTEM_ACCESS_VIEW_EVENT_DB         _ULL(0x000000000010)
+#define SYSTEM_ACCESS_EDIT_EVENT_DB         _ULL(0x000000000020)
+#define SYSTEM_ACCESS_EPP                   _ULL(0x000000000040)
+#define SYSTEM_ACCESS_MANAGE_ACTIONS        _ULL(0x000000000080)
+#define SYSTEM_ACCESS_DELETE_ALARMS         _ULL(0x000000000100)
+#define SYSTEM_ACCESS_MANAGE_PACKAGES       _ULL(0x000000000200)
+#define SYSTEM_ACCESS_VIEW_EVENT_LOG        _ULL(0x000000000400)
+#define SYSTEM_ACCESS_MANAGE_TOOLS          _ULL(0x000000000800)
+#define SYSTEM_ACCESS_MANAGE_SCRIPTS        _ULL(0x000000001000)
+#define SYSTEM_ACCESS_VIEW_TRAP_LOG         _ULL(0x000000002000)
+#define SYSTEM_ACCESS_VIEW_AUDIT_LOG        _ULL(0x000000004000)
+#define SYSTEM_ACCESS_MANAGE_AGENT_CFG      _ULL(0x000000008000)
+#define SYSTEM_ACCESS_MANAGE_SITUATIONS     _ULL(0x000000010000)
+#define SYSTEM_ACCESS_SEND_SMS              _ULL(0x000000020000)
+#define SYSTEM_ACCESS_MOBILE_DEVICE_LOGIN   _ULL(0x000000040000)
+#define SYSTEM_ACCESS_REGISTER_AGENTS       _ULL(0x000000080000)
+#define SYSTEM_ACCESS_READ_SERVER_FILES     _ULL(0x000000100000)
+#define SYSTEM_ACCESS_SERVER_CONSOLE        _ULL(0x000000200000)
+#define SYSTEM_ACCESS_MANAGE_SERVER_FILES   _ULL(0x000000400000)
+#define SYSTEM_ACCESS_MANAGE_MAPPING_TBLS   _ULL(0x000000800000)
+#define SYSTEM_ACCESS_MANAGE_SUMMARY_TBLS   _ULL(0x000001000000)
+#define SYSTEM_ACCESS_REPORTING_SERVER      _ULL(0x000002000000)
+#define SYSTEM_ACCESS_XMPP_COMMANDS         _ULL(0x000004000000)
+#define SYSTEM_ACCESS_MANAGE_IMAGE_LIB      _ULL(0x000008000000)
+#define SYSTEM_ACCESS_UNLINK_ISSUES         _ULL(0x000010000000)
+#define SYSTEM_ACCESS_VIEW_SYSLOG           _ULL(0x000020000000)
+#define SYSTEM_ACCESS_USER_SCHEDULED_TASKS  _ULL(0x000040000000)
+#define SYSTEM_ACCESS_OWN_SCHEDULED_TASKS   _ULL(0x000080000000)
+#define SYSTEM_ACCESS_ALL_SCHEDULED_TASKS   _ULL(0x000100000000)
+#define SYSTEM_ACCESS_SCHEDULE_SCRIPT       _ULL(0x000200000000)
+#define SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD  _ULL(0x000400000000)
+#define SYSTEM_ACCESS_SCHEDULE_MAINTENANCE  _ULL(0x000800000000)
+#define SYSTEM_ACCESS_MANAGE_REPOSITORIES   _ULL(0x001000000000)
+#define SYSTEM_ACCESS_VIEW_REPOSITORIES     _ULL(0x002000000000)
+
+#define SYSTEM_ACCESS_FULL                  _ULL(0x003FFFFFFFFF)
 
 #endif /* NETXMS_CUSTOM_USER_RIGHTS */
 
index 7524879..edccea0 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2015 Victor Kirhenshtein
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 6e63c88..4ff2501 100644 (file)
@@ -106,6 +106,7 @@ import org.netxms.client.maps.NetworkMapLink;
 import org.netxms.client.maps.NetworkMapPage;
 import org.netxms.client.maps.elements.NetworkMapElement;
 import org.netxms.client.maps.elements.NetworkMapObject;
+import org.netxms.client.market.Repository;
 import org.netxms.client.mt.MappingTable;
 import org.netxms.client.mt.MappingTableDescriptor;
 import org.netxms.client.objects.AbstractObject;
@@ -8753,30 +8754,107 @@ public class NXCSession
        waitForRCC(msg.getMessageId());
    }
    
+   /**
+    * @param type
+    * @return
+    * @throws IOException
+    * @throws NXCException
+    */
    public List<ZmqSubscription> getZmqSubscriptions(ZmqSubscriptionType type) throws IOException, NXCException
    {
-       final NXCPMessage msg = newMessage(type == ZmqSubscriptionType.EVENT ? NXCPCodes.CMD_ZMQ_GET_EVT_SUBSCRIPTIONS : NXCPCodes.CMD_ZMQ_GET_DATA_SUBSCRIPTIONS);
-       sendMessage(msg);
-       final NXCPMessage response = waitForRCC(msg.getMessageId());
+      final NXCPMessage msg = newMessage(type == ZmqSubscriptionType.EVENT ? NXCPCodes.CMD_ZMQ_GET_EVT_SUBSCRIPTIONS
+            : NXCPCodes.CMD_ZMQ_GET_DATA_SUBSCRIPTIONS);
+      sendMessage(msg);
+      final NXCPMessage response = waitForRCC(msg.getMessageId());
 
-       final List<ZmqSubscription> subscriptions = new ArrayList<ZmqSubscription>();
-       
-       long baseId = NXCPCodes.VID_ZMQ_SUBSCRIPTION_BASE;
-       while (true)
-       {
-          long objectId = response.getFieldAsInt32(baseId);
-          if (objectId == 0)
-          {
-              break;
-          }
-          boolean ignoreItems = response.getFieldAsBoolean(baseId + 1);
-          long[] dciElements = response.getFieldAsUInt32Array(baseId + 2);
-          
-          subscriptions.add(new ZmqSubscription(objectId, ignoreItems, dciElements));
-          
-          baseId += 10;
-       }
-       
-       return subscriptions;
+      final List<ZmqSubscription> subscriptions = new ArrayList<ZmqSubscription>();
+
+      long baseId = NXCPCodes.VID_ZMQ_SUBSCRIPTION_BASE;
+      while(true)
+      {
+         long objectId = response.getFieldAsInt32(baseId);
+         if (objectId == 0)
+         {
+            break;
+         }
+         boolean ignoreItems = response.getFieldAsBoolean(baseId + 1);
+         long[] dciElements = response.getFieldAsUInt32Array(baseId + 2);
+
+         subscriptions.add(new ZmqSubscription(objectId, ignoreItems, dciElements));
+
+         baseId += 10;
+      }
+
+      return subscriptions;
+   }
+
+   /**
+    * Get list of configured repositories
+    * 
+    * @return list of configured repositories
+    * @throws IOException
+    * @throws NXCException
+    */
+   public List<Repository> getRepositories() throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_REPOSITORIES);
+      sendMessage(msg);
+      final NXCPMessage response = waitForRCC(msg.getMessageId());
+      
+      int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
+      List<Repository> list = new ArrayList<Repository>(count);
+      long fieldId = NXCPCodes.VID_ELEMENT_LIST_BASE;
+      for(int i = 0; i < count; i++)
+      {
+         list.add(new Repository(response, fieldId));
+         fieldId += 10;
+      }
+      return list;
+   }
+   
+   /**
+    * Add repository. Will update given repository object with assigned ID.
+    * 
+    * @param r
+    * @throws IOException
+    * @throws NXCException
+    */
+   public void addRepository(Repository r) throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_ADD_REPOSITORY);
+      r.fillMessage(msg);
+      sendMessage(msg);
+      final NXCPMessage response = waitForRCC(msg.getMessageId());
+      r.setId(response.getFieldAsInt32(NXCPCodes.VID_OBJECT_ID));
+   }
+
+   /**
+    * Modify repository.
+    * 
+    * @param r
+    * @throws IOException
+    * @throws NXCException
+    */
+   public void modifyRepository(Repository r) throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_MODIFY_REPOSITORY);
+      r.fillMessage(msg);
+      sendMessage(msg);
+      waitForRCC(msg.getMessageId());
+   }
+
+   /**
+    * Delete repository.
+    * 
+    * @param id
+    * @throws IOException
+    * @throws NXCException
+    */
+   public void deleteRepository(int id) throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_DELETE_REPOSITORY);
+      msg.setFieldInt32(NXCPCodes.VID_REPOSITORY_ID, id);
+      sendMessage(msg);
+      waitForRCC(msg.getMessageId());
    }
 }
index 84762a3..805a920 100644 (file)
@@ -46,6 +46,7 @@ public class UserAccessRights
    public static final long SYSTEM_ACCESS_SCHEDULE_SCRIPT       = 0x0200000000L;
    public static final long SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD  = 0x0400000000L;
    public static final long SYSTEM_ACCESS_SCHEDULE_MAINTENANCE  = 0x0800000000L;
+   public static final long SYSTEM_ACCESS_MANAGE_REPOSITORIES   = 0x1000000000L;
 
        // Object access rights
        public static final int OBJECT_ACCESS_READ          = 0x00000001;
index aa1d8dc..fd57243 100644 (file)
@@ -26,6 +26,7 @@ import org.netxms.base.NXCPMessage;
  */
 public class Repository
 {
+   private int id;
    private String url;
    private String authToken;
    private String description;
@@ -39,6 +40,7 @@ public class Repository
     */
    public Repository(String url, String authToken, String description)
    {
+      this.id = 0;
       this.url = url;
       this.authToken = authToken;
       this.description = description;
@@ -52,9 +54,10 @@ public class Repository
     */
    public Repository(NXCPMessage msg, long baseId)
    {
-      url = msg.getFieldAsString(baseId);
-      authToken = msg.getFieldAsString(baseId + 1);
-      description = msg.getFieldAsString(baseId + 2);
+      id = msg.getFieldAsInt32(baseId);
+      url = msg.getFieldAsString(baseId + 1);
+      authToken = msg.getFieldAsString(baseId + 2);
+      description = msg.getFieldAsString(baseId + 3);
    }
    
    /**
@@ -64,11 +67,28 @@ public class Repository
     */
    public void fillMessage(NXCPMessage msg)
    {
+      msg.setFieldInt32(NXCPCodes.VID_REPOSITORY_ID, id);
       msg.setField(NXCPCodes.VID_URL, url);
       msg.setField(NXCPCodes.VID_AUTH_TOKEN, authToken);
       msg.setField(NXCPCodes.VID_DESCRIPTION, description);
    }
 
+   /**
+    * @return the id
+    */
+   public int getId()
+   {
+      return id;
+   }
+
+   /**
+    * @param id the id to set
+    */
+   public void setId(int id)
+   {
+      this.id = id;
+   }
+
    /**
     * @return the url
     */
index 21aedf1..2c0cb29 100644 (file)
@@ -54,7 +54,7 @@ public class ViewAgentFilesProvider implements ITreeContentProvider
        @Override
        public Object[] getChildren(final Object parentElement)
        {
-          if(((AgentFile)parentElement).getChildren() == null)
+          if (((AgentFile)parentElement).getChildren() == null)
           {
          ConsoleJob job = new ConsoleJob(Messages.get().ViewAgentFilesProvider_JobTitle, null, Activator.PLUGIN_ID, null) {
             @Override
index dfad009..38d10e5 100644 (file)
@@ -2,13 +2,13 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: NXMC Server Configuration Plug-in
 Bundle-SymbolicName: org.netxms.ui.eclipse.serverconfig;singleton:=true
-Bundle-Version: 2.0.7
+Bundle-Version: 2.0.8
 Bundle-Activator: org.netxms.ui.eclipse.serverconfig.Activator
 Bundle-Vendor: netxms.org
 Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
  org.eclipse.core.runtime;bundle-version="3.8.0",
  org.eclipse.ui.forms;bundle-version="3.5.200",
- org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.9",
+ org.netxms.ui.eclipse.clientlibrary;bundle-version="2.0.10",
  org.netxms.ui.eclipse.console;bundle-version="2.0.10",
  org.netxms.ui.eclipse.eventmanager;bundle-version="2.0.1",
  org.netxms.ui.eclipse.objectbrowser;bundle-version="2.0.3",
index dbb129b..424081b 100644 (file)
             id="org.netxms.ui.eclipse.serverconfig.commands.open_scheduled_tasks"
             name="Scheduled tasks">
       </command>
+      <command
+            id="org.netxms.ui.eclipse.serverconfig.commands.publish_config"
+            name="Publish configuration">
+      </command>
    </extension>
 
    <extension point = "org.eclipse.ui.actionSets">
             schemeId="org.netxms.ui.eclipse.defaultKeyBinding"
             sequence="M1+N">
       </key>
+      <key
+            commandId="org.netxms.ui.eclipse.serverconfig.commands.publish_config"
+            contextId="org.netxms.ui.eclipse.serverconfig.context.ExportFileBuilder"
+            schemeId="org.netxms.ui.eclipse.defaultKeyBinding"
+            sequence="M1+P">
+      </key>
    </extension>
    <extension
          point="org.eclipse.ui.activities">
index f1d67f0..faffd74 100644 (file)
@@ -1,5 +1,6 @@
 package org.netxms.ui.eclipse.serverconfig;
 
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -77,4 +78,35 @@ public class Activator extends AbstractUIPlugin
        {
                return imageDescriptorFromPlugin(PLUGIN_ID, path);
        }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logInfo(String msg)
+   {
+      log(Status.INFO, msg, null);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    */
+   public static void logError(String msg, Throwable t)
+   {
+      log(Status.ERROR, msg, t);
+   }
+
+   /**
+    * Log via platform logging facilities
+    * 
+    * @param msg
+    * @param t
+    */
+   public static void log(int status, String msg, Throwable t)
+   {
+      getDefault().getLog().log(new Status(status, PLUGIN_ID, Status.OK, msg, t));
+   }
 }
index a15be27..3fd4892 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2015 Victor Kirhenshtein
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 package org.netxms.ui.eclipse.serverconfig.views;
 
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -56,11 +60,13 @@ import org.eclipse.ui.forms.widgets.TableWrapLayout;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.part.ViewPart;
+import org.netxms.base.NXCommon;
 import org.netxms.client.NXCSession;
 import org.netxms.client.Script;
 import org.netxms.client.datacollection.DciSummaryTableDescriptor;
 import org.netxms.client.events.EventProcessingPolicyRule;
 import org.netxms.client.events.EventTemplate;
+import org.netxms.client.market.Repository;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.Template;
 import org.netxms.client.objecttools.ObjectTool;
@@ -74,6 +80,7 @@ import org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.Activator;
 import org.netxms.ui.eclipse.serverconfig.Messages;
 import org.netxms.ui.eclipse.serverconfig.dialogs.ObjectToolSelectionDialog;
+import org.netxms.ui.eclipse.serverconfig.dialogs.RepositorySelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SelectSnmpTrapDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.SummaryTableSelectionDialog;
 import org.netxms.ui.eclipse.serverconfig.dialogs.helpers.TrapListLabelProvider;
@@ -108,6 +115,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
    private TableViewer toolsViewer;
    private TableViewer summaryTableViewer;
        private Action actionSave;
+       private Action actionPublish;
        private Map<Long, EventTemplate> events = new HashMap<Long, EventTemplate>();
        private Map<Long, Template> templates = new HashMap<Long, Template>();
        private Map<Long, SnmpTrap> traps = new HashMap<Long, SnmpTrap>();
@@ -705,6 +713,16 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                };
                actionSave.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.save_exported_config"); //$NON-NLS-1$
       handlerService.activateHandler(actionSave.getActionDefinitionId(), new ActionHandler(actionSave));
+      
+      actionPublish = new Action("&Publish...", Activator.getImageDescriptor("icons/publish.gif")) {
+         @Override
+         public void run()
+         {
+            publish();
+         }
+      };
+      actionPublish.setActionDefinitionId("org.netxms.ui.eclipse.serverconfig.commands.publish_config"); //$NON-NLS-1$
+      handlerService.activateHandler(actionPublish.getActionDefinitionId(), new ActionHandler(actionPublish));
        }
        
        /**
@@ -726,6 +744,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        private void fillLocalPullDown(IMenuManager manager)
        {
                manager.add(actionSave);
+               manager.add(actionPublish);
        }
 
        /**
@@ -737,6 +756,7 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
        private void fillLocalToolBar(IToolBarManager manager)
        {
                manager.add(actionSave);
+      manager.add(actionPublish);
        }
 
        /* (non-Javadoc)
@@ -759,32 +779,123 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
                        firePropertyChange(PROP_DIRTY);
                }
        }
-
+       
        /**
-        * Save settings
+        * Publish configuration
         */
-       private void save()
+       private void publish()
        {
-               final long[] eventList = new long[events.size()];
-               int i = 0;
-               for(EventTemplate t : events.values())
-                       eventList[i++] = t.getCode();
-               
-               final long[] templateList = new long[templates.size()];
-               i = 0;
-               for(Template t : templates.values())
-                       templateList[i++] = t.getObjectId();
-               
-               final long[] trapList = new long[traps.size()];
-               i = 0;
-               for(SnmpTrap t : traps.values())
-                       trapList[i++] = t.getId();
-               
-               final UUID[] ruleList = new UUID[rules.size()];
-               i = 0;
-               for(EventProcessingPolicyRule r : rules.values())
-                       ruleList[i++] = r.getGuid();
-               
+          new ConsoleJob("Get list of configured repositories", this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final List<Repository> repositories = session.getRepositories();
+            runInUIThread(new Runnable() {
+               @Override
+               public void run()
+               {
+                  publishStage2(repositories);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return "Cannot get list of configured repositories";
+         }
+      }.start();
+       }
+       
+       /**
+        * Publish configuration - stage 2
+        * 
+        * @param repositories
+        */
+       private void publishStage2(List<Repository> repositories)
+       {
+          RepositorySelectionDialog dlg = new RepositorySelectionDialog(getSite().getShell(), repositories);
+          if (dlg.open() != Window.OK)
+             return;
+          
+          final Repository repository = dlg.getSelection();
+          doExport(new ExportCompletionHandler() {
+         @Override
+         public void exportCompleted(final String xml)
+         {
+            new ConsoleJob("Publish configuration", ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
+               @Override
+               protected void runInternal(IProgressMonitor monitor) throws Exception
+               {
+                  URL url = new URL(repository.getUrl() + "/rest-api/push-export?accessToken=" + repository.getAuthToken());
+                  URLConnection conn = url.openConnection();
+                  if (!(conn instanceof HttpURLConnection))
+                  {
+                     throw new Exception("Unsupported URL type");
+                  }
+                  ((HttpURLConnection)conn).setRequestMethod("POST");
+                  ((HttpURLConnection)conn).setRequestProperty("User-Agent", "NetXMS Console/" + NXCommon.VERSION);
+                  ((HttpURLConnection)conn).setRequestProperty("Content-Type", "application/xml; charset=utf-8");
+                  ((HttpURLConnection)conn).setDoOutput(true);
+                  ((HttpURLConnection)conn).setAllowUserInteraction(false);
+                  ((HttpURLConnection)conn).setUseCaches(false);
+                  
+                  OutputStream out = conn.getOutputStream();
+                  try
+                  {
+                     out.write(xml.getBytes("UTF-8"));
+                     out.flush();
+                     
+                     int responseCode = ((HttpURLConnection)conn).getResponseCode();
+                     Activator.logInfo("Publish config: url=" + url.toString() + " response=" + responseCode);
+                     if (responseCode != 200)
+                     {
+                        throw new Exception(String.format("HTTP error %d", responseCode));
+                     }
+                  }
+                  finally
+                  {
+                     out.close();
+                  }
+               }
+               
+               @Override
+               protected String getErrorMessage()
+               {
+                  return "Cannot publish configuration to repository";
+               }
+            }.start();
+         }
+      });
+       }
+       
+       /**
+        * Do export operation and call completion handler when done
+        * 
+        * @param completionHandler
+        */
+       private void doExport(final ExportCompletionHandler completionHandler)
+       {
+      final long[] eventList = new long[events.size()];
+      int i = 0;
+      for(EventTemplate t : events.values())
+         eventList[i++] = t.getCode();
+      
+      final long[] templateList = new long[templates.size()];
+      i = 0;
+      for(Template t : templates.values())
+         templateList[i++] = t.getObjectId();
+      
+      final long[] trapList = new long[traps.size()];
+      i = 0;
+      for(SnmpTrap t : traps.values())
+         trapList[i++] = t.getId();
+      
+      final UUID[] ruleList = new UUID[rules.size()];
+      i = 0;
+      for(EventProcessingPolicyRule r : rules.values())
+         ruleList[i++] = r.getGuid();
+      
       final long[] scriptList = new long[scripts.size()];
       i = 0;
       for(Script s : scripts.values())
@@ -800,66 +911,80 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
       for(DciSummaryTableDescriptor t : summaryTables.values())
          summaryTableList[i++] = t.getId();
       
-               final String descriptionText = description.getText();
-               
-               new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList);
-                               runInUIThread(new Runnable() {
+      final String descriptionText = description.getText();
+      
+      new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList);
+            runInUIThread(new Runnable() {
                @Override
                public void run()
                {
-                  FileDialog dlg = new FileDialog(getSite().getShell(), SWT.SAVE);
-                  dlg.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
-                  dlg.setFilterNames(new String[] { Messages.get().ConfigurationImportDialog_FileTypeXML, Messages.get().ConfigurationImportDialog_FileTypeAll });
-                  dlg.setOverwrite(true);
-                  dlg.setFileName(exportFileName);
-                  final String fileName = dlg.open();
-                  if (fileName != null)
+                  completionHandler.exportCompleted(xml);
+               }
+            });
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return Messages.get().ExportFileBuilder_ExportJobError;
+         }
+      }.start();
+       }
+
+       /**
+        * Save settings
+        */
+       private void save()
+       {
+          doExport(new ExportCompletionHandler() {
+         @Override
+         public void exportCompleted(final String xml)
+         {
+            FileDialog dlg = new FileDialog(getSite().getShell(), SWT.SAVE);
+            dlg.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
+            dlg.setFilterNames(new String[] { Messages.get().ConfigurationImportDialog_FileTypeXML, Messages.get().ConfigurationImportDialog_FileTypeAll });
+            dlg.setOverwrite(true);
+            dlg.setFileName(exportFileName);
+            final String fileName = dlg.open();
+            if (fileName != null)
+            {
+               exportFileName = fileName;
+               new ConsoleJob("Save exported configuration", ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
+                  @Override
+                  protected void runInternal(IProgressMonitor monitor) throws Exception
                   {
-                     exportFileName = fileName;
-                     new ConsoleJob("Save exported configuration", ExportFileBuilder.this, Activator.PLUGIN_ID, null) {
+                     OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8"); //$NON-NLS-1$
+                     try
+                     {
+                        out.write(xml);
+                     }
+                     finally
+                     {
+                        out.close();
+                     }
+                     runInUIThread(new Runnable() {
                         @Override
-                        protected void runInternal(IProgressMonitor monitor) throws Exception
+                        public void run()
                         {
-                           OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8"); //$NON-NLS-1$
-                           try
-                           {
-                              out.write(xml);
-                           }
-                           finally
-                           {
-                              out.close();
-                           }
-                           runInUIThread(new Runnable() {
-                              @Override
-                              public void run()
-                              {
-                                 modified = false;
-                                 firePropertyChange(PROP_DIRTY);
-                              }
-                           });
+                           modified = false;
+                           firePropertyChange(PROP_DIRTY);
                         }
-                        
-                        @Override
-                        protected String getErrorMessage()
-                        {
-                           return "Cannot save exported configuration to file";
-                        }
-                     }.start();
+                     });
                   }
-               }
-            });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().ExportFileBuilder_ExportJobError;
-                       }
-               }.start();
+                  
+                  @Override
+                  protected String getErrorMessage()
+                  {
+                     return "Cannot save exported configuration to file";
+                  }
+               }.start();
+            }
+         }
+      });
        }
 
        /* (non-Javadoc)
@@ -1137,4 +1262,17 @@ public class ExportFileBuilder extends ViewPart implements ISaveablePart
          setModified();
       }
    }
+   
+   /**
+    * Export completion handler
+    */
+   private interface ExportCompletionHandler
+   {
+      /**
+       * Called when export is complete
+       * 
+       * @param xml resulting XML document
+       */
+      public void exportCompleted(final String xml);
+   }
 }
index 7753cb2..1537d26 100644 (file)
@@ -363,10 +363,20 @@ TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD code, TCHAR *pszBuffer)
       _T("CMD_ENTER_MAINT_MODE"),
       _T("CMD_LEAVE_MAINT_MODE"),
       _T("CMD_JOIN_CLUSTER"),
-      _T("CMD_CLUSTER_NOTIFY")
+      _T("CMD_CLUSTER_NOTIFY"),
+      _T("CMD_ZMQ_SUBSCRIBE_EVENT"),
+      _T("CMD_ZMQ_UNSUBSCRIBE_EVENT"),
+      _T("CMD_ZMQ_SUBSCRIBE_DATA"),
+      _T("CMD_ZMQ_UNSUBSCRIBE_DATA"),
+      _T("CMD_ZMQ_GET_EVT_SUBSCRIPTIONS"),
+      _T("CMD_ZMQ_GET_DATA_SUBSCRIPTIONS"),
+      _T("CMD_GET_REPOSITORIES"),
+      _T("CMD_ADD_REPOSITORY"),
+      _T("CMD_MODIFY_REPOSITORY"),
+      _T("CMD_DELETE_REPOSITORY")
    };
 
-   if ((code >= CMD_LOGIN) && (code <= CMD_CLUSTER_NOTIFY))
+   if ((code >= CMD_LOGIN) && (code <= CMD_DELETE_REPOSITORY))
       _tcscpy(pszBuffer, pszMsgNames[code - CMD_LOGIN]);
    else
       _sntprintf(pszBuffer, 64, _T("CMD_0x%04X"), code);
index cf278a5..a9bd7cc 100644 (file)
@@ -18,8 +18,8 @@ libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp addrlist.cpp \
                        isc.cpp job.cpp jobmgr.cpp jobqueue.cpp layer2.cpp \
                        ldap.cpp lln.cpp lldp.cpp locks.cpp logfilter.cpp \
                        loghandle.cpp logs.cpp macdb.cpp main.cpp maint.cpp \
-                       mdconn.cpp mdsession.cpp mobile.cpp modules.cpp \
-                       mt.cpp ndd.cpp ndp.cpp \
+                       market.cpp mdconn.cpp mdsession.cpp mobile.cpp \
+                       modules.cpp mt.cpp ndd.cpp ndp.cpp \
                        netinfo.cpp netmap.cpp netobj.cpp netsrv.cpp \
                        node.cpp nodelink.cpp np.cpp nxsl_classes.cpp \
                        nxslext.cpp objects.cpp objtools.cpp package.cpp \
index 3de39a0..98a5d69 100644 (file)
@@ -139,17 +139,27 @@ static void SendNewRecord(ClientSession *pSession, void *pArg)
 /**
  * Write audit record
  */
-void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, UINT32 userId,
+void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, bool isSuccess, UINT32 userId,
                                      const TCHAR *workstation, int sessionId, UINT32 objectId,
                                      const TCHAR *format, ...)
+{
+   va_list args;
+   va_start(args, format);
+   WriteAuditLog2(subsys, isSuccess, userId, workstation, sessionId, objectId, format, args);
+   va_end(args);
+}
+
+/**
+ * Write audit record
+ */
+void NXCORE_EXPORTABLE WriteAuditLog2(const TCHAR *subsys, bool isSuccess, UINT32 userId,
+                                      const TCHAR *workstation, int sessionId, UINT32 objectId,
+                                      const TCHAR *format, va_list args)
 {
        String text, query;
-       va_list args;
        NXCPMessage msg;
 
-       va_start(args, format);
        text.appendFormattedStringV(format, args);
-       va_end(args);
 
        query.appendFormattedString(_T("INSERT INTO audit_log (record_id,timestamp,subsystem,success,user_id,workstation,session_id,object_id,message) VALUES(%d,") TIME_T_FMT _T(",%s,%d,%d,%s,%d,%d,%s)"),
       InterlockedIncrement(&m_recordId), time(NULL), (const TCHAR *)DBPrepareString(g_dbDriver, subsys), isSuccess ? 1 : 0,
diff --git a/src/server/core/market.cpp b/src/server/core/market.cpp
new file mode 100644 (file)
index 0000000..f79e399
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2016 Raden Solutions
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: market.cpp
+**
+**/
+
+#include "nxcore.h"
+
+/**
+ * Get free repository ID
+ */
+static INT32 NewRepositoryId()
+{
+   INT32 id = -1;
+   DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+   DB_RESULT hResult = DBSelect(hdb, _T("SELECT max(id) FROM config_repositories"));
+   if (hResult != NULL)
+   {
+      if (DBGetNumRows(hResult) > 0)
+         id = DBGetFieldLong(hResult, 0, 0) + 1;
+      else
+         id = 1;
+      DBFreeResult(hResult);
+   }
+   DBConnectionPoolReleaseConnection(hdb);
+   return id;
+}
+
+/**
+ * Check if given repository ID is valid
+ */
+static int CheckRepositoryId(INT32 id)
+{
+   int result = -1;
+   DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+   DB_STATEMENT hStmt = DBPrepare(hdb, _T("SELECT count(*) FROM config_repositories WHERE id=?"));
+   if (hStmt != NULL)
+   {
+      DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
+      DB_RESULT hResult = DBSelectPrepared(hStmt);
+      if (hResult != NULL)
+      {
+         result = DBGetFieldLong(hResult, 0, 0);
+         DBFreeResult(hResult);
+      }
+      DBFreeStatement(hStmt);
+   }
+   DBConnectionPoolReleaseConnection(hdb);
+   return result;
+}
+
+/**
+ * Get configured repositories
+ */
+void ClientSession::getRepositories(NXCPMessage *request)
+{
+   NXCPMessage msg;
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
+
+   if (checkSysAccessRights(SYSTEM_ACCESS_MANAGE_REPOSITORIES) || checkSysAccessRights(SYSTEM_ACCESS_VIEW_REPOSITORIES))
+   {
+      DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+      DB_RESULT hResult = DBSelect(hdb, _T("SELECT id,url,auth_token,description FROM config_repositories"));
+      if (hResult != NULL)
+      {
+         TCHAR buffer[1024];
+         int count = DBGetNumRows(hResult);
+         msg.setField(VID_NUM_ELEMENTS, (INT32)count);
+         UINT32 fieldId = VID_ELEMENT_LIST_BASE;
+         for(int i = 0; i < count; i++)
+         {
+            msg.setField(fieldId++, DBGetFieldLong(hResult, i, 0));
+            msg.setField(fieldId++, DBGetField(hResult, i, 1, buffer, 1024));
+            msg.setField(fieldId++, DBGetField(hResult, i, 2, buffer, 1024));
+            msg.setField(fieldId++, DBGetField(hResult, i, 3, buffer, 1024));
+            fieldId += 6;
+         }
+         msg.setField(VID_RCC, RCC_SUCCESS);
+         writeAuditLog(AUDIT_SYSCFG, true, 0, _T("Read list of configured repositories"));
+      }
+      else
+      {
+         msg.setField(VID_RCC, RCC_DB_FAILURE);
+      }
+      DBConnectionPoolReleaseConnection(hdb);
+   }
+   else
+   {
+      msg.setField(VID_RCC, RCC_ACCESS_DENIED);
+      writeAuditLog(AUDIT_SYSCFG, false, 0, _T("Access denied accessing list of configured repositories"));
+   }
+
+   sendMessage(&msg);
+}
+
+/**
+ * Add repository
+ */
+void ClientSession::addRepository(NXCPMessage *request)
+{
+   NXCPMessage msg;
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
+
+   if (checkSysAccessRights(SYSTEM_ACCESS_MANAGE_REPOSITORIES))
+   {
+      INT32 id = NewRepositoryId();
+      if (id > 0)
+      {
+         DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+         DB_STATEMENT hStmt = DBPrepare(hdb, _T("INSERT INTO config_repositories (id,url,auth_token,description) VALUES (?,?,?,?)"));
+         if (hStmt != NULL)
+         {
+            TCHAR *url = request->getFieldAsString(VID_URL);
+            TCHAR *authToken = request->getFieldAsString(VID_AUTH_TOKEN);
+            TCHAR *description = request->getFieldAsString(VID_DESCRIPTION);
+
+            DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
+            DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, url, DB_BIND_STATIC);
+            DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, authToken, DB_BIND_STATIC);
+            DBBind(hStmt, 4, DB_SQLTYPE_VARCHAR, description, DB_BIND_STATIC);
+
+            if (DBExecute(hStmt))
+            {
+               writeAuditLog(AUDIT_SYSCFG, true, 0, _T("New repository added (id=%d url=%s)"), id, CHECK_NULL(url));
+               msg.setField(VID_RCC, RCC_SUCCESS);
+               msg.setField(VID_REPOSITORY_ID, id);
+            }
+            else
+            {
+               msg.setField(VID_RCC, RCC_DB_FAILURE);
+            }
+
+            DBFreeStatement(hStmt);
+            free(url);
+            free(authToken);
+            free(description);
+         }
+         else
+         {
+            msg.setField(VID_RCC, RCC_DB_FAILURE);
+         }
+         DBConnectionPoolReleaseConnection(hdb);
+      }
+      else
+      {
+         msg.setField(VID_RCC, RCC_DB_FAILURE);
+      }
+   }
+   else
+   {
+      msg.setField(VID_RCC, RCC_ACCESS_DENIED);
+      writeAuditLog(AUDIT_SYSCFG, false, 0, _T("Access denied on adding repository"));
+   }
+
+   sendMessage(&msg);
+}
+
+/**
+ * Add repository
+ */
+void ClientSession::modifyRepository(NXCPMessage *request)
+{
+   NXCPMessage msg;
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
+
+   INT32 id = request->getFieldAsInt32(VID_REPOSITORY_ID);
+   if (checkSysAccessRights(SYSTEM_ACCESS_MANAGE_REPOSITORIES))
+   {
+      int check = CheckRepositoryId(id);
+      if (check > 0)
+      {
+         DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+         DB_STATEMENT hStmt = DBPrepare(hdb, _T("UPDATE config_repositories SET url=?,auth_token=?,description=? WHERE id=?"));
+         if (hStmt != NULL)
+         {
+            TCHAR *url = request->getFieldAsString(VID_URL);
+            TCHAR *authToken = request->getFieldAsString(VID_AUTH_TOKEN);
+            TCHAR *description = request->getFieldAsString(VID_DESCRIPTION);
+
+            DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, url, DB_BIND_STATIC);
+            DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, authToken, DB_BIND_STATIC);
+            DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, description, DB_BIND_STATIC);
+            DBBind(hStmt, 4, DB_SQLTYPE_INTEGER, id);
+
+            if (DBExecute(hStmt))
+            {
+               writeAuditLog(AUDIT_SYSCFG, true, 0, _T("Repository updated (id=%d url=%s)"), id, CHECK_NULL(url));
+               msg.setField(VID_RCC, RCC_SUCCESS);
+            }
+            else
+            {
+               msg.setField(VID_RCC, RCC_DB_FAILURE);
+            }
+
+            DBFreeStatement(hStmt);
+            free(url);
+            free(authToken);
+            free(description);
+         }
+         else
+         {
+            msg.setField(VID_RCC, RCC_DB_FAILURE);
+         }
+         DBConnectionPoolReleaseConnection(hdb);
+      }
+      else if (check == 0)
+      {
+         msg.setField(VID_RCC, RCC_INVALID_OBJECT_ID);
+      }
+      else
+      {
+         msg.setField(VID_RCC, RCC_DB_FAILURE);
+      }
+   }
+   else
+   {
+      msg.setField(VID_RCC, RCC_ACCESS_DENIED);
+      writeAuditLog(AUDIT_SYSCFG, false, 0, _T("Access denied on changing repository [%d]"), id);
+   }
+
+   sendMessage(&msg);
+}
+
+/**
+ * Delete repository
+ */
+void ClientSession::deleteRepository(NXCPMessage *request)
+{
+   NXCPMessage msg;
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
+
+   INT32 id = request->getFieldAsInt32(VID_REPOSITORY_ID);
+   if (checkSysAccessRights(SYSTEM_ACCESS_MANAGE_REPOSITORIES))
+   {
+      int check = CheckRepositoryId(id);
+      if (check > 0)
+      {
+         DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
+         DB_STATEMENT hStmt = DBPrepare(hdb, _T("DELETE FROM config_repositories WHERE id=?"));
+         if (hStmt != NULL)
+         {
+            DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
+            if (DBExecute(hStmt))
+            {
+               writeAuditLog(AUDIT_SYSCFG, true, 0, _T("Repository [%d] deleted"), id);
+               msg.setField(VID_RCC, RCC_SUCCESS);
+            }
+            else
+            {
+               msg.setField(VID_RCC, RCC_DB_FAILURE);
+            }
+
+            DBFreeStatement(hStmt);
+         }
+         else
+         {
+            msg.setField(VID_RCC, RCC_DB_FAILURE);
+         }
+         DBConnectionPoolReleaseConnection(hdb);
+      }
+      else if (check == 0)
+      {
+         msg.setField(VID_RCC, RCC_INVALID_OBJECT_ID);
+      }
+      else
+      {
+         msg.setField(VID_RCC, RCC_DB_FAILURE);
+      }
+   }
+   else
+   {
+      msg.setField(VID_RCC, RCC_ACCESS_DENIED);
+      writeAuditLog(AUDIT_SYSCFG, false, 0, _T("Access denied on deleting repository [%d]"), id);
+   }
+
+   sendMessage(&msg);
+}
index 36466bb..cec4ece 100644 (file)
@@ -182,6 +182,10 @@ DEFINE_THREAD_STARTER(sendEventLog)
 DEFINE_THREAD_STARTER(sendMib)
 DEFINE_THREAD_STARTER(sendSyslog)
 DEFINE_THREAD_STARTER(uploadUserFileToAgent)
+DEFINE_THREAD_STARTER(getRepositories)
+DEFINE_THREAD_STARTER(addRepository)
+DEFINE_THREAD_STARTER(modifyRepository)
+DEFINE_THREAD_STARTER(deleteRepository)
 
 /**
  * Client communication read thread starter
@@ -365,6 +369,17 @@ void ClientSession::debugPrintf(int level, const TCHAR *format, ...)
    }
 }
 
+/**
+ * Write audit log
+ */
+void ClientSession::writeAuditLog(const TCHAR *subsys, bool success, UINT32 objectId, const TCHAR *format, ...)
+{
+   va_list args;
+   va_start(args, format);
+   WriteAuditLog2(subsys, success, m_dwUserId, m_workstation, m_id, objectId, format, args);
+   va_end(args);
+}
+
 /**
  * Check channel subscription
  */
@@ -1443,6 +1458,18 @@ void ClientSession::processingThread()
          case CMD_REMOVE_SCHEDULE:
             removeScheduledTask(pMsg);
             break;
+         case CMD_GET_REPOSITORIES:
+            CALL_IN_NEW_THREAD(getRepositories, pMsg);
+            break;
+         case CMD_ADD_REPOSITORY:
+            CALL_IN_NEW_THREAD(addRepository, pMsg);
+            break;
+         case CMD_MODIFY_REPOSITORY:
+            CALL_IN_NEW_THREAD(modifyRepository, pMsg);
+            break;
+         case CMD_DELETE_REPOSITORY:
+            CALL_IN_NEW_THREAD(deleteRepository, pMsg);
+            break;
 #ifdef WITH_ZMQ
          case CMD_ZMQ_SUBSCRIBE_EVENT:
             zmqManageSubscription(pMsg, zmq::EVENT, true);
index f60f142..6421de2 100644 (file)
@@ -491,6 +491,10 @@ private:
    DECLARE_THREAD_STARTER(sendMib)
    DECLARE_THREAD_STARTER(sendSyslog)
    DECLARE_THREAD_STARTER(uploadUserFileToAgent)
+   DECLARE_THREAD_STARTER(getRepositories)
+   DECLARE_THREAD_STARTER(addRepository)
+   DECLARE_THREAD_STARTER(modifyRepository)
+   DECLARE_THREAD_STARTER(deleteRepository)
 
    void readThread();
    void writeThread();
@@ -498,10 +502,12 @@ private:
    void updateThread();
    void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
 
+   void writeAuditLog(const TCHAR *subsys, bool success, UINT32 objectId, const TCHAR *format, ...);
+   void debugPrintf(int level, const TCHAR *format, ...);
+
    void setupEncryption(NXCPMessage *request);
    void respondToKeepalive(UINT32 dwRqId);
    void onFileUpload(BOOL bSuccess);
-   void debugPrintf(int level, const TCHAR *format, ...);
    void sendServerInfo(UINT32 dwRqId);
    void login(NXCPMessage *pRequest);
    void sendAllObjects(NXCPMessage *pRequest);
@@ -718,6 +724,10 @@ private:
    void addScheduledTask(NXCPMessage *request);
    void updateScheduledTask(NXCPMessage *request);
    void removeScheduledTask(NXCPMessage *request);
+   void getRepositories(NXCPMessage *request);
+   void addRepository(NXCPMessage *request);
+   void modifyRepository(NXCPMessage *request);
+   void deleteRepository(NXCPMessage *request);
 #ifdef WITH_ZMQ
    void zmqManageSubscription(NXCPMessage *request, zmq::SubscriptionType type, bool subscribe);
    void zmqListSubscriptions(NXCPMessage *request, zmq::SubscriptionType type);
@@ -1026,9 +1036,12 @@ void ReinitializeSyslogParser();
 void EscapeString(String &str);
 
 void InitAuditLog();
-void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, UINT32 userId,
+void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, bool isSuccess, UINT32 userId,
                                      const TCHAR *workstation, int sessionId, UINT32 objectId,
                                      const TCHAR *format, ...);
+void NXCORE_EXPORTABLE WriteAuditLog2(const TCHAR *subsys, bool isSuccess, UINT32 userId,
+                                      const TCHAR *workstation, int sessionId, UINT32 objectId,
+                                      const TCHAR *format, va_list args);
 
 bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
 UINT32 ImportConfig(Config *config, UINT32 flags);