Extract from Usermanager login, password, date of disconnect

Hello, I use usermanager interested of the script to retrieve the login, password, service plan, and the date of disconnection, now doing just sending a file to a backup database on your mail, but then move this database to another mikrotik I have not come out, which is interested in the script just might save the data from UserManager the format of:

login;password;serviceplan;dateofdisconnection

Example:

12345;54321;5mbit;07.15.2014
34D23;34122;5mbit;07.19.2014
34D23;3AA22;2mbit;07.30.2014

You can use API!

Using PHP PEAR2 API you can do something like this:

try {
$client = new RouterOS\Client('YOUR_IP_HERE', 'YOUR_USERNAME_HERE', 'YOUR_PASSWORD_HERE', null, false, 5, Transmitter\NetworkStream::CRYPTO_TLS);
} catch (\Exception $e) {
echo $e->getMessage();
}
$username = 'USERNAME_TO_READ_HERE';
$last_seen = $client->sendSync(new RouterOS\Request('/tool user-manager user get number='.$username.' value-name=last-seen'))->getArgument('ret'); 

echo $last_seen;

You can get all you want about each user, or you can also get a list of all your users with this request:
/tool/user-manager/user/print

The parameters you need are:
name, password, actual-profile, last-seen

Note that if you need to fetch several pieces of information at once (even if for a single user), not only can you, but also should, use “print” instead of “get”.

So:

$user = $client->sendSync(new RouterOS\Request('/tool user-manager user print', RouterOS\Query::where('name', $username)));

$password = $user('password');
$actual_profile = $user('actual-profile');
$last_seen = $user('last-seen'); 

Or to get all:

$users = $client->sendSync(new RouterOS\Request('/tool user-manager user print'))->getAllOfType(RouterOS\Response::TYPE_DATA);
foreach ($users as $user) {
    $username = $user('name');
    $password = $user('password');
    $actual_profile = $user('actual-profile');
    $last_seen = $user('last-seen');

    // Do what you will with each user's data
} 

I have to install php or perl on RouterOS(I have not long started to use routeros and do not know all of its packages)?

I want to have all of these data in a single file.

cat somefile.txt
12345;54321;5mbit;07.15.2014
34D23;34122;5mbit;07.19.2014
34D23;3AA22;2mbit;07.30.2014

last-seen - this time, to which the user account is valid? My vouchers have time limitations 4w2d, I need the date to which the my vouchers are valid(in user manager i have not found time limit for my vouchers), thank you very much.

No. You have to install PHP on the backup server. You can’t install PHP on RouterOS even if you wanted to.

I thought you said you want it in a backup database (you know, as in MySQL, PostgreSQL, MSSQL, etc.)… in which case, this is the best way to do it.

If you want it in a file that you then email, you’d have to use the “/tool email send” command, and the email will just receive the raw file that you’d then have to manually parse out if you want it in a database. If you instead have an API application, you can skip the file parsing phase, and just directly instert the data into the database, once you’ve fetched it, as above.

No. This is “date of disconnect”, i.e. the time the user is known to have disconnected (either on their own, or because their time was up)… or “dateofdisconnect”, as you said.

If by “date of disconnect” you mean “date I am supposed to be disconnecting this user, because that’s the time they have paid up to” (as you are only NOW implying), you’d want to check the profile of the customer this user is associated with. It’s “start-at” time, plus “validity” will give you the time you’re supposed to disconnect the user.