| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The SSH Backend for the plugin manager.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of user hook plugin_manager_backend. Checks
|
| 11 |
* if the requirements for the ssh backend are enabled.
|
| 12 |
*
|
| 13 |
* @return
|
| 14 |
* Return 'ssh' if the requirements are available.
|
| 15 |
*/
|
| 16 |
function ssh_plugin_manager_backend() {
|
| 17 |
if (function_exists('ssh2_connect')) {
|
| 18 |
return 'ssh';
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Install the supplied files to the appropriate locations.
|
| 24 |
*
|
| 25 |
* @param $files
|
| 26 |
* The files to install.
|
| 27 |
* @param $type
|
| 28 |
* Either 'module' or 'theme' to indicate where to install to.
|
| 29 |
* @param $username
|
| 30 |
* Local FTP Username
|
| 31 |
* @param $password
|
| 32 |
* Local FTP Password
|
| 33 |
* @return
|
| 34 |
* TRUE if all the files were installed, FALSE otherwise.
|
| 35 |
*/
|
| 36 |
|
| 37 |
function ssh_plugin_manager_copy($files, $type, $username, $password) {
|
| 38 |
// Figure out the type of files.
|
| 39 |
if (!in_array($type, array('modules', 'themes'))) {
|
| 40 |
return FALSE;
|
| 41 |
}
|
| 42 |
$dir = 'sites/all/'. drupal_strtolower($type);
|
| 43 |
|
| 44 |
// Connect to the localhost via ssh.
|
| 45 |
$connection = ssh2_connect('localhost');
|
| 46 |
if ($connection == FALSE) {
|
| 47 |
drupal_set_message(t('Could not connect to ssh on this host.'), 'error');
|
| 48 |
return FALSE;
|
| 49 |
}
|
| 50 |
|
| 51 |
if (!ssh2_auth_password($connection, $username, $password)) {
|
| 52 |
drupal_set_message(t('The supplied username/password combination '
|
| 53 |
.'was not accepted.'), 'error');
|
| 54 |
return FALSE;
|
| 55 |
}
|
| 56 |
|
| 57 |
// Prepare the directories to use later.
|
| 58 |
$extract_dir = file_directory_path() .'/plugin_manager_extraction';
|
| 59 |
|
| 60 |
|
| 61 |
// Try to guess the ftp address for the drupal install.
|
| 62 |
// Start by putting the entire address together and replacing \ with /.
|
| 63 |
$local_path = rtrim(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT'] . base_path()), '/');
|
| 64 |
|
| 65 |
// Process each of the files.
|
| 66 |
foreach ($files AS $file) {
|
| 67 |
if (trim($file, "\\/") != $file) {
|
| 68 |
ssh2_exec($connection, "mkdir ". escapeshellarg("$local_path/$dir/$file"));
|
| 69 |
}
|
| 70 |
else {
|
| 71 |
ssh2_scp_send($connection, "$extract_dir/$file", "$local_path/$dir/$file");
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
return TRUE;
|
| 76 |
}
|