lib/3rdParty/phpseclib/Net/SSH2.php

Properties

Description

Pure-PHP implementation of SSHv2.

PHP versions 4 and 5 Here are some examples of how to use this library: login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> setPassword('whatever'); $key->loadKey(file_get_contents('privatekey')); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', $key)) { exit('Login Failed'); } echo $ssh->read('username@username:~$'); $ssh->write("ls -la\n"); echo $ssh->read('username@username:~$'); ?> LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Constants

  NET_SSH2_MASK_CONSTRUCTOR = 1




  NET_SSH2_MASK_LOGIN = 2




  NET_SSH2_MASK_SHELL = 4




  NET_SSH2_CHANNEL_EXEC = 0




  NET_SSH2_CHANNEL_SHELL = 1




  NET_SSH2_LOG_SIMPLE = 1

Returns the message numbers


  NET_SSH2_LOG_COMPLEX = 2

Returns the message content


  NET_SSH2_READ_SIMPLE = 1

Returns when a string matching $expect exactly is found


  NET_SSH2_READ_REGEX = 2

Returns when a string matching the regular expression $expect is found


  $value = $key




Classes

Net_SSH2

Properties

 
 
public  
0.1.0  
No 
No 

Description

Pure-PHP implementation of SSHv2.

Methods

Net_SSH2, __destruct, _close_channel, _define_array, _disconnect, _filter, _format_log, _get_binary_packet, _get_channel_packet, _initShell, _key_exchange, _keyboard_interactive_login, _keyboard_interactive_process, _send_binary_packet, _send_channel_packet, _string_shift, disconnect, exec, getCompressionAlgorithmsClient2Server, getCompressionAlgorithmsServer2Client, getEncryptionAlgorithmsClient2Server, getEncryptionAlgorithmsServer2Client, getErrors, getKexAlgorithms, getLanguagesClient2Server, getLanguagesServer2Client, getLastError, getLog, getMACAlgorithmsClient2Server, getMACAlgorithmsServer2Client, getServerHostKeyAlgorithms, getServerIdentification, getServerPublicHostKey, read, write,

Net_SSH2( String   $host,   $port = 22,   $timeout = 10, ) : \Net_SSH2

Description

Default Constructor.
Connects to an SSHv2 server

Arguments

Name Type Description Default
$host String
$port n/a 22
$timeout n/a 10

Return value

Type Description
\Net_SSH2

Tags

Name Description
access public

__destruct( ) : n/a

Description

Destructor.
Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call disconnect().

Return value

Type Description
n/a n/a

Tags

Name Description
access public

_close_channel( Integer   $client_channel, ) : Boolean

Description

Closes and flushes a channel
Net_SSH2 doesn't properly close most channels. For exec() channels are normally closed by the server and for SFTP channels are presumably closed when the client disconnects. This functions is intended for SCP more than anything.

Arguments

Name Type Description Default
$client_channel Integer

Return value

Type Description
Boolean

Tags

Name Description
access private

_define_array( ) : n/a

Description

Define Array
Takes any number of arrays whose indices are integers and whose values are strings and defines a bunch of named constants from it, using the value as the name of the constant and the index as the value of the constant. If any of the constants that would be defined already exists, none of the constants will be defined.

Return value

Type Description
n/a n/a

Tags

Name Description
access private

_disconnect( Integer   $reason, ) : Boolean

Description

Disconnect

Arguments

Name Type Description Default
$reason Integer

Return value

Type Description
Boolean

Tags

Name Description
access private

_filter(   $payload, ) : String

Description

Filter Binary Packets
Because some binary packets need to be ignored...

Arguments

Name Type Description Default
$payload n/a

Return value

Type Description
String

Tags

Name Description
see
access private

_format_log( Array   $message_log, Array   $message_number_log, ) : String

Description

Formats a log for printing

Arguments

Name Type Description Default
$message_log Array
$message_number_log Array

Return value

Type Description
String

Tags

Name Description
access private

_get_binary_packet( ) : String

Description

Gets Binary Packets
See '6. Binary Packet Protocol' of rfc4253 for more info.

Return value

Type Description
String

Tags

Name Description
see
access private

_get_channel_packet(   $client_channel,   $skip_extended = false, ) : Mixed

Description

Gets channel data
Returns the data as a string if it's available and false if not.

Arguments

Name Type Description Default
$client_channel n/a
$skip_extended n/a false

Return value

Type Description
Mixed

Tags

Name Description
access private

_initShell( ) : Boolean

Description

Creates an interactive shell

Return value

Type Description
Boolean

Tags

Name Description
see
see
access private

_key_exchange( String   $kexinit_payload_server, ) : n/a

Description

Key Exchange

Arguments

Name Type Description Default
$kexinit_payload_server String

Return value

Type Description
n/a n/a

Tags

Name Description
access private

_keyboard_interactive_login( String   $username, String   $password, ) : Boolean

Description

Login via keyboard-interactive authentication
See {@link http://tools.ietf.org/html/rfc4256 RFC4256} for details. This is not a full-featured keyboard-interactive authenticator.

Arguments

Name Type Description Default
$username String
$password String

Return value

Type Description
Boolean

Tags

Name Description
access private

_keyboard_interactive_process( ) : Boolean

Description

Handle the keyboard-interactive requests / responses.

Return value

Type Description
Boolean

Tags

Name Description
access private

_send_binary_packet( String   $data, ) : Boolean

Description

Sends Binary Packets
See '6. Binary Packet Protocol' of rfc4253 for more info.

Arguments

Name Type Description Default
$data String

Return value

Type Description
Boolean

Tags

Name Description
see
access private

_send_channel_packet( Integer   $client_channel, String   $data, ) : Boolean

Description

Sends channel data
Spans multiple SSH_MSG_CHANNEL_DATAs if appropriate

Arguments

Name Type Description Default
$client_channel Integer
$data String

Return value

Type Description
Boolean

Tags

Name Description
access private

_string_shift( String   $string,   $index = 1, ) : String

Description

String Shift
Inspired by array_shift

Arguments

Name Type Description Default
$string String
$index n/a 1

Return value

Type Description
String

Tags

Name Description
access private

disconnect( ) : n/a

Description

Disconnect

Return value

Type Description
n/a n/a

Tags

Name Description
access public

exec( String   $command,   $block = true, ) : String

Description

Execute Command
If $block is set to false then Net_SSH2::_get_channel_packet(NET_SSH2_CHANNEL_EXEC) will need to be called manually. In all likelihood, this is not a feature you want to be taking advantage of.

Arguments

Name Type Description Default
$command String
$block n/a true

Return value

Type Description
String

Tags

Name Description
access public

getCompressionAlgorithmsClient2Server( ) : Array

Description

Return a list of the compression algorithms the server supports, when receiving stuff from the client.

Return value

Type Description
Array

Tags

Name Description
access public

getCompressionAlgorithmsServer2Client( ) : Array

Description

Return a list of the compression algorithms the server supports, when sending stuff to the client.

Return value

Type Description
Array

Tags

Name Description
access public

getEncryptionAlgorithmsClient2Server( ) : Array

Description

Return a list of the (symmetric key) encryption algorithms the server supports, when receiving stuff from the client.

Return value

Type Description
Array

Tags

Name Description
access public

getEncryptionAlgorithmsServer2Client( ) : Array

Description

Return a list of the (symmetric key) encryption algorithms the server supports, when sending stuff to the client.

Return value

Type Description
Array

Tags

Name Description
access public

getErrors( ) : String

Description

Returns all errors

Return value

Type Description
String

Tags

Name Description
access public

getKexAlgorithms( ) : Array

Description

Return a list of the key exchange algorithms the server supports.

Return value

Type Description
Array

Tags

Name Description
access public

getLanguagesClient2Server( ) : Array

Description

Return a list of the languages the server supports, when receiving stuff from the client.

Return value

Type Description
Array

Tags

Name Description
access public

getLanguagesServer2Client( ) : Array

Description

Return a list of the languages the server supports, when sending stuff to the client.

Return value

Type Description
Array

Tags

Name Description
access public

getLastError( ) : String

Description

Returns the last error

Return value

Type Description
String

Tags

Name Description
access public

getLog( ) : String

Description

Returns a log of the packets that have been sent and received.
Returns a string if NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX, an array if NET_SSH2_LOGGING == NET_SSH2_LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING')

Return value

Type Description
String or Array

Tags

Name Description
access public

getMACAlgorithmsClient2Server( ) : Array

Description

Return a list of the MAC algorithms the server supports, when receiving stuff from the client.

Return value

Type Description
Array

Tags

Name Description
access public

getMACAlgorithmsServer2Client( ) : Array

Description

Return a list of the MAC algorithms the server supports, when sending stuff to the client.

Return value

Type Description
Array

Tags

Name Description
access public

getServerHostKeyAlgorithms( ) : Array

Description

Return a list of the host key (public key) algorithms the server supports.

Return value

Type Description
Array

Tags

Name Description
access public

getServerIdentification( ) : String

Description

Return the server identification.

Return value

Type Description
String

Tags

Name Description
access public

getServerPublicHostKey( ) : Mixed

Description

Returns the server public host key.
Caching this the first time you connect to a server and checking the result on subsequent connections is recommended. Returns false if the server signature is not signed correctly with the public host key.

Return value

Type Description
Mixed

Tags

Name Description
access public

read( String   $expect, Integer   $mode = NET_SSH2_READ_SIMPLE, ) : String

Description

Returns the output of an interactive shell
Returns when there's a match for $expect, which can take the form of a string literal or, if $mode == NET_SSH2_READ_REGEX, a regular expression.

Arguments

Name Type Description Default
$expect String
$mode Integer NET_SSH2_READ_SIMPLE

Return value

Type Description
String

Tags

Name Description
see
access public

write( String   $cmd, ) : Boolean

Description

Inputs a command into an interactive shell.

Arguments

Name Type Description Default
$cmd String

Return value

Type Description
Boolean

Tags

Name Description
see
access public

Properties

$bitmap, $channel_buffers, $channel_extended_data_type_codes, $channel_open_failure_reasons, $channel_status, $compression_algorithms_client_to_server, $compression_algorithms_server_to_client, $decrypt, $decrypt_block_size, $disconnect_reasons, $encrypt, $encrypt_block_size, $encryption_algorithms_client_to_server, $encryption_algorithms_server_to_client, $errors, $exchange_hash, $fsock, $get_seq_no, $hmac_check, $hmac_create, $hmac_size, $identifier, $interactiveBuffer, $kex_algorithms, $languages_client_to_server, $languages_server_to_client, $mac_algorithms_client_to_server, $mac_algorithms_server_to_client, $message_log, $message_number_log, $message_numbers, $packet_size_client_to_server, $send_seq_no, $server_channels, $server_host_key_algorithms, $server_identifier, $server_public_host_key, $session_id, $signature, $signature_format, $terminal_modes, $window_size, $window_size_client_to_server,

Integer  public  $bitmap = 0

Execution Bitmap
The bits that are set reprsent functions that have been called already. This is used to determine if a requisite function has been successfully executed. If not, an error should be thrown.

Array  public  $channel_buffers = array()

Channel Buffers
If a client requests a packet from one channel but receives two packets from another those packets should be placed in a buffer

Array  public  $channel_extended_data_type_codes = array()

SSH_MSG_CHANNEL_EXTENDED_DATA's data_type_codes


Array  public  $channel_open_failure_reasons = array()

SSH_MSG_CHANNEL_OPEN_FAILURE 'reason codes', defined in RFC4254


Array  public  $channel_status = array()

Channel Status
Contains the type of the last sent message

Array  public  $compression_algorithms_client_to_server =

Compression Algorithms: Client to Server


Array  public  $compression_algorithms_server_to_client =

Compression Algorithms: Server to Client


Object  public  $decrypt = false

Server to Client Encryption Object


Integer  public  $decrypt_block_size = 8

Block Size for Client to Server Encryption


Array  public  $disconnect_reasons = array()

Disconnection Message 'reason codes' defined in RFC4253


Object  public  $encrypt = false

Client to Server Encryption Object


Integer  public  $encrypt_block_size = 8

Block Size for Server to Client Encryption
"Note that the length of the concatenation of 'packet_length', 'padding_length', 'payload', and 'random padding' MUST be a multiple of the cipher block size or 8, whichever is larger. This constraint MUST be enforced, even when using stream ciphers." -- http://tools.ietf.org/html/rfc4253#section-6

Array  public  $encryption_algorithms_client_to_server =

Encryption Algorithms: Client to Server


Array  public  $encryption_algorithms_server_to_client =

Encryption Algorithms: Server to Client


String  public  $errors = array()

Error information


String  public  $exchange_hash = false

Exchange hash
The current exchange hash

Object  public  $fsock =

The Socket Object


Integer  public  $get_seq_no = 0

Get Sequence Number
See 'Section 6.4. Data Integrity' of rfc4253 for more info.

Object  public  $hmac_check = false

Server to Client HMAC Object


Object  public  $hmac_create = false

Client to Server HMAC Object


Integer  public  $hmac_size = false

Size of server to client HMAC
We need to know how big the HMAC will be for the server to client direction so that we know how many bytes to read. For the client to server side, the HMAC object will make the HMAC as long as it needs to be. All we need to do is append it.

String  public  $identifier = 'SSH-2.0-phpseclib_0.2'

The SSH identifier


Array  public  $interactiveBuffer = ''

Interactive Buffer


Array  public  $kex_algorithms =

Key Exchange Algorithms


Array  public  $languages_client_to_server =

Languages: Client to Server


Array  public  $languages_server_to_client =

Languages: Server to Client


Array  public  $mac_algorithms_client_to_server =

MAC Algorithms: Client to Server


Array  public  $mac_algorithms_server_to_client =

MAC Algorithms: Server to Client


Array  public  $message_log = array()

Message Log


Array  public  $message_number_log = array()

Message Number Log


Array  public  $message_numbers = array()

Message Numbers


Array  public  $packet_size_client_to_server = array()

Packet Size
Maximum packet size indexed by channel

Integer  public  $send_seq_no = 0

Send Sequence Number
See 'Section 6.4. Data Integrity' of rfc4253 for more info.

Array  public  $server_channels = array()

Server Channels
Maps client channels to server channels

Array  public  $server_host_key_algorithms =

Server Host Key Algorithms


String  public  $server_identifier = ''

Server Identifier


String  public  $server_public_host_key =

Server Public Host Key


String  public  $session_id = false

Session identifer
"The exchange hash H from the first key exchange is additionally used as the session identifier, which is a unique identifier for this connection." -- http://tools.ietf.org/html/rfc4253#section-7.2

String  public  $signature = ''

Server signature
Verified against $this->session_id

String  public  $signature_format = ''

Server signature format
ssh-rsa or ssh-dss.

Array  public  $terminal_modes = array()

Terminal Modes


Integer  public  $window_size = 2147483647

The Window Size
Bytes the other party can send before it must wait for the window to be adjusted (0x7FFFFFFF = 4GB)

Array  public  $window_size_client_to_server = array()

Window size
Window size indexed by channel

Documentation was generated by phpDocumentor 2.1.0 .

Namespaces

  • global

    Packages