7 private $cmdstart = '[cmdstartline]';
8 private $cmdend = '[cmdendline]';
10 function __construct($host) {
15 // $this->connection = ssh2_connect($this->host, 22);
16 $this->connection
= ssh2_connect($this->host
, 22, array('hostkey'=>'ssh-dss'));
17 if (!$this->connection
) {
21 if (!@ssh2_auth_password($this->connection, 'mandrake', 'mandrake')) {
23 if (!@ssh2_auth_pubkey_file
($this->connection
, 'mandrake',
24 '/home/mandrake/.ssh/id_dsa.pub',
25 '/home/mandrake/.ssh/id_dsa.bs')) {
28 $this->shell
= ssh2_shell($this->connection
, 'vanilla', array('HISTFILE' => ''));
32 $max_time = 20; //time in seconds
33 while (((time() - $start_time) < $max_time)) {
34 $buf = fgets ($this->shell
);
35 if (strstr ($buf, '$')) {
46 $realcmd = "echo '".$this->cmdstart
."'; ". $cmd ."; echo '".$this->cmdend
."'\n";
47 if (fwrite ($this->shell
, $realcmd) != strlen($realcmd)) {
54 $max_time = 30; //time in seconds
55 while (((time() - $start_time) < $max_time)) {
56 $line = fgets($this->shell
);
58 # Avoid CPU 100% usage.
62 if (!strstr ($line, $cmd)) {
63 if (preg_match('/'.escapeshellcmd($this->cmdstart
).'/',$line)) {
66 elseif (preg_match('/'.escapeshellcmd($this->cmdend
).'/',$line)) {
68 return array_map("trim", split("\n", $output));