From 6f85c6af5e2cc677acfa784e82e604a79518c11f Mon Sep 17 00:00:00 2001 From: Garrett K Date: Wed, 3 Mar 2021 05:49:53 +0000 Subject: [PATCH] 0.3.14 --- CHANGELOG | 5 + assets/pages/jquery.templates.js | 2 +- backend/process_cable.php | 31 +--- backend/process_path_finder.php | 8 +- backend/retrieve_path_full.php | 2 +- includes/App.class.php | 257 +++++++++++++++++++++++++++++++ includes/content-path2.php | 240 ++--------------------------- includes/modals.php | 2 +- 8 files changed, 281 insertions(+), 266 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bdf5ec6..c88b156 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ ChangeLog for PatchCableMgr **************************************************** Contents + - Changes Introduced In 0.3.14 - Changes Introduced In 0.3.13 - Changes Introduced In 0.3.12 - Changes Introduced In 0.3.11 @@ -32,6 +33,10 @@ Contents **************************************************** \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ +**Changes introduced in 0.3.14 +[Enhance] Added support for point-to-multipoint connections to represent breakout cables +[Fix] Broken template image upload + **Changes introduced in 0.3.13 [Fix] Failure to import trunk data correctly on backup restore diff --git a/assets/pages/jquery.templates.js b/assets/pages/jquery.templates.js index 6910985..55f3a88 100755 --- a/assets/pages/jquery.templates.js +++ b/assets/pages/jquery.templates.js @@ -782,7 +782,7 @@ function makeRackObjectsClickable(){ if(templateCombined == 'no') { $('#templateImageAction').on('click', function(event){ event.preventDefault(); - $('#modalImageUpload').modal('show'); + $('#modalTemplateImageUpload').modal('show'); }); $('#templateImageDelete').on('click', function(event){ event.preventDefault(); diff --git a/backend/process_cable.php b/backend/process_cable.php index 572c38c..a4bc179 100755 --- a/backend/process_cable.php +++ b/backend/process_cable.php @@ -439,7 +439,7 @@ function validate($data, &$validate, &$qls){ $validate->validateTrunkedEndpoint($connectionPeerArray); // Validate no loops will result - if($qls->App->loopDetected($localID, $localFace, $localDepth, $localPort, $remoteID, $remoteFace, $remoteDepth, $remotePort)) { + if($qls->App->loopDetected2($localID, $localFace, $localDepth, $localPort, $remoteID, $remoteFace, $remoteDepth, $remotePort)) { $errMsg = 'Loop detected.'; array_push($validate->returnData['error'], $errMsg); } @@ -461,35 +461,6 @@ function validate($data, &$validate, &$qls){ array_push($validate->returnData['error'], $errMsg); } } - - if(count($remotePortArray) > 1) { - - $breakoutCableValid = true; - $localObj = $qls->App->objectArray[$localID]; - $localTemplateID = $localObj['template_id']; - $localTemplate = $qls->App->templateArray[$localTemplateID]; - $localTemplateFunction = $localTemplate['templateFunction']; - if($remoteTemplateFunction != 'Endpoint') { - $localTemplateFunction = false; - } - - foreach($remotePortArray as $remotePortData) { - $remoteID = $remotePortData['remoteID']; - $remoteObj = $qls->App->objectArray[$remoteID]; - $remoteTemplateID = $remoteObj['template_id']; - $remoteTemplate = $qls->App->templateArray[$remoteTemplateID]; - $remoteTemplateFunction = $remoteTemplate['templateFunction']; - if($remoteTemplateFunction != 'Endpoint') { - //$breakoutCableValid = false; - $breakoutCableValid = true; - } - } - - if(!$breakoutCableValid) { - $errMsg = 'One-to-many connections must be between two endpoints.'; - array_push($validate->returnData['error'], $errMsg); - } - } } } return; diff --git a/backend/process_path_finder.php b/backend/process_path_finder.php index ace66e9..4d30ca8 100755 --- a/backend/process_path_finder.php +++ b/backend/process_path_finder.php @@ -318,7 +318,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){ $finalPathArray = array(); foreach($reachableArray as $reachable) { - findPaths2($qls, $maxResults, $maxDepth, $reachable, $endpointAObj, $endpointBObj, $finalPathArray, $previousPathType); + findPaths($qls, $maxResults, $maxDepth, $reachable, $endpointAObj, $endpointBObj, $finalPathArray, $previousPathType); } foreach($finalPathArray as $mediaType => &$pathData) { @@ -332,7 +332,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){ echo json_encode($validate->returnData); } -function findPaths2(&$qls, &$maxResults, &$maxDepth, &$reachable, &$focus, &$endpointBObj, &$finalPathArray, &$previousPathType, $workingArray=array(), $visitedObjArray=array(), $reachableTypeArray=array('local'=>0,'adjacent'=>0,'path'=>0)){ +function findPaths(&$qls, &$maxResults, &$maxDepth, &$reachable, &$focus, &$endpointBObj, &$finalPathArray, &$previousPathType, $workingArray=array(), $visitedObjArray=array(), $reachableTypeArray=array('local'=>0,'adjacent'=>0,'path'=>0)){ // Path type signals which path should be searched, // trunk or reachable. @@ -426,7 +426,7 @@ function findPaths2(&$qls, &$maxResults, &$maxDepth, &$reachable, &$focus, &$end 'port' => $focusPort ); - findPaths2($qls, $maxResults, $maxDepth, $reachable, $newFocus, $endpointBObj, $finalPathArray, $trunkPathType, $workingArray, $visitedObjArray, $reachableTypeArray); + findPaths($qls, $maxResults, $maxDepth, $reachable, $newFocus, $endpointBObj, $finalPathArray, $trunkPathType, $workingArray, $visitedObjArray, $reachableTypeArray); // Clear last path branch so we can continue searching for($arrayCount=0; $arrayCount<1; $arrayCount++) { @@ -532,7 +532,7 @@ function findPaths2(&$qls, &$maxResults, &$maxDepth, &$reachable, &$focus, &$end // Increment reachableTypeCount $reachableTypeArray[$reachableType]++; - findPaths2($qls, $maxResults, $maxDepth, $reachable, $newFocus, $endpointBObj, $finalPathArray, $reachablePathType, $workingArray, $visitedObjArray, $reachableTypeArray); + findPaths($qls, $maxResults, $maxDepth, $reachable, $newFocus, $endpointBObj, $finalPathArray, $reachablePathType, $workingArray, $visitedObjArray, $reachableTypeArray); // Clear last path branch so we can continue searching for($arrayCount=0; $arrayCount<3; $arrayCount++) { diff --git a/backend/retrieve_path_full.php b/backend/retrieve_path_full.php index bf0005b..36c2312 100755 --- a/backend/retrieve_path_full.php +++ b/backend/retrieve_path_full.php @@ -25,7 +25,7 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){ // Create $path include_once $_SERVER['DOCUMENT_ROOT'].'/includes/content-path2.php'; - include_once $_SERVER['DOCUMENT_ROOT'].'/includes/content-path.php'; + //include_once $_SERVER['DOCUMENT_ROOT'].'/includes/content-path.php'; $validate->returnData['success'] = $qls->App->buildPathFull2($pathArray); //$validate->returnData['success'] = $qls->App->buildPathFull($path, $connectorCode39); } diff --git a/includes/App.class.php b/includes/App.class.php index 37cabb5..5c446be 100755 --- a/includes/App.class.php +++ b/includes/App.class.php @@ -3232,6 +3232,263 @@ var $qls; return str_replace('‑', '-', $string); } + function crawlPath($objID, $objFace, $objDepth, $objPort, $detectDivergence=false){ + + // pathArray contains all necessary path data + $pathArray = array(); + + // Retrieve initial connection set + $selected = true; + $connSet = $this->crawlConn($selected, $objID, $objFace, $objDepth, $objPort); + $selected = false; + if($detectDivergence) { + $this->detectDivergence($connSet[0]); + $this->detectDivergence($connSet[1]); + } + array_push($pathArray, $connSet); + + for($direction=0; $direction<2; $direction++) { + + do { + + // Set path array pointer + // 0 for up, -1 for down + $pathArrayPointer = ($direction == 0) ? 0 : count($pathArray)-1; + + // Get port trunk peer + $trunkSet = $this->crawlTrunk($pathArray[$pathArrayPointer][$direction]); + if($detectDivergence) { + $this->detectDivergence($trunkSet); + } + $trunkFound = (count($trunkSet)) ? true : false; + + // Find connections for each trunked port + $workingConnSet = array(array(),array()); + foreach($trunkSet as $port) { + + // Store port info + $remoteObjID = $port['objID']; + $remoteObjFace = $port['objFace']; + $remoteObjDepth = $port['objDepth']; + $remoteObjPort = $port['objPort']; + + // Find connections + $connSet = $this->crawlConn($selected, $remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort); + if($detectDivergence) { + $this->detectDivergence($connSet[0]); + $this->detectDivergence($connSet[1]); + } + + // Add ports to workingConnSet + if($direction == 0) { + foreach($connSet[0] as $port) { + array_push($workingConnSet[1], $port); + } + foreach($connSet[1] as $port) { + array_push($workingConnSet[0], $port); + } + } else { + foreach($connSet[0] as $port) { + array_push($workingConnSet[0], $port); + } + foreach($connSet[1] as $port) { + array_push($workingConnSet[1], $port); + } + + } + } + + // Add connection set to appropriate end of pathArray + if($trunkFound) { + if($direction == 0) { + array_unshift($pathArray, $workingConnSet); + } else { + array_push($pathArray, $workingConnSet); + } + } + } while($trunkFound); + } + return $pathArray; + } + + function crawlTrunk($portSet) { + + $trunkSet = array(); + + // Loop over each port of $conn + foreach($portSet as $portSetID => $port) { + + // Gather port data + $objID = $port['objID']; + $objFace = $port['objFace']; + $objDepth = $port['objDepth']; + $objPort = $port['objPort']; + + // Gather trunk peer data + if(isset($this->peerArray[$objID][$objFace][$objDepth])) { + + // Gather trunk peer object + $peer = $this->peerArray[$objID][$objFace][$objDepth]; + + // Gather trunk peer data + $peerObjID = $peer['peerID']; + $peerObjFace = $peer['peerFace']; + $peerObjDepth = $peer['peerDepth']; + $peerObjPort = $objPort; + + // Create a working array for cleanliness + $workingArray = array( + 'objID' => $peerObjID, + 'objFace' => $peerObjFace, + 'objDepth' => $peerObjDepth, + 'objPort' => $peerObjPort + ); + + // Store trunk data + $trunkSet[$portSetID] = $workingArray; + } + } + + return $trunkSet; + } + + function crawlConn($selected, $objID, $objFace, $objDepth, $objPort, &$connSet=array(array(),array()), $connSetID=0) { + + $managedCableID = (isset($this->inventoryArray[$objID][$objFace][$objDepth][$objPort])) ? $this->inventoryArray[$objID][$objFace][$objDepth][$objPort][0]['localEndID'] : 0; + if($managedCableID != 0) { + $managedCable = $this->inventoryByIDArray[$managedCableID]; + $managedCableMediaTypeID = $managedCable['mediaType']; + $managedCableLength = $managedCable['length']; + $includeUnit = true; + $length = $this->calculateCableLength($managedCableMediaTypeID, $managedCableLength, $includeUnit); + $mediaTypeID = $managedCable['mediaType']; + $connectorTypeID = $managedCable['localConnector']; + } else { + $length = 'Unk. Length'; + $mediaTypeID = false; + $connectorTypeID = false; + } + + // Store port details + $workingArray = array( + 'objID' => $objID, + 'objFace' => $objFace, + 'objDepth' => $objDepth, + 'objPort' => $objPort, + 'selected' => $selected, + 'length' => $length, + 'mediaTypeID' => $mediaTypeID, + 'connectorTypeID' => $connectorTypeID + ); + + // Add port info to connection set + array_push($connSet[$connSetID], $workingArray); + + // Is local port connected? + if(isset($this->inventoryArray[$objID][$objFace][$objDepth][$objPort])) { + + // Flip the connection set ID + $connSetID = ($connSetID == 0) ? 1 : 0; + + // Loop over each local port connection + $inventoryEntry = $this->inventoryArray[$objID][$objFace][$objDepth][$objPort]; + foreach($inventoryEntry as $connection) { + + // Collect remote object data + $remoteObjID = $connection['id']; + $remoteObjFace = $connection['face']; + $remoteObjDepth = $connection['depth']; + $remoteObjPort = $connection['port']; + $managedCableID = $connection['localEndID']; + + // Verify this node has not been visited already + $alreadySeen = false; + foreach($connSet as $conn) { + foreach($conn as $port) { + if($port['objID'] == $remoteObjID and $port['objFace'] == $remoteObjFace and $port['objDepth'] == $remoteObjDepth and $port['objPort'] == $remoteObjPort) { + $alreadySeen = true; + } + } + } + + if(!$alreadySeen) { + $selected = false; + $this->crawlConn($selected, $remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $connSet, $connSetID); + } + } + } + + return $connSet; + } + + function detectDivergence(&$dataSet) { + + $pathDiverges = false; + + // Detect path divergence + foreach($dataSet as $portIndex => $port) { + + // Identify parent object ID + $portObjID = $port['objID']; + $portObj = $this->objectArray[$portObjID]; + $portObjParentID = $portObj['parent_id']; + while($portObjParentID != 0) { + $portObj = $this->objectArray[$portObjParentID]; + $portObjParentID = $portObj['parent_id']; + } + + // Determine path divergence + if($portIndex == 0) { + $baselineParentID = $portObjParentID; + } else { + if($portObjParentID != $baselineParentID) { + + // Flag this path as divergent + $pathDiverges = true; + + // Remove divergent connection + unset($dataSet[$portIndex]); + } + } + } + + return $pathDiverges; + } + + function loopDetected2($aID, $aFace, $aDepth, $aPort, $bID, $bFace, $bDepth, $bPort){ + + $visitedArray = array(); + $loopDetected = false; + $pathArrayA = $this->crawlPath($aID, $aFace, $aDepth, $aPort); + $pathArrayB = $this->crawlPath($bID, $bFace, $bDepth, $bPort); + $pathArray = array($pathArrayA, $pathArrayB); + + foreach($pathArray as $path) { + foreach($path as $connection) { + foreach($connection as $connectionSide) { + foreach($connectionSide as $port) { + + $objID = $port['objID']; + $objFace = $port['objFace']; + $objDepth = $port['objDepth']; + $objPort = $port['objPort']; + + $portString = $objID.'-'.$objFace.'-'.$objDepth.'-'.$objPort; + $portStringHash = md5($portString); + + if(in_array($portStringHash, $visitedArray)) { + $loopDetected = true; + } + + array_push($visitedArray, $portStringHash); + + } + } + } + } + return $loopDetected; + } + function loopDetected($aID, $aFace, $aDepth, $aPort, $bID, $bFace, $bDepth, $bPort){ // If cable is connected to an object diff --git a/includes/content-path2.php b/includes/content-path2.php index 59e8d24..90f6326 100755 --- a/includes/content-path2.php +++ b/includes/content-path2.php @@ -1,239 +1,21 @@ App->inventoryByIDArray[$managedCableID]; + $rootCable = $qls->App->inventoryByIDArray[$managedCableID]; - $objID2 = $rootCable2['local_object_id']; - $objFace2 = $rootCable2['local_object_face']; - $objDepth2 = $rootCable2['local_object_depth']; - $objPort2 = $rootCable2['local_object_port']; + $objID = $rootCable['local_object_id']; + $objFace = $rootCable['local_object_face']; + $objDepth = $rootCable['local_object_depth']; + $objPort = $rootCable['local_object_port']; } -$selectedObjID2 = $objID; -$selectedObjFace2 = $objFace; -$selectedObjDepth2 = $objDepth; -$selectedObjPort2 = $objPort; +$selectedObjID = $objID; +$selectedObjFace = $objFace; +$selectedObjDepth = $objDepth; +$selectedObjPort = $objPort; -// Retrieve initial connection set -$selected = true; -$connSet = crawlConn($qls, $selected, $selectedObjID2, $selectedObjFace2, $selectedObjDepth2, $selectedObjPort2); -detectDivergence($connSet[0]); -detectDivergence($connSet[1]); -//$connSet[0]['selected'] = true; -array_push($pathArray, $connSet); - -for($direction=0; $direction<2; $direction++) { - - do { - - // Set path array pointer - // 0 for up, -1 for down - $pathArrayPointer = ($direction == 0) ? 0 : count($pathArray)-1; - - error_log('Debug (pathArray): '.json_encode($pathArray)); - error_log('Debug (pathArrayPointer): '.$pathArrayPointer); - error_log('Debug (direction): '.$direction); - error_log('Debug (crawlTrunk data): '.json_encode($pathArray[$pathArrayPointer][$direction])); - - // Get port trunk peer - $trunkSet = crawlTrunk($qls, $pathArray[$pathArrayPointer][$direction]); - detectDivergence($trunkSet); - $trunkFound = (count($trunkSet)) ? true : false; - - // Find connections for each trunked port - $workingConnSet = array(array(),array()); - foreach($trunkSet as $port) { - - // Store port info - $selectedObjID2 = $port['objID']; - $selectedObjFace2 = $port['objFace']; - $selectedObjDepth2 = $port['objDepth']; - $selectedObjPort2 = $port['objPort']; - - // Find connections - $selected = false; - $connSet = crawlConn($qls, $selected, $selectedObjID2, $selectedObjFace2, $selectedObjDepth2, $selectedObjPort2); - detectDivergence($connSet[0]); - detectDivergence($connSet[1]); - - // Add ports to workingConnSet - if($direction == 0) { - foreach($connSet[0] as $port) { - array_push($workingConnSet[1], $port); - } - foreach($connSet[1] as $port) { - array_push($workingConnSet[0], $port); - } - } else { - foreach($connSet[0] as $port) { - array_push($workingConnSet[0], $port); - } - foreach($connSet[1] as $port) { - array_push($workingConnSet[1], $port); - } - - } - } - - // Add connection set to appropriate end of pathArray - if($trunkFound) { - if($direction == 0) { - array_unshift($pathArray, $workingConnSet); - } else { - array_push($pathArray, $workingConnSet); - } - } - } while($trunkFound); -} - -error_log('Debug (FINAL pathArray): '.json_encode($pathArray)); - -function crawlTrunk(&$qls, $portSet) { - - $trunkSet = array(); - - // Loop over each port of $conn - foreach($portSet as $portSetID => $port) { - - // Gather port data - $objID = $port['objID']; - $objFace = $port['objFace']; - $objDepth = $port['objDepth']; - $objPort = $port['objPort']; - - // Gather trunk peer data - if(isset($qls->App->peerArray[$objID][$objFace][$objDepth])) { - - // Gather trunk peer object - $peer = $qls->App->peerArray[$objID][$objFace][$objDepth]; - - // Gather trunk peer data - $peerObjID = $peer['peerID']; - $peerObjFace = $peer['peerFace']; - $peerObjDepth = $peer['peerDepth']; - $peerObjPort = $objPort; - - // Create a working array for cleanliness - $workingArray = array( - 'objID' => $peerObjID, - 'objFace' => $peerObjFace, - 'objDepth' => $peerObjDepth, - 'objPort' => $peerObjPort - ); - - // Store trunk data - $trunkSet[$portSetID] = $workingArray; - } - } - - return $trunkSet; -} - -function crawlConn(&$qls, $selected, $objID, $objFace, $objDepth, $objPort, &$connSet=array(array(),array()), $connSetID=0) { - - $managedCableID = (isset($qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort])) ? $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort][0]['localEndID'] : 0; - if($managedCableID != 0) { - $managedCable = $qls->App->inventoryByIDArray[$managedCableID]; - $managedCableMediaTypeID = $managedCable['mediaType']; - $managedCableLength = $managedCable['length']; - $includeUnit = true; - $length = $qls->App->calculateCableLength($managedCableMediaTypeID, $managedCableLength, $includeUnit); - $mediaTypeID = $managedCable['mediaType']; - $connectorTypeID = $managedCable['localConnector']; - } else { - $length = 'Unk. Length'; - $mediaTypeID = false; - $connectorTypeID = false; - } - - // Store port details - $workingArray = array( - 'objID' => $objID, - 'objFace' => $objFace, - 'objDepth' => $objDepth, - 'objPort' => $objPort, - 'selected' => $selected, - 'length' => $length, - 'mediaTypeID' => $mediaTypeID, - 'connectorTypeID' => $connectorTypeID - ); - - // Add port info to connection set - array_push($connSet[$connSetID], $workingArray); - - // Is local port connected? - if(isset($qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort])) { - - // Flip the connection set ID - $connSetID = ($connSetID == 0) ? 1 : 0; - - // Loop over each local port connection - $inventoryEntry = $qls->App->inventoryArray[$objID][$objFace][$objDepth][$objPort]; - foreach($inventoryEntry as $connection) { - - // Collect remote object data - $remoteObjID = $connection['id']; - $remoteObjFace = $connection['face']; - $remoteObjDepth = $connection['depth']; - $remoteObjPort = $connection['port']; - $managedCableID = $connection['localEndID']; - - // Verify this node has not been visited already - $alreadySeen = false; - foreach($connSet as $conn) { - foreach($conn as $port) { - if($port['objID'] == $remoteObjID and $port['objFace'] == $remoteObjFace and $port['objDepth'] == $remoteObjDepth and $port['objPort'] == $remoteObjPort) { - $alreadySeen = true; - } - } - } - - if(!$alreadySeen) { - $selected = false; - crawlConn($qls, $selected, $remoteObjID, $remoteObjFace, $remoteObjDepth, $remoteObjPort, $connSet, $connSetID); - } - } - } - - return $connSet; -} - -function detectDivergence(&$dataSet) { - - $pathDiverges = false; - - // Detect path divergence - foreach($dataSet as $portIndex => $port) { - - // Identify parent object ID - $portObjID = $port['objID']; - $portObj = $qls->App->objectArray[$portObjID]; - $portObjParentID = $portObj['parent_id']; - while($portObjParentID != 0) { - $portObj = $qls->App->objectArray[$portObjParentID]; - $portObjParentID = $portObj['parent_id']; - } - - // Determine path divergence - if($portIndex == 0) { - $baselineParentID = $portObjParentID; - } else { - if($portObjParentID != $baselineParentID) { - - // Flag this path as divergent - $pathDiverges = true; - - // Remove divergent connection - unset($dataSet[$portIndex]); - } - } - } - - return $pathDiverges; -} +$detectDivergence = true; +$pathArray = $qls->App->crawlPath($selectedObjID, $selectedObjFace, $selectedObjDepth, $selectedObjPort, $detectDivergence); ?> diff --git a/includes/modals.php b/includes/modals.php index ee88b07..fff9102 100755 --- a/includes/modals.php +++ b/includes/modals.php @@ -668,7 +668,7 @@ -