/[drupal]/contributions/modules/plugin_manager/ssh.backend.inc
ViewVC logotype

Contents of /contributions/modules/plugin_manager/ssh.backend.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Aug 12 00:52:40 2008 UTC (15 months, 2 weeks ago) by joshuarogers
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +8 -3 lines
File MIME type: text/x-php
Fixed all problems reported by the coder module.
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 }

  ViewVC Help
Powered by ViewVC 1.1.2