Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- @ini_set('zlib.output_compression',0);
- @ini_set('implicit_flush',1);
- @ob_end_clean();
- set_time_limit(0);
- if($_GET["pass"]!="***")
- die("Auth error");
- //session_start();
- //$_SESSION["auth"]="ok";
- $temp_fifo_file = '/tmp/dolphin-pipe-'.uniqid('dolph');
- if (!posix_mkfifo($temp_fifo_file, 0600)) {
- echo "Fatal error: Cannot create fifo file: something wrong with the system.\n";
- exit(1);
- }
- if (!posix_mkfifo($temp_fifo_file."-ctrl", 0600)) {
- echo "Fatal error: Cannot create fifo file: something wrong with the system.\n";
- exit(1);
- }
- //die("ok2");
- function deleteTempFifo() {
- unlink($GLOBALS['temp_fifo_file']);
- popen("/bin/rm -rf ".$GLOBALS['temp_fifo_file'], "r");
- unlink($GLOBALS['temp_fifo_file']."-ctrl");
- popen("/bin/rm -rf ".$GLOBALS['temp_fifo_file']."-ctrl", "r");
- }
- register_shutdown_function('deleteTempFifo');
- $cmdfp = fopen($temp_fifo_file, 'r+');
- $cmdfpctrl = fopen($temp_fifo_file."-ctrl", 'r+');
- stream_set_blocking($cmdfp, 0);
- stream_set_blocking($cmdfpctrl, 0);
- putenv('TERM=vt100');
- $cols = 80;
- $rows = 24;
- chdir(dirname(__FILE__));
- $cmd = "bash --rcfile ./bashrc -i 2>&1";
- // try to compile pseudo-terminal emulator if we can
- /*if (!file_exists('pt')) {
- system('cc -D__'.strtoupper(trim(`uname`)).'__ -o pt pt.c -lutil 2>&1', $retval);
- if ($retval) echo('<b>Warning:</b> Cannot compile pseudotty helper');
- }*/
- clearstatcache();
- if (file_exists('pt')) $cmd = "./pt $rows $cols $cmd";
- $pp = proc_open($cmd, array(array('pipe','r'), array('pipe', 'w')), $pipes);
- stream_set_blocking($pipes[0], 0);
- stream_set_blocking($pipes[1], 0);
- ?>
- <html><head><title>Terminal</title></head><body>
- <script>
- var pipeName = <?=json_encode($temp_fifo_file)?>, pending_str = '', processing = false, timeout=0, before=new Date();
- var sendCmdInterv = setInterval(function() {
- var now = new Date();
- var elapsedTime = (now.getTime() - before.getTime());
- timeout=timeout+elapsedTime;
- //console.log(timeout);
- if (processing) return;
- if (pending_str.length) {
- timeout=0;
- processing = true;
- var previous_str = pending_str;
- pending_str = '';
- var http = new XMLHttpRequest();
- http.open("GET", "send-cmd.php?pass=<?=$_GET["pass"] ?>&pipe=" + pipeName + "&cmd=" + encodeURIComponent(previous_str), true);
- http.onreadystatechange = function() {
- if (http.readyState == 4 && http.status == 200) {
- processing = false;
- pending_str = '';
- } else {
- pending_str = previous_str + pending_str;
- }
- };
- http.send(null);
- }
- if(timeout>30*1000)
- {
- timeout=0;
- processing = true;
- var http = new XMLHttpRequest();
- http.open("GET", "send-cmd.php?pass=<?=$_GET["pass"] ?>&ctrl=ok&pipe=" + pipeName + "&cmd=0", true);
- http.onreadystatechange = function() {
- processing = false;
- };
- http.send(null);
- }
- before=new Date();
- }, 16);
- function send_cmd(val) {
- pending_str += val;
- }
- </script>
- <style>
- .term {
- font-family: monaco,courier,fixed,monospace,swiss,sans-serif;
- font-size: 13px;
- line-height: 16px;
- color: #f0f0f0;
- background: #000000;
- }
- tr {
- height: 16px;
- }
- .termReverse {
- color: #000000;
- background: #00ff00;
- }
- </style>
- <script src="utils.js"></script>
- <script src="term.js"></script>
- <script>var term = new Term(<?=$cols?>, <?=$rows?>, send_cmd); term.open();</script>
- <?php
- echo "<!-- ".str_repeat('-', 104096)." -->\n";
- //flush();
- ob_implicit_flush(1);
- echo str_repeat(' ',1024*64);
- sleep(1);
- $waited=0;
- while (!feof($pipes[1])) {
- $ln = fgets($pipes[1], 4096);
- if ($ln !== false) {
- $ln = str_replace("\n", "\r\n", $ln);
- echo '<script>term.write('.json_encode($ln).');</script>';
- //flush();
- echo str_repeat(' ',1024*64);
- $waited=0;
- // sleep(0.1);
- continue;
- }
- $inp_ln = fgets($cmdfp, 4096);
- if ($inp_ln !== false) {
- // ensure that command is fully written by setting blocking to 1
- stream_set_blocking($pipes[0], 1);
- fwrite($pipes[0], $inp_ln);
- stream_set_blocking($pipes[0], 0);
- }
- $ctrl_ln = fgets($cmdfpctrl, 4096);
- if ($ctrl_ln !== false)
- {
- for($i=0; $i<strlen($ctrl_ln); $i++)
- {
- switch($ctrl_ln[$i])
- {
- case '0':
- $waited=0;
- echo str_repeat(' ',1024*64);
- //die("oke");
- break;
- default:
- break;
- }
- }
- }
- $waited=$waited+20000;
- if($waited>50000000)
- {
- //echo str_repeat(' ',1024*64);
- //$waited=0;
- die("<script>clearInterval(sendCmdInterv);</script>
- </body>
- </html>");
- }
- usleep(20000);
- }
- proc_close($pp);
- ?>
- <script>clearInterval(sendCmdInterv);</script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement