Browse Source

minor refactoring (and bugfix); show IP address and user name in the ban list. see #126

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
c0f7927397
  1. 17
      pyweb/mumble/media/js/banviewer.js
  2. 18
      pyweb/mumble/mmobjects.py
  3. 13
      pyweb/mumble/utils.py
  4. 6
      pyweb/mumble/views.py

17
pyweb/mumble/media/js/banviewer.js

@ -11,17 +11,28 @@ Ext.ux.BanViewerPanel = function( config ){
colModel: new Ext.grid.ColumnModel([{
header: gettext('Timestamp'),
dataIndex: 'start',
width: 100,
width: 150,
renderer: function( value ){
return new Date(value*1000).format( "Y-m-d H:i:s" );
}
}, {
header: gettext('Address'),
width: 250,
dataIndex: 'addrstr',
renderer: function( value, meta, record, rowIdx, colIdx, store ){
return value + "/" + record.data['bits'];
}
}, {
header: gettext('User name'),
width: 150,
dataIndex: 'name'
}, {
header: gettext('Duration'),
width: 100,
dataIndex: 'duration'
}, {
header: gettext('Reason'),
width: 500,
width: 300,
dataIndex: 'reason'
}]),
bbar: [{
@ -36,7 +47,7 @@ Ext.ux.BanViewerPanel = function( config ){
directFn: Mumble.bans,
paramOrder: ['server'],
root: 'data',
fields: ['start', 'address', 'bits', 'duration', 'reason'],
fields: ['start', 'address', 'bits', 'duration', 'reason', 'addrstr', 'name'],
autoLoad: true,
remoteSort: false
}),

18
pyweb/mumble/mmobjects.py

@ -25,6 +25,7 @@ from django.contrib.sites.models import Site
from django.utils.http import urlquote
from django.conf import settings
from mumble.utils import iptostring
def cmp_channels( left, rite ):
""" Compare two channels, first by position, and if that equals, by name. """
@ -277,14 +278,7 @@ class mmPlayer( object ):
def getIpAsString( self ):
""" Get the client's IPv4 or IPv6 address, in a pretty format. """
addr = self.player_obj.address
if max( addr[:10] ) == 0 and addr[10:12] == (255, 255):
return "%d.%d.%d.%d" % tuple( addr[12:] )
ip6addr = [(hi << 8 | lo) for (hi, lo) in zip(addr[0::2], addr[1::2])]
# colon-separated string:
ipstr = ':'.join([ ("%x" % part) for part in ip6addr ])
# 0:0:0 -> ::
return re.sub( "((^|:)(0:){2,})", '::', ipstr, 1 )
return iptostring(self.player_obj.address)
ipaddress = property( getIpAsString )
fqdn = property( lambda self: socket.getfqdn( self.ipaddress ),
@ -305,11 +299,11 @@ class mmPlayer( object ):
def asDict( self, authed=False ):
pldata = self.player_obj.__dict__.copy()
if authed:
if "ipaddress" in pldata:
if "address" in pldata:
if authed:
pldata["x_addrstring"] = self.ipaddress
elif "address" in pldata:
del pldata["address"]
else:
del pldata["address"]
if self.channel.server.hasUserTexture(self.userid):
from views import showTexture

13
pyweb/mumble/utils.py

@ -15,6 +15,19 @@
* GNU General Public License for more details.
"""
import re
def iptostring(addr):
""" Get the client's IPv4 or IPv6 address, in a pretty format. """
if max( addr[:10] ) == 0 and addr[10:12] == (255, 255):
return "%d.%d.%d.%d" % tuple( addr[12:] )
ip6addr = [(hi << 8 | lo) for (hi, lo) in zip(addr[0::2], addr[1::2])]
# colon-separated string:
ipstr = ':'.join([ ("%x" % part) for part in ip6addr ])
# 0:0:0 -> ::
return re.sub( "((^|:)(0:){2,})", '::', ipstr, 1 )
class ObjectInfo( object ):
""" Wraps arbitrary information to be easily accessed. """

6
pyweb/mumble/views.py

@ -36,6 +36,7 @@ from django.views.decorators.csrf import csrf_exempt
from models import Mumble, MumbleUser
from forms import MumbleForm, MumbleUserForm, MumbleUserPasswordForm
from forms import MumbleUserLinkForm, MumbleTextureForm, MumbleKickForm
from utils import iptostring
from djextdirect.provider import Provider
from djextdirect.views import login, logout
@ -280,13 +281,14 @@ def log( request, server, start, limit, filter ):
@EXT_DIRECT_PROVIDER.register_method( "Mumble" )
def bans( request, server ):
""" Retrieve log messages. """
""" Retrieve bans. """
srv = get_object_or_404( Mumble, id=int(server) )
if not srv.isUserAdmin( request.user ):
raise Exception( "Access denied" )
return { 'data': [
{ 'start': ent.start, 'address': ent.address, 'bits': ent.bits,
'duration': ent.duration, 'reason': ent.reason }
'duration': ent.duration, 'reason': ent.reason, 'name': ent.name,
'addrstr': iptostring(ent.address) }
for ent in srv.getBans()
], 'success': True }

Loading…
Cancel
Save