PHP Class RouterosAPI, routeros-api

RouterOS PHP API class v1.6 Author: Denis Basta Contributors: Nick Barnes Ben Menking (ben [at] infotechsc [dot] com) Jeremy Jefferson (http://jeremyj.com) Cristian Deluxe (djcristiandeluxe [at] gmail [dot] com) Mikhail Moskalev (mmv.rus [at] gmail [dot] com) http://www.mikrotik.com http://wiki.mikrotik.com/wiki/API_PHP_class ****************************
Show file Open project: BenMenking/routeros-api Class Usage Examples

Public Properties

Property Type Description
$attempts Connection attempt timeout and data read timeout
$connected Show debug information
$debug
$delay Connection attempt count
$error_no Variable for storing socket resource
$error_str Variable for storing connection error number, if any
$port Connection state
$socket Delay between connection attempts in seconds
$ssl Port to connect to (default 8729 for ssl)
$timeout Connect using SSL (must enable api-ssl in IP/Services)

Public Methods

Method Description
__destruct ( ) : void Standard destructor
arrayChangeKeyName ( array &$array ) : array Change "-" and "/" from array key to "_"
comm ( string $com, array $arr = [] ) : array Write (send) data to Router OS
connect ( string $ip, string $login, string $password ) : boolean Login to RouterOS
debug ( string $text ) : void Print text for debug purposes
disconnect ( ) : void Disconnect from RouterOS
encodeLength ( string $length ) : void
isIterable ( $var ) * Check, can be var used in foreach
parseResponse ( array $response ) : array Parse response from Router OS
parseResponse4Smarty ( array $response ) : array Parse response from Router OS
read ( boolean $parse = true ) : array Read data from Router OS
write ( string $command, mixed $param2 = true ) : boolean Write (send) data to Router OS

Method Details

__destruct() public method

Standard destructor
public __destruct ( ) : void
return void

arrayChangeKeyName() public method

Change "-" and "/" from array key to "_"
public arrayChangeKeyName ( array &$array ) : array
$array array Input array
return array Array with changed key names

comm() public method

Write (send) data to Router OS
public comm ( string $com, array $arr = [] ) : array
$com string A string with the command to send
$arr array An array with arguments or queries
return array Array with parsed

connect() public method

Login to RouterOS
public connect ( string $ip, string $login, string $password ) : boolean
$ip string Hostname (IP or domain) of the RouterOS server
$login string The RouterOS username
$password string The RouterOS password
return boolean If we are connected or not

debug() public method

Print text for debug purposes
public debug ( string $text ) : void
$text string Text to print
return void

disconnect() public method

Disconnect from RouterOS
public disconnect ( ) : void
return void

encodeLength() public method

public encodeLength ( string $length ) : void
$length string
return void

isIterable() public method

* Check, can be var used in foreach
public isIterable ( $var )

parseResponse() public method

Parse response from Router OS
public parseResponse ( array $response ) : array
$response array Response data
return array Array with parsed data

parseResponse4Smarty() public method

Parse response from Router OS
public parseResponse4Smarty ( array $response ) : array
$response array Response data
return array Array with parsed data

read() public method

Read data from Router OS
public read ( boolean $parse = true ) : array
$parse boolean Parse the data? default: true
return array Array with parsed or unparsed data

write() public method

Write (send) data to Router OS
public write ( string $command, mixed $param2 = true ) : boolean
$command string A string with the command to send
$param2 mixed If we set an integer, the command will send this data as a "tag" If we set it to boolean true, the funcion will send the comand and finish If we set it to boolean false, the funcion will send the comand and wait for next command Default: true
return boolean Return false if no command especified

Property Details

$attempts public property

Connection attempt timeout and data read timeout
public $attempts

$connected public property

Show debug information
public $connected

$debug public property

public $debug

$delay public property

Connection attempt count
public $delay

$error_no public property

Variable for storing socket resource
public $error_no

$error_str public property

Variable for storing connection error number, if any
public $error_str

$port public property

Connection state
public $port

$socket public property

Delay between connection attempts in seconds
public $socket

$ssl public property

Port to connect to (default 8729 for ssl)
public $ssl

$timeout public property

Connect using SSL (must enable api-ssl in IP/Services)
public $timeout