2022-10-05 10:51:18 +07:00
|
|
|
<?php
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
class Radius
|
|
|
|
{
|
2022-10-05 10:51:18 +07:00
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function getTableNas()
|
|
|
|
{
|
2023-08-28 08:45:35 +07:00
|
|
|
return ORM::for_table('nas', 'radius');
|
|
|
|
}
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function getTableCustomer()
|
|
|
|
{
|
2023-08-28 08:45:35 +07:00
|
|
|
return ORM::for_table('radcheck', 'radius');
|
|
|
|
}
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function getTablePackage()
|
|
|
|
{
|
2023-08-28 08:45:35 +07:00
|
|
|
return ORM::for_table('radgroupreply', 'radius');
|
|
|
|
}
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function getTableUserPackage()
|
|
|
|
{
|
2023-08-28 08:45:35 +07:00
|
|
|
return ORM::for_table('radusergroup', 'radius');
|
|
|
|
}
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function nasList($search = null){
|
|
|
|
if($search == null){
|
|
|
|
return ORM::for_table('nas', 'radius')->find_many();
|
|
|
|
}else{
|
|
|
|
return ORM::for_table('nas', 'radius')
|
|
|
|
->where_like('nasname', $search)
|
|
|
|
->where_like('shortname', $search)
|
|
|
|
->where_like('description', $search)
|
|
|
|
->find_many();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function nasAdd($name, $ip, $ports, $secret, $description = "", $type = 'other', $server = null, $community = null)
|
|
|
|
{
|
2023-10-03 15:03:47 +07:00
|
|
|
$n = Radius::getTableNas()->create();
|
2023-08-28 08:45:35 +07:00
|
|
|
$n->nasname = $ip;
|
|
|
|
$n->shortname = $name;
|
|
|
|
$n->type = $type;
|
|
|
|
$n->ports = $ports;
|
|
|
|
$n->secret = $secret;
|
|
|
|
$n->description = $description;
|
|
|
|
$n->server = $server;
|
|
|
|
$n->community = $community;
|
|
|
|
$n->save();
|
|
|
|
return $n->id();
|
|
|
|
}
|
2023-10-03 15:03:47 +07:00
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function nasUpdate($id, $name, $ip, $ports, $secret, $description = "", $type = 'other', $server = null, $community = null)
|
|
|
|
{
|
2023-10-03 15:03:47 +07:00
|
|
|
$n = Radius::getTableNas()->find_one($id);
|
2023-10-03 15:46:55 +07:00
|
|
|
if (empty($n)) {
|
2023-08-28 08:45:35 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$n->nasname = $ip;
|
|
|
|
$n->shortname = $name;
|
|
|
|
$n->type = $type;
|
|
|
|
$n->ports = $ports;
|
|
|
|
$n->secret = $secret;
|
|
|
|
$n->description = $description;
|
|
|
|
$n->server = $server;
|
|
|
|
$n->community = $community;
|
2023-10-03 15:03:47 +07:00
|
|
|
return $n->save();
|
2023-08-28 08:45:35 +07:00
|
|
|
}
|
|
|
|
|
2023-10-03 15:46:55 +07:00
|
|
|
public static function planAdd($plan_id, $plan_name, $rate, $pool = null)
|
|
|
|
{
|
|
|
|
$rates = explode('/', $rate);
|
|
|
|
$r = Radius::getTablePackage()->create();
|
|
|
|
$r->groupname = $plan_name;
|
|
|
|
$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->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_name;
|
|
|
|
$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, $plan_name, $rate, $pool = null)
|
|
|
|
{
|
|
|
|
$rates = explode('/', $rate);
|
2023-10-04 11:37:32 +07:00
|
|
|
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();
|
2023-10-03 15:46:55 +07:00
|
|
|
$r->groupname = $plan_name;
|
2023-10-04 11:37:32 +07:00
|
|
|
$r->value = $rates[1];
|
2023-10-03 15:46:55 +07:00
|
|
|
if ($r->save()) {
|
2023-10-04 11:37:32 +07:00
|
|
|
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Xmit-Rate')->findOne();
|
|
|
|
$r->groupname = $plan_name;
|
|
|
|
$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->value = $pool;
|
|
|
|
if ($r->save()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-03 15:46:55 +07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-04 11:37:32 +07:00
|
|
|
}else{
|
|
|
|
if(!empty($plan_id)){
|
|
|
|
return Radius::planAdd($plan_id, $plan_name, $rate, $pool);
|
|
|
|
}
|
2023-10-03 15:46:55 +07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-10-05 10:51:18 +07:00
|
|
|
}
|