diff --git a/deploy/kamailio/Dockerfile b/deploy/kamailio/Dockerfile index 0fdab5c..8c36e5a 100644 --- a/deploy/kamailio/Dockerfile +++ b/deploy/kamailio/Dockerfile @@ -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/ diff --git a/deploy/kamailio/config/kamailio.cfg b/deploy/kamailio/config/kamailio.cfg index 86e1c98..8660cf0 100644 --- a/deploy/kamailio/config/kamailio.cfg +++ b/deploy/kamailio/config/kamailio.cfg @@ -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) @@ -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) diff --git a/deploy/kamailio/config/request_gw.py b/deploy/kamailio/config/request_gw.py index d03771d..ae0621c 100755 --- a/deploy/kamailio/config/request_gw.py +++ b/deploy/kamailio/config/request_gw.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import sys -import Router.Logger as Logger import KSR as KSR import httplib2 import json @@ -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: @@ -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