Community discussions

 
onyegbadocu
just joined
Topic Author
Posts: 12
Joined: Wed Nov 22, 2017 12:49 pm

PEAR2\Net\RouterOS sync with Sql

Mon Jul 29, 2019 1:31 pm

Hello Guys,
i have installed PEAR2\Net\RouterOS and it is working very well. Is there anyway i can make the script to run automatically at intervals?
The file which contains the code is mikro.php. if open my web browser and type : localhost\hotspot1\mikro.php
users will be uploaded to the userman. Instead of refreshing a web browser each time there is a new user in the sql,is there anyway we make the script to run automatically

The work around i did was to allow the user to click on a link to activate so that the browser refreshes but there could be a better way of doing it.
My code is below:
<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
//$db = mysqli_connect('localhost','root','', 'dbname');

try {
$client = new RouterOS\Client('172.17.65.1', 'admin', 'Uspf2019!');
//$router = new RouterOS\Client('172.16.7.3', 'admin', 'password@1');
$mysqli = new mysqli('localhost:3306', 'user1', 'password@1', 'hotspot');
echo 'successfully registered!Click <a href= "http://fuotuoke.org/login.html">here</a> here to login';

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


$users = $mysqli->query("SELECT `Firstname`, `Lastname`, `Email`, `StaffID` AS `username`, `password`,
`Telephone`, `Location` FROM `staff_register`");

while($user = $users->fetch_object()) {
$addRequest
->setArgument('customer', 'admin')
->setArgument('shared-users', '6')
->setArgument('username', $user->username)
->setArgument('password', $user->password)
->setArgument('first-name', $user->Firstname)
->setArgument('last-name', $user->Lastname)
->setArgument('email', $user->Email)
->setArgument('phone', $user->Telephone)
->setArgument('location', $user->Location)
->setArgument('copy-from', 'master-staff');
$client($addRequest);
//$router($addRequest);

}


} catch (RouterOS\SocketException $e) {
echo 'Connection to RouterOS failed... ' . $e;
} catch (RouterOS\DataFlowException $e) {
echo $e->getMessage();//Wrong username or password; probably
} catch (Exception $e) {
echo 'Unknown exception... ' . $e; //Connection fail to MySQL; probably
}


?>
 
vasilaos
Frequent Visitor
Frequent Visitor
Posts: 91
Joined: Tue Aug 04, 2009 9:50 am

Re: PEAR2\Net\RouterOS sync with Sql  [SOLVED]

Mon Jul 29, 2019 11:45 pm

Use crontab
 
onyegbadocu
just joined
Topic Author
Posts: 12
Joined: Wed Nov 22, 2017 12:49 pm

Re: PEAR2\Net\RouterOS sync with Sql

Tue Jul 30, 2019 8:09 am

Hello Vasiloas,
Thanks for the quick response.How do i use conrotab?
Meanwhile, i have issue with my router board 1100. Each time i execute the script,it will echo 'invalid user name and password'.I have checked my password and username and they are correct.other router os are not giving me issues.
 
onyegbadocu
just joined
Topic Author
Posts: 12
Joined: Wed Nov 22, 2017 12:49 pm

Re: PEAR2\Net\RouterOS sync with Sql

Thu Aug 01, 2019 10:11 pm

Hello vasiloas,
The crontab worked for me. I used the Task scheduler on windows to to trigger the script. As for the invalid user name and password issue when Mikrotik API is excuted,i downgraded from version 6.45.2 to 6.42 (RB1100AH) and it worked. It there is a special login style for version 6.45.2

Who is online

Users browsing this forum: No registered users and 7 guests