Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!KAMAILIO
- #
- # Kamailio (OpenSER) SIP Server v5.1 - default configuration script
- # - define WITH_DEBUG
- #!define WITH_MYSQL
- #!define WITH_AUTH
- #!define WITH_USRLOCDB
- #!define WITH_PRESENCE
- #!define WITH_MESSAGE
- ####### Defined Values #########
- # *** Value defines - IDs used later in config
- #!ifdef WITH_MYSQL
- #!ifndef DBURL
- #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
- #!endif
- #!endif
- #!ifdef WITH_MULTIDOMAIN
- # - the value for 'use_domain' parameters
- #!define MULTIDOMAIN 1
- #!else
- #!define MULTIDOMAIN 0
- #!endif
- # - flags
- # FLT_ - per transaction (message) flags
- # FLB_ - per branch flags
- #!define FLT_ACC 1
- #!define FLT_ACCMISSED 2
- #!define FLT_ACCFAILED 3
- #!define FLT_NATS 5
- #!define FLB_NATB 6
- #!define FLB_NATSIPPING 7
- ####### Global Parameters #########
- ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
- #!ifdef WITH_DEBUG
- debug=4
- log_stderror=no
- #!else
- debug=2
- log_stderror=no
- #!endif
- memdbg=5
- memlog=5
- log_facility=LOG_LOCAL0
- log_name="imServer"
- log_prefix="{$fU@$si:$sp} {$mt $hdr(CSeq)} "
- log_prefix_mode=0
- /* number of SIP routing processes */
- children=4
- #check_via=no # (cmd. line: -v)
- #dns=off # (cmd. line: -r)
- #rev_dns=off # (cmd. line: -R)
- /* uncomment the next line to disable TCP (default on) */
- # disable_tcp=yes
- /* uncomment the next line to disable the auto discovery of local aliases
- * based on reverse DNS on IPs (default on) */
- auto_aliases=no
- /* add local domain aliases */
- alias="192.168.10.18"
- port=9060
- /* uncomment and configure the following line if you want Kamailio to
- * bind on a specific interface/port/proto (default bind on all available) */
- # listen=udp:10.0.0.10:5060
- /* life time of TCP connection when there is no traffic
- * - a bit higher than registration expires to cope with UA behind NAT */
- tcp_connection_lifetime=3605
- ####### Modules Section ########
- /* set paths to location of modules */
- mpath="/usr/local/lib64/kamailio/modules/"
- #!ifdef WITH_MYSQL
- loadmodule "db_mysql.so"
- #!endif
- loadmodule "tm.so"
- loadmodule "tmx.so"
- loadmodule "jsonrpcs.so"
- loadmodule "kex.so"
- loadmodule "corex.so"
- loadmodule "sl.so"
- loadmodule "rr.so"
- loadmodule "pv.so"
- loadmodule "maxfwd.so"
- loadmodule "usrloc.so"
- loadmodule "registrar.so"
- loadmodule "textops.so"
- loadmodule "siputils.so"
- loadmodule "xlog.so"
- loadmodule "sanity.so"
- loadmodule "ctl.so"
- loadmodule "cfg_rpc.so"
- loadmodule "acc.so"
- loadmodule "counters.so"
- #!ifdef WITH_AUTH
- loadmodule "auth.so"
- loadmodule "auth_db.so"
- #!endif
- #!ifdef WITH_MULTIDOMAIN
- loadmodule "domain.so"
- #!endif
- #!ifdef WITH_PRESENCE
- loadmodule "presence.so"
- loadmodule "presence_xml.so"
- #!endif
- #!ifdef WITH_NAT
- loadmodule "nathelper.so"
- loadmodule "rtpproxy.so"
- #!endif
- #!ifdef WITH_XMLRPC
- loadmodule "xmlrpc.so"
- #!endif
- #!ifdef WITH_DEBUG
- loadmodule "debugger.so"
- #!endif
- #!ifdef WITH_MESSAGE
- loadmodule "msilo.so"
- #!endif
- # ----------------- setting module-specific parameters ---------------
- #------- xlog params -------
- modparam("xlog", "prefix", "")
- # ----- jsonrpcs params -----
- modparam("jsonrpcs", "pretty_format", 1)
- # ----- tm params -----
- # auto-discard branches from previous serial forking leg
- modparam("tm", "failure_reply_mode", 3)
- # default retransmission timeout: 10sec
- modparam("tm", "fr_timer", 10)
- # default invite retransmission timeout after 1xx: 15sec
- modparam("tm", "fr_inv_timer", 15)
- modparam("tm", "wt_timer", 10 )
- # ----- rr params -----
- # set next param to 1 to add value to ;lr param (helps with some UAs)
- modparam("rr", "enable_full_lr", 0)
- # do not append from tag to the RR (no need for this script)
- modparam("rr", "append_fromtag", 0)
- # ----- registrar params -----
- modparam("registrar", "method_filtering", 1)
- /* uncomment the next line to disable parallel forking via location */
- # modparam("registrar", "append_branches", 0)
- /* uncomment the next line not to allow more than 10 contacts per AOR */
- # modparam("registrar", "max_contacts", 10)
- modparam("registrar", "default_expires", 120)
- /* max value for expires of registrations */
- modparam("registrar", "max_expires", 3600)
- /* set it to 1 to enable GRUU */
- modparam("registrar", "gruu_enabled", 0)
- # ----- acc params -----
- /* what special events should be accounted ? */
- modparam("acc", "early_media", 0)
- modparam("acc", "report_ack", 0)
- modparam("acc", "report_cancels", 0)
- /* by default ww do not adjust the direct of the sequential requests.
- * if you enable this parameter, be sure the enable "append_fromtag"
- * in "rr" module */
- modparam("acc", "detect_direction", 0)
- /* account triggers (flags) */
- modparam("acc", "log_flag", FLT_ACC)
- modparam("acc", "log_missed_flag", FLT_ACCMISSED)
- modparam("acc", "log_extra",
- "src_user=$fU;src_domain=$fd;src_ip=$si;"
- "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
- modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
- /* enhanced DB accounting */
- #!ifdef WITH_ACCDB
- modparam("acc", "db_flag", FLT_ACC)
- modparam("acc", "db_missed_flag", FLT_ACCMISSED)
- modparam("acc", "db_url", DBURL)
- modparam("acc", "db_extra",
- "src_user=$fU;src_domain=$fd;src_ip=$si;"
- "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
- #!endif
- # ----- usrloc params -----
- /* enable DB persistency for location entries */
- #!ifdef WITH_USRLOCDB
- modparam("usrloc", "db_url", DBURL)
- modparam("usrloc", "db_mode", 0)
- modparam("usrloc", "use_domain", MULTIDOMAIN)
- #!endif
- # ----- auth_db params -----
- #!ifdef WITH_AUTH
- modparam("auth_db", "db_url", DBURL)
- modparam("auth_db", "calculate_ha1", yes)
- modparam("auth_db", "password_column", "password")
- modparam("auth_db", "load_credentials", "")
- modparam("auth_db", "use_domain", MULTIDOMAIN)
- #!endif
- # ----- alias_db params -----
- #!ifdef WITH_ALIASDB
- modparam("alias_db", "db_url", DBURL)
- modparam("alias_db", "use_domain", MULTIDOMAIN)
- #!endif
- # ----- domain params -----
- #!ifdef WITH_MULTIDOMAIN
- modparam("domain", "db_url", DBURL)
- /* register callback to match myself condition with domains list */
- modparam("domain", "register_myself", 1)
- #!endif
- #!ifdef WITH_PRESENCE
- # ----- presence params -----
- modparam("presence", "db_url", DBURL)
- # ----- presence_xml params -----
- modparam("presence_xml", "db_url", DBURL)
- modparam("presence_xml", "force_active", 1)
- #!endif
- #!ifdef WITH_MESSAGE
- # ----- msilo params -----
- modparam("msilo", "db_url", DBURL)
- modparam("msilo", "db_table", "silo")
- modparam("msilo", "sc_mid", "id")
- modparam("msilo","from_address","sip:registrar@192.168.10.18:9060")
- modparam("msilo","contact_hdr","Contact: registrar@192.168.10.18:9060;msilo=yes\r\n")
- modparam("msilo","content_type_hdr","Content-Type: text/plain\r\n")
- #modparam("msilo","offline_message","*** User $rU is offline!")
- #modparam("msilo", "expire_time", 3600) // discard offline messages after 1 hr
- #modparam("msilo", "check_time", 10)
- #!endif
- #!ifdef WITH_NAT
- # ----- rtpproxy params -----
- modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
- # ----- nathelper params -----
- modparam("nathelper", "natping_interval", 30)
- modparam("nathelper", "ping_nated_only", 1)
- modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
- modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
- # params needed for NAT traversal in other modules
- modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
- modparam("usrloc", "nat_bflag", FLB_NATB)
- #!endif
- #!ifdef WITH_XMLRPC
- # ----- xmlrpc params -----
- modparam("xmlrpc", "route", "XMLRPC");
- modparam("xmlrpc", "url_match", "^/RPC")
- #!endif
- #!ifdef WITH_DEBUG
- # ----- debugger params -----
- modparam("debugger", "cfgtrace", 1)
- modparam("debugger", "log_level_name", "exec")
- #!endif
- ####### Routing Logic ########
- request_route {
- # NAT detection
- route(NATDETECT);
- # handle retransmissions
- if (!is_method("ACK")) {
- if(t_precheck_trans()) {
- t_check_trans();
- exit;
- }
- t_check_trans();
- }
- # handle requests within SIP dialogs
- route(WITHINDLG);
- # authentication
- route(AUTH);
- # record routing for dialog forming requests (in case they are routed)
- # - remove preloaded route headers
- remove_hf("Route");
- if (is_method("INVITE|SUBSCRIBE")) {
- record_route();
- }
- # handle presence related requests
- route(PRESENCE);
- # handle registrations
- route(REGISTRAR);
- #!ifdef WITH_MESSAGE
- # backup r-uri for m_dump() in case of delivery failure
- $avp(11) = $ru;
- xlogl("L_NOTICE", "[$rm] MSILO: copied ru:$ru to avp(11) and rd:$rd \n");
- if (is_method("MESSAGE")) {
- route(MSILO_MESSAGE);
- }
- #!endif
- if ($rU==$null) {
- # request with no Username in RURI
- sl_send_reply("484","Address Incomplete");
- exit;
- }
- # user location service
- route(LOCATION);
- }
- route[MSILO_MESSAGE] {
- xlogl("L_NOTICE", "[$rm] Received message: [[$rb]]\n");
- xlogl("L_NOTICE", "[$rm] r-uri: $ru d-uri: $du \n");
- # domestic SIP destinations are handled using our USRLOC DB
- if ( !lookup("location") ) {
- if (!t_newtran()) {
- xlogl("L_ERROR", "[$rm] -> ERROR creating new transaction \n");
- sl_reply_error();
- exit;
- };
- xlogl("L_NOTICE", "[$rm] -> Storing MSILO_MESSAGE \n [$ru]-[$tu]-[$ou] \n ");
- if (m_store("$ru")) {
- xlogl("L_NOTICE", "MSILO: offline message stored! \n");
- if (!t_reply("202", "Accpeted and Strored")) {
- xlogl("L_ERROR", "MSILO: ERROR sending 202 reply... \n");
- sl_reply_error();
- }
- } else {
- xlogl("L_ERROR", "MSILO: offline message NOT stored... \n");
- if (!t_reply("503", "Service Unavailable")) {
- sl_reply_error();
- }
- }
- // t_relay();
- // t_reply("202", "Accepted");
- } else {
- xlogl("L_NOTICE", "[$rm] -> loaction found. Relying message [[$rb]] to the UAC \n");
- //t_relay();
- route(RELAY);
- exit;
- }
- exit;
- }
- # Handle SIP registrations
- route[REGISTRAR] {
- if (!is_method("REGISTER")) return; // discard all non-REGISTER methods
- if(isflagset(FLT_NATS)) {
- setbflag(FLB_NATB);
- #!ifdef WITH_NATSIPPING
- setbflag(FLB_NATSIPPING); //# do SIP NAT pinging
- #!endif
- }
- #!ifdef WITH_MESSAGE
- $avp(received) = "sip:" + $si + ":" + $sp + ";transport=" + $proto;
- xlogl("L_INFO", "[$rm] -> UAC actual location $avp(received) \n");
- if (!save("location",0x04)) {
- xlogl("L_ERROR", "[$rm] -> Unable to save user location \n");
- sl_reply_error();
- }
- else {
- xlogl("L_INFO", "[$rm] -> dumping messages with MSILO \n");
- # MSILO - dumping user's offline messages to user
- //if (m_dump("$fu")) {
- if (m_dump()) {
- xlogl("L_NOTICE", "MSILO: offline messages for $fu dumped - if they were \n");
- }
- else {
- xlogl("L_NOTICE", "MSILO: no offline messages dumped \n");
- };
- }
- #!endif
- exit;
- }
- # User location service
- route[LOCATION] {
- $avp(oexten) = $rU;
- if (!lookup("location")) {
- $var(rc) = $rc;
- route(TOVOICEMAIL);
- if (!t_newtran()) {
- xlogl("L_ERROR", "[$rm] -> ERR creating new transaction");
- sl_reply_error();
- exit;
- }
- switch ($var(rc)) {
- case -1:
- case -3:
- send_reply("404", "Not Found");
- exit;
- case -2:
- send_reply("405", "Method Not Allowed");
- exit;
- }
- // place route(MSILO_MESSAGE) here
- }
- # when routing via usrloc, log the missed calls also
- if (is_method("INVITE")) {
- setflag(FLT_ACCMISSED);
- }
- route(RELAY);
- exit;
- }
- # Presence server processing
- route[PRESENCE] {
- if(!is_method("PUBLISH|SUBSCRIBE")) return;
- if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {
- route(TOVOICEMAIL);
- # returns here if no voicemail server is configured
- sl_send_reply("404", "No voicemail service");
- exit;
- }
- #!ifdef WITH_PRESENCE
- if (!t_newtran()) {
- sl_reply_error();
- exit;
- }
- if(is_method("PUBLISH")) {
- handle_publish();
- t_release();
- } else if(is_method("SUBSCRIBE")) {
- handle_subscribe();
- t_release();
- }
- exit;
- #!endif
- # if presence enabled, this part will not be executed
- if (is_method("PUBLISH") || $rU==$null) {
- sl_send_reply("404", "Not here");
- exit;
- }
- return;
- }
- # IP authorization and user authentication
- route[AUTH] {
- #!ifdef WITH_AUTH
- if (is_method("REGISTER|MESSAGE") || from_uri==myself) {
- xlogl("L_NOTICE", "[$rm] -> Auth requested from $fU \n");
- #!ifdef WITH_MESSAGE
- if(is_method("MESSAGE")) {
- xlogl("L_NOTICE", "[$rm] -> is_method(MESSAGE) for $fU \n");
- if(src_ip==myself) {
- xlogl("L_NOTICE", "[$rm] -> src_ip == myself for $fU \n");
- xlogl("L_NOTICE", "[$rm] -> UAS will deliver stored messages for $fU \n");
- if (!sl_send_reply("202", "Accepted and Delivering")) {
- sl_reply_error();
- }
- return;
- }
- }
- #!endif
- # authenticate requests
- if (!auth_check("$fd", "subscriber", "1")) {
- auth_challenge("$fd", "0");
- xlogl("L_NOTICE", "[$rm] -> Auth Challenge sent for $fU \n");
- exit;
- }
- # user authenticated - remove auth header
- if(!is_method("REGISTER|PUBLISH")) {
- consume_credentials();
- xlogl("L_NOTICE", "[$rm] -> Auth request Accpeted for $fU credentials consumed \n");
- }
- }
- # if caller is not local subscriber, then check if it calls
- # a local destination, otherwise deny, not an open relay here
- if (from_uri!=myself && uri!=myself) {
- xlogl("L_NOTICE", "[$rm] -> request not relaying \n");
- sl_send_reply("403","Not relaying");
- exit;
- }
- #!endif
- return;
- }
- # Wrapper for relaying requests
- route[RELAY] {
- # enable additional event routes for forwarded requests
- # - serial forking, RTP relaying handling, a.s.o.
- if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
- if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
- }
- if (is_method("INVITE|SUBSCRIBE|UPDATE|MESSAGE")) {
- if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
- }
- //if (is_method("INVITE|MESSAGE")) {
- // if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
- //}
- if (!t_relay()) {
- sl_reply_error();
- }
- exit;
- }
- # Handle requests within SIP dialogs
- route[WITHINDLG] {
- if (!has_totag()) return;
- # sequential request withing a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- route(DLGURI);
- if (is_method("BYE")) {
- setflag(FLT_ACC); # do accounting ...
- setflag(FLT_ACCFAILED); # ... even if the transaction fails
- } else if ( is_method("ACK") ) {
- # ACK is forwarded statelessly
- route(NATMANAGE);
- } else if ( is_method("NOTIFY") ) {
- # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
- record_route();
- }
- route(RELAY);
- exit;
- }
- if (is_method("SUBSCRIBE") && uri == myself) {
- # in-dialog subscribe requests
- route(PRESENCE);
- exit;
- }
- if ( is_method("ACK") ) {
- if ( t_check_trans() ) {
- # no loose-route, but stateful ACK;
- # must be an ACK after a 487
- # or e.g. 404 from upstream server
- route(RELAY);
- exit;
- } else {
- # ACK without matching transaction ... ignore and discard
- exit;
- }
- }
- sl_send_reply("404","Not here");
- exit;
- }
- # Caller NAT detection
- route[NATDETECT] {
- #!ifdef WITH_NAT
- force_rport();
- if (nat_uac_test("19")) {
- if (is_method("REGISTER")) {
- fix_nated_register();
- } else {
- if(is_first_hop()) {
- set_contact_alias();
- }
- }
- setflag(FLT_NATS);
- }
- #!endif
- return;
- }
- # RTPProxy control and signaling updates for NAT traversal
- route[NATMANAGE] {
- #!ifdef WITH_NAT
- if (is_request()) {
- if(has_totag()) {
- if(check_route_param("nat=yes")) {
- setbflag(FLB_NATB);
- }
- }
- }
- if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return;
- if(nat_uac_test("8")) {
- rtpproxy_manage("co");
- } else {
- rtpproxy_manage("cor");
- }
- if (is_request()) {
- if (!has_totag()) {
- if(t_is_branch_route()) {
- add_rr_param(";nat=yes");
- }
- }
- }
- if (is_reply()) {
- if(isbflagset(FLB_NATB)) {
- if(is_first_hop())
- set_contact_alias();
- }
- }
- #!endif
- return;
- }
- # URI update for dialog requests
- route[DLGURI] {
- #!ifdef WITH_NAT
- if(!isdsturiset()) {
- handle_ruri_alias();
- }
- #!endif
- return;
- }
- # XMLRPC routing
- #!ifdef WITH_XMLRPC
- route[XMLRPC] {
- # allow XMLRPC from localhost
- if ((method=="POST" || method=="GET") && (src_ip==127.0.0.1)) {
- # close connection only for xmlrpclib user agents (there is a bug in
- # xmlrpclib: it waits for EOF before interpreting the response).
- if ($hdr(User-Agent) =~ "xmlrpclib")
- set_reply_close();
- set_reply_no_connect();
- dispatch_rpc();
- exit;
- }
- send_reply("403", "Forbidden");
- exit;
- }
- #!endif
- # Routing to voicemail server
- route[TOVOICEMAIL] {
- return;
- }
- # Manage outgoing branches
- branch_route[MANAGE_BRANCH] {
- xlogl("L_INFO", "new branch [$T_branch_idx] to $ru\n");
- route(NATMANAGE);
- }
- # Manage incoming replies
- onreply_route[MANAGE_REPLY] {
- xlogl("L_INFO", "[$rm] Incoming reply \n");
- if(status=~"[12][0-9][0-9]") {
- route(NATMANAGE);
- }
- }
- # Manage failure routing cases
- failure_route[MANAGE_FAILURE] {
- route(NATMANAGE);
- if (t_is_canceled()) exit;
- #!ifdef WITH_MESSAGE
- if (method=="MESSAGE") {
- xlogl("L_NOTICE", "MSILO: the downstream UA doesn't support MESSAGEs...\n");
- # we have changed the R-URI with the contact address, ignore it now
- if (m_store("$ou")){
- // if (m_store("$avp(11)")){
- xlogl("L_NOTICE", "MSILO: offline message stored for $ou ! \n");
- t_reply("202", "Accepted in failure_route");
- }
- else {
- xlogl("L_ERROR", "MSILO: offline message NOT stored...for $ou \n");
- t_reply("503", "Service Unavailable");
- };
- }
- #!endif
- }
Add Comment
Please, Sign In to add comment