diff --git a/app/extensions/app_config.php b/app/extensions/app_config.php index eccfb282fc..ad79a9acde 100644 --- a/app/extensions/app_config.php +++ b/app/extensions/app_config.php @@ -2,7 +2,7 @@ //application details $apps[$x]['name'] = "Extensions"; $apps[$x]['uuid'] = 'e68d9689-2769-e013-28fa-6214bf47fca3'; - $apps[$x]['category'] = 'Switch';; + $apps[$x]['category'] = 'Switch'; $apps[$x]['subcategory'] = ''; $apps[$x]['version'] = ''; $apps[$x]['license'] = 'Mozilla Public License 1.1'; diff --git a/app/extensions/extension_edit.php b/app/extensions/extension_edit.php index 1cc89444b8..2869e5e46f 100644 --- a/app/extensions/extension_edit.php +++ b/app/extensions/extension_edit.php @@ -350,7 +350,11 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $db->commit(); //syncrhonize configuration - save_extension_xml(); + if (is_readable($_SESSION['switch']['extensions']['dir'])) { + require_once "app/extensions/resources/extension.php"; + $extension = new extension; + $extension->xml(); + } //write the provision files if (strlen($provisioning_list)>0) { @@ -477,7 +481,11 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { unset($sql); //syncrhonize configuration - save_extension_xml(); + if (is_readable($_SESSION['switch']['extensions']['dir'])) { + require_once "app/extensions/resources/extension.php"; + $extension = new extension; + $extension->xml(); + } //write the provision files if (strlen($provisioning_list)>0) { diff --git a/app/extensions/resources/classes/extension.php b/app/extensions/resources/classes/extension.php new file mode 100644 index 0000000000..cbd7ed2ccd --- /dev/null +++ b/app/extensions/resources/classes/extension.php @@ -0,0 +1,351 @@ + + Copyright (C) 2010 + All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//define the directory class + class extension { + public $db; + public $domain_uuid; + public $domain_name; + private $app_uuid; + + public function __construct() { + require_once "includes/classes/database.php"; + $this->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; + } + + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + public function get_domain_uuid() { + return $this->domain_uuid; + } + + public function set_domain_uuid($domain_uuid){ + $this->domain_uuid = $domain_uuid; + } + + public function xml() { + if (isset($_SESSION['switch']['extensions']['dir'])) { + //declare global variables + global $config, $db, $domain_uuid; + + //get the context based from the domain_uuid + if (count($_SESSION['domains']) == 1) { + $user_context = "default"; + } + else { + $user_context = $_SESSION['domains'][$domain_uuid]['domain_name']; + } + + //delete all old extensions to prepare for new ones + $dialplan_list = glob($_SESSION['switch']['extensions']['dir']."/".$user_context."/v_*.xml"); + foreach($dialplan_list as $name => $value) { + unlink($value); + } + + //write the xml files + $sql = "select * from v_extensions "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "order by call_group asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $i = 0; + $extension_xml_condensed = false; + while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) { + $call_group = $row['call_group']; + $call_group = str_replace(";", ",", $call_group); + $tmp_array = explode(",", $call_group); + foreach ($tmp_array as &$tmp_call_group) { + $tmp_call_group = trim($tmp_call_group); + if (strlen($tmp_call_group) > 0) { + if (strlen($call_group_array[$tmp_call_group]) == 0) { + $call_group_array[$tmp_call_group] = $row['extension']; + } + else { + $call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group].','.$row['extension']; + } + } + $i++; + } + $user_context = $row['user_context']; + $vm_password = $row['vm_password']; + $vm_password = str_replace("#", "", $vm_password); //preserves leading zeros + + //echo "enabled: ".$row['enabled']; + if ($row['enabled'] != "false") { + $extension_uuid = $row['extension_uuid']; + //remove invalid characters from the file names + $extension = $row['extension']; + $extension = str_replace(" ", "_", $extension); + $extension = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $extension); + $dial_string = $row['dial_string']; + if (strlen($dial_string) == 0) { + $dial_string = "{sip_invite_domain=\${domain_name},presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}"; + } + + $xml .= "\n"; + $cidr = ''; + if (strlen($row['cidr']) > 0) { + $cidr = " cidr=\"" . $row['cidr'] . "\""; + } + $number_alias = ''; + if (strlen($row['number_alias']) > 0) { + $number_alias = " number-alias=\"".$row['number_alias']."\""; + } + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + switch ($row['vm_enabled']) { + case "true": + $xml .= " \n"; + break; + case "false": + $xml .= " \n"; + break; + default: + $xml .= " \n"; + } + if (strlen($row['vm_mailto']) > 0) { + $xml .= " \n"; + + switch ($row['vm_attach_file']) { + case "true": + $xml .= " \n"; + break; + case "false": + $xml .= " \n"; + break; + default: + $xml .= " \n"; + } + switch ($row['vm_keep_local_after_email']) { + case "true": + $xml .= " \n"; + break; + case "false": + $xml .= " \n"; + break; + default: + $xml .= " \n"; + } + $xml .= " \n"; + } + if (strlen($row['mwi_account']) > 0) { + $xml .= " \n"; + } + if (strlen($row['auth_acl']) > 0) { + $xml .= " \n"; + } + if (strlen($row['directory_exten_visible']) > 0) { + $xml .= " \n"; + } + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + if (strlen($row['call_group']) > 0) { + $xml .= " \n"; + } + if (strlen($row['hold_music']) > 0) { + $xml .= " \n"; + } + $xml .= " \n"; + if (strlen($switch_account_code) > 0) { + $xml .= " \n"; + } + else { + $xml .= " \n"; + } + $xml .= " \n"; + if (strlen($row['effective_caller_id_name']) > 0) { + $xml .= " \n"; + } + if (strlen($row['effective_caller_id_number']) > 0) { + $xml .= " \n"; + } + if (strlen($row['outbound_caller_id_name']) > 0) { + $xml .= " \n"; + } + if (strlen($row['outbound_caller_id_number']) > 0) { + $xml .= " \n"; + } + if (strlen($row['emergency_caller_id_number']) > 0) { + $xml .= " \n"; + } + if (strlen($row['directory_full_name']) > 0) { + $xml .= " \n"; + } + if (strlen($row['directory_visible']) > 0) { + $xml .= " \n"; + } + if (strlen($row['limit_max']) > 0) { + $xml .= " \n"; + } + else { + $xml .= " \n"; + } + if (strlen($row['limit_destination']) > 0) { + $xml .= " \n"; + } + if (strlen($row['sip_force_contact']) > 0) { + $xml .= " \n"; + } + if (strlen($row['sip_force_expires']) > 0) { + $xml .= " \n"; + } + if (strlen($row['nibble_account']) > 0) { + $xml .= " \n"; + } + switch ($row['sip_bypass_media']) { + case "bypass-media": + $xml .= " \n"; + break; + case "bypass-media-after-bridge": + $xml .= " \n"; + break; + case "proxy-media": + $xml .= " \n"; + break; + } + + $xml .= " \n"; + $xml .= " \n"; + + if (!is_readable($_SESSION['switch']['extensions']['dir']."/".$row['user_context'])) { + mkdir($_SESSION['switch']['extensions']['dir']."/".$row['user_context'],0755,true); + } + if (strlen($extension) > 0) { + $fout = fopen($_SESSION['switch']['extensions']['dir']."/".$row['user_context']."/v_".$extension.".xml","w"); + } + $xml .= "\n"; + fwrite($fout, $xml); + unset($xml); + fclose($fout); + } + } + unset ($prep_statement); + + //prepare extension + $extension_dir_path = realpath($_SESSION['switch']['extensions']['dir']); + $user_context = str_replace(" ", "_", $user_context); + $user_context = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $user_context); + + //define the group members + $xml = "\n"; + $xml .= "\n"; + $xml .= "\n"; + $xml .= " \n"; + if ($user_context == "default") { + $xml .= " \n"; + } + else { + $xml .= " \n"; + } + $xml .= " \n"; + //$xml .= " \n"; + $xml .= " \n"; + $xml .= "\n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= "\n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $xml .= "\n"; + $previous_call_group = ""; + foreach ($call_group_array as $key => $value) { + $call_group = trim($key); + $extension_list = trim($value); + if (strlen($call_group) > 0) { + if ($previous_call_group != $call_group) { + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + $extension_array = explode(",", $extension_list); + foreach ($extension_array as &$tmp_extension) { + $xml .= " \n"; + } + $xml .= " \n"; + $xml .= " \n"; + $xml .= "\n"; + } + $previous_call_group = $call_group; + } + unset($call_group); + } + $xml .= " \n"; + $xml .= "\n"; + $xml .= " \n"; + $xml .= ""; + + //write the xml file + if (is_readable($extension_dir_path) && strlen($extension_dir_path) > 0) { + $fout = fopen($extension_dir_path."/".$user_context.".xml","w"); + fwrite($fout, $xml); + unset($xml); + fclose($fout); + } + + //apply settings + $_SESSION["reload_xml"] = true; + } + } + +?> \ No newline at end of file diff --git a/app/xml_cdr/app_config.php b/app/xml_cdr/app_config.php index d6f7f65546..d08c076504 100644 --- a/app/xml_cdr/app_config.php +++ b/app/xml_cdr/app_config.php @@ -39,7 +39,7 @@ $apps[$x]['menu'][0]['groups'][] = 'superadmin'; $apps[$x]['menu'][1]['title']['en-us'] = 'Call Detail Records'; - $apps[$x]['menu'][1]['title']['es-mx'] = ''; + $apps[$x]['menu'][1]['title']['es-mx'] = ''; $apps[$x]['menu'][1]['title']['de'] = ''; $apps[$x]['menu'][1]['title']['de-ch'] = ''; $apps[$x]['menu'][1]['title']['de-at'] = ''; @@ -90,6 +90,15 @@ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'extension_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_extensions'; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'extension_uuid'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = 'v_id'; $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index ee3bd1d455..d6765b3174 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2013 the Initial Developer. All Rights Reserved. Contributor(s): @@ -210,6 +210,11 @@ function process_xml_cdr($db, $leg, $xml_string) { $database->fields['xml_cdr'] = check_str($xml_string); } + //insert the check_str($extension_uuid) + if (check_str($extension_uuid)) { + $database->fields['extension_uuid'] = check_str($extension_uuid); + } + //insert xml_cdr into the db if (strlen($start_stamp) > 0) { $database->add(); diff --git a/includes/install/scripts/xml_handler.lua b/includes/install/scripts/xml_handler.lua index 2e1ee6db35..1d8bc511a6 100644 --- a/includes/install/scripts/xml_handler.lua +++ b/includes/install/scripts/xml_handler.lua @@ -757,6 +757,7 @@ table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); if (string.len(call_group) > 0) then diff --git a/includes/lib_switch.php b/includes/lib_switch.php index a8fc82e46b..4989887c7f 100644 --- a/includes/lib_switch.php +++ b/includes/lib_switch.php @@ -1733,6 +1733,7 @@ function save_extension_xml() { //echo "enabled: ".$row['enabled']; if ($row['enabled'] != "false") { + $extension_uuid = $row['extension_uuid']; //remove invalid characters from the file names $extension = $row['extension']; $extension = str_replace(" ", "_", $extension); @@ -1803,6 +1804,7 @@ function save_extension_xml() { $xml .= " \n"; $xml .= " \n"; $xml .= " \n"; + $xml .= " \n"; if (strlen($row['call_group']) > 0) { $xml .= " \n"; }