3

I'm building a WiFi authentication tool with user profile edit and guest credentials, etc.

I can write users to the mikrotik and remove users without an issue, but I can't find any documentation on editing the user profile. I suppose I could just remove it and add a new record, but that is just inefficient and may create issues with user keys down the line.

I'm using class.routeros_api.php and I'm on version 6.30

To add a user is done like so...

$response = $api->comm("/tool/user-manager/user/add",array(
    "customer"          => "admin",
    "username"          => "guest_user",
    "location"          => "Guest",
    "first-name"        => "Guest",
    "last-name"         => "1",
    "password"          => "somepw",
    "shared-users"      => "1",
    "copy-from"         => "00:00:00:00:00:00"
));

Deleting a user...

$response = $api->comm("/tool/user-manager/user/remove",array(
    ".id"               => "*15"
));

so I figured editing a user would be something like...

$response = $api->comm("/tool/user-manager/user/edit",array(
    ".id"               => "*15",
    "username"          => "someotheruser",
    "password"          => "someotherpass"
));

However, the error I'm receiving is...

<<< [28] /tool/user-manager/user/edit 
<<< [8] =.id=*14 
<<< [14] =username=someotheruser
<<< [19] =password=someotherpass

>>> [5/5] bytes read. 
>>> [5, 35]!trap 
>>> [26/26] bytes read. 
>>> [26, 8]=message=unknown parameter 
>>> [5/5] bytes read. 
>>> [5, 1]!done

If someone has done this before and can assist with the appropriate syntax for the "/tool/user-manager/user/edit" command, it would be greatly appreciated.

zgr024
  • 1,111
  • 11
  • 24
  • 1
    I don't have access to my Mikrotik test router right now but either the edit command or one of the parameters you are passing is not valid. To figure out what commands and parameters are available, connect via WinBox, open a terminal window and type `/tool/user-manager/user [TAB]` and it will list the available commands. You can then get the parameter list by typing the command and `[TAB]` again. – drew010 Jul 29 '15 at 17:19
  • Here is an example for the built in users: `[admin@demo] > /user edit [TAB]` shows: `admin root john number value-name`, then doing `/user edit admin [TAB]` shows: `address comment group name password value-name` which are the parameters you can set for editing the user `admin`. Hope that helps for now. These then can be translated to API commands and parameters you can use in your code. – drew010 Jul 29 '15 at 17:20
  • But that doesn't give me the syntax for the API on what to pass as the second parameter – zgr024 Jul 29 '15 at 17:37
  • I can edit... `caller-id, first-name, phone, username, caller-id-bind-on-first-use, ip-address, random-password, wireless-enc-algo, comment, last-name, reg-key, wireless-enc-key, customer, location, registration-date, wireless-psk, email, password, & shared-users` but the syntax for the API is still unknown – zgr024 Jul 29 '15 at 18:10

1 Answers1

6

So after some research into how this thing actually works, it appears I was just using the wrong command.

The correct way to edit a user on the mikrotik is to do the following...

$api->comm("/tool/user-manager/user/set",array(
    ".id"               => "*14",
    "username"          => "somenewuser"
    "password"          => "somenewpassword",
));

In fact, "set" is the way you post edits for every feature. "edit" is for multi-line editing.

Special thanks to drew010 for the WinBox idea and the link to the commands wiki.

zgr024
  • 1,111
  • 11
  • 24
  • 1
    Yup I just found that `set` is the proper command too :) edit is for multi-line editing on the terminal: http://wiki.mikrotik.com/wiki/Manual:Console#General_Commands – drew010 Jul 29 '15 at 19:57