Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titlemydomain.com.js
borderStylesolid

function is_mysipdomain_routable(profile)
{
    var ifaceAddr = profile.sipMessage.getInterfaceAddress();
    var ifacePort = profile.sipMessage.getInterfacePort();
    var ds = profile.sipMessage.getRequestUriUser();
    var domain = profile.sipMessage.getFromHost();
    var ts = profile.sipMessage.getToUser();

    if (is_my_pbx_routable(profile, ifaceAddr, ifacePort, ds, domain, ts))
        return true;
    else if (is_my_sip_trunk_routable(profile, ifaceAddr, ifacePort, ds, domain))
             return true;
}

function is_my_sip_trunk_routable(profile, ifaceAddr, ifacePort, ds, domain)
{

    if (typeof ds != "string")
        return false;
//
// Check if the packet came in using the LAN interface
//
    if ( ifaceAddr != sip_interface_address[1] ||
               ifacePort != sip_interface_port[1])
        return false;
//
// Route it to our ITSP
//
    profile.setTargetDomain("myitsp.com");
    profile.setTargetAddress("udp", "proxy.myitsp.com", "5060");
//
// Use the WAN interface to send it out
//
    profile.setInterfaceAddress(sip_interface_address[0], sip_interface_port[0]);
//
// Bridge it using our account
//

    var pattern=/\b((\d\d\d)|((1)\d\d\d))?(\d{7})\b/;
    var pattern2=/\b9((\d\d\d)|((1)\d\d\d))?(\d{7})\b/;
    var pattern_ac=/\b(1?(\d\d\d))\b/;
    var pattern_am=/\b((\d\d\d)(\d\d\d)?)\b/;

    if ( pattern.test(ds) == true )
       {
        profile.sipMessage.setRequestUriUser( "1" + (ds.replace(pattern, "$1").replace(pattern_ac, "$2") + "888").replace(pattern_am, "$2") + ds.replace(pattern, "$5") );
        profile.sipMessage.setFromUser("user");
        profile.bridge("user", "passwd");
       }
    else if ( pattern2.test(ds) == true )
       {
        profile.sipMessage.setRequestUriUser( "1" + (ds.replace(pattern2, "$1").replace(pattern_ac, "$2") + "888").replace(pattern_am, "$2") + ds.replace(pattern2, "$5") );
        profile.sipMessage.setFromUser("user2");
        profile.bridge("user2", "passwd2");
       }
    else return false;

    return true;
}

function is_my_pbx_routable(profile, ifaceAddr, ifacePort, ds, domain, ts)
{

    if (typeof domain != "string")
        return false;
//
// Check if the packet came in using the WAN interface
//
    if ( ifaceAddr != sip_interface_address[0] ||
              ifacePort != sip_interface_port[0])
        return false;
//
// Check if the domain is valid
//
    if (domain != "mydomain.com")
        return false;
//
// route it to our PBX
//
    profile.setTargetDomain("mydomain.com");
    profile.setTargetAddress("udp", "sipx.mydomain.com", "5060");
//
// Use the LAN interface to send it out
//
    profile.setInterfaceAddress(sip_interface_address[1], sip_interface_port[1]);
//    profile.setInterfaceAddress("192.168.2.2", "5060");
//
// Check if the source address is the ITSP. If yes, bridge it
//
    if (profile.sipMessage.getSourceAddress() == "10.0.168.10")
       {
        if (ts == "1XXXXXXX181")
           {
            profile.sipMessage.setRequestUriUser("501");
            profile.bridge("501", "sipxpasswd");
           }
        else if (ts == "1XXXXXXX139")
           {
            profile.sipMessage.setRequestUriUser("503");
            profile.bridge("503", "sipxpasswd");
           }
        else if (ts == "1XXXXXXXX07")
           {
            profile.sipMessage.setRequestUriUser("504");
            profile.bridge("504", "sipxpasswd");
           }
        else if (ts == "1XXXXXXXX82")
           {
            profile.sipMessage.setRequestUriUser("1XXXXXXXX82");
            profile.bridge("514", "sipxpasswd");
           }
        else if (ts == "1XXXXXXXX67")
           {
            profile.sipMessage.setRequestUriUser("501");
            profile.bridge("501", "sipxpasswd");
           }
       }

    return true;
}