show_config.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. //-
  3. // Copyright (c) 2011-2015 Joe Clarke <jclarke@cisco.com>
  4. // All rights reserved.
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions
  7. // are met:
  8. // 1. Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // 2. Redistributions in binary form must reproduce the above copyright
  11. // notice, this list of conditions and the following disclaimer in the
  12. // documentation and/or other materials provided with the distribution.
  13. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. // SUCH DAMAGE.
  24. require_once 'swreg/swreg.inc.php';
  25. $cfg = $_GET['cfg'];
  26. $dname = $_GET['dname'];
  27. $type = '';
  28. if (isset($_GET['type'])) {
  29. $type = $_GET['type'];
  30. }
  31. if (!isset($cfg) || !isset($dname)) {
  32. die("Error: Configuration file not specified via the cfg parameter or device name not specified with the dname parameter\r\n");
  33. }
  34. $path = DEVICE_CONFIG_DIR;
  35. $ext = 'txt';
  36. if ($type == 'profile') {
  37. $path = PORT_PROFILE_DIR;
  38. $ext = 'tmpl';
  39. }
  40. $basename = basename($cfg);
  41. if (!preg_match("/\.$ext$/", $basename)) {
  42. die("Error: Incorrect file type, $cfg\r\n");
  43. }
  44. $contents = file_get_contents("$path/$basename");
  45. if (!$contents) {
  46. die("Failed to open $path/$basename for reading\r\n");
  47. }
  48. $contents = preg_replace('/"/', '\\"', $contents);
  49. $contents = preg_replace("/\r\n/", '\\n', $contents);
  50. $contents = preg_replace("/\n/", '\\\\n', $contents);
  51. ?>
  52. <!DOCTYPE html>
  53. <html>
  54. <head>
  55. <title>Configuration for
  56. <?= $dname ?>
  57. </title>
  58. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  59. <script src="codemirror.js"></script>
  60. <link rel="stylesheet" href="codemirror.css" />
  61. <link rel="stylesheet" href="midnight.css" />
  62. <script src="cisco-config.js"></script>
  63. </head>
  64. <body>
  65. <hr />
  66. <script language="Javascript">
  67. var cfgViewer = CodeMirror(document.body, {
  68. value: "<?= $contents ?>",
  69. mode: "cisco-config",
  70. lineNumbers: true,
  71. theme: "midnight",
  72. readOnly: true
  73. });
  74. cfgViewer.setSize(null, 600);
  75. </script>
  76. <hr />
  77. </body>
  78. </html>