Misc: Database class integration.

This commit is contained in:
Nate 2019-09-04 12:21:57 -06:00
parent 9e301a0c97
commit fdf28ca6fc
5 changed files with 331 additions and 318 deletions

View File

@ -28,7 +28,6 @@
//define the conference center class //define the conference center class
class conference_centers { class conference_centers {
public $db;
public $domain_uuid; public $domain_uuid;
public $meeting_uuid; public $meeting_uuid;
public $order_by; public $order_by;
@ -44,13 +43,7 @@
* Called when the object is created * Called when the object is created
*/ */
public function __construct() { 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;
}
} }
/** /**
@ -72,7 +65,7 @@
if (permission_exists("conference_room_view_all")) { if (permission_exists("conference_room_view_all")) {
$not_admin = 0; $not_admin = 0;
} }
$sql = "select count(*) as num_rows from v_conference_rooms as r, v_meetings as p "; $sql = "select count(*) from v_conference_rooms as r, v_meetings as p ";
if ($not_admin) { if ($not_admin) {
$sql .= "v_meeting_users as u, "; $sql .= "v_meeting_users as u, ";
} }
@ -101,7 +94,6 @@
* get the list of conference rooms * get the list of conference rooms
*/ */
public function rooms() { public function rooms() {
//get variables used to control the order //get variables used to control the order
$order_by = $this->order_by; $order_by = $this->order_by;
$order = $this->order; $order = $this->order;
@ -114,7 +106,6 @@
//validate the order //validate the order
switch ($order) { switch ($order) {
case 'asc': case 'asc':
break;
case 'desc': case 'desc':
break; break;
default: default:
@ -157,7 +148,8 @@
} }
if (strlen($this->order_by) == 0) { if (strlen($this->order_by) == 0) {
$sql .= "order by r.description, r.meeting_uuid asc "; $sql .= "order by r.description, r.meeting_uuid asc ";
} else { }
else {
$sql .= "order by $order_by $order "; $sql .= "order by $order_by $order ";
} }
$sql .= "limit :rows_per_page offset :offset "; $sql .= "limit :rows_per_page offset :offset ";
@ -196,9 +188,8 @@
//set the previous uuid //set the previous uuid
$previous = $row["conference_room_uuid"]; $previous = $row["conference_room_uuid"];
} }
unset($conference_rooms);
} }
unset ($parameters, $sql); unset($sql, $parameters, $conference_rooms);
return $result; return $result;
} }
@ -213,22 +204,21 @@
//get call recording from database //get call recording from database
if (is_uuid($_GET['id'])) { if (is_uuid($_GET['id'])) {
$conference_session_uuid = check_str($_GET['id']); $conference_session_uuid = $_GET['id'];
}
if ($conference_session_uuid != '') {
$sql = "select recording from v_conference_sessions "; $sql = "select recording from v_conference_sessions ";
$sql .= "where conference_session_uuid = :conference_session_uuid "; $sql .= "where conference_session_uuid = :conference_session_uuid ";
//$sql .= "and domain_uuid = '".$domain_uuid."' \n"; //$sql .= "and domain_uuid = :domain_uuid ";
$parameters['conference_session_uuid'] = $conference_session_uuid; $parameters['conference_session_uuid'] = $conference_session_uuid;
//$parameters['domain_uuid'] = $domain_uuid;
$database = new database; $database = new database;
$conference_sessions = $database->select($sql, $parameters, 'all'); $conference_sessions = $database->select($sql, $parameters, 'all');
if (is_array($conference_sessions)) { if (is_array($conference_sessions)) {
foreach($conference_sessions as &$row) { foreach ($conference_sessions as &$row) {
$recording = $row['recording']; $recording = $row['recording'];
break; break;
} }
} }
unset ($sql, $prep_statement, $conference_sessions); unset($sql, $parameters, $conference_sessions);
} }
//set the path for the directory //set the path for the directory
@ -239,23 +229,23 @@
$record_name = basename($recording); $record_name = basename($recording);
//download the file //download the file
if (file_exists($record_path . '/' . $record_name . '.wav')) { if (file_exists($record_path.'/'.$record_name.'.wav')) {
$record_name = $record_name . '.wav'; $record_name = $record_name.'.wav';
} }
else { else {
if (file_exists($record_path . '/' . $record_name . '.mp3')) { if (file_exists($record_path.'/'.$record_name.'.mp3')) {
$record_name = $record_name . '.mp3'; $record_name = $record_name.'.mp3';
} }
} }
//download the file //download the file
if (file_exists($record_path . '/' . $record_name)) { if (file_exists($record_path.'/'.$record_name)) {
//content-range //content-range
//if (isset($_SERVER['HTTP_RANGE'])) { //if (isset($_SERVER['HTTP_RANGE'])) {
// range_download($full_recording_path); // range_download($full_recording_path);
//} //}
ob_clean(); ob_clean();
$fd = fopen($record_path . '/' . $record_name, "rb"); $fd = fopen($record_path.'/'.$record_name, "rb");
if ($_GET['t'] == "bin") { if ($_GET['t'] == "bin") {
header("Content-Type: application/force-download"); header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");
@ -274,14 +264,14 @@
header('Content-Disposition: attachment; filename="'.$record_name.'"'); header('Content-Disposition: attachment; filename="'.$record_name.'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// header("Content-Length: " . filesize($full_recording_path)); // header("Content-Length: ".filesize($full_recording_path));
ob_clean(); ob_clean();
fpassthru($fd); fpassthru($fd);
} }
//if base64, remove temp recording file //if base64, remove temp recording file
//if ($_SESSION['conference']['storage_type']['text'] == 'base64' && $row['conference_recording_base64'] != '') { //if ($_SESSION['conference']['storage_type']['text'] == 'base64' && $row['conference_recording_base64'] != '') {
// @unlink($record_path . '/' . $record_name); // @unlink($record_path.'/'.$record_name);
//} //}
} }
} //end download method } //end download method
@ -301,4 +291,4 @@
print_r($result); print_r($result);
*/ */
?> ?>

View File

@ -88,12 +88,23 @@
$this->dialplan_uuid = uuid(); $this->dialplan_uuid = uuid();
} }
else { else {
//delete the previous details //build previous details delete array
$sql = "delete from v_dialplan_details "; $array['dialplan_details'][0]['dialplan_uuid'] = $this->dialplan_uuid;
$sql .= "where dialplan_uuid = '".$this->dialplan_uuid."' "; $array['dialplan_details'][0]['domain_uuid'] = $this->domain_uuid;
$sql .= "and domain_uuid = '".$this->domain_uuid."' ";
$this->db->exec($sql); //grant temporary permissions
unset($sql); $p = new permissions;
$p->add('dialplan_detail_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = 'fax';
$database->app_uuid = '24108154-4ac3-1db6-1551-4731703a4440';
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('dialplan_detail_delete', 'temp');
} }
//set the fax name //set the fax name
@ -195,4 +206,4 @@ $c->fax_description = $fax_description;
$c->dialplan(); $c->dialplan();
*/ */
?> ?>

View File

@ -8,19 +8,11 @@
if (!class_exists('messages')) { if (!class_exists('messages')) {
class messages { class messages {
public $db;
/** /**
* Called when the object is created * Called when the object is created
*/ */
public function __construct() { 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;
}
} }
/** /**
@ -50,14 +42,29 @@ if (!class_exists('messages')) {
} }
//delete the checked rows //delete the checked rows
if ($action == 'delete') { if ($action == 'delete') {
$x = 0;
foreach($messages as $row) { foreach($messages as $row) {
if ($row['action'] == 'delete' or $row['checked'] == 'true') { if ($row['action'] == 'delete' or $row['checked'] == 'true') {
$sql = "delete from v_messages "; //build delete array
$sql .= "where message_uuid = '".$row['message_uuid']."'; "; $array['messages'][$x]['message_uuid'] = $row['message_uuid'];
$this->db->query($sql); $x++;
unset($sql);
} }
} }
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('message_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = 'messages';
$database->app_uuid = '4a20815d-042c-47c8-85df-085333e79b87';
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('message_delete', 'temp');
}
unset($messages); unset($messages);
} }
} }
@ -79,4 +86,4 @@ $obj = new messages;
$obj->delete(); $obj->delete();
*/ */
?> ?>

View File

@ -28,16 +28,12 @@ include "root.php";
//define the provision class //define the provision class
class provision { class provision {
public $db;
public $domain_uuid; public $domain_uuid;
public $domain_name; public $domain_name;
public $template_dir; public $template_dir;
public $mac; public $mac;
public function __construct() { public function __construct() {
//get the database object
global $db;
$this->db = $db;
//set the default template directory //set the default template directory
if (PHP_OS == "Linux") { if (PHP_OS == "Linux") {
//set the default template dir //set the default template dir
@ -49,7 +45,8 @@ include "root.php";
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision'; $this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
} }
} }
} elseif (PHP_OS == "FreeBSD") { }
else if (PHP_OS == "FreeBSD") {
//if the FreeBSD port is installed use the following paths by default. //if the FreeBSD port is installed use the following paths by default.
if (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) { if (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
if (strlen($this->template_dir) == 0) { if (strlen($this->template_dir) == 0) {
@ -67,17 +64,20 @@ include "root.php";
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision'; $this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
} }
} }
} elseif (PHP_OS == "NetBSD") { }
else if (PHP_OS == "NetBSD") {
//set the default template_dir //set the default template_dir
if (strlen($this->template_dir) == 0) { if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision'; $this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
} }
} elseif (PHP_OS == "OpenBSD") { }
else if (PHP_OS == "OpenBSD") {
//set the default template_dir //set the default template_dir
if (strlen($this->template_dir) == 0) { if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision'; $this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
} }
} else { }
else {
//set the default template_dir //set the default template_dir
if (strlen($this->template_dir) == 0) { if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision'; $this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
@ -105,59 +105,54 @@ include "root.php";
//normalize the mac address //normalize the mac address
$mac = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $mac)); $mac = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $mac));
//check in the devices table for a specific mac address //check in the devices table for a specific mac address
$sql = "SELECT count(*) FROM v_devices "; $sql = "select count(*) from v_devices ";
$sql .= "WHERE device_mac_address=:mac "; $sql .= "where device_mac_address = :mac ";
$parameters['mac'] = $mac; $parameters['mac'] = $mac;
$database = new database; $database = new database;
$num_rows = $database->select($sql, $parameters, 'column'); $num_rows = $database->select($sql, $parameters, 'column');
if ($num_rows > 0) { return $num_rows > 0 ? true : false;
return true; unset($sql, $parameters, $num_rows);
}
else {
return false;
}
} }
//set the mac address in the correct format for the specific vendor //set the mac address in the correct format for the specific vendor
public function format_mac($mac, $vendor) { public function format_mac($mac, $vendor) {
switch (strtolower($vendor)) { switch (strtolower($vendor)) {
case "algo": case "algo":
$mac = strtoupper($mac); return strtoupper($mac);
break; break;
case "aastra": case "aastra":
$mac = strtoupper($mac); return strtoupper($mac);
break; break;
case "cisco": case "cisco":
$mac = strtoupper($mac); return strtoupper($mac);
break; break;
case "linksys": case "linksys":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "mitel": case "mitel":
$mac = strtoupper($mac); return strtoupper($mac);
break; break;
case "polycom": case "polycom":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "snom": case "snom":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "escene": case "escene":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "grandstream": case "grandstream":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "yealink": case "yealink":
$mac = strtolower($mac); return strtolower($mac);
break; break;
case "gigaset": case "gigaset":
$mac = strtoupper($mac); return strtoupper($mac);
break; break;
default: default:
$mac = strtolower($mac); return strtolower($mac);
} }
return $mac;
} }
//send http error //send http error
@ -177,12 +172,7 @@ include "root.php";
//define a function to check if a contact exists in the contacts array //define a function to check if a contact exists in the contacts array
private function contact_exists($contacts, $uuid) { private function contact_exists($contacts, $uuid) {
if (is_array($contacts[$uuid])) { return is_array($contacts[$uuid]) ? true : false;
return true;
}
else {
return false;
}
} }
private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $is_group) { private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $is_group) {
@ -282,8 +272,8 @@ include "root.php";
//get the domain_name //get the domain_name
if (strlen($domain_name) == 0) { if (strlen($domain_name) == 0) {
$sql = "SELECT domain_name FROM v_domains "; $sql = "select domain_name from v_domains ";
$sql .= "WHERE domain_uuid=:domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid; $parameters['domain_uuid'] = $domain_uuid;
$database = new database; $database = new database;
$domain_name = $database->select($sql, $parameters, 'column'); $domain_name = $database->select($sql, $parameters, 'column');
@ -291,9 +281,9 @@ include "root.php";
} }
//build the provision array //build the provision array
$provision = Array(); $provision = array();
if (is_array($_SESSION['provision'])) { if (is_array($_SESSION['provision'])) {
foreach($_SESSION['provision'] as $key=>$val) { foreach ($_SESSION['provision'] as $key => $val) {
if (strlen($val['var']) > 0) { $value = $val['var']; } if (strlen($val['var']) > 0) { $value = $val['var']; }
if (strlen($val['text']) > 0) { $value = $val['text']; } if (strlen($val['text']) > 0) { $value = $val['text']; }
if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } if (strlen($val['boolean']) > 0) { $value = $val['boolean']; }
@ -313,66 +303,64 @@ include "root.php";
if ($this->mac_exists($mac)) { if ($this->mac_exists($mac)) {
//get the device_template //get the device_template
//if (strlen($device_template) == 0) { $sql = "select * from v_devices ";
$sql = "SELECT * FROM v_devices "; $sql .= "where device_mac_address = :mac_address ";
$sql .= "WHERE device_mac_address = :mac_address "; if ($provision['http_domain_filter'] == "true") {
if ($provision['http_domain_filter'] == "true") { $sql .= "and domain_uuid=:domain_uuid ";
$sql .= "AND domain_uuid=:domain_uuid "; $parameters['domain_uuid'] = $domain_uuid;
}
$parameters['mac_address'] = $mac;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
unset($parameters);
if (is_array($row) && sizeof($row) != 0) {
//checks either device enabled
if ($row['device_enabled'] != 'true') {
if ($_SESSION['provision']['debug']['boolean'] == 'true') {
echo "<br/>device disabled<br/>";
}
else {
$this->http_error('404');
}
exit;
}
//register that we have seen the device
$sql = "update v_devices ";
$sql .= "set device_provisioned_date = :device_provisioned_date, device_provisioned_method = :device_provisioned_method, device_provisioned_ip = :device_provisioned_ip ";
$sql .= "where domain_uuid = :domain_uuid and device_mac_address = :device_mac_address ";
$parameters['domain_uuid'] = $domain_uuid; $parameters['domain_uuid'] = $domain_uuid;
} $parameters['device_mac_address'] = strtolower($mac);
$parameters['mac_address'] = $mac; $parameters['device_provisioned_date'] = date("Y-m-d H:i:s");
$database = new database; $parameters['device_provisioned_method'] = (isset($_SERVER["HTTPS"]) ? 'https' : 'http');
$row = $database->select($sql, $parameters, 'row'); $parameters['device_provisioned_ip'] = $_SERVER['REMOTE_ADDR'];
unset($parameters); $database = new database;
$database->execute($sql, $parameters);
unset($parameters);
if (is_array($row) && sizeof($row) != 0) { //set the variables from values in the database
$device_uuid = $row["device_uuid"];
//checks either device enabled $device_label = $row["device_label"];
if($row['device_enabled'] != 'true'){ if (strlen($row["device_vendor"]) > 0) {
if ($_SESSION['provision']['debug']['boolean'] == 'true'){ $device_vendor = strtolower($row["device_vendor"]);
echo "<br/>device disabled<br/>"; }
} $device_user_uuid = $row["device_user_uuid"];
else { $device_model = $row["device_model"];
$this->http_error('404'); $device_firmware_version = $row["device_firmware_version"];
} $device_enabled = $row["device_enabled"];
exit; $device_template = $row["device_template"];
} $device_profile_uuid = $row["device_profile_uuid"];
$device_description = $row["device_description"];
//register that we have seen the device }
$sql = "UPDATE v_devices "; unset($row);
$sql .= "SET device_provisioned_date = :device_provisioned_date, device_provisioned_method = :device_provisioned_method, device_provisioned_ip = :device_provisioned_ip ";
$sql .= "WHERE domain_uuid = :domain_uuid AND device_mac_address = :device_mac_address ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['device_mac_address'] = strtolower($mac);
$parameters['device_provisioned_date'] = date("Y-m-d H:i:s");
$parameters['device_provisioned_method'] = (isset($_SERVER["HTTPS"]) ? 'https' : 'http');
$parameters['device_provisioned_ip'] = $_SERVER['REMOTE_ADDR'];
$database = new database;
$database->execute($sql, $parameters);
unset($parameters);
//set the variables from values in the database
$device_uuid = $row["device_uuid"];
$device_label = $row["device_label"];
if (strlen($row["device_vendor"]) > 0) {
$device_vendor = strtolower($row["device_vendor"]);
}
$device_user_uuid = $row["device_user_uuid"];
$device_model = $row["device_model"];
$device_firmware_version = $row["device_firmware_version"];
$device_enabled = $row["device_enabled"];
$device_template = $row["device_template"];
$device_profile_uuid = $row["device_profile_uuid"];
$device_description = $row["device_description"];
}
unset($row);
//}
//find a template that was defined on another phone and use that as the default. //find a template that was defined on another phone and use that as the default.
if (strlen($device_template) == 0) { if (strlen($device_template) == 0) {
$sql = "SELECT * FROM v_devices "; $sql = "select * from v_devices ";
$sql .= "WHERE domain_uuid=:domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
$sql .= "AND device_enabled='true' "; $sql .= "and device_enabled = 'true' ";
$sql .= "limit 1 "; $sql .= "limit 1 ";
$parameters['domain_uuid'] = $domain_uuid; $parameters['domain_uuid'] = $domain_uuid;
$database = new database; $database = new database;
@ -395,6 +383,7 @@ include "root.php";
$templates['Linksys/SPA-2102'] = 'linksys/spa2102'; $templates['Linksys/SPA-2102'] = 'linksys/spa2102';
$templates['Linksys/SPA-3102'] = 'linksys/spa3102'; $templates['Linksys/SPA-3102'] = 'linksys/spa3102';
$templates['Linksys/SPA-9212'] = 'linksys/spa921'; $templates['Linksys/SPA-9212'] = 'linksys/spa921';
$templates['Cisco/SPA301'] = 'cisco/spa301'; $templates['Cisco/SPA301'] = 'cisco/spa301';
$templates['Cisco/SPA301D'] = 'cisco/spa302d'; $templates['Cisco/SPA301D'] = 'cisco/spa302d';
$templates['Cisco/SPA303'] = 'cisco/spa303'; $templates['Cisco/SPA303'] = 'cisco/spa303';
@ -406,6 +395,7 @@ include "root.php";
$templates['Cisco/SPA512G'] = 'cisco/spa512g'; $templates['Cisco/SPA512G'] = 'cisco/spa512g';
$templates['Cisco/SPA514G'] = 'cisco/spa514g'; $templates['Cisco/SPA514G'] = 'cisco/spa514g';
$templates['Cisco/SPA525G2'] = 'cisco/spa525g2'; $templates['Cisco/SPA525G2'] = 'cisco/spa525g2';
$templates['snom300-SIP'] = 'snom/300'; $templates['snom300-SIP'] = 'snom/300';
$templates['snom320-SIP'] = 'snom/320'; $templates['snom320-SIP'] = 'snom/320';
$templates['snom360-SIP'] = 'snom/360'; $templates['snom360-SIP'] = 'snom/360';
@ -468,6 +458,7 @@ include "root.php";
$templates['HW GXV3140'] = 'grandstream/gxv3140'; $templates['HW GXV3140'] = 'grandstream/gxv3140';
$templates['HW GXV3240'] = 'grandstream/gxv3240'; $templates['HW GXV3240'] = 'grandstream/gxv3240';
$templates['HW GXV3175'] = 'grandstream/gxv3175'; $templates['HW GXV3175'] = 'grandstream/gxv3175';
$templates['PolycomVVX-VVX_101-UA/4'] = 'polycom/4.x'; $templates['PolycomVVX-VVX_101-UA/4'] = 'polycom/4.x';
$templates['PolycomVVX-VVX_201-UA/4'] = 'polycom/4.x'; $templates['PolycomVVX-VVX_201-UA/4'] = 'polycom/4.x';
$templates['PolycomVVX-VVX_300-UA/4'] = 'polycom/4.x'; $templates['PolycomVVX-VVX_300-UA/4'] = 'polycom/4.x';
@ -492,6 +483,7 @@ include "root.php";
$templates['PolycomVVX-VVX_501-UA/5'] = 'polycom/5.x'; $templates['PolycomVVX-VVX_501-UA/5'] = 'polycom/5.x';
$templates['PolycomVVX-VVX_600-UA/5'] = 'polycom/5.x'; $templates['PolycomVVX-VVX_600-UA/5'] = 'polycom/5.x';
$templates['PolycomVVX-VVX_601-UA/5'] = 'polycom/5.x'; $templates['PolycomVVX-VVX_601-UA/5'] = 'polycom/5.x';
$templates['Vesa VCS754'] = 'vtech/vcs754'; $templates['Vesa VCS754'] = 'vtech/vcs754';
$templates['Wget/1.11.3'] = 'konftel/kt300ip'; $templates['Wget/1.11.3'] = 'konftel/kt300ip';
foreach ($templates as $key=>$value){ foreach ($templates as $key=>$value){
@ -503,7 +495,7 @@ include "root.php";
unset($templates); unset($templates);
//mac address does not exist in the table so add it //mac address does not exist in the table so add it
if ($_SESSION['provision']['auto_insert_enabled']['boolean'] == "true" and strlen($domain_uuid) > 0) { if ($_SESSION['provision']['auto_insert_enabled']['boolean'] == "true" && is_uuid($domain_uuid)) {
//get a new primary key //get a new primary key
$device_uuid = uuid(); $device_uuid = uuid();
@ -541,12 +533,12 @@ include "root.php";
//} //}
//alternate device_uuid //alternate device_uuid
if (strlen($device_uuid) > 0 && is_uuid($device_uuid)) { if (is_uuid($device_uuid)) {
$sql = "SELECT * FROM v_devices "; $sql = "select * from v_devices ";
$sql .= "WHERE device_uuid = :device_uuid "; $sql .= "where device_uuid = :device_uuid ";
$sql .= "AND device_enabled = 'true' "; $sql .= "and device_enabled = 'true' ";
if ($provision['http_domain_filter'] == "true") { if ($provision['http_domain_filter'] == "true") {
$sql .= "AND domain_uuid=:domain_uuid "; $sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid; $parameters['domain_uuid'] = $domain_uuid;
} }
$parameters['device_uuid'] = $device_uuid; $parameters['device_uuid'] = $device_uuid;
@ -559,10 +551,10 @@ include "root.php";
//override the original device_uuid //override the original device_uuid
$device_uuid = $device_uuid_alternate; $device_uuid = $device_uuid_alternate;
//get the new devices information //get the new devices information
$sql = "SELECT * FROM v_devices "; $sql = "select * from v_devices ";
$sql .= "WHERE device_uuid = :device_uuid "; $sql .= "where device_uuid = :device_uuid ";
if($provision['http_domain_filter'] == "true") { if($provision['http_domain_filter'] == "true") {
$sql .= "AND domain_uuid=:domain_uuid "; $sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid; $parameters['domain_uuid'] = $domain_uuid;
} }
$parameters['device_uuid'] = $device_uuid; $parameters['device_uuid'] = $device_uuid;
@ -585,10 +577,10 @@ include "root.php";
} }
//get the device settings table in the provision category from the profile and update the provision array //get the device settings table in the provision category from the profile and update the provision array
if ((strlen($device_uuid) > 0) and (strlen($device_profile_uuid) > 0)) { if (is_uuid($device_uuid) && is_uuid($device_profile_uuid)) {
$sql = "SELECT * FROM v_device_profile_settings "; $sql = "select * from v_device_profile_settings ";
$sql .= "WHERE device_profile_uuid = :device_profile_uuid "; $sql .= "where device_profile_uuid = :device_profile_uuid ";
$sql .= "AND profile_setting_enabled = 'true' "; $sql .= "and profile_setting_enabled = 'true' ";
$parameters['device_profile_uuid'] = $device_profile_uuid; $parameters['device_profile_uuid'] = $device_profile_uuid;
$database = new database; $database = new database;
$device_profile_settings = $database->select($sql, $parameters, 'all'); $device_profile_settings = $database->select($sql, $parameters, 'all');
@ -603,10 +595,10 @@ include "root.php";
} }
//get the device settings table in the provision category and update the provision array //get the device settings table in the provision category and update the provision array
if (strlen($device_uuid) > 0) { if (is_uuid($device_uuid)) {
$sql = "SELECT * FROM v_device_settings "; $sql = "select * from v_device_settings ";
$sql .= "WHERE device_uuid = :device_uuid "; $sql .= "where device_uuid = :device_uuid ";
$sql .= "AND device_setting_enabled = 'true' "; $sql .= "and device_setting_enabled = 'true' ";
$parameters['device_uuid'] = $device_uuid; $parameters['device_uuid'] = $device_uuid;
$database = new database; $database = new database;
$device_settings = $database->select($sql, $parameters, 'all'); $device_settings = $database->select($sql, $parameters, 'all');
@ -648,7 +640,7 @@ include "root.php";
$mac_dash = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2); $mac_dash = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
//get the provisioning information from device lines table //get the provisioning information from device lines table
if (strlen($device_uuid) > 0) { if (is_uuid($device_uuid)) {
//get the device lines array //get the device lines array
$sql = "select * from v_device_lines "; $sql = "select * from v_device_lines ";
$sql .= "where device_uuid = :device_uuid "; $sql .= "where device_uuid = :device_uuid ";
@ -739,7 +731,7 @@ include "root.php";
$view->assign("user", $lines); $view->assign("user", $lines);
//get the list of contact directly assigned to the user //get the list of contact directly assigned to the user
if (strlen($device_user_uuid) > 0 and strlen($domain_uuid) > 0) { if (is_uuid($device_user_uuid) && is_uuid($domain_uuid)) {
//get the contacts assigned to the groups and add to the contacts array //get the contacts assigned to the groups and add to the contacts array
if ($_SESSION['provision']['contact_groups']['boolean'] == "true") { if ($_SESSION['provision']['contact_groups']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, true); $this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, true);
@ -752,7 +744,7 @@ include "root.php";
} }
//get the extensions and add them to the contacts array //get the extensions and add them to the contacts array
if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0 and $_SESSION['provision']['contact_extensions']['boolean'] == "true") { if (is_uuid($device_uuid) && is_uuid($domain_uuid) && $_SESSION['provision']['contact_extensions']['boolean'] == "true") {
//get contacts from the database //get contacts from the database
$sql = "select extension_uuid as contact_uuid, directory_first_name, directory_last_name, "; $sql = "select extension_uuid as contact_uuid, directory_first_name, directory_last_name, ";
$sql .= "effective_caller_id_name, effective_caller_id_number, "; $sql .= "effective_caller_id_name, effective_caller_id_number, ";
@ -807,11 +799,11 @@ include "root.php";
} }
//get the provisioning information from device keys //get the provisioning information from device keys
if (isset($device_uuid)) { if (is_uuid($device_uuid)) {
//get the device profile keys //get the device profile keys
if (isset($device_profile_uuid) && is_uuid($device_profile_uuid)) { if (is_uuid($device_profile_uuid)) {
$sql = "SELECT "; $sql = "select ";
$sql .= "profile_key_id as device_key_id, "; $sql .= "profile_key_id as device_key_id, ";
$sql .= "profile_key_category as device_key_category, "; $sql .= "profile_key_category as device_key_category, ";
$sql .= "profile_key_vendor as device_key_vendor, "; $sql .= "profile_key_vendor as device_key_vendor, ";
@ -822,28 +814,28 @@ include "root.php";
$sql .= "profile_key_protected as device_key_protected, "; $sql .= "profile_key_protected as device_key_protected, ";
$sql .= "profile_key_label as device_key_label, "; $sql .= "profile_key_label as device_key_label, ";
$sql .= "profile_key_icon as device_key_icon "; $sql .= "profile_key_icon as device_key_icon ";
$sql .= "FROM v_device_profile_keys "; $sql .= "from v_device_profile_keys ";
$sql .= "WHERE device_profile_uuid = :device_profile_uuid "; $sql .= "where device_profile_uuid = :device_profile_uuid ";
if (strtolower($device_vendor) == 'escene'){ if (strtolower($device_vendor) == 'escene'){
$sql .= "AND (lower(profile_key_vendor) = 'escene' or lower(profile_key_vendor) = 'escene programmable' or profile_key_vendor is null) "; $sql .= "and (lower(profile_key_vendor) = 'escene' or lower(profile_key_vendor) = 'escene programmable' or profile_key_vendor is null) ";
} }
else { else {
$sql .= "AND (lower(profile_key_vendor) = :device_vendor or profile_key_vendor is null) "; $sql .= "and (lower(profile_key_vendor) = :device_vendor or profile_key_vendor is null) ";
$parameters['device_vendor'] = $device_vendor; $parameters['device_vendor'] = $device_vendor;
} }
$sql .= "ORDER BY "; $sql .= "order by ";
$sql .= "profile_key_vendor ASC, "; $sql .= "profile_key_vendor asc, ";
$sql .= "CASE profile_key_category "; $sql .= "case profile_key_category ";
$sql .= "WHEN 'line' THEN 1 "; $sql .= "when 'line' then 1 ";
$sql .= "WHEN 'memory' THEN 2 "; $sql .= "when 'memory' then 2 ";
$sql .= "WHEN 'programmable' THEN 3 "; $sql .= "when 'programmable' then 3 ";
$sql .= "WHEN 'expansion' THEN 4 "; $sql .= "when 'expansion' then 4 ";
$sql .= "ELSE 100 END, "; $sql .= "else 100 end, ";
if ($GLOBALS['db_type'] == "mysql") { if ($GLOBALS['db_type'] == "mysql") {
$sql .= "profile_key_id ASC "; $sql .= "profile_key_id asc ";
} }
else { else {
$sql .= "CAST(profile_key_id as numeric) ASC "; $sql .= "cast(profile_key_id as numeric) asc ";
} }
$parameters['device_profile_uuid'] = $device_profile_uuid; $parameters['device_profile_uuid'] = $device_profile_uuid;
$database = new database; $database = new database;
@ -868,28 +860,28 @@ include "root.php";
} }
//get the device keys //get the device keys
$sql = "SELECT * FROM v_device_keys "; $sql = "select * from v_device_keys ";
$sql .= "WHERE device_uuid = :device_uuid "; $sql .= "where device_uuid = :device_uuid ";
if (strtolower($device_vendor) == 'escene'){ if (strtolower($device_vendor) == 'escene'){
$sql .= "AND (lower(device_key_vendor) = 'escene' or lower(device_key_vendor) = 'escene programmable' or device_key_vendor is null) "; $sql .= "and (lower(device_key_vendor) = 'escene' or lower(device_key_vendor) = 'escene programmable' or device_key_vendor is null) ";
} }
else { else {
$sql .= "AND (lower(device_key_vendor) = :device_vendor or device_key_vendor is null) "; $sql .= "and (lower(device_key_vendor) = :device_vendor or device_key_vendor is null) ";
$parameters['device_vendor'] = $device_vendor; $parameters['device_vendor'] = $device_vendor;
} }
$sql .= "ORDER BY "; $sql .= "order by ";
$sql .= "device_key_vendor ASC, "; $sql .= "device_key_vendor asc, ";
$sql .= "CASE device_key_category "; $sql .= "case device_key_category ";
$sql .= "WHEN 'line' THEN 1 "; $sql .= "when 'line' then 1 ";
$sql .= "WHEN 'memory' THEN 2 "; $sql .= "when 'memory' then 2 ";
$sql .= "WHEN 'programmable' THEN 3 "; $sql .= "when 'programmable' then 3 ";
$sql .= "WHEN 'expansion' THEN 4 "; $sql .= "when 'expansion' then 4 ";
$sql .= "ELSE 100 END, "; $sql .= "else 100 end, ";
if ($GLOBALS['db_type'] == "mysql") { if ($GLOBALS['db_type'] == "mysql") {
$sql .= "device_key_id ASC "; $sql .= "device_key_id asc ";
} }
else { else {
$sql .= "CAST(device_key_id as numeric) ASC "; $sql .= "cast(device_key_id as numeric) asc ";
} }
$parameters['device_uuid'] = $device_uuid; $parameters['device_uuid'] = $device_uuid;
$database = new database; $database = new database;
@ -1048,7 +1040,6 @@ include "root.php";
} }
} }
} }
unset ($prep_statement);
//set the mac address in the correct format //set the mac address in the correct format
$mac = $this->format_mac($mac, $device_vendor); $mac = $this->format_mac($mac, $device_vendor);
@ -1056,7 +1047,8 @@ include "root.php";
// set date/time for versioning provisioning templates // set date/time for versioning provisioning templates
if (strlen($_SESSION['provision']['version_format']['text']) > 0) { if (strlen($_SESSION['provision']['version_format']['text']) > 0) {
$time = date($_SESSION['provision']['version_format']['text']); $time = date($_SESSION['provision']['version_format']['text']);
} else { }
else {
$time = date("dmyHi"); $time = date("dmyHi");
} }
@ -1077,8 +1069,8 @@ include "root.php";
//personal ldap password //personal ldap password
global $laddr_salt; global $laddr_salt;
if (isset($device_user_uuid)) { if (is_uuid($device_user_uuid)) {
$sql = "SELECT contact_uuid FROM v_users WHERE user_uuid = :device_user_uuid "; $sql = "select contact_uuid from v_users where user_uuid = :device_user_uuid ";
$parameters['device_user_uuid'] = $device_user_uuid; $parameters['device_user_uuid'] = $device_user_uuid;
$database = new database; $database = new database;
$contact_uuid = $database->select($sql, $parameters, 'column'); $contact_uuid = $database->select($sql, $parameters, 'column');
@ -1173,9 +1165,9 @@ include "root.php";
function write() { function write() {
//build the provision array //build the provision array
$provision = Array(); $provision = array();
if (is_array($_SESSION['provision'])) { if (is_array($_SESSION['provision'])) {
foreach($_SESSION['provision'] as $key=>$val) { foreach ($_SESSION['provision'] as $key => $val) {
if (strlen($val['var']) > 0) { $value = $val['var']; } if (strlen($val['var']) > 0) { $value = $val['var']; }
if (strlen($val['text']) > 0) { $value = $val['text']; } if (strlen($val['text']) > 0) { $value = $val['text']; }
if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } if (strlen($val['boolean']) > 0) { $value = $val['boolean']; }
@ -1186,7 +1178,7 @@ include "root.php";
} }
//check either we have destination path to write files //check either we have destination path to write files
if(strlen($provision["path"]) == 0) { if (strlen($provision["path"]) == 0) {
return; return;
} }
@ -1198,101 +1190,107 @@ include "root.php";
$result = $database->select($sql, null, 'all'); $result = $database->select($sql, null, 'all');
//process each device //process each device
if (is_array($result)) foreach ($result as &$row) { if (is_array($result)) {
//get the values from the database and set as variables foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"]; //get the values from the database and set as variables
$device_uuid = $row["device_uuid"]; $domain_uuid = $row["domain_uuid"];
$device_mac_address = $row["device_mac_address"]; $device_uuid = $row["device_uuid"];
$device_label = $row["device_label"]; $device_mac_address = $row["device_mac_address"];
$device_vendor = strtolower($row["device_vendor"]); $device_label = $row["device_label"];
$device_model = $row["device_model"]; $device_vendor = strtolower($row["device_vendor"]);
$device_firmware_version = $row["device_firmware_version"]; $device_model = $row["device_model"];
$device_enabled = $row["device_enabled"]; $device_firmware_version = $row["device_firmware_version"];
$device_template = $row["device_template"]; $device_enabled = $row["device_enabled"];
$device_username = $row["device_username"]; $device_template = $row["device_template"];
$device_password = $row["device_password"]; $device_username = $row["device_username"];
$device_description = $row["device_description"]; $device_password = $row["device_password"];
$device_description = $row["device_description"];
//clear the cache //clear the cache
clearstatcache(); clearstatcache();
//loop through the provision template directory //loop through the provision template directory
$dir_array = array(); $dir_array = array();
if (strlen($device_template) > 0) { if (strlen($device_template) > 0) {
$template_path = path_join($this->template_dir, $device_template); $template_path = path_join($this->template_dir, $device_template);
$dir_list = opendir($template_path); $dir_list = opendir($template_path);
if ($dir_list) { if ($dir_list) {
$x = 0; $x = 0;
while (false !== ($file = readdir($dir_list))) { while (false !== ($file = readdir($dir_list))) {
$ignore = $file == "." || $file == ".." || substr($file, -3) == ".db" || $ignore = $file == "." || $file == ".." || substr($file, -3) == ".db" ||
substr($file, -4) == ".svn" || substr($file, -4) == ".git"; substr($file, -4) == ".svn" || substr($file, -4) == ".git";
if (!$ignore) { if (!$ignore) {
$dir_array[] = path_join($template_path, $file); $dir_array[] = path_join($template_path, $file);
if ($x > 1000) { break; }; if ($x > 1000) { break; };
$x++; $x++;
}
} }
closedir($dir_list);
unset($x, $file);
} }
closedir($dir_list); unset($dir_list, $template_path);
unset($x, $file);
} }
unset($dir_list, $template_path);
}
//loop through the provision templates //loop through the provision templates
if (is_array($dir_array)) foreach ($dir_array as &$template_path) { if (is_array($dir_array)) {
if (is_dir($template_path)) continue; foreach ($dir_array as &$template_path) {
if (!file_exists($template_path)) continue; if (is_dir($template_path)) continue;
if (!file_exists($template_path)) continue;
//template file name //template file name
$file_name = basename($template_path); $file_name = basename($template_path);
//configure device object //configure device object
$this->domain_uuid = $domain_uuid; $this->domain_uuid = $domain_uuid;
$this->mac = $device_mac_address; $this->mac = $device_mac_address;
$this->file = $file_name; $this->file = $file_name;
//format the mac address //format the mac address
$mac = $this->format_mac($device_mac_address, $device_vendor); $mac = $this->format_mac($device_mac_address, $device_vendor);
//replace {$mac} in the file name //replace {$mac} in the file name
$file_name = str_replace("{\$mac}", $mac, $file_name); $file_name = str_replace("{\$mac}", $mac, $file_name);
//render and write configuration to file //render and write configuration to file
$provision_dir_array = explode(";", $provision["path"]); $provision_dir_array = explode(";", $provision["path"]);
if (is_array($provision_dir_array)) foreach($provision_dir_array as $directory) { if (is_array($provision_dir_array)) {
//destinatino file path foreach ($provision_dir_array as $directory) {
$dest_path = path_join($directory, $file_name); //destinatino file path
$dest_path = path_join($directory, $file_name);
if ($device_enabled == 'true') { if ($device_enabled == 'true') {
//output template to string for header processing //output template to string for header processing
$file_contents = $this->render(); $file_contents = $this->render();
//write the file //write the file
if(!is_dir($directory)) { if (!is_dir($directory)) {
mkdir($directory, 0777, true); mkdir($directory, 0777, true);
} }
$fh = fopen($dest_path,"w") or die("Unable to write to $directory for provisioning. Make sure the path exists and permissons are set correctly."); $fh = fopen($dest_path,"w") or die("Unable to write to $directory for provisioning. Make sure the path exists and permissons are set correctly.");
fwrite($fh, $file_contents); fwrite($fh, $file_contents);
fclose($fh); fclose($fh);
}
else { // device disabled
//remove only files with `{$mac}` name
if (strpos($template_path, '{$mac}') !== false){
unlink($dest_path);
}
}
unset($dest_path);
}
} }
else { // device disabled //unset variables
//remove only files with `{$mac}` name unset($file_name, $provision_dir_array);
if(strpos($template_path, '{$mac}') !== false){
unlink($dest_path);
}
}
unset($dest_path);
} }
//unset variables }
unset($file_name, $provision_dir_array);
} //end for each
//unset variables //unset variables
unset($dir_array); unset($dir_array);
}
} }
} //end write function } //end write function
} //end provision class } //end provision class
?> ?>

View File

@ -29,19 +29,11 @@
if (!class_exists('streams')) { if (!class_exists('streams')) {
class streams { class streams {
public $db;
/** /**
* Called when the object is created * Called when the object is created
*/ */
public function __construct() { 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;
}
} }
/** /**
@ -71,21 +63,36 @@ if (!class_exists('streams')) {
} }
//delete the checked rows //delete the checked rows
if ($action == 'delete') { if ($action == 'delete') {
$x = 0;
foreach($streams as $row) { foreach($streams as $row) {
if ($row['action'] == 'delete' or $row['checked'] == 'true') { if ($row['action'] == 'delete' or $row['checked'] == 'true') {
$sql = "delete from v_streams "; //build delete array
$sql .= "where stream_uuid = '".$row['stream_uuid']."'; "; $array['streams'][$x++]['stream_uuid'] = $row['stream_uuid'];
$this->db->query($sql); $x++;
unset($sql);
} }
} }
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('stream_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = 'streams';
$database->app_uuid = 'ffde6287-aa18-41fc-9a38-076d292e0a38';
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('stream_delete', 'temp');
}
unset($streams); unset($streams);
} }
} }
} }
} //end the delete function }
} //end the class }
} }
/* /*
@ -93,4 +100,4 @@ $obj = new streams;
$obj->delete(); $obj->delete();
*/ */
?> ?>