Customer deactivate plan
This commit is contained in:
parent
7a524a50e3
commit
6d835620f5
@ -68,18 +68,18 @@ class Radius
|
|||||||
return $n->save();
|
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);
|
$rates = explode('/', $rate);
|
||||||
$r = Radius::getTablePackage()->create();
|
$r = Radius::getTablePackage()->create();
|
||||||
$r->groupname = $plan_name;
|
$r->groupname = "plan_".$plan_id;
|
||||||
$r->attribute = 'Ascend-Data-Rate';
|
$r->attribute = 'Ascend-Data-Rate';
|
||||||
$r->op = ':=';
|
$r->op = ':=';
|
||||||
$r->value = $rates[1];
|
$r->value = $rates[1];
|
||||||
$r->plan_id = $plan_id;
|
$r->plan_id = $plan_id;
|
||||||
if ($r->save()) {
|
if ($r->save()) {
|
||||||
$r = Radius::getTablePackage()->create();
|
$r = Radius::getTablePackage()->create();
|
||||||
$r->groupname = $plan_name;
|
$r->groupname = "plan_".$plan_id;
|
||||||
$r->attribute = 'Ascend-Xmit-Rate';
|
$r->attribute = 'Ascend-Xmit-Rate';
|
||||||
$r->op = ':=';
|
$r->op = ':=';
|
||||||
$r->value = $rates[0];
|
$r->value = $rates[0];
|
||||||
@ -87,7 +87,7 @@ class Radius
|
|||||||
if ($r->save()) {
|
if ($r->save()) {
|
||||||
if ($pool != null) {
|
if ($pool != null) {
|
||||||
$r = Radius::getTablePackage()->create();
|
$r = Radius::getTablePackage()->create();
|
||||||
$r->groupname = $plan_name;
|
$r->groupname = "plan_".$plan_id;
|
||||||
$r->attribute = 'Framed-Pool';
|
$r->attribute = 'Framed-Pool';
|
||||||
$r->op = ':=';
|
$r->op = ':=';
|
||||||
$r->value = $pool;
|
$r->value = $pool;
|
||||||
@ -103,21 +103,21 @@ class Radius
|
|||||||
return false;
|
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);
|
$rates = explode('/', $rate);
|
||||||
if (Radius::getTablePackage()->where_equal('plan_id', $plan_id)->find_one()) {
|
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 = 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];
|
$r->value = $rates[1];
|
||||||
if ($r->save()) {
|
if ($r->save()) {
|
||||||
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Xmit-Rate')->findOne();
|
$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];
|
$r->value = $rates[0];
|
||||||
if ($r->save()) {
|
if ($r->save()) {
|
||||||
if ($pool != null) {
|
if ($pool != null) {
|
||||||
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Framed-Pool')->findOne();
|
$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;
|
$r->value = $pool;
|
||||||
if ($r->save()) {
|
if ($r->save()) {
|
||||||
return true;
|
return true;
|
||||||
@ -129,11 +129,38 @@ class Radius
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!empty($plan_id)) {
|
if (!empty($plan_id)) {
|
||||||
return Radius::planAdd($plan_id, $plan_name, $rate, $pool);
|
return Radius::planAdd($plan_id, $rate, $pool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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
|
* When add a plan to Customer, use this
|
||||||
@ -143,12 +170,12 @@ class Radius
|
|||||||
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||||
if ($p) {
|
if ($p) {
|
||||||
// if exists
|
// if exists
|
||||||
$p->groupname = $plan['name_plan'];
|
$p->groupname = "plan_".$plan['id'];
|
||||||
return $p->save();
|
return $p->save();
|
||||||
}else{
|
}else{
|
||||||
$p = Radius::getTableUserPackage()->create();
|
$p = Radius::getTableUserPackage()->create();
|
||||||
$p->username = $customer['username'];
|
$p->username = $customer['username'];
|
||||||
$p->groupname = $plan['name_plan'];
|
$p->groupname = "plan_".$plan['id'];
|
||||||
$p->priority = 1;
|
$p->priority = 1;
|
||||||
return $p->save();
|
return $p->save();
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ switch ($action) {
|
|||||||
$plan_id = $d->id();
|
$plan_id = $d->id();
|
||||||
|
|
||||||
if ($config['radius_enable']) {
|
if ($config['radius_enable']) {
|
||||||
Radius::planAdd($plan_id, $name, $radiusRate);
|
Radius::planAdd($plan_id, $radiusRate);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($routers);
|
$mikrotik = Mikrotik::info($routers);
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$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;
|
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
|
||||||
|
|
||||||
if ($config['radius_enable']) {
|
if ($config['radius_enable']) {
|
||||||
Radius::planUpdate($id, $name, $radiusRate);
|
Radius::planUpdate($id, $radiusRate);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($routers);
|
$mikrotik = Mikrotik::info($routers);
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||||
@ -477,7 +477,7 @@ switch ($action) {
|
|||||||
$plan_id = $d->id();
|
$plan_id = $d->id();
|
||||||
|
|
||||||
if ($config['radius_enable']) {
|
if ($config['radius_enable']) {
|
||||||
Radius::planAdd($plan_id, $name, $radiusRate, $pool);
|
Radius::planAdd($plan_id, $radiusRate, $pool);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($routers);
|
$mikrotik = Mikrotik::info($routers);
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$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;
|
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown;
|
||||||
|
|
||||||
if ($config['radius_enable']) {
|
if ($config['radius_enable']) {
|
||||||
Radius::planUpdate($id, $name, $radiusRate, $pool);
|
Radius::planUpdate($id, $radiusRate, $pool);
|
||||||
} else {
|
} else {
|
||||||
$mikrotik = Mikrotik::info($routers);
|
$mikrotik = Mikrotik::info($routers);
|
||||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user