mirror of
https://github.com/RangeNetworks/openbts.git
synced 2025-11-02 04:43:16 +00:00
new versions of freeswitch stuff
git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@2435 19bc5d8c-e614-43d4-8b26-e1612bc8e597
This commit is contained in:
@@ -33,26 +33,40 @@ or implied, of Kurtis Heimerl.
|
||||
<!-- set all the openbts variables -->
|
||||
<extension name="openbts" continue="true">
|
||||
<condition field="to_user" expression="^smsc$">
|
||||
<!-- first, parse SMS -->
|
||||
<action inline="true" application="python" data="OpenBTS_Parse_SMS"/>
|
||||
<!-- second, look up sender -->
|
||||
<!-- freeswitch eats 's, switch them up here -->
|
||||
<action inline="true" application="python" data='OpenBTS_DB SELECT callerid FROM sip_buddies WHERE name="${from_user}"'/>
|
||||
<!-- result in _openbts_ret -->
|
||||
<action inline="true" application="set" data="openbts_callerid=${_openbts_ret}"/>
|
||||
</condition>
|
||||
</extension>
|
||||
|
||||
<!-- openbts_db_loc set in vars.xml -->
|
||||
<!-- register a user in the subscriber registry -->
|
||||
<extension name="registration">
|
||||
<condition field="openbts_tp_dest_address" expression="^101$"/>
|
||||
<!-- is it a number? -->
|
||||
<condition field="openbts_text" expression="^\d{7,10}$">
|
||||
|
||||
<!-- if so, try to register user -->
|
||||
<action application="set" data="caller_number=${python(OpenBTS_DB -d ${openbts_db_loc} -c ${from_user})}" />
|
||||
<!-- return value in _openbts_ret -->
|
||||
<action application="python" data="OpenBTS_New_User"/>
|
||||
<action application="set" data="response_text=${_openbts_ret}"/>
|
||||
<!-- lookup new number -->
|
||||
<action application="python" data='OpenBTS_DB SELECT callerid FROM sip_buddies WHERE name="${from_user}"'/>
|
||||
<!-- text back the return value -->
|
||||
<action application="python" data="OpenBTS_Send_SMS ${caller_number}|101|${_openbts_ret}"/>
|
||||
<action application="python" data="OpenBTS_Send_SMS ${_openbts_ret}|101|${response_text}"/>
|
||||
|
||||
<!-- if not, look up user and respond with instructions -->
|
||||
<anti-action application="set" data="caller_number=${python(OpenBTS_DB -d ${openbts_db_loc} -c ${from_user})}" />
|
||||
<anti-action application="python" data="OpenBTS_Send_SMS ${caller_number}|101|Please send just the number you want!"/>
|
||||
<!-- if not, reply -->
|
||||
<!-- this doesn't work yet, missing MC->MS encoder
|
||||
<anti-action application="python" data="OpenBTS_Reply_SMS 101|101|Please send a 7-10 digit number!"/>
|
||||
-->
|
||||
|
||||
</condition>
|
||||
</extension>
|
||||
|
||||
<extension name="echo">
|
||||
<condition field="openbts_tp_dest_address" expression="^9189$">
|
||||
<action application="python" data="OpenBTS_Send_SMS ${openbts_callerid}|9189|${openbts_text}"/>
|
||||
</condition>
|
||||
</extension>
|
||||
|
||||
|
||||
@@ -29,12 +29,11 @@ or implied, of Kurtis Heimerl.
|
||||
<extension name="local_call">
|
||||
|
||||
<!-- openbts_db_loc set in vars.xml -->
|
||||
<condition field="destination_number" expression="^\d{7}$"/>
|
||||
<condition field="${python(OpenBTS_DB -d ${openbts_db_loc} -t ${destination_number})}" expression="IMSI\d{15}"/>
|
||||
<condition field="${python(OpenBTS_DB -d ${openbts_db_loc} -c ${username})}" expression="\d{7}">
|
||||
<action application="set" data="target=${python(OpenBTS_DB -d ${openbts_db_loc} -t ${destination_number})}" />
|
||||
<action application="set" data="effective_caller_id_number=${python(OpenBTS_DB -d ${openbts_db_loc} -c ${username})}" />
|
||||
<action application="bridge" data="sofia/internal/${target}@${domain}:${sip_received_port}"/>
|
||||
<condition field='${python(OpenBTS_DB SELECT name FROM sip_buddies WHERE callerid="${destination_number}")}' expression="IMSI\d{15}"/>
|
||||
<condition field='${python(OpenBTS_DB SELECT callerid FROM sip_buddies WHERE name="${username}"' expression="\d{7,10}">
|
||||
<action application="set" data='target=${python(OpenBTS_DB SELECT name FROM sip_buddies WHERE callerid="${destination_number}")}' />
|
||||
<action application="set" data='effective_caller_id_number=${python(OpenBTS_DB SELECT callerid FROM sip_buddies WHERE name="${username}"'/>
|
||||
<action application="bridge" data="sofia/internal/${target}@${domain}:${sip_received_port}"/>
|
||||
</condition>
|
||||
|
||||
</extension>
|
||||
|
||||
@@ -26,66 +26,47 @@
|
||||
|
||||
import csv
|
||||
import sqlite3
|
||||
import getopt
|
||||
import sys
|
||||
from freeswitch import *
|
||||
|
||||
def get_target(cur, destination):
|
||||
cur.execute('select name from sip_buddies where callerid=?', (destination,))
|
||||
res = cur.fetchone()
|
||||
if (res):
|
||||
return res[0]
|
||||
else:
|
||||
return res
|
||||
|
||||
def get_caller_id(cur, caller):
|
||||
cur.execute('select callerid from sip_buddies where name=?', (caller,))
|
||||
res = cur.fetchone()
|
||||
if (res):
|
||||
return res[0]
|
||||
else:
|
||||
return res
|
||||
|
||||
def usage(stream, code):
|
||||
stream.write("ERROR: %d" % code)
|
||||
exit(1)
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
db_loc = None
|
||||
caller = None
|
||||
destination = None
|
||||
|
||||
|
||||
opts, args = getopt.getopt(args.split(" "), "d:c:t:", ["db=", "caller=", "target="])
|
||||
|
||||
for o,a in opts:
|
||||
if o in ("-d", "--db="):
|
||||
db_loc = a
|
||||
elif o in ("-c", "--caller="):
|
||||
caller = a
|
||||
elif o in ("-t", "--target="):
|
||||
destination = a
|
||||
else:
|
||||
usage(stream,0)
|
||||
|
||||
if (not db_loc):
|
||||
usage(stream,1)
|
||||
if (caller and destination):
|
||||
usage(stream,2)
|
||||
|
||||
def execute_cmd(db_loc, cmd):
|
||||
conn = sqlite3.connect(db_loc)
|
||||
cur = conn.cursor()
|
||||
if (caller):
|
||||
stream.write(str(get_caller_id(cur, caller)))
|
||||
else:
|
||||
stream.write(str(get_target(cur, destination)))
|
||||
cur.execute(cmd)
|
||||
res = cur.fetchone()
|
||||
conn.close()
|
||||
return res
|
||||
|
||||
#not using this now
|
||||
def handler(session,args):
|
||||
db_loc = session.getVariable("db_loc")
|
||||
caller = session.getVariable("username")
|
||||
destination = session.getVariable("destination_number")
|
||||
if (db_loc and caller and destination):
|
||||
res = get_vars(db_loc, caller, destination)
|
||||
def err(msg):
|
||||
consoleLog(msg)
|
||||
exit(1)
|
||||
|
||||
def parse_and_op(args):
|
||||
sys.stderr.write(args + "\n")
|
||||
args = args.split('|')
|
||||
cmd = args[0]
|
||||
db_loc = getGlobalVariable('openbts_db_loc')
|
||||
if (len(args) > 1):
|
||||
db_loc = args[1]
|
||||
|
||||
if not(db_loc):
|
||||
err('Missing DB. Is openbts_db_loc defined?\n')
|
||||
|
||||
try:
|
||||
res = execute_cmd(db_loc, cmd)
|
||||
return str(res[0])
|
||||
except Exception as err:
|
||||
consoleLog('err', str(err) + "\n")
|
||||
exit(1)
|
||||
|
||||
def chat(message, args):
|
||||
res = parse_and_op(args)
|
||||
consoleLog('info', "Returned: " + res)
|
||||
message.chat_execute('set', '_openbts_ret=%s' % res)
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
res = parse_and_op(args)
|
||||
consoleLog('info', "Returned: " + res)
|
||||
if (res):
|
||||
stream.write(str(res))
|
||||
|
||||
|
||||
@@ -86,21 +86,29 @@ def chat(message, args):
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
args = args.split('|')
|
||||
db_loc = args[0]
|
||||
caller = args[1]
|
||||
target = args[2]
|
||||
port = args[3]
|
||||
if (len(args) < 3):
|
||||
err('Missing Args\n')
|
||||
caller = args[0]
|
||||
target = args[1]
|
||||
port = args[2]
|
||||
|
||||
db_loc = None
|
||||
if (len(args) == 4):
|
||||
db_loc = args[3]
|
||||
|
||||
#if they don't all exist
|
||||
if (not db_loc or db_loc == ''):
|
||||
db_loc = getGlobalVariable("openbts_db_loc")
|
||||
|
||||
if not (db_loc and caller and target and port):
|
||||
err("Missing/Malformed Args \n")
|
||||
if (not db_loc):
|
||||
err("Missing DB. Is openbts_db_loc defined?\n")
|
||||
|
||||
if not (caller and target and port):
|
||||
err("Malformed Args \n")
|
||||
|
||||
if (caller == '' or
|
||||
target == '' or
|
||||
port == ''):
|
||||
err("Missing/Malformed Args \n")
|
||||
err("Malformed Args \n")
|
||||
|
||||
stream.write(str(create_user(db_loc, caller, target, port)))
|
||||
|
||||
@@ -114,15 +114,21 @@ def parse(rp_message):
|
||||
(rp_dest_address_type, rp_dest_address, rp_message) = get_rp_destination_address(rp_message)
|
||||
rp_user_data = get_rp_user_data(rp_message)
|
||||
|
||||
#rp_message finished
|
||||
#rp_message finished
|
||||
(tp_message_type, rp_user_data) = get_tp_message_type(rp_user_data)
|
||||
(tp_message_reference, rp_user_data) = get_tp_message_reference(rp_user_data)
|
||||
(tp_dest_address_type, tp_dest_address, rp_user_data) = get_tp_destination_address(rp_user_data)
|
||||
(tp_protocol_id, rp_user_data) = get_tp_protocol_identifier(rp_user_data)
|
||||
(tp_data_coding_scheme, rp_user_data) = get_tp_data_coding_scheme(rp_user_data)
|
||||
(tp_validity_period, rp_user_data) = get_tp_validity_period(rp_user_data)
|
||||
#check to see if validity period field is there
|
||||
if (int(tp_message_type, 16) & 0x10 == 0):
|
||||
tp_validity_period = None
|
||||
else:
|
||||
(tp_validity_period, rp_user_data) = get_tp_validity_period(rp_user_data)
|
||||
(tp_user_data, rp_user_data) = get_tp_user_data(rp_user_data)
|
||||
|
||||
sys.stderr.write(tp_user_data)
|
||||
|
||||
return {"openbts_rp_message_type" : rp_message_type,
|
||||
"openbts_rp_message_reference" : rp_message_reference,
|
||||
"openbts_rp_originator_address" : rp_originator_address,
|
||||
@@ -136,14 +142,10 @@ def parse(rp_message):
|
||||
"openbts_tp_data_coding_scheme" : tp_data_coding_scheme,
|
||||
"openbts_tp_validity_period" : tp_validity_period,
|
||||
"openbts_tp_user_data" : tp_user_data,
|
||||
"openbts_text" : messaging.utils.unpack_msg(tp_user_data).encode('UTF8')
|
||||
"openbts_text" : messaging.utils.unpack_msg(tp_user_data).encode('UTF8').rstrip('\0')
|
||||
}
|
||||
|
||||
if (len(rp_user_data[0]) != rp_user_data[1]): #index equals total
|
||||
raise Exception("EXTRA DATA AFTER TP-USER-DATA")
|
||||
|
||||
def chat(message, args):
|
||||
#sys.stderr.write(str(message.serialize()))
|
||||
try:
|
||||
content = parse(message.getBody())
|
||||
for key in content.keys():
|
||||
@@ -151,6 +153,11 @@ def chat(message, args):
|
||||
except Exception as err:
|
||||
consoleLog('err', str(err))
|
||||
sys.stderr.write(str(err))
|
||||
exit(1)
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
consoleLog('err', 'Cannot call Parse_SMS from the FS API\n')
|
||||
exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if (len(sys.argv) < 2):
|
||||
|
||||
@@ -68,8 +68,8 @@ def gen_body(to, text):
|
||||
tp_len = (len(tp_header) + len(tp_user_data))/2 #octets, not bytes
|
||||
return rp_header + gen_hex(tp_len) + tp_header + tp_user_data
|
||||
|
||||
def send_message(to, fromm, text):
|
||||
#fromm = 'IMSI641104278340235'
|
||||
#forward the message to smqueue for store-and-forwarding
|
||||
def send_smqueue_message(to, fromm, text):
|
||||
event = Event("CUSTOM", "SMS::SEND_MESSAGE")
|
||||
event.addHeader("proto", "sip");
|
||||
event.addHeader("dest_proto", "sip");
|
||||
@@ -82,18 +82,21 @@ def send_message(to, fromm, text):
|
||||
event.addHeader("replying", "false");
|
||||
event.addBody(gen_body(to, text));
|
||||
|
||||
#sys.stderr.write(event.serialize())
|
||||
event.fire()
|
||||
|
||||
def chat(message, args):
|
||||
args = args.split('|')
|
||||
if (len(args) < 3):
|
||||
consoleLog('err', 'Missing Args\n')
|
||||
exit(1)
|
||||
to = args[0]
|
||||
fromm = args[1]
|
||||
text = args[2]
|
||||
if ((not to or to == '') or
|
||||
(not fromm or fromm == '')):
|
||||
consoleLog('err', 'Missing Args\n')
|
||||
send_message(to, fromm, text)
|
||||
consoleLog('err', 'Malformed Args\n')
|
||||
exit(1)
|
||||
send_smqueue_message(to, fromm, text)
|
||||
|
||||
def fsapi(session, stream, env, args):
|
||||
#chat doesn't use message anyhow
|
||||
|
||||
Reference in New Issue
Block a user