Esempio n. 1
0
function fax_get_config($engine)
{
    global $version;
    global $ext;
    global $amp_conf;
    global $core_conf;
    $ast_ge_11 = version_compare($version, '11', 'ge');
    $ast_ge_10 = version_compare($version, '10', 'ge');
    $ast_lt_18 = version_compare($version, '1.8', 'lt');
    $ast_ge_16 = version_compare($version, '1.6', 'ge');
    $fax = fax_detect($version);
    if ($fax['module'] && ($ast_lt_18 || $fax['ffa'] || $fax['spandsp'])) {
        //dont continue unless we have a fax module in asterisk
        $t38_fb = $ast_ge_16 ? ',f' : '';
        $context = 'ext-fax';
        $dests = fax_get_destinations();
        if ($dests) {
            foreach ($dests as $row) {
                $exten = $row['user'];
                $ext->add($context, $exten, '', new ext_set('FAX_FOR', $row['name'] . ' (' . $row['user'] . ')'));
                $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ${FAX_FOR}, From: ${CALLERID(all)}'));
                $ext->add($context, $exten, '', new ext_set('FAX_ATTACH_FORMAT', $row['faxattachformat']));
                $ext->add($context, $exten, '', new ext_set('FAX_RX_EMAIL', $row['faxemail']));
                $ext->add($context, $exten, 'receivefax', new ext_goto('receivefax', 's'));
            }
        }
        /*
          FAX Failures are not handled well as of this coding in by ReceiveFAX. If there is a license available then it provides
          information. If not, nothing is provided. FAXSTATUS is supported in 1.4 to handle legacy with RxFax(). In order to create
          dialplan to try and handle all cases, we use FAXSTATUS and set it ourselves as needed. It appears that if a fax fails with
          ReceiveFAX we can always continue execution and if it succeeds, then execution goes to hangup. So using that information
          we try to trap and report on all cases.
        */
        $exten = 's';
        $ext->add($context, $exten, '', new ext_macro('user-callerid'));
        // $cmd,n,Macro(user-callerid)
        $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}'));
        $ext->add($context, $exten, 'receivefax', new ext_stopplaytones(''));
        switch ($fax['module']) {
            case 'app_rxfax':
                $ext->add($context, $exten, '', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif'));
                //receive fax, then email it on
                break;
            case 'app_fax':
                // $fax['receivefax'] should be rxfax or receivefax, it could be none in which case we don't know. We'll just make it
                // ReceiveFAX in that case since it will fail anyhow.
                if ($fax['receivefax'] == 'rxfax') {
                    $ext->add($context, $exten, '', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif'));
                    //receive fax, then email it on
                } elseif ($fax['receivefax'] == 'receivefax') {
                    $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                    //receive fax, then email it on
                } else {
                    $ext->add($context, $exten, '', new ext_noop('ERROR: NO Receive FAX application detected, putting in dialplan for ReceiveFAX as default'));
                    $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                    //receive fax, then email it on
                    $ext->add($context, $exten, '', new ext_execif('$["${FAXSTATUS}" = ""]', 'Set', 'FAXSTATUS=${IF($["${FAXOPT(error)}" = ""]?"FAILED LICENSE EXCEEDED":"FAILED FAXOPT: error: ${FAXOPT(error)} status: ${FAXOPT(status)} statusstr: ${FAXOPT(statusstr)}")}'));
                }
                break;
            case 'res_fax':
                $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                //receive fax, then email it on
                if ($ast_ge_16) {
                    if ($fax['ffa']) {
                        $ext->add($context, $exten, '', new ext_execif('$["${FAXSTATUS}"="" | "${FAXSTATUS}" = "FAILED" & "${FAXERROR}" = "INIT_ERROR"]', 'Set', 'FAXSTATUS=FAILED LICENSE MAY BE EXCEEDED check log errors'));
                    }
                    $ext->add($context, $exten, '', new ext_execif('$["${FAXSTATUS:0:6}"="FAILED" && "${FAXERROR}"!="INIT_ERROR"]', 'Set', 'FAXSTATUS="FAILED: error: ${FAXERROR} statusstr: ${FAXOPT(statusstr)}"'));
                } else {
                    // Some versions or settings appear to have successful completions continue, so check status and goto hangup code
                    if ($fax['ffa']) {
                        $ext->add($context, $exten, '', new ext_execif('$["${FAXOPT(error)}"=""]', 'Set', 'FAXSTATUS=FAILED LICENSE MAY BE EXCEEDED'));
                    }
                    $ext->add($context, $exten, '', new ext_execif('$["${FAXOPT(error)}"!="" && "${FAXOPT(error)}"!="NO_ERROR"]', 'Set', 'FAXSTATUS="FAILED FAXOPT: error: ${FAXOPT(error)} status: ${FAXOPT(status)} statusstr: ${FAXOPT(statusstr)}"'));
                }
                $ext->add($context, $exten, '', new ext_hangup());
                break;
            default:
                // unknown
                $ext->add($context, $exten, '', new ext_noop('No Known FAX Technology installed to receive a fax, aborting'));
                $ext->add($context, $exten, '', new ext_set('FAXSTATUS', 'FAILED No Known Fax Reception Apps available to process'));
                $ext->add($context, $exten, '', new ext_hangup());
        }
        $exten = 'h';
        // if there is a file there, mail it even if we failed:
        $ext->add($context, $exten, '', new ext_gotoif('$[${STAT(e,${ASTSPOOLDIR}/fax/${UNIQUEID}.tif)} = 0]', 'failed'));
        $ext->add($context, $exten, '', new ext_noop_trace('PROCESSING FAX with status: [${FAXSTATUS}] for: [${FAX_RX_EMAIL}], From: [${CALLERID(all)}]'));
        $ext->add($context, $exten, 'process', new ext_gotoif('$[${LEN(${FAX_RX_EMAIL})} = 0]', 'noemail'));
        //delete is a variable so that other modules can prevent it should then need to prosses the file further
        $ext->add($context, $exten, 'delete_opt', new ext_set('DELETE_AFTER_SEND', 'true'));
        //strreplace wasn't put into asterisk until 10, so fallback to replace to older asterisk versions
        if ($ast_ge_10) {
            $ext->add($context, $exten, '', new ext_system('${ASTVARLIBDIR}/bin/fax2mail.php --remotestationid "${FAXOPT(remotestationid)}" --to "${FAX_RX_EMAIL}" --dest "${FROM_DID}" --callerid \'${STRREPLACE(CALLERID(all),\',\\\\\')}\' --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif --exten "${FAX_FOR}" --delete "${DELETE_AFTER_SEND}" --attachformat "${FAX_ATTACH_FORMAT}"'));
        } else {
            $ext->add($context, $exten, '', new ext_system('${ASTVARLIBDIR}/bin/fax2mail.php --remotestationid "${FAXOPT(remotestationid)}" --to "${FAX_RX_EMAIL}" --dest "${FROM_DID}" --callerid \'${REPLACE(CALLERID(all),\', )}\' --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif --exten "${FAX_FOR}" --delete "${DELETE_AFTER_SEND}" --attachformat "${FAX_ATTACH_FORMAT}"'));
        }
        $ext->add($context, $exten, 'end', new ext_macro('hangupcall'));
        $ext->add($context, $exten, 'noemail', new ext_noop('ERROR: No Email Address to send FAX: status: [${FAXSTATUS}],  From: [${CALLERID(all)}]'));
        $ext->add($context, $exten, '', new ext_macro('hangupcall'));
        $ext->add($context, $exten, 'failed', new ext_noop('FAX ${FAXSTATUS} for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}'), 'process', 101);
        $ext->add($context, $exten, '', new ext_macro('hangupcall'));
        $modulename = 'fax';
        $fcc = new featurecode($modulename, 'simu_fax');
        $fc_simu_fax = $fcc->getCodeActive();
        unset($fcc);
        if ($fc_simu_fax != '') {
            $default_address = sql('SELECT value FROM fax_details WHERE `key` = \'FAX_RX_EMAIL\'', 'getRow');
            $ext->addInclude('from-internal-additional', 'app-fax');
            // Add the include from from-internal
            $ext->add('app-fax', $fc_simu_fax, '', new ext_setvar('FAX_RX_EMAIL', $default_address[0]));
            $ext->add('app-fax', $fc_simu_fax, '', new ext_goto('1', 's', 'ext-fax'));
            $ext->add('app-fax', 'h', '', new ext_macro('hangupcall'));
        }
        // This is not really needed but is put here in case some ever accidently switches the order below when
        // checking for this setting since $fax['module'] will be set there and the 2nd part never checked
        $fax_settings['force_detection'] = 'yes';
    } else {
        $fax_settings = fax_get_settings();
    }
    if ($fax['module'] && ($ast_lt_18 || $fax['ffa'] || $fax['spandsp']) || $fax_settings['force_detection'] == 'yes') {
        if ($ast_ge_11 && isset($core_conf) && is_a($core_conf, "core_conf")) {
            $core_conf->addSipGeneral('faxdetect', 'no');
        } else {
            if ($ast_ge_16 && isset($core_conf) && is_a($core_conf, "core_conf")) {
                $core_conf->addSipGeneral('faxdetect', 'yes');
            }
        }
        $ext->add('ext-did-0001', 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
        $ext->add('ext-did-0002', 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
        // Add fax extension to ivr and announcement as inbound controle may be passed quickly to them and still detection is desired
        if (function_exists('ivr_list')) {
            $ivrlist = ivr_list();
            if (is_array($ivrlist)) {
                foreach ($ivrlist as $item) {
                    $ext->add("ivr-" . $item['ivr_id'], 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
                }
            }
        }
        if (function_exists('announcement_list')) {
            foreach (announcement_list() as $row) {
                $ext->add('app-announcement-' . $row['announcement_id'], 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
            }
        }
    }
}
Esempio n. 2
0
function ivr_sidebar($id)
{
    ?>
        <div class="rnav"><ul>
        <li><a id="<?php 
    echo empty($id) ? 'current' : 'nul';
    ?>
" href="config.php?display=ivr&amp;action=add"><?php 
    echo _("Add IVR");
    ?>
</a></li>
<?php 
    $ivr_results = ivr_list();
    if (isset($ivr_results)) {
        foreach ($ivr_results as $tresult) {
            echo "<li><a id=\"" . ($id == $tresult['ivr_id'] ? 'current' : 'nul') . "\" href=\"config.php?display=ivr";
            echo "&amp;action=edit&amp;id={$tresult['ivr_id']}\">{$tresult['displayname']}</a></li>\n";
        }
    }
    echo "</ul></div>\n";
}
Esempio n. 3
0
function ivr_get_config($engine)
{
    global $ext;
    switch ($engine) {
        case "asterisk":
            $ddial_contexts = array();
            $ivrlist = ivr_list();
            if (is_array($ivrlist)) {
                foreach ($ivrlist as $item) {
                    $id = "ivr-" . $item['ivr_id'];
                    $details = ivr_get_details($item['ivr_id']);
                    $announcement_id = isset($details['announcement_id']) ? $details['announcement_id'] : '';
                    $timeout_id = isset($details['timeout_id']) ? $details['timeout_id'] : '';
                    $invalid_id = isset($details['invalid_id']) ? $details['invalid_id'] : '';
                    $loops = isset($details['loops']) ? $details['loops'] : '2';
                    $retvm = isset($details['retvm']) ? $details['retvm'] : '';
                    if (!empty($details['enable_directdial'])) {
                        if ($details['enable_directdial'] == 'CHECKED') {
                            $ext->addInclude($id, 'from-did-direct-ivr');
                            //generated in core module
                        } else {
                            $ext->addInclude($id, 'from-ivr-directory-' . $details['enable_directdial']);
                            $ddial_contexts[$details['enable_directdial']] = true;
                        }
                    }
                    // I'm not sure I like the ability of people to send voicemail from the IVR.
                    // Make it a config option, possibly?
                    // $ext->addInclude($item[0],'app-messagecenter');
                    if (!empty($details['enable_directory'])) {
                        $ext->addInclude($id, 'app-directory');
                        $dir = featurecodes_getFeatureCode('infoservices', 'directory');
                        $ext->add($id, '#', '', new ext_dbdel('${BLKVM_OVERRIDE}'));
                        $ext->add($id, '#', '', new ext_setvar('__NODEST', ''));
                        $ext->add($id, '#', '', new ext_goto("app-directory,{$dir},1"));
                    }
                    $ext->add($id, 'h', '', new ext_hangup(''));
                    if ($announcement_id) {
                        $announcement_msg = recordings_get_file($announcement_id);
                        $ext->add($id, 's', '', new ext_setvar('MSG', "{$announcement_msg}"));
                    } else {
                        $ext->add($id, 's', '', new ext_setvar('MSG', ""));
                    }
                    $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0));
                    $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext']));
                    $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}'));
                    $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
                    $ext->add($id, 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]', 'begin'));
                    $ext->add($id, 's', '', new ext_answer(''));
                    $ext->add($id, 's', '', new ext_wait('1'));
                    $ext->add($id, 's', 'begin', new ext_digittimeout(3));
                    $ext->add($id, 's', '', new ext_responsetimeout($details['timeout']));
                    if ($retvm) {
                        $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN'));
                    } else {
                        $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', ''));
                    }
                    $ext->add($id, 's', '', new ext_execif('$["${MSG}" != ""]', 'Background', '${MSG}'));
                    $ext->add($id, 's', '', new ext_waitexten());
                    $ext->add($id, 'hang', '', new ext_playback('vm-goodbye'));
                    $ext->add($id, 'hang', '', new ext_hangup(''));
                    $default_t = true;
                    // Actually add the IVR commands now.
                    $dests = ivr_get_dests($item['ivr_id']);
                    $timeout = false;
                    $invalid = false;
                    $addloop = false;
                    if (!empty($dests)) {
                        foreach ($dests as $dest) {
                            if ($dest['selection'] == 't' && empty($details['alt_timeout'])) {
                                $timeout = true;
                            } elseif ($dest['selection'] == 'i' && empty($details['alt_invalid'])) {
                                $invalid = true;
                            } elseif ($dest['selection'] == 't' && !empty($details['alt_timeout'])) {
                                $timeout = true;
                                if ($timeout_id) {
                                    $timeout_msg = recordings_get_file($timeout_id);
                                    $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$timeout_msg}"));
                                }
                                $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin'));
                            } elseif ($dest['selection'] == 'i' && !empty($details['alt_invalid'])) {
                                $invalid = true;
                                $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                                if ($invalid_id) {
                                    $invalid_msg = recordings_get_file($invalid_id);
                                    $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$invalid_msg}"));
                                } else {
                                    $ext->add($id, $dest['selection'], '', new ext_execif('$[${LOOPCOUNT} <= ' . $loops . ']', 'Playback', 'invalid'));
                                }
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin'));
                            }
                            $ext->add($id, $dest['selection'], '', new ext_dbdel('${BLKVM_OVERRIDE}'));
                            $ext->add($id, $dest['selection'], '', new ext_setvar('__NODEST', ''));
                            // if the goto goes loops back to this ivr, then don't go to the begining or it will break the return to previous ivr info
                            //
                            $dest_context = trim(strtok($dest['dest'], ",|"));
                            if ($dest_context == $id) {
                                $dest['dest'] = $id . ',s,begin';
                            }
                            if ($dest['ivr_ret']) {
                                $ext->add($id, $dest['selection'], '', new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]', $dest['dest'] . ':${IVR_CONTEXT_${CONTEXT}},return,1'));
                            } else {
                                $ext->add($id, $dest['selection'], '', new ext_goto($dest['dest']));
                            }
                        }
                    }
                    // Apply invalid if required
                    if (!$invalid) {
                        if ($invalid_id) {
                            $invalid_msg = recordings_get_file($invalid_id);
                            $ext->add($id, 'i', '', new ext_setvar('MSG', "{$invalid_msg}"));
                        } else {
                            $ext->add($id, 'i', '', new ext_playback('invalid'));
                        }
                        $ext->add($id, 'i', '', new ext_goto('loop,1'));
                        $addloop = true;
                    }
                    if (!$timeout) {
                        if ($timeout_id) {
                            $timeout_msg = recordings_get_file($timeout_id);
                            $ext->add($id, 't', '', new ext_setvar('MSG', "{$timeout_msg}"));
                        }
                        $ext->add($id, 't', '', new ext_goto('loop,1'));
                        $addloop = true;
                    }
                    if ($addloop) {
                        $ext->add($id, 'loop', '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]'));
                        $ext->add($id, 'loop', '', new ext_gotoif('$[${LOOPCOUNT} > ' . $loops . ']', 'hang,1'));
                        $ext->add($id, 'loop', '', new ext_goto($id . ',s,begin'));
                        // these need to be reset or inheritance problems makes them go away in some conditions and infinite inheritance creates other problems
                        // reset the message including blanking it if set by a sub-ivr
                        $announcement_msg = $announcement_id ? $announcement_msg : '';
                        $ext->add($id, 'return', '', new ext_setvar('MSG', "{$announcement_msg}"));
                        $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}'));
                        $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}'));
                        $ext->add($id, 'return', '', new ext_goto($id . ',s,begin'));
                    }
                }
                if (!empty($ddial_contexts)) {
                    global $version;
                    $ast_lt_14 = version_compare($version, '1.4', 'lt');
                    foreach (array_keys($ddial_contexts) as $dir_id) {
                        $context = 'from-ivr-directory-' . $dir_id;
                        $entries = function_exists('directory_get_dir_entries') ? directory_get_dir_entries($dir_id) : array();
                        foreach ($entries as $dstring) {
                            $exten = $dstring['dial'] == '' ? $dstring['foreign_id'] : $dstring['dial'];
                            if ($exten == '' || $exten == 'custom') {
                                continue;
                            }
                            if ($ast_lt_14) {
                                $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'dbDel', '${BLKVM_OVERRIDE}'));
                            } else {
                                $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'Noop', 'Deleting: ${BLKVM_OVERRIDE}: ${DB_DELETE(${BLKVM_OVERRIDE})}'));
                            }
                            $ext->add($context, $exten, '', new ext_setvar('__NODEST', ''));
                            $ext->add($context, $exten, '', new ext_goto('1', $exten, 'from-internal'));
                        }
                    }
                }
            }
            break;
    }
}
Esempio n. 4
0
function queues_check_compoundrecordings()
{
    global $db;
    $compound_recordings = array();
    $sql = "SELECT extension, descr, agentannounce_id, ivr_id FROM queues_config WHERE (ivr_id != 'none' AND ivr_id != '') OR agentannounce_id != ''";
    $results = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
    if (function_exists('ivr_list')) {
        $ivr_details = ivr_list();
        foreach ($ivr_details as $item) {
            $ivr_hash[$item['ivr_id']] = $item;
        }
        $check_ivr = true;
    } else {
        $check_ivr = false;
    }
    foreach ($results as $result) {
        $agentannounce = $result['agentannounce_id'] ? recordings_get_file($result['agentannounce_id']) : '';
        if (strpos($agentannounce, "&") !== false) {
            $compound_recordings[] = array('extension' => $result['extension'], 'descr' => $result['descr'], 'error' => _("Agent Announce Msg"));
        }
        if ($result['ivr_id'] != 'none' && $result['ivr_id'] != '' && $check_ivr) {
            $id = $ivr_hash[$result['ivr_id']]['announcement_id'];
            $announce = $id ? recordings_get_file($id) : '';
            if (strpos($announce, "&") !== false) {
                $compound_recordings[] = array('extension' => $result['extension'], 'descr' => $result['descr'], 'error' => sprintf(_("IVR Announce: %s"), $ivr_hash[$result['ivr_id']]['displayname']));
            }
        }
    }
    return $compound_recordings;
}
Esempio n. 5
0
        echo _("You can optionally present an existing IVR as a 'break out' menu.<br><br>This IVR must only contain single-digit 'dialed options'. The Recording set for the IVR will be played at intervals specified in 'Repeat Frequency', below.");
        ?>
</span></a></td>
		<td>
			<select name="announcemenu" tabindex="<?php 
        echo ++$tabindex;
        ?>
">
			<?php 
        // setting this will set the context= option
        $default = isset($announcemenu) ? $announcemenu : "none";
        echo '<option value=none ' . ($default == "none" ? 'SELECTED' : '') . '>' . _("None") . '</option>';
        //query for exisiting aa_N contexts
        //
        // If a previous bogus IVR was listed, we will leave it in with an error but will no longer show such IVRs as valid options.
        $unique_aas = ivr_list();
        $compound_recordings = false;
        $is_error = false;
        if (isset($unique_aas)) {
            foreach ($unique_aas as $unique_aa) {
                $menu_id = $unique_aa['ivr_id'];
                $menu_name = $unique_aa['displayname'];
                $unique_aa['announcement'] = recordings_get_file($unique_aa['announcement_id']);
                if (strpos($unique_aa['announcement'], "&") === false) {
                    echo '<option value="' . $menu_id . '" ' . ($default == $menu_id ? 'SELECTED' : '') . '>' . ($menu_name ? $menu_name : _("Menu ID ") . $menu_id) . "</option>\n";
                } else {
                    $compound_recordings = true;
                    if ($menu_id == $default) {
                        echo '<option style="color:red" value="' . $menu_id . '" ' . ($default == $menu_id ? 'SELECTED' : '') . '>' . ($menu_name ? $menu_name : _("Menu ID ") . $menu_id) . " (**)</option>\n";
                        $is_error = true;
                    }
Esempio n. 6
0
function fax_get_config($engine)
{
    global $version;
    global $ext;
    global $amp_conf;
    global $core_conf;
    $fax = fax_detect($version);
    if ($fax['module']) {
        //dont continue unless we have a fax module in asterisk
        $t38_fb = version_compare($version, '1.6', 'ge') ? ',f' : '';
        $context = 'ext-fax';
        $dests = fax_get_destinations();
        $sender_address = sql('SELECT value FROM fax_details WHERE `key` = \'sender_address\'', 'getRow');
        if ($dests) {
            foreach ($dests as $row) {
                $exten = $row['user'];
                $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ' . $row['name'] . ' (' . $row['user'] . '), From: ${CALLERID(all)}'));
                $ext->add($context, $exten, '', new ext_set('FAX_RX_EMAIL', $row['faxemail']));
                $ext->add($context, $exten, 'receivefax', new ext_goto('receivefax', 's'));
            }
        }
        /*
          FAX Failures are not handled well as of this coding in by ReceiveFAX. If there is a license available then it provides
          information. If not, nothing is provided. FAXSTATUS is supported in 1.4 to handle legacy with RxFax(). In order to create
          dialplan to try and handle all cases, we use FAXSTATUS and set it ourselves as needed. It appears that if a fax fails with
          ReceiveFAX we can always continue execution and if it succeeds, then execution goes to hangup. So using that information
          we try to trap and report on all cases.
        */
        $exten = 's';
        $ext->add($context, $exten, '', new ext_macro('user-callerid'));
        // $cmd,n,Macro(user-callerid)
        $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}'));
        $ext->add($context, $exten, 'receivefax', new ext_stopplaytones(''));
        switch ($fax['module']) {
            case 'app_rxfax':
                $ext->add($context, $exten, '', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif'));
                //recive fax, then email it on
                break;
            case 'app_fax':
                // $fax['receivefax'] should be rxfax or receivefax, it could be none in which case we don't know. We'll just make it
                // ReceiveFAX in that case since it will fail anyhow.
                if ($fax['receivefax'] == 'rxfax') {
                    $ext->add($context, $exten, '', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif'));
                    //recive fax, then email it on
                } elseif ($fax['receivefax'] == 'receivefax') {
                    $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                    //recive fax, then email it on
                } else {
                    $ext->add($context, $exten, '', new ext_noop('ERROR: NO Receive FAX application detected, putting in dialplan for ReceiveFAX as default'));
                    $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                    //recive fax, then email it on
                    $ext->add($context, $exten, '', new ext_execif('$["${FAXSTATUS}" = ""]', 'Set', 'FAXSTATUS=${IF($["${FAXOPT(error)}" = ""]?"FAILED LICENSE EXCEEDED":"FAILED FAXOPT: error: ${FAXOPT(error)} status: ${FAXOPT(status)} statusstr: ${FAXOPT(statusstr)}")}'));
                }
                break;
            case 'res_fax':
                $ext->add($context, $exten, '', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif' . $t38_fb));
                //recive fax, then email it on
                // Some versions or settings appear to have successful completions continue, so check status and goto hangup code
                $ext->add($context, $exten, '', new ext_execif('$["${FAXOPT(error)}"=""]', 'Set', 'FAXSTATUS=FAILED LICENSE EXCEEDED'));
                $ext->add($context, $exten, '', new ext_execif('$["${FAXOPT(error)}"!="" && "${FAXOPT(error)}"!="NO_ERROR"]', 'Set', 'FAXSTATUS="FAILED FAXOPT: error: ${FAXOPT(error)} status: ${FAXOPT(status)} statusstr: ${FAXOPT(statusstr)}"'));
                $ext->add($context, $exten, '', new ext_hangup());
                break;
            default:
                // unknown
                $ext->add($context, $exten, '', new ext_noop('No Known FAX Technology installed to receive a fax, aborting'));
                $ext->add($context, $exten, '', new ext_set('FAXSTATUS', 'FAILED No Known Fax Reception Apps available to process'));
                $ext->add($context, $exten, '', new ext_hangup());
        }
        $exten = 'h';
        $ext->add($context, $exten, '', new ext_gotoif('$["${FAXSTATUS:0:6}" = "FAILED"]', 'failed'));
        $ext->add($context, $exten, 'process', new ext_gotoif('$[${LEN(${FAX_RX_EMAIL})} = 0]', 'end'));
        $ext->add($context, $exten, '', new ext_system('${ASTVARLIBDIR}/bin/fax-process.pl --to "${FAX_RX_EMAIL}" --from "' . $sender_address['0'] . '" --dest "${FROM_DID}" --subject "New fax from ${URIENCODE(${CALLERID(name)})} ${URIENCODE(<${CALLERID(number)}>)}" --attachment fax_${URIENCODE(${CALLERID(number)})}.pdf --type application/pdf --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif'));
        $ext->add($context, $exten, 'end', new ext_macro('hangupcall'));
        $ext->add($context, $exten, 'failed', new ext_noop('FAX ${FAXSTATUS} for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}'), 'process', 101);
        $ext->add($context, $exten, '', new ext_macro('hangupcall'));
        //write out res_fax.conf and res_fax_digium.conf
        fax_write_conf();
        $modulename = 'fax';
        $fcc = new featurecode($modulename, 'simu_fax');
        $fc_simu_fax = $fcc->getCodeActive();
        unset($fcc);
        if ($fc_simu_fax != '') {
            $default_address = sql('SELECT value FROM fax_details WHERE `key` = \'FAX_RX_EMAIL\'', 'getRow');
            $ext->addInclude('from-internal-additional', 'app-fax');
            // Add the include from from-internal
            $ext->add('app-fax', $fc_simu_fax, '', new ext_setvar('FAX_RX_EMAIL', $default_address[0]));
            $ext->add('app-fax', $fc_simu_fax, '', new ext_goto('1', 's', 'ext-fax'));
            $ext->add('app-fax', 'h', '', new ext_macro('hangupcall'));
        }
        // This is not really needed but is put here in case some ever accidently switches the order below when
        // checking for this setting since $fax['module'] will be set there and the 2nd part never checked
        $fax_settings['force_detection'] = 'yes';
    } else {
        $fax_settings = fax_get_settings();
    }
    if ($fax['module'] | $fax_settings['force_detection'] == 'yes') {
        //dont continue unless we have a fax module in asterisk
        $ast_ge_16 = version_compare($version, '1.6', 'ge');
        if ($ast_ge_16 && isset($core_conf) && is_a($core_conf, "core_conf")) {
            $core_conf->addSipGeneral('faxdetect', 'yes');
        }
        $ext->add('ext-did-0001', 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
        $ext->add('ext-did-0002', 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
        // Add fax extension to ivr and announcement as inbound controle may be passed quickly to them and still detection is desired
        if (function_exists('ivr_list')) {
            $ivrlist = ivr_list();
            if (is_array($ivrlist)) {
                foreach ($ivrlist as $item) {
                    $ext->add("ivr-" . $item['ivr_id'], 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
                }
            }
        }
        if (function_exists('announcement_list')) {
            foreach (announcement_list() as $row) {
                $ext->add('app-announcement-' . $row['announcement_id'], 'fax', '', new ext_goto('${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)}'));
            }
        }
    }
}