Skip to content

Commit

Permalink
[NF] - ZF -> Laravel: RsPrefixesController - closes islandbridgenetwo…
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrobin authored and barryo committed Nov 25, 2017
1 parent a46ef5e commit 21c1ba3
Show file tree
Hide file tree
Showing 21 changed files with 594 additions and 14 deletions.
147 changes: 147 additions & 0 deletions app/Http/Controllers/RsPrefixesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

namespace IXP\Http\Controllers;

/*
* Copyright (C) 2009-2017 Internet Neutral Exchange Association Company Limited By Guarantee.
* All Rights Reserved.
*
* This file is part of IXP Manager.
*
* IXP Manager 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, version v2.0 of the License.
*
* IXP Manager 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 v2.0
* along with IXP Manager. If not, see:
*
* http://www.gnu.org/licenses/gpl-2.0.html
*/

use Auth, D2EM;

use Entities\{
RSPrefix as RSPrefixEntity,
Customer as CustomerEntity,
User as UserEntity,
VirtualInterface as VirtualInterfaceEntity,
VlanInterface as VlanInterfaceEntity
};

use Illuminate\View\View;


/**
* Route Server Prefixes Controller
* @author Barry O'Donovan <[email protected]>
* @author Yann Robin <[email protected]>
* @category Controller
* @copyright Copyright (C) 2009-2017 Internet Neutral Exchange Association Company Limited By Guarantee
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
*/
class RsPrefixesController extends Controller {

/**
* Display all the RsPrefixes
*
* @return View
*/
public function list( ): View {

return view( 'rs-prefixes/list' )->with([
'types' => RSPrefixEntity::$SUMMARY_TYPES_FNS,
'rsRouteTypes' => array_keys( RSPrefixEntity::$ROUTES_TYPES_FNS ),
'cust_prefixes' => D2EM::getRepository( RSPrefixEntity::class )->aggregateRouteSummaries()
]);
}

/**
* Display all the RsPrefixes for a Customer in Restricted version for the user type CustUser
*
* @param int|null $protocol protocol selected
* @return View
*/
public function viewRestricted( $protocol = null ) {
if( Auth::getUser()->getPrivs() != UserEntity::AUTH_CUSTADMIN || Auth::getUser()->getPrivs() != UserEntity::AUTH_SUPERUSER ) {
abort( 403 );
}

return $this->view( Auth::getUser()->getCustomer()->getId() , null, $protocol);
}

/**
* Display all the RsPrefixes for a Customer filtered by protocol or for all protocol
*
* @param int $cid customer ID
* @param int|null $protocol protocol selected
* @return View
*/
public function viewFiltered( $cid, $protocol = null ) {
return $this->view( $cid, null, $protocol);
}

/**
* Display all the RsPrefixes for a Customer
*
* @param int $cid customer ID
* @param string $type type of Rs prefix (adv_nacc|adv_acc|nadv_acc)
* @param int|null $protocol protocol selected
* @return View
*/
public function view( $cid, $type , $protocol = null ) : View {
/** @var CustomerEntity $c */
if( !( $c = D2EM::getRepository( CustomerEntity::class )->find( $cid ) ) ) {
abort(404);
}

if( $type ){
if( !in_array( $type, array_keys( RSPrefixEntity::$SUMMARY_TYPES_FNS ) ) ) {
abort(404);
}
} else{
$type = false;
}


if( !in_array( $protocol, [ 4, 6 ] ) ){
$protocol = false;
}

// does the customer have VLAN interfaces that filtering is disabled on?
$totalVlanInts = 0;
$filteredVlanInts = 0;

foreach( $c->getVirtualInterfaces() as $vi ) {
/** @var VirtualInterfaceEntity $vi */
foreach( $vi->getVlanInterfaces() as $vli ) {
/** @var VlanInterfaceEntity $vli */
if( $vli->getVlan()->getPrivate() ){
continue;
}

if( $vli->getIrrdbfilter() ){
$filteredVlanInts++;
}
$totalVlanInts++;
}
}

return view( 'rs-prefixes/view' )->with([
'totalVl' => $totalVlanInts,
'filteredVl' => $filteredVlanInts ,
'protocol' => $protocol,
'type' => $type,
'rsRouteTypes' => array_keys( RSPrefixEntity::$ROUTES_TYPES_FNS ),
'c' => $c,
'aggRoutes' => D2EM::getRepository( RSPrefixEntity::class )->aggregateRoutes( $c->getId(), $protocol ? $protocol : null )
]);


}

}
13 changes: 13 additions & 0 deletions app/Utils/Foil/Extensions/IXP.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function provideFunctions() {
'scaleBits' => [ $this, 'scaleBits' ],
'scaleBytes' => [ $this, 'scaleBytes' ],
'softwrap' => [ $this, 'softwrap' ],
'asNumber' => [ $this, 'asNumber' ],
];
}

Expand Down Expand Up @@ -281,5 +282,17 @@ public function as112UiActive(): bool
return boolval( config( 'ixp.as112.ui_active', false ) );
}

/**
* Replaces an AS Number with some JS magic to invoke a bootbox.
*
* @param string $asn The AS number
*
* @return html
*/
public function asNumber( $asn )
{
return '<a href="#asnumber-' . $asn . '" href="#" onClick=\'asnumber(' . $asn . '); return false;\'>' . $asn . '</a>';
}


}
2 changes: 1 addition & 1 deletion application/views/customer/overview.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
{if not isset( $options['frontend']['disabled']['rs-prefixes'] ) or not $options['frontend']['disabled']['rs-prefixes'] }
{if $cust->isRouteServerClient()}
<li>
<a href="{genUrl controller="rs-prefixes" action="list" custid=$cust->getId()}">
<a href="{route('rs-prefixes@viewFiltered', [ 'cid' => $cust->getId() ])}">
RS Prefixes
{if $rsRoutes.adv_nacc.total gt 0}
<span class="badge badge-important">{$rsRoutes.adv_nacc.total}</span>
Expand Down
2 changes: 1 addition & 1 deletion application/views/dashboard/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{if not isset( $options['frontend']['disabled']['rs-prefixes'] ) or not $options['frontend']['disabled']['rs-prefixes'] }
{if $user->getCustomer()->isRouteServerClient()}
<li>
<a href="{genUrl controller="rs-prefixes" action="list" tab='adv_nacc'}">
<a href="{route('rs-prefixes@viewRestricted')}">
Prefixes
{if $rsRoutes.adv_nacc.total gt 0}
<span class="badge badge-important">{$rsRoutes.adv_nacc.total}</span>
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"clipboard": "^1.6.1",
"ip-address": "^5.0",
"moment": "^2.18.1",
"select2": "^4.0.3"
"select2": "^4.0.3",
"bootbox.js": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion database/Entities/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public function removeVirtualInterface(\Entities\VirtualInterface $virtualInterf
/**
* Get VirtualInterfaces
*
* @return Doctrine\Common\Collections\Collection
* @return Doctrine\Common\Collection
*/
public function getVirtualInterfaces()
{
Expand Down
2 changes: 1 addition & 1 deletion database/Entities/VirtualInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function removeVlanInterface(\Entities\VlanInterface $vlanInterfaces)
/**
* Get VlanInterfaces
*
* @return \Doctrine\Common\Collections\Collection|VlanInterface[]
* @return \Doctrine\Common\Collection
*/
public function getVlanInterfaces()
{
Expand Down
5 changes: 4 additions & 1 deletion database/Repositories/RSPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ public function aggregateRoutes( $cust, $protocol = null )
{
$aggRoutes = [];

foreach( \Entities\RSPrefix::$ROUTES_TYPES_FNS as $type => $fn )
foreach( \Entities\RSPrefix::$ROUTES_TYPES_FNS as $type => $fn ){
$aggRoutes[ $type ] = $this->$fn( $protocol, $cust );
}


return $aggRoutes;
}
Expand Down Expand Up @@ -353,6 +355,7 @@ public function getRoutes( $irrdb, $rsOriginIsNull, $protocol = null, $cust = nu

if( $cust !== null )
$query->setParameter( 3, $cust );


return $query->getArrayResult();
}
Expand Down
19 changes: 19 additions & 0 deletions public/css/ixp-manager.css
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,22 @@ td a:hover{
.help-block {
display: none;
}

.badge-primary{
color: #fff;
background-color: #007bff;
}

.badge-success{
color: #fff;
background-color: #5cb85c;
}

.badge-danger{
color: #fff;
background-color: #d9534f;
}
.badge-warning{
color: #fff;
background-color: #f0ad4e;
}
6 changes: 0 additions & 6 deletions public/js/bootbox.min.js

This file was deleted.

30 changes: 30 additions & 0 deletions public/js/ixp-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,33 @@ function ixpRandomString( length = 12 ) {

return result;
}


/**
* Replaces an AS Number with some JS magic to invoke a BootBox.
*
* @param string asNumber The AS number
*
* @return html
*/
function asnumber( asNumber ) {

event.preventDefault();

let html = `<iframe width="100%" height="500px" src="https://apps.db.ripe.net/search/query.html?searchtext=as${asNumber}" frameborder="0" allowfullscreen></iframe>`;

bootbox.dialog({
message: html,
size: "large",
title: "Informations",
buttons: {
cancel: {
label: 'Close',
callback: function () {
$('.bootbox.modal').modal('hide');
return false;
}
}
}
});
}
2 changes: 1 addition & 1 deletion resources/views/layouts/ixpv4.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<script type="text/javascript" src="<?= asset('/bower_components/select2/dist/js/select2.min.js') ?>"></script>
<script type="text/javascript" src="<?= asset('/js/900-oss-framework.js') ?>"></script>
<script type="text/javascript" src="<?= asset('/js/ixp-manager.js') ?>"></script>
<script type="text/javascript" src="<?= asset('/js/bootbox.min.js') ?>"></script>
<script type="text/javascript" src="<?= asset('/bower_components/bootbox.js/bootbox.js') ?>"></script>

<script>
$( ".chzn-select" ).select2({ width: '100%' });
Expand Down
Loading

0 comments on commit 21c1ba3

Please sign in to comment.