Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions deploy/kamailio/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
FROM ghcr.io/kamailio/kamailio:5.6.3-bullseye
FROM ghcr.io/kamailio/kamailio:6.1.4-trixie

RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-dev python3-pip cron \
&& apt autoremove -y \
&& apt autoclean -y

RUN pip3 install --upgrade pip
RUN pip3 install --upgrade setuptools
RUN pip3 install requests httplib2 mysql-connector-python
RUN pip3 install --break-system-packages requests httplib2 mysql-connector-python

WORKDIR /etc/kamailio/

Expand Down
2 changes: 1 addition & 1 deletion deploy/kamailio/config/kamailio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ loadmodule "siptrace.so"

# ------ dialog -------
modparam("dialog", "enable_stats", 1)
modparam("dialog", "dlg_flag", 4)
modparam("dialog", "hash_size", 4096)
modparam("dialog", "db_url", DBURL)
modparam("dialog", "db_mode", 1)
Expand All @@ -349,6 +348,7 @@ modparam("dialog", "db_mode", 1)
modparam("app_python3", "load", "/etc/kamailio/request_gw.py")
modparam("app_python3", "mod_init_function", "mod_init")
modparam("app_python3", "child_init_method", "child_init")
modparam("app_python3", "threads_mode", 1)

# ------ ssl -------
#modparam("tls", "tls_force_run", 1)
Expand Down
31 changes: 19 additions & 12 deletions deploy/kamailio/config/request_gw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import sys
import Router.Logger as Logger
import KSR as KSR
import httplib2
import json
Expand All @@ -12,6 +11,14 @@
from contextlib import closing
from configparser import ConfigParser


class Logger:
"""Kamailio 6 dropped the legacy Router module: log through KSR."""
@staticmethod
def LM_ERR(text):
KSR.err(text)


parser = ConfigParser()
parser.optionxform = str
with open("/etc/kamailio/kamctlrc") as stream:
Expand Down Expand Up @@ -100,27 +107,27 @@ def lockGw (self):

def handler(self, msg, args):
Logger.LM_ERR("Loggers.py: LM_ERR: msg: %s" % str(args))
Logger.LM_ERR('RequestGw.handler(%s, %s)\n' % (msg.Type, str(args)))
if (msg.Type == 'SIP_REQUEST' and
(any((msg.RURI).find(d) != -1 for d in self.sipDomains) or
(msg.RURI).find(self.publicIP) != -1)):
if msg.Method == 'INVITE' and (msg.RURI).find(self.gwNamePart) == -1:
Logger.LM_ERR('SIP request, method = %s, RURI = %s, From = %s\n' % (msg.Method, msg.RURI, msg.getHeader('from')))
uri = msg.RURI
Logger.LM_ERR('RequestGw.handler(%s, %s)\n' % (KSR.pv.get("$mt"), str(args)))
if (KSR.pv.get("$mt") == 1 and
(any(KSR.pv.get("$ru").find(d) != -1 for d in self.sipDomains) or
KSR.pv.get("$ru").find(self.publicIP) != -1)):
if KSR.pv.get("$rm") == 'INVITE' and KSR.pv.get("$ru").find(self.gwNamePart) == -1:
Logger.LM_ERR('SIP request, method = %s, RURI = %s, From = %s\n' % (KSR.pv.get("$rm"), KSR.pv.get("$ru"), KSR.pv.get("$hdr(From)")))
uri = KSR.pv.get("$ru")
room = (uri.split(":", 1)[1]).split('@')[0]
displayName = ""
if "<" in msg.getHeader('from'):
displayName = (msg.getHeader('from').split('<')[0])
if "<" in KSR.pv.get("$hdr(From)"):
displayName = (KSR.pv.get("$hdr(From)").split('<')[0])
Logger.LM_ERR('Room Name %s\n' % room )
gwRes = self.lockGw()
if gwRes:
gwUri = gwRes['username']
gwSocket = gwRes['socket'].split(':')[1]
Logger.LM_ERR('Returned Gateway: %s\n' % gwUri)
msg.rewrite_ruri("sip:%s@%s" % (gwUri, gwSocket))
KSR.pv.sets("$ru", "sip:%s@%s" % (gwUri, gwSocket))
displayNameWRoom = '"%s-%s%s"' % (str(len(room)), room, displayName.replace('"',''))
KSR.uac.uac_replace_from(displayNameWRoom, "")
Logger.LM_ERR('########## SIP request, method = %s, RURI = %s, From = %s\n' % (msg.Method, msg.RURI, msg.getHeader('from')))
Logger.LM_ERR('########## SIP request, method = %s, RURI = %s, From = %s\n' % (KSR.pv.get("$rm"), KSR.pv.get("$ru"), KSR.pv.get("$hdr(From)")))

return 1

Expand Down
Loading