Advertisement
Maksym_Shcherbakov

https://blog.ipcalls24.com/htable-in-kamailio/

Mar 15th, 2021
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. #!define DBURL "postgres://kamailio:secret_password@localhost:5433/kamailio"
  2.  
  3.  
  4. loadmodule "pv.so"
  5. loadmodule "ctl.so"
  6. loadmodule "xlog.so"
  7. loadmodule "jsonrpcs.so"
  8. loadmodule "tm.so"
  9. loadmodule "textops.so"
  10. loadmodule "sl.so"
  11. loadmodule "usrloc.so"
  12. loadmodule "registrar.so"
  13. loadmodule "auth.so"
  14. loadmodule "db_postgres.so"
  15. loadmodule "auth_db.so"
  16. loadmodule "siputils.so"
  17. loadmodule "nathelper.so"
  18.  
  19. loadmodule "rr.so"
  20. #loadmodule "tmx.so"
  21. loadmodule "rtpengine.so"
  22. loadmodule "htable.so"
  23.  
  24. #############[Подключение к БД]###########
  25. modparam("auth_db", "db_url", DBURL); # указываем URL для подключения, берем его из ранее созданной директивы DBURL
  26.  
  27. modparam("auth_db", "load_credentials", "$avp(pass)=password")
  28.  
  29. modparam("htable", "htable", "auth=>size=10;autoexpire=1800;")
  30. modparam("htable", "htable", "ipban=>size=10;autoexpire=60;initval=0;")
  31.  
  32. modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
  33.  
  34. request_route {
  35. route(REQINIT);
  36.  
  37. if (is_method("CANCEL")) {
  38. if (t_check_trans()) {
  39. route(RELAY);
  40. }
  41. exit;
  42. }
  43.  
  44. if (is_method("INVITE") || is_method("REGISTER")) {
  45. route(NAT);
  46. }
  47.  
  48. if (is_method("REGISTER")) {
  49. route(AUTH);
  50. }
  51.  
  52. route(DIALOG);
  53. }
  54.  
  55. route[REQINIT] {
  56. if($sht(ipban=>$si) > 5) {
  57. exit;
  58. }
  59. force_rport;
  60. }
  61.  
  62. route[AUTH] {
  63. if (sht_match_name("auth", "eq", "$Au")) {
  64. if (!pv_auth_check("$fd", "$sht(auth=>$Au)", "0", "1")) {
  65. auth_challenge("$fd", "1");
  66. $sht(ipban=>$si) = $sht(ipban=>$si) + 1;
  67. exit;
  68. }
  69. consume_credentials();
  70. $sht(ipban=>$si) = $null;
  71. if (is_method("REGISTER")) {
  72. save("location");
  73. exit;
  74. }
  75. } else {
  76. if (!auth_check("$fd", "subscriber", "1")) {
  77. auth_challenge("$fd", "1");
  78. $sht(ipban=>$si) = $sht(ipban=>$si) + 1;
  79. exit;
  80. }
  81. $sht(auth=>$Au) = $avp(pass);
  82. $sht(ipban=>$si) = $null;
  83. consume_credentials();
  84. if (is_method("REGISTER")) {
  85. save("location");
  86. exit;
  87. }
  88. }
  89. }
  90.  
  91. route[NAT] {
  92. if (nat_uac_test("19")) {
  93. if (is_method("REGISTER")) {
  94. set_contact_alias();
  95. } else {
  96. if(is_first_hop()) {
  97. set_contact_alias();
  98. }
  99. }
  100. }
  101. return;
  102. }
  103.  
  104. route[DIALOG] {
  105. if (is_method("INVITE")) {
  106. route(AUTH);
  107. if (!lookup("location")) {
  108. sl_send_reply("403", "Forbidden");
  109. exit;
  110. }
  111. handle_ruri_alias();
  112. record_route();
  113. route(RELAY);
  114. }
  115. if (has_totag()) {
  116. if (loose_route()) {
  117. handle_ruri_alias();
  118. route(RELAY);
  119. }
  120. }
  121. if (is_method("ACK")) {
  122. if ( t_check_trans() ) {
  123. route(RELAY);
  124. exit;
  125. } else {
  126. exit;
  127. }
  128. }
  129. }
  130.  
  131. route[RELAY] {
  132. if (has_body("application/sdp")) {
  133. rtpengine_manage("replace-session-connection replace-origin ICE=remove direction=internal direction=external");
  134. }
  135. t_on_reply("REPLY");
  136. t_relay();
  137. }
  138.  
  139. onreply_route[REPLY] {
  140. route(NAT);
  141. if (has_body("application/sdp")) {
  142. rtpengine_manage("replace-session-connection replace-origin ICE=remove direction=internal direction=external");
  143. }
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement