78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
class RadiusDB_Client {
|
|
private $db;
|
|
|
|
public function __construct($host=false,$user=false,$pass=false,$dbname=false) {
|
|
if(!$host) $host=RADIUSDB_DBHOST;
|
|
if(!$user) $user=RADIUSDB_DBUSER;
|
|
if(!$pass) $pass=RADIUSDB_DBPASS;
|
|
if(!$dbname) $dbname=RADIUSDB_DBNAME;
|
|
|
|
$this->db = new FronkDB($host,$user,$pass,$dbname);
|
|
}
|
|
|
|
public function getUser($username) {
|
|
$user = new RadiusDB_User($this->db);
|
|
$user->load($username);
|
|
return $user;
|
|
}
|
|
|
|
public function searchUsers($search, $exact=false) {
|
|
$users = array();
|
|
$search = $this->db->escape($search);
|
|
if($exact) {
|
|
$res = $this->db->select("radcheck", "username", "username='$search' GROUP BY username ORDER BY LENGTH(username), username");
|
|
} else {
|
|
$res = $this->db->select("radcheck", "username", "username like '$search' GROUP BY username ORDER BY LENGTH(username), username");
|
|
}
|
|
if($this->db->num_rows($res)) {
|
|
while($data = $this->db->fetch_object($res)) {
|
|
$users[] = $data->username;
|
|
}
|
|
}
|
|
return $users;
|
|
}
|
|
|
|
public function searchUsersByIp($ip) {
|
|
$users = array();
|
|
$ip = $this->db->escape($ip);
|
|
$res = $this->db->select("radreply", "username", "attribute='Framed-IP-Address' AND value='$ip' GROUP BY username ORDER BY username");
|
|
if($this->db->num_rows($res)) {
|
|
while($data = $this->db->fetch_object($res)) {
|
|
$users[] = $data->username;
|
|
}
|
|
}
|
|
return $users;
|
|
}
|
|
|
|
public function getUserByCustnum($custnum, $e = false) {
|
|
$users = array();
|
|
$search = $this->db->escape($custnum);
|
|
$field = "Custnum";
|
|
if($e) {
|
|
$field = "Custnume";
|
|
}
|
|
$res = $this->db->select("Hotspot_Usersettings", "Username", "$field = '$custnum' GROUP BY Username ORDER BY Username LIMIT 1");
|
|
if($this->db->num_rows($res)) {
|
|
$data = $this->db->fetch_object($res);
|
|
$user = $this->getUser($data->Username);
|
|
if($user->username) {
|
|
return $user;
|
|
}
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getNas($nasname) {
|
|
$nas = new RadiusDB_Nas($this->db);
|
|
$nas->load($nasname);
|
|
return $nas;
|
|
}
|
|
|
|
public function restartRadiusServer() {
|
|
exec("/usr/bin/sudo /usr/sbin/service freeradius restart");
|
|
return true;
|
|
}
|
|
} |