mirror of https://gerrit.osmocom.org/osmo-dev
simplify dialplan cfg, use freeswitch_dialplan_dgsm.py from osmo-hlr.git
Change-Id: Ida2de649dc0c83e6f56c9e78af065acea7935002
This commit is contained in:
parent
6d5952474f
commit
bed7d341e1
|
@ -1,29 +1,12 @@
|
||||||
<!--
|
|
||||||
NOTICE:
|
|
||||||
|
|
||||||
This context is usually accessed via the external sip profile listening on port 5080.
|
|
||||||
|
|
||||||
It is recommended to have separate inbound and outbound contexts. Not only for security
|
|
||||||
but clearing up why you would need to do such a thing. You don't want outside un-authenticated
|
|
||||||
callers hitting your default context which allows dialing calls thru your providers and results
|
|
||||||
in Toll Fraud.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- http://wiki.freeswitch.org/wiki/Dialplan_XML -->
|
|
||||||
<include>
|
<include>
|
||||||
<context name="public">
|
<context name="public">
|
||||||
|
|
||||||
<extension name="unloop">
|
<extension name="unloop">
|
||||||
<condition field="${unroll_loops}" expression="^true$"/>
|
<condition field="${unroll_loops}" expression="^true$"/>
|
||||||
<condition field="${sip_looped_call}" expression="^true$">
|
<condition field="${sip_looped_call}" expression="^true$">
|
||||||
<action application="deflect" data="${destination_number}"/>
|
<action application="deflect" data="${destination_number}"/>
|
||||||
</condition>
|
</condition>
|
||||||
</extension>
|
</extension>
|
||||||
<!--
|
|
||||||
Tag anything pass thru here as an outside_call so you can make sure not
|
|
||||||
to create any routing loops based on the conditions that it came from
|
|
||||||
the outside of the switch.
|
|
||||||
-->
|
|
||||||
<extension name="outside_call" continue="true">
|
<extension name="outside_call" continue="true">
|
||||||
<condition>
|
<condition>
|
||||||
<action application="set" data="outside_call=true"/>
|
<action application="set" data="outside_call=true"/>
|
||||||
|
@ -41,34 +24,9 @@
|
||||||
<condition field="destination_number" expression=".*">
|
<condition field="destination_number" expression=".*">
|
||||||
<action application="set" data="hangup_after_bridge=true"/>
|
<action application="set" data="hangup_after_bridge=true"/>
|
||||||
<action application="set" data="session_in_hangup_hook=true"/>
|
<action application="set" data="session_in_hangup_hook=true"/>
|
||||||
<action application="set" data="api_hangup_hook=python dialplan-dgsm"/>
|
|
||||||
<action application="set" data="ringback=%(2000, 4000, 440.0, 480.0)"/>
|
<action application="set" data="ringback=%(2000, 4000, 440.0, 480.0)"/>
|
||||||
<action application="python" data="dialplan-dgsm"/>
|
<action application="python" data="freeswitch_dialplan_dgsm"/>
|
||||||
<!--<action application="bridge" data="{absolute_codec_string='G729'}sofia/gateway/provider/${destination_number}" />-->
|
|
||||||
</condition>
|
</condition>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
You can place files in the public directory to get included.
|
|
||||||
-->
|
|
||||||
<!--<X-PRE-PROCESS cmd="include" data="public/*.xml"/>-->
|
|
||||||
<!--
|
|
||||||
If you have made it this far lets challenge the caller and if they authenticate
|
|
||||||
lets try what they dialed in the default context. (commented out by default)
|
|
||||||
-->
|
|
||||||
<!--
|
|
||||||
<extension name="check_auth" continue="true">
|
|
||||||
<condition field="${sip_authorized}" expression="^true$" break="never">
|
|
||||||
<anti-action application="respond" data="407"/>
|
|
||||||
</condition>
|
|
||||||
</extension>
|
|
||||||
|
|
||||||
<extension name="transfer_to_default">
|
|
||||||
<condition>
|
|
||||||
<action application="transfer" data="${destination_number} XML default"/>
|
|
||||||
</condition>
|
|
||||||
</extension>
|
|
||||||
-->
|
|
||||||
</context>
|
</context>
|
||||||
</include>
|
</include>
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
NETDIR="$(cd $(dirname "$0")/..; pwd)"
|
DIALPLANDIR="$(cd $(dirname "$0")/../../../src/osmo-hlr/contrib/dgsm; pwd)"
|
||||||
(sleep 5; echo; echo; echo "NOTE: type 'shutdown' to quit"; echo) &
|
(sleep 5; echo; echo; echo "NOTE: type 'shutdown' to quit"; echo) &
|
||||||
|
|
||||||
|
if ! [ -e "$DIALPLANDIR/freeswitch_dialplan_dgsm.py" ]; then
|
||||||
|
echo "ERROR: freeswitch_dialplan_dgsm.py not found in: $DIALPLANDIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
export PYTHONPATH="$NETDIR/freeswitch/python:$PYTHONPATH"
|
export PYTHONPATH="$PYTHONPATH:$DIALPLANDIR"
|
||||||
|
|
||||||
if ! [ -d /usr/lib/freeswitch/mod ]; then
|
if ! [ -d /usr/lib/freeswitch/mod ]; then
|
||||||
echo "ERROR: missing dir /usr/lib/freeswitch/mod"
|
echo "ERROR: missing dir /usr/lib/freeswitch/mod"
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
import json
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def query_mslookup(service_type, id, id_type='msisdn'):
|
|
||||||
query_str = '%s.%s.%s' % (service_type, id, id_type)
|
|
||||||
print('[dialplan-dgsm] mslookup: ' + query_str)
|
|
||||||
|
|
||||||
result_line = subprocess.check_output([
|
|
||||||
'osmo-mslookup-client', query_str, '-f', 'json'])
|
|
||||||
if isinstance(result_line, bytes):
|
|
||||||
result_line = result_line.decode('ascii')
|
|
||||||
|
|
||||||
print('[dialplan-dgsm] mslookup result: ' + result_line)
|
|
||||||
return json.loads(result_line)
|
|
||||||
|
|
||||||
|
|
||||||
def handler(session, args):
|
|
||||||
""" Handle calls: bridge to the SIP server found with mslookup. """
|
|
||||||
print('[dialplan-dgsm] call handler')
|
|
||||||
msisdn = session.getVariable('destination_number')
|
|
||||||
|
|
||||||
# Run osmo-mslookup-client binary. We have also tried to directly call the C functions with ctypes but this has
|
|
||||||
# lead to hard-to-debug segfaults.
|
|
||||||
try:
|
|
||||||
result = query_mslookup("sip.voice", msisdn)
|
|
||||||
|
|
||||||
# This example only makes use of IPv4
|
|
||||||
if not result['v4']:
|
|
||||||
print('[dialplan-dgsm] no IPv4 result from mslookup')
|
|
||||||
session.hangup('UNALLOCATED_NUMBER')
|
|
||||||
return
|
|
||||||
|
|
||||||
sip_ip, sip_port = result['v4'] # osmo-dev defaults: same as ${SIPCON_LOCAL}
|
|
||||||
dial_str = 'sofia/internal/sip:{}@{}:{}'.format(msisdn, sip_ip, sip_port)
|
|
||||||
print('[dialplan-dgsm] dial_str: ' + str(dial_str))
|
|
||||||
|
|
||||||
session.execute('bridge', dial_str)
|
|
||||||
except:
|
|
||||||
print('[dialplan-dgsm]: exception during call handler')
|
|
||||||
session.hangup('UNALLOCATED_NUMBER')
|
|
||||||
|
|
||||||
|
|
||||||
def fsapi(session, stream, env, args):
|
|
||||||
""" Freeswitch refuses to load the module without this. """
|
|
||||||
stream.write(env.serialize())
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('id', type=int)
|
|
||||||
parser.add_argument('-i', '--id-type', default='msisdn', help='default: "msisdn"')
|
|
||||||
parser.add_argument('-s', '--service', default='sip.voice', help='default: "sip.voice"')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
result = query_mslookup(args.service, args.id, args.id_type)
|
|
||||||
print(json.dumps(result))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in New Issue