<div class="row">
					<div class="form-group">
						<div class="col-md-3">
							<label class="control-label" for="codecw"><?php 
echo _("Codecs");
?>
</label>
						</div>
						<div class="col-md-9">
							<?php 
echo \show_help(_("This is the default Codec setting for new Trunks and Extensions."));
?>
							<?php 
$seq = 1;
echo '<ul class="sortable">';
foreach (FreePBX::Sipsettings()->getCodecs('audio', true) as $codec => $codec_state) {
    $codec_trans = _($codec);
    $codec_checked = $codec_state ? 'checked' : '';
    echo '<li><a href="#">' . '<img src="assets/sipsettings/images/arrow_up_down.png" height="16" width="16" border="0" alt="move" style="float:none; margin-left:-6px; margin-bottom:-3px;cursor:move" /> ' . '<input type="checkbox" ' . ($codec_checked ? 'value="' . $seq++ . '" ' : '') . 'name="voicecodecs[' . $codec . ']" ' . 'id="' . $codec . '" ' . 'class="audio-codecs" ' . $codec_checked . ' />' . '<label for="' . $codec . '"> ' . '<small>' . $codec_trans . '</small>' . " </label></a></li>\n";
}
echo '</ul>';
?>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--END Codecs-->
</div>
</form>
 /**
  * Generate Individual Endpoint
  * @param {string} $config  configuration
  * @param {array} &$retarr Returned Array
  */
 private function generateEndpoint($config, &$retarr)
 {
     // Validate $config array
     $this->validateEndpoint($config);
     if ($config['sipdriver'] != 'chan_pjsip') {
         return false;
     }
     $endpoint = $auth = $aor = $identify = array();
     // With pjsip, we need three sections.
     $endpointname = $config['account'];
     $endpoint[] = "type=endpoint";
     $authname = "{$endpointname}-auth";
     $identifyname = "{$endpointname}-identify";
     $identify[] = "type=identify";
     $auth[] = "type=auth";
     $aorname = "{$endpointname}";
     $aor[] = "type=aor";
     //identify
     $identify[] = "endpoint={$endpointname}";
     // Endpoint
     $endpoint[] = "aors={$aorname}";
     $endpoint[] = "auth={$authname}";
     if (!empty($config['disallow'])) {
         $endpoint[] = "disallow=" . str_replace('&', ',', $config['disallow']);
         // As above.
     }
     $endpoint[] = "allow=" . str_replace('&', ',', $config['allow']);
     // & is invalid in pjsip, but valid in chan_sip
     $endpoint[] = "context=" . $config['context'];
     $endpoint[] = "callerid=" . $config['callerid'];
     // PJSIP Has a limited number of dtmf settings. If we don't know what it is, set it to RFC.
     $validdtmf = array("rfc4733", "inband", "info");
     if (version_compare($this->version, '13', 'ge')) {
         $validdtmf[] = "auto";
     }
     if (!in_array($config['dtmfmode'], $validdtmf)) {
         if (version_compare($this->version, '13', 'ge')) {
             $config['dtmfmode'] = "auto";
         } else {
             $config['dtmfmode'] = "rfc4733";
         }
     }
     $endpoint[] = "dtmf_mode=" . $config['dtmfmode'];
     //http://issues.freepbx.org/browse/FREEPBX-8643
     if (isset($config['mailbox'])) {
         if (empty($config['mwi_subscription']) || $config['mwi_subscription'] == 'solicited') {
             //solicited mwi
             $aor[] = "mailboxes=" . $config['mailbox'];
         } else {
             //unsolicited mwi
             $endpoint[] = "mailboxes=" . $config['mailbox'];
         }
     }
     if (version_compare($this->version, '12.5.0', 'ge') && isset($config['accountcode']) && trim($config['accountcode']) != "") {
         $endpoint[] = "accountcode=" . $config['accountcode'];
     }
     //check transport to make sure it's valid
     $trans = array_keys($this->getTransportConfigs());
     if (!empty($config['transport'])) {
         if (!in_array($config['transport'], $trans)) {
             // throw new Exception('Invalid Transport Defined on device '.$endpointname);
             // Remove it, it's now autodetecting.
             unset($config['transport']);
         } else {
             $endpoint[] = "transport=" . $config['transport'];
         }
     }
     $endpoint[] = "aggregate_mwi=" . (isset($config['aggregate_mwi']) ? $config['aggregate_mwi'] : "yes");
     if (!empty($config['namedcallgroup'])) {
         $endpoint[] = "named_call_group=" . $config['namedcallgroup'];
     }
     if (!empty($config['namedpickupgroup'])) {
         $endpoint[] = "named_pickup_group=" . $config['namedpickupgroup'];
     }
     if (!empty($config['avpf'])) {
         $endpoint[] = "use_avpf=" . $config['avpf'];
     }
     if (!empty($config['icesupport'])) {
         $endpoint[] = "ice_support=" . $config['icesupport'];
     }
     if (!empty($config['media_use_received_transport']) && version_compare($this->version, "12.4.0", "ge")) {
         $endpoint[] = "media_use_received_transport=" . $config['media_use_received_transport'];
     }
     if (!empty($config['trustrpid'])) {
         $endpoint[] = "trust_id_inbound=" . $config['trustrpid'];
     }
     if (!empty($config['match'])) {
         $identify[] = "match=" . $config['match'];
     }
     if (!empty($config['mediaencryption'])) {
         $endpoint[] = "media_encryption=" . $config['mediaencryption'];
     } else {
         // Automatically enable sdes if possible
         //
         // Requires sipsettings 13.0.16 or higher
         if ($this->freepbx->Modules->moduleHasMethod('Sipsettings', 'getTLSConfig')) {
             if (\FreePBX::Sipsettings()->getTLSConfig()) {
                 $endpoint[] = "media_encryption=sdes";
             }
         }
     }
     if (!empty($config['timers'])) {
         $endpoint[] = "timers=" . $config['timers'];
     }
     if (!empty($config['mediaencryptionoptimistic'])) {
         $endpoint[] = "media_encryption_optimistic=" . $config['mediaencryptionoptimistic'];
     }
     if (!empty($config['device_state_busy_at']) && is_numeric($config['device_state_busy_at']) && $config['device_state_busy_at'] > 0) {
         $endpoint[] = "device_state_busy_at=" . $config['device_state_busy_at'];
     }
     if (isset($config['sendrpid'])) {
         if ($config['sendrpid'] == "yes" || $config['sendrpid'] == "both") {
             $endpoint[] = "send_rpid=yes";
         }
         if ($config['sendrpid'] == "pai" || $config['sendrpid'] == "both") {
             $endpoint[] = "send_pai=yes";
         }
     }
     //rtp_symmetric needs to be yes for NAT --mjordan, Digium
     $endpoint[] = !empty($config['rtp_symmetric']) ? "rtp_symmetric=" . $config['rtp_symmetric'] : "rtp_symmetric=yes";
     //rewrite_contact needs to be yes for NAT --mjordan, Digium
     $endpoint[] = !empty($config['rewrite_contact']) ? "rewrite_contact=" . $config['rewrite_contact'] : "rewrite_contact=yes";
     $endpoint[] = !empty($config['force_rport']) ? "force_rport=" . $config['force_rport'] : "force_rport=yes";
     if (!empty($this->language)) {
         $endpoint[] = "language=" . $this->language;
     }
     // Auth
     $auth[] = "auth_type=userpass";
     $auth[] = "password="******"username="******"max_contacts=1";
         $aor[] = "remove_existing=yes";
     } else {
         $aor[] = "max_contacts=" . $config['max_contacts'];
         $aor[] = "remove_existing=no";
     }
     if (isset($config['maximum_expiration'])) {
         $aor[] = "maximum_expiration=" . $config['maximum_expiration'];
     }
     if (isset($config['minimum_expiration'])) {
         $aor[] = "minimum_expiration=" . $config['minimum_expiration'];
     }
     if (!empty($config['qualifyfreq'])) {
         $aor[] = "qualify_frequency=" . $config['qualifyfreq'];
     }
     if (isset($retarr["pjsip.endpoint.conf"][$endpointname])) {
         throw new \Exception("Endpoint {$endpointname} already exists.");
     }
     $retarr["pjsip.endpoint.conf"][$endpointname] = $endpoint;
     if (!empty($this->_endpoint[$endpointname]) && is_array($this->_endpoint[$endpointname])) {
         foreach ($this->_endpoint[$endpointname] as $el) {
             $retarr["pjsip.endpoint.conf"][$endpointname][] = "{$el['key']}={$el['value']}";
         }
         unset($this->_endpoint[$endpointname]);
     }
     if (isset($retarr["pjsip.auth.conf"][$authname])) {
         throw new \Exception("Auth {$authname} already exists.");
     }
     $retarr["pjsip.auth.conf"][$authname] = $auth;
     if (!empty($this->_auth[$authname]) && is_array($this->_auth[$authname])) {
         foreach ($this->_auth[$authname] as $el) {
             $retarr["pjsip.auth.conf"][$authname][] = "{$el['key']}={$el['value']}";
         }
         unset($this->_auth[$authname]);
     }
     if (isset($retarr["pjsip.aor.conf"][$aorname])) {
         throw new \Exception("AOR {$aorname} already exists.");
     }
     $retarr["pjsip.aor.conf"][$aorname] = $aor;
     if (!empty($this->_aor[$aorname]) && is_array($this->_aor[$aorname])) {
         foreach ($this->_aor[$aorname] as $el) {
             $retarr["pjsip.aor.conf"][$aorname][] = "{$el['key']}={$el['value']}";
         }
         unset($this->_aor[$aorname]);
     }
     if (isset($retarr["pjsip.identify.conf"][$identifyname])) {
         throw new \Exception("Identify {$aorname} already exists.");
     }
     $retarr["pjsip.identify.conf"][$identifyname] = $identify;
     if (!empty($this->_identify[$identifyname]) && is_array($this->_identify[$identifyname])) {
         foreach ($this->_identify[$identifyname] as $el) {
             $retarr["pjsip.identify.conf"][$identifyname][] = "{$el['key']}={$el['value']}";
         }
         unset($this->_identify[$identifyname]);
     }
 }
Beispiel #3
0
        out(_("ulaw, alaw, gsm, g726 added"));
    }
    if ($haspjsip) {
        FreePBX::create()->Config->set_conf_values(array('ASTSIPDRIVER' => 'both'), true, true);
    } else {
        FreePBX::create()->Config->set_conf_values(array('ASTSIPDRIVER' => 'chansip'), true, true);
    }
    $ss->setConfig("udpport-0.0.0.0", $pjsip_port);
    $ss->setConfig("tcpport-0.0.0.0", $pjsip_port);
    $ss->setConfig("tlsport-0.0.0.0", $pjsiptls_port);
    $ss->setConfig("binds", array("udp" => array("0.0.0.0" => "on")));
} else {
    out(_("already exists"));
}
//OK let's do some migrating for BMO
$ss = FreePBX::Sipsettings();
if (!$ss->getConfig('rtpstart') || !$ss->getConfig('rtpend')) {
    out(_("Migrate rtp.conf values if needed and initialize"));
    $sql = "SELECT data FROM sipsettings WHERE keyword = 'rtpstart'";
    $rtpstart = sql($sql, 'getOne');
    if (!$rtpstart) {
        $sql = "SELECT value FROM admin WHERE variable = 'RTPSTART'";
        $rtpstart = sql($sql, 'getOne');
        if ($rtpstart) {
            out(sprintf(_("saving previous value of %s"), $rtpstart));
        }
    }
    if ($rtpstart) {
        out(_('Migrating rtpstart Setting from Old Format to BMO Object'));
        $ss->setConfig('rtpstart', $rtpstart);
    }
Beispiel #4
0
 private function answer_externsetup()
 {
     if ($_REQUEST['answer'] != "yes") {
         return;
     }
     include 'Natget.class.php';
     $n = new Natget();
     $myip = $n->getVisibleIP();
     $myroutes = $n->getRoutes();
     \FreePBX::Sipsettings()->setConfig('externip', $myip);
     // Update routes
     $ssroutes = \FreePBX::Sipsettings()->getConfig('localnets');
     if (!is_array($ssroutes)) {
         $ssroutes = array();
     }
     // I don't like these loops, it feels messy.
     foreach ($myroutes as $r) {
         // $r = [ "1.2.3.0", "24" ]
         $found = false;
         foreach ($ssroutes as $current) {
             // $current = {"net":"1.2.3.0","mask":"24"}
             if ($current['net'] == $r[0] && $current['mask'] == $r[1]) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $ssroutes[] = array("net" => $r[0], "mask" => $r[1]);
         }
     }
     $ssroutes = \FreePBX::Sipsettings()->setConfig('localnets', $ssroutes);
     return true;
 }
Beispiel #5
0
function sipsettings_edit($sip_settings)
{
    global $db;
    global $amp_conf;
    $save_settings = array();
    $save_to_admin = array();
    // Used only by ALLOW_SIP_ANON for now
    $vd = new sipsettings_validate();
    // TODO: this is where I will build validation before saving
    //
    $integer_msg = _("%s must be a non-negative integer");
    foreach ($sip_settings as $key => $val) {
        switch ($key) {
            case 'bindaddr':
                $msg = _("Bind Address (bindaddr) must be an IP address.");
                $ipv6_ok = version_compare($amp_conf['ASTVERSION'], '1.8', 'ge');
                $save_settings[] = array($key, $db->escapeSimple($vd->is_ip($val, $key, $msg, $ipv6_ok)), '2', SIP_NORMAL);
                break;
            case 'bindport':
                $msg = _("Bind Port (bindport) must be between 1024..65535, default 5060");
                $save_settings[] = array($key, $db->escapeSimple($vd->is_ip_port($val, $key, $msg)), '1', SIP_NORMAL);
                break;
            case 'rtpholdtimeout':
                // validation: must be > $sip_settings['rtptimeout'] (and of course a proper number)
                //$vd->log_error();
                if ($val < $sip_settings['rtptimeout']) {
                    $msg = _("rtpholdtimeout must be higher than rtptimeout");
                    $vd->log_error($val, $key, $msg);
                }
                $msg = sprintf($integer_msg, $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_int($val, $key, $msg)), '10', SIP_NORMAL);
                break;
            case 'rtptimeout':
            case 'rtpkeepalive':
            case 'checkmwi':
            case 'registertimeout':
            case 'minexpiry':
            case 'maxexpiry':
            case 'defaultexpiry':
                $msg = sprintf($integer_msg, $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_int($val, $key, $msg)), '10', SIP_NORMAL);
                break;
            case 'maxcallbitrate':
            case 'registerattempts':
                $msg = sprintf($integer_msg, $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_int($val, $key, $msg)), '10', SIP_NORMAL);
                break;
            case 'sip_language':
                $msg = "Language must be alphanumeric and installed";
                $save_settings[] = array($key, $db->escapeSimple($vd->is_alphanumeric($val, $key, $msg)), '0', SIP_NORMAL);
                break;
            case 'context':
                $msg = sprintf(_("%s must be alphanumeric"), $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_alphanumeric($val, $key, $msg)), '0', SIP_NORMAL);
                break;
            case 'externrefresh':
                $msg = sprintf($integer_msg, $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_int($val, $key, $msg)), '41', SIP_NORMAL);
                break;
            case 'nat':
                $save_settings[] = array($key, $val, '39', SIP_NORMAL);
                break;
            case 'externip_val':
                if ($sip_settings['nat_mode'] == 'externip') {
                    if (trim($val) == "" && !FreePBX::create()->Sipsettings->getConfig('externip')) {
                        $msg = _("External IP can not be blank when NAT Mode is set to Static and no default IP address provided on the main page");
                        $vd->log_error($val, $key, $msg);
                    } else {
                        $save_settings[] = array($key, $val, '40', SIP_NORMAL);
                    }
                }
                break;
            case 'externhost_val':
                if (trim($val) == '' && $sip_settings['nat_mode'] == 'externhost') {
                    $msg = _("Dynamic Host can not be blank");
                    $vd->log_error($val, $key, $msg);
                }
                $save_settings[] = array($key, $val, '40', SIP_NORMAL);
                break;
            case 'jbenable':
                $save_settings[] = array($key, $val, '4', SIP_NORMAL);
                break;
            case 'jbforce':
            case 'jbimpl':
            case 'jblog':
                $save_settings[] = array($key, $val, '5', SIP_NORMAL);
                break;
            case 'jbmaxsize':
            case 'jbresyncthreshold':
                $msg = sprintf($integer_msg, $key);
                $save_settings[] = array($key, $db->escapeSimple($vd->is_int($val, $key, $msg)), '5', SIP_NORMAL);
                break;
            case 'nat_mode':
            case 'g726nonstandard':
            case 't38pt_udptl':
            case 'videosupport':
            case 'canreinvite':
            case 'notifyringing':
            case 'notifyhold':
            case 'allowguest':
            case 'srvlookup':
                $save_settings[] = array($key, $val, '10', SIP_NORMAL);
                break;
            case 'ALLOW_SIP_ANON':
                $save_to_admin[] = array($key, $val);
                break;
            default:
                if (substr($key, 0, 9) == "localnet_") {
                    // ip validate this and store
                    $seq = substr($key, 9);
                    $msg = _("Localnet setting must be an IP address");
                    $save_settings[] = array($key, $db->escapeSimple($vd->is_ip($val, $key, $msg)), 42 + $seq, SIP_NORMAL);
                } else {
                    if (substr($key, 0, 8) == "netmask_") {
                        // ip validate this and store
                        $seq = substr($key, 8);
                        $msg = _("Localnet netmask must be formatted properly (e.g. 255.255.255.0 or 24)");
                        $save_settings[] = array($key, $db->escapeSimple($vd->is_netmask($val, $key, $msg)), $seq, SIP_NORMAL);
                    } else {
                        if (substr($key, 0, 15) == "sip_custom_key_") {
                            $seq = substr($key, 15);
                            $save_settings[] = array($db->escapeSimple($val), $db->escapeSimple($sip_settings["sip_custom_val_{$seq}"]), $seq, SIP_CUSTOM);
                        } else {
                            if (substr($key, 0, 15) == "sip_custom_val_") {
                                // skip it, we will seek it out when we see the sip_custom_key
                            } else {
                                $save_settings[] = array($key, $val, '0', SIP_NORMAL);
                            }
                        }
                    }
                }
        }
    }
    /* if there were any validation errors, we will return them and not proceed with saving */
    if (count($vd->errors)) {
        return $vd->errors;
    } else {
        $fvcodecs = array();
        $seq = 1;
        foreach ($_REQUEST['vcodec'] as $codec => $v) {
            $fvcodecs[$codec] = $seq++;
        }
        FreePBX::Sipsettings()->setCodecs('video', $fvcodecs);
        // TODO: normally don't like doing delete/insert but otherwise we would have do update for each
        //       individual setting and then an insert if there was nothing to update. So this is cleaner
        //       this time around.
        //
        sql("DELETE FROM `sipsettings` WHERE 1");
        $compiled = $db->prepare('INSERT INTO `sipsettings` (`keyword`, `data`, `seq`, `type`) VALUES (?,?,?,?)');
        $result = $db->executeMultiple($compiled, $save_settings);
        if (DB::IsError($result)) {
            die_freepbx($result->getDebugInfo() . "<br><br>" . 'error adding to sipsettings table');
        }
        if (!empty($save_to_admin)) {
            $compiled = $db->prepare("REPLACE INTO `admin` (`variable`, `value`) VALUES (?,?)");
            $result = $db->executeMultiple($compiled, $save_to_admin);
            if (DB::IsError($result)) {
                die_freepbx($result->getDebugInfo() . "<br><br>" . 'error adding to sipsettings table');
            }
        }
        return true;
    }
}
Beispiel #6
0
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <tr class="nat-settings externip">
    <td><a href="#" class="info"><?php 
echo _("Override External IP");
?>
<span><?php 
echo _("External Static IP or FQDN as seen on the WAN side of the router. (asterisk: externip)") . " &nbsp; " . _("Note that this will, by default, inherit the settings from the General page");
?>
</span></a></td>
<?php 
$placeholder = FreePBX::Sipsettings()->getConfig('externip');
if (!$placeholder) {
    $placeholder = "Enter IP Address";
}
?>
    <td><input type="text" id="externip_val" name="externip_val" value="<?php 
echo $externip_val;
?>
" placeholder="<?php 
echo $placeholder;
?>
" tabindex="<?php 
echo ++$tabindex;
?>
"></td>
  </tr>
Beispiel #7
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);
                    }
                }
            }
        }
    }
}
Beispiel #8
0
 public function getSipPorts()
 {
     // Returns an array of ports or ranges used by SIP or PJSIP.
     $udp = array();
     $tcp = array();
     // Let's get chansip settings if we need them.
     if ($this->chansip) {
         $bindport = "";
         $settings = \FreePBX::Sipsettings()->getChanSipSettings(true);
         foreach ($settings as $arr) {
             if (empty($arr['data'])) {
                 continue;
             }
             if ($arr['keyword'] == 'bindport') {
                 $bindport = $arr['data'];
                 break;
             }
         }
         if (empty($bindport)) {
             $bindport = 5060;
         }
         $udp[] = array("dest" => "0.0.0.0", "dport" => $bindport, "name" => "chansip");
         // TODO: chan_sip TCP.. Maybe
     }
     // Do we have pjsip?
     if ($this->pjsip) {
         // Woo. What are our settings?
         $ss = \FreePBX::Sipsettings();
         $allBinds = $ss->getConfig("binds");
         $websocket = false;
         foreach ($allBinds as $type => $listenArr) {
             // What interface(s) are we listening on?
             foreach ($listenArr as $ipaddr => $mode) {
                 if ($mode != "on") {
                     continue;
                 }
                 if ($type == "ws" || $type == "wss") {
                     $websocket = \FreePBX::Config()->get('HTTPBINDPORT');
                     continue;
                 }
                 $port = $ss->getConfig($type . "port-" . $ipaddr);
                 if (!$port) {
                     continue;
                 }
                 if ($type == "tcp") {
                     $tcp[] = array("dest" => $ipaddr, "dport" => $port, "name" => "pjsip");
                 } elseif ($type == "udp") {
                     $udp[] = array("dest" => $ipaddr, "dport" => $port, "name" => "pjsip");
                 } else {
                     throw new \Exception("Unknown protocol {$type}");
                 }
             }
         }
         if ($websocket) {
             $tcp[] = array("dest" => $ipaddr, "dport" => $websocket, "name" => "pjsip");
         }
     }
     $retarr = array("udp" => $udp, "tcp" => $tcp);
     return $retarr;
 }
Beispiel #9
0
 private function getSvc_chansip()
 {
     $retarr = array("name" => _("CHAN_SIP Protocol"), "defzones" => array("internal"), "descr" => _("This is the legacy chan_sip driver."), "fw" => array());
     $driver = \FreePBX::Config()->get('ASTSIPDRIVER');
     if ($driver == "both" || $driver == "chan_sip") {
         $tcp = false;
         $bindport = 5060;
         // Note bug in sipsettings =< 13.0.14.5 that getChanSipSettings won't
         // return correct details when not returnraw
         $settings = \FreePBX::Sipsettings()->getChanSipSettings(true);
         foreach ($settings as $arr) {
             if ($arr['keyword'] == "tcpenable" && $arr['data'] == "yes") {
                 $tcp = true;
                 continue;
             }
             if ($arr['keyword'] == "bindport") {
                 $bindport = $arr['data'];
                 continue;
             }
         }
         $retarr['fw'][] = array("protocol" => "udp", "port" => $bindport);
         if ($tcp) {
             $retarr['fw'][] = array("protocol" => "tcp", "port" => $bindport);
         }
     }
     // Make sure there's actually some binds.
     if (!$retarr['fw']) {
         $retarr['descr'] = _("CHANSIP is not available on this machine");
         $retarr['disabled'] = true;
     }
     return $retarr;
 }