secondary.cfg 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #
  2. # iptel.org real world configuration for secondary host
  3. #
  4. # $Id$
  5. #
  6. debug=3 # debug level (cmd line: -dddddddddd)
  7. #fork=yes
  8. fork=no
  9. #log_stderror=no # (cmd line: -E)
  10. log_stderror=yes # (cmd line: -E)
  11. check_via=yes # (cmd. line: -v)
  12. dns=on # (cmd. line: -r)
  13. rev_dns=yes # (cmd. line: -R)
  14. port=5060
  15. children=1
  16. # advertise IP address in Via (as opposed to advertising DNS name
  17. # which is annoying for downstream servers and some phones can
  18. # not handle DNS at all)
  19. listen=195.37.77.100
  20. loadmodule "../sip_router/modules/sl/sl.so"
  21. loadmodule "../sip_router/modules/print/print.so"
  22. loadmodule "../sip_router/modules/tm/tm.so"
  23. loadmodule "../sip_router/modules/acc/acc.so"
  24. loadmodule "../sip_router/modules/rr/rr.so"
  25. loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
  26. loadmodule "../sip_router/modules/mysql/mysql.so"
  27. loadmodule "../sip_router/modules/usrloc/usrloc.so"
  28. loadmodule "../sip_router/modules/auth/auth.so"
  29. loadmodule "../sip_router/modules/cpl/cpl.so"
  30. modparam("usrloc", "use_database", 1)
  31. modparam("usrloc", "use_database", 0)
  32. modparam("usrloc", "table", "location")
  33. modparam("usrloc", "user_column", "user")
  34. modparam("usrloc", "contact_column", "contact")
  35. modparam("usrloc", "expires_column", "expires")
  36. modparam("usrloc", "q_column", "q")
  37. modparam("usrloc", "callid_column", "callid")
  38. modparam("usrloc", "cseq_column", "cseq")
  39. modparam("usrloc", "flush_interval", 60)
  40. modparam("usrloc", "db_url", "sql://csps:47csps11@dbhost/csps107")
  41. modparam("auth", "db_url", "sql://csps:47csps11@dbhost/csps107")
  42. modparam("auth", "table", "subscriber")
  43. modparam("auth", "user_column", "user")
  44. route{
  45. # filter local stateless ACK generated by authentication of mf replies
  46. sl_filter_ACK();
  47. # filter too old messages
  48. log("Checking maxfwd\n");
  49. if (!mf_process_maxfwd_header("10")) {
  50. log("Too many hops\n");
  51. sl_send_reply("483","Too Many Hops");
  52. break;
  53. };
  54. # Do strict routing if route headers present
  55. rewriteFromRoute();
  56. # divert voicemail requests
  57. if (uri=~"mail\.iptel\.org" | uri=~":5066") {
  58. log("Request is for voicemail\n");
  59. sethost("iptel.org");
  60. t_relay_to("fox.iptel.org", "5066");
  61. break;
  62. };
  63. # process requests for iptel.org (note the wildcard in
  64. # the regex end -- that captures URIs which have port
  65. # numbers or parameters in them); also include gateway
  66. # here too -- we RR to the gateway which means that its
  67. # address shows up in d-uri of subsequent requests after
  68. # having called rewriteFromRoute and we want the requests
  69. # to go through our PSTN authorization code
  70. if (uri=~"[@:]iptel\.org([;:].*)*" | uri=~"[@:]195\.37\.77\.101([;:].*)*" |
  71. uri=~"@195\.37\.77\.110([;:].*)*" ) {
  72. log("Request is for iptel.org\n");
  73. # registers always MUST be authenticated to
  74. # avoid stealing incoming calls
  75. if (method=="REGISTER") {
  76. log("Request is REGISTER\n");
  77. if (!authorize("iptel.org")) {
  78. log("REGISTER has no credentials, sending challenge\n");
  79. challenge("iptel.org", "noqop");
  80. break;
  81. };
  82. # prohibit attempts to grab someone else's To address
  83. # using valid credentials
  84. if (!check_to()) {
  85. log("Cheating attempt\n");
  86. sl_send_reply("403", "What a nasty guy you are");
  87. break;
  88. };
  89. # update Contact database
  90. log("REGISTER is authorized, saving location\n");
  91. save_contact("location");
  92. break;
  93. };
  94. # various aliases (might use a database in future)
  95. if (uri=~"sip:9040@.*") {
  96. setuser("jiri");
  97. };
  98. # special measure for our US friends
  99. if (uri=~"sip:17@") {
  100. seturi("sip:[email protected]");
  101. };
  102. # if (uri=~"sip:jiri@.*" & method=="INVITE") {
  103. # t_fork_to("[email protected]");
  104. # };
  105. # if (uri=~"sip:jiri@.*" & method=="INVITE") {
  106. # t_fork_to("195.37.77.110", "5060");
  107. # };
  108. # now it's about PSTN destinations through our gateway;
  109. # note that 8.... is exempted for numerical destinations
  110. if (uri=~"sip:[0-79][0-9]*@.*") {
  111. # label this transaction to be accounted
  112. t_setflag("acc");
  113. # free call destinations ... no authentication needed
  114. if (uri=~"sip:001795061546@.*" | uri=~"sip:0016097265544.*" | uri=~"sip:[79][0-9][0-9][0-9]@.*") {
  115. log("Free PSTN\n");
  116. } else {
  117. # all other PSTN destinations only for authenticated users
  118. # (Cisco GW, which has no digest support, is authenticated
  119. # by its IP address -- that's for sure not very strong;
  120. # wth confirmed that we filter packets coming from outside
  121. # and bearing SRC IP address of a Fokus network)
  122. if (!(src_ip==195.37.77.110) & !(authorize("iptel.org"))) {
  123. challenge("iptel.org", "noqop");
  124. break;
  125. };
  126. # authorize only for INVITEs -- RR/Contact may result in weird
  127. # things showing up in d-uri that would break our logic; our
  128. # major concern is INVITE which causes PSTN costs anyway
  129. if (method=="INVITE") {
  130. # does the authenticated user have a permission for local
  131. # calls? (i.e., is he in the "local" group?)
  132. if (uri=~"sip:0[1-9][0-9]+@.*") {
  133. if (!is_in_group("local")) {
  134. sl_send_reply("403", "Local Toodle Noodle...");
  135. break;
  136. };
  137. # the same for long-distance
  138. } else if (uri=~"sip:00[1-9][0-9]+@.*") {
  139. if (uri=~"sip:001[089]" | uri=~"sip:00900.*" ) {
  140. sl_send_reply("403", "Added Value Destinations not permitted...");
  141. break;
  142. };
  143. if (!is_in_group("ld")) {
  144. sl_send_reply("403", "LD Toodle Noodle...");
  145. break;
  146. };
  147. # the same for international calls
  148. } else if (uri=~"sip:000[1-9][0-9]+@.*") {
  149. if (!is_in_group("int")) {
  150. sl_send_reply("403", "International Toodle Noodle...");
  151. break;
  152. };
  153. # everything else (e.g., interplanetary calls) is denied
  154. } else {
  155. sl_send_reply("403", "interplanetary Toodle Noodle...");
  156. break;
  157. };
  158. };
  159. ;
  160. };
  161. # requests to gateway must be record-route because the GW accepts
  162. # only reqeusts coming from our proxy
  163. if (method=="INVITE")
  164. addRecordRoute();
  165. # if you have passed through all the checks, let your call go to GW!
  166. rewritehostport("195.37.77.110:5060");
  167. } else {
  168. /* added by Bogdan for cpl demo - Dorgham request*/
  169. if (uri=~"sip:test@.*" && method=="INVITE")
  170. {
  171. log("SER : runing CPL!! :)\n");
  172. if ( !cpl_run_script() )
  173. {
  174. log("SER : Error during running CPL script!\n");
  175. }else{
  176. if ( cpl_is_response_reject() ) {
  177. log("SER: reject");
  178. sl_send_reply("603","I am not available!");
  179. break;
  180. }else if ( cpl_is_response_redirect() ) {
  181. log("SER : redirect\n");
  182. cpl_update_contact();
  183. sl_send_reply("302","Moved temporarily");
  184. break;
  185. };
  186. };
  187. };
  188. # native SIP destinations are handled using our USRLOC DB
  189. if (!lookup_contact("location")) {
  190. log("Unable to lookup contact, sending 404\n");
  191. sl_send_reply("404", "Not Found");
  192. break;
  193. };
  194. # requests from gateway should be RR-ed too
  195. if (src_ip==195.37.77.110 && method=="INVITE") {
  196. addRecordRoute();
  197. };
  198. };
  199. } else {
  200. # outbound requests are allowed only for our users -- we don't
  201. # support relaying and don't like strangers bothering us
  202. # with resolving DNS
  203. log("that's a request to outside");
  204. if (!(src_ip==195.37.77.110) & !(authorize("iptel.org"))) {
  205. challenge("iptel.org", "noqop");
  206. break;
  207. };
  208. # there should be check_from here too -- but I'm to tired
  209. # to test it tonight
  210. };
  211. # we now know we may, we now where, let it go out now!
  212. t_relay();
  213. }