test.cfg 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #
  2. # $Id$
  3. #
  4. # iptel.org real world configuration
  5. #
  6. # ----------- global configuration parameters ------------------------
  7. debug=3 # debug level (cmd line: -dddddddddd)
  8. #fork=yes
  9. fork=no
  10. #log_stderror=no # (cmd line: -E)
  11. log_stderror=yes # (cmd line: -E)
  12. check_via=yes # (cmd. line: -v)
  13. dns=on # (cmd. line: -r)
  14. rev_dns=yes # (cmd. line: -R)
  15. #port=5060
  16. port=8060
  17. children=1
  18. # advertise IP address in Via (as opposed to advertising DNS name
  19. # which is annoying for downstream servers and some phones can
  20. # not handle DNS at all)
  21. listen=195.37.77.100
  22. # ------------------ module loading ----------------------------------
  23. loadmodule "../sip_router/modules/sl/sl.so"
  24. loadmodule "../sip_router/modules/print/print.so"
  25. loadmodule "../sip_router/modules/tm/tm.so"
  26. loadmodule "../sip_router/modules/acc/acc.so"
  27. loadmodule "../sip_router/modules/rr/rr.so"
  28. loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
  29. loadmodule "../sip_router/modules/mysql/mysql.so"
  30. loadmodule "../sip_router/modules/usrloc/usrloc.so"
  31. loadmodule "../sip_router/modules/auth/auth.so"
  32. loadmodule "../sip_router/modules/cpl/cpl.so"
  33. # ----------------- setting module-specific parameters ---------------
  34. # -- usrloc params --
  35. modparam("usrloc", "use_database", 1)
  36. modparam("usrloc", "table", "location")
  37. modparam("usrloc", "user_column", "user")
  38. modparam("usrloc", "contact_column", "contact")
  39. modparam("usrloc", "expires_column", "expires")
  40. modparam("usrloc", "q_column", "q")
  41. modparam("usrloc", "callid_column", "callid")
  42. modparam("usrloc", "cseq_column", "cseq")
  43. modparam("usrloc", "flush_interval", 60)
  44. modparam("usrloc", "db_url", "sql://csps:47csps11@dbhost/csps107")
  45. # -- auth params --
  46. modparam("auth", "db_url", "sql://csps:47csps11@dbhost/csps107")
  47. modparam("auth", "user_column", "user")
  48. # nonce generation secret; particularly useful if multiple servers
  49. # in a proxy farm are configured to authenticate
  50. modparam("auth", "secret", "439tg8h349g8hq349t9384hg")
  51. # calculate_ha1=false means password column includes ha1 strings;
  52. # if it was false, plain-text passwords would be assumed
  53. modparam("auth", "calculate_ha1", false)
  54. modparam("auth", "nonce_expire", 300)
  55. modparam("auth", "retry_count", 5)
  56. # password_column, realm_column, group_table, group_user_column,
  57. # group_group_column are set to their default values
  58. # password_column_2 allows to deal with clients who put domain name
  59. # in authentication credentials when calculate_ha1=false (if true,
  60. # it works); if set to a value and USER_DOMAIN_HACK was enabled
  61. # in defs.h, authentication will still work
  62. # -- acc params --
  63. # report ACKs too for sake of completeness -- as we account PSTN
  64. # destinations which are RR, ACKs should show up
  65. modparam("acc", "report_ack", 1)
  66. # don't bother me with early media reports (I don't like 183
  67. # too much anyway...ever thought of timer C hitting after
  68. # listening to music-on-hold for five minutes?)
  69. modparam("acc", "early_media", 0)
  70. modparam("acc", "log_level", 1)
  71. # that is the flag for which we will account -- don't forget to
  72. # set the same one :-)
  73. modparam("acc", "acc_flag", 1 )
  74. # we are interested only in succesful transactions
  75. modparam("acc", "failed_transactions", 0 )
  76. # -- tm params --
  77. modparam("tm", "fr_timer", 10 )
  78. modparam("tm", "fr_inv_timer", 30 )
  79. # ------------------------- request routing logic -------------------
  80. # main routing logic
  81. route{
  82. # filter local stateless ACK generated by authentication of mf replies
  83. sl_filter_ACK();
  84. # filter too old messages
  85. log("Checking maxfwd\n");
  86. if (!mf_process_maxfwd_header("10")) {
  87. log("Too many hops\n");
  88. sl_send_reply("483","Too Many Hops");
  89. break;
  90. };
  91. # Do strict routing if route headers present
  92. rewriteFromRoute();
  93. # divert voicemail requests
  94. if (uri=~"mail\.iptel\.org" | uri=~":5066") {
  95. log("Request is for voicemail\n");
  96. sethost("iptel.org");
  97. t_relay_to("fox.iptel.org", "5066");
  98. break;
  99. };
  100. # if this request is not for our domain, fall over to
  101. # outbound request processing; include gateway's address
  102. # in matching too -- we RR requests to it, so that
  103. # its address may show up in subsequent requests
  104. # after rewriteFromRoute
  105. if (!(uri=~"[@:]iptel\.org([;:].*)*"
  106. | uri=~"[@:]195\.37\.77\.101([;:].*)*" |
  107. uri=~"@195\.37\.77\.110([;:].*)*" )) {
  108. route(2);
  109. };
  110. # here we continue with requests for our domain...
  111. # various aliases (might use a database in future)
  112. if (uri=~"sip:9040@") {
  113. seturi("[email protected]");
  114. };
  115. if (uri=~"sip:17@") {
  116. seturi("sip:[email protected]");
  117. };
  118. # check again, if it is still for our domain after aliases
  119. if ( !(uri=~"[@:]iptel\.org([;:].*)*" |
  120. uri=~"[@:]195\.37\.77\.101([;:].*)*" |
  121. uri=~"@195\.37\.77\.110([;:].*)*" )) {
  122. route(2);
  123. };
  124. log("Request is for iptel.org\n");
  125. # registers always MUST be authenticated to
  126. # avoid stealing incoming calls
  127. if (method=="REGISTER") {
  128. log("Request is REGISTER\n");
  129. if (!www_authorize( "iptel.org" /* realm */,
  130. "subscriber" /* table name */ )) {
  131. log("REGISTER has no credentials, sending challenge\n");
  132. www_challenge( "iptel.org" /* realm */,
  133. "0" /* no qop -- M$ can't deal with it */);
  134. break;
  135. };
  136. # prohibit attempts to grab someone else's To address
  137. # using valid credentials
  138. if (!check_to()) {
  139. log("To Cheating attempt\n");
  140. sl_send_reply("403", "That is ugly -- use To=id next time");
  141. break;
  142. };
  143. # update Contact database
  144. log("REGISTER is authorized, saving location\n");
  145. save_contact("location");
  146. break;
  147. };
  148. # now check if it's about PSTN destinations through our gateway;
  149. # note that 8.... is exempted for numerical destinations
  150. if (uri=~"sip:[0-79][0-9]*@.*") {
  151. route(3);
  152. };
  153. # ---------- demo - begin --------------
  154. /* added by Bogdan for cpl demo - Dorgham request*/
  155. if (uri=~"sip:test@.*" && method=="INVITE")
  156. {
  157. log("SER : runing CPL!! :)\n");
  158. if ( !cpl_run_script() )
  159. {
  160. log("SER : Error during running CPL script!\n");
  161. }else{
  162. if ( cpl_is_response_reject() ) {
  163. log("SER: reject");
  164. sl_send_reply("603","I am not available!");
  165. break;
  166. }else if ( cpl_is_response_redirect() ) {
  167. log("SER : redirect\n");
  168. cpl_update_contact();
  169. sl_send_reply("302","Moved temporarily");
  170. break;
  171. };
  172. };
  173. };
  174. # -------------- demo - end -------------
  175. # native SIP destinations are handled using our USRLOC DB
  176. if (!lookup_contact("location")) {
  177. log("Unable to lookup contact, sending 404\n");
  178. sl_send_reply("404", "Not Found");
  179. break;
  180. };
  181. # check whether some inventive user has uploaded gateway
  182. # contacts to UsrLoc to bypass our authorization logic
  183. if (uri=~"@195\.37\.77\.110([;:].*)*" ) {
  184. log("Weird! Gateway address in UsrLoc!\n");
  185. route(3);
  186. };
  187. # requests from gateway should be RR-ed too
  188. if (src_ip==195.37.77.110 && method=="INVITE") {
  189. addRecordRoute();
  190. };
  191. # we now know we may, we know where, let it go out now!
  192. t_relay();
  193. }
  194. # routing logic for outbound requests targeted out of our domain
  195. route[2] {
  196. # outbound requests are allowed only for our users -- we don't
  197. # support relaying and don't like strangers bothering us
  198. # with resolving DNS
  199. log("that's a request to outside");
  200. if (!(src_ip==195.37.77.110) &
  201. !(proxy_authorize( "iptel.org" /* realm */,
  202. "subscriber" /* table name */ ))) {
  203. # see comments bellow on these ACK/CANCEL exceptions
  204. if (method=="ACK" ) {
  205. log("failed outbound authentication for ACK granted");
  206. } else if (method=="CANCEL") {
  207. log("failed outbound authentication for ACK granted");
  208. } else proxy_challenge("iptel.org" /* realm */, "0" /* no-qop */);
  209. break;
  210. };
  211. # to maintain credibility of our proxy, we check From to be
  212. # equal of credential id -- all outbound request leaving our
  213. # proxy are guaranteed to be generated by persons in "From"
  214. if (!check_from()) {
  215. log("From Cheating attempt\n");
  216. sl_send_reply("403", "That is ugly -- use From=id next time");
  217. break;
  218. };
  219. t_relay();
  220. }
  221. # logic for calls through our PSTN gateway
  222. route[3] {
  223. # free call destinations ... no authentication needed
  224. if (uri=~"sip:001795061546@.*" | uri=~"sip:0016097265544.*"
  225. | uri=~"sip:[79][0-9][0-9][0-9]@.*") {
  226. log("Free PSTN\n");
  227. } else {
  228. # all other PSTN destinations only for authenticated users
  229. # (Cisco GW, which has no digest support, is authenticated
  230. # by its IP address -- that's for sure not very strong;
  231. # wth confirmed that we filter packets coming from outside
  232. # and bearing SRC IP address of our network)
  233. if (!(src_ip==195.37.77.110) &
  234. !(proxy_authorize( "iptel.org" /* realm */,
  235. "subscriber" /* table name */))) {
  236. # we are forgiving and ignore improper credentials
  237. # for ACK/CANCEL as bis-09 is somewhat cryptic about
  238. # its use and many UACs have not gotten it right
  239. if (method=="ACK" ) {
  240. log("failed gw authentication for ACK granted");
  241. } else if (method=="CANCEL") {
  242. log("failed gw authentication for ACK granted");
  243. } else proxy_challenge( "iptel.org" /* realm */,
  244. "0" /* no qop */ );
  245. break;
  246. };
  247. # authorize only for INVITEs -- RR/Contact may result in weird
  248. # things showing up in d-uri that would break our logic; our
  249. # major concern is INVITE which causes PSTN costs anyway
  250. if (method=="INVITE") {
  251. # does the authenticated user have a permission for local
  252. # calls? (i.e., is he in the "local" group?)
  253. if (uri=~"sip:0[1-9][0-9]+@.*") {
  254. if (!is_in_group("local")) {
  255. sl_send_reply("403", "Local Toodle Noodle...");
  256. break;
  257. };
  258. # the same for long-distance
  259. } else if (uri=~"sip:00[1-9][0-9]+@.*") {
  260. if (uri=~"sip:001[089]" | uri=~"sip:00900.*" ) {
  261. sl_send_reply("403", "Added Value Destinations not permitted...");
  262. break;
  263. };
  264. if (!is_in_group("ld")) {
  265. sl_send_reply("403", "LD Toodle Noodle...");
  266. break;
  267. };
  268. # the same for international calls
  269. } else if (uri=~"sip:000[1-9][0-9]+@.*") {
  270. if (!is_in_group("int")) {
  271. sl_send_reply("403", "International Toodle Noodle...");
  272. break;
  273. };
  274. # everything else (e.g., interplanetary calls) is denied
  275. } else {
  276. sl_send_reply("403", "interplanetary Toodle Noodle...");
  277. break;
  278. };
  279. }; # INVITE to authorized PSTN
  280. }; # authorized PSTN
  281. # requests to gateway must be record-route because the GW accepts
  282. # only reqeusts coming from our proxy
  283. if (method=="INVITE")
  284. addRecordRoute();
  285. # if you have passed through all the checks, let your call go to GW!
  286. rewritehostport("195.37.77.110:5060");
  287. # tag this transaction for accounting
  288. setflag(1);
  289. t_relay();
  290. }