hotspot plan radius

This commit is contained in:
Ibnu Maksum
2023-10-03 15:46:55 +07:00
parent 9e33a5740b
commit ce01771800
15 changed files with 393 additions and 242 deletions

View File

@ -98,7 +98,7 @@ class Package
if ($p['type'] == 'Hotspot') {
if ($b) {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -155,7 +155,7 @@ class Package
$t->type = "Hotspot";
$t->save();
} else {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -202,7 +202,7 @@ class Package
} else {
if ($b) {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -260,7 +260,7 @@ class Package
$t->type = "PPPOE";
$t->save();
} else {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -342,7 +342,7 @@ class Package
$mikrotik = Mikrotik::info($p['routers']);
if ($p['type'] == 'Hotspot') {
if ($b) {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -351,7 +351,7 @@ class Package
Mikrotik::addHotspotUser($client, $p, $c);
}
} else {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -362,7 +362,7 @@ class Package
}
} else {
if ($b) {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
@ -371,7 +371,7 @@ class Package
Mikrotik::addPpoeUser($client, $p, $c);
}
} else {
if (!$_c['radius_mode']) {
if (!$_c['radius_enable']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);

View File

@ -1,24 +1,42 @@
<?php
class Radius {
class Radius
{
public static function getTableNas(){
public static function getTableNas()
{
return ORM::for_table('nas', 'radius');
}
public static function getTableCustomer(){
public static function getTableCustomer()
{
return ORM::for_table('radcheck', 'radius');
}
public static function getTablePackage(){
public static function getTablePackage()
{
return ORM::for_table('radgroupreply', 'radius');
}
public static function getTableUserPackage(){
public static function getTableUserPackage()
{
return ORM::for_table('radusergroup', 'radius');
}
public static function addNas($name, $ip, $ports, $secret, $description = "",$type = 'other', $server= null, $community= null){
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)
{
$n = Radius::getTableNas()->create();
$n->nasname = $ip;
$n->shortname = $name;
@ -32,9 +50,10 @@ class Radius {
return $n->id();
}
public static function updateNas($id, $name, $ip, $ports, $secret, $description = "",$type = 'other', $server= null, $community= null){
public static function nasUpdate($id, $name, $ip, $ports, $secret, $description = "", $type = 'other', $server = null, $community = null)
{
$n = Radius::getTableNas()->find_one($id);
if(empty($n)){
if (empty($n)) {
return false;
}
$n->nasname = $ip;
@ -48,4 +67,64 @@ class Radius {
return $n->save();
}
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);
$r = Radius::getTablePackage()->where_equal('plan_id', $plan_id)->whereEqual('attribute', 'Ascend-Data-Rate')->findOne();
$r->groupname = $plan_name;
$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_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 {
return true;
}
}
}
return false;
}
}