Update provision.php

This commit is contained in:
FusionPBX 2019-06-09 18:44:33 -06:00 committed by GitHub
parent 0fcaec3f06
commit c75ee3cb5a
1 changed files with 23 additions and 19 deletions

View File

@ -199,7 +199,7 @@ include "root.php";
}
}
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) {
$sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
$sql .= "c.contact_type, c.contact_category, p.phone_label,";
$sql .= "p.phone_number, p.phone_extension, p.phone_primary ";
@ -267,7 +267,7 @@ include "root.php";
}
}
private function contact_grandstream(&$contacts, &$line, $domain_uuid, $device_user_uuid){
private function contact_grandstream(&$contacts, &$line, $domain_uuid, $device_user_uuid) {
// Get username for this.
$sql = "SELECT username FROM v_users WHERE user_uuid = '${device_user_uuid}' AND domain_uuid = '${domain_uuid}' LIMIT 1";
$prep_statement = $this->db->prepare(check_sql($sql));
@ -280,7 +280,7 @@ include "root.php";
// Easier than assigning these common groups to every user.
// Check provision global_contact_groups and sanitize for sql.
$global_contact_groups['enabled']=false;
if ( preg_match('/[a-zA-Z0-9-_, ]/',$_SESSION['provision']['grandstream_global_contact_groups']['text'])){
if ( preg_match('/[a-zA-Z0-9-_, ]/',$_SESSION['provision']['grandstream_global_contact_groups']['text'])) {
$global_contact_groups['enabled']=true;
$gp=array();
$groups=explode(',',$_SESSION['provision']['grandstream_global_contact_groups']['text']);
@ -297,13 +297,14 @@ include "root.php";
$sql .= " INNER JOIN v_contact_groups cg ";
$sql .= " ON cg.group_uuid = g.group_uuid ";
$sql .= "WHERE ug.user_uuid = '$device_user_uuid' ";
if ( $global_contact_groups['enabled'] ){
if ($global_contact_groups['enabled']) {
$sql .= "UNION ";
$sql .= "SELECT g.group_uuid, g.group_name, g.group_description ";
$sql .= "FROM v_groups g ";
$sql .= "WHERE g.group_name IN( ".$global_contact_groups['sql'].") ";
}
$sql .= "ORDER BY group_description";
//echo $sql."\n\n";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$user_groups = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@ -327,7 +328,7 @@ include "root.php";
$sql .= " FROM v_user_groups ug ";
$sql .= " WHERE ug.user_uuid = '$device_user_uuid' ";
$sql .= " AND ug.domain_uuid = '$domain_uuid' ";
if ( $global_contact_groups['enabled'] ){
if ($global_contact_groups['enabled']) {
$sql .= " UNION ";
$sql .= " SELECT g.group_uuid ";
$sql .= " FROM v_groups g ";
@ -341,6 +342,8 @@ include "root.php";
$sql .= " AND cu.domain_uuid = '$domain_uuid' ";
$sql .= ")";
$sql .= "ORDER BY contact_name_given, contact_name_family";
//echo $sql."\n\n";
//exit;
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$user_contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@ -956,7 +959,8 @@ include "root.php";
if ($_SESSION['provision']['contact_users']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, false);
}
// Grandstream get the contacts assigned to the user and groups and add to the contacts array
//get the contacts assigned to the user and groups and add to the contacts array
if ($_SESSION['provision']['contact_grandstream']['boolean'] == "true") {
$this->contact_grandstream($contacts, $line, $domain_uuid, $device_user_uuid);
}
@ -1246,7 +1250,7 @@ include "root.php";
// personal ldap password
global $laddr_salt;
if (isset($device_user_uuid)){
if (isset($device_user_uuid)) {
$sql = "SELECT contact_uuid FROM v_users WHERE user_uuid='".$device_user_uuid."'";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
@ -1312,7 +1316,7 @@ include "root.php";
//make sure the file exists
if (!file_exists($template_dir."/".$device_template ."/".$file)) {
echo "file not found ".$template_dir."/".$device_template ."/".$file;
if ($_SESSION['provision']['debug']['boolean'] == 'true'){
if ($_SESSION['provision']['debug']['boolean'] == 'true') {
echo ":$template_dir/$device_template/$file<br/>";
echo "template_dir: $template_dir<br/>";
echo "device_template: $device_template<br/>";
@ -1326,7 +1330,7 @@ include "root.php";
$file_contents = $view->render($file);
//log file for testing
if ($_SESSION['provision']['debug']['boolean'] == 'true'){
if ($_SESSION['provision']['debug']['boolean'] == 'true') {
$tmp_file = "/tmp/provisioning_log.txt";
$fh = fopen($tmp_file, 'w') or die("can't open file");
$tmp_string = $mac."\n";
@ -1355,7 +1359,7 @@ include "root.php";
}
//check either we have destination path to write files
if(strlen($provision["path"]) == 0){
if(strlen($provision["path"]) == 0) {
return;
}
@ -1432,7 +1436,7 @@ include "root.php";
//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
$file_contents = $this->render();
@ -1444,7 +1448,7 @@ include "root.php";
fwrite($fh, $file_contents);
fclose($fh);
}
else{ // device disabled
else { // device disabled
//remove only files with `{$mac}` name
if(strpos($template_path, '{$mac}') !== false){
unlink($dest_path);