|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland |
| 5 | + All rights reserved. |
| 6 | +
|
| 7 | + This file is part of the NOCtools package. |
| 8 | +
|
| 9 | + Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie |
| 10 | + http://www.opensolutions.ie/ |
| 11 | +
|
| 12 | + Redistribution and use in source and binary forms, with or without |
| 13 | + modification, are permitted provided that the following conditions are met: |
| 14 | +
|
| 15 | + * Redistributions of source code must retain the above copyright |
| 16 | + notice, this list of conditions and the following disclaimer. |
| 17 | + * Redistributions in binary form must reproduce the above copyright |
| 18 | + notice, this list of conditions and the following disclaimer in the |
| 19 | + documentation and/or other materials provided with the distribution. |
| 20 | + * Neither the name of Open Source Solutions Limited nor the |
| 21 | + names of its contributors may be used to endorse or promote products |
| 22 | + derived from this software without specific prior written permission. |
| 23 | +
|
| 24 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 25 | + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 26 | + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 | + DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 28 | + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 | + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 31 | + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 | + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | +*/ |
| 35 | + |
| 36 | +/** |
| 37 | + * StpController |
| 38 | + * |
| 39 | + * @author Barry O'Donovan <[email protected]> |
| 40 | + */ |
| 41 | + |
| 42 | +class StpController extends OSS_Controller_Action |
| 43 | +{ |
| 44 | + |
| 45 | + /** |
| 46 | + * The default action - show the home page |
| 47 | + */ |
| 48 | + public function indexAction() |
| 49 | + { |
| 50 | + } |
| 51 | + |
| 52 | + public function rstpPortRolesAction() |
| 53 | + { |
| 54 | + if( $this->getRequest()->isPost() ) |
| 55 | + { |
| 56 | + $this->view->rstpPortRolesDevice = $device = $this->_getParam( 'rstpPortRolesDevice' ); |
| 57 | + $this->view->limitToVlan = $limitToVlan = $this->_getParam( 'limitToVlan', false ); |
| 58 | + |
| 59 | + try |
| 60 | + { |
| 61 | + $host = new \OSS\SNMP( $device, $this->_options['community'] ); |
| 62 | + $vlans = $host->useCisco_VTP()->vlanNames(); |
| 63 | + } |
| 64 | + catch( \OSS\Exception $e ) |
| 65 | + { |
| 66 | + $this->addMessage( "Could not query VLAN and port role information via SNMP from " . $device, OSS_Message::ERROR ); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + $roles = array(); |
| 71 | + $unknowns = array(); |
| 72 | + $portsInRSTP = array(); |
| 73 | + |
| 74 | + if( $limitToVlan && isset( $vlans[ $limitToVlan ] ) ) |
| 75 | + { |
| 76 | + $name = $vlans[ $limitToVlan ]; |
| 77 | + unset( $vlans ); |
| 78 | + $vlans = [ $limitToVlan => $name ]; |
| 79 | + } |
| 80 | + |
| 81 | + foreach( $vlans as $vid => $vname ) |
| 82 | + { |
| 83 | + try |
| 84 | + { |
| 85 | + $roles[ $vid ] = $host->useCisco_RSTP()->rstpPortRole( $vid, true ); |
| 86 | + |
| 87 | + foreach( $roles[ $vid ] as $portId => $role ) |
| 88 | + if( !isset( $portsInRSTP[ $portId ] ) ) |
| 89 | + $portsInRSTP[ $portId ] = $portId; |
| 90 | + } |
| 91 | + catch( \OSS\Exception $e ) |
| 92 | + { |
| 93 | + $unknowns[ $vid ] = $vname; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + ksort( $portsInRSTP, SORT_NUMERIC ); |
| 98 | + $this->view->portsInRSTP = $portsInRSTP; |
| 99 | + $this->view->ports = $host->useIface()->names(); |
| 100 | + $this->view->vlans = $vlans; |
| 101 | + $this->view->roles = $roles; |
| 102 | + $this->view->unknowns = unknowns; |
| 103 | + |
| 104 | + unset( $host ); |
| 105 | + } |
| 106 | + |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments