im_gw.cfg 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. ### ----- IM Gateway [SMS+Jabber] config file for 'bat.iptel.org' ----
  2. # ----------- global configuration parameters ------------------------
  3. debug=9 # debug level (cmd line: -dddddddddd)
  4. #fork=yes
  5. #fork=no
  6. #log_stderror=no # (cmd line: -E)
  7. log_stderror=yes # (cmd line: -E)
  8. check_via=yes # (cmd. line: -v)
  9. dns=on # (cmd. line: -r)
  10. rev_dns=yes # (cmd. line: -R)
  11. port=5070
  12. children=2
  13. # advertise IP address in Via (as opposed to advertising DNS name
  14. # which is annoying for downstream servers and some phones can
  15. # not handle DNS at all)
  16. listen=195.37.77.100
  17. # ------------------ module loading ----------------------------------
  18. loadmodule "../sip_router/modules/sl/sl.so"
  19. loadmodule "../sip_router/modules/print/print.so"
  20. loadmodule "../sip_router/modules/tm/tm_mod.so"
  21. loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
  22. loadmodule "../sip_router/modules/sms/sms.so"
  23. loadmodule "../sip_router/modules/textops/textops.so"
  24. loadmodule "../sip_router/modules/mysql/mysql.so"
  25. loadmodule "../sip_router/modules/jabber/jabber.so"
  26. loadmodule "../sip_router/modules/pike/pike.so"
  27. # ----------------- setting module-specific parameters ---------------
  28. # -- sms params --
  29. modparam("sms","modems","Falcom [d=/dev/ttyS0;b=9600;p=9254;m=new;l=10;r=2]")
  30. modparam("sms","networks","D1[c=491710765000;m=10]")
  31. modparam("sms","links","Falcom[D1]")
  32. modparam("sms","domain","iptel.org")
  33. modparam("sms","max_sms_parts",3)
  34. modparam("sms","use_contact",1)
  35. # -- tm params --
  36. modparam("tm", "fr_timer", 10 )
  37. modparam("tm", "fr_inv_timer", 10 )
  38. modparam("tm", "wt_timer", 10 )
  39. # -- pike params --
  40. # no more than minimum 5 or maximum 5*3 msg per 10 secs - only for sms
  41. modparam("pike","sampling_time_unit",60)
  42. modparam("pike","reqs_density_per_unit",5)
  43. modparam("pike","removel_latency",30)
  44. # -- jabber params --
  45. modparam("jabber","db_url","mysql://s2jgw:[email protected]/sip_jab")
  46. modparam("jabber","jaddress","bat.iptel.org")
  47. modparam("jabber","jport",5222)
  48. modparam("jabber","workers",2)
  49. modparam("jabber","max_jobs",10)
  50. modparam("jabber","delay_time",17)
  51. modparam("jabber","cache_time",1800)
  52. # ------------------------- request routing logic -------------------
  53. # main routing logic
  54. route{
  55. # filter too old messages
  56. log("LOG: Checking maxfwd\n");
  57. if (!mf_process_maxfwd_header("10")) {
  58. log("LOG: Too many hops\n");
  59. sl_send_reply("483","Too Many Hops");
  60. break;
  61. };
  62. # messages too large are denied
  63. if (len_gt( max_len )) {
  64. sl_send_reply("513", "Riesengross -- Message too large");
  65. break;
  66. };
  67. # accept only req coming from iptel.org
  68. if (!src_ip==195.37.77.101 |
  69. !( uri=~"iptel.org" | uri=~"195\.37\.77\.100" ))
  70. {
  71. sl_send_reply("403","Forbidden");
  72. log("SER:Forbidden request: wrong src_ip or req_uri\n");
  73. break;
  74. };
  75. # we are not interested in non-MESSAGE requests
  76. if (!method=="MESSAGE")
  77. {
  78. sl_send_reply("501","Not Implemented");
  79. break;
  80. };
  81. # error occurred ...
  82. if (! t_newtran())
  83. {
  84. sl_reply_error();
  85. break;
  86. };
  87. # do what you want to do - first, it's for SMS or JABBER ?
  88. if ( search("To:.*@icq\.iptel\.org")
  89. | search("To:.*@msn\.iptel\.org")
  90. | search("To:.*@aim\.iptel\.org")
  91. | search("To:.*@yahoo\.iptel\.org") )
  92. {
  93. ### ----- JABBER GATEWAY ------
  94. log("MESSAGE received -> sending as JABBER\n");
  95. if (jab_send_message())
  96. {
  97. if (!t_reply("202","Accepted"))
  98. {
  99. # if replying failed, retry statelessly
  100. sl_reply_error();
  101. };
  102. }else{
  103. if (!t_reply("502","Bad gateway - IM error"))
  104. {
  105. # if replying failed, retry statelessly
  106. sl_reply_error();
  107. };
  108. };
  109. break; # End of Jabber
  110. };
  111. ### ------ SMS GATEWAY --------
  112. # let's block ips that send a lot of request!!
  113. if (!pike_check_req() )
  114. {
  115. break;
  116. };
  117. # SMS expects only the numbers as follows +<int> <area> <nr>
  118. if (!(uri=~"sip:+[^0][0-9]{3}"))
  119. {
  120. log("SER: invalid number format!!\n");
  121. if (!t_reply("502","Bad gateway - invalid number"))
  122. {
  123. # if replying failed, retry statelessly
  124. sl_reply_error();
  125. };
  126. break;
  127. };
  128. if (sms_send_msg_to_net("D1"))
  129. {
  130. # for sending replies, we woun't use the statefull
  131. # function because it is not able to add the Contact
  132. # header (in fact to add any rpl_lump :-( )
  133. # things went well, send ok upstream
  134. if (!t_reply("202", "yes sir, SMS sent over"))
  135. {
  136. # if replying failed, retry statelessly
  137. sl_reply_error();
  138. };
  139. } else {
  140. if (!t_reply("502", "Bad gateway - SMS error"))
  141. {
  142. # if replying failed, retry statelessly
  143. sl_reply_error();
  144. };
  145. break;
  146. };
  147. }