fix add nas

This commit is contained in:
Ibnu Maksum 2023-10-03 15:03:47 +07:00
parent 6e3df253c6
commit 9e33a5740b
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
2 changed files with 16 additions and 26 deletions

View File

@ -2,24 +2,24 @@
class Radius { class Radius {
public function getTableNas(){ public static function getTableNas(){
return ORM::for_table('nas', 'radius'); return ORM::for_table('nas', 'radius');
} }
public function getTableCustomer(){ public static function getTableCustomer(){
return ORM::for_table('radcheck', 'radius'); return ORM::for_table('radcheck', 'radius');
} }
public function getTablePackage(){ public static function getTablePackage(){
return ORM::for_table('radgroupreply', 'radius'); return ORM::for_table('radgroupreply', 'radius');
} }
public function getTableUserPackage(){ public static function getTableUserPackage(){
return ORM::for_table('radusergroup', 'radius'); return ORM::for_table('radusergroup', 'radius');
} }
public function addNas($name, $ip, $ports, $secret, $description = "",$type = 'other', $server= null, $community= null){ public static function addNas($name, $ip, $ports, $secret, $description = "",$type = 'other', $server= null, $community= null){
$n = $this->getTableNas()->create(); $n = Radius::getTableNas()->create();
$n->nasname = $ip; $n->nasname = $ip;
$n->shortname = $name; $n->shortname = $name;
$n->type = $type; $n->type = $type;
@ -31,8 +31,9 @@ class Radius {
$n->save(); $n->save();
return $n->id(); return $n->id();
} }
public function updateNas($id, $name, $ip, $ports, $secret, $description = "",$type = 'other', $server= null, $community= null){
$n = $this->getTableNas()->find_one($id); public static function updateNas($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; return false;
} }
@ -44,8 +45,7 @@ class Radius {
$n->description = $description; $n->description = $description;
$n->server = $server; $n->server = $server;
$n->community = $community; $n->community = $community;
$n->save(); return $n->save();
return true;
} }
} }

View File

@ -55,17 +55,7 @@ switch ($action) {
$msg .= 'NAS IP Exists<br>'; $msg .= 'NAS IP Exists<br>';
} }
if ($msg == '') { if ($msg == '') {
$b = ORM::for_table('nas', 'radius')->create(); $id = Radius::addNas($shortname, $nasname, $ports, $secret, $description, $type, $server, $community);
$b->nasname = $nasname;
$b->shortname = $shortname;
$b->secret = $secret;
$b->ports = $ports;
$b->type = $type;
$b->server = $server;
$b->community = $community;
$b->description = $description;
$b->save();
$id = $b->id();
if ($id > 0) { if ($id > 0) {
r2(U . 'radius/nas-edit/' . $id, 's', "NAS Added"); r2(U . 'radius/nas-edit/' . $id, 's', "NAS Added");
} else { } else {
@ -119,10 +109,6 @@ switch ($action) {
if (empty($type)) { if (empty($type)) {
$type = null; $type = null;
} }
$d = ORM::for_table('nas', 'radius')->find_one($id);
if (!$d) {
$msg .= 'NAS NOT Exists<br>';
}
if ($msg == '') { if ($msg == '') {
$d->nasname = $nasname; $d->nasname = $nasname;
$d->shortname = $shortname; $d->shortname = $shortname;
@ -133,7 +119,11 @@ switch ($action) {
$d->community = $community; $d->community = $community;
$d->description = $description; $d->description = $description;
$d->save(); $d->save();
if (Radius::updateNas($id, $shortname, $nasname, $ports, $secret, $description, $type, $server, $community)) {
r2(U . 'radius/nas-edit/' . $id, 's', "NAS Saved"); r2(U . 'radius/nas-edit/' . $id, 's', "NAS Saved");
} else {
r2(U . 'radius/nas-add', 'e', 'NAS NOT Exists');
}
} else { } else {
r2(U . 'radius/nas-add', 'e', $msg); r2(U . 'radius/nas-add', 'e', $msg);
} }