Skip to content

Commit

Permalink
[IM] Improve query and function for switch configuration display
Browse files Browse the repository at this point in the history
This came from examinig #497 but could not reproduce this bug report.
  • Loading branch information
barryo committed Jan 16, 2019
1 parent c06ac1d commit 5274189
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Switches/SwitchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ public function configuration( Request $r ) : View {
'infras' => $s ? [ $s->getInfrastructure()->getId() => $s->getInfrastructure()->getName() ] : D2EM::getRepository( InfrastructureEntity::class )->getNames( true ),
'locations' => $s ? [ $s->getCabinet()->getLocation()->getId() => $s->getCabinet()->getLocation()->getName() ] : D2EM::getRepository( LocationEntity::class )->getNames(),
'switches' => D2EM::getRepository( SwitcherEntity::class )->getByLocationAndInfrastructure( $infra, $location ),
'config' => D2EM::getRepository( SwitcherEntity::class )->getConfiguration( $s ? $s->getId() : null , null, null, Auth::getUser()->isSuperUser() , $infra ? $infra->getId() : null, $location ? $location->getId() : null )
'config' => D2EM::getRepository( SwitcherEntity::class )->getConfiguration( $s ? $s->getId() : null ,$infra ? $infra->getId() : null, $location ? $location->getId() : null )
]);
}

Expand Down
41 changes: 14 additions & 27 deletions database/Repositories/Switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,12 @@ public function getNamesByLocation( $active = false, $idLocation = null )
* Return an array of configurations
*
* @param int $switchid Switcher id for filtering results
* @param int $vlanid Vlan id for filtering results
* @param int $ixpid IXP id for filtering results
* @param bool $superuser Does the user is super user ?
* @param int $infra Infrastructure id for filtering results
* @param int $facility Facility id for filtering results
*
* @return array
*/
public function getConfiguration( $switchid = null, $vlanid = null, $ixpid = null, $superuser = true, $infra = null, $facility = null )
public function getConfiguration( $switchid = null, $infra = null, $facility = null )
{
$q =
"SELECT s.name AS switchname,
Expand All @@ -212,55 +209,45 @@ public function getConfiguration( $switchid = null, $vlanid = null, $ixpid = nul
c.id AS custid,
c.autsys AS asn,
vli.rsclient AS rsclient,
vli.ipv4enabled AS ipv4enabled,
vli.ipv6enabled AS ipv6enabled,
v.name AS vlan,
GROUP_CONCAT( DISTINCT ipv4.address ) AS ipv4address,
GROUP_CONCAT( DISTINCT ipv6.address ) AS ipv6address
FROM \\Entities\\VlanInterface vli
FROM Entities\\VlanInterface vli
JOIN vli.IPv4Address ipv4
LEFT JOIN vli.IPv6Address ipv6
JOIN vli.IPv6Address ipv6
LEFT JOIN vli.Vlan v
LEFT JOIN vli.VirtualInterface vi
LEFT JOIN vi.Customer c
LEFT JOIN vi.PhysicalInterfaces pi
LEFT JOIN pi.SwitchPort sp
LEFT JOIN sp.Switcher s
LEFT JOIN v.Infrastructure vinf
LEFT JOIN vinf.IXP vixp
LEFT JOIN s.Infrastructure sinf
LEFT JOIN sinf.IXP sixp
LEFT JOIN s.Infrastructure inf
LEFT JOIN s.Cabinet cab
WHERE 1=1 ";

if( $switchid !== null )
if( $switchid !== null ) {
$q .= 'AND s.id = ' . intval( $switchid ) . ' ';
}

if( $vlanid !== null )
$q .= 'AND v.id = ' . intval( $vlanid ) . ' ';

if( $ixpid !== null )
$q .= 'AND ( sixp.id = ' . intval( $ixpid ) . ' OR vixp.id = ' . intval( $ixpid ) . ' ) ';

if( !$superuser && $ixpid )
$q .= 'AND ?1 MEMBER OF c.IXPs ';

if( $infra !== null )
$q .= 'AND sinf.id = ' . intval( $infra ) . ' ';
if( $infra !== null ) {
$q .= 'AND inf.id = ' . intval( $infra ) . ' ';
}

if( $facility !== null )
if( $facility !== null ) {
$q .= 'AND cab.Location = ' . intval( $facility ) . ' ';
}


$q .= " GROUP BY switchname, switchid, duplex, portstatus, customer, custid, asn, rsclient, vlan ";
$q .= " GROUP BY switchname, switchid, duplex, portstatus, customer, custid, asn, rsclient, ipv4enabled, ipv6enabled, vlan ";

$q .= " ORDER BY customer ASC";

$query = $this->getEntityManager()->createQuery( $q );

if( !$superuser && $ixpid )
$query->setParameter( 1, $ixpid );

return $query->getArrayResult();
}

Expand Down
8 changes: 6 additions & 2 deletions resources/views/switches/configuration.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@
<?php if( $conf[ "rsclient" ] ): ?>Yes<?php else: ?>No<?php endif; ?>
</td>
<td>
<?= str_replace( ",", "<br>" , $conf[ "ipv4address" ] ) ?>
<?php if( $conf['ipv4enabled'] ): ?>
<?= str_replace( ",", "<br>" , $conf[ "ipv4address" ] ) ?>
<?php endif; ?>
</td>
<td>
<?= str_replace( ",", "<br>" , $conf[ "ipv6address" ] ) ?>
<?php if( $conf['ipv6enabled'] ): ?>
<?= str_replace( ",", "<br>" , $conf[ "ipv6address" ] ) ?>
<?php endif; ?>
</td>
<td>
<?php if( isset( Entities\PhysicalInterface::$STATES[ $conf[ "portstatus" ] ] ) ): ?>
Expand Down

0 comments on commit 5274189

Please sign in to comment.