diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-04-12 02:49:22 +1000 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-04-12 02:49:22 +1000 |
| commit | c9423a2c34a5b93bf9cf2c506acca713781e60b6 (patch) | |
| tree | 16f4a569d34fc67365b453bafe561524fce87b22 /inc/remote.php | |
| parent | 88092e4f9e50e94f094e55c54a6150df104043b1 (diff) | |
large cleanup
Diffstat (limited to 'inc/remote.php')
| -rw-r--r-- | inc/remote.php | 116 |
1 files changed, 63 insertions, 53 deletions
diff --git a/inc/remote.php b/inc/remote.php index bf170486..664aa2bb 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -1,57 +1,67 @@ <?php - class Remote { - public function __construct($config) { - foreach($config as $name => $value) { - $this->{$name} = $value; - } - - $methods = Array(); - - if(!isset($this->auth['method'])) - error('Unspecified authentication method.'); - - // Connect - $this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods); - - switch($this->auth['method']) { - case 'pubkey': - - if(!isset($this->auth['public'])) - error('Public key filename not specified.'); - if(!isset($this->auth['private'])) - error('Private key filename not specified.'); - - if(!ssh2_auth_pubkey_file($this->connection, $this->auth['username'], $this->auth['public'], $this->auth['private'], isset($this->auth['passphrase']) ? $this->auth['passphrase']: null)) - error('Public key authentication failed.'); - break; - case 'plain': - if(!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password'])) - error('Plain-text authentication failed.'); - break; - default: - error('Unknown authentication method: "' . $this->auth['method'] . '".'); - } - + +/* + * Copyright (c) 2010-2012 Tinyboard Development Group + */ + +if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { + // You cannot request this file directly. + exit; +} + +class Remote { + public function __construct($config) { + foreach($config as $name => $value) { + $this->{$name} = $value; } - public function write($data, $remote_path) { - global $config; - - switch($this->type) { - case 'sftp': - $sftp = ssh2_sftp($this->connection); - file_write('ssh2.sftp://' . $sftp . $remote_path, $data, true); - break; - case 'scp': - $file = tempnam($config['tmp'], 'tinyboard-scp'); - // Write to temp file - file_write($file, $data); - - ssh2_scp_send($this->connection, $file, $remote_path, 0755); - break; - default: - error('Unknown send method.'); - } + $methods = Array(); + + if(!isset($this->auth['method'])) + error('Unspecified authentication method.'); + + // Connect + $this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods); + + switch($this->auth['method']) { + case 'pubkey': + + if(!isset($this->auth['public'])) + error('Public key filename not specified.'); + if(!isset($this->auth['private'])) + error('Private key filename not specified.'); + + if(!ssh2_auth_pubkey_file($this->connection, $this->auth['username'], $this->auth['public'], $this->auth['private'], isset($this->auth['passphrase']) ? $this->auth['passphrase']: null)) + error('Public key authentication failed.'); + break; + case 'plain': + if(!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password'])) + error('Plain-text authentication failed.'); + break; + default: + error('Unknown authentication method: "' . $this->auth['method'] . '".'); + } + + } + + public function write($data, $remote_path) { + global $config; + + switch($this->type) { + case 'sftp': + $sftp = ssh2_sftp($this->connection); + file_write('ssh2.sftp://' . $sftp . $remote_path, $data, true); + break; + case 'scp': + $file = tempnam($config['tmp'], 'tinyboard-scp'); + // Write to temp file + file_write($file, $data); + + ssh2_scp_send($this->connection, $file, $remote_path, 0755); + break; + default: + error('Unknown send method.'); } - }; -?> + } +}; + |
