소스 검색

Merge pull request #9614 from rpastrana/HPCC-2968-hostnames

HPCC-2968 ConfigMgr should allow hostnames in computer configuration

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 년 전
부모
커밋
152c3b0fe4

+ 3 - 1
deployment/deployutils/deployutils.cpp

@@ -3371,7 +3371,9 @@ void formIPList(const char* ip, StringArray& formattedIpList)
           const char* ip = sArray.item(i);
           if(ip && *ip)
           {
-              if( strchr(ip, '-') != 0 )
+              //we should only enter this section IF we encounter a true ip range, not just a hostname with a dash
+              IpAddress range;
+              if(range.ipsetrange(ip) >1 && !range.isHost())
               {
                 StringArray rangeArr, commIPPart ;
                 StringBuffer comip;

+ 1 - 0
esp/files/configmgr.html

@@ -860,6 +860,7 @@ You need to have Javascript enabled in order to use ConfigMgr. Please enable Jav
             <tr><td class="prompt">Range:</td><td><input id="isRange" type="checkbox" name="isRange" value="true" checked onclick="isRangeClicked(this.checked);"/></tr>        
             <tr><td class="prompt">Start IP Address:</td><td><input type="text" id="cfgAddComputersStartIP" /></td></tr>
             <tr><td class="prompt" id="cfgAddComputersStopIPLabel">Stop IP Address:</td><td><input type="text" id="cfgAddComputersStopIP" /></td></tr>
+            <tr><td class="prompt" id="cfgAddComputersHostnameLabel">Hostname:</td><td><input type="text" id="cfgAddComputersHostname" /></td></tr>
         </table>
       </div>
      </div> 

+ 82 - 3
esp/files/scripts/configmgr/common.js

@@ -208,7 +208,7 @@ function getFirstNodeName(dt, parentName,fldType) {
       break;
     }
   }
-  
+
   if (typeof (rec) === 'undefined')
     return;
 
@@ -255,6 +255,84 @@ function saveOpenEditors(myDataTable) {
   }
 }
 
+function isValidIPSubNetRange(start, end)
+{
+  errorMessage = "";
+  var startInt = parseInt(start);
+  var endInt = parseInt(end);
+  if (!isNaN(startInt))
+  {
+    if (startInt > 255)
+      errorMessage = "IP subnet range exceeds boundry: " + start;
+
+    if (end)
+    {
+      if (isNaN(endInt))
+        errorMessage = "IP subnet range end is not a valid valud: " + end;
+      else if (endInt > 255)
+        errorMessage = "IP subnet range end exceeds boundry: " + end;
+      else if (startInt >= endInt)
+        errorMessage = "IP range is invalid: " + start + "-" + end;
+    }
+  }
+  else
+    errorMessage = "IP range contains non-numeric values: " + start;
+
+  return errorMessage;
+}
+
+function isValidNetworkAddress(addressList, theName, ignoredot, checkspecial)
+{
+  var errorString = "";
+  addressList = addressList.replace(/;$/, "");
+  var addressArray = new Array();
+  addressArray = addressList.split(";");
+
+  const urlPattern = /^(http[s]?:\/\/)?([^:\/\s]+)(?:\:([0-9]+))?((\/\w+)*\/)?([\w\-\.]+[^#?\s]+)?(.*)?(#[\w\-]+)?$/;
+
+  for (var currAddIndex = 0; currAddIndex < addressArray.length; currAddIndex++)
+  {
+    var currentAddress = addressArray[currAddIndex];
+    var match = currentAddress.match(urlPattern);
+    if (match == null)
+        errorString = errorString + theName + ": " + currentAddress + " does not appear to be a valid network address.\n";
+    else
+    {
+      if (match[1])
+            errorString = errorString + theName + ": " + currentAddress + " contains a URL connection protocol.\n";
+      else if (match[2] == null)
+          errorString = errorString + theName + ": " + currentAddress + " does not appear to contain a host.";
+      else if (match[3] || match[4] || match[5] || match[6])
+          errorString = errorString + theName + ": " + currentAddress + " should only contain a host name or ip/ip range.\n";
+      else
+      {
+          if (ignoredot && currentAddress === ".")
+              continue;
+
+          const ipRangePattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:-(\d{1,3}))?$/;
+          var ipRangeMatch = currentAddress.match(ipRangePattern);
+
+          if (ipRangeMatch) //IP form, perhaps range
+          {
+            if (checkspecial)
+            {
+              if (currentAddress == "0.0.0.0" || currentAddress == "255.255.255.255")
+                errorString = errorString + theName + ': ' + IPvalue + ' is a special IP address and cannot be used here.';
+            }
+
+            if(ipRangeMatch[5] != null) //IP range format detected
+            {
+                var invalidIPSubNet = isValidIPSubNetRange(ipRangeMatch[4], ipRangeMatch[5]);
+                if (invalidIPSubNet)
+                  errorString = errorString + theName + ": " + invalidIPSubNet + "\n";
+            }
+          }
+        }
+     }
+  }
+  return errorString;
+}
+
 function isValidIPAddress(ipList, theName, ignoredot, checkspecial) {
   var errorString = "";
   var k = 0;
@@ -285,7 +363,7 @@ function isValidIPAddress(ipList, theName, ignoredot, checkspecial) {
         errorString = errorString + theName + ': ' + IPvalue + ' is a special IP address and cannot be used here.';
     }
 
-    if (ignoredot && IPvalue === ".") 
+    if (ignoredot && IPvalue === ".")
       continue;
 
     if (ipArray == null)
@@ -346,7 +424,7 @@ function addUniqueToArray(arr, itm) {
             flag = true;
           else
             return;
-        } 
+        }
     }
 
     if (arr.length == 0)
@@ -371,3 +449,4 @@ function isNotInEnv(notInEnvList, name)
   else
     return false;
 }
+

+ 1 - 1
esp/files/scripts/configmgr/configmgr.js

@@ -845,7 +845,7 @@ function handleConfigCellClickEvent(oArgs, caller, isComplex) {
 
     if (compName === "Hardware" && (attrName === "netAddress" || attrName === "mask" || attrName === "subnet")) {
       var errMsg = "";
-      errMsg = isValidIPAddress(newValue, attrName, true, false);
+      errMsg = isValidNetworkAddress(newValue, attrName, true, false);
 
       if (errMsg.length > 0) {
         alert(errMsg);

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 212 - 176
esp/files/scripts/configmgr/navtree.js


+ 45 - 10
esp/services/WsDeploy/WsDeployService.cpp

@@ -4722,21 +4722,56 @@ bool CWsDeployFileInfo::handleComputer(IEspContext &context, IEspHandleComputerR
 
   if (!strcmp(operation, "New"))
   {
-    StringBuffer sbTemp;
-    IPropertyTree* pCompTree = createPTree(XML_TAG_HARDWARE);
-    generateHardwareHeaders(pEnvRoot, sbTemp, false, pCompTree, true);
+    const char* prefix = pParams->queryProp("@prefix");
+    const char* domain = pParams->queryProp(XML_ATTR_DOMAIN);
+    const char* cType = pParams->queryProp(XML_ATTR_COMPUTERTYPE);
+    const char* netAddress = pParams->queryProp("@startIP");
+    const char* hostName = pParams->queryProp("@hostname");
 
-    StringBuffer sbNewName(type);
-    xpath.clear().appendf("%s", type);
+    StringBuffer sName;
 
-    getUniqueName(pEnvRoot, sbNewName, xpath.str(), XML_TAG_HARDWARE);
-    xpath.clear().append(type).append("/").append(XML_ATTR_NAME);
-    pCompTree->setProp(xpath.str(), sbNewName);
+    if ( (!netAddress || !*netAddress) && (hostName && *hostName))
+    {
+      netAddress = hostName;
+      sName.set(hostName);
+    }
+    else
+    {
+      sName.set(prefix);
+    }
 
-    pEnvRoot->queryPropTree(XML_TAG_HARDWARE)->addPropTree(type, pCompTree->queryPropTree(type));
+    // Create string for common attributes
+    StringBuffer attr;
+    attr.setf(" %s=\"%s\" %s=\"%s\"", &XML_ATTR_DOMAIN[1], domain, &XML_ATTR_COMPUTERTYPE[1], cType);
 
-    resp.setCompName(sbNewName.str());
+    StringBuffer sNode("<" XML_TAG_HARDWARE ">");
+
+    sNode.appendf("<" XML_TAG_COMPUTER " %s=\"%s\" %s=\"%s\" %s/>",
+                  &XML_ATTR_NAME[1], getUniqueName(pEnvRoot, sName, XML_TAG_COMPUTER, XML_TAG_HARDWARE),
+                  &XML_ATTR_NETADDRESS[1], netAddress,
+                  attr.str());
+    sNode.append("</" XML_TAG_HARDWARE ">");
+    IPropertyTree* pTree = createPTreeFromXMLString(sNode);
+
+    if (m_bCloud)
+    {
+      StringBuffer sbMsg;
+      CCloudActionHandler lockCloud(this, CLOUD_LOCK_ENV, CLOUD_UNLOCK_ENV, m_userWithLock.str(), "8015", pTree);
+      bool ret = lockCloud.start(sbMsg);
+      if (!ret || sbMsg.length())
+      {
+        resp.setStatus("false");
+        throw MakeStringException(-1, "Cannot add new range of computers as environment lock could not be obtained. Reason(s):\n%s", sbMsg.str());
+      }
+    }
+
+    if (pTree)
+    {
+      mergePTree(pEnvRoot->queryPropTree(XML_TAG_HARDWARE), pTree);
+      resp.setCompName(sName.str());
+    }
     resp.setStatus("true");
+
   }
   else if (!strcmp(operation, "NewRange"))
   {