pstn.cfg 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #
  2. # $Id$
  3. #
  4. # example: ser configured as PSTN gateway guard; PSTN gateway is located
  5. # at 192.168.0.10
  6. #
  7. # ------------------ module loading ----------------------------------
  8. loadmodule "modules/sl/sl.so"
  9. loadmodule "modules/tm/tm.so"
  10. loadmodule "modules/acc/acc.so"
  11. loadmodule "modules/rr/rr.so"
  12. loadmodule "modules/maxfwd/maxfwd.so"
  13. loadmodule "modules/mysql/mysql.so"
  14. loadmodule "modules/auth/auth.so"
  15. loadmodule "modules/auth_db/auth_db.so"
  16. loadmodule "modules/group/group.so"
  17. loadmodule "modules/uri/uri.so"
  18. # ----------------- setting module-specific parameters ---------------
  19. modparam("auth_db", "db_url","mysql://ser:heslo@localhost/ser")
  20. modparam("auth_db", "calculate_ha1", yes)
  21. modparam("auth_db", "password_column", "password")
  22. # -- acc params --
  23. modparam("acc", "log_level", 1)
  24. # that is the flag for which we will account -- don't forget to
  25. # set the same one :-)
  26. modparam("acc", "log_flag", 1 )
  27. # ------------------------- request routing logic -------------------
  28. # main routing logic
  29. route{
  30. /* ********* ROUTINE CHECKS ********************************** */
  31. # filter too old messages
  32. if (!mf_process_maxfwd_header("10")) {
  33. log("LOG: Too many hops\n");
  34. sl_send_reply("483","Too Many Hops");
  35. break;
  36. };
  37. if (len_gt( max_len )) {
  38. sl_send_reply("513", "Wow -- Message too large");
  39. break;
  40. };
  41. /* ********* RR ********************************** */
  42. /* grant Route routing if route headers present */
  43. if (loose_route()) { t_relay(); break; };
  44. /* record-route INVITEs -- all subsequent requests must visit us */
  45. if (method=="INVITE") {
  46. record_route();
  47. };
  48. # now check if it really is a PSTN destination which should be handled
  49. # by our gateway; if not, and the request is an invitation, drop it --
  50. # we cannot terminate it in PSTN; relay non-INVITE requests -- it may
  51. # be for example BYEs sent by gateway to call originator
  52. if (!uri=~"sip:\+?[0-9]+@.*") {
  53. if (method=="INVITE") {
  54. sl_send_reply("403", "Call cannot be served here");
  55. } else {
  56. forward(uri:host, uri:port);
  57. };
  58. break;
  59. };
  60. # account completed transactions via syslog
  61. setflag(1);
  62. # free call destinations ... no authentication needed
  63. if ( is_user_in("Request-URI", "free-pstn") /* free destinations */
  64. | uri=~"sip:[79][0-9][0-9][0-9]@.*" /* local PBX */
  65. | uri=~"sip:98[0-9][0-9][0-9][0-9]") {
  66. log("free call");
  67. } else if (src_ip==192.168.0.10) {
  68. # our gateway doesn't support digest authentication;
  69. # verify that a request is coming from it by source
  70. # address
  71. log("gateway-originated request");
  72. } else {
  73. # in all other cases, we need to check the request against
  74. # access control lists; first of all, verify request
  75. # originator's identity
  76. if (!proxy_authorize( "gateway" /* realm */,
  77. "subscriber" /* table name */)) {
  78. proxy_challenge( "gateway" /* realm */, "0" /* no qop */ );
  79. break;
  80. };
  81. # authorize only for INVITEs -- RR/Contact may result in weird
  82. # things showing up in d-uri that would break our logic; our
  83. # major concern is INVITE which causes PSTN costs
  84. if (method=="INVITE") {
  85. # does the authenticated user have a permission for local
  86. # calls (destinations beginning with a single zero)?
  87. # (i.e., is he in the "local" group?)
  88. if (uri=~"sip:0[1-9][0-9]+@.*") {
  89. if (!is_user_in("credentials", "local")) {
  90. sl_send_reply("403", "No permission for local calls");
  91. break;
  92. };
  93. # the same for long-distance (destinations begin with two zeros")
  94. } else if (uri=~"sip:00[1-9][0-9]+@.*") {
  95. if (!is_user_in("credentials", "ld")) {
  96. sl_send_reply("403", " no permission for LD ");
  97. break;
  98. };
  99. # the same for international calls (three zeros)
  100. } else if (uri=~"sip:000[1-9][0-9]+@.*") {
  101. if (!is_user_in("credentials", "int")) {
  102. sl_send_reply("403", "International permissions needed");
  103. break;
  104. };
  105. # everything else (e.g., interplanetary calls) is denied
  106. } else {
  107. sl_send_reply("403", "Forbidden");
  108. break;
  109. };
  110. }; # INVITE to authorized PSTN
  111. }; # authorized PSTN
  112. # if you have passed through all the checks, let your call go to GW!
  113. rewritehostport("192.168.0.10:5060");
  114. # forward the request now
  115. if (!t_relay()) {
  116. sl_reply_error();
  117. break;
  118. };
  119. }