Skip to content

Commit

Permalink
IRRDB last updated on member overview
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Aug 11, 2024
1 parent c555e2b commit 13f89cf
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,8 @@ public function irrdbFiltered(): bool
{
return (bool)self::leftJoin( 'virtualinterface AS vi', 'vi.custid', 'cust.id' )
->leftJoin( 'vlaninterface AS vli', 'vli.virtualinterfaceid', 'vi.id' )
->where( 'cust.id', $this->id )->where( 'irrdbfilter', true )
->where( 'cust.id', $this->id )->where( 'rsclient', true )
->where( 'irrdbfilter', true )
->get()->count();
}

Expand Down
76 changes: 72 additions & 4 deletions app/Models/IrrdbUpdateLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace IXP\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
Expand All @@ -12,10 +13,10 @@
* @method static \Illuminate\Database\Eloquent\Builder|IrrdbUpdateLog query()
* @property int $id
* @property int $cust_id
* @property string|null $prefix_v4
* @property string|null $prefix_v6
* @property string|null $asn_v4
* @property string|null $asn_v6
* @property \Illuminate\Support\Carbon|null $prefix_v4
* @property \Illuminate\Support\Carbon|null $prefix_v6
* @property \Illuminate\Support\Carbon|null $asn_v4
* @property \Illuminate\Support\Carbon|null $asn_v6
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|IrrdbUpdateLog whereAsnV4($value)
Expand Down Expand Up @@ -44,4 +45,71 @@ class IrrdbUpdateLog extends Model
'asn_v6',
];


/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'prefix_v4' => 'datetime',
'prefix_v6' => 'datetime',
'asn_v4' => 'datetime',
'asn_v6' => 'datetime',
];
}

/**
* Find the /oldest/ /relevant/ last update:
*
* - oldest: will be null if never updated
* - relevant: if customer is not v6 enabled, ignore these fields
*
* @param Customer $c
* @return Carbon
*/
public static function lastUpdatedMax( Customer $c ): ?Carbon
{
/** @var IrrdbUpdateLog $log */
$log = self::firstWhere('cust_id', $c->id);

if( !$log || !$c->irrdbFiltered() ) {
return null;
}

$oldest = null;

if( $c->isIPvXEnabled(4) ) {
if( !$oldest && $log->prefix_v4 ) {
$oldest = $log->prefix_v4;
} else if( $oldest && $oldest > $log->prefix_v4 ) {
$oldest = $log->prefix_v4;
}

if( !$oldest && $log->asn_v4 ) {
$oldest = $log->asn_v4;
} else if( $oldest && $oldest > $log->asn_v4 ) {
$oldest = $log->asn_v4;
}
}

if( $c->isIPvXEnabled(6) ) {
if( !$oldest && $log->prefix_v6 ) {
$oldest = $log->prefix_v6;
} else if( $oldest && $oldest > $log->prefix_v6 ) {
$oldest = $log->prefix_v6;
}

if( !$oldest && $log->asn_v6 ) {
$oldest = $log->asn_v6;
} else if( $oldest && $oldest > $log->asn_v6 ) {
$oldest = $log->asn_v6;
}
}

return $oldest;
}

}
15 changes: 14 additions & 1 deletion public/css/ixp-pack.css
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ td a:hover{
*
* @import "tailwindcss/preflight";
*/
/*! tailwindcss v3.4.7 | MIT License | https://tailwindcss.com
/*! tailwindcss v3.4.9 | MIT License | https://tailwindcss.com
*/
/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
Expand Down Expand Up @@ -4417,6 +4417,9 @@ a:hover {
.tw-flex {
display: flex;
}
.tw-inline-flex {
display: inline-flex;
}
.tw-hidden {
display: none;
}
Expand Down Expand Up @@ -4606,6 +4609,10 @@ a:hover {
padding-left: 2.5rem;
padding-right: 2.5rem;
}
.tw-px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.tw-px-3 {
padding-left: 0.75rem;
padding-right: 0.75rem;
Expand Down Expand Up @@ -4706,6 +4713,9 @@ a:hover {
.tw-font-bold {
font-weight: 700;
}
.tw-font-medium {
font-weight: 500;
}
.tw-font-normal {
font-weight: 400;
}
Expand Down Expand Up @@ -4814,6 +4824,9 @@ a:hover {
--tw-shadow-colored: 0 4px 8px 0 var(--tw-shadow-color), 0 2px 4px 0 var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.tw-ring-yellow-600\/20 {
--tw-ring-color: rgb(214 158 46 / 0.2);
}
.\[a-f0-9\:\\\.\\-\] {
a-f0-9: \.\-;
}
Expand Down
15 changes: 14 additions & 1 deletion public/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @import "tailwindcss/preflight";
*/
/*! tailwindcss v3.4.7 | MIT License | https://tailwindcss.com
/*! tailwindcss v3.4.9 | MIT License | https://tailwindcss.com
*/
/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
Expand Down Expand Up @@ -1118,6 +1118,9 @@ a:hover {
.tw-flex {
display: flex;
}
.tw-inline-flex {
display: inline-flex;
}
.tw-hidden {
display: none;
}
Expand Down Expand Up @@ -1307,6 +1310,10 @@ a:hover {
padding-left: 2.5rem;
padding-right: 2.5rem;
}
.tw-px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.tw-px-3 {
padding-left: 0.75rem;
padding-right: 0.75rem;
Expand Down Expand Up @@ -1407,6 +1414,9 @@ a:hover {
.tw-font-bold {
font-weight: 700;
}
.tw-font-medium {
font-weight: 500;
}
.tw-font-normal {
font-weight: 400;
}
Expand Down Expand Up @@ -1515,6 +1525,9 @@ a:hover {
--tw-shadow-colored: 0 4px 8px 0 var(--tw-shadow-color), 0 2px 4px 0 var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.tw-ring-yellow-600\/20 {
--tw-ring-color: rgb(214 158 46 / 0.2);
}
.\[a-f0-9\:\\\.\\-\] {
a-f0-9: \.\-;
}
Expand Down
4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"/css/tailwind.css": "/css/tailwind.css?id=36c5dc0854a90855bacbdf77cb4d91fb",
"/css/tailwind.css": "/css/tailwind.css?id=869de96c060a52baebfdf0a41c343ea9",
"/js/ixp-pack.js": "/js/ixp-pack.js?id=ec1db54aba350f56e45c1c8297dd62d7",
"/css/ixp-pack.css": "/css/ixp-pack.css?id=27c9999fbdb5d8e52ad36e151eb8a2e8",
"/css/ixp-pack.css": "/css/ixp-pack.css?id=2e976369d67ec2c99b81e9c105b4e740",
"/fonts/FontAwesome.otf": "/fonts/FontAwesome.otf?id=663236d7aa447620b641032d1b7be57c",
"/fonts/fontawesome-webfont.eot": "/fonts/fontawesome-webfont.eot?id=016fa45033a942ffecadc970f22fe41b",
"/fonts/fontawesome-webfont.svg": "/fonts/fontawesome-webfont.svg?id=912ec66d7572ff821749319396470bde",
Expand Down
28 changes: 25 additions & 3 deletions resources/views/customer/overview-tabs/overview.foil.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
$c = $t->c; /** @var \IXP\Models\Customer $c */

use IXP\Models\IrrdbUpdateLog;

$c = $t->c; /** @var \IXP\Models\Customer $c */
?>
<div class="d-flex row">
<div class="col-sm-12">
Expand Down Expand Up @@ -94,11 +97,30 @@
<b>IRRDB</b>
</td>
<td>
<?php if( $irrdb = $c->irrdbConfig ): ?>
<?php if( $c->irrdbFiltered() && $irrdb = $c->irrdbConfig ): ?>
<?= $t->ee( $irrdb->source )?>
<?php if( $c->routeServerClient() && $c->irrdbFiltered() ): ?>
(<a href="<?= route( "irrdb@list", [ "cust" => $c->id, "type" => 'prefix', "protocol" => $c->isIPvXEnabled( 4) ? 4 : 6 ] ) ?>">entries</a>)
(<a href="<?= route( "irrdb@list", [ "cust" => $c->id, "type" => 'prefix', "protocol" => $c->isIPvXEnabled( 4) ? 4 : 6 ] ) ?>">entries</a>)<br>

<?php
$lastUpdatedWarn = false;
if( $lastUpdated = IrrdbUpdateLog::lastUpdatedMax($c) ) {
if( $lastUpdated->isBefore( now()->subDay() ) ) {
$lastUpdatedWarn = true;
}
$lastUpdated = $lastUpdated->format('Y-m-d H:i');
} else {
$lastUpdatedWarn = true;
$lastUpdated = 'NEVER';
}
?>
Last updated:
<?= $lastUpdatedWarn ? '<span class="tw-inline-flex tw-items-center tw-rounded-md tw-ml-2 tw-px-2 tw-py-1 tw-text-xs tw-font-medium tw-bg-yellow-50 -text-yellow-800 tw-ring-yellow-600/20">' : '' ?>
<?= $lastUpdated ?>
<?= $lastUpdatedWarn ? '</span>' : '' ?>
<?php endif; ?>
<?php else: ?>
<em>(no IRRDB filtering)</em>
<?php endif; ?>
</td>
</tr>
Expand Down

0 comments on commit 13f89cf

Please sign in to comment.