From 729ab451d5dd046e01535d5d76f0867b876fec99 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Wed, 28 Oct 2009 22:19:27 +0100 Subject: [PATCH] move the code that copies config data from murmur to md to the models and add syncing for existing instances, see #49 --- pyweb/mumble/management/server_detect.py | 38 ++++-------------- pyweb/mumble/models.py | 50 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/pyweb/mumble/management/server_detect.py b/pyweb/mumble/management/server_detect.py index f81fd3e..02e5ad1 100644 --- a/pyweb/mumble/management/server_detect.py +++ b/pyweb/mumble/management/server_detect.py @@ -83,10 +83,7 @@ def find_existing_instances( **kwargs ): if v > 1: print "Successfully connected to Murmur via connection string %s, using %s." % ( dbusName, ctl.method ); - default = ctl.getDefaultConf(); - servIDs = ctl.getAllServers(); - bootedIDs = ctl.getBootedServers(); for id in servIDs: if v > 1: @@ -95,44 +92,25 @@ def find_existing_instances( **kwargs ): try: instance = models.Mumble.objects.get( dbus=dbusName, srvid=id ); except models.Mumble.DoesNotExist: - conf = ctl.getAllConf(id); - - servername = find_in_dicts( "registername", conf, default, "noname" ); - if not servername: - # RegistrationName was found in the dicts, but is an empty string - servername = "noname"; - values = { - "name": servername, "srvid": id, "dbus": dbusName, - "addr": find_in_dicts( ( "registerhostame", "host" ), conf, default, "0.0.0.0" ), - "port": find_in_dicts( "port", conf, default ), - "url": find_in_dicts( "registerurl", conf, default ), - "motd": find_in_dicts( "welcometext", conf, default ), - "passwd": find_in_dicts( "password", conf, default ), - "supw": '', - "users": find_in_dicts( "users", conf, default ), - "bwidth": find_in_dicts( "bandwidth", conf, default ), - "sslcrt": find_in_dicts( "certificate", conf, default ), - "sslkey": find_in_dicts( "key", conf, default ), - "booted": ( id in bootedIDs ), } - if values['addr'].find( ':' ) != -1: - # The addr is a hostname which actually contains a port number, but we already got that from - # the port field, so we can simply drop it. - values['addr'] = values['addr'].split(':')[0]; - if v: - print 'Found new Murmur "%s" running on %s:%s.' % ( values['name'], values['addr'], values['port'] ); + print 'Found new Murmur instance... ', # now create a model for the record set. instance = models.Mumble( **values ); - instance.save( dontConfigureMurmur=True ); else: if v > 1: - print "This instance is already listed in the database."; + print "Syncing Murmur instance... ", + + instance.configureFromMurmur(); + print instance.name; + + instance.save( dontConfigureMurmur=True ); + # Now search for players on this server that have not yet been registered if v > 1: diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 50e635d..a8e64e6 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -167,6 +167,56 @@ class Mumble( models.Model ): return models.Model.save( self ); + def configureFromMurmur( self ): + default = self.ctl.getDefaultConf(); + conf = self.ctl.getAllConf( self.srvid ); + + def find_in_dicts( keys, valueIfNotFound=None ): + if not isinstance( keys, tuple ): + keys = ( keys, ); + + for keyword in keys: + if keyword in conf: + return conf[keyword]; + + for keyword in keys: + keyword = keyword.lower(); + if keyword in default: + return default[keyword]; + + return valueIfNotFound; + + servername = find_in_dicts( "registername", "noname" ); + if not servername: + # RegistrationName was found in the dicts, but is an empty string + servername = "noname"; + + addr = find_in_dicts( ( "registerhostname", "host" ), "0.0.0.0" ); + if addr.find( ':' ) != -1: + # The addr is a hostname which actually contains a port number, but we already got that from + # the port field, so we can simply drop it. + addr = addr.split(':')[0]; + + self.name = servername; + self.addr = addr; + self.port = find_in_dicts( "port" ); + self.url = find_in_dicts( "registerurl" ); + self.motd = find_in_dicts( "welcometext" ); + self.passwd = find_in_dicts( "password" ); + self.supw = ''; + self.users = find_in_dicts( "users" ); + self.bwidth = find_in_dicts( "bandwidth" ); + self.sslcrt = find_in_dicts( "certificate" ); + self.sslkey = find_in_dicts( "key" ); + self.obfsc = bool( find_in_dicts( 'obfuscate' ) ); + self.player = find_in_dicts( 'playername' ); + self.channel = find_in_dicts( 'channelname' ); + self.defchan = int( find_in_dicts( 'defaultchannel' ) ); + self.booted = ( self.srvid in self.ctl.getBootedServers() ); + + self.save( dontConfigureMurmur=True ); + + def isUserAdmin( self, user ): """Determine if the given user is an admin on this server.""" if user.is_authenticated():