PHP Class TorControl\TorControl

Control a Tor server using the socket connection. The spec of the control protocol: https://gitweb.torproject.org/torspec.git/blob_plain/HEAD:/control-spec.txt
Author: Kévin Dunglas ([email protected])
Mostrar archivo Open project: dunglas/php-torcontrol Class Usage Examples

Protected Properties

Property Type Description
$connected boolean Connected.
$defautOptions array Default options.
$options array Options.
$socket resource Socket to the TOR server.

Public Methods

Method Description
__construct ( array $options = [] ) Creates a new instance of the controller.
__destruct ( ) Destructs the instance.
authenticate ( ) : TorControl Authenticates to the Tor server.
connect ( ) : TorControl Connects to the Tor server.
executeCommand ( string $cmd ) : array Executes a command on the Tor server.
getOption ( string $key ) : mixed Gets an option.
isConnected ( ) : boolean Gets the controller connection status.
quit ( ) Closes the connection to the Tor server.
quote ( string $str ) : string Quotes and escapes to use in a command.

Private Methods

Method Description
checkConnected ( ) Check if connected.
detectAuthMethod ( ) Detects auth method using the PROTOCOLINFO command.

Method Details

__construct() public method

Creates a new instance of the controller.
public __construct ( array $options = [] )
$options array Configuration settings All settings are optional. - hostname: server to join (default: 127.0.0.1) - port: port to try (default: 9051) - authmethod: connection method (if not set will try to autodetect) Allowed values: - TorControl::AUTH_METHOD_NULL: no security - TorControl::AUTH_METHOD_HASHEDPASSWORD: password - TorControl::AUTH_METHOD_COOKIE: cookie file - password: the password (mandatory if AUTH_METHOD_HASHEDPASSWORD is used) - cookiefile: the file (if TorControl::AUTH_METHOD_COOKIE is used, if not set will autodetect) - timeout: connection timeout (default: default_socket_timeout's PHP setting)

__destruct() public method

Destructs the instance.
public __destruct ( )

authenticate() public method

Autodetect authentication method if not set in options
public authenticate ( ) : TorControl
return TorControl

connect() public method

Connects to the Tor server.
public connect ( ) : TorControl
return TorControl

executeCommand() public method

Executes a command on the Tor server.
public executeCommand ( string $cmd ) : array
$cmd string
return array

getOption() public method

Gets an option.
public getOption ( string $key ) : mixed
$key string
return mixed

isConnected() public method

Gets the controller connection status.
public isConnected ( ) : boolean
return boolean

quit() public method

Closes the connection to the Tor server.
public quit ( )

quote() public static method

Quotes and escapes to use in a command.
public static quote ( string $str ) : string
$str string
return string

Property Details

$connected protected_oe property

Connected.
protected bool $connected
return boolean

$defautOptions protected_oe static_oe property

Default options.
protected static array $defautOptions
return array

$options protected_oe property

Options.
protected array $options
return array

$socket protected_oe property

Socket to the TOR server.
protected resource $socket
return resource