# # $Id: ser.cfg,v 1.21 2003/06/04 13:47:36 jiri Exp $ # # simple quick-start config script # /* History: * -------- * 2003-11-14 - Entra nel blocco mangle se l'indirizzo e` privato. * 2003-11-13 - Aggiunto il encode_contact su ogni INVITE interno, aggiunto anche ACC * 2003-11-06 - Change MSILO param in modparam("msilo","db_url","mysql://user:xxx@127.0.0.1/msilo") */ # ----------- global configuration parameters ------------------------ debug=9 # debug level (cmd line: -dddddddddd) fork=yes log_stderror=yes # alias="sip.quellidelpirana.it" alias="192.168.100.50" mhomed=yes check_via=no # (cmd. line: -v) dns=no # (cmd. line: -r) rev_dns=no # (cmd. line: -R) port=5060 children=4 fifo="/tmp/ser_fifo" # ------------------ module loading ---------------------------------- loadmodule "/usr/lib/ser/modules/dbtext.so" loadmodule "/usr/lib/ser/modules/mysql.so" loadmodule "/usr/lib/ser/modules/acc.so" loadmodule "/usr/lib/ser/modules/sl.so" loadmodule "/usr/lib/ser/modules/tm.so" loadmodule "/usr/lib/ser/modules/rr.so" loadmodule "/usr/lib/ser/modules/maxfwd.so" loadmodule "/usr/lib/ser/modules/usrloc.so" loadmodule "/usr/lib/ser/modules/registrar.so" loadmodule "/usr/lib/ser/modules/auth.so" loadmodule "/usr/lib/ser/modules/auth_db.so" loadmodule "/usr/lib/ser/modules/textops.so" loadmodule "/usr/lib/ser/modules/exec.so" loadmodule "/usr/lib/ser/modules/mangler.so" loadmodule "/usr/lib/ser/modules/msilo.so" loadmodule "/usr/lib/ser/modules/xlog.so" loadmodule "/usr/lib/ser/modules/vm.so" # ----------------- setting module-specific parameters --------------- # -- usrloc params -- modparam("usrloc", "db_mode", 2) # -- auth params -- modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") # -- rr params -- # add value to ;lr param to make some broken UAs happy modparam("rr", "enable_full_lr", 1) # -- msilo params -- modparam("msilo","db_url","mysql://ser:heslo@localhost/ser") modparam("msilo","registrar","sip:registrar@192.168.100.50") # -- domain params -- # modparam("domain", "db_url", "sql://ser:heslo@localhost/ser") # URL for accessing the database # modparam("domain", "db_mode", 1) # -- registrar params -- # modparam("registrar", "use_domain", 1) # -- tm params -- modparam("tm", "fr_timer", 20 ) modparam("tm", "fr_inv_timer", 30 ) modparam("tm", "wt_timer", 20 ) # -- acc params -- # set the reporting log level # modparam("acc", "log_level", 1) # number of flag, which will be used for accounting; if a message is # labeled with this flag, its completion status will be reported modparam("acc", "db_flag", 1 ) modparam("acc", "db_missed_flag", 3 ) modparam("acc", "report_ack", 0) # non traccio gli ack modparam("acc", "report_cancels", 1) # -- db URL -- # modparam("msilo|domain", "db_url","mysql://ser:heslo@localhost/ser") # ------------------------- request routing logic ------------------- # main routing logic route{ log(1, ""); log(1, "Avvio procedura di Route"); xlog("L_NOTICE", "method <%rm> from <%fu> - <%is> source address"); xlog("L_NOTICE", "request URI <%ru> - to URI <%tu>"); # initial sanity checks -- messages with # max_forwards==0, or excessively long requests if (!mf_process_maxfwd_header("10")) { sl_send_reply("483","Too Many Hops"); break; }; if ( msg:len >= max_len ) { sl_send_reply("513", "Message too big"); break; }; # setflag(1); # Attivando qui segno nel database tutto (SUBSCRIBE, INVITE, MESSAGE, REGISTER..) # we record-route all messages -- to make sure that # subsequent messages will go through our proxy; that's # particularly good if upstream and downstream entities # use different transport protocol record_route(); # loose-route processing if (loose_route()) { t_relay(); break; }; /* outgoing connection */ /* 2003-11-14 - Adesso entra nel blocco se un indirizzo e` privato */ # if (src_ip == 192.168.0.0 and !uri == myself ) { if ( search("Contact: .*192\.168\.") ) { log(1, "Ahi ahi ahi.... il canal, chi ga' suga' el canal?"); route(1); } else{ ;/* we should only mangle replies */ }; /* ************ requests for our domain ********** */ /* now, the request is for sure for our domain */ # if the request is for other domain use UsrLoc # (in case, it does not work, use the following command # with proper names and addresses in it) if (uri==myself) { log(1, "myself block: start"); /* we received something for a local phone */ if (uri=~"enc_prefix*") { log(1, "myself block: incoming request for mangled address\n"); decode_contact(); if (!t_relay()) { sl_reply_error(); }; break; }; if (method=="REGISTER") { log(1, "REGISTER"); # Authorize registering user if (!www_authorize("192.168.100.50", "subscriber")) { log(1, "REGISTER: failed"); www_challenge("192.168.100.50", "0"); break; }; log(1, "Save Location"); save("location"); # MSILO - dumping user's offline messages log("REGISTER received -> dumping messages with MSILO\n"); if (m_dump()) { log("MSILO: offline messages dumped - if there were some\n"); }else{ log("MSILO: no offline messages dumped\n"); }; log(1, "Fine ricezione messaggi & EXIT \n"); break; }; if (method=="INVITE") { setflag(1); # log(1, "Encode contact for INVITE method"); # encode_contact("enc_prefix", "192.168.100.50"); }; if (method=="MESSAGE") { setflag(1); }; # native SIP destinations are handled using our USRLOC DB if (!lookup("location")) { log(1, "myself block: user not found...\n"); if (! t_newtran()) { log(1, "could not create new transaction\n"); sl_reply_error(); break; }; # L'utente che cercavo ed e` del mio odminio, e` off-line. Se la richiesta e` un # messaggio lo mando a MSILO altrimenti mando tutto a VOICEMAIL # we do not care about anything else but MESSAGEs if (!method=="MESSAGE") { if(method=="ACK" || method=="INVITE" || method=="BYE" || method=="REFER"){ log(1, "myself block: jumping to vm route block.\n"); route(2); } else if (!t_reply("404", "User not found")) { sl_reply_error(); }; break; }; # MSILO - storing as offline message log("MESSAGE received -> storing using MSILO\n"); if (m_store("0")) { log(1, "MSILO: message stored\n"); if (!t_reply("202", "User is currently offline. Message accepted for later delivery.")) { sl_reply_error(); }; }else{ log(1, "MSILO: message NOT stored\n"); if (!t_reply("503", "Service MSILO currently unavailable")) { sl_reply_error(); }; }; break; }; # if the downstream UA does not support MESSAGE requests # go to failure_route[1] t_on_failure("1"); t_relay(); break; }; # forward to current uri now; use stateful forwarding; that # works reliably even if we forward from TCP to UDP # Se non riesco a forwardare verso l'uri corrente segnala l'errore log(1, "relaying...\n"); if (!t_relay()) { sl_reply_error(); }; } /* route block for mangling */ route[1]{ log(1, "route-block 1 (mangling)\n"); /* we mangle the contact address and ports in SDP part of the message */ if (method == "INVITE") { log(1, "mangle block: INVITE received.\n"); log(1, " Will mangle ip.\n"); # sdp_mangle_ip("192.168.0.66/32",""); if ( src_ip == 192.168.100.89 ) { log("HHHHHHHHHIIIIIIIIIIIII"); sdp_mangle_ip("192.168.100.1/254", "192.168.100.50"); log(1, "Mangled"); }; /* different mangling based on what phone is calling if (src_ip==192.168.0.66){ log(1, "mangle block: From HYDRA. Will mangle port.\n"); sdp_mangle_port("+1000"); }; */ }; /* rewrite Contact: header */ if (search("Contact: .*@192\.168\.")) { log(1, "mangle block: Will encode Contact: header.\n"); /* we seem to have a private address on a Contact which is not valid */ encode_contact("enc_prefix","192.168.100.50"); }; } /* route block for voice mail */ route[2]{ t_reply("100","Trying -- just wait a minute !"); if(method=="INVITE" || method=="REFER"){ log(1, "**************** vm start - begin ******************\n"); if( uri =~ "conference" ){ if(!vm("/tmp/am_fifo","conference")){ log("could not contact conference server\n"); t_reply("500","could not contact conference server"); }; } else if( uri =~ "echo" ){ if(!vm("/tmp/am_fifo","echo")){ log("could not contact echo\n"); t_reply("500","could not contact echo"); }; }else{ if(!vm("/tmp/am_fifo","voicemail")){ log("could not contact voicemail\n"); t_reply("500","could not contact voicemail"); }; }; log(1, "**************** vm start - end ******************\n"); break; }; if(method=="BYE"){ log(1, "**************** vm end/refer - begin ******************\n"); if(!vm("/tmp/am_fifo","bye")){ log(1, "could not contact the media server\n"); t_reply("500","could not contact the media server"); }; log(1, "**************** vm end/refer - end ********************\n"); break; }; } /* failure route block for msilo */ failure_route[1] { log(1, "failure_route block 1\n"); # forwarding failed -- check if the request was a MESSAGE if (!method=="MESSAGE") { break; }; log(1,"MSILO: the downstream UA does not support MESSAGE requests ...\n"); # we have changed the R-URI with the contact address -- ignore it now if (m_store("1")) { log(1, "MSILO: offline message stored\n"); t_reply("202", "Accepted"); }else{ log(1, "MSILO: offline message NOT stored\n"); t_reply("503", "Service Unavailable"); }; }