Skip to content

Commit

Permalink
Update openSIPS IMS configuration files
Browse files Browse the repository at this point in the history
Co-authored-by: Razvan Crainea <[email protected]>
  • Loading branch information
herlesupreeth and razvancrainea committed Jan 17, 2025
1 parent 2dc170e commit 5ae69db
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
41 changes: 41 additions & 0 deletions opensips_ims_pcscf/opensips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ mpath="/usr/lib/x86_64-linux-gnu/opensips/modules"

####### Modules Section ########

#### MYSQL module
loadmodule "db_mysql.so"

#### SIGNALING module
loadmodule "signaling.so"

Expand Down Expand Up @@ -135,6 +138,18 @@ modparam("rtpengine", "rtpengine_sock", "udp:RTPENGINE_IP:2223")
loadmodule "event_route.so"
loadmodule "json.so"

#### PRESENCE modules
loadmodule "presence.so"
loadmodule "presence_reginfo.so"
loadmodule "pua.so"
modparam("pua","db_url", "mysql://opensips_pcscf:heslo@MYSQL_IP/opensips_pcscf")

loadmodule "pua_reginfo.so"

modparam("pua_reginfo", "ul_domain", "location")
modparam("pua_reginfo", "ul_identities_key", "identities")
modparam("pua_reginfo", "default_domain", "IMS_DOMAIN")
modparam("pua_reginfo", "server_address", "sip:[email protected]_DOMAIN")


####### Routing Logic ########
Expand Down Expand Up @@ -180,6 +195,11 @@ route{
t_on_reply("rtpengine_answer");
}

if (is_method("SUBSCRIBE|NOTIFY") && is_myself($rd)) {
route(handle_presence);
exit;
}

# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(relay);
Expand Down Expand Up @@ -208,6 +228,10 @@ route{
t_on_reply("register_reply");
route(relay);
exit;
} else if (is_method("SUBSCRIBE|PUBLISH")) {
xlog("L_INFO", "[$ci] Received $rm for $tu - handling\n");
route(handle_presence);
exit;
} else if (is_method("INVITE")) {
if (loose_route()) {
xlog("L_INFO", "[$ci] Received INVITE for $tu - relaying to S-CSCF ($ru/$du)\n");
Expand Down Expand Up @@ -436,3 +460,20 @@ event_route[E_DM_REQUEST] {

}
}

route[handle_presence] {
if (!t_newtran()){
sl_reply_error();
exit;
}
if ($hdr(Event) != "reg") {
xlog("L_ERR", "[$ci] Unhandled event $hdr(Event)\n");
send_reply(489, "Bad Event");
exit;
}

if (is_method("PUBLISH"))
handle_publish();
if (is_method("SUBSCRIBE"))
handle_subscribe();
}
25 changes: 25 additions & 0 deletions opensips_ims_pcscf/pcscf_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ cp /mnt/pcscf/pcscf.dictionary /etc/opensips
cp /mnt/pcscf/opensips.cfg /etc/opensips
cp -r /mnt/pcscf/db /etc/opensips

while ! mysqladmin ping -h ${MYSQL_IP} --silent; do
sleep 5;
done

# Sleep until permissions are set
sleep 10;

# Create PCSCF database, populate tables and grant privileges
if [[ -z "`mysql -u root -h ${MYSQL_IP} -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='opensips_pcscf'" 2>&1`" ]];
then
mysql -u root -h ${MYSQL_IP} -e "create database opensips_pcscf;"
mysql -u root -h ${MYSQL_IP} opensips_pcscf < /usr/share/opensips/mysql/standard-create.sql
mysql -u root -h ${MYSQL_IP} opensips_pcscf < /usr/share/opensips/mysql/presence-create.sql
PCSCF_USER_EXISTS=`mysql -u root -h ${MYSQL_IP} -s -N -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE User = 'opensips_pcscf' AND Host = '%')"`
if [[ "$PCSCF_USER_EXISTS" == 0 ]]
then
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'opensips_pcscf'@'%' IDENTIFIED WITH mysql_native_password BY 'heslo'";
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'opensips_pcscf'@'$PCSCF_IP' IDENTIFIED WITH mysql_native_password BY 'heslo'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON opensips_pcscf.* TO 'opensips_pcscf'@'%'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON opensips_pcscf.* TO 'opensips_pcscf'@'$PCSCF_IP'";
mysql -u root -h ${MYSQL_IP} -e "FLUSH PRIVILEGES;"
fi
fi

sed -i 's|PCSCF_IP|'$PCSCF_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|IMS_DOMAIN|'$IMS_DOMAIN'|g' /etc/opensips/opensips.cfg
sed -i 's|EPC_DOMAIN|'$EPC_DOMAIN'|g' /etc/opensips/opensips.cfg
sed -i 's|SCSCF_IP|'$SCSCF_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|RTPENGINE_IP|'$RTPENGINE_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|MYSQL_IP|'$MYSQL_IP'|g' /etc/opensips/opensips.cfg

sed -i 's|PCRF_BIND_PORT|'$PCRF_BIND_PORT'|g' /etc/opensips/freeDiameter.conf
sed -i 's|PCSCF_BIND_PORT|'$PCSCF_BIND_PORT'|g' /etc/opensips/freeDiameter.conf
Expand Down
5 changes: 2 additions & 3 deletions opensips_ims_scscf/opensips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ route{
$rU = $(rU{s.select,0,;});
}
if (!dp_translate(1, $rU, $var(dialplan))) {
xlog("L_ERR", "[$ci] dial $rU not in dialplan\n");
t_reply(404, "Unknown user");
exit;
$var(dialplan) = "USER";
xlog("L_DBG", "[$ci] unknown dialplan - considering $var(dialplan)\n");
}
xlog("L_INFO", "[$ci] Dial $rU is a $var(dialplan) dialplan\n");
switch ($var(dialplan)) {
Expand Down

0 comments on commit 5ae69db

Please sign in to comment.