Main Page | Namespace List | File List | File Members

test-pers.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $debug=TRUE;
00004 $remote = "user@example.com";
00005 $password = "password";
00006 $workdir = "/tmp";
00007 
00008 // Setup environment
00009 umask(0077);
00010 $tmpfname = tempnam($workdir, 'open-');
00011 chmod($tmpfname, 0700);
00012 if ($debug) echo $tmpfname."\n";
00013 
00014 putenv("DISPLAY=none:0.");
00015 putenv("SSH_ASKPASS=$tmpfname");
00016 
00017 // make askpass command
00018 $fp = fopen($tmpfname, "w");
00019 fputs($fp, "#!/bin/sh\necho $password\n");
00020 if (! $debug) 
00021     fputs($fp, "/bin/touch $tmpfname.called\n");
00022 else
00023      fputs($fp, "/bin/rm -f $tmpfname\n");
00024 fclose($fp);
00025 // go
00026 
00027 $child_stdout = tempnam($workdir, "open_sh-O-");
00028 $child_stderr = tempnam($workdir, "open_sh-E-");
00029 
00030 $descriptorspec = array(
00031     0 => array("pipe", "r"),  // connect child's stdin to the read end of a pipe
00032     1 => array("file", $child_stdout, "a"),  // connect child's stdout to the write end of a pipe
00033     2 => array("file", $child_stderr, "a")   // stderr is a pipe to read from
00034 );
00035 
00036 // Open master
00037 if ($debug) echo "ssh -x -t -t -M -S /tmp/open-sock $remote\n";
00038 $process = proc_open("ssh -x -t -t -M -S /tmp/open-sock $remote", 
00039                  $descriptorspec,
00040                  $pipes);
00041 
00042 
00043 fwrite($pipes[0], "\necho Started\n");
00044 
00045 do {
00046         echo "wait\n";
00047         usleep(100000); // wait 0.1 seconds
00048 } while (! file_exists("/tmp/open-sock"));
00049 
00050 // there we go
00051         putenv("SSH_ASKPASS=");
00052         $f = popen("ssh -x -t -t -S /tmp/open-sock $remote ls", "w");
00053         pclose($f);
00054 
00055 
00056 
00057 // finish
00058 fwrite($pipes[0], "\necho Stopped\n");
00059 
00060 // Close master
00061 fwrite($pipes[0], "\nlogout\n");
00062 fclose($pipes[0]);
00063 proc_close($process);
00064 
00065 ?>

Generated on Thu Jun 16 11:03:56 2005 for SExec by doxygen 1.3.6