Skip to content

Commit

Permalink
ResponseCollection::toArray() now also checks whether the responses a…
Browse files Browse the repository at this point in the history
…re indexed, to avoid undefined index notices;

Charset conversion is now disabled for the new login method during the sending of the login message, which makes ANSI passwords work properly with it;

CS fixes.
  • Loading branch information
boenrobot committed Oct 19, 2019
1 parent 3c0125d commit a03e1ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/PEAR2/Net/RouterOS/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,14 @@ private static function _login(
$request = new Request('/login');
$request->setArgument('name', $username);
$request->setArgument('password', $password);
$oldCharset = $com->getCharset($com::CHARSET_ALL);
$com->setCharset(null, $com::CHARSET_ALL);
$request->verify($com)->send($com);
$com->setCharset($oldCharset, $com::CHARSET_ALL);
$response = new Response($com, false, $timeout);
if ($response->getType() === Response::TYPE_FINAL && null === $response->getProperty('ret')) {
if ($response->getType() === Response::TYPE_FINAL
&& null === $response->getProperty('ret')
) {
// version >= 6.43
return null === $response->getProperty('message');
} elseif ($response->getType() === Response::TYPE_FINAL) {
Expand All @@ -301,7 +306,12 @@ private static function _login(
'response',
'00' . md5(
chr(0) . $password
. pack('H*', is_string($response->getProperty('ret')) ? $response->getProperty('ret') : stream_get_contents($response->getProperty('ret')))
. pack(
'H*',
is_string($response->getProperty('ret'))
? $response->getProperty('ret')
: stream_get_contents($response->getProperty('ret'))
)
)
);
$request->verify($com)->send($com);
Expand All @@ -327,7 +337,7 @@ private static function _login(
* {@link Communicator::CHARSET_REMOTE}, and when receiving,
* {@link Communicator::CHARSET_REMOTE} is converted to
* {@link Communicator::CHARSET_LOCAL}. Setting NULL to either charset will
* disable charset convertion, and data will be both sent and received "as
* disable charset conversion, and data will be both sent and received "as
* is".
*
* @param mixed $charset The charset to set. If $charsetType is
Expand Down Expand Up @@ -392,7 +402,7 @@ public function sendAsync(Request $request, $callback = null)
{
//Error checking
$tag = $request->getTag();
if ('' == $tag) {
if ('' === (string)$tag) {
throw new DataFlowException(
'Asynchonous commands must have a tag.',
DataFlowException::CODE_TAG_REQUIRED
Expand Down Expand Up @@ -652,7 +662,7 @@ public function getPendingRequestsCount()
public function cancelRequest($tag = null)
{
$cancelRequest = new Request('/cancel');
$hasTag = !('' == $tag);
$hasTag = !('' === (string)$tag);
$hasReg = null !== $this->registry;
if ($hasReg && !$hasTag) {
$tags = array_merge(
Expand Down Expand Up @@ -856,7 +866,7 @@ protected function dispatchNextResponse($sTimeout = 0, $usTimeout = 0)
$this->pendingRequestsCount--;
}

if ('' != $tag) {
if ('' !== (string)$tag) {
if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
if ($this->callbacks[$tag]($response, $this)) {
try {
Expand Down
4 changes: 3 additions & 1 deletion src/PEAR2/Net/RouterOS/ResponseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ public function getIndex()
public function toArray($flags = self::ARRAY_DEFAULT)
{
$result = $this->responses;
if (($flags & self::ARRAY_INDEXED) === self::ARRAY_INDEXED) {
if (($flags & self::ARRAY_INDEXED) === self::ARRAY_INDEXED
&& null !== $this->index
) {
$positions = $this->responsesIndex[$this->index];
asort($positions, SORT_NUMERIC);
$positions = array_flip($positions);
Expand Down

0 comments on commit a03e1ce

Please sign in to comment.