Fix select router
This commit is contained in:
parent
5024df9c0b
commit
77f21ece61
@ -68,115 +68,63 @@ class Radius
|
|||||||
return $n->save();
|
return $n->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function planAdd($plan_id, $rate, $pool = null)
|
public static function planUpSert($plan_id, $rate, $pool = null)
|
||||||
{
|
{
|
||||||
$rates = explode('/', $rate);
|
$rates = explode('/', $rate);
|
||||||
$r = Radius::getTablePackage()->create();
|
Radius::upsertPackage($plan_id, 'Ascend-Data-Rate', $rates[1], ':=');
|
||||||
$r->groupname = "plan_".$plan_id;
|
Radius::upsertPackage($plan_id, 'Ascend-Xmit-Rate', $rates[0], ':=');
|
||||||
$r->attribute = 'Ascend-Data-Rate';
|
if ($pool != null) {
|
||||||
$r->op = ':=';
|
Radius::upsertPackage($plan_id, 'Framed-Pool', $pool, ':=');
|
||||||
$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()) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
} 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
|
// Delete Plan
|
||||||
Radius::getTablePackage()->where_equal('plan_id', "plan_".$plan_id)->delete_many();
|
Radius::getTablePackage()->where_equal('plan_id', "plan_" . $plan_id)->delete_many();
|
||||||
// Reset User Plan
|
// Reset User Plan
|
||||||
$c = Radius::getTableUserPackage()->where_equal('groupname', "plan_".$plan_id)->findMany();
|
$c = Radius::getTableUserPackage()->where_equal('groupname', "plan_" . $plan_id)->findMany();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
foreach($c as $u){
|
foreach ($c as $u) {
|
||||||
$u->groupname = '';
|
$u->groupname = '';
|
||||||
$u->save();
|
$u->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function customerChangeUsername($from, $to){
|
|
||||||
|
public static function customerChangeUsername($from, $to)
|
||||||
|
{
|
||||||
$c = Radius::getTableCustomer()->where_equal('username', $from)->findMany();
|
$c = Radius::getTableCustomer()->where_equal('username', $from)->findMany();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
foreach($c as $u){
|
foreach ($c as $u) {
|
||||||
$u->username = $to;
|
$u->username = $to;
|
||||||
$u->save();
|
$u->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$c = Radius::getTableUserPackage()->where_equal('username', $from)->findMany();
|
$c = Radius::getTableUserPackage()->where_equal('username', $from)->findMany();
|
||||||
if ($c) {
|
if ($c) {
|
||||||
foreach($c as $u){
|
foreach ($c as $u) {
|
||||||
$u->username = $to;
|
$u->username = $to;
|
||||||
$u->save();
|
$u->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function customerDeactivate($username){
|
public static function customerDeactivate($username)
|
||||||
|
{
|
||||||
global $radius_pass;
|
global $radius_pass;
|
||||||
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
$r = Radius::getTableCustomer()->where_equal('username', $username)->whereEqual('attribute', 'Cleartext-Password')->findOne();
|
||||||
if($r){
|
if ($r) {
|
||||||
// no need to delete, because it will make ID got higher
|
// no need to delete, because it will make ID got higher
|
||||||
// we just change the password
|
// we just change the password
|
||||||
$r->value = md5(time().$username.$radius_pass);
|
$r->value = md5(time() . $username . $radius_pass);
|
||||||
$r->save();
|
$r->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function customerDelete($username){
|
public static function customerDelete($username)
|
||||||
|
{
|
||||||
Radius::getTableCustomer()->where_equal('username', $username)->delete_many();
|
Radius::getTableCustomer()->where_equal('username', $username)->delete_many();
|
||||||
Radius::getTableUserPackage()->where_equal('username', $username)->delete_many();
|
Radius::getTableUserPackage()->where_equal('username', $username)->delete_many();
|
||||||
}
|
}
|
||||||
@ -184,17 +132,18 @@ class Radius
|
|||||||
/**
|
/**
|
||||||
* When add a plan to Customer, use this
|
* When add a plan to Customer, use this
|
||||||
*/
|
*/
|
||||||
public static function customerAddPlan($customer, $plan){
|
public static function customerAddPlan($customer, $plan)
|
||||||
if(Radius::customerAdd($customer, $plan)){
|
{
|
||||||
|
if (Radius::customerUpsert($customer, $plan)) {
|
||||||
$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_".$plan['id'];
|
$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_".$plan['id'];
|
$p->groupname = "plan_" . $plan['id'];
|
||||||
$p->priority = 1;
|
$p->priority = 1;
|
||||||
return $p->save();
|
return $p->save();
|
||||||
}
|
}
|
||||||
@ -202,88 +151,47 @@ class Radius
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function customerAdd($customer, $plan)
|
public static function customerUpsert($customer, $plan)
|
||||||
{
|
{
|
||||||
if (Radius::getTableCustomer()->where_equal('username', $customer['username'])->findOne()) {
|
if ($plan['type'] == 'PPPOE') {
|
||||||
// Edit if exists
|
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', (empty($customer['pppoe_password'])) ? $customer['password'] : $customer['pppoe_password']);
|
||||||
$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 {
|
} else {
|
||||||
// add if not exists
|
Radius::upsertCustomer($customer['username'], 'Cleartext-Password', $customer['password']);
|
||||||
$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'], 'Simultaneous-Use', ($plan['type'] == 'PPPOE')? 1: $plan['shared_users'] );
|
||||||
return false;
|
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>
|
<option value=''>{$_L['Select_Routers']}</option>
|
||||||
|
{if $_c['radius_enable']}
|
||||||
|
<option value="radius">Radius</option>
|
||||||
|
{/if}
|
||||||
{foreach $d as $ds}
|
{foreach $d as $ds}
|
||||||
{if $_c['radius_enable']}
|
|
||||||
<option value="radius">Radius</option>
|
|
||||||
{/if}
|
|
||||||
<option value="{$ds['name']}">{$ds['name']}</option>
|
<option value="{$ds['name']}">{$ds['name']}</option>
|
||||||
{/foreach}
|
{/foreach}
|
Loading…
x
Reference in New Issue
Block a user