Advertisement
Guest User

Untitled

a guest
Jul 16th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. route{
  2. if($ua =~ "friendly-scanner"){
  3. # estamos identificando o tipo de ataque baseado no user agente e saindo sem resposta
  4. # neste caso a tendencia é que ele para de tentar
  5. xlog("L_NOTICE", "Auth error for $fU@$fd from $si cause -1");
  6. xlog("FRIENDLY-SCANNER: UA: $ua From_TAG: $ft From_URI: $fu Received IP: $Ri IP SOURCE: $si");
  7. exit;
  8. }
  9.  
  10. force_rport();
  11. if (nat_uac_test("23")) {
  12. if (is_method("REGISTER")) {
  13. fix_nated_register();
  14. setbflag(NAT);
  15. } else {
  16. fix_nated_contact();
  17. setflag(NAT);
  18. }
  19. }
  20.  
  21.  
  22. if (!mf_process_maxfwd_header("10")) {
  23. sl_send_reply("483","Too Many Hops");
  24. exit;
  25. }
  26.  
  27. if(method=="OPTIONS"){
  28. sl_send_reply("200", "OK");
  29. exit;
  30. }
  31.  
  32. if (has_totag()) {
  33. # sequential request withing a dialog should
  34. # take the path determined by record-routing
  35. if (loose_route()) {
  36.  
  37. # validate the sequential request against dialog
  38. if ( $DLG_status!=NULL && !validate_dialog() ) {
  39. xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
  40. ## exit;
  41. }
  42.  
  43. if (is_method("BYE")) {
  44. setflag(ACC_DO); # do accounting ...
  45. setflag(ACC_FAILED); # ... even if the transaction fails
  46. } else if (is_method("INVITE")) {
  47. # even if in most of the cases is useless, do RR for
  48. # re-INVITEs alos, as some buggy clients do change route set
  49. # during the dialog.
  50. record_route();
  51. }
  52.  
  53. if (check_route_param("nat=yes"))
  54. setflag(NAT);
  55.  
  56. # route it out to whatever destination was set by loose_route()
  57. # in $du (destination URI).
  58. route(relay);
  59. } else {
  60. if (is_method("SUBSCRIBE") && $rd == "127.0.0.1:5060") { # CUSTOMIZE ME
  61. # in-dialog subscribe requests
  62. route(handle_presence);
  63. exit;
  64. }
  65. if ( is_method("ACK") ) {
  66. if ( t_check_trans() ) {
  67. # non loose-route, but stateful ACK; must be an ACK after
  68. # a 487 or e.g. 404 from upstream server
  69. t_relay();
  70. exit;
  71. } else {
  72. # ACK without matching transaction ->
  73. # ignore and discard
  74. exit;
  75. }
  76. }
  77. sl_send_reply("404","Not here");
  78. }
  79. exit;
  80. }
  81.  
  82. # CANCEL processing
  83. if (is_method("CANCEL"))
  84. {
  85. if (t_check_trans())
  86. t_relay();
  87. exit;
  88. }
  89.  
  90. t_check_trans();
  91.  
  92. if ( !(is_method("REGISTER") && is_from_local()) ) {
  93.  
  94.  
  95. # authenticate if from local subscriber
  96. # authenticate all initial non-REGISTER request that pretend to be
  97. # generated by local subscriber (domain from FROM URI is local)
  98. if (!proxy_authorize("", "subscriber")) {
  99. proxy_challenge("", "0");
  100. exit;
  101. }
  102. if (!db_check_from()) {
  103. sl_send_reply("403","Forbidden auth ID");
  104. exit;
  105. }
  106.  
  107. consume_credentials();
  108. # caller authenticated
  109.  
  110. } else {
  111. # if caller is not local, then called number must be local
  112.  
  113. if (!is_uri_host_local()) {
  114. send_reply("403","Rely forbidden");
  115. exit;
  116. }
  117. }
  118.  
  119. # preloaded route checking
  120. if (loose_route()) {
  121. xlog("L_ERR",
  122. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  123. if (!is_method("ACK"))
  124. sl_send_reply("403","Preload Route denied");
  125. exit;
  126. }
  127.  
  128. # record routing
  129. if (!is_method("REGISTER|MESSAGE"))
  130. record_route();
  131.  
  132. # account only INVITEs
  133. if (is_method("INVITE")) {
  134.  
  135. # create dialog with timeout
  136. if ( !create_dialog("B") ) {
  137. send_reply("500","Internal Server Error");
  138. exit;
  139. }
  140.  
  141. setflag(ACC_DO); # do accounting
  142. }
  143.  
  144.  
  145. if (!is_uri_host_local()) {
  146. append_hf("P-hint: outbound\r\n");
  147.  
  148. route(relay);
  149. }
  150.  
  151. # requests for my domain
  152.  
  153. if( is_method("PUBLISH|SUBSCRIBE"))
  154. route(handle_presence);
  155.  
  156. if (!is_method("REGISTER"))
  157. record_route();
  158.  
  159. if (is_method("REGISTER"))
  160. {
  161.  
  162. # authenticate the REGISTER requests
  163. if (!www_authorize("", "subscriber"))
  164. {
  165. www_challenge("", "0");
  166. exit;
  167. }
  168.  
  169. if (!db_check_to())
  170. {
  171. sl_send_reply("403","Forbidden auth ID");
  172. exit;
  173. }
  174.  
  175. if ( 0 ) setflag(TCP_PERSISTENT);
  176.  
  177. if (!save("location"))
  178. sl_reply_error();
  179.  
  180. exit;
  181. }
  182.  
  183. if ($rU==NULL) {
  184. # request with no Username in RURI
  185. sl_send_reply("484","Address Incomplete");
  186. exit;
  187. }
  188.  
  189.  
  190. if ($rU=~"^0+") {
  191.  
  192. $rd="10.1.1.247";
  193. $rp=5060;
  194. route(relay);
  195. exit;
  196. }
  197.  
  198.  
  199. # do lookup with method filtering
  200. if (!lookup("location","m")) {
  201. if (!db_does_uri_exist()) {
  202. send_reply("420","Bad Extension");
  203. exit;
  204. }
  205.  
  206. t_newtran();
  207. t_reply("404", "Not Found");
  208. exit;
  209. }
  210.  
  211. if (isbflagset(NAT)) setflag(NAT);
  212.  
  213. # when routing via usrloc, log the missed calls also
  214. setflag(ACC_MISSED);
  215. route(relay);
  216. }
  217.  
  218.  
  219. route[relay] {
  220. # for INVITEs enable some additional helper routes
  221. if (is_method("INVITE")) {
  222.  
  223. if (isflagset(NAT)) {
  224. rtpproxy_offer("ro");
  225. }
  226.  
  227. t_on_branch("per_branch_ops");
  228. t_on_reply("handle_nat");
  229. t_on_failure("missed_call");
  230. }
  231.  
  232. if (isflagset(NAT)) {
  233. add_rr_param(";nat=yes");
  234. }
  235.  
  236. if (!t_relay()) {
  237. send_reply("500","Internal Error");
  238. };
  239. exit;
  240. }
  241.  
  242.  
  243. # Presence route
  244. route[handle_presence]
  245. {
  246. if (!t_newtran())
  247. {
  248. sl_reply_error();
  249. exit;
  250. }
  251.  
  252. if(is_method("PUBLISH"))
  253. {
  254. handle_publish();
  255. }
  256. else
  257. if( is_method("SUBSCRIBE"))
  258. {
  259. handle_subscribe();
  260. }
  261.  
  262. exit;
  263. }
  264.  
  265.  
  266. branch_route[per_branch_ops] {
  267. xlog("new branch at $ru\n");
  268. }
  269.  
  270.  
  271. onreply_route[handle_nat] {
  272. if (nat_uac_test("1"))
  273. fix_nated_contact();
  274. if ( isflagset(NAT) )
  275. rtpproxy_answer("ro");
  276. xlog("incoming reply\n");
  277. }
  278.  
  279.  
  280. failure_route[missed_call] {
  281. if (t_was_cancelled()) {
  282. exit;
  283. }
  284.  
  285. # uncomment the following lines if you want to block client
  286. # redirect based on 3xx replies.
  287. ##if (t_check_status("3[0-9][0-9]")) {
  288. ##t_reply("404","Not found");
  289. ## exit;
  290. ##}
  291.  
  292.  
  293. }
  294.  
  295.  
  296.  
  297. local_route {
  298. if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
  299.  
  300. acc_db_request("200 Dialog Timeout", "acc");
  301.  
  302. }
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement