diff options
-rw-r--r-- | config/freeswitch_dev/dialplan.default.xml | 52 | ||||
-rw-r--r-- | config/freeswitch_dev/freeswitch.inc | 568 | ||||
-rw-r--r-- | config/freeswitch_dev/freeswitch_hunt_group.tmp | 32 | ||||
-rw-r--r-- | config/freeswitch_dev/freeswitch_hunt_group_edit.tmp | 31 | ||||
-rw-r--r-- | config/freeswitch_dev/index.tmp | 5 | ||||
-rw-r--r-- | config/freeswitch_dev/originate.js | 84 | ||||
-rw-r--r-- | config/freeswitch_dev/please_say_your_name_and_reason_for_calling.wav | bin | 0 -> 35860 bytes | |||
-rw-r--r-- | config/freeswitch_dev/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav | bin | 0 -> 68104 bytes |
8 files changed, 614 insertions, 158 deletions
diff --git a/config/freeswitch_dev/dialplan.default.xml b/config/freeswitch_dev/dialplan.default.xml index 93ecff16..426dedd8 100644 --- a/config/freeswitch_dev/dialplan.default.xml +++ b/config/freeswitch_dev/dialplan.default.xml @@ -177,16 +177,16 @@ <action application="bridge" data="user/${dialed_extension}@${domain_name}"/> </condition> </extension> - + <X-PRE-PROCESS cmd="include" data="default/*.xml"/> - + <!-- - dial the extension (1000-1019) for 30 seconds and go to voicemail if the + dial the extension 3, 4, or 5 digit extensions for 30 seconds and go to voicemail if the call fails (continue_on_fail=true), otherwise hang up after a successful bridge (hangup_after-bridge=true) --> <extension name="Local_Extension"> - <condition field="destination_number" expression="(^\d{4}$|^\d{3}$)"> + <condition field="destination_number" expression="(^\d{5}$|^\d{4}$|^\d{3}$)"> <action application="set" data="dialed_extension=$1"/> <action application="export" data="dialed_extension=$1"/> <!-- bind_meta_app can have these args <key> [a|b|ab] [a|b|o|s] <app> --> @@ -240,24 +240,54 @@ </extension> --> + <!-- voicemail main2 extension --> + <extension name="vmain2"> + <condition field="destination_number" expression="^vmain2$|^\*97$|^\*4000$"> + <action application="answer"/> + <action application="sleep" data="1000"/> + <action application="voicemail" data="check default ${domain_name}"/> + </condition> + </extension> + <!-- voicemail main extension --> <extension name="vmain"> - <condition field="destination_number" expression="^vmain|\*98$"> + <condition field="destination_number" expression="^vmain$|^\*98$"> <action application="answer"/> <action application="sleep" data="1000"/> <action application="voicemail" data="check default ${domain_name} ${sip_from_user}"/> </condition> </extension> - - <!-- voicemail main2 extension --> - <extension name="vmain2"> - <condition field="destination_number" expression="^vmain2|\*4000"> + + <extension name="send_to_voicemail_5digits"> + <condition field="destination_number" expression="^\*99(\d{5})$"> <action application="answer"/> <action application="sleep" data="1000"/> - <action application="voicemail" data="check default ${domain_name}"/> + <action application="set" data="dialed_extension=$1"/> + <action application="export" data="dialed_extension=$1"/> + <action application="voicemail" data="default ${domain_name} ${dialed_extension}"/> </condition> </extension> - + + <extension name="send_to_voicemail_4digits"> + <condition field="destination_number" expression="^\*99(\d{4})$"> + <action application="answer"/> + <action application="sleep" data="1000"/> + <action application="set" data="dialed_extension=$1"/> + <action application="export" data="dialed_extension=$1"/> + <action application="voicemail" data="default ${domain_name} ${dialed_extension}"/> + </condition> + </extension> + + <extension name="send_to_voicemail_3digits"> + <condition field="destination_number" expression="^\*99(\d{3})$"> + <action application="answer"/> + <action application="sleep" data="1000"/> + <action application="set" data="dialed_extension=$1"/> + <action application="export" data="dialed_extension=$1"/> + <action application="voicemail" data="default ${domain_name} ${dialed_extension}"/> + </condition> + </extension> + <!-- dial via SIP uri --> <extension name="sip_uri"> <condition field="destination_number" expression="^sip:(.*)$"> diff --git a/config/freeswitch_dev/freeswitch.inc b/config/freeswitch_dev/freeswitch.inc index 77847d8e..7d25a8e8 100644 --- a/config/freeswitch_dev/freeswitch.inc +++ b/config/freeswitch_dev/freeswitch.inc @@ -32,6 +32,8 @@ POSSIBILITY OF SUCH DAMAGE. */ +//ob_start("ob_gzhandler"); + function build_menu() { //$script_name_array = split ("/", $_SERVER["SCRIPT_NAME"]); @@ -1062,14 +1064,15 @@ function sync_package_freeswitch_hunt_group() //$rowhelper['huntgrouptimeout'] //$rowhelper['huntgroupcontext'] //$rowhelper['huntgroupringback'] - //$rowhelper['huntgroupcidnameprefix'] + //$rowhelper['huntgroupcidnameprefix'] + //$rowhelper['huntgrouppin'] + //$rowhelper['huntgroupcallerannounce'] //$rowhelper['huntgroupdescr'] //add each Hunt Group to the dialplan $a_dialplan_includes = &$config['installedpackages']['freeswitchdialplanincludes']['config']; $a_dialplan_include_details = &$config['installedpackages']['freeswitchdialplanincludedetails']['config']; - if (strlen($rowhelper['huntgroupid']) > 0) { $action = 'add'; //set default action to add $i = 0; @@ -1083,7 +1086,6 @@ function sync_package_freeswitch_hunt_group() //$row['enabled']; if ($row['opt1name'] == "huntgroupid" && $row['opt1value'] == $rowhelper['huntgroupid']) { - //update $action = 'update'; $dialplanincludeid = $row['dialplanincludeid']; $extensionname = $row['extensionname']; @@ -1094,8 +1096,6 @@ function sync_package_freeswitch_hunt_group() $opt1name = $row['opt1name']; $opt1value = $row['opt1value']; $id = $i; - //echo "update".$i."<br />\n"; - } $i++; } @@ -1105,99 +1105,268 @@ function sync_package_freeswitch_hunt_group() $ent = array(); if ($action == 'add') { + //create huntgroup extension in the dialplan + $ent = array(); + $dialplanincludeid = guid(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['extensionname'] = $rowhelper['huntgroupname']; + $ent['order'] = '9001'; //if update use the existing order number and extension name and desc + $ent['context'] = $rowhelper['huntgroupcontext']; + $ent['enabled'] = 'true'; + $ent['descr'] = 'huntgroup'; + $ent['opt1name'] = 'huntgroupid'; + $ent['opt1value'] = $rowhelper['huntgroupid']; + + $a_dialplan_includes[] = $ent; //add to the config + unset($ent); + + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'condition'; //condition, action, antiaction + $ent['fieldtype'] = 'destination_number'; + $ent['fielddata'] = '^'.$rowhelper['huntgroupextension'].'$'; + $a_dialplan_include_details[] = $ent; + unset($ent); + $huntgroupid = str_replace(array("{", "}"), "", $rowhelper['huntgroupid']); + + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'javascript'; + $ent['fielddata'] = 'huntgroup_'.$huntgroupid.'.js'; + $a_dialplan_include_details[] = $ent; + unset($ent); + + unset($huntgroupid); + + } + if ($action == 'update') { + //update the huntgroup + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['extensionname'] = $rowhelper['huntgroupname']; + $ent['order'] = $order; + $ent['context'] = $context; + $ent['enabled'] = $enabled; + $ent['descr'] = $descr; + $ent['opt1name'] = $opt1name; + $ent['opt1value'] = $opt1value; + + //update the config + $a_dialplan_includes[$id] = $ent; + + unset($ent); + unset($extensionname); + unset($order); + unset($context); + unset($enabled); + unset($descr); + unset($opt1name); + unset($opt1value); + unset($id); + } + unset($action); + unset($dialplanincludeid); + + //check whether the fifo queue exists already + $action = 'add'; //set default action to add + $i = 0; + if (count($a_dialplan_includes) > 0) { + + foreach($a_dialplan_includes as $row) { + + //$row['dialplanincludeid']; + //$row['extensionname']; + //$row['context']; + //$row['enabled']; + + if ($row['opt1name'] == "huntgroupfifoid" && $row['opt1value'] == $rowhelper['huntgroupid']) { + $action = 'update'; + $dialplanincludeid = $row['dialplanincludeid']; + $extensionname = $row['extensionname']; + $order = $row['order']; + $context = $row['context']; + $enabled = $row['enabled']; + $descr = $row['descr']; + $opt1name = $row['opt1name']; + $opt1value = $row['opt1value']; + $id = $i; + } + $i++; + } + unset($i); + } + + if ($action == 'add') { + + //create a fifo queue for each huntgroup + $ent = array(); $dialplanincludeid = guid(); $ent['dialplanincludeid'] = $dialplanincludeid; - $ent['extensionname'] = $rowhelper['huntgroupname']; - $ent['order'] = '9001'; //if update use the existing order number and extension name and desc + $ent['extensionname'] = $rowhelper['huntgroupname'].'.park'; + $ent['order'] = '9999'; //if update use the existing order number and extension name and desc $ent['context'] = $rowhelper['huntgroupcontext']; $ent['enabled'] = 'true'; - $ent['descr'] = 'huntgroup'; - $ent['opt1name'] = 'huntgroupid'; + $ent['descr'] = 'fifo '.$rowhelper['huntgroupextension']; + $ent['opt1name'] = 'huntgroupfifoid'; $ent['opt1value'] = $rowhelper['huntgroupid']; + $a_dialplan_includes[] = $ent; //add to the config + unset($ent); - //add to the config - $a_dialplan_includes[] = $ent; - unset($ent); - $ent = array(); $ent['dialplanincludeid'] = $dialplanincludeid; $ent['tag'] = 'condition'; //condition, action, antiaction $ent['fieldtype'] = 'destination_number'; - $ent['fielddata'] = '^'.$rowhelper['huntgroupextension'].'$'; - $a_dialplan_include_details[] = $ent; + $ent['fielddata'] = '^\*'.$rowhelper['huntgroupextension'].'$'; + $ent['fieldorder'] = '000'; + $a_dialplan_include_details[] = $ent; //add to the config + unset($ent); + + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'set'; + $ent['fielddata'] = 'fifo_music=$${hold_music}'; + $ent['fieldorder'] = '001'; + $a_dialplan_include_details[] = $ent; //add to the config unset($ent); - $huntgroupid = str_replace(array("{", "}"), "", $rowhelper['huntgroupid']); + $huntgrouptimeouttype = $rowhelper['huntgrouptimeouttype']; + $huntgrouptimeoutdestination = $rowhelper['huntgrouptimeoutdestination']; + if ($huntgrouptimeouttype == "voicemail") { $huntgrouptimeoutdestination = '***'.$huntgrouptimeoutdestination; } $ent = array(); $ent['dialplanincludeid'] = $dialplanincludeid; $ent['tag'] = 'action'; //condition, action, antiaction - $ent['fieldtype'] = 'javascript'; - $ent['fielddata'] = 'huntgroup_'.$huntgroupid.'.js'; + $ent['fieldtype'] = 'set'; + $ent['fielddata'] = 'fifo_orbit_exten='.$huntgrouptimeoutdestination.':'.$rowhelper['huntgrouptimeout']; + $ent['fieldorder'] = '002'; $a_dialplan_include_details[] = $ent; - unset($ent); + unset($ent); //add to the config - unset($huntgroupid); - + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'fifo'; + $ent['fielddata'] = $rowhelper['huntgroupextension'].'@${domain_name} in'; + $ent['fieldorder'] = '003'; + $a_dialplan_include_details[] = $ent; //add to the config + unset($ent); } if ($action == 'update') { + //update the huntgroup + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['extensionname'] = $rowhelper['huntgroupname'].'.park'; + $ent['order'] = $order; + $ent['context'] = $rowhelper['huntgroupcontext']; + $ent['enabled'] = $enabled; + $ent['descr'] = 'fifo '.$rowhelper['huntgroupextension']; + $ent['opt1name'] = $opt1name; + $ent['opt1value'] = $opt1value; + + //update the config + $a_dialplan_includes[$id] = $ent; - $ent['dialplanincludeid'] = $dialplanincludeid; - $ent['extensionname'] = $rowhelper['huntgroupname']; - $ent['order'] = $order; - $ent['context'] = $context; - $ent['enabled'] = $enabled; - $ent['descr'] = $descr; - $ent['opt1name'] = $opt1name; - $ent['opt1value'] = $opt1value; + unset($ent); + unset($extensionname); + unset($order); + unset($context); + unset($enabled); + unset($descr); + unset($opt1name); + unset($opt1value); + unset($id); + + //delete dialplan include details + if (count($a_dialplan_include_details) > 0) { + foreach($a_dialplan_include_details as $row) { + if ($row['dialplanincludeid'] == $dialplanincludeid) { + $id = $i; + unset($a_dialplan_include_details[$id]); + } + $i++; + } + unset($i); + } - //update the config - $a_dialplan_includes[$id] = $ent; + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'condition'; //condition, action, antiaction + $ent['fieldtype'] = 'destination_number'; + $ent['fielddata'] = '^\*'.$rowhelper['huntgroupextension'].'$'; + $ent['fieldorder'] = '000'; + $a_dialplan_include_details[] = $ent; //add to the config + unset($ent); - unset($ent); - unset($extensionname); - unset($order); - unset($context); - unset($enabled); - unset($descr); - unset($opt1name); - unset($opt1value); - unset($id); + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'set'; + $ent['fielddata'] = 'fifo_music=$${hold_music}'; + $ent['fieldorder'] = '001'; + $a_dialplan_include_details[] = $ent; //add to the config + unset($ent); + + $huntgrouptimeouttype = $rowhelper['huntgrouptimeouttype']; + $huntgrouptimeoutdestination = $rowhelper['huntgrouptimeoutdestination']; + if ($huntgrouptimeouttype == "voicemail") { $huntgrouptimeoutdestination = '***'.$huntgrouptimeoutdestination; } + + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'set'; + $ent['fielddata'] = 'fifo_orbit_exten='.$huntgrouptimeoutdestination.':'.$rowhelper['huntgrouptimeout']; + $ent['fieldorder'] = '002'; + $a_dialplan_include_details[] = $ent; + unset($ent); //add to the config + + $ent = array(); + $ent['dialplanincludeid'] = $dialplanincludeid; + $ent['tag'] = 'action'; //condition, action, antiaction + $ent['fieldtype'] = 'fifo'; + $ent['fielddata'] = $rowhelper['huntgroupextension'].'@${domain_name} in'; + $ent['fieldorder'] = '003'; + $a_dialplan_include_details[] = $ent; //add to the config + unset($ent); } + write_config(); - - sync_package_freeswitch_dialplan_includes(); + sync_package_freeswitch_dialplan_includes(); unset($dialplanincludeid); } //end if strlen huntgroupid; add the Hunt Group to the dialplan - //--- begin: pin number ------------------------------------ - if (strlen($rowhelper['huntgrouppin']) > 0) { - $tmp .= "var pin = '".$rowhelper['huntgrouppin']."';\n"; - $tmp .= "if (pin.length > 0) {\n"; - $tmp .= " var dtmf = new Object();\n"; - $tmp .= " dtmf.digits = \"\";\n"; - $tmp .= " digitmaxlength = 6;\n"; - $tmp .= " session.execute(\"set\", \"playback_terminators=#\");\n"; - $tmp .= " session.streamFile( \"/usr/local/freeswitch/sounds/custom/8000/please_enter_the_pin_number.wav\", mycb, \"dtmf\");\n"; - $tmp .= " session.collectInput( mycb, dtmf, timeoutpin );\n"; - $tmp .= "\n"; - $tmp .= " if (dtmf.digits == pin || pin.length == 0) {\n"; - $tmp .= " //continue\n"; - $tmp .= " }\n"; - $tmp .= " else {\n"; - $tmp .= " console_log( \"info\", \"Pin: \" + dtmf.digits + \" is incorrect\\n\" );\n"; - $tmp .= " session.streamFile( \"/usr/local/freeswitch/sounds/custom/8000/your_pin_number_is_incorect_goodbye.wav\", mycb, \"dtmf\");\n"; - $tmp .= " session.hangup();\n"; - $tmp .= " }\n"; - $tmp .= "}"; - } - //--- end: pin number ------------------------------------ - + + //Get the list of destinations then build the Hunt Group javascript $tmp = ""; $tmp .= "\n"; + $tmp .= "session.answer();\n"; + $tmp .= "var domain_name = session.getVariable(\"domain_name\");\n"; + $tmp .= "var extension = '".$rowhelper['huntgroupextension']."';\n"; + $tmp .= "var result;\n"; + $tmp .= "var timeoutpin = 7500;\n"; + $tmp .= "\n"; + $tmp .= "var objdate = new Date();\n"; + $tmp .= "var adjusthours = 0; //Adjust Server time that is set to GMT 7 hours\n"; + $tmp .= "var adjustoperator = \"-\"; //+ or -\n"; + $tmp .= "if (adjustoperator == \"-\") {\n"; + $tmp .= "var objdate2 = new Date(objdate.getFullYear(),objdate.getMonth(),objdate.getDate(),(objdate.getHours() - adjusthours),objdate.getMinutes(),objdate.getSeconds());\n"; + $tmp .= "}\n"; + $tmp .= "if (adjustoperator == \"+\") {\n"; + $tmp .= "var objdate2 = new Date(objdate.getFullYear(),objdate.getMonth(),objdate.getDate(),(objdate.getHours() + adjusthours),objdate.getMinutes(),objdate.getSeconds());\n"; + $tmp .= "}\n"; + $tmp .= "var Hours = objdate2.getHours();\n"; + $tmp .= "var Mins = objdate2.getMinutes();\n"; + $tmp .= "var Seconds = objdate2.getSeconds();\n"; + $tmp .= "var Month = objdate2.getMonth() + 1;\n"; + $tmp .= "var Date = objdate2.getDate();\n"; + $tmp .= "var Year = objdate2.getYear()\n"; + $tmp .= "var Day = objdate2.getDay()+1;\n"; + $tmp .= "var exit = false;\n"; + $tmp .= "\n"; $tmp .= " function get_sofia_contact(extension,domain_name, profile){\n"; $tmp .= " if (profile == \"auto\") {\n"; @@ -1229,57 +1398,131 @@ function sync_package_freeswitch_hunt_group() $tmp .= " return sofia_contact;\n"; $tmp .= " }\n"; $tmp .= "\n"; + + $tmp .= "\n"; + $tmp .= " function mycb( session, type, obj, arg ) {\n"; + $tmp .= " try {\n"; + $tmp .= " if ( type == \"dtmf\" ) {\n"; + $tmp .= " console_log( \"info\", \"digit: \"+obj.digit+\"\\n\" );\n"; + $tmp .= " if ( obj.digit == \"#\" ) {\n"; + $tmp .= " //console_log( \"info\", \"detected pound sign.\\n\" );\n"; + $tmp .= " exit = true;\n"; + $tmp .= " return( false );\n"; + $tmp .= " }\n"; + $tmp .= "\n"; + $tmp .= " dtmf.digits += obj.digit;\n"; + $tmp .= "\n"; + $tmp .= " if ( dtmf.digits.length >= digitmaxlength ) {\n"; + $tmp .= " exit = true;\n"; + $tmp .= " return( false );\n"; + $tmp .= " }\n"; + $tmp .= " }\n"; + $tmp .= " } catch (e) {\n"; + $tmp .= " console_log( \"err\", e+\"\\n\" );\n"; + $tmp .= " }\n"; + $tmp .= " return( true );\n"; + $tmp .= " } //end function mycb\n"; + $tmp .= "\n"; + $tmp .= "\n"; - $tmp .= " dialed_extension = session.getVariable(\"dialed_extension\");\n"; - $tmp .= " domain_name = session.getVariable(\"domain_name\");\n"; - $tmp .= " domain = session.getVariable(\"domain\");\n"; - $tmp .= " us_ring = session.getVariable(\"us-ring\");\n"; - $tmp .= " caller_id_name = session.getVariable(\"caller_id_name\");\n"; - $tmp .= " caller_id_number = session.getVariable(\"caller_id_number\");\n"; - $tmp .= " effective_caller_id_name = session.getVariable(\"effective_caller_id_name\");\n"; - $tmp .= " effective_caller_id_number = session.getVariable(\"effective_caller_id_number\");\n"; - $tmp .= " outbound_caller_id_name = session.getVariable(\"outbound_caller_id_name\");\n"; - $tmp .= " outbound_caller_id_number = session.getVariable(\"outbound_caller_id_number\");\n"; + $tmp .= "dialed_extension = session.getVariable(\"dialed_extension\");\n"; + $tmp .= "domain_name = session.getVariable(\"domain_name\");\n"; + $tmp .= "domain = session.getVariable(\"domain\");\n"; + $tmp .= "us_ring = session.getVariable(\"us-ring\");\n"; + $tmp .= "caller_id_name = session.getVariable(\"caller_id_name\");\n"; + $tmp .= "caller_id_number = session.getVariable(\"caller_id_number\");\n"; + $tmp .= "effective_caller_id_name = session.getVariable(\"effective_caller_id_name\");\n"; + $tmp .= "effective_caller_id_number = session.getVariable(\"effective_caller_id_number\");\n"; + $tmp .= "outbound_caller_id_name = session.getVariable(\"outbound_caller_id_name\");\n"; + $tmp .= "outbound_caller_id_number = session.getVariable(\"outbound_caller_id_number\");\n"; $tmp .= "\n"; + + //pin number requested from caller if provided + if (strlen($rowhelper['huntgrouppin']) > 0) { + $tmp .= "var pin = '".$rowhelper['huntgrouppin']."';\n"; + $tmp .= "if (pin.length > 0) {\n"; + $tmp .= " var dtmf = new Object();\n"; + $tmp .= " dtmf.digits = \"\";\n"; + $tmp .= " digitmaxlength = 6;\n"; + $tmp .= " session.execute(\"set\", \"playback_terminators=#\");\n"; + $tmp .= " session.streamFile( \"/usr/local/freeswitch/sounds/custom/8000/please_enter_the_pin_number.wav\", mycb, \"dtmf\");\n"; + $tmp .= " session.collectInput( mycb, dtmf, timeoutpin );\n"; + $tmp .= "\n"; + $tmp .= " if (dtmf.digits == pin || pin.length == 0) {\n"; + $tmp .= " //continue\n"; + $tmp .= " }\n"; + $tmp .= " else {\n"; + $tmp .= " console_log( \"info\", \"Pin: \" + dtmf.digits + \" is incorrect\\n\" );\n"; + $tmp .= " session.streamFile( \"/usr/local/freeswitch/sounds/custom/8000/your_pin_number_is_incorect_goodbye.wav\", mycb, \"dtmf\");\n"; + $tmp .= " session.hangup();\n"; + $tmp .= " }\n"; + $tmp .= "}\n"; + $tmp .= "\n"; + } + + //caller announce requested from caller if provided + if ($rowhelper['huntgroupcallerannounce'] == "true") { + $tmp .= "function originate(session, sipuri, extension, caller_announce, caller_id_name, caller_id_number) {\n"; + $tmp .= " caller_id_name = caller_id_name.replace(\" \", \"+\");\n"; + $tmp .= " apiExecute(\"jsrun\", \"originate.js \"+session.uuid+\" \"+sipuri+\" \"+extension+\" \"+caller_announce+\" \"+caller_id_name+\" \"+caller_id_number);\n"; + $tmp .= "}"; + $tmp .= "\n"; + $tmp .= "var caller_announce = extension+\"_\"+Year+Month+Day+Hours+Mins+Seconds+\".wav\";\n"; + $tmp .= "session.streamFile( \"/usr/local/freeswitch/sounds/custom/8000/please_say_your_name_and_reason_for_calling.wav\");\n"; + $tmp .= "session.execute(\"gentones\", \"%(1000, 0, 640)\");\n"; + $tmp .= "session.execute(\"set\", \"playback_terminators=#\");\n"; + $tmp .= "session.execute(\"record\", \"/tmp/\"+caller_announce+\" 180 200\");\n"; + $tmp .= "\n"; + $tmp .= "result = session.setAutoHangup(false);\n"; + $tmp .= "session.execute(\"transfer\", \"*\"+extension+\" XML default\");\n"; + $tmp .= "\n"; + } + //set caller id prefix - if (strlen($rowhelper['huntgroupcidnameprefix'])> 0) { - $tmp .= "session.execute(\"set\", \"caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+caller_id_name);\n"; - $tmp .= "session.execute(\"set\", \"effective_caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+effective_caller_id_name);\n"; - $tmp .= "session.execute(\"set\", \"outbound_caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+outbound_caller_id_name);\n"; - } + if (strlen($rowhelper['huntgroupcidnameprefix'])> 0) { + $tmp .= "session.execute(\"set\", \"caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+caller_id_name);\n"; + $tmp .= "session.execute(\"set\", \"effective_caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+effective_caller_id_name);\n"; + $tmp .= "session.execute(\"set\", \"outbound_caller_id_name=".$rowhelper['huntgroupcidnameprefix']."\"+outbound_caller_id_name);\n"; + } - if (isset($rowhelper['huntgroupringback'])){ - if ($rowhelper['huntgroupringback'] == "ring"){ - $tmp .= " session.execute(\"set\", \"ringback=\"+us_ring); //set to ringtone\n"; - $tmp .= " session.execute(\"set\", \"transfer_ringback=\"+us_ring); //set to ringtone\n"; + //set ring back + if (isset($rowhelper['huntgroupringback'])){ + if ($rowhelper['huntgroupringback'] == "ring"){ + $tmp .= "session.execute(\"set\", \"ringback=\"+us_ring); //set to ringtone\n"; + $tmp .= "session.execute(\"set\", \"transfer_ringback=\"+us_ring); //set to ringtone\n"; + } + if ($rowhelper['huntgroupringback'] == "music"){ + $tmp .= "session.execute(\"set\", \"ringback=\${hold_music}\"); //set to ringtone\n"; + $tmp .= "session.execute(\"set\", \"transfer_ringback=\${hold_music}\"); //set to ringtone\n"; + } } - if ($rowhelper['huntgroupringback'] == "music"){ - $tmp .= " session.execute(\"set\", \"ringback=\${hold_music}\"); //set to ringtone\n"; - $tmp .= " session.execute(\"set\", \"transfer_ringback=\${hold_music}\"); //set to ringtone\n"; + else { + $tmp .= "session.execute(\"set\", \"ringback=\${hold_music}\"); //set to ringtone\n"; + $tmp .= "session.execute(\"set\", \"transfer_ringback=\${hold_music}\"); //set to ringtone\n"; } - } - else { - $tmp .= " session.execute(\"set\", \"ringback=\${hold_music}\"); //set to ringtone\n"; - $tmp .= " session.execute(\"set\", \"transfer_ringback=\${hold_music}\"); //set to ringtone\n"; - } if ($rowhelper['huntgrouptimeout'] > 0) { - $tmp .= " session.execute(\"set\", \"call_timeout=".$rowhelper['huntgrouptimeout']."\");\n"; - $tmp .= " session.execute(\"set\", \"continue_on_fail=true\");\n"; + $tmp .= "session.execute(\"set\", \"call_timeout=".$rowhelper['huntgrouptimeout']."\");\n"; + $tmp .= "session.execute(\"set\", \"continue_on_fail=true\");\n"; } - $tmp .= " session.execute(\"set\", \"hangup_after_bridge=true\");\n"; + $tmp .= "session.execute(\"set\", \"hangup_after_bridge=true\");\n"; $tmp .= "\n"; - $tmp .= " //console_log( \"info\", \"dialed extension:\"+dialed_extension+\".\\n\" );\n"; - $tmp .= " //console_log( \"info\", \"domain: \"+domain+\".\\n\" );\n"; - $tmp .= " //console_log( \"info\", \"us_ring: \"+us_ring+\".\\n\" );\n"; - $tmp .= " //console_log( \"info\", \"domain: \"+domain+\".\\n\" );\n"; - $tmp .= " //console_log( \"info\", \"domain_name: \"+domain_name+\".\\n\" );\n"; + $tmp .= "//console_log( \"info\", \"dialed extension:\"+dialed_extension+\".\\n\" );\n"; + $tmp .= "//console_log( \"info\", \"domain: \"+domain+\".\\n\" );\n"; + $tmp .= "//console_log( \"info\", \"us_ring: \"+us_ring+\".\\n\" );\n"; + $tmp .= "//console_log( \"info\", \"domain: \"+domain+\".\\n\" );\n"; + $tmp .= "//console_log( \"info\", \"domain_name: \"+domain_name+\".\\n\" );\n"; $tmp .= "\n"; - $tmp .= " //console_log( \"info\", \"action call now don't wait for dtmf\\n\" );\n"; - $tmp .= " if ( session.ready() ) {\n"; - $tmp .= " session.answer();\n"; + $tmp .= "//console_log( \"info\", \"action call now don't wait for dtmf\\n\" );\n"; + if ($rowhelper['huntgroupcallerannounce'] == "true") { + //do nothing + } + else { + $tmp .= "if ( session.ready() ) {\n"; + $tmp .= " session.answer();\n"; + } $tmp .= "\n"; $a_hunt_group = &$config['installedpackages']['freeswitchhuntgroup']['config']; @@ -1323,20 +1566,21 @@ function sync_package_freeswitch_hunt_group() if (strlen($row['destinationnumber']) == 0) { $row['destinationnumber'] = "internal"; } if ($row['destinationtype'] == "extension") { - $tmp .= " sofia_contact_".$row['destinationnumber']." = get_sofia_contact(\"".$row['destinationnumber']."\",domain_name, \"".$row['destinationprofile']."\");\n"; + $tmp .= "sofia_contact_".$row['destinationnumber']." = get_sofia_contact(\"".$row['destinationnumber']."\",domain_name, \"".$row['destinationprofile']."\");\n"; $tmp_sub_array["application"] = "bridge"; $tmp_sub_array["data"] = "sofia_contact_".$row['destinationnumber']; $tmp_array[$i] = $tmp_sub_array; - unset($tmp_sub_array); + unset($tmp_sub_array); } - if ($row['destinationtype'] == "voicemail") { - $tmp .= " session.execute(\"voicemail\", \"default \${domain} ".$row['destinationnumber']."\");\n"; + if ($row['destinationtype'] == "voicemail") { + $tmp_sub_array["application"] = "voicemail"; + $tmp .= "session.execute(\"voicemail\", \"default \${domain} ".$row['destinationnumber']."\");\n"; //$tmp_sub_array["application"] = "voicemail"; //$tmp_sub_array["data"] = "default \${domain} ".$row['destinationnumber']; //$tmp_array[$i] = $tmp_sub_array; unset($tmp_sub_array); } - if ($row['destinationtype'] == "sip uri") { + if ($row['destinationtype'] == "sip uri") { $tmp_sub_array["application"] = "bridge"; $tmp_sub_array["data"] = "\"".$row['destinationnumber']."\""; $tmp_array[$i] = $tmp_sub_array; @@ -1350,43 +1594,65 @@ function sync_package_freeswitch_hunt_group() unset($i); } //if count - + $i = 0; + if(count($tmp_array) > 0) { + foreach ($tmp_array as $row) { + $tmpdata = $row["data"]; + if ($row["application"] == "voicemail") { $tmpdata = "***".$tmpdata; } + if ($i < 1) { + $tmp_buffer = $tmpdata; + } + else { + $tmp_buffer .= "+\",\"+".$tmpdata; + } + $i++; + } + } + unset($i); + $delimiter = ","; + $tmp_application = $tmp_array[0]["application"]; switch ($rowhelper['huntgrouptype']) { case "simultaneous": //print_r($tmp_array); - $i = 0; - if(count($tmp_array) > 0) { - foreach ($tmp_array as $row) { - if ($i < 1) { - $tmp_buffer = $row["data"]; - } - else { - $tmp_buffer .= "+\",\"+".$row["data"]; + if ($rowhelper['huntgroupcallerannounce'] == "true") { + $i = 0; + if (count($tmp_array) > 0) { + foreach ($tmp_array as $row) { + $tmpdata = $row["data"]; + if ($row["application"] == "voicemail") { $tmpdata = "***".$tmpdata; } + $tmp .= " result = originate (session, ".$tmpdata.", extension, caller_announce, caller_id_name, caller_id_number);\n"; } - $i++; } } - unset($i); - - $delimiter = ","; - $tmp_application = $tmp_array[0]["application"]; + else { + $tmp .= "\n"; + $tmp .= " session.execute(\"".$tmp_application."\", $tmp_buffer);\n"; + //$tmp .= " session.execute(\"bridge\", sofia_contact_100+\",\"+sofia_contact_101+\",\"+sofia_contact_102+\",\"+sofia_contact_103+\",\"+sofia_contact_104);\n"; + //$tmp .= " //session.execute(\"bridge\", \"sofia/gateway/flowroute.com/12081231234,\"+sofia_contact_101);\n"; + } unset($tmp_array); - - $tmp .= "\n"; - $tmp .= " session.execute(\"".$tmp_application."\", $tmp_buffer);\n"; - //$tmp .= " session.execute(\"bridge\", sofia_contact_100+\",\"+sofia_contact_101+\",\"+sofia_contact_102+\",\"+sofia_contact_103+\",\"+sofia_contact_104);\n"; - //$tmp .= " //session.execute(\"bridge\", \"sofia/gateway/flowroute.com/12081231234,\"+sofia_contact_101);\n"; - break; case "sequentially": $tmp .= "\n"; //print_r($tmp_array); $i = 0; - if (count($tmp_array) > 0) { - foreach ($tmp_array as $row) { - $tmp .= " session.execute(\"".$row["application"]."\", ".$row["data"].");\n"; + if (count($tmp_array) > 0) { + if ($rowhelper['huntgroupcallerannounce'] == "true") { + $i = 0; + if (count($tmp_array) > 0) { + //foreach ($tmp_array as $row) { + //$tmpdata = $row["data"]; + //if ($row["application"] == "voicemail") { $tmpdata = "***".$tmpdata; } + $tmp .= " result = originate (session, ".$tmp_buffer.", extension, caller_announce, caller_id_name, caller_id_number);\n"; + //} + } + } + else { + foreach ($tmp_array as $row) { + $tmp .= " session.execute(\"".$row["application"]."\", ".$row["data"].");\n"; + } } unset($tmp_array); } @@ -1394,7 +1660,6 @@ function sync_package_freeswitch_hunt_group() break; } - //set the timeout destination $huntgrouptimeoutdestination = $a_hunt_group[$x]['huntgrouptimeoutdestination']; $huntgrouptimeouttype = $a_hunt_group[$x]['huntgrouptimeouttype']; @@ -1402,19 +1667,28 @@ function sync_package_freeswitch_hunt_group() if ($row['huntgrouptimeouttype'] == "voicemail") { $huntgrouptimeouttype = "voicemail"; } if ($row['huntgrouptimeouttype'] == "sip uri") { $huntgrouptimeouttype = "bridge"; } $tmp .= "\n"; - $tmp .= " //timeout\n"; - $tmp .= " session.execute(\"".$huntgrouptimeouttype."\", \"default \${domain} ".$huntgrouptimeoutdestination."\");\n"; - + if ($rowhelper['huntgroupcallerannounce'] == "true") { + //do nothing + } + else { + $tmp .= " //timeout\n"; + $tmp .= " session.execute(\"".$huntgrouptimeouttype."\", \"default \${domain} ".$huntgrouptimeoutdestination."\");\n"; + } $tmp .= "\n"; - $tmp .= " //clear variables\n"; - $tmp .= " dialed_extension = \"\";\n"; - $tmp .= " new_extension = \"\";\n"; - $tmp .= " domain_name = \"\";\n"; - $tmp .= " domain = \"\";"; + $tmp .= " //clear variables\n"; + $tmp .= " dialed_extension = \"\";\n"; + $tmp .= " new_extension = \"\";\n"; + $tmp .= " domain_name = \"\";\n"; + $tmp .= " domain = \"\";"; $tmp .= "\n"; - $tmp .= " } //end if session.ready\n"; + if ($rowhelper['huntgroupcallerannounce'] == "true") { + //do nothing + } + else { + $tmp .= "} //end if session.ready\n"; + } $tmp .= "\n"; if (strlen($rowhelper['huntgroupid']) > 0) { @@ -2748,7 +3022,7 @@ function freeswitch_php_install_command() global $config; //exec("/etc/./rc.conf_mount_rw"); - $freeswitch_package_version = "0.9.4.8"; + $freeswitch_package_version = "0.9.5"; $freeswitch_build_version = "1.0.4 pre 8"; $freeswitch_build_revision = "13784"; @@ -2825,7 +3099,9 @@ function freeswitch_php_install_command() exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."call_forward_has_been_set.wav"); exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."call_forward_has_been_deleted.wav"); exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."begin_recording.wav"); - exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."your_pin_number_is_incorect_goodbye.wav"); + exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."your_pin_number_is_incorect_goodbye.wav"); + exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."please_say_your_name_and_reason_for_calling.wav"); + exec("cd /usr/local/freeswitch/sounds/custom/8000/;fetch ".$download_path."press_1_to_accept_2_to_reject_or_3_for_voicemail.wav"); //mod_fax exec("cd /usr/local/freeswitch/mod/;fetch ".$download_path."mod_fax.so"); @@ -2854,7 +3130,12 @@ function freeswitch_php_install_command() unlink_if_exists("/tmp/edit_area.tgz"); } + //rename PHP files from .tmp to .php + exec("cd /tmp/;fetch ".$download_path."index.tmp"); + exec("cp /tmp/index.tmp /usr/local/www/packages/freeswitch/index.php"); + unlink_if_exists("/tmp/index.tmp"); + exec("cd /tmp/;fetch ".$download_path."class.smtp.tmp"); exec("cp /tmp/class.smtp.tmp /usr/local/www/packages/freeswitch/class.smtp.php"); unlink_if_exists("/tmp/class.smtp.tmp"); @@ -3012,6 +3293,7 @@ function freeswitch_php_install_command() unlink_if_exists("/tmp/freeswitch_vars.tmp"); exec("cd /usr/local/freeswitch/scripts/;fetch ".$download_path."disa.js"); + exec("cd /usr/local/freeswitch/scripts/;fetch ".$download_path."originate.js"); exec("cp /usr/local/freeswitch/htdocs/slim.swf /usr/local/www/packages/freeswitch/slim.swf"); /* freeswitch settings defaults */ diff --git a/config/freeswitch_dev/freeswitch_hunt_group.tmp b/config/freeswitch_dev/freeswitch_hunt_group.tmp index 911b7d5b..ea3fe44d 100644 --- a/config/freeswitch_dev/freeswitch_hunt_group.tmp +++ b/config/freeswitch_dev/freeswitch_hunt_group.tmp @@ -35,7 +35,8 @@ require("/usr/local/pkg/freeswitch.inc"); $a_hunt_group = &$config['installedpackages']['freeswitchhuntgroup']['config']; - +$a_dialplan_includes = &$config['installedpackages']['freeswitchdialplanincludes']['config']; +$a_dialplan_include_details = &$config['installedpackages']['freeswitchdialplanincludedetails']['config']; if ($_GET['act'] == "del") { if ($_GET['type'] == 'huntgroup') { @@ -43,6 +44,35 @@ if ($_GET['act'] == "del") { if (file_exists("/usr/local/freeswitch/scripts/huntgroup_".$_GET['huntgroupid'].".js")) { unlink("/usr/local/freeswitch/scripts/huntgroup_".$_GET['huntgroupid'].".js"); } + /* + //delete dialplan include details + if (count($a_dialplan_includes) > 0) { + $i = 0; + foreach($a_dialplan_includes as $row) { + echo $row['opt1value']." == {".$_GET['huntgroupid']."}<br />\n"; + if ($row['opt1value'] == '{'.$_GET['huntgroupid'].'}') { + $dialplanincludeid = $row['dialplanincludeid']; + $id = $i; + unset($a_dialplan_include_details[$id]); + } + $i++; + } + unset($i); + } + + //delete dialplan include details + if (count($a_dialplan_include_details) > 0) { + $i = 0; + foreach($a_dialplan_include_details as $row) { + if ($row['dialplanincludeid'] == $dialplanincludeid) { + $id = $i; + unset($a_dialplan_include_details[$id]); + } + $i++; + } + unset($i); + } + */ unset($a_hunt_group[$_GET['id']]); write_config(); sync_package_freeswitch_hunt_group(); diff --git a/config/freeswitch_dev/freeswitch_hunt_group_edit.tmp b/config/freeswitch_dev/freeswitch_hunt_group_edit.tmp index 82fa87e0..fe22a78e 100644 --- a/config/freeswitch_dev/freeswitch_hunt_group_edit.tmp +++ b/config/freeswitch_dev/freeswitch_hunt_group_edit.tmp @@ -60,6 +60,7 @@ if (isset($id) && $a_hunt_group[$id]) { $pconfig['huntgroupringback'] = $a_hunt_group[$id]['huntgroupringback']; $pconfig['huntgroupcidnameprefix'] = $a_hunt_group[$id]['huntgroupcidnameprefix']; $pconfig['huntgrouppin'] = $a_hunt_group[$id]['huntgrouppin']; + $pconfig['huntgroupcallerannounce'] = $a_hunt_group[$id]['huntgroupcallerannounce']; $pconfig['huntgroupdescr'] = $a_hunt_group[$id]['huntgroupdescr']; } @@ -97,9 +98,10 @@ if ($_POST) { $huntgroupent['huntgrouptimeout'] = $_POST['huntgrouptimeout']; $huntgroupent['huntgrouptimeoutdestination'] = $_POST['huntgrouptimeoutdestination']; $huntgroupent['huntgrouptimeouttype'] = $_POST['huntgrouptimeouttype']; - $huntgroupent['huntgroupringback'] = $_POST['huntgroupringback']; - $huntgroupent['huntgroupcidnameprefix'] = $_POST['huntgroupcidnameprefix']; - $huntgroupent['huntgrouppin'] = $_POST['huntgrouppin']; + $huntgroupent['huntgroupringback'] = $_POST['huntgroupringback']; + $huntgroupent['huntgroupcidnameprefix'] = $_POST['huntgroupcidnameprefix']; + $huntgroupent['huntgrouppin'] = $_POST['huntgrouppin']; + $huntgroupent['huntgroupcallerannounce'] = $_POST['huntgroupcallerannounce']; $huntgroupent['huntgroupdescr'] = $_POST['huntgroupdescr']; if (isset($id) && $a_hunt_group[$id]) { @@ -296,6 +298,29 @@ display_top_tabs(build_menu()); </td> </tr> + <tr> + <td width="22%" valign="top" class="vncell">Caller Announce</td> + <td width="78%" class="vtable"> + <?php + echo " <select name='huntgroupcallerannounce' class='formfld'>\n"; + echo " <option></option>\n"; + if (htmlspecialchars($pconfig['huntgroupcallerannounce']) == "true") { + echo " <option selected='yes'>true</option>\n"; + } + else { + echo " <option>true</option>\n"; + } + if (htmlspecialchars($pconfig['huntgroupcallerannounce']) == "false") { + echo " <option selected='yes'>false</option>\n"; + } + else { + echo " <option>false</option>\n"; + } + echo " </select>\n"; + ?> + </td> + </tr> + <tr> <td width="22%" valign="top" class="vncell">Description</td> <td width="78%" class="vtable"> diff --git a/config/freeswitch_dev/index.tmp b/config/freeswitch_dev/index.tmp new file mode 100644 index 00000000..68984113 --- /dev/null +++ b/config/freeswitch_dev/index.tmp @@ -0,0 +1,5 @@ +<?php + +header( 'Location: /' ); + +?>
\ No newline at end of file diff --git a/config/freeswitch_dev/originate.js b/config/freeswitch_dev/originate.js new file mode 100644 index 00000000..a7c6fa2e --- /dev/null +++ b/config/freeswitch_dev/originate.js @@ -0,0 +1,84 @@ +var uuid = argv[0]; +var sipuri = argv[1]; +var extension = argv[2]; +var caller_announce = argv[3]; +var caller_id_name = argv[4]; +var caller_id_number = argv[5]; +var tmp_sipuri; + +caller_id_name = caller_id_name.replace("+", " "); +//console_log( "info", "caller_announce: "+caller_announce+"\n" ); + +function originate (session, sipuri, extension, caller_announce, caller_id_name, caller_id_number) { + + var dtmf = new Object(); + var cid; + dtmf.digits = ""; + cid = ",origination_caller_id_name="+caller_id_name+",origination_caller_id_number="+caller_id_number; + + new_session = new Session("{ignore_early_media=true"+cid+"}"+sipuri); + new_session.execute("set", "call_timeout=30"); + + if ( new_session.ready() ) { + + console_log( "info", "followme: new_session uuid "+new_session.uuid+"\n" ); + console_log( "info", "followme: no dtmf detected\n" ); + + digitmaxlength = 1; + while (new_session.ready()) { + + if (caller_announce.length > 0) { + new_session.streamFile( "/tmp/"+caller_announce); + } + new_session.streamFile( "/usr/local/freeswitch/sounds/custom/8000/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav"); + if (new_session.ready()) { + if (dtmf.digits.length == 0) { + dtmf.digits += new_session.getDigits(1, "#", 10000); // 10 seconds + if (dtmf.digits.length == 0) { + + } + else { + break; //dtmf found end the while loop + } + } + } + } + + if ( dtmf.digits.length > "0" ) { + if ( dtmf.digits == "1" ) { + console_log( "info", "followme: call accepted\n" ); //accept + new_session.execute("fifo", extension+"@${domain_name} out nowait"); + return true; + } + else if ( dtmf.digits == "2" ) { + console_log( "info", "followme: call rejected\n" ); //reject + new_session.hangup; + return false; + } + else if ( dtmf.digits == "3" ) { + console_log( "info", "followme: call sent to voicemail\n" ); //reject + new_session.hangup; + exit; + return true; + } + + } + else { + console_log( "info", "followme: no dtmf detected\n" ); //reject + new_session.hangup; + return false; + } + + } +} + +sipuri_array = sipuri.split(","); +for (i = 0; i < sipuri_array.length; i++){ + tmp_sipuri = sipuri_array[i]; + console_log("info", "tmp_sipuri: "+tmp_sipuri); + result = originate (session, tmp_sipuri, extension, caller_announce, caller_id_name, caller_id_number); + if (result) { + break; + exit; + } +}
\ No newline at end of file diff --git a/config/freeswitch_dev/please_say_your_name_and_reason_for_calling.wav b/config/freeswitch_dev/please_say_your_name_and_reason_for_calling.wav Binary files differnew file mode 100644 index 00000000..325a879d --- /dev/null +++ b/config/freeswitch_dev/please_say_your_name_and_reason_for_calling.wav diff --git a/config/freeswitch_dev/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav b/config/freeswitch_dev/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav Binary files differnew file mode 100644 index 00000000..9c01616a --- /dev/null +++ b/config/freeswitch_dev/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav |