show_config.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. require_once 'swreg/swreg.inc.php';
  29. require_once 'swreg_web.inc.php';
  30. $cfg = $_GET['cfg'];
  31. $dname = $_GET['dname'];
  32. $type = $_GET['type'];
  33. if (!isset($cfg) || !isset($dname)) {
  34. die("Error: Configuration file not specified via the cfg parameter or device name not specified with the dname parameter\r\n");
  35. }
  36. $path = DEVICE_CONFIG_DIR;
  37. $ext = "txt";
  38. if (isset($type) && $type == 'profile') {
  39. $path = TFTPBOOT;
  40. $ext = "tmpl";
  41. }
  42. $basename = basename($cfg);
  43. if (!preg_match("/\.$ext$/", $basename)) {
  44. die("Error: Incorrect file type, $cfg\r\n");
  45. }
  46. $contents = file_get_contents("$path/$basename");
  47. if (!$contents) {
  48. die("Failed to open $path/$basename for reading\r\n");
  49. }
  50. $contents = preg_replace("/\"/", "\\\"", $contents);
  51. $contents = preg_replace("/\r\n/", "\\n", $contents);
  52. $contents = preg_replace("/\n/", "\\\\n", $contents);
  53. ?>
  54. <html>
  55. <head>
  56. <title>Configuration for <?=$dname?></title>
  57. <script src="codemirror.js"></script>
  58. <link rel="stylesheet" href="codemirror.css" />
  59. <link rel="stylesheet" href="midnight.css" />
  60. <script src="cisco-config.js"></script>
  61. </head>
  62. <body>
  63. <hr/>
  64. <script language="Javascript">
  65. var cfgViewer = CodeMirror(document.body, {
  66. value : "<?=$contents?>",
  67. mode : "cisco-config",
  68. lineNumbers : true,
  69. theme : "midnight",
  70. readOnly : true
  71. });
  72. cfgViewer.setSize(null, 600);
  73. </script>
  74. <hr/>
  75. </body>
  76. </html>