Mikrotik:使用PHP API更改usermanager用户密码

时间:2017-04-05 20:44:43

标签: php api mikrotik

我试图创建一个可以使用PHP API更改用户密码的PHP代码,这是我目前的代码:

<?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();
}
?>

当我运行此代码时,它似乎只返回我搜索的用户名,但密码没有变化。有什么帮助吗?

1 个答案:

答案 0 :(得分: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');