From bd23c786704261c112debde023736c7c2e56c101 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Tue, 28 Jun 2016 15:18:40 -0600 Subject: [PATCH] Use FreeSWITCH to run mkdir so it inherits its own user and group permissions. --- app/calls_active/calls_active_inc.php | 2 +- app/dialplan_inbound/app_defaults.php | 4 ++-- app/extensions/app_defaults.php | 2 +- .../resources/classes/extension.php | 2 +- app/fax/fax_edit.php | 10 ++++---- app/fax/fax_files.php | 10 ++++---- app/fax/fax_send.php | 14 +++++------ app/music_on_hold/music_on_hold.php | 2 +- app/phrases/app_defaults.php | 2 +- app/recordings/app_defaults.php | 2 +- .../voicemail_greetings.php | 2 +- app/voicemails/app_defaults.php | 2 +- app/xml_cdr/resources/classes/xml_cdr.php | 4 ++-- app/xml_cdr/v_xml_cdr_import.php | 4 ++-- resources/functions.php | 24 +++++++++++++++++++ resources/switch.php | 10 ++++---- 16 files changed, 60 insertions(+), 36 deletions(-) diff --git a/app/calls_active/calls_active_inc.php b/app/calls_active/calls_active_inc.php index dd125d4030..74d8b05995 100644 --- a/app/calls_active/calls_active_inc.php +++ b/app/calls_active/calls_active_inc.php @@ -217,7 +217,7 @@ else { echo " ".$text['label-park']." \n"; //record start/stop $tmp_dir = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d"); - mkdir($tmp_dir, 02770, true); + event_socket_mkdir($tmp_dir); $tmp_file = $tmp_dir."/".$uuid.".wav"; if (file_exists($tmp_file)) { //stop diff --git a/app/dialplan_inbound/app_defaults.php b/app/dialplan_inbound/app_defaults.php index 273039313e..911ff1f94e 100644 --- a/app/dialplan_inbound/app_defaults.php +++ b/app/dialplan_inbound/app_defaults.php @@ -52,7 +52,7 @@ //if the public directory doesn't exist then create it if ($domains_processed == 1) { if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { - if (!is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { mkdir($_SESSION['switch']['dialplan']['dir'].'/public',02770,true); } + if (!is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { event_socket_mkdir($_SESSION['switch']['dialplan']['dir'].'/public'); } } } @@ -61,7 +61,7 @@ //make sure the public directory and xml file exist if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { if (!is_dir($_SESSION['switch']['dialplan']['dir'].'/public'.$_SESSION['domains'][$domain_uuid]['domain_name'])) { - mkdir($_SESSION['switch']['dialplan']['dir'].'/public/'.$_SESSION['domains'][$domain_uuid]['domain_name'],02770,true); + event_socket_mkdir($_SESSION['switch']['dialplan']['dir'].'/public/'.$_SESSION['domains'][$domain_uuid]['domain_name']); } $file = $_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$domain_uuid]['domain_name'].".xml"; if (!file_exists($file)) { diff --git a/app/extensions/app_defaults.php b/app/extensions/app_defaults.php index 1c58229baf..d06a2f30f8 100644 --- a/app/extensions/app_defaults.php +++ b/app/extensions/app_defaults.php @@ -27,7 +27,7 @@ //if the extensions dir doesn't exist then create it if ($domains_processed == 1) { if (strlen($_SESSION['switch']['extensions']['dir']) > 0) { - if (!is_dir($_SESSION['switch']['extensions']['dir'])) { mkdir($_SESSION['switch']['extensions']['dir'],02770,true); } + if (!is_dir($_SESSION['switch']['extensions']['dir'])) { event_socket_mkdir($_SESSION['switch']['extensions']['dir']); } } } diff --git a/app/extensions/resources/classes/extension.php b/app/extensions/resources/classes/extension.php index 685c022efa..bcc4f4f88c 100644 --- a/app/extensions/resources/classes/extension.php +++ b/app/extensions/resources/classes/extension.php @@ -397,7 +397,7 @@ if (!class_exists('extension')) { $xml .= " \n"; if (!is_readable($_SESSION['switch']['extensions']['dir']."/".$row['user_context'])) { - mkdir($_SESSION['switch']['extensions']['dir']."/".$row['user_context'],02770,true); + event_socket_mkdir($_SESSION['switch']['extensions']['dir']."/".$row['user_context']); } if (strlen($extension) > 0) { $fout = fopen($_SESSION['switch']['extensions']['dir']."/".$row['user_context']."/v_".$extension.".xml","w"); diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php index 94a32320ec..125e781b69 100644 --- a/app/fax/fax_edit.php +++ b/app/fax/fax_edit.php @@ -64,19 +64,19 @@ else { //make sure the directories exist if (!is_dir($_SESSION['switch']['storage']['dir'])) { - mkdir($_SESSION['switch']['storage']['dir'],02770,true); + event_socket_mkdir($_SESSION['switch']['storage']['dir']); } if (!is_dir($fax_dir.'/'.$fax_extension)) { - mkdir($fax_dir.'/'.$fax_extension,02770,true); + event_socket_mkdir($fax_dir.'/'.$fax_extension); } if (!is_dir($dir_fax_inbox)) { - mkdir($dir_fax_inbox,02770,true); + event_socket_mkdir($dir_fax_inbox); } if (!is_dir($dir_fax_sent)) { - mkdir($dir_fax_sent,02770,true); + event_socket_mkdir($dir_fax_sent); } if (!is_dir($dir_fax_temp)) { - mkdir($dir_fax_temp,02770,true); + event_socket_mkdir($dir_fax_temp); } } diff --git a/app/fax/fax_files.php b/app/fax/fax_files.php index 8a7cce084f..b9323e5ed3 100644 --- a/app/fax/fax_files.php +++ b/app/fax/fax_files.php @@ -145,19 +145,19 @@ else { //make sure the directories exist if (!is_dir($_SESSION['switch']['storage']['dir'])) { - mkdir($_SESSION['switch']['storage']['dir'],02770,true); + event_socket_mkdir($_SESSION['switch']['storage']['dir']); } if (!is_dir($fax_dir.'/'.$fax_extension)) { - mkdir($fax_dir.'/'.$fax_extension,02770,true); + event_socket_mkdir($fax_dir.'/'.$fax_extension); } if (!is_dir($dir_fax_inbox)) { - mkdir($dir_fax_inbox,02770,true); + event_socket_mkdir($dir_fax_inbox); } if (!is_dir($dir_fax_sent)) { - mkdir($dir_fax_sent,02770,true); + event_socket_mkdir($dir_fax_sent); } if (!is_dir($dir_fax_temp)) { - mkdir($dir_fax_temp,02770,true); + event_socket_mkdir($dir_fax_temp); } } diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index 85c02c03dd..83dd0cee8f 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -206,25 +206,25 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ //make sure the directories exist if (!is_dir($_SESSION['switch']['storage']['dir'])) { - mkdir($_SESSION['switch']['storage']['dir'],02770,true); + event_socket_mkdir($_SESSION['switch']['storage']['dir']); } if (!is_dir($_SESSION['switch']['storage']['dir'].'/fax')) { - mkdir($_SESSION['switch']['storage']['dir'].'/fax',02770,true); + event_socket_mkdir($_SESSION['switch']['storage']['dir'].'/fax'); } if (!is_dir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'])) { - mkdir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'],02770,true); + event_socket_mkdir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']); } if (!is_dir($fax_dir.'/'.$fax_extension)) { - mkdir($fax_dir.'/'.$fax_extension,02770,true); + event_socket_mkdir($fax_dir.'/'.$fax_extension); } if (!is_dir($dir_fax_inbox)) { - mkdir($dir_fax_inbox,02770,true); + event_socket_mkdir($dir_fax_inbox); } if (!is_dir($dir_fax_sent)) { - mkdir($dir_fax_sent,02770,true); + event_socket_mkdir($dir_fax_sent); } if (!is_dir($dir_fax_temp)) { - mkdir($dir_fax_temp,02770,true); + event_socket_mkdir($dir_fax_temp); } } diff --git a/app/music_on_hold/music_on_hold.php b/app/music_on_hold/music_on_hold.php index 5a652237e2..5e4ee3ec98 100644 --- a/app/music_on_hold/music_on_hold.php +++ b/app/music_on_hold/music_on_hold.php @@ -231,7 +231,7 @@ } //check target folder, move uploaded file if (!is_dir($moh_path)) { - mkdir($moh_path, 02770, true); + event_socket_mkdir($moh_path); } if (is_dir($moh_path)) { if (copy($moh_file_name_temp, $moh_path.'/'.$moh_file_name)) { diff --git a/app/phrases/app_defaults.php b/app/phrases/app_defaults.php index ffc11cc54b..31e5b58e95 100644 --- a/app/phrases/app_defaults.php +++ b/app/phrases/app_defaults.php @@ -69,7 +69,7 @@ if ($domains_processed == 1) { foreach ($conf_lang_folders as $conf_lang_folder) { //create phrases folder, if necessary if (!file_exists($conf_lang_folder."/phrases/")) { - mkdir($conf_lang_folder."/phrases/", 02770); + event_socket_mkdir($conf_lang_folder."/phrases/"); } //parse language, open xml file $conf_lang = substr($conf_lang_folder, -2); diff --git a/app/recordings/app_defaults.php b/app/recordings/app_defaults.php index e44bb92fdc..bac35e648e 100644 --- a/app/recordings/app_defaults.php +++ b/app/recordings/app_defaults.php @@ -26,7 +26,7 @@ //if the recordings directory doesn't exist then create it if (strlen($_SESSION['switch']['recordings']['dir']."/".$domain_name) > 0) { - if (!is_readable($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { mkdir($_SESSION['switch']['recordings']['dir']."/".$domain_name,02770,true); } + if (!is_readable($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { event_socket_mkdir($_SESSION['switch']['recordings']['dir']."/".$domain_name,02770,true); } } if ($domains_processed == 1) { diff --git a/app/voicemail_greetings/voicemail_greetings.php b/app/voicemail_greetings/voicemail_greetings.php index 9b580efeea..73501d32bd 100644 --- a/app/voicemail_greetings/voicemail_greetings.php +++ b/app/voicemail_greetings/voicemail_greetings.php @@ -155,7 +155,7 @@ require_once "resources/check_auth.php"; $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (count($result) == 0 && !file_exists($v_greeting_dir.'/'.$file_name)) { //move the uploaded greeting - mkdir($v_greeting_dir, 02770, true); + event_socket_mkdir($v_greeting_dir); move_uploaded_file($_FILES['file']['tmp_name'], $v_greeting_dir.'/'.$file_name); //set newly uploaded greeting as active greeting for voicemail box $sql = "update v_voicemails "; diff --git a/app/voicemails/app_defaults.php b/app/voicemails/app_defaults.php index 724b83c574..5713ea38f3 100644 --- a/app/voicemails/app_defaults.php +++ b/app/voicemails/app_defaults.php @@ -42,7 +42,7 @@ if ($domains_processed == 1) { foreach ($voicemails as $row) { $path = $_SESSION['switch']['voicemail']['dir'].'/default/'.$row['domain_name'].'/'.$row['voicemail_id']; if (!file_exists($path)) { - mkdir($path, 02770, true); + event_socket_mkdir($path); } } unset ($prep_statement, $sql); diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index b908aea8e7..89b15e26d3 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -399,7 +399,7 @@ if (!class_exists('xml_cdr')) { catch(PDOException $e) { $tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/failed/'; if(!file_exists($tmp_dir)) { - mkdir($tmp_dir, 02770, true); + event_socket_mkdir($tmp_dir); } if ($_SESSION['cdr']['format']['text'] == "xml") { $tmp_file = $uuid.'.xml'; @@ -426,7 +426,7 @@ if (!class_exists('xml_cdr')) { $tmp_day = date("d", $tmp_time); $tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; if(!file_exists($tmp_dir)) { - mkdir($tmp_dir, 02770, true); + event_socket_mkdir($tmp_dir); } if ($_SESSION['cdr']['format']['text'] == "xml") { $tmp_file = $uuid.'.xml'; diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index 3792c44c14..465d12ddc5 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -445,7 +445,7 @@ catch(PDOException $e) { $tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/failed/'; if(!file_exists($tmp_dir)) { - mkdir($tmp_dir, 02770, true); + event_socket_mkdir($tmp_dir); } if ($_SESSION['cdr']['format']['text'] == "xml") { $tmp_file = $uuid.'.xml'; @@ -472,7 +472,7 @@ $tmp_day = date("d", $tmp_time); $tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; if(!file_exists($tmp_dir)) { - mkdir($tmp_dir, 02770, true); + event_socket_mkdir($tmp_dir); } if ($_SESSION['cdr']['format']['text'] == "xml") { $tmp_file = $uuid.'.xml'; diff --git a/resources/functions.php b/resources/functions.php index e8ac82d7b3..060a59243c 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -1956,4 +1956,28 @@ function number_pad($number,$n) { } } + function event_socket_mkdir($dir) { + //if the handle does not exist create it + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if (!$fp) { + return false; + } + //send the mkdir command to freeswitch + if ($fp) { + //send the api command to check if the module exists + $switch_cmd = "system mkdir -p '$dir'"; + $switch_result = event_socket_request($fp, 'api '.$switch_cmd); + unset($switch_cmd); + if (trim($switch_result) == "-ERR no reply") { + return true; + } + else { + return false; + } + } + else { + return false; + } + } + ?> \ No newline at end of file diff --git a/resources/switch.php b/resources/switch.php index 383f26cc50..10a0b8d8a3 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -942,12 +942,12 @@ function save_dialplan_xml() { $dialplan_filename = $dialplan_order."_v_".$dialplan_name.".xml"; if (strlen($row['dialplan_context']) > 0) { if (!is_dir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'])) { - mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'],02770,true); + event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']); } if ($row['dialplan_context'] == "public") { if (count($_SESSION['domains']) > 1 && strlen($row['domain_uuid']) > 0) { if (!is_dir($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name'])) { - mkdir($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name'],02770,true); + event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name']); } file_put_contents($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name']."/".$dialplan_filename, $tmp); } @@ -957,7 +957,7 @@ function save_dialplan_xml() { } else { if (!is_dir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'])) { - mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'],02770,true); + event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']); } file_put_contents($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']."/".$dialplan_filename, $tmp); } @@ -1334,7 +1334,7 @@ if (!function_exists('save_sip_profile_xml')) { // make profile dir if needed $profile_dir = $_SESSION['switch']['conf']['dir']."/sip_profiles"; - if (!is_readable($profile_dir)) { mkdir($profile_dir,02770,true); } + if (!is_readable($profile_dir)) { event_socket_mkdir($profile_dir); } //get the global variables global $domain_uuid; @@ -1399,7 +1399,7 @@ if (!function_exists('save_sip_profile_xml')) { } //if the directory does not exist then create it - if (!is_readable($profile_dir.'/'.$sip_profile_name)) { mkdir($profile_dir.'/'.$sip_profile_name,02770,true); } + if (!is_readable($profile_dir.'/'.$sip_profile_name)) { event_socket_mkdir($profile_dir.'/'.$sip_profile_name); } } //end foreach unset($sql, $result, $row_count);