port_profiles.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. #-
  3. # Copyright (c) 2011-2015 Joe Clarke <jclarke@cisco.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. #
  27. #
  28. include_once 'db.inc.php';
  29. include_once 'swreg/swreg.inc.php';
  30. include_once 'swreg_web.inc.php';
  31. require_once 'MDB2.php';
  32. require_once 'Log.php';
  33. require_once 'functions.php';
  34. $dsn = "mysql://$db_user:$db_pass@$db_host/$db_name";
  35. $options = array('result_buffering', false);
  36. $dbh = MDB2::factory($dsn, $options);
  37. if (PEAR::isError($dbh)) {
  38. die($dbh->getMessage());
  39. }
  40. $dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
  41. $logger = Log::singleton('file', LOGFILE, TOOL_NAME . ' : Port Profiles');
  42. if ($logger === FALSE) {
  43. die("Failed to open logfile.\n");
  44. }
  45. $mask = Log::UPTO(LOG_LEVEL);
  46. $logger->setMask($mask);
  47. $base = get_base($_SERVER['SCRIPT_NAME']);
  48. $errors = array();
  49. if (isset($_REQUEST['submit'])) {
  50. $d = $_REQUEST['delete'];
  51. foreach ($d as $profile => $value) {
  52. if ($value == 1) {
  53. $sql = "DELETE FROM EXCEPTIONS WHERE name='{$profile}'";
  54. $res = $dbh->query($sql);
  55. if (PEAR::isError($res)) {
  56. array_push($errors, "Failed to delete {$profile}: {$res->getUserInfo()}");
  57. } else {
  58. unlink(TFTPBOOT . "/{$profile}.tmpl");
  59. $logger->info("User {$_SERVER['REMOTE_USER']} deleted port profile {$profile}");
  60. }
  61. }
  62. }
  63. }
  64. $wc = '';
  65. if (isset($_REQUEST['filter'])) {
  66. if ($_REQUEST['filter'] != "All") {
  67. $wc = " WHERE pid = '{$_REQUEST['filter']}'";
  68. }
  69. }
  70. $sql = 'SELECT EXCEPTIONS.* FROM EXCEPTIONS ' . $wc . ' ORDER BY name';
  71. if (isset($_REQUEST['profile_name'])) {
  72. $sql = "SELECT * FROM EXCEPTIONS WHERE name LIKE '%{$_REQUEST['profile_name']}%' ORDER BY name";
  73. }
  74. $res = $dbh->query($sql);
  75. if (PEAR::isError($res)) {
  76. echo "<p><font color=\"red\">Error querying for port profiles: {$res->getUserInfo()}</font></p>\r\n";
  77. exit(1);
  78. }
  79. $profiles = array();
  80. while ($row = $res->fetchRow()) {
  81. array_push($profiles, $row);
  82. }
  83. print_header(TOOL_NAME . ": Port Profiles");
  84. ?>
  85. <script language="javascript">
  86. var deletes = 0;
  87. </script>
  88. <body class="flex">
  89. <div id="headswreg">
  90. <div class="apage">
  91. <div id="header">
  92. <h1><?=TOOL_NAME?>: Port Profiles</h1>
  93. </div>
  94. <br/>
  95. <div>
  96. Total Port Profiles Displayed: <b><?=count($profiles)?></b>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="apage">
  101. <table class="noborder" summary="Filter Table">
  102. <tr>
  103. <td class="left_act">Show Only Port Profiles For:
  104. <select name="filter" onChange="MM_jumpMenu('parent', this, 0)">
  105. <option value="<?=$_SERVER['PHP_SELF']?>?filter=All" <?=($_REQUEST['filter'] == 'All') ? 'selected' : ''?>>All</option>
  106. <option value="<?=$_SERVER['PHP_SELF']?>?filter=__ANY__" <?=($_REQUEST['filter'] == '__ANY__') ? 'selected' : ''?>>Any Switch</option>
  107. <?php
  108. foreach ($ZTP_PIDS as $spid) {
  109. $selected = ($_REQUEST['filter'] == "$spid") ? 'selected' : '';
  110. ?>
  111. <option value="<?=$_SERVER['PHP_SELF']?>?filter=<?=$spid?>" <?=$selected?>><?=$spid?></option>
  112. <?php
  113. }
  114. ?>
  115. </select>
  116. </td>
  117. <form method="POST" name="search_form" action="<?=$_SERVER['PHP_SELF']?>">
  118. <td class="right">Profile Search:
  119. <input type="text" size="16" name="profile_name" value="<?=$_REQUEST['profile_name']?>">
  120. <input type="image" value="Submit" name="search" src="/images/submit_button.png">
  121. </td>
  122. </form>
  123. </tr>
  124. </table>
  125. <br/>
  126. <table class="noborder" summary="Control Table">
  127. <tr>
  128. <td class="left"><a href="<?=$base?>/add_port_profile.php">Add Port Profile</a> |
  129. <a href="<?=$base?>/logicsw.php">Logical Switches</a></td>
  130. </tr>
  131. </table>
  132. <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?"); }'>
  133. <table class="swreg" summary="Button Table" class="full">
  134. <tr>
  135. <td><input type="reset" value="Reset" name="reset">
  136. <input type="submit" value="Submit" name="submit"></td>
  137. </tr>
  138. </table>
  139. <br/>
  140. <div align="center">
  141. <?php
  142. foreach ($errors as $error) {
  143. ?>
  144. <p class="error"><?=$error?></p>
  145. <?php
  146. }
  147. ?>
  148. </div>
  149. <table class="swreg" summary="Port Profile Table" class="full">
  150. <tr>
  151. <th class="delete">Row No.</th>
  152. <th class="delete">Delete?</td>
  153. <th class="headlink">Name</th>
  154. <th class="headlink">Product ID</th>
  155. <th class="headlink">File Name</th>
  156. <th class="headlink">View</th>
  157. </tr>
  158. <?php
  159. foreach (array_merge($_GET, $_POST) as $name => $value) {
  160. ?>
  161. <input type="hidden" name="<?=$name?>" value="<?=$value?>">
  162. <?php
  163. }
  164. $i = 0;
  165. foreach ($profiles as $row) {
  166. $name = $row['name'];
  167. ?>
  168. <tr <?=get_row_color($i)?>>
  169. <td><?=$i + 1?>.</td>
  170. <td><input type="checkbox" name="delete[<?=$name?>]" value="1" onClick="if (this.checked == true) { deletes++; } else { deletes--; }"></td>
  171. <td class="wide"><?=$name?></td>
  172. <td><?=$row['pid']?></td>
  173. <td><?=$row['path']?></td>
  174. <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>
  175. </tr>
  176. <?php
  177. $i++;
  178. }
  179. ?>
  180. </table>
  181. <br/>
  182. <table class="swreg" summary="Button Table" class="full">
  183. <tr>
  184. <td><input type="reset" value="Reset" name="reset">
  185. <input type="submit" value="Submit" name="submit"></td>
  186. </tr>
  187. </table>
  188. </form>
  189. </div>
  190. </body>
  191. </html>
  192. <?php
  193. cleanup();
  194. ?>