– Kamailio SIP Server –

Inside Group Dialling

The PBX specify the features of grouping global extensions and assign shorter number to reach them. For example, people inside same department can call each other using shorter numbers than dialling entire 10 digit long extension.

To get this feature you need: - assign to each user a group id - map shorter number to full extension for each group

Assign Group ID

The easiest and faster way is to extend subscriber table with one extra column where to store the group id:

ALTER TABLE subscriber ADD COLUMN pbxgroupid INT NOT NULL DEFAULT 0;

Then, set the load_credentials parameter of auth_db module to load the value upon caller authentication:

modparam("auth_db", "load_credentials", "$avp(s:pbxgroupid)=pbxgroupid")

Map Group Extensions

Create the table to store the mappings:

CREATE TABLE pbxgroups (
  id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
  username VARCHAR(64) DEFAULT '' NOT NULL,
  domain VARCHAR(128) DEFAULT '' NOT NULL,
  groupid INT DEFAULT 0 NOT NULL,
  shortdial VARCHAR(16) DEFAULT '' NOT NULL,
  extension VARCHAR(64) DEFAULT '' NOT NULL,
  CONSTRAINT pg_u UNIQUE (username, domain, groupid, shortdial)
) ENGINE=MyISAM;

Config File Route

You have to load sqlops module and set database a connection, for example:

loadmodule "sqlops.so"

modparam("sqlops","sqlcon","ca=>mysql://openser:openserrw@localhost/openser")

You have to insert following route in your config and call it when your dialling plan rules requires. Remember, it has to be called after the caller has been authenticated:

route[30] {
    sql_query("ca"
        "select extension from pbxgroups where groupid=$avp(s:pbxgroupid) and username='$fU' and domain='$fd' and shortdial='$rU'",
        "ra");
    if($dbr(ra=>rows)>0)
        $rU = $dbr(ra=>[0,0]);
    sql_result_free("ra");
}

Example of Usage

Call the route when the dialed extension has 4 digits:

if($rU=~"^[0-9]{4}$")
   route(30);

Remarks

* if you have a single domain deployment, then you can remove the 'domain' column from table and sql_query(…) * you can store full URI in extension column, then use next in route[30]:

if($dbr(ra=>rows)>0)
  $ru = $dbr(ra=>[0,0]);

ToC