It remains for us to configure the most important file for SIP telephony - sip.conf. Here you need to be careful, I had to jump with a tambourine for a couple of hours to make it work. And if everything works from the same subnet, this does not mean that you can normally receive or connect two subscribers in different networks for NAT. I set up the work as follows:
CREATE TABLE `sipusers` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`accountcode` VARCHAR(20) NULL DEFAULT NULL,
`disallow` VARCHAR(100) NULL DEFAULT 'all',
`allow` VARCHAR(100) NULL DEFAULT 'g729;ilbc;gsm;ulaw;alaw',
`allowoverlap` ENUM('yes','no') NULL DEFAULT 'yes',
`allowsubscribe` ENUM('yes','no') NULL DEFAULT 'yes',
`allowtransfer` VARCHAR(3) NULL DEFAULT NULL,
`amaflags` VARCHAR(13) NULL DEFAULT NULL,
`autoframing` VARCHAR(3) NULL DEFAULT NULL,
`auth` VARCHAR(40) NULL DEFAULT NULL,
`buggymwi` ENUM('yes','no') NULL DEFAULT 'no',
`callgroup` VARCHAR(10) NULL DEFAULT NULL,
`callerid` VARCHAR(80) NULL DEFAULT NULL,
`cid_number` VARCHAR(40) NULL DEFAULT NULL,
`fullname` VARCHAR(40) NULL DEFAULT NULL,
`call-limit` INT(8) NULL DEFAULT '0',
`callingpres` VARCHAR(80) NULL DEFAULT NULL,
`canreinvite` CHAR(6) NULL DEFAULT 'yes',
`context` VARCHAR(80) NULL DEFAULT NULL,
`defaultip` VARCHAR(15) NULL DEFAULT NULL,
`dtmfmode` VARCHAR(7) NULL DEFAULT NULL,
`fromuser` VARCHAR(80) NULL DEFAULT NULL,
`fromdomain` VARCHAR(80) NULL DEFAULT NULL,
`fullcontact` VARCHAR(80) NULL DEFAULT NULL,
`g726nonstandard` ENUM('yes','no') NULL DEFAULT 'no',
`host` VARCHAR(31) NOT NULL DEFAULT 'dynamic',
`insecure` VARCHAR(20) NULL DEFAULT NULL,
`ipaddr` VARCHAR(15) NOT NULL DEFAULT '',
`language` CHAR(2) NULL DEFAULT NULL,
`lastms` VARCHAR(20) NULL DEFAULT NULL,
`mailbox` VARCHAR(50) NULL DEFAULT NULL,
`maxcallbitrate` INT(8) NULL DEFAULT '384',
`mohsuggest` VARCHAR(80) NULL DEFAULT NULL,
`md5secret` VARCHAR(80) NULL DEFAULT NULL,
`musiconhold` VARCHAR(100) NULL DEFAULT NULL,
`name` VARCHAR(80) NOT NULL DEFAULT '',
`nat` VARCHAR(30) NOT NULL DEFAULT 'no',
`outboundproxy` VARCHAR(80) NULL DEFAULT NULL,
`deny` VARCHAR(95) NULL DEFAULT NULL,
`permit` VARCHAR(95) NULL DEFAULT NULL,
`pickupgroup` VARCHAR(10) NULL DEFAULT NULL,
`port` VARCHAR(5) NOT NULL DEFAULT '',
`progressinband` ENUM('yes','no','never') NULL DEFAULT 'no',
`promiscredir` ENUM('yes','no') NULL DEFAULT 'no',
`qualify` CHAR(3) NULL DEFAULT NULL,
`regexten` VARCHAR(80) NOT NULL DEFAULT '',
`regseconds` INT(11) NOT NULL DEFAULT '0',
`rfc2833compensate` ENUM('yes','no') NULL DEFAULT 'no',
`rtptimeout` CHAR(3) NULL DEFAULT NULL,
`rtpholdtimeout` CHAR(3) NULL DEFAULT NULL,
`secret` VARCHAR(80) NULL DEFAULT NULL,
`sendrpid` ENUM('yes','no') NULL DEFAULT 'yes',
`setvar` VARCHAR(100) NOT NULL DEFAULT '',
`subscribecontext` VARCHAR(80) NULL DEFAULT NULL,
`subscribemwi` VARCHAR(3) NULL DEFAULT NULL,
`t38pt_udptl` ENUM('yes','no') NULL DEFAULT 'no',
`trustrpid` ENUM('yes','no') NULL DEFAULT 'no',
`type` VARCHAR(6) NOT NULL DEFAULT 'friend',
`useclientcode` ENUM('yes','no') NULL DEFAULT 'no',
`defaultuser` VARCHAR(80) NOT NULL DEFAULT '',
`usereqphone` VARCHAR(3) NOT NULL DEFAULT 'no',
`videosupport` ENUM('yes','no') NULL DEFAULT 'yes',
`vmexten` VARCHAR(80) NULL DEFAULT NULL,
`useragent` VARCHAR(80) NULL DEFAULT NULL,
`regserver` VARCHAR(80) NULL DEFAULT NULL,
`callbackextension` VARCHAR(80) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name` (`name`),
INDEX `name_2` (`name`)
)
COLLATE='cp1251_general_ci'
ENGINE=MyISAM
ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=1;
<?php // // SIP // class M_SIP { private static $instance; // . const host = "bestmyfamily.com"; const user = "***"; const password = "***"; const db = "***"; public $dbSIP; // . // // . // public static function Instance() { if(self::$instance == null) self::$instance = new M_SIP(); return self::$instance; } // // // function __construct() { // $this->dbSIP = mysqli_connect(self::host, self::user, self::password) or exit; $result = mysqli_select_db($this->dbSIP, self::db) or exit; mysqli_query($this->dbSIP, 'SET NAMES utf8'); } // public function RegUserOnServer($pid, $uid) { $arr = array( 'accountcode' => Null, 'disallow' => 'all', 'allow' => 'ulaw;alaw', 'allowoverlap' => 'no', 'allowsubscribe' => 'no', 'allowtransfer' => Null, 'amaflags' => Null, 'autoframing' => Null, 'auth' => Null, 'buggymwi' => 'no', 'callgroup' => Null, 'callerid' => Null, 'cid_number' => Null, 'fullname' => Null, 'call-limit' => 0, 'callingpres' => Null, 'canreinvite' => "no", 'context' => 'myfamily', 'defaultip' => Null, 'dtmfmode' => Null, 'fromuser' => Null, 'fromdomain' => Null, 'fullcontact' => Null, 'g726nonstandard' => 'no', 'host' => 'dynamic', 'insecure' => Null, 'ipaddr' => Null, 'language' => 'en', 'lastms' => 0, 'mailbox' => Null, 'maxcallbitrate' => 384, 'mohsuggest' => Null, 'md5secret' => Null, 'musiconhold' => Null, 'name' => "", 'nat' => 'force_rport,comedia', 'outboundproxy' => Null, 'deny' => Null, 'permit' => Null, 'pickupgroup' => Null, 'port' => '', 'progressinband' => 'no', 'promiscredir' => 'no', 'qualify' => Null, 'regexten' => 1000001, 'regseconds' => 0, 'rfc2833compensate' => 'no', 'rtptimeout' => Null, 'rtpholdtimeout' => Null, 'secret' => $uid, 'sendrpid' => 'yes', 'setvar' => '', 'subscribecontext' => Null, 'subscribemwi' => Null, 't38pt_udptl' => 'no', 'trustrpid' => 'no', 'type' => 'friend', 'useclientcode' => 'no', 'defaultuser' => "", 'usereqphone' => 'no', 'videosupport' => 'no', 'vmexten' => Null, 'useragent' => Null, 'regserver' => Null, 'callbackextension' => Null ); return $this->Insert('sipusers', $arr); } // // // $table - // $object - " - " // - // private function Insert($table, $object, $isReplace = false) { $columns = array(); $values = array(); foreach ($object as $key => $value) { $key = mysqli_real_escape_string($this->dbSIP, $key); $columns[] = "`" . $key . "`"; if ($value === null) { $values[] = 'NULL'; } else { $value = mysqli_real_escape_string($this->dbSIP, $value); $values[] = "'$value'"; } } $columns_s = implode(',', $columns); $values_s = implode(',', $values); // ? if ($isReplace) $query = "REPLACE INTO $table ($columns_s) VALUES ($values_s)"; else $query = "INSERT IGNORE INTO $table ($columns_s) VALUES ($values_s)"; $result = mysqli_query($this->dbSIP, $query); if (!$result) die($this->SqlError(mysqli_error($this->dbSIP))); $id = mysqli_insert_id($this->dbSIP); return $id; } // // SQL // function SqlError($error) { return json_encode(array( 'code' => 99, 'error' => $error ) ); } }
Source: https://habr.com/ru/post/282187/
All Articles