| 25 | | if (!empty($code)) { |
|---|
| 26 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('dialnumber', '${EXTEN:'.strlen($code).'}')); |
|---|
| 27 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_dbget('user-intercom','AMPUSER/${dialnumber}/intercom')); |
|---|
| 28 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_gotoif('$["${user-intercom}" = "disabled" ]', 'nointercom')); |
|---|
| 29 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__SIPADDHEADER', 'Call-Info: \;answer-after=0')); |
|---|
| 30 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__ALERT_INFO', 'Ring Answer')); |
|---|
| 31 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true')); |
|---|
| 32 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_macro('user-callerid')); |
|---|
| 33 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_dial('Local/${dialnumber}@from-internal/n','','')); |
|---|
| 34 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_busy()); |
|---|
| 35 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_macro('hangupcall')); |
|---|
| 36 | | $ext->add('ext-intercom', '_'.$code.'.', 'nointercom', new ext_noop('Intercom disallowed by ${dialnumber}')); |
|---|
| 37 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_playback('intercom&for&extension')); |
|---|
| 38 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_saydigits('${dialnumber}')); |
|---|
| 39 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_playback('is&disabled')); |
|---|
| 40 | | $ext->add('ext-intercom', '_'.$code.'.', '', new ext_congestion()); |
|---|
| 41 | | |
|---|
| | 25 | $extpaging = 'ext-paging'; |
|---|
| | 26 | if (!empty($intercom_code)) { |
|---|
| | 27 | $code = '_'.$intercom_code.'.'; |
|---|
| | 28 | $context = 'ext-intercom'; |
|---|
| | 29 | $ext->add($context, $code, '', new ext_setvar('dialnumber', '${EXTEN:'.strlen($intercom_code).'}')); |
|---|
| | 30 | $ext->add($context, $code, '', new ext_macro('user-callerid')); |
|---|
| | 31 | $ext->add($context, $code, '', new ext_gotoif('$["${DB(AMPUSER/${dialnumber}/intercom/${AMPUSER})}" = "allow" ]', 'allow')); |
|---|
| | 32 | $ext->add($context, $code, '', new ext_gotoif('$["${DB(AMPUSER/${dialnumber}/intercom/${AMPUSER})}" = "deny" ]', 'nointercom')); |
|---|
| | 33 | $ext->add($context, $code, '', new ext_gotoif('$["${DB(AMPUSER/${dialnumber}/intercom)}" = "disabled" ]', 'nointercom')); |
|---|
| | 34 | $ext->add($context, $code, 'allow', new ext_dbget('DEVICES','AMPUSER/${dialnumber}/device')); |
|---|
| | 35 | $ext->add($context, $code, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'end')); |
|---|
| | 36 | $ext->add($context, $code, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}')); |
|---|
| | 37 | $ext->add($context, $code, '', new ext_gotoif('$[${LOOPCNT} > 1 ]', 'pagemode')); |
|---|
| | 38 | $ext->add($context, $code, '', new ext_macro('autoanswer','${DEVICES}')); |
|---|
| | 39 | $ext->add($context, $code, 'check', new ext_chanisavail('${DIAL}', 'sj')); |
|---|
| | 40 | $ext->add($context, $code, '', new ext_dial('${DIAL}','5,A(beep)')); |
|---|
| | 41 | $ext->add($context, $code, '', new ext_busy()); |
|---|
| | 42 | $ext->add($context, $code, '', new ext_macro('hangupcall')); |
|---|
| | 43 | $ext->add($context, $code, '', new ext_busy(), 'check',101); |
|---|
| | 44 | $ext->add($context, $code, '', new ext_macro('hangupcall')); |
|---|
| | 45 | $ext->add($context, $code, 'pagemode', new ext_setvar('ITER', '1')); |
|---|
| | 46 | $ext->add($context, $code, '', new ext_setvar('DIALSTR', '')); |
|---|
| | 47 | $ext->add($context, $code, '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true')); |
|---|
| | 48 | $ext->add($context, $code, 'begin', new ext_setvar('DIALSTR', '${DIALSTR}&LOCAL/PAGE${CUT(DEVICES,&,${ITER})}@'.$extpaging)); |
|---|
| | 49 | $ext->add($context, $code, '', new ext_setvar('ITER', '$[${ITER} + 1]')); |
|---|
| | 50 | $ext->add($context, $code, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin')); |
|---|
| | 51 | $ext->add($context, $code, '', new ext_setvar('DIALSTR', '${DIALSTR:1}')); |
|---|
| | 52 | $ext->add($context, $code, '', new ext_setvar('_FORCE_PAGE', '0')); |
|---|
| | 53 | $ext->add($context, $code, '', new ext_setvar('_AMPUSER', '${AMPUSER}')); |
|---|
| | 54 | $ext->add($context, $code, '', new ext_page('${DIALSTR},d')); |
|---|
| | 55 | $ext->add($context, $code, '', new ext_busy()); |
|---|
| | 56 | $ext->add($context, $code, '', new ext_macro('hangupcall')); |
|---|
| | 57 | $ext->add($context, $code, 'nointercom', new ext_noop('Intercom disallowed by ${dialnumber}')); |
|---|
| | 58 | $ext->add($context, $code, '', new ext_playback('intercom&for&extension')); |
|---|
| | 59 | $ext->add($context, $code, '', new ext_saydigits('${dialnumber}')); |
|---|
| | 60 | $ext->add($context, $code, '', new ext_playback('is&disabled')); |
|---|
| | 61 | $ext->add($context, $code, '', new ext_congestion()); |
|---|
| | 62 | |
|---|
| | 63 | $extintercomusers = 'ext-intercom-users'; |
|---|
| 51 | | $fcc = new featurecode('paging', 'intercom-on'); |
|---|
| 52 | | $oncode = $fcc->getCodeActive(); |
|---|
| 53 | | unset($fcc); |
|---|
| 54 | | |
|---|
| 55 | | if ($oncode) { |
|---|
| 56 | | $ext->add('ext-intercom-users', $oncode, '', new ext_answer('')); |
|---|
| 57 | | $ext->add('ext-intercom-users', $oncode, '', new ext_wait('1')); |
|---|
| 58 | | $ext->add('ext-intercom-users', $oncode, '', new ext_macro('user-callerid')); |
|---|
| 59 | | $ext->add('ext-intercom-users', $oncode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'enabled')); |
|---|
| 60 | | $ext->add('ext-intercom-users', $oncode, '', new ext_playback('intercom&enabled')); |
|---|
| 61 | | $ext->add('ext-intercom-users', $oncode, '', new ext_macro('hangupcall')); |
|---|
| 62 | | } |
|---|
| | 76 | $fcc = new featurecode('paging', 'intercom-on'); |
|---|
| | 77 | $oncode = $fcc->getCodeActive(); |
|---|
| | 78 | unset($fcc); |
|---|
| | 79 | |
|---|
| | 80 | if ($oncode) { |
|---|
| | 81 | $ext->add($context, $oncode, '', new ext_answer('')); |
|---|
| | 82 | $ext->add($context, $oncode, '', new ext_wait('1')); |
|---|
| | 83 | $ext->add($context, $oncode, '', new ext_macro('user-callerid')); |
|---|
| | 84 | $ext->add($context, $oncode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'enabled')); |
|---|
| | 85 | $ext->add($context, $oncode, '', new ext_playback('intercom&enabled')); |
|---|
| | 86 | $ext->add($context, $oncode, '', new ext_macro('hangupcall')); |
|---|
| | 87 | |
|---|
| | 88 | $target = '${EXTEN:'.strlen($oncode).'}'; |
|---|
| | 89 | $oncode = "_".$oncode."."; |
|---|
| | 90 | $ext->add($context, $oncode, '', new ext_answer('')); |
|---|
| | 91 | $ext->add($context, $oncode, '', new ext_wait('1')); |
|---|
| | 92 | $ext->add($context, $oncode, '', new ext_macro('user-callerid')); |
|---|
| | 93 | $ext->add($context, $oncode, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/intercom/'.$target.')}" = "allow" ]}','unset')); |
|---|
| | 94 | $ext->add($context, $oncode, '', new ext_gotoif('$[${DB_EXISTS(AMPUSER/${EXTEN:3}/device)} != 1]','invaliduser')); |
|---|
| | 95 | $ext->add($context, $oncode, '', new ext_dbput('AMPUSER/${AMPUSER}/intercom/'.$target, 'allow')); |
|---|
| | 96 | $ext->add($context, $oncode, '', new ext_playback('intercom&enabled&for&extension&number')); |
|---|
| | 97 | $ext->add($context, $oncode, '', new ext_saydigits($target)); |
|---|
| | 98 | $ext->add($context, $oncode, '', new ext_macro('hangupcall')); |
|---|
| | 99 | $ext->add($context, $oncode, 'unset', new ext_dbdeltree('AMPUSER/${AMPUSER}/intercom/'.$target)); |
|---|
| | 100 | $ext->add($context, $oncode, '', new ext_playback('intercom&enabled&cancelled&for&extension&number')); |
|---|
| | 101 | $ext->add($context, $oncode, '', new ext_saydigits($target)); |
|---|
| | 102 | $ext->add($context, $oncode, '', new ext_macro('hangupcall')); |
|---|
| | 103 | $ext->add($context, $oncode, 'invaliduser', new ext_playback('extension&number')); |
|---|
| | 104 | $ext->add($context, $oncode, '', new ext_saydigits($target)); |
|---|
| | 105 | $ext->add($context, $oncode, '', new ext_playback('is&invalid')); |
|---|
| | 106 | $ext->add($context, $oncode, '', new ext_macro('hangupcall')); |
|---|
| | 107 | } |
|---|
| 64 | | $fcc = new featurecode('paging', 'intercom-off'); |
|---|
| 65 | | $offcode = $fcc->getCodeActive(); |
|---|
| 66 | | unset($fcc); |
|---|
| 67 | | |
|---|
| 68 | | if ($offcode) { |
|---|
| 69 | | $ext->add('ext-intercom-users', $offcode, '', new ext_answer('')); |
|---|
| 70 | | $ext->add('ext-intercom-users', $offcode, '', new ext_wait('1')); |
|---|
| 71 | | $ext->add('ext-intercom-users', $offcode, '', new ext_macro('user-callerid')); |
|---|
| 72 | | $ext->add('ext-intercom-users', $offcode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'disabled')); |
|---|
| 73 | | $ext->add('ext-intercom-users', $offcode, '', new ext_playback('intercom&disabled')); |
|---|
| 74 | | $ext->add('ext-intercom-users', $offcode, '', new ext_macro('hangupcall')); |
|---|
| 75 | | } |
|---|
| | 109 | $fcc = new featurecode('paging', 'intercom-off'); |
|---|
| | 110 | $offcode = $fcc->getCodeActive(); |
|---|
| | 111 | unset($fcc); |
|---|
| | 112 | |
|---|
| | 113 | if ($offcode) { |
|---|
| | 114 | $ext->add($context, $offcode, '', new ext_answer('')); |
|---|
| | 115 | $ext->add($context, $offcode, '', new ext_wait('1')); |
|---|
| | 116 | $ext->add($context, $offcode, '', new ext_macro('user-callerid')); |
|---|
| | 117 | $ext->add($context, $offcode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'disabled')); |
|---|
| | 118 | $ext->add($context, $offcode, '', new ext_playback('intercom&disabled')); |
|---|
| | 119 | $ext->add($context, $offcode, '', new ext_macro('hangupcall')); |
|---|
| | 120 | |
|---|
| | 121 | $target = '${EXTEN:'.strlen($offcode).'}'; |
|---|
| | 122 | $offcode = "_".$offcode."."; |
|---|
| | 123 | $ext->add($context, $offcode, '', new ext_answer('')); |
|---|
| | 124 | $ext->add($context, $offcode, '', new ext_wait('1')); |
|---|
| | 125 | $ext->add($context, $offcode, '', new ext_macro('user-callerid')); |
|---|
| | 126 | $ext->add($context, $offcode, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/intercom/'.$target.')}" = "deny" ]}','unset2')); |
|---|
| | 127 | $ext->add($context, $offcode, '', new ext_gotoif('$[${DB_EXISTS(AMPUSER/${EXTEN:3}/device)} != 1]','invaliduser2')); |
|---|
| | 128 | $ext->add($context, $offcode, '', new ext_dbput('AMPUSER/${AMPUSER}/intercom/'.$target, 'deny')); |
|---|
| | 129 | $ext->add($context, $offcode, '', new ext_playback('intercom&disabled&for&extension&number')); |
|---|
| | 130 | $ext->add($context, $offcode, '', new ext_saydigits($target)); |
|---|
| | 131 | $ext->add($context, $offcode, '', new ext_macro('hangupcall')); |
|---|
| | 132 | $ext->add($context, $offcode, 'unset2', new ext_dbdeltree('AMPUSER/${AMPUSER}/intercom/'.$target)); |
|---|
| | 133 | $ext->add($context, $offcode, '', new ext_playback('intercom&disabled&cancelled&for&extension&number')); |
|---|
| | 134 | $ext->add($context, $offcode, '', new ext_saydigits($target)); |
|---|
| | 135 | $ext->add($context, $offcode, '', new ext_macro('hangupcall')); |
|---|
| | 136 | $ext->add($context, $offcode, 'invaliduser2', new ext_playback('extension&number')); |
|---|
| | 137 | $ext->add($context, $offcode, '', new ext_saydigits($target)); |
|---|
| | 138 | $ext->add($context, $offcode, '', new ext_playback('is&invalid')); |
|---|
| | 139 | $ext->add($context, $offcode, '', new ext_macro('hangupcall')); |
|---|
| 78 | | // Get a list of all the phones used for paging |
|---|
| 79 | | $sql = "SELECT DISTINCT ext FROM paging_groups"; |
|---|
| 80 | | $results = $db->getAll($sql); |
|---|
| 81 | | if (!isset($results[0][0])) { |
|---|
| 82 | | // There are no phones here, no paging support, lets give up now. |
|---|
| 83 | | return 0; |
|---|
| 84 | | } |
|---|
| 85 | | // We have paging support. |
|---|
| 86 | | $ext->addInclude('from-internal-additional','ext-paging'); |
|---|
| 87 | | // Lets give all the phones their PAGExxx lines. |
|---|
| 88 | | // TODO: Support for specific phones configurations |
|---|
| 89 | | foreach ($results as $grouparr) { |
|---|
| 90 | | $skipheaders = false; |
|---|
| 91 | | $xtn=trim($grouparr[0]); |
|---|
| 92 | | if (strtoupper(substr($xtn,-1)) == "X") { |
|---|
| 93 | | // hack for allowing no SIP headers |
|---|
| 94 | | //TODO : replace this with DevicesTakeTwo stuff |
|---|
| 95 | | $xtn = rtrim($xtn,"xX"); |
|---|
| 96 | | $skipheaders = true; |
|---|
| 97 | | } |
|---|
| | 142 | /* Create macro-autoanswer that will try to intelligently set the |
|---|
| | 143 | required parameters to handle paging. Eventually it will use |
|---|
| | 144 | known device information. |
|---|
| | 145 | |
|---|
| | 146 | This macro does the following: |
|---|
| | 147 | |
|---|
| | 148 | Input: FreePBX Device number to be called requiring autoanswer |
|---|
| | 149 | Output: ${DIAL} Channel Variable with the dial string to be called |
|---|
| | 150 | Appropriate SIP headers added |
|---|
| | 151 | Other special requirements that may be custom for this device |
|---|
| | 152 | |
|---|
| | 153 | 1. Set ${DIAL} to the device's dial string |
|---|
| | 154 | 2. If there is a device specific macro defined in the DEVICE's object |
|---|
| | 155 | (DEVICE/<devicenum>/autoanswer/macro) then execute that macro and end |
|---|
| | 156 | 3. Set prepare defaults for Alert-Info and Call-Info headers and |
|---|
| | 157 | SIP_URI_OPTIONS |
|---|
| | 158 | 4. Try to identify and endpoints by their useragents that may need known |
|---|
| | 159 | changes and make those changes. |
|---|
| | 160 | 5. Set the variables and end |
|---|
| | 161 | |
|---|
| | 162 | This macro is called for intercoming and paging to try and enable the |
|---|
| | 163 | target device to auto-answer. Devices with special needs can be handled |
|---|
| | 164 | with the device specific macro. For example, if you have a device that |
|---|
| | 165 | can not auto-answer except by specifically configuring a line key on |
|---|
| | 166 | the device that always answers, you could use a device specific macro |
|---|
| | 167 | to change the dialstring. If you had a set of such devices, you could |
|---|
| | 168 | standardize on the device numbers (e.g. nnnn for normal calls and 2nnnn |
|---|
| | 169 | for auto-answer calls). You could then create a general purpose macro |
|---|
| | 170 | to modify the dial string accordingly. Provisioning tools will be able |
|---|
| | 171 | to take advantage of setting and creating such an ability. |
|---|
| | 172 | */ |
|---|
| | 173 | |
|---|
| | 174 | $macro = 'macro-autoanswer'; |
|---|
| | 175 | $ext->add($macro, "s", '', new ext_setvar('DIAL', '${DB(DEVICE/${ARG1}/dial)}')); |
|---|
| | 176 | $ext->add($macro, "s", '', new ext_gotoif('$["${DB(DEVICE/${ARG1}/autoanswer/macro)}" != "" ]', 'macro')); |
|---|
| | 177 | $ext->add($macro, "s", '', new ext_setvar('phone', '${SIPPEER(${CUT(DIAL,/,2)}:useragent)}')); |
|---|
| | 178 | $ext->add($macro, "s", '', new ext_setvar('ALERTINFO', 'Alert-Info: Ring Answer')); |
|---|
| | 179 | $ext->add($macro, "s", '', new ext_setvar('CALLINFO', 'Call-Info: \;answer-after=0')); |
|---|
| | 180 | $ext->add($macro, "s", '', new ext_setvar('SIPURI', 'intercom=true')); |
|---|
| | 181 | |
|---|
| | 182 | // Defaults are setup, now make specific adjustments for detected phones |
|---|
| | 183 | // |
|---|
| | 184 | $ext->add($macro, "s", '', new ext_execif('$["${phone:0:5}" = "Mitel"]', 'Set','CALLINFO=Call-Info: <sip:broadworks.net>\;answer-after=0')); |
|---|
| | 185 | $ext->add($macro, "s", '', new ext_execif('$["${phone:0:4}" = "snom"]', 'Set','CALLINFO=Call-Info: <sip:broadworks.net>\;answer-after=0')); |
|---|
| | 186 | $ext->add($macro, "s", '', new ext_execif('$["${phone:0:6}" = "Aastra"]', 'Set','ALERTINFO=Alert-Info: \;info=alert-autoanswer')); |
|---|
| | 187 | $ext->add($macro, "s", '', new ext_execif('$["${phone:0:6}" = "Aastra"]', 'Set','CALLINFO=')); |
|---|
| | 188 | |
|---|
| | 189 | // Now any adjustments have been made, set the headers and done |
|---|
| | 190 | // |
|---|
| | 191 | $ext->add($macro, "s", '', new ext_execif('$["${ALERTINFO}" != ""]', 'SipAddHeader','${ALERTINFO}')); |
|---|
| | 192 | $ext->add($macro, "s", '', new ext_execif('$["${CALLINFO}" != ""]', 'SipAddHeader','${CALLINFO}')); |
|---|
| | 193 | $ext->add($macro, "s", '', new ext_execif('$["${SIPURI}" != ""]', 'Set','__SIP_URI_OPTIONS=${SIPURI}')); |
|---|
| | 194 | $ext->add($macro, "s", 'macro', new ext_macro('${DB(DEVICE/${ARG1}/autoanswer/macro)}','${ARG1}'), 'n',2); |
|---|
| | 195 | |
|---|
| | 196 | |
|---|
| | 197 | |
|---|
| | 198 | $ext->addInclude('from-internal-additional',$extpaging); |
|---|
| | 199 | // Create the paging context that is used in the paging application for each phone to auto-answer |
|---|
| 99 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${AMPUSER} = '.$xtn.' ]','skipself')); |
|---|
| 100 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${FORCE_PAGE} != 1 ]','AVAIL')); |
|---|
| 101 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('AVAILSTATUS', 'not checked')); |
|---|
| 102 | | $ext->add('ext-paging', "PAGE${xtn}", '', new ext_goto('SKIPCHECK')); |
|---|
| 103 | | $ext->add('ext-paging', "PAGE${xtn}", 'AVAIL', new ext_chanisavail('${DB(DEVICE/'.$xtn.'/dial)}', 'js')); |
|---|
| 104 | | $ext->add('ext-paging', "PAGE${xtn}", 'SKIPCHECK', new ext_noop('Seems to be available (state = ${AVAILSTATUS}')); |
|---|
| | 201 | $ext->add($extpaging, "_PAGE.", '', new ext_gotoif('$[ ${AMPUSER} = ${EXTEN:4} ]','skipself')); |
|---|
| | 202 | $ext->add($extpaging, "_PAGE.", '', new ext_gotoif('$[ ${FORCE_PAGE} != 1 ]','AVAIL')); |
|---|
| | 203 | $ext->add($extpaging, "_PAGE.", '', new ext_setvar('AVAILSTATUS', 'not checked')); |
|---|
| | 204 | $ext->add($extpaging, "_PAGE.", '', new ext_goto('SKIPCHECK')); |
|---|
| | 205 | $ext->add($extpaging, "_PAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:4}/dial)}', 'js')); |
|---|
| | 206 | $ext->add($extpaging, "_PAGE.", 'SKIPCHECK', new ext_noop('Seems to be available (state = ${AVAILSTATUS}')); |
|---|