forked from kevinowino869/mitrobill
Radius add plan user
This commit is contained in:
parent
78cbb105aa
commit
7a524a50e3
@ -98,7 +98,9 @@ class Package
|
||||
|
||||
if ($p['type'] == 'Hotspot') {
|
||||
if ($b) {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -155,7 +157,9 @@ class Package
|
||||
$t->type = "Hotspot";
|
||||
$t->save();
|
||||
} else {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -202,7 +206,9 @@ class Package
|
||||
} else {
|
||||
|
||||
if ($b) {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -260,7 +266,9 @@ class Package
|
||||
$t->type = "PPPOE";
|
||||
$t->save();
|
||||
} else {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -342,7 +350,9 @@ class Package
|
||||
$mikrotik = Mikrotik::info($p['routers']);
|
||||
if ($p['type'] == 'Hotspot') {
|
||||
if ($b) {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -351,7 +361,9 @@ class Package
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
}
|
||||
} else {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -362,7 +374,9 @@ class Package
|
||||
}
|
||||
} else {
|
||||
if ($b) {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
@ -371,7 +385,9 @@ class Package
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
} else {
|
||||
if (!$_c['radius_enable']) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p);
|
||||
}else{
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
|
@ -23,10 +23,11 @@ class Radius
|
||||
return ORM::for_table('radusergroup', 'radius');
|
||||
}
|
||||
|
||||
public static function nasList($search = null){
|
||||
if($search == null){
|
||||
public static function nasList($search = null)
|
||||
{
|
||||
if ($search == null) {
|
||||
return ORM::for_table('nas', 'radius')->find_many();
|
||||
}else{
|
||||
} else {
|
||||
return ORM::for_table('nas', 'radius')
|
||||
->where_like('nasname', $search)
|
||||
->where_like('shortname', $search)
|
||||
@ -105,7 +106,7 @@ class Radius
|
||||
public static function planUpdate($plan_id, $plan_name, $rate, $pool = null)
|
||||
{
|
||||
$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->groupname = $plan_name;
|
||||
$r->value = $rates[1];
|
||||
@ -126,11 +127,117 @@ class Radius
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!empty($plan_id)){
|
||||
} else {
|
||||
if (!empty($plan_id)) {
|
||||
return Radius::planAdd($plan_id, $plan_name, $rate, $pool);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* When add a plan to Customer, use this
|
||||
*/
|
||||
public static function customerAddPlan($customer, $plan){
|
||||
if(Radius::customerAdd($customer, $plan)){
|
||||
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||
if ($p) {
|
||||
// if exists
|
||||
$p->groupname = $plan['name_plan'];
|
||||
return $p->save();
|
||||
}else{
|
||||
$p = Radius::getTableUserPackage()->create();
|
||||
$p->username = $customer['username'];
|
||||
$p->groupname = $plan['name_plan'];
|
||||
$p->priority = 1;
|
||||
return $p->save();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function customerAdd($customer, $plan)
|
||||
{
|
||||
if (Radius::getTableCustomer()->where_equal('username', $customer['username'])->findOne()) {
|
||||
// Edit if exists
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
if($r){
|
||||
if($plan['type']=='PPPOE'){
|
||||
if(empty($customer['pppoe_password'])){
|
||||
$r->value = $customer['password'];
|
||||
}else{
|
||||
$r->value = $customer['pppoe_password'];
|
||||
}
|
||||
}else{
|
||||
$r->value = $customer['password'];
|
||||
}
|
||||
$r->save();
|
||||
}else{
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $customer['username'];
|
||||
$r->attribute = 'Cleartext-Password';
|
||||
$r->op = ':=';
|
||||
if($plan['type']=='PPPOE'){
|
||||
if(empty($customer['pppoe_password'])){
|
||||
$r->value = $customer['password'];
|
||||
}else{
|
||||
$r->value = $customer['pppoe_password'];
|
||||
}
|
||||
}else{
|
||||
$r->value = $customer['password'];
|
||||
}
|
||||
$r->save();
|
||||
}
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $customer['username'])->whereEqual('attribute', 'Simultaneous-Use')->findOne();
|
||||
if($r){
|
||||
if($plan['type']=='PPPOE'){
|
||||
$r->value = 1;
|
||||
}else{
|
||||
$r->value = $plan['shared_users'];
|
||||
}
|
||||
$r->save();
|
||||
}else{
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $customer['username'];
|
||||
$r->attribute = 'Simultaneous-Use';
|
||||
$r->op = ':=';
|
||||
if($plan['type']=='PPPOE'){
|
||||
$r->value = 1;
|
||||
}else{
|
||||
$r->value = $plan['shared_users'];
|
||||
}
|
||||
$r->save();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// add if not exists
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $customer['username'];
|
||||
$r->attribute = 'Cleartext-Password';
|
||||
$r->op = ':=';
|
||||
if($plan['type']=='PPPOE'){
|
||||
if(empty($customer['pppoe_password'])){
|
||||
$r->value = $customer['password'];
|
||||
}else{
|
||||
$r->value = $customer['pppoe_password'];
|
||||
}
|
||||
}else{
|
||||
$r->value = $customer['password'];
|
||||
}
|
||||
if ($r->save()) {
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $customer['username'];
|
||||
$r->attribute = 'Simultaneous-Use';
|
||||
$r->op = ':=';
|
||||
if($plan['type']=='PPPOE'){
|
||||
$r->value = 1;
|
||||
}else{
|
||||
$r->value = $plan['shared_users'];
|
||||
}
|
||||
$r->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user