hotspot plan radius

This commit is contained in:
Ibnu Maksum
2023-10-03 15:46:55 +07:00
parent 9e33a5740b
commit ce01771800
15 changed files with 393 additions and 242 deletions

View File

@ -28,27 +28,31 @@ switch ($action) {
$log = '';
$router = '';
foreach ($plans as $plan) {
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
if (!empty($plan['pool_expired'])) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
if($plan['is_radius']){
}else{
if ($router != $plan['routers']) {
$mikrotik = Mikrotik::info($plan['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
$router = $plan['routers'];
}
if ($plan['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
} else {
$unitdown = 'M';
}
if ($plan['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
} else {
$unitup = 'M';
}
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
if (!empty($plan['pool_expired'])) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
}
}
}
r2(U . 'services/hotspot', 's', $log);
@ -132,7 +136,7 @@ switch ($action) {
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_plan'); #HOOK
if (!$config['radius_mode']) {
if (!$config['radius_enable']) {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
@ -146,6 +150,7 @@ switch ($action) {
case 'add-post':
$name = _post('name');
$radius = _post('radius');
$typebp = _post('typebp');
$limit_type = _post('limit_type');
$time_limit = _post('time_limit');
@ -168,10 +173,14 @@ switch ($action) {
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '') {
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
if(empty($radius)){
if ($routers == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
}
$d = ORM::for_table('tbl_plans')->where('name_plan', $name)->where('type', 'Hotspot')->find_one();
if ($d) {
$msg .= $_L['Plan_already_exist'] . '<br>';
@ -183,25 +192,20 @@ switch ($action) {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
$raddown = '000';
} else {
$unitdown = 'M';
$raddown = '000000';
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
$radup = '000';
} else {
$unitup = 'M';
$radup = '000000';
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if (!$config['radius_mode']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
if (!empty($pool_expired)) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
}
}
$radiusRate = $b['rate_up'].$radup.'/'.$b['rate_down'].$raddown;
$d = ORM::for_table('tbl_plans')->create();
$d->name_plan = $name;
@ -217,10 +221,29 @@ switch ($action) {
$d->validity = $validity;
$d->validity_unit = $validity_unit;
$d->shared_users = $sharedusers;
$d->routers = $routers;
$d->pool_expired = $pool_expired;
if(!empty($radius)){
$d->is_radius = 1;
$d->routers = '';
}else{
$d->is_radius = 0;
$d->routers = $routers;
$d->pool_expired = $pool_expired;
}
$d->enabled = $enabled;
$d->save();
$plan_id = $d->id();
if ($config['radius_enable']) {
Radius::planAdd($plan_id, $name, $radiusRate);
}else{
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
if (!empty($pool_expired)) {
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
}
}
r2(U . 'services/hotspot', 's', $_L['Created_Successfully']);
} else {
@ -243,7 +266,6 @@ switch ($action) {
$sharedusers = _post('sharedusers');
$validity = _post('validity');
$validity_unit = _post('validity_unit');
$routers = _post('routers');
$pool_expired = _post('pool_expired');
$enabled = _post('enabled');
@ -254,10 +276,9 @@ switch ($action) {
if (Validator::UnsignedNumber($price) == false) {
$msg .= 'The price must be a number' . '<br>';
}
if ($name == '' or $id_bw == '' or $price == '' or $validity == '' or $routers == '') {
if ($name == '' or $id_bw == '' or $price == '' or $validity == '') {
$msg .= $_L['All_field_is_required'] . '<br>';
}
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
if ($d) {
} else {
@ -268,17 +289,24 @@ switch ($action) {
$b = ORM::for_table('tbl_bandwidth')->where('id', $id_bw)->find_one();
if ($b['rate_down_unit'] == 'Kbps') {
$unitdown = 'K';
$raddown = '000';
} else {
$unitdown = 'M';
$raddown = '000000';
}
if ($b['rate_up_unit'] == 'Kbps') {
$unitup = 'K';
$radup = '000';
} else {
$unitup = 'M';
$radup = '000000';
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
$radiusRate = $b['rate_up'].$radup.'/'.$b['rate_down'].$raddown;
if (!$config['radius_mode']) {
if ($config['radius_enable']) {
Radius::planUpdate($id, $name, $radiusRate);
}else{
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
@ -299,7 +327,6 @@ switch ($action) {
$d->validity = $validity;
$d->validity_unit = $validity_unit;
$d->shared_users = $sharedusers;
$d->routers = $routers;
$d->pool_expired = $pool_expired;
$d->enabled = $enabled;
$d->save();
@ -364,7 +391,7 @@ switch ($action) {
$d = ORM::for_table('tbl_plans')->find_one($id);
if ($d) {
run_hook('delete_ppoe'); #HOOK
if (!$config['radius_mode']) {
if (!$config['radius_enable']) {
$mikrotik = Mikrotik::info($d['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePpoePlan($client, $d['name_plan']);
@ -416,7 +443,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if (!$config['radius_mode']) {
if (!$config['radius_enable']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::addPpoePlan($client, $name, $pool, $rate);
@ -487,7 +514,7 @@ switch ($action) {
}
$rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown;
if (!$config['radius_mode']) {
if (!$config['radius_enable']) {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::setPpoePlan($client, $name, $pool, $rate);