diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index 46f50adfe2..a65a3f1139 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -201,6 +201,7 @@ namespace OpenSim.Region.Capabilities { //Console.WriteLine("caps request " + request); string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails); + //m_log.DebugFormat("[CAPS] CapsRequest {0}", result); return result; } diff --git a/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs new file mode 100644 index 0000000000..52b9c3e92d --- /dev/null +++ b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs @@ -0,0 +1,288 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using libsecondlife; +using Nini.Config; +using Nwc.XmlRpc; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Servers; +using OpenSim.Region.Capabilities; +using Caps = OpenSim.Region.Capabilities.Caps; +using OpenSim.Region.Environment.Interfaces; +using OpenSim.Region.Environment.Scenes; + +namespace OpenSim.Region.Environment.Modules +{ + public class AsteriskVoiceModule : IRegionModule + { + private static readonly log4net.ILog m_log = + log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; + private IConfig m_config; + private string m_asterisk; + private string m_asterisk_password; + private string m_asterisk_salt; + private int m_asterisk_timeout; + private string m_sipDomain; + private string m_confDomain; + + private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; + private static readonly string m_provisionVoiceAccountRequestPath = "0008/"; + + public void Initialise(Scene scene, IConfigSource config) + { + m_scene = scene; + m_config = config.Configs["AsteriskVoice"]; + + if (null == m_config) + { + m_log.Info("[ASTERISKVOICE] no config found, plugin disabled"); + return; + } + + if (!m_config.GetBoolean("enabled", false)) + { + m_log.Info("[ASTERISKVOICE] plugin disabled by configuration"); + return; + } + m_log.Info("[ASTERISKVOICE] plugin enabled"); + + try { + m_sipDomain = m_config.GetString("sip_domain", String.Empty); + m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain); + + m_confDomain = m_config.GetString("conf_domain", String.Empty); + m_log.InfoFormat("[ASTERISKVOICE] using conf domain {0}", m_confDomain); + + m_asterisk = m_config.GetString("asterisk_frontend", String.Empty); + m_asterisk_password = m_config.GetString("asterisk_password", String.Empty); + m_asterisk_timeout = m_config.GetInt("asterisk_timeout", 3000); + m_asterisk_salt = m_config.GetString("asterisk_salt", "Wuffwuff"); + if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter"); + if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter"); + m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk); + + scene.EventManager.OnRegisterCaps += OnRegisterCaps; + } + catch (Exception e) + { + m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message); + m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString()); + return; + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "AsteriskVoiceModule"; } + } + + public bool IsSharedModule + { + get { return false; } + } + + public void OnRegisterCaps(LLUUID agentID, Caps caps) + { + m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); + string capsBase = "/CAPS/" + caps.CapsObjectPath; + caps.RegisterHandler("ParcelVoiceInfoRequest", + new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, + delegate(string request, string path, string param) + { + return ParcelVoiceInfoRequest(request, path, param, + agentID, caps); + })); + caps.RegisterHandler("ProvisionVoiceAccountRequest", + new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, + delegate(string request, string path, string param) + { + return ProvisionVoiceAccountRequest(request, path, param, + agentID, caps); + })); + } + + /// + /// Callback for a client request for ParcelVoiceInfo + /// + /// + /// + /// + /// + /// + /// + public string ParcelVoiceInfoRequest(string request, string path, string param, + LLUUID agentID, Caps caps) + { + // we need to do: + // - send channel_uri: as "sip:regionID@m_sipDomain" + try + { + m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", + request, path, param); + + + // setup response to client + Hashtable creds = new Hashtable(); + creds["channel_uri"] = String.Format("sip:{0}@{1}", + m_scene.RegionInfo.RegionID.ToString(), m_sipDomain); + + string regionName = m_scene.RegionInfo.RegionName; + ScenePresence avatar = m_scene.GetScenePresence(agentID); + if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); + LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); + + LLSDParcelVoiceInfoResponse parcelVoiceInfo = + new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); + + string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); + + + // update region on asterisk-opensim frontend + Hashtable requestData = new Hashtable(); + requestData["admin_password"] = m_asterisk_password; + requestData["region"] = m_scene.RegionInfo.RegionID.ToString(); + if (!String.IsNullOrEmpty(m_confDomain)) + { + requestData["region"] += String.Format("@{0}", m_confDomain); + } + + ArrayList SendParams = new ArrayList(); + SendParams.Add(requestData); + XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams); + XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); + Hashtable responseData = (Hashtable)updateAccountResponse.Value; + + if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed"); + + bool success = Convert.ToBoolean((string)responseData["success"]); + if (!success) throw new Exception("region_update failed"); + + + m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: {0}", r); + return r; + } + catch (Exception e) + { + m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0}, retry later", e.Message); + m_log.DebugFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0} failed", e.ToString()); + + return "undef"; + } + + return null; + } + + /// + /// Callback for a client request for Voice Account Details + /// + /// + /// + /// + /// + /// + /// + public string ProvisionVoiceAccountRequest(string request, string path, string param, + LLUUID agentID, Caps caps) + { + // we need to + // - get user data from UserProfileCacheService + // - generate nonce for user voice account password + // - issue XmlRpc request to asterisk opensim front end: + // + user: base 64 encoded user name (otherwise SL + // client is unhappy) + // + password: nonce + // - the XmlRpc call to asteris-opensim was successful: + // send account details back to client + try + { + m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", + request, path, param); + + // get user data & prepare voice account response + string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); + voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); + + CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); + if (null == userInfo) throw new Exception("cannot get user details"); + + // we generate a nonce everytime + string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt); + LLSDVoiceAccountResponse voiceAccountResponse = + new LLSDVoiceAccountResponse(voiceUser, voicePassword); + string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); + m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); + + + // update user account on asterisk frontend + Hashtable requestData = new Hashtable(); + requestData["admin_password"] = m_asterisk_password; + requestData["username"] = voiceUser; + if (!String.IsNullOrEmpty(m_sipDomain)) + { + requestData["username"] += String.Format("@{0}", m_sipDomain); + } + requestData["password"] = voicePassword; + + ArrayList SendParams = new ArrayList(); + SendParams.Add(requestData); + XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams); + XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); + Hashtable responseData = (Hashtable)updateAccountResponse.Value; + + if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed"); + + bool success = Convert.ToBoolean((string)responseData["success"]); + if (!success) throw new Exception("account_update failed"); + + return r; + } + catch (Exception e) + { + m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0}, retry later", e.Message); + m_log.DebugFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0} failed", e.ToString()); + + return "undef"; + } + + return null; + } + } +} diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 6a0494719e..4e997403c2 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -173,6 +173,22 @@ account_management_server = https://www.bhr.vivox.com/api2 ; Global SIP Server for conference calls sip_domain = testserver.com +[AsteriskVoice] +; PLEASE NOTE that we don't have voice support in OpenSim quite yet - these configuration options are stubs +enabled = false +; SIP account server domain +sip_domain = testserver.com +; SIP conf server domain +conf_domain = testserver.com +; URL of the asterisk opensim frontend +asterisk_frontend = http://testserver.com:49153/ +; password for the asterisk frontend XmlRpc calls +asterisk_password = bah-humbug +; timeout for XmlRpc calls to asterisk front end (in ms) +asterisk_timeout = 3000 +; salt for asterisk nonces +asterisk_salt = paluempalum + ; Uncomment the following to control the progression of daytime ; in the Sim. The defaults are what is shown below ;[Sun] diff --git a/share/python/asterisk/asterisk-opensim.cfg b/share/python/asterisk/asterisk-opensim.cfg new file mode 100644 index 0000000000..174dd7a479 --- /dev/null +++ b/share/python/asterisk/asterisk-opensim.cfg @@ -0,0 +1,16 @@ +[xmlrpc] +baseurl = http://127.0.0.1:53263/ +debug = true + +[mysql] +server = localhost +database = asterisk +user = asterisk +password = asterisk +debug = true + +[mysql-templates] +tables = create-table.sql +user = create-user.sql +region = create-region.sql +debug = true diff --git a/share/python/asterisk/asterisk-opensim.py b/share/python/asterisk/asterisk-opensim.py new file mode 100644 index 0000000000..aad72ebc2b --- /dev/null +++ b/share/python/asterisk/asterisk-opensim.py @@ -0,0 +1,231 @@ +#!/usr/bin/python +# -*- encoding: utf-8 -*- + +from __future__ import with_statement + +import base64 +import ConfigParser +import optparse +import MySQLdb +import re +import SimpleXMLRPCServer +import socket +import sys +import uuid + +class AsteriskOpenSimServerException(Exception): + pass + +class AsteriskOpenSimServer(SimpleXMLRPCServer.SimpleXMLRPCServer): + '''Subclassed SimpleXMLRPCServer to be able to muck around with the socket options. + ''' + + def __init__(self, config): + baseURL = config.get('xmlrpc', 'baseurl') + match = reURLParser.match(baseURL) + if not match: + raise AsteriskOpenSimServerException('baseURL "%s" is not a well-formed URL' % (baseURL)) + + host = 'localhost' + port = 80 + path = None + if match.group('host'): + host = match.group('host') + port = int(match.group('port')) + else: + host = match.group('hostonly') + + self.__host = host + self.__port = port + + SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(self,(host, port)) + + def host(self): + return self.__host + + def port(self): + return self.__port + + def server_bind(self): + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) + + +class AsteriskFrontend(object): + '''AsteriskFrontend serves as an XmlRpc function dispatcher. + ''' + + def __init__(self, config, db): + '''Constructor to take note of the AsteriskDB object. + ''' + self.__db = db + try: + self.__debug = config.getboolean('dispatcher', 'debug') + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + self.__debug = False + + def account_update(self, request): + '''update (or create) the SIP account data in the Asterisk RealTime DB. + + OpenSim's AsteriskVoiceModule will call this method each + time it receives a ProvisionVoiceAccount request. + ''' + print '[asterisk-opensim] account_update: new request' + + for p in ['admin_password', 'username', 'password']: + if p not in request: + print '[asterisk-opensim] account_update: failed: missing password' + return { 'success': 'false', 'error': 'missing parameter "%s"' % (p)} + + # turn base64 binary UUID into proper UUID + user = request['username'].partition('@')[0] + user = user.lstrip('x').replace('-','+').replace('_','/') + user = uuid.UUID(bytes = base64.standard_b64decode(user)) + + if self.__debug: print '[asterisk-opensim]: account_update: user %s' % user + + error = self.__db.AccountUpdate(user = user, password = request['password']) + if error: + print '[asterisk-opensim]: DB.AccountUpdate failed' + return { 'success': 'false', 'error': error} + + print '[asterisk-opensim] account_update: done' + return { 'success': 'true'} + + + def region_update(self, request): + '''update (or create) a VoIP conference call for a region. + + OpenSim's AsteriskVoiceModule will call this method each time it + receives a ParcelVoiceInfo request. + ''' + print '[asterisk-opensim] region_update: new request' + + for p in ['admin_password', 'region']: + if p not in request: + print '[asterisk-opensim] region_update: failed: missing password' + return { 'success': 'false', 'error': 'missing parameter "%s"' % (p)} + + region = request['region'].partition('@')[0] + if self.__debug: print '[asterisk-opensim]: region_update: region %s' % user + + error = self.__db.RegionUpdate(region = region) + if error: + print '[asterisk-opensim]: DB.RegionUpdate failed' + return { 'success': 'false', 'error': error} + + print '[asterisk-opensim] region_update: done' + return { 'success': 'true' } + +class AsteriskDBException(Exception): + pass + +class AsteriskDB(object): + '''AsteriskDB maintains the connection to Asterisk's MySQL database. + ''' + def __init__(self, config): + # configure from config object + self.__server = config.get('mysql', 'server') + self.__database = config.get('mysql', 'database') + self.__user = config.get('mysql', 'user') + self.__password = config.get('mysql', 'password') + + try: + self.__debug = config.getboolean('mysql', 'debug') + self.__debug_t = config.getboolean('mysql-templates', 'debug') + except ConfigParser.NoOptionError: + self.__debug = False + + self.__tablesTemplate = self.__loadTemplate(config, 'tables') + self.__userTemplate = self.__loadTemplate(config, 'user') + self.__regionTemplate = self.__loadTemplate(config, 'region') + + self.__mysql = MySQLdb.connect(host = self.__server, db = self.__database, + user = self.__user, passwd = self.__password) + if self.__assertDBExists(): + raise AsteriskDBException('could not initialize DB') + + def __loadTemplate(self, config, templateName): + template = config.get('mysql-templates', templateName) + t = '' + with open(template, 'r') as templateFile: + for line in templateFile: + line = line.rstrip('\n') + t += line + return t.split(';') + + + def __assertDBExists(self): + '''Assert that DB tables exist. + ''' + try: + cursor = self.__mysql.cursor() + for sql in self.__tablesTemplate[:]: + if not sql: continue + sql = sql % { 'database': self.__database } + if self.__debug: print 'AsteriskDB.__assertDBExists: %s' % sql + cursor.execute(sql) + cursor.fetchall() + cursor.close() + except MySQLdb.Error, e: + if self.__debug: print 'AsteriskDB.__assertDBExists: Error %d: %s' % (e.args[0], e.args[1]) + return e.args[1] + return None + + def AccountUpdate(self, user, password): + print 'AsteriskDB.AccountUpdate: user %s' % (user) + try: + cursor = self.__mysql.cursor() + for sql in self.__userTemplate[:]: + if not sql: continue + sql = sql % { 'database': self.__database, 'username': user, 'password': password } + if self.__debug_t: print 'AsteriskDB.AccountUpdate: sql: %s' % sql + cursor.execute(sql) + cursor.fetchall() + cursor.close() + except MySQLdb.Error, e: + if self.__debug: print 'AsteriskDB.RegionUpdate: Error %d: %s' % (e.args[0], e.args[1]) + return e.args[1] + return None + + def RegionUpdate(self, region): + print 'AsteriskDB.RegionUpdate: region %s' % (region) + try: + cursor = self.__mysql.cursor() + for sql in self.__regionTemplate[:]: + if not sql: continue + sql = sql % { 'database': self.__database, 'regionname': region } + if self.__debug_t: print 'AsteriskDB.RegionUpdate: sql: %s' % sql + cursor.execute(sql) + res = cursor.fetchall() + except MySQLdb.Error, e: + if self.__debug: print 'AsteriskDB.RegionUpdate: Error %d: %s' % (e.args[0], e.args[1]) + return e.args[1] + return None + + +reURLParser = re.compile(r'^http://((?P[^/]+):(?P\d+)|(?P[^/]+))/', re.IGNORECASE) + +# main +if __name__ == '__main__': + + parser = optparse.OptionParser() + parser.add_option('-c', '--config', dest = 'config', help = 'config file', metavar = 'CONFIG') + (options, args) = parser.parse_args() + + if not options.config: + parser.error('missing option config') + sys.exit(1) + + config = ConfigParser.ConfigParser() + config.readfp(open(options.config)) + + server = AsteriskOpenSimServer(config) + server.register_introspection_functions() + server.register_instance(AsteriskFrontend(config, AsteriskDB(config))) + + # get cracking + print '[asterisk-opensim] server ready on %s:%d' % (server.host(), server.port()) + server.serve_forever() + + sys.exit(0) diff --git a/share/python/asterisk/create-region.sql b/share/python/asterisk/create-region.sql new file mode 100644 index 0000000000..a11e77a493 --- /dev/null +++ b/share/python/asterisk/create-region.sql @@ -0,0 +1,4 @@ +USE %(database)s; +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(regionname)s', 1, 'Answer', ''); +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(regionname)s', 2, 'Wait', '1'); +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(regionname)s', 3, 'Meetme', '%(regionname)s|Acdi'); \ No newline at end of file diff --git a/share/python/asterisk/create-table.sql b/share/python/asterisk/create-table.sql new file mode 100644 index 0000000000..4fe190f9e0 --- /dev/null +++ b/share/python/asterisk/create-table.sql @@ -0,0 +1,62 @@ +USE %(database)s; +CREATE TABLE IF NOT EXISTS `ast_sipfriends` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(80) NOT NULL default '', + `host` varchar(31) NOT NULL default 'dynamic', + `nat` varchar(5) NOT NULL default 'route', + `type` enum('user','peer','friend') NOT NULL default 'friend', + `accountcode` varchar(20) default NULL, + `amaflags` varchar(13) default NULL, + `callgroup` varchar(10) default NULL, + `callerid` varchar(80) default NULL, + `call-limit` int(11) NOT NULL default '0', + `cancallforward` char(3) default 'no', + `canreinvite` char(3) default 'no', + `context` varchar(80) default 'pre_outgoing', + `defaultip` varchar(15) default NULL, + `dtmfmode` varchar(7) default NULL, + `fromuser` varchar(80) default NULL, + `fromdomain` varchar(80) default NULL, + `insecure` varchar(4) default NULL, + `language` char(2) default NULL, + `mailbox` varchar(50) default NULL, + `md5secret` varchar(80) default NULL, + `deny` varchar(95) default NULL, + `permit` varchar(95) default NULL, + `mask` varchar(95) default NULL, + `musiconhold` varchar(100) default NULL, + `pickupgroup` varchar(10) default NULL, + `qualify` char(3) default NULL, + `regexten` varchar(80) default NULL, + `restrictcid` char(3) default NULL, + `rtptimeout` char(3) default NULL, + `rtpholdtimeout` char(3) default NULL, + `secret` varchar(80) default NULL, + `setvar` varchar(100) default NULL, + `disallow` varchar(100) default 'all', + `allow` varchar(100) default 'g729', + `fullcontact` varchar(80) NOT NULL default '', + `ipaddr` varchar(15) NOT NULL default '', + `port` smallint(5) unsigned NOT NULL default '0', + `regserver` varchar(100) default NULL, + `regseconds` int(11) NOT NULL default '0', + `username` varchar(80) NOT NULL default '', + `user` varchar(255) NOT NULL, + `placement` varchar(255) NOT NULL, + `description` varchar(255) NOT NULL, + `delay` int(4) NOT NULL default '0', + `sortorder` int(11) NOT NULL default '1', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; + +CREATE TABLE IF NOT EXISTS `extensions_table` ( + `id` int(11) NOT NULL auto_increment, + `context` varchar(20) NOT NULL default '', + `exten` varchar(36) NOT NULL default '', + `priority` tinyint(4) NOT NULL default '0', + `app` varchar(20) NOT NULL default '', + `appdata` varchar(128) NOT NULL default '', + PRIMARY KEY (`context`,`exten`,`priority`), + KEY `id` (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; \ No newline at end of file diff --git a/share/python/asterisk/create-user.sql b/share/python/asterisk/create-user.sql new file mode 100644 index 0000000000..68b8147681 --- /dev/null +++ b/share/python/asterisk/create-user.sql @@ -0,0 +1,5 @@ +USE %(database)s; +REPLACE INTO ast_sipfriends (port,context,disallow,allow,type,secret,host,name) VALUES ('5060','avatare','all','ulaw','friend','%(password)s','dynamic','%(username)s'); +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(username)s', 1, 'Answer', ''); +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(username)s', 2, 'Wait', '1'); +REPLACE INTO `extensions_table` (context,exten,priority,app,appdata) VALUES ('avatare', '%(username)s', 3, 'Dial', 'SIP/%(username)s,60'); \ No newline at end of file diff --git a/share/python/asterisk/test-client.py b/share/python/asterisk/test-client.py new file mode 100644 index 0000000000..d1872cd01f --- /dev/null +++ b/share/python/asterisk/test-client.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# -*- encoding: utf-8 -*- + +import xmlrpclib + +# XML-RPC URL (http_listener_port) +asteriskServerURL = 'http://127.0.0.1:53263' + +# instantiate server object +asteriskServer = xmlrpclib.Server(asteriskServerURL) + +try: + # invoke admin_alert: requires password and message + res = asteriskServer.region_update({ + 'admin_password': 'c00lstuff', + 'region' : '941ae087-a7da-43b4-900b-9fe48387ae57@secondlife.zurich.ibm.com' + }) + print res + + res = asteriskServer.account_update({ + 'admin_password': 'c00lstuff', + 'username' : '0780d90b-1939-4152-a283-8d1261fb1b68@secondlife.zurich.ibm.com', + 'password' : '$1$dd02c7c2232759874e1c205587017bed' + }) + print res +except Exception, e: + print e +