Skip to content

Commit

Permalink
[NF] IRRDB summary / status explorer - ref #877
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Jan 26, 2025
1 parent 90dd4f2 commit d594cd3
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 22 deletions.
1 change: 0 additions & 1 deletion .idea/IXP-Manager.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace IXP\Http\Controllers;
namespace IXP\Http\Controllers\Irrdb;

/*
* Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace IXP\Http\Controllers;
namespace IXP\Http\Controllers\Irrdb;

/*
* Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee.
Expand All @@ -26,13 +26,15 @@
use Auth, Cache;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

use IXP\Http\Controllers\Controller;
use IXP\Jobs\UpdateIrrdb;

use IXP\Http\Requests\Irrdb as IrrdbRequest;

use IXP\Models\{Aggregators\IrrdbAggregator, Customer, User};
use IXP\Models\{Aggregators\IrrdbAggregator, Customer, User, VirtualInterface, VlanInterface};

/**
* Irrdb Controller
Expand All @@ -46,6 +48,39 @@
*/
class IrrdbController extends Controller
{

/**
* Display a table of all members IRRDB status
*
* Protected via route in web-auth-superuser.php
*
* @param Request $r
* @return View
*/
public function summary( Request $r ) : View
{
// find all customers who use the route servers and are IRRDB filtered:
$custids = VirtualInterface::select('custid')

Check failure on line 63 in app/Http/Controllers/Irrdb/IrrdbController.php

View workflow job for this annotation

GitHub Actions / ci-ex-dusk

UndefinedMagicMethod

app/Http/Controllers/Irrdb/IrrdbController.php:63:20: UndefinedMagicMethod: Magic method IXP\Models\VirtualInterface::select does not exist (see https://psalm.dev/219)
->join('vlaninterface', 'vlaninterface.virtualinterfaceid', '=', 'virtualinterface.id')
->where('vlaninterface.rsclient', 1 )
->where('vlaninterface.irrdbfilter', 1 )
->groupBy('custid')
->orderBy('custid')
->pluck('custid');


// using the above, get these customers details and update log for the table:
$customers_logs = Customer::whereIn('id', $custids)

Check failure on line 73 in app/Http/Controllers/Irrdb/IrrdbController.php

View workflow job for this annotation

GitHub Actions / ci-ex-dusk

UndefinedMagicMethod

app/Http/Controllers/Irrdb/IrrdbController.php:73:27: UndefinedMagicMethod: Magic method IXP\Models\Customer::wherein does not exist (see https://psalm.dev/219)
->select('id', 'name', 'autsys', 'abbreviatedName')
->with('irrdbUpdateLog')
->get();

return view( 'irrdb/summary', [
'customers_logs' => $customers_logs,
] );

}

/**
* Display the list of IRRDB (ASN/Prefix), (IPv4/IPv6) for a customer
*
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ public function virtualInterfaces(): HasMany
return $this->hasMany(VirtualInterface::class, 'custid');
}

/**
* Get the virtual interfaces for the customer
*/
public function irrdbUpdateLog(): Hasone
{
return $this->hasOne(IrrdbUpdateLog::class, 'cust_id');
}



/**
* Get the peers for the customer
*/
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions resources/views/irrdb/js/summary.foil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script>
let tableList = $( '#ixpDataTable' );
tableList.dataTable({
stateSave: true,
stateDuration : DATATABLE_STATE_DURATION,
"aLengthMenu": [[20, 50, 100, 500, -1], [20, 50, 100, 500, "All"]],
"bAutoWidth": false,
"aaSorting": [[0, 'asc']],
"iDisplayLength": 100,
});
$(document).ready(function() {
tableList.show();
});
</script>
116 changes: 116 additions & 0 deletions resources/views/irrdb/summary.foil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/** @var Foil\Template\Template $t */
$this->layout( 'layouts/ixpv4' )
?>

<?php $this->section( 'page-header-preamble' ) ?>
IRRDB Summary
<?php $this->append() ?>

<?php $this->section( 'page-header-postamble' ) ?>
<div class="btn-group btn-group-sm ml-auto" role="group">
<a target="_blank" class="btn btn-white" href="https://docs.ixpmanager.org/latest/features/irrdb/">
Documentation
</a>
</div>
<?php $this->append() ?>

<?php $this->section( 'content' ) ?>

<div class="alert alert-info mt-4 mb-4" role="alert">
This page shows the last update times of each <?= config( 'ixp_fe.lang.customer.many' ) ?> IRRDB entries.
Entries are considered stale if they have not been updated in the last 24 hours.
</div>


<div class="row">
<div class="col-sm-12">
<?= $t->alerts() ?>

<table id="ixpDataTable" class="table table-striped table-bordered collapse" style="width:100%">
<thead class="thead-dark">
<tr>
<th><?= ucfirst( config( 'ixp_fe.lang.customer.one' ) ) ?></th>
<th class="tw-text-center">V4 Prefixes</th>
<th class="tw-text-center">V6 Prefixes</th>
<th class="tw-text-center">V4 ASNs</th>
<th class="tw-text-center">V6 ASNs</th>
</tr>
</thead>
<tbody>

<?php foreach( $t->customers_logs as $c ): ?>
<tr>
<td data-sort="<?= $c->abbreviatedName ?>">
<a href="<?= route( 'customer@overview', [ 'cust' => $c->id ] ) ?>">
<?= $c->abbreviatedName ?> (AS<?= $c->autsys ?>)
</a>
</td>

<?php foreach( [ 'prefix_v4', 'prefix_v6', 'asn_v4', 'asn_v6' ] as $type ): ?>

<td class="tw-text-center"
data-sort="<?= !$c->isIPvXEnabled( substr( $type, -1 ) ) ? -1000 : $c?->irrdbUpdateLog?->$type?->timestamp ?? 0 ?>">

<?php if( !$c->isIPvXEnabled( substr( $type, -1 ) ) ): ?>

<a class="badge badge-secondary">n/a</a>

<?php else: ?>

<?php if( $c->irrdbUpdateLog === null || $c->irrdbUpdateLog->$type === null ): ?>

<a class="badge badge-danger"
href="<?= route( 'irrdb@list', [
'cust' => $c,
'type' => str_starts_with( $type, 'prefix' ) ? 'prefix' : 'asn',
'protocol' => str_ends_with( $type, '4' ) ? '4' : '6',
] ) ?>"
>NEVER</a>

<?php else: ?>

<span class="tw-tabular-nums" title="<?= $c->irrdbUpdateLog->$type->format('Y-m-d H:i') ?>">
<?= $c->irrdbUpdateLog->$type->diffForHumans() ?>
</span>

<?php if( $c->irrdbUpdateLog->$type->isBefore( now()->subDay() ) ): ?>

<a class="badge badge-warning"
href="<?= route( 'irrdb@list', [
'cust' => $c,
'type' => str_starts_with( $type, 'prefix' ) ? 'prefix' : 'asn',
'protocol' => str_ends_with( $type, '4' ) ? '4' : '6',
] ) ?>"
>STALE</a>

<?php else: ?>

<a href="<?= route( 'irrdb@list', [
'cust' => $c,
'type' => str_starts_with( $type, 'prefix' ) ? 'prefix' : 'asn',
'protocol' => str_ends_with( $type, '4' ) ? '4' : '6',
] ) ?>" <i class="ml-2 fa fa-arrow-circle-o-right"></i></a>

<?php endif; ?>

<?php endif; ?>

<?php endif; ?>

</td>

<?php endforeach; ?>

</tr>
<?php endforeach; ?>
</tbody>
</table>

</div>
</div>
<?php $this->append() ?>

<?php $this->section( 'scripts' ) ?>
<?= $t->insert( 'irrdb/js/summary' ); ?>
<?php $this->append() ?>
19 changes: 16 additions & 3 deletions resources/views/layouts/menu.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,25 @@
</ul>
<?php endif; ?>

<li class=" <?= !request()->is( 'irrdb-config/*' ) ?: 'active' ?>">
<a href="<?= route( 'irrdb-config@list' ) ?>" class="nav-link">
IRRDB Configuration

<li>
<a href="<?= route( 'irrdb@summary' ) ?>" class="nav-link">
IRRDB Summary
</a>
</li>

<?php if( request()->is( 'irrdb-config*' ) ): ?>
<ul>
<li class="nav-sub-menu-item <?= !request()->is( 'irrdb-config/*' ) ?: 'active' ?>">
<a href="<?= route( 'irrdb-config@list' ) ?>">
IRRDB Configuration
</a>
</li>
</ul>
<?php endif; ?>



<li>
<a href="<?= route( 'layer2-address@list' ) ?>" class="nav-link">
MAC Addresses
Expand Down
9 changes: 9 additions & 0 deletions routes/web-auth-superuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@
Route::get( 'rs-filters/list-customers', 'RsFilterController@listCustomers' )->name( 'rs-filters@list-customers' );


/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// IRRDB
///

Route::get( 'irrdb/summary', 'Irrdb\IrrdbController@summary' )->name( 'irrdb@summary' );





Expand Down
2 changes: 1 addition & 1 deletion routes/web-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
///
/// IRRDB
///
Route::group( [ 'prefix' => 'irrdb' ], function() {
Route::group( [ 'namespace' => 'Irrdb', 'prefix' => 'irrdb' ], function() {
Route::get( 'customer/{cust}/{type}/{protocol}', 'IrrdbController@list' )->name( 'irrdb@list' );
Route::get( 'update/{cust}/{type}/{protocol}', 'IrrdbController@update' )->name( 'irrdb@update' );
});
Expand Down
2 changes: 1 addition & 1 deletion routes/web-eloquent2frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
IXP\Http\Controllers\CustKitController::routes();
IXP\Http\Controllers\Customer\CustomerTagController::routes();
IXP\Http\Controllers\InfrastructureController::routes();
IXP\Http\Controllers\IrrdbConfigController::routes();
IXP\Http\Controllers\Irrdb\IrrdbConfigController::routes();
IXP\Http\Controllers\Layer2AddressController::routes();
IXP\Http\Controllers\LocationController::routes();
IXP\Http\Controllers\LoginHistoryController::routes();
Expand Down

0 comments on commit d594cd3

Please sign in to comment.