-1

I'm trying to create a PHP code that can change a user password using PHP API, here is my code so far:

<?php

require('routeros_api.class.php');

$API = new routerosAPI();

$API->debug = true;

if ($API->connect('192.168.0.101', 'user', 'password')) {

  $API->write('/tool/user-manager/user/getall', false);
    $API->write('=.proplist=username', false);
    $API->write('?username=john');
    $API->write('/tool/user-manager/user/set',false);
    $API->write('password=4321');    

  $READ = $API->read(false);
  $ARRAY = $API->parseResponse($READ);
  print_r($ARRAY);
   $API->disconnect();
}
?>

When I run this code it appears to only return the username I'm searching but the password doesn't change. Any help?

evertjr
  • 3
  • 1
  • 3
  • Please submit the API you are using as well. We will not know what API does with this request you are sending. – serdar.sanri Apr 05 '17 at 20:52
  • @guyfawkes From the tag and his code he seems to be using the [Mikrotik RouterOS PHP API](https://wiki.mikrotik.com/wiki/API_PHP_class). – Seanny123 Apr 06 '17 at 01:27
  • @guyfawkes I'm using this API https://github.com/BenMenking/routeros-api – evertjr Apr 06 '17 at 15:46
  • hmm, I am not 100% sure but looking at their documentation, each process seems to have a read following. Did you try to add `$API->read(false);` after you have username line? Logically, it seems like, you need to get the user first then send another request to change password. – serdar.sanri Apr 06 '17 at 16:12

1 Answers1

0

You are using incorrect commands. I was not using PHP API, so some parts will be described by words instead of code.

First of all you need to get ID of the record to edit. If username is john, it will be:

$API->write('/tool/user-manager/user/print', false);
$API->write('=.proplist=.id', false);
$API->write('?username=john');

Read and parse response. For example returned .id is *1. Use this to change password:

$API->write('/tool/user-manager/user/set', false);
$API->write('=.id=*1', false);
$API->write('=password=new_pass');
Uladzimir Palekh
  • 1,846
  • 13
  • 16