fixed broken VPN connectors configuration
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Apr 2015 09:28:49 +0000 (12:28 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Apr 2015 09:28:49 +0000 (12:28 +0300)
20 files changed:
ChangeLog
android/src/agent/res/values/build_number.xml
android/src/console/res/values/build_number.xml
build/build_number
include/build.h
src/java/build/set_build_number.cmd
src/java/client/netxms-base/src/main/java/org/netxms/base/BuildNumber.java
src/java/client/netxms-base/src/main/java/org/netxms/base/InetAddressEx.java
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCObjectModificationData.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/objects/VPNConnector.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/AddSubnetDialog.java [moved from src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/AddAddressListElementDialog.java with 71% similarity]
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/VPNSubnets.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java [deleted file]
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java [new file with mode: 0644]
src/server/core/vpnconn.cpp
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/AddSubnetDialog.java [moved from webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/AddAddressListElementDialog.java with 71% similarity]
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/VPNSubnets.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java [deleted file]
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java [new file with mode: 0644]

index 8a42545..1951302 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+*
+* 2.0-M5
+*
+
+- Management console:
+       - Fixed broken VPN connectors configuration
+
+
 *
 * 2.0-M4
 *
index 3ba63ad..c4e3ce4 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-       <string name="build_number">8015</string>
+       <string name="build_number">8016</string>
 </resources>
index 3ba63ad..c4e3ce4 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-       <string name="build_number">8015</string>
+       <string name="build_number">8016</string>
 </resources>
index e39da90..cdf8e56 100644 (file)
@@ -1 +1 @@
-8015
+8016
index de50113..4b2151d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef __build_h
 #define __build_h
-#define NETXMS_VERSION_BUILD 8015
-#define NETXMS_VERSION_BUILD_STRING _T("8015")
+#define NETXMS_VERSION_BUILD 8016
+#define NETXMS_VERSION_BUILD_STRING _T("8016")
 #endif
index 52dae6f..9512513 100644 (file)
@@ -1,5 +1,5 @@
 package org.netxms.base;
 public final class BuildNumber {
-   public static final String TEXT = "8015";
-   public static final int NUMBER = 8015;
+   public static final String TEXT = "8016";
+   public static final int NUMBER = 8016;
 }
index 11241a6..014092f 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * NetXMS - open source network management system
- * Copyright (C) 2003-2014 Victor Kirhenshtein
+ * Copyright (C) 2003-2015 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
@@ -127,4 +127,42 @@ public class InetAddressEx
          return null;
       }
    }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((address == null) ? 0 : address.hashCode());
+      result = prime * result + mask;
+      return result;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      InetAddressEx other = (InetAddressEx)obj;
+      if (address == null)
+      {
+         if (other.address != null)
+            return false;
+      }
+      else if (!address.equals(other.address))
+         return false;
+      if (mask != other.mask)
+         return false;
+      return true;
+   }
 }
index b350512..cc63ec9 100644 (file)
@@ -173,8 +173,8 @@ public class NXCObjectModificationData
        private int height;
        private String filter;
        private long peerGatewayId;
-       private List<IpAddressListElement> localNetworks;
-       private List<IpAddressListElement> remoteNetworks;
+       private List<InetAddressEx> localNetworks;
+       private List<InetAddressEx> remoteNetworks;
        private PostalAddress postalAddress;
        
        /**
@@ -1391,7 +1391,7 @@ public class NXCObjectModificationData
    /**
     * @return the localNetworks
     */
-   public List<IpAddressListElement> getLocalNetworks()
+   public List<InetAddressEx> getLocalNetworks()
    {
       return localNetworks;
    }
@@ -1399,7 +1399,7 @@ public class NXCObjectModificationData
    /**
     * @return the remoteNetworks
     */
-   public List<IpAddressListElement> getRemoteNetworks()
+   public List<InetAddressEx> getRemoteNetworks()
    {
       return remoteNetworks;
    }
@@ -1407,7 +1407,7 @@ public class NXCObjectModificationData
    /**
     * @param remoteNetworks the remoteNetworks to set
     */
-   public void setVpnNetworks(List<IpAddressListElement> localNetworks, List<IpAddressListElement> remoteNetworks)
+   public void setVpnNetworks(List<InetAddressEx> localNetworks, List<InetAddressEx> remoteNetworks)
    {
       this.localNetworks = localNetworks;
       this.remoteNetworks = remoteNetworks;
index 1eddccd..b921343 100644 (file)
@@ -4371,20 +4371,18 @@ public class NXCSession
 
       if ((flags & NXCObjectModificationData.MODIFY_VPN_NETWORKS) != 0)
       {
-         long varId = NXCPCodes.VID_VPN_NETWORK_BASE;         
+         long fieldId = NXCPCodes.VID_VPN_NETWORK_BASE;         
 
          msg.setFieldInt32(NXCPCodes.VID_NUM_LOCAL_NETS, data.getLocalNetworks().size());
-         for(IpAddressListElement e : data.getLocalNetworks())
+         for(InetAddressEx a : data.getLocalNetworks())
          {
-            msg.setField(varId++, e.getAddr1());
-            msg.setField(varId++, e.getAddr2());
+            msg.setField(fieldId++, a);
          }
 
          msg.setFieldInt32(NXCPCodes.VID_NUM_REMOTE_NETS, data.getRemoteNetworks().size());
-         for(IpAddressListElement e : data.getRemoteNetworks())
+         for(InetAddressEx a : data.getRemoteNetworks())
          {
-            msg.setField(varId++, e.getAddr1());
-            msg.setField(varId++, e.getAddr2());
+            msg.setField(fieldId++, a);
          }
       }
       
index 07f80fe..e6dbefd 100644 (file)
@@ -1,14 +1,28 @@
 /**
- * 
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2015 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
+ * 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.
  */
 package org.netxms.client.objects;
 
-import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.List;
+import org.netxms.base.InetAddressEx;
 import org.netxms.base.NXCPCodes;
 import org.netxms.base.NXCPMessage;
-import org.netxms.client.IpAddressListElement;
 import org.netxms.client.NXCSession;
 
 /**
@@ -17,8 +31,8 @@ import org.netxms.client.NXCSession;
 public class VPNConnector extends GenericObject
 {
    private long peerGatewayId;
-   private List<IpAddressListElement> localSubnets;
-   private List<IpAddressListElement> remoteSubnets;
+   private List<InetAddressEx> localSubnets;
+   private List<InetAddressEx> remoteSubnets;
    
    /**
     * Create from NXCP message
@@ -32,23 +46,19 @@ public class VPNConnector extends GenericObject
       
       peerGatewayId = msg.getFieldAsInt64(NXCPCodes.VID_PEER_GATEWAY);
       
-      long varId = NXCPCodes.VID_VPN_NETWORK_BASE;
+      long fieldId = NXCPCodes.VID_VPN_NETWORK_BASE;
       int count = msg.getFieldAsInt32(NXCPCodes.VID_NUM_LOCAL_NETS);
-      localSubnets = new ArrayList<IpAddressListElement>(count);
+      localSubnets = new ArrayList<InetAddressEx>(count);
       for(int i = 0; i < count; i++)
       {
-         InetAddress addr = msg.getFieldAsInetAddress(varId++);
-         InetAddress mask = msg.getFieldAsInetAddress(varId++);
-         localSubnets.add(new IpAddressListElement(IpAddressListElement.SUBNET, addr, mask));
+         localSubnets.add(msg.getFieldAsInetAddressEx(fieldId++));
       }
 
       count = msg.getFieldAsInt32(NXCPCodes.VID_NUM_REMOTE_NETS);
-      remoteSubnets = new ArrayList<IpAddressListElement>(count);
+      remoteSubnets = new ArrayList<InetAddressEx>(count);
       for(int i = 0; i < count; i++)
       {
-         InetAddress addr = msg.getFieldAsInetAddress(varId++);
-         InetAddress mask = msg.getFieldAsInetAddress(varId++);
-         remoteSubnets.add(new IpAddressListElement(IpAddressListElement.SUBNET, addr, mask));
+         remoteSubnets.add(msg.getFieldAsInetAddressEx(fieldId++));
       }
    }
 
@@ -95,7 +105,7 @@ public class VPNConnector extends GenericObject
    /**
     * @return the localSubnets
     */
-   public List<IpAddressListElement> getLocalSubnets()
+   public List<InetAddressEx> getLocalSubnets()
    {
       return localSubnets;
    }
@@ -103,7 +113,7 @@ public class VPNConnector extends GenericObject
    /**
     * @return the remoteSubnets
     */
-   public List<IpAddressListElement> getRemoteSubnets()
+   public List<InetAddressEx> getRemoteSubnets()
    {
       return remoteSubnets;
    }
@@ -27,25 +27,26 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.netxms.base.InetAddressEx;
 import org.netxms.ui.eclipse.objectmanager.Messages;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.LabeledSpinner;
 import org.netxms.ui.eclipse.widgets.LabeledText;
 
 /**
  * Dialog for adding address list element
  */
-public class AddAddressListElementDialog extends Dialog
+public class AddSubnetDialog extends Dialog
 {
-       private LabeledText textAddr1;
-       private LabeledText textAddr2;
-       private InetAddress address1;
-       private InetAddress address2;
+       private LabeledText address;
+       private LabeledSpinner mask;
+       private InetAddressEx subnet;
        
        /**
         * @param parentShell
         */
-       public AddAddressListElementDialog(Shell parentShell)
+       public AddSubnetDialog(Shell parentShell)
        {
                super(parentShell);
        }
@@ -57,7 +58,7 @@ public class AddAddressListElementDialog extends Dialog
        protected void configureShell(Shell newShell)
        {
                super.configureShell(newShell);
-               newShell.setText(Messages.get().AddAddressListElementDialog_Title);
+               newShell.setText("Add Subnet");
        }
 
        /* (non-Javadoc)
@@ -72,25 +73,26 @@ public class AddAddressListElementDialog extends Dialog
                layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
                layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
                layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
+               layout.numColumns = 2;
                dialogArea.setLayout(layout);
                
                
-               textAddr1 = new LabeledText(dialogArea, SWT.NONE);
-               textAddr1.setLabel(Messages.get().AddAddressListElementDialog_NetworkAddress);
-               textAddr1.setText("0.0.0.0"); //$NON-NLS-1$
+               address = new LabeledText(dialogArea, SWT.NONE);
+               address.setLabel(Messages.get().AddAddressListElementDialog_NetworkAddress);
+               address.setText("0.0.0.0"); //$NON-NLS-1$
                GridData gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                gd.widthHint = 300;
-               textAddr1.setLayoutData(gd);            
-               
-               textAddr2 = new LabeledText(dialogArea, SWT.NONE);
-               textAddr2.setLabel(Messages.get().AddAddressListElementDialog_NetworkMask);
-               textAddr2.setText("255.255.255.0"); //$NON-NLS-1$
-               gd = new GridData();
-               gd.horizontalAlignment = SWT.FILL;
-               gd.grabExcessHorizontalSpace = true;
-               textAddr2.setLayoutData(gd);
+               address.setLayoutData(gd);              
+
+               mask = new LabeledSpinner(dialogArea, SWT.NONE);
+               mask.setLabel(Messages.get().AddAddressListElementDialog_NetworkMask);
+               mask.getSpinnerControl().setMinimum(0);
+      mask.getSpinnerControl().setMaximum(128);
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      mask.setLayoutData(gd);    
                
                return dialogArea;
        }
@@ -103,8 +105,8 @@ public class AddAddressListElementDialog extends Dialog
        {
                try
                {
-                       address1 = InetAddress.getByName(textAddr1.getText());
-                       address2 = InetAddress.getByName(textAddr2.getText());
+                       InetAddress a = InetAddress.getByName(address.getText().trim());
+                       subnet = new InetAddressEx(a, mask.getSelection());
                }
                catch(UnknownHostException e)
                {
@@ -115,18 +117,10 @@ public class AddAddressListElementDialog extends Dialog
        }
 
        /**
-        * @return the address1
-        */
-       public InetAddress getAddress1()
-       {
-               return address1;
-       }
-
-       /**
-        * @return the address2
+        * @return subnet address
         */
-       public InetAddress getAddress2()
+       public InetAddressEx getSubnet()
        {
-               return address2;
+               return subnet;
        }
 }
index 3abbd44..d24d7e9 100644 (file)
@@ -35,7 +35,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
 import org.eclipse.ui.forms.events.HyperlinkAdapter;
 import org.eclipse.ui.forms.events.HyperlinkEvent;
 import org.eclipse.ui.forms.widgets.ImageHyperlink;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.base.InetAddressEx;
 import org.netxms.client.NXCObjectModificationData;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objects.AbstractObject;
@@ -45,8 +45,8 @@ import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
 import org.netxms.ui.eclipse.objectmanager.Activator;
 import org.netxms.ui.eclipse.objectmanager.Messages;
-import org.netxms.ui.eclipse.objectmanager.dialogs.AddAddressListElementDialog;
-import org.netxms.ui.eclipse.objectmanager.propertypages.helpers.AddressListElementComparator;
+import org.netxms.ui.eclipse.objectmanager.dialogs.AddSubnetDialog;
+import org.netxms.ui.eclipse.objectmanager.propertypages.helpers.SubnetComparator;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 
@@ -60,8 +60,8 @@ public class VPNSubnets extends PropertyPage
    private TableViewer localNetworksList;
    private TableViewer remoteNetworksList;
    private boolean modified = false; 
-   private List<IpAddressListElement> localNetworksElements;
-   private List<IpAddressListElement> remoteNetworksElements;
+   private List<InetAddressEx> localNetworksElements;
+   private List<InetAddressEx> remoteNetworksElements;
 
    /* (non-Javadoc)
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
@@ -108,8 +108,8 @@ public class VPNSubnets extends PropertyPage
       clientArea.setLayoutData(gd);
       
       //networks lists
-      localNetworksElements = new ArrayList<IpAddressListElement>(connector.getLocalSubnets());
-      remoteNetworksElements = new ArrayList<IpAddressListElement>(connector.getRemoteSubnets());
+      localNetworksElements = new ArrayList<InetAddressEx>(connector.getLocalSubnets());
+      remoteNetworksElements = new ArrayList<InetAddressEx>(connector.getRemoteSubnets());
       createNetworkList(clientArea, Messages.get().VPNSubnets_LocalNetworks, localNetworksList, localNetworksElements);
       createNetworkList(clientArea, Messages.get().VPNSubnets_RemoteNetworks, remoteNetworksList, remoteNetworksElements);
       
@@ -123,7 +123,7 @@ public class VPNSubnets extends PropertyPage
     * @param viewList viewer to be created and added to view
     * @param data elements that should be added as a content of this viewer
     */
-   private void createNetworkList(Composite dialogArea, String title, TableViewer viewList, final List<IpAddressListElement> data) 
+   private void createNetworkList(Composite dialogArea, String title, TableViewer viewList, final List<InetAddressEx> data) 
    {
       Group clientArea = new Group(dialogArea, SWT.NONE);
       clientArea.setText(title);      
@@ -148,7 +148,7 @@ public class VPNSubnets extends PropertyPage
       viewList.getTable().setLayoutData(gd);
       viewList.getTable().setSortDirection(SWT.UP);
       viewList.setContentProvider(new ArrayContentProvider());
-      viewList.setComparator(new AddressListElementComparator());
+      viewList.setComparator(new SubnetComparator());
       viewList.setInput(data.toArray());
       
       final TableViewer list = viewList;
@@ -183,15 +183,15 @@ public class VPNSubnets extends PropertyPage
    /**
     * Add element to subnet list
     */
-   private void addTargetAddressListElement(TableViewer elementList, List<IpAddressListElement> elements)
+   private void addTargetAddressListElement(TableViewer elementList, List<InetAddressEx> elements)
    {
-      AddAddressListElementDialog dlg = new AddAddressListElementDialog(getShell());
+      AddSubnetDialog dlg = new AddSubnetDialog(getShell());
       if (dlg.open() == Window.OK)
       {
-         IpAddressListElement element = new IpAddressListElement(IpAddressListElement.SUBNET, dlg.getAddress1(), dlg.getAddress2());
-         if (!elements.contains(element))
+         InetAddressEx subnet = dlg.getSubnet();
+         if (!elements.contains(subnet))
          {
-            elements.add(element);
+            elements.add(subnet);
             elementList.setInput(elements.toArray());
             modified = true;
          }
@@ -201,7 +201,7 @@ public class VPNSubnets extends PropertyPage
    /**
     * Remove element(s) from subnet list
     */
-   private void removeTargetAddressListElements(TableViewer elementList, List<IpAddressListElement> elements)
+   private void removeTargetAddressListElements(TableViewer elementList, List<InetAddressEx> elements)
    {
       IStructuredSelection selection = (IStructuredSelection)elementList.getSelection();
       if (selection.size() > 0)
diff --git a/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java b/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java
deleted file mode 100644 (file)
index cbf61d7..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 
- */
-package org.netxms.ui.eclipse.objectmanager.propertypages.helpers;
-
-import java.net.InetAddress;
-
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.swt.SWT;
-import org.netxms.client.IpAddressListElement;
-
-/**
- * Comparator for address list elements
- */
-public class AddressListElementComparator extends ViewerComparator
-{
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
-        */
-       @Override
-       public int compare(Viewer viewer, Object e1, Object e2)
-       {
-               IpAddressListElement a1 = (IpAddressListElement)e1;
-               IpAddressListElement a2 = (IpAddressListElement)e2;
-               
-               int rc = compareIpAddresses(a1.getAddr1(), a2.getAddr1());
-               if (rc == 0)
-               {
-                       rc = compareIpAddresses(a1.getAddr2(), a2.getAddr2());
-               }
-               
-               int dir = ((TableViewer)viewer).getTable().getSortDirection();
-               return (dir == SWT.UP) ? rc : -rc;
-       }
-       
-       /**
-        * Compare two IP addresses
-        * 
-        * @param a1
-        * @param a2
-        * @return
-        */
-       private int compareIpAddresses(InetAddress a1, InetAddress a2)
-       {
-               byte[] b1 = a1.getAddress();
-               byte[] b2 = a2.getAddress();
-               
-               for(int i = 0; i < b1.length; i++)
-               {
-                       int rc = b1[i] - b2[i];
-                       if (rc != 0)
-                               return Integer.signum(rc);
-               }
-               return 0;
-       }
-}
diff --git a/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java b/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java
new file mode 100644 (file)
index 0000000..faf5863
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2015 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
+ * 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.
+ */
+package org.netxms.ui.eclipse.objectmanager.propertypages.helpers;
+
+import java.net.InetAddress;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.netxms.base.InetAddressEx;
+
+/**
+ * Comparator for subnets
+ */
+public class SubnetComparator extends ViewerComparator
+{
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+        */
+       @Override
+       public int compare(Viewer viewer, Object e1, Object e2)
+       {
+               InetAddressEx a1 = (InetAddressEx)e1;
+               InetAddressEx a2 = (InetAddressEx)e2;
+               
+               int rc = compareIpAddresses(a1.address, a2.address);
+               if (rc == 0)
+               {
+                       rc = a1.mask - a2.mask;
+               }
+               
+               int dir = ((TableViewer)viewer).getTable().getSortDirection();
+               return (dir == SWT.UP) ? rc : -rc;
+       }
+       
+       /**
+        * Compare two IP addresses
+        * 
+        * @param a1
+        * @param a2
+        * @return
+        */
+       private int compareIpAddresses(InetAddress a1, InetAddress a2)
+       {
+               byte[] b1 = a1.getAddress();
+               byte[] b2 = a2.getAddress();
+               
+               for(int i = 0; i < b1.length; i++)
+               {
+                       int rc = b1[i] - b2[i];
+                       if (rc != 0)
+                               return Integer.signum(rc);
+               }
+               return 0;
+       }
+}
index 3cf8290..20285ea 100644 (file)
@@ -255,6 +255,7 @@ UINT32 VPNConnector::modifyFromMessageInternal(NXCPMessage *pRequest)
       for(i = 0; i < count; i++)
          m_localNetworks->add(new InetAddress(pRequest->getFieldAsInetAddress(fieldId++)));
 
+      m_remoteNetworks->clear();
       count = pRequest->getFieldAsInt32(VID_NUM_REMOTE_NETS);
       for(i = 0; i < count; i++)
          m_remoteNetworks->add(new InetAddress(pRequest->getFieldAsInetAddress(fieldId++)));
@@ -27,25 +27,26 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.netxms.base.InetAddressEx;
 import org.netxms.ui.eclipse.objectmanager.Messages;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
+import org.netxms.ui.eclipse.widgets.LabeledSpinner;
 import org.netxms.ui.eclipse.widgets.LabeledText;
 
 /**
  * Dialog for adding address list element
  */
-public class AddAddressListElementDialog extends Dialog
+public class AddSubnetDialog extends Dialog
 {
-       private LabeledText textAddr1;
-       private LabeledText textAddr2;
-       private InetAddress address1;
-       private InetAddress address2;
+       private LabeledText address;
+       private LabeledSpinner mask;
+       private InetAddressEx subnet;
        
        /**
         * @param parentShell
         */
-       public AddAddressListElementDialog(Shell parentShell)
+       public AddSubnetDialog(Shell parentShell)
        {
                super(parentShell);
        }
@@ -57,7 +58,7 @@ public class AddAddressListElementDialog extends Dialog
        protected void configureShell(Shell newShell)
        {
                super.configureShell(newShell);
-               newShell.setText(Messages.get().AddAddressListElementDialog_Title);
+               newShell.setText("Add Subnet");
        }
 
        /* (non-Javadoc)
@@ -72,25 +73,26 @@ public class AddAddressListElementDialog extends Dialog
                layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
                layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
                layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
+               layout.numColumns = 2;
                dialogArea.setLayout(layout);
                
                
-               textAddr1 = new LabeledText(dialogArea, SWT.NONE);
-               textAddr1.setLabel(Messages.get().AddAddressListElementDialog_NetworkAddress);
-               textAddr1.setText("0.0.0.0"); //$NON-NLS-1$
+               address = new LabeledText(dialogArea, SWT.NONE);
+               address.setLabel(Messages.get().AddAddressListElementDialog_NetworkAddress);
+               address.setText("0.0.0.0"); //$NON-NLS-1$
                GridData gd = new GridData();
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
                gd.widthHint = 300;
-               textAddr1.setLayoutData(gd);            
-               
-               textAddr2 = new LabeledText(dialogArea, SWT.NONE);
-               textAddr2.setLabel(Messages.get().AddAddressListElementDialog_NetworkMask);
-               textAddr2.setText("255.255.255.0"); //$NON-NLS-1$
-               gd = new GridData();
-               gd.horizontalAlignment = SWT.FILL;
-               gd.grabExcessHorizontalSpace = true;
-               textAddr2.setLayoutData(gd);
+               address.setLayoutData(gd);              
+
+               mask = new LabeledSpinner(dialogArea, SWT.NONE);
+               mask.setLabel(Messages.get().AddAddressListElementDialog_NetworkMask);
+               mask.getSpinnerControl().setMinimum(0);
+      mask.getSpinnerControl().setMaximum(128);
+      gd = new GridData();
+      gd.horizontalAlignment = SWT.FILL;
+      mask.setLayoutData(gd);    
                
                return dialogArea;
        }
@@ -103,8 +105,8 @@ public class AddAddressListElementDialog extends Dialog
        {
                try
                {
-                       address1 = InetAddress.getByName(textAddr1.getText());
-                       address2 = InetAddress.getByName(textAddr2.getText());
+                       InetAddress a = InetAddress.getByName(address.getText().trim());
+                       subnet = new InetAddressEx(a, mask.getSelection());
                }
                catch(UnknownHostException e)
                {
@@ -115,18 +117,10 @@ public class AddAddressListElementDialog extends Dialog
        }
 
        /**
-        * @return the address1
-        */
-       public InetAddress getAddress1()
-       {
-               return address1;
-       }
-
-       /**
-        * @return the address2
+        * @return subnet address
         */
-       public InetAddress getAddress2()
+       public InetAddressEx getSubnet()
        {
-               return address2;
+               return subnet;
        }
 }
index 3abbd44..d24d7e9 100644 (file)
@@ -35,7 +35,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
 import org.eclipse.ui.forms.events.HyperlinkAdapter;
 import org.eclipse.ui.forms.events.HyperlinkEvent;
 import org.eclipse.ui.forms.widgets.ImageHyperlink;
-import org.netxms.client.IpAddressListElement;
+import org.netxms.base.InetAddressEx;
 import org.netxms.client.NXCObjectModificationData;
 import org.netxms.client.NXCSession;
 import org.netxms.client.objects.AbstractObject;
@@ -45,8 +45,8 @@ import org.netxms.ui.eclipse.jobs.ConsoleJob;
 import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
 import org.netxms.ui.eclipse.objectmanager.Activator;
 import org.netxms.ui.eclipse.objectmanager.Messages;
-import org.netxms.ui.eclipse.objectmanager.dialogs.AddAddressListElementDialog;
-import org.netxms.ui.eclipse.objectmanager.propertypages.helpers.AddressListElementComparator;
+import org.netxms.ui.eclipse.objectmanager.dialogs.AddSubnetDialog;
+import org.netxms.ui.eclipse.objectmanager.propertypages.helpers.SubnetComparator;
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.WidgetHelper;
 
@@ -60,8 +60,8 @@ public class VPNSubnets extends PropertyPage
    private TableViewer localNetworksList;
    private TableViewer remoteNetworksList;
    private boolean modified = false; 
-   private List<IpAddressListElement> localNetworksElements;
-   private List<IpAddressListElement> remoteNetworksElements;
+   private List<InetAddressEx> localNetworksElements;
+   private List<InetAddressEx> remoteNetworksElements;
 
    /* (non-Javadoc)
     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
@@ -108,8 +108,8 @@ public class VPNSubnets extends PropertyPage
       clientArea.setLayoutData(gd);
       
       //networks lists
-      localNetworksElements = new ArrayList<IpAddressListElement>(connector.getLocalSubnets());
-      remoteNetworksElements = new ArrayList<IpAddressListElement>(connector.getRemoteSubnets());
+      localNetworksElements = new ArrayList<InetAddressEx>(connector.getLocalSubnets());
+      remoteNetworksElements = new ArrayList<InetAddressEx>(connector.getRemoteSubnets());
       createNetworkList(clientArea, Messages.get().VPNSubnets_LocalNetworks, localNetworksList, localNetworksElements);
       createNetworkList(clientArea, Messages.get().VPNSubnets_RemoteNetworks, remoteNetworksList, remoteNetworksElements);
       
@@ -123,7 +123,7 @@ public class VPNSubnets extends PropertyPage
     * @param viewList viewer to be created and added to view
     * @param data elements that should be added as a content of this viewer
     */
-   private void createNetworkList(Composite dialogArea, String title, TableViewer viewList, final List<IpAddressListElement> data) 
+   private void createNetworkList(Composite dialogArea, String title, TableViewer viewList, final List<InetAddressEx> data) 
    {
       Group clientArea = new Group(dialogArea, SWT.NONE);
       clientArea.setText(title);      
@@ -148,7 +148,7 @@ public class VPNSubnets extends PropertyPage
       viewList.getTable().setLayoutData(gd);
       viewList.getTable().setSortDirection(SWT.UP);
       viewList.setContentProvider(new ArrayContentProvider());
-      viewList.setComparator(new AddressListElementComparator());
+      viewList.setComparator(new SubnetComparator());
       viewList.setInput(data.toArray());
       
       final TableViewer list = viewList;
@@ -183,15 +183,15 @@ public class VPNSubnets extends PropertyPage
    /**
     * Add element to subnet list
     */
-   private void addTargetAddressListElement(TableViewer elementList, List<IpAddressListElement> elements)
+   private void addTargetAddressListElement(TableViewer elementList, List<InetAddressEx> elements)
    {
-      AddAddressListElementDialog dlg = new AddAddressListElementDialog(getShell());
+      AddSubnetDialog dlg = new AddSubnetDialog(getShell());
       if (dlg.open() == Window.OK)
       {
-         IpAddressListElement element = new IpAddressListElement(IpAddressListElement.SUBNET, dlg.getAddress1(), dlg.getAddress2());
-         if (!elements.contains(element))
+         InetAddressEx subnet = dlg.getSubnet();
+         if (!elements.contains(subnet))
          {
-            elements.add(element);
+            elements.add(subnet);
             elementList.setInput(elements.toArray());
             modified = true;
          }
@@ -201,7 +201,7 @@ public class VPNSubnets extends PropertyPage
    /**
     * Remove element(s) from subnet list
     */
-   private void removeTargetAddressListElements(TableViewer elementList, List<IpAddressListElement> elements)
+   private void removeTargetAddressListElements(TableViewer elementList, List<InetAddressEx> elements)
    {
       IStructuredSelection selection = (IStructuredSelection)elementList.getSelection();
       if (selection.size() > 0)
diff --git a/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java b/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/AddressListElementComparator.java
deleted file mode 100644 (file)
index cbf61d7..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * 
- */
-package org.netxms.ui.eclipse.objectmanager.propertypages.helpers;
-
-import java.net.InetAddress;
-
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.swt.SWT;
-import org.netxms.client.IpAddressListElement;
-
-/**
- * Comparator for address list elements
- */
-public class AddressListElementComparator extends ViewerComparator
-{
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
-        */
-       @Override
-       public int compare(Viewer viewer, Object e1, Object e2)
-       {
-               IpAddressListElement a1 = (IpAddressListElement)e1;
-               IpAddressListElement a2 = (IpAddressListElement)e2;
-               
-               int rc = compareIpAddresses(a1.getAddr1(), a2.getAddr1());
-               if (rc == 0)
-               {
-                       rc = compareIpAddresses(a1.getAddr2(), a2.getAddr2());
-               }
-               
-               int dir = ((TableViewer)viewer).getTable().getSortDirection();
-               return (dir == SWT.UP) ? rc : -rc;
-       }
-       
-       /**
-        * Compare two IP addresses
-        * 
-        * @param a1
-        * @param a2
-        * @return
-        */
-       private int compareIpAddresses(InetAddress a1, InetAddress a2)
-       {
-               byte[] b1 = a1.getAddress();
-               byte[] b2 = a2.getAddress();
-               
-               for(int i = 0; i < b1.length; i++)
-               {
-                       int rc = b1[i] - b2[i];
-                       if (rc != 0)
-                               return Integer.signum(rc);
-               }
-               return 0;
-       }
-}
diff --git a/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java b/webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/helpers/SubnetComparator.java
new file mode 100644 (file)
index 0000000..faf5863
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2015 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
+ * 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.
+ */
+package org.netxms.ui.eclipse.objectmanager.propertypages.helpers;
+
+import java.net.InetAddress;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.swt.SWT;
+import org.netxms.base.InetAddressEx;
+
+/**
+ * Comparator for subnets
+ */
+public class SubnetComparator extends ViewerComparator
+{
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+        */
+       @Override
+       public int compare(Viewer viewer, Object e1, Object e2)
+       {
+               InetAddressEx a1 = (InetAddressEx)e1;
+               InetAddressEx a2 = (InetAddressEx)e2;
+               
+               int rc = compareIpAddresses(a1.address, a2.address);
+               if (rc == 0)
+               {
+                       rc = a1.mask - a2.mask;
+               }
+               
+               int dir = ((TableViewer)viewer).getTable().getSortDirection();
+               return (dir == SWT.UP) ? rc : -rc;
+       }
+       
+       /**
+        * Compare two IP addresses
+        * 
+        * @param a1
+        * @param a2
+        * @return
+        */
+       private int compareIpAddresses(InetAddress a1, InetAddress a2)
+       {
+               byte[] b1 = a1.getAddress();
+               byte[] b2 = a2.getAddress();
+               
+               for(int i = 0; i < b1.length; i++)
+               {
+                       int rc = b1[i] - b2[i];
+                       if (rc != 0)
+                               return Integer.signum(rc);
+               }
+               return 0;
+       }
+}