Skip to content

Commit

Permalink
Added SSL functionality
Browse files Browse the repository at this point in the history
Added class boolean variable $ssl.
Changed connect method to use SSL for connections if $ssl is set to true.
api-ssl must be enabled on the routeros config under /IP/Services and uses port 8729 by default.
  • Loading branch information
Shinra Dev Team committed Mar 5, 2016
1 parent 36c6dae commit 2ad25d3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions routeros_api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class RouterosAPI
{
var $debug = false; // Show debug information
var $connected = false; // Connection state
var $port = 8728; // Port to connect to
var $port = 8728; // Port to connect to (default 8729 for ssl)
var $ssl = false; // Connect using SSL (must enable api-ssl in IP/Services)
var $timeout = 3; // Connection attempt timeout and data read timeout
var $attempts = 5; // Connection attempt count
var $delay = 3; // Delay between connection attempts in seconds
Expand Down Expand Up @@ -95,8 +96,9 @@ public function connect($ip, $login, $password)
{
for ($ATTEMPT = 1; $ATTEMPT <= $this->attempts; $ATTEMPT++) {
$this->connected = false;
$this->debug('Connection attempt #' . $ATTEMPT . ' to ' . $ip . ':' . $this->port . '...');
$this->socket = @fsockopen($ip, $this->port, $this->error_no, $this->error_str, $this->timeout);
$PROTOCOL = ($this->ssl ? 'ssl://' : '' );
$this->debug('Connection attempt #' . $ATTEMPT . ' to ' . $PROTOCOL . $ip . ':' . $this->port . '...');
$this->socket = @fsockopen($PROTOCOL . $ip, $this->port, $this->error_no, $this->error_str, $this->timeout);
if ($this->socket) {
socket_set_timeout($this->socket, $this->timeout);
$this->write('/login');
Expand Down

0 comments on commit 2ad25d3

Please sign in to comment.