Community discussions

 
yulley
just joined
Topic Author
Posts: 4
Joined: Fri Jul 10, 2009 4:49 pm

userman with PHP

Sun Mar 17, 2019 4:47 pm

please help...
i need add user and profile to userman ROS 6.42 with PHP,
for add user success with this script
<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';

$util = new RouterOS\Util(
    $client = new RouterOS\Client('192.168.88.1', 'admin', 'admin', '8728')
);
$util->setMenu('/tool user-manager user');
$util->add(
    array(
		'customer' => 'admin',
		'disabled' => 'no',
        'username' => 'user1',
		'password' => 'user1',
		'shared-users' => '1',
        'phone' => '+6281345678'
    )
);
but not success add profile with this
<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';
$util = new RouterOS\Util(
    $client = new RouterOS\Client('192.168.88.1', 'admin', 'admin', '8728')
);
$util->setMenu('/tool user-manager user create-and-activate-profile');
$util->add(
    array(
		'customer' => 'admin',
		'numbers' => '0',
		'profile' => 'profile1'
    )
);
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: userman with PHP  [SOLVED]

Mon Mar 25, 2019 12:12 am

"create-and-activate-profile" is a command, not a menu IIRC.

It's not a normal CRUD command, so you'll have to make a request to give to Client, instead of using Util.

Also, numbers should really contain the username (or otherwise the ID returned by finding the customer/username combo). e.g.
$client->sendSync(
    $util->setMenu('/tool user-manager user')->newRequest(
        'create-and-activate-profile',
        array(
	    'customer' => 'admin',
	    'numbers' => 'user1',
	    'profile' => 'profile1'
        )
    )
);
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
AdamGweleg
just joined
Posts: 11
Joined: Wed May 29, 2019 1:34 am

Re: userman with PHP

Fri Jul 05, 2019 2:58 pm

"create-and-activate-profile" is a command, not a menu IIRC.

It's not a normal CRUD command, so you'll have to make a request to give to Client, instead of using Util.

Also, numbers should really contain the username (or otherwise the ID returned by finding the customer/username combo). e.g.
$client->sendSync(
    $util->setMenu('/tool user-manager user')->newRequest(
        'create-and-activate-profile',
        array(
	    'customer' => 'admin',
	    'numbers' => 'user1',
	    'profile' => 'profile1'
        )
    )
);
Im using this code but when i run the code I've noted that the router CPU is rising to 30% and each voucher is taking more than 2 minutes.

My router is RB1100AHx4 dude edition v6.43.16

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';


for ($i = 0;$i < 7500; ){
    set_time_limit(0);
    
   
    $lines = file('add.txt');
       
    foreach ($lines as $line){

if ($i<7500){


    $util = new RouterOS\Util(
        $client = new RouterOS\Client('192.168.1.1', 'admin', '12345')
    );
    
    $voucher = (int)$line;
    $util->setMenu('/tool user-manager user');
    $util->add(
    
        array(
            'customer'=>'admin',
            'disabled'=>'no',
            'password' => '1234',
            'shared-users' => '1',
            'username' => $voucher,
            'wireless-enc-algo'=>'none',
            'wireless-enc-key'=>'',
            'wireless-psk'=>''
            // 'copy-from' =>'master1d'
        )
        );

     $client->sendSync($util->setMenu('/tool user-manager user')-> newRequest('create-and-activate-profile', [

        'numbers' => $voucher,
        'customer' => 'admin',
        'profile' => '1D'
     ]));



    $i++;
    echo "numer of vouchers is: ". $i. "<br>";
    echo" VoucherAdded" ." ".$line."<br>";
}




        
    }
    

    
    }

    
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: userman with PHP

Sat Jul 06, 2019 4:21 pm

What you're doing is that for every iteration in your loop, you're making a brand new connection, login to the router once again. This is a huge waste of resources.

Move the new RouterOS\Util and new RouterOS\Client outside of the loop, so that you keep using the same connection for all vouchers.

Also, you have two loops, with the "for" one not really serving its purpose. Remove it. You're already making the 7500 check inside the foreach anyway... i.e. only the first 7500 lines in your file would result in vauchers.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
AdamGweleg
just joined
Posts: 11
Joined: Wed May 29, 2019 1:34 am

Re: userman with PHP

Sat Jul 06, 2019 6:11 pm

What you're doing is that for every iteration in your loop, you're making a brand new connection, login to the router once again. This is a huge waste of resources.

Move the new RouterOS\Util and new RouterOS\Client outside of the loop, so that you keep using the same connection for all vouchers.

Also, you have two loops, with the "for" one not really serving its purpose. Remove it. You're already making the 7500 check inside the foreach anyway... i.e. only the first 7500 lines in your file would result in vauchers.
Thank you boen_robot

Today morning I've upgraded my router to the latest stable version because I thought the problem with the router version, and now when I'm trying to connect to the router using API I'm getting a username or password error. 😔

and I'm sure of the credentials are fine because i can log in through inbox.

Any help please??
 
yulley
just joined
Topic Author
Posts: 4
Joined: Fri Jul 10, 2009 4:49 pm

Re: userman with PHP

Tue Jul 09, 2019 11:38 am

Thank you very much and work with your script
so now i have new problem after added new profile, the billing/time left session will start and pause if any profile before and active in session.
maybe any script just add new profile without activated new profile (new profile will active after previous profile ended).

* i'm sorry my english not good
"create-and-activate-profile" is a command, not a menu IIRC.

It's not a normal CRUD command, so you'll have to make a request to give to Client, instead of using Util.

Also, numbers should really contain the username (or otherwise the ID returned by finding the customer/username combo). e.g.
$client->sendSync(
    $util->setMenu('/tool user-manager user')->newRequest(
        'create-and-activate-profile',
        array(
	    'customer' => 'admin',
	    'numbers' => 'user1',
	    'profile' => 'profile1'
        )
    )
);
 
onyegbadocu
just joined
Posts: 12
Joined: Wed Nov 22, 2017 12:49 pm

Re: userman with PHP

Mon Jul 15, 2019 12:24 am

Hello,
I know this an old post. Please i need an assistance on this issue. I am building a database using my php. I want to use a script to add these users from the php database to Userman.
Through google and this forum, i have downloaded Infinitel Hotspot Auto service but to no avail. I have used pearl but to no avail.
see my script below

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
//$db = mysqli_connect('localhost','root','','students');
$client = new RouterOS\Client('192.168.2.2', 'admin', 'password@1', '8728');
$mysqli = new mysqli('localhost', 'root', '', 'students');

$addRequest = new RouterOS\Request('/tool user-manager user add');


$users = $mysqli->query('SELECT `RegistrationID` AS `username`, `Lastname` AS `password` FROM `user`');


//die(var_dump($users->fetch_object()));
while ($user = $users->fetch_object()) {
$addRequest
->setArgument('name', $user->username)
->setArgument('password', $user->password)
->setArgument('customer', 'admin')
->setArgument('profile', 'staff');
$client($addRequest);
// var_dump($addRequest);
}
?>
 
onyegbadocu
just joined
Posts: 12
Joined: Wed Nov 22, 2017 12:49 pm

Re: userman with PHP

Sat Jul 20, 2019 2:33 pm

please help...
i need add user and profile to userman ROS 6.42 with PHP,
for add user success with this script
<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';

$util = new RouterOS\Util(
    $client = new RouterOS\Client('192.168.88.1', 'admin', 'admin', '8728')
);
$util->setMenu('/tool user-manager user');
$util->add(
    array(
		'customer' => 'admin',
		'disabled' => 'no',
        'username' => 'user1',
		'password' => 'user1',
		'shared-users' => '1',
        'phone' => '+6281345678'
    )
);
but not success add profile with this
<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';
$util = new RouterOS\Util(
    $client = new RouterOS\Client('192.168.88.1', 'admin', 'admin', '8728')
);
$util->setMenu('/tool user-manager user create-and-activate-profile');
$util->add(
    array(
		'customer' => 'admin',
		'numbers' => '0',
		'profile' => 'profile1'
    )
);
I need assistance . i cant load Pear2\Autoloader. php.I get an error that there is a missing directory.

Who is online

Users browsing this forum: No registered users and 7 guests