Customer deactivate plan

This commit is contained in:
Ibnu Maksum 2023-10-04 14:16:39 +07:00
parent 7a524a50e3
commit 6d835620f5
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 42 additions and 15 deletions

View File

@ -68,18 +68,18 @@ class Radius
return $n->save();
}
public static function planAdd($plan_id, $plan_name, $rate, $pool = null)
public static function planAdd($plan_id, $rate, $pool = null)
{
$rates = explode('/', $rate);
$r = Radius::getTablePackage()->create();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->attribute = 'Ascend-Data-Rate';
$r->op = ':=';
$r->value = $rates[1];
$r->plan_id = $plan_id;
if ($r->save()) {
$r = Radius::getTablePackage()->create();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->attribute = 'Ascend-Xmit-Rate';
$r->op = ':=';
$r->value = $rates[0];
@ -87,7 +87,7 @@ class Radius
if ($r->save()) {
if ($pool != null) {
$r = Radius::getTablePackage()->create();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->attribute = 'Framed-Pool';
$r->op = ':=';
$r->value = $pool;
@ -103,21 +103,21 @@ class Radius
return false;
}
public static function planUpdate($plan_id, $plan_name, $rate, $pool = null)
public static function planUpdate($plan_id, $rate, $pool = null)
{
$rates = explode('/', $rate);
if (Radius::getTablePackage()->where_equal('plan_id', $plan_id)->find_one()) {
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Data-Rate')->findOne();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->value = $rates[1];
if ($r->save()) {
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Xmit-Rate')->findOne();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->value = $rates[0];
if ($r->save()) {
if ($pool != null) {
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Framed-Pool')->findOne();
$r->groupname = $plan_name;
$r->groupname = "plan_".$plan_id;
$r->value = $pool;
if ($r->save()) {
return true;
@ -129,11 +129,38 @@ class Radius
}
} else {
if (!empty($plan_id)) {
return Radius::planAdd($plan_id, $plan_name, $rate, $pool);
return Radius::planAdd($plan_id, $rate, $pool);
}
}
return false;
}
public static function customerChangeUsername($from, $to){
$c = Radius::getTableCustomer()->where_equal('username', $from)->findMany();
if ($c) {
foreach($c as $u){
$u->username = $to;
$u->save();
}
}
$c = Radius::getTableUserPackage()->where_equal('username', $from)->findMany();
if ($c) {
foreach($c as $u){
$u->username = $to;
$u->save();
}
}
}
public static function customerDeactivate($customer){
global $radius_pass;
$r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Cleartext-Password')->findOne();
if($r){
// no need to delete, because it will make ID got higher
// we just change the password
$r->value = md5(time().$customer['username'].$radius_pass);
$r->save();
}
}
/**
* When add a plan to Customer, use this
@ -143,12 +170,12 @@ class Radius
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
if ($p) {
// if exists
$p->groupname = $plan['name_plan'];
$p->groupname = "plan_".$plan['id'];
return $p->save();
}else{
$p = Radius::getTableUserPackage()->create();
$p->username = $customer['username'];
$p->groupname = $plan['name_plan'];
$p->groupname = "plan_".$plan['id'];
$p->priority = 1;
return $p->save();
}

View File

@ -233,7 +233,7 @@ switch ($action) {
$plan_id = $d->id();
if ($config['radius_enable']) {
Radius::planAdd($plan_id, $name, $radiusRate);
Radius::planAdd($plan_id, $radiusRate);
} else {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
@ -304,7 +304,7 @@ switch ($action) {
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
if ($config['radius_enable']) {
Radius::planUpdate($id, $name, $radiusRate);
Radius::planUpdate($id, $radiusRate);
} else {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
@ -477,7 +477,7 @@ switch ($action) {
$plan_id = $d->id();
if ($config['radius_enable']) {
Radius::planAdd($plan_id, $name, $radiusRate, $pool);
Radius::planAdd($plan_id, $radiusRate, $pool);
} else {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
@ -542,7 +542,7 @@ switch ($action) {
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
if ($config['radius_enable']) {
Radius::planUpdate($id, $name, $radiusRate, $pool);
Radius::planUpdate($id, $radiusRate, $pool);
} else {
$mikrotik = Mikrotik::info($routers);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);