Browse Source

add Ice secret and display address fields. (this means mumble-django-nat is now integrated in the main branch.)

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
6e95ecd191
  1. 75
      pyweb/mumble/models.py

75
pyweb/mumble/models.py

@ -36,7 +36,7 @@ def mk_config_property( field, doc="" ):
return None return None
def set_field( self, value ): def set_field( self, value ):
self.setConf( field, value )
self.setConf( field, str(value) )
return property( get_field, set_field, doc=doc ) return property( get_field, set_field, doc=doc )
@ -56,16 +56,20 @@ class Mumble( models.Model ):
deleted as well. deleted as well.
""" """
name = models.CharField( _('Server Name'), max_length = 200 );
dbus = models.CharField( _('DBus or ICE base'), max_length = 200, default = settings.DEFAULT_CONN, help_text=_(
name = models.CharField( _('Server Name'), max_length=200 );
dbus = models.CharField( _('DBus or ICE base'), max_length=200, default=settings.DEFAULT_CONN, help_text=_(
"Examples: 'net.sourceforge.mumble.murmur' for DBus or 'Meta:tcp -h 127.0.0.1 -p 6502' for Ice.") ); "Examples: 'net.sourceforge.mumble.murmur' for DBus or 'Meta:tcp -h 127.0.0.1 -p 6502' for Ice.") );
srvid = models.IntegerField( _('Server ID'), editable = False );
addr = models.CharField( _('Server Address'), max_length = 200, help_text=_(
srvid = models.IntegerField( _('Server ID'), editable=False );
addr = models.CharField( _('Server Address'), max_length=200, help_text=_(
"Hostname or IP address to bind to. You should use a hostname here, because it will appear on the " "Hostname or IP address to bind to. You should use a hostname here, because it will appear on the "
"global server list.") ); "global server list.") );
port = models.IntegerField( _('Server Port'), default=settings.MUMBLE_DEFAULT_PORT, help_text=_( port = models.IntegerField( _('Server Port'), default=settings.MUMBLE_DEFAULT_PORT, help_text=_(
"Port number to bind to. Use -1 to auto assign one.") ); "Port number to bind to. Use -1 to auto assign one.") );
display = models.CharField( _('Server Display Address'), max_length=200, blank=True, help_text=_(
"This field is only relevant if you are located behind a NAT, and names the Hostname or IP address "
"to use in the Channel Viewer and for the global server list registration. If not given, the addr "
"and port fields are used. If display and bind ports are equal, you can omit it here.") );
secret = models.CharField( _('Ice Secret'), max_length=200, blank=True );
supw = property( lambda self: '', supw = property( lambda self: '',
lambda self, value: self.ctl.setSuperUserPassword( self.srvid, value ), lambda self, value: self.ctl.setSuperUserPassword( self.srvid, value ),
@ -137,26 +141,10 @@ class Mumble( models.Model ):
'maxrange': 2**16, 'maxrange': 2**16,
}); });
self.ctl.setConf( self.srvid, 'host', socket.gethostbyname( self.addr ) );
self.ctl.setConf( self.srvid, 'host', socket.gethostbyname(self.addr) );
self.ctl.setConf( self.srvid, 'port', str(self.port) ); self.ctl.setConf( self.srvid, 'port', str(self.port) );
self.ctl.setConf( self.srvid, 'registername', self.name ); self.ctl.setConf( self.srvid, 'registername', self.name );
self.ctl.setConf( self.srvid, 'registerurl', self.url );
# registerHostname needs to take the port no into account
if self.port and self.port != settings.MUMBLE_DEFAULT_PORT:
self.ctl.setConf( self.srvid, 'registerhostname', "%s:%d" % ( self.addr, self.port ) );
else:
self.ctl.setConf( self.srvid, 'registerhostname', self.addr );
if self.supw:
self.ctl.setSuperUserPassword( self.srvid, self.supw );
self.supw = '';
if self.booted != self.ctl.isBooted( self.srvid ):
if self.booted:
self.ctl.start( self.srvid );
else:
self.ctl.stop( self.srvid );
self.ctl.setConf( self.srvid, 'registerhostname', self.netloc );
# Now allow django to save the record set # Now allow django to save the record set
return models.Model.save( self ); return models.Model.save( self );
@ -355,20 +343,37 @@ class Mumble( models.Model ):
channels = property( getChannels, doc="A convenience wrapper for getChannels()." ); channels = property( getChannels, doc="A convenience wrapper for getChannels()." );
rootchan = property( lambda self: self.channels[0], doc="A convenience wrapper for getChannels()[0]." ); rootchan = property( lambda self: self.channels[0], doc="A convenience wrapper for getChannels()[0]." );
def getURL( self, forUser = None ):
""" Create an URL of the form mumble://username@host:port/ for this server. """
userstr = "";
if forUser is not None:
userstr = "%s@" % forUser.name;
def getNetloc( self ):
""" Return the address from the Display field (if any), or the server address.
Users from outside a NAT will need to use the Display address to connect
to this server instance.
"""
if self.display:
if ":" in self.display:
return self.display;
else:
daddr = self.display;
else:
daddr = self.addr;
versionstr = "version=%d.%d.%d" % tuple(self.version[0:3]);
if self.port and self.port != settings.MUMBLE_DEFAULT_PORT:
return "%s:%d" % (daddr, self.port);
else:
return daddr;
if self.port != settings.MUMBLE_DEFAULT_PORT:
return "mumble://%s%s:%d/?%s" % ( userstr, self.addr, self.port, versionstr );
netloc = property( getNetloc, doc=getNetloc.__doc__ );
return "mumble://%s%s/?%s" % ( userstr, self.addr, versionstr );
def getURL( self, forUser = None ):
""" Create an URL of the form mumble://username@host:port/ for this server. """
from urlparse import urlunsplit
versionstr = "version=%d.%d.%d" % tuple(self.version[:3]);
if forUser is not None:
netloc = "%s@%s" % ( forUser.name, self.netloc );
return urlunsplit(( "mumble", netloc, "", versionstr, "" ))
else:
return urlunsplit(( "mumble", self.netloc, "", versionstr, "" ))
connecturl = property( getURL, doc="A convenience wrapper for getURL()." );
connecturl = property( getURL, doc=getURL.__doc__ );
version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." ); version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." );
@ -472,7 +477,7 @@ class MumbleUser( models.Model ):
self.server.rootchan.acl.save(); self.server.rootchan.acl.save();
return value; return value;
aclAdmin = property( getAdmin, setAdmin, doc="Wrapper around getAdmin/setAdmin (not a database field like isAdmin)" );
aclAdmin = property( getAdmin, setAdmin, doc='Admin on root channel' );
# Registration fetching # Registration fetching
def getRegistration( self ): def getRegistration( self ):

Loading…
Cancel
Save