simplified Mikrotik Connection

This commit is contained in:
Ibnu Maksum
2022-09-18 00:52:39 +07:00
parent e6f8826490
commit ac813ca132
11 changed files with 489 additions and 1177 deletions

View File

@ -40,34 +40,12 @@ switch ($action) {
$c = ORM::for_table('tbl_user_recharges')->where('username',$user['username'])->find_one();
if ($c){
$mikrotik = Router::_info($c['routers']);
$mikrotik = Mikrotik::info($c['routers']);
if($c['type'] == 'Hotspot'){
if(!$_c['radius_mode']){
try {
$iport = explode(":",$mikrotik['ip_address']);
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null);
} catch (Exception $e) {
die("Unable to connect to the router.<br>".$e->getMessage());
}
$printRequest = new RouterOS\Request('/ip/hotspot/user/print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(RouterOS\Query::where('name', $user['username']));
$id = $client->sendSync($printRequest)->getProperty('.id');
$setRequest = new RouterOS\Request('/ip/hotspot/user/set');
$setRequest->setArgument('numbers', $id);
$setRequest->setArgument('password', $npass);
$client->sendSync($setRequest);
//remove hotspot active
$onlineRequest = new RouterOS\Request('/ip/hotspot/active/print');
$onlineRequest->setArgument('.proplist', '.id');
$onlineRequest->setQuery(RouterOS\Query::where('user', $user['username']));
$id = $client->sendSync($onlineRequest)->getProperty('.id');
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
$removeRequest->setArgument('numbers', $id);
$client->sendSync($removeRequest);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setHotspotUser($client,$c['username'],$npass);
Mikrotik::removeHotspotActiveUser($client,$user['username']);
}
$d->password = $npass;
$d->save();
@ -79,31 +57,9 @@ switch ($action) {
}else{
if(!$_c['radius_mode']){
try {
$iport = explode(":",$mikrotik['ip_address']);
$client = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'],($iport[1])?$iport[1]:null);
} catch (Exception $e) {
die("Unable to connect to the router.<br>".$e->getMessage());
}
$printRequest = new RouterOS\Request('/ppp/secret/print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(RouterOS\Query::where('name', $user['username']));
$id = $client->sendSync($printRequest)->getProperty('.id');
$setRequest = new RouterOS\Request('/ppp/secret/set');
$setRequest->setArgument('numbers', $id);
$setRequest->setArgument('password', $npass);
$client->sendSync($setRequest);
//remove pppoe active
$onlineRequest = new RouterOS\Request('/ppp/active/print');
$onlineRequest->setArgument('.proplist', '.id');
$onlineRequest->setQuery(RouterOS\Query::where('name', $user['username']));
$id = $client->sendSync($onlineRequest)->getProperty('.id');
$removeRequest = new RouterOS\Request('/ppp/active/remove');
$removeRequest->setArgument('numbers', $id);
$client->sendSync($removeRequest);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPpoeUser($client,$c['username'],$npass);
Mikrotik::removePpoeActive($client,$user['username']);
}
$d->password = $npass;
$d->save();