123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- //-
- // Copyright (c) 2011-2017 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';
- require_once 'Log.php';
- require_once 'functions.php';
- $dsn = "$db_driver:host=$db_host;dbname=$db_name";
- $options = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- try {
- $dbh = new PDO($dsn, $db_user, $db_pass, $options);
- } catch (PDOException $e) {
- die($e->getMessage());
- }
- $logger = Log::singleton('file', LOGFILE, TOOL_NAME . ' : Port Profiles');
- if ($logger === false) {
- die("Failed to open logfile.\n");
- }
- $mask = Log::MAX(LOG_LEVEL);
- $logger->setMask($mask);
- $base = get_base($_SERVER['SCRIPT_NAME']);
- $ruser = '<AUTHENTICATION NOT ENABLED>';
- if (isset($_SERVER['REMOTE_USER'])) {
- $ruser = $_SERVER['REMOTE_USER'];
- }
- $errors = array();
- if (isset($_REQUEST['submit'])) {
- $d = $_REQUEST['delete'];
- foreach ($d as $profile => $value) {
- if ($value == 1) {
- $sql = "DELETE FROM EXCEPTIONS WHERE name=:name";
- try {
- $sth = $dbh->prepare($sql);
- $sth->execute(['name' => $profile]);
- $sth->closeCursor();
- unlink(PORT_PROFILE_DIR . "/{$profile}.tmpl");
- $logger->info("User {$ruser} deleted port profile {$profile}");
- } catch (PDOException $e) {
- array_push($errors, "Failed to delete {$profile}: {$e->getMessage()}");
- }
- }
- }
- }
- $wc = '';
- $params = null;
- if (isset($_REQUEST['filter'])) {
- if ($_REQUEST['filter'] != 'All') {
- $wc = " WHERE pid = :pid";
- $params = ['pid' => $_REQUEST['filter']];
- }
- }
- $sql = 'SELECT EXCEPTIONS.* FROM EXCEPTIONS ' . $wc . ' ORDER BY name';
- if (isset($_REQUEST['profile_name'])) {
- $sql = "SELECT * FROM EXCEPTIONS WHERE name LIKE :name ORDER BY name";
- $params = ['name' => "%{$_REQUEST['profile_name']}%"];
- }
- $res = null;
- try {
- $res = $dbh->prepare($sql);
- $res->execute($params);
- } catch (PDOException $e) {
- echo "<p><font color=\"red\">Error querying for port profiles: {$e->getMessage()}</font></p>\r\n";
- exit(1);
- }
- $profiles = array();
- while ($row = $res->fetch()) {
- array_push($profiles, $row);
- }
- $filter = '';
- if (isset($_REQUEST['filter'])) {
- $filter = $_REQUEST['filter'];
- }
- print_header(TOOL_NAME . ': Port Profiles');
- ?>
- <body class="flex">
- <script language="javascript">
- var deletes = 0;
- $(document).ready(function () {
- $('#devtable').DataTable({
- "scrollY": "400px",
- "scrollCollapse": true,
- "paging": false
- });
- });
- </script>
- <div id="headswreg">
- <div class="apage">
- <div id="header">
- <h1>
- <?= TOOL_NAME ?>: Port Profiles
- </h1>
- </div>
- <br />
- </div>
- </div>
- <div class="apage">
- <form method="POST" name="search_form" action="<?= $_SERVER['PHP_SELF'] ?>">
- <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" <?= ($filter == 'All') ? 'selected' : '' ?>>All
- </option>
- <option value="<?= $_SERVER['PHP_SELF'] ?>?filter=__ANY__" <?= ($filter == '__ANY__') ? 'selected' : '' ?>>
- Any
- Switch</option>
- <?php
- foreach ($ZTP_PIDS as $spid) {
- $selected = ($filter == "$spid") ? 'selected' : ''; ?>
- <option value="<?= $_SERVER['PHP_SELF'] ?>?filter=<?= $spid ?>" <?= $selected ?>>
- <?= $spid ?>
- </option>
- <?php
- }
- ?>
- </select>
- </td>
- <td class="right">Profile Search:
- <input type="text" size="16" name="profile_name"
- value="<?= (isset($_REQUEST['profile_name'])) ? $_REQUEST['profile_name'] : '' ?>">
- <input type="image" value="Submit" name="search" src="/images/submit_button.png">
- </td>
- </tr>
- </table>
- </form>
- <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?"); }'>
- <?php
- foreach (array_merge($_GET, $_POST) as $name => $value) {
- ?>
- <input type="hidden" name="<?= $name ?>" value="<?= $value ?>">
- <?php
- }
- ?>
- <div class="fbtable">
- <table summary="Button Table" width="100%" cellspacing="0">
- <tr>
- <td><input type="reset" value="Reset" name="reset">
- <input type="submit" value="Submit" name="submit">
- </td>
- </tr>
- </table>
- </div>
- <br />
- <div align="center">
- <?php
- foreach ($errors as $error) {
- ?>
- <p class="error">
- <?= $error ?>
- </p>
- <?php
- }
- ?>
- </div>
- <div class="fulltable">
- <table id="devtable" class="display compact" width="100%" cellspacing="0" summary="Port Profile Table">
- <thead>
- <tr>
- <th class="headlink">Row No.</th>
- <th class="headlink">Delete?</th>
- <th class="headlink">Name</th>
- <th class="headlink">Product ID</th>
- <th class="headlink">File Name</th>
- <th class="headlink">View</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $i = 0;
- foreach ($profiles as $row) {
- $name = $row['name']; ?>
- <tr>
- <td>
- <?= $i + 1 ?>.
- </td>
- <td><input type="checkbox" name="delete[<?= $name ?>]" value="1"
- onClick="if (this.checked == true) { deletes++; } else { deletes--; }"></td>
- <td>
- <?= $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;
- }
- ?>
- </tbody>
- </table>
- </div>
- <br />
- <div class="fbtable">
- <table width="100%" cellspacing="0" summary="Button Table">
- <tr>
- <td><input type="reset" value="Reset" name="reset">
- <input type="submit" value="Submit" name="submit">
- </td>
- </tr>
- </table>
- </div>
- </form>
- </div>
- </body>
- </html>
- <?php
- cleanup();
- ?>
|