| | | | Shell Commander is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | | the Free Software Foundation; either version 2 of the License, or (at | | your option) any later version. | | | | Shell Commander is distributed in the hope that it will be useful, but | | WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | General Public License for more details. | | | | You should have received a copy of the GNU General Public License along | | with Shell Commander; if not, write to the Free Software Foundation, | | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | | | \***************************************************************************/ /** SHELL COMMANDER 1.0 * * @package shcmd * @version 1.0 * @author Pavel Tzonkov * @copyright 2005-2007 Shell Commander Project * @link http://sourceforge.net/projects/shcmd * @license http://www.opensource.org/licenses/gpl-license.php GPL */ error_reporting(0); session_start(); unset($user, $pass); // Prevent registering of $user and $pass variables if // register_glabals=on in php.ini /*=-- SETTINGS --=*\ \*=-- SETTINGS --=*/ //........................................................... GENERAL OPTIONS $history_chars = 20; // Maximal number of characters per line in displayed // history dropdown //............................................................. USER ACCOUNTS // The passwords should be stored with their md5 sums. // For example, the following two lines do one and the same thing. If you // uncomment one of them it creates an user account with username 'user' and // password 'pass'. // $user[] = "myuser"; $pass[] = md5("apassw"); // $user[] = "user"; $pass[] = "1a1dc91c907325c69271ddf0c944bc72"; // // You can add more than one user accounts. //................................................................... ALIASES $alias = array( 'la' => "ls -la", 'rf' => "rm -f", 'unbz2' => "tar -xjpf", 'ungz' => "tar -xzpf", 'top' => "top -bn1" ); /*=-- GLOBAL VARIABLES --=*\ \*=-- GLOBAL VARIABLES --=*/ $self = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], "/") + 1); $pr_login = "Login:"; $pr_pass = "Password:"; $err = "Invalid login!"; $succ = "Successful login!"; if (isset($_GET['cmd'])) $_GET['cmd'] = gpc_clear_slashes($_GET['cmd']); /*=-- AUTHENTICATION --=*\ \*=-- AUTHENTICATION --=*/ //............................................................. NOT LOGGED IN if (isset($_GET['cmd']) && !isset($_SESSION['shcmd']['user'])) { //........................................... WE HAVE USERNAME & PASSWORD if (isset($_SESSION['shcmd']['login']) && isset($_GET['cmd'])) { $output = "\n$pr_pass"; //................................................... USERNAME EXISTS if (in_array($_SESSION['shcmd']['login'], $user)) { $key = array_search($_SESSION['shcmd']['login'], $user); if ($pass[$key] != md5($_GET['cmd'])) { //........ WRONG PASSWORD $output .= "\n$err\n"; unset($_SESSION['shcmd']['login']); $prompt = $pr_login; } else { //..................................... SUCCESSFUL LOGIN $_SESSION['shcmd']['user'] = $_SESSION['shcmd']['login']; $_SESSION['shcmd']['whoami'] = substr(shell_exec("whoami"), 0, -1); $_SESSION['shcmd']['host'] = substr(shell_exec("uname -n"), 0, -1); $_SESSION['shcmd']['dir'] = substr(shell_exec("pwd"), 0, -1); $output .= "\n$succ\n"; $prompt = set_prompt(); unset($_SESSION['shcmd']['login']); } } else { //......................................... NO SUCH USERNAME $output .= "\n$err\n"; unset($_SESSION['shcmd']['login']); $prompt = $pr_login; } //................................................. WE HAVE ONLY USERNAME } elseif (!isset($_SESSION['shcmd']['login'])) { $_SESSION['shcmd']['login'] = $_GET['cmd']; $output = "\n$pr_login {$_GET['cmd']}"; $prompt = $pr_pass; } ajax_dump($prompt, $output); /*=-- MEMBER'S AREA --=*\ \*=-- MEMBER'S AREA --=*/ } elseif (isset($_GET['cmd'])) { chdir($_SESSION['shcmd']['dir']); $prompt = set_prompt(); $first_word = first_word($_GET['cmd']); switch ($first_word) { case "exit": session_destroy(); $output = "\n$prompt{$_GET['cmd']}\n" . substr(shell_exec("{$_GET['cmd']} 2>&1"), 0, -1); break; case "cd": $output = "\n$prompt"; $result = shell_exec($_GET['cmd'] . " 2>&1 ; pwd"); $result = explode("\n", $result); if (count($result) > 2) //.................. WE HAVE AN ERROR MESSAGE $result[0] = "\n" . substr($result[0], strpos($result[0], "cd: ")); else { $_SESSION['shcmd']['dir'] = $result[0]; $result[0] = ""; } $prompt = set_prompt(); $output .= $_GET['cmd'] . $result[0]; break; default: if (array_key_exists($_GET['cmd'], $alias)) $_GET['cmd'] = $alias[$_GET['cmd']]; $output = "\n$prompt{$_GET['cmd']}\n" . substr(shell_exec("{$_GET['cmd']} 2>&1"), 0, -1); } ajax_dump($prompt, $output); } else { /*=-- HTML PAGE --=*\ \*=-- HTML PAGE --=*/ ?> Shell Commander
" ID="history_cell">