From e7cd583c1edcea7f600064fac89a94a52a84a553 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Wed, 1 Oct 2008 20:18:57 +0000 Subject: removing asterisk: it's now living at http://forge.opensimulator.org/gf/project/asteriskvoice/ --- share/python/asterisk/asterisk-opensim.cfg | 16 -- share/python/asterisk/asterisk-opensim.py | 231 ------------------------ share/python/asterisk/create-region.sql | 4 - share/python/asterisk/create-table.sql | 62 ------- share/python/asterisk/create-user.sql | 5 - share/python/asterisk/test-client.py | 28 --- share/python/matrix/matrix.py | 272 ----------------------------- 7 files changed, 618 deletions(-) delete mode 100644 share/python/asterisk/asterisk-opensim.cfg delete mode 100755 share/python/asterisk/asterisk-opensim.py delete mode 100644 share/python/asterisk/create-region.sql delete mode 100644 share/python/asterisk/create-table.sql delete mode 100644 share/python/asterisk/create-user.sql delete mode 100755 share/python/asterisk/test-client.py delete mode 100755 share/python/matrix/matrix.py (limited to 'share/python') diff --git a/share/python/asterisk/asterisk-opensim.cfg b/share/python/asterisk/asterisk-opensim.cfg deleted file mode 100644 index 174dd7a..0000000 --- a/share/python/asterisk/asterisk-opensim.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[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 deleted file mode 100755 index aad72eb..0000000 --- a/share/python/asterisk/asterisk-opensim.py +++ /dev/null @@ -1,231 +0,0 @@ -#!/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 deleted file mode 100644 index a11e77a..0000000 --- a/share/python/asterisk/create-region.sql +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 4fe190f..0000000 --- a/share/python/asterisk/create-table.sql +++ /dev/null @@ -1,62 +0,0 @@ -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 deleted file mode 100644 index 68b8147..0000000 --- a/share/python/asterisk/create-user.sql +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100755 index d1872cd..0000000 --- a/share/python/asterisk/test-client.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/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 - diff --git a/share/python/matrix/matrix.py b/share/python/matrix/matrix.py deleted file mode 100755 index be7ec25..0000000 --- a/share/python/matrix/matrix.py +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8 -*- -# 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. - -import xml.etree.ElementTree as ET -import re -import urllib -import urllib2 -import ConfigParser -import optparse -import os -import sys - -def longHelp(): - print ''' -matrix.py is a little launcher tool that knows about the GridInfo -protocol. it expects the grid coordinates to be passed as a -command line argument either as a "matrix:" or as an "opensim:" style -URI: - - matrix://osgrid.org:8002/ - -you can also provide region/X/Y/Z coordinates: - - matrix://osgrid.org:8002/Wright%20Plaza/128/50/75 - -and, it also understands avatar names and passwords: - - matrix://mr%20smart:secretpassword@osgrid.org:8002/Wright%20Plaza/128/50/75 - -when you run it the first time, it will complain about a missing -.matrixcfg file --- this is needed so that it can remember where your -secondlife client lives on your box. to generate that file, simply run - - matrix.py --secondlife path-to-your-secondlife-client-executable - - ''' - -def ParseOptions(): - '''Parse the command line options and setup options. - ''' - - parser = optparse.OptionParser() - parser.add_option('-c', '--config', dest = 'config', help = 'config file', metavar = 'CONFIG') - parser.add_option('-s', '--secondlife', dest = 'client', help = 'location of secondlife client', metavar = 'SL-CLIENT') - parser.add_option('-l', '--longhelp', action='store_true', dest = 'longhelp', help = 'longhelp') - (options, args) = parser.parse_args() - - if options.longhelp: - parser.print_help() - longHelp() - sys.exit(0) - - return options - -def ParseConfig(options): - '''Ensure configuration exists and parse it. - ''' - # - # we are using ~/.matrixcfg to store the location of the - # secondlife client, os.path.normpath and os.path.expanduser - # should make sure that we are fine cross-platform - # - if not options.config: - options.config = '~/.matrixcfg' - - cfgPath = os.path.normpath(os.path.expanduser(options.config)) - - # - # if ~/.matrixcfg does not exist we are in trouble... - # - if not os.path.exists(cfgPath) and not options.client: - print '''oops, i've no clue where your secondlife client lives around here. - i suggest you run me with the "--secondlife path-of-secondlife-client" argument.''' - sys.exit(1) - - # - # ok, either ~/.matrixcfg does exist or we are asked to create it - # - config = ConfigParser.ConfigParser() - if os.path.exists(cfgPath): - config.readfp(open(cfgPath)) - - if options.client: - if config.has_option('secondlife', 'client'): - config.remove_option('secondlife', 'client') - if not config.has_section('secondlife'): - config.add_section('secondlife') - config.set('secondlife', 'client', options.client) - - cfg = open(cfgPath, mode = 'w+') - config.write(cfg) - cfg.close() - - return config.get('secondlife', 'client') - - -# -# regex: parse a URI -# -reURI = re.compile(r'''^(?P[a-zA-Z0-9]+):// # scheme - ((?P[^:@]+)(:(?P[^@]+))?@)? # avatar name and password (optional) - (?P[^:/]+)(:(?P\d+))? # host, port (optional) - (?P/.*) # path - $''', re.IGNORECASE | re.VERBOSE) - -# -# regex: parse path as location -# -reLOC = re.compile(r'''^/(?P[^/]+)/ # region name - (?P\d+)/ # X position - (?P\d+)/ # Y position - (?P\d+) # Z position - ''', re.IGNORECASE | re.VERBOSE) - -def ParseUri(uri): - '''Parse a URI and return its constituent parts. - ''' - - match = reURI.match(uri) - if not match or not match.group('scheme') or not match.group('host'): - print 'hmm... cannot parse URI %s, giving up' % uri - sys.exit(1) - - scheme = match.group('scheme') - host = match.group('host') - port = match.group('port') - avatar = match.group('avatar') - password = match.group('password') - path = match.group('path') - - return (scheme, host, port, avatar, password, path) - -def ParsePath(path): - '''Try and parse path as /region/X/Y/Z. - ''' - - loc = None - match = reLOC.match(path) - if match: - loc = 'secondlife:///%s/%d/%d/%d' % (match.group('region'), - int(match.group('x')), - int(match.group('y')), - int(match.group('z'))) - return loc - - -def GetGridInfo(host, port): - '''Invoke /get_grid_info on target grid and obtain additional parameters - ''' - - gridname = None - gridnick = None - login = None - welcome = None - economy = None - - # - # construct GridInfo URL - # - if port: - gridInfoURI = 'http://%s:%d/get_grid_info' % (host, int(port)) - else: - gridInfoURI = 'http://%s/get_grid_info' % (host) - - # - # try to retrieve GridInfo - # - try: - gridInfoXml = ET.parse(urllib2.urlopen(gridInfoURI)) - - gridname = gridInfoXml.findtext('/gridname') - gridnick = gridInfoXml.findtext('/gridnick') - login = gridInfoXml.findtext('/login') - welcome = gridInfoXml.findtext('/welcome') - economy = gridInfoXml.findtext('/economy') - authenticator = gridInfoXml.findtext('/authenticator') - - except urllib2.URLError: - print 'oops, failed to retrieve grid info, proceeding with guestimates...' - - return (gridname, gridnick, login, welcome, economy) - - -def StartClient(client, nick, login, welcome, economy, avatar, password, location): - clientArgs = [ client ] - clientArgs += ['-loginuri', login] - - if welcome: clientArgs += ['-loginpage', welcome] - if economy: clientArgs += ['-helperuri', economy] - - if avatar and password: - clientArgs += ['-login'] - clientArgs += urllib.unquote(avatar).split() - clientArgs += [password] - - if location: - clientArgs += [location] - - # - # all systems go - # - os.execv(client, clientArgs) - - -if __name__ == '__main__': - # - # parse command line options and deal with help requests - # - options = ParseOptions() - client = ParseConfig(options) - - # - # sanity check: URI supplied? - # - if not sys.argv: - print 'missing opensim/matrix URI' - sys.exit(1) - - # - # parse URI and extract scheme. host, port?, avatar?, password? - # - uri = sys.argv.pop() - (scheme, host, port, avatar, password, path) = ParseUri(uri) - - # - # sanity check: matrix: or opensim: scheme? - # - if scheme != 'matrix' and scheme != 'opensim': - print 'hmm...unknown scheme %s, calling it a day' % scheme - - # - # get grid info from OpenSim server - # - (gridname, gridnick, login, welcome, economy) = GetGridInfo(host, port) - - # - # fallback: use supplied uri in case GridInfo drew a blank - # - if not login: login = uri - - # - # take a closer look at path: if it's a /region/X/Y/Z pattern, use - # it as the "SLURL - # - location = ParsePath(path) - StartClient(client, gridnick, login, welcome, economy, avatar, password, location) - -- cgit v1.1