From c0f792739700358865526bb7f59851de7a798756 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Thu, 9 Dec 2010 21:38:08 +0100 Subject: [PATCH] minor refactoring (and bugfix); show IP address and user name in the ban list. see #126 --- pyweb/mumble/media/js/banviewer.js | 17 ++++++++++++++--- pyweb/mumble/mmobjects.py | 18 ++++++------------ pyweb/mumble/utils.py | 13 +++++++++++++ pyweb/mumble/views.py | 6 ++++-- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/pyweb/mumble/media/js/banviewer.js b/pyweb/mumble/media/js/banviewer.js index 73c5d37..d5598fe 100644 --- a/pyweb/mumble/media/js/banviewer.js +++ b/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 }), diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index 0a67eb4..e737341 100644 --- a/pyweb/mumble/mmobjects.py +++ b/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 diff --git a/pyweb/mumble/utils.py b/pyweb/mumble/utils.py index 52a6732..e2bb041 100644 --- a/pyweb/mumble/utils.py +++ b/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. """ diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 12a8d36..5042cd9 100644 --- a/pyweb/mumble/views.py +++ b/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 }