[Users] How to log the username of caller and callee to acc table?

Charles Wang lazy.charles at gmail.com
Thu May 17 17:44:38 CEST 2007


 Hi all,

I ever used SER and I know it will save the From information such as
101 at 192.168.11.200 to sip_from or from_uri in its acc table.
But in my openser, I also setup the acc module. Where is my caller info?

I can find a lot of number such as "2806655523" in my from_tag.
I wanna store the caller and callee info in my acc table when I make an
internal call or an external call.

Can anybody kind to help me to solve it? or give me some tips please.
PS: I got this openser.cfg from http://www.sipwise.com/wizard.

Best regards,
Charles

########################################################################
# Parts of my openser.cfg Configuration
########################################################################

loadmodule "acc.so"
modparam("acc", "early_media", 0)
modparam("acc", "failed_transaction_flag", 24)
modparam("acc", "report_ack", 0)
modparam("acc", "report_cancels", 0)
modparam("acc", "log_flag", 0)
modparam("acc", "log_missed_flag", 0)
modparam("acc", "log_level", 2)
modparam("acc", "db_flag", 25)
modparam("acc", "db_missed_flag", 0)
modparam("acc", "db_table_acc", "acc")
modparam("acc", "db_table_missed_calls", "missed_calls")
modparam("acc", "db_url", "mysql://openser:openserrw@localhost /openser")
modparam("acc", "acc_method_column", "method")
modparam("acc", "acc_callid_column", "callid")
modparam("acc", "acc_time_column", "time")
modparam("acc", "acc_totag_column", "to_tag")
modparam("acc", "acc_from_tag_column", "from_tag")
modparam("acc", "detect_direction", 1)
modparam("acc", "acc_sip_code_column", "sip_code")
modparam("acc", "acc_sip_reason_column", "sip_reason")
modparam("acc", "multi_leg_info", "src_leg=$avp(i:901);dst_leg=$avp(i:902)")

########################################################################
# Request route 'main'
########################################################################
route[0]
{
 xlog("L_INFO", "New request - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");

 force_rport();
 if(msg:len > max_len)
 {

  xlog("L_INFO", "Message too big - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  sl_send_reply("513", "Message Too Big");
  exit;
 }
 if (!mf_process_maxfwd_header("10"))
 {

  xlog("L_INFO", "Too many hops - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  sl_send_reply("483", "Too Many Hops");
  exit;
 }
 if(!is_method("REGISTER"))
 {
  if(nat_uac_test("19"))
  {
   record_route(";nat=yes");
  }
  else
  {
   record_route();
  }
 }
 if(is_method("CANCEL") || is_method("BYE"))
 {
  end_media_session();
 }
 if(loose_route())
 {
  if(!has_totag())
  {

   xlog("L_INFO", "Initial loose-routing rejected - M=$rm RURI=$ru F=$fu
T=$tu IP=$si ID=$ci\n");
   sl_send_reply("403", "Initial Loose-Routing Rejected");
   exit;
  }
  if(nat_uac_test("19") || search("^Route:.*;nat=yes"))
  {
   fix_nated_contact();
   if(!search("^Content-Length:[ ]*0"))
   {
    setbflag(6);
   }
  }
  if(is_method("BYE"))
  {
   setflag(24); # account failed transactions
   setflag(25); # account successful transactions
  }
  # mark as loose-routed for acc
  setflag(26);

  route(11);
 }
 if(is_method("REGISTER"))
 {
  route(10);
 }
 setflag(24); # account failed transactions
 setflag(25); # account successful transactions
 if(is_method("INVITE"))
 {
  route(12);
 }
 if(is_method("CANCEL") || is_method("ACK"))
 {
  route(16);
 }

 route(17);
}

########################################################################
# Request route 'clear-usr-preferences-caller'
########################################################################
route[1]
{
 xlog("L_INFO", "Clear caller preferences - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
 avp_delete("$avp(s:caller_cli)/g");
 avp_delete("$avp(s:clir)/g");

}

########################################################################
# Request route 'clear-usr-preferences-callee'
########################################################################
route[2]
{
 xlog("L_INFO", "Clear callee preferences - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
 avp_delete("$avp(s:callee_fr_inv_timer)/g");
 avp_delete("$avp(s:cfu)/g");

}

########################################################################
# Request route 'usr-preferences-caller'
############################################################ ############
route[3]
{
 route(1);
 xlog("L_INFO", "Load caller preferences for uuid '$avp(s:caller_uuid)' -
M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
 # load caller avps
 avp_db_load("$avp(s:caller_uuid)", "*");
 avp_copy("$avp(s:cli)", "$avp(s:caller_cli)/d");
 if(is_avp_set("$avp(s:clir)/n") && avp_check("$avp(s:clir)", "eq/i:1"))
 {
  # mark for anonymization
  setflag(28);
 }

}

########################################################################
# Request route 'usr-preferences-callee'
########################################################################
route[4]
{
 xlog("L_INFO", "Load callee preferences for uuid '$avp(s:callee_uuid)' -
M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
 # load callee avps
 avp_db_load("$avp(s:callee_uuid)", "*");
 if(is_avp_set("$avp(s:cfu)/s"))
 {

  xlog("L_INFO", "Call-forward-unconditional to '$avp(s:cfu)' found - M=$rm
RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
  route(5);
  route(6);
  avp_delete("$avp(s:caller_uuid)/g");
  avp_copy("$avp(s:callee_uuid)", "$avp(s:caller_uuid)/d");
  avp_pushto("$ru", "$avp(s:cfu)");

  route(3);
  route(13);
  exit;
 }
 if(is_avp_set("$avp(s:ringtimeout)/n"))
 {

  xlog("L_INFO", "Setting ring timeout to $avp(s:ringtimeout) secs - M=$rm
RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
  avp_copy("$avp(s:ringtimeout)", "$avp(s:callee_fr_inv_timer)/d");
 }

}

########################################################################
# Request route 'acc-caller'
############################################################ ############
route[5]
{
 xlog("L_INFO", "Setting acc source-leg for uuid '$avp(s:caller_uuid)' -
M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
 avp_printf("$avp(i:901)", "$avp(s:caller_uuid)|$fU|$fd");

}

########################################################################
# Request route 'acc-callee'
########################################################################
route[6]
{
 xlog("L_INFO", "Setting acc destination-leg for uuid '$avp(s:callee_uuid)'
- M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
 avp_printf("$avp(i:902)", "$avp(s:callee_uuid)|$rU|$rd");

}

########################################################################
# Request route 'acc-failure'
########################################################################
route[7]
{
 xlog("L_INFO", "Accounting failed request for uuid '$avp(s:caller_uuid)' -
M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
 route(5);
 route(6);
 resetflag(24);
 acc_db_request("404", "acc");

}

########################################################################
# Request route 'clir'
########################################################################
route[8]
{
 if(isflagset(28) && !isflagset(27))
 {
  setflag(27);

  xlog("L_INFO", "Anonymize caller - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  uac_replace_from("Anonymous"," sip:anonymous at anonymous.invalid");
  if(is_present_hf("Privacy"))
  {
   remove_hf("Privacy");
  }
  append_hf("Privacy: id\r\n");
 }

}

########################################################################
# Request route 'stop-media-proxy'
########################################################################
route[9]
{
 if(isflagset(22))
 {
  end_media_session();
 }

}

########################################################################
# Request route 'base-route-register'
########################################################################
route[10]
{
 sl_send_reply("100", "Trying");
 if(!www_authorize("", "subscriber"))
 {

  xlog("L_INFO", "Register authentication failed - M=$rm RURI=$ru F=$fu
T=$tu IP=$si ID=$ci\n");
  www_challenge("", "0");
  exit;
 }
 if(!check_to())
 {

  xlog("L_INFO", "Spoofed To-URI detected - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
  sl_send_reply("403", "Spoofed To-URI Detected");
  exit;
 }
 consume_credentials();
 if(!search("^Contact:[ ]*\*") && nat_uac_test("19"))
 {
  fix_nated_register();
  setbflag(6);
 }
 if(!save("location"))
 {

  xlog("L_ERR", "Saving contact failed - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  sl_reply_error();
  exit;
 }

 xlog("L_INFO", "Registration successful - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
 exit;

}

########################################################################
# Request route 'base-outbound'
########################################################################
route[11]
{
 if(is_present_hf("P-Asserted-Identity"))
 {
  remove_hf("P-Asserted-Identity");
 }
 if(is_present_hf("Remote-Party-ID"))
 {
  remove_hf("Remote-Party-ID");
 }
 if(is_avp_set("$avp(s:caller_cli)/s"))
 {
  if(!isflagset(28))
  {

   xlog("L_INFO", "Set caller CLI '$avp(s:caller_cli)' - M=$rm RURI=$ru
F=$fu T=$tu IP=$si ID=$ci\n");
   append_hf("P-Asserted-Identity: <$avp(s:caller_cli)>\r\n");
  }
 }

 route(8);
 if(isbflagset(6) && !isflagset(22))
 {
  setflag(22);
  fix_nated_contact();
  use_media_proxy();

  t_on_reply("2");
 }
 else
 {

  t_on_reply("1");
 }

 xlog("L_INFO", "Request leaving server - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
 if(!isflagset(21))
 {

  t_on_failure("2");
  if(!isflagset(26))
  {

   route(5);
   route(6);
  }
 }
 if(!t_relay())
 {
  sl_reply_error();
  if(is_method("INVITE") && isbflagset(6))
  {
   end_media_session();
  }
 }
 exit;

}

########################################################################
# Request route 'base-route-invite'
########################################################################
route[12]
{
 sl_send_reply("100", "Trying");
 if(from_gw())
 {
  $avp(s:caller_uuid) = "0";

  xlog("L_INFO", "Call from PSTN' - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  setflag(23);
 }
 else
 {
  if(allow_trusted())
  {
   if(is_avp_set("$avp(s:peer_uuid)/s"))
   {
    # use tag-column from trusted-table as uuid for this caller
    avp_copy("$avp(s:peer_uuid)", "$avp(s:caller_uuid)/d");
   }
   else
   {
    # if no uuid is set, use "0" as default uuid
    $avp(s:caller_uuid) = "0";
   }

   xlog("L_INFO", "Call from trusted peer with uuid '$avp(s:caller_uuid)' -
M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
   if(!is_domain_local("$rd"))
   {

    xlog("L_INFO", "Rejecting peering attempt with non-local request domain
- M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
    sl_send_reply("403", "Relaying Denied");
    exit;
   }
   setflag(23);
  }
  else
  {
   if(!proxy_authorize("", "subscriber"))
   {

    xlog("L_INFO", "Proxy authentication failed - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
    proxy_challenge("", "0");
    exit;
   }
   if(!check_from())
   {

    xlog("L_INFO", "Spoofed From-URI detected - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
    sl_send_reply("403", "Spoofed From-URI Detected");
    exit;
   }
   consume_credentials();
  }
 }

 route(3);
 if(nat_uac_test("19"))
 {
  setbflag(6);
 }

 route(13);
}

########################################################################
# Request route 'invite-find-callee'
########################################################################
route[13]
{
 if(lookup("aliases"))
 {

  xlog("L_INFO", "Callee was aliased - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
 }

 route(2);
 if(!is_domain_local("$rd"))
 {
  setflag(20);
  $avp(s:callee_uuid) = "0";

  route(15);
 }
 avp_delete("$avp(s:callee_uuid)");
 avp_db_query("select uuid from subscriber where username = '$rU'",
"$avp(s:callee_uuid)");
 if(is_avp_set("$avp(s:callee_uuid)/s"))
 {

  xlog("L_INFO", "Callee is local, uuid='$avp(s:callee_uuid)' - M=$rm
RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
  route(14);
 }
 else
 {
  $avp(s:callee_uuid) = "0";

  xlog("L_INFO", "Callee is not local - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  route(15);
 }
 exit;
}

########################################################################
# Request route 'invite-to-internal'
########################################################################
route[14]
{
 route(4);
 if(!lookup("location"))
 {
  xlog("L_INFO", "Local user offline - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  route(7);
  sl_send_reply("404", "User Offline");
 }
 else
 {
  xlog("L_INFO", "Local user online - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  route(11);
 }
 exit;
}

########################################################################
# Request route 'invite-to-external'
########################################################################
route[15]
{
 if(isflagset(20))
 {
  xlog("L_INFO", "Call to foreign domain - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  route(11);
  exit;
 }
 if(!isflagset(23))
 {
  # don't allow calls relaying from PSTN to PSTN, if not explicitely
forwarded
  if(uri =~ "^sip:0[0-9]+@")
  {
   # only route numeric users to PSTN
   xlog("L_INFO", "Loading PSTN gateways - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
   if(!load_gws())
   {
    xlog("L_ERR", "Error loading PSTN gateways - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
    sl_send_reply("503", "PSTN Termination Currently Unavailable");
    exit;
   }
   if(!next_gw())
   {
    xlog("L_ERR", "No PSTN gateways available - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
    sl_send_reply("503", "PSTN Termination Currently Unavailable");
    exit;
   }
   setflag(21);
   t_on_failure("1");
   route(11);
  }
 }
 xlog("L_INFO", "Call to unknown user - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
 route(7);
 sl_send_reply("404", "User Not Found");
 exit;
}

########################################################################
# Request route 'base-route-local'
########################################################################
route[16]
{
 t_on_reply("1");
 if(t_check_trans())
 {
  xlog("L_INFO", "Request leaving server - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
  if(!t_relay())
  {
   sl_reply_error();
  }
 }
 else
 {
  xlog("L_INFO", "Dropping mis-routed request - M=$rm RURI=$ru F=$fu T=$tu
IP=$si ID=$ci\n");
 }
 exit;
}

########################################################################
# Request route 'base-route-generic'
########################################################################
route[17]
{
 xlog("L_INFO", "Method not supported - M=$rm RURI=$ru F=$fu T=$tu IP=$si
ID=$ci\n");
 sl_send_reply("501", "Method Not Supported Here");
 exit;

}

# Request route 'base-filter-failover'
route[18]
{
 if(!t_check_status("408|500|503"))
 {

  xlog("L_INFO", "No failover routing needed for this response code - M=$rm
RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
  route(9);
  exit;
 }

}

# Reply route 'base-standard-reply'
onreply_route[1]
{
 xlog("L_INFO", "Reply - S=$rs D=$rr F=$fu T=$tu IP=$si ID=$ci\n");
 exit;

}

# Reply route 'base-nat-reply'
onreply_route[2]
{
 xlog("L_INFO", "NAT-Reply - S=$rs D=$rr F=$fu T=$tu IP=$si ID=$ci\n");
 if(nat_uac_test("1"))
 {
  fix_nated_contact();
 }
 if(isbflagset(6) && status=~"(180)|(183)|2[0-9][0-9]")
 {
  if(!search("^Content-Length:[ ]*0"))
  {
   use_media_proxy();
  }
 }
 exit;
}


-- 

Best Regards
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20070517/17de9f3e/attachment.htm>


More information about the sr-users mailing list