mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Misc Classes: Database class integration.
This commit is contained in:
@@ -8,19 +8,11 @@
|
||||
if (!class_exists('registrations')) {
|
||||
class registrations {
|
||||
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,105 +39,105 @@ if (!class_exists('registrations')) {
|
||||
//get the default settings
|
||||
$sql = "select sip_profile_name from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_enabled = 'true' ";
|
||||
if ($profile == 'all' || $profile == '') {
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($profile != 'all' && $profile != '') {
|
||||
$sql .= "and sip_profile_name = :sip_profile_name ";
|
||||
$parameters['sip_profile_name'] = $profile;
|
||||
}
|
||||
else {
|
||||
$sql .= "and sip_profile_name=:sip_profile_name ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->bindParam(':sip_profile_name', $profile);
|
||||
}
|
||||
$prep_statement->execute();
|
||||
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($sip_profiles as $field) {
|
||||
$database = new database;
|
||||
$sip_profiles = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
||||
foreach ($sip_profiles as $field) {
|
||||
|
||||
//get sofia status profile information including registrations
|
||||
$cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
|
||||
$xml_response = trim(event_socket_request($fp, $cmd));
|
||||
if ($xml_response == "Invalid Profile!") { $xml_response = "<error_msg>".$text['label-message']."</error_msg>"; }
|
||||
$xml_response = str_replace("<profile-info>", "<profile_info>", $xml_response);
|
||||
$xml_response = str_replace("</profile-info>", "</profile_info>", $xml_response);
|
||||
if (strlen($xml_response) > 101) {
|
||||
try {
|
||||
$xml = new SimpleXMLElement($xml_response);
|
||||
//get sofia status profile information including registrations
|
||||
$cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
|
||||
$xml_response = trim(event_socket_request($fp, $cmd));
|
||||
if ($xml_response == "Invalid Profile!") { $xml_response = "<error_msg>".$text['label-message']."</error_msg>"; }
|
||||
$xml_response = str_replace("<profile-info>", "<profile_info>", $xml_response);
|
||||
$xml_response = str_replace("</profile-info>", "</profile_info>", $xml_response);
|
||||
if (strlen($xml_response) > 101) {
|
||||
try {
|
||||
$xml = new SimpleXMLElement($xml_response);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$array = json_decode(json_encode($xml), true);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit;
|
||||
|
||||
//normalize the array
|
||||
if (is_array($array) && !is_array($array['registrations']['registration'][0])) {
|
||||
$row = $array['registrations']['registration'];
|
||||
unset($array['registrations']['registration']);
|
||||
$array['registrations']['registration'][0] = $row;
|
||||
}
|
||||
$array = json_decode(json_encode($xml) , true);
|
||||
}
|
||||
|
||||
//normalize the array
|
||||
if (is_array($array) && !is_array($array['registrations']['registration'][0])) {
|
||||
$row = $array['registrations']['registration'];
|
||||
unset($array['registrations']['registration']);
|
||||
$array['registrations']['registration'][0] = $row;
|
||||
}
|
||||
//set the registrations array
|
||||
if (is_array($array)) {
|
||||
foreach ($array['registrations']['registration'] as $row) {
|
||||
|
||||
//set the registrations array
|
||||
if (is_array($array)) {
|
||||
foreach ($array['registrations']['registration'] as $row) {
|
||||
//build the registrations array
|
||||
//$registrations[0] = $row;
|
||||
$user_array = explode('@', $row['user']);
|
||||
$registrations[$id]['user'] = $row['user'] ?: '';
|
||||
$registrations[$id]['call-id'] = $row['call-id'] ?: '';
|
||||
$registrations[$id]['contact'] = $row['contact'] ?: '';
|
||||
$registrations[$id]['sip-auth-user'] = $row['sip-auth-user'] ?: '';
|
||||
$registrations[$id]['agent'] = $row['agent'] ?: '';
|
||||
$registrations[$id]['host'] = $row['host'] ?: '';
|
||||
$registrations[$id]['network-port'] = $row['network-port'] ?: '';
|
||||
$registrations[$id]['sip-auth-realm'] = $row['sip-auth-realm'] ?: '';
|
||||
$registrations[$id]['mwi-account'] = $row['mwi-account'] ?: '';
|
||||
$registrations[$id]['status'] = $row['status'] ?: '';
|
||||
$registrations[$id]['ping-time'] = $row['ping-time'] ?: '';
|
||||
$registrations[$id]['sip_profile_name'] = $field['sip_profile_name'];
|
||||
|
||||
//build the registrations array
|
||||
//$registrations[0] = $row;
|
||||
$user_array = explode('@', $row['user']);
|
||||
$registrations[$id]['user'] = $row['user'] ?: '';
|
||||
$registrations[$id]['call-id'] = $row['call-id'] ?: '';
|
||||
$registrations[$id]['contact'] = $row['contact'] ?: '';
|
||||
$registrations[$id]['sip-auth-user'] = $row['sip-auth-user'] ?: '';
|
||||
$registrations[$id]['agent'] = $row['agent'] ?: '';
|
||||
$registrations[$id]['host'] = $row['host'] ?: '';
|
||||
$registrations[$id]['network-port'] = $row['network-port'] ?: '';
|
||||
$registrations[$id]['sip-auth-realm'] = $row['sip-auth-realm'] ?: '';
|
||||
$registrations[$id]['mwi-account'] = $row['mwi-account'] ?: '';
|
||||
$registrations[$id]['status'] = $row['status'] ?: '';
|
||||
$registrations[$id]['ping-time'] = $row['ping-time'] ?: '';
|
||||
$registrations[$id]['sip_profile_name'] = $field['sip_profile_name'];
|
||||
|
||||
//get network-ip to url or blank
|
||||
if(isset($row['network-ip'])) {
|
||||
$registrations[$id]['network-ip'] = $row['network-ip'];
|
||||
} else {
|
||||
$registrations[$id]['network-ip'] = '';
|
||||
}
|
||||
|
||||
//get the LAN IP address if it exists replace the external ip
|
||||
$call_id_array = explode('@', $row['call-id']);
|
||||
if (isset($call_id_array[1])) {
|
||||
$agent = $row['agent'];
|
||||
$lan_ip = $call_id_array[1];
|
||||
if (false !== stripos($agent, 'grandstream')) {
|
||||
$lan_ip = str_ireplace(
|
||||
array('A','B','C','D','E','F','G','H','I','J'),
|
||||
array('0','1','2','3','4','5','6','7','8','9'),
|
||||
$lan_ip);
|
||||
//get network-ip to url or blank
|
||||
if (isset($row['network-ip'])) {
|
||||
$registrations[$id]['network-ip'] = $row['network-ip'];
|
||||
}
|
||||
else {
|
||||
$registrations[$id]['network-ip'] = '';
|
||||
}
|
||||
elseif(1 === preg_match('/\ACL750A/', $agent)) {
|
||||
//required for GIGASET Sculpture CL750A puts _ in it's lan ip account
|
||||
$lan_ip = preg_replace('/_/', '.', $lan_ip);
|
||||
}
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
} else {
|
||||
$registrations[$id]['lan-ip'] = '';
|
||||
}
|
||||
|
||||
//remove unrelated domains
|
||||
if (count($_SESSION["domains"]) > 1) {
|
||||
if (!(permission_exists('registration_all') && $profile == "all")) {
|
||||
if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
|
||||
elseif ($user_array[1] == $_SESSION['domain_name']){}
|
||||
else {
|
||||
unset($registrations[$id]);
|
||||
//get the LAN IP address if it exists replace the external ip
|
||||
$call_id_array = explode('@', $row['call-id']);
|
||||
if (isset($call_id_array[1])) {
|
||||
$agent = $row['agent'];
|
||||
$lan_ip = $call_id_array[1];
|
||||
if (false !== stripos($agent, 'grandstream')) {
|
||||
$lan_ip = str_ireplace(
|
||||
array('A','B','C','D','E','F','G','H','I','J'),
|
||||
array('0','1','2','3','4','5','6','7','8','9'),
|
||||
$lan_ip);
|
||||
}
|
||||
elseif(1 === preg_match('/\ACL750A/', $agent)) {
|
||||
//required for GIGASET Sculpture CL750A puts _ in it's lan ip account
|
||||
$lan_ip = preg_replace('/_/', '.', $lan_ip);
|
||||
}
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
}
|
||||
else {
|
||||
$registrations[$id]['lan-ip'] = '';
|
||||
}
|
||||
|
||||
//remove unrelated domains
|
||||
if (count($_SESSION["domains"]) > 1) {
|
||||
if (!(permission_exists('registration_all') && $profile == "all")) {
|
||||
if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
|
||||
else if ($user_array[1] == $_SESSION['domain_name']) {}
|
||||
else {
|
||||
unset($registrations[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//increment the array id
|
||||
$id++;
|
||||
//increment the array id
|
||||
$id++;
|
||||
}
|
||||
unset($array);
|
||||
}
|
||||
unset($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return the registrations array
|
||||
@@ -166,17 +158,14 @@ if (!class_exists('registrations')) {
|
||||
//get the default settings
|
||||
$sql = "select sip_profile_name from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_enabled = 'true' ";
|
||||
if ($profile == 'all' || $profile == '') {
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($profile != 'all' && $profile != '') {
|
||||
$sql .= "and sip_profile_name = :sip_profile_name ";
|
||||
$parameters['sip_profile_name'] = $profile;
|
||||
}
|
||||
else {
|
||||
$sql .= "and sip_profile_name=:sip_profile_name ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->bindParam(':sip_profile_name', $profile);
|
||||
}
|
||||
$prep_statement->execute();
|
||||
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($sip_profiles as $field) {
|
||||
$database = new database;
|
||||
$sip_profiles = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
||||
foreach ($sip_profiles as $field) {
|
||||
|
||||
//get sofia status profile information including registrations
|
||||
$cmd = "api sofia xmlstatus profile ".$field['sip_profile_name']." reg";
|
||||
@@ -193,10 +182,11 @@ if (!class_exists('registrations')) {
|
||||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$array = json_decode(json_encode($xml) , true);
|
||||
$array = json_decode(json_encode($xml), true);
|
||||
$count = $count + count($array['registrations']['registration']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//return the registrations count
|
||||
@@ -205,10 +195,11 @@ if (!class_exists('registrations')) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
$obj = new registrations;
|
||||
$registrations = $obj->get('all');
|
||||
print($registrations);
|
||||
*/
|
||||
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user