From e19423471f945b2042150bcbf5194fb65bd3b48b Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Thu, 12 Oct 2023 13:42:52 +0700 Subject: [PATCH] add radius expiration --- system/autoload/Mikrotik.php | 4 ++-- system/autoload/Package.php | 12 ++++++------ system/autoload/Radius.php | 9 +++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php index 45c91616..178a6194 100644 --- a/system/autoload/Mikrotik.php +++ b/system/autoload/Mikrotik.php @@ -78,7 +78,7 @@ class Mikrotik $profileID = $client->sendSync($printRequest)->getProperty('.id'); if (empty($profileID)) { Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate); - }else{ + } else { $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); $client( $setRequest @@ -105,7 +105,7 @@ class Mikrotik ->setArgument('address-pool', $pool) ->setArgument('rate-limit', '512K/512K') ); - }else{ + } else { $setRequest = new RouterOS\Request('/ip/hotspot/user/profile/set'); $client( $setRequest diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 2885e78e..9cfa98d7 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -99,7 +99,7 @@ class Package if ($p['type'] == 'Hotspot') { if ($b) { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, "$date_exp $time"); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); @@ -158,7 +158,7 @@ class Package $t->save(); } else { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, "$date_exp $time"); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); @@ -207,7 +207,7 @@ class Package if ($b) { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, "$date_exp $time"); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); @@ -267,7 +267,7 @@ class Package $t->save(); } else { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, "$date_exp $time"); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); @@ -351,7 +351,7 @@ class Package if ($p['type'] == 'Hotspot') { if ($b) { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, $b['expiration'].''.$b['time']); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); @@ -362,7 +362,7 @@ class Package } } else { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p); + Radius::customerAddPlan($c, $p, $b['expiration'].''.$b['time']); }else{ $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removeHotspotUser($client, $c['username']); diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index 3261eeb3..687ae82e 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -132,7 +132,7 @@ class Radius /** * When add a plan to Customer, use this */ - public static function customerAddPlan($customer, $plan) + public static function customerAddPlan($customer, $plan, $expired = null, $quota = null) { if (Radius::customerUpsert($customer, $plan)) { $p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne(); @@ -147,6 +147,11 @@ class Radius $p->priority = 1; return $p->save(); } + //expired + if ($plan['type'] == 'HOTSPOT') { + + } + Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired))); } return false; } @@ -158,7 +163,7 @@ class Radius } else { Radius::upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']); } - Radius::upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE')? 1: $plan['shared_users'] ); + Radius::upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']); return false; }