Main Page | Namespace List | File List | File Members

remotessh.php

Go to the documentation of this file.
00001 <?php
00002 /**
00003  * Routines to make an SSH connection to a remote host
00004  *
00005  * @package SExec
00006  * @author José R. Valverde <jrvalverde@acm.org>
00007  * @version 0.1
00008  * @copyright José R. Valverde <jrvalverde@es.embnet.org>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  * 
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025  
00026 /** 
00027  * Do a remote ssh connection with local password
00028  */
00029 function do_ssh($host, $user, $password, $command)
00030 {
00031         umask(0077);
00032         $tmpfname = tempnam("/tmp", "egTinker");
00033         chmod($tmpfname, 0700);
00034         $fp = fopen($tmpfname, "w");
00035         fputs($fp, "#!/bin/sh\necho $password\n");
00036         fclose($fp);
00037         putenv("DISPLAY=none:0.");
00038         putenv("SSH_ASKPASS=$tmpfname");
00039         system("ssh -x -t -t $host -l$user $command");
00040         unlink($tmpfname);
00041 }
00042 
00043 /**
00044  * Do a remote scp connection with local password
00045  */
00046 function do_scp($origin, $destination, $password)
00047 {
00048         umask(0077);
00049         $tmpfname = tempnam("/tmp", "ssh");
00050         chmod($tmpfname, 0700);
00051         $fp = fopen($tmpfname, "w");
00052         fputs($fp, "#!/bin/sh\necho $password\n");
00053         fclose($fp);
00054         putenv("DISPLAY=none:0.");
00055         putenv("SSH_ASKPASS=$tmpfname");
00056         system("scp -pqrC $origin $destination &");
00057         unlink($tmpfname);
00058 }
00059 
00060 do_ssh("example.com", "user", "example.com", "ls");
00061 
00062 do_scp("SSH", "user@example.com:.", "password");
00063 
00064 do_ssh("example.com", "user", "password", "ls");
00065 do_ssh("example.com", "user", "password", "ls SSH");
00066 
00067 
00068 ?>

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