I used to use https://github.com/BenMenking/routeros-api PHP class to access ROS API over the net.
It was quite well approach until I tried to use SSL protected link. I activated API-SSL in the device configuration (I used the same certificate I used to set up OVPN client), changed my code that try to access the API over SSL… nope, no luck:
PHP Warning: fsockopen(): SSL: Connection reset by peer in routeros_api.class.php on line 111
PHP Warning: fsockopen(): Failed to enable crypto in routeros_api.class.php on line 111
PHP Warning: fsockopen(): unable to connect to ssl://hostname:8729 (Unknown error) in routeros_api.class.php on line 111
I tried several PHP versions (5.5, 5.6), no luck as well.
The code associated is the following:
$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);
(I’ve stripped @ from the beginning of fsockopen)
I tried to add the following:
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'allow_self_signed' => true,
'verify_peer_name' => false
]
];
$context = stream_context_create($contextOptions);
right before fsockopen call, and it won’t helped, too.
Have you ever seen that problem? Is there any way to get over it? I suspect this is not a PHP problem, but this is not a ROS problem, too - but theit mutual “misunderstanding”.