SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | @ini_set('zlib.output_compression',0); | |
3 | ||
4 | @ini_set('implicit_flush',1); | |
5 | ||
6 | @ob_end_clean(); | |
7 | ||
8 | set_time_limit(0); | |
9 | - | if($_GET["pass"]!="8914void8914") |
9 | + | if($_GET["pass"]!="***") |
10 | die("Auth error"); | |
11 | //session_start(); | |
12 | //$_SESSION["auth"]="ok"; | |
13 | ||
14 | $temp_fifo_file = '/tmp/dolphin-pipe-'.uniqid('dolph'); | |
15 | if (!posix_mkfifo($temp_fifo_file, 0600)) { | |
16 | echo "Fatal error: Cannot create fifo file: something wrong with the system.\n"; | |
17 | exit(1); | |
18 | } | |
19 | //die("ok2"); | |
20 | function deleteTempFifo() { | |
21 | unlink($GLOBALS['temp_fifo_file']); | |
22 | popen("/bin/rm -rf ".$GLOBALS['temp_fifo_file'], "r"); | |
23 | } | |
24 | register_shutdown_function('deleteTempFifo'); | |
25 | ||
26 | $cmdfp = fopen($temp_fifo_file, 'r+'); | |
27 | stream_set_blocking($cmdfp, 0); | |
28 | ||
29 | putenv('TERM=vt100'); | |
30 | $cols = 80; | |
31 | $rows = 24; | |
32 | ||
33 | chdir(dirname(__FILE__)); | |
34 | $cmd = "bash --rcfile ./bashrc -i 2>&1"; | |
35 | // try to compile pseudo-terminal emulator if we can | |
36 | /*if (!file_exists('pt')) { | |
37 | system('cc -D__'.strtoupper(trim(`uname`)).'__ -o pt pt.c -lutil 2>&1', $retval); | |
38 | if ($retval) echo('<b>Warning:</b> Cannot compile pseudotty helper'); | |
39 | }*/ | |
40 | clearstatcache(); | |
41 | if (file_exists('pt')) $cmd = "./pt $rows $cols $cmd"; | |
42 | $pp = proc_open($cmd, array(array('pipe','r'), array('pipe', 'w')), $pipes); | |
43 | stream_set_blocking($pipes[0], 0); | |
44 | stream_set_blocking($pipes[1], 0); | |
45 | ?> | |
46 | <html><head><title>Terminal</title></head><body> | |
47 | <script> | |
48 | - | var pipeName = <?=json_encode($temp_fifo_file)?>, pending_str = '', processing = false, timeout=0; |
48 | + | var pipeName = <?=json_encode($temp_fifo_file)?>, pending_str = '', processing = false, timeout=0, before=new Date(); |
49 | var sendCmdInterv = setInterval(function() { | |
50 | - | timeout=timeout+16; |
50 | + | var now = new Date(); |
51 | var elapsedTime = (now.getTime() - before.getTime()); | |
52 | timeout=timeout+elapsedTime; | |
53 | //console.log(timeout); | |
54 | if (processing) return; | |
55 | if (pending_str.length) { | |
56 | timeout=0; | |
57 | processing = true; | |
58 | var previous_str = pending_str; | |
59 | pending_str = ''; | |
60 | var http = new XMLHttpRequest(); | |
61 | http.open("GET", "send-cmd.php?pass=<?=$_GET["pass"] ?>&pipe=" + pipeName + "&cmd=" + encodeURIComponent(previous_str), true); | |
62 | http.onreadystatechange = function() { | |
63 | if (http.readyState == 4 && http.status == 200) { | |
64 | processing = false; | |
65 | pending_str = ''; | |
66 | } else { | |
67 | pending_str = previous_str + pending_str; | |
68 | } | |
69 | }; | |
70 | http.send(null); | |
71 | } | |
72 | if(timeout>30*1000) | |
73 | { | |
74 | timeout=0; | |
75 | processing = true; | |
76 | var http = new XMLHttpRequest(); | |
77 | http.open("GET", "send-cmd.php?pass=<?=$_GET["pass"] ?>&pipe=" + pipeName + "&cmd=%03", true); | |
78 | http.onreadystatechange = function() { | |
79 | processing = false; | |
80 | }; | |
81 | http.send(null); | |
82 | } | |
83 | before=new Date(); | |
84 | }, 16); | |
85 | ||
86 | function send_cmd(val) { | |
87 | pending_str += val; | |
88 | } | |
89 | </script> | |
90 | <style> | |
91 | .term { | |
92 | font-family: monaco,courier,fixed,monospace,swiss,sans-serif; | |
93 | font-size: 13px; | |
94 | line-height: 16px; | |
95 | color: #f0f0f0; | |
96 | background: #000000; | |
97 | } | |
98 | ||
99 | tr { | |
100 | height: 16px; | |
101 | } | |
102 | ||
103 | .termReverse { | |
104 | color: #000000; | |
105 | background: #00ff00; | |
106 | } | |
107 | </style> | |
108 | <script src="utils.js"></script> | |
109 | <script src="term.js"></script> | |
110 | <script>var term = new Term(<?=$cols?>, <?=$rows?>, send_cmd); term.open();</script> | |
111 | <?php | |
112 | echo "<!-- ".str_repeat('-', 104096)." -->\n"; | |
113 | //flush(); | |
114 | ob_implicit_flush(1); | |
115 | echo str_repeat(' ',1024*64); | |
116 | sleep(1); | |
117 | $waited=0; | |
118 | while (!feof($pipes[1])) { | |
119 | $ln = fgets($pipes[1], 4096); | |
120 | if ($ln !== false) { | |
121 | $ln = str_replace("\n", "\r\n", $ln); | |
122 | echo '<script>term.write('.json_encode($ln).');</script>'; | |
123 | //flush(); | |
124 | echo str_repeat(' ',1024*64); | |
125 | $waited=0; | |
126 | // sleep(0.1); | |
127 | continue; | |
128 | } | |
129 | ||
130 | $inp_ln = fgets($cmdfp, 4096); | |
131 | if ($inp_ln !== false) { | |
132 | // ensure that command is fully written by setting blocking to 1 | |
133 | stream_set_blocking($pipes[0], 1); | |
134 | - | if($waited>60000000) |
134 | + | |
135 | stream_set_blocking($pipes[0], 0); | |
136 | } | |
137 | $waited=$waited+20000; | |
138 | - | die(); |
138 | + | if($waited>50000000) |
139 | { | |
140 | //echo str_repeat(' ',1024*64); | |
141 | //$waited=0; | |
142 | die("<script>clearInterval(sendCmdInterv);</script> | |
143 | </body> | |
144 | </html>"); | |
145 | } | |
146 | usleep(20000); | |
147 | } | |
148 | proc_close($pp); | |
149 | ?> | |
150 | <script>clearInterval(sendCmdInterv);</script> | |
151 | </body> | |
152 | </html> |