Пример #1
0
function customcontexts_configpageinit($dispnum)
{
    global $currentcomponent;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($extdisplay == '') {
        return true;
    }
    if ($dispnum == 'devices' || $dispnum == 'extensions') {
        $device_info = core_devices_get($extdisplay);
        if (empty($device_info)) {
            return true;
        } else {
            $tech = $device_info['tech'];
            switch ($tech) {
                case 'iax2':
                case 'iax':
                case 'sip':
                case 'dahdi':
                case 'zap':
                    $_REQUEST['tech'] = $tech;
                    $_REQUEST['customcontext'] = $device_info['context'];
                    break;
                default:
                    return true;
            }
        }
    } else {
        return true;
    }
    $contextssel = customcontexts_getcontexts();
    $currentcomponent->addoptlistitem('contextssel', 'from-internal', 'ALLOW ALL (Default)');
    foreach ($contextssel as $val) {
        $currentcomponent->addoptlistitem('contextssel', $val[0], $val[1]);
    }
    $currentcomponent->setoptlistopts('contextssel', 'sort', false);
    switch ($dispnum) {
        case 'devices':
            $currentcomponent->addguifunc('customcontexts_devices_configpageload');
            break;
        case 'extensions':
            $currentcomponent->addguifunc('customcontexts_extensions_configpageload');
            break;
    }
}
Пример #2
0
function core_devices_configpageload()
{
    global $currentcomponent;
    global $amp_conf;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        $currentcomponent->addguielem('_top', new gui_hidden('tech', "virtual"));
        $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Virtual Extension")), 0);
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = '?display=users&skip=0&extdisplay=' . urlencode($deviceInfo['user']);
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', isset($extdisplay) && trim($extdisplay) !== '' ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = $extdisplay ? _("Edit User") : _("Add User");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay), "general");
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false), "general");
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The CallerID name for this device will be set to this description until it is logged into."), '!isUnicodeLetter() || isWhitespace()', $msgInvalidDevDesc, false), "general");
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false), "general");
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false), "general");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID), "advanced");
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID), "advanced");
        }
        $currentcomponent->addguielem('_top', new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem('_top', new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $msgInvalidChannel = _("Please enter the channel for this device");
            $msgConfirmSecret = _("You have not entered a Secret for this device, although this is possible it is generally bad practice to not assign a Secret to a device. Are you sure you want to leave the Secret empty?");
            $msgInvalidSecret = _("Please enter a Secret for this device");
            $secret_validation = '(isEmpty() && !confirm("' . $msgConfirmSecret . '"))';
            if ($amp_conf['DEVICE_STRONG_SECRETS']) {
                $secret_validation .= ' || (!isEmpty() && weakSecret())';
            }
            if ($display == 'extensions') {
                $section = $extdisplay ? _("Edit Extension") : _("Add Extension");
            } else {
                $section = $extdisplay ? _("Edit User") : _("Add User");
            }
            $drivers = FreePBX::Core()->getAllDrivers();
            if (isset($drivers[$devinfo_tech])) {
                $devopts = $drivers[$devinfo_tech]->getDeviceDisplay($display, $deviceInfo, $currentcomponent, $section);
            } else {
                $devopts = array();
            }
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    $devdisable = isset($devoptarr['disable']) ? $devoptarr['disable'] : false;
                    $devonchange = isset($devoptarr['onchange']) ? $devoptarr['onchange'] : '';
                    $prompttext = isset($devoptarr['prompttext']) ? $devoptarr['prompttext'] : $devopt;
                    $hidden = isset($devoptarr['hidden']) ? $devoptarr['hidden'] : false;
                    $type = isset($devoptarr['type']) ? $devoptarr['type'] : (isset($devoptarr['select']) ? 'select' : 'text');
                    $text = isset($devoptarr['text']) ? $devoptarr['text'] : '';
                    $category = isset($devoptarr['category']) ? $devoptarr['category'] : 'advanced';
                    $sec = isset($devoptarr['section']) ? $devoptarr['section'] : $section;
                    $class = isset($devoptarr['class']) ? $devoptarr['class'] : '';
                    $autocomplete = false;
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($sec, new gui_hidden($devopname . "_origional", $devoptcurrent), 4, null, $category);
                        if ($devoptcurrent == '' && empty($extdisplay)) {
                            $devoptcurrent = \FreePBX::Core()->generateSecret();
                        }
                    }
                    if (!$hidden) {
                        // editing to show advanced as well
                        // Added optional selectbox to enable the unsupported misdn module
                        $tooltip = isset($devoptarr['tt']) ? $devoptarr['tt'] : '';
                        if ($type == 'select') {
                            $currentcomponent->addguielem($sec, new gui_selectbox($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable, $class), 4, null, $category);
                        } elseif ($type == 'text') {
                            $currentcomponent->addguielem($sec, new gui_textbox($devopname, $devoptcurrent, $prompttext, $tooltip, $devoptjs, $devoptfailmsg, true, 0, $devdisable, false, $class, $autocomplete), 4, null, $category);
                        } elseif ($type == 'button') {
                            $currentcomponent->addguielem($sec, new gui_button($devopname, $devoptcurrent, $prompttext, $tooltip, $text, $devoptjs, $devdisable, $class), 4, null, $category);
                        } elseif ($type == 'radio') {
                            $currentcomponent->addguielem($sec, new gui_radio($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable, $class, false), 4, null, $category);
                        }
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($sec, new gui_hidden($devopname, $devoptcurrent), 4, null, $category);
                    }
                }
            }
        }
    }
}
Пример #3
0
 public function getDeviceDisplay($display, $deviceInfo, $currentcomponent, $primarySection)
 {
     $section = _("Settings");
     $category = "general";
     $pports = array();
     $techd = $deviceInfo['tech'] == 'sip' ? 'CHAN_SIP' : strtoupper($deviceInfo['tech']);
     $devinfo_tech = $deviceInfo['tech'];
     if ($this->freepbx->Modules->moduleHasMethod("sipsettings", "getBinds")) {
         $out = $this->freepbx->Sipsettings->getBinds();
         if (isset($out[$devinfo_tech])) {
             foreach ($out[$devinfo_tech] as $ip => $data1) {
                 foreach ($data1 as $protocol => $port) {
                     if ($protocol == "ws" || $protocol == "wss") {
                         continue;
                     }
                     // Is this the default port for this protocol?
                     $defaultport = false;
                     if ($protocol == "udp" && $port == 5060) {
                         $defaultport = true;
                     } elseif ($protocol == "tcp" && $port == 5060) {
                         $defaultport = true;
                     } elseif ($protocol == "tls" && $port == 5061) {
                         $defaultport = true;
                     }
                     // If the bind address is 0.0.0.0 (or :: or [::]), we don't need to say
                     // that it's listening on a specific address.
                     if ($ip == "0.0.0.0" || $ip == "::" || ($ip = "[::]")) {
                         if ($defaultport) {
                             $pports[] = sprintf(_("Port %s (%s)"), $port, strtoupper($protocol));
                         } else {
                             $pports[] = sprintf(_("Port %s (%s - this is a <strong>NON STANDARD</strong> port)"), $port, strtoupper($protocol));
                         }
                     } else {
                         if ($defaultport) {
                             $pports[] = sprintf(_("Interface %s, Port %s (%s)"), $ip, $port, strtoupper($protocol));
                         } else {
                             $pports[] = sprintf(_("Interface %s, Port %s (%s - this is a <strong>NON STANDARD</strong> port)"), $ip, $port, strtoupper($protocol));
                         }
                     }
                 }
             }
         }
         if (!$pports) {
             $pport = "(SipSettings Error)";
         } else {
             $pport = join(", ", $pports);
         }
         $display_mode = "advanced";
         $mode = \FreePBX::Config()->get("FPBXOPMODE");
         if (!empty($mode)) {
             $display_mode = $mode;
         }
         if ($display_mode != 'basic') {
             $extrac = !empty($pport) ? sprintf(_('listening on %s'), $pport) : '';
             $device_uses = sprintf(_("This device uses %s technology %s"), "<strong>" . $techd . "</strong>", $extrac);
             $currentcomponent->addguielem($primarySection, new \gui_label('techlabel', '<div class="alert alert-info" role="alert" style="width:100%">' . $device_uses . '</div>'), 1, null, $category);
         }
     } else {
         $currentcomponent->addguielem($primarySection, new \gui_label('techlabel', '<div class="alert alert-danger" role="alert" style="width:100%">' . _("The Asterisk SIP Setting Module is not installed or is disabled. Please install it.") . '</div>'), 1, null, $category);
     }
     // We need to scream loudly if this device is using a channel driver that's disabled.
     if ($devinfo_tech == "pjsip" || $devinfo_tech == "sip") {
         $sipdriver = $this->freepbx->Config->get_conf_setting('ASTSIPDRIVER');
         if ($sipdriver != "both") {
             // OK, one is disabled.
             if ($devinfo_tech == "sip") {
                 $iwant = "chan_sip";
             } else {
                 $iwant = "chan_pjsip";
             }
             if ($iwant != $sipdriver) {
                 // Poot.
                 $err = sprintf(_("<strong>CRITICAL ERROR!</strong> Required Service %s is disabled! This device is unusable!"), strtoupper($iwant));
                 $currentcomponent->addguielem($primarySection, new \gui_label('techerrlabel', $err), 3, null, $category);
             }
         }
     }
     if (!empty($_REQUEST['tech_hardware'])) {
         $tmparr = explode('_', $_REQUEST['tech_hardware']);
         $deviceInfo['tech'] = $tmparr[0];
     } else {
         $tmparr = core_devices_get($_REQUEST['extdisplay']);
         $deviceInfo['tech'] = $tmparr['tech'];
     }
     unset($tmparr);
     $tmparr = array();
     $msgConfirmSecret = _("You have not entered a Secret for this device, although this is possible it is generally bad practice to not assign a Secret to a device. Are you sure you want to leave the Secret empty?");
     $msgInvalidSecret = _("Please enter a Secret for this device");
     $secret_validation = '(isEmpty() && !confirm("' . $msgConfirmSecret . '"))';
     $tt = _("Password (secret) configured for the device. Should be alphanumeric with at least 2 letters and numbers to keep secure.") . ' [secret]';
     $tmparr['secret'] = array('prompttext' => _('Secret'), 'class' => 'password-meter', 'value' => '', 'tt' => $tt, 'level' => 0, 'jsvalidation' => $secret_validation, 'failvalidationmsg' => $msgInvalidSecret, 'category' => $category, 'section' => $primarySection);
     $section = _("Device Options");
     $category = "advanced";
     $sipdriver = $this->freepbx->Config->get_conf_setting('ASTSIPDRIVER');
     $tmparr['sipdriver'] = array('hidden' => true, 'value' => 'chan_' . strtolower($deviceInfo['tech']), 'level' => 0);
     if ($deviceInfo['tech'] == "sip") {
         $mydriver = "CHAN_SIP";
         $otherdriver = "CHAN_PJSIP";
     } else {
         $mydriver = "CHAN_PJSIP";
         $otherdriver = "CHAN_SIP";
     }
     //Inverted Driver, only allow the change if in certain modes
     if (isset($deviceInfo['id'])) {
         $ttt = sprintf(_("Change To %s Driver"), $otherdriver);
         if ($sipdriver == 'both' || $sipdriver == 'chan_sip' && $deviceInfo['tech'] == 'pjsip' || $sipdriver == 'chan_pjsip' && $deviceInfo['tech'] == 'sip') {
             $tt = _("Change the SIP Channel Driver to use {$otherdriver}.");
             $tmparr['changecdriver'] = array('text' => $ttt, 'prompttext' => _('Change SIP Driver'), 'type' => 'button', 'value' => 'button', 'tt' => $tt, 'level' => 1, 'jsvalidation' => "frm_" . $display . "_changeDriver();return false;");
         } else {
             $tt = _("You cannot change to {$otherdriver} as it is not enabled. Please enable {$otherdriver} in Advanced Settings");
             $tmparr['changecdriver'] = array('text' => _("Changing SIP Driver unavailable"), 'prompttext' => $ttt, 'type' => 'button', 'value' => 'button', 'tt' => $tt, 'level' => 1, 'disable' => true);
         }
     }
     if ($mydriver == "CHAN_PJSIP") {
         $select[] = array('value' => 'rfc4733', 'text' => _('RFC 4733'));
         if (version_compare($this->version, '13', 'ge')) {
             $select[] = array('value' => 'auto', 'text' => _('Auto'));
         }
     } else {
         $select[] = array('value' => 'rfc2833', 'text' => _('RFC 2833'));
         $select[] = array('value' => 'auto', 'text' => _('Auto'));
         $select[] = array('value' => 'shortinfo', 'text' => _('SIP INFO (application/dtmf)'));
     }
     unset($tt, $ttt, $mydriver, $otherdriver);
     $select[] = array('value' => 'info', 'text' => _('SIP INFO (application/dtmf-relay)'));
     $select[] = array('value' => 'inband', 'text' => _('In band audio (Not recommended)'));
     $tt = _("The DTMF signaling mode used by this device, usually RFC for most phones.") . ' [dtmfmode]';
     $tmparr['dtmfmode'] = array('prompttext' => _('DTMF Signaling'), 'value' => 'rfc2833', 'tt' => $tt, 'select' => $select, 'level' => 0);
     unset($select);
     $tt = _("Re-Invite policy for this device, see Asterisk documentation for details.") . ' [canreinvite]';
     $select[] = array('value' => 'no', 'text' => _('No'));
     $select[] = array('value' => 'yes', 'text' => _('Yes'));
     $select[] = array('value' => 'nonat', 'text' => 'nonat');
     $select[] = array('value' => 'update', 'text' => 'update');
     $tmparr['canreinvite'] = array('prompttext' => _('Can Reinvite'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_CANREINVITE'), 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
     $tt = _("Asterisk context this device will send calls to. Only change this is you know what you are doing.") . ' [context]';
     $tmparr['context'] = array('prompttext' => _('Context'), 'value' => 'from-internal', 'tt' => $tt, 'level' => 1);
     $tt = _("Host settings for this device, almost always dynamic for endpoints.") . ' [host]';
     $tmparr['host'] = array('prompttext' => _('Host'), 'value' => 'dynamic', 'tt' => $tt, 'level' => 1);
     unset($select);
     $select[] = array('value' => 'no', 'text' => _('No'));
     $select[] = array('value' => 'yes', 'text' => _('Yes'));
     $tt = _("Whether Asterisk should trust the RPID settings from this device. Usually should be yes for CONNECTEDLINE() functionality to work if supported by the endpoint.") . '[trustrpid]';
     $tmparr['trustrpid'] = array('prompttext' => _('Trust RPID'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_TRUSTRPID'), 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
     unset($select);
     $select[] = array('value' => 'no', 'text' => _('No'));
     $select[] = array('value' => 'yes', 'text' => _('Send Remote-Party-ID header'));
     if (version_compare($this->version, '1.8', 'ge')) {
         $select[] = array('value' => 'pai', 'text' => _('Send P-Asserted-Identity header'));
     }
     $tt = _("Whether Asterisk should send RPID (or PAI) info to the device. Usually should be enabled to the settings used by your device for CONNECTEDLINE() functionality to work if supported by the endpoint.") . '[sendrpid]';
     $tmparr['sendrpid'] = array('prompttext' => _('Send RPID'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_SENDRPID'), 'tt' => $tt, 'select' => $select, 'level' => 1);
     unset($select);
     $select[] = array('value' => 'friend', 'text' => 'friend');
     $select[] = array('value' => 'peer', 'text' => 'peer');
     $select[] = array('value' => 'user', 'text' => 'user');
     $tt = _("Asterisk connection type, usually friend for endpoints.") . '[type]';
     $tmparr['type'] = array('prompttext' => _('Connection Type'), 'value' => 'friend', 'tt' => $tt, 'select' => $select, 'level' => 1);
     unset($select);
     $select[] = array('value' => 'accept', 'text' => _('Accept'));
     $select[] = array('value' => 'originate', 'text' => _('originate'));
     $select[] = array('value' => 'refuse', 'text' => _('Refuse'));
     $tt = _("The sessions are kept alive by sending a RE-INVITE or UPDATE request at a negotiated interval. If a session refresh fails then all the entities that support Session-Timers clear their internal session state. Default is Accept.") . '[session-timers]';
     $tmparr['sessiontimers'] = array('prompttext' => _('Session Timers'), 'value' => 'accept', 'tt' => $tt, 'select' => $select, 'level' => 1);
     unset($select);
     $select[] = array('value' => 'yes', 'text' => sprintf(_('Yes - (%s)'), 'force_rport,comedia'));
     $select[] = array('value' => 'no', 'text' => sprintf(_('No - (%s)'), 'no'));
     if (version_compare($this->version, '1.8', 'ge')) {
         $select[] = array('value' => 'force_rport', 'text' => sprintf(_('Force rport - (%s)'), 'force_rport'));
         $select[] = array('value' => 'comedia', 'text' => sprintf(_('comedia - (%s)'), 'comedia'));
     }
     if (version_compare($this->version, '11.5', 'ge')) {
         $select[] = array('value' => 'auto_force_rport,auto_comedia', 'text' => sprintf(_('Automatic Force Both - (%s)'), "auto_force_rport,auto_comedia"));
         $select[] = array('value' => 'auto_force_rport', 'text' => sprintf(_('Automatic Force rport - (%s)'), 'auto_force_rport'));
         $select[] = array('value' => 'auto_comedia', 'text' => sprintf(_('Automatic comedia - (%s)'), 'auto_comedia'));
     }
     $select[] = array('value' => 'never', 'text' => sprintf(_('Never - (%s)'), 'no'));
     $select[] = array('value' => 'route', 'text' => sprintf(_('Route - (%s)'), 'force_rport'));
     $tt = _("NAT setting, see Asterisk documentation for details. Yes usually works for both internal and external devices. Set to No if the device will always be internal.") . '[nat]';
     $tmparr['nat'] = array('prompttext' => _('NAT Mode'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_NAT'), 'tt' => $tt, 'select' => $select, 'level' => 0);
     $tt = _("Endpoint port number to use, usually 5060. Some 2 ports devices such as ATA may used 5061 for the second port.");
     $tmparr['port'] = array('prompttext' => _('Port'), 'value' => '5060', 'tt' => $tt, 'level' => 1);
     $tt = _("Setting to yes (equivalent to 2000 msec) will send an OPTIONS packet to the endpoint periodically (default every minute). Used to monitor the health of the endpoint. If delays are longer then the qualify time, the endpoint will be taken offline and considered unreachable. Can be set to a value which is the msec threshhold. Setting to no will turn this off. Can also be helpful to keep NAT pinholes open.");
     $tmparr['qualify'] = array('prompttext' => _('Qualify'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_QUALIFY'), 'tt' => $tt, 'level' => 1);
     if (version_compare($this->version, '1.6', 'ge')) {
         $tt = _("Frequency in seconds to send qualify messages to the endpoint.");
         $tmparr['qualifyfreq'] = array('prompttext' => _('Qualify Frequency'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_QUALIFYFREQ'), 'tt' => $tt, 'level' => 1);
     }
     if (version_compare($this->version, '1.8', 'ge')) {
         unset($select);
         $select[] = array('value' => 'udp,tcp,tls', 'text' => _('All - UDP Primary'));
         $select[] = array('value' => 'tcp,udp,tls', 'text' => _('All - TCP Primary'));
         $select[] = array('value' => 'tls,udp,tcp', 'text' => _('All - TLS Primary'));
         if (version_compare($this->version, '11', 'ge')) {
             $select[] = array('value' => 'ws,udp,tcp,tls', 'text' => _('All - WS Primary'));
             $select[] = array('value' => 'wss,udp,tcp,tls', 'text' => _('All - WSS Primary'));
         }
         $select[] = array('value' => 'udp', 'text' => _('UDP Only'));
         $select[] = array('value' => 'tcp', 'text' => _('TCP Only'));
         $select[] = array('value' => 'tls', 'text' => _('TLS Only'));
         if (version_compare($this->version, '11', 'ge')) {
             $select[] = array('value' => 'ws', 'text' => _('WS Only'));
             $select[] = array('value' => 'wss', 'text' => _('WSS Only'));
             $select[] = array('value' => 'wss,ws', 'text' => _('WS, WSS Only - WSS Primary'));
         }
         $tt = _("This sets the allowed transport settings for this device and the default (Primary) transport for outgoing. The default transport is only used for outbound messages until a registration takes place.  During the peer registration the transport type may change to another supported type if the peer requests so. In most common cases, this does not have to be changed as most devices register in conjunction with the host=dynamic setting. If you are using TCP and/or TLS you need to make sure the general SIP Settings are configured for the system to operate in those modes and for TLS, proper certificates have been generated and configured. If you are using websockets (such as WebRTC) then you must select an option that includes WS");
         $tmparr['transport'] = array('prompttext' => _('Transport'), 'value' => 'Auto', 'tt' => $tt, 'select' => $select, 'level' => 1);
         if (version_compare($this->version, '11', 'ge')) {
             unset($select);
             $select[] = array('value' => 'no', 'text' => _('No'));
             $select[] = array('value' => 'yes', 'text' => _('Yes'));
             $tt = _("Whether to Enable AVPF. Defaults to no. The WebRTC standard has selected AVPF as the audio video profile to use for media streams. This is not the default profile in use by Asterisk. As a result the following must be enabled to use WebRTC");
             $tmparr['avpf'] = array('prompttext' => _('Enable AVPF'), 'value' => 'no', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
         }
         if (version_compare($this->version, '11', 'ge')) {
             unset($select);
             $select[] = array('value' => 'no', 'text' => _('No'));
             $select[] = array('value' => 'yes', 'text' => _('Yes'));
             $tt = _("Force 'RTP/AVP', 'RTP/AVPF', 'RTP/SAVP', and 'RTP/SAVPF' to be used for media streams when appropriate, even if a DTLS stream is present.");
             $tmparr['force_avp'] = array('prompttext' => _('Force AVP'), 'value' => 'no', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
         }
         if (version_compare($this->version, '11', 'ge')) {
             unset($select);
             $select[] = array('value' => 'no', 'text' => _('No'));
             $select[] = array('value' => 'yes', 'text' => _('Yes'));
             $tt = _("Whether to Enable ICE Support. Defaults to no. ICE (Interactive Connectivity Establishment) is a protocol for Network Address Translator(NAT) traversal for UDP-based multimedia sessions established with the offer/answer model. This option is commonly enabled in WebRTC setups");
             $tmparr['icesupport'] = array('prompttext' => _('Enable ICE Support'), 'value' => 'no', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
         }
         unset($select);
         $select[] = array('value' => 'no', 'text' => _('No'));
         $select[] = array('value' => 'yes', 'text' => _('Yes (SRTP only)'));
         $tt = _("Whether to offer SRTP encrypted media (and only SRTP encrypted media) on outgoing calls to a peer. Calls will fail with HANGUPCAUSE=58 if the peer does not support SRTP. Defaults to no.");
         $tmparr['encryption'] = array('prompttext' => _('Enable Encryption'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_SIP_ENCRYPTION'), 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
     }
     unset($select);
     $select[] = array('value' => 'no', 'text' => _('No'));
     $select[] = array('value' => 'yes', 'text' => _('Yes'));
     $select[] = array('value' => 'inherit', 'text' => _('Inherit'));
     $tt = _("Enable or disable video support for this extension. If set to inherit it will use the global value from SIP Settings. Default is inherit");
     $tmparr['videosupport'] = array('prompttext' => _('Video Support'), 'value' => 'inherit', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio');
     //videosupport
     $tt = _("Callgroup(s) that this device is part of, can be one or more alpha/numeric callgroups, e.g. '1,3000-3005,sales,sales2'.");
     $tmparr['namedcallgroup'] = array('prompttext' => _('Call Groups'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_CALLGROUP'), 'tt' => $tt, 'level' => 1, 'jsvalidation' => "frm_" . $display . "_pickupGroup()");
     $tt = _("Pickupgroups(s) that this device can pickup calls from, can be one or more alpha/numeric callgroups, e.g. '1,3000-3005,sales,sales2'. Device does not have to be in a group to be able to pickup calls from that group.");
     $tmparr['namedpickupgroup'] = array('prompttext' => _('Pickup Groups'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_PICKUPGROUP'), 'tt' => $tt, 'level' => 1, 'jsvalidation' => "frm_" . $display . "_pickupGroup()");
     $tt = _("Disallowed codecs. Set this to all to remove all codecs defined in the general settings and then specify specific codecs separated by '&' on the 'allow' setting, or just disallow specific codecs separated by '&'.");
     $tmparr['disallow'] = array('prompttext' => _('Disallowed Codecs'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_DISALLOW'), 'tt' => $tt, 'level' => 1);
     $tt = _("Allow specific codecs, separated by the '&' sign and in priority order. E.g. 'ulaw&g729'. Codecs allowed in the general settings will also be allowed unless removed with the 'disallow' directive.");
     $tmparr['allow'] = array('prompttext' => _('Allowed Codecs'), 'value' => $this->freepbx->Config->get_conf_setting('DEVICE_ALLOW'), 'tt' => $tt, 'level' => 1);
     $tt = _("How to dial this device, this should not be changed unless you know what you are doing.");
     $tmparr['dial'] = array('prompttext' => _('Dial'), 'value' => '', 'tt' => $tt, 'level' => 2);
     $tt = _("Accountcode for this device.");
     $tmparr['accountcode'] = array('prompttext' => _('Account Code'), 'value' => '', 'tt' => $tt, 'level' => 1);
     $tt = _("Mailbox for this device. This should not be changed unless you know what you are doing.");
     $tmparr['mailbox'] = array('prompttext' => _('Mailbox'), 'value' => '', 'tt' => $tt, 'level' => 2);
     $tt = _("Asterisk dialplan extension to reach voicemail for this device. Some devices use this to auto-program the voicemail button on the endpoint. If left blank, the default vmexten setting is automatically configured by the voicemail module. Only change this on devices that may have special needs.");
     $tmparr['vmexten'] = array('prompttext' => _('Voicemail Extension'), 'value' => '', 'tt' => $tt, 'level' => 1);
     $tt = _("IP Address range to deny access to, in the form of network/netmask.") . " " . _("You may add multiple subnets, separate them with an &amp;.");
     $tmparr['deny'] = array('prompttext' => _('Deny'), 'value' => '0.0.0.0/0.0.0.0', 'tt' => $tt, 'level' => 1);
     $tt = _("IP Address range to allow access to, in the form of network/netmask. This can be a very useful security option when dealing with remote extensions that are at a known location (such as a branch office) or within a known ISP range for some home office situations.") . " " . _("You may add multiple subnets, separate them with an &amp;.");
     $tmparr['permit'] = array('prompttext' => _('Permit'), 'value' => '0.0.0.0/0.0.0.0', 'tt' => $tt, 'level' => 1);
     $currentcomponent->addjsfunc('changeDriver()', "\n\t\tif(confirm('" . _('Are you Sure you want to Change the SIP Channel Driver? (The Page will Refresh, then you MUST hit submit to resave the device when you are done to propagate the new settings)') . "')) {\n\t\t\tif(\$('#devinfo_sipdriver').val() == 'chan_sip') {\n\t\t\t\t\$('#devinfo_sipdriver').val('chan_pjsip');\n\t\t\t} else {\n\t\t\t\t\$('#devinfo_sipdriver').val('chan_sip');\n\t\t\t}\n\t\t\t\$('form[name=frm_" . $display . "]').append('<input type=\"hidden\" name=\"changesipdriver\" value=\"yes\">');\n\t\t\t\$('form[name=frm_" . $display . "]').submit();\n\t\t}\n\t\t", 0);
     $currentcomponent->addjsfunc('pickupGroup()', "\n\t\tvar val = \$('#devinfo_pickupgroup').val();\n\t\tif(isEmpty(val) && val != '0') {\n\t\t\treturn false;\n\t\t}\n\t\tvar commas = \$('#devinfo_pickupgroup').val().split(','), stop = false;\n\t\t\$.each(commas, function(i,v) {\n\t\t\tvar s = v.split('-');\n\t\t\t\$.each(s, function(i,v) {\n\t\t\t\tif(parseInt(v) < 1 || parseInt(v) > 63) {\n\t\t\t\t\talert('" . _("Value must be between 1 and 63") . "')\n\t\t\t\t\tstop = true;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\treturn stop;\n\t\t", 0);
     $devopts = $tmparr;
     return $devopts;
 }
Пример #4
0
function core_devices_configpageload()
{
    global $currentcomponent;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Device")), 0);
        } else {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add an Extension")), 0);
        }
        $currentcomponent->addguielem('_top', new gui_label('instructions', _("Please select your Device below then click Submit")));
        $currentcomponent->addguielem('Device', new gui_selectbox('tech_hardware', $currentcomponent->getoptlist('devicelist'), '', _("Device"), '', false));
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = $_SERVER['PHP_SELF'] . '?type=setup&display=users&skip=0&extdisplay=' . $deviceInfo['user'];
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', $extdisplay ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = _("Device Info");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay));
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false));
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The caller id name for this device will be set to this description until it is logged into."), '!isAlphanumeric() || isWhitespace()', $msgInvalidDevDesc, false));
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This caller id will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other caller id settings."), '!isCallerID()', $msgInvalidEmergCID));
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false));
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false));
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This caller id will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other caller id settings."), '!isCallerID()', $msgInvalidEmergCID));
        }
        $currentcomponent->addguielem($section, new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem($section, new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $device_uses = sprintf(_("This device uses %s technology."), $devinfo_tech) . (strtoupper($devinfo_tech) == 'ZAP' && ast_with_dahdi() ? " (" . _("Via DAHDI compatibility mode") . ")" : "");
            $currentcomponent->addguielem($section, new gui_label('techlabel', $device_uses), 4);
            $devopts = $currentcomponent->getgeneralarrayitem('devtechs', $devinfo_tech);
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($section, new gui_hidden($devopname . "_origional", $devoptcurrent), 4);
                    }
                    if ($devoptarr['level'] == 0 || $extdisplay && $devoptarr['level'] == 1) {
                        // editing to show advanced as well
                        $currentcomponent->addguielem($section, new gui_textbox($devopname, $devoptcurrent, $devopt, '', $devoptjs, $devoptfailmsg), 4);
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($section, new gui_hidden($devopname, $devoptcurrent), 4);
                    }
                }
            }
        }
    }
}
Пример #5
0
function core_devices_configpageload()
{
    global $currentcomponent;
    global $amp_conf;
    $tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
    if ($tech_hardware == 'virtual') {
        return true;
    }
    // Init vars from $_REQUEST[]
    $display = isset($_REQUEST['display']) ? $_REQUEST['display'] : null;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
    if ($action == 'del') {
        // Deleted
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_subheading('del', $extdisplay . ' ' . _("deleted"), false));
        }
    } elseif ($extdisplay == '' && $tech_hardware == '') {
        // Adding
        if ($display != 'extensions') {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Device")), 0);
        } else {
            $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add an Extension")), 0);
        }
        $currentcomponent->addguielem('_top', new gui_label('instructions', _("Please select your Device below then click Submit")));
        $currentcomponent->addguielem('Device', new gui_selectbox('tech_hardware', $currentcomponent->getoptlist('devicelist'), '', _("Device"), '', false));
    } else {
        $deviceInfo = array();
        if ($extdisplay) {
            // Editing
            $deviceInfo = core_devices_get($extdisplay);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Device") . ": {$extdisplay}", false), 0);
                $delURL = '?' . $_SERVER['QUERY_STRING'] . '&action=del';
                $tlabel = sprintf(_("Delete Device %s"), $extdisplay);
                $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/telephone_delete.png"/>&nbsp;' . $tlabel . '</span>';
                $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
                if ($deviceInfo['device_user'] != 'none') {
                    $editURL = '?display=users&skip=0&extdisplay=' . $deviceInfo['user'];
                    $tlabel = $deviceInfo['devicetype'] == 'adhoc' ? sprintf(_("Edit Default User: %s"), $deviceInfo['user']) : sprintf(_("Edit Fixed User: %s"), $deviceInfo['user']);
                    $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/user_edit.png"/>&nbsp;' . $tlabel . '</span>';
                    $currentcomponent->addguielem('_top', new gui_link('edit_user', $label, $editURL, true, false), 0);
                }
            }
        } else {
            $tmparr = explode('_', $tech_hardware);
            $deviceInfo['tech'] = $tmparr[0];
            $deviceInfo['hardware'] = $tmparr[1];
            unset($tmparr);
            if ($display != 'extensions') {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Device"), strtoupper($deviceInfo['tech']))), 0);
            } else {
                $currentcomponent->addguielem('_top', new gui_pageheading('title', sprintf(_("Add %s Extension"), strtoupper($deviceInfo['tech']))), 0);
            }
        }
        // Ensure they exist before the extract
        $devinfo_description = $devinfo_emergency_cid = null;
        $devinfo_devicetype = $devinfo_user = $devinfo_hardware = null;
        $devinfo_tech = null;
        if (is_array($deviceInfo)) {
            extract($deviceInfo, EXTR_PREFIX_ALL, 'devinfo');
        }
        // Setup vars for use in the gui later on
        $fc_logon = featurecodes_getFeatureCode('core', 'userlogon');
        $fc_logoff = featurecodes_getFeatureCode('core', 'userlogoff');
        $msgInvalidDevID = _("Please enter a device id.");
        $msgInvalidDevDesc = _("Please enter a valid Description for this device");
        $msgInvalidEmergCID = _("Please enter a valid Emergency CID");
        $msgInvalidExtNum = _("Please enter a valid extension number.");
        // Actual gui
        $currentcomponent->addguielem('_top', new gui_hidden('action', $extdisplay ? 'edit' : 'add'));
        $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
        if ($display != 'extensions') {
            $section = _("Device Info");
            if ($extdisplay) {
                // Editing
                $currentcomponent->addguielem($section, new gui_hidden('deviceid', $extdisplay));
            } else {
                // Adding
                $currentcomponent->addguielem($section, new gui_textbox('deviceid', $extdisplay, _("Device ID"), _("Give your device a unique integer ID.  The device will use this ID to authenticate to the system."), '!isInteger()', $msgInvalidDevID, false));
            }
            $currentcomponent->addguielem($section, new gui_textbox('description', $devinfo_description, _("Description"), _("The CallerID name for this device will be set to this description until it is logged into."), '!isAlphanumeric() || isWhitespace()', $msgInvalidDevDesc, false));
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID));
            $currentcomponent->addguielem($section, new gui_selectbox('devicetype', $currentcomponent->getoptlist('devicetypelist'), $devinfo_devicetype, _("Device Type"), _("Devices can be fixed or adhoc. Fixed devices are always associated to the same extension/user. Adhoc devices can be logged into and logged out of by users.") . ' ' . $fc_logon . ' ' . _("logs into a device.") . ' ' . $fc_logoff . ' ' . _("logs out of a device."), false));
            $currentcomponent->addguielem($section, new gui_selectbox('deviceuser', $currentcomponent->getoptlist('deviceuserlist'), $devinfo_user, _("Default User"), _("Fixed devices will always mapped to this user.  Adhoc devices will be mapped to this user by default.<br><br>If selecting 'New User', a new User Extension of the same Device ID will be set as the Default User."), false));
        } else {
            $section = _("Extension Options");
            $currentcomponent->addguielem($section, new gui_textbox('emergency_cid', $devinfo_emergency_cid, _("Emergency CID"), _("This CallerID will always be set when dialing out an Outbound Route flagged as Emergency.  The Emergency CID overrides all other CallerID settings."), '!isCallerID()', $msgInvalidEmergCID));
        }
        $currentcomponent->addguielem($section, new gui_hidden('tech', $devinfo_tech));
        $currentcomponent->addguielem($section, new gui_hidden('hardware', $devinfo_hardware));
        if ($devinfo_tech && $devinfo_tech != "virtual") {
            $section = _("Device Options");
            $devinfo_techd = $devinfo_tech == 'sip' ? 'CHAN_SIP' : strtoupper($devinfo_tech);
            if (FreePBX::Modules()->moduleHasMethod("sipsettings", "getBinds")) {
                $out = FreePBX::Sipsettings()->getBinds();
                foreach ($out[$devinfo_tech] as $ip => $data1) {
                    foreach ($data1 as $protocol => $port) {
                        $pport .= $ip . ":" . $port . ', ';
                    }
                }
                $pport = rtrim($pport, ", ");
            } else {
                $pport = '';
            }
            $extrac = !empty($pport) ? sprintf(_('listening on <strong>%s</strong>'), $pport) : '';
            $device_uses = sprintf(_("This device uses %s technology %s"), "<strong>" . $devinfo_techd . "</strong>", $extrac) . (strtoupper($devinfo_tech) == 'ZAP' && ast_with_dahdi() ? " (" . _("Via DAHDi compatibility mode") . ")" : "");
            $currentcomponent->addguielem($section, new gui_label('techlabel', '<div class="alert alert-info" role="alert" style="width:100%">' . $device_uses . '</div>'), 4);
            // We need to scream loudly if this device is using a channel driver that's disabled.
            if ($devinfo_tech == "pjsip" || $devinfo_tech == "sip") {
                $sipdriver = FreePBX::create()->Config->get_conf_setting('ASTSIPDRIVER');
                if ($sipdriver != "both") {
                    // OK, one is disabled.
                    if ($devinfo_tech == "sip") {
                        $iwant = "chan_sip";
                    } else {
                        $iwant = "chan_pjsip";
                    }
                    if ($iwant != $sipdriver) {
                        // Poot.
                        $err = sprintf(_("<strong>CRITICAL ERROR!</strong> Required Service %s is disabled! This device is unusable!"), strtoupper($iwant));
                        $currentcomponent->addguielem($section, new gui_label('techerrlabel', $err), 3);
                    }
                }
            }
            $devopts = $currentcomponent->getgeneralarrayitem('devtechs', $devinfo_tech);
            if (is_array($devopts)) {
                foreach ($devopts as $devopt => $devoptarr) {
                    $devopname = 'devinfo_' . $devopt;
                    $devoptcurrent = isset(${$devopname}) ? ${$devopname} : $devoptarr['value'];
                    $devoptjs = isset($devoptarr['jsvalidation']) ? $devoptarr['jsvalidation'] : '';
                    $devoptfailmsg = isset($devoptarr['failvalidationmsg']) ? $devoptarr['failvalidationmsg'] : '';
                    $devdisable = isset($devoptarr['disable']) ? $devoptarr['disable'] : false;
                    $devonchange = isset($devoptarr['onchange']) ? $devoptarr['onchange'] : '';
                    $prompttext = isset($devoptarr['prompttext']) ? $devoptarr['prompttext'] : $devopt;
                    $hidden = isset($devoptarr['hidden']) ? $devoptarr['hidden'] : false;
                    $type = isset($devoptarr['type']) ? $devoptarr['type'] : (isset($devoptarr['select']) ? 'select' : 'text');
                    $text = isset($devoptarr['text']) ? $devoptarr['text'] : '';
                    // We compare the existing secret against what might be in the put to detect changes when validating
                    if ($devopt == "secret") {
                        $currentcomponent->addguielem($section, new gui_hidden($devopname . "_origional", $devoptcurrent), 4);
                        if ($devoptcurrent == '' && empty($extdisplay)) {
                            $devoptcurrent = md5(uniqid());
                        }
                    }
                    if (!$hidden && ($devoptarr['level'] == 0 || $amp_conf['ALWAYS_SHOW_DEVICE_DETAILS'] && $devoptarr['level'] < 2 || $extdisplay != '')) {
                        // editing to show advanced as well
                        // Added optional selectbox to enable the unsupported misdn module
                        $tooltip = isset($devoptarr['tt']) ? $devoptarr['tt'] : '';
                        if ($type == 'select') {
                            $currentcomponent->addguielem($section, new gui_selectbox($devopname, $devoptarr['select'], $devoptcurrent, $prompttext, $tooltip, false, $devonchange, $devdisable), 4);
                        } elseif ($type == 'text') {
                            $currentcomponent->addguielem($section, new gui_textbox($devopname, $devoptcurrent, $prompttext, $tooltip, $devoptjs, $devoptfailmsg, true, 0, $devdisable), 4);
                        } elseif ($type == 'button') {
                            $currentcomponent->addguielem($section, new gui_button($devopname, $devoptcurrent, $prompttext, $tooltip, $text, $devoptjs, $devdisable), 4);
                        }
                    } else {
                        // add so only basic
                        $currentcomponent->addguielem($section, new gui_hidden($devopname, $devoptcurrent), 4);
                    }
                }
            }
        }
    }
}
Пример #6
0
    }
}
if (in_array('addext', $actions)) {
    $actions_taken = true;
    $any_users = core_users_get($ext);
    debug("core_users_add({$user_add_arr})");
    if (isset($any_users['extension']) || !core_users_add($user_add_arr)) {
        var_dump($any_users);
        fatal("Attempt to add user failed, aborting");
        exit(1);
    }
}
if (in_array('addext', $actions)) {
    $actions_taken = true;
    debug("core_devices_add({$ext}, {$tech}, '', 'fixed', {$ext}, {$displayname}, {$emergencycid})");
    $any_devices = core_devices_get($ext);
    if (count($any_devices) > 0 || !core_devices_add($ext, $tech, '', 'fixed', $ext, $displayname, $emergencycid)) {
        var_dump($any_devices);
        fatal("Attempt to add device failed, aborting");
        exit(1);
    }
}
if (in_array('remext', $actions)) {
    $actions_taken = true;
    if (core_users_get($ext) != null) {
        debug("removing user {$ext}");
        core_users_del($ext);
        core_devices_del($ext);
    } else {
        debug("not removing user {$ext}");
    }
Пример #7
0
function accountcodepreserve_hookGet_config($engine)
{
    global $ext;
    global $astman;
    global $active_modules;
    switch ($engine) {
        case "asterisk":
            /* set the inheritable channel variable to the callee's accountcode if there is one. Then it will be available in any outbound
                 trunk calls replacing the code of the user who is making the call. This way a CF situation results in the CF user's account code.
                 With typical calls, the callee will be ARG2 of macro-exten-vm so if coming from there, use that. Otherwise it will be the
                 EXTEN that called this macro (such as a followme) so we use MACRO_EXTEN.
               */
            $priority = 'report2';
            $ext->splice('macro-user-callerid', 's', $priority, new ext_execif('$["${CALLEE_ACCOUNCODE}" = ""]', 'Set', '__CALLEE_ACCOUNCODE=${DB(AMPUSER/${IF($["${MACRO_CONTEXT}"="macro-exten-vm"]?${ARG2}:${MACRO_EXTEN})}/accountcode)}'));
            /* check and set the account code in every route (so we don't have to do it in every trunk in case there are fail-over trunks
             */
            if (function_exists('core_routing_getroutepatternsbyid')) {
                // 2.8+ schema version
                //
                $routes = core_routing_list();
                foreach ($routes as $route) {
                    $patterns = core_routing_getroutepatternsbyid($route['route_id']);
                    $context = 'outrt-' . $route['route_id'];
                    foreach ($patterns as $pattern) {
                        $fpattern = core_routing_formatpattern($pattern);
                        $extension = $fpattern['dial_pattern'];
                        $ext->splice($context, $extension, 2, new ext_execif('$[ "${CALLEE_ACCOUNCODE}" != "" ] ', 'Set', 'CDR(accountcode)=${CALLEE_ACCOUNCODE}'));
                    }
                }
            } else {
                // 2.7- schema version
                //
                $route_list = core_routing_getroutenames();
                foreach ($route_list as $route) {
                    $context = 'outrt-' . $route[0];
                    $patterns = core_routing_getroutepatterns($route[0]);
                    foreach ($patterns as $rt) {
                        //strip the pipe out as that's what we use for the dialplan extension
                        $extension = str_replace('|', '', $rt);
                        // If there are any wildcards in there, add a _ to the start
                        if (preg_match("/\\.|z|x|\\[|\\]/i", $extension)) {
                            $extension = "_" . $extension;
                        }
                        $ext->splice($context, $extension, 0, new ext_execif('$[ "${CALLEE_ACCOUNCODE}" != "" ] ', 'Set', 'CDR(accountcode)=${CALLEE_ACCOUNCODE}'));
                    }
                }
            }
            /* Now lookup each device that has an account code set and create the AMPUSER/user/accountcode key for that user based on the
                     first device that we see associated with them. If multiple devices point to the same user, the code used will only be one of them.
            
                     TODO: note this is fine for extension mode assuming there is always a 1-to-1 mapping of device/user. For deviceanduser mode
                           it would be necessary to have accountcodes stored with the user and not with the device. And then macro-user-callerid
                           would need to set the account code for each user on all calls, just like it does with the language module. (Meaning
                           a need to splice a new field into the user. This would not be hard to do, basically an almost exact cut-and-paste of
                           the language module code that handles the user gui hook for the language in extensions/users.
                   */
            $account_codes = array();
            $devices = FreePBX::Core()->getAllDevicesByType();
            if (!empty($devices) && is_array($devices)) {
                foreach ($devices as $device) {
                    if ($device['user'] != 'none' && $device['tech'] != 'custom') {
                        $dev_props = core_devices_get($device['user']);
                        if (isset($dev_props['accountcode']) && $dev_props['accountcode'] != '') {
                            $account_codes[$device['user']] = $dev_props['accountcode'];
                        }
                    }
                }
            }
            foreach ($account_codes as $user => $accountcode) {
                $astman->database_put("AMPUSER", $user . "/accountcode", $accountcode);
                /*
                				// database_put is expensive so read it first and only write if it's been changed
                				//
                				$old_code = trim($astman->database_get("AMPUSER",$user."/accountcode"));
                				if ($old_code != trim($accountcode)) {
                		  		$astman->database_put("AMPUSER",$user."/accountcode",$accountcode);
                				}
                */
            }
            unset($account_codes);
            unset($devices);
            break;
    }
}