Fix select router
This commit is contained in:
parent
5024df9c0b
commit
77f21ece61
@ -68,74 +68,18 @@ class Radius
|
||||
return $n->save();
|
||||
}
|
||||
|
||||
public static function planAdd($plan_id, $rate, $pool = null)
|
||||
public static function planUpSert($plan_id, $rate, $pool = null)
|
||||
{
|
||||
$rates = explode('/', $rate);
|
||||
$r = Radius::getTablePackage()->create();
|
||||
$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_".$plan_id;
|
||||
$r->attribute = 'Ascend-Xmit-Rate';
|
||||
$r->op = ':=';
|
||||
$r->value = $rates[0];
|
||||
$r->plan_id = $plan_id;
|
||||
if ($r->save()) {
|
||||
Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
||||
Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||
if ($pool != null) {
|
||||
$r = Radius::getTablePackage()->create();
|
||||
$r->groupname = "plan_".$plan_id;
|
||||
$r->attribute = 'Framed-Pool';
|
||||
$r->op = ':=';
|
||||
$r->value = $pool;
|
||||
$r->plan_id = $plan_id;
|
||||
if ($r->save()) {
|
||||
return true;
|
||||
Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function planUpdate($plan_id, $rate, $pool = null)
|
||||
public static function planDelete($plan_id)
|
||||
{
|
||||
$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_".$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_".$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_".$plan_id;
|
||||
$r->value = $pool;
|
||||
if ($r->save()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!empty($plan_id)) {
|
||||
return Radius::planAdd($plan_id, $rate, $pool);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function planDelete($plan_id){
|
||||
// Delete Plan
|
||||
Radius::getTablePackage()->where_equal('plan_id', "plan_" . $plan_id)->delete_many();
|
||||
// Reset User Plan
|
||||
@ -148,7 +92,9 @@ class Radius
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerChangeUsername($from, $to){
|
||||
|
||||
public static function customerChangeUsername($from, $to)
|
||||
{
|
||||
$c = Radius::getTableCustomer()->where_equal('username', $from)->findMany();
|
||||
if ($c) {
|
||||
foreach ($c as $u) {
|
||||
@ -165,7 +111,8 @@ class Radius
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerDeactivate($username){
|
||||
public static function customerDeactivate($username)
|
||||
{
|
||||
global $radius_pass;
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||
if ($r) {
|
||||
@ -176,7 +123,8 @@ class Radius
|
||||
}
|
||||
}
|
||||
|
||||
public static function customerDelete($username){
|
||||
public static function customerDelete($username)
|
||||
{
|
||||
Radius::getTableCustomer()->where_equal('username', $username)->delete_many();
|
||||
Radius::getTableUserPackage()->where_equal('username', $username)->delete_many();
|
||||
}
|
||||
@ -184,8 +132,9 @@ class Radius
|
||||
/**
|
||||
* When add a plan to Customer, use this
|
||||
*/
|
||||
public static function customerAddPlan($customer, $plan){
|
||||
if(Radius::customerAdd($customer, $plan)){
|
||||
public static function customerAddPlan($customer, $plan)
|
||||
{
|
||||
if (Radius::customerUpsert($customer, $plan)) {
|
||||
$p = Radius::getTableUserPackage()->where_equal('username', $customer['username'])->findOne();
|
||||
if ($p) {
|
||||
// if exists
|
||||
@ -202,88 +151,47 @@ class Radius
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function customerAdd($customer, $plan)
|
||||
public static function customerUpsert($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'];
|
||||
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', (empty($customer['pppoe_password'])) ? $customer['password'] : $customer['pppoe_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;
|
||||
}
|
||||
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']);
|
||||
}
|
||||
Radius::upsertCustomer($customer['username'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE')? 1: $plan['shared_users'] );
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing plan
|
||||
*/
|
||||
private static function upsertPackage($plan_id, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = Radius::getTablePackage()->create();
|
||||
$r->groupname = "plan_" . $plan_id;
|
||||
$r->plan_id = $plan_id;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* To insert or update existing customer
|
||||
*/
|
||||
private static function upsertCustomer($username, $attr, $value, $op = ':=')
|
||||
{
|
||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', $attr)->find_one();
|
||||
if (!$r) {
|
||||
$r = Radius::getTableCustomer()->create();
|
||||
$r->username = $username;
|
||||
}
|
||||
$r->attribute = $attr;
|
||||
$r->op = $op;
|
||||
$r->value = $value;
|
||||
return $r->save();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<option value=''>{$_L['Select_Routers']}</option>
|
||||
{foreach $d as $ds}
|
||||
{if $_c['radius_enable']}
|
||||
<option value="radius">Radius</option>
|
||||
{/if}
|
||||
{foreach $d as $ds}
|
||||
<option value="{$ds['name']}">{$ds['name']}</option>
|
||||
{/foreach}
|
Loading…
x
Reference in New Issue
Block a user