From 6293d8a78a600d72e405804f746581584215cb7b Mon Sep 17 00:00:00 2001 From: Ruslan Makhmatkhanov Date: Tue, 4 Oct 2022 15:20:37 +0300 Subject: [PATCH 01/17] Correct options descriptions: add missing start word --- jasmin/bin/jasmind.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jasmin/bin/jasmind.py b/jasmin/bin/jasmind.py index f36280972..82009ca8b 100755 --- a/jasmin/bin/jasmind.py +++ b/jasmin/bin/jasmind.py @@ -58,9 +58,9 @@ class Options(usage.Options): ['enable-dlr-thrower', None, 'Enable DLR Thrower service (not recommended: start the dlrd daemon instead)'], ['enable-dlr-lookup', None, 'Enable DLR Lookup service (not recommended: start the dlrlookupd daemon instead)'], # @TODO: deliver-thrower must be executed as a standalone process, just like dlr-thrower - ['disable-deliver-thrower', None, 'Do not DeliverSm Thrower service'], - ['disable-http-api', None, 'Do not HTTP API'], - ['disable-jcli', None, 'Do not jCli console'], + ['disable-deliver-thrower', None, 'Do not start DeliverSm Thrower service'], + ['disable-http-api', None, 'Do not start HTTP API'], + ['disable-jcli', None, 'Do not start jCli console'], ['enable-interceptor-client', None, 'Start Interceptor client'], ] From 6757a91401ce56151b9395e4f0699e83eebb3076 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:04:05 +0400 Subject: [PATCH 02/17] docker restapi set to slim --- docker/Dockerfile.restapi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile.restapi b/docker/Dockerfile.restapi index 750a421ed..03a220325 100644 --- a/docker/Dockerfile.restapi +++ b/docker/Dockerfile.restapi @@ -1,4 +1,4 @@ -FROM python:3-buster +FROM python:3.11-slim-bullseye MAINTAINER Jookies LTD From d6f5fc26de129b21426fd752dd00fb233efe24ef Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:04:55 +0400 Subject: [PATCH 03/17] python with jemalloc --- docker/Dockerfile.restapi | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile.restapi b/docker/Dockerfile.restapi index 03a220325..23bb16ff9 100644 --- a/docker/Dockerfile.restapi +++ b/docker/Dockerfile.restapi @@ -9,14 +9,16 @@ RUN groupadd -r jasmin && useradd -r -g jasmin jasmin RUN apt-get update && apt-get install -y \ libffi-dev \ libssl-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + # Run python with jemalloc + # More on this: + # - https://zapier.com/engineering/celery-python-jemalloc/ + # - https://paste.pics/581cc286226407ab0be400b94951a7d9 + libjemalloc2 -# For RestAPI MODE -ENV RESTAPI_MODE 0 -ENV RESTAPI_OLD_HTTP_HOST '127.0.0.1' +RUN apt-get clean && rm -rf /var/lib/apt/lists/* -ENV ENABLE_PUBLISH_SUBMIT_SM_RESP 0 +# Run python with jemalloc +ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 ENV ROOT_PATH / ENV CONFIG_PATH /etc/jasmin From 3e7e37089b4a24be7d50d611f26efcfbce4f7f31 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:05:17 +0400 Subject: [PATCH 04/17] cleanup --- docker/Dockerfile.restapi | 20 ++++++++++++++++---- docker/restapi-docker-entrypoint.sh | 12 ++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile.restapi b/docker/Dockerfile.restapi index 23bb16ff9..83c18cd1e 100644 --- a/docker/Dockerfile.restapi +++ b/docker/Dockerfile.restapi @@ -22,11 +22,11 @@ ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 ENV ROOT_PATH / ENV CONFIG_PATH /etc/jasmin -ENV RESOURCE_PATH /etc/jasmin/resource -ENV STORE_PATH /etc/jasmin/store +ENV RESOURCE_PATH ${CONFIG_PATH}/resource +ENV STORE_PATH ${CONFIG_PATH}/store ENV LOG_PATH /var/log/jasmin -RUN mkdir -p ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} +RUN mkdir -p ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} RUN chown jasmin:jasmin ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} WORKDIR /build @@ -41,10 +41,22 @@ RUN pip install gunicorn ENV UNICODEMAP_JP unicode-ascii COPY misc/config/*.cfg ${CONFIG_PATH}/ -COPY misc/config/resource/*.xml ${RESOURCE_PATH}/ +COPY misc/config/resource ${RESOURCE_PATH} WORKDIR /etc/jasmin +# Default Redis and RabbitMQ connections +ENV AMQP_BROKER_HOST 'rabbitmq' +ENV AMQP_BROKER_PORT 5672 +ENV REDIS_CLIENT_HOST 'redis' +ENV REDIS_CLIENT_PORT 6379 + +# For RestAPI MODE +ENV RESTAPI_MODE 0 +ENV RESTAPI_OLD_HTTP_HOST '127.0.0.1' + +ENV ENABLE_PUBLISH_SUBMIT_SM_RESP 0 + # Change binding host for jcli RUN sed -i '/\[jcli\]/a bind=0.0.0.0' ${CONFIG_PATH}/jasmin.cfg # Change binding port for redis, and amqp diff --git a/docker/restapi-docker-entrypoint.sh b/docker/restapi-docker-entrypoint.sh index 9ece3310c..68db4a223 100755 --- a/docker/restapi-docker-entrypoint.sh +++ b/docker/restapi-docker-entrypoint.sh @@ -2,10 +2,10 @@ set -e # Change binding host:port for redis, and amqp -sed -i "/\[redis-client\]/,/host=/ s/host=.*/host=$REDIS_CLIENT_HOST/" /etc/jasmin/jasmin.cfg -sed -i "/\[redis-client\]/,/port=/ s/port=.*/port=$REDIS_CLIENT_PORT/" /etc/jasmin/jasmin.cfg -sed -i "/\[amqp-broker\]/,/host=/ s/host=.*/host=$AMQP_BROKER_HOST/" /etc/jasmin/jasmin.cfg -sed -i "/\[amqp-broker\]/,/port=/ s/port=.*/port=$AMQP_BROKER_PORT/" /etc/jasmin/jasmin.cfg +sed -i "/\[redis-client\]/,/host=/ s/host=.*/host=$REDIS_CLIENT_HOST/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[redis-client\]/,/port=/ s/port=.*/port=$REDIS_CLIENT_PORT/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[amqp-broker\]/,/host=/ s/host=.*/host=$AMQP_BROKER_HOST/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[amqp-broker\]/,/port=/ s/port=.*/port=$AMQP_BROKER_PORT/" ${CONFIG_PATH}/jasmin.cfg echo 'Cleaning lock files' rm -f /tmp/*.lock @@ -23,11 +23,11 @@ else if [ "$ENABLE_PUBLISH_SUBMIT_SM_RESP" = 1 ]; then # Enable publish_submit_sm_resp echo 'Enabling publish_submit_sm_resp' - sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=True/g" /etc/jasmin/jasmin.cfg + sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=True/g" ${CONFIG_PATH}/jasmin.cfg else # Disable publish_submit_sm_resp echo 'Disabling publish_submit_sm_resp' - sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=False/g" /etc/jasmin/jasmin.cfg + sed -i "s/.*publish_submit_sm_resp\s*=.*/publish_submit_sm_resp=False/g" ${CONFIG_PATH}/jasmin.cfg fi if [ "$2" = "--enable-interceptor-client" ]; then From 39ee472e4a4c6924c859db9c5b6ec973e050ca07 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:01:29 +0400 Subject: [PATCH 05/17] dynamic sub-services host/port --- docker/Dockerfile | 42 +++++++++++++++++++++---------------- docker/docker-entrypoint.sh | 10 +++++++++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 75846aefb..ea941b0a2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -20,12 +20,14 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* # Run python with jemalloc ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 -# Install Jasmin SMS gateway -RUN mkdir -p /etc/jasmin/resource \ - /etc/jasmin/store \ - /var/log/jasmin \ - && chown jasmin:jasmin /etc/jasmin/store \ - /var/log/jasmin +ENV ROOT_PATH / +ENV CONFIG_PATH /etc/jasmin +ENV RESOURCE_PATH /etc/jasmin/resource +ENV STORE_PATH /etc/jasmin/store +ENV LOG_PATH /var/log/jasmin + +RUN mkdir -p ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} +RUN chown jasmin:jasmin ${CONFIG_PATH} ${RESOURCE_PATH} ${STORE_PATH} ${LOG_PATH} WORKDIR /build @@ -35,21 +37,25 @@ RUN pip install . ENV UNICODEMAP_JP unicode-ascii -ENV ROOT_PATH / -ENV CONFIG_PATH /etc/jasmin -ENV RESOURCE_PATH /etc/jasmin/resource -ENV STORE_PATH /etc/jasmin/store -ENV LOG_PATH /var/log/jasmin - COPY misc/config/*.cfg ${CONFIG_PATH}/ COPY misc/config/resource ${RESOURCE_PATH} -WORKDIR /usr/jasmin - -# Change binding host for jcli, redis, and amqp -RUN sed -i '/\[jcli\]/a bind=0.0.0.0' /etc/jasmin/jasmin.cfg -RUN sed -i '/\[redis-client\]/a host=redis' /etc/jasmin/jasmin.cfg -RUN sed -i '/\[amqp-broker\]/a host=rabbitmq' /etc/jasmin/jasmin.cfg +WORKDIR /etc/jasmin + +# Default Redis and RabbitMQ connections +ENV AMQP_BROKER_HOST 'rabbitmq' +ENV AMQP_BROKER_PORT 5672 +ENV REDIS_CLIENT_HOST 'redis' +ENV REDIS_CLIENT_PORT 6379 + +# Change binding host for jcli +RUN sed -i '/\[jcli\]/a bind=0.0.0.0' ${CONFIG_PATH}/jasmin.cfg +# Change binding port for redis, and amqp +RUN sed -i "/\[redis-client\]/a port=$REDIS_CLIENT_PORT" ${CONFIG_PATH}/jasmin.cfg +RUN sed -i "/\[amqp-broker\]/a port=$AMQP_BROKER_PORT" ${CONFIG_PATH}/jasmin.cfg +# Change binding host for redis, and amqp +RUN sed -i "/\[redis-client\]/a host=$REDIS_CLIENT_HOST" ${CONFIG_PATH}/jasmin.cfg +RUN sed -i "/\[amqp-broker\]/a host=$AMQP_BROKER_HOST" ${CONFIG_PATH}/jasmin.cfg EXPOSE 2775 8990 1401 VOLUME ["/var/log/jasmin", "/etc/jasmin", "/etc/jasmin/store"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 3be0ad3c0..cbe1e71ed 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,6 +1,16 @@ #!/bin/bash set -e +# Change binding host:port for redis, and amqp +sed -i "/\[redis-client\]/,/host=/ s/host=.*/host=$REDIS_CLIENT_HOST/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[redis-client\]/,/port=/ s/port=.*/port=$REDIS_CLIENT_PORT/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[amqp-broker\]/,/host=/ s/host=.*/host=$AMQP_BROKER_HOST/" ${CONFIG_PATH}/jasmin.cfg +sed -i "/\[amqp-broker\]/,/port=/ s/port=.*/port=$AMQP_BROKER_PORT/" ${CONFIG_PATH}/jasmin.cfg + +echo 'Cleaning lock files' +rm -f /tmp/*.lock + + if [ "$2" = "--enable-interceptor-client" ]; then echo 'Starting interceptord' interceptord.py & From 9981e452e278805fa1426e3bcfb62103040c03be Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Sun, 1 Jan 2023 12:03:50 +0400 Subject: [PATCH 06/17] if path is url, use urllib.request to get --- jasmin/protocols/cli/mointerceptorm.py | 17 ++++++++++++++--- jasmin/protocols/cli/mtinterceptorm.py | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index ba52a89ed..2a4488b70 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -133,9 +133,20 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - # Open file and get its content - with open(script_path, 'r') as content_file: - pyCode = content_file.read() + import os + if os.path.isfile(script_path): + # Open file and get its content + with open(script_path, 'r') as content_file: + pyCode = content_file.read() + else: + # Assume it's a URL + import urllib.request + try: + with urllib.request.urlopen(script_path) as content_file: + pyCode = content_file.read().decode('utf-8') + except urllib.error.URLError as e: + # Handle errors that may occur while reading the file from a URL + return self.protocol.sendData('[URL]: %s' % str(e)) # Test compilation of the script compile(pyCode, '', 'exec') diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index 29a2ef284..c6e93b291 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -133,9 +133,20 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - # Open file and get its content - with open(script_path, 'r') as content_file: - pyCode = content_file.read() + import os + if os.path.isfile(script_path): + # Open file and get its content + with open(script_path, 'r') as content_file: + pyCode = content_file.read() + else: + # Assume it's a URL + import urllib.request + try: + with urllib.request.urlopen(script_path) as content_file: + pyCode = content_file.read().decode('utf-8') + except urllib.error.URLError as e: + # Handle errors that may occur while reading the file from a URL + return self.protocol.sendData('[URL]: %s' % str(e)) # Test compilation of the script compile(pyCode, '', 'exec') From 1fd35292359738f0c0a74bae25ef2d559823b99f Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Sun, 1 Jan 2023 12:06:13 +0400 Subject: [PATCH 07/17] InvalidScriptSyntax message inclue url example --- jasmin/protocols/cli/mointerceptorm.py | 2 +- jasmin/protocols/cli/mtinterceptorm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index 2a4488b70..879e00dec 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -22,7 +22,7 @@ def validate_typed_script(script): m = re.match(r'(python3)\((.*)\)', script, re.I) if not m: - raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script).') + raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script) or python3(https://domain.com/path/to/script).') else: language = m.group(1).lower() script_path = m.group(2) diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index c6e93b291..6d2eb300a 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -22,7 +22,7 @@ def validate_typed_script(script): m = re.match(r'(python3)\((.*)\)', script, re.I) if not m: - raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script).') + raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script) or python3(https://domain.com/path/to/script).') else: language = m.group(1).lower() script_path = m.group(2) From 987be21ce7f60dcd3a066048b827ab58c4783e79 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 2 Jan 2023 18:36:29 +0400 Subject: [PATCH 08/17] handle only http/s, ftp, and file --- jasmin/protocols/cli/mointerceptorm.py | 7 ++++--- jasmin/protocols/cli/mtinterceptorm.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index 879e00dec..55197ee6b 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -134,19 +134,20 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): if stype == 'python3': import os + import urllib if os.path.isfile(script_path): # Open file and get its content with open(script_path, 'r') as content_file: pyCode = content_file.read() - else: - # Assume it's a URL - import urllib.request + elif urllib.parse.urlparse(script_path).scheme in ['https', 'http', 'ftp', 'file']: try: with urllib.request.urlopen(script_path) as content_file: pyCode = content_file.read().decode('utf-8') except urllib.error.URLError as e: # Handle errors that may occur while reading the file from a URL return self.protocol.sendData('[URL]: %s' % str(e)) + else: + raise NotImplementedError("Not implemented yet !") # Test compilation of the script compile(pyCode, '', 'exec') diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index 6d2eb300a..bb56126ce 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -134,19 +134,20 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): if stype == 'python3': import os + import urllib if os.path.isfile(script_path): # Open file and get its content with open(script_path, 'r') as content_file: pyCode = content_file.read() - else: - # Assume it's a URL - import urllib.request + elif urllib.parse.urlparse(script_path).scheme in ['https', 'http', 'ftp', 'file']: try: with urllib.request.urlopen(script_path) as content_file: pyCode = content_file.read().decode('utf-8') except urllib.error.URLError as e: # Handle errors that may occur while reading the file from a URL return self.protocol.sendData('[URL]: %s' % str(e)) + else: + raise NotImplementedError("Not implemented yet !") # Test compilation of the script compile(pyCode, '', 'exec') From b620681857712d6c968f36ee26fbd2b28f11c1c7 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 2 Jan 2023 15:48:22 +0000 Subject: [PATCH 09/17] add note to docs about remote path --- misc/doc/sources/management/jcli/modules.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/misc/doc/sources/management/jcli/modules.rst b/misc/doc/sources/management/jcli/modules.rst index f2cf19609..67c3bedaf 100644 --- a/misc/doc/sources/management/jcli/modules.rst +++ b/misc/doc/sources/management/jcli/modules.rst @@ -736,6 +736,12 @@ Here's an example of adding a **DefaultInterceptor** to a python script:: .. note:: As of now, only **python3** script is permitted. +.. note:: The path to the script can be any of the fallowing: + + * **python3(/path/to/script.py)** or **python3(file://path/to/script.py)**: The path must be absolute, relative path is not supported + * **python3(https://example.com/path/to/script.py)**: The script is a remote python3 script. The script will be + downloaded and copied to Jasmin core. Accepts http, https, and ftp protocols. + .. note:: Pay attention that the given script is copied to Jasmin core, do not expect Jasmin to refresh the script code when you update it, you'll need to redefine the *mointerceptor* rule again so Jasmin will refresh the script. From 8372cc51b1098387c48c85e7682bdf6cd06b0793 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 2 Jan 2023 16:56:54 +0000 Subject: [PATCH 10/17] reversed error message --- jasmin/protocols/cli/mointerceptorm.py | 2 +- jasmin/protocols/cli/mtinterceptorm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index 55197ee6b..cc3206c05 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -22,7 +22,7 @@ def validate_typed_script(script): m = re.match(r'(python3)\((.*)\)', script, re.I) if not m: - raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script) or python3(https://domain.com/path/to/script).') + raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script).') else: language = m.group(1).lower() script_path = m.group(2) diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index bb56126ce..3d147289b 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -22,7 +22,7 @@ def validate_typed_script(script): m = re.match(r'(python3)\((.*)\)', script, re.I) if not m: - raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script) or python3(https://domain.com/path/to/script).') + raise InvalidScriptSyntax('Invalid syntax for script, must be python3(/path/to/script).') else: language = m.group(1).lower() script_path = m.group(2) From 03b6a4cdeb2c770caaaa5b0c7a3ad9ad3d02e708 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Thu, 12 Jan 2023 09:41:53 +0000 Subject: [PATCH 11/17] detect path type with urlparse --- jasmin/protocols/cli/mointerceptorm.py | 8 ++++---- jasmin/protocols/cli/mtinterceptorm.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index cc3206c05..2402efee2 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -133,13 +133,13 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - import os - import urllib - if os.path.isfile(script_path): + import urllib.parse, urllib.request, urllib.error + pathscheme = urllib.parse.urlparse(script_path).scheme + if pathscheme == '': # Open file and get its content with open(script_path, 'r') as content_file: pyCode = content_file.read() - elif urllib.parse.urlparse(script_path).scheme in ['https', 'http', 'ftp', 'file']: + elif pathscheme in ['https', 'http', 'ftp', 'file']: try: with urllib.request.urlopen(script_path) as content_file: pyCode = content_file.read().decode('utf-8') diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index 3d147289b..0081ffb9a 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -133,13 +133,13 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - import os - import urllib - if os.path.isfile(script_path): + import urllib.parse, urllib.request, urllib.error + pathscheme = urllib.parse.urlparse(script_path).scheme + if pathscheme == '': # Open file and get its content with open(script_path, 'r') as content_file: pyCode = content_file.read() - elif urllib.parse.urlparse(script_path).scheme in ['https', 'http', 'ftp', 'file']: + elif pathscheme in ['https', 'http', 'ftp', 'file']: try: with urllib.request.urlopen(script_path) as content_file: pyCode = content_file.read().decode('utf-8') From 3b7433b304256a12eef781c249f9a7eafa3f8123 Mon Sep 17 00:00:00 2001 From: BlackOrder <4302157+BlackOrder@users.noreply.github.com> Date: Mon, 26 Dec 2022 10:14:14 +0400 Subject: [PATCH 12/17] cast logprivacy to boolean --- jasmin/protocols/cli/smppccm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jasmin/protocols/cli/smppccm.py b/jasmin/protocols/cli/smppccm.py index 956b83339..3d48cafc4 100644 --- a/jasmin/protocols/cli/smppccm.py +++ b/jasmin/protocols/cli/smppccm.py @@ -67,7 +67,7 @@ def castInputToBuiltInType(key, value): return replace_if_present_flap_value_map[value] elif key == 'priority': return priority_flag_value_map[value] - elif key in ['con_fail_retry', 'con_loss_retry', 'ssl']: + elif key in ['con_fail_retry', 'con_loss_retry', 'ssl', 'logprivacy']: if value == 'yes': return True elif value == 'no': From dc0c5c7bcdbc8f4713b97926207d3fde834b7e8f Mon Sep 17 00:00:00 2001 From: Kisuke-CZE Date: Fri, 20 Oct 2023 13:22:33 +0200 Subject: [PATCH 13/17] Quickfix for setting default values for multipart messages. --- jasmin/protocols/http/endpoints/send.py | 7 +++++++ jasmin/protocols/smpp/factory.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/jasmin/protocols/http/endpoints/send.py b/jasmin/protocols/http/endpoints/send.py index 5da155b22..804a2d5ba 100644 --- a/jasmin/protocols/http/endpoints/send.py +++ b/jasmin/protocols/http/endpoints/send.py @@ -126,6 +126,13 @@ def route_routable(self, updated_request): # Update SubmitSmPDU by default values from user MtMessagingCredential SubmitSmPDU = v.updatePDUWithUserDefaults(SubmitSmPDU) + + # Force same default values on subPDU while multipart + _pdu = SubmitSmPDU + while hasattr(_pdu, 'nextPdu'): + _pdu = _pdu.nextPdu + _pdu = v.updatePDUWithUserDefaults(_pdu) + # Prepare for interception then routing routedConnector = None # init diff --git a/jasmin/protocols/smpp/factory.py b/jasmin/protocols/smpp/factory.py index 3c4c07ff9..1c3ad8b07 100644 --- a/jasmin/protocols/smpp/factory.py +++ b/jasmin/protocols/smpp/factory.py @@ -298,6 +298,12 @@ def submit_sm_event_interceptor(self, system_id, *args): # Update SubmitSmPDU by default values from user MtMessagingCredential SubmitSmPDU = v.updatePDUWithUserDefaults(SubmitSmPDU) + + # Force same default values on subPDU while multipart + _pdu = SubmitSmPDU + while hasattr(_pdu, 'nextPdu'): + _pdu = _pdu.nextPdu + _pdu = v.updatePDUWithUserDefaults(_pdu) if self.RouterPB is None: self.log.error('(submit_sm_event_interceptor/%s) RouterPB not set: submit_sm will not be routed', From ff9424adde73d17797f63505d7d932714e1eb252 Mon Sep 17 00:00:00 2001 From: Kisuke-CZE Date: Tue, 24 Oct 2023 13:43:36 +0200 Subject: [PATCH 14/17] Adjust logging. Log message DLR, SRC_ADDR and DST_ADDR according to last part of the message. --- jasmin/managers/listeners.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jasmin/managers/listeners.py b/jasmin/managers/listeners.py index aafa4af63..1b239776c 100644 --- a/jasmin/managers/listeners.py +++ b/jasmin/managers/listeners.py @@ -291,10 +291,12 @@ def submit_sm_resp_event(self, r, amqpMessage): splitMethod = 'sar' elif UDHI_INDICATOR_SET and r.request.params['short_message'][:3] == b'\x05\x00\x03': splitMethod = 'udh' + + # create _pdu before splitting, so we can use it in both branches (logging the message according the last part of message) + _pdu = r.request # Concatenate short_message if splitMethod is not None: - _pdu = r.request if splitMethod == 'sar': short_message = _pdu.params['short_message'] else: @@ -328,12 +330,12 @@ def submit_sm_resp_event(self, r, amqpMessage): r.response.params['message_id'], r.response.status, amqpMessage.content.properties['priority'], - r.request.params['registered_delivery'].receipt, + _pdu.params['registered_delivery'].receipt, 'none' if ('headers' not in amqpMessage.content.properties or 'expiration' not in amqpMessage.content.properties['headers']) else amqpMessage.content.properties['headers']['expiration'], - r.request.params['source_addr'], - r.request.params['destination_addr'], + _pdu.params['source_addr'], + _pdu.params['destination_addr'], logged_content) else: # Message must be retried ? From 7fff3f25637e0a852545588f61a8bfbd91d6b409 Mon Sep 17 00:00:00 2001 From: Kisuke-CZE Date: Tue, 24 Oct 2023 13:57:27 +0200 Subject: [PATCH 15/17] Revert "Adjust logging. Log message DLR, SRC_ADDR and DST_ADDR according to last part of the message." This reverts commit ff9424adde73d17797f63505d7d932714e1eb252. --- jasmin/managers/listeners.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/jasmin/managers/listeners.py b/jasmin/managers/listeners.py index 1b239776c..aafa4af63 100644 --- a/jasmin/managers/listeners.py +++ b/jasmin/managers/listeners.py @@ -291,12 +291,10 @@ def submit_sm_resp_event(self, r, amqpMessage): splitMethod = 'sar' elif UDHI_INDICATOR_SET and r.request.params['short_message'][:3] == b'\x05\x00\x03': splitMethod = 'udh' - - # create _pdu before splitting, so we can use it in both branches (logging the message according the last part of message) - _pdu = r.request # Concatenate short_message if splitMethod is not None: + _pdu = r.request if splitMethod == 'sar': short_message = _pdu.params['short_message'] else: @@ -330,12 +328,12 @@ def submit_sm_resp_event(self, r, amqpMessage): r.response.params['message_id'], r.response.status, amqpMessage.content.properties['priority'], - _pdu.params['registered_delivery'].receipt, + r.request.params['registered_delivery'].receipt, 'none' if ('headers' not in amqpMessage.content.properties or 'expiration' not in amqpMessage.content.properties['headers']) else amqpMessage.content.properties['headers']['expiration'], - _pdu.params['source_addr'], - _pdu.params['destination_addr'], + r.request.params['source_addr'], + r.request.params['destination_addr'], logged_content) else: # Message must be retried ? From b4f516e0493860f6ba163116d7e84048df248506 Mon Sep 17 00:00:00 2001 From: The Z <1020111+farirat@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:22:55 +0100 Subject: [PATCH 16/17] avoiding imports from inside code for better readability and to allow any import error to raise early. --- jasmin/protocols/cli/mointerceptorm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jasmin/protocols/cli/mointerceptorm.py b/jasmin/protocols/cli/mointerceptorm.py index 2402efee2..42df11f8a 100644 --- a/jasmin/protocols/cli/mointerceptorm.py +++ b/jasmin/protocols/cli/mointerceptorm.py @@ -2,6 +2,7 @@ import re import inspect import pickle +import urllib.parse, urllib.request, urllib.error from jasmin.protocols.cli.managers import PersistableManager, Session from jasmin.protocols.cli.filtersm import MOFILTERS from jasmin.routing.jasminApi import MOInterceptorScript @@ -133,7 +134,6 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - import urllib.parse, urllib.request, urllib.error pathscheme = urllib.parse.urlparse(script_path).scheme if pathscheme == '': # Open file and get its content From 8a41ef327237221f3605dd16ff91a3b36d41236f Mon Sep 17 00:00:00 2001 From: The Z <1020111+farirat@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:23:47 +0100 Subject: [PATCH 17/17] avoiding imports from inside code for better readability and to allow any import error to raise early. --- jasmin/protocols/cli/mtinterceptorm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jasmin/protocols/cli/mtinterceptorm.py b/jasmin/protocols/cli/mtinterceptorm.py index 0081ffb9a..ae734351c 100644 --- a/jasmin/protocols/cli/mtinterceptorm.py +++ b/jasmin/protocols/cli/mtinterceptorm.py @@ -2,6 +2,7 @@ import re import inspect import pickle +import urllib.parse, urllib.request, urllib.error from jasmin.protocols.cli.managers import PersistableManager, Session from jasmin.protocols.cli.filtersm import MTFILTERS from jasmin.routing.jasminApi import MTInterceptorScript @@ -133,7 +134,6 @@ def parse_args_and_call_with_instance(self, *args, **kwargs): stype, script_path = validate_typed_script(arg) if stype == 'python3': - import urllib.parse, urllib.request, urllib.error pathscheme = urllib.parse.urlparse(script_path).scheme if pathscheme == '': # Open file and get its content