This commit is contained in:
Garrett K 2021-03-03 05:49:53 +00:00
parent 9d8d4c2a39
commit 6f85c6af5e
8 changed files with 281 additions and 266 deletions

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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++) {

View File

@ -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);
}

View File

@ -3232,6 +3232,263 @@ var $qls;
return str_replace('&#8209;', '-', $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

View File

@ -1,239 +1,21 @@
<?php
// pathArray contains all necessary path data
$pathArray = array();
if($connectorCode39) {
$managedCableID = base_convert($connectorCode39, 36, 10);
$rootCable2 = $qls->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);
?>

View File

@ -668,7 +668,7 @@
</div><!-- /.modal -->
<!-- image upload modal -->
<div id="modalImageUpload" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalLabelImageUpload" aria-hidden="true">
<div id="modalTemplateImageUpload" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalLabelImageUpload" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">