Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!KAMAILIO
- #
- # Kamailio (OpenSER) SIP Server v5.1 - Push configuration script
- #!substdef "!ALIAS_IP!192.168.106.7!g"
- #!substdef "!LISTEN_PORT!9060!g"
- #!substdef "!FS_IP!192.168.106.7!g"
- #!substdef "!FS_PORT!5060!g"
- #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
- # - the value for 'use_domain' parameters
- #!define MULTIDOMAIN 1
- #!define FLB_NATB 6
- #!define FLB_NATSIPPING 7
- memdbg=5
- memlog=5
- debug=2
- # ----- log params -----
- log_stderror=no
- log_facility=LOG_LOCAL6
- log_name="SIPServer"
- log_prefix="{$hdr(CSeq) [$pr:$fU@$si:$sp]} " #prefix with Caller info
- log_prefix_mode=0
- fork=yes
- children=4
- disable_tcp=yes
- /* add local domain aliases */
- alias=ALIAS_IP
- port=LISTEN_PORT
- /* set paths to location of modules */
- mpath="/usr/local/lib64/kamailio/modules/"
- # ------------------ Load Modules ----------------------------------
- loadmodule "db_mysql.so"
- loadmodule "jsonrpcs.so"
- loadmodule "tm.so"
- loadmodule "sl.so"
- loadmodule "rr.so"
- loadmodule "pv.so"
- loadmodule "maxfwd.so"
- loadmodule "textops.so"
- loadmodule "siputils.so"
- loadmodule "xlog.so"
- loadmodule "sqlops.so"
- loadmodule "jansson.so"
- loadmodule "auth.so"
- loadmodule "avpops.so"
- loadmodule "path.so"
- loadmodule "kex.so"
- loadmodule "usrloc.so"
- loadmodule "registrar.so"
- loadmodule "nathelper.so"
- loadmodule "domain.so"
- # ----------------- setting module-specific parameters ---------------
- # ------- xlogl params -------
- modparam("xlog", "prefix", "")
- # ----- jsonrpcs params -----
- modparam("jsonrpcs", "pretty_format", 1)
- modparam("sqlops","sqlcon","cb=>mysql://root:yahoo7@localhost/kamailio")
- # ----- usrloc params -----
- /* enable DB persistency for location entries */
- #!ifdef WITH_USRLOCDB
- modparam("usrloc", "db_url", DBURL)
- modparam("usrloc", "db_mode", 2)
- modparam("usrloc", "use_domain", MULTIDOMAIN)
- #!endif
- # ----- nathelper params -----
- modparam("nathelper", "natping_interval", 30)
- modparam("nathelper", "ping_nated_only", 1)
- modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
- # params needed for NAT traversal in other modules
- modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
- modparam("usrloc", "nat_bflag", FLB_NATB)
- # ------------------------- request routing logic -------------------
- # main routing logic
- request_route {
- /* ********* ROUTINE CHECKS ********************************** */
- xlogl("L_INFO", "[$rm] received in request_route with r-uri ($ru) \n");
- # grant Route routing if route headers present
- if (has_totag()) {
- xlogl("L_INFO", "[$rm] received in request_route->has_totag() \n");
- if (loose_route()) {
- xlogl("L_INFO", "[$rm] received in request_route->has_totag->loose_route(): route RELAY \n");
- route(RELAY);
- break;
- } else {
- if ( is_method("ACK") ) {
- xlogl("L_INFO", "[$rm] received in request_route->!has_totag->if_ACK \n");
- if ( t_check_trans() ) {
- xlogl("L_INFO", "[$rm] received in request_route->!has_totag->if_ACK->t_check_trans: route RELAY \n");
- route(RELAY);
- break;
- } else {
- exit;
- }
- }
- xlogl("L_ERROR", "[$rm] received in request_route->!has_totag: sl_send_reply(404) \n");
- sl_send_reply("404","Not here");
- }
- exit;
- }
- # Process initial REGISTER|INVITE|OPTIONS
- if ( !has_totag() ) {
- xlogl("L_INFO", "[$rm] received in request_route->if_INVITE: record_route() \n");
- record_route();
- if ( is_method("REGISTER") ) {
- if ( search("expires=0") ) {
- xlogl("L_INFO", "----[UNREGISTER]---- SIP Un$rm request received from $fu with Contcat header: $hdr(Contact) \n");
- } else {
- xlogl("L_INFO", "----[$rm]---- SIP $rm request received from $fu with contact header [$ct] \n");
- route(AUTH);
- # add kamailio path header
- if ( !add_path_received() ) {
- xlogl("L_ERROR", "[$rm] --> Unable to add Path \n");
- sl_send_reply("503", "Internal Path Error");
- }
- setbflag(FLB_NATB);
- setbflag(FLB_NATSIPPING);
- if ( !save("location", "0x02") ) {
- xlogl("L_ERROR", "[$rm] --> Unable save location \n");
- sl_reply_error();
- }
- }
- }
- } else {
- xlogl("L_ERROR", "[$rm] received in request_route->if_INVITE: sl_send_reply(404) \n");
- sl_send_reply("404","Not here");
- exit;
- }
- xlogl("L_INFO", "[$rm] received in request_route: rewritehostport: 192.168.106.7:5060 \n");
- $du = "sip:192.168.106.7:5060";
- # forward the request now
- route(RELAY);
- }
- route[AUTH] {
- #Step2: parse JSON using module-json and collect $avp(password) ($avp(password) = $json(property/user_secret);)
- if (is_method("REGISTER") || from_uri==myself) {
- # authenticate requests
- sql_query("cb", "SELECT dir_params FROM astpp.sip_devices WHERE username = '$fU'", "ra");
- if ( $dbr(ra=>rows) > 0 ){
- $var(i) = 0;
- while( $var(i) < $dbr(ra=>rows) ) {
- $avp(password) = $dbr(ra=>[$var(i),0]);
- }
- $var(i) = $var(i) + 1;
- }
- xlogl("Result string is $avp(password)");
- jansson_get_field($avp(password), "password", "$avp(password)");
- xlogl("[$rm] -> received Password: $avp(password) \n");
- sql_result_free("ra");
- #Step3: Auth module use pv_<auth-functions>
- if (!pv_auth_check("$fU", "$avp(password)", 0, 1)) {
- xlogl("[$rm] --> received pv_auth_check FAILED, sending auth_challenge \n");
- auth_challenge("$fd", "0");
- exit;
- }
- xlogl("[$rm] --> pv_auth_check SUCCESS, sending auth_challenge \n");
- # user authenticated - remove auth header
- if(!is_method("REGISTER|PUBLISH")) {
- xlogl("[$rm] --> pv_auth_check SUCCESS, consume_credentials \n");
- consume_credentials();
- }
- }
- # 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("[$rm] --> 403 Not relaying for non-local subscriber \n");
- sl_send_reply("403","Not relaying");
- exit;
- }
- return;
- }
- route[RELAY] {
- if (!t_relay()) {
- xlogl("L_ERROR", "Failed to RELAY transaction in route[RELAY] \n");
- sl_reply_error();
- }
- }
Add Comment
Please, Sign In to add comment