diff --git a/app/call_broadcast/call_broadcast_send.php b/app/call_broadcast/call_broadcast_send.php index 1ccf411c42..3041391e16 100644 --- a/app/call_broadcast/call_broadcast_send.php +++ b/app/call_broadcast/call_broadcast_send.php @@ -260,10 +260,10 @@ require_once "resources/header.php"; $phone_1 = preg_replace('{\D}', '', $tmp_value_array[0]); if ($gateway == "loopback") { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_1."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_1."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } else { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_1." ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_1." ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } echo $cmd."
\n"; cmd_async($cmd); @@ -335,20 +335,20 @@ require_once "resources/header.php"; //make the call if (strlen($phone_1)> 0) { if ($gateway == "loopback") { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_1."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_1."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } else { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_1." ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_1." ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } //echo $cmd."
\n"; cmd_async($cmd); } if (strlen($phone_2)> 0) { if ($gateway == "loopback") { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_2."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}loopback/".$phone_2."/default/XML ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } else { - $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_2." ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; + $cmd = $_SESSION['switch']['bin']['dir']."/fs_cli -x \"luarun call_broadcast_originate.lua {call_timeout=".$broadcast_timeout."}sofia/gateway/".$gateway."/".$phone_2." ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename." '".$broadcast_caller_id_name."' ".$broadcast_caller_id_number." ".$broadcast_timeout." '".$broadcast_destination_application."' '".$broadcast_destination_data."'\";"; } //echo $cmd."
\n"; cmd_async($cmd); diff --git a/app/call_centers/call_center_agent_edit.php b/app/call_centers/call_center_agent_edit.php index e72dc42c19..34002e36ac 100644 --- a/app/call_centers/call_center_agent_edit.php +++ b/app/call_centers/call_center_agent_edit.php @@ -129,48 +129,47 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //get and then set the complete agent_contact with the call_timeout and when necessary confirm //if you change this variable, also change resources/switch.php - $tmp_confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout=".$agent_call_timeout; + $confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout=".$agent_call_timeout; if(strstr($agent_contact, '}') === FALSE) { //not found if(stristr($agent_contact, 'sofia/gateway') === FALSE) { //add the call_timeout - $tmp_agent_contact = "{call_timeout=".$agent_call_timeout."}".$agent_contact; + $agent_contact = "{call_timeout=".$agent_call_timeout.",sip_invite_domain=".$_SESSION['domain_name']."}".$agent_contact; } else { //add the call_timeout and confirm - $tmp_agent_contact = $tmp_first.',call_timeout='.$agent_call_timeout.$tmp_last; - $tmp_agent_contact = "{".$tmp_confirm.",call_timeout=".$agent_call_timeout."}".$agent_contact; - echo "\n\n".$tmp_agent_contact."\n\n"; + $agent_contact = $first.',call_timeout='.$agent_call_timeout.$last; + $agent_contact = "{".$confirm.",call_timeout=".$agent_call_timeout.",sip_invite_domain=".$_SESSION['domain_name']."}".$agent_contact; + echo "\n\n".$agent_contact."\n\n"; } } else { //found if(stristr($agent_contact, 'sofia/gateway') === FALSE) { //not found + $position = strrpos($agent_contact, "}"); + $first = substr($agent_contact, 0, $position); + $last = substr($agent_contact, $position); if(stristr($agent_contact, 'call_timeout') === FALSE) { - //add the call_timeout - $tmp_pos = strrpos($agent_contact, "}"); - $tmp_first = substr($agent_contact, 0, $tmp_pos); - $tmp_last = substr($agent_contact, $tmp_pos); - $tmp_agent_contact = $tmp_first.',call_timeout='.$agent_call_timeout.$tmp_last; + $call_timeout = ',call_timeout='.$agent_call_timeout; } else { - //the string has the call timeout - $tmp_agent_contact = $agent_contact; + $call_timeout = ''; } + $agent_contact = $first.',sip_invite_domain='.$_SESSION['domain_name'].$call_timeout.$last; } else { //found - $tmp_pos = strrpos($agent_contact, "}"); - $tmp_first = substr($agent_contact, 0, $tmp_pos); - $tmp_last = substr($agent_contact, $tmp_pos); + $position = strrpos($agent_contact, "}"); + $first = substr($agent_contact, 0, $position); + $last = substr($agent_contact, $position); if(stristr($agent_contact, 'call_timeout') === FALSE) { //add the call_timeout and confirm - $tmp_agent_contact = $tmp_first.','.$tmp_confirm.',call_timeout='.$agent_call_timeout.$tmp_last; + $agent_contact = $first.','.$confirm.',sip_invite_domain='.$_SESSION['domain_name'].'call_timeout='.$agent_call_timeout.$last; } else { //add confirm - $tmp_agent_contact = $tmp_first.','.$tmp_confirm.$tmp_last; + $agent_contact = $first.',sip_invite_domain='.$_SESSION['domain_name'].','.$confirm.$last; } } } @@ -193,7 +192,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $response = event_socket_request($fp, $cmd); usleep(200); //agent set contact - $cmd = "api callcenter_config agent set contact ".$agent_name."@".$_SESSION['domains'][$domain_uuid]['domain_name']." ".$tmp_agent_contact; + $cmd = "api callcenter_config agent set contact ".$agent_name."@".$_SESSION['domains'][$domain_uuid]['domain_name']." ".$agent_contact; $response = event_socket_request($fp, $cmd); usleep(200); //agent set status diff --git a/app/call_centers/call_center_queue_delete.php b/app/call_centers/call_center_queue_delete.php index 5abb84093f..e00655459a 100644 --- a/app/call_centers/call_center_queue_delete.php +++ b/app/call_centers/call_center_queue_delete.php @@ -43,59 +43,60 @@ else { $id = check_str($_GET["id"]); } -if (strlen($id) > 0) { +//delete the data + if (strlen($id) > 0) { - //get the dialplan uuid - $sql = "select * from v_call_center_queues "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and call_center_queue_uuid = '$id' "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) { - $queue_name = $row['queue_name']; - $dialplan_uuid = $row['dialplan_uuid']; - } + //get the dialplan uuid + $sql = "select * from v_call_center_queues "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and call_center_queue_uuid = '$id' "; + $prep_statement = $db->prepare($sql); + $prep_statement->execute(); + while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) { + $queue_name = $row['queue_name']; + $dialplan_uuid = $row['dialplan_uuid']; + } - //delete the tier from the database - $sql = "delete from v_call_center_tiers "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and queue_name = '$queue_name' "; - $db->query($sql); - unset($sql); + //delete the tier from the database + $sql = "delete from v_call_center_tiers "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and queue_name = '$queue_name' "; + $db->query($sql); + unset($sql); - //delete the call center queue - $sql = "delete from v_call_center_queues "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the call center queue + $sql = "delete from v_call_center_queues "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and call_center_queue_uuid = '$id' "; + $db->query($sql); + unset($sql); - //delete the dialplan entry - $sql = "delete from v_dialplans "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the dialplan entry + $sql = "delete from v_dialplans "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and dialplan_uuid = '$dialplan_uuid' "; + $db->query($sql); + unset($sql); - //delete the dialplan details - $sql = "delete from v_dialplan_details "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); + //delete the dialplan details + $sql = "delete from v_dialplan_details "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and dialplan_uuid = '$dialplan_uuid' "; + $db->query($sql); + unset($sql); - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$_SESSION["context"]); - remove_config_from_cache('configuration:callcenter.conf'); + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$_SESSION["context"]); + remove_config_from_cache('configuration:callcenter.conf'); - //synchronize configuration - save_dialplan_xml(); - save_call_center_xml(); + //synchronize configuration + save_dialplan_xml(); + save_call_center_xml(); - //apply settings reminder - $_SESSION["reload_xml"] = true; -} + //apply settings reminder + $_SESSION["reload_xml"] = true; + } //redirect the browser $_SESSION["message"] = $text['message-delete']; diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php index e37cf5f245..81ce4acbfb 100644 --- a/app/call_centers/call_center_queue_edit.php +++ b/app/call_centers/call_center_queue_edit.php @@ -255,7 +255,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $db->exec(check_sql($sql)); unset($sql); - //syncrhonize the configuration + //synchronize the configuration save_call_center_xml(); remove_config_from_cache('configuration:callcenter.conf'); @@ -311,20 +311,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } unset ($prep_statement); - //dialplan add or update - $c = new call_center; - $c->db = $db; - $c->domain_uuid = $_SESSION['domain_uuid']; - $c->call_center_queue_uuid = $call_center_queue_uuid; - $c->dialplan_uuid = $dialplan_uuid; - $c->queue_name = $queue_name; - $c->queue_name = $queue_name; - $c->queue_cid_prefix = $queue_cid_prefix; - $c->queue_timeout_action = $queue_timeout_action; - $c->queue_description = $queue_description; - $c->destination_number = $queue_extension; - $a = $c->dialplan(); - //synchronize the configuration save_call_center_xml(); remove_config_from_cache('configuration:callcenter.conf'); @@ -337,6 +323,20 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $_SESSION["message"] = $text['message-update']; } //if ($action == "update") + //dialplan add or update + $c = new call_center; + $c->db = $db; + $c->domain_uuid = $_SESSION['domain_uuid']; + $c->call_center_queue_uuid = $call_center_queue_uuid; + $c->dialplan_uuid = $dialplan_uuid; + $c->queue_name = $queue_name; + $c->queue_name = $queue_name; + $c->queue_cid_prefix = $queue_cid_prefix; + $c->queue_timeout_action = $queue_timeout_action; + $c->queue_description = $queue_description; + $c->destination_number = $queue_extension; + $a = $c->dialplan(); + //add agent/tier to queue $agent_name = check_str($_POST["agent_name"]); $tier_level = check_str($_POST["tier_level"]); @@ -399,8 +399,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } //redirect - header("Location: call_center_queue_edit.php?id=".$call_center_queue_uuid); - return; + header("Location: call_center_queue_edit.php?id=".$call_center_queue_uuid); + return; } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -739,7 +739,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; $record_ext=($_SESSION['record_ext']=='mp3'?'mp3':'wav'); - $record_template = $_SESSION['switch']['recordings']['dir']."/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}/\${uuid}.".$record_ext; + $record_template = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}/\${uuid}.".$record_ext; echo " \n"; echo " \n"; //recordings - if($dh = opendir($_SESSION['switch']['recordings']['dir']."/")) { + if($dh = opendir($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/")) { $tmp_selected = false; $files = Array(); echo "\n"; while ($file = readdir($dh)) { if ($file != "." && $file != ".." && $file[0] != '.') { - if (!is_dir($_SESSION['switch']['recordings']['dir']."/".$file)) { - $selected = ($conference_center_greeting == $_SESSION['switch']['recordings']['dir']."/".$file && strlen($conference_center_greeting) > 0) ? true : false; - echo " \n"; + if (!is_dir($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$file)) { + $selected = ($conference_center_greeting == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$file && strlen($conference_center_greeting) > 0) ? true : false; + echo " \n"; if ($selected) { $tmp_selected = true; } } } @@ -393,8 +393,8 @@ else { if (permission_exists('conference_center_add') || permission_exists('conference_center_edit')) { if (!$tmp_selected) { echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$conference_center_greeting)) { - echo " \n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$conference_center_greeting)) { + echo " \n"; } else if (substr($conference_center_greeting, -3) == "wav" || substr($conference_center_greeting, -3) == "mp3") { echo " \n"; diff --git a/app/conference_centers/conference_session_details.php b/app/conference_centers/conference_session_details.php index eeea9296c1..1ed402ab62 100644 --- a/app/conference_centers/conference_session_details.php +++ b/app/conference_centers/conference_session_details.php @@ -77,7 +77,7 @@ else { echo " \n"; echo " ".$text['title-conference_session_details']."\n"; echo " \n"; - $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; + $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; $tmp_name = ''; if (file_exists($tmp_dir.'/'.$row['conference_session_uuid'].'.mp3')) { $tmp_name = $row['conference_session_uuid'].".mp3"; diff --git a/app/conference_centers/conference_sessions.php b/app/conference_centers/conference_sessions.php index eecd71e4fb..4c669ac46a 100644 --- a/app/conference_centers/conference_sessions.php +++ b/app/conference_centers/conference_sessions.php @@ -146,7 +146,7 @@ else { echo " ".$start_date." \n"; echo " ".$end_date." \n"; echo " ".$row['profile']." \n"; - $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; + $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; $tmp_name = ''; if (file_exists($tmp_dir.'/'.$row['conference_session_uuid'].'.mp3')) { $tmp_name = $row['conference_session_uuid'].".mp3"; diff --git a/app/conferences_active/conference_exec.php b/app/conferences_active/conference_exec.php index f21af3adbb..2b5419aa3d 100644 --- a/app/conferences_active/conference_exec.php +++ b/app/conferences_active/conference_exec.php @@ -141,7 +141,7 @@ else { $switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value); } elseif ($data == "record") { - $recording_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); + $recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); $switch_cmd .= $recording_dir."/".$uuid.".wav"; if (!file_exists($recording_dir."/".$uuid.".wav")) { $switch_result = event_socket_request($fp, "api ".$switch_cmd); @@ -149,7 +149,7 @@ else { } elseif ($data == "norecord") { //stop recording and rename the file - $recording_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); + $recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); $switch_cmd .= $recording_dir."/".$uuid.".wav"; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } diff --git a/app/conferences_active/conference_interactive_inc.php b/app/conferences_active/conference_interactive_inc.php index 2c3a989593..0b9fbcf0ad 100644 --- a/app/conferences_active/conference_interactive_inc.php +++ b/app/conferences_active/conference_interactive_inc.php @@ -104,7 +104,7 @@ else { echo " \n"; echo "\n"; - $recording_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); + $recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d"); $recording_name = ''; if (file_exists($recording_dir.'/'.$row['uuid'].'.wav')) { $recording_name = $session_uuid.".wav"; diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index d6051689c1..3d48fb6059 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -679,7 +679,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if ($row["dialplan_detail_tag"] != "condition") { if ($row["dialplan_detail_tag"] == "action" && $row["dialplan_detail_type"] == "set" && strpos($row["dialplan_detail_data"], "accountcode") == 0) { continue; } //exclude set:accountcode actions echo " \n"; - echo " \n"; + echo " \n"; if (strlen($row['dialplan_detail_uuid']) > 0) { echo " \n"; } diff --git a/app/devices/app_config.php b/app/devices/app_config.php index 6f3f3cfaac..e92e7eb465 100644 --- a/app/devices/app_config.php +++ b/app/devices/app_config.php @@ -51,6 +51,10 @@ $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; $apps[$x]['permissions'][$y]['groups'][] = 'admin'; $y++; + $apps[$x]['permissions'][$y]['name'] = 'device_files'; + $apps[$x]['permissions'][$y]['groups'][] = 'superadmin'; + //$apps[$x]['permissions'][$y]['groups'][] = 'admin'; + $y++; $apps[$x]['permissions'][$y]['name'] = "device_extension_view"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $apps[$x]['permissions'][$y]['groups'][] = "admin"; diff --git a/app/devices/app_languages.php b/app/devices/app_languages.php index 577792fd96..fe7dbea165 100644 --- a/app/devices/app_languages.php +++ b/app/devices/app_languages.php @@ -789,17 +789,17 @@ $text['label-orbit']['de-at'] = "Park + Orbit"; $text['label-orbit']['ar-eg'] = ""; $text['label-orbit']['he'] = ""; -$text['label-normal']['en-us'] = "normal"; -$text['label-normal']['es-cl'] = "normal"; -$text['label-normal']['pt-pt'] = "normal"; -$text['label-normal']['fr-fr'] = "normal"; +$text['label-normal']['en-us'] = "Normal"; +$text['label-normal']['es-cl'] = "Normal"; +$text['label-normal']['pt-pt'] = "Normal"; +$text['label-normal']['fr-fr'] = "Normal"; $text['label-normal']['pt-br'] = "Normal"; -$text['label-normal']['pl'] = "normalny"; -$text['label-normal']['uk'] = "звичайно"; -$text['label-normal']['sv-se'] = "normal"; -$text['label-normal']['de-at'] = "normal"; -$text['label-normal']['ar-eg'] = ""; -$text['label-normal']['he'] = ""; +$text['label-normal']['pl'] = "Normalny"; +$text['label-normal']['uk'] = "Звичайно"; +$text['label-normal']['sv-se'] = "Normal"; +$text['label-normal']['de-at'] = "Normal"; +$text['label-normal']['ar-eg'] = "Normal"; +$text['label-normal']['he'] = "Normal"; $text['label-none']['en-us'] = "None"; $text['label-none']['es-cl'] = "Ninguno"; @@ -1378,6 +1378,19 @@ $text['label-device_mac_address']['de-at'] = "MAC Adresse"; $text['label-device_mac_address']['ar-eg'] = ""; $text['label-device_mac_address']['he'] = ""; +$text['label-download']['en-us'] = "Download"; +$text['label-download']['es-cl'] = ""; +$text['label-download']['pt-pt'] = ""; +$text['label-download']['fr-fr'] = ""; +$text['label-download']['pt-br'] = ""; +$text['label-download']['pl'] = ""; +$text['label-download']['uk'] = ""; +$text['label-download']['sv-se'] = ""; +$text['label-download']['ro'] = ""; +$text['label-download']['de-at'] = ""; +$text['label-download']['ar-eg'] = ""; +$text['label-download']['he'] = ""; + $text['label-device_label']['en-us'] = "Label"; $text['label-device_label']['es-cl'] = "Etiqueta"; $text['label-device_label']['pt-pt'] = "Rótulo"; @@ -1715,18 +1728,109 @@ $text['label-xfer']['de-at'] = ""; $text['label-xfer']['ar-eg'] = ""; $text['label-xfer']['he'] = ""; -$text['label-automata']['en-us'] = "automata"; -$text['label-automata']['es-cl'] = "automata"; -$text['label-automata']['pt-pt'] = "automata"; -$text['label-automata']['fr-fr'] = "automata"; +$text['label-automata']['en-us'] = "Automata"; +$text['label-automata']['es-cl'] = "Automata"; +$text['label-automata']['pt-pt'] = "Automata"; +$text['label-automata']['fr-fr'] = "Automata"; $text['label-automata']['pt-br'] = "Automata"; -$text['label-automata']['pl'] = "automaty"; -$text['label-automata']['uk'] = ""; +$text['label-automata']['pl'] = "Automaty"; +$text['label-automata']['uk'] = "Automata"; $text['label-automata']['sv-se'] = "Automata"; -$text['label-automata']['ro'] = ""; -$text['label-automata']['de-at'] = "automata"; -$text['label-automata']['ar-eg'] = ""; -$text['label-automata']['he'] = ""; +$text['label-automata']['ro'] = "Automata"; +$text['label-automata']['de-at'] = "Automata"; +$text['label-automata']['ar-eg'] = "Automata"; +$text['label-automata']['he'] = "Automata"; + +$text['label-messages']['en-us'] = "Messages"; +$text['label-messages']['es-cl'] = "Messages"; +$text['label-messages']['pt-pt'] = "Messages"; +$text['label-messages']['fr-fr'] = "Messages"; +$text['label-messages']['pt-br'] = "Messages"; +$text['label-messages']['pl'] = "Messages"; +$text['label-messages']['uk'] = "Messages"; +$text['label-messages']['sv-se'] = "Messages"; +$text['label-messages']['ro'] = "Messages"; +$text['label-messages']['de-at'] = "Messages"; +$text['label-messages']['ar-eg'] = "Messages"; +$text['label-messages']['he'] = "Messages"; + +$text['label-micmute']['en-us'] = "MicMute"; +$text['label-micmute']['es-cl'] = "MicMute"; +$text['label-micmute']['pt-pt'] = "MicMute"; +$text['label-micmute']['fr-fr'] = "MicMute"; +$text['label-micmute']['pt-br'] = "MicMute"; +$text['label-micmute']['pl'] = "MicMute"; +$text['label-micmute']['uk'] = "MicMute"; +$text['label-micmute']['sv-se'] = "MicMute"; +$text['label-micmute']['ro'] = "MicMute"; +$text['label-micmute']['de-at'] = "MicMute"; +$text['label-micmute']['ar-eg'] = "MicMute"; +$text['label-micmute']['he'] = "MicMute"; + +$text['label-redial']['en-us'] = "Redial"; +$text['label-redial']['es-cl'] = "Redial"; +$text['label-redial']['pt-pt'] = "Redial"; +$text['label-redial']['fr-fr'] = "Redial"; +$text['label-redial']['pt-br'] = "Redial"; +$text['label-redial']['pl'] = "Redial"; +$text['label-redial']['uk'] = "Redial"; +$text['label-redial']['sv-se'] = "Redial"; +$text['label-redial']['ro'] = "Redial"; +$text['label-redial']['de-at'] = "Redial"; +$text['label-redial']['ar-eg'] = "Redial"; +$text['label-redial']['he'] = "Redial"; + +$text['label-null']['en-us'] = "Null"; +$text['label-null']['es-cl'] = "Null"; +$text['label-null']['pt-pt'] = "Null"; +$text['label-null']['fr-fr'] = "Null"; +$text['label-null']['pt-br'] = "Null"; +$text['label-null']['pl'] = "Null"; +$text['label-null']['uk'] = "Null"; +$text['label-null']['sv-se'] = "Null"; +$text['label-null']['ro'] = "Null"; +$text['label-null']['de-at'] = "Null"; +$text['label-null']['ar-eg'] = "Null"; +$text['label-null']['he'] = "Null"; + +$text['label-speeddial']['en-us'] = "SpeedDial"; +$text['label-speeddial']['es-cl'] = "SpeedDial"; +$text['label-speeddial']['pt-pt'] = "SpeedDial"; +$text['label-speeddial']['fr-fr'] = "SpeedDial"; +$text['label-speeddial']['pt-br'] = "SpeedDial"; +$text['label-speeddial']['pl'] = "SpeedDial"; +$text['label-speeddial']['uk'] = "SpeedDial"; +$text['label-speeddial']['sv-se'] = "SpeedDial"; +$text['label-speeddial']['ro'] = "SpeedDial"; +$text['label-speeddial']['de-at'] = "SpeedDial"; +$text['label-speeddial']['ar-eg'] = "SpeedDial"; +$text['label-speeddial']['he'] = "SpeedDial"; + +$text['label-speeddialmenu']['en-us'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['es-cl'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pt-pt'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['fr-fr'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pt-br'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['pl'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['uk'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['sv-se'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['ro'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['de-at'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['ar-eg'] = "SpeedDialMenu"; +$text['label-speeddialmenu']['he'] = "SpeedDialMenu"; + +$text['label-url']['en-us'] = "URL"; +$text['label-url']['es-cl'] = "URL"; +$text['label-url']['pt-pt'] = "URL"; +$text['label-url']['fr-fr'] = "URL"; +$text['label-url']['pt-br'] = "URL"; +$text['label-url']['pl'] = "URL"; +$text['label-url']['uk'] = "URL"; +$text['label-url']['sv-se'] = "URL"; +$text['label-url']['ro'] = "URL"; +$text['label-url']['de-at'] = "URL"; +$text['label-url']['ar-eg'] = "URL"; +$text['label-url']['he'] = "URL"; $text['label-auto_answer']['en-us'] = "Auto Answer"; $text['label-auto_answer']['es-cl'] = "Respuesta Automática"; @@ -2508,6 +2612,32 @@ $text['button-copy']['de-at'] = "Kopieren"; $text['button-copy']['ar-eg'] = "نسخ"; $text['button-copy']['he'] = "העתקה"; +$text['button-files']['en-us'] = "Files"; +$text['button-files']['es-cl'] = ""; +$text['button-files']['pt-pt'] = ""; +$text['button-files']['fr-fr'] = ""; +$text['button-files']['pt-br'] = ""; +$text['button-files']['pl'] = ""; +$text['button-files']['uk'] = ""; +$text['button-files']['sv-se'] = ""; +$text['button-files']['ro'] = ""; +$text['button-files']['de-at'] = ""; +$text['button-files']['ar-eg'] = ""; +$text['button-files']['he'] = ""; + +$text['button-download']['en-us'] = "Download"; +$text['button-download']['es-cl'] = ""; +$text['button-download']['pt-pt'] = ""; +$text['button-download']['fr-fr'] = ""; +$text['button-download']['pt-br'] = ""; +$text['button-download']['pl'] = ""; +$text['button-download']['uk'] = ""; +$text['button-download']['sv-se'] = ""; +$text['button-download']['ro'] = ""; +$text['button-download']['de-at'] = ""; +$text['button-download']['ar-eg'] = ""; +$text['button-download']['he'] = ""; + $text['button-back']['en-us'] = "Back"; $text['button-back']['es-cl'] = "Volver"; $text['button-back']['pt-pt'] = "Voltar"; diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index af2231ef23..e7064dfeb6 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -233,6 +233,9 @@ require_once "resources/require.php"; //array cleanup $x = 0; //unset($_POST["autocomplete"]); + unset($_POST["target_file"]); + unset($_POST["file_action"]); + foreach ($_POST["device_lines"] as $row) { //unset the empty row if (strlen($row["line_number"]) == 0) { @@ -515,10 +518,68 @@ require_once "resources/require.php"; }); } + \n"; + echo " var fade_speed = 400;\n"; + echo " function show_files() {\n"; + echo " document.getElementById('file_action').value = 'files';\n"; + echo " $('#button_files').fadeOut(fade_speed, function() {\n"; + echo " $('#button_back_location').fadeOut(fade_speed);\n"; + echo " $('#button_back').fadeIn(fade_speed);\n"; + echo " $('#target_file').fadeIn(fade_speed);\n"; + echo " $('#button_download').fadeIn(fade_speed);\n"; + echo " });"; + echo " }"; + echo " function hide_files() {\n"; + echo " document.getElementById('file_action').value = '';\n"; + echo " $('#button_back_location').fadeIn(fade_speed);\n"; + echo " $('#button_back').fadeOut(fade_speed);\n"; + echo " $('#target_file').fadeOut(fade_speed);\n"; + echo " $('#button_download').fadeOut(fade_speed, function() {\n"; + echo " $('#button_files').fadeIn(fade_speed);\n"; + echo " document.getElementById('target_file').selectedIndex = 0;\n"; + echo " });\n"; + echo " }\n"; + + echo " function download(d) {\n"; + echo " if (d == '".$text['label-download']."') return;\n"; + if ($_SESSION['provision']['http_domain_filter']['text'] == "false") { + $domain_name = $_SERVER["HTTP_HOST"]; + } + else { + $domain_name = $_SESSION['domain_name']; + } + echo " window.location = 'https://".$domain_name."/app/provision?mac=$device_mac_address&file=' + d + '&content_type=application/octet-stream';\n"; + echo " }\n"; + + echo "\n"; + echo " $( document ).ready(function() {\n"; + echo " $('#default_setting_search').focus();\n"; + if ($search == '') { + echo " // scroll to previous category\n"; + echo " var category_span_id;\n"; + echo " var url = document.location.href;\n"; + echo " var hashindex = url.indexOf('#');\n"; + echo " if (hashindex == -1) { }\n"; + echo " else {\n"; + echo " category_span_id = url.substr(hashindex + 1);\n"; + echo " }\n"; + echo " if (category_span_id) {\n"; + echo " $('#page').animate({scrollTop: $('#anchor_'+category_span_id).offset().top - 200}, 'slow');\n"; + echo " }\n"; + } + echo " });\n"; + echo ""; + } + //show the content echo "
\n"; //echo ""; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "\n"; - } echo " \n"; @@ -896,7 +931,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "
"; @@ -528,7 +589,27 @@ require_once "resources/require.php"; echo "

"; echo "
\n"; - echo " \n"; + echo " \n"; + if (permission_exists("device_files")) { + //get the template directory + $prov = new provision; + $prov->domain_uuid = $domain_uuid; + $template_dir = $prov->template_dir; + $files = glob($template_dir.'/'.$device_template.'/*'); + //add file buttons and the file list + echo " "; + echo " "; + echo " \n"; + //echo " "; + } if (permission_exists('device_add') && $action != "add") { echo " \n"; } @@ -964,6 +1045,13 @@ require_once "resources/require.php"; + + + + + + + "; } } diff --git a/app/devices/device_profile_edit.php b/app/devices/device_profile_edit.php index db58b6063a..bfe703b584 100644 --- a/app/devices/device_profile_edit.php +++ b/app/devices/device_profile_edit.php @@ -454,6 +454,13 @@ require_once "resources/require.php"; + + + + + + + "; } } diff --git a/app/dialplan/dialplan_copy.php b/app/dialplan/dialplan_copy.php index c99d664145..de81736106 100644 --- a/app/dialplan/dialplan_copy.php +++ b/app/dialplan/dialplan_copy.php @@ -77,6 +77,15 @@ else { } unset ($prep_statement); +//create a new app_uuid when copying a dialplan except for these exceptions + switch ($app_uuid) { + case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": //inbound routes + case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": //outbound routes + case "4b821450-926b-175a-af93-a03c441818b1": //time conditions + default: + $app_uuid = uuid(); + } + //copy the dialplan $dialplan_uuid = uuid(); $sql = "insert into v_dialplans "; diff --git a/app/dialplan/resources/classes/dialplan.php b/app/dialplan/resources/classes/dialplan.php index c828cc25b1..92631e73d3 100644 --- a/app/dialplan/resources/classes/dialplan.php +++ b/app/dialplan/resources/classes/dialplan.php @@ -381,7 +381,11 @@ include "root.php"; if (!is_array($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) { //get the outbound routes from the database $sql = "select * from v_dialplans as d, v_dialplan_details as s "; - $sql .= "where d.domain_uuid = '".$this->domain_uuid."' "; + $sql .= "where "; + $sql .= "( "; + $sql .= "d.domain_uuid = '".$this->domain_uuid."' "; + $sql .= "or d.domain_uuid is null "; + $sql .= ") "; $sql .= "and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; $sql .= "and d.dialplan_enabled = 'true' "; $sql .= "and d.dialplan_uuid = s.dialplan_uuid "; diff --git a/app/dialplan/resources/switch/conf/dialplan/999_local_extension.xml b/app/dialplan/resources/switch/conf/dialplan/999_local_extension.xml index a53fda713e..559821b785 100644 --- a/app/dialplan/resources/switch/conf/dialplan/999_local_extension.xml +++ b/app/dialplan/resources/switch/conf/dialplan/999_local_extension.xml @@ -1,9 +1,9 @@ - + - - + + diff --git a/app/dialplan_inbound/dialplan_inbound_add.php b/app/dialplan_inbound/dialplan_inbound_add.php index 25dbfb37fd..bf4205d8fe 100644 --- a/app/dialplan_inbound/dialplan_inbound_add.php +++ b/app/dialplan_inbound/dialplan_inbound_add.php @@ -145,12 +145,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $dialplan_name = str_replace("/", "", $dialplan_name); //set the context - if (count($_SESSION["domains"]) > 1) { - $context = 'default'; - } - else { - $context = '$${domain_name}'; - } + $context = '$${domain_name}'; //start the atomic transaction $count = $db->exec("BEGIN;"); //returns affected rows diff --git a/app/dialplan_outbound/dialplan_outbound_add.php b/app/dialplan_outbound/dialplan_outbound_add.php index 7a9c4a48e1..02c2d184be 100644 --- a/app/dialplan_outbound/dialplan_outbound_add.php +++ b/app/dialplan_outbound/dialplan_outbound_add.php @@ -207,7 +207,7 @@ else { $label = $text['label-11d']; $abbrv = "11d"; break; - case "^\+?1?(\d{10})$": + case "^(?:\+1|1)?([2-9]\d\d[2-9]\d{6})$": $label = $text['label-north-america']; $abbrv = "10-11d"; break; diff --git a/app/emails/app_languages.php b/app/emails/app_languages.php index 5c08ca3825..c373cd8ce5 100644 --- a/app/emails/app_languages.php +++ b/app/emails/app_languages.php @@ -72,6 +72,15 @@ $text['label-type_voicemail']['pl'] = "Poczta głosowa"; $text['label-type_voicemail']['sv-se'] = "Röstbrevlåda"; $text['label-type_voicemail']['de-at'] = "Mailbox"; +$text['label-type_email2fax']['en-us'] = "Email to fax report"; +$text['label-type_email2fax']['es-cl'] = ""; +$text['label-type_email2fax']['pt-pt'] = ""; +$text['label-type_email2fax']['fr-fr'] = ""; +$text['label-type_email2fax']['pt-br'] = ""; +$text['label-type_email2fax']['pl'] = ""; +$text['label-type_email2fax']['sv-se'] = ""; +$text['label-type_email2fax']['de-at'] = ""; + $text['label-type']['en-us'] = "Type"; $text['label-type']['es-cl'] = "Tipo"; $text['label-type']['pt-pt'] = "Tipo"; diff --git a/app/fax/app_config.php b/app/fax/app_config.php index 8567a0023d..83fe88019d 100644 --- a/app/fax/app_config.php +++ b/app/fax/app_config.php @@ -277,6 +277,14 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_send_greeting"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_send_channels"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $z++; //$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "fax_keep_local"; //$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "fax_local"; //$apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; @@ -499,4 +507,79 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; + $y = 4; //table array index + $z = 0; //field array index + $apps[$x]['db'][$y]['table'] = 'v_fax_tasks'; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'fax_task_uuid'; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid'; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)'; + $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'fax_uuid'; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid'; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)'; + $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign'; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_fax'; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'fax_uuid'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'FAX server primary key'; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_next_time'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'timestamp'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_lock_time'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'timestamp'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_fax_file'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_wav_file'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_uri'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_dial_string'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_dtmf'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_reply_address'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_interrupted'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_status'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_no_answer_counter'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_no_answer_retry_counter'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_retry_counter'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_description'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; ?> \ No newline at end of file diff --git a/app/fax/app_defaults.php b/app/fax/app_defaults.php index b3ab8cd98c..9efab50752 100644 --- a/app/fax/app_defaults.php +++ b/app/fax/app_defaults.php @@ -12,6 +12,13 @@ if ($domains_processed == 1) { $array[$x]['default_setting_description'] = 'Path to image/logo file displayed in the header of the cover sheet.'; $x++; $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'cover_font'; + $array[$x]['default_setting_name'] = 'text'; + $array[$x]['default_setting_value'] = 'times'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = 'Font used to generate cover page. Can be full path to .ttf file or font name alredy installed.'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; $array[$x]['default_setting_subcategory'] = 'cover_footer'; $array[$x]['default_setting_name'] = 'text'; $array[$x]['default_setting_value'] = "The information contained in this facsimile is intended for the sole confidential use of the recipient(s) designated above, and may contain confidential and legally privileged information. If you are not the intended recipient, you are hereby notified that the review, disclosure, dissemination, distribution, copying, duplication in any form, and taking of any action in regards to the contents of this document - except with respect to its direct delivery to the intended recipient - is strictly prohibited. Please notify the sender immediately and destroy this cover sheet and all attachments. If stored or viewed electronically, please permanently delete it from your system."; @@ -60,6 +67,55 @@ if ($domains_processed == 1) { $array[$x]['default_setting_enabled'] = 'true'; $array[$x]['default_setting_description'] = 'Keep the file after sending or receiving the fax.'; $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_mode'; + $array[$x]['default_setting_name'] = 'text'; + $array[$x]['default_setting_value'] = 'queue'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = ''; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_retry_limit'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '5'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Number of attempts to send fax (count only calls with answer)'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_retry_interval'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '15'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Delay before we make next call after answered call'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_no_answer_retry_limit'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '3'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Number of unanswered attempts in sequence'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_no_answer_retry_interval'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '30'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Delay before we make next call after no answered call'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_no_answer_limit'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '3'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Giveup reach the destination after this number of sequences'; + $x++; + $array[$x]['default_setting_category'] = 'fax'; + $array[$x]['default_setting_subcategory'] = 'send_no_answer_interval'; + $array[$x]['default_setting_name'] = 'numeric'; + $array[$x]['default_setting_value'] = '300'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = 'Delay before next call sequence'; + $x++; //get an array of the default settings $sql = "select * from v_default_settings "; $prep_statement = $db->prepare($sql); diff --git a/app/fax/app_languages.php b/app/fax/app_languages.php index 93ad7aa319..5ab3463d98 100644 --- a/app/fax/app_languages.php +++ b/app/fax/app_languages.php @@ -1111,6 +1111,28 @@ $text['label-accountcode']['de-at'] = "Account Code"; $text['label-accountcode']['ro'] = "Cod cont"; $text['label-accountcode']['he'] = "קוד חשבון"; +$text['label-fax_send_greeting']['en-us'] = "Greeting"; +$text['label-fax_send_greeting']['es-cl'] = ""; +$text['label-fax_send_greeting']['pt-pt'] = ""; +$text['label-fax_send_greeting']['fr-fr'] = ""; +$text['label-fax_send_greeting']['pt-br'] = ""; +$text['label-fax_send_greeting']['pl'] = ""; +$text['label-fax_send_greeting']['sv-se'] = ""; +$text['label-fax_send_greeting']['de-at'] = ""; +$text['label-fax_send_greeting']['ro'] = ""; +$text['label-fax_send_greeting']['he'] = ""; + +$text['label-fax_send_channels']['en-us'] = "Number of channels"; +$text['label-fax_send_channels']['es-cl'] = ""; +$text['label-fax_send_channels']['pt-pt'] = ""; +$text['label-fax_send_channels']['fr-fr'] = ""; +$text['label-fax_send_channels']['pt-br'] = ""; +$text['label-fax_send_channels']['pl'] = ""; +$text['label-fax_send_channels']['sv-se'] = ""; +$text['label-fax_send_channels']['de-at'] = ""; +$text['label-fax_send_channels']['ro'] = ""; +$text['label-fax_send_channels']['he'] = ""; + $text['header-sent']['en-us'] = "Sent Faxes"; $text['header-sent']['es-cl'] = "Los Faxes Enviados"; $text['header-sent']['pt-pt'] = "Faxes Enviados"; diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php index 27ffdc8ca4..8a23a3cf4c 100644 --- a/app/fax/fax_edit.php +++ b/app/fax/fax_edit.php @@ -53,12 +53,7 @@ else { } //set the fax directory - if (count($_SESSION["domains"]) > 1) { - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; - } - else { - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'; - } + $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; //get the fax extension if (strlen($fax_extension) > 0) { @@ -135,8 +130,10 @@ else { } else { $forward_prefix = $forward_prefix.$fax_forward_number.'#'; //found } - $fax_local = check_str($_POST["fax_local"]); + $fax_local = check_str($_POST["fax_local"]); //! @todo check in database $fax_description = check_str($_POST["fax_description"]); + $fax_send_greeting = check_str($_POST["fax_send_greeting"]); + $fax_send_channels = check_str($_POST["fax_send_channels"]); } //delete the user from the fax users @@ -274,6 +271,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (strlen($fax_forward_number) > 0) { $sql .= "fax_forward_number, "; } + $sql .= "fax_send_greeting,"; + $sql .= "fax_send_channels,"; $sql .= "fax_description "; $sql .= ")"; $sql .= "values "; @@ -305,6 +304,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (strlen($fax_forward_number) > 0) { $sql .= "'$fax_forward_number', "; } + $sql .= (strlen($fax_send_greeting)==0?'NULL':"'$fax_send_greeting'") . ","; + $sql .= (strlen($fax_send_channels)==0?'NULL':"'$fax_send_channels'") . ","; + $sql .= "'$fax_description' "; $sql .= ")"; $db->exec(check_sql($sql)); @@ -345,9 +347,16 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { else { $sql .= "fax_forward_number = null, "; } + $tmp = strlen($fax_send_greeting)==0?'NULL':"'$fax_send_greeting'"; + $sql .= "fax_send_greeting = $tmp,"; + $tmp = strlen($fax_send_channels)==0?'NULL':"'$fax_send_channels'"; + $sql .= "fax_send_channels = $tmp,"; + $sql .= "fax_description = '$fax_description' "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and fax_uuid = '$fax_uuid' "; + $db->exec(check_sql($sql)); unset($sql); } @@ -426,9 +435,14 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $fax_caller_id_number = $row["fax_caller_id_number"]; $fax_forward_number = $row["fax_forward_number"]; $fax_description = $row["fax_description"]; + $fax_send_greeting = $row["fax_send_greeting"]; + $fax_send_channels = $row["fax_send_channels"]; } unset ($prep_statement); } + else{ + $fax_send_channels = 10; + } //replace the dash with a space $fax_name = str_replace("-", " ", $fax_name); @@ -667,6 +681,28 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } } + echo "
\n"; + echo " ".$text['label-fax_send_greeting']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-fax_send_greeting']."\n"; + echo "
\n"; + echo " ".$text['label-fax_send_channels']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-fax_send_channels']."\n"; + echo "
\n"; echo " ".$text['label-description']."\n"; @@ -677,7 +713,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "".$text['description-info']."\n"; echo "
"; echo "
"; echo "\n"; - } echo "
"; diff --git a/app/fax/fax_emails.php b/app/fax/fax_emails.php index 906a7eb013..234367e7b8 100644 --- a/app/fax/fax_emails.php +++ b/app/fax/fax_emails.php @@ -29,6 +29,8 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/functions/object_to_array.php"; require_once "resources/functions/parse_attachments.php"; +require_once "resources/functions/parse_message.php"; +require_once "resources/classes/text.php"; //get accounts to monitor $sql = "select * from v_fax "; @@ -54,6 +56,12 @@ if (sizeof($result) != 0) { $event_socket['password'] = $record['event_socket_password']; unset($sql, $prep_statement, $record); + $fax_send_mode_default = $_SESSION['fax']['send_mode']['text']; + if(strlen($fax_send_mode_default) == 0){ + $fax_send_mode_default = 'direct'; + } + $fax_cover_font_default = $_SESSION['fax']['cover_font']['text']; + foreach ($result as $row) { //get fax server and account connection details $fax_uuid = $row["fax_uuid"]; @@ -73,12 +81,23 @@ if (sizeof($result) != 0) { $fax_email_connection_mailbox = $row["fax_email_connection_mailbox"]; $fax_email_outbound_subject_tag = $row["fax_email_outbound_subject_tag"]; $fax_email_outbound_authorized_senders = $row["fax_email_outbound_authorized_senders"]; + $fax_send_greeting = $row["fax_send_greeting"]; //load default settings, then domain settings over top unset($_SESSION); $_SESSION = $default_settings; load_domain_settings($domain_uuid); + $fax_send_mode = $_SESSION['fax']['send_mode']['text']; + if(strlen($fax_send_mode) == 0){ + $fax_send_mode = $fax_send_mode_default; + } + + $fax_cover_font = $_SESSION['fax']['cover_font']['text']; + if(strlen($fax_cover_font) == 0){ + $fax_cover_font = $fax_cover_font_default; + } + //load event socket connection parameters $_SESSION['event_socket_ip_address'] = $event_socket['ip_address']; $_SESSION['event_socket_port'] = $event_socket['port']; @@ -158,22 +177,14 @@ if (sizeof($result) != 0) { else { $fax_numbers[] = $tmp; } - foreach ($fax_numbers as $index => $fax_number) { - $fax_numbers[$index] = preg_replace("~[^0-9]~", "", $fax_number); - if ($fax_numbers[$index] == '') { unset($fax_numbers[$index]); } - } unset($fax_subject); //clear so not on cover page //get email body (if any) for cover page - $fax_message = imap_fetchbody($connection, $email_id, '1.1', FT_UID); - $fax_message = strip_tags($fax_message); - $fax_message = trim($fax_message); + $fax_message = parse_message($connection, $email_id, FT_UID); if ($fax_message == '') { - $fax_message = imap_fetchbody($connection, $email_id, '1', FT_UID); $fax_message = strip_tags($fax_message); - $fax_message = trim($fax_message); + $fax_message = str_replace("\r\n\r\n","\r\n", $fax_message); } - $fax_message = str_replace("\r\n\r\n","\r\n", $fax_message); // set fax directory (used for pdf creation - cover and/or attachments) $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.(($domain_name != '') ? '/'.$domain_name : null); @@ -199,8 +210,12 @@ if (sizeof($result) != 0) { } //send fax + $cwd = getcwd(); $included = true; require("fax_send.php"); + if($cwd){ + chdir($cwd); + } //reset variables unset($fax_numbers); diff --git a/app/fax/fax_files.php b/app/fax/fax_files.php index 8f83b675dd..bb08fa837d 100644 --- a/app/fax/fax_files.php +++ b/app/fax/fax_files.php @@ -86,7 +86,7 @@ else { } //set the fax directory - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); + $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; //download the fax if ($_GET['a'] == "download") { diff --git a/app/fax/fax_files_remote.php b/app/fax/fax_files_remote.php index ddc87a7dca..28c5d76b83 100644 --- a/app/fax/fax_files_remote.php +++ b/app/fax/fax_files_remote.php @@ -135,7 +135,7 @@ else { if (imap_delete($connection, $email_id, FT_UID)) { if (imap_expunge($connection)) { //clean up local inbox copy - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); + $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; @unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$attachment[0]['filename']); //redirect user $_SESSION["message"] = $text['message-delete']; diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index e134e37bbe..b016ba0bfd 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -58,13 +58,17 @@ if (!$included) { $fax_uuid = check_str($_REQUEST["id"]); if (if_group("superadmin") || if_group("admin")) { //show all fax extensions - $sql = "select * from v_fax "; + $sql = "select fax_uuid, fax_extension, fax_caller_id_name, fax_caller_id_number, "; + $sql .= "accountcode, fax_send_greeting "; + $sql .= "from v_fax "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and fax_uuid = '$fax_uuid' "; } else { //show only assigned fax extensions - $sql = "select * from v_fax as f, v_fax_users as u "; + $sql = "select f.fax_uuid, f.fax_extension, f.fax_caller_id_name, f.fax_caller_id_number, "; + $sql .= "f.accountcode, f.fax_send_greeting "; + $sql .= "from v_fax as f, v_fax_users as u "; $sql .= "where f.fax_uuid = u.fax_uuid "; $sql .= "and f.domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and f.fax_uuid = '$fax_uuid' "; @@ -84,35 +88,113 @@ if (!$included) { } foreach ($result as &$row) { //set database fields as variables + $fax_uuid = $row["fax_uuid"]; $fax_extension = $row["fax_extension"]; $fax_caller_id_name = $row["fax_caller_id_name"]; $fax_caller_id_number = $row["fax_caller_id_number"]; $fax_accountcode = $row["accountcode"]; + $fax_send_greeting = $row["fax_send_greeting"]; //limit to one row break; } unset ($prep_statement); + $fax_send_mode = $_SESSION['fax']['send_mode']['text']; + if(strlen($fax_send_mode) == 0){ + $fax_send_mode = 'direct'; + } } //set the fax directory - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null); + $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; + // set fax cover font to generate pdf + $fax_cover_font = $_SESSION['fax']['cover_font']['text']; +} +else{ + require_once "resources/classes/EventSocket.php"; } -function correct_path($p) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return str_replace('/', '\\', $p); +if(!function_exists('correct_path')) { + function correct_path($p) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return str_replace('/', '\\', $p); + } + return $p; } - return $p; } -function gs_cmd($args) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return 'gswin32c '.$args; +if(!function_exists('gs_cmd')) { + function gs_cmd($args) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return 'gswin32c '.$args; + } + return 'gs '.$args; } - return 'gs '.$args; +} + +if(!function_exists('fax_enqueue')) { + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ + global $db, $db_type; + + $fax_task_uuid = uuid(); + $dial_string .= "fax_task_uuid='" . $fax_task_uuid . "',"; + $description = ''; //! @todo add description + if ($db_type == "pgsql") { + $date_utc_now_sql = "NOW() at time zone 'utc'"; + } + if ($db_type == "mysql") { + $date_utc_now_sql = "UTC_TIMESTAMP()"; + } + if ($db_type == "sqlite") { + $date_utc_now_sql = "datetime('now')"; + } + $sql = <<prepare($sql); + $i = 0; + $stmt->bindValue(++$i, $fax_task_uuid); + $stmt->bindValue(++$i, $fax_uuid); + $stmt->bindValue(++$i, $fax_file); + $stmt->bindValue(++$i, $wav_file); + $stmt->bindValue(++$i, $fax_uri); + $stmt->bindValue(++$i, $dial_string); + $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); + $stmt->bindValue(++$i, $description); + if ($stmt->execute()) { + $response = 'Enqueued'; + } + else{ + //! @todo log error + $response = 'Fail enqueue'; + var_dump($db->errorInfo()); + } + unset($stmt); + return $response; + } +} + +if(!function_exists('fax_split_dtmf')) { +function fax_split_dtmf(&$fax_number, &$fax_dtmf){ + $tmp = array(); + $fax_dtmf = ''; + if(preg_match('/^\s*(.*?)\s*\((.*)\)\s*$/', $fax_number, $tmp)){ + $fax_number = $tmp[1]; + $fax_dtmf = $tmp[2]; + } +} } //get the fax extension @@ -131,7 +213,7 @@ function gs_cmd($args) { mkdir($_SESSION['switch']['storage']['dir'].'/fax'); chmod($_SESSION['switch']['storage']['dir'].'/fax',0774); } - if (count($_SESSION["domains"]) > 1 && !is_dir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'])) { + if (!is_dir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'])) { mkdir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']); chmod($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'],0774); } @@ -156,7 +238,6 @@ function gs_cmd($args) { //clear file status cache clearstatcache(); - //send the fax $continue = false; @@ -164,14 +245,6 @@ function gs_cmd($args) { if (($_POST['action'] == "send")) { $fax_numbers = $_POST['fax_numbers']; - if (sizeof($fax_numbers) > 0) { - foreach ($fax_numbers as $index => $fax_number) { - $fax_numbers[$index] = preg_replace("~[^0-9]~", "", $fax_number); - if ($fax_numbers[$index] == '') { unset($fax_numbers[$index]); } - } - sort($fax_numbers); - } - $fax_uuid = check_str($_POST["id"]); $fax_caller_id_name = check_str($_POST['fax_caller_id_name']); $fax_caller_id_number = check_str($_POST['fax_caller_id_number']); @@ -193,6 +266,23 @@ function gs_cmd($args) { $continue = true; } +// cleanup numbers + if (isset($fax_numbers)) { + foreach ($fax_numbers as $index => $fax_number) { + fax_split_dtmf($fax_number, $fax_dtmf); + $fax_number = preg_replace("~[^0-9]~", "", $fax_number); + $fax_dtmf = preg_replace("~[^0-9Pp*#]~", "", $fax_dtmf); + if ($fax_number != ''){ + if ($fax_dtmf != '') {$fax_number .= " (" . $fax_dtmf . ")";} + $fax_numbers[$index] = $fax_number; + } + else{ + unset($fax_numbers[$index]); + } + } + sort($fax_numbers); + } + if ($continue) { //determine page size switch ($fax_page_size) { @@ -315,6 +405,19 @@ function gs_cmd($args) { $pdf -> setPrintFooter(false); $pdf -> SetMargins(0, 0, 0, true); + if(strlen($fax_cover_font) > 0){ + if(substr($fax_cover_font, -4) == '.ttf'){ + $pdf_font = TCPDF_FONTS::addTTFfont($fax_cover_font); + } + else{ + $pdf_font = $fax_cover_font; + } + } + + if(!$pdf_font){ + $pdf_font = 'times'; + } + //add blank page $pdf -> AddPage('P', array($page_width, $page_height)); @@ -322,9 +425,6 @@ function gs_cmd($args) { $x = 0; $y = 0; - // output grid - //showgrid($pdf); - //logo $display_logo = false; if (!isset($_SESSION['fax']['cover_logo']['text'])) { @@ -368,23 +468,23 @@ function gs_cmd($args) { //header if ($fax_header != '') { $pdf -> SetLeftMargin(0.5); - $pdf -> SetFont("times", "", 10); + $pdf -> SetFont($pdf_font, "", 10); $pdf -> Write(0.3, $fax_header); } //fax, cover sheet $pdf -> SetTextColor(0,0,0); - $pdf -> SetFont("times", "B", 55); + $pdf -> SetFont($pdf_font, "B", 55); $pdf -> SetXY($x + 4.55, $y + 0.25); $pdf -> Cell($x + 3.50, $y + 0.4, $text['label-fax-fax'], 0, 0, 'R', false, null, 0, false, 'T', 'T'); - $pdf -> SetFont("times", "", 12); + $pdf -> SetFont($pdf_font, "", 12); $pdf -> SetFontSpacing(0.0425); $pdf -> SetXY($x + 4.55, $y + 1.0); $pdf -> Cell($x + 3.50, $y + 0.4, $text['label-fax-cover-sheet'], 0, 0, 'R', false, null, 0, false, 'T', 'T'); $pdf -> SetFontSpacing(0); //field labels - $pdf -> SetFont("times", "B", 12); + $pdf -> SetFont($pdf_font, "B", 12); if ($fax_recipient != '' || sizeof($fax_numbers) > 0) { $pdf -> Text($x + 0.5, $y + 2.0, strtoupper($text['label-fax-recipient']).":"); } @@ -399,7 +499,7 @@ function gs_cmd($args) { } //field values - $pdf -> SetFont("times", "", 12); + $pdf -> SetFont($pdf_font, "", 12); $pdf -> SetXY($x + 2.0, $y + 1.95); if ($fax_recipient != '') { $pdf -> Write(0.3, $fax_recipient); @@ -439,7 +539,7 @@ function gs_cmd($args) { //message $pdf -> Rect($x + 0.5, $y + 3.4, 7.5, 6.25, 'D'); if ($fax_message != '') { - $pdf -> SetFont("times", "", 12); + $pdf -> SetFont($pdf_font, "", 12); $pdf -> SetXY($x + 0.75, $y + 3.65); $pdf -> MultiCell(7, 5.75, $fax_message, 0, 'L', false); } @@ -527,7 +627,7 @@ function gs_cmd($args) { } //preview, if requested - if ($_REQUEST['submit'] == $text['button-preview']) { + if (($_REQUEST['submit'] != '') && ($_REQUEST['submit'] == $text['button-preview'])) { unset($file_type); if (file_exists($dir_fax_temp.'/'.$fax_instance_uuid.'.pdf')) { $file_type = 'pdf'; @@ -592,29 +692,64 @@ function gs_cmd($args) { } //send the fax + $fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif"; + $common_dial_string = "for_fax=1,"; + $common_dial_string .= "accountcode='" . $fax_accountcode . "',"; + $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; + $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; + $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; + $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; + $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; + $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; + $common_dial_string .= "fax_header='" . $fax_caller_id_name . "',"; + $common_dial_string .= "fax_file='" . $fax_file . "',"; + foreach ($fax_numbers as $fax_number) { - $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); - if ($fp) { - //prepare the fax command - $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_prefix.$fax_number); - $fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif"; - if (count($route_array) == 0) { - //send the internal call to the registered extension - $fax_uri = "user/".$fax_number."@".$_SESSION['domain_name']; - $t38 = ""; + $dial_string = $common_dial_string; + fax_split_dtmf($fax_number, $fax_dtmf); + + //prepare the fax command + $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_prefix . $fax_number); + + if (count($route_array) == 0) { + //send the internal call to the registered extension + $fax_uri = "user/".$fax_number."@".$_SESSION['domain_name']; + $t38 = ""; + } + else { + //send the external call + $fax_uri = $route_array[0]; + $t38 = "fax_enable_t38=true,fax_enable_t38_request=true,"; + } + + if ($fax_send_mode != 'queue') { + $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; + $dial_string .= "fax_uri=" . $fax_uri . ","; + $dial_string .= "fax_retry_attempts=1" . ","; + $dial_string .= "fax_retry_limit=20" . ","; + $dial_string .= "fax_retry_sleep=180" . ","; + $dial_string .= "fax_verbose=true" . ","; + $dial_string .= "fax_use_ecm=off" . ","; + $dial_string .= "api_hangup_hook='lua fax_retry.lua'"; + $dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')"; + + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $cmd = "api originate " . $dial_string; + // echo($cmd . "
\n"); + //send the command to event socket + $response = event_socket_request($fp, $cmd); + $response = str_replace("\n", "", $response); + $uuid = str_replace("+OK ", "", $response); } - else { - //send the external call - $fax_uri = $route_array[0]; - $t38 = "fax_enable_t38=true,fax_enable_t38_request=true,"; - } - $cmd = "api originate {for_fax=1,accountcode='".$fax_accountcode."',sip_h_X-accountcode='".$fax_accountcode."',domain_uuid=".$_SESSION["domain_uuid"].",domain_name=".$_SESSION["domain_name"].",mailto_address='".$mailto_address."',mailfrom_address='".$mailfrom_address."',origination_caller_id_name='".$fax_caller_id_name."',origination_caller_id_number='".$fax_caller_id_number."',fax_ident='".$fax_caller_id_number."',fax_header='".$fax_caller_id_name."',fax_uri=".$fax_uri.",fax_file='".$fax_file."',fax_retry_attempts=1,fax_retry_limit=20,fax_retry_sleep=180,fax_verbose=true,fax_use_ecm=off,".$t38."api_hangup_hook='lua fax_retry.lua'}".$fax_uri." &txfax('".$fax_file."')"; - //send the command to event socket - $response = event_socket_request($fp, $cmd); - $response = str_replace("\n", "", $response); - $uuid = str_replace("+OK ", "", $response); fclose($fp); } + else{ // enqueue + $wav_file = ''; //! @todo add custom message + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); + } } //wait for a few seconds diff --git a/app/fax/resources/classes/fax.php b/app/fax/resources/classes/fax.php index b86627c44c..0100aeaeaa 100644 --- a/app/fax/resources/classes/fax.php +++ b/app/fax/resources/classes/fax.php @@ -174,12 +174,7 @@ $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "rxfax"; - if (count($_SESSION["domains"]) > 1) { - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'].'/'.$this->fax_extension.'/inbox/'.$this->forward_prefix.'${last_fax}.tif'; - } - else { - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'].'/fax/'.$this->fax_extension.'/inbox/'.$this->forward_prefix.'${last_fax}.tif'; - } + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'].'/'.$this->fax_extension.'/inbox/'.$this->forward_prefix.'${last_fax}.tif'; $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; $y++; diff --git a/app/fax/resources/functions/parse_attachments.php b/app/fax/resources/functions/parse_attachments.php index 9999660636..f5a5f1f508 100644 --- a/app/fax/resources/functions/parse_attachments.php +++ b/app/fax/resources/functions/parse_attachments.php @@ -1,48 +1,48 @@ parts) && count($structure->parts)) { + if(isset($structure->parts) && count($structure->parts)) { - for($i = 0; $i < count($structure->parts); $i++) { + for($i = 0; $i < count($structure->parts); $i++) { - if($structure->parts[$i]->ifdparameters) { - foreach($structure->parts[$i]->dparameters as $object) { - if(strtolower($object->attribute) == 'filename') { - $attachments[$i]['is_attachment'] = true; - $attachments[$i]['filename'] = $object->value; - } - } - } + if($structure->parts[$i]->ifdparameters) { + foreach($structure->parts[$i]->dparameters as $object) { + if(strtolower($object->attribute) == 'filename') { + $attachments[$i]['is_attachment'] = true; + $attachments[$i]['filename'] = $object->value; + } + } + } - if($structure->parts[$i]->ifparameters) { - foreach($structure->parts[$i]->parameters as $object) { - if(strtolower($object->attribute) == 'name') { - $attachments[$i]['is_attachment'] = true; - $attachments[$i]['name'] = $object->value; - } - } - } + if($structure->parts[$i]->ifparameters) { + foreach($structure->parts[$i]->parameters as $object) { + if(strtolower($object->attribute) == 'name') { + $attachments[$i]['is_attachment'] = true; + $attachments[$i]['name'] = $object->value; + } + } + } - if($attachments[$i]['is_attachment']) { - $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1, $option); - if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 - $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); - $attachments[$i]['size'] = strlen($attachments[$i]['attachment']); - } - elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE - $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); - $attachments[$i]['size'] = strlen($attachments[$i]['attachment']); - } - } + if($attachments[$i]['is_attachment']) { + $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1, $option); + if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 + $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); + $attachments[$i]['size'] = strlen($attachments[$i]['attachment']); + } + elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE + $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); + $attachments[$i]['size'] = strlen($attachments[$i]['attachment']); + } + } unset($attachments[$i]['is_attachment']); - } + } - } - return array_values($attachments); //reindex + } + return array_values($attachments); //reindex } ?> \ No newline at end of file diff --git a/app/fax/resources/functions/parse_message.php b/app/fax/resources/functions/parse_message.php new file mode 100644 index 0000000000..c2945e76b2 --- /dev/null +++ b/app/fax/resources/functions/parse_message.php @@ -0,0 +1,38 @@ +parts) && count($structure->parts)) { + for($i = 0; $i < count($structure->parts); $i++) { + $msg = ''; + $part = $structure->parts[$i]; + if($part->type == TYPETEXT){ + $msg = imap_fetchbody($connection, $message_number, $i+1, $option); + if($part->encoding == ENCBASE64){ + $msg = base64_decode($msg); + } + else if($part->encoding == ENCQUOTEDPRINTABLE){ + $msg = quoted_printable_decode($msg); + } + if($msg && $to_charset){ + $charset = ''; + if(isset($part->parameters) && count($part->parameters)) { + foreach($part->parameters as &$parameter){ + if($parameter->attribute == 'CHARSET') { + $charset = $parameter->value; + break; + } + } + } + if($charset){ + $msg = mb_convert_encoding($msg, $to_charset, $charset); + } + } + + if($msg){ + return $msg; + } + } + } + } +} diff --git a/app/ivr_menus/ivr_menu_edit.php b/app/ivr_menus/ivr_menu_edit.php index eb85e04752..40a40e3d24 100644 --- a/app/ivr_menus/ivr_menu_edit.php +++ b/app/ivr_menus/ivr_menu_edit.php @@ -440,9 +440,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; $recording_filename = $row["recording_filename"]; - if ($ivr_menu_greet_long == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_greet_long) > 0) { + if ($ivr_menu_greet_long == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename && strlen($ivr_menu_greet_long) > 0) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else if ($ivr_menu_greet_long == $recording_filename && strlen($ivr_menu_greet_long) > 0) { $tmp_selected = true; @@ -500,8 +500,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (if_group("superadmin")) { if (!$tmp_selected) { echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_greet_long)) { - echo " \n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_long)) { + echo " \n"; } else if (substr($ivr_menu_greet_long, -3) == "wav" || substr($ivr_menu_greet_long, -3) == "mp3") { echo " \n"; @@ -538,9 +538,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; $recording_filename = $row["recording_filename"]; - if ($ivr_menu_greet_short == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_greet_short) > 0) { + if ($ivr_menu_greet_short == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename && strlen($ivr_menu_greet_short) > 0) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else if ($ivr_menu_greet_short == $recording_filename && strlen($ivr_menu_greet_short) > 0) { $tmp_selected = true; @@ -599,8 +599,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (if_group("superadmin")) { if (!$tmp_selected && strlen($ivr_menu_greet_short) > 0) { echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_greet_short)) { - echo " \n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_short)) { + echo " \n"; } else if (substr($ivr_menu_greet_short, -3) == "wav" || substr($ivr_menu_greet_short, -3) == "mp3") { echo " \n"; @@ -877,9 +877,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; $recording_filename = $row["recording_filename"]; - if ($ivr_menu_invalid_sound == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_invalid_sound) > 0) { + if ($ivr_menu_invalid_sound == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename && strlen($ivr_menu_invalid_sound) > 0) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else if ($ivr_menu_invalid_sound == $recording_filename && strlen($ivr_menu_invalid_sound) > 0) { $tmp_selected = true; @@ -935,8 +935,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (if_group("superadmin")) { if (!$tmp_selected) { echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_invalid_sound)) { - echo " \n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_invalid_sound)) { + echo " \n"; } else if (substr($ivr_menu_invalid_sound, -3) == "wav" || substr($ivr_menu_invalid_sound, -3) == "mp3") { echo " \n"; @@ -973,9 +973,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; $recording_filename = $row["recording_filename"]; - if ($ivr_menu_exit_sound == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_exit_sound) > 0) { + if ($ivr_menu_exit_sound == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename && strlen($ivr_menu_exit_sound) > 0) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else if ($ivr_menu_exit_sound == $recording_filename && strlen($ivr_menu_exit_sound) > 0) { $tmp_selected = true; @@ -1031,8 +1031,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (if_group("superadmin")) { if (!$tmp_selected) { echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_exit_sound)) { - echo " \n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_exit_sound)) { + echo " \n"; } else if (substr($ivr_menu_exit_sound, -3) == "wav" || substr($ivr_menu_exit_sound, -3) == "mp3") { echo " \n"; diff --git a/app/ivr_menus/resources/classes/ivr_menu.php b/app/ivr_menus/resources/classes/ivr_menu.php index 2f4d03959c..beaba4f804 100644 --- a/app/ivr_menus/resources/classes/ivr_menu.php +++ b/app/ivr_menus/resources/classes/ivr_menu.php @@ -575,23 +575,6 @@ include "root.php"; $database->fields['dialplan_detail_order'] = '030'; $database->add(); - /* - $database->table = "v_dialplan_details"; - $database->fields['domain_uuid'] = $this->domain_uuid; - $database->fields['dialplan_uuid'] = $this->dialplan_uuid; - $database->fields['dialplan_detail_uuid'] = uuid(); - $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction - $database->fields['dialplan_detail_type'] = 'ivr'; - if (count($_SESSION["domains"]) > 1) { - $database->fields['dialplan_detail_data'] = $_SESSION['domain_name'].'-'.$this->ivr_menu_name; - } - else { - $database->fields['dialplan_detail_data'] = $this->ivr_menu_name; - } - $database->fields['dialplan_detail_order'] = '035'; - $database->add(); - */ - $database->table = "v_dialplan_details"; $database->fields['domain_uuid'] = $this->domain_uuid; $database->fields['dialplan_uuid'] = $this->dialplan_uuid; diff --git a/app/music_on_hold/resources/classes/switch_music_on_hold.php b/app/music_on_hold/resources/classes/switch_music_on_hold.php index 3e3aaf1e01..40bc2ba8e4 100644 --- a/app/music_on_hold/resources/classes/switch_music_on_hold.php +++ b/app/music_on_hold/resources/classes/switch_music_on_hold.php @@ -90,7 +90,7 @@ include "root.php"; } } //recordings - if($dh = opendir($_SESSION['switch']['recordings']['dir']."/")) { + if($dh = opendir($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/")) { $tmp_selected = false; $files = Array(); //$select .= "\n"; diff --git a/app/operator_panel/index.php b/app/operator_panel/index.php index daa77ee8bd..481696d0ba 100644 --- a/app/operator_panel/index.php +++ b/app/operator_panel/index.php @@ -357,7 +357,7 @@ require_once "resources/header.php"; } function get_record_cmd(uuid) { - cmd = "uuid_record " + uuid + " start /archive////" + uuid + ".wav"; + cmd = "uuid_record " + uuid + " start /archive////" + uuid + ".wav"; return cmd; } diff --git a/app/phrases/app_defaults.php b/app/phrases/app_defaults.php index 43f23c3b08..1d707c96b6 100644 --- a/app/phrases/app_defaults.php +++ b/app/phrases/app_defaults.php @@ -109,8 +109,8 @@ if ($domains_processed == 1) { foreach ($result as &$row) { $phrase_detail_uuid = $row['phrase_detail_uuid']; $phrase_detail_data = $row['phrase_detail_data']; - if (substr_count($phrase_detail_data, $_SESSION['switch']['recordings']['dir']) > 0) { - $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/', '', $phrase_detail_data); + if (substr_count($phrase_detail_data, $_SESSION['switch']['recordings']['dir'].'/'.$domain_name) > 0) { + $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/', '', $phrase_detail_data); } //update function and data to be base64 compatible $phrase_detail_data = "lua(streamfile.lua ".$phrase_detail_data.")"; @@ -141,7 +141,7 @@ if ($domains_processed == 1) { $phrase_detail_data = str_replace('lua(streamfile.lua ', '', $phrase_detail_data); $phrase_detail_data = str_replace(')', '', $phrase_detail_data); if (substr_count($phrase_detail_data, '/') === 0) { - $phrase_detail_data = $_SESSION['switch']['recordings']['dir'].'/'.$phrase_detail_data; + $phrase_detail_data = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/'.$phrase_detail_data; } $sql = "update v_phrase_details set "; $sql .= "phrase_detail_function = 'play-file', "; diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php index 387255a9bb..512bdef71a 100644 --- a/app/phrases/phrase_edit.php +++ b/app/phrases/phrase_edit.php @@ -305,7 +305,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"lua(streamfile.lua ".$row["recording_filename"].")\"));\n"; } else { - echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"".$_SESSION['switch']['recordings']['dir'].'/'.$row["recording_filename"]."\"));\n"; + echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"".$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row["recording_filename"]."\"));\n"; } } echo "obj_action.appendChild(opt_group);\n"; @@ -470,7 +470,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { } if ($field['phrase_detail_function'] == 'play-file') { $phrase_detail_function = $text['label-play']; - $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/', '', $field['phrase_detail_data']); + $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/', '', $field['phrase_detail_data']); } echo "\n"; echo " ".$phrase_detail_function." \n"; diff --git a/app/provision/app_defaults.php b/app/provision/app_defaults.php index 7e80fd2e59..da82965d6e 100644 --- a/app/provision/app_defaults.php +++ b/app/provision/app_defaults.php @@ -179,6 +179,13 @@ $array[$x]['default_setting_enabled'] = 'false'; $array[$x]['default_setting_description'] = ''; $x++; + $array[$x]['default_setting_category'] = 'provision'; + $array[$x]['default_setting_subcategory'] = 'directory_extensions'; + $array[$x]['default_setting_name'] = 'boolean'; + $array[$x]['default_setting_value'] = 'true'; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = 'allow extensions to be provisioned as contacts as $extensions in provision templates'; + $x++; $array[$x]['default_setting_category'] = 'ntp_server_primary'; $array[$x]['default_setting_subcategory'] = 'directory'; $array[$x]['default_setting_name'] = 'text'; diff --git a/app/provision/index.php b/app/provision/index.php index 73f2f73915..ae17fefba2 100644 --- a/app/provision/index.php +++ b/app/provision/index.php @@ -42,6 +42,15 @@ openlog("fusion-provisioning", LOG_PID | LOG_PERROR, LOG_LOCAL0); // $device_template = check_str($_REQUEST['template']); //} +//get the mac address for Cisco 79xx in the URL as &name=SEP000000000000 + if (empty($mac)){ + $name = check_str($_REQUEST['name']); + if (substr($name, 0, 3) == "SEP") { + $mac = strtolower(substr($name, 3, 12)); + unset($name); + } + } + //check alternate MAC source if (empty($mac)){ //set the http user agent @@ -283,20 +292,33 @@ openlog("fusion-provisioning", LOG_PID | LOG_PERROR, LOG_LOCAL0); //deliver the customized config over HTTP/HTTPS //need to make sure content-type is correct - $cfg_ext = ".cfg"; - if ($device_vendor === "aastra" && strrpos($file, $cfg_ext, 0) === strlen($file) - strlen($cfg_ext)) { - header("Content-Type: text/plain"); - header("Content-Length: ".strlen($file_contents)); - } else if ($device_vendor === "yealink") { - header("Content-Type: text/plain"); - header("Content-Length: ".strval(strlen($file_contents))); - } else if ($device_vendor === "snom" && $device_template === "snom/m3") { - $file_contents = utf8_decode($file_contents); - header("Content-Type: text/plain; charset=iso-8859-1"); - header("Content-Length: ".strlen($file_contents)); - } else { - header("Content-Type: text/xml; charset=utf-8"); - header("Content-Length: ".strlen($file_contents)); + if ($_REQUEST['content_type'] == 'application/octet-stream') { + $file_name = str_replace("{\$mac}",$mac,$file); + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($file_name).'"'); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . filesize($file_contents)); + } + else { + $cfg_ext = ".cfg"; + if ($device_vendor === "aastra" && strrpos($file, $cfg_ext, 0) === strlen($file) - strlen($cfg_ext)) { + header("Content-Type: text/plain"); + header("Content-Length: ".strlen($file_contents)); + } else if ($device_vendor === "yealink") { + header("Content-Type: text/plain"); + header("Content-Length: ".strval(strlen($file_contents))); + } else if ($device_vendor === "snom" && $device_template === "snom/m3") { + $file_contents = utf8_decode($file_contents); + header("Content-Type: text/plain; charset=iso-8859-1"); + header("Content-Length: ".strlen($file_contents)); + } else { + header("Content-Type: text/xml; charset=utf-8"); + header("Content-Length: ".strlen($file_contents)); + } } echo $file_contents; closelog(); diff --git a/app/provision/resources/classes/provision.php b/app/provision/resources/classes/provision.php index 66fa4645cb..60a7cdb141 100644 --- a/app/provision/resources/classes/provision.php +++ b/app/provision/resources/classes/provision.php @@ -180,11 +180,17 @@ include "root.php"; if (strlen($device_template) == 0) { $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_mac_address=:mac "; + if($provision['http_domain_filter'] == "true") { + $sql .= "AND domain_uuid=:domain_uuid "; + } //$sql .= "WHERE device_mac_address= '$mac' "; $prep_statement_2 = $this->db->prepare(check_sql($sql)); if ($prep_statement_2) { //use the prepared statement $prep_statement_2->bindParam(':mac', $mac); + if($provision['http_domain_filter'] == "true") { + $prep_statement_2->bindParam(':domain_uuid', $domain_uuid); + } $prep_statement_2->execute(); $row = $prep_statement_2->fetch(); //set the variables from values in the database @@ -300,8 +306,14 @@ include "root.php"; if (strlen($device_uuid) > 0) { $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_uuid = '".$device_uuid."' "; + if($provision['http_domain_filter'] == "true") { + $sql .= "AND domain_uuid=:domain_uuid "; + } $prep_statement_3 = $this->db->prepare(check_sql($sql)); if ($prep_statement_3) { + if($provision['http_domain_filter'] == "true") { + $prep_statement_3->bindParam(':domain_uuid', $domain_uuid); + } $prep_statement_3->execute(); $row = $prep_statement_3->fetch(); $device_uuid_alternate = $row["device_uuid_alternate"]; @@ -311,8 +323,14 @@ include "root.php"; //get the new devices information $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_uuid = '".$device_uuid."' "; + if($provision['http_domain_filter'] == "true") { + $sql .= "AND domain_uuid=:domain_uuid "; + } $prep_statement_4 = $this->db->prepare(check_sql($sql)); if ($prep_statement_4) { + if($provision['http_domain_filter'] == "true") { + $prep_statement_4->bindParam(':domain_uuid', $domain_uuid); + } $prep_statement_4->execute(); $row = $prep_statement_4->fetch(); $device_label = $row["device_label"]; @@ -384,7 +402,7 @@ include "root.php"; //get the contacts array and add to the template engine if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0 and $_SESSION['provision']['directory']['boolean'] == "true") { //get contacts from the database - $sql = "select c.contact_organization, c.contact_name_given, c.contact_name_family, p.phone_number, p.phone_extension "; + $sql = "select c.contact_category, c.contact_organization, c.contact_name_given, c.contact_name_family, p.phone_number, p.phone_extension "; $sql .= "from v_contacts as c, v_contact_phones as p "; $sql .= "where c.domain_uuid = '".$domain_uuid."' "; $sql .= "and c.contact_uuid = p.contact_uuid "; @@ -455,6 +473,29 @@ include "root.php"; unset ($prep_statement); } + //get the extensions array and add to the template engine + if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0 and $_SESSION['provision']['directory_extensions']['boolean'] == "true") { + //get contacts from the database + $sql = "select c.contact_organization, c.contact_name_given, c.contact_name_family, e.extension "; + $sql .= "from v_contacts as c, v_extension_users as cte, v_extensions as e, v_users as u "; + $sql .= "where c.domain_uuid = '".$domain_uuid."' "; + $sql .= "and c.contact_uuid = u.contact_uuid "; + $sql .= "and u.user_uuid = cte.user_uuid "; + $sql .= "and cte.extension_uuid = e.extension_uuid "; + $sql .= "and e.directory_visible = 'true' "; + foreach ($lines as $line){ + $sql .= "and e.extension != '" . $line['user_id']. "' "; + } + $sql .= "order by c.contact_organization desc, c.contact_name_given asc, c.contact_name_family asc "; + $prep_statement = $this->db->prepare(check_sql($sql)); + $prep_statement->execute(); + $extensions = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement, $sql); + + //assign the contacts array + $view->assign("extensions", $extensions); + } + //get the provisioning information from device keys if (strlen($device_uuid) > 0) { //get the device keys array @@ -623,21 +664,21 @@ include "root.php"; case "ldap search": $device_key_type = "21"; break; } } - if ($device_key_category == "memory") { - switch ($device_key_type) { - case "speed dial": $device_key_type = "0"; break; - case "blf": $device_key_type = "1"; break; - case "presence watcher": $device_key_type = "2"; break; - case "eventlist blf": $device_key_type = "3"; break; - case "speed dial active": $device_key_type = "4"; break; - case "dial dtmf": $device_key_type = "5"; break; - case "voicemail": $device_key_type = "6"; break; - case "call return": $device_key_type = "7"; break; - case "transfer": $device_key_type = "8"; break; - case "call park": $device_key_type = "9"; break; - case "intercom": $device_key_type = "10"; break; - case "ldap search": $device_key_type = "11"; break; - } + if ($device_key_category == "memory" || $device_key_category == "expansion") { + switch ($device_key_type) { + case "speed dial": $device_key_type = "0"; break; + case "blf": $device_key_type = "1"; break; + case "presence watcher": $device_key_type = "2"; break; + case "eventlist blf": $device_key_type = "3"; break; + case "speed dial active": $device_key_type = "4"; break; + case "dial dtmf": $device_key_type = "5"; break; + case "voicemail": $device_key_type = "6"; break; + case "call return": $device_key_type = "7"; break; + case "transfer": $device_key_type = "8"; break; + case "call park": $device_key_type = "9"; break; + case "intercom": $device_key_type = "10"; break; + case "ldap search": $device_key_type = "11"; break; + } } } @@ -760,6 +801,13 @@ include "root.php"; $tmp_array = ''; $i = 0; + //build the provision array + foreach($_SESSION['provision'] as $key=>$val) { + if (strlen($val['var']) > 0) { $value = $val['var']; } + if (strlen($val['text']) > 0) { $value = $val['text']; } + $provision[$key] = $value; + } + //get the devices $sql = "select * from v_devices "; //$sql .= "where domain_uuid = '".$this->domain_uuid."' "; diff --git a/app/recordings/app_defaults.php b/app/recordings/app_defaults.php index 1d2552b251..7e22c12191 100644 --- a/app/recordings/app_defaults.php +++ b/app/recordings/app_defaults.php @@ -25,8 +25,8 @@ */ //if the recordings directory doesn't exist then create it - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - if (!is_readable($_SESSION['switch']['recordings']['dir'])) { mkdir($_SESSION['switch']['recordings']['dir'],0777,true); } + 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,0777,true); } } if ($domains_processed == 1) { @@ -45,7 +45,7 @@ if ($domains_processed == 1) { $recording_domain_uuid = $row['domain_uuid']; $recording_filename = $row['recording_filename']; //set recording directory - $recording_directory = $_SESSION['switch']['recordings']['dir']; + $recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name; //encode recording file (if exists) if (file_exists($recording_directory.'/'.$recording_filename)) { $recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename)); @@ -78,7 +78,7 @@ if ($domains_processed == 1) { $recording_filename = $row['recording_filename']; $recording_base64 = $row['recording_base64']; //set recording directory - $recording_directory = $_SESSION['switch']['recordings']['dir']; + $recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name; //remove local file, if any if (file_exists($recording_directory.'/'.$recording_filename)) { @unlink($recording_directory.'/'.$recording_filename); diff --git a/app/recordings/recording_delete.php b/app/recordings/recording_delete.php index b460300109..9738b8756a 100644 --- a/app/recordings/recording_delete.php +++ b/app/recordings/recording_delete.php @@ -66,8 +66,8 @@ if (strlen($id)>0) { unset($sql); //delete the recording - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$filename)) { - @unlink($_SESSION['switch']['recordings']['dir']."/".$filename); + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename)) { + @unlink($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$filename); } } diff --git a/app/recordings/recording_edit.php b/app/recordings/recording_edit.php index e5d29ce62b..e4b6bc6187 100644 --- a/app/recordings/recording_edit.php +++ b/app/recordings/recording_edit.php @@ -83,7 +83,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (permission_exists('recording_edit')) { //if file name is not the same then rename the file if ($recording_filename != $recording_filename_original) { - rename($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); + rename($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); } //update the database with the new data diff --git a/app/recordings/recordings.php b/app/recordings/recordings.php index 97843d156d..c12e09d01e 100644 --- a/app/recordings/recordings.php +++ b/app/recordings/recordings.php @@ -49,7 +49,7 @@ require_once "resources/check_auth.php"; if ($_GET['a'] == "download" && (permission_exists('recording_play') || permission_exists('recording_download'))) { session_cache_limiter('public'); if ($_GET['type'] = "rec") { - $path = $_SESSION['switch']['recordings']['dir']; + $path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']; //if from recordings, get recording details from db $recording_uuid = check_str($_GET['id']); //recordings @@ -115,7 +115,7 @@ require_once "resources/check_auth.php"; if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { $recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']); $recording_filename = str_replace("'", "", $recording_filename); - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); + move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); $_SESSION['message'] = $text['message-uploaded'].": ".htmlentities($recording_filename); @@ -146,9 +146,9 @@ require_once "resources/check_auth.php"; $array_base64_exists[$row['recording_uuid']] = ($row['recording_base64'] != '') ? true : false; //if not base64, convert back to local files and remove base64 from db if ($_SESSION['recordings']['storage_type']['text'] != 'base64' && $row['recording_base64'] != '') { - if (!file_exists($_SESSION['switch']['recordings']['dir'].'/'.$row['recording_filename'])) { + if (!file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'])) { $recording_decoded = base64_decode($row['recording_base64']); - file_put_contents($_SESSION['switch']['recordings']['dir'].'/'.$row['recording_filename'], $recording_decoded); + file_put_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename'], $recording_decoded); $sql = "update v_recordings set recording_base64 = null where domain_uuid = '".$domain_uuid."' and recording_uuid = '".$row['recording_uuid']."' "; $db->exec(check_sql($sql)); unset($sql); @@ -158,10 +158,10 @@ require_once "resources/check_auth.php"; unset ($prep_statement); //add recordings to the database - if (is_dir($_SESSION['switch']['recordings']['dir'].'/')) { - if ($dh = opendir($_SESSION['switch']['recordings']['dir'].'/')) { + if (is_dir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/')) { + if ($dh = opendir($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/')) { while (($recording_filename = readdir($dh)) !== false) { - if (filetype($_SESSION['switch']['recordings']['dir']."/".$recording_filename) == "file") { + if (filetype($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$recording_filename) == "file") { if (!in_array($recording_filename, $array_recordings)) { //file not found in db, add it @@ -187,7 +187,7 @@ require_once "resources/check_auth.php"; $sql .= "'".$recording_name."', "; $sql .= "'".$recording_description."' "; if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { - $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename)); + $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename)); $sql .= ", '".$recording_base64."' "; } $sql .= ")"; @@ -199,7 +199,7 @@ require_once "resources/check_auth.php"; if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $found_recording_uuid = array_search($recording_filename, $array_recordings); if (!$array_base64_exists[$found_recording_uuid]) { - $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename)); + $recording_base64 = base64_encode(file_get_contents($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename)); $sql = "update v_recordings set "; $sql .= "recording_base64 = '".$recording_base64."' "; $sql .= "where domain_uuid = '".$domain_uuid."' "; @@ -211,8 +211,8 @@ require_once "resources/check_auth.php"; } //if base64, remove local file - if ($_SESSION['recordings']['storage_type']['text'] == 'base64' && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename)) { - @unlink($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); + if ($_SESSION['recordings']['storage_type']['text'] == 'base64' && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename)) { + @unlink($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$recording_filename); } } @@ -307,7 +307,7 @@ require_once "resources/check_auth.php"; echo " ".$row['recording_name']."\n"; if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { echo " ".$row['recording_filename']."\n"; - $tmp_filesize = filesize($_SESSION['switch']['recordings']['dir'].'/'.$row['recording_filename']); + $tmp_filesize = filesize($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['recording_filename']); $tmp_filesize = byte_convert($tmp_filesize); echo " ".$tmp_filesize."\n"; } diff --git a/app/registrations/cmd.php b/app/registrations/cmd.php index f3f4c0a4f9..6a010d125d 100644 --- a/app/registrations/cmd.php +++ b/app/registrations/cmd.php @@ -54,9 +54,15 @@ else { if (preg_replace('/^.*?(cisco).*$/i', '$1', strtolower($agent)) == "cisco") { $vendor = "cisco"; } + if (preg_replace('/^.*?(cisco\/spa).*$/i', '$1', strtolower($agent)) == "cisco/spa") { + $vendor = "cisco-spa"; + } if (preg_replace('/^.*?(grandstream).*$/i', '$1', strtolower($agent)) == "grandstream") { $vendor = "grandstream"; } + if (preg_replace('/^.*?(linksys).*$/i', '$1', strtolower($agent)) == "linksys") { + $vendor = "linksys"; + } if (preg_replace('/^.*?(polycom).*$/i', '$1', strtolower($agent)) == "polycom") { $vendor = "polycom"; } diff --git a/app/settings/app_defaults.php b/app/settings/app_defaults.php index 3f12171d26..7cc0757849 100644 --- a/app/settings/app_defaults.php +++ b/app/settings/app_defaults.php @@ -76,6 +76,18 @@ if ($domains_processed == 1) { $db->exec(check_sql($sql)); unset($sql); } + + if(isset($_SESSION['event_socket_ip_address'])) { + $event_socket_ip_address = $_SESSION['event_socket_ip_address']; + if(isset($_SESSION['event_socket_port'])) { $event_socket_port = $_SESSION['event_socket_port']; } + if(isset($_SESSION['event_socket_password'])) { $event_socket_password = $_SESSION['event_socket_password']; } + $sql = "update v_settings "; + $sql .= "set event_socket_ip_address = '$event_socket_ip_address' "; + $sql .= "set event_socket_port = '$event_socket_port' "; + $sql .= "set event_socket_password = '$event_socket_password' "; + $db->exec(check_sql($sql)); + unset($sql); + } } ?> \ No newline at end of file diff --git a/app/sip_profiles/app_defaults.php b/app/sip_profiles/app_defaults.php index 24d9cf2d80..3de33883bb 100644 --- a/app/sip_profiles/app_defaults.php +++ b/app/sip_profiles/app_defaults.php @@ -92,15 +92,18 @@ $sip_profile_description = "The Internal IPV6 profile binds to the IP version 6 address and is similar to the Internal profile.\n"; break; case "external": - $sip_profile_description .= "The External profile external provides anonymous calling in the public context. "; + $sip_profile_description = "The External profile external provides anonymous calling in the public context. "; $sip_profile_description .= "By default the External profile binds to port 5080. "; $sip_profile_description .= "Calls can be sent using a SIP URL \"voip.domain.com:5080\" "; break; + case "external-ipv6": + $sip_profile_description = "The External IPV6 profile binds to the IP version 6 address and is similar to the External profile.\n"; + break; case "lan": $sip_profile_description = "The LAN profile is the same as the Internal profile except that it is bound to the LAN IP.\n"; break; default: - $sip_profile_description .= ''; + $sip_profile_description = ''; } //add the sip profile if it is not false diff --git a/app/sip_profiles/resources/xml/sip_profiles/external-ipv6.xml b/app/sip_profiles/resources/xml/sip_profiles/external-ipv6.xml new file mode 100644 index 0000000000..f48bc7ed0e --- /dev/null +++ b/app/sip_profiles/resources/xml/sip_profiles/external-ipv6.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + +{v_sip_profile_settings} + + diff --git a/app/system/app_languages.php b/app/system/app_languages.php index 0906685a9b..e576287a32 100644 --- a/app/system/app_languages.php +++ b/app/system/app_languages.php @@ -80,6 +80,66 @@ $text['label-os']['sv-se'] = "Operativsystem"; $text['label-os']['uk'] = "Операційна система "; $text['label-os']['de-at'] = "Betriebssystem"; +$text['label-version']['en-us'] = "Version"; +$text['label-version']['es-cl'] = ""; +$text['label-version']['pt-pt'] = ""; +$text['label-version']['fr-fr'] = ""; +$text['label-version']['pt-br'] = ""; +$text['label-version']['pl'] = ""; +$text['label-version']['sv-se'] = ""; +$text['label-version']['uk'] = ""; +$text['label-version']['de-at'] = ""; + +$text['label-git_info']['en-us'] = "Git Information"; +$text['label-git_info']['es-cl'] = ""; +$text['label-git_info']['pt-pt'] = ""; +$text['label-git_info']['fr-fr'] = ""; +$text['label-git_info']['pt-br'] = ""; +$text['label-git_info']['pl'] = ""; +$text['label-git_info']['sv-se'] = ""; +$text['label-git_info']['uk'] = ""; +$text['label-git_info']['de-at'] = ""; + +$text['label-switch_version']['en-us'] = "Switch Version"; +$text['label-switch_version']['es-cl'] = ""; +$text['label-switch_version']['pt-pt'] = ""; +$text['label-switch_version']['fr-fr'] = ""; +$text['label-switch_version']['pt-br'] = ""; +$text['label-switch_version']['pl'] = ""; +$text['label-switch_version']['sv-se'] = ""; +$text['label-switch_version']['uk'] = ""; +$text['label-switch_version']['de-at'] = ""; + +$text['label-git_branch']['en-us'] = "Branch:"; +$text['label-git_branch']['es-cl'] = ""; +$text['label-git_branch']['pt-pt'] = ""; +$text['label-git_branch']['fr-fr'] = ""; +$text['label-git_branch']['pt-br'] = ""; +$text['label-git_branch']['pl'] = ""; +$text['label-git_branch']['sv-se'] = ""; +$text['label-git_branch']['uk'] = ""; +$text['label-git_branch']['de-at'] = ""; + +$text['label-git_commit']['en-us'] = "Commit:"; +$text['label-git_commit']['es-cl'] = ""; +$text['label-git_commit']['pt-pt'] = ""; +$text['label-git_commit']['fr-fr'] = ""; +$text['label-git_commit']['pt-br'] = ""; +$text['label-git_commit']['pl'] = ""; +$text['label-git_commit']['sv-se'] = ""; +$text['label-git_commit']['uk'] = ""; +$text['label-git_commit']['de-at'] = ""; + +$text['label-git_origin']['en-us'] = "Origin:"; +$text['label-git_origin']['es-cl'] = ""; +$text['label-git_origin']['pt-pt'] = ""; +$text['label-git_origin']['fr-fr'] = ""; +$text['label-git_origin']['pt-br'] = ""; +$text['label-git_origin']['pl'] = ""; +$text['label-git_origin']['sv-se'] = ""; +$text['label-git_origin']['uk'] = ""; +$text['label-git_origin']['de-at'] = ""; + $text['label-memcache_status']['en-us'] = "Memcache Status"; $text['label-memcache_status']['es-cl'] = "Estado de Memcache"; $text['label-memcache_status']['pt-pt'] = "Estado da Memcache"; diff --git a/app/system/system.php b/app/system/system.php index eb77d27d99..9129f39707 100644 --- a/app/system/system.php +++ b/app/system/system.php @@ -78,13 +78,47 @@ $document['title'] = $text['title-sys-status']; if (permission_exists('system_view_info')) { echo "\n"; echo " \n"; - echo " Version\n"; + echo " ".$text['label-version']."\n"; echo " \n"; echo " \n"; echo " ".software_version()."\n"; echo " \n"; echo "\n"; + $git_path = normalize_path_to_os($_SERVER["DOCUMENT_ROOT"]."/.git"); + if(file_exists($git_path)){ + $git_branch = shell_exec('git --git-dir='.$git_path.' name-rev --name-only HEAD'); + rtrim($git_branch); + $git_commit = shell_exec('git --git-dir='.$git_path.' rev-parse HEAD'); + rtrim($git_commit); + $git_origin = shell_exec('git --git-dir='.$git_path.' config --get remote.origin.url'); + rtrim($git_commit); + echo "\n"; + echo " \n"; + echo " ".$text['label-git_info']."\n"; + echo " \n"; + echo " \n"; + echo " ".$text['label-git_branch']." ".$git_branch."
\n"; + echo " ".$text['label-git_commit']." ".$git_commit."
\n"; + echo " ".$text['label-git_origin']." ".$git_origin."
\n"; + echo " \n"; + echo "\n"; + } + + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $switch_version = event_socket_request($fp, 'api version'); + preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(\s*(\d+\w+)\s*\)/", $switch_version, $matches); + $switch_version = $matches[1]; + $switch_bits = $matches[2]; + echo "\n"; + echo " \n"; + echo " ".$text['label-switch_version']."\n"; + echo " \n"; + echo " $switch_version ($switch_bits)\n"; + echo "\n"; + } + echo "\n"; @@ -320,37 +354,37 @@ $document['title'] = $text['title-sys-status']; echo " ".$text['title-memcache']."\n"; echo " \n"; - $mc_fail = false; + $memcache_fail = false; $mod = new modules; if ($mod -> active("mod_memcache")) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "memcache status verbose"; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); - $mc_lines = preg_split('/\n/', $switch_result); - foreach($mc_lines as $mc_line) { - if (strlen(trim($mc_line)) > 0 && substr_count($mc_line, ': ') > 0) { - $mc_temp = explode(': ', $mc_line); - $mc_status[$mc_temp[0]] = $mc_temp[1]; + $memcache_lines = preg_split('/\n/', $switch_result); + foreach($memcache_lines as $memcache_line) { + if (strlen(trim($memcache_line)) > 0 && substr_count($memcache_line, ': ') > 0) { + $memcache_temp = explode(': ', $memcache_line); + $memcache_status[$memcache_temp[0]] = $memcache_temp[1]; } } - if (is_array($mc_status) && sizeof($mc_status) > 0) { - foreach($mc_status as $mc_field => $mc_value) { + if (is_array($memcache_status) && sizeof($memcache_status) > 0) { + foreach($memcache_status as $memcache_field => $memcache_value) { echo "\n"; - echo " ".$mc_field."\n"; - echo " ".$mc_value."\n"; + echo " ".$memcache_field."\n"; + echo " ".$memcache_value."\n"; echo "\n"; } } - else { $mc_fail = true; } + else { $memcache_fail = true; } } - else { $mc_fail = true; } + else { $memcache_fail = true; } } - else { $mc_fail = true; } + else { $memcache_fail = true; } - if ($mc_fail) { + if ($memcache_fail) { echo "\n"; echo " ".$text['label-memcache_status']."\n"; echo " ".$text['message-unavailable']."\n"; diff --git a/app/time_conditions/time_condition_edit.php b/app/time_conditions/time_condition_edit.php index f3e70b9f77..1a3178ddcb 100644 --- a/app/time_conditions/time_condition_edit.php +++ b/app/time_conditions/time_condition_edit.php @@ -860,7 +860,7 @@ function add_custom_condition($destination, $group_id, $dialplan_action = '') { echo " ".$text['label-group']."\n"; echo " "; echo " "; - echo " "; + echo " "; //$destination = new destinations; echo $destination->select('dialplan', 'dialplan_action['.$group_id.']', $dialplan_action); echo " "; diff --git a/app/vars/app_defaults.php b/app/vars/app_defaults.php index 96309fd365..1a0c840845 100644 --- a/app/vars/app_defaults.php +++ b/app/vars/app_defaults.php @@ -43,12 +43,34 @@ $vars = <<=2;+=.1;%(1400,0,350,440)","var_cat":"Defaults","var_enabled":"true","var_description":""}, {"var_name":"sit","var_value":"%(274,0,913.8);%(274,0,1370.6);%(380,0,1776.7)","var_cat":"Defaults","var_enabled":"true","var_description":""}, {"var_name":"sip_tls_version","var_value":"tlsv1","var_cat":"SIP","var_enabled":"true","var_description":"U0lQIGFuZCBUTFMgc2V0dGluZ3Mu"}, @@ -56,12 +78,12 @@ $vars = <<prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + + if ($row['num_rows'] == 0) { + $sql = "insert into v_vars "; + $sql .= "("; + $sql .= "var_uuid, "; + $sql .= "var_name, "; + $sql .= "var_value, "; + $sql .= "var_cat, "; + $sql .= "var_enabled, "; + $sql .= "var_order, "; + $sql .= "var_description "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'default_country', "; + $sql .= "'".$country["isocode"]."', "; + $sql .= "'Defaults', "; + $sql .= "'true', "; + $sql .= "'".$x."', "; + $sql .= "'' "; + $sql .= ");"; + $db->exec(check_sql($sql)); + unset($sql, $row); + $x++; + } } - } - - if ( !$found ) { - return; - } - - // Set default Country ISO code - $sql = "select count(*) as num_rows from v_vars "; - $sql .= "where var_name = 'default_country' "; - $sql .= "and var_cat = 'Defaults' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - - if ($row['num_rows'] == 0) { - $sql = "insert into v_vars "; - $sql .= "("; - $sql .= "var_uuid, "; - $sql .= "var_name, "; - $sql .= "var_value, "; - $sql .= "var_cat, "; - $sql .= "var_enabled, "; - $sql .= "var_order, "; - $sql .= "var_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'default_country', "; - $sql .= "'".$country["isocode"]."', "; - $sql .= "'Defaults', "; - $sql .= "'true', "; - $sql .= "'".$x."', "; - $sql .= "'' "; - $sql .= ");"; - $db->exec(check_sql($sql)); - unset($sql, $row); - $x++; + unset($prep_statement, $sql); + + // Set default Country code + $sql = "select count(*) as num_rows from v_vars "; + $sql .= "where var_name = 'default_countrycode' "; + $sql .= "and var_cat = 'Defaults' "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + $sql = "insert into v_vars "; + $sql .= "("; + $sql .= "var_uuid, "; + $sql .= "var_name, "; + $sql .= "var_value, "; + $sql .= "var_cat, "; + $sql .= "var_enabled, "; + $sql .= "var_order, "; + $sql .= "var_description "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'default_countrycode', "; + $sql .= "'".$country["countrycode"]."', "; + $sql .= "'Defaults', "; + $sql .= "'true', "; + $sql .= "'".$x."', "; + $sql .= "'' "; + $sql .= ");"; + $db->exec(check_sql($sql)); + unset($sql, $row); + $x++; + } } - } - unset($prep_statement, $sql); - - // Set default Country code - $sql = "select count(*) as num_rows from v_vars "; - $sql .= "where var_name = 'default_countrycode' "; - $sql .= "and var_cat = 'Defaults' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $sql = "insert into v_vars "; - $sql .= "("; - $sql .= "var_uuid, "; - $sql .= "var_name, "; - $sql .= "var_value, "; - $sql .= "var_cat, "; - $sql .= "var_enabled, "; - $sql .= "var_order, "; - $sql .= "var_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'default_countrycode', "; - $sql .= "'".$country["countrycode"]."', "; - $sql .= "'Defaults', "; - $sql .= "'true', "; - $sql .= "'".$x."', "; - $sql .= "'' "; - $sql .= ");"; - $db->exec(check_sql($sql)); - unset($sql, $row); - $x++; + unset($prep_statement, $sql); + + // Set default International Direct Dialing code + $sql = "select count(*) as num_rows from v_vars "; + $sql .= "where var_name = 'default_exitcode' "; + $sql .= "and var_cat = 'Defaults' "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + $sql = "insert into v_vars "; + $sql .= "("; + $sql .= "var_uuid, "; + $sql .= "var_name, "; + $sql .= "var_value, "; + $sql .= "var_cat, "; + $sql .= "var_enabled, "; + $sql .= "var_order, "; + $sql .= "var_description "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'default_exitcode', "; + $sql .= "'".$country["exitcode"]."', "; + $sql .= "'Defaults', "; + $sql .= "'true', "; + $sql .= "'".$x."', "; + $sql .= "'' "; + $sql .= ");"; + $db->exec(check_sql($sql)); + unset($sql, $row); + $x++; + } } + unset($prep_statement, $sql); + + unset($countries); } - unset($prep_statement, $sql); - - // Set default International Direct Dialing code - $sql = "select count(*) as num_rows from v_vars "; - $sql .= "where var_name = 'default_exitcode' "; - $sql .= "and var_cat = 'Defaults' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $sql = "insert into v_vars "; - $sql .= "("; - $sql .= "var_uuid, "; - $sql .= "var_name, "; - $sql .= "var_value, "; - $sql .= "var_cat, "; - $sql .= "var_enabled, "; - $sql .= "var_order, "; - $sql .= "var_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'default_exitcode', "; - $sql .= "'".$country["exitcode"]."', "; - $sql .= "'Defaults', "; - $sql .= "'true', "; - $sql .= "'".$x."', "; - $sql .= "'' "; - $sql .= ");"; - $db->exec(check_sql($sql)); - unset($sql, $row); - $x++; - } - } - unset($prep_statement, $sql); - - unset($countries); } } diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index 4dfce90452..291389ff27 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -219,7 +219,7 @@ $database->fields['domain_name'] = $domain_name; //check whether a recording exists - $recording_relative_path = '/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; + $recording_relative_path = '/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; if (file_exists($_SESSION['switch']['recordings']['dir'].$recording_relative_path.'/'.$uuid.'.wav')) { $recording_file = $recording_relative_path.'/'.$uuid.'.wav'; } diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index a667148085..e3e076edf9 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -396,7 +396,7 @@ else { //handle recordings if (permission_exists('recording_play') || permission_exists('recording_download')) { - $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$path_mod.'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; + $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$path_mod.'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; $tmp_name = ''; if(!empty($row['recording_file']) && file_exists($row['recording_file'])){ $tmp_name=$row['recording_file']; diff --git a/app/xml_cdr/xml_cdr_delete.php b/app/xml_cdr/xml_cdr_delete.php index 16f8614357..be3de7ac6e 100644 --- a/app/xml_cdr/xml_cdr_delete.php +++ b/app/xml_cdr/xml_cdr_delete.php @@ -54,8 +54,8 @@ if (sizeof($_REQUEST) > 0) { $prep_statement->execute(); unset($sql, $prep_statement); //delete recording, if any - if ($recording_file_path[$index] != '' && file_exists($_SESSION['switch']['recordings']['dir'].base64_decode($recording_file_path[$index]))) { - @unlink($_SESSION['switch']['recordings']['dir'].base64_decode($recording_file_path[$index])); + if ($recording_file_path[$index] != '' && file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].base64_decode($recording_file_path[$index]))) { + @unlink($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].base64_decode($recording_file_path[$index])); } } } diff --git a/app/xml_cdr/xml_cdr_details.php b/app/xml_cdr/xml_cdr_details.php index aca8978688..af95603150 100644 --- a/app/xml_cdr/xml_cdr_details.php +++ b/app/xml_cdr/xml_cdr_details.php @@ -194,7 +194,7 @@ else { //echo " ".$language."\n"; //echo " ".$context."\n"; echo " "; - if (file_exists($_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) { + if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) { //echo " \n"; //echo " "; @@ -208,7 +208,7 @@ else { } echo " \n"; echo " "; - if (file_exists($_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) { + if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$uuid.'.wav')) { echo " \n"; echo $caller_id_number.' '; echo " "; @@ -276,7 +276,7 @@ else { if ($key == "bridge_uuid" || $key == "signal_bond") { echo " \n"; echo " ".$value." \n"; - $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; + $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; $tmp_name = ''; if (file_exists($tmp_dir.'/'.$value.'.wav')) { $tmp_name = $value.".wav"; @@ -290,12 +290,12 @@ else { elseif (file_exists($tmp_dir.'/'.$value.'_1.mp3')) { $tmp_name = $value."_1.mp3"; } - if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) { + if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) { echo " \n"; echo " play"; echo "  "; } - if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) { + if (strlen($tmp_name) > 0 && file_exists($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day.'/'.$tmp_name)) { echo " \n"; echo " download"; echo " "; diff --git a/core/app_languages.php b/core/app_languages.php new file mode 100644 index 0000000000..ebdcde1c04 --- /dev/null +++ b/core/app_languages.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index ea4d04d6c9..c6484cbd31 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -24,22 +24,6 @@ Mark J Crane */ -global $IS_WINDOWS; - -if ($IS_WINDOWS == null) { - if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } -} - -if (!function_exists('correct_path')) { - function correct_path($p) { - global $IS_WINDOWS; - if ($IS_WINDOWS) { - return str_replace('/', '\\', $p); - } - return $p; - } -} - //proccess this only one time if ($domains_processed == 1) { @@ -66,163 +50,5 @@ if ($domains_processed == 1) { unset($sql); } unset($prep_statement, $result); - - //replace the backslash with a forward slash - $db_path = str_replace("\\", "/", $db_path); - - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - //get the odbc information - $sql = "select count(*) as num_rows from v_databases "; - $sql .= "where database_driver = 'odbc' "; - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } - $prep_statement = $db->prepare($sql); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset($prep_statement); - if ($row['num_rows'] > 0) { - $odbc_num_rows = $row['num_rows']; - - $sql = "select * from v_databases "; - $sql .= "where database_driver = 'odbc' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $dsn_name = $row["database_name"]; - $dsn_username = $row["database_username"]; - $dsn_password = $row["database_password"]; - break; //limit to 1 row - } - unset ($prep_statement); - } - else { - $odbc_num_rows = '0'; - } - } - - //get the recordings directory - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $sql = "select * from v_default_settings "; - $sql .= "where default_setting_category = 'switch' "; - $sql .= "and default_setting_subcategory = 'recordings' "; - $sql .= "and default_setting_name = 'dir' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $recordings_dir = $row["default_setting_value"]; - } - unset($prep_statement, $result); - } - - //config.lua - if (is_dir("/etc/fusionpbx")){ - $config = "/etc/fusionpbx/config.lua"; - } elseif (is_dir("/usr/local/etc/fusionpbx")){ - $config = "/usr/local/etc/fusionpbx/config.lua"; - } - else { - $config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua"; - } - $fout = fopen($config,"w"); - $tmp = "\n"; - $tmp .= "--set the variables\n"; - if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { - $tmp .= correct_path(" sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['phrases']['dir']) > 0) { - $tmp .= correct_path(" phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['db']['dir']) > 0) { - $tmp .= correct_path(" database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $tmp .= correct_path(" recordings_dir = [[".$recordings_dir."]];\n"); - } - if (strlen($_SESSION['switch']['storage']['dir']) > 0) { - $tmp .= correct_path(" storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) { - $tmp .= correct_path(" voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n"); - } - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - $tmp .= correct_path(" scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n"); - } - $tmp .= correct_path(" php_dir = [[".PHP_BINDIR."]];\n"); - if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { - $tmp .= " php_bin = \"php.exe\";\n"; - } - else { - $tmp .= " php_bin = \"php\";\n"; - } - $tmp .= correct_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); - $tmp .= "\n"; - - if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) { - $tmp .= "--database information\n"; - $tmp .= " database = {}\n"; - $tmp .= " database[\"type\"] = \"".$db_type."\";\n"; - $tmp .= " database[\"name\"] = \"".$db_name."\";\n"; - $tmp .= correct_path(" database[\"path\"] = [[".$db_path."]];\n"); - - if (strlen($dsn_name) > 0) { - $tmp .= " database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; - $tmp .= " database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n"; - } - elseif ($db_type == "pgsql") { - if ($db_host == "localhost") { $db_host = "127.0.0.1"; } - $tmp .= " database[\"system\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=".$db_name." user=".$db_username." password=".$db_password." options='' application_name='".$db_name."'\";\n"; - $tmp .= " database[\"switch\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=freeswitch user=".$db_username." password=".$db_password." options='' application_name='freeswitch'\";\n"; - } - elseif ($db_type == "sqlite") { - $tmp .= " database[\"system\"] = \"sqlite://".$db_path."/".$db_name."\";\n"; - $tmp .= " database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n"; - } - elseif ($db_type == "mysql") { - $tmp .= " database[\"system\"] = \"\";\n"; - $tmp .= " database[\"switch\"] = \"\";\n"; - } - $tmp .= "\n"; - } - $tmp .= "--set defaults\n"; - $tmp .= " expire = {}\n"; - $tmp .= " expire[\"directory\"] = \"3600\";\n"; - $tmp .= " expire[\"dialplan\"] = \"3600\";\n"; - $tmp .= " expire[\"languages\"] = \"3600\";\n"; - $tmp .= " expire[\"sofia.conf\"] = \"3600\";\n"; - $tmp .= " expire[\"acl.conf\"] = \"3600\";\n"; - $tmp .= "\n"; - $tmp .= "--set xml_handler\n"; - $tmp .= " xml_handler = {}\n"; - $tmp .= " xml_handler[\"fs_path\"] = false;\n"; - $tmp .= "\n"; - $tmp .= "--set the debug options\n"; - $tmp .= " debug[\"params\"] = false;\n"; - $tmp .= " debug[\"sql\"] = false;\n"; - $tmp .= " debug[\"xml_request\"] = false;\n"; - $tmp .= " debug[\"xml_string\"] = false;\n"; - $tmp .= " debug[\"cache\"] = false;\n"; - $tmp .= "\n"; - $tmp .= "--additional info\n"; - $tmp .= " domain_count = ".count($_SESSION["domains"]).";\n"; - $tmp .= correct_path(" temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n"); - if (isset($_SESSION['domain']['dial_string']['text'])) { - $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; - } - $tmp .= "\n"; - $tmp .= "--include local.lua\n"; - $tmp .= " require(\"resources.functions.file_exists\");\n"; - $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; - $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; - $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; - $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; - $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; - $tmp .= " require(\"resources.local\");\n"; - $tmp .= " end\n"; - fwrite($fout, $tmp); - unset($tmp); - fclose($fout); - } } ?> \ No newline at end of file diff --git a/core/domain_settings/domain_delete.php b/core/domain_settings/domain_delete.php index e65af3bb40..7e544a963a 100644 --- a/core/domain_settings/domain_delete.php +++ b/core/domain_settings/domain_delete.php @@ -176,7 +176,7 @@ if (strlen($id) > 0) { //delete the recordings if (strlen($_SESSION['switch'][recordings]['dir']) > 0) { - system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$domain_name); + system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name); } //delete voicemail diff --git a/core/domain_settings/domain_edit.php b/core/domain_settings/domain_edit.php index a31abb390b..870a2c9ad9 100644 --- a/core/domain_settings/domain_edit.php +++ b/core/domain_settings/domain_edit.php @@ -234,8 +234,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { } // rename switch/recordings/[domain] (folder) - if ( isset($_SESSION['switch']['recordings']['dir']) ) { - $switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $_SESSION['switch']['recordings']['dir']); + if ( file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']) ) { + $switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']); if ( file_exists($switch_recordings_dir."/".$original_domain_name) ) { @rename($switch_recordings_dir."/".$original_domain_name, $switch_recordings_dir."/".$domain_name); // folder } diff --git a/core/install/app_config.php b/core/install/app_config.php new file mode 100644 index 0000000000..aa400f46cb --- /dev/null +++ b/core/install/app_config.php @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/core/install/app_languages.php b/core/install/app_languages.php new file mode 100644 index 0000000000..668e6dff7a --- /dev/null +++ b/core/install/app_languages.php @@ -0,0 +1,606 @@ + \ No newline at end of file diff --git a/core/install/app_menu.php b/core/install/app_menu.php new file mode 100644 index 0000000000..78831564c0 --- /dev/null +++ b/core/install/app_menu.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/core/install/index.php b/core/install/index.php new file mode 100644 index 0000000000..36d012f0f7 --- /dev/null +++ b/core/install/index.php @@ -0,0 +1,83 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Matthew Vale +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +//detect install state + +$first_time_install = true; +if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { + $first_time_install = false; +} elseif (file_exists("/etc/fusionpbx/config.php")) { + //linux + $first_time_install = false; +} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { + $first_time_install = false; +} + +if($first_time_install) { + header("Location: ".PROJECT_PATH."/core/install/install_first_time.php"); + exit; +} +require_once "resources/check_auth.php"; +if (!if_group("superadmin")) { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//includes and title + require_once "resources/header.php"; + $document['title'] = $text['title-install']; + + echo "".$text['header-install'].""; + echo "

"; + echo $text['description-install']; + echo "

"; + + echo "
\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "
\n"; + echo " "; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/core/install/install_first_time.php b/core/install/install_first_time.php new file mode 100644 index 0000000000..1b629de24b --- /dev/null +++ b/core/install/install_first_time.php @@ -0,0 +1,390 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2015 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Matthew Vale +*/ +require_once "root.php"; +require_once "resources/functions.php"; +require_once "resources/classes/text.php"; + +//initialize variables we are going to use + $event_host = ''; + $event_port = ''; + $event_password = ''; + $install_language = 'en-us'; + $admin_username = ''; + $admin_password = ''; + $install_default_country = 'US'; + $install_template_name = ''; + $domain_name = ''; + $db_type = ''; + $db_path = ''; + $db_host = ''; + $db_port = ''; + $db_name = ''; + $db_username = ''; + $db_password = ''; + $db_create = ''; + $db_create_username = ''; + $db_create_password = ''; + +//detect the iso country code from the locale +//TBD $locale = Locale::getDefault(); +$timezone = 'UTC'; +if (is_link('/etc/localtime')) { + // Mac OS X (and older Linuxes) + // /etc/localtime is a symlink to the + // timezone in /usr/share/zoneinfo. + $filename = readlink('/etc/localtime'); + if (strpos($filename, '/usr/share/zoneinfo/') === 0) { + $timezone = substr($filename, 20); + } +} elseif (file_exists('/etc/timezone')) { + // Ubuntu / Debian. + $data = file_get_contents('/etc/timezone'); + if ($data) { + $timezone = rtrim($data); + } +} elseif (file_exists('/etc/sysconfig/clock')) { + // RHEL / CentOS + $data = parse_ini_file('/etc/sysconfig/clock'); + if (!empty($data['ZONE'])) { + $timezone = $data['ZONE']; + } +} + +date_default_timezone_set($timezone); + +//detect install state +$first_time_install = true; +if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { + $first_time_install = false; +} elseif (file_exists("/etc/fusionpbx/config.php")) { + $first_time_install = false; +} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { + $first_time_install = false; +} + +if(!$first_time_install) { + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + if (!if_group("superadmin")) { + echo "access denied"; + exit; + } +} + +$install_step = ''; +$return_install_step = ''; + +if (count($_POST) > 0) { + $install_language = check_str($_POST["install_language"]); + $install_step = check_str($_POST["install_step"]); + $return_install_step = check_str($_POST["return_install_step"]); + if(isset($_POST["event_host"])){ + $event_host = check_str($_POST["event_host"]); + $event_port = check_str($_POST["event_port"]); + $event_password = check_str($_POST["event_password"]); + } + if(isset($_POST["db_type"])){ + $db_type = $_POST["db_type"]; + $admin_username = $_POST["admin_username"]; + $admin_password = $_POST["admin_password"]; + $install_default_country = $_POST["install_default_country"]; + $install_template_name = $_POST["install_template_name"]; + $domain_name = $_POST["domain_name"]; + } +} + +if(!$install_step) { $install_step = 'select_language'; } + + $_SESSION['domain']['language']['code'] = $install_language; + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set a default template + $default_template = 'enhanced'; + if (isset($_SESSION['domain']['template']['name']) and strlen($_SESSION['domain']['template']['name']) != 0) { + $default_template = $_SESSION['domain']['template']['name']; + } + +//set a default enviroment if first_time + if($first_time_install){ + //initialize some varibles to cut down on warnings + $_SESSION['message'] = ''; + $v_link_label_play = ''; + $v_link_label_pause = ''; + $default_login = 0; + $onload = ''; + } + +//get the contents of the template and save it to the template variable + $template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php'); + +//buffer the content + ob_end_clean(); //clean the buffer + ob_start(); + + $messages = array(); + if (!extension_loaded('PDO')) { + $messages[] = "PHP PDO was not detected. Please install it before proceeding"; + } + + echo "
\n"; + $msg = ''; + //make sure the includes directory is writable so the config.php file can be written. + if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/pdo.php")) { + $messages[] = "Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH." and its sub-directories are required during the install."; + } + //test for selinux + if (file_exists('/usr/sbin/getenforce')) { + $enforcing; + exec('getenforce', $enforcing); + if($enforcing[0] == 'Enforcing'){ + $messages[] = "SELinux is enabled and enforcing you must have a policy installed to let the webserver connect to the switch event socket
". + "You can use the following to find what ports are allowed
semanage port -l | grep '^http_port_t'
"; + } + } + //test for windows and non sqlite + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' and strlen($db_type) > 0 and $db_type !='sqlite') { + $messages[] = "Windows requires a system DSN ODBC connection this must be configured."; + } + + //action code + if($return_install_step == 'config_detail'){ + //check for all required data + $existing_errors = count($messages); + if (strlen($admin_username) == 0) { $messages[] = "Please provide the Admin Username"; } + if (strlen($admin_password) == 0) { $messages[] = "Please provide the Admin Password"; } + elseif (strlen($admin_password) < 5) { $messages[] = "Please provide an Admin Password that is 5 or more characters.
\n"; } + if ( count($messages) > $existing_errors) { $install_step = 'config_detail'; } + } + + if($install_step =='execute') + { + //start the rocket launch! + + //set the max execution time to 1 hour + ini_set('max_execution_time',3600); + } + + //display messages + if (count($messages)>0) { + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
Messages
    \n"; + foreach ($messages as $message){ + echo "
  • $message
  • \n"; + } + echo "
\n"; + echo "
\n"; + } + +//includes and title + $document['title'] = $text['title-install_first_time']; + + //view code + if($install_step == 'select_language'){ + include "resources/page_parts/install_select_language.php"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + }elseif($install_step == 'detect_config'){ + if(!($event_host == '' || $event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1' )){ + echo "

Warning you have choosen a value other than localhost for event_host, this is unsoported at present

\n"; + } + include "resources/page_parts/install_event_socket.php"; + if($detect_ok){ + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + }else{ + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + } + elseif($install_step == 'config_detail'){ + if(!$domain_name){ + //get the domain + $domain_array = explode(":", $_SERVER["HTTP_HOST"]); + $domain_name = $domain_array[0]; + } + include "resources/page_parts/install_config_detail.php"; + } + elseif($install_step == 'config_database'){ + include "resources/page_parts/install_config_database.php"; + } + elseif($install_step == 'execute'){ + echo "

".$text['header-installing']."

\n"; + //$protocol = 'http'; + //if($_SERVER['HTTPS']) { $protocol = 'https'; } + //echo ""; + require_once "core/install/resources/classes/detect_switch.php"; + $detect_switch = new detect_switch($event_host, $event_port, $event_password); + $detect_ok = true; + try { + $detect_switch->detect(); + } catch(Exception $e){ + echo "

Failed to detect configuration detect_switch reported: " . $e->getMessage() . "

\n"; + $detect_ok = false; + } + if($detect_ok){ + $install_ok = true; + echo "
\n";
+			function error_handler($err_severity, $errstr, $errfile, $errline ) {
+				if (0 === error_reporting()) { return false;}
+				switch($err_severity)
+				{
+					case E_ERROR:               throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_PARSE:               throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_CORE_ERROR:          throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_COMPILE_ERROR:       throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_USER_ERROR:          throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_STRICT:              throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_RECOVERABLE_ERROR:   throw new Exception ($errstr . " in $errfile line: $errline");
+					default: 					return false;
+				}
+			}
+			#set_error_handler("error_handler");
+			try {
+				require_once "resources/classes/global_settings.php";
+				$global_settings = new global_settings($detect_switch, $domain_name);
+				if(is_null($global_settings)){ throw new Exception("Error global_settings came back with null");	}
+				require_once "resources/classes/install_fusionpbx.php";
+				$system = new install_fusionpbx($global_settings);
+				$system->admin_username = $admin_username;
+				$system->admin_password = $admin_password;
+				$system->default_country = $install_default_country;
+				$system->install_language = $install_language;
+				$system->template_name = $install_template_name;
+
+				require_once "resources/classes/install_switch.php";
+				$switch = new install_switch($global_settings);
+				//$switch->debug = true;
+				//$system->debug = true;
+				$switch->echo_progress = true;
+				$system->echo_progress = true;
+				$system->install_phase_1();
+				$switch->install_phase_1();
+				$system->install_phase_2();
+				$switch->install_phase_2();
+			}catch(Exception $e){
+				echo "
\n"; + echo "

Failed to install
" . $e->getMessage() . "

\n"; + try { + require_once "resources/classes/install_fusionpbx.php"; + $system = new install_fusionpbx($global_settings); + $system->remove_config(); + }catch(Exception $e){ + echo "

Failed to remove config: " . $e->getMessage() . "

\n"; + } + $install_ok = false; + } + restore_error_handler(); + if($install_ok){ + echo "\n"; + header("Location: ".PROJECT_PATH."/logout.php"); + $_SESSION['message'] = 'Install complete'; + }else{ + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + } + }else{ + echo "

Unkown install_step '$install_step'

\n"; + } + +if($first_time_install){ + //grab the default theme + $set_session_theme = 1; + $domains_processed = 1; + include "themes/enhanced/app_defaults.php"; + unset($set_session_theme, $domains_processed); + //initialize some defaults so we can be 'logged in' + $_SESSION['username'] = 'first_time_install'; + $_SESSION['permissions'][]['permission_name'] = 'superadmin'; + $_SESSION['menu'] = ''; +} + +// add the content to the template and then send output + $body = ob_get_contents(); //get the output from the buffer + ob_end_clean(); //clean the buffer + + //replace known used constants + $body = str_replace ("", PROJECT_PATH, $body); //defined in /resources/menu.php + + ob_start(); + eval('?>' . $template . '", $document['title'], $template); // defined in each individual page + $output = str_replace ("", $custom_head, $output); // defined in each individual page + $output = str_replace ("", $_SESSION["menu"], $output); //defined in /resources/menu.php + $output = str_replace ("", PROJECT_PATH, $output); //defined in /resources/menu.php + + $pos = strrpos($output, ""); + if ($pos === false) { + $output = $body; //if tag not found just show the body + } + else { + //replace the body + $output = str_replace ("", $body, $output); + } + + echo $output; + unset($output); + +?> \ No newline at end of file diff --git a/core/install/resources/classes/detect_switch.php b/core/install/resources/classes/detect_switch.php new file mode 100644 index 0000000000..4245d5bc61 --- /dev/null +++ b/core/install/resources/classes/detect_switch.php @@ -0,0 +1,173 @@ + + Copyright (C) 2010-2015 + All Rights Reserved. + + Contributor(s): + Matthew Vale + +*/ +require_once "root.php"; +require_once "resources/classes/EventSocket.php"; + +//define the install class + class detect_switch { + + // cached data + protected $_dirs; + protected $_vdirs; + public function get_dirs() { return $this->_dirs; } + public function get_vdirs() { return $this->_vdirs; } + + // version information + protected $_major; + protected $_minor; + protected $_build; + public function major() { return $this->_major; } + public function minor() { return $this->_minor; } + public function build() { return $this->_build; } + public function version() { return $this->_major.".".$this->_minor.".".$this->_build; } + + // dirs - detected by from the switch + protected $_base_dir = ''; + protected $_cache_dir = ''; + protected $_certs_dir = ''; + protected $_conf_dir = ''; + protected $_db_dir = ''; + protected $_external_ssl_dir = ''; + protected $_grammar_dir = ''; + protected $_htdocs_dir = ''; + protected $_internal_ssl_dir = ''; + protected $_log_dir = ''; + protected $_mod_dir = ''; + protected $_recordings_dir = ''; + protected $_run_dir = ''; + protected $_script_dir = ''; + protected $_sounds_dir = ''; + protected $_storage_dir = ''; + protected $_temp_dir = ''; + public function base_dir() { return $this->_base_dir; } + public function cache_dir() { return $this->_cache_dir; } + public function certs_dir() { return $this->_certs_dir; } + public function conf_dir() { return $this->_conf_dir; } + public function db_dir() { return $this->_db_dir; } + public function external_ssl_dir() { return $this->_external_ssl_dir; } + public function grammar_dir() { return $this->_grammar_dir; } + public function htdocs_dir() { return $this->_htdocs_dir; } + public function internal_ssl_dir() { return $this->_internal_ssl_dir; } + public function log_dir() { return $this->_log_dir; } + public function mod_dir() { return $this->_mod_dir; } + public function recordings_dir() { return $this->_recordings_dir; } + public function run_dir() { return $this->_run_dir; } + public function script_dir() { return $this->_script_dir; } + public function sounds_dir() { return $this->_sounds_dir; } + public function storage_dir() { return $this->_storage_dir; } + public function temp_dir() { return $this->_temp_dir; } + + // virtual dirs - assumed based on the detected dirs + protected $_voicemail_vdir = ''; + protected $_phrases_vdir = ''; + protected $_extensions_vdir = ''; + protected $_sip_profiles_vdir = ''; + protected $_dialplan_vdir = ''; + protected $_backup_vdir = ''; + public function voicemail_vdir() { return $this->_voicemail_vdir; } + public function phrases_vdir() { return $this->_phrases_vdir; } + public function extensions_vdir() { return $this->_extensions_vdir; } + public function sip_profiles_vdir() { return $this->_sip_profiles_vdir; } + public function dialplan_vdir() { return $this->_dialplan_vdir; } + public function backup_vdir() { return $this->_backup_vdir; } + + // event socket + public $event_host = 'localhost'; + public $event_port = '8021'; + public $event_password = 'ClueCon'; + protected $event_socket; + + public function __construct($event_host, $event_port, $event_password) { + //do not take these settings from session as they be detecting a new switch + if($event_host){ $this->event_host = $event_host; } + if($event_port){ $this->event_port = $event_port; } + if($event_password){ $this->event_password = $event_password; } + $this->connect_event_socket(); + if(!$this->event_socket){ + $this->detect_event_socket(); + } + $this->_dirs = preg_grep ('/.*_dir$/', get_class_methods('detect_switch') ); + sort( $this->_dirs ); + $this->_vdirs = preg_grep ('/.*_vdir$/', get_class_methods('detect_switch') ); + sort( $this->_vdirs ); + } + + protected function detect_event_socket() { + //perform searches for user's config here + } + + public function detect() { + $this->connect_event_socket(); + if(!$this->event_socket){ + throw new Exception('Failed to use event socket'); + } + $FS_Version = $this->event_socket_request('api version'); + preg_match("/FreeSWITCH Version (\d+)\.(\d+)\.(\d+(?:\.\d+)?)/", $FS_Version, $matches); + $this->_major = $matches[1]; + $this->_minor = $matches[2]; + $this->_build = $matches[3]; + $FS_Vars = $this->event_socket_request('api global_getvar'); + foreach (explode("\n",$FS_Vars) as $FS_Var){ + preg_match("/(\w+_dir)=(.*)/", $FS_Var, $matches); + if(count($matches) > 0 and property_exists($this, "_" . $matches[1])){ + $field = "_" . $matches[1]; + $this->$field = normalize_path($matches[2]); + } + } + $this->_voicemail_vdir = normalize_path($this->_storage_dir . DIRECTORY_SEPARATOR . "voicemail"); + $this->_phrases_vdir = normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "lang"); + $this->_extensions_vdir = normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "directory"); + $this->_sip_profiles_vdir = normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "sip_profiles"); + $this->_dialplan_vdir = normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "dialplan"); + $this->_backup_vdir = normalize_path(sys_get_temp_dir()); + } + + protected function connect_event_socket(){ + $esl = new EventSocket; + if ($esl->connect($this->event_host, $this->event_port, $this->event_password)) { + $this->event_socket = $esl->reset_fp(); + return true; + } + return false; + } + + protected function event_socket_request($cmd) { + $esl = new EventSocket($this->event_socket); + $result = $esl->request($cmd); + $esl->reset_fp(); + return $result; + } + + public function restart_switch() { + $this->connect_event_socket(); + if(!$this->event_socket){ + throw new Exception('Failed to use event socket'); + } + $this->event_socket_request('api fsctl shutdown restart elegant'); + } + } +?> \ No newline at end of file diff --git a/core/install/resources/classes/global_settings.php b/core/install/resources/classes/global_settings.php new file mode 100644 index 0000000000..8d10cfd716 --- /dev/null +++ b/core/install/resources/classes/global_settings.php @@ -0,0 +1,223 @@ + + Copyright (C) 2010-2015 + All Rights Reserved. + + Contributor(s): + Matthew Vale + +*/ +require_once "root.php"; + +//define the install class + class global_settings { + + // cached data + protected $_switch_dirs; + protected $_switch_vdirs; + public function get_switch_dirs() { return $this->_switch_dirs; } + public function get_switch_vdirs() { return $this->_switch_vdirs; } + + // dirs - detected from the switch + protected $_switch_base_dir = ''; + protected $_switch_cache_dir = ''; + protected $_switch_certs_dir = ''; + protected $_switch_conf_dir = ''; + protected $_switch_db_dir = ''; + protected $_switch_external_ssl_dir = ''; + protected $_switch_grammar_dir = ''; + protected $_switch_htdocs_dir = ''; + protected $_switch_internal_ssl_dir = ''; + protected $_switch_log_dir = ''; + protected $_switch_mod_dir = ''; + protected $_switch_recordings_dir = ''; + protected $_switch_run_dir = ''; + protected $_switch_script_dir = ''; + protected $_switch_sounds_dir = ''; + protected $_switch_storage_dir = ''; + protected $_switch_temp_dir = ''; + public function switch_base_dir() { return $this->_switch_base_dir; } + public function switch_cache_dir() { return $this->_switch_cache_dir; } + public function switch_certs_dir() { return $this->_switch_certs_dir; } + public function switch_conf_dir() { return $this->_switch_conf_dir; } + public function switch_db_dir() { return $this->_switch_db_dir; } + public function switch_external_ssl_dir() { return $this->_switch_external_ssl_dir; } + public function switch_grammar_dir() { return $this->_switch_grammar_dir; } + public function switch_htdocs_dir() { return $this->_switch_htdocs_dir; } + public function switch_internal_ssl_dir() { return $this->_switch_internal_ssl_dir; } + public function switch_log_dir() { return $this->_switch_log_dir; } + public function switch_mod_dir() { return $this->_switch_mod_dir; } + public function switch_recordings_dir() { return $this->_switch_recordings_dir; } + public function switch_run_dir() { return $this->_switch_run_dir; } + public function switch_script_dir() { return $this->_switch_script_dir; } + public function switch_sounds_dir() { return $this->_switch_sounds_dir; } + public function switch_storage_dir() { return $this->_switch_storage_dir; } + public function switch_temp_dir() { return $this->_switch_temp_dir; } + + // virtual dirs - assumed based on the detected dirs + protected $_switch_voicemail_vdir = ''; + protected $_switch_phrases_vdir = ''; + protected $_switch_extensions_vdir = ''; + protected $_switch_sip_profiles_vdir = ''; + protected $_switch_dialplan_vdir = ''; + protected $_switch_backup_vdir = ''; + public function switch_voicemail_vdir() { return $this->_switch_voicemail_vdir; } + public function switch_phrases_vdir() { return $this->_switch_phrases_vdir; } + public function switch_extensions_vdir() { return $this->_switch_extensions_vdir; } + public function switch_sip_profiles_vdir() { return $this->_switch_sip_profiles_vdir; } + public function switch_dialplan_vdir() { return $this->_switch_dialplan_vdir; } + public function switch_backup_vdir() { return $this->_switch_backup_vdir; } + + // event socket + protected $_switch_event_host; + protected $_switch_event_port; + protected $_switch_event_password; + public function switch_event_host() { return $this->_switch_event_host; } + public function switch_event_port() { return $this->_switch_event_port; } + public function switch_event_password() { return $this->_switch_event_password; } + + // database information + protected $_db_type; + protected $_db_path; + protected $_db_host; + protected $_db_port; + protected $_db_name; + protected $_db_username; + protected $_db_password; + protected $_db_create; + protected $_db_create_username; + protected $_db_create_password; + public function db_type() { return $this->_db_type; } + public function db_path() { return $this->_db_path; } + public function db_host() { return $this->_db_host; } + public function db_port() { return $this->_db_port; } + public function db_name() { return $this->_db_name; } + public function db_username() { return $this->_db_username; } + public function db_password() { return $this->_db_password; } + public function db_create() { return $this->_db_create; } + public function db_create_username() { return $this->_db_create_username; } + public function db_create_password() { return $this->_db_create_password; } + + //misc information + protected $_domain_uuid; + protected $_domain_name; + protected $_domain_count; + public function domain_uuid() { return $this->_domain_uuid; } + public function domain_name() { return $this->_domain_name; } + public function domain_count() { return $this->_domain_count; } + public function set_domain_uuid($domain_uuid) { + $e = new Exception(); + $trace = $e->getTrace(); + if($trace[1]['function'] != 'create_domain'){ + throw new Exception('Only create_domain is allowed to update the domain_uuid'); + } + $this->_domain_uuid = $domain_uuid; + } + + public function __construct($detect_switch = null, $domain_name = null, $domain_uuid = null) { + $this->_switch_dirs = preg_grep ('/^switch_.*_dir$/', get_class_methods('global_settings') ); + sort( $this->_switch_dirs ); + $this->_switch_vdirs = preg_grep ('/^switch_.*_vdir$/', get_class_methods('global_settings') ); + sort( $this->_switch_vdirs ); + if(is_null($detect_switch)){ + //take settings from session + if(!isset($_SESSION['switch'])){ + throw new Exception("No detect_switch was passed to me but \$_SESSION['switch'] is empty!"); + } + foreach ($this->_switch_dirs as $dir){ + $category = 'switch'; + $session_var; + preg_match( '/^switch_(.*)_dir$/', $dir, $session_var); + $dir = "_$dir"; + if($session_var[1] == 'script'){ $session_var[1] = 'scripts'; } + if($session_var[1] == 'temp'){ $category = 'server'; } + $this->$dir = $_SESSION[$category][$session_var[1]]['dir']; + } + foreach ($this->_switch_vdirs as $vdir){ + $category = 'switch'; + $session_var; + preg_match( '/^switch_(.*)_vdir$/', $vdir, $session_var); + $vdir = "_$vdir"; + if($session_var[1] == 'backup'){ $category = 'server'; } + $this->$vdir = $_SESSION[$category][$session_var[1]]['dir']; + } + $this->_switch_event_host = $_SESSION['event_socket_ip_address']; + $this->_switch_event_port = $_SESSION['event_socket_port']; + $this->_switch_event_password = $_SESSION['event_socket_password']; + + // domain info + $this->_domain_name = $_SESSION['domain_name']; + $this->_domain_uuid = $_SESSION['domain_uuid']; + + // collect misc info + $this->_domain_count = count($_SESSION["domains"]); + + // collect db_info + global $db_type, $db_path, $db_host, $db_port, $db_name, $db_username, $db_password; + $this->_db_type = $db_type; + $this->_db_path = $db_path; + $this->_db_host = $db_host; + $this->_db_port = $db_port; + $this->_db_name = $db_name; + $this->_db_username = $db_username; + $this->_db_password = $db_password; + + }elseif(!is_a($detect_switch, 'detect_switch')){ + throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)'); + + }else{ + //copy from detect_switch + foreach($detect_switch->get_dirs() as $dir){ + $t_dir = "_switch_$dir"; + $this->$t_dir = $detect_switch->$dir(); + } + foreach($detect_switch->get_vdirs() as $vdir){ + $t_vdir = "_switch_$vdir"; + $this->$t_vdir = $detect_switch->$vdir(); + } + $this->_switch_event_host = $detect_switch->event_host; + $this->_switch_event_port = $detect_switch->event_port; + $this->_switch_event_password = $detect_switch->event_password; + + //copy from _POST + foreach($_POST as $key=>$value){ + if(substr($key,0,3) == "db_"){ + $o_key = "_$key"; + $this->$o_key = $value; + } + } + if($this->_db_create and strlen($this->_db_create_username) == 0) + { + $this->_db_create_username = $this->_db_username; + $this->_db_create_password = $this->_db_password; + } + if (strlen($this->_db_port) == 0) { $this->_db_port = "5432"; } + + // domain info + if(strlen($domain_uuid) == 0){ $domain_uuid = uuid(); } + $this->_domain_name = $domain_name; + $this->_domain_uuid = $domain_uuid; + + //collect misc info + $this->_domain_count = 1; //assumed to be one + } + } + } +?> \ No newline at end of file diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php new file mode 100644 index 0000000000..41d28ca92c --- /dev/null +++ b/core/install/resources/classes/install_fusionpbx.php @@ -0,0 +1,1124 @@ + + Copyright (C) 2010-2015 + All Rights Reserved. + + Contributor(s): + Mark J Crane + Matthew Vale +*/ +include "root.php"; + +//define the install class + class install_fusionpbx { + + protected $global_settings; + protected $config_php; + protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286'; + protected $dbh; + + public $debug = false; + public $echo_progress = false; + + public $install_language = 'en-us'; + public $admin_username; + public $admin_password; + public $default_country = 'US'; + public $template_name = 'enhanced'; + + function __construct($global_settings) { + if(is_null($global_settings)){ + require_once "resources/classes/global_settings.php"; + $global_settings = new global_settings(); + }elseif(!is_a($global_settings, 'global_settings')){ + throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)'); + } + $this->global_settings = $global_settings; + if (is_dir("/etc/fusionpbx")){ + $this->config_php = "/etc/fusionpbx/config.php"; + } elseif (is_dir("/usr/local/etc/fusionpbx")){ + $this->config_php = "/usr/local/etc/fusionpbx/config.php"; + } + elseif (is_dir($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources")) { + $this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php"; + } + else { + $this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php"; + } + $this->config_php = normalize_path_to_os($this->config_php); + } + + function write_debug($message) { + if($this->debug){ + echo "$message\n"; + } + } + + function write_progress($message) { + if($this->echo_progress){ + echo "$message\n"; + } + } + + function install_phase_1() { + ini_set('max_execution_time',3600); + $this->write_progress("Install phase 1 started for FusionPBX"); + $this->create_config_php(); + $this->write_progress("\tExecuting config.php"); + require $this->config_php; + global $db; + $db = $this->dbh; + $this->create_database(); + $this->create_domain(); + $this->create_superuser(); + $this->write_progress("\tRunning requires"); + require "resources/require.php"; + $this->create_menus(); + $this->write_progress("Install phase 1 complete for FusionPBX"); + } + + function install_phase_2() { + ini_set('max_execution_time',3600); + $this->write_progress("Install phase 2 started for FusionPBX"); + $this->app_defaults(); + $this->write_progress("Install phase 2 complete for FusionPBX"); + } + + function upgrade() { + $this->app_defaults(); + } + + protected function create_config_php() { + $this->write_progress("\tCreating " . $this->config_php); + $tmp_config = "global_settings->db_type()."'; //sqlite, mysql, pgsql, others with a manually created PDO connection\n"; + $tmp_config .= "\n"; + if ($this->global_settings->db_type() == "sqlite") { + $tmp_config .= " //sqlite: the db_name and db_path are automatically assigned however the values can be overidden by setting the values here.\n"; + $tmp_config .= " \$db_name = '".$this->global_settings->db_name()."'; //host name/ip address + '.db' is the default database filename\n"; + $tmp_config .= " \$db_path = '".$this->global_settings->db_path()."'; //the path is determined by a php variable\n"; + } + $tmp_config .= "\n"; + $tmp_config .= " //mysql: database connection information\n"; + if ($this->global_settings->db_type() == "mysql") { + $db_host = $this->global_settings->db_host(); + if ( $db_host == "localhost") { + //if localhost is used it defaults to a Unix Socket which doesn't seem to work. + //replace localhost with 127.0.0.1 so that it will connect using TCP + $db_host = "127.0.0.1"; + } + $tmp_config .= " \$db_host = '".$db_host."';\n"; + $tmp_config .= " \$db_port = '".$this->global_settings->db_port()."';\n"; + $tmp_config .= " \$db_name = '".$this->global_settings->db_name()."';\n"; + $tmp_config .= " \$db_username = '".$this->global_settings->db_username()."';\n"; + $tmp_config .= " \$db_password = '".$this->global_settings->db_password()."';\n"; + } + else { + $tmp_config .= " //\$db_host = '';\n"; + $tmp_config .= " //\$db_port = '';\n"; + $tmp_config .= " //\$db_name = '';\n"; + $tmp_config .= " //\$db_username = '';\n"; + $tmp_config .= " //\$db_password = '';\n"; + } + $tmp_config .= "\n"; + $tmp_config .= " //pgsql: database connection information\n"; + if ($this->global_settings->db_type() == "pgsql") { + $cmt_out = ''; + if($this->global_settings->db_host() != 'localhost') { $cmt_out = "//"; } + $tmp_config .= " $cmt_out\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n"; + $tmp_config .= " \$db_port = '".$this->global_settings->db_port()."';\n"; + $tmp_config .= " \$db_name = '".$this->global_settings->db_name()."';\n"; + $tmp_config .= " \$db_username = '".$this->global_settings->db_username()."';\n"; + $tmp_config .= " \$db_password = '".$this->global_settings->db_password()."';\n"; + } + else { + $tmp_config .= " //\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n"; + $tmp_config .= " //\$db_port = '".$this->global_settings->db_port()."';\n"; + $tmp_config .= " //\$db_name = '".$this->global_settings->db_name()."';\n"; + $tmp_config .= " //\$db_username = '".$this->global_settings->db_username()."';\n"; + $tmp_config .= " //\$db_password = '".$this->global_settings->db_password()."';\n"; + } + $tmp_config .= "\n"; + $tmp_config .= " //show errors\n"; + $tmp_config .= " ini_set('display_errors', '1');\n"; + $tmp_config .= " //error_reporting (E_ALL); // Report everything\n"; + $tmp_config .= " //error_reporting (E_ALL ^ E_NOTICE); // Report everything\n"; + $tmp_config .= " error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings"; + $tmp_config .= "\n"; + $tmp_config .= "?>"; + + if((file_exists($this->config_php) + and !is_writable($this->config_php)) + or !is_writable(dirname($this->config_php)) + ) { + throw new Exception("cannot write to '" . $this->config_php . "'" ); + } + $fout = fopen($this->config_php,"w"); + fwrite($fout, $tmp_config); + unset($tmp_config); + fclose($fout); + } + + protected function create_database() { + $this->write_progress("\tUsing database as type " . $this->global_settings->db_type()); + $function = "create_database_" . $this->global_settings->db_type(); + $this->$function(); + + //sqlite is natively supported under all known OS'es + if($this->global_settings->db_type() != 'sqlite'){ + if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){ + //non sqlite database support only uses ODBC under windows + $this->create_odbc_database_connection(); + }elseif($this->global_settings->db_type() != 'pgsql'){ + //switch supports postgresql natively + $this->create_odbc_database_connection(); + } + } + } + + protected function create_odbc_database_connection() { + //needed for non native database support + $database_uuid = uuid(); + $sql = "insert into v_databases "; + $sql .= "("; + $sql .= "database_uuid, "; + $sql .= "database_driver, "; + $sql .= "database_type, "; + $sql .= "database_host, "; + $sql .= "database_port, "; + $sql .= "database_name, "; + $sql .= "database_username, "; + $sql .= "database_password, "; + $sql .= "database_path, "; + $sql .= "database_description "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'$database_uuid', "; + $sql .= "'odbc', "; + $sql .= "'".$this->global_settings->db_type()."', "; + $sql .= "'".$this->global_settings->db_host()."', "; + $sql .= "'".$this->global_settings->db_port()."', "; + $sql .= "'".$this->global_settings->db_name()."', "; + $sql .= "'".$this->global_settings->db_username()."', "; + $sql .= "'".$this->global_settings->db_password()."', "; + $sql .= "'".$this->global_settings->db_path()."', "; + $sql .= "'Created by installer' "; + $sql .= ")"; + if($this->dbh->exec(check_sql($sql)) === false){ + throw new Exception("Failed to create odbc_database entery: " . join(":", $this->dbh->errorInfo())); + } + unset($sql); + } + + protected function create_database_sqlite() { + //sqlite database will be created when the config.php is loaded and only if the database file does not exist + try { + $this->dbh = new PDO('sqlite:'.$this->global_settings->db_path().'/'.$this->global_settings->db_name()); //sqlite 3 + //$this->dbh = new PDO('sqlite::memory:'); //sqlite 3 + } + catch (PDOException $error) { + throw Exception("Failed to create database: " . $error->getMessage()); + } + + //add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] ) + if (!function_exists('php_now')) { + function php_now() { + if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) { + @date_default_timezone_set(@date_default_timezone_get()); + } + return date("Y-m-d H:i:s"); + } + } + $this->dbh->sqliteCreateFunction('now', 'php_now', 0); + + //add the database structure + require_once "resources/classes/schema.php"; + $schema = new schema; + $schema->db = $this->dbh; + $schema->db_type = $this->global_settings->db_type(); + $schema->sql(); + $schema->exec(); + + //get the contents of the sql file + if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){ + $filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql"; + } + else { + $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql'; + } + $file_contents = file_get_contents($filename); + unset($filename); + + //replace \r\n with \n then explode on \n + $file_contents = str_replace("\r\n", "\n", $file_contents); + + //loop line by line through all the lines of sql code + $this->dbh->beginTransaction(); + $string_array = explode("\n", $file_contents); + $x = 0; + foreach($string_array as $sql) { + try { + $this->dbh->query($sql); + } + catch (PDOException $error) { + throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql ); + } + $x++; + } + unset ($file_contents, $sql); + $this->dbh->commit(); + + //set the file permissions + chmod($this->global_settings->db_path().'/'.$this->global_settings->db_name(), 0777); + } + + protected function create_database_pgsql() { + if ($this->global_settings->db_create()) { + //Attempt to create new PG role and database + $this->write_progress("\tCreating database"); + try { + if (strlen($this->global_settings->db_host()) > 0) { + $this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1"); + } else { + $this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1"); + } + } catch (PDOException $error) { + throw new Exception("error connecting to database in order to create: " . $error->getMessage()); + } + + //create the database, user, grant perms + if($this->dbh->exec("CREATE DATABASE {$this->global_settings->db_name()}") === false) { + throw new Exception("Failed to create database {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo())); + } + if($this->global_settings->db_username() != $this->global_settings->db_create_username()){ + if($this->dbh->exec("CREATE USER {$this->global_settings->db_username()} WITH PASSWORD '{$this->global_settings->db_password()}'") === false){ + throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo())); + } + if($this->dbh->exec("GRANT ALL ON {$this->global_settings->db_name()} TO {$this->global_settings->db_username()}") === false){ + throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo())); + } + } + + //close database connection_aborted + $this->dbh = null; + } + + $this->write_progress("\tInstalling data to database"); + //open database connection with $this->global_settings->db_name() + try { + if (strlen($this->global_settings->db_host()) > 0) { + $this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} dbname={$this->global_settings->db_name()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()}"); + } else { + $this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()} dbname={$this->global_settings->db_name()}"); + } + } + catch (PDOException $error) { + throw new Exception("error connecting to database: " . $error->getMessage()); + } + + + //add the database structure + require_once "resources/classes/schema.php"; + $schema = new schema; + $schema->db = $this->dbh; + $schema->db_type = $this->global_settings->db_type(); + $schema->sql(); + $schema->exec(); + + //get the contents of the sql file + if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){ + $filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql"; + } + else { + $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql'; + } + $file_contents = file_get_contents($filename); + + //replace \r\n with \n then explode on \n + $file_contents = str_replace("\r\n", "\n", $file_contents); + + //loop line by line through all the lines of sql code + $string_array = explode("\n", $file_contents); + $x = 0; + foreach($string_array as $sql) { + if (strlen($sql) > 3) { + try { + $this->dbh->query($sql); + } + catch (PDOException $error) { + throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql ); + } + } + $x++; + } + unset ($file_contents, $sql); + } + + protected function create_database_mysql() { + //database connection + $connect_string; + if (strlen($this->global_settings->db_host()) == 0 && strlen($this->global_settings->db_port()) == 0) { + //if both host and port are empty use the unix socket + $connect_string = "mysql:host=$this->global_settings->db_host();unix_socket=/var/run/mysqld/mysqld.sock;"; + } + elseif (strlen($this->global_settings->db_port()) == 0) { + //leave out port if it is empty + $connect_string = "mysql:host=$this->global_settings->db_host();"; + } + else { + $connect_string = "mysql:host=$this->global_settings->db_host();port=$this->global_settings->db_port();"; + } + + //create the table, user and set the permissions only if the db_create_username was provided + if ($this->global_settings->db_create()) { + $this->write_progress("\tCreating database"); + try { + $this->dbh = new PDO($connect_string, $this->global_settings->db_create_username(), db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); + $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + } + catch (PDOException $error) { + throw new Exception("error connecting to database for ccreate: " . $error->getMessage() . "\n" . $sql ); + } + //select the mysql database + try { + $this->dbh->query("USE mysql;"); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //create user and set the permissions + try { + $tmp_sql = "CREATE USER '".$this->global_settings->db_username()."'@'%' IDENTIFIED BY '".$this->global_settings->db_password()."'; "; + $this->dbh->query($tmp_sql); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //set account to unlimited use + try { + if ($this->global_settings->db_host() == "localhost" || $this->global_settings->db_host() == "127.0.0.1") { + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'localhost' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); + + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'127.0.0.1' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); + } + else { + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'".$this->global_settings->db_host()."' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); + } + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //create the database and set the create user with permissions + try { + $tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->global_settings->db_name()."; "; + $this->dbh->query($tmp_sql); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //set user permissions + try { + $this->dbh->query("GRANT ALL PRIVILEGES ON ".$this->global_settings->db_name().".* TO '".$this->global_settings->db_username()."'@'%'; "); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //make the changes active + try { + $tmp_sql = "FLUSH PRIVILEGES; "; + $this->dbh->query($tmp_sql); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + $this->dbh = null; + } //if (strlen($this->global_settings->db_create_username()) > 0) + + $this->write_progress("\tInstalling data to database"); + //select the database + try { + $this->dbh = new PDO($connect_string, $this->global_settings->db_username(), db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); + $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + } + catch (PDOException $error) { + throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql ); + } + try { + $this->dbh->query("USE ".$this->global_settings->db_name().";"); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //add the database structure + require_once "resources/classes/schema.php"; + $schema = new schema; + $schema->db = $this->dbh; + $schema->db_type = $this->global_settings->db_type(); + $schema->sql(); + $schema->exec(); + + //add the defaults data into the database + //get the contents of the sql file + if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql')){ + $filename = "/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql"; + } + else { + $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql'; + } + $file_contents = file_get_contents($filename); + + //replace \r\n with \n then explode on \n + $file_contents = str_replace("\r\n", "\n", $file_contents); + + //loop line by line through all the lines of sql code + $string_array = explode("\n", $file_contents); + $x = 0; + foreach($string_array as $sql) { + if (strlen($sql) > 3) { + try { + if ($this->debug) { + $this->write_debug( $sql."\n"); + } + $this->dbh->query($sql); + } + catch (PDOException $error) { + //echo "error on line $x: " . $error->getMessage() . " sql: $sql
"; + //die(); + } + } + $x++; + } + unset ($file_contents, $sql); + } + + protected function create_domain() { + $this->write_progress("\tChecking if domain exists '" . $this->global_settings->domain_name() . "'"); + $sql = "select * from v_domains "; + $sql .= "where domain_name = '".$this->global_settings->domain_name()."' "; + $sql .= "limit 1"; + $this->write_debug($sql); + $prep_statement = $this->dbh->prepare(check_sql($sql)); + if($prep_statement->execute() === false){ + throw new Exception("Failed to search for domain: " . join(":", $this->dbh->errorInfo())); + } + $result = $prep_statement->fetch(PDO::FETCH_NAMED); + unset($sql, $prep_statement); + if ($result) { + $this->global_settings->set_domain_uuid($result['domain_uuid']); + $this->write_progress("... domain exists as '" . $this->global_settings->domain_uuid() . "'"); + if($result['domain_enabled'] != 'true'){ + throw new Exception("Domain already exists but is disabled, this is unexpected"); + } + } else { + $this->write_progress("\t... creating domain"); + $sql = "insert into v_domains "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "domain_name, "; + $sql .= "domain_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$this->global_settings->domain_uuid()."', "; + $sql .= "'".$this->global_settings->domain_name()."', "; + $sql .= "'Default Domain' "; + $sql .= ");"; + + $this->write_debug($sql); + if($this->dbh->exec(check_sql($sql)) === false){ + throw new Exception("Failed to execute sql statement: " . join(":", $this->dbh->errorInfo())); + } + unset($sql); + + //domain settings + $x = 0; + $tmp[$x]['name'] = 'uuid'; + $tmp[$x]['value'] = $this->menu_uuid; + $tmp[$x]['category'] = 'domain'; + $tmp[$x]['subcategory'] = 'menu'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'name'; + $tmp[$x]['category'] = 'domain'; + $tmp[$x]['subcategory'] = 'time_zone'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'code'; + $tmp[$x]['value'] = 'en-us'; + $tmp[$x]['category'] = 'domain'; + $tmp[$x]['subcategory'] = 'language'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'iso_code'; + $tmp[$x]['value'] = $this->default_country; + $tmp[$x]['category'] = 'domain'; + $tmp[$x]['subcategory'] = 'country'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'name'; + $tmp[$x]['value'] = $this->template_name; + $tmp[$x]['category'] = 'domain'; + $tmp[$x]['subcategory'] = 'template'; + $tmp[$x]['enabled'] = 'true'; + $x++; + + //switch settings + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $switch_bin_dir; + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'bin'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_base_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'base'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_conf_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'conf'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_db_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'db'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_log_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'log'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_mod_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'mod'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_script_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'scripts'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_grammar_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'grammar'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_storage_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'storage'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_voicemail_vdir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'voicemail'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_recordings_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'recordings'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_sounds_dir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'sounds'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_phrases_vdir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'phrases'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = ''; + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'provision'; + $tmp[$x]['enabled'] = 'false'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_extensions_vdir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'extensions'; + $tmp[$x]['enabled'] = 'false'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_sip_profiles_vdir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'sip_profiles'; + $tmp[$x]['enabled'] = 'false'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_dialplan_vdir(); + $tmp[$x]['category'] = 'switch'; + $tmp[$x]['subcategory'] = 'dialplan'; + $tmp[$x]['enabled'] = 'false'; + $x++; + + //server settings + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_temp_dir(); + $tmp[$x]['category'] = 'server'; + $tmp[$x]['subcategory'] = 'temp'; + $tmp[$x]['enabled'] = 'true'; + $x++; + #throw new Exception("I don't know how to find /etc/init.d for server > startup_scripts"); + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = ''; + $tmp[$x]['category'] = 'server'; + $tmp[$x]['subcategory'] = 'startup_script'; + $tmp[$x]['enabled'] = 'true'; + $x++; + $tmp[$x]['name'] = 'dir'; + $tmp[$x]['value'] = $this->global_settings->switch_backup_vdir(); + $tmp[$x]['category'] = 'server'; + $tmp[$x]['subcategory'] = 'backup'; + $tmp[$x]['enabled'] = 'true'; + $x++; + + $this->dbh->beginTransaction(); + foreach($tmp as $row) { + $sql = "insert into v_default_settings "; + $sql .= "("; + $sql .= "default_setting_uuid, "; + $sql .= "default_setting_name, "; + $sql .= "default_setting_value, "; + $sql .= "default_setting_category, "; + $sql .= "default_setting_subcategory, "; + $sql .= "default_setting_enabled "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'".$row['name']."', "; + $sql .= "'".$row['value']."', "; + $sql .= "'".$row['category']."', "; + $sql .= "'".$row['subcategory']."', "; + $sql .= "'".$row['enabled']."' "; + $sql .= ");"; + $this->write_debug($sql); + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + $this->dbh->commit(); + unset($tmp); + + //get the list of installed apps from the core and mod directories + $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); + $x=0; + foreach ($config_list as $config_path) { + include($config_path); + $x++; + } + + //add the groups + $x = 0; + $tmp[$x]['group_name'] = 'superadmin'; + $tmp[$x]['group_description'] = 'Super Administrator Group'; + $x++; + $tmp[$x]['group_name'] = 'admin'; + $tmp[$x]['group_description'] = 'Administrator Group'; + $x++; + $tmp[$x]['group_name'] = 'user'; + $tmp[$x]['group_description'] = 'User Group'; + $x++; + $tmp[$x]['group_name'] = 'public'; + $tmp[$x]['group_description'] = 'Public Group'; + $x++; + $tmp[$x]['group_name'] = 'agent'; + $tmp[$x]['group_description'] = 'Call Center Agent Group'; + $this->dbh->beginTransaction(); + foreach($tmp as $row) { + $sql = "insert into v_groups "; + $sql .= "("; + $sql .= "group_uuid, "; + $sql .= "group_name, "; + $sql .= "group_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'".$row['group_name']."', "; + $sql .= "'".$row['group_description']."' "; + $sql .= ");"; + $this->write_debug($sql); + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + unset($tmp); + $this->dbh->commit(); + //assign the default permissions to the groups + $this->dbh->beginTransaction(); + foreach($apps as $app) { + if ($app['permissions']) { + foreach ($app['permissions'] as $row) { + if ($this->debug) { + $this->write_debug( "v_group_permissions\n"); + $this->write_debug( json_encode($row)."\n\n"); + } + if ($row['groups']) { + foreach ($row['groups'] as $group) { + //add the record + $sql = "insert into v_group_permissions "; + $sql .= "("; + $sql .= "group_permission_uuid, "; + $sql .= "permission_name, "; + $sql .= "group_name "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'".$row['name']."', "; + $sql .= "'".$group."' "; + $sql .= ");"; + if ($this->debug) { + $this->write_debug( $sql."\n"); + } + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + } + } + } + } + $this->dbh->commit(); + } + } + + protected function create_superuser() { + $this->write_progress("\tChecking if superuser exists '" . $this->admin_username . "'"); + $sql = "select * from v_users "; + $sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' "; + $sql .= "and username = '".$this->admin_username."' "; + $sql .= "limit 1 "; + $this->write_debug($sql); + $prep_statement = $this->dbh->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetch(PDO::FETCH_NAMED); + unset($sql, $prep_statement); + $salt = generate_password('20', '4'); + if ($result) { + $this->admin_uuid = $result['user_uuid']; + $this->write_progress("... superuser exists as '" . $this->admin_uuid . "', updating password"); + $sql = "update v_users "; + $sql .= "set password = '".md5($salt.$this->admin_password)."' "; + $sql .= "set salt = '$salt' "; + $sql .= "where USER_uuid = '".$this->admin_uuid."' "; + $this->write_debug($sql); + $this->dbh->exec(check_sql($sql)); + }else{ + $this->write_progress("\t... creating super user"); + //add a user and then add the user to the superadmin group + //prepare the values + $this->admin_uuid = uuid(); + $contact_uuid = uuid(); + //set a sessiong variable + $_SESSION["user_uuid"] = $user_uuid; + //salt used with the password to create a one way hash + //add the user account + $sql = "insert into v_users "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "user_uuid, "; + $sql .= "contact_uuid, "; + $sql .= "username, "; + $sql .= "password, "; + $sql .= "salt, "; + $sql .= "add_date, "; + $sql .= "add_user "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$this->global_settings->domain_uuid()."', "; + $sql .= "'".$this->admin_uuid."', "; + $sql .= "'$contact_uuid', "; + $sql .= "'".$this->admin_username."', "; + $sql .= "'".md5($salt.$this->admin_password)."', "; + $sql .= "'$salt', "; + $sql .= "now(), "; + $sql .= "'".$this->admin_username."' "; + $sql .= ");"; + $this->write_debug( $sql."\n"); + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + $this->write_progress("\tChecking if superuser contact exists"); + $sql = "select count(*) from v_contacts "; + $sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' "; + $sql .= "and contact_name_given = '".$this->admin_username."' "; + $sql .= "and contact_nickname = '".$this->admin_username."' "; + $sql .= "limit 1 "; + $this->write_debug($sql); + $prep_statement = $this->dbh->prepare(check_sql($sql)); + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['count'] == 0) { + $sql = "insert into v_contacts "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "contact_uuid, "; + $sql .= "contact_type, "; + $sql .= "contact_name_given, "; + $sql .= "contact_nickname "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$this->global_settings->domain_uuid()."', "; + $sql .= "'$contact_uuid', "; + $sql .= "'user', "; + $sql .= "'".$this->admin_username."', "; + $sql .= "'".$this->admin_username."' "; + $sql .= ")"; + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + $this->write_progress("\tChecking if superuser is in the correct group"); + $sql = "select count(*) from v_group_users "; + $sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' "; + $sql .= "and user_uuid = '".$this->admin_uuid."' "; + $sql .= "and group_name = 'superadmin' "; + $sql .= "limit 1 "; + $this->write_debug($sql); + $prep_statement = $this->dbh->prepare(check_sql($sql)); + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['count'] == 0) { + //add the user to the superadmin group + $sql = "insert into v_group_users "; + $sql .= "("; + $sql .= "group_user_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "user_uuid, "; + $sql .= "group_name "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'".$this->global_settings->domain_uuid()."', "; + $sql .= "'".$this->admin_uuid."', "; + $sql .= "'superadmin' "; + $sql .= ");"; + $this->write_debug( $sql."\n"); + $this->dbh->exec(check_sql($sql)); + unset($sql); + } + } + + protected function create_menus() { + $this->write_progress("\tCreating menus"); + //set the defaults + $menu_name = 'default'; + $menu_language = 'en-us'; + $menu_description = 'Default Menu Set'; + + $this->write_progress("\tChecking if menu exists"); + $sql = "select count(*) from v_menus "; + $sql .= "where menu_uuid = '".$this->menu_uuid."' "; + $sql .= "limit 1 "; + $this->write_debug($sql); + $prep_statement = $this->dbh->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetch(PDO::FETCH_NAMED); + unset($sql, $prep_statement); + if ($result['count'] == 0) { + $this->write_progress("\t... creating menu '" . $menu_name. "'"); + $sql = "insert into v_menus "; + $sql .= "("; + $sql .= "menu_uuid, "; + $sql .= "menu_name, "; + $sql .= "menu_language, "; + $sql .= "menu_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$this->menu_uuid."', "; + $sql .= "'$menu_name', "; + $sql .= "'$menu_language', "; + $sql .= "'$menu_description' "; + $sql .= ");"; + if ($this->debug) { + $this->write_debug( $sql."\n"); + } + $this->dbh->exec(check_sql($sql)); + unset($sql); + + //add the menu items + require_once "resources/classes/menu.php"; + $menu = new menu; + $menu->db = $this->dbh; + $menu->menu_uuid = $this->menu_uuid; + $menu->restore(); + unset($menu); + } + } + + protected function app_defaults() { + $this->write_progress("\tRunning app_defaults"); + + //set needed session settings + $_SESSION["username"] = $this->admin_username; + $_SESSION["domain_uuid"] = $this->global_settings->domain_uuid(); + require $this->config_php; + require "resources/require.php"; + $_SESSION['event_socket_ip_address'] = $this->global_settings->event_host; + $_SESSION['event_socket_port'] = $this->global_settings->event_port; + $_SESSION['event_socket_password'] = $this->global_settings->event_password; + + //get the groups assigned to the user and then set the groups in $_SESSION["groups"] + $sql = "SELECT * FROM v_group_users "; + $sql .= "where domain_uuid=:domain_uuid "; + $sql .= "and user_uuid=:user_uuid "; + $prep_statement = $this->dbh->prepare(check_sql($sql)); + $prep_statement->bindParam(':domain_uuid', $this->global_settings->domain_uuid); + $prep_statement->bindParam(':user_uuid', $this->admin_uuid); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $_SESSION["groups"] = $result; + unset($sql, $row_count, $prep_statement); + + //get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions'] + $x = 0; + $sql = "select distinct(permission_name) from v_group_permissions "; + foreach($_SESSION["groups"] as $field) { + if (strlen($field['group_name']) > 0) { + if ($x == 0) { + $sql .= "where (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') "; + } + else { + $sql .= "or (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') "; + } + $x++; + } + } + $prep_statement_sub = $this->dbh->prepare($sql); + $prep_statement_sub->execute(); + $_SESSION['permissions'] = $prep_statement_sub->fetchAll(PDO::FETCH_NAMED); + unset($sql, $prep_statement_sub); + + //include the config.php + $db_type = $this->global_settings->db_type(); + $db_path = $this->global_settings->db_path(); + $db_host = $this->global_settings->db_host(); + $db_port = $this->global_settings->db_port(); + $db_name = $this->global_settings->db_name(); + $db_username = $this->global_settings->db_username(); + $db_password = $this->global_settings->db_password(); + + //add the database structure + require_once "resources/classes/schema.php"; + $schema = new schema; + echo $schema->schema(); + + //run all app_defaults.php files + $default_language = $this->install_language; + $domain = new domains; + $domain->upgrade(); + + //synchronize the config with the saved settings + save_switch_xml(); + + //do not show the apply settings reminder on the login page + $_SESSION["reload_xml"] = false; + + //clear the menu + $_SESSION["menu"] = ""; + + } + + public function remove_config() { + if (file_exists('/bin/rm')) { + $this->write_debug('rm -f ' . $this->config_php); + exec ('rm -f ' . $this->config_php); + } + elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){ + $this->write_debug("del /S /F /Q '$dir'"); + exec("del /F /Q '" . $this->config_php . "'"); + } + else { + $this->write_debug("delete file: ".$file); + unlink($this->config_php); + } + clearstatcache(); + } + } + +?> \ No newline at end of file diff --git a/core/install/resources/classes/install_switch.php b/core/install/resources/classes/install_switch.php new file mode 100644 index 0000000000..0e7fbf5803 --- /dev/null +++ b/core/install/resources/classes/install_switch.php @@ -0,0 +1,455 @@ + + Copyright (C) 2010-2015 + All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; + +//define the install class + class install_switch { + + protected $global_settings; + protected $config_lua; + protected $dbh; + + public $debug = false; + public $echo_progress = false; + + function __construct($global_settings) { + if(is_null($global_settings)){ + require_once "core/install/resources/classes/global_settings.php"; + $global_settings = new global_settings(); + }elseif(!is_a($global_settings, 'global_settings')){ + throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)'); + } + $this->global_settings = $global_settings; + if (is_dir("/etc/fusionpbx")){ + $this->config_lua = "/etc/fusionpbx/config.lua"; + }elseif (is_dir("/usr/local/etc/fusionpbx")){ + $this->config_lua = "/usr/local/etc/fusionpbx/config.lua"; + }elseif(strlen($this->global_settings->switch_script_dir()) > 0) { + $this->config_lua = $this->global_settings->switch_script_dir()."/resources/config.lua"; + }else{ + throw new Exception("Could not work out where to put the config.lua"); + } + $this->config_lua = normalize_path_to_os($this->config_lua); + } + + //utility Functions + + function write_debug($message) { + if($this->debug){ + echo "$message\n"; + } + } + + function write_progress($message) { + if($this->echo_progress){ + echo "$message\n"; + } + } + + //$options '-n' --no-clobber + protected function recursive_copy($src, $dst, $options = '') { + if (file_exists('/bin/cp')) { + if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') { + //copy -R recursive, preserve attributes for SUN + $cmd = 'cp -Rp '.$src.'/* '.$dst; + } else { + //copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss + $cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst; + } + $this->write_debug($cmd); + exec ($cmd); + } + elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){ + $src = normalize_path_to_os($src); + $dst = normalize_path_to_os($dst); + exec("xcopy /E /Y \"$src\" \"$dst\""); + } + else { + throw new Exception('Could not perform copy operation on this platform, implementation missing'); + $dir = opendir($src); + if (!$dir) { + if (!mkdir($src, 0755, true)) { + throw new Exception("recursive_copy() source directory '".$src."' does not exist."); + } + } + if (!is_dir($dst)) { + if (!mkdir($dst, 0755, true)) { + throw new Exception("recursive_copy() failed to create destination directory '".$dst."'"); + } + } + //This looks wrong, essentially if we can't use /bin/cp it manually fils dirs, not correct + $script_dir_target = $_SESSION['switch']['scripts']['dir']; + $script_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'); + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) { + if ( + substr_count($file_path_source, '/..') == 0 && + substr_count($file_path_source, '/.') == 0 && + substr_count($file_path_source, '/.svn') == 0 && + substr_count($file_path_source, '/.git') == 0 + ) { + if ($dst != $src.'/resources/config.lua') { + $this->write_debug($file_path_source.' ---> '.$dst); + copy($file_path_source, $dst); + chmod($dst, 0755); + } + } + } + + while(false !== ($file = readdir($dir))) { + if (($file != '.') && ($file != '..')) { + if (is_dir($src.'/'.$file)) { + $this->recursive_copy($src.'/'.$file, $dst.'/'.$file); + } + else { + //copy only missing files -n --no-clobber + if (strpos($options,'-n') !== false) { + if (!file_exists($dst.'/'.$file)) { + $this->write_debug("copy(".$src."/".$file.", ".$dst."/".$file.")"); + copy($src.'/'.$file, $dst.'/'.$file); + } + } + else { + copy($src.'/'.$file, $dst.'/'.$file); + } + } + } + } + closedir($dir); + } + } + + protected function recursive_delete($dir) { + if (file_exists('/bin/rm')) { + $this->write_debug('rm -Rf '.$dir.'/*'); + exec ('rm -Rf '.$dir.'/*'); + } + elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){ + $dst = normalize_path_to_os($dst); + $this->write_debug("del /S /F /Q \"$dir\""); + exec("del /S /F /Q \"$dir\""); + } + else { + foreach (glob($dir) as $file) { + if (is_dir($file)) { + $this->write_debug("rm dir: ".$file); + $this->recursive_delete("$file/*"); + rmdir($file); + } else { + $this->write_debug("delete file: ".$file); + unlink($file); + } + } + } + clearstatcache(); + } + + protected function backup_dir($dir, $backup_name){ + if (!is_readable($dir)) { + throw new Exception("backup_dir() source directory '".$dir."' does not exist."); + } + $dst_tar = join( DIRECTORY_SEPARATOR, array(sys_get_temp_dir(), "$backup_name.tar")); + //pharData is the correct ay to do it, but it keeps creating incomplete archives + //$tar = new PharData($dst_tar); + //$tar->buildFromDirectory($dir); + $this->write_debug("backing up to $dst_tar"); + if (file_exists('/bin/tar')) { + exec('tar -cvf ' .$dst_tar. ' -C '.$dir .' .'); + }else{ + $this->write_debug('WARN: old config could not be compressed'); + $dst_dir = join( DIRECTORY_SEPARATOR, array(sys_get_temp_dir(), "$backup_name")); + recursive_copy($dir, $dst_dir); + } + } + + function install_phase_1() { + $this->write_progress("Install phase 1 started for switch"); + $this->copy_conf(); + $this->copy_scripts(); + $this->write_progress("Install phase 1 completed for switch"); + } + + function install_phase_2() { + $this->write_progress("Install phase 2 started for switch"); + $this->create_config_lua(); + $this->restart_switch(); + $this->write_progress("Install phase 2 completed for switch"); + } + + function upgrade() { + $this->copy_scripts(); + $this->create_config_lua(); + } + + protected function copy_conf() { + $this->write_progress("\tCopying Config"); + //make a backup of the config + if (file_exists($this->global_settings->switch_conf_dir())) { + $this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config'); + $this->recursive_delete($this->global_settings->switch_conf_dir()); + } + //make sure the conf directory exists + if (!is_dir($this->global_settings->switch_conf_dir())) { + if (!mkdir($this->global_settings->switch_conf_dir(), 0774, true)) { + throw new Exception("Failed to create the switch conf directory '".$this->global_settings->switch_conf_dir()."'. "); + } + } + //copy resources/templates/conf to the freeswitch conf dir + if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){ + $src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf"; + } + else { + $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf"; + } + $dst_dir = $this->global_settings->switch_conf_dir(); + if (is_readable($dst_dir)) { + $this->recursive_copy($src_dir, $dst_dir); + unset($src_dir, $dst_dir); + } + $fax_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax')); + if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); } + $voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail')); + if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); } + + //create the dialplan/default.xml for single tenant or dialplan/domain.xml + if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) { + $dialplan = new dialplan; + $dialplan->domain_uuid = $this->domain_uuid; + $dialplan->domain = $this->domain_name; + $dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan")); + $dialplan->restore_advanced_xml(); + if($this->_debug){ + print_r($dialplan->result, $message); + $this->write_debug($message); + } + } + + //write the xml_cdr.conf.xml file + if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/xml_cdr")) { + xml_cdr_conf_xml(); + } + + //write the switch.conf.xml file + if (file_exists($this->global_settings->switch_conf_dir())) { + switch_conf_xml(); + } + + } + + protected function copy_scripts() { + $this->write_progress("\tCopying Scripts"); + $script_dir = $this->global_settings->switch_script_dir(); + if(strlen($script_dir) == 0) { + throw new Exception("Cannot copy scripts the 'script_dir' is empty"); + } + if (file_exists($script_dir)) { + if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){ + $src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts'; + } + else { + $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'; + } + $dst_dir = $script_dir; + if (is_readable($script_dir)) { + $this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']); + unset($src_dir, $dst_dir); + }else{ + throw new Exception("Cannot read from '$src_dir' to get the scripts"); + } + chmod($dst_dir, 0774); + }else{ + $this->write_progress("\tSkipping scripts, script_dir is unset"); + } + } + + public function create_config_lua() { + //define the database connection as global + global $db; + + //send progress + $this->write_progress("\tCreating " . $this->config_lua); + + //set the directories + $path = dirname($this->config_lua); + $parent_dir = basename($path); + if ($parent_dir == 'resources' and !file_exists($path)){ + $this->write_progress("\t... creating missing '$path'"); + if (!mkdir($path, 0755, true)) { + throw new Exception("Failed to create the missing resources directory '$path'"); + } + } + + //get the odbc information + $sql = "select count(*) as num_rows from v_databases "; + $sql .= "where database_driver = 'odbc' "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset($prep_statement); + if ($row['num_rows'] > 0) { + $odbc_num_rows = $row['num_rows']; + $sql = "select * from v_databases "; + $sql .= "where database_driver = 'odbc' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $dsn_name = $row["database_name"]; + $dsn_username = $row["database_username"]; + $dsn_password = $row["database_password"]; + break; //limit to 1 row + } + unset ($prep_statement); + } + else { + $odbc_num_rows = '0'; + } + } + + //config.lua + $fout = fopen($this->config_lua,"w"); + if(!$fout){ + throw new Exception("Failed to open '".$this->config_lua."' for writing"); + } + $tmp = "\n"; + $tmp .= "--set the variables\n"; + if (strlen($this->global_settings->switch_sounds_dir()) > 0) { + $tmp .= normalize_path_to_os(" sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n"); + } + if (strlen($this->global_settings->switch_phrases_vdir()) > 0) { + $tmp .= normalize_path_to_os(" phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n"); + } + if (strlen($this->global_settings->switch_db_dir()) > 0) { + $tmp .= normalize_path_to_os(" database_dir = [[".$this->global_settings->switch_db_dir()."]];\n"); + } + if (strlen($this->global_settings->switch_recordings_dir()) > 0) { + $tmp .= normalize_path_to_os(" recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n"); + } + if (strlen($this->global_settings->switch_storage_dir()) > 0) { + $tmp .= normalize_path_to_os(" storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n"); + } + if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) { + $tmp .= normalize_path_to_os(" voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n"); + } + if (strlen($this->global_settings->switch_script_dir()) > 0) { + $tmp .= normalize_path_to_os(" scripts_dir = [[".$this->global_settings->switch_script_dir()."]];\n"); + } + $tmp .= normalize_path_to_os(" php_dir = [[".PHP_BINDIR."]];\n"); + if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { + $tmp .= " php_bin = \"php.exe\";\n"; + } + else { + $tmp .= " php_bin = \"php\";\n"; + } + $tmp .= normalize_path_to_os(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n"); + $tmp .= "\n"; + + if ((strlen($this->global_settings->db_type()) > 0) || (strlen($dsn_name) > 0)) { + $tmp .= "--database information\n"; + $tmp .= " database = {}\n"; + $tmp .= " database[\"type\"] = \"".$this->global_settings->db_type()."\";\n"; + $tmp .= " database[\"name\"] = \"".$this->global_settings->db_name()."\";\n"; + $tmp .= normalize_path_to_os(" database[\"path\"] = [[".$this->global_settings->db_path()."]];\n"); + + if (strlen($dsn_name) > 0) { + $tmp .= " database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n"; + $tmp .= " database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n"; + } + elseif ($this->global_settings->db_type() == "pgsql") { + $db_host = $this->global_settings->db_host(); + if($db_host == 'localhost') { $db_host = '127.0.0.1'; } // lua cannot resolve localhost + if (filter_var($db_host, FILTER_VALIDATE_IP)) { + $host_type = "hostaddr"; + } + else { + $host_type = "host"; + } + $tmp .= " database[\"system\"] = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=".$this->global_settings->db_name()." user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='".$this->global_settings->db_name()."'\";\n"; + $tmp .= " database[\"switch\"] = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=freeswitch user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='freeswitch'\";\n"; + } + elseif ($this->global_settings->db_type() == "sqlite") { + $tmp .= " database[\"system\"] = \"sqlite://".$this->global_settings->db_path()."/".$this->global_settings->db_name()."\";\n"; + $tmp .= " database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n"; + } + elseif ($this->global_settings->db_type() == "mysql") { + $tmp .= " database[\"system\"] = \"\";\n"; + $tmp .= " database[\"switch\"] = \"\";\n"; + } + $tmp .= "\n"; + } + $tmp .= "--set defaults\n"; + $tmp .= " expire = {}\n"; + $tmp .= " expire[\"directory\"] = \"3600\";\n"; + $tmp .= " expire[\"dialplan\"] = \"3600\";\n"; + $tmp .= " expire[\"languages\"] = \"3600\";\n"; + $tmp .= " expire[\"sofia.conf\"] = \"3600\";\n"; + $tmp .= " expire[\"acl.conf\"] = \"3600\";\n"; + $tmp .= "\n"; + $tmp .= "--set xml_handler\n"; + $tmp .= " xml_handler = {}\n"; + $tmp .= " xml_handler[\"fs_path\"] = false;\n"; + $tmp .= "\n"; + $tmp .= "--set the debug options\n"; + $tmp .= " debug[\"params\"] = false;\n"; + $tmp .= " debug[\"sql\"] = false;\n"; + $tmp .= " debug[\"xml_request\"] = false;\n"; + $tmp .= " debug[\"xml_string\"] = false;\n"; + $tmp .= " debug[\"cache\"] = false;\n"; + $tmp .= "\n"; + $tmp .= "--additional info\n"; + $tmp .= " domain_count = ".$this->global_settings->domain_count().";\n"; + $tmp .= normalize_path_to_os(" temp_dir = [[".$this->global_settings->switch_temp_dir()."]];\n"); + if (isset($_SESSION['domain']['dial_string']['text'])) { + $tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n"; + } + $tmp .= "\n"; + $tmp .= "--include local.lua\n"; + $tmp .= " require(\"resources.functions.file_exists\");\n"; + $tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n"; + $tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n"; + $tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n"; + $tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n"; + $tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n"; + $tmp .= " require(\"resources.local\");\n"; + $tmp .= " end\n"; + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + } + + protected function restart_switch() { + $esl = new EventSocket; + if(!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) { + throw new Exception("Failed to connect to switch"); + } + if (!$esl->request('api fsctl shutdown restart elegant')){ + throw new Exception("Failed to send switch restart"); + } + $esl->reset_fp(); + } + } +?> \ No newline at end of file diff --git a/core/install/resources/classes/iso_countries.php b/core/install/resources/classes/iso_countries.php new file mode 100644 index 0000000000..3609754ab7 --- /dev/null +++ b/core/install/resources/classes/iso_countries.php @@ -0,0 +1,250 @@ + 'Afghanistan', + 'AX' => 'Aland Islands', + 'AL' => 'Albania', + 'DZ' => 'Algeria', + 'AS' => 'American Samoa', + 'AD' => 'Andorra', + 'AO' => 'Angola', + 'AI' => 'Anguilla', + 'AQ' => 'Antarctica', + 'AG' => 'Antigua And Barbuda', + 'AR' => 'Argentina', + 'AM' => 'Armenia', + 'AW' => 'Aruba', + 'AU' => 'Australia', + 'AT' => 'Austria', + 'AZ' => 'Azerbaijan', + 'BS' => 'Bahamas', + 'BH' => 'Bahrain', + 'BD' => 'Bangladesh', + 'BB' => 'Barbados', + 'BY' => 'Belarus', + 'BE' => 'Belgium', + 'BZ' => 'Belize', + 'BJ' => 'Benin', + 'BM' => 'Bermuda', + 'BT' => 'Bhutan', + 'BO' => 'Bolivia', + 'BA' => 'Bosnia And Herzegovina', + 'BW' => 'Botswana', + 'BV' => 'Bouvet Island', + 'BR' => 'Brazil', + 'IO' => 'British Indian Ocean Territory', + 'BN' => 'Brunei Darussalam', + 'BG' => 'Bulgaria', + 'BF' => 'Burkina Faso', + 'BI' => 'Burundi', + 'KH' => 'Cambodia', + 'CM' => 'Cameroon', + 'CA' => 'Canada', + 'CV' => 'Cape Verde', + 'KY' => 'Cayman Islands', + 'CF' => 'Central African Republic', + 'TD' => 'Chad', + 'CL' => 'Chile', + 'CN' => 'China', + 'CX' => 'Christmas Island', + 'CC' => 'Cocos (Keeling) Islands', + 'CO' => 'Colombia', + 'KM' => 'Comoros', + 'CG' => 'Congo', + 'CD' => 'Congo, Democratic Republic', + 'CK' => 'Cook Islands', + 'CR' => 'Costa Rica', + 'CI' => 'Cote D\'Ivoire', + 'HR' => 'Croatia', + 'CU' => 'Cuba', + 'CY' => 'Cyprus', + 'CZ' => 'Czech Republic', + 'DK' => 'Denmark', + 'DJ' => 'Djibouti', + 'DM' => 'Dominica', + 'DO' => 'Dominican Republic', + 'EC' => 'Ecuador', + 'EG' => 'Egypt', + 'SV' => 'El Salvador', + 'GQ' => 'Equatorial Guinea', + 'ER' => 'Eritrea', + 'EE' => 'Estonia', + 'ET' => 'Ethiopia', + 'FK' => 'Falkland Islands (Malvinas)', + 'FO' => 'Faroe Islands', + 'FJ' => 'Fiji', + 'FI' => 'Finland', + 'FR' => 'France', + 'GF' => 'French Guiana', + 'PF' => 'French Polynesia', + 'TF' => 'French Southern Territories', + 'GA' => 'Gabon', + 'GM' => 'Gambia', + 'GE' => 'Georgia', + 'DE' => 'Germany', + 'GH' => 'Ghana', + 'GI' => 'Gibraltar', + 'GR' => 'Greece', + 'GL' => 'Greenland', + 'GD' => 'Grenada', + 'GP' => 'Guadeloupe', + 'GU' => 'Guam', + 'GT' => 'Guatemala', + 'GG' => 'Guernsey', + 'GN' => 'Guinea', + 'GW' => 'Guinea-Bissau', + 'GY' => 'Guyana', + 'HT' => 'Haiti', + 'HM' => 'Heard Island & Mcdonald Islands', + 'VA' => 'Holy See (Vatican City State)', + 'HN' => 'Honduras', + 'HK' => 'Hong Kong', + 'HU' => 'Hungary', + 'IS' => 'Iceland', + 'IN' => 'India', + 'ID' => 'Indonesia', + 'IR' => 'Iran, Islamic Republic Of', + 'IQ' => 'Iraq', + 'IE' => 'Ireland', + 'IM' => 'Isle Of Man', + 'IL' => 'Israel', + 'IT' => 'Italy', + 'JM' => 'Jamaica', + 'JP' => 'Japan', + 'JE' => 'Jersey', + 'JO' => 'Jordan', + 'KZ' => 'Kazakhstan', + 'KE' => 'Kenya', + 'KI' => 'Kiribati', + 'KR' => 'Korea', + 'KW' => 'Kuwait', + 'KG' => 'Kyrgyzstan', + 'LA' => 'Lao People\'s Democratic Republic', + 'LV' => 'Latvia', + 'LB' => 'Lebanon', + 'LS' => 'Lesotho', + 'LR' => 'Liberia', + 'LY' => 'Libyan Arab Jamahiriya', + 'LI' => 'Liechtenstein', + 'LT' => 'Lithuania', + 'LU' => 'Luxembourg', + 'MO' => 'Macao', + 'MK' => 'Macedonia', + 'MG' => 'Madagascar', + 'MW' => 'Malawi', + 'MY' => 'Malaysia', + 'MV' => 'Maldives', + 'ML' => 'Mali', + 'MT' => 'Malta', + 'MH' => 'Marshall Islands', + 'MQ' => 'Martinique', + 'MR' => 'Mauritania', + 'MU' => 'Mauritius', + 'YT' => 'Mayotte', + 'MX' => 'Mexico', + 'FM' => 'Micronesia, Federated States Of', + 'MD' => 'Moldova', + 'MC' => 'Monaco', + 'MN' => 'Mongolia', + 'ME' => 'Montenegro', + 'MS' => 'Montserrat', + 'MA' => 'Morocco', + 'MZ' => 'Mozambique', + 'MM' => 'Myanmar', + 'NA' => 'Namibia', + 'NR' => 'Nauru', + 'NP' => 'Nepal', + 'NL' => 'Netherlands', + 'AN' => 'Netherlands Antilles', + 'NC' => 'New Caledonia', + 'NZ' => 'New Zealand', + 'NI' => 'Nicaragua', + 'NE' => 'Niger', + 'NG' => 'Nigeria', + 'NU' => 'Niue', + 'NF' => 'Norfolk Island', + 'MP' => 'Northern Mariana Islands', + 'NO' => 'Norway', + 'OM' => 'Oman', + 'PK' => 'Pakistan', + 'PW' => 'Palau', + 'PS' => 'Palestinian Territory, Occupied', + 'PA' => 'Panama', + 'PG' => 'Papua New Guinea', + 'PY' => 'Paraguay', + 'PE' => 'Peru', + 'PH' => 'Philippines', + 'PN' => 'Pitcairn', + 'PL' => 'Poland', + 'PT' => 'Portugal', + 'PR' => 'Puerto Rico', + 'QA' => 'Qatar', + 'RE' => 'Reunion', + 'RO' => 'Romania', + 'RU' => 'Russian Federation', + 'RW' => 'Rwanda', + 'BL' => 'Saint Barthelemy', + 'SH' => 'Saint Helena', + 'KN' => 'Saint Kitts And Nevis', + 'LC' => 'Saint Lucia', + 'MF' => 'Saint Martin', + 'PM' => 'Saint Pierre And Miquelon', + 'VC' => 'Saint Vincent And Grenadines', + 'WS' => 'Samoa', + 'SM' => 'San Marino', + 'ST' => 'Sao Tome And Principe', + 'SA' => 'Saudi Arabia', + 'SN' => 'Senegal', + 'RS' => 'Serbia', + 'SC' => 'Seychelles', + 'SL' => 'Sierra Leone', + 'SG' => 'Singapore', + 'SK' => 'Slovakia', + 'SI' => 'Slovenia', + 'SB' => 'Solomon Islands', + 'SO' => 'Somalia', + 'ZA' => 'South Africa', + 'GS' => 'South Georgia And Sandwich Isl.', + 'ES' => 'Spain', + 'LK' => 'Sri Lanka', + 'SD' => 'Sudan', + 'SR' => 'Suriname', + 'SJ' => 'Svalbard And Jan Mayen', + 'SZ' => 'Swaziland', + 'SE' => 'Sweden', + 'CH' => 'Switzerland', + 'SY' => 'Syrian Arab Republic', + 'TW' => 'Taiwan', + 'TJ' => 'Tajikistan', + 'TZ' => 'Tanzania', + 'TH' => 'Thailand', + 'TL' => 'Timor-Leste', + 'TG' => 'Togo', + 'TK' => 'Tokelau', + 'TO' => 'Tonga', + 'TT' => 'Trinidad And Tobago', + 'TN' => 'Tunisia', + 'TR' => 'Turkey', + 'TM' => 'Turkmenistan', + 'TC' => 'Turks And Caicos Islands', + 'TV' => 'Tuvalu', + 'UG' => 'Uganda', + 'UA' => 'Ukraine', + 'AE' => 'United Arab Emirates', + 'GB' => 'United Kingdom', + 'US' => 'United States', + 'UM' => 'United States Outlying Islands', + 'UY' => 'Uruguay', + 'UZ' => 'Uzbekistan', + 'VU' => 'Vanuatu', + 'VE' => 'Venezuela', + 'VN' => 'Viet Nam', + 'VG' => 'Virgin Islands, British', + 'VI' => 'Virgin Islands, U.S.', + 'WF' => 'Wallis And Futuna', + 'EH' => 'Western Sahara', + 'YE' => 'Yemen', + 'ZM' => 'Zambia', + 'ZW' => 'Zimbabwe', +); +?> \ No newline at end of file diff --git a/core/install/resources/page_parts/install_config_database.php b/core/install/resources/page_parts/install_config_database.php new file mode 100644 index 0000000000..054059e742 --- /dev/null +++ b/core/install/resources/page_parts/install_config_database.php @@ -0,0 +1,281 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Matthew Vale +*/ + + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + if ($db_type == "sqlite") { + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + } + + if ($db_type == "mysql") { + + //set defaults + if (strlen($db_host) == 0) { $db_host = 'localhost'; } + if (strlen($db_port) == 0) { $db_port = '3306'; } + //if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + } + + if ($db_type == "pgsql") { + if (strlen($db_host) == 0) { $db_host = 'localhost'; } + if (strlen($db_port) == 0) { $db_port = '5432'; } + if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + echo "
".$text['header-config_database']." 
\n"; + echo " Database Filename\n"; + echo "\n"; + echo "
\n"; + echo " Set the database filename. The file extension should be '.db'.\n"; + echo "\n"; + echo "
\n"; + echo " Database Directory\n"; + echo "\n"; + echo "
\n"; + echo " Set the path to the database directory.\n"; + echo "
\n"; + echo " Database Host\n"; + echo "\n"; + echo "
\n"; + echo " Enter the host address for the database server.\n"; + echo "\n"; + echo "
\n"; + echo " Database Port\n"; + echo "\n"; + echo "
\n"; + echo " Enter the port number. It is optional if the database is using the default port.\n"; + echo "\n"; + echo "
\n"; + echo " Database Name\n"; + echo "\n"; + echo "
\n"; + echo " Enter the name of the database.\n"; + echo "\n"; + echo "
\n"; + echo " Database Username\n"; + echo "\n"; + echo "
\n"; + echo " Enter the database username. \n"; + echo "\n"; + echo "
\n"; + echo " Database Password\n"; + echo "\n"; + echo "
\n"; + echo " Enter the database password.\n"; + echo "\n"; + echo "
\n"; + echo " Create Database Options\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "Choose whether to create the database\n"; + echo "
\n"; + echo " Create Database Username\n"; + echo "\n"; + echo "
\n"; + echo " Optional, this username is used to create the database, a database user and set the permissions. \n"; + echo " By default this username is 'root' however it can be any account with permission to add a database, user, and grant permissions. \n"; + echo "
\n"; + echo " Create Database Password\n"; + echo "\n"; + echo "
\n"; + echo " Enter the create database password.\n"; + echo "\n"; + echo "
\n"; + echo " Database Host\n"; + echo "\n"; + echo "
\n"; + echo " Enter the host address for the database server.\n"; + echo "\n"; + echo "
\n"; + echo " Database Port\n"; + echo "\n"; + echo "
\n"; + echo " Enter the port number. It is optional if the database is using the default port.\n"; + echo "\n"; + echo "
\n"; + echo " Database Name\n"; + echo "\n"; + echo "
\n"; + echo " Enter the name of the database.\n"; + echo "\n"; + echo "
\n"; + echo " Database Username\n"; + echo "\n"; + echo "
\n"; + echo " Enter the database username.\n"; + echo "\n"; + echo "
\n"; + echo " Database Password\n"; + echo "\n"; + echo "
\n"; + echo " Enter the database password.\n"; + echo "\n"; + echo "
\n"; + echo " Create Database Options\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " Create Database Username\n"; + echo "\n"; + echo "
\n"; + echo " Optional, this username is used to create the database, a database user and set the permissions. \n"; + echo " By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n"; + echo " Leave blank to use the details above. \n"; + echo "
\n"; + echo " Create Database Password\n"; + echo "\n"; + echo "
\n"; + echo " Enter the create database password.\n"; + echo "\n"; + echo "
"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; +?> \ No newline at end of file diff --git a/core/install/resources/page_parts/install_config_detail.php b/core/install/resources/page_parts/install_config_detail.php new file mode 100644 index 0000000000..6fd2c8ce05 --- /dev/null +++ b/core/install/resources/page_parts/install_config_detail.php @@ -0,0 +1,147 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Matthew Vale +*/ + + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
".$text['header-config_detail']." 
\n"; + echo " Username\n"; + echo "\n"; + echo "
\n"; + echo " Enter the username to use when logging in with the browser.
\n"; + echo "
\n"; + echo " Password\n"; + echo "\n"; + echo "
\n"; + echo " Enter the password to use when logging in with the browser.
\n"; + echo "
\n"; + echo " Country\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " Select ISO country code used to initialize calling contry code variables.
\n"; + echo "
\n"; + echo " Theme: \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " Select a theme to set as the default.
\n"; + echo "
\n"; + echo " Domain name\n"; + echo "\n"; + echo "
\n"; + echo " Enter the default domain name. \n"; + echo "\n"; + echo "
\n"; + echo " Database Type\n"; + echo "\n"; + echo "
\n"; + echo " Select the database type.\n"; + echo "\n"; + echo "
"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; +?> \ No newline at end of file diff --git a/core/install/resources/page_parts/install_event_socket.php b/core/install/resources/page_parts/install_event_socket.php new file mode 100644 index 0000000000..5d25ff6c43 --- /dev/null +++ b/core/install/resources/page_parts/install_event_socket.php @@ -0,0 +1,144 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + //fetch the values + require_once "core/install/resources/classes/detect_switch.php"; + $switch_detect = new detect_switch($event_host, $event_port, $event_password); + //$switch_detect->event_port = 2021; + $detect_ok = true; + try { + $switch_detect->detect(); + } catch(Exception $e){ + echo "

Failed to detect configuration detect_switch reported: " . $e->getMessage() ."

\n"; + $detect_ok = false; + } + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo " \n"; + echo " \n"; + echo " "; + + echo "
".$text['header-event_socket']."

"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-event_host']."\n"; + echo "\n"; + echo " event_host."\" onchange='JavaScript:disable_next()'/>\n"; + echo "
\n"; + echo $text['description-event_host']."\n"; + echo "
\n"; + echo " ".$text['label-event_port']."\n"; + echo "\n"; + echo " event_port."\" onchange='JavaScript:disable_next()'/>\n"; + echo "
\n"; + echo $text['description-event_port']."\n"; + echo "
\n"; + echo " ".$text['label-event_password']."\n"; + echo "\n"; + echo " event_password."\" onchange='JavaScript:disable_next()'/>\n"; + echo "
\n"; + echo $text['description-event_password']."\n"; + echo "
\n"; + echo "
"; + echo "
"; + echo "
"; + if($detect_ok){ + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + $id = 1; + echo "\n"; + echo "\n"; + echo "\n"; + + foreach ($switch_detect->get_dirs() as $folder) + { + if($id % 2 == 0){ echo "\n"; } + echo "\n"; + echo "\n"; + if($id % 2 == 1){ echo "\n"; } + $id++; + } + if($id % 2 == 1){ echo "\n"; } + echo "\n"; + echo "\n"; + echo "\n"; + $id=0; + foreach ($switch_detect->get_vdirs() as $folder) + { + if($id % 2 == 0){ echo "\n"; } + echo "\n"; + echo "\n"; + if($id % 2 == 1){ echo "\n"; } + $id++; + } + + echo "
".$text['title-detected_configuration']."
\n"; + echo "Switch version\n"; + echo "\n"; + echo " ".$switch_detect->version()."\n"; + echo "
\n"; + echo $folder."\n"; + echo "\n"; + echo " ".$switch_detect->$folder()."\n"; + echo "

".$text['title-assumed_configuration']."
\n"; + echo $folder."\n"; + echo "\n"; + echo " ".$switch_detect->$folder()."\n"; + echo "
"; + } + + +?> \ No newline at end of file diff --git a/core/install/resources/page_parts/install_select_language.php b/core/install/resources/page_parts/install_select_language.php new file mode 100644 index 0000000000..1f3715b622 --- /dev/null +++ b/core/install/resources/page_parts/install_select_language.php @@ -0,0 +1,69 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Matthew Vale +*/ + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
".$text['header-select_language']."

"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-select_language']."\n"; + echo "\n"; + echo "
"; + foreach($_SESSION['app']['languages'] as $lang_code){ + echo "
"; + echo " \n"; + echo "
"; + } + echo "
"; + echo "
\n"; + echo $text['description-select_language']."\n"; + echo "
"; + echo "

"; + echo "
"; +?> \ No newline at end of file diff --git a/core/install/root.php b/core/install/root.php new file mode 100644 index 0000000000..884d2b08a3 --- /dev/null +++ b/core/install/root.php @@ -0,0 +1,50 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +// make sure the PATH_SEPARATOR is defined + if (!defined("PATH_SEPARATOR")) { + if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); } + } + +// make sure the document_root is set + $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); + //echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."
\n"; + //echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."
\n"; + //echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."
\n"; + +// if the project directory exists then add it to the include path otherwise add the document root to the include path + if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){ + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' ); + } + else { + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); + } + +?> \ No newline at end of file diff --git a/core/install/upgrade_switch.php b/core/install/upgrade_switch.php new file mode 100644 index 0000000000..fd34d3c806 --- /dev/null +++ b/core/install/upgrade_switch.php @@ -0,0 +1,59 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +// set included, if not + if (!isset($included)) { $included = false; } + +//check the permission + if(defined('STDIN')) { + $document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]); + preg_match("/^(.*)\/core\/.*$/", $document_root, $matches); + $document_root = $matches[1]; + set_include_path($document_root); + require_once "resources/require.php"; + $_SERVER["DOCUMENT_ROOT"] = $document_root; + $format = 'text'; //html, text + } + else if (!$included) { + include "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + if (permission_exists('upgrade_switch') || if_group("superadmin")) { + //echo "access granted"; + } + else { + echo "access denied"; + exit; + } + $format = 'html'; //html, text + } + +//run switch upgrade + require_once "resources/classes/install_switch.php"; + $switch = new install_switch(); + $switch->upgrade(); + +?> \ No newline at end of file diff --git a/core/upgrade/app_config.php b/core/upgrade/app_config.php index effd5308f4..55cc41a13b 100644 --- a/core/upgrade/app_config.php +++ b/core/upgrade/app_config.php @@ -32,6 +32,9 @@ $apps[$x]['permissions'][$y]['menu']['uuid'] = "e7bb1296-3141-48c9-a95a-82d2768d0ae4"; $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; $y++; + $apps[$x]['permissions'][$y]['name'] = "upgrade_switch"; + $apps[$x]['permissions'][$y]['groups'][] = "superadmin"; + $y++; //schema details $y = 0; //table array index diff --git a/core/upgrade/app_defaults.php b/core/upgrade/app_defaults.php index b5625f3e7a..18edf8e23e 100644 --- a/core/upgrade/app_defaults.php +++ b/core/upgrade/app_defaults.php @@ -26,19 +26,6 @@ if ($domains_processed == 1) { - //process if the scripts directory exists - if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - //if the resource scripts resource directory does not exist then create it - if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) { - mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true); - } - - //copy the files and directories from resources/install - $install = new install; - $install->domain_uuid = $domain_uuid; - $install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir']; - $install->copy_scripts(); - } //update the software table $sql = "select count(*) as num_rows from v_software "; diff --git a/core/upgrade/app_languages.php b/core/upgrade/app_languages.php index b7d735eced..3e28a8da98 100644 --- a/core/upgrade/app_languages.php +++ b/core/upgrade/app_languages.php @@ -180,6 +180,16 @@ $text['label-upgrade_apps']['sv-se'] = "App Standard"; $text['label-upgrade_apps']['uk'] = "Типові значення додатків"; $text['label-upgrade_apps']['de-at'] = "Applikationen zurücksetzen"; +$text['label-upgrade_switch']['en-us'] = "Switch Upgrade"; +$text['label-upgrade_switch']['es-cl'] = ""; +$text['label-upgrade_switch']['pt-pt'] = ""; +$text['label-upgrade_switch']['fr-fr'] = ""; +$text['label-upgrade_switch']['pt-br'] = ""; +$text['label-upgrade_switch']['pl'] = ""; +$text['label-upgrade_switch']['sv-se'] = ""; +$text['label-upgrade_switch']['uk'] = ""; +$text['label-upgrade_switch']['de-at'] = ""; + $text['label-upgrade']['en-us'] = "Upgrade"; $text['label-upgrade']['es-cl'] = "Actualizar"; $text['label-upgrade']['pt-pt'] = "Actualizar"; @@ -390,6 +400,16 @@ $text['description-upgrade_apps']['sv-se'] = "Återställer standardinställning $text['description-upgrade_apps']['uk'] = "Встановлює типові значення для додатків"; $text['description-upgrade_apps']['de-at'] = "Setzt alle Applikationen auf die Standardeinstellungen zurück."; +$text['description-upgrade_switch']['en-us'] = "Runs the upgrade switch routine."; +$text['description-upgrade_switch']['es-cl'] = ""; +$text['description-upgrade_switch']['pt-pt'] = ""; +$text['description-upgrade_switch']['fr-fr'] = ""; +$text['description-upgrade_switch']['pt-br'] = ""; +$text['description-upgrade_switch']['pl'] = ""; +$text['description-upgrade_switch']['sv-se'] = ""; +$text['description-upgrade_switch']['uk'] = ""; +$text['description-upgrade_switch']['de-at'] = ""; + $text['description-upgrade']['en-us'] = "Select the actions below you wish to perform."; $text['description-upgrade']['es-cl'] = "Seleccione las acciones a continuación que desea realizar."; $text['description-upgrade']['pt-pt'] = "Selecione as ações abaixo você deseja executar."; diff --git a/core/upgrade/index.php b/core/upgrade/index.php index ef686b4b33..376c7b54d8 100644 --- a/core/upgrade/index.php +++ b/core/upgrade/index.php @@ -35,6 +35,7 @@ if ( !permission_exists('upgrade_source') && !permission_exists('upgrade_schema') && !permission_exists('upgrade_apps') && + !permission_exists('upgrade_switch') && !permission_exists('menu_restore') && !permission_exists('group_edit') ) { @@ -52,7 +53,7 @@ if (sizeof($_POST) > 0) { // run source update if ($do["source"] && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) { - chdir("/var/www/fusionpbx/"); + chdir($_SERVER["DOCUMENT_ROOT"]); exec("git pull", $response_source_update); $update_failed = true; if (sizeof($response_source_update) > 0) { @@ -72,10 +73,8 @@ if (sizeof($_POST) > 0) { //update scripts folder, if allowed (default) if ($_SESSION['switch']['scripts']['dir'] != '') { //copy the files and directories from resources/install - $install = new install; - $install->domain_uuid = $domain_uuid; - $install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir']; - $install->copy_scripts(); + $obj = new install_switch; + $obj->upgrade(); //set the message $response_message = $text['message-upgrade_source_scripts']; } @@ -123,6 +122,13 @@ if (sizeof($_POST) > 0) { $response_message = "Permission Defaults Restored"; } + // upgrade switch + if ($do["switch"] && permission_exists("upgrade_switch")) { + $included = true; + require_once("core/install/upgrade_switch.php"); + $response_message = "Switch Upgraded"; + } + if (sizeof($_POST['do']) > 1) { $response_message = $text['message-upgrade']; } @@ -252,6 +258,22 @@ if (permission_exists("group_edit")) { echo "\n"; } +if (permission_exists("upgrade_switch")) { + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "
\n"; + echo " ".$text['label-upgrade_switch']; + echo " \n"; + echo " \n"; + echo "
\n"; +} + echo "
"; echo "
"; echo "

"; diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index 0a882c14c1..3698ef8332 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -67,7 +67,10 @@ $obj = new schema; echo $obj->schema("text"); -//run all app_defaults.php files +//request the switch to perform upgrade functions + $obj = new install_switch; + $obj->upgrade(); + require_once "resources/classes/domains.php"; $domain = new domains; $domain->upgrade(); diff --git a/index.php b/index.php index 0e64a38080..d8b23953cb 100644 --- a/index.php +++ b/index.php @@ -41,7 +41,7 @@ include "root.php"; } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { //bsd } else { - header("Location: ".PROJECT_PATH."/resources/install.php"); + header("Location: ".PROJECT_PATH."/core/install/install_first_time.php"); exit; } diff --git a/resources/classes/config.php b/resources/classes/config.php new file mode 100644 index 0000000000..a63ba0d03e --- /dev/null +++ b/resources/classes/config.php @@ -0,0 +1,127 @@ + $value) { + unset($this->$key); + } + } + + /** + * Determine whether the config.php exists + * @var string $db_type - type of database + * @var string $db_name - name of the database + * @var string $db_username - username to access the database + * @var string $db_password - password to access the database + * @var string $db_host - hostname of the database server + * @var string $db_path - path of the database file + * @var string $db_port - network port to connect to the database + */ + public function get() { + $this->find(); + if ($this->exists()) { + require $this->config_path; + $this->db_type = $db_type; + $this->db_name = $db_name; + $this->db_username = $db_username; + $this->db_password = $db_password; + $this->db_host = $db_host; + $this->db_path = $db_path; + $this->db_port = $db_port; + } + } + + /** + * Find the path to the config.php + * @var string $config_path - full path to the config.php file + */ + public function find() { + //get the PROJECT PATH + include "root.php"; + // find the file + if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { + $this->config_path = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php"; + } elseif (file_exists("/etc/fusionpbx/config.php")) { + $this->config_path = "/etc/fusionpbx/config.php"; + } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { + $this->config_path = "/usr/local/etc/fusionpbx/config.php"; + } + else { + $this->config_path = ''; + } + //return the path + return $this->config_path; + } + + /** + * Determine whether the config.php exists + */ + public function exists() { + $this->find(); + if (strlen($this->config_path) > 0) { + return true; + } + else { + return false; + } + } +} +/* +$config = new config; +$config_exists = $config->exists(); +$config_path = $config->find(); +$config->get(); +$db_type = $config->db_type; +$db_name = $config->db_name; +$db_username = $config->db_username; +$db_password = $config->db_password; +$db_host = $config->db_host; +$db_path = $config->db_path; +$db_port = $config->db_port; +echo "config_path: ".$config_path."\n"; +if ($config_exists) { + echo "config_exists: true\n"; +} else { + echo "config_exists: false\n"; +} +echo "db_type: ".$db_type."\n"; +echo "db_name: ".$db_name."\n"; +echo "db_username: ".$db_username."\n"; +echo "db_password: ".$db_password."\n"; +echo "db_host: ".$db_host."\n"; +echo "db_path: ".$db_path."\n"; +echo "db_port: ".$db_port."\n"; +*/ + +?> \ No newline at end of file diff --git a/resources/classes/domains.php b/resources/classes/domains.php index eecf800459..c0cc1e751f 100644 --- a/resources/classes/domains.php +++ b/resources/classes/domains.php @@ -186,36 +186,25 @@ //set the context $_SESSION["context"] = $_SESSION["domain_name"]; - //recordings add the domain to the path if there is more than one domains - if (count($_SESSION["domains"]) > 1) { - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - if (substr($_SESSION['switch']['recordings']['dir'], -strlen($_SESSION["domain_name"])) != $_SESSION["domain_name"]) { - //get the default recordings directory - $sql = "select * from v_default_settings "; - $sql .= "where default_setting_enabled = 'true' "; - $sql .= "and default_setting_category = 'switch' "; - $sql .= "and default_setting_subcategory = 'recordings' "; - $sql .= "and default_setting_name = 'dir' "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result_default_settings as $row) { - $name = $row['default_setting_name']; - $category = $row['default_setting_category']; - $subcategory = $row['default_setting_subcategory']; - $switch_recordings_dir = $row['default_setting_value']; - } - //add the domain - $_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir . '/' . $_SESSION["domain_name"]; - } - } - } } public function upgrade() { //set the global variable - global $db, $db_type, $db_name, $db_username, $db_password, $db_host, $db_path, $db_port; + global $db; + + //get the db variables + $config = new config; + $config_exists = $config->exists(); + $config_path = $config->find(); + $config->get(); + $db_type = $config->db_type; + $db_name = $config->db_name; + $db_username = $config->db_username; + $db_password = $config->db_password; + $db_host = $config->db_host; + $db_path = $config->db_path; + $db_port = $config->db_port; //get the PROJECT PATH include "root.php"; @@ -259,16 +248,6 @@ $prep_statement->execute(); $result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - //get the default recordings directory - foreach($result_default_settings as $row) { - $name = $row['default_setting_name']; - $category = $row['default_setting_category']; - $subcategory = $row['default_setting_subcategory']; - if ($category == 'switch' && $subcategory == 'recordings' && $name == 'dir') { - $switch_recordings_dir = $row['default_setting_value']; - } - } - //loop through all domains $sql = "select * from v_domains "; $v_prep_statement = $db->prepare(check_sql($sql)); @@ -336,11 +315,6 @@ } } - //set the recordings directory - if (strlen($switch_recordings_dir) > 1 && count($_SESSION["domains"]) > 1) { - $_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir."/".$domain_name; - } - //get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php $default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php"); foreach ($default_list as &$default_path) { @@ -356,6 +330,10 @@ if (function_exists('save_dialplan_xml')) { save_dialplan_xml(); } + //update config.lua + require_once "core/install/resources/classes/install_switch.php"; + $switch = new install_switch; + $switch->create_config_lua(); //clear the session variables unset($_SESSION['domain']); diff --git a/resources/classes/fax.php b/resources/classes/fax.php index bd936bdb01..195a0e8370 100644 --- a/resources/classes/fax.php +++ b/resources/classes/fax.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Copyright (C) 2010 + Copyright (C) 2010-2015 All Rights Reserved. Contributor(s): @@ -89,6 +89,7 @@ include "root.php"; //add the fax if (strlen($this->fax_extension) > 0) { + //add the dialplan $database = new database; $database->table = "v_dialplans"; @@ -190,12 +191,7 @@ include "root.php"; $database->fields['dialplan_detail_uuid'] = uuid(); $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction $database->fields['dialplan_detail_type'] = 'rxfax'; - if (count($_SESSION["domains"]) > 1) { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domains'][$row['domain_uuid']]['domain_name'].'/'.$this->fax_extension.'/inbox/${last_fax}.tif'; - } - else { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$this->fax_extension.'/inbox/${last_fax}.tif'; - } + $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domains'][$this->domain_uuid]['domain_name'].'/'.$this->fax_extension.'/inbox/${last_fax}.tif'; $database->fields['dialplan_detail_data'] = $dialplan_detail_data; $database->fields['dialplan_detail_order'] = '040'; $database->add(); @@ -322,7 +318,6 @@ include "root.php"; $database->update(); } else { -// $this->dialplan_uuid = uuid(); $database->fields['domain_uuid'] = $this->domain_uuid; $database->fields['dialplan_uuid'] = $this->dialplan_uuid; $database->add(); @@ -427,12 +422,7 @@ include "root.php"; $database->fields['dialplan_detail_uuid'] = uuid(); $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction $database->fields['dialplan_detail_type'] = 'rxfax'; - if (count($_SESSION["domains"]) > 1) { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domains'][$row['domain_uuid']]['domain_name'].'/'.$this->fax_extension.'/inbox/${last_fax}.tif'; - } - else { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$this->fax_extension.'/inbox/${last_fax}.tif'; - } + $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domains'][$this->domain_uuid]['domain_name'].'/'.$this->fax_extension.'/inbox/${last_fax}.tif'; $database->fields['dialplan_detail_data'] = $dialplan_detail_data; $database->fields['dialplan_detail_order'] = '040'; $database->add(); diff --git a/resources/classes/install.php b/resources/classes/install.php deleted file mode 100644 index a6b2d210b4..0000000000 --- a/resources/classes/install.php +++ /dev/null @@ -1,207 +0,0 @@ - - Copyright (C) 2010-2015 - All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ -include "root.php"; - -//define the install class - class install { - - var $result; - var $domain_uuid; - var $domain; - var $switch_conf_dir; - var $switch_scripts_dir; - var $switch_sounds_dir; - - //$options '-n' --no-clobber - public function recursive_copy($src, $dst, $options = '') { - if (file_exists('/bin/cp')) { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') { - //copy -R recursive, preserve attributes for SUN - $cmd = 'cp -Rp '.$src.'/* '.$dst; - } else { - //copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss - $cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst; - } - exec ($cmd); - //echo $cmd."\n"; - } - else { - $dir = opendir($src); - if (!$dir) { - if (!mkdir($src, 0755, true)) { - throw new Exception("recursive_copy() source directory '".$src."' does not exist."); - } - } - if (!is_dir($dst)) { - if (!mkdir($dst, 0755, true)) { - throw new Exception("recursive_copy() failed to create destination directory '".$dst."'"); - } - } - $scripts_dir_target = $_SESSION['switch']['scripts']['dir']; - $scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'); - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) { - if ( - substr_count($file_path_source, '/..') == 0 && - substr_count($file_path_source, '/.') == 0 && - substr_count($file_path_source, '/.svn') == 0 && - substr_count($file_path_source, '/.git') == 0 - ) { - if ($dst != $src.'/resources/config.lua') { - //echo $file_path_source.' ---> '.$dst.'
'; - copy($file_path_source, $dst); - chmod($dst, 0755); - } - } - } - - while(false !== ($file = readdir($dir))) { - if (($file != '.') && ($file != '..')) { - if (is_dir($src.'/'.$file)) { - $this->recursive_copy($src.'/'.$file, $dst.'/'.$file); - } - else { - //copy only missing files -n --no-clobber - if (strpos($options,'-n') !== false) { - if (!file_exists($dst.'/'.$file)) { - copy($src.'/'.$file, $dst.'/'.$file); - //echo "copy(".$src."/".$file.", ".$dst."/".$file.");
\n"; - } - } - else { - copy($src.'/'.$file, $dst.'/'.$file); - } - } - } - } - closedir($dir); - } - } - - function recursive_delete($dir) { - if (file_exists('/bin/rm')) { - exec ('rm -Rf '.$dir.'/*'); - } - else { - foreach (glob($dir) as $file) { - if (is_dir($file)) { - $this->recursive_delete("$file/*"); - rmdir($file); - //echo "rm dir: ".$file."\n"; - } else { - //echo "delete file: ".$file."\n"; - unlink($file); - } - } - } - clearstatcache(); - } - - function copy() { - $this->copy_scripts(); - //$this->copy_sounds(); - } - - function copy_conf() { - if (file_exists($this->switch_conf_dir)) { - //make a backup copy of the conf directory - $src_dir = $this->switch_conf_dir; - $dst_dir = $this->switch_conf_dir.'.orig'; - if (is_readable($src_dir)) { - $this->recursive_copy($src_dir, $dst_dir); - $this->recursive_delete($src_dir); - } - else { - if ($src_dir != "/conf") { - mkdir($src_dir, 0774, true); - } - } - //make sure the conf directory exists - if (!is_dir($this->switch_conf_dir)) { - if (!mkdir($this->switch_conf_dir, 0774, true)) { - throw new Exception("Failed to create the switch conf directory '".$this->switch_conf_dir."'. "); - } - } - //copy resources/templates/conf to the freeswitch conf dir - if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){ - $src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf"; - } - else { - $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf"; - } - $dst_dir = $this->switch_conf_dir; - if (is_readable($dst_dir)) { - $this->recursive_copy($src_dir, $dst_dir); - } - //print_r($install->result); - } - } - // added /examples/ into the string - function copy_scripts() { - if (file_exists($this->switch_scripts_dir)) { - if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){ - $src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts'; - } - else { - $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts'; - } - $dst_dir = $this->switch_scripts_dir; - if (is_readable($this->switch_scripts_dir)) { - $this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']); - unset($src_dir, $dst_dir); - } - chmod($dst_dir, 0774); - } - } - - //function copy_sounds() { - // if (file_exists($this->switch_sounds_dir)) { - // if (file_exists('/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/')){ - // $src_dir = '/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/'; - // changes the output dir for testing - // $dst_dir = $this->switch_sounds_dir.'/en/us/fusionpbx/custom/'; - // } - // else { - // $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sounds/en/us/callie/custom/'; - // $dst_dir = $this->switch_sounds_dir.'/en/us/callie/custom/'; - // } - // $this->recursive_copy($src_dir, $dst_dir, "-n"); - // if (is_readable($this->switch_sounds_dir)) { - // $this->recursive_copy($src_dir, $dst_dir); - // chmod($dst_dir, 0664); - // } - // } - //} - } - -//how to use the class - //$install = new install; - //$install->domain_uuid = $domain_uuid; - //$install->switch_conf_dir = $switch_conf_dir; - //$install->switch_scripts_dir = $switch_scripts_dir; - //$install->switch_sounds_dir = $switch_sounds_dir; - //$install->copy(); - //print_r($install->result); -?> \ No newline at end of file diff --git a/resources/classes/schema.php b/resources/classes/schema.php index df8f51835b..282d7dde05 100644 --- a/resources/classes/schema.php +++ b/resources/classes/schema.php @@ -448,8 +448,20 @@ include "root.php"; public function schema ($format) { //set the global variable - global $db, $db_type, $db_name, $db_username, $db_password; - global $db_host, $db_path, $db_port, $upgrade_data_types, $text; + global $db, $upgrade_data_types, $text; + + //get the db variables + $config = new config; + $config_exists = $config->exists(); + $config_path = $config->find(); + $config->get(); + $db_type = $config->db_type; + $db_name = $config->db_name; + $db_username = $config->db_username; + $db_password = $config->db_password; + $db_host = $config->db_host; + $db_path = $config->db_path; + $db_port = $config->db_port; //get the PROJECT PATH include "root.php"; diff --git a/resources/classes/text.php b/resources/classes/text.php index dcff4a97be..e873cea00b 100644 --- a/resources/classes/text.php +++ b/resources/classes/text.php @@ -1,19 +1,16 @@ $key); } } - /** * Get a specific item from the cache * @var string $language_code examples: en-us, es-cl, fr-fr, pt-pt * @var string $app_path examples: app/exec or core/domains */ public function get($language_code = null, $app_path = null) { + //get the global app_languages.php + include $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/core/app_languages.php"; //get the app_languages.php if ($app_path != null) { include $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/".$app_path."/app_languages.php"; @@ -37,7 +35,6 @@ class text { else { include getcwd().'/app_languages.php'; } - //get the available languages krsort($text); foreach ($text as $lang_label => $lang_codes) { @@ -48,24 +45,32 @@ class text { } } $_SESSION['app']['languages'] = array_unique($app_languages); - + //check the session language + if(isset($_SESSION['domain'])){ + $language_code = $_SESSION['domain']['language']['code']; + }elseif($language_code == null){ + $language_code = 'en-us'; + } //reduce to specific language if ($language_code != 'all') { foreach($text as $key => $value) { - if ($language_code == null) { - $text[$key] = $value[$_SESSION['domain']['language']['code']]; - } - else { - $text[$key] = $value[$language_code]; + $text[$key] = $value[$language_code]; + } + } + if ($language_code != 'all') { + foreach($language_name as $code => $value) { + $text["language-$code"] = $value; + } + }else{ + foreach($language_name as $code => $value) { + foreach($language_name as $c_code => $value) { + $text["language-$code"][$c_code] = $value; } } } - + //return the array of translations return $text; - } - } - ?> \ No newline at end of file diff --git a/resources/countries.php b/resources/countries.php new file mode 100644 index 0000000000..88f144c60a --- /dev/null +++ b/resources/countries.php @@ -0,0 +1,916 @@ + \ No newline at end of file diff --git a/resources/functions.php b/resources/functions.php index c1bd498810..04e6d1f3f1 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -600,6 +600,19 @@ } //echo realpath(sys_get_temp_dir()); + if ( !function_exists('normalize_path')) { + //don't use DIRECTORY_SEPARATOR as it will change on a per platform basis and we need consistency + function normalize_path($path) { + return str_replace(array('/','\\'), '/', $path); + } + } + + if ( !function_exists('normalize_path_to_os')) { + function normalize_path_to_os($path) { + return str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $path); + } + } + if (!function_exists('username_exists')) { function username_exists($username) { global $db, $domain_uuid; diff --git a/resources/install.php b/resources/install.php deleted file mode 100644 index 5680e4162d..0000000000 --- a/resources/install.php +++ /dev/null @@ -1,2113 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2014 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ -include "root.php"; -require_once "resources/functions.php"; - -//include required classes - require_once "resources/classes/text.php"; - -//set debug to true or false - $v_debug = true; - -//set the default domain_uuid - $_SESSION["domain_uuid"] = uuid(); - -//add the menu uuid - $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286'; - -//error reporting - ini_set('display_errors', '1'); - //error_reporting (E_ALL); // Report everything - error_reporting (E_ALL ^ E_NOTICE); // Report everything - //error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings - -//set the default time zone - date_default_timezone_set('UTC'); - -//if the config file exists then disable the install page - $config_exists = false; - if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { - $config_exists = true; - } elseif (file_exists("/etc/fusionpbx/config.php")) { - //linux - $config_exists = true; - } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { - $config_exists = true; - } - if ($config_exists) { - $msg .= "Already Installed"; - header("Location: ".PROJECT_PATH."/index.php?msg=".urlencode($msg)); - exit; - } - -//set the max execution time to 1 hour - ini_set('max_execution_time',3600); - -//save an install log if debug is true - if ($v_debug) { - $fp = fopen(sys_get_temp_dir()."/install.log", "w"); - } - -//set php variables with data from http post - $db_type = $_POST["db_type"]; - $admin_username = $_POST["admin_username"]; - $admin_password = $_POST["admin_password"]; - $db_name = $_POST["db_name"]; - $db_host = $_POST["db_host"]; - $db_port = $_POST["db_port"]; - $db_name = $_POST["db_name"]; - $domain_name = $_POST["domain_name"]; - $db_username = $_POST["db_username"]; - $db_password = $_POST["db_password"]; - $db_create_username = $_POST["db_create_username"]; - $db_create_password = $_POST["db_create_password"]; - $db_path = $_POST["db_path"]; - $install_step = $_POST["install_step"]; - $install_tmp_dir = $_POST["install_tmp_dir"]; - $install_backup_dir = $_POST["install_backup_dir"]; - $install_switch_base_dir = $_POST["install_switch_base_dir"]; - $install_default_country = $_POST["install_default_country"]; - $install_template_name = $_POST["install_template_name"]; - - if(!$domain_name){ - //get the domain - $domain_array = explode(":", $_SERVER["HTTP_HOST"]); - $domain_name = $domain_array[0]; - } - -//clean up the values - if (strlen($install_switch_base_dir) > 0) { - $install_switch_base_dir = realpath($install_switch_base_dir); - $install_switch_base_dir = str_replace("\\", "/", $install_switch_base_dir); - } - - $install_tmp_dir = realpath($_POST["install_tmp_dir"]); - $install_tmp_dir = str_replace("\\", "/", $install_tmp_dir); - - $install_backup_dir = realpath($_POST["install_backup_dir"]); - $install_backup_dir = str_replace("\\", "/", $install_backup_dir); - -//set the default db_name - if ($db_type == "sqlite") { - if (strlen($db_name) == 0) { $db_name = "fusionpbx.db"; } - } - -//set the required directories - - //set the freeswitch bin directory - if (file_exists('/usr/local/freeswitch/bin')) { - $install_switch_base_dir = '/usr/local/freeswitch'; - $switch_bin_dir = '/usr/local/freeswitch/bin'; - } - if (file_exists('/opt/freeswitch')) { - $install_switch_base_dir = '/opt/freeswitch'; - $switch_bin_dir = '/opt/freeswitch/bin'; - } - - //set the default startup script directory - if (file_exists('/usr/local/etc/rc.d')) { - $startup_script_dir = '/usr/local/etc/rc.d'; - } - if (file_exists('/etc/init.d')) { - $startup_script_dir = '/etc/init.d'; - } - - //set the default directories - $switch_bin_dir = $install_switch_base_dir.'/bin'; //freeswitch bin directory - $switch_conf_dir = $install_switch_base_dir.'/conf'; - $switch_db_dir = $install_switch_base_dir.'/db'; - $switch_log_dir = $install_switch_base_dir.'/log'; - $switch_mod_dir = $install_switch_base_dir.'/mod'; - $switch_extensions_dir = $switch_conf_dir.'/directory'; - $switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles'; - $switch_dialplan_dir = $switch_conf_dir.'/dialplan'; - $switch_scripts_dir = $install_switch_base_dir.'/scripts'; - $switch_grammar_dir = $install_switch_base_dir.'/grammar'; - $switch_storage_dir = $install_switch_base_dir.'/storage'; - $switch_voicemail_dir = $install_switch_base_dir.'/storage/voicemail'; - $switch_recordings_dir = $install_switch_base_dir.'/recordings'; - $switch_sounds_dir = $install_switch_base_dir.'/sounds'; - $install_tmp_dir = realpath(sys_get_temp_dir()); - $install_backup_dir = realpath(sys_get_temp_dir()); - $v_download_path = ''; - - //set specific alternative directories as required - switch (PHP_OS) { - case "Linux": - //set the default db_path - if (strlen($db_path) == 0) { - if (file_exists('/var/lib/fusionpbx/db')) { - $db_path = '/var/lib/fusionpbx/db'; - } - } - //set the other default directories - if (file_exists('/usr/bin')) { - $switch_bin_dir = '/usr/bin'; //freeswitch bin directory - } - //new - if (file_exists('/etc/fusionpbx/switch/conf')) { - $switch_conf_dir = '/etc/fusionpbx/switch/conf'; - $switch_extensions_dir = $switch_conf_dir.'/directory'; - $switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles'; - $switch_dialplan_dir = $switch_conf_dir.'/dialplan'; - } - //old - //if (file_exists('/etc/freeswitch/vars.xml')) { - // $switch_conf_dir = '/etc/freeswitch'; - // $switch_extensions_dir = $switch_conf_dir.'/directory'; - // $switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles'; - // $switch_dialplan_dir = $switch_conf_dir.'/dialplan'; - //} - if (file_exists('/var/lib/freeswitch/db')) { - $switch_db_dir = '/var/lib/freeswitch/db'; - } - if (file_exists('/var/log/freeswitch')) { - $switch_log_dir = '/var/log/freeswitch'; - } - if (file_exists('/usr/lib/freeswitch/mod')) { - $switch_mod_dir = '/usr/lib/freeswitch/mod'; - } - //new - if (file_exists('/var/lib/fusionpbx/scripts')) { - $switch_scripts_dir = '/var/lib/fusionpbx/scripts'; - } - //old - //if (file_exists('/usr/share/freeswitch/scripts')) { - // $switch_scripts_dir = '/usr/share/freeswitch/scripts'; - //} - //new - if (file_exists('/usr/share/freeswitch/grammar')) { - $switch_grammar_dir = '/usr/share/freeswitch/grammar'; - } - //old - //if (file_exists('/usr/share/freeswitch/grammar')) { - // $switch_grammar_dir = '/usr/share/freeswitch/grammar'; - //} - //new - if (file_exists('/var/lib/fusionpbx/storage')) { - $switch_storage_dir = '/var/lib/fusionpbx/storage'; - $switch_voicemail_dir = $switch_storage_dir.'/voicemail'; - } - //old - //if (file_exists('/var/lib/freeswitch/storage')) { - // $switch_storage_dir = '/var/lib/freeswitch/storage'; - // $switch_voicemail_dir = $switch_storage_dir.'/voicemail'; - //} - //new - if (file_exists('/var/lib/fusionpbx/recordings')) { - $switch_recordings_dir = '/var/lib/fusionpbx/recordings'; - } - //old - //if (file_exists('/var/lib/freeswitch/recordings')) { - // $switch_recordings_dir = '/var/lib/freeswitch/recordings'; - //} - if (file_exists('/usr/share/freeswitch/sounds')) { - $switch_sounds_dir = '/usr/share/freeswitch/sounds'; - } - break; - case "FreeBSD": - //if the FreeBSD port is installed use the following paths by default. - if (file_exists('/var/db/freeswitch')) { - //FreeBSD port - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = '/var/db/fusionpbx'; - if (!is_readable($db_path)) { mkdir($db_path,0774,true); } - } - //set the other default directories - $switch_bin_dir = '/usr/local/bin'; //freeswitch bin directory - $switch_conf_dir = '/usr/local/etc/freeswitch'; - $switch_db_dir = '/var/db/freeswitch'; - $switch_log_dir = '/var/log/freeswitch'; - $switch_mod_dir = '/usr/local/lib/freeswitch/mod'; - $switch_extensions_dir = $switch_conf_dir.'/directory'; - $switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles'; - $switch_dialplan_dir = $switch_conf_dir.'/dialplan'; - $switch_scripts_dir = '/var/cache/freeswitch/scripts'; - $switch_grammar_dir = '/usr/local/share/freeswitch/grammar'; - $switch_storage_dir = '/var/cache/freeswitch/storage'; - $switch_recordings_dir = '/var/cache/freeswitch/recordings'; - $switch_sounds_dir = '/usr/local/share/freeswitch/sounds'; - } - elseif (file_exists('/data/freeswitch')) { - //FreeBSD embedded - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = '/data/db/fusionpbx'; - if (!is_readable($db_path)) { mkdir($db_path,0777,true); } - } - //set the other default directories - $switch_bin_dir = '/usr/local/bin'; //freeswitch bin directory - $switch_conf_dir = '/usr/local/etc/freeswitch/conf'; - $switch_db_dir = '/data/freeswitch/db'; - if (is_readable('/var/log/freeswitch')) { - $switch_log_dir = '/var/log/freeswitch'; - } - else { - $switch_log_dir = '/data/freeswitch/log'; - } - $switch_mod_dir = '/usr/local/lib/freeswitch/mod'; - $switch_extensions_dir = $switch_conf_dir.'/directory'; - $switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles'; - $switch_dialplan_dir = $switch_conf_dir.'/dialplan'; - $switch_scripts_dir = '/usr/local/etc/freeswitch/scripts'; - $switch_grammar_dir = '/usr/local/etc/freeswitch/grammar'; - $switch_storage_dir = '/data/freeswitch'; - $switch_voicemail_dir = '/data/freeswitch/voicemail'; - $switch_recordings_dir = '/data/freeswitch/recordings'; - $switch_sounds_dir = '/data/freeswitch/sounds'; - } - else { - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; - } - } - break; - case "NetBSD": - $startup_script_dir = ''; - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; - } - break; - case "OpenBSD": - $startup_script_dir = ''; - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; - } - break; - default: - //set the default db_path - if (strlen($db_path) == 0) { - $db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; - } - } - // - // CYGWIN_NT-5.1 - // Darwin - // FreeBSD - // HP-UX - // IRIX64 - // Linux - // NetBSD - // OpenBSD - // SunOS - // Unix - // WIN32 - // WINNT - // Windows - // CYGWIN_NT-5.1 - // IRIX64 - // SunOS - // HP-UX - // OpenBSD (not in Wikipedia) - - //set the dir defaults for windows - if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") { - if (substr($_SERVER["DOCUMENT_ROOT"], -3) == "www") { - //integrated installer - $install_switch_base_dir = realpath($_SERVER["DOCUMENT_ROOT"]."/.."); - $startup_script_dir = ''; - } elseif (is_readable('C:/program files/FreeSWITCH')) { - $install_switch_base_dir = 'C:/program files/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('D:/program files/FreeSWITCH')) { - $install_switch_base_dir = 'D:/program files/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('E:/program files/FreeSWITCH')) { - $install_switch_base_dir = 'E:/program files/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('F:/program files/FreeSWITCH')) { - $install_switch_base_dir = 'F:/program files/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('C:/FreeSWITCH')) { - $install_switch_base_dir = 'C:/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('D:/FreeSWITCH')) { - $install_switch_base_dir = 'D:/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('E:/FreeSWITCH')) { - $install_switch_base_dir = 'E:/FreeSWITCH'; - $startup_script_dir = ''; - } elseif (is_readable('F:/FreeSWITCH')) { - $install_switch_base_dir = 'F:/FreeSWITCH'; - $startup_script_dir = ''; - } - } -$msg = ''; -if ($_POST["install_step"] == "2" && count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { - //check for all required data - if (strlen($admin_username) == 0) { $msg .= "Please provide the Admin Username
\n"; } - if (strlen($admin_password) == 0) { - $msg .= "Please provide the Admin Password
\n"; - } - else { - if (strlen($admin_password) < 5) { - $msg .= "Please provide an Admin Password that is 5 or more characters.
\n"; - } - } - //define the step to return to - if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { - $_POST["install_step"] = ""; - } -} -if ($_POST["install_step"] == "3" && count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { - //check for all required data - if (strlen($db_type) == 0) { $msg .= "Please provide the Database Type
\n"; } - if (PHP_OS == "FreeBSD" && file_exists('/usr/local/etc/freeswitch/conf')) { - //install_switch_base_dir not required for the freebsd freeswitch port; - } - if (strlen($install_tmp_dir) == 0) { $msg .= "Please provide the Temp Directory.
\n"; } - if (strlen($install_backup_dir) == 0) { $msg .= "Please provide the Backup Directory.
\n"; } - if (strlen($install_template_name) == 0) { $msg .= "Please provide the Theme.
\n"; } - //define the step to return to - if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { - $_POST["install_step"] = "2"; - } -} -//show the error message if one exists - if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { - require_once "resources/persist_form_var.php"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo $msg."
"; - echo "
\n"; - persistformvar($_POST); - echo "
\n"; - exit; - } - -if ($_POST["install_step"] == "3" && count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { - - //generate the config.php - $tmp_config = ""; - - if (is_dir("/etc/fusionpbx")){ - $config = "/etc/fusionpbx/config.php"; - } elseif (is_dir("/usr/local/etc/fusionpbx")){ - $config = "/usr/local/etc/fusionpbx/config.php"; - } - elseif (is_dir($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources")) { - $config = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php"; - } - else { - $config = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php"; - } - $fout = fopen($config,"w"); - fwrite($fout, $tmp_config); - unset($tmp_config); - fclose($fout); - - //include the new config.php file - require $config; - - //create the sqlite database - if ($db_type == "sqlite") { - //sqlite database will be created when the config.php is loaded and only if the database file does not exist - try { - $db_tmp = new PDO('sqlite:'.$db_path.'/'.$db_name); //sqlite 3 - //$db_tmp = new PDO('sqlite::memory:'); //sqlite 3 - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } - - //add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] ) - if (!function_exists('php_now')) { - function php_now() { - if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) { - @date_default_timezone_set(@date_default_timezone_get()); - } - return date("Y-m-d H:i:s"); - } - } - $db_tmp->sqliteCreateFunction('now', 'php_now', 0); - - //add the database structure - require_once "resources/classes/schema.php"; - $schema = new schema; - $schema->db = $db_tmp; - $schema->db_type = $db_type; - $schema->sql(); - $schema->exec(); - - //get the contents of the sql file - if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){ - $filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql"; - } - else { - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql'; - } - $file_contents = file_get_contents($filename); - unset($filename); - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $db_tmp->beginTransaction(); - $string_array = explode("\n", $file_contents); - $x = 0; - foreach($string_array as $sql) { - try { - $db_tmp->query($sql); - } - catch (PDOException $error) { - echo "error: " . $error->getMessage() . " sql: $sql
"; - //die(); - } - $x++; - } - unset ($file_contents, $sql); - $db_tmp->commit(); - - //set the file permissions - chmod($db_path.'/'.$db_name, 0777); - } - - //create the pgsql database - if ($db_type == "pgsql") { - - //echo "DB Name: {$db_name}
"; - //echo "DB Host: {$db_host}
"; - //echo "DB User: {$db_username}
"; - //echo "DB Pass: {$db_password}
"; - //echo "DB Port: {$db_port}
"; - //echo "DB Create User: {$db_create_username}
"; - //echo "DB Create Pass: {$db_create_password}
"; - - //if $db_create_username provided, attempt to create new PG role and database - if (strlen($db_create_username) > 0) { - try { - if (strlen($db_port) == 0) { $db_port = "5432"; } - if (strlen($db_host) > 0) { - $db_tmp = new PDO("pgsql:host={$db_host} port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1"); - } else { - $db_tmp = new PDO("pgsql:host=localhost port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1"); - } - } catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } - - //create the database, user, grant perms - $db_tmp->exec("CREATE DATABASE {$db_name}"); - $db_tmp->exec("CREATE USER {$db_username} WITH PASSWORD '{$db_password}'"); - $db_tmp->exec("GRANT ALL ON {$db_name} TO {$db_username}"); - - //close database connection_aborted - $db_tmp = null; - } - - //open database connection with $db_name - try { - if (strlen($db_port) == 0) { $db_port = "5432"; } - if (strlen($db_host) > 0) { - $db_tmp = new PDO("pgsql:host={$db_host} port={$db_port} dbname={$db_name} user={$db_username} password={$db_password}"); - } else { - $db_tmp = new PDO("pgsql:host=localhost port={$db_port} user={$db_username} password={$db_password} dbname={$db_name}"); - } - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
"; - die(); - } - - //add the database structure - require_once "resources/classes/schema.php"; - $schema = new schema; - $schema->db = $db_tmp; - $schema->db_type = $db_type; - $schema->sql(); - $schema->exec(); - - //get the contents of the sql file - if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){ - $filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql"; - } - else { - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql'; - } - $file_contents = file_get_contents($filename); - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $string_array = explode("\n", $file_contents); - $x = 0; - foreach($string_array as $sql) { - if (strlen($sql) > 3) { - try { - $db_tmp->query($sql); - } - catch (PDOException $error) { - echo "error: " . $error->getMessage() . " sql: $sql
"; - die(); - } - } - $x++; - } - unset ($file_contents, $sql); - } - - //create the mysql database - if ($db_type == "mysql") { - //database connection - try { - if (strlen($db_host) == 0 && strlen($db_port) == 0) { - //if both host and port are empty use the unix socket - if (strlen($db_create_username) == 0) { - $db_tmp = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); - } - else { - $db_tmp = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); - } - } - else { - if (strlen($db_port) == 0) { - //leave out port if it is empty - if (strlen($db_create_username) == 0) { - $db_tmp = new PDO("mysql:host=$db_host;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); - } - else { - $db_tmp = new PDO("mysql:host=$db_host;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); } - } - else { - if (strlen($db_create_username) == 0) { - $db_tmp = new PDO("mysql:host=$db_host;port=$db_port;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); - } - else { - $db_tmp = new PDO("mysql:host=$db_host;port=$db_port;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); - } - } - } - $db_tmp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $db_tmp->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //create the table, user and set the permissions only if the db_create_username was provided - if (strlen($db_create_username) > 0) { - //select the mysql database - try { - $db_tmp->query("USE mysql;"); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //create user and set the permissions - try { - $tmp_sql = "CREATE USER '".$db_username."'@'%' IDENTIFIED BY '".$db_password."'; "; - $db_tmp->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //set account to unlimited use - try { - if ($db_host == "localhost" || $db_host == "127.0.0.1") { - $tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'localhost' "; - $tmp_sql .= "IDENTIFIED BY '".$db_password."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $db_tmp->query($tmp_sql); - - $tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'127.0.0.1' "; - $tmp_sql .= "IDENTIFIED BY '".$db_password."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $db_tmp->query($tmp_sql); - } - else { - $tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'".$db_host."' "; - $tmp_sql .= "IDENTIFIED BY '".$db_password."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $db_tmp->query($tmp_sql); - } - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //create the database and set the create user with permissions - try { - $tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$db_name."; "; - $db_tmp->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //set user permissions - try { - $db_tmp->query("GRANT ALL PRIVILEGES ON ".$db_name.".* TO '".$db_username."'@'%'; "); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //make the changes active - try { - $tmp_sql = "FLUSH PRIVILEGES; "; - $db_tmp->query($tmp_sql); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - } //if (strlen($db_create_username) > 0) - - //select the database - try { - $db_tmp->query("USE ".$db_name.";"); - } - catch (PDOException $error) { - if ($v_debug) { - print "error: " . $error->getMessage() . "
"; - } - } - - //add the database structure - require_once "resources/classes/schema.php"; - $schema = new schema; - $schema->db = $db_tmp; - $schema->db_type = $db_type; - $schema->sql(); - $schema->exec(); - - //add the defaults data into the database - //get the contents of the sql file - if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql')){ - $filename = "/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql"; - } - else { - $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql'; - } - $file_contents = file_get_contents($filename); - - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); - - //loop line by line through all the lines of sql code - $string_array = explode("\n", $file_contents); - $x = 0; - foreach($string_array as $sql) { - if (strlen($sql) > 3) { - try { - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->query($sql); - } - catch (PDOException $error) { - //echo "error on line $x: " . $error->getMessage() . " sql: $sql
"; - //die(); - } - } - $x++; - } - unset ($file_contents, $sql); - } - - //replace back slashes with forward slashes - $install_switch_base_dir = str_replace("\\", "/", $install_switch_base_dir); - $startup_script_dir = str_replace("\\", "/", $startup_script_dir); - $install_tmp_dir = str_replace("\\", "/", $install_tmp_dir); - $install_backup_dir = str_replace("\\", "/", $install_backup_dir); - - //add the domain - $sql = "insert into v_domains "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "domain_name, "; - $sql .= "domain_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$_SESSION["domain_uuid"]."', "; - $sql .= "'".$domain_name."', "; - $sql .= "'' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - - //get the web server protocol - //$install_server_protocol = $_SERVER["SERVER_PORT"]; - //$server_protocol_array = explode('/', $_SERVER["SERVER_PROTOCOL"]); - //$install_server_protocol = strtolower($server_protocol[0]); - //unset($server_protocol_array); - - //add the default settings - $x = 0; - $tmp[$x]['name'] = 'uuid'; - $tmp[$x]['value'] = $menu_uuid; - $tmp[$x]['category'] = 'domain'; - $tmp[$x]['subcategory'] = 'menu'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'name'; - $tmp[$x]['category'] = 'domain'; - $tmp[$x]['subcategory'] = 'time_zone'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'code'; - $tmp[$x]['value'] = 'en-us'; - $tmp[$x]['category'] = 'domain'; - $tmp[$x]['subcategory'] = 'language'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'iso_code'; - $tmp[$x]['value'] = $install_default_country; - $tmp[$x]['category'] = 'domain'; - $tmp[$x]['subcategory'] = 'country'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'name'; - $tmp[$x]['value'] = $install_template_name; - $tmp[$x]['category'] = 'domain'; - $tmp[$x]['subcategory'] = 'template'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $install_tmp_dir; - $tmp[$x]['category'] = 'server'; - $tmp[$x]['subcategory'] = 'temp'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $startup_script_dir; - $tmp[$x]['category'] = 'server'; - $tmp[$x]['subcategory'] = 'startup_script'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $install_backup_dir; - $tmp[$x]['category'] = 'server'; - $tmp[$x]['subcategory'] = 'backup'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_bin_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'bin'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $install_switch_base_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'base'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_conf_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'conf'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_db_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'db'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_log_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'log'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_extensions_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'extensions'; - $tmp[$x]['enabled'] = 'false'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_sip_profiles_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'sip_profiles'; - $tmp[$x]['enabled'] = 'false'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_dialplan_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'dialplan'; - $tmp[$x]['enabled'] = 'false'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_mod_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'mod'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_scripts_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'scripts'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_grammar_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'grammar'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_storage_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'storage'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_voicemail_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'voicemail'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_recordings_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'recordings'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = $switch_sounds_dir; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'sounds'; - $tmp[$x]['enabled'] = 'true'; - $x++; - $tmp[$x]['name'] = 'dir'; - $tmp[$x]['value'] = ''; - $tmp[$x]['category'] = 'switch'; - $tmp[$x]['subcategory'] = 'provision'; - $tmp[$x]['enabled'] = 'false'; - $x++; - $db_tmp->beginTransaction(); - foreach($tmp as $row) { - $sql = "insert into v_default_settings "; - $sql .= "("; - $sql .= "default_setting_uuid, "; - $sql .= "default_setting_name, "; - $sql .= "default_setting_value, "; - $sql .= "default_setting_category, "; - $sql .= "default_setting_subcategory, "; - $sql .= "default_setting_enabled "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['name']."', "; - $sql .= "'".$row['value']."', "; - $sql .= "'".$row['category']."', "; - $sql .= "'".$row['subcategory']."', "; - $sql .= "'".$row['enabled']."' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - } - $db_tmp->commit(); - unset($tmp); - - //get the list of installed apps from the core and mod directories - $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); - $x=0; - foreach ($config_list as $config_path) { - include($config_path); - $x++; - } - - //add the groups - $x = 0; - $tmp[$x]['group_name'] = 'superadmin'; - $tmp[$x]['group_description'] = 'Super Administrator Group'; - $x++; - $tmp[$x]['group_name'] = 'admin'; - $tmp[$x]['group_description'] = 'Administrator Group'; - $x++; - $tmp[$x]['group_name'] = 'user'; - $tmp[$x]['group_description'] = 'User Group'; - $x++; - $tmp[$x]['group_name'] = 'public'; - $tmp[$x]['group_description'] = 'Public Group'; - $x++; - $tmp[$x]['group_name'] = 'agent'; - $tmp[$x]['group_description'] = 'Call Center Agent Group'; - $db_tmp->beginTransaction(); - foreach($tmp as $row) { - $sql = "insert into v_groups "; - $sql .= "("; - $sql .= "group_uuid, "; - $sql .= "group_name, "; - $sql .= "group_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['group_name']."', "; - $sql .= "'".$row['group_description']."' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - } - unset($tmp); - $db_tmp->commit(); - - //add a user and then add the user to the superadmin group - //prepare the values - $user_uuid = uuid(); - $contact_uuid = uuid(); - //set a sessiong variable - $_SESSION["user_uuid"] = $user_uuid; - //salt used with the password to create a one way hash - $salt = generate_password('20', '4'); - //add the user account - $sql = "insert into v_users "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "user_uuid, "; - $sql .= "contact_uuid, "; - $sql .= "username, "; - $sql .= "password, "; - $sql .= "salt, "; - $sql .= "add_date, "; - $sql .= "add_user "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$_SESSION["domain_uuid"]."', "; - $sql .= "'$user_uuid', "; - $sql .= "'$contact_uuid', "; - $sql .= "'".$admin_username."', "; - $sql .= "'".md5($salt.$admin_password)."', "; - $sql .= "'$salt', "; - $sql .= "now(), "; - $sql .= "'".$admin_username."' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - - //add to contacts - $sql = "insert into v_contacts "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "contact_uuid, "; - $sql .= "contact_type, "; - $sql .= "contact_name_given, "; - $sql .= "contact_nickname "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$_SESSION["domain_uuid"]."', "; - $sql .= "'$contact_uuid', "; - $sql .= "'user', "; - $sql .= "'$admin_username', "; - $sql .= "'$admin_username' "; - $sql .= ")"; - $db_tmp->exec(check_sql($sql)); - unset($sql); - - //add the user to the superadmin group - $sql = "insert into v_group_users "; - $sql .= "("; - $sql .= "group_user_uuid, "; - $sql .= "domain_uuid, "; - $sql .= "user_uuid, "; - $sql .= "group_name "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$_SESSION["domain_uuid"]."', "; - $sql .= "'".$_SESSION["user_uuid"]."', "; - $sql .= "'superadmin' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - - //assign the default permissions to the groups - $db_tmp->beginTransaction(); - foreach($apps as $app) { - if ($app['permissions']) { - foreach ($app['permissions'] as $row) { - if ($v_debug) { - fwrite($fp, "v_group_permissions\n"); - fwrite($fp, json_encode($row)."\n\n"); - } - if ($row['groups']) { - foreach ($row['groups'] as $group) { - //add the record - $sql = "insert into v_group_permissions "; - $sql .= "("; - $sql .= "group_permission_uuid, "; - $sql .= "permission_name, "; - $sql .= "group_name "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['name']."', "; - $sql .= "'".$group."' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db_tmp->exec(check_sql($sql)); - unset($sql); - } - } - } - } - } - $db_tmp->commit(); - - //unset the temporary database connection - unset($db_tmp); - - //include additional files - require "resources/require.php"; - - //set the defaults - $menu_name = 'default'; - $menu_language = 'en-us'; - $menu_description = ''; - //add the parent menu - $sql = "insert into v_menus "; - $sql .= "("; - $sql .= "menu_uuid, "; - $sql .= "menu_name, "; - $sql .= "menu_language, "; - $sql .= "menu_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$menu_uuid."', "; - $sql .= "'$menu_name', "; - $sql .= "'$menu_language', "; - $sql .= "'$menu_description' "; - $sql .= ");"; - if ($v_debug) { - fwrite($fp, $sql."\n"); - } - $db->exec(check_sql($sql)); - unset($sql); - - //add the menu items - require_once "resources/classes/menu.php"; - $menu = new menu; - $menu->db = $db; - $menu->menu_uuid = $menu_uuid; - $menu->restore(); - unset($menu); - - //setup the switch config directory if it exists - if (file_exists($switch_conf_dir) && $switch_conf_dir != "/conf") { - if ($v_debug) { - fwrite($fp, "switch_base_dir: ".$install_switch_base_dir."\n"); - fwrite($fp, "switch_conf_dir: ".$switch_conf_dir."\n"); - fwrite($fp, "switch_dialplan_dir: ".$switch_dialplan_dir."\n"); - fwrite($fp, "switch_scripts_dir: ".$switch_scripts_dir."\n"); - fwrite($fp, "switch_sounds_dir: ".$switch_sounds_dir."\n"); - fwrite($fp, "switch_recordings_dir: ".$switch_recordings_dir."\n"); - } - - //create the necessary directories - if (!is_readable($install_tmp_dir)) { mkdir($install_tmp_dir,0777,true); } - if (!is_readable($install_backup_dir)) { mkdir($install_backup_dir,0777,true); } - if (is_readable($switch_log_dir)) { - if (!is_readable($switch_scripts_dir.'') && $switch_scripts_dir != "/scripts") { mkdir($switch_scripts_dir.'',0777,true); } - // if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/8000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/8000',0777,true); } - // if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/16000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/16000',0777,true); } - // if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/32000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/32000',0777,true); } - // if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/48000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/48000',0777,true); } - if (!is_readable($switch_storage_dir.'/fax/') && $switch_scripts_dir != "/storage") { mkdir($switch_storage_dir.'/fax',0777,true); } - if (!is_readable($switch_recordings_dir.'') && $switch_scripts_dir != "/recordings") { mkdir($switch_recordings_dir.'',0777,true); } - } - - //copy the files and directories from resources/install - require_once "resources/classes/install.php"; - $install = new install; - $install->domain_uuid = $_SESSION["domain_uuid"]; - $install->domain = $domain_name; - $install->switch_conf_dir = $switch_conf_dir; - $install->switch_scripts_dir = $switch_scripts_dir; - // $install->switch_sounds_dir = $switch_sounds_dir; - $install->copy_conf(); - $install->copy(); - - //create the dialplan/default.xml for single tenant or dialplan/domain.xml - if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) { - $dialplan = new dialplan; - $dialplan->domain_uuid = $_SESSION["domain_uuid"]; - $dialplan->domain = $domain_name; - $dialplan->switch_dialplan_dir = $switch_dialplan_dir; - $dialplan->restore_advanced_xml(); - //print_r($dialplan->result); - } - - //write the xml_cdr.conf.xml file - if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/xml_cdr")) { - xml_cdr_conf_xml(); - } - - //write the switch.conf.xml file - if (file_exists($switch_conf_dir)) { - switch_conf_xml(); - } - } - - //login the user account - $_SESSION["username"] = $admin_username; - - //get the groups assigned to the user and then set the groups in $_SESSION["groups"] - $sql = "SELECT * FROM v_group_users "; - $sql .= "where domain_uuid=:domain_uuid "; - $sql .= "and user_uuid=:user_uuid "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"]); - $prep_statement->bindParam(':user_uuid', $_SESSION["user_uuid"]); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $_SESSION["groups"] = $result; - unset($sql, $row_count, $prep_statement); - - //get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions'] - $x = 0; - $sql = "select distinct(permission_name) from v_group_permissions "; - foreach($_SESSION["groups"] as $field) { - if (strlen($field['group_name']) > 0) { - if ($x == 0) { - $sql .= "where (domain_uuid = '".$_SESSION["domain_uuid"]."' and group_name = '".$field['group_name']."') "; - } - else { - $sql .= "or (domain_uuid = '".$_SESSION["domain_uuid"]."' and group_name = '".$field['group_name']."') "; - } - $x++; - } - } - $prep_statementsub = $db->prepare($sql); - $prep_statementsub->execute(); - $_SESSION['permissions'] = $prep_statementsub->fetchAll(PDO::FETCH_NAMED); - unset($sql, $prep_statementsub); - - //make sure the database schema and installation have performed all necessary tasks - $display_results = false; - $display_type = 'none'; - require_once "resources/classes/schema.php"; - $obj = new schema; - $obj->schema($db, $db_type, $db_name, $display_type); - - //run all app_defaults.php files - require_once "resources/classes/domains.php"; - $domain = new domains; - $domain->upgrade(); - - //synchronize the config with the saved settings - save_switch_xml(); - - //do not show the apply settings reminder on the login page - $_SESSION["reload_xml"] = false; - - //clear the menu - $_SESSION["menu"] = ""; - - //redirect to the login page - $msg = "install complete"; - header("Location: ".PROJECT_PATH."/logout.php?msg=".urlencode($msg)); -} - -//set a default template - if (strlen($_SESSION['domain']['template']['name']) == 0) { $_SESSION['domain']['template']['name'] = 'enhanced'; } - -//get the contents of the template and save it to the template variable - $template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$_SESSION['domain']['template']['name'].'/template.php'); - -//buffer the content - ob_end_clean(); //clean the buffer - ob_start(); - -//show the html form - if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/header.php")) { - $install_msg .= "
  • Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/ is required during the install.
  • \n"; - } - if (!extension_loaded('PDO')) { - $install_msg .= "
  • PHP PDO was not detected. Please install it before proceeding.
  • "; - } - - if ($install_msg) { - echo "
    \n"; - echo "
    \n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
    Message
      $install_msg
    \n"; - echo "
    \n"; - } - - echo "
    \n"; - $msg = ''; - //make sure the includes directory is writable so the config.php file can be written. - if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/pdo.php")) { - $msg .= "Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."
    "; - $msg .= "and its sub-directories are required during the install.

    \n"; - } - - //display the message - if (strlen($msg) > 0) { - //echo "not writable"; - echo $msg; - echo "
    \n"; - echo "
    \n"; - unset($msg); - //exit; - } - -// step 1 - if ($_POST["install_step"] == "") { - echo "
    \n"; - echo "
    \n"; - echo "\n"; - - //echo "\n"; - //echo "\n"; - //echo "\n"; - echo "\n"; - echo "\n"; - echo " \n"; - //echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - //echo "\n"; - echo "\n"; - - $db_type = $_POST["db_type"]; - $install_step = $_POST["install_step"]; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo " \n"; - echo " \n"; - echo " "; - - echo "
    Installation
    \n"; - echo " The installation is a simple two step process. \n"; - echo "
      \n"; - echo "
    • Step 1 is used for selecting the database engine to use. After making that section then ensure the paths are correct and then press next.
    • "; - echo "
    • Step 2 requests the database specific settings. When finished press save. The installation will then complete the tasks required to do the install.
    Step 1 
    \n"; - echo " Database Type\n"; - echo "\n"; - echo "
    \n"; - echo " Select the database type.\n"; - echo "\n"; - echo "
    \n"; - echo " Username\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the username to use when logging in with the browser.
    \n"; - echo "
    \n"; - echo " Password\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the password to use when logging in with the browser.
    \n"; - echo "
    \n"; - echo " Country\n"; - echo "\n"; - echo " \n"; - echo "
    \n"; - echo " Select ISO country code used to initialize calling contry code variables.
    \n"; - echo "
    \n"; - echo " Theme: \n"; - echo " \n"; - echo " \n"; - echo "
    \n"; - echo " Select a theme to set as the default.
    \n"; - echo "
    \n"; - echo " Domain name\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the default domain name. \n"; - echo "\n"; - echo "
    \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
    "; - echo "
    "; - echo "
    "; - } - -// step 2, sqlite - if ($_POST["install_step"] == "2" && $_POST["db_type"] == "sqlite") { - echo "
    \n"; - echo "
    \n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo " \n"; - echo " \n"; - echo " "; - - echo "
    Installation: Step 2 - SQLite
    \n"; - echo " Database Filename\n"; - echo "\n"; - echo "
    \n"; - echo " Set the database filename. The file extension should be '.db'.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Directory\n"; - echo "\n"; - echo "
    \n"; - echo " Set the path to the database directory.\n"; - echo "
    \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
    "; - echo "
    "; - echo "
    "; - } - -// step 2, mysql - if ($_POST["install_step"] == "2" && $_POST["db_type"] == "mysql") { - - //set defaults - if (strlen($db_host) == 0) { $db_host = 'localhost'; } - if (strlen($db_port) == 0) { $db_port = '3306'; } - //if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; } - - //echo "However if preferred the database can be created manually with the mysql.sql script. "; - echo "
    \n"; - echo "
    \n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo " \n"; - echo " \n"; - echo " "; - - echo "
    Installation: Step 2 - MySQL
    \n"; - echo " Database Host\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the host address for the database server.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Port\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the port number. It is optional if the database is using the default port.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Name\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the name of the database.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Username\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the database username. \n"; - echo "\n"; - echo "
    \n"; - echo " Database Password\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the database password.\n"; - echo "\n"; - echo "
    \n"; - echo " Create Database Username\n"; - echo "\n"; - echo "
    \n"; - echo " Optional, this username is used to create the database, a database user and set the permissions. \n"; - echo " By default this username is 'root' however it can be any account with permission to add a database, user, and grant permissions. \n"; - echo "
    \n"; - echo " Create Database Password\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the create database password.\n"; - echo "\n"; - echo "
    \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
    "; - echo "
    "; - echo "
    "; - } - -// step 2, pgsql - if ($_POST["install_step"] == "2" && $_POST["db_type"] == "pgsql") { - if (strlen($db_host) == 0) { $db_host = 'localhost'; } - if (strlen($db_port) == 0) { $db_port = '5432'; } - if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; } - - echo "
    \n"; - echo "
    \n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo " \n"; - echo " \n"; - echo " "; - - echo "
    Installation: Step 2 - Postgres
    \n"; - echo " Database Host\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the host address for the database server.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Port\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the port number. It is optional if the database is using the default port.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Name\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the name of the database.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Username\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the database username.\n"; - echo "\n"; - echo "
    \n"; - echo " Database Password\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the database password.\n"; - echo "\n"; - echo "
    \n"; - echo " Create Database Username\n"; - echo "\n"; - echo "
    \n"; - echo " Optional, this username is used to create the database, a database user and set the permissions. \n"; - echo " By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n"; - echo " Leave blank if the user and empty database already exist and you do not want them created. \n"; - echo "
    \n"; - echo " Create Database Password\n"; - echo "\n"; - echo "
    \n"; - echo " Enter the create database password.\n"; - echo "\n"; - echo "
    \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
    "; - echo "
    "; - echo "
    "; - } - - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - -// add the content to the template and then send output - $body = $content_from_db.ob_get_contents(); //get the output from the buffer - ob_end_clean(); //clean the buffer - - ob_start(); - eval('?>' . $template . '", $custom_title, $template); // defined in each individual page - $output = str_replace ("", $custom_head, $output); // defined in each individual page - $output = str_replace ("", $_SESSION["menu"], $output); //defined in /resources/menu.php - $output = str_replace ("", PROJECT_PATH, $output); //defined in /resources/menu.php - - $pos = strrpos($output, ""); - if ($pos === false) { - $output = $body; //if tag not found just show the body - } - else { - //replace the body - $output = str_replace ("", $body, $output); - } - - echo $output; - unset($output); - -?> diff --git a/resources/install/scripts/app/conference_center/index.lua b/resources/install/scripts/app/conference_center/index.lua index 395db64a75..08d43c42a6 100644 --- a/resources/install/scripts/app/conference_center/index.lua +++ b/resources/install/scripts/app/conference_center/index.lua @@ -148,6 +148,7 @@ default_language = session:getVariable("default_language"); default_dialect = session:getVariable("default_dialect"); --recording = session:getVariable("recording"); + domain_name = session:getVariable("domain_name"); --set the end epoch end_epoch = os.time(); @@ -339,6 +340,9 @@ --freeswitch.consoleLog("notice", "[conference center] destination_number: " .. destination_number .. "\n"); --freeswitch.consoleLog("notice", "[conference center] caller_id_number: " .. caller_id_number .. "\n"); + --add the domain name to the recordings directory + recordings_dir = recordings_dir .. "/"..domain_name; + --set the sounds path for the language, dialect and voice default_language = session:getVariable("default_language"); default_dialect = session:getVariable("default_dialect"); @@ -411,10 +415,6 @@ --add the domain to the recording directory freeswitch.consoleLog("notice", "[conference center] domain_count: " .. domain_count .. "\n"); - if (domain_count > 1) then - recordings_dir = recordings_dir.."/"..domain_name; - freeswitch.consoleLog("notice", "[conference center] recordings_dir: " .. recordings_dir .. "\n"); - end --sounds enter_sound = "tone_stream://v=-20;%(100,1000,100);v=-20;%(90,60,440);%(90,60,620)"; @@ -707,7 +707,7 @@ --there is one other member in this conference session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/conference/conf-one_other_member_conference.wav"); elseif (member_count == "0") then - session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/conference/conf-alone.wav"); + --conference profile defines the alone sound file else --say the count session:execute("say", default_language.." number pronounced "..member_count); diff --git a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua index b30412451d..047619cadb 100644 --- a/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua +++ b/resources/install/scripts/app/conference_center/resources/scripts/start_recording.lua @@ -36,10 +36,8 @@ --get the current time start_epoch = os.time(); - --set the recording variable - if (domain_count > 1) then - recordings_dir = recordings_dir.."/"..domain_name; - end + --add the domain name to the recordings directory + recordings_dir = recordings_dir .. "/"..domain_name; recordings_dir = recordings_dir.."/archive/"..os.date("%Y", start_epoch).."/"..os.date("%b", start_epoch).."/"..os.date("%d", start_epoch); mkdir(recordings_dir); recording = recordings_dir.."/"..conference_session_uuid; diff --git a/resources/install/scripts/app/dialplan/index.lua b/resources/install/scripts/app/dialplan/index.lua index fbd3892031..b173b2ca57 100644 --- a/resources/install/scripts/app/dialplan/index.lua +++ b/resources/install/scripts/app/dialplan/index.lua @@ -36,7 +36,6 @@ destination_number = session:getVariable("destination_number"); call_direction = session:getVariable("call_direction"); domain_name = session:getVariable("domain_name"); - recordings_dir = session:getVariable("recordings_dir"); --determine the call direction if (call_direction == nil) then diff --git a/resources/install/scripts/app/event_notify/index.lua b/resources/install/scripts/app/event_notify/index.lua index 827ddfe664..b32ecd5f93 100644 --- a/resources/install/scripts/app/event_notify/index.lua +++ b/resources/install/scripts/app/event_notify/index.lua @@ -67,6 +67,16 @@ --cisco if (vendor == "cisco") then + if (command == "reboot") then + event:addHeader('event-string', 'check-sync'); + end + if (command == "check_sync") then + event:addHeader('event-string', 'check-sync'); + end + end + +--cisco-spa + if (vendor == "cisco-spa") then if (command == "reboot") then event:addHeader('event-string', 'reboot=true'); end @@ -85,6 +95,16 @@ end end +--linksys + if (vendor == "linksys") then + if (command == "reboot") then + event:addHeader('event-string', 'reboot=true'); + end + if (command == "check_sync") then + event:addHeader('event-string', 'reboot=true'); + end + end + --polycom if (vendor == "polycom") then if (command == "reboot") then diff --git a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua index 81ac0ffd13..628822955c 100644 --- a/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua +++ b/resources/install/scripts/app/fax/resources/scripts/hangup_rx.lua @@ -41,6 +41,16 @@ --array count require "resources.functions.count"; + local IS_WINDOWS = (package.config:sub(1,1) == '\\') + + local function quote(s) + local q = IS_WINDOWS and '"' or "'" + if s:find('%s') or s:find(q, nil, true) then + s = q .. s:gsub(q, q..q) .. q + end + return s + end + -- set channel variables to lua variables domain_uuid = env:getHeader("domain_uuid"); domain_name = env:getHeader("domain_name"); @@ -181,23 +191,17 @@ end --fax to email - cmd = "'"..php_dir.."/"..php_bin.."' '"..document_root.."/secure/fax_to_email.php' "; - cmd = cmd .. "email='"..fax_email.."' "; - cmd = cmd .. "extension="..fax_extension.." "; - cmd = cmd .. "name='"..fax_file.."' "; - cmd = cmd .. "messages='result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages.."' "; - cmd = cmd .. "domain="..domain_name.." "; - cmd = cmd .. "caller_id_name='"; - if (caller_id_name ~= nil) then - cmd = cmd .. caller_id_name; - end - cmd = cmd .. "' "; - cmd = cmd .. "caller_id_number="; - if (caller_id_number ~= nil) then - cmd = cmd .. caller_id_number; - end - cmd = cmd .. " "; - if (string.len(fax_forward_number) > 0) then + + -- cmd = "lua" .. " " .. quote(scripts_dir .. "/fax_to_email.lua") .. " "; + cmd = quote(php_dir.."/"..php_bin).." "..quote(document_root.."/secure/fax_to_email.php").." "; + cmd = cmd .. "email="..quote(fax_email).." "; + cmd = cmd .. "extension="..quote(fax_extension).." "; + cmd = cmd .. "name="..quote(fax_file).." "; + cmd = cmd .. "messages=" .. quote("result:"..fax_result_text.." sender:"..fax_remote_station_id.." pages:"..fax_document_total_pages).." "; + cmd = cmd .. "domain="..quote(domain_name).." "; + cmd = cmd .. "caller_id_name=" .. quote(caller_id_name or '') .. " "; + cmd = cmd .. "caller_id_number=" .. quote(caller_id_number or '') .. " "; + if #fax_forward_number > 0 then cmd = cmd .. "fax_relay=true "; end freeswitch.consoleLog("notice", "[fax] command: " .. cmd .. "\n"); diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/exec.lua b/resources/install/scripts/app/fax/resources/scripts/queue/exec.lua new file mode 100644 index 0000000000..5ff3fab443 --- /dev/null +++ b/resources/install/scripts/app/fax/resources/scripts/queue/exec.lua @@ -0,0 +1,187 @@ +-- @usage without queue +-- api: originate {fax_file='',wav_file='',fax_dtmf=''}user/108@domain.local &lua(app/fax/resources/scripts/queue/exec.lua) +-- @usage with queue task +-- api: originate {fax_task_uuid=''}user/108@domain.local &lua(app/fax/resources/scripts/queue/exec.lua) +-- @fax_dtmf +-- 0-9*# - dtmf symbols +-- @200 - dtmf duration in ms +-- p - pause 500 ms +-- P - pause 1000 ms +-- +-- example: pause 5 sec dial 008 pause 2 sec paly greeting +-- PPPPP008@300PP +-- + +require "resources.functions.config" +local log = require "resources.functions.log".fax_task + +-- If we handle queue task +local fax_task_uuid = session:getVariable('fax_task_uuid') +local task if fax_task_uuid then + local Tasks = require "app.fax.resources.scripts.queue.tasks" + task = Tasks.select_task(fax_task_uuid) + if not task then + log.warningf("Can not found fax task: %q", tostring(fax_task_uuid)) + return + end +end + +if task then + local str = 'Queue task :' + for k, v in pairs(task) do + str = str .. ('\n %q = %q'):format(k, v) + end + log.info(str) +else + log.info('Not queued task') +end + +local function empty(t) return (not t) or (#t == 0) end + +local function not_empty(t) if not empty(t) then return t end end + +local dtmf, wav_file, fax_file + +if task then + dtmf = not_empty(task.dtmf) + wav_file = not_empty(task.wav_file) or not_empty(task.greeting) + fax_file = not_empty(task.fax_file) +else + dtmf = not_empty(session:getVariable('fax_dtmf')) + wav_file = not_empty(session:getVariable('wav_file')) + fax_file = not_empty(session:getVariable('fax_file')) +end + +if not (wav_file or fax_file) then + log.warning("No fax or wav file") + return +end + +local function decode_dtmf(dtmf) + local r, sleep, seq = {} + dtmf:gsub('P', 'pp'):gsub('.', function(ch) + if ch == ';' or ch == ',' then + r[#r + 1] = sleep or seq + sleep, seq = nil + elseif ch == 'p' then + r[#r + 1] = seq + sleep = (sleep or 0) + 500 + seq = nil + else + r[#r + 1] = sleep + seq = (seq or '') .. ch + sleep = nil + end + end) + r[#r + 1] = sleep or seq + return r +end + +local function send_fax() + session:execute("txfax", fax_file) +end + +local function start_fax_detect(detect_duration) + if not tone_detect_cb then + function tone_detect_cb(s, type, obj, arg) + if type == "event" then + if obj:getHeader('Event-Name') == 'DETECTED_TONE' then + return "false" + end + end + end + end + + log.notice("Start detecting fax") + + detect_duration = detect_duration or 60000 + + session:setInputCallback("tone_detect_cb") + session:execute("tone_detect", "txfax 2100 r +" .. tostring(detect_duration) .. " set remote_fax_detected=txfax") + session:execute("tone_detect", "rxfax 1100 r +" .. tostring(detect_duration) .. " set remote_fax_detected=rxfax") + session:setVariable("sip_api_on_image", "uuid_break " .. session:getVariable("uuid") .. " all") +end + +local function stop_fax_detect() + session:unsetInputCallback() + session:execute("stop_tone_detect") + session:setVariable("sip_api_on_image", "") +end + +local function fax_deteced() + if session:getVariable('has_t38') == 'true' then + log.noticef('Detected t38') + session:setVariable('remote_fax_detected', 'txfax') + end + + if fax_file and session:getVariable('remote_fax_detected') then + log.noticef("Detected %s", session:getVariable('remote_fax_detected')) + if session:getVariable('remote_fax_detected') == 'txfax' then + send_fax() + else + log.warning('Remote fax try send fax') + end + return true + end +end + +local function check() + if not session:ready() then return false end + if fax_deteced() then return false end + return true +end + +local function task() + local session_uuid = session:getVariable('uuid') + + session:setVariable('fax_queue_task_session', session_uuid) + + log.infof("SESSION UUID: %s", session_uuid) + + session:waitForAnswer(session) + + while not session:answered() do + if not session:ready() then return end + session:sleep(500) + end + + if not (session:ready() and session:answered()) then return end + + if fax_file and wav_file then + start_fax_detect() + end + + if dtmf then + dtmf = decode_dtmf(dtmf) + for _, element in ipairs(dtmf) do + if type(element) == 'number' then + session:streamFile("silence_stream://" .. tostring(element)) + else + session:execute("send_dtmf", element) + end + if not check() then return end + end + end + + if wav_file then + session:streamFile(wav_file) + if not check() then return end + end + + if fax_file then + if wav_file then + stop_fax_detect() + end + send_fax() + end +end + +log.noticef("START TASK") +log.notice("Fax:" .. tostring(fax_file)) +log.notice("Wav:" .. tostring(wav_file)) + +task() + +log.noticef("STOP TASK") +log.notice("Ready: " .. tostring(session:ready())) +log.notice("Answered: " .. tostring(session:answered())) diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/next.lua b/resources/install/scripts/app/fax/resources/scripts/queue/next.lua new file mode 100644 index 0000000000..4780867a1d --- /dev/null +++ b/resources/install/scripts/app/fax/resources/scripts/queue/next.lua @@ -0,0 +1,87 @@ +require "resources.functions.config" + +require "resources.functions.sleep" +local log = require "resources.functions.log".next_fax_task +local Tasks = require "app.fax.resources.scripts.queue.tasks" +local Esl = require "resources.functions.esl" + +local FAX_OPTIONS = { + "fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default"; + "fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=false"; + "fax_use_ecm=true,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false"; + "fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=true"; + "fax_use_ecm=false,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false"; +} + +local function task_send_mail(task) + local number_dialed = task.uri:match("/([^/]-)%s*$") + + Tasks.send_mail_task(task, { + "Fax to: " .. number_dialed .. " FAILED", + table.concat{ + "We are sorry the fax failed to go through. ", + "It has been attached. Please check the number " .. number_dialed .. ", ", + "and if it was correct you might consider emailing it instead.", + }} + ) +end + +local function next_task() + local task, err = Tasks.next_task() + + if not task then + if err then + log.noticef('Can not select next task: %s', tostring(err)) + else + log.notice("No task") + end + return + end + + local esl + local ok, err = pcall(function() + + local mode = (task.retry_counter % #FAX_OPTIONS) + 1 + local dial_string = '{' .. + task.dial_string .. "api_hangup_hook='lua app/fax/resources/scripts/queue/retry.lua'," .. + FAX_OPTIONS[mode] .. + '}' .. task.uri + + local originate = 'originate ' .. dial_string .. ' &lua(app/fax/resources/scripts/queue/exec.lua)' + + log.notice(originate) + esl = assert(Esl.new()) + local ok, status, info = esl:api(originate) + if not ok then + Tasks.wait_task(task, false, info) + if task.status ~= 0 then + Tasks.remove_task(task) + task_send_mail(task) + end + log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info)) + else + log.noticef("originate successfuly: %s", tostring(info)) + end + end) + + if esl then esl:close() end + + if not ok then + Tasks.release_task(task) + log.noticef("Error execute task: %s", tostring(err)) + end + + return true +end + +local function poll_once() + Tasks.cleanup_tasks() + while next_task() do + sleep(5000) + end + Tasks.release_db() +end + +return { + poll_once = poll_once; +} diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua new file mode 100644 index 0000000000..1d634ea725 --- /dev/null +++ b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua @@ -0,0 +1,359 @@ +-- include libraries + require "resources.functions.config"; + require "resources.functions.explode"; + require "resources.functions.split"; + require "resources.functions.count"; + + local log = require "resources.functions.log".fax_retry + local Database = require "resources.functions.database" + local Settings = require "resources.functions.lazy_settings" + local Tasks = require "app.fax.resources.scripts.queue.tasks" + local send_mail = require "resources.functions.send_mail" + + local fax_task_uuid = env:getHeader('fax_task_uuid') + if not fax_task_uuid then + log.warning("No [fax_task_uuid] channel variable") + return + end + local task = Tasks.select_task(fax_task_uuid) + if not task then + log.warningf("Can not find fax task: %q", tostring(fax_task_uuid)) + return + end + +-- show all channel variables + if debug["fax_serialize"] then + log.noticef("info:\n%s", env:serialize()) + end + + local dbh = Database.new('system') + +-- Channel/FusionPBX variables + local uuid = env:getHeader("uuid") + local fax_queue_task_session = env:getHeader('fax_queue_task_session') + local domain_uuid = env:getHeader("domain_uuid") or task.domain_uuid + local domain_name = env:getHeader("domain_name") or task.domain_name + local origination_caller_id_name = env:getHeader("origination_caller_id_name") or '000000000000000' + local origination_caller_id_number = env:getHeader("origination_caller_id_number") or '000000000000000' + local accountcode = env:getHeader("accountcode") or domain_name + local duration = tonumber(env:getHeader("billmsec")) or 0 + local sip_to_user = env:getHeader("sip_to_user") + local bridge_hangup_cause = env:getHeader("bridge_hangup_cause") + local hangup_cause_q850 = tonumber(env:getHeader("hangup_cause_q850")) + local answered = duration > 0 + +-- fax variables + local fax_success = env:getHeader('fax_success') + local has_t38 = env:getHeader('has_t38') or 'false' + local t38_broken_boolean = env:getHeader('t38_broken_boolean') or '' + local fax_result_code = tonumber(env:getHeader('fax_result_code')) or 2 + local fax_result_text = env:getHeader('fax_result_text') or 'FS_NOT_SET' + local fax_ecm_used = env:getHeader('fax_ecm_used') or '' + local fax_local_station_id = env:getHeader('fax_local_station_id') or '' + local fax_document_transferred_pages = env:getHeader('fax_document_transferred_pages') or nil + local fax_document_total_pages = env:getHeader('fax_document_total_pages') or nil + local fax_image_resolution = env:getHeader('fax_image_resolution') or '' + local fax_image_size = env:getHeader('fax_image_size') or nil + local fax_bad_rows = env:getHeader('fax_bad_rows') or nil + local fax_transfer_rate = env:getHeader('fax_transfer_rate') or nil + local fax_v17_disabled = env:getHeader('fax_v17_disabled') or '' + local fax_ecm_requested = env:getHeader('fax_ecm_requested') or '' + local fax_remote_station_id = env:getHeader('fax_remote_station_id') or '' + + local fax_options = ("fax_use_ecm=%s,fax_enable_t38=%s,fax_enable_t38_request=%s,fax_disable_v17=%s"):format( + env:getHeader('fax_use_ecm') or '', + env:getHeader('fax_enable_t38') or '', + env:getHeader('fax_enable_t38_request') or '', + env:getHeader('fax_disable_v17') or '' + ) + +-- Fax task params + local fax_uri = env:getHeader("fax_uri") or task.uri + local fax_file = env:getHeader("fax_file") or task.fax_file + local wav_file = env:getHeader("wav_file") or task.wav_file + local fax_uuid = task.fax_uuid + +-- Email variables + local number_dialed = fax_uri:match("/([^/]-)%s*$") + + log.noticef([[<<< CALL RESULT >>> + uuid: = '%s' + task_session_uuid: = '%s' + answered: = '%s' + fax_file: = '%s' + wav_file: = '%s' + fax_uri: = '%s' + sip_to_user: = '%s' + accountcode: = '%s' + origination_caller_id_name: = '%s' + origination_caller_id_number: = '%s' + mailto_address: = '%s' + hangup_cause_q850: = '%s' + fax_options = '%s' +]], + tostring(uuid) , + tostring(fax_queue_task_session) , + tostring(answered) , + tostring(fax_file) , + tostring(wav_file) , + tostring(fax_uri) , + tostring(sip_to_user) , + tostring(accountcode) , + tostring(origination_caller_id_name) , + tostring(origination_caller_id_number) , + tostring(task.reply_address) , + tostring(hangup_cause_q850) , + fax_options +) + + if fax_success then + log.noticef([[<<< FAX RESULT >>> + fax_success = '%s' + has_t38 = '%s' + t38_broken_boolean = '%s' + fax_result_code = '%s' + fax_result_text = '%s' + fax_ecm_used = '%s' + fax_local_station_id = '%s' + fax_document_transferred_pages = '%s' + fax_document_total_pages = '%s' + fax_image_resolution = '%s' + fax_image_size = '%s' + fax_bad_rows = '%s' + fax_transfer_rate = '%s' + fax_v17_disabled = '%s' + fax_ecm_requested = '%s' + fax_remote_station_id = '%s' + '%s' +]], + fax_success , + has_t38 , + t38_broken_boolean , + fax_result_code , + fax_result_text , + fax_ecm_used , + fax_local_station_id , + fax_document_transferred_pages , + fax_document_total_pages , + fax_image_resolution , + fax_image_size , + fax_bad_rows , + fax_transfer_rate , + fax_v17_disabled , + fax_ecm_requested , + fax_remote_station_id , + '---------------------------------' + ) + end + + log.debug([[<<< DEBUG >>> + domain_name = '%s' + domain_uuid = '%s' + task.domain_name = '%s' + task.domain_uuid = '%s' +]], + tostring(domain_name ), + tostring(domain_uuid ), + tostring(task.domain_name ), + tostring(task.domain_uuid ) +) + + assert(fax_uuid, 'no fax server uuid') + assert(domain_name, 'no domain name') + assert(domain_uuid, 'no domain uuid') + assert(domain_uuid:lower() == task.domain_uuid:lower(), 'invalid domain uuid') + assert(domain_name:lower() == task.domain_name:lower(), 'invalid domain name') + +--settings + local settings = Settings.new(dbh, domain_name, domain_uuid) + local keep_local = settings:get('fax', 'keep_local','boolean') + local storage_type = (keep_local == "false") and "" or settings:get('fax', 'storage_type', 'text') + + local function opt(v, default) + if v then return "'" .. v .. "'" end + return default or 'NULL' + end + + local function now_sql() + return (database["type"] == "sqlite") and "'"..os.date("%Y-%m-%d %X").."'" or "now()"; + end + +--add to fax logs + do + local fields = { + "fax_log_uuid"; + "domain_uuid"; + "fax_uuid"; + "fax_success"; + "fax_result_code"; + "fax_result_text"; + "fax_file"; + "fax_ecm_used"; + "fax_local_station_id"; + "fax_document_transferred_pages"; + "fax_document_total_pages"; + "fax_image_resolution"; + "fax_image_size"; + "fax_bad_rows"; + "fax_transfer_rate"; + "fax_retry_attempts"; + "fax_retry_limit"; + "fax_retry_sleep"; + "fax_uri"; + "fax_date"; + "fax_epoch"; + } + + local values = { + "'"..uuid .. "'"; + "'"..domain_uuid .. "'"; + opt(fax_uuid); + opt(fax_success); + opt(fax_result_code); + opt(fax_result_text); + opt(fax_file); + opt(fax_ecm_used); + opt(fax_local_station_id); + opt(fax_document_transferred_pages, "'0'"); + opt(fax_document_total_pages, "'0'"); + opt(fax_image_resolution); + opt(fax_image_size); + opt(fax_bad_rows); + opt(fax_transfer_rate); + opt(fax_retry_attempts); + opt(fax_retry_limit); + opt(fax_retry_sleep); + opt(fax_uri); + now_sql(); + "'"..os.time().."' "; + } + + local sql = "insert into v_fax_logs(" .. table.concat(fields, ",") .. ")" .. + "values(" .. table.concat(values, ",") .. ")" + + if (debug["sql"]) then + log.noticef("SQL: %s", sql); + end + + dbh:query(sql); + end + +-- add the fax files + if fax_success == "1" then + + if storage_type == "base64" then + --include the base64 function + require "resources.functions.base64"; + + --base64 encode the file + local f = io.open(fax_file, "rb"); + if not f then + log.waitng("Can not find file %s", fax_file) + storage_type = nil + else + local file_content = f:read("*all"); + f:close() + fax_base64 = base64.encode(file_content) + end + end + + -- build SQL + local sql do + sql = { + "insert into v_fax_files("; + "fax_file_uuid"; ","; + "fax_uuid"; ","; + "fax_mode"; ","; + "fax_destination"; ","; + "fax_file_type"; ","; + "fax_file_path"; ","; + "fax_caller_id_name"; ","; + "fax_caller_id_number"; ","; + "fax_date"; ","; + "fax_epoch"; ","; + "fax_base64"; ","; + "domain_uuid"; " "; + ") values ("; + opt(uuid); ","; + opt(fax_uuid); ","; + "'tx'"; ","; + opt(sip_to_user); ","; + "'tif'"; ","; + opt(fax_file); ","; + opt(origination_caller_id_name); ","; + opt(origination_caller_id_number); ","; + now_sql(); ","; + "'" .. os.time() .. "'"; ","; + opt(fax_base64); ","; + opt(domain_uuid); " "; + ")" + } + + sql = table.concat(sql, "\n"); + if (debug["sql"]) then + log.noticef("SQL: %s", sql); + end + end + + if storage_type == "base64" then + local db_type, db_cnn = split_first(database["system"], "://", true) + local luasql = require ("luasql." .. db_type); + local env = assert (luasql[db_type]()); + local dbh = env:connect(db_cnn); + dbh:execute(sql) + dbh:close() + env:close() + else + result = dbh:query(sql) + end + end + + if fax_success == "1" then + --Success + log.infof("RETRY STATS SUCCESS: GATEWAY[%s]", fax_options); + + if keep_local == "false" then + os.remove(fax_file); + end + + Tasks.remove_task(task) + Tasks.send_mail_task(task, { + "Fax to: " .. number_dialed .. " SENT", + table.concat{ + "We are happy to report the fax was sent successfully.", + "It has been attached for your records.", + }}, uuid + ) + end + + if fax_success ~= "1" then + if not answered then + log.noticef("no answer: %d", hangup_cause_q850) + else + if not fax_success then + log.noticef("Fax not detected: %s", fax_options) + else + log.noticef("fax fail %s", fax_options) + end + end + + -- if task use group call then retry.lua will be called multiple times + -- here we check eathre that channel which execute `exec.lua` + -- Note that if there no one execute `exec.lua` we do not need call this + -- becase it should deal in `next.lua` + if fax_queue_task_session == uuid then + Tasks.wait_task(task, answered, hangup_cause_q850) + if task.status ~= 0 then + Tasks.remove_task(task) + Tasks.send_mail_task(task, { + "Fax to: " .. number_dialed .. " FAILED", + table.concat{ + "We are sorry the fax failed to go through. ", + "It has been attached. Please check the number "..number_dialed..", ", + "and if it was correct you might consider emailing it instead.", + }}, uuid + ) + end + end + end + diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua new file mode 100644 index 0000000000..e6ba83835f --- /dev/null +++ b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua @@ -0,0 +1,277 @@ +local Database = require "resources.functions.database" +local Settings = require "resources.functions.lazy_settings" +local send_mail = require "resources.functions.send_mail" + +local db + +local date_utc_now_sql +local now_add_sec_sql + +if database.type == 'pgsql' then + date_utc_now_sql = "NOW() at time zone 'utc'" + now_add_sec_sql = "NOW() at time zone 'utc' + interval '%s second'" +elseif database.type == 'mysql' then + date_utc_now_sql = "UTC_TIMESTAMP()" + now_add_sec_sql = "DATE_ADD(UTC_TIMESTAMP(), INTERVAL %s SECOND)" +elseif database.type == 'sqlite' then + date_utc_now_sql = "datetime('now')" + now_add_sec_sql = "datetime('now', '%s seconds')" +else + error("unsupported database type: " .. database.type) +end + +-- Broken on FS 1.4 with native postgresql +-- Fixed on 1.6.0 +-- Also works with ODBC +local ignore_affected_rows = true +if dbh_affected_rows_broken ~= nil then + ignore_affected_rows = dbh_affected_rows_broken +end + +local Q850_TIMEOUT = { + [17] = 60; +} + +local select_task_common_sql = [[ +select + t1.fax_task_uuid as uuid, + t1.fax_uuid as fax_uuid, + t3.domain_name, + t3.domain_uuid, + t1.task_status as status, + t1.task_uri as uri, + t1.task_dial_string as dial_string, + t1.task_dtmf as dtmf, + t1.task_fax_file as fax_file, + t1.task_wav_file as wav_file, + t1.task_reply_address as reply_address, + t1.task_no_answer_counter as no_answer_counter, + t1.task_no_answer_retry_counter as no_answer_retry_counter, + t1.task_retry_counter as retry_counter, + t2.fax_send_greeting as greeting +from v_fax_tasks t1 + inner join v_fax t2 on t2.fax_uuid = t1.fax_uuid + inner join v_domains t3 on t2.domain_uuid = t3.domain_uuid +where t1.task_interrupted <> 'true' +]] + +local next_task_sql = select_task_common_sql .. [[ +and t1.task_status = 0 and t1.task_next_time < ]] .. date_utc_now_sql .. [[ +and t2.fax_send_channels > (select count(*) from v_fax_tasks as tasks + where tasks.fax_uuid = t1.fax_uuid and + tasks.task_status > 0 and tasks.task_status <= 2 +) +order by t1.task_next_time +]] + +local select_task_sql = select_task_common_sql .. "and t1.fax_task_uuid='%s'" + +local aquire_task_sql = [[ + update v_fax_tasks set task_status = 1, task_lock_time = ]] .. date_utc_now_sql .. [[ + where fax_task_uuid = '%s' and task_status = 0 +]] + +local wait_task_sql = [[ + update v_fax_tasks + set task_status = %s, + task_lock_time = NULL, + task_no_answer_counter = %s, + task_no_answer_retry_counter = %s, + task_retry_counter = %s, + task_next_time = ]] .. now_add_sec_sql .. [[ + where fax_task_uuid = '%s' +]] + +local remove_task_task_sql = [[ + delete from v_fax_tasks + where fax_task_uuid = '%s' +]] + +local release_task_sql = [[ + update v_fax_tasks + set task_status = 0, task_lock_time = NULL, + task_next_time = ]] .. now_add_sec_sql .. [[ + where fax_task_uuid = '%s' +]] + +local release_stuck_tasks_sql = [[ + update v_fax_tasks + set task_status = 0, task_lock_time = NULL, + task_next_time = ]] .. date_utc_now_sql .. [[ + where task_lock_time < ]] .. now_add_sec_sql:format('-3600') .. [[ +]] + +local remove_finished_tasks_sql = [[ + delete from v_fax_tasks where task_status > 3 +]] + +local function serialize(task, header) + local str = header or '' + for k, v in pairs(task) do + str = str .. ('\n %q = %q'):format(tostring(k), tostring(v)) + end + return str +end + +local function get_db() + if not db then + db = assert(Database.new('system')) + end + return db +end + +local function next_task() + local db = get_db() + + while true do + local task, err = db:first_row(next_task_sql) + if not task then return nil, err end + local ok, err = db:query( aquire_task_sql:format(task.uuid) ) + if not ok then return nil, err end + local rows = db:affected_rows() + if ignore_affected_rows then + rows = 1 + end + if rows == 1 then + task.no_answer_counter = tonumber(task.no_answer_counter) + task.no_answer_retry_counter = tonumber(task.no_answer_retry_counter) + task.retry_counter = tonumber(task.retry_counter) + return task + end + end +end + +local function select_task(fax_task_uuid) + local db = get_db() + + local task, err = db:first_row(select_task_sql:format(fax_task_uuid)) + if not task then return nil, err end + + task.no_answer_counter = tonumber(task.no_answer_counter) + task.no_answer_retry_counter = tonumber(task.no_answer_retry_counter) + task.retry_counter = tonumber(task.retry_counter) + + return task +end + +local function wait_task(task, answered, q850) + local db = get_db() + + local interval = 30 + + local settings = Settings.new(db, task.domain_name, task.domain_uuid) + task.status = 0 + + if not answered then + interval = Q850_TIMEOUT[q850 or 17] or interval + end + + if not answered then + local fax_send_no_answer_retry_limit = tonumber(settings:get('fax', 'send_no_answer_retry_limit', 'numeric')) or 0 + task.no_answer_retry_counter = task.no_answer_retry_counter + 1 + + if task.no_answer_retry_counter >= fax_send_no_answer_retry_limit then + task.no_answer_retry_counter = 0 + task.no_answer_counter = task.no_answer_counter + 1 + local fax_send_no_answer_limit = tonumber(settings:get('fax', 'send_no_answer_limit', 'numeric')) or 0 + if task.no_answer_counter >= fax_send_no_answer_limit then + task.status = 4 + else + interval = tonumber(settings:get('fax', 'send_no_answer_interval', 'numeric')) or interval + end + else + interval = tonumber(settings:get('fax', 'send_no_answer_retry_interval', 'numeric')) or interval + end + else + task.retry_counter = task.retry_counter + 1 + local fax_send_retry_limit = tonumber(settings:get('fax', 'send_retry_limit', 'numeric')) or 0 + + if task.retry_counter >= fax_send_retry_limit then + task.status = 4 + else + interval = tonumber(settings:get('fax', 'send_retry_interval', 'numeric')) or interval + task.task_seq_call_counter = 0 + end + end + + local sql = wait_task_sql:format( + tostring(task.status), + tostring(task.no_answer_counter), + tostring(task.no_answer_retry_counter), + tostring(task.retry_counter), + tostring(interval), + task.uuid + ) + + print(sql) + + local ok, err = db:query( sql ) + + if not ok then return nil, err end + + return task +end + +local function remove_task(task) + local db = get_db() + + local sql = remove_task_task_sql:format(task.uuid) + local ok, err = db:query( sql ) + if not ok then return nil, err end + return db:affected_rows() +end + +local function release_task(task) + local db = get_db() + + local interval = 30 + + local sql = release_task_sql:format( + tostring(interval), + task.uuid + ) + + local ok, err = db:query( sql ) + + if not ok then return nil, err end + + return task +end + +local function cleanup_tasks() + local db = get_db() + + db:query(release_stuck_tasks_sql) + db:query(remove_finished_tasks_sql) +end + +local function send_mail_task(task, message, call_uuid) + if not task.reply_address or #task.reply_address == 0 then + return + end + + local mail_x_headers = { + ["X-FusionPBX-Domain-UUID"] = task.domain_uuid; + ["X-FusionPBX-Domain-Name"] = task.domain_name; + ["X-FusionPBX-Call-UUID"] = call_uuid; + ["X-FusionPBX-Email-Type"] = 'email2fax'; + } + + return send_mail(mail_x_headers, task.reply_address, message) +end + +return { + release_db = function() + if db then + db:release() + db = nil + end + end; + next_task = next_task; + wait_task = wait_task; + select_task = select_task; + remove_task = remove_task; + release_task = release_task; + cleanup_tasks = cleanup_tasks; + send_mail_task = send_mail_task; +} diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 25e07493f7..bf4d2a193f 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -453,6 +453,7 @@ local log = require "resources.functions.log".ring_group else --external number y = 0; + dial_string = ''; previous_dialplan_uuid = ''; for k, r in pairs(dialplans) do if (y > 0) then @@ -497,7 +498,7 @@ local log = require "resources.functions.log".ring_group end elseif (r.dialplan_detail_type == "bridge") then if (bridge_match) then - dial_string = dial_string .. "|" .. square .."]"..dialplan_detail_data; + dial_string = dial_string .. delimiter .. square .."]"..dialplan_detail_data; square = "["; else dial_string = square .."]"..dialplan_detail_data; diff --git a/resources/install/scripts/app/voicemail/app_languages.lua b/resources/install/scripts/app/voicemail/app_languages.lua index 0c2daed73b..57dc356a16 100644 --- a/resources/install/scripts/app/voicemail/app_languages.lua +++ b/resources/install/scripts/app/voicemail/app_languages.lua @@ -1,4 +1,4 @@ -text = {}; +text = text or {}; text['label-download'] = {}; text['label-download']['en-us'] = "Download"; @@ -24,3 +24,4 @@ text['label-attached']['fr-fr'] = "Attaché"; text['label-attached']['de-de'] = "im Anhang"; text['label-attached']['de-at'] = "im Anhang"; +return text \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index ee9e79e5cd..2cddb544c1 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -78,6 +78,10 @@ if (not vm_disk_quota) then vm_disk_quota = session:getVariable("vm_disk_quota"); end + record_silence_threshold = session:getVariable("record-silence-threshold"); + if (not record_silence_threshold) then + record_silence_threshold = 300; + end voicemail_authorized = session:getVariable("voicemail_authorized"); if (not vm_message_ext) then vm_message_ext = 'wav'; end diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua index da41ef98fb..efa6da0e36 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua @@ -63,11 +63,10 @@ --prepare to record the greeting if (session:ready()) then max_len_seconds = 30; - silence_threshold = 30; silence_seconds = 5; mkdir(voicemail_dir.."/"..voicemail_id); -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", max_len_seconds, record_silence_threshold, silence_seconds); --session:execute("record", voicemail_dir.."/"..uuid.." 180 200"); end end diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua index 4b830f5297..397e52c32e 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua @@ -143,10 +143,9 @@ --save the recording -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) max_len_seconds = 300; - silence_threshold = 30; silence_seconds = 5; if (storage_path == "http_cache") then - result = session:recordFile(storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds); else mkdir(voicemail_dir.."/"..voicemail_id); if (vm_message_ext == "mp3") then @@ -154,10 +153,10 @@ if (shout_exists == "true") then freeswitch.consoleLog("notice", "using mod_shout for mp3 encoding\n"); --record in mp3 directly - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".mp3", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".mp3", max_len_seconds, record_silence_threshold, silence_seconds); else --create initial wav recording - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, record_silence_threshold, silence_seconds); --use lame to encode, if available if (file_exists("/usr/bin/lame")) then freeswitch.consoleLog("notice", "using lame for mp3 encoding\n"); @@ -176,7 +175,7 @@ end end else - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, max_len_seconds, record_silence_threshold, silence_seconds); end end diff --git a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua index 7009932369..0480f8c9dd 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -23,6 +23,8 @@ -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. + local send_mail = require 'resources.functions.send_mail' + --define a function to send email function send_email(id, uuid) --get voicemail message details @@ -52,7 +54,8 @@ --require the email address to send the email if (string.len(voicemail_mail_to) > 2) then --include languages file - require "app.voicemail.app_languages"; + local Text = require "resources.functions.text" + local text = Text.new("app.voicemail.app_languages") --get voicemail message details sql = [[SELECT * FROM v_voicemail_messages @@ -103,10 +106,12 @@ end --prepare the headers - headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; - headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; - headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; - headers = headers..'"X-FusionPBX-Email-Type":"voicemail"}'; + local headers = { + ["X-FusionPBX-Domain-UUID"] = domain_uuid; + ["X-FusionPBX-Domain-Name"] = domain_name; + ["X-FusionPBX-Call-UUID"] = uuid; + ["X-FusionPBX-Email-Type"] = 'voicemail'; + } --prepare the subject local f = io.open(file_subject, "r"); @@ -134,11 +139,11 @@ body = body:gsub("${sip_to_user}", id); body = body:gsub("${dialed_user}", id); if (voicemail_file == "attach") then - body = body:gsub("${message}", text['label-attached'][default_language.."-"..default_dialect]); + body = body:gsub("${message}", text['label-attached']); elseif (voicemail_file == "link") then - body = body:gsub("${message}", ""..text['label-download'][default_language.."-"..default_dialect]..""); + body = body:gsub("${message}", ""..text['label-download']..""); else - body = body:gsub("${message}", ""..text['label-listen'][default_language.."-"..default_dialect]..""); + body = body:gsub("${message}", ""..text['label-listen']..""); end body = body:gsub(" ", " "); body = body:gsub("%s+", ""); @@ -147,22 +152,15 @@ body = body:gsub("\n", ""); body = trim(body); - --send the email + --prepare file file = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; - if (voicemail_file == "attach") then - freeswitch.email("", - "", - "To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nX-Headers: "..headers.."\nSubject: "..subject, - body, - file - ); - else - freeswitch.email("", - "", - "To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nX-Headers: "..headers.."\nSubject: "..subject, - body - ); - end + + --send the email + send_mail(headers, + voicemail_mail_to, + {subject, body}, + (voicemail_file == "attach") and file + ); end --whether to keep the voicemail message and details local after email diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.lua new file mode 100644 index 0000000000..4f7c500011 --- /dev/null +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.lua @@ -0,0 +1,165 @@ +-- xml_handler.lua +-- Part of FusionPBX +-- Copyright (C) 2015 Mark J Crane +-- All rights reserved. +-- +-- Redistribution and use in source and binary forms, with or without +-- modification, are permitted provided that the following conditions are met: +-- +-- 1. Redistributions of source code must retain the above copyright notice, +-- this list of conditions and the following disclaimer. +-- +-- 2. Redistributions in binary form must reproduce the above copyright +-- notice, this list of conditions and the following disclaimer in the +-- documentation and/or other materials provided with the distribution. +-- +-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +-- POSSIBILITY OF SUCH DAMAGE. + +--get the cache + hostname = trim(api:execute("switchname", "")); + if (trim(api:execute("module_exists", "mod_memcache")) == "true") then + XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. hostname)); + else + XML_STRING = "-ERR NOT FOUND"; + end + +--set the cache + if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then + + --connect to the database + require "resources.functions.database_handle"; + dbh = database_handle('system'); + + --exits the script if we didn't connect properly + assert(dbh:connected()); + + --get the ivr menu from the database + sql = [[SELECT * FROM v_ivr_menus + WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' + AND ivr_menu_enabled = 'true' ]]; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); + end + status = dbh:query(sql, function(row) + domain_uuid = row["domain_uuid"]; + ivr_menu_name = row["ivr_menu_name"]; + --ivr_menu_extension = row["ivr_menu_extension"]; + ivr_menu_greet_long = row["ivr_menu_greet_long"]; + ivr_menu_greet_short = row["ivr_menu_greet_short"]; + ivr_menu_invalid_sound = row["ivr_menu_invalid_sound"]; + ivr_menu_exit_sound = row["ivr_menu_exit_sound"]; + ivr_menu_confirm_macro = row["ivr_menu_confirm_macro"]; + ivr_menu_confirm_key = row["ivr_menu_confirm_key"]; + ivr_menu_tts_engine = row["ivr_menu_tts_engine"]; + ivr_menu_tts_voice = row["ivr_menu_tts_voice"]; + ivr_menu_confirm_attempts = row["ivr_menu_confirm_attempts"]; + ivr_menu_timeout = row["ivr_menu_timeout"]; + --ivr_menu_exit_app = row["ivr_menu_exit_app"]; + --ivr_menu_exit_data = row["ivr_menu_exit_data"]; + ivr_menu_inter_digit_timeout = row["ivr_menu_inter_digit_timeout"]; + ivr_menu_max_failures = row["ivr_menu_max_failures"]; + ivr_menu_max_timeouts = row["ivr_menu_max_timeouts"]; + ivr_menu_digit_len = row["ivr_menu_digit_len"]; + + ivr_menu_direct_dial = row["ivr_menu_direct_dial"]; + ivr_menu_ringback = row["ivr_menu_ringback"]; + ivr_menu_cid_prefix = row["ivr_menu_cid_prefix"]; + ivr_menu_description = row["ivr_menu_description"]; + end); + + --recording path + + + --start the xml array + local xml = {} + table.insert(xml, [[]]); + table.insert(xml, [[]]); + table.insert(xml, [[
    ]]); + table.insert(xml, [[ ]]); + + table.insert(xml, [[ ]]); + dbh:query(sql, function(row) + + --build the xml + table.insert(xml, [[ ]]); + + --get the ivr menu options + sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' ORDER BY ivr_menu_option_order asc ]]; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); + end + status = dbh:query(sql, function(r) + dbh:query(sql, function(r) + ivr_menu_option_digits = r.ivr_menu_option_digits + ivr_menu_option_action = r.ivr_menu_option_action + ivr_menu_option_param = r.ivr_menu_option_param + ivr_menu_option_description = row.ivr_menu_option_description + table.insert(xml, [[]]); + end) + + --direct dial + if (ivr_menu_direct_dial == "true") then + table.insert(xml, [[\n"); + end + end) + table.insert(xml, [[ ]]); + + --close the extension tag if it was left open + table.insert(xml, [[ ]]); + table.insert(xml, [[
    ]]); + table.insert(xml, [[
    ]]); + XML_STRING = table.concat(xml, "\n"); + if (debug["xml_string"]) then + freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n"); + end + + --close the database connection + dbh:release(); + --freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}")); + + --set the cache + result = trim(api:execute("memcache", "set configuration:ivr.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' ".."expire['ivr.conf']")); + + --send the xml to the console + if (debug["xml_string"]) then + local file = assert(io.open(temp_dir .. "/ivr.conf.xml", "w")); + file:write(XML_STRING); + file:close(); + end + + --send to the console + if (debug["cache"]) then + freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf:" .. hostname .." source: database\n"); + end + else + --replace the ' back to a single quote + XML_STRING = XML_STRING:gsub("'", "'"); + --send to the console + if (debug["cache"]) then + freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf source: memcache\n"); + end + end --if XML_STRING diff --git a/resources/install/scripts/call_forward.lua b/resources/install/scripts/call_forward.lua index fc4f693f38..bd1dd11142 100644 --- a/resources/install/scripts/call_forward.lua +++ b/resources/install/scripts/call_forward.lua @@ -108,7 +108,7 @@ --check to see if the pin number is correct if not session:ready() then return end - local sql = "SELECT * FROM v_voicemails "; + local sql = "SELECT voicemail_password FROM v_voicemails "; sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' "; sql = sql .. "AND voicemail_id = '" .. extension .."' "; if (debug["sql"]) then diff --git a/resources/install/scripts/fax_queue_monitor.lua b/resources/install/scripts/fax_queue_monitor.lua new file mode 100644 index 0000000000..a9250d455e --- /dev/null +++ b/resources/install/scripts/fax_queue_monitor.lua @@ -0,0 +1,42 @@ + local sleep_interval = 60; + +--include config.lua + require "resources.functions.config"; + +--general functions + require "resources.functions.file_exists"; + require "resources.functions.mkdir"; + require "resources.functions.sleep"; + + local log = require "resources.functions.log".fax_queue_monitor + local Next = require "app.fax.resources.scripts.queue.next" + + mkdir(scripts_dir .. "/run"); + +--define the run file + local run_file = scripts_dir .. "/run/fax_queue.tmp"; + +--used to stop the lua service + local file = assert(io.open(run_file, "w")); + file:write("remove this file to stop the script"); + file:close() + + log.notice("Start") + + while true do + local ok, err = pcall(function() + Next.poll_once() + end) + + if not ok then + log.errf("fail poll queue: %s", tostring(err)) + end + + if not file_exists(run_file) then + break; + end + + sleep(sleep_interval * 1000) + end + + log.notice("Stop") diff --git a/resources/install/scripts/fax_queue_poll_once.lua b/resources/install/scripts/fax_queue_poll_once.lua new file mode 100644 index 0000000000..b8453bdafd --- /dev/null +++ b/resources/install/scripts/fax_queue_poll_once.lua @@ -0,0 +1 @@ +require "app.fax.resources.scripts.queue.next".poll_once() \ No newline at end of file diff --git a/resources/install/scripts/fifo_member.lua b/resources/install/scripts/fifo_member.lua index 54b364db10..c7874b4d2e 100644 --- a/resources/install/scripts/fifo_member.lua +++ b/resources/install/scripts/fifo_member.lua @@ -23,7 +23,6 @@ -- Mark J Crane sounds_dir = ""; -recordings_dir = ""; pin_number = ""; max_tries = "3"; digit_timeout = "3000"; diff --git a/resources/install/scripts/intercept.lua b/resources/install/scripts/intercept.lua index a7a6695731..326d93b985 100644 --- a/resources/install/scripts/intercept.lua +++ b/resources/install/scripts/intercept.lua @@ -24,9 +24,10 @@ -- Errol W Samuels --user defined variables - max_tries = "3"; - digit_timeout = "5000"; - extension = argv[1]; + local extension = argv[1]; + +-- we can use any number because other box should check sip_h_X_*** headers first + local pickup_number = '*8' -- extension and '**' or '*8' --set the debug options debug["sql"] = false; @@ -34,139 +35,298 @@ --include config.lua require "resources.functions.config"; ---connect to the database - if (file_exists(database_dir.."/core.db")) then - --dbh = freeswitch.Dbh("core:core"); -- when using sqlite - dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); - else - require "resources.functions.database_handle"; - dbh = database_handle('switch'); - end +--add the function + require "resources.functions.explode"; + require "resources.functions.trim"; + require "resources.functions.channel_utils"; --prepare the api object api = freeswitch.API(); ---add the function - require "resources.functions.trim"; - require "resources.functions.channel_utils"; +--Get intercept logger + local log = require "resources.functions.log".intercept ---exits the script if we didn't connect properly - assert(dbh:connected()); - -if ( session:ready() ) then - --answer the session - session:answer(); - - --get session variables - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - context = session:getVariable("context"); - sofia_profile_name = session:getVariable("sofia_profile_name"); - - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end - - --set defaults - if (digit_min_length) then - --do nothing - else - digit_min_length = "2"; - end - - if (digit_max_length) then - --do nothing - else - digit_max_length = "11"; - end - - --if the pin number is provided then require it - if (pin_number) then - --sleep - session:sleep(500); - --get the user pin number - min_digits = 2; - max_digits = 20; - digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); - --validate the user pin number - pin_number_table = explode(",",pin_number); - for index,pin_number in pairs(pin_number_table) do - if (digits == pin_number) then - --set the variable to true - auth = true; - --set the authorized pin number that was used - session:setVariable("pin_number", pin_number); - --end the loop - break; - end - end - --if not authorized play a message and then hangup - if (not auth) then - session:streamFile("phrase:voicemail_fail_auth:#"); - session:hangup("NORMAL_CLEARING"); - return; - end - end - - --predefined variables - uuid = ''; - call_hostname = ''; - callee_num = ''; - - --check the database to get the uuid of a ringing call - sql = "select uuid, call_uuid, hostname, callee_num, ip_addr from channels "; - sql = sql .. "where callstate in ('RINGING', 'EARLY') "; - --sql = sql .. "AND direction = 'outbound' "; - if (extension) then - sql = sql .. "and presence_id = '"..extension.."@"..domain_name.."' "; - else - if (domain_count > 1) then - sql = sql .. "and context = '"..context.."' "; - end - end - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "sql "..sql.."\n"); - end - dbh:query(sql, function(result) - --for key, val in pairs(result) do - -- freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n"); - --end - if result.uuid == result.call_uuid then - uuid = channel_variable(result.uuid, 'ent_originate_aleg_uuid') or - channel_variable(result.uuid, 'cc_member_session_uuid') or - channel_variable(result.uuid, 'fifo_bridge_uuid') or - result.uuid - else - uuid = result.call_uuid; - end - call_hostname = result.hostname; - callee_num = result.callee_num; - end); -end +--include database class + local Database = require "resources.functions.database" --get the hostname - hostname = trim(api:execute("hostname", "")); - freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n"); + local hostname = trim(api:execute("switchname", "")); + +-- redirect call to another box + local function make_proxy_call(destination, call_hostname) + destination = destination .. "@" .. domain_name + local profile, proxy = "internal", call_hostname; + + local sip_auth_username = session:getVariable("sip_auth_username"); + local sip_auth_password = api:execute("user_data", sip_auth_username .. "@" .. domain_name .." param password"); + local auth = "sip_auth_username="..sip_auth_username..",sip_auth_password='"..sip_auth_password.."'" + dial_string = "{sip_invite_domain=" .. domain_name .. "," .. auth .. "}sofia/" .. profile .. "/" .. destination .. ";fs_path=sip:" .. proxy; + log.notice("Send call to other host...."); + session:execute("bridge", dial_string); + end + +-- check pin number if defined + local function pin(pin_number) + if not pin_number then + return true + end + + --sleep + session:sleep(500); + --get the user pin number + local min_digits = 2; + local max_digits = 20; + local max_tries = "3"; + local digit_timeout = "5000"; + local digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); + + --validate the user pin number + local pin_number_table = explode(",",pin_number); + for index,pin_number in pairs(pin_number_table) do + if (digits == pin_number) then + --set the authorized pin number that was used + session:setVariable("pin_number", pin_number); + --done + return true; + end + end + + --if not authorized play a message and then hangup + session:streamFile("phrase:voicemail_fail_auth:#"); + session:hangup("NORMAL_CLEARING"); + return; + end + +-- do intercept if we get redirected request from another box + local function proxy_intercept() + -- Proceed calls from other boxes + + -- Check if this call from other box with setted intercept_uuid + local intercept_uuid = session:getVariable("sip_h_X-intercept_uuid") + + if intercept_uuid and #intercept_uuid > 0 then + log.notice("Get intercept_uuid from sip header. Do intercept....") + session:execute("intercept", intercept_uuid) + return true + end + + -- Check if this call from other box and we need parent uuid for channel + local child_intercept_uuid = session:getVariable("sip_h_X-child_intercept_uuid") + if (not child_intercept_uuid) or (#child_intercept_uuid == 0) then + return + end + + -- search parent uuid + log.notice("Get child_intercept_uuid from sip header.") + local parent_uuid = + channel_variable(child_intercept_uuid, 'ent_originate_aleg_uuid') or + channel_variable(child_intercept_uuid, 'cc_member_session_uuid') or + channel_variable(child_intercept_uuid, 'fifo_bridge_uuid') or + child_intercept_uuid + + if parent_uuid == child_intercept_uuid then + log.notice("Can not found parent call. Try intercept child.") + session:execute("intercept", child_intercept_uuid) + return true + end + + -- search parent hostname + call_hostname = hostname + --[[ parent and child have to be on same box so we do not search it + log.notice("Found parent channel try detect parent hostname") + local dbh = Database.new('switch') + local sql = "SELECT hostname FROM channels WHERE uuid='" .. parent_uuid .. "'" + local call_hostname = dbh:first_value(sql) + dbh:release() + + if not call_hostname then + log.notice("Can not find host name. Channels is dead?") + return true + end + --]] + + if hostname == call_hostname then + log.notice("Found parent call on local machine. Do intercept....") + session:execute("intercept", parent_uuid); + return true + end + + log.noticef("Found parent call on remote machine `%s`.", call_hostname) + session:execute("export", "sip_h_X-intercept_uuid="..parent_uuid); + make_proxy_call(pickup_number, call_hostname) + return true + end + +-- return array of extensions for group + local function select_group_extensions() + -- connect to Fusion database + local dbh = Database.new('system'); + + --get the call groups the extension is a member of + local sql = "SELECT call_group FROM v_extensions "; + sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "AND (extension = '"..caller_id_number.."'"; + sql = sql .. "OR number_alias = '"..caller_id_number.."')"; + sql = sql .. "limit 1"; + local call_group = dbh:first_value(sql) or '' + log.noticef("call_group: `%s`", call_group); + call_groups = explode(",", call_group); + + --get the extensions in the call groups + sql = "SELECT extension, number_alias FROM v_extensions "; + sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; + sql = sql .. "AND ("; + for key,call_group in ipairs(call_groups) do + if (key > 1) then + sql = sql .. "OR "; + end + if (#call_group > 0) then + sql = sql .. "call_group like '%"..call_group.."%' "; + else + sql = sql .. "call_group = '' "; + end + end + sql = sql .. ") "; + if (debug["sql"]) then + log.notice("sql "..sql); + end + local extensions = {} + dbh:query(sql, function(row) + local member = row.extension + if row.number_alias and #row.number_alias > 0 then + member = row.number_alias + end + extensions[#extensions+1] = member + log.noticef("member `%s`", member) + end); + + -- release Fusion database + dbh:release() + + -- return result + return extensions + end + +--check if the session is ready + if ( session:ready() ) then + --answer the session + session:answer(); + --get session variables + domain_uuid = session:getVariable("domain_uuid"); + domain_name = session:getVariable("domain_name"); + pin_number = session:getVariable("pin_number"); + context = session:getVariable("context"); + caller_id_number = session:getVariable("caller_id_number"); + end + +--check if the session is ready + if ( session:ready() ) then + if proxy_intercept() then + return + end + end + +--check if the session is ready + if ( session:ready() ) then + --if the pin number is provided then require it + if not pin(pin_number) then + return + end + end + + if ( session:ready() ) then + -- select intercept mode + if not extension then + log.notice("GROUP INTERCEPT") + extensions = select_group_extensions() + else + log.noticef("INTERCEPT %s", extension) + extensions = {extension} + end + + --connect to FS database + local dbh = Database.new('switch') + + --check the database to get the uuid of a ringing call + call_hostname = ""; + sql = "SELECT uuid, call_uuid, hostname FROM channels "; + sql = sql .. "WHERE callstate in ('RINGING', 'EARLY') "; + -- next check should prevent pickup call from extension + -- e.g. if extension 100 dial some cell phone and some one else dial *8 + -- he can pickup this call. + if not extension then + sql = sql .. "AND direction = 'outbound' "; + end + sql = sql .. "AND (1<>1 "; + for key,extension in pairs(extensions) do + sql = sql .. "OR presence_id = '"..extension.."@"..domain_name.."' "; + end + sql = sql .. ") "; + sql = sql .. "and call_uuid is not null "; + sql = sql .. "limit 1 "; + if (debug["sql"]) then + log.notice("sql "..sql); + end + local is_child + dbh:query(sql, function(row) + -- for key, val in pairs(row) do + -- log.notice("row "..key.." "..val); + -- end + -- log.notice("-----------------------"); + is_child = (row.uuid == row.call_uuid) + uuid = row.call_uuid; + call_hostname = row.hostname; + end); + + if is_child then + -- we need intercept `parent` call e.g. call in FIFO/CallCenter Queue + if (call_hostname == hostname) then + log.notice("Found child call on local machine. Try find parent channel.") + local parent_uuid = + channel_variable(uuid, 'ent_originate_aleg_uuid') or + channel_variable(uuid, 'cc_member_session_uuid') or + channel_variable(uuid, 'fifo_bridge_uuid') or + uuid + + --[[ parent and child have to be on same box so we do not search it + if parent_uuid ~= uuid then + local sql = "SELECT hostname FROM channels WHERE uuid='" .. uuid .. "'" + call_hostname = dbh:first_value(sql) + end + --]] + + if call_hostname then + uuid = parent_uuid + if call_hostname ~= hostname then + log.noticef("Found parent call on remote machine `%s`.", call_hostname) + else + log.notice("Found parent call on local machine.") + end + end + + else + log.noticef("Found child call on remote machine `%s`.", call_hostname) + -- we can not find parent on this box because channel on other box so we have to + -- forward call to this box + session:execute("export", "sip_h_X-child_intercept_uuid="..uuid); + return make_proxy_call(pickup_number, call_hostname) + end + end + + --release FS database + dbh:release() + end + + log.noticef( "Hostname: %s Call Hostname: %s", hostname, call_hostname); --intercept a call that is ringing - if (uuid) then + if (uuid ~= nil) then if (session:getVariable("billmsec") == nil) then if (hostname == call_hostname) then session:execute("intercept", uuid); else session:execute("export", "sip_h_X-intercept_uuid="..uuid); - session:execute("export", "sip_h_X-domain_uuid="..domain_uuid); - session:execute("export", "sip_h_X-domain_name="..domain_name); - session:execute("export", "sip_h_X-callee_num="..callee_num); - port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port"); - session:execute("bridge", "sofia/"..sofia_profile_name.."/**@"..call_hostname..":"..port); - freeswitch.consoleLog("NOTICE", "Send call to other host.... \n"); + make_proxy_call(pickup_number, call_hostname) end end end diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index bfc82f5a18..db4db46d05 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -14,223 +14,5 @@ -- -- The Original Code is FusionPBX -- --- The Initial Developer of the Original Code is --- Mark J Crane --- Copyright (C) 2010 - 2014 --- the Initial Developer. All Rights Reserved. --- --- Contributor(s): --- Mark J Crane ---user defined variables - max_tries = "3"; - digit_timeout = "5000"; - extension = argv[1]; - ---set the debug options - debug["sql"] = false; - ---include config.lua - require "resources.functions.config"; - ---add the function - require "resources.functions.explode"; - require "resources.functions.trim"; - require "resources.functions.channel_utils"; - ---prepare the api object - api = freeswitch.API(); - ---connect to the database - require "resources.functions.database_handle"; - dbh = database_handle('system'); - ---get the hostname - hostname = trim(api:execute("switchname", "")); - ---check if the session is ready - if ( session:ready() ) then - --answer the session - session:answer(); - - --get session variables - domain_uuid = session:getVariable("domain_uuid"); - domain_name = session:getVariable("domain_name"); - pin_number = session:getVariable("pin_number"); - sounds_dir = session:getVariable("sounds_dir"); - context = session:getVariable("context"); - caller_id_number = session:getVariable("caller_id_number"); - sofia_profile_name = session:getVariable("sofia_profile_name"); - - --set the sounds path for the language, dialect and voice - default_language = session:getVariable("default_language"); - default_dialect = session:getVariable("default_dialect"); - default_voice = session:getVariable("default_voice"); - if (not default_language) then default_language = 'en'; end - if (not default_dialect) then default_dialect = 'us'; end - if (not default_voice) then default_voice = 'callie'; end - - --set defaults - if (digit_min_length) then - --do nothing - else - digit_min_length = "2"; - end - - if (digit_max_length) then - --do nothing - else - digit_max_length = "11"; - end - - --if the pin number is provided then require it - if (pin_number) then - --sleep - session:sleep(500); - --get the user pin number - min_digits = 2; - max_digits = 20; - digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); - --validate the user pin number - pin_number_table = explode(",",pin_number); - for index,pin_number in pairs(pin_number_table) do - if (digits == pin_number) then - --set the variable to true - auth = true; - --set the authorized pin number that was used - session:setVariable("pin_number", pin_number); - --end the loop - break; - end - end - --if not authorized play a message and then hangup - if (not auth) then - session:streamFile("phrase:voicemail_fail_auth:#"); - session:hangup("NORMAL_CLEARING"); - return; - end - end - - --get the call groups the extension is a member of - sql = "SELECT call_group FROM v_extensions "; - sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "AND (extension = '"..caller_id_number.."'"; - sql = sql .. "OR number_alias = '"..caller_id_number.."')"; - status = dbh:query(sql, function(row) - call_group = row.call_group; - freeswitch.consoleLog("NOTICE", "[intercept_group] call_group: "..call_group.."\n"); - end); - call_groups = explode(",", call_group); - - --get the extensions in the call groups - sql = "SELECT extension, number_alias FROM v_extensions "; - sql = sql .. "WHERE domain_uuid = '"..domain_uuid.."' "; - sql = sql .. "AND ("; - x = 0; - for key,call_group in pairs(call_groups) do - if (x == 0) then - if (string.len(call_group) > 0) then - sql = sql .. "call_group like '%"..call_group.."%' "; - else - sql = sql .. "call_group = '' "; - end - else - if (string.len(call_group) > 0) then - sql = sql .. "OR call_group like '%"..call_group.."%' "; - end - end - x = x + 1; - end - x = 0; - sql = sql .. ") "; - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "[intercept_group] sql "..sql.."\n"); - end - extensions = {} - status = dbh:query(sql, function(row) - local member = row.extension - if row.number_alias and #row.number_alias > 0 then - member = row.number_alias - end - extensions[x] = member - freeswitch.consoleLog("NOTICE", "[intercept_group] member "..extensions[x].."\n"); - x = x + 1; - end); - - --connect to the database - if (file_exists(database_dir.."/core.db")) then - --dbh = freeswitch.Dbh("core:core"); -- when using sqlite - dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db"); - else - require "resources.functions.database_handle"; - dbh = database_handle('switch'); - end - - --exits the script if we didn't connect properly - assert(dbh:connected()); - - --check the database to get the uuid of a ringing call - call_hostname = ""; - sql = "SELECT uuid, call_uuid, hostname, ip_addr FROM channels "; - sql = sql .. "WHERE callstate in ('RINGING', 'EARLY') "; - --sql = sql .. "AND direction = 'outbound' "; - sql = sql .. "AND ("; - x = 0; - for key,extension in pairs(extensions) do - if (x == 0) then - sql = sql .. " presence_id = '"..extension.."@"..domain_name.."' "; - else - sql = sql .. "OR presence_id = '"..extension.."@"..domain_name.."' "; - end - x = x + 1; - end - sql = sql .. ") "; - sql = sql .. "and call_uuid is not null "; - sql = sql .. "and direction = 'outbound' "; - --if (domain_count > 1) then - -- sql = sql .. "and context = '"..context.."' "; - --end - sql = sql .. "limit 1 "; - if (debug["sql"]) then - freeswitch.consoleLog("NOTICE", "[intercept_group] sql "..sql.."\n"); - end - dbh:query(sql, function(row) - --for key, val in pairs(row) do - -- freeswitch.consoleLog("NOTICE", "row "..key.." "..val.."\n"); - --end - if row.uuid == row.call_uuid then - uuid = channel_variable(row.uuid, 'ent_originate_aleg_uuid') or - channel_variable(row.uuid, 'cc_member_session_uuid') or - channel_variable(row.uuid, 'fifo_bridge_uuid') or - row.uuid - else - uuid = row.call_uuid; - end - call_hostname = row.hostname; - ip_addr = row.ip_addr; - end); - end - - freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n"); - ---intercept a call that is ringing - if (uuid ~= nil) then - if (session:getVariable("billmsec") == nil) then - if (hostname == call_hostname) then - session:execute("intercept", uuid); - else - session:execute("export", "sip_h_X-intercept_uuid="..uuid); - session:execute("export", "sip_h_X-domain_uuid="..domain_uuid); - session:execute("export", "sip_h_X-domain_name="..domain_name); - port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port"); - session:execute("bridge", "sofia/"..sofia_profile_name.."/*8@"..call_hostname..":"..port); - freeswitch.consoleLog("NOTICE", "Send call to other host.... \n"); - end - end - end - ---notes - --originate a call - --cmd = "originate user/1007@voip.example.com &intercept("..uuid..")"; - --api = freeswitch.API(); - --result = api:executeString(cmd); +require "intercept" diff --git a/resources/install/scripts/ivr_menu.lua b/resources/install/scripts/ivr_menu.lua index 554bcdc2f7..24418d531e 100644 --- a/resources/install/scripts/ivr_menu.lua +++ b/resources/install/scripts/ivr_menu.lua @@ -76,10 +76,8 @@ end end ---set the recordings directory - if (domain_count > 1) then - recordings_dir = recordings_dir .. "/"..domain_name; - end +--add the domain name to the recordings directory + recordings_dir = recordings_dir .. "/"..domain_name; --set default variable(s) tries = 0; @@ -407,8 +405,12 @@ if (row.ivr_menu_option_action == "menu-exec-app") then --get the action and data pos = string.find(row.ivr_menu_option_param, " ", 0, true); - action = string.sub(row.ivr_menu_option_param, 0, pos-1); - data = string.sub(row.ivr_menu_option_param, pos+1); + if pos then + action = string.sub(row.ivr_menu_option_param, 0, pos-1); + data = string.sub(row.ivr_menu_option_param, pos+1); + else + action, data = row.ivr_menu_option_param, "" + end --check if the option uses a regex regex = string.find(row.ivr_menu_option_digits, "(", 0, true); @@ -431,7 +433,11 @@ end if (action == "lua") then pos = string.find(data, " ", 0, true); - script = string.sub(data, 0, pos-1); + if pos then + script = string.sub(data, 0, pos-1); + else + script = data + end end end --if regex match diff --git a/resources/install/scripts/recordings.lua b/resources/install/scripts/recordings.lua index f03fd0a0d4..540258adfd 100644 --- a/resources/install/scripts/recordings.lua +++ b/resources/install/scripts/recordings.lua @@ -100,6 +100,7 @@ recording_slots = session:getVariable("recording_slots"); recording_prefix = session:getVariable("recording_prefix"); recording_name = session:getVariable("recording_name"); + domain_name = session:getVariable("domain_name"); --select the recording number if (recording_slots) then @@ -256,20 +257,9 @@ if ( session:ready() ) then domain_name = session:getVariable("domain_name"); domain_uuid = session:getVariable("domain_uuid"); - --set the base recordings dir - base_recordings_dir = recordings_dir; + --add the domain name to the recordings directory + recordings_dir = recordings_dir .. "/"..domain_name; - --use the recording_dir when the variable is set - if (session:getVariable("recordings_dir")) then - if (base_recordings_dir ~= session:getVariable("recordings_dir")) then - recordings_dir = session:getVariable("recordings_dir"); - end - end - - --get the recordings from the config.lua and append the domain_name if the system is multi-tenant - if (domain_count > 1) then - recordings_dir = recordings_dir .. "/" .. domain_name; - end --set the sounds path for the language, dialect and voice default_language = session:getVariable("default_language"); default_dialect = session:getVariable("default_dialect"); diff --git a/resources/install/scripts/resources/functions/cache.lua b/resources/install/scripts/resources/functions/cache.lua index 06548af1cd..6d121eb995 100644 --- a/resources/install/scripts/resources/functions/cache.lua +++ b/resources/install/scripts/resources/functions/cache.lua @@ -8,7 +8,13 @@ require "resources.functions.trim"; -local api = api or freeswitch.API(); +local api = api +if (not api) and freeswitch then api = freeswitch.API() else +api = {} +function api:execute() + return '-ERR UNSUPPORTTED' +end +end local function send_event(action, key) local event = freeswitch.Event("MEMCACHE", action); diff --git a/resources/install/scripts/resources/functions/database.lua b/resources/install/scripts/resources/functions/database.lua index 3cb9580d86..17abe280ba 100644 --- a/resources/install/scripts/resources/functions/database.lua +++ b/resources/install/scripts/resources/functions/database.lua @@ -1,108 +1,190 @@ require 'resources.functions.config' -require 'resources.functions.file_exists' -require 'resources.functions.database_handle' -local unpack = unpack or table.unpack +----------------------------------------------------------- +local OdbcDatabase = {} if not freeswitch then +OdbcDatabase.__index = OdbcDatabase -local Database = {} do +local odbc = require "odbc.dba" -Database.__index = Database +function OdbcDatabase.new(name) + local self = setmetatable({}, OdbcDatabase) -function Database.new(name) - local dbh = assert(name) - if type(name) == 'string' then - if name == 'switch' and file_exists(database_dir.."/core.db") then - dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db") - else - dbh = database_handle(name) - end - end - assert(dbh:connected()) + local connection_string = assert(database[name]) - local self = setmetatable({ - _dbh = dbh; - }, Database) + local typ, dsn, user, password = connection_string:match("^(.-)://(.-):(.-):(.-)$") + assert(typ == 'odbc', "unsupported connection string:" .. connection_string) - return self + self._dbh = odbc.Connect(dsn, user, password) + + return self end -function Database:query(sql, fn) - return self._dbh:query(sql, fn) +function OdbcDatabase:query(sql, fn) + self._rows_affected = nil + if fn then + return self._dbh:neach(sql, function(row) + local o = {} + for k, v in pairs(row) do + if v == odbc.NULL then + o[k] = nil + else + o[k] = tostring(v) + end + end + return fn(o) + end) + end + local ok, err = self._dbh:exec(sql) + if not ok then return nil, err end + self._rows_affected = ok + return self._rows_affected +end + +function OdbcDatabase:affected_rows() + return self._rows_affected; +end + +function OdbcDatabase:release() + if self._dbh then + self._dbh:destroy() + self._dbh = nil + end +end + +function OdbcDatabase:connected() + return self._dbh and self._dbh:connected() +end + +end +----------------------------------------------------------- + +----------------------------------------------------------- +local FsDatabase = {} if freeswitch then + +require "resources.functions.file_exists" +require "resources.functions.database_handle" + +FsDatabase.__index = FsDatabase + +function FsDatabase.new(name) + local dbh = assert(name) + if type(name) == 'string' then + if name == 'switch' and file_exists(database_dir.."/core.db") then + dbh = freeswitch.Dbh("sqlite://"..database_dir.."/core.db") + else + dbh = database_handle(name) + end + end + assert(dbh:connected()) + + local self = setmetatable({ + _dbh = dbh; + }, FsDatabase) + + return self +end + +function FsDatabase:query(sql, fn) + if fn then + return self._dbh:query(sql, fn) + end + return self._dbh:query(sql) +end + +function FsDatabase:affected_rows() + if self._dbh then + return self._dbh:affected_rows() + end +end + +function FsDatabase:release() + if self._dbh then + self._dbh:release() + self._dbh = nil + end +end + +function FsDatabase:connected() + return self._dbh and self._dbh:connected() +end + +end +----------------------------------------------------------- + +----------------------------------------------------------- +local Database = {} do +Database.__index = Database +Database.__base = freeswitch and FsDatabase or OdbcDatabase +Database = setmetatable(Database, Database.__base) + +function Database.new(...) + local self = Database.__base.new(...) + setmetatable(self, Database) + return self end function Database:first_row(sql) - local result - local ok, err = self:query(sql, function(row) - result = row - return 1 - end) - if not ok then return nil, err end - return result + local result + local ok, err = self:query(sql, function(row) + result = row + return 1 + end) + if not ok then return nil, err end + return result end function Database:first_value(sql) - local result, err = self:first_row(sql) - if not result then return nil, err end - local k, v = next(result) - return v + local result, err = self:first_row(sql) + if not result then return nil, err end + local k, v = next(result) + return v end function Database:first(sql, ...) - local result, err = self:first_row(sql) - if not result then return nil, err end - local t, n = {}, select('#', ...) - for i = 1, n do - t[i] = result[(select(i, ...))] - end - return unpack(t, 1, n) + local result, err = self:first_row(sql) + if not result then return nil, err end + local t, n = {}, select('#', ...) + for i = 1, n do + t[i] = result[(select(i, ...))] + end + return unpack(t, 1, n) end function Database:fetch_all(sql) - local result = {} - local ok, err = self:query(sql, function(row) - result[#result + 1] = row - end) - if not ok then return nil, err end - return result + local result = {} + local ok, err = self:query(sql, function(row) + result[#result + 1] = row + end) + if (not ok) and err then return nil, err end + return result end -function Database:release(sql) - if self._dbh then - self._dbh:release() - self._dbh = nil - end -end +function Database.__self_test__(...) + local db = Database.new(...) + assert(db:connected()) -function Database:connected(sql) - return self._dbh and self._dbh:connected() -end + assert("1" == db:first_value("select 1 as v union all select 2 as v")) -function Database.__self_test__(name) - local db = Database.new(name or 'system') - assert(db:connected()) + local t = assert(db:first_row("select '1' as v union all select '2' as v")) + assert(t.v == "1") - assert("1" == db:first_value("select 1 as v")) + t = assert(db:fetch_all("select '1' as v union all select '2' as v")) + assert(#t == 2) + assert(t[1].v == "1") + assert(t[2].v == "2") - local t = assert(db:first_row("select 1 as v")) - assert(t.v == "1") + local a, b = assert(db:first("select '1' as b, '2' as a", 'a', 'b')) + assert(a == "2") + assert(b == "1") - t = assert(db:fetch_all("select 1 as v union all select 2 as v")) - assert(#t == 2) - assert(t[1].v == "1") - assert(t[2].v == "2") + -- assert(nil == db:first_value("some non sql query")) - local a, b = assert(db:first("select 1 as b, 2 as a", 'a', 'b')) - assert(a == "2") - assert(b == "1") - - -- assert(nil == db:first_value("some non sql query")) - - db:release() - assert(not db:connected()) + db:release() + assert(not db:connected()) + print(" * databse - OK!") end end - --- Database.__self_test__() +----------------------------------------------------------- return Database \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/esl.lua b/resources/install/scripts/resources/functions/esl.lua new file mode 100644 index 0000000000..f334be191c --- /dev/null +++ b/resources/install/scripts/resources/functions/esl.lua @@ -0,0 +1,169 @@ +local function class(base) + local t = base and setmetatable({}, base) or {} + t.__index = t + t.__class = t + t.__base = base + + function t.new(...) + local o = setmetatable({}, t) + if o.__init then + if t == ... then -- we call as Class:new() + return o:__init(select(2, ...)) + else -- we call as Class.new() + return o:__init(...) + end + end + return o + end + + return t +end + +local EventSocket = class() do + +if not freeswitch then + +local socket = require "socket" +local ESLParser = require "lluv.esl".ESLParser +local split_status = require "lluv.esl.utils".split_status +local Database = require "resources.functions.database" + +local EOL = '\n' + +local host, port, auth + +function EventSocket:__init() + if not host then + local db = Database.new('system') + local settings, err = db:first_row("select event_socket_ip_address, event_socket_port, event_socket_password from v_settings") + if not settings then return nil, err end + host, port, auth = settings.event_socket_ip_address, settings.event_socket_port, settings.event_socket_password + end + + return self:_connect(host, port, auth) +end + +function EventSocket:_connect(host, port, password) + local err + self._cnn, err = socket.connect(host, port) + if not self._cnn then return nil, err end + + self._cnn:settimeout(1) + + self._parser = ESLParser.new() + local auth + while true do + local event + event, err = self:_recv_event() + if not event then break end + + local ct = event:getHeader('Content-Type') + if ct == 'auth/request' then + self._cnn:send('auth ' .. password .. EOL .. EOL) + elseif ct == 'command/reply' then + local reply = event:getHeader('Reply-Text') + if reply then + local ok, status, msg = split_status(reply) + if ok then auth = true else err = msg end + else + err = 'invalid response' + end + break + end + end + + if not auth then + self._cnn:close() + self._cnn = nil + return nil, err + end + + return self +end + +function EventSocket:_recv_event() + local event, err = self._parser:next_event() + + while event == true do + local str, rst + str, err, rst = self._cnn:receive("*l") + if str then self._parser:append(str):append(EOL) end + if rst then self._parser:append(rst) end + if err and err ~= 'timeout' then + break + end + event = self._parser:next_event() + end + + if (not event) or (event == true) then + return nil, err + end + + return event +end + +function EventSocket:_request(cmd) + if not self._cnn then return nil, 'closed' end + + for str in (cmd .. '\n'):gmatch("(.-)\n") do + self._cnn:send(str .. EOL) + end + self._cnn:send(EOL) + + return self:_recv_event() +end + +function EventSocket:api(cmd) + local event, err = self:_request('api ' .. cmd) + if not event then return nil, err end + local body = event:getBody() + if body then + local ok, status, msg = split_status(body) + if ok == nil then return body end + return ok, status, msg + end + return event:getReply() +end + +function EventSocket:close() + if self._cnn then + self._cnn:close() + self._cnn = nil + end +end + +end + +if freeswitch then + +local api + +-- [+-][OK|ERR|USAGE|...][Message] +local function split_status(str) + local ok, status, msg = string.match(str, "^%s*([-+])([^%s]+)%s*(.-)%s*$") + if not ok then return nil, str end + return ok == '+', status, msg +end + +function EventSocket:__init() + self._api = api or freeswitch.API() + api = self._api + return self +end + +function EventSocket:api(cmd) + local result = self._api:executeString(cmd) + local ok, status, msg = split_status(result) + if ok == nil then return result end + return ok, status, msg +end + +function EventSocket:close() + self._api = nil +end + +end + +end + +return EventSocket diff --git a/resources/install/scripts/resources/functions/lazy_settings.lua b/resources/install/scripts/resources/functions/lazy_settings.lua new file mode 100644 index 0000000000..c6950b4d4e --- /dev/null +++ b/resources/install/scripts/resources/functions/lazy_settings.lua @@ -0,0 +1,172 @@ +-- -- Global settings +-- local settings = Settings.new('system') +-- print(settings:get('switch', 'base', 'dir')) +-- +-- Domain settings (to `fax_retry.lua`) +-- local Settings = require "resources.functions.settings" +-- local settings = Settings.new(dbh, domain_name, domain_uuid) +-- storage_type = settings:get('fax', 'storage_type', 'text') or '' +-- storage_path = settings:get('fax', 'storage_path', 'text') or '' +-- storage_path = storage_path +-- :gsub("${domain_name}", domain_name) +-- :gsub("${voicemail_id}", voicemail_id) +-- :gsub("${voicemail_dir}", voicemail_dir) + +local Database = require "resources.functions.database" +local cache = require "resources.functions.cache" +require "resources.functions.split" + +----------------------------------------------------------- +local Settings = {} do +Settings.__index = Settings + +local NONE = '15783958-912c-4893-8866-4ccd1ca73c6e' + +local function append(t, v) + t[#t+1] = v + return t +end + +local function append_setting(array, category, subcategory, name, value) + --add the category array + if not array[category] then + array[category] = {} + end + + --add the subcategory array + if not array[category][subcategory] then + array[category][subcategory] = {} + end + + --set the name and value + if (name == "array") then + if not array[category][subcategory][name] then + array[category][subcategory][name] = {} + end + append(array[category][subcategory][name], value); + elseif value ~= nil then + array[category][subcategory][name] = value; + end +end + +function Settings.new(db, domain_name, domain_uuid) + local self = setmetatable({}, Settings) + self._array = {} + self._db = db + self._domain_name = domain_name + self._domain_uuid = domain_uuid + + return self +end + +function Settings:_cache_key(category, subcategory, name) + return 'setting:' .. (self._domain_name or '') .. ':' .. category .. ':' .. subcategory .. ':' .. name +end + +function Settings:set(category, subcategory, name, value) + append_setting(self._array, category, subcategory, name, value) + return self +end + +function Settings:get(category, subcategory, name) + local a = self._array + local v = a[category] and a[category][subcategory] and a[category][subcategory][name] + if v == NONE then return nil end + if v ~= nil then return v end + + local key = self:_cache_key(category, subcategory, name) + + v = cache.get(key) + if v then + if v ~= NONE and name == 'array' then + v = split(v, '/+/', true) + end + self:set(category, subcategory, name, v) + if v == NONE then return nil end + return v + end + + return self:_load(category, subcategory, name) +end + +function Settings:_load(category, subcategory, name) + local domain_uuid = self._domain_uuid + local db = self._db + if type(self._db) == 'string' then + db = Database.new(self._db) + end + + local found = false + --get the domain settings + if domain_uuid then + local sql = "SELECT domain_setting_uuid,domain_setting_category,domain_setting_subcategory,domain_setting_name,domain_setting_value " + sql = sql .. "FROM v_domain_settings "; + sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "'"; + sql = sql .. "AND domain_setting_enabled = 'true' "; + sql = sql .. "AND domain_setting_category = '" .. category .."'"; + sql = sql .. "AND domain_setting_subcategory = '" .. subcategory .. "'"; + sql = sql .. "AND domain_setting_name = '" .. name .. "'"; + sql = sql .. "AND domain_setting_value is not null "; + sql = sql .. "ORDER BY domain_setting_category, domain_setting_subcategory ASC "; + + db:query(sql, function(row) + found = true; + self:set( + row.domain_setting_category, + row.domain_setting_subcategory, + row.domain_setting_name, + row.domain_setting_value + ) + end) + end + + if not found then + local sql = "SELECT default_setting_uuid,default_setting_category,default_setting_subcategory,default_setting_name,default_setting_value " + sql = sql .. "FROM v_default_settings "; + sql = sql .. "WHERE default_setting_enabled = 'true' "; + sql = sql .. "AND default_setting_category = '" .. category .."'"; + sql = sql .. "AND default_setting_subcategory = '" .. subcategory .. "'"; + sql = sql .. "AND default_setting_name = '" .. name .. "'"; + sql = sql .. "AND default_setting_value is not null "; + sql = sql .. "ORDER BY default_setting_category, default_setting_subcategory ASC"; + + db:query(sql, function(row) + found = true; + self:set( + row.default_setting_category, + row.default_setting_subcategory, + row.default_setting_name, + row.default_setting_value + ) + end) + end + + if not found then + self:set(category, subcategory, name, NONE) + end + + local a = self._array + local v = a[category] and a[category][subcategory] and a[category][subcategory][name] + + if cache.support() then + local key = self:_cache_key(category, subcategory, name) + local value = v + if v ~= NONE and name == 'array' then + value = table.concat(v, '/+/') + end + local exp = expire and expire["settings"] or 3600 + cache.set(key, value, exp) + end + + if type(self._db) == 'string' then + db:release() + end + + if v == NONE then return nil end + return v +end + +end +----------------------------------------------------------- + +return Settings diff --git a/resources/install/scripts/resources/functions/log.lua b/resources/install/scripts/resources/functions/log.lua index b6cb59652b..eb73e5c13c 100644 --- a/resources/install/scripts/resources/functions/log.lua +++ b/resources/install/scripts/resources/functions/log.lua @@ -3,9 +3,14 @@ -- log.noticef("%s %s", "hello", "world") -- -- log if debug.SQL or debug.xml_handler.SQL then -- log.tracef("SQL", "SQL is %s", sql) - -local function log(name, level, msg) - freeswitch.consoleLog(level, "[" .. name .. "] " .. msg .. "\n") +local log if freeswitch then + log = function (name, level, msg) + freeswitch.consoleLog(level, "[" .. name .. "] " .. msg .. "\n") + end +else + log = function (name, level, msg) + print(os.date("%Y-%m-%d %X") .. '[' .. level:upper() .. '] [' .. name .. '] ' .. msg) + end end local function logf(name, level, ...) @@ -41,6 +46,7 @@ local LEVELS = { 'warning', 'notice', 'info', + 'debug', } local TRACE_LEVEL = 'notice' diff --git a/resources/install/scripts/resources/functions/send_mail.lua b/resources/install/scripts/resources/functions/send_mail.lua new file mode 100644 index 0000000000..430983ed2e --- /dev/null +++ b/resources/install/scripts/resources/functions/send_mail.lua @@ -0,0 +1,107 @@ + +local send_mail + +if not freeswitch then + local Settings = require "resources.functions.lazy_settings" + local Database = require "resources.functions.database" + local log = require "resources.functions.log".sendmail + local sendmail = require "sendmail" + local uuid = require "uuid" + + function send_mail(headers, address, message, file) + local domain_uuid = headers["X-FusionPBX-Domain-UUID"] + local domain_name = headers["X-FusionPBX-Domain-Name"] + local email_type = headers["X-FusionPBX-Email-Type"] or 'info' + local call_uuid = headers["X-FusionPBX-Email-Type"] + local db = dbh or Database.new('system') + local settings = Settings.new(db, domain_name, domain_uuid) + + local ssl = settings:get('email', 'smtp_secure', 'var'); + + local ok, err = sendmail{ + server = { + address = settings:get('email','smtp_host','var'); + user = settings:get('email','smtp_username','var'); + password = settings:get('email','smtp_password','var'); + ssl = (ssl == 'true') and { verify = {"none"} }; + }, + + from = { + title = settings:get('email', 'smtp_from_name', 'var'); + address = settings:get('email', 'smtp_from', 'var'); + }, + + to = { + address = address; + }, + + message = message; + file = file; + } + + if not ok then + log.warningf("Mailer Error: %s", err) + + local email_uuid = uuid.new() + local sql = "insert into v_emails ( " + sql = sql .. "email_uuid, " + if call_uuid then sql = sql .. "call_uuid, " end + sql = sql .. "domain_uuid, " + sql = sql .. "sent_date, " + sql = sql .. "type, " + sql = sql .. "status, " + sql = sql .. "email " + sql = sql .. ") values ( " + sql = sql .. "'" .. email_uuid .. "', " + if call_uuid then sql = sql .. "'" .. call_uuid .. "', " end + sql = sql .. "'" .. domain_uuid .. "', " + sql = sql .. "now()," + sql = sql .. "'" .. email_type .. "', " + sql = sql .. "'failed', " + sql = sql .. "'' " + sql = sql .. ") " + + db:query(sql) + + log.infof("Retained in v_emails as email_uuid = %s", email_uuid) + else + log.infof("Mail to %s sent!", address) + end + end +end + +if freeswitch then + function send_mail(headers, address, message, file) + local xheaders = "{" + for k,v in pairs(headers) do + xheaders = xheaders .. ('"%s":"%s",'):format(k, v) + end + xheaders = xheaders:sub(1,-2) .. '}' + + local subject = message[1] + local body = message[2] or '' + + local mail_headers = + "To: " .. address .. "\n" .. + "From: " .. address .. "\n" .. + "Subject: " .. subject .. "\n" .. + "X-Headers: " .. xheaders + + if file then + freeswitch.email(address, address, mail_headers, body, file) + else + freeswitch.email(address, address, mail_headers, body) + end + end +end + +return send_mail + +-- local headers = { +-- ["X-FusionPBX-Domain-UUID"] = '2d171c4c-b237-49ca-9d76-9cffc1618fa7'; +-- ["X-FusionPBX-Domain-Name"] = 'domain.com'; +-- ["X-FusionPBX-Email-Type"] = 'voicemail'; +-- } +-- send_mail(headers, 'alexey@domain.com', {'hello', 'world'}) + + diff --git a/resources/install/scripts/resources/functions/sleep.lua b/resources/install/scripts/resources/functions/sleep.lua new file mode 100644 index 0000000000..e7ace57abd --- /dev/null +++ b/resources/install/scripts/resources/functions/sleep.lua @@ -0,0 +1,15 @@ +if freeswitch then + +function sleep(ms) + freeswitch.msleep(ms) +end + +else + +local socket = require "socket" + +function sleep(ms) + socket.sleep(ms/1000) +end + +end diff --git a/resources/install/scripts/resources/functions/split.lua b/resources/install/scripts/resources/functions/split.lua new file mode 100644 index 0000000000..c46e0cad0b --- /dev/null +++ b/resources/install/scripts/resources/functions/split.lua @@ -0,0 +1,27 @@ +function split(str, sep, plain) + local b, res = 1, {} + while b <= #str do + local e, e2 = string.find(str, sep, b, plain) + if e then + res[#res + 1] = string.sub(str, b, e-1) + b = e2 + 1 + else + res[#res + 1] = string.sub(str, b) + break + end + end + return res +end + +function split_first(str, sep, plain) + local e, e2 = string.find(str, sep, nil, plain) + if e then + return string.sub(str, 1, e - 1), string.sub(str, e2 + 1) + end + return str +end + +local unpack = unpack or table.unpack + +function usplit(...) return unpack(split(...)) end + diff --git a/resources/install/scripts/resources/functions/text.lua b/resources/install/scripts/resources/functions/text.lua new file mode 100644 index 0000000000..11bf0933a2 --- /dev/null +++ b/resources/install/scripts/resources/functions/text.lua @@ -0,0 +1,71 @@ +--- +-- @tparam table dict Dictionary +-- @tparam[opt='en'] string language default language +-- @tparam[opt='us'] string dialect default language +-- @return[1] nil if key is unknown +-- @return[2] empty string if language/dialect unknown or there no appropriate value for default language/dialect +-- @return[3] translated value accordint dictionary/language/dialect +-- +-- @usage +-- local dict = { +-- ['label-text'] = { +-- ['en-us'] = 'text'; +-- ['ru-ru'] = 'текст'; +-- } +-- } +-- local text = Text.new(dict) +-- -- use global `default_language` and `default_dialect` to resolve language +-- var = text['label-attached'] +-- -- use prefix form +-- var = text'label-attached' +-- -- Implicit specify language +-- var = text('label-attached', 'ru', 'ru') +-- -- set global variables(you can set them even after ctor call) +-- default_language, default_dialect = 'ru', 'ru' +-- var = text['label-attached'] +local function make_text(dict, language, dialect) + if not (language and dialect) then + language, dialect = 'en', 'us' + end + + if type(dict) == 'string' then + dict = require(dict) + end + + local default = (language .. '-' .. dialect):lower() + + local function index(_, k) + local t = dict[k] + if not t then return end + + local lang + if default_language and default_dialect then + lang = (default_language .. '-' .. default_dialect):lower() + end + if not lang then lang = default end + return t[lang] or t[default] or '' + end + + local function call(self, k, language, dialect) + if language and dialect then + local t = dict[k] + if not t then return end + local lang = (language .. '-' .. dialect):lower() + local v = t[lang] + if v then return v end + end + return self[k] + end + + return setmetatable({},{ + __newindex = function() + error('Can not add field to proxy') + end; + __index = index; + __call = call; + }) +end + +return { + new = make_text; +} \ No newline at end of file diff --git a/resources/switch.php b/resources/switch.php index e4eb04c532..bf96fa85a3 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -1267,10 +1267,24 @@ if (!function_exists('switch_conf_xml')) { //prepare the php variables if (stristr(PHP_OS, 'WIN')) { - $bindir = getenv(PHPRC); - $v_mailer_app ='""'. $bindir."/php". '" -f '.$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure/v_mailto.php -- "'; - $v_mailer_app = sprintf("'%s'", $v_mailer_app); + $bindir = find_php_by_extension(); + if(!$bindir) + $bindir = getenv(PHPRC); + + $secure_path = path_join($_SERVER["DOCUMENT_ROOT"], PROJECT_PATH, 'secure'); + + $v_mail_bat = path_join($secure_path, 'mailto.bat'); + $v_mail_cmd = '@' . + '"' . str_replace('/', '\\', path_join($bindir, 'php.exe')) . '" ' . + '"' . str_replace('/', '\\', path_join($secure_path, 'v_mailto.php')) . '" '; + + $fout = fopen($v_mail_bat, "w+"); + fwrite($fout, $v_mail_cmd); + fclose($fout); + + $v_mailer_app = '"' . str_replace('/', '\\', $v_mail_bat) . '"'; $v_mailer_app_args = ""; + unset($v_mail_bat, $v_mail_cmd, $secure_path, $bindir, $fout); } else { if (file_exists(PHP_BINDIR.'/php')) { define("PHP_BIN", "php"); } @@ -1453,4 +1467,50 @@ if (!function_exists('save_switch_xml')) { } } +if(!function_exists('path_join')) { + function path_join() { + $args = func_get_args(); + $paths = array(); + foreach ($args as $arg) { + $paths = array_merge($paths, (array)$arg); + } + + $prefix = null; + foreach($paths as &$path) { + if($prefix === null && strlen($path) > 0) { + if(substr($path, 0, 1) == '/') $prefix = '/'; + else $prefix = ''; + } + $path = trim( $path, '/' ); + } + + if($prefix === null){ + return ''; + } + + $paths = array_filter($paths); + + return $prefix . join('/', $paths); + } +} + +if(!function_exists('find_php_by_extension')) { + /*Tesetd on WAMP and OpenServer*/ + function find_php_by_extension(){ + $bin_dir = get_cfg_var('extension_dir'); + + while($bin_dir){ + $bin_dir = dirname($bin_dir); + $php_bin = path_join($bin_dir, 'php.exe'); + if(file_exists($php_bin)) + break; + } + + if(!$bin_dir) + return false; + + return $bin_dir; + } +} + ?> diff --git a/resources/templates/conf/lang/en/ivr/wakeup.xml b/resources/templates/conf/lang/en/ivr/wakeup.xml index 8c41736405..7ce070c06f 100644 --- a/resources/templates/conf/lang/en/ivr/wakeup.xml +++ b/resources/templates/conf/lang/en/ivr/wakeup.xml @@ -5,49 +5,51 @@ - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,13 +59,7 @@ - - - - - - - + @@ -73,13 +69,10 @@ - - - + - - - + + @@ -90,13 +83,20 @@ - - - - - - - + + + + + + + + + + + + + + @@ -104,26 +104,45 @@ - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - + + - + \ No newline at end of file diff --git a/resources/templates/conf/lang/en/wakeup/sounds.xml b/resources/templates/conf/lang/en/wakeup/sounds.xml index 8c41736405..57d54bfd11 100644 --- a/resources/templates/conf/lang/en/wakeup/sounds.xml +++ b/resources/templates/conf/lang/en/wakeup/sounds.xml @@ -5,49 +5,34 @@ - - - - - - - - - - - - - - - - - - - - + + - - - - + + + + + + + + + - + - - - - - + + + @@ -57,13 +42,7 @@ - - - - - - - + @@ -73,13 +52,10 @@ - - - + - - - + + @@ -90,12 +66,8 @@ - - - - - - + + @@ -104,26 +76,45 @@ - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - + + - + \ No newline at end of file diff --git a/resources/templates/conf/sip_profiles/external-ipv6.xml.noload b/resources/templates/conf/sip_profiles/external-ipv6.xml.noload new file mode 100644 index 0000000000..b980a94d1b --- /dev/null +++ b/resources/templates/conf/sip_profiles/external-ipv6.xml.noload @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/templates/provision/cisco/7940/SIPDefault.cnf b/resources/templates/provision/cisco/7940/SIPDefault.cnf index 489f5c97ea..e69de29bb2 100644 --- a/resources/templates/provision/cisco/7940/SIPDefault.cnf +++ b/resources/templates/provision/cisco/7940/SIPDefault.cnf @@ -1,131 +0,0 @@ -# Image Version -image_version: "P0S3-08-7-00" - -# Proxy Server -proxy1_address: "192.168.1.1" - -# Proxy Server Port (default - 5060) -proxy1_port:"5060" - -# Emergency Proxy info -proxy_emergency: "192.168.1.1" -proxy_emergency_port: "5060" - -# Backup Proxy info -proxy_backup: "192.168.1.1" -proxy_backup_port: "5060" - -# Outbound Proxy info -outbound_proxy: "" -outbound_proxy_port: "5060" - -# NAT/Firewall Traversal -nat_enable: "0" -nat_address: "" -voip_control_port: "5060" -start_media_port: "16384" -end_media_port: "32766" -nat_received_processing: "0" - -# Proxy Registration (0-disable (default), 1-enable) -proxy_register: "1" - -# Phone Registration Expiration [1-3932100 sec] (Default - 3600) -timer_register_expires: "80" - -# Codec for media stream (g711ulaw (default), g711alaw, g729) -preferred_codec: "none" - -# TOS bits in media stream [0-5] (Default - 5) -tos_media: "5" - -# Enable VAD (0-disable (default), 1-enable) -enable_vad: "0" - -# Allow for the bridge on a 3way call to join remaining parties upon hangup -cnf_join_enable: "1" ; 0-Disabled, 1-Enabled (default) - -# Allow Transfer to be completed while target phone is still ringing -semi_attended_transfer: "0" ; 0-Disabled, 1-Enabled (default) - -# Telnet Level (enable or disable the ability to telnet into this phone -telnet_level: "2" ; 0-Disabled (default), 1-Enabled, 2-Privileged - -# Inband DTMF Settings (0-disable, 1-enable (default)) -dtmf_inband: "1" - -# Out of band DTMF Settings (none-disable, avt-avt enable (default), avt_always - always avt ) -dtmf_outofband: "avt" - -# DTMF dB Level Settings (1-6dB down, 2-3db down, 3-nominal (default), 4-3db up, 5-6dB up) -dtmf_db_level: "3" - -# SIP Timers -timer_t1: "500" ; Default 500 msec -timer_t2: "4000" ; Default 4 sec -sip_retx: "10" ; Default 11 -sip_invite_retx: "6" ; Default 7 -timer_invite_expires: "180" ; Default 180 sec - -# Setting for Message speeddial to UOne box -messages_uri: "*97" - -# TFTP Phone Specific Configuration File Directory -tftp_cfg_dir: "" - -# Time Server -sntp_mode: "unicast" -sntp_server: "192.168.1.1" -time_zone: "EST" -dst_offset: "1" -dst_start_month: "Mar" -dst_start_day: "" -dst_start_day_of_week: "Sun" -dst_start_week_of_month: "2" -dst_start_time: "02" -dst_stop_month: "Nov" -dst_stop_day: "" -dst_stop_day_of_week: "Sunday" -dst_stop_week_of_month: "1" -dst_stop_time: "2" -dst_auto_adjust: "1" - -# Do Not Disturb Control (0-off, 1-on, 2-off with no user control, 3-on with no user control) -dnd_control: "2" ; Default 0 (Do Not Disturb feature is off) - -# Caller ID Blocking (0-disabled, 1-enabled, 2-disabled no user control, 3-enabled no user control) -callerid_blocking: "0" ; Default 0 (Disable sending all calls as anonymous) - -# Anonymous Call Blocking (0-disbaled, 1-enabled, 2-disabled no user control, 3-enabled no user control) -anonymous_call_block: "0" ; Default 0 (Disable blocking of anonymous calls) - -# Call Waiting (0-disabled, 1-enabled, 2-disabled with no user control, 3-enabled with no user control) -call_waiting: "1" ; Default 1 (Call Waiting enabled) - -# DTMF AVT Payload (Dynamic payload range for AVT tones - 96-127) -dtmf_avt_payload: "101" ; Default 100 - -# XML file that specifies the dialplan desired -dial_template: "dialplan" - -# Network Media Type (auto, full100, full10, half100, half10) -network_media_type: "auto" - -#Autocompletion During Dial (0-off, 1-on [default]) -autocomplete: "1" - -#Time Format (0-12hr, 1-24hr [default]) -time_format_24hr: "0" - -# URL for external Phone Services -#services_url: "http://{$domain_name}/app/provision/?file=services.php" - -# URL for external Directory location -directory_url: "http://{$domain_name}/app/provision/?file=directory.php" - -# URL for branding logo -#logo_url: "http://{$domain_name}/app/provision/logo.bmp" - -# Remote Party ID -remote_party_id: 1 ; 0-Disabled (default), 1-Enabled - diff --git a/resources/templates/provision/cisco/7940/SIP{$mac}.cnf b/resources/templates/provision/cisco/7940/SIP{$mac}.cnf index 66cdbae8a0..4a4bb88bdb 100644 --- a/resources/templates/provision/cisco/7940/SIP{$mac}.cnf +++ b/resources/templates/provision/cisco/7940/SIP{$mac}.cnf @@ -1,19 +1,150 @@ -phone_label: "{$display_name_1}" -proxy1_address: "{$server_address_1}" +{if isset($cisco_time_zone)} +# Image version +image_version: "{$cisco_image_version}" +{/if} + +# Phone settings +phone_label: "{$label}" proxy_register: 1 timer_register_expires: 300 preferred_codec: g711ulaw enable_vad: 0 dial_template: "dialplan" -line1_name: "{$user_id_1}" -line1_displayname: "{$user_id_1}" -line1_shortname: "{$short_name_1}" -line1_authname: "{$auth_id_1}" -line1_password: "{$user_password_1}" +{foreach $lines as $row}reg.{$row.line_number}.displayName="{$row.display_name}" +#registration information +proxy{$row.line_number}_address: "{$row.server_address}" +proxy{$row.line_number}_port:"{$row.sip_port}" +line{$row.line_number}_name: "{$row.user_id}" +line{$row.line_number}_displayname: "{$row.user_id}" +line{$row.line_number}_shortname: "{$row.display_name}" +line{$row.line_number}_authname: "{$row.auth_id}" +line{$row.line_number}_password: "{$row.password}" -line2_name: "{$user_id_2}" -line2_displayname: "{$user_id_2}" -line2_shortname: "{$short_name_2}" -line2_authname: "{$auth_id_2}" -line2_password: "{$user_password_2}" \ No newline at end of file +{/foreach} +# Emergency Proxy info +proxy_emergency: "{$proxy_emergency}" +proxy_emergency_port: "{$proxy_emergency_port}" + +# Backup Proxy info +proxy_backup: "{$proxy_backup}" +proxy_backup_port: "{$proxy_backup_port}" + +# Outbound Proxy info +outbound_proxy: "{$outbound_proxy}" +outbound_proxy_port: "{$outbound_proxy_port}" + +# NAT/Firewall Traversal +voip_control_port: "5060" +start_media_port: "16384" +end_media_port: "32768" +nat_received_processing: "0" +nat_enable: "{if isset($nat_enable)}{$nat_enable}{else}1{/if}" +nat_address: "{$nat_nat_address}" + +# Sync value of the phone used for remote reset +sync: 1 ; Default 1 + +# Proxy Registration (0-disable (default), 1-enable) +proxy_register: "1" + +# Phone Registration Expiration [1-3932100 sec] (Default - 3600) +timer_register_expires: "80" + +# Codec for media stream (g711ulaw (default), g711alaw, g729) +preferred_codec: "none" + +# TOS bits in media stream [0-5] (Default - 5) +tos_media: "5" + +# Enable VAD (0-disable (default), 1-enable) +enable_vad: "0" + +# Allow for the bridge on a 3way call to join remaining parties upon hangup +cnf_join_enable: "1" ; 0-Disabled, 1-Enabled (default) + +# Allow Transfer to be completed while target phone is still ringing +semi_attended_transfer: "0" ; 0-Disabled, 1-Enabled (default) + +# Telnet Level (enable or disable the ability to telnet into this phone +telnet_level: "2" ; 0-Disabled (default), 1-Enabled, 2-Privileged + +# Inband DTMF Settings (0-disable, 1-enable (default)) +dtmf_inband: "1" + +# Out of band DTMF Settings (none-disable, avt-avt enable (default), avt_always - always avt ) +dtmf_outofband: "avt" + +# DTMF dB Level Settings (1-6dB down, 2-3db down, 3-nominal (default), 4-3db up, 5-6dB up) +dtmf_db_level: "3" + +# SIP Timers +timer_t1: "500" ; Default 500 msec +timer_t2: "4000" ; Default 4 sec +sip_retx: "10" ; Default 11 +sip_invite_retx: "6" ; Default 7 +timer_invite_expires: "180" ; Default 180 sec + +# Setting for Message speeddial to UOne box +messages_uri: "*97" + +# TFTP Phone Specific Configuration File Directory +tftp_cfg_dir: "" + +# Time Server +sntp_mode: "unicast" +sntp_server: "{$ntp_server_primary}" +{if isset($cisco_time_zone)} +time_zone: "{$cisco_time_zone}" +{/if} +dst_offset: "1" +dst_start_month: "Mar" +dst_start_day: "" +dst_start_day_of_week: "Sun" +dst_start_week_of_month: "2" +dst_start_time: "02" +dst_stop_month: "Nov" +dst_stop_day: "" +dst_stop_day_of_week: "Sunday" +dst_stop_week_of_month: "1" +dst_stop_time: "2" +dst_auto_adjust: "1" + +# Do Not Disturb Control (0-off, 1-on, 2-off with no user control, 3-on with no user control) +dnd_control: "2" ; Default 0 (Do Not Disturb feature is off) + +# Caller ID Blocking (0-disabled, 1-enabled, 2-disabled no user control, 3-enabled no user control) +callerid_blocking: "0" ; Default 0 (Disable sending all calls as anonymous) + +# Anonymous Call Blocking (0-disbaled, 1-enabled, 2-disabled no user control, 3-enabled no user control) +anonymous_call_block: "0" ; Default 0 (Disable blocking of anonymous calls) + +# Call Waiting (0-disabled, 1-enabled, 2-disabled with no user control, 3-enabled with no user control) +call_waiting: "1" ; Default 1 (Call Waiting enabled) + +# DTMF AVT Payload (Dynamic payload range for AVT tones - 96-127) +dtmf_avt_payload: "101" ; Default 100 + +# XML file that specifies the dialplan desired +dial_template: "dialplan" + +# Network Media Type (auto, full100, full10, half100, half10) +network_media_type: "auto" + +#Autocompletion During Dial (0-off, 1-on [default]) +autocomplete: "1" + +#Time Format (0-12hr, 1-24hr [default]) +time_format_24hr: "0" + +# URL for external Phone Services +#services_url: "http://{$domain_name}/app/provision/file/services.xml" + +# URL for external Directory location +directory_url: "http://{$domain_name}/app/provision/file/directory.xml" + +# URL for branding logo +#logo_url: "http://{$domain_name}/app/provision/logo.bmp" + +# Remote Party ID +remote_party_id: 1 ; 0-Disabled (default), 1-Enabled diff --git a/resources/templates/provision/cisco/7940/directory-enterprise.xml b/resources/templates/provision/cisco/7940/directory-enterprise.xml index 7b84648f36..5c977112b0 100644 --- a/resources/templates/provision/cisco/7940/directory-enterprise.xml +++ b/resources/templates/provision/cisco/7940/directory-enterprise.xml @@ -1,31 +1,25 @@ - + Enterprise Please choose... - - Dial - SoftKey:Select - 1 - - {assign var=x value=1} - {foreach $contacts as $row} - {if $row.contact_category == "enterprise"} - - {if $row.contact_name_given != ""} - {$row.contact_name_given} {$row.contact_name_family} - {else} - {$row.contact_organization} - {/if} - {if $row.phone_number != ""} - Dial:{$row.phone_number}# - {else} - Dial:{$row.phone_extension}# - {/if} - - {/if} - {/foreach} - - Exit - SoftKey:Exit - 4 - - +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "enterprise"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + + + + + diff --git a/resources/templates/provision/cisco/7940/directory-personal.xml b/resources/templates/provision/cisco/7940/directory-personal.xml index 9d774ab56a..2e6750eb98 100644 --- a/resources/templates/provision/cisco/7940/directory-personal.xml +++ b/resources/templates/provision/cisco/7940/directory-personal.xml @@ -1,31 +1,24 @@ - + Personal Please choose... - - Dial - SoftKey:Select - 1 - - {assign var=x value=1} - {foreach $contacts as $row} - {if $row.contact_category == "personal"} - - {if $row.contact_name_given != ""} - {$row.contact_name_given} {$row.contact_name_family} - {else} - {$row.contact_organization} - {/if} - {if $row.phone_number != ""} - Dial:{$row.phone_number}# - {else} - Dial:{$row.phone_extension}# - {/if} - - {/if} - {/foreach} - - Exit - SoftKey:Exit - 4 - - +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "personal"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + + + + diff --git a/resources/templates/provision/cisco/7940/directory-speed_dial.xml b/resources/templates/provision/cisco/7940/directory-speed_dial.xml index f100c38cd6..16138ed111 100644 --- a/resources/templates/provision/cisco/7940/directory-speed_dial.xml +++ b/resources/templates/provision/cisco/7940/directory-speed_dial.xml @@ -1,32 +1,21 @@ - + Speed Dial Please choose... - - Dial - SoftKey:Select - 1 - - {assign var=x value=1} - {foreach $contacts as $row} - {if $row.contact_category == "speed dial"} - - {if $row.contact_name_given != ""} - {$row.contact_name_given} {$row.contact_name_family} - {else} - {$row.contact_organization} - {/if} - {if $row.phone_number != ""} - Dial:{$row.phone_number}# - {else} - Dial:{$row.phone_extension}# - {/if} - - {/if} - {assign var=x value=$x+1} - {/foreach} - - Exit - SoftKey:Exit - 4 - - +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "speed dial"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + diff --git a/resources/templates/provision/cisco/7940/directory.xml b/resources/templates/provision/cisco/7940/directory.xml index 9c90716c7c..24351b9b2d 100644 --- a/resources/templates/provision/cisco/7940/directory.xml +++ b/resources/templates/provision/cisco/7940/directory.xml @@ -1,28 +1,17 @@ Contacts Please choose... + - - Enterprise - http://{$domain_name}/app/provision?file=directory-enterprise&mac={$mac} + --> Enterprise + http://{$domain_name}/app/provision/file/directory-enterprise.xml?mac={$mac} Speed Dial - http://{$domain_name}/app/provision/?file=directory-speed_dial&mac={$mac} + http://{$domain_name}/app/provision/file/directory-speed_dial.xml?mac={$mac} - - Select - SoftKey:Select - 1 - - - Exit - SoftKey:Exit - 4 - \ No newline at end of file diff --git a/resources/templates/provision/cisco/7940/syncinfo.xml b/resources/templates/provision/cisco/7940/syncinfo.xml new file mode 100644 index 0000000000..98d9050dae --- /dev/null +++ b/resources/templates/provision/cisco/7940/syncinfo.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/templates/provision/cisco/7960/DISTINCTIVERINGLIST.XML b/resources/templates/provision/cisco/7960/DISTINCTIVERINGLIST.XML new file mode 100644 index 0000000000..8841ee8303 --- /dev/null +++ b/resources/templates/provision/cisco/7960/DISTINCTIVERINGLIST.XML @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/templates/provision/cisco/7960/RINGLIST.XML b/resources/templates/provision/cisco/7960/RINGLIST.XML new file mode 100644 index 0000000000..c30df63119 --- /dev/null +++ b/resources/templates/provision/cisco/7960/RINGLIST.XML @@ -0,0 +1,30 @@ + + + Chirp 3 + ringer3.pcm + + + Old Style + ringer1.pcm + + + Door Chime + doorchime.pcm + + + Red Alert + redalert.pcm + + + Terri + terri.pcm + + + Door Chime 2 + chime2.pcm + + + Silence + silence.pcm + + diff --git a/resources/templates/provision/cisco/7960/SIPDefault.cnf b/resources/templates/provision/cisco/7960/SIPDefault.cnf index aa90396792..e69de29bb2 100644 --- a/resources/templates/provision/cisco/7960/SIPDefault.cnf +++ b/resources/templates/provision/cisco/7960/SIPDefault.cnf @@ -1,131 +0,0 @@ -# Image Version -image_version: "P0S3-08-7-00" - -# Proxy Server -proxy1_address: "192.168.1.1" - -# Proxy Server Port (default - 5060) -proxy1_port:"5060" - -# Emergency Proxy info -proxy_emergency: "192.168.1.1" -proxy_emergency_port: "5060" - -# Backup Proxy info -proxy_backup: "192.168.1.1" -proxy_backup_port: "5060" - -# Outbound Proxy info -outbound_proxy: "" -outbound_proxy_port: "5060" - -# NAT/Firewall Traversal -nat_enable: "0" -nat_address: "" -voip_control_port: "5060" -start_media_port: "16384" -end_media_port: "32766" -nat_received_processing: "0" - -# Proxy Registration (0-disable (default), 1-enable) -proxy_register: "1" - -# Phone Registration Expiration [1-3932100 sec] (Default - 3600) -timer_register_expires: "3600" - -# Codec for media stream (g711ulaw (default), g711alaw, g729) -preferred_codec: "none" - -# TOS bits in media stream [0-5] (Default - 5) -tos_media: "5" - -# Enable VAD (0-disable (default), 1-enable) -enable_vad: "0" - -# Allow for the bridge on a 3way call to join remaining parties upon hangup -cnf_join_enable: "1" ; 0-Disabled, 1-Enabled (default) - -# Allow Transfer to be completed while target phone is still ringing -semi_attended_transfer: "0" ; 0-Disabled, 1-Enabled (default) - -# Telnet Level (enable or disable the ability to telnet into this phone -telnet_level: "2" ; 0-Disabled (default), 1-Enabled, 2-Privileged - -# Inband DTMF Settings (0-disable, 1-enable (default)) -dtmf_inband: "1" - -# Out of band DTMF Settings (none-disable, avt-avt enable (default), avt_always - always avt ) -dtmf_outofband: "avt" - -# DTMF dB Level Settings (1-6dB down, 2-3db down, 3-nominal (default), 4-3db up, 5-6dB up) -dtmf_db_level: "3" - -# SIP Timers -timer_t1: "500" ; Default 500 msec -timer_t2: "4000" ; Default 4 sec -sip_retx: "10" ; Default 11 -sip_invite_retx: "6" ; Default 7 -timer_invite_expires: "180" ; Default 180 sec - -# Setting for Message speeddial to UOne box -messages_uri: "*98" - -# TFTP Phone Specific Configuration File Directory -tftp_cfg_dir: "" - -# Time Server -sntp_mode: "unicast" -sntp_server: "192.168.1.1" -time_zone: "EST" -dst_offset: "1" -dst_start_month: "Mar" -dst_start_day: "" -dst_start_day_of_week: "Sun" -dst_start_week_of_month: "2" -dst_start_time: "02" -dst_stop_month: "Nov" -dst_stop_day: "" -dst_stop_day_of_week: "Sunday" -dst_stop_week_of_month: "1" -dst_stop_time: "2" -dst_auto_adjust: "1" - -# Do Not Disturb Control (0-off, 1-on, 2-off with no user control, 3-on with no user control) -dnd_control: "0" ; Default 0 (Do Not Disturb feature is off) - -# Caller ID Blocking (0-disabled, 1-enabled, 2-disabled no user control, 3-enabled no user control) -callerid_blocking: "0" ; Default 0 (Disable sending all calls as anonymous) - -# Anonymous Call Blocking (0-disbaled, 1-enabled, 2-disabled no user control, 3-enabled no user control) -anonymous_call_block: "0" ; Default 0 (Disable blocking of anonymous calls) - -# Call Waiting (0-disabled, 1-enabled, 2-disabled with no user control, 3-enabled with no user control) -call_waiting: "1" ; Default 1 (Call Waiting enabled) - -# DTMF AVT Payload (Dynamic payload range for AVT tones - 96-127) -dtmf_avt_payload: "101" ; Default 100 - -# XML file that specifies the dialplan desired -dial_template: "dialplan" - -# Network Media Type (auto, full100, full10, half100, half10) -network_media_type: "auto" - -#Autocompletion During Dial (0-off, 1-on [default]) -autocomplete: "1" - -#Time Format (0-12hr, 1-24hr [default]) -time_format_24hr: "0" - -# URL for external Phone Services -#services_url: "http://192.168.1.1/xmlservices/index.php" - -# URL for external Directory location -#directory_url: "http://192.168.1.1/xmlservices/PhoneDirectory.php" - -# URL for branding logo -#logo_url: "http://192.168.1.1/cisco/bmp/trixbox.bmp" - -# Remote Party ID -remote_party_id: 1 ; 0-Disabled (default), 1-Enabled - diff --git a/resources/templates/provision/cisco/7960/SIP{$mac}.cnf b/resources/templates/provision/cisco/7960/SIP{$mac}.cnf index f2dda35d42..4a4bb88bdb 100644 --- a/resources/templates/provision/cisco/7960/SIP{$mac}.cnf +++ b/resources/templates/provision/cisco/7960/SIP{$mac}.cnf @@ -1,43 +1,150 @@ -phone_label: "{$display_name_1}" -proxy1_address: "{$server_address_1}" +{if isset($cisco_time_zone)} +# Image version +image_version: "{$cisco_image_version}" +{/if} + +# Phone settings +phone_label: "{$label}" proxy_register: 1 timer_register_expires: 300 preferred_codec: g711ulaw enable_vad: 0 dial_template: "dialplan" -line1_name: "{$user_id_1}" -line1_displayname: "{$user_id_1}" -line1_shortname: "{$short_name_1}" -line1_authname: "{$auth_id_1}" -line1_password: "{$user_password_1}" +{foreach $lines as $row}reg.{$row.line_number}.displayName="{$row.display_name}" +#registration information +proxy{$row.line_number}_address: "{$row.server_address}" +proxy{$row.line_number}_port:"{$row.sip_port}" +line{$row.line_number}_name: "{$row.user_id}" +line{$row.line_number}_displayname: "{$row.user_id}" +line{$row.line_number}_shortname: "{$row.display_name}" +line{$row.line_number}_authname: "{$row.auth_id}" +line{$row.line_number}_password: "{$row.password}" -line2_name: "{$user_id_2}" -line2_displayname: "{$user_id_2}" -line2_shortname: "{$short_name_2}" -line2_authname: "{$auth_id_2}" -line2_password: "{$user_password_2}" +{/foreach} +# Emergency Proxy info +proxy_emergency: "{$proxy_emergency}" +proxy_emergency_port: "{$proxy_emergency_port}" -line3_name: "{$user_id_3}" -line3_displayname: "{$user_id_3}" -line3_shortname: "{$short_name_3}" -line3_authname: "{$auth_id_3}" -line3_password: "{$user_password_3}" +# Backup Proxy info +proxy_backup: "{$proxy_backup}" +proxy_backup_port: "{$proxy_backup_port}" + +# Outbound Proxy info +outbound_proxy: "{$outbound_proxy}" +outbound_proxy_port: "{$outbound_proxy_port}" + +# NAT/Firewall Traversal +voip_control_port: "5060" +start_media_port: "16384" +end_media_port: "32768" +nat_received_processing: "0" +nat_enable: "{if isset($nat_enable)}{$nat_enable}{else}1{/if}" +nat_address: "{$nat_nat_address}" -line4_name: "{$user_id_4}" -line4_displayname: "{$user_id_4}" -line4_shortname: "{$short_name_4}" -line4_authname: "{$auth_id_4}" -line4_password: "{$user_password_4}" +# Sync value of the phone used for remote reset +sync: 1 ; Default 1 -line5_name: "{$user_id_5}" -line5_displayname: "{$user_id_5}" -line5_shortname: "{$short_name_5}" -line5_authname: "{$auth_id_5}" -line5_password: "{$user_password_5}" +# Proxy Registration (0-disable (default), 1-enable) +proxy_register: "1" + +# Phone Registration Expiration [1-3932100 sec] (Default - 3600) +timer_register_expires: "80" + +# Codec for media stream (g711ulaw (default), g711alaw, g729) +preferred_codec: "none" + +# TOS bits in media stream [0-5] (Default - 5) +tos_media: "5" -line6_name: "{$user_id_6}" -line6_displayname: "{$user_id_6}" -line6_shortname: "{$short_name_6}" -line6_authname: "{$auth_id_6}" -line6_password: "{$user_password_6}" \ No newline at end of file +# Enable VAD (0-disable (default), 1-enable) +enable_vad: "0" + +# Allow for the bridge on a 3way call to join remaining parties upon hangup +cnf_join_enable: "1" ; 0-Disabled, 1-Enabled (default) + +# Allow Transfer to be completed while target phone is still ringing +semi_attended_transfer: "0" ; 0-Disabled, 1-Enabled (default) + +# Telnet Level (enable or disable the ability to telnet into this phone +telnet_level: "2" ; 0-Disabled (default), 1-Enabled, 2-Privileged + +# Inband DTMF Settings (0-disable, 1-enable (default)) +dtmf_inband: "1" + +# Out of band DTMF Settings (none-disable, avt-avt enable (default), avt_always - always avt ) +dtmf_outofband: "avt" + +# DTMF dB Level Settings (1-6dB down, 2-3db down, 3-nominal (default), 4-3db up, 5-6dB up) +dtmf_db_level: "3" + +# SIP Timers +timer_t1: "500" ; Default 500 msec +timer_t2: "4000" ; Default 4 sec +sip_retx: "10" ; Default 11 +sip_invite_retx: "6" ; Default 7 +timer_invite_expires: "180" ; Default 180 sec + +# Setting for Message speeddial to UOne box +messages_uri: "*97" + +# TFTP Phone Specific Configuration File Directory +tftp_cfg_dir: "" + +# Time Server +sntp_mode: "unicast" +sntp_server: "{$ntp_server_primary}" +{if isset($cisco_time_zone)} +time_zone: "{$cisco_time_zone}" +{/if} +dst_offset: "1" +dst_start_month: "Mar" +dst_start_day: "" +dst_start_day_of_week: "Sun" +dst_start_week_of_month: "2" +dst_start_time: "02" +dst_stop_month: "Nov" +dst_stop_day: "" +dst_stop_day_of_week: "Sunday" +dst_stop_week_of_month: "1" +dst_stop_time: "2" +dst_auto_adjust: "1" + +# Do Not Disturb Control (0-off, 1-on, 2-off with no user control, 3-on with no user control) +dnd_control: "2" ; Default 0 (Do Not Disturb feature is off) + +# Caller ID Blocking (0-disabled, 1-enabled, 2-disabled no user control, 3-enabled no user control) +callerid_blocking: "0" ; Default 0 (Disable sending all calls as anonymous) + +# Anonymous Call Blocking (0-disbaled, 1-enabled, 2-disabled no user control, 3-enabled no user control) +anonymous_call_block: "0" ; Default 0 (Disable blocking of anonymous calls) + +# Call Waiting (0-disabled, 1-enabled, 2-disabled with no user control, 3-enabled with no user control) +call_waiting: "1" ; Default 1 (Call Waiting enabled) + +# DTMF AVT Payload (Dynamic payload range for AVT tones - 96-127) +dtmf_avt_payload: "101" ; Default 100 + +# XML file that specifies the dialplan desired +dial_template: "dialplan" + +# Network Media Type (auto, full100, full10, half100, half10) +network_media_type: "auto" + +#Autocompletion During Dial (0-off, 1-on [default]) +autocomplete: "1" + +#Time Format (0-12hr, 1-24hr [default]) +time_format_24hr: "0" + +# URL for external Phone Services +#services_url: "http://{$domain_name}/app/provision/file/services.xml" + +# URL for external Directory location +directory_url: "http://{$domain_name}/app/provision/file/directory.xml" + +# URL for branding logo +#logo_url: "http://{$domain_name}/app/provision/logo.bmp" + +# Remote Party ID +remote_party_id: 1 ; 0-Disabled (default), 1-Enabled diff --git a/resources/templates/provision/cisco/7960/directory-enterprise.xml b/resources/templates/provision/cisco/7960/directory-enterprise.xml new file mode 100644 index 0000000000..5c977112b0 --- /dev/null +++ b/resources/templates/provision/cisco/7960/directory-enterprise.xml @@ -0,0 +1,25 @@ + + Enterprise + Please choose... +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "enterprise"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + + + + + diff --git a/resources/templates/provision/cisco/7960/directory-personal.xml b/resources/templates/provision/cisco/7960/directory-personal.xml new file mode 100644 index 0000000000..2e6750eb98 --- /dev/null +++ b/resources/templates/provision/cisco/7960/directory-personal.xml @@ -0,0 +1,24 @@ + + Personal + Please choose... +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "personal"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + + + + diff --git a/resources/templates/provision/cisco/7960/directory-speed_dial.xml b/resources/templates/provision/cisco/7960/directory-speed_dial.xml new file mode 100644 index 0000000000..16138ed111 --- /dev/null +++ b/resources/templates/provision/cisco/7960/directory-speed_dial.xml @@ -0,0 +1,21 @@ + + Speed Dial + Please choose... +{assign var=x value=1} +{foreach $contacts as $row}{if $row.contact_category == "speed dial"} + +{if $row.contact_name_given != ""} + {$row.contact_name_given} {$row.contact_name_family} +{else} + {$row.contact_organization} +{/if} +{if $row.phone_number != ""} + {$row.phone_number} +{else} + {$row.phone_extension} +{/if} + +{/if} +{assign var=x value=$x+1} +{/foreach} + diff --git a/resources/templates/provision/cisco/7960/directory.xml b/resources/templates/provision/cisco/7960/directory.xml new file mode 100644 index 0000000000..24351b9b2d --- /dev/null +++ b/resources/templates/provision/cisco/7960/directory.xml @@ -0,0 +1,17 @@ + + Contacts + Please choose... + + Enterprise + http://{$domain_name}/app/provision/file/directory-enterprise.xml?mac={$mac} + + + Speed Dial + http://{$domain_name}/app/provision/file/directory-speed_dial.xml?mac={$mac} + + \ No newline at end of file diff --git a/resources/templates/provision/cisco/7960/syncinfo.xml b/resources/templates/provision/cisco/7960/syncinfo.xml new file mode 100644 index 0000000000..98d9050dae --- /dev/null +++ b/resources/templates/provision/cisco/7960/syncinfo.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/templates/provision/cisco/spa509g/{$mac}.xml b/resources/templates/provision/cisco/spa509g/{$mac}.xml index 5250df8d7a..d7cf81c49a 100644 --- a/resources/templates/provision/cisco/spa509g/{$mac}.xml +++ b/resources/templates/provision/cisco/spa509g/{$mac}.xml @@ -349,7 +349,7 @@ {$display_name_1} {$voicemail_number} -http://www.coltarus.com/pic/Coltaruslogo-phone-509g-70.bmp +http://{$domain_name}/themes/enhanced/images/logo.bmp BMP Picture BMP Picture Auto diff --git a/resources/templates/provision/grandstream/gxp21xx/{$mac}.xml b/resources/templates/provision/grandstream/gxp21xx/{$mac}.xml index 2b0445ef10..d534b1bd28 100644 --- a/resources/templates/provision/grandstream/gxp21xx/{$mac}.xml +++ b/resources/templates/provision/grandstream/gxp21xx/{$mac}.xml @@ -3590,7 +3590,33 @@ Outgoing calls. 0 - No, 1 - Yes. Default is 0 --> {$memory_key_value_18} - + +{$start_id = 23000} +{foreach $keys as $row} +{if $row.device_key_category == "expansion"} +{$key_id = $row.device_key_id - 1} +{$type_id = $start_id + ($key_id * 5)} +{$line_id = ($start_id + 1) + ($key_id * 5)} +{$label_id = ($start_id + 2) + ($key_id * 5)} +{$value_id = ($start_id + 3) + ($key_id * 5)} +{if $row.device_key_type == "speed dial"} 0{/if} +{if $row.device_key_type == "blf"} 1{/if} +{if $row.device_key_type == "presence watcher"} 2{/if} +{if $row.device_key_type == "eventlist blf"} 3{/if} +{if $row.device_key_type == "speed dial active"} 4{/if} +{if $row.device_key_type == "dial dtmf"} 5{/if} +{if $row.device_key_type == "voicemail"} 6{/if} +{if $row.device_key_type == "call return"} 7{/if} +{if $row.device_key_type == "transfer"} 8{/if} +{if $row.device_key_type == "call park"} 9{/if} +{if $row.device_key_type == "intercom"} 10{/if} +{if $row.device_key_type == "ldap search"} 11{/if} + + {$row.device_key_line} + {$row.device_key_label} + {$row.device_key_value} +{/if} +{/foreach} \ No newline at end of file diff --git a/resources/templates/provision/mitel/5324/MN_{$mac}.cfg b/resources/templates/provision/mitel/5324/MN_{$mac}.cfg new file mode 100644 index 0000000000..b081d013c3 --- /dev/null +++ b/resources/templates/provision/mitel/5324/MN_{$mac}.cfg @@ -0,0 +1,365 @@ + + 1 + 1 + 0 + 1 + 02.00.00.24 + R7.2.02.00.00.24 + 0 + 0 + 0 + 5060 + 0 + -1 + {if isset($mitel_vlan_id)}{$mitel_vlan_id}{else}-1{/if} + sip1 + -example.com + 0 + 0 + operator@example.com + 0 + + + + + + + + 1 + 12 + 1 + 1 + 0 + 1 + http://rss.news.yahoo.com/rss/topstories + 135.199.77.12 + 135.199.77.12 + 128.138.141.172 + {$mitel_time_zone} + 2 + 120 + + 0.0.0.0 + 5060 + 5 + 20 + 0 + 0 + 101 + 0 + 0 + + 0 + 0 + 10 + + 1 + 60 + 0 + + ****** + 0 + 0 + 0 + 0 + admin + Administrator + 510731ac096ebcb3989fb1ed5b7075bb + 0 + + 0 + + 0 + 0 + 16 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 80 + 443 + 1 + 4 + 1 + 0 + 0 + + 0 + 213.192.59.75 + + 0 + 20000 + 20998 + 0 + 0 + 3 + 0 + en_US + US + 1 + 3 + 2 + 1 + 11 + 1 + 1 + 2 + 201 + sipdnld.mitel.com + sipdnld.mitel.com + 1 + + 0 + 3 + 0 + 0 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 1 + 1 + 1 + 1 + 0 + ****** + 1440 + 1 + 1440 + 23 + 59 + 1 + + 5d41402abc4b2a76b9719d911017c592 + + + sip + {$voicemail_number} + 1 + + 90 + + {foreach $lines as $row} + + + {/foreach} + + + + + 7.2 + \ No newline at end of file diff --git a/resources/templates/provision/mitel/5340/MN_{$mac}.cfg b/resources/templates/provision/mitel/5340/MN_{$mac}.cfg new file mode 100644 index 0000000000..ea1c742f2d --- /dev/null +++ b/resources/templates/provision/mitel/5340/MN_{$mac}.cfg @@ -0,0 +1,365 @@ + + 1 + 1 + 0 + 1 + 02.00.00.24 + R7.2.02.00.00.24 + 0 + 0 + 0 + 5060 + 0 + -1 + {if isset($mitel_vlan_id)}{$mitel_vlan_id}{else}-1{/if} + sip1 + -example.com + 0 + 0 + operator@example.com + 0 + + + + + + + + 1 + 12 + 1 + 1 + 0 + 1 + http://rss.news.yahoo.com/rss/topstories + 135.199.77.12 + 135.199.77.12 + 128.138.141.172 + {$mitel_time_zone} + 2 + 120 + + 0.0.0.0 + 5060 + 5 + 20 + 0 + 0 + 101 + 0 + 0 + + 0 + 0 + 10 + + 1 + 60 + 0 + + ****** + 0 + 0 + 0 + 0 + admin + Administrator + 510731ac096ebcb3989fb1ed5b7075bb + 0 + + 0 + + 0 + 0 + 16 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 80 + 443 + 1 + 4 + 1 + 0 + 0 + + 0 + 213.192.59.75 + + 0 + 20000 + 20998 + 0 + 0 + 3 + 0 + en_US + US + 1 + 3 + 2 + 1 + 11 + 1 + 1 + 2 + 201 + sipdnld.mitel.com + sipdnld.mitel.com + 1 + + 0 + 3 + 0 + 0 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 1 + 1 + 1 + 1 + 0 + ****** + 1440 + 1 + 1440 + 23 + 59 + 1 + + 5d41402abc4b2a76b9719d911017c592 + + + sip + {$voicemail_number} + 1 + + 90 + + {foreach $lines as $row} + + + {/foreach} + + + + + 7.2 + \ No newline at end of file diff --git a/resources/templates/provision/polycom/4.x/{$mac}.cfg b/resources/templates/provision/polycom/4.x/{$mac}.cfg index b5d9431b66..c8f8e4a624 100644 --- a/resources/templates/provision/polycom/4.x/{$mac}.cfg +++ b/resources/templates/provision/polycom/4.x/{$mac}.cfg @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/resources/templates/provision/polycom/5.x/{$mac}.cfg b/resources/templates/provision/polycom/5.x/{$mac}.cfg index b5d9431b66..c8f8e4a624 100755 --- a/resources/templates/provision/polycom/5.x/{$mac}.cfg +++ b/resources/templates/provision/polycom/5.x/{$mac}.cfg @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/resources/templates/provision/yealink/t46g/y000000000028.cfg b/resources/templates/provision/yealink/t46g/y000000000028.cfg index 7e540ed1fe..4fdd27011c 100644 --- a/resources/templates/provision/yealink/t46g/y000000000028.cfg +++ b/resources/templates/provision/yealink/t46g/y000000000028.cfg @@ -26,8 +26,45 @@ network.pc_port.speed_duplex = network.pc_port.dhcp_server = 1 network.static_dns_enable = 0 +{if isset($vlan_port_id) } ####################################################################################### -## VLAN ## +## VLAN ENABLED ## +####################################################################################### +network.vlan.internet_port_enable = 1 + +#Configure the VLAN ID, it ranges from 1 to 4094, the default value is 1. +#Require reboot; +network.vlan.internet_port_vid = {$vlan_port_id} + +#Configure the VLAN priority, it ranges from 0 (default) to 7. +#Require reboot; +network.vlan.internet_port_priority = + +#Enable or disable the VLAN of PC port; 0-Disabled (default), 1-Enabled; +#Require reboot; +network.vlan.pc_port_enable = 1 + +#Configure the VLAN ID, it ranges from 1 to 4094, the default value is 1. +#Require reboot; +network.vlan.pc_port_vid = {$vlan_pc_port_id} + +#Configure the VLAN priority, it ranges from 0 (default) to 7. +#Require reboot; +network.vlan.pc_port_priority = + +#Enable or disable the DHCP to obtain the information of the VLAN; 0-Disabled; 1-Enabled (default); +#Require reboot; +network.vlan.dhcp_enable = + +#Configure the DHCP option to obtain the information of the VLAN. It ranges from 0 to 255. +#Multiple options separated by a comma. It supports up to 5 options in all. +#Require reboot; +network.vlan.dhcp_option = + +{else} + +####################################################################################### +## VLAN ENABLED ## ####################################################################################### network.vlan.internet_port_enable = 0 @@ -60,6 +97,8 @@ network.vlan.dhcp_enable = #Require reboot; network.vlan.dhcp_option = +{/if} + ####################################################################################### ## WEB Port ## ####################################################################################### @@ -521,30 +560,25 @@ bw.directory_enable = 0 ####################################################################################### ## LDAP ## ####################################################################################### -#Configure the search criteria for name and number lookups. -ldap.enable = -ldap.name_filter = -ldap.number_filter = -ldap.host = 0.0.0.0 -ldap.port = 389 -ldap.base = -ldap.user = -ldap.password = - -#Specify the maximum of the displayed search results. It ranges from 1 to 32000, the default value is 50. -ldap.max_hits = -ldap.name_attr = -ldap.numb_attr = -ldap.display_name = - -#Configure the LDAP version. The valid value is 2 or 3 (default). -ldap.version = - -#Enable or disable the phone to query the contact name from the LDAP server when receiving an incoming call; 0-Disabled (default), 1-Enabled; -ldap.call_in_lookup = - -#Enable or disable the phone to sort the search results in alphabetical order; 0-Disabled (default), 1-Enabled; -ldap.ldap_sort = +#Configure the backlight time (in seconds). The valid values are: 1-Always on, 60 (default), 120, 300, 600, 1800. +security.trust_certificates = 0 +phone_setting.backlight_time = 0 +ldap.name_filter = {$ldap_name_filter} +ldap.number_filter = {$ldap_number_filter} +ldap.host = {$ldap_host} +ldap.base = {$ldap_base} +ldap.user = {$ldap_user} +ldap.password = {$ldap_password} +ldap.display_name = {$ldap_display_name} +ldap.version = {$ldap_version} +ldap.call_in_lookup = {$ldap_call_in_lookup} +ldap.dial_lookup = {$ldap_dial_lookup} +ldap.enable = {$ldap_enable} +ldap.ldap_sort = {$ldap_sort} +ldap.port = {$ldap_port} +ldap.max_hits = {$ldap_max_hits} +ldap.name_attr = {$ldap_name_attr} +ldap.numb_attr = {$ldap_numb_attr} ####################################################################################### ## Features ## @@ -1525,7 +1559,7 @@ super_search.url = ## Directory Setting ## ####################################################################################### #Configure the access URL of the directory setting file. -directory_setting.url = +directory_setting.url ={$yealink_directory_setting_url} ####################################################################################### ## Configure the access URL of firmware ## diff --git a/resources/templates/provision/yealink/t48g/{$mac}.cfg b/resources/templates/provision/yealink/t48g/{$mac}.cfg index c9387f2da9..101b2090f6 100644 --- a/resources/templates/provision/yealink/t48g/{$mac}.cfg +++ b/resources/templates/provision/yealink/t48g/{$mac}.cfg @@ -924,8 +924,8 @@ account.2.xsi.port = #Configure the time zone and time zone name. The time zone ranges from -11 to +12, the default value is +8. #local_time.time_zone = +8 #local_time.time_zone_name = China(Beijing) -local_time.time_zone = ${time_zone} -local_time.time_zone_name = ${time_zone_name} +local_time.time_zone = {$time_zone} +local_time.time_zone_name = {$time_zone_name} ####################################################################################### diff --git a/secure/fax_to_email.php b/secure/fax_to_email.php index 6972b225b9..3005595d6b 100644 --- a/secure/fax_to_email.php +++ b/secure/fax_to_email.php @@ -37,6 +37,267 @@ if (defined('STDIN')) { //echo "$document_root is document_root\n"; } +if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; } + +if(!function_exists('exec_in_dir')) { + function exec_in_dir($dir, $cmd, &$ok){ + $args = func_get_args(); + $cwd = getcwd(); + chdir($dir); + $output = array(); + $ret = 0; + $result = exec($cmd, $output, $ret); + if($cwd) + chdir($cwd); + $ok = ($ret == 0); + return join($output, "\n"); + } +} + +if(!function_exists('correct_path')) { + function correct_path($p) { + global $IS_WINDOWS; + if ($IS_WINDOWS) { + return str_replace('/', '\\', $p); + } + return $p; + } +} + +if(!function_exists('path_join')) { + function path_join() { + $args = func_get_args(); + $paths = array(); + foreach ($args as $arg) { + $paths = array_merge($paths, (array)$arg); + } + + $prefix = null; + foreach($paths as &$path) { + if($prefix === null && strlen($path) > 0) { + if(substr($path, 0, 1) == '/') $prefix = '/'; + else $prefix = ''; + } + $path = trim( $path, '/' ); + } + + if($prefix === null){ + return ''; + } + + $paths = array_filter($paths); + + return $prefix . join('/', $paths); + } +} + +if(!function_exists('tiff2pdf')) { + function tiff2pdf($tiff_file_name){ + //convert the tif to a pdf + //Ubuntu: apt-get install libtiff-tools + + global $IS_WINDOWS; + + if(!file_exists($tiff_file_name)){ + echo "tiff file does not exists"; + return false; // "tiff file does not exists"; + } + + $GS = $IS_WINDOWS ? 'gswin32c' : 'gs'; + $tiff_file = pathinfo($tiff_file_name); + $dir_fax = $tiff_file['dirname']; + $fax_file_name = $tiff_file['filename']; + $pdf_file_name = path_join( $dir_fax, $fax_file_name . '.pdf' ); + + if(file_exists($pdf_file_name)) + return $pdf_file_name; + + $dir_fax_temp = $_SESSION['server']['temp']['dir']; + if(!$dir_fax_temp){ + $dir_fax_temp = path_join(dirname($dir_fax), 'temp'); + } + + if(!file_exists($dir_fax_temp)){ + echo"can not create temporary directory"; + return false; // + } + + $cmd = "tiffinfo " . correct_path($tiff_file_name) . ' | grep "Resolution:"'; + $ok = false; + $resp = exec_in_dir($dir_fax, $cmd, $ok); + if(!$ok){ + echo"can not find fax resoulution"; + return false; // "can not find fax resoulution" + } + + $ppi_w = 0; + $ppi_h = 0; + $tmp = array(); + if(preg_match('/Resolution.*?(\d+).*?(\d+)/', $resp, $tmp)){ + $ppi_w = $tmp[1]; + $ppi_h = $tmp[2]; + } + + $cmd = "tiffinfo " . $tiff_file_name . ' | grep "Image Width:"'; + $resp = exec_in_dir($dir_fax, $cmd, $ok); + if(!$ok){ + echo"can not find fax size"; + return false; // "can not find fax size" + } + + $pix_w = 0; + $pix_h = 0; + $tmp = array(); + if(preg_match('/Width.*?(\d+).*?Length.*?(\d+)/', $resp, $tmp)){ + $pix_w = $tmp[1]; + $pix_h = $tmp[2]; + } + + $page_width = $pix_w / $ppi_w; + $page_height = $pix_h / $ppi_h; + $page_size = 'a4'; + + if (($page_width > 8.4) && ($page_height > 13)) { + $page_width = 8.5; + $page_height = 14; + $page_size = 'legal'; + } + elseif (($page_width > 8.4) && ($page_height < 12)) { + $page_width = 8.5; + $page_height = 11; + $page_size = 'letter'; + } + elseif (($page_width < 8.4) && ($page_height > 11)) { + $page_width = 8.3; + $page_height = 11.7; + $page_size = 'a4'; + } + $page_width = sprintf('%.4f', $page_width); + $page_height = sprintf('%.4f', $page_height); + + $cmd = join(array('tiff2pdf', + '-i -u i', + '-p', $page_size, + '-w', $page_width, + '-l', $page_height, + '-f', + '-o', correct_path(path_join($dir_fax_temp, $fax_file_name . '.pdf')), + correct_path($tiff_file_name), + ), ' '); + + $resp = exec_in_dir($dir_fax, $cmd, $ok); + + if(!file_exists(path_join($dir_fax_temp, $fax_file_name . '.pdf'))){ + echo "can not create temporary pdf: $resp"; + return false; + } + + $cmd = join(array($GS, + '-q -sDEVICE=tiffg3', + '-r' . $ppi_w . 'x' . $ppi_h, + '-g' . $pix_w . 'x' . $pix_h, + '-dNOPAUSE', + '-sOutputFile=' . $fax_file_name . '_temp.tif', + '--', + $fax_file_name . '.pdf', + '-c quit', + ), ' '); + + $resp = exec_in_dir($dir_fax_temp, $cmd, $ok); + + unlink(path_join($dir_fax_temp, $fax_file_name . '.pdf')); + + if(!file_exists(path_join($dir_fax_temp, $fax_file_name . '_temp.tif'))){ + echo "can not temporary tiff: $resp"; + return false; + } + + $cmd = join(array('tiff2pdf', + '-i -u i', + '-p', $page_size, + '-w', $page_width, + '-l', $page_height, + '-f', + '-o', correct_path($pdf_file_name), + correct_path(path_join($dir_fax_temp, $fax_file_name . '_temp.tif')), + ), ' '); + + $resp = exec_in_dir($dir_fax, $cmd, $ok); + + unlink(path_join($dir_fax_temp, $fax_file_name . '_temp.tif')); + + if(!file_exists($pdf_file_name)){ + echo "can not create pdf: $resp"; + return false; + } + + return $pdf_file_name; + } +} + +if(!function_exists('fax_enqueue')) { + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ + global $db, $db_type; + + $fax_task_uuid = uuid(); + $dial_string .= "fax_task_uuid='" . $fax_task_uuid . "',"; + $description = ''; //! @todo add description + if ($db_type == "pgsql") { + $date_utc_now_sql = "NOW() at time zone 'utc'"; + } + if ($db_type == "mysql") { + $date_utc_now_sql = "UTC_TIMESTAMP()"; + } + if ($db_type == "sqlite") { + $date_utc_now_sql = "datetime('now')"; + } + $sql = <<prepare($sql); + $i = 0; + $stmt->bindValue(++$i, $fax_task_uuid); + $stmt->bindValue(++$i, $fax_uuid); + $stmt->bindValue(++$i, $fax_file); + $stmt->bindValue(++$i, $wav_file); + $stmt->bindValue(++$i, $fax_uri); + $stmt->bindValue(++$i, $dial_string); + $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); + $stmt->bindValue(++$i, $description); + if ($stmt->execute()) { + $response = 'Enqueued'; + } + else{ + //! @todo log error + $response = 'Fail enqueue'; + var_dump($db->errorInfo()); + } + unset($stmt); + return $response; + } +} + +if(!function_exists('fax_split_dtmf')) { + function fax_split_dtmf(&$fax_number, &$fax_dtmf){ + $tmp = array(); + $fax_dtmf = ''; + if(preg_match('/^\s*(.*?)\s*\((.*)\)\s*$/', $fax_number, $tmp)){ + $fax_number = $tmp[1]; + $fax_dtmf = $tmp[2]; + } + } +} + //includes if (!defined('STDIN')) { include "root.php"; } require_once "resources/require.php"; @@ -111,19 +372,12 @@ if (defined('STDIN')) { } $mailto_address = $fax_email; - echo "mailto_adress is ".$mailto_address."\n"; - echo "fax_email is ".$fax_email."\n"; //get the fax file name (only) if a full path - $array = explode("/", $fax_file); - $fax_file_only = $array[count($array)-1]; - $fax_file_name = pathinfo($fax_file_only, PATHINFO_FILENAME); - unset($array); - -//used for debug - echo "fax_email $fax_email\n"; - echo "fax_extension $fax_extension\n"; - echo "fax_name $fax_file_only\n"; + $fax_path = pathinfo($fax_file); + $fax_file_only = $fax_path['basename']; + $fax_file_name = $fax_path['filename']; + $dir_fax = $fax_path['dirname']; //get the domain_uuid from the database $sql = "select * from v_domains "; @@ -153,6 +407,7 @@ if (defined('STDIN')) { foreach ($result as &$row) { //set database fields as variables //$fax_email = $row["fax_email"]; + $fax_uuid = $row["fax_uuid"]; $fax_accountcode = $row["fax_accountcode"]; $fax_pin_number = $row["fax_pin_number"]; $fax_caller_id_name = $row["fax_caller_id_name"]; @@ -164,129 +419,128 @@ if (defined('STDIN')) { unset ($prep_statement); //set the fax directory - $dir_fax = $_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name.'/'.$fax_extension.'/inbox'; - echo "dir_fax is $dir_fax\n"; - if (!file_exists($dir_fax)) { - $dir_fax = $_SESSION['switch']['storage']['dir'].'/fax/'.$fax_extension.'/inbox'; - } - -//convert the tif to a pdf - //Ubuntu: apt-get install libtiff-tools - $fax_file_warning = ""; - if (file_exists($dir_fax.'/'.$fax_file_name.".tif")) { - if (!file_exists($dir_fax.'/'.$fax_file_name.".pdf")) { - //define temp directory - $dir_fax_temp = str_replace('/inbox', '/temp', $dir_fax); - if (!is_dir($dir_fax_temp)) { - mkdir($dir_fax_temp,0774,true); - chmod($dir_fax_temp,0774); - } - //enter fax directory - chdir($dir_fax); - //get fax resolution (ppi, W & H) - $resp = exec("tiffinfo ".$fax_file_name.".tif | grep 'Resolution:'"); - $resp_array = explode(' ', trim($resp)); - $ppi_w = (int) $resp_array[1]; - $ppi_h = (int) $resp_array[2]; - unset($resp_array); - $gs_r = $ppi_w.'x'.$ppi_h; //used by ghostscript - //get page dimensions/size (pixels/inches, W & H) - $resp = exec("tiffinfo ".$fax_file_name.".tif | grep 'Image Width:'"); - $resp_array = explode(' ', trim($resp)); - $pix_w = $resp_array[2]; - $pix_h = $resp_array[5]; - unset($resp_array); - $gs_g = $pix_w.'x'.$pix_h; //used by ghostscript - $page_width = $pix_w / $ppi_w; - $page_height = $pix_h / $ppi_h; - if ($page_width > 8.4 && $page_height > 13) { - $page_width = 8.5; - $page_height = 14; - $page_size = 'legal'; - } - else if ($page_width > 8.4 && $page_height < 12) { - $page_width = 8.5; - $page_height = 11; - $page_size = 'letter'; - } - else if ($page_width < 8.4 && $page_height > 11) { - $page_width = 8.3; - $page_height = 11.7; - $page_size = 'a4'; - } - //generate pdf (a work around, as tiff2pdf improperly inverts the colors) - $cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax_temp.'/'.$fax_file_name.".pdf ".$dir_fax.'/'.$fax_file_name.".tif"; - exec($cmd_tif2pdf); - chdir($dir_fax_temp); - $cmd_pdf2tif = "gs -q -sDEVICE=tiffg3 -r".$gs_r." -g".$gs_g." -dNOPAUSE -sOutputFile=".$fax_file_name."_temp.tif -- ".$fax_file_name.".pdf -c quit"; - exec($cmd_pdf2tif); //convert pdf to tif - @unlink($dir_fax_temp.'/'.$fax_file_name.".pdf"); - $cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax.'/'.$fax_file_name.".pdf ".$dir_fax_temp.'/'.$fax_file_name."_temp.tif"; - exec($cmd_tif2pdf); - @unlink($dir_fax_temp.'/'.$fax_file_name."_temp.tif"); + if (!file_exists($dir_fax) || !file_exists(path_join($dir_fax, $fax_file_only))) { + $dir_fax = $_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name.'/'.$fax_extension.'/inbox'; + if (!file_exists($dir_fax) || !file_exists(path_join($dir_fax, $fax_file_only))) { + $dir_fax = $_SESSION['switch']['storage']['dir'].'/fax/'.$fax_extension.'/inbox'; } } - else { - $fax_file_warning = " Fax image not available on server."; - echo $fax_file_warning."
    "; + + $fax_file = path_join($dir_fax, $fax_file_only); + +//used for debug + echo "mailto_adress is $mailto_address\n"; + echo "fax_email is $fax_email\n"; + echo "fax_extension is $fax_extension\n"; + echo "fax_name is $fax_file_only\n"; + echo "dir_fax is $dir_fax\n"; + echo "full_path is $fax_file\n"; + + $pdf_file = tiff2pdf($fax_file); + if(!$pdf_file){ + $fax_file_warning = ' Fax image not available on server.'; } + else{ + $fax_file_warning = ''; + } + +//used for debug + echo "pdf file is $pdf_file\n"; //forward the fax - if (strpos($fax_file_name,'#') !== false) { - $tmp = explode("#",$fax_file_name); - $fax_forward_number = $tmp[0]; - } + if(file_exists($fax_file)) { + if (strpos($fax_file_name,'#') !== false) { + $tmp = explode("#",$fax_file_name); + $fax_forward_number = $tmp[0]; + } - echo "fax_forward_number is $fax_forward_number\n"; - if (strlen($fax_forward_number) > 0) { - if (file_exists($dir_fax."/".$fax_file_name.".tif")) { - //get the event socket information - $sql = "select * from v_settings "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); - foreach ($result as &$row) { - $event_socket_ip_address = $row["event_socket_ip_address"]; - $event_socket_port = $row["event_socket_port"]; - $event_socket_password = $row["event_socket_password"]; - break; - } - //create the event socket connection - $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password); - //send the command with event socket - if ($fp) { - //prepare the fax originate command - $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_forward_number); - $fax_file = $dir_fax."/".$fax_file_name.".tif"; - if (count($route_array) == 0) { - //send the internal call to the registered extension - $fax_uri = "user/".$fax_forward_number."@".$domain_name; - $t38 = ""; - } - else { - //send the external call - $fax_uri = $route_array[0]; - $t38 = "fax_enable_t38=true,fax_enable_t38_request=true"; - } - $cmd = "api originate {absolute_codec_string='PCMU,PCMA',accountcode='".$fax_accountcode."',sip_h_X-accountcode='".$fax_accountcode."',domain_uuid=".$_SESSION["domain_uuid"].",domain_name=".$_SESSION["domain_name"].",mailto_address='".$mailto_address."',mailfrom_address='".$mailfrom_address."',origination_caller_id_name='".$fax_caller_id_name."',origination_caller_id_number=".$fax_caller_id_number.",fax_uri=".$fax_uri.",fax_file='".$fax_file."',fax_retry_attempts=1,fax_retry_limit=20,fax_retry_sleep=180,fax_verbose=true,fax_use_ecm=off,".$t38.",api_hangup_hook='lua fax_retry.lua'}".$fax_uri." &txfax('".$fax_file."')"; - //send info to the log - echo "fax forward\n"; - echo $cmd."\n"; - //send the command to event socket - $response = event_socket_request($fp, $cmd); - $response = str_replace("\n", "", $response); - //send info to the log - echo "response: ".$response."\n"; - //get the uuid - $uuid = str_replace("+OK ", "", $response); - //close event socket - fclose($fp); - } + echo "fax_forward_number is $fax_forward_number\n"; + if (strlen($fax_forward_number) > 0) { + fax_split_dtmf($fax_forward_number, $fax_dtmf); + + $fax_send_mode = $_SESSION['fax']['send_mode']['text']; + if(strlen($fax_send_mode) == 0){ + $fax_send_mode = 'direct'; + } + + $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_forward_number); + if (count($route_array) == 0) { + //send the internal call to the registered extension + $fax_uri = "user/".$fax_forward_number."@".$domain_name; + $t38 = ""; + } + else { + //send the external call + $fax_uri = $route_array[0]; + $t38 = "fax_enable_t38=true,fax_enable_t38_request=true"; + } + + $common_dial_string = "absolute_codec_string='PCMU,PCMA',"; + $common_dial_string .= "accountcode='" . $fax_accountcode . "',"; + $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; + $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; + $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; + $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; + $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; + $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; + $common_dial_string .= "fax_header='" . $fax_caller_id_name . "',"; + $common_dial_string .= "fax_file='" . $fax_file . "',"; + + if ($fax_send_mode != 'queue') { + $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; + $dial_string .= "fax_uri=" . $fax_uri . ","; + $dial_string .= "fax_retry_attempts=1" . ","; + $dial_string .= "fax_retry_limit=20" . ","; + $dial_string .= "fax_retry_sleep=180" . ","; + $dial_string .= "fax_verbose=true" . ","; + $dial_string .= "fax_use_ecm=off" . ","; + $dial_string .= "api_hangup_hook='lua fax_retry.lua'"; + $dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')"; + + //get the event socket information + $sql = "select * from v_settings "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + foreach ($result as &$row) { + $event_socket_ip_address = $row["event_socket_ip_address"]; + $event_socket_port = $row["event_socket_port"]; + $event_socket_password = $row["event_socket_password"]; + break; + } + + //create the event socket connection + $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password); + + //send the command with event socket + if ($fp) { + //prepare the fax originate command + $cmd = "api originate " . $dial_string; + //send info to the log + echo "fax forward\n"; + echo $cmd."\n"; + //send the command to event socket + $response = event_socket_request($fp, $cmd); + $response = str_replace("\n", "", $response); + //send info to the log + echo "response: ".$response."\n"; + //get the uuid + $uuid = str_replace("+OK ", "", $response); + //close event socket + fclose($fp); + } + } + else{ + $wav_file = ''; + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); + } } } //send the email - if (strlen($fax_email) > 0 && file_exists($dir_fax."/".$fax_file_name.".tif")) { + if (strlen($fax_email) > 0 && file_exists($fax_file)) { //prepare the message $tmp_subject = (($fax_email_inbound_subject_tag != '') ? "[".$fax_email_inbound_subject_tag."]" : "Fax Received").": ".$fax_file_name; @@ -340,11 +594,11 @@ if (defined('STDIN')) { //add the attachments if (strlen($fax_file_name) > 0) { - if (file_exists($dir_fax.'/'.$fax_file_name.".pdf")) { - $mail->AddAttachment($dir_fax.'/'.$fax_file_name.'.pdf'); // pdf attachment + if ($pdf_file && file_exists($pdf_file)) { + $mail->AddAttachment($pdf_file); // pdf attachment } else { - $mail->AddAttachment($dir_fax.'/'.$fax_file_name.'.tif'); // tif attachment + $mail->AddAttachment($fax_file); // tif attachment } //$filename='fax.tif'; $encoding = "base64"; $type = "image/tif"; //$mail->AddStringAttachment(base64_decode($strfax),$filename,$encoding,$type); @@ -373,7 +627,7 @@ if (defined('STDIN')) { // failed_fax_emails.sh - this is created when we have a email we need to re-send. At the time it is created, an at job is created to execute it in 3 minutes time, // this allows us to try sending the email again at that time. If the file exists but there is no at job this is because there are no longer any emails queued // as we have successfully sent them all. - if (strlen($fax_email) > 0 && file_exists($dir_fax."/".$fax_file_name.".tif")) { + if (strlen($fax_email) > 0 && file_exists($fax_file)) { if (stristr(PHP_OS, 'WIN')) { //not compatible with windows } @@ -387,7 +641,7 @@ if (defined('STDIN')) { } else { // create an instruction log to email messages once the connection to the mail server has been restored $fp = fopen($fax_to_email_queue_dir."/failed_fax_emails.log", "a"); - fwrite($fp, PHP_BINDIR."/php ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/fax_to_email.php email='".$fax_email."' extension=".$fax_extension." name='".$dir_fax.'/'.$fax_file_only."' messages='".$fax_messages."' domain=".$domain_name." caller_id_name='".$caller_id_name."' caller_id_number=".$caller_id_number." retry=true\n"); + fwrite($fp, PHP_BINDIR."/php ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/fax_to_email.php email='".$fax_email."' extension=".$fax_extension." name='".$fax_file."' messages='".$fax_messages."' domain=".$domain_name." caller_id_name='".$caller_id_name."' caller_id_number=".$caller_id_number." retry=true\n"); fclose($fp); // create a script to do the delayed mailing $fp = fopen($_SESSION['server']['temp']['dir']."/failed_fax_emails.sh", "w"); @@ -413,4 +667,4 @@ if (defined('STDIN')) { fwrite($fp, $content); fclose($fp); -?> +?> \ No newline at end of file diff --git a/secure/v_mailto.php b/secure/v_mailto.php index e81de0c6b1..5a7566a081 100644 --- a/secure/v_mailto.php +++ b/secure/v_mailto.php @@ -292,11 +292,14 @@ $mailer_error = $mail->ErrorInfo; echo "Mailer Error: ".$mailer_error."\n\n"; + $call_uuid = $headers["X-FusionPBX-Call-UUID"]; // log/store message in database for review $email_uuid = uuid(); $sql = "insert into v_emails ( "; $sql .= "email_uuid, "; - $sql .= "call_uuid, "; + if ($call_uuid) { + $sql .= "call_uuid, "; + } $sql .= "domain_uuid, "; $sql .= "sent_date, "; $sql .= "type, "; @@ -304,7 +307,9 @@ $sql .= "email "; $sql .= ") values ( "; $sql .= "'".$email_uuid."', "; - $sql .= "'".$headers["X-FusionPBX-Call-UUID"]."', "; + if ($call_uuid) { + $sql .= "'".$call_uuid."', "; + } $sql .= "'".$headers["X-FusionPBX-Domain-UUID"]."', "; $sql .= "now(),"; $sql .= "'".$headers["X-FusionPBX-Email-Type"]."', "; diff --git a/themes/enhanced/app_defaults.php b/themes/enhanced/app_defaults.php index f08e217176..5080029782 100644 --- a/themes/enhanced/app_defaults.php +++ b/themes/enhanced/app_defaults.php @@ -26,7 +26,64 @@ if ($domains_processed == 1) { + //get the background images + $relative_path = PROJECT_PATH.'/themes/enhanced/images/backgrounds'; + $backgrounds = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$relative_path); + unset($array); + $x = 0; + while (false !== ($file = readdir($backgrounds))) { + if ($file != "." AND $file != ".."){ + $new_path = $dir.'/'.$file; + $level = explode('/',$new_path); + $ext = pathinfo($file, PATHINFO_EXTENSION); + if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") { + $x++; + $array[$x]['default_setting_category'] = 'theme'; + $array[$x]['default_setting_subcategory'] = 'background_image'; + $array[$x]['default_setting_name'] = 'array'; + $array[$x]['default_setting_value'] = $relative_path.'/'.$file; + $array[$x]['default_setting_enabled'] = 'false'; + $array[$x]['default_setting_description'] = 'Set a relative path or URL within a selected compatible template.'; + } + if ($x > 300) { break; }; + } + } + + if(!$set_session_theme){ + //get default settings + $sql = "select * from v_default_settings "; + $sql .= "where default_setting_category = 'theme' "; + $sql .= "and default_setting_subcategory = 'background_image' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset($prep_statement); + + $background_image_enabled = false; + //add theme default settings + foreach ($array as $row) { + $found = false; + foreach ($default_settings as $field) { + if ($field["default_setting_value"] == $row["default_setting_value"]) { + $found = true; + } + //enable_background_image is a new setting, if a user has any background images enabled we should turn it on + if ($field["default_setting_enabled"] == 'enabled') { + $background_image_enabled = true; + } + } + if (!$found) { + $orm = new orm; + $orm->name('default_settings'); + $orm->save($row); + $message = $orm->message; + //print_r($message); + } + } + } + //define array of settings + unset($array); $x = 0; $array[$x]['default_setting_category'] = 'theme'; $array[$x]['default_setting_subcategory'] = 'login_opacity'; @@ -181,25 +238,46 @@ if ($domains_processed == 1) { $array[$x]['default_setting_value'] = '0.96'; $array[$x]['default_setting_enabled'] = 'false'; $array[$x]['default_setting_description'] = 'Set the opacity of the main menu (decimal, Minimized theme only).'; + $x++; + $array[$x]['default_setting_category'] = 'theme'; + $array[$x]['default_setting_subcategory'] = 'background_image_enabled'; + $array[$x]['default_setting_name'] = 'boolean'; + $array[$x]['default_setting_value'] = 'true'; + $array[$x]['default_setting_enabled'] = 'false'; + if($background_image_enabled) { $array[$x]['default_setting_enabled'] = 'true'; } + $array[$x]['default_setting_description'] = 'Enable use of background images.'; - //iterate and add each, if necessary - foreach ($array as $index => $default_settings) { - //add theme default settings - $sql = "select count(*) as num_rows from v_default_settings "; - $sql .= "where default_setting_category = 'theme' "; - $sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' "; - $prep_statement = $db->prepare($sql); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset($prep_statement); - if ($row['num_rows'] == 0) { - $orm = new orm; - $orm->name('default_settings'); - $orm->save($array[$index]); - $message = $orm->message; + if($set_session_theme){ + foreach ($array as $index => $default_settings) { + $sub_category = $array[$index]['default_setting_subcategory']; + $name = $array[$index]['default_setting_name']; + if($array[$index]['default_setting_enabled'] == 'true'){ + $_SESSION['theme'][$sub_category][$name] = $array[$index]['default_setting_value']; + }else{ + $_SESSION['theme'][$sub_category][$name] = ''; + } + } + } + else{ + //iterate and add each, if necessary + foreach ($array as $index => $default_settings) { + //add theme default settings + $sql = "select count(*) as num_rows from v_default_settings "; + $sql .= "where default_setting_category = 'theme' "; + $sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset($prep_statement); + if ($row['num_rows'] == 0) { + $orm = new orm; + $orm->name('default_settings'); + $orm->save($array[$index]); + $message = $orm->message; + } + unset($row); } - unset($row); } } @@ -209,7 +287,7 @@ if ($domains_processed == 1) { $array[$x]['default_setting_category'] = 'theme'; $array[$x]['default_setting_subcategory'] = 'background_color'; $array[$x]['default_setting_name'] = 'array'; - $array[$x]['default_setting_value'] = '#ffffff'; + $array[$x]['default_setting_value'] = '#6c89b5'; $array[$x]['default_setting_enabled'] = 'true'; $array[$x]['default_setting_order'] = '0'; $array[$x]['default_setting_description'] = 'Set a background (HTML compatible) color.'; @@ -217,78 +295,41 @@ if ($domains_processed == 1) { $array[$x]['default_setting_category'] = 'theme'; $array[$x]['default_setting_subcategory'] = 'background_color'; $array[$x]['default_setting_name'] = 'array'; - $array[$x]['default_setting_value'] = '#e7ebf1'; + $array[$x]['default_setting_value'] = '#144794'; $array[$x]['default_setting_order'] = '1'; $array[$x]['default_setting_enabled'] = 'true'; $array[$x]['default_setting_description'] = 'Set a secondary background (HTML compatible) color, for a gradient effect.'; - //add secondary background color separately, if missing - $sql = "select count(*) as num_rows from v_default_settings "; - $sql .= "where default_setting_category = 'theme' "; - $sql .= "and default_setting_subcategory = 'background_color' "; - $prep_statement = $db->prepare($sql); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset($prep_statement); - if ($row['num_rows'] == 0) { - $orm = new orm; - $orm->name('default_settings'); - foreach ($array as $index => $null) { - $orm->save($array[$index]); + if($set_session_theme){ + foreach ($array as $index => $default_settings) { + $sub_category = $array[$index]['default_setting_subcategory']; + $idx = $array[$index]['default_setting_order']; + if($array[$index]['default_setting_enabled'] == 'true'){ + $_SESSION['theme'][$sub_category][$idx] = $array[$index]['default_setting_value']; } - $message = $orm->message; - //print_r($message); } - unset($row); + return; } - - //get the background images - $relative_path = PROJECT_PATH.'/themes/enhanced/images/backgrounds'; - $backgrounds = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$relative_path); - unset($array); - $x = 0; - while (false !== ($file = readdir($backgrounds))) { - if ($file != "." AND $file != ".."){ - $new_path = $dir.'/'.$file; - $level = explode('/',$new_path); - $ext = pathinfo($file, PATHINFO_EXTENSION); - if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") { - $x++; - $array[$x]['default_setting_category'] = 'theme'; - $array[$x]['default_setting_subcategory'] = 'background_image'; - $array[$x]['default_setting_name'] = 'array'; - $array[$x]['default_setting_value'] = $relative_path.'/'.$file; - $array[$x]['default_setting_enabled'] = 'false'; - $array[$x]['default_setting_description'] = 'Set a relative path or URL within a selected compatible template.'; + else{ + //add secondary background color separately, if missing + $sql = "select count(*) as num_rows from v_default_settings "; + $sql .= "where default_setting_category = 'theme' "; + $sql .= "and default_setting_subcategory = 'background_color' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset($prep_statement); + if ($row['num_rows'] == 0) { + $orm = new orm; + $orm->name('default_settings'); + foreach ($array as $index => $null) { + $orm->save($array[$index]); + } + $message = $orm->message; + //print_r($message); } - if ($x > 300) { break; }; - } - } - - //get default settings - $sql = "select * from v_default_settings "; - $sql .= "where default_setting_category = 'theme' "; - $sql .= "and default_setting_subcategory = 'background_image' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - unset($prep_statement); - - //add theme default settings - foreach ($array as $row) { - $found = false; - foreach ($default_settings as $field) { - if ($field["default_setting_value"] == $row["default_setting_value"]) { - $found = true; - } - } - if (!$found) { - $orm = new orm; - $orm->name('default_settings'); - $orm->save($row); - $message = $orm->message; - //print_r($message); + unset($row); } } diff --git a/themes/enhanced/template.php b/themes/enhanced/template.php index 3b5579bcb9..23aadd820a 100644 --- a/themes/enhanced/template.php +++ b/themes/enhanced/template.php @@ -251,7 +251,7 @@ form { margin: 0; } -input.btn, input.button { +input.btn, input.button, button { font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif; padding: 2px 6px 3px 6px; color: #fff; @@ -273,7 +273,7 @@ input.btn, input.button { -moz-opacity: 0.9; } -input.btn:hover, input.button:hover, img.list_control_icon:hover { +input.btn:hover, input.button:hover, img.list_control_icon:hover, button:hover { box-shadow: 0 0 5px #cddaf0; -webkit-box-shadow: 0 0 5px #cddaf0; -moz-box-shadow: 0 0 5px #cddaf0; @@ -282,7 +282,7 @@ input.btn:hover, input.button:hover, img.list_control_icon:hover { cursor: pointer; } -input.txt, textarea.txt, select.txt, .formfld { +input.txt, textarea.txt, select.txt, .formfld, label.radio { font-family: arial; font-size: 12px; color: #000; @@ -311,6 +311,16 @@ input.txt:focus, .formfld:focus { box-shadow: 0 0 5px #cddaf0; } +fieldset.container { + border:none; + padding:0; + margin:1px; + display:inline-block; +} +label.radio +{ + display:block; +} /* removes spinners (increment/decrement controls) inside input fields */ input[type=number] { -moz-appearance: textfield; } ::-webkit-inner-spin-button { -webkit-appearance: none; } @@ -1424,7 +1434,7 @@ if (strlen($_SESSION['message']) > 0) {