From facb069dad1a38fa8eb3e3e8a020b448d212c390 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Wed, 25 Mar 2009 21:03:10 +0100 Subject: [PATCH] added an object that represents the ACL instead of messing with array indices --- pyweb/mumble/mmobjects.py | 34 ++++++++++++++++++++++++++++++++++ pyweb/mumble/models.py | 34 +++++++++++++++++----------------- pyweb/settings.py | 2 +- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index 1d957fc..947fb9c 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -218,3 +218,37 @@ class mmPlayer( object ): def visit( self, callback, lvl = 0 ): callback( self, lvl ); + + +class mmACL: + def __init__( self, channelId, aclObj ): + aclsrc, groupsrc, inherit = aclObj; + + self.channelId = channelId; + + self.acls = []; + for line in aclsrc: + acl = {}; + acl['applyHere'], acl['applySubs'], acl['inherited'], acl['playerid'], acl['group'], acl['allow'], acl['deny'] = line; + self.acls.append( acl ); + + self.groups = []; + for line in groupsrc: + group = {}; + group['name'], group['inherited'], group['inherit'], group['inheritable'], group['add'], group['remove'], group['members'] = line; + self.groups.append( group ); + if group['name'] == "admin": + self.admingroup = group; + + self.inherit = inherit; + + def pack( self ): + return ( + self.channelId, + [( acl['applyHere'], acl['applySubs'], acl['inherited'], acl['playerid'], acl['group'], acl['allow'], acl['deny'] ) for acl in self.acls ], + [( group['name'], group['inherited'], group['inherit'], group['inheritable'], group['add'], group['remove'], group['members'] ) for group in self.groups ], + self.inherit + ); + + + diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 010f230..8e288dd 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -33,7 +33,7 @@ from django.contrib.auth.models import User from django.db import models -from mmobjects import mmServer +from mmobjects import mmServer, mmACL import dbus import socket @@ -187,27 +187,27 @@ class MumbleUser( models.Model ): def getAdmin( self ): # Get ACL of root Channel, get the admin group and see if I'm in it bus = self.server.getDbusObject(); - aclinfo, groupinfo, inherit = bus.getACL(0); + acl = mmACL( bus.getACL(0) ); - for grp in groupinfo: - if grp[0] == 'admin': - return self.mumbleid in grp[4]; - return False; + if not hasattr( acl, "admingroup" ): + raise ValueError( "The admin group was not found in the ACL's groups list!" ); + return self.mumbleid in acl.admingroup['add']; def setAdmin( self, value ): # Get ACL of root Channel, get the admin group and see if I'm in it bus = self.server.getDbusObject(); - aclinfo, groupinfo, inherit = bus.getACL(0); - - for grp in groupinfo: - if grp[0] == 'admin': - if value != ( self.mumbleid in grp[4] ): - if value: - grp[4].append( self.mumbleid ); - else: - grp[4].remove( self.mumbleid ); - break; - bus.setACL( 0, aclinfo, groupinfo, inherit ); + acl = mmACL( 0, bus.getACL(0) ); + + if not hasattr( acl, "admingroup" ): + raise ValueError( "The admin group was not found in the ACL's groups list!" ); + + if value != ( self.mumbleid in acl.admingroup['add'] ): + if value: + acl.admingroup['add'].append( dbus.Int32(self.mumbleid) ); + else: + acl.admingroup['add'].remove( self.mumbleid ); + + bus.setACL( *acl.pack() ); return value; diff --git a/pyweb/settings.py b/pyweb/settings.py index 599c0f7..14ac170 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -6,7 +6,7 @@ ## The only setting you normally need to alter is this path. ## ## Set this to the path where you extracted mumble-django. ## ## ## -MUMBLE_DJANGO_ROOT = '/home/mistagee/mumble-django/hgrep'; ## +MUMBLE_DJANGO_ROOT = '/home/mistagee/mumble-django'; ## ## ## ## For a basic installation, this is all you need to edit in ## ## this file, the rest will be handled automatically! ##