From 492ea5985c42e35f79fac89cb47c1df189b20297 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 13 Oct 2023 16:03:12 +0700 Subject: [PATCH] add mikrotik spesific vendor atribut for radius --- system/autoload/Radius.php | 27 +++++++++++++++++++++++---- system/autoload/Timezone.php | 9 +++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/system/autoload/Radius.php b/system/autoload/Radius.php index 246fefb..25a0466 100644 --- a/system/autoload/Radius.php +++ b/system/autoload/Radius.php @@ -88,6 +88,7 @@ class Radius $rates = explode('/', $rate); Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':='); Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':='); + Radius::upsertPackage($plan_id, 'Mikrotik-Rate-Limit', $rate, ':='); if ($pool != null) { Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':='); } @@ -151,6 +152,7 @@ class Radius */ public static function customerAddPlan($customer, $plan, $expired = null) { + global $config; if (Radius::customerUpsert($customer, $plan)) { $p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne(); if ($p) { @@ -188,16 +190,25 @@ class Radius $datalimit = $plan['data_limit'] . "000000"; Radius::upsertCustomer($customer['username'], 'Max-Volume', $datalimit); Radius::upsertCustomer($customer['username'], 'Expire-After', $timelimit); + // Mikrotik Spesific + Radius::upsertCustomer($customer['username'], 'Mikrotik-Recv-Limit', $datalimit); + Radius::upsertCustomer($customer['username'], 'Mikrotik-Xmit-Limit', $datalimit); } } else { - $r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Max-Volume')->findOne(); - if($r) $r->delete(); - $r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Expire-After')->findOne(); - if($r) $r->delete(); + Radius::delAtribute(Radius::getTableCustomer(), 'Max-Volume', 'username', $customer['username']); + Radius::delAtribute(Radius::getTableCustomer(), 'Expire-After', 'username', $customer['username']); + Radius::delAtribute(Radius::getTableCustomer(), 'Mikrotik-Recv-Limit', 'username', $customer['username']); + Radius::delAtribute(Radius::getTableCustomer(), 'Mikrotik-Xmit-Limit', 'username', $customer['username']); } // expired user if ($expired != null) { Radius::upsertCustomer($customer['username'], 'expiration', date('d M Y H:i:s', strtotime($expired))); + // Mikrotik Spesific + Radius::upsertCustomer( + $customer['username'], + 'WISPr-Session-Terminate-Time', + date('Y-m-d', strtotime($expired)).'T'.date('H:i:s', strtotime($expired)).Timezone::getTimeOffset($config['timezone']) + ); } else { $r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'expiration')->findOne(); if($r) $r->delete(); @@ -215,9 +226,17 @@ class Radius Radius::upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']); } Radius::upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']); + // Mikrotik Spesific + Radius::upsertCustomer($customer['username'], 'Port-Limit', ($plan['type'] == 'PPPOE') ? 1 : $plan['shared_users']); + Radius::upsertCustomer($customer['username'], 'Mikrotik-Wireless-Comment',$customer['fullname']); return true; } + private static function delAtribute($tabel, $attribute, $key, $value){ + $r = $tabel->where_equal($key, $value)->whereEqual('attribute', $attribute)->findOne(); + if($r) $r->delete(); + } + /** * To insert or update existing plan */ diff --git a/system/autoload/Timezone.php b/system/autoload/Timezone.php index d781002..41f0bad 100644 --- a/system/autoload/Timezone.php +++ b/system/autoload/Timezone.php @@ -38,4 +38,13 @@ class Timezone { return $timezoneList; } + + public static function getTimeOffset($tz = 'Asia/Jakarta'){ + $utcTime = new DateTime('now', new DateTimeZone('UTC')); + $currentTimezone = new DateTimeZone($tz); + $offset = $currentTimezone->getOffset($utcTime); + $sign = ($offset > 0) ? '+' : '-'; + $offset = gmdate('H:i', abs($offset)); + return $sign.$offset; + } } \ No newline at end of file