[ Index ] |
PHP Cross Reference of phpSSH |
[Summary view] [Print]
1 <?php 2 3 $debug=TRUE; 4 $remote = "user@example.com"; 5 $password = "password"; 6 $workdir = "/tmp"; 7 8 // Setup environment 9 umask(0077); 10 $tmpfname = tempnam($workdir, 'open-'); 11 chmod($tmpfname, 0700); 12 if ($debug) echo $tmpfname."\n"; 13 14 putenv("DISPLAY=none:0."); 15 putenv("SSH_ASKPASS=$tmpfname"); 16 17 // make askpass command 18 $fp = fopen($tmpfname, "w"); 19 fputs($fp, "#!/bin/sh\necho $password\n"); 20 if (! $debug) 21 fputs($fp, "/bin/touch $tmpfname.called\n"); 22 else 23 fputs($fp, "/bin/rm -f $tmpfname\n"); 24 fclose($fp); 25 // go 26 27 $child_stdout = tempnam($workdir, "open_sh-O-"); 28 $child_stderr = tempnam($workdir, "open_sh-E-"); 29 30 $descriptorspec = array( 31 0 => array("pipe", "r"), // connect child's stdin to the read end of a pipe 32 1 => array("file", $child_stdout, "a"), // connect child's stdout to the write end of a pipe 33 2 => array("file", $child_stderr, "a") // stderr is a pipe to read from 34 ); 35 36 // Open master 37 if ($debug) echo "ssh -x -t -t -M -S /tmp/open-sock $remote\n"; 38 $process = proc_open("ssh -x -t -t -M -S /tmp/open-sock $remote", 39 $descriptorspec, 40 $pipes); 41 42 43 fwrite($pipes[0], "\necho Started\n"); 44 45 do { 46 echo "wait\n"; 47 usleep(100000); // wait 0.1 seconds 48 } while (! file_exists("/tmp/open-sock")); 49 50 // there we go 51 putenv("SSH_ASKPASS="); 52 $f = popen("ssh -x -t -t -S /tmp/open-sock $remote ls", "w"); 53 pclose($f); 54 55 56 57 // finish 58 fwrite($pipes[0], "\necho Stopped\n"); 59 60 // Close master 61 fwrite($pipes[0], "\nlogout\n"); 62 fclose($pipes[0]); 63 proc_close($process); 64 65 ?>
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 31 15:44:47 2005 | Cross-referenced by PHPXref 0.4.1 |