GideonLeGrange / mikrotik-java

A Java client implementation for the Mikrotik RouterOS API.
Apache License 2.0
181 stars 101 forks source link

Problem to remove active users command #10

Closed jeanpablojp closed 10 years ago

jeanpablojp commented 10 years ago

I'm trying to remove active users from hotspot but its not working. I've tried this commands:

(I need to remove all the active users from hotspot where the field user="teste")

This works on mikrotik: /ip hotspot active remove [find user="teste"]

Using the API i've tried: /ip/hotspot/active/remove [find user='teste'] /ip/hotspot/active/remove user='teste' /ip/hotspot/active/remove [find user=\"teste\"] /ip/hotspot/active/remove user=\"teste\"

There is a bug or limitation here or i'm doing something wrong here???

Thanks in advance.

GideonLeGrange commented 10 years ago

What happens? Does it simply do nothing, or does it generate an error?

GideonLeGrange commented 10 years ago

I've looked this up, and unfortunately you won't be able to use the 'find' command from the API. This not a restriction of my library, but of the underlying RouterOS API.

On this page http://wiki.mikrotik.com/wiki/API_command_notes they simply say:

Note: Find command have many constructs that are part of scripting, thus not available through API

You should however be able to delete the users by retrieving their information and issuing a delete command for the user's unique .id or name, or by just deleting them by name.

Example that should work:

con.execute("/ip/hotspot/user/remove .id=joe")

Example that will work:

Example:

        List<Map<String, String>> res = con.execute("/ip/hotspot/active/print where name=teste");
        for (Map<String, String> attr : res) {
            String id = attr.get(".id");
            con.execute("/ip/hotspot/active/remove .id=" + id);
        }
    }
GideonLeGrange commented 10 years ago

Issue closed. Not a bug, but design feature of underlying API.

KostasC22 commented 9 years ago

I am little confused here. To me neither of this is working: Example that should work:

con.execute("/ip/hotspot/user/remove .id=joe")

Example that will work:

Example:

    List<Map<String, String>> res = con.execute("/ip/hotspot/active/print where name=teste");
    for (Map<String, String> attr : res) {
        String id = attr.get(".id");
        con.execute("/ip/hotspot/active/remove .id=" + id);
    }
}
KostasC22 commented 9 years ago

I found what my problem was instead of "/ip/hotspot/active/print where name=teste", you must have "/ip/hotspot/active/print where user=teste" Thanks!