Skip to content

Commit

Permalink
Merge pull request #440 from dOpensource/v0.644
Browse files Browse the repository at this point in the history
V0.644
  • Loading branch information
mackhendricks committed Jun 27, 2022
2 parents 383a57b + 06ca6ce commit 93bbf5f
Show file tree
Hide file tree
Showing 14 changed files with 520 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
16 changes: 13 additions & 3 deletions dsiprouter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ function updateKamailioConfig {
local TELEBLOCK_GW_PORT=${TELEBLOCK_GW_PORT:-$(getConfigAttrib 'TELEBLOCK_GW_PORT' ${DSIP_CONFIG_FILE})}
local TELEBLOCK_MEDIA_IP=${TELEBLOCK_MEDIA_IP:-$(getConfigAttrib 'TELEBLOCK_MEDIA_IP' ${DSIP_CONFIG_FILE})}
local TELEBLOCK_MEDIA_PORT=${TELEBLOCK_MEDIA_PORT:-$(getConfigAttrib 'TELEBLOCK_MEDIA_PORT' ${DSIP_CONFIG_FILE})}

# Set the External IP Address for the WebRTC Port
sed -i "s/server:\(.*\):4443/server:$EXTERNAL_IP:4443/g" ${DSIP_KAMAILIO_TLS_CONFIG_FILE}

# update kamailio config file
if [[ "$DEBUG" == "True" ]]; then
Expand Down Expand Up @@ -758,9 +761,6 @@ function generateKamailioConfig {
cp -f ${DSIP_KAMAILIO_CONFIG_DIR}/tls_dsiprouter.cfg ${DSIP_KAMAILIO_TLS_CONFIG_FILE}
cp -f ${DSIP_KAMAILIO_CONFIG_DIR}/*.inc ${SYSTEM_KAMAILIO_CONFIG_DIR}

# Set the External IP Address for the WebRTC Port
sed -i "s/EXTERNAL_IP/$EXTERNAL_IP/g" ${DSIP_KAMAILIO_TLS_CONFIG_FILE}

# version specific settings
if (( ${KAM_VERSION} >= 52 )); then
sed -i -r -e 's~#+(modparam\(["'"'"']htable["'"'"'], ?["'"'"']dmq_init_sync["'"'"'], ?[0-9]\))~\1~g' ${DSIP_KAMAILIO_CONFIG_FILE}
Expand All @@ -780,6 +780,16 @@ function generateKamailioConfig {
else
disableKamailioConfigAttrib 'WITH_LCR' ${DSIP_KAMAILIO_CONFIG_FILE}
fi

mpath=$(find /usr/lib{32,64,}/{i386*/*,i386*/kamailio/*,x86_64*/*,x86_64*/kamailio/*,*} -name drouting.so -printf '%h/' -quit 2>/dev/null)

if [ -f ${mpath}/stirshaken.so ]; then
enableKamailioConfigAttrib 'WITH_STIRSHAKEN' ${DSIP_KAMAILIO_CONFIG_FILE}
else
disableKamailioConfigAttrib 'WITH_STIRSHAKEN' ${DSIP_KAMAILIO_CONFIG_FILE}
fi



# Backup kamcfg and link the dsiprouter kamcfg
cp -f ${SYSTEM_KAMAILIO_CONFIG_FILE} ${SYSTEM_KAMAILIO_CONFIG_FILE}.$(date +%Y%m%d_%H%M%S)
Expand Down
79 changes: 79 additions & 0 deletions gui/dsiprouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,85 @@ def deleteOutboundRoute():
finally:
db.close()

@app.route('/stirshaken')
def displayStirShaken(msg=None):
"""
Display TransNexus settings in view
"""

try:
if not session.get('logged_in'):
return redirect(url_for('index'))

if (settings.DEBUG):
debugEndpoint()

stir_shaken = {}
stir_shaken["stir_shaken_enabled"] = settings.STIR_SHAKEN_ENABLED
stir_shaken["stir_shaken_prefix_a"] = settings.STIR_SHAKEN_PREFIX_A
stir_shaken["stir_shaken_prefix_b"] = settings.STIR_SHAKEN_PREFIX_B
stir_shaken["stir_shaken_prefix_c"] = settings.STIR_SHAKEN_PREFIX_C
stir_shaken["stir_shaken_prefix_invalid"] = settings.STIR_SHAKEN_PREFIX_INVALID
stir_shaken["stir_shaken_block_invalid"] = settings.STIR_SHAKEN_BLOCK_INVALID

return render_template('stirshaken.html', stir_shaken=stir_shaken, msg=msg)

except http_exceptions.HTTPException as ex:
debugException(ex)
error = "http"
return showError(type=error)
except Exception as ex:
debugException(ex)
error = "server"
return showError(type=error)


@app.route('/stirshaken', methods=['POST'])
def addUpdateStirShaken():
"""
Update STIR/SHAKEN config file settings
"""

try:
if not session.get('logged_in'):
return redirect(url_for('index'))

if (settings.DEBUG):
debugEndpoint()

form = stripDictVals(request.form.to_dict())

stir_shaken = {}
stir_shaken["STIR_SHAKEN_ENABLED"] = form.get('stir_shaken_enabled', 0)
stir_shaken["STIR_SHAKEN_PREFIX_A"] = form.get('stir_shaken_prefix_a', '')
stir_shaken["STIR_SHAKEN_PREFIX_B"] = form.get('stir_shaken_prefix_b', '')
stir_shaken["STIR_SHAKEN_PREFIX_C"] = form.get('stir_shaken_prefix_c', '')
stir_shaken["STIR_SHAKEN_PREFIX_INVALID"] = form.get('stir_shaken_prefix_invalid', '')
stir_shaken["STIR_SHAKEN_BLOCK_INVALID"] = form.get('stir_shaken_block_invalid', 0)

if stir_shaken["STIR_SHAKEN_ENABLED"] == "1":
stir_shaken["STIR_SHAKEN_ENABLED"] = 1
else:
stir_shaken["STIR_SHAKEN_ENABLED"] = 0

if stir_shaken["STIR_SHAKEN_BLOCK_INVALID"] == "on":
stir_shaken["STIR_SHAKEN_BLOCK_INVALID"] = 1
else:
stir_shaken["STIR_SHAKEN_BLOCK_INVALID"] = 0

updateConfig(settings, stir_shaken, hot_reload=True)
globals.reload_required = True
return displayStirShaken()

except http_exceptions.HTTPException as ex:
debugException(ex)
error = "http"
return showError(type=error)
except Exception as ex:
debugException(ex)
error = "server"
return showError(type=error)


# custom jinja filters
def yesOrNoFilter(list, field):
Expand Down
20 changes: 20 additions & 0 deletions gui/modules/api/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ def reloadKamailio():
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['transnexus', 'authservice_host', str(settings.TRANSNEXUS_AUTHSERVICE_HOST)]})

# Settings for STIR/SHAKEN
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_enabled', str(settings.STIR_SHAKEN_ENABLED)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_a', str(settings.STIR_SHAKEN_PREFIX_A)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_b', str(settings.STIR_SHAKEN_PREFIX_B)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_c', str(settings.STIR_SHAKEN_PREFIX_C)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_invalid', str(settings.STIR_SHAKEN_PREFIX_INVALID)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_block_invalid', str(settings.STIR_SHAKEN_BLOCK_INVALID)]})

for cmdset in reload_cmds:
r = requests.get('http://127.0.0.1:5060/api/kamailio', json=cmdset)
if r.status_code >= 400:
Expand Down
30 changes: 29 additions & 1 deletion gui/modules/api/kamailio/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,41 @@ def reloadKamailio():
{'method': 'cfg.seti', 'jsonrpc': '2.0', 'id': 1,
'params': ['teleblock', 'media_port', str(settings.TELEBLOCK_MEDIA_PORT)]})

# Settings for TransNexus
# Settings for TransNexus
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['transnexus', 'authservice_enabled', str(settings.TRANSNEXUS_AUTHSERVICE_ENABLED)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['transnexus', 'authservice_host', str(settings.TRANSNEXUS_AUTHSERVICE_HOST)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['transnexus', 'verifyservice_enabled', str(settings.TRANSNEXUS_VERIFYSERVICE_ENABLED)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['transnexus', 'verifyservice_host', str(settings.TRANSNEXUS_VERIFYSERVICE_HOST)]})

# Settings for STIR/SHAKEN
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_enabled', str(settings.STIR_SHAKEN_ENABLED)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_a', str(settings.STIR_SHAKEN_PREFIX_A)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_b', str(settings.STIR_SHAKEN_PREFIX_B)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_c', str(settings.STIR_SHAKEN_PREFIX_C)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_prefix_invalid', str(settings.STIR_SHAKEN_PREFIX_INVALID)]})
reload_cmds.append(
{'method': 'cfg.sets', 'jsonrpc': '2.0', 'id': 1,
'params': ['stir_shaken', 'stir_shaken_block_invalid', str(settings.STIR_SHAKEN_BLOCK_INVALID)]})



for cmdset in reload_cmds:
r = requests.get('http://127.0.0.1:5060/api/kamailio', json=cmdset)
Expand Down
14 changes: 13 additions & 1 deletion gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# dSIPRouter internal settings

VERSION = '0.643'
VERSION = '0.644'
DEBUG = False
# '' (default) = handle inbound with domain mapping from endpoints, inbound from carriers and outbound to carriers
# 'outbound' = act as an outbound proxy only (no domain routing)
Expand Down Expand Up @@ -99,12 +99,24 @@
TRANSNEXUS_AUTHSERVICE_ENABLED = 0
TRANSNEXUS_AUTHSERVICE_HOST = 'sip.clearip.com'
TRANSNEXUS_LICENSE_KEY = ''
TRANSNEXUS_VERIFYSERVICE_ENABLED = 0
TRANSNEXUS_VERIFYSERVICE_HOST = "inbound.sip.clearip.com:5060"

# Flowroute API Settings
FLOWROUTE_ACCESS_KEY = ''
FLOWROUTE_SECRET_KEY = ''
FLOWROUTE_API_ROOT_URL = 'https://api.flowroute.com/v2'


# STIR/SHAKEN Settings
STIR_SHAKEN_ENABLED = 0
STIR_SHAKEN_PREFIX_A = ''
STIR_SHAKEN_PREFIX_B = ''
STIR_SHAKEN_PREFIX_C = ''
STIR_SHAKEN_PREFIX_INVALID = ''
STIR_SHAKEN_BLOCK_INVALID = 0


# updated dynamically! These values will be overwritten
INTERNAL_IP_ADDR = '68.183.203.128'
INTERNAL_IP_NET = '68.183.203.*'
Expand Down
20 changes: 20 additions & 0 deletions gui/static/js/stirshaken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;(function (window, document) {
'use strict';

$(document).ready(function() {
/* listener for stir chaken toggle */
$('#toggleStirShaken').change(function () {
if ($(this).is(":checked") || $(this).prop("checked")) {
$('#stirShakenOptions').removeClass("hidden");
$(this).val("1");
$(this).bootstrapToggle('on');
}
else {
$('#stirShakenOptions').addClass("hidden");
$(this).val("0");
$(this).bootstrapToggle('off');
}
});
});

})(window, document);
1 change: 1 addition & 0 deletions gui/templates/fullwidth_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<li><a href="/certificates">Certificates</a></li>
<li><a href="/teleblock">Teleblock</a></li>
<li><a href="/transnexus">TransNexus</a></li>
<li><a href="/stirshaken">STIR/SHAKEN</a></li>
</ul>
</li>

Expand Down
94 changes: 94 additions & 0 deletions gui/templates/stirshaken.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends 'fullwidth_layout.html' %}

{% block title %}STIR/SHAKEN Configuration{% endblock %}

{% block custom_css %}
{% endblock %}

{% block body %}
<div>
{% if msg %}
<div class="alert alert-danger container">
<h2 style="color: rgb(0, 0, 0);"><strong>{{ msg }}</strong></h2>
</div>
{% endif %}
</div>
<div class="col-md-12">


<form action="/stirshaken" method="POST" role="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="saveTeleblock">
<h4>STIR/SHAKEN Settings</h4>
<button name='save' id='save' class='btn btn-success btn-md' data-title="Add" data-toggle="modal"
data-target="#add">Save
</button>
</div>
<hr>
<div class="form-group">
<label class="label-toggle">STIR/SHAKEN Service </label>
{% if stir_shaken["stir_shaken_enabled"] == 1 %}
<input id="toggleStirShaken" name="stir_shaken_enabled" type="checkbox" checked
title="Toggle STIR/SHAKEN"
data-toggle="toggle"
value="{{ stir_shaken["stir_shaken_enabled"] }}"
data-on="<span class='icon-gryphon'></span> Enabled"
data-off="<span class='icon-gryphon'></span> Disabled"
data-width="120px">
{% else %}
<input id="toggleStirShaken" name="stir_shaken_enabled" type="checkbox" title="Toggle STIR/SHAKEN"
data-toggle="toggle"
value="{{ stir_shaken["stir_shaken_enabled"] }}"
data-on="<span class='icon-gryphon'></span> Enabled"
data-off="<span class='icon-gryphon'></span> Disabled"
data-width="120px">
{% endif %}
</div>
{% if stir_shaken["stir_shaken_enabled"] == 1 %}
<div id="stirShakenOptions" class="form-group">
{% else %}
<div id="stirShakenOptions" class="form-group hidden">
{% endif %}
<div class="form-group">
<input class="form-control " type="text" id="stir_shaken_prefix_a" name="stir_shaken_prefix_a"
placeholder="Caller ID Prefix A Validated Calls"
value="{{ stir_shaken["stir_shaken_prefix_a"] }}">
</div>

<div class="form-group">
<input class="form-control " type="text" id="stir_shaken_prefix_b" name="stir_shaken_prefix_b"
placeholder="Caller ID Prefix B Validated Calls"
value="{{ stir_shaken["stir_shaken_prefix_b"] }}">
</div>

<div class="form-group">
<input class="form-control " type="text" id="stir_shaken_prefix_c" name="stir_shaken_prefix_c"
placeholder="Caller ID Prefix C Validated Calls"
value="{{ stir_shaken["stir_shaken_prefix_c"] }}">
</div>

<div class="form-group">
<input class="form-control " type="text" id="stir_shaken_prefix_invalid"
name="stir_shaken_prefix_invalid"
placeholder="Caller ID Prefix Invalid Calls"
value="{{ stir_shaken["stir_shaken_prefix_invalid"] }}">
</div>

<div class="checkbox">
<label>
<input type="checkbox" name="stir_shaken_block_invalid" {{ 'checked' if (stir_shaken["stir_shaken_block_invalid"] == 1) else '' }}> Block Invalidated Calls
</label>
</div>



</div> <!--End of STIR/SHAKEN settings-->
</form>
</div>


{% endblock %}

{% block custom_js %}
{{ script_tag('stirshaken') }}
{% endblock %}
27 changes: 27 additions & 0 deletions kamailio/debian/11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ EOF
cp -f /tmp/kamailio/src/modules/dsiprouter/dsiprouter.so ${KAM_MODULES_DIR} ||
return 1

# Setup STIRSHAKEN Module
## Get required packages
apt-get install -y libcurl4-openssl-dev libjwt-dev libjansson-dev cmake

## Compile and install libjwt
git clone https://github.com/benmcollins/libjwt.git /tmp/libjwt &&
( cd /tmp/libjwt; autoreconf -i; ./configure; make; make install; exit $?; )

## Compile and install libks
git clone https://github.com/signalwire/libks /tmp/libks &&
( cd /tmp/libks; cmake .; make install; exit $?; )

## Install libstirshaken module
git clone https://github.com/signalwire/libstirshaken /tmp/libstirshaken
( cd /tmp/libstirshaken; ./bootstrap.sh; ./configure; make; make install; ldconfig; exit $?; )

## Compile and install Kamailio STIRShaken Module
( cd /tmp/kamailio/src/modules/stirshaken; make; exit $?; ) &&
cp -f /tmp/kamailio/src/modules/stirshaken/stirshaken.so ${KAM_MODULES_DIR} ||
return 1

return 0
}

Expand All @@ -184,6 +205,12 @@ function uninstall {
# Backup kamailio configuration directory
mv -f ${SYSTEM_KAMAILIO_CONFIG_DIR} ${SYSTEM_KAMAILIO_CONFIG_DIR}.bak.$(date +%Y%m%d_%H%M%S)

# Uninstall Stirshaken Required Packages
cd /tmp/libjwt; make uninstall; cd /tmp; rm -rf /tmp/libjwt
cd /tmp/libks; make uninstall; cd /tmp; rm -rf /tmp/libks
cd /tmp/libstirshaken; make uninstall; cd /tmp; rm -rf /tmp/libstirshaken
cd /tmp; rm -rf /tmp/kamailio

# Uninstall Kamailio modules
apt-get -y remove --purge kamailio\*

Expand Down

0 comments on commit 93bbf5f

Please sign in to comment.