Files
thetool/lib/RadiusDB/Nas.php
2024-05-06 13:24:25 +02:00

69 lines
1.5 KiB
PHP

<?php
class RadiusDB_Nas {
private $db;
public $id;
public $nasname;
public $intaddress;
public $shortname;
public $type;
public $secret;
public $description;
public function __construct($db) {
$this->db = $db;
}
public function load($nasname) {
//var_dump($this->db);
$nasname = $this->db->escape($nasname);
$res = $this->db->select("nas", "*", "nasname='$nasname'");
if(!$this->db->num_rows($res)) {
$this->type = "other";
$this->secret = Helper::getNewPassword(24);
return true;
}
$nas = $this->db->fetch_object($res);
$this->id = $nas->id;
$this->nasname = $nas->nasname;
$this->intaddress = $nas->intaddress;
$this->shortname = $nas->shortname;
$this->type = $nas->type;
$this->secret = $nas->secret;
$this->description = $nas->description;
return true;
}
public function save() {
if(!$this->nasname) {
return false;
}
if(!$this->secret) {
return false;
}
if($this->id) {
$id = $this->id;
}
$values['nasname'] = $this->nasname;
$values['intaddress'] = $this->nasname; // is supposed to be the same as nasname
$values['shortname'] = $this->shortname;
$values['type'] = $this->type;
$values['secret'] = $this->secret;
$values['description'] = $this->description;
if($id) {
if(!$this->db->update("nas", $values, "id=$id")) {
return false;
}
} else {
if(!$id = $this->db->insert("nas", $values)) {
return false;
}
}
return $id;
}
}