123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- #-
- # Copyright (c) 2011-2015 Joe Clarke <jclarke@cisco.com>
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions
- # are met:
- # 1. Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- # 2. Redistributions in binary form must reproduce the above copyright
- # notice, this list of conditions and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- #
- # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- # SUCH DAMAGE.
- #
- #
- include_once 'db.inc.php';
- include_once 'swreg/swreg.inc.php';
- include_once 'swreg_web.inc.php';
- require_once 'MDB2.php';
- require_once 'Log.php';
- require_once 'functions.php';
- $dsn = "mysql://$db_user:$db_pass@$db_host/$db_name";
- $options = array('result_buffering', false);
- $dbh = MDB2::factory($dsn, $options);
- if (PEAR::isError($dbh)) {
- die($dbh->getMessage());
- }
- $dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
- $logger = Log::singleton('file', LOGFILE, TOOL_NAME . ' : Port Profiles');
- if ($logger === FALSE) {
- die("Failed to open logfile.\n");
- }
- $mask = Log::UPTO(LOG_LEVEL);
- $logger->setMask($mask);
- $base = get_base($_SERVER['SCRIPT_NAME']);
- $errors = array();
- if (isset($_REQUEST['submit'])) {
- $d = $_REQUEST['delete'];
- foreach ($d as $profile => $value) {
- if ($value == 1) {
- $sql = "DELETE FROM EXCEPTIONS WHERE name='{$profile}'";
- $res = $dbh->query($sql);
- if (PEAR::isError($res)) {
- array_push($errors, "Failed to delete {$profile}: {$res->getUserInfo()}");
- } else {
- unlink(TFTPBOOT . "/{$profile}.tmpl");
- $logger->info("User {$_SERVER['REMOTE_USER']} deleted port profile {$profile}");
- }
- }
- }
- }
- $wc = '';
- if (isset($_REQUEST['filter'])) {
- if ($_REQUEST['filter'] != "All") {
- $wc = " WHERE pid = '{$_REQUEST['filter']}'";
- }
- }
- $sql = 'SELECT EXCEPTIONS.* FROM EXCEPTIONS ' . $wc . ' ORDER BY name';
- if (isset($_REQUEST['profile_name'])) {
- $sql = "SELECT * FROM EXCEPTIONS WHERE name LIKE '%{$_REQUEST['profile_name']}%' ORDER BY name";
- }
- $res = $dbh->query($sql);
- if (PEAR::isError($res)) {
- echo "<p><font color=\"red\">Error querying for port profiles: {$res->getUserInfo()}</font></p>\r\n";
- exit(1);
- }
- $profiles = array();
- while ($row = $res->fetchRow()) {
- array_push($profiles, $row);
- }
- print_header(TOOL_NAME . ": Port Profiles");
- ?>
- <script language="javascript">
- var deletes = 0;
- </script>
- <body class="flex">
- <div id="headswreg">
- <div class="apage">
- <div id="header">
- <h1><?=TOOL_NAME?>: Port Profiles</h1>
- </div>
- <br/>
- <div>
- Total Port Profiles Displayed: <b><?=count($profiles)?></b>
- </div>
- </div>
- </div>
- <div class="apage">
- <table class="noborder" summary="Filter Table">
- <tr>
- <td class="left_act">Show Only Port Profiles For:
- <select name="filter" onChange="MM_jumpMenu('parent', this, 0)">
- <option value="<?=$_SERVER['PHP_SELF']?>?filter=All" <?=($_REQUEST['filter'] == 'All') ? 'selected' : ''?>>All</option>
- <option value="<?=$_SERVER['PHP_SELF']?>?filter=__ANY__" <?=($_REQUEST['filter'] == '__ANY__') ? 'selected' : ''?>>Any Switch</option>
- <?php
- foreach ($ZTP_PIDS as $spid) {
- $selected = ($_REQUEST['filter'] == "$spid") ? 'selected' : '';
- ?>
- <option value="<?=$_SERVER['PHP_SELF']?>?filter=<?=$spid?>" <?=$selected?>><?=$spid?></option>
- <?php
- }
- ?>
- </select>
- </td>
- <form method="POST" name="search_form" action="<?=$_SERVER['PHP_SELF']?>">
- <td class="right">Profile Search:
- <input type="text" size="16" name="profile_name" value="<?=$_REQUEST['profile_name']?>">
- <input type="image" value="Submit" name="search" src="/images/submit_button.png">
- </td>
- </form>
- </tr>
- </table>
- <br/>
- <table class="noborder" summary="Control Table">
- <tr>
- <td class="left"><a href="<?=$base?>/add_port_profile.php">Add Port Profile</a> |
- <a href="<?=$base?>/logicsw.php">Logical Switches</a></td>
- </tr>
- </table>
- <form name="mod_port_profile_form" method="POST" action="<?=$_SERVER['PHP_SELF']?>" onSubmit='if (deletes > 0) { return confirm("Are you sure you want to delete these port profiles?"); }'>
- <table class="swreg" summary="Button Table" class="full">
- <tr>
- <td><input type="reset" value="Reset" name="reset">
- <input type="submit" value="Submit" name="submit"></td>
- </tr>
- </table>
- <br/>
- <div align="center">
- <?php
- foreach ($errors as $error) {
- ?>
- <p class="error"><?=$error?></p>
- <?php
- }
- ?>
- </div>
- <table class="swreg" summary="Port Profile Table" class="full">
- <tr>
- <th class="delete">Row No.</th>
- <th class="delete">Delete?</td>
- <th class="headlink">Name</th>
- <th class="headlink">Product ID</th>
- <th class="headlink">File Name</th>
- <th class="headlink">View</th>
- </tr>
- <?php
- foreach (array_merge($_GET, $_POST) as $name => $value) {
- ?>
- <input type="hidden" name="<?=$name?>" value="<?=$value?>">
- <?php
- }
- $i = 0;
- foreach ($profiles as $row) {
- $name = $row['name'];
- ?>
- <tr <?=get_row_color($i)?>>
- <td><?=$i + 1?>.</td>
- <td><input type="checkbox" name="delete[<?=$name?>]" value="1" onClick="if (this.checked == true) { deletes++; } else { deletes--; }"></td>
- <td class="wide"><?=$name?></td>
- <td><?=$row['pid']?></td>
- <td><?=$row['path']?></td>
- <td><a href="#" onClick='window.open("<?=$base?>/show_config.php?type=profile&cfg=<?=$row['path']?>&dname=<?=$row['name']?>", "Config for profile <?=$row['name']?>", "height=650,width=980"); return false;'>View</a></td>
- </tr>
- <?php
- $i++;
- }
- ?>
- </table>
- <br/>
- <table class="swreg" summary="Button Table" class="full">
- <tr>
- <td><input type="reset" value="Reset" name="reset">
- <input type="submit" value="Submit" name="submit"></td>
- </tr>
- </table>
- </form>
- </div>
- </body>
- </html>
- <?php
- cleanup();
- ?>
|