00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 $debug_sexec = TRUE;
00033
00034 require_once 'ssh.php';
00035
00036
00037
00038
00039 echo "<pre>\n";
00040
00041 $rmt = new SExec($remote, $password);
00042 if ($rmt == FALSE) {
00043 echo "Couldn't open the connection\n";
00044 exit;
00045 }
00046
00047 echo "Created\n";
00048
00049 #$debug_passthru = TRUE;
00050 if (isset($debug_passthru)) {
00051 echo "Using passthru to send ls...\n\n";
00052 $rmt->ssh_passthru("ls", $status=0);
00053 echo "\nExit status was $status";
00054 }
00055
00056 #$debug_exec = TRUE;
00057 if (isset($debug_exec)) {
00058 $rmt->ssh_exec("ls", $out="");
00059 # $rmt->ssh_exec("ls");
00060 print_r($out);
00061 foreach ($out as $line)
00062 echo $line . "\n";
00063 }
00064
00065 #$debug_copy_to = TRUE;
00066 if (isset($debug_copy_to)) {
00067 echo "\nCopy ldir ./CVS to rdir $remote:k/.\n";
00068 $rmt->ssh_copy_to("./CVS", "k", $out);
00069 echo "\nCopy lfile ./CVS/Entries to rdir $remote:k/.\n";
00070 $rmt->ssh_copy_to("./CVS/Entries", "k", $out);
00071 echo "\nCopy ldir ./CVS to rfile $remote:k/p\n";
00072 $rmt->ssh_copy_to("./CVS", "k/p", $out);
00073 echo "\nCopy lfile ./CVS/Entries to rfile $remote:k/p\n";
00074 $rmt->ssh_copy_to("./CVS/Entries", "k/p", $out);
00075 }
00076
00077 #$debug_copy_from = TRUE;
00078 if (isset($debug_copy_from)) {
00079 echo "\nCopy rdir ./k/CVS to ldir k/.\n";
00080 $rmt->ssh_copy_from("./k/CVS", "k", $out);
00081 echo "\nCopy rfile ./k/CVS/Entries to ldir k/.\n";
00082 $rmt->ssh_copy_from("./k/CVS/Entries", "k", $out);
00083 echo "\nCopy rdir ./k/CVS to lfile k/p\n";
00084 $rmt->ssh_copy_from("./k/CVS", "k/p", $out);
00085 echo "\nCopy rfile ./k/CVS/Entries to lfile k/p\n";
00086 $rmt->ssh_copy_from("./k/CVS/Entries", "k/p", $out);
00087 $rmt->destruct() ; exit;
00088 }
00089
00090 #$debug_persistent_shell = TRUE;
00091 if (isset($debug_persistent_shell))
00092 {
00093 $p = $rmt->ssh_open_shell();
00094
00095 echo "after open I got this\n";
00096 print_r($p);
00097
00098 sleep(1);
00099 echo "[1] flushing stdout after login\n";
00100 do {
00101 $line = fgets($p["std_out"], 1024);
00102 echo "> ".$line;
00103 } while ((! feof($p["std_out"]) ) && (! ereg("bossa-nova", $line)));
00104 $last = ftell($p["std_out"]);
00105
00106 echo "\n[2]sending hello\n";
00107 fwrite($p['std_in'], "./hello\n"); fflush($p['std_in']);
00108 sleep(1); flush();
00109 fseek($p["std_out"], $last);
00110 echo "< ";
00111 print_r(fgets($p["std_out"], 1024));
00112 echo "< ";
00113 print_r(fgets($p["std_out"], 1024));
00114 echo "\n";
00115 $last = ftell($p["std_out"]);
00116 fwrite($p['std_in'], "Oh yes I do\n"); fflush($p['std_in']);
00117 sleep(2);
00118
00119 echo "flushing files\n\tstdout\n";
00120 flush();
00121 fseek($p["std_out"], $last);
00122 do {
00123 $line = fgets($p["std_out"], 1024);
00124 echo ">> ".$line;
00125 } while (! feof($p["std_out"]) );
00126 # echo "stderr\n";
00127 # do {
00128 # $line = fgets($p["std_err"], 1024);
00129 # echo ">>> ".$line."\n";
00130 # } while (! feof($p['std_err']) && (strlen($line) != 0));;
00131
00132 $rmt->ssh_close($p);
00133 }
00134
00135 $debug_persistent_cmd = TRUE;
00136 if (isset($debug_persistent_cmd))
00137 {
00138 echo "\nCopying interactive script to $remote:\n";
00139 $rmt->ssh_copy_to("./interact.sh", ".", $out);
00140
00141 $p = $rmt->ssh_open_command("./interact.sh");
00142 echo "after open I got this\n";
00143 print_r($p);
00144 sleep(1);
00145
00146 $line = fgets($p["std_out"], 1024);
00147 echo "> ".$line ."\n";
00148 $line = fgets($p["std_out"], 1024);
00149 echo "> ".$line ."\n";
00150 sleep(1);
00151
00152 echo "\nSending 'SExecClient'\n";
00153 fwrite($p['std_in'], 'SExecClient\n'); fflush($p['std_in']);
00154 sleep(1);
00155 $out = fgets($p['std_out'], 1024);
00156 echo "\nGot [". $out . "]\n";
00157
00158 echo "flushing files\nstdout\n";
00159 flush();
00160 do {
00161 $line = fgets($p["std_out"], 1024);
00162 echo "> ".$line ."\n";
00163 } while (! feof($p["std_out"]) );;
00164 echo "stderr\n";
00165 do {
00166 $line = fgets($p["std_err"], 1024);
00167 echo ">> ".$line."\n";
00168 } while (! feof($p['std_err']));;
00169
00170 $rmt->ssh_close($p);
00171 }
00172
00173 #$debug_popen = TRUE;
00174 if (isset($debug_popen)) {
00175 $cout = $rmt->ssh_popen("ls -C", "r");
00176 echo fread($cout, 8192);
00177 $rmt->ssh_pclose($cout);
00178 echo "\n";
00179
00180
00181
00182
00183
00184
00185
00186 }
00187
00188 $rmt->destruct();
00189
00190
00191 echo "</pre>\n\n";
00192 exit;
00193
00194 ?>