Source code of Leftypol imageboard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

<?php
12 years ago
/*
* Copyright (c) 2010-2013 Tinyboard Development Group
12 years ago
*/
defined('TINYBOARD') or exit;
12 years ago
class Remote {
public function __construct($config) {
12 years ago
foreach ($config as $name => $value) {
12 years ago
$this->{$name} = $value;
}
$methods = array();
12 years ago
12 years ago
if (!isset($this->auth['method']))
12 years ago
error('Unspecified authentication method.');
// Connect
$this->connection = ssh2_connect($this->host, isset($this->port) ? $this->port : 22, $methods);
12 years ago
switch ($this->auth['method']) {
12 years ago
case 'pubkey':
12 years ago
if (!isset($this->auth['public']))
12 years ago
error('Public key filename not specified.');
12 years ago
if (!isset($this->auth['private']))
12 years ago
error('Private key filename not specified.');
12 years ago
if (!ssh2_auth_pubkey_file($this->connection, $this->auth['username'], $this->auth['public'], $this->auth['private'], isset($this->auth['passphrase']) ? $this->auth['passphrase']: null))
12 years ago
error('Public key authentication failed.');
break;
case 'plain':
12 years ago
if (!ssh2_auth_password($this->connection, $this->auth['username'], $this->auth['password']))
12 years ago
error('Plain-text authentication failed.');
break;
default:
error('Unknown authentication method: "' . $this->auth['method'] . '".');
}
}
public function write($data, $remote_path) {
global $config;
12 years ago
switch ($this->type) {
12 years ago
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.');
}
12 years ago
}
};