Advertisement
Guest User

Untitled

a guest
Jan 13th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.48 KB | None | 0 0
  1. #!ifdef ACCDB_COMMENT
  2. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  3. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  4. ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
  5. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  6. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  7. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  8. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  9. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  10. ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
  11. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  12. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  13. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  14. #!endif
  15.  
  16. ####### Include Local Config If Exists #########
  17. import_file "kamailio-local.cfg"
  18.  
  19. ####### Defined Values #########
  20.  
  21. #!define WITH_NAT
  22. #!define WITH_MYSQL
  23. #!define WITH_DEBUG
  24. #!define WITH_AUTH
  25. #!define WITH_ALIASDB
  26. #!define WITH_USRLOCDB
  27. #!define WITH_TLS
  28.  
  29. # *** Value defines - IDs used later in config
  30. #!ifdef WITH_MYSQL
  31. # - database URL - used to connect to database server by modules such
  32. # as: auth_db, acc, usrloc, a.s.o.
  33. #!ifndef DBURL
  34. #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
  35. #!endif
  36. #!endif
  37. #!ifdef WITH_MULTIDOMAIN
  38. # - the value for 'use_domain' parameters
  39. #!define MULTIDOMAIN 1
  40. #!else
  41. #!define MULTIDOMAIN 0
  42. #!endif
  43.  
  44. # - flags
  45. # FLT_ - per transaction (message) flags
  46. # FLB_ - per branch flags
  47. #!define FLT_ACC 1
  48. #!define FLT_ACCMISSED 2
  49. #!define FLT_ACCFAILED 3
  50. #!define FLT_NATS 5
  51.  
  52. #!define FLB_NATB 6
  53. #!define FLB_NATSIPPING 7
  54.  
  55. ####### Global Parameters #########
  56.  
  57. ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
  58. #!ifdef WITH_DEBUG
  59. debug=2
  60. log_stderror=yes
  61. #!else
  62. debug=2
  63. log_stderror=no
  64. #!endif
  65.  
  66. memdbg=5
  67. memlog=5
  68.  
  69. log_facility=LOG_LOCAL0
  70.  
  71. fork=yes
  72. children=4
  73.  
  74. /* uncomment the next line to disable TCP (default on) */
  75. #disable_tcp=yes
  76.  
  77. /* uncomment the next line to disable the auto discovery of local aliases
  78. based on reverse DNS on IPs (default on) */
  79. #auto_aliases=no
  80.  
  81. /* add local domain aliases */
  82. #alias="sip.mydomain.com"
  83.  
  84. /* uncomment and configure the following line if you want Kamailio to
  85. bind on a specific interface/port/proto (default bind on all available) */
  86. #listen=udp:10.0.0.10:5060
  87.  
  88. /* port to listen to
  89. * - can be specified more than once if needed to listen on many ports */
  90. port=5060
  91.  
  92. #!ifdef WITH_TLS
  93. enable_tls=yes
  94. #!endif
  95.  
  96. # life time of TCP connection when there is no traffic
  97. # - a bit higher than registration expires to cope with UA behind NAT
  98. tcp_connection_lifetime=3605
  99.  
  100. ####### Custom Parameters #########
  101.  
  102. # These parameters can be modified runtime via RPC interface
  103. # - see the documentation of 'cfg_rpc' module.
  104. #
  105. # Format: group.id = value 'desc' description
  106. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  107. #
  108.  
  109. #!ifdef WITH_PSTN
  110. # PSTN GW Routing
  111. #
  112. # - pstn.gw_ip: valid IP or hostname as string value, example:
  113. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  114. #
  115. # - by default is empty to avoid misrouting
  116. pstn.gw_ip = "" desc "PSTN GW Address"
  117. pstn.gw_port = "" desc "PSTN GW Port"
  118. #!endif
  119.  
  120. #!ifdef WITH_VOICEMAIL
  121. # VoiceMail Routing on offline, busy or no answer
  122. #
  123. # - by default Voicemail server IP is empty to avoid misrouting
  124. voicemail.srv_ip = "" desc "VoiceMail IP Address"
  125. voicemail.srv_port = "5060" desc "VoiceMail Port"
  126. #!endif
  127.  
  128. ####### Modules Section ########
  129.  
  130. # set paths to location of modules (to sources or installation folders)
  131. #!ifdef WITH_SRCPATH
  132. mpath="modules_k:modules"
  133. #!else
  134. mpath="/usr/local/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/"
  135. #mpath="/usr/local/lib/kamailio/modules_k/:/usr/lib64/kamailio/modules/"
  136. #!endif
  137.  
  138. #!ifdef WITH_MYSQL
  139. loadmodule "db_mysql.so"
  140. #!endif
  141.  
  142.  
  143. loadmodule "rtimer.so"
  144. loadmodule "sqlops.so"
  145. loadmodule "htable.so"
  146.  
  147. loadmodule "snmpstats.so"
  148. loadmodule "ldap.so"
  149. loadmodule "mi_fifo.so"
  150. loadmodule "kex.so"
  151. loadmodule "corex.so"
  152. loadmodule "tm.so"
  153. loadmodule "tmx.so"
  154. loadmodule "sl.so"
  155. loadmodule "rr.so"
  156. loadmodule "pv.so"
  157. loadmodule "maxfwd.so"
  158. loadmodule "usrloc.so"
  159. loadmodule "registrar.so"
  160. loadmodule "textops.so"
  161. loadmodule "siputils.so"
  162. loadmodule "xlog.so"
  163. loadmodule "sanity.so"
  164. loadmodule "ctl.so"
  165. loadmodule "cfg_rpc.so"
  166. loadmodule "mi_rpc.so"
  167. loadmodule "acc.so"
  168.  
  169. #!ifdef WITH_AUTH
  170. loadmodule "auth.so"
  171. loadmodule "auth_db.so"
  172. #!ifdef WITH_IPAUTH
  173. loadmodule "permissions.so"
  174. #!endif
  175. #!endif
  176.  
  177. #!ifdef WITH_ALIASDB
  178. loadmodule "alias_db.so"
  179. #!endif
  180.  
  181. #!ifdef WITH_SPEEDDIAL
  182. loadmodule "speeddial.so"
  183. #!endif
  184.  
  185. #!ifdef WITH_MULTIDOMAIN
  186. loadmodule "domain.so"
  187. #!endif
  188.  
  189. #!ifdef WITH_PRESENCE
  190. loadmodule "presence.so"
  191. loadmodule "presence_xml.so"
  192. #!endif
  193.  
  194. #!ifdef WITH_NAT
  195. loadmodule "nathelper.so"
  196. loadmodule "rtpproxy.so"
  197. #!endif
  198.  
  199. #!ifdef WITH_TLS
  200. loadmodule "tls.so"
  201. #!endif
  202.  
  203. #!ifdef WITH_ANTIFLOOD
  204. loadmodule "htable.so"
  205. loadmodule "pike.so"
  206. #!endif
  207.  
  208. #!ifdef WITH_XMLRPC
  209. loadmodule "xmlrpc.so"
  210. #!endif
  211.  
  212. #!ifdef WITH_DEBUG
  213. loadmodule "debugger.so"
  214. #!endif
  215.  
  216. # ----------------- setting module-specific parameters ---------------
  217. modparam("snmpstats", "sipEntityType", "registrarServer")
  218. modparam("snmpstats", "snmpgetPath", "/usr/bin/")
  219. modparam("ldap", "config_file", "/etc/kamailio/ldap.cfg")
  220. modparam("rtimer", "timer", "name=tst;interval=300;mode=1;")
  221. modparam("rtimer", "exec", "timer=tst;route=STATS")
  222.  
  223. modparam("sqlops","sqlcon","ca=>mysql://kamailio:kamailiorw@localhost/kamailio")
  224. modparam("htable", "htable", "stats=>size=6;")
  225.  
  226. # ----- mi_fifo params -----
  227. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  228.  
  229.  
  230. # ----- tm params -----
  231. # auto-discard branches from previous serial forking leg
  232. modparam("tm", "failure_reply_mode", 3)
  233. # default retransmission timeout: 30sec
  234. modparam("tm", "fr_timer", 30000)
  235. # default invite retransmission timeout after 1xx: 120sec
  236. modparam("tm", "fr_inv_timer", 120000)
  237.  
  238.  
  239. # ----- rr params -----
  240. # add value to ;lr param to cope with most of the UAs
  241. modparam("rr", "enable_full_lr", 1)
  242. # do not append from tag to the RR (no need for this script)
  243. modparam("rr", "append_fromtag", 0)
  244.  
  245.  
  246. # ----- registrar params -----
  247. modparam("registrar", "method_filtering", 1)
  248. /* uncomment the next line to disable parallel forking via location */
  249. # modparam("registrar", "append_branches", 0)
  250. /* uncomment the next line not to allow more than 10 contacts per AOR */
  251. #modparam("registrar", "max_contacts", 10)
  252. # max value for expires of registrations
  253. modparam("registrar", "max_expires", 3600)
  254. # set it to 1 to enable GRUU
  255. modparam("registrar", "gruu_enabled", 0)
  256.  
  257.  
  258. # ----- acc params -----
  259. /* what special events should be accounted ? */
  260. modparam("acc", "early_media", 0)
  261. modparam("acc", "report_ack", 0)
  262. modparam("acc", "report_cancels", 0)
  263. /* by default ww do not adjust the direct of the sequential requests.
  264. if you enable this parameter, be sure the enable "append_fromtag"
  265. in "rr" module */
  266. modparam("acc", "detect_direction", 0)
  267. /* account triggers (flags) */
  268. modparam("acc", "log_flag", FLT_ACC)
  269. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  270. modparam("acc", "log_extra",
  271. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  272. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  273. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  274. /* enhanced DB accounting */
  275. #!ifdef WITH_ACCDB
  276. modparam("acc", "db_flag", FLT_ACC)
  277. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  278. modparam("acc", "db_url", DBURL)
  279. modparam("acc", "db_extra",
  280. "src_user=$fU;src_domain=$fd;src_ip=$si;"
  281. "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  282. #!endif
  283.  
  284.  
  285. # ----- usrloc params -----
  286. /* enable DB persistency for location entries */
  287. #!ifdef WITH_USRLOCDB
  288. modparam("usrloc", "db_url", DBURL)
  289. modparam("usrloc", "db_mode", 2)
  290. modparam("usrloc", "use_domain", MULTIDOMAIN)
  291. #!endif
  292.  
  293.  
  294. # ----- auth_db params -----
  295. #!ifdef WITH_AUTH
  296. modparam("auth_db", "db_url", DBURL)
  297. modparam("auth_db", "calculate_ha1", yes)
  298. modparam("auth_db", "password_column", "password")
  299. modparam("auth_db", "load_credentials", "")
  300. modparam("auth_db", "use_domain", MULTIDOMAIN)
  301.  
  302. # ----- permissions params -----
  303. #!ifdef WITH_IPAUTH
  304. modparam("permissions", "db_url", DBURL)
  305. modparam("permissions", "db_mode", 1)
  306. #!endif
  307.  
  308. #!endif
  309.  
  310.  
  311. # ----- alias_db params -----
  312. #!ifdef WITH_ALIASDB
  313. modparam("alias_db", "db_url", DBURL)
  314. modparam("alias_db", "use_domain", MULTIDOMAIN)
  315. #!endif
  316.  
  317.  
  318. # ----- speeddial params -----
  319. #!ifdef WITH_SPEEDDIAL
  320. modparam("speeddial", "db_url", DBURL)
  321. modparam("speeddial", "use_domain", MULTIDOMAIN)
  322. #!endif
  323.  
  324.  
  325. # ----- domain params -----
  326. #!ifdef WITH_MULTIDOMAIN
  327. modparam("domain", "db_url", DBURL)
  328. # register callback to match myself condition with domains list
  329. modparam("domain", "register_myself", 1)
  330. #!endif
  331.  
  332.  
  333. #!ifdef WITH_PRESENCE
  334. # ----- presence params -----
  335. modparam("presence", "db_url", DBURL)
  336.  
  337. # ----- presence_xml params -----
  338. modparam("presence_xml", "db_url", DBURL)
  339. modparam("presence_xml", "force_active", 1)
  340. #!endif
  341.  
  342.  
  343. #!ifdef WITH_NAT
  344. # ----- rtpproxy params -----
  345. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  346.  
  347. # ----- nathelper params -----
  348. #changed from 30 to 15:
  349. modparam("nathelper", "natping_interval", 15)
  350. modparam("nathelper", "ping_nated_only", 1)
  351. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  352. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  353.  
  354. # params needed for NAT traversal in other modules
  355. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  356. modparam("usrloc", "nat_bflag", FLB_NATB)
  357. #!endif
  358.  
  359.  
  360. #!ifdef WITH_TLS
  361. # ----- tls params -----
  362. modparam("tls", "config", "/etc/kamailio/tls.cfg")
  363. #!endif
  364.  
  365. #!ifdef WITH_ANTIFLOOD
  366. # ----- pike params -----
  367. modparam("pike", "sampling_time_unit", 2)
  368. modparam("pike", "reqs_density_per_unit", 16)
  369. modparam("pike", "remove_latency", 4)
  370.  
  371. # ----- htable params -----
  372. # ip ban htable with autoexpire after 5 minutes
  373. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  374. #!endif
  375.  
  376. #!ifdef WITH_XMLRPC
  377. # ----- xmlrpc params -----
  378. modparam("xmlrpc", "route", "XMLRPC");
  379. modparam("xmlrpc", "url_match", "^/RPC")
  380. #!endif
  381.  
  382. #!ifdef WITH_DEBUG
  383. # ----- debugger params -----
  384. modparam("debugger", "cfgtrace", 1)
  385. #!endif
  386.  
  387. ####### Routing Logic ########
  388.  
  389.  
  390. # Main SIP request routing logic
  391. # - processing of any incoming SIP request starts with this route
  392. # - note: this is the same as route { ... }
  393. request_route {
  394.  
  395. # per request initial checks
  396. route(REQINIT);
  397.  
  398.  
  399. # NAT detection
  400. route(NATDETECT);
  401.  
  402. # CANCEL processing
  403. if (is_method("CANCEL"))
  404. {
  405. if (t_check_trans()) {
  406. route(RELAY);
  407. }
  408. exit;
  409. }
  410.  
  411. # handle requests within SIP dialogs
  412. route(WITHINDLG);
  413.  
  414. ### only initial requests (no To tag)
  415.  
  416. t_check_trans();
  417.  
  418.  
  419. # authentication
  420. route(AUTH);
  421.  
  422. # record routing for dialog forming requests (in case they are routed)
  423. # - remove preloaded route headers
  424. remove_hf("Route");
  425. if (is_method("INVITE|SUBSCRIBE"))
  426. record_route();
  427.  
  428. # account only INVITEs
  429. if (is_method("INVITE"))
  430. {
  431. setflag(FLT_ACC); # do accounting
  432. }
  433.  
  434. # dispatch requests to foreign domains
  435. route(SIPOUT);
  436.  
  437. ### requests for my local domains
  438.  
  439. # handle presence related requests
  440. route(PRESENCE);
  441.  
  442. # handle registrations
  443. route(REGISTRAR);
  444.  
  445. if ($rU==$null)
  446. {
  447. # request with no Username in RURI
  448. sl_send_reply("484","Address Incomplete");
  449. exit;
  450. }
  451.  
  452.  
  453. # dispatch destinations to PSTN
  454. #route(PSTN);
  455.  
  456. #Fwd to asterisk.
  457.  
  458. if (uri==myself) {
  459. if (method=="REGISTER") {
  460. save("location");
  461. break;
  462. };
  463. if(method=="INVITE") {
  464. if (uri =~ "sip:[2-4][0-9][0-9]@*") {
  465. route(3);
  466. break;
  467. }
  468. }
  469. lookup("aliases");
  470. if (!uri==myself) {
  471. append_hf("P-hint: outbound alias\r\n");
  472. route(1);
  473. break;
  474. };
  475. if (!lookup("location")) {
  476. sl_send_reply("404", "Not Found");
  477. break;
  478. };
  479. }
  480.  
  481. #end of routing to asterisk
  482.  
  483. # user location service
  484. route(LOCATION);
  485.  
  486. }
  487.  
  488. route[RELAY] {
  489.  
  490. # enable additional event routes for forwarded requests
  491. # - serial forking, RTP relaying handling, a.s.o.
  492. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
  493. if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
  494. }
  495. if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
  496. if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
  497. }
  498. if (is_method("INVITE")) {
  499. if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
  500. }
  501.  
  502. if (!t_relay()) {
  503. sl_reply_error();
  504. }
  505. exit;
  506. }
  507.  
  508. # Per SIP request initial checks
  509. route[REQINIT] {
  510. #!ifdef WITH_ANTIFLOOD
  511. # flood dection from same IP and traffic ban for a while
  512. # be sure you exclude checking trusted peers, such as pstn gateways
  513. # - local host excluded (e.g., loop to self)
  514. if(src_ip!=myself)
  515. {
  516. if($sht(ipban=>$si)!=$null)
  517. {
  518. # ip is already blocked
  519. xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  520. exit;
  521. }
  522. if (!pike_check_req())
  523. {
  524. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  525. $sht(ipban=>$si) = 1;
  526. exit;
  527. }
  528. }
  529. #!endif
  530.  
  531. if (!mf_process_maxfwd_header("10")) {
  532. sl_send_reply("483","Too Many Hops");
  533. exit;
  534. }
  535.  
  536. if(!sanity_check("1511", "7"))
  537. {
  538. xlog("Malformed SIP message from $si:$sp\n");
  539. exit;
  540. }
  541. }
  542.  
  543. # Handle requests within SIP dialogs
  544. route[WITHINDLG] {
  545. if (has_totag()) {
  546. # sequential request withing a dialog should
  547. # take the path determined by record-routing
  548. if (loose_route()) {
  549. route(DLGURI);
  550. if (is_method("BYE")) {
  551. setflag(FLT_ACC); # do accounting ...
  552. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  553. }
  554. else if ( is_method("ACK") ) {
  555. # ACK is forwarded statelessy
  556. route(NATMANAGE);
  557. }
  558. else if ( is_method("NOTIFY") ) {
  559. # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  560. record_route();
  561. }
  562. route(RELAY);
  563. } else {
  564. if (is_method("SUBSCRIBE") && uri == myself) {
  565. # in-dialog subscribe requests
  566. route(PRESENCE);
  567. exit;
  568. }
  569. if ( is_method("ACK") ) {
  570. if ( t_check_trans() ) {
  571. # no loose-route, but stateful ACK;
  572. # must be an ACK after a 487
  573. # or e.g. 404 from upstream server
  574. route(RELAY);
  575. exit;
  576. } else {
  577. # ACK without matching transaction ... ignore and discard
  578. exit;
  579. }
  580. }
  581. sl_send_reply("404","Not here");
  582. }
  583. exit;
  584. }
  585. }
  586.  
  587. # Handle SIP registrations
  588. route[REGISTRAR] {
  589. if (is_method("REGISTER"))
  590. {
  591. if(isflagset(FLT_NATS))
  592. {
  593. setbflag(FLB_NATB);
  594. # uncomment next line to do SIP NAT pinging
  595. setbflag(FLB_NATSIPPING);
  596. }
  597. if (!save("location"))
  598. sl_reply_error();
  599.  
  600. exit;
  601. }
  602. }
  603.  
  604. # USER location service
  605. route[LOCATION] {
  606.  
  607. #!ifdef WITH_SPEEDDIAL
  608. # search for short dialing - 2-digit extension
  609. if($rU=~"^[0-9][0-9]$")
  610. if(sd_lookup("speed_dial"))
  611. route(SIPOUT);
  612. #!endif
  613.  
  614. #!ifdef WITH_ALIASDB
  615. # search in DB-based aliases
  616. if(alias_db_lookup("dbaliases"))
  617. route(SIPOUT);
  618. #!endif
  619.  
  620. $avp(oexten) = $rU;
  621. if (!lookup("location")) {
  622. $var(rc) = $rc;
  623. route(TOVOICEMAIL);
  624. t_newtran();
  625. switch ($var(rc)) {
  626. case -1:
  627. case -3:
  628. send_reply("404", "Not Found");
  629. exit;
  630. case -2:
  631. send_reply("405", "Method Not Allowed");
  632. exit;
  633. }
  634. }
  635.  
  636. # when routing via usrloc, log the missed calls also
  637. if (is_method("INVITE"))
  638. {
  639. setflag(FLT_ACCMISSED);
  640. }
  641.  
  642. route(RELAY);
  643. exit;
  644. }
  645.  
  646. # Presence server route
  647. route[PRESENCE] {
  648. if(!is_method("PUBLISH|SUBSCRIBE"))
  649. return;
  650.  
  651. #!ifdef WITH_PRESENCE
  652. if (!t_newtran())
  653. {
  654. sl_reply_error();
  655. exit;
  656. };
  657.  
  658. if(is_method("PUBLISH"))
  659. {
  660. handle_publish();
  661. t_release();
  662. }
  663. else
  664. if( is_method("SUBSCRIBE"))
  665. {
  666. handle_subscribe();
  667. t_release();
  668. }
  669. exit;
  670. #!endif
  671.  
  672. # if presence enabled, this part will not be executed
  673. if (is_method("PUBLISH") || $rU==$null)
  674. {
  675. sl_send_reply("404", "Not here");
  676. exit;
  677. }
  678. return;
  679. }
  680.  
  681. # Authentication route
  682. route[AUTH] {
  683. if(is_method("REGISTER"))
  684. {
  685. if(is_present_hf("Authorization"))
  686. {
  687. # ldap search
  688. if (ldapsearch here)
  689. {
  690. switch ($retcode)
  691. {
  692. case -1:
  693. # no LDAP entry found
  694. sl_send_reply("404", "User Not Found");
  695. exit;
  696. case -2:
  697. # internal error
  698. sl_send_reply("500", "Internal server error");
  699. exit;
  700. default:
  701. exit;
  702. }
  703.  
  704. }
  705.  
  706. ldap_result("pager/$avp(s:username)");
  707. ldap_result("sippass/$avp(s:password)");
  708. xlog("L_INFO", "ldap_search: found [$retcode] entries for (uid=$fU)");
  709. if(!pv_www_authenticate("$td", "$avp(s:password)", "0")) {
  710. xlog ("L_INFO", "ldap pv_authenticate failed") ;
  711. www_challenge("$td","1");
  712. exit;
  713. }
  714.  
  715. xlog ("L_INFO", "ldap pv_authenticate ok") ;
  716. return;
  717. } else {
  718. www_challenge("$td","1");
  719. exit;
  720. }
  721. }
  722. }
  723.  
  724.  
  725. # Caller NAT detection route
  726. route[NATDETECT] {
  727. #!ifdef WITH_NAT
  728. force_rport();
  729. if (nat_uac_test("19")) {
  730. log(1, "=============NAT Detected=========== \n");
  731. if (is_method("REGISTER")) {
  732. fix_nated_register();
  733. } else {
  734. add_contact_alias();
  735. }
  736. setflag(FLT_NATS);
  737. }
  738. #!endif
  739. return;
  740. }
  741.  
  742. # RTPProxy control
  743. route[NATMANAGE] {
  744. #!ifdef WITH_NAT
  745. if (is_request()) {
  746. if(has_totag()) {
  747. if(check_route_param("nat=yes")) {
  748. setbflag(FLB_NATB);
  749. }
  750. }
  751. }
  752. if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
  753. return;
  754.  
  755. rtpproxy_manage("co");
  756.  
  757. if (is_request()) {
  758. if (!has_totag()) {
  759. if(t_is_branch_route()) {
  760. add_rr_param(";nat=yes");
  761. }
  762. }
  763. }
  764. if (is_reply()) {
  765. if(isbflagset(FLB_NATB)) {
  766. add_contact_alias();
  767. }
  768. }
  769. #!endif
  770. return;
  771. }
  772.  
  773. # URI update for dialog requests
  774. route[DLGURI] {
  775. #!ifdef WITH_NAT
  776. if(!isdsturiset()) {
  777. handle_ruri_alias();
  778. }
  779. #!endif
  780. return;
  781. }
  782.  
  783. # Routing to foreign domains
  784. route[SIPOUT] {
  785. if (!uri==myself)
  786. {
  787. append_hf("P-hint: outbound\r\n");
  788. route(RELAY);
  789. }
  790. }
  791.  
  792. # PSTN GW routing
  793. route[PSTN] {
  794. #!ifdef WITH_PSTN
  795. # check if PSTN GW IP is defined
  796. if (strempty($sel(cfg_get.pstn.gw_ip))) {
  797. xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");
  798. return;
  799. }
  800.  
  801. # route to PSTN dialed numbers starting with '+' or '00'
  802. # (international format)
  803. # - update the condition to match your dialing rules for PSTN routing
  804. if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))
  805. return;
  806.  
  807. # only local users allowed to call
  808. if(from_uri!=myself) {
  809. sl_send_reply("403", "Not Allowed");
  810. exit;
  811. }
  812.  
  813. if (strempty($sel(cfg_get.pstn.gw_port))) {
  814. $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
  815. } else {
  816. $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":"
  817. + $sel(cfg_get.pstn.gw_port);
  818. }
  819.  
  820. route(RELAY);
  821. exit;
  822. #!endif
  823.  
  824. return;
  825. }
  826.  
  827. # XMLRPC routing
  828. #!ifdef WITH_XMLRPC
  829. route[XMLRPC] {
  830. # allow XMLRPC from localhost
  831. if ((method=="POST" || method=="GET")
  832. && (src_ip==127.0.0.1)) {
  833. # close connection only for xmlrpclib user agents (there is a bug in
  834. # xmlrpclib: it waits for EOF before interpreting the response).
  835. if ($hdr(User-Agent) =~ "xmlrpclib")
  836. set_reply_close();
  837. set_reply_no_connect();
  838. dispatch_rpc();
  839. exit;
  840. }
  841. send_reply("403", "Forbidden");
  842. exit;
  843. }
  844. #!endif
  845.  
  846. # route to voicemail server
  847. route[TOVOICEMAIL] {
  848. #!ifdef WITH_VOICEMAIL
  849. if(!is_method("INVITE"))
  850. return;
  851.  
  852. # check if VoiceMail server IP is defined
  853. if (strempty($sel(cfg_get.voicemail.srv_ip))) {
  854. xlog("SCRIPT: VoiceMail rotuing enabled but IP not defined\n");
  855. return;
  856. }
  857. if($avp(oexten)==$null)
  858. return;
  859.  
  860. $ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip)
  861. + ":" + $sel(cfg_get.voicemail.srv_port);
  862. route(RELAY);
  863. exit;
  864. #!endif
  865.  
  866. return;
  867. }
  868.  
  869. # manage outgoing branches
  870. branch_route[MANAGE_BRANCH] {
  871. xdbg("new branch [$T_branch_idx] to $ru\n");
  872. route(NATMANAGE);
  873. }
  874.  
  875. # manage incoming replies
  876. onreply_route[MANAGE_REPLY] {
  877. xdbg("incoming reply\n");
  878. if(status=~"[12][0-9][0-9]")
  879. route(NATMANAGE);
  880. }
  881.  
  882. # manage failure routing cases
  883. failure_route[MANAGE_FAILURE] {
  884. route(NATMANAGE);
  885.  
  886. if (t_is_canceled()) {
  887. exit;
  888. }
  889.  
  890. #!ifdef WITH_BLOCK3XX
  891. # block call redirect based on 3xx replies.
  892. if (t_check_status("3[0-9][0-9]")) {
  893. t_reply("404","Not found");
  894. exit;
  895. }
  896. #!endif
  897.  
  898. #!ifdef WITH_VOICEMAIL
  899. # serial forking
  900. # - route to voicemail on busy or no answer (timeout)
  901. if (t_check_status("486|408")) {
  902. $du = $null;
  903. route(TOVOICEMAIL);
  904. exit;
  905. }
  906. #!endif
  907. }
  908.  
  909.  
  910. route[1]
  911. {
  912. if (!t_relay()) {
  913. sl_reply_error();
  914. log(1, "=================Error=============== \n");
  915. };
  916. }
  917. route[3]{
  918. log(1, "=============Forwarding to Asterisk=========== \n");
  919. rewritehostport("127.0.0.1:5080");
  920. route(1);
  921. break;
  922. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement