[ Index ]

PHP Cross Reference of phpSSH

/ -> remotessh.php (source)

   1  <?php
   2  /**
   3   * Routines to make an SSH connection to a remote host
   4   *
   5   * @package SExec
   6   * @author José R. Valverde <jrvalverde@acm.org>
   7   * @version 0.1
   8   * @copyright José R. Valverde <jrvalverde@es.embnet.org>
   9   *
  10   * This library is free software; you can redistribute it and/or
  11   * modify it under the terms of the GNU Lesser General Public
  12   * License as published by the Free Software Foundation; either
  13   * version 2.1 of the License, or (at your option) any later version.
  14   * 
  15   * This library is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18   * Lesser General Public License for more details.
  19   * 
  20   * You should have received a copy of the GNU Lesser General Public
  21   * License along with this library; if not, write to the Free Software
  22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23   *
  24   */
  25   
  26  /** 
  27   * Do a remote ssh connection with local password
  28   */
  29  function do_ssh($host, $user, $password, $command)
  30  {
  31      umask(0077);
  32      $tmpfname = tempnam("/tmp", "egTinker");
  33      chmod($tmpfname, 0700);
  34      $fp = fopen($tmpfname, "w");
  35      fputs($fp, "#!/bin/sh\necho $password\n");
  36      fclose($fp);
  37      putenv("DISPLAY=none:0.");
  38      putenv("SSH_ASKPASS=$tmpfname");
  39      system("ssh -x -t -t $host -l$user $command");
  40      unlink($tmpfname);
  41  }
  42  
  43  /**
  44   * Do a remote scp connection with local password
  45   */
  46  function do_scp($origin, $destination, $password)
  47  {
  48      umask(0077);
  49      $tmpfname = tempnam("/tmp", "ssh");
  50      chmod($tmpfname, 0700);
  51      $fp = fopen($tmpfname, "w");
  52      fputs($fp, "#!/bin/sh\necho $password\n");
  53      fclose($fp);
  54      putenv("DISPLAY=none:0.");
  55      putenv("SSH_ASKPASS=$tmpfname");
  56      system("scp -pqrC $origin $destination &");
  57      unlink($tmpfname);
  58  }
  59  
  60  do_ssh("example.com", "user", "example.com", "ls");
  61  
  62  do_scp("SSH", "user@example.com:.", "password");
  63  
  64  do_ssh("example.com", "user", "password", "ls");
  65  do_ssh("example.com", "user", "password", "ls SSH");
  66  
  67  
  68  ?>


Generated: Tue May 31 15:44:47 2005 Cross-referenced by PHPXref 0.4.1