Skip to content

Commit

Permalink
[NF] Update OUI database from named file or IEEE website - for issue #87
Browse files Browse the repository at this point in the history


Typically called as:

    bin/ixptool.php -a oui-cli.update-database

which will create / update the OUI database directly from the latest IEEE file from their website.

A specific file can be passed via the `fromfile` parameter. You can also force a
database reset (drop all OUI entries and re-populate) via the `refresh` parameter.

Neither of these options are typically necessary:

    bin/ixptool.php -a oui-cli.update-database -p fromfile=/path/to/oui.txt,refresh=1

Note that we bundle a recent OUI file in `date/oui` also.
  • Loading branch information
barryo committed Feb 17, 2014
1 parent ecfe124 commit 641c7eb
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions application/controllers/OuiCliController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* Copyright (C) 2009-2014 Internet Neutral Exchange Association Limited.
* 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
*/


/**
* Controller: OUI CLI Actions
*
* @author Barry O'Donovan <barry@opensolutions.ie>
* @category IXP
* @package IXP_Controller
* @copyright Copyright (c) 2009 - 2014, Internet Neutral Exchange Association Ltd
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
*/
class OuiCliController extends IXP_Controller_CliAction
{
public function updateDatabaseAction()
{
$ouitool = new IXP_OUI( $this->getParam( 'fromfile', false ) );

$ouiRepo = $this->getD2R( '\\Entities\OUI' );

$this->getD2EM()->getConnection()->beginTransaction();

if( $refresh = $this->getParam( 'refresh', false ) )
$ouiRepo->clear();

foreach( $ouitool->loadList()->processRawData() as $oui => $organisation )
{
if( !$refresh && ( $o = $ouiRepo->findOneBy( [ 'oui' => $oui ] ) ) )
{
if( $o->getOrganisation() != $organisation )
$o->setOrganisation( $organisation );
continue;
}

$o = new \Entities\OUI;
$o->setOui( $oui );
$o->setOrganisation( $organisation );
$this->getD2EM()->persist( $o );
}

$this->getD2EM()->flush();
}

}

0 comments on commit 641c7eb

Please sign in to comment.