Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

720 lines
25 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009, withgod <withgod@sourceforge.net>
  5. * 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  6. *
  7. * Mumble-Django is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This package is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. """
  17. from time import time
  18. from functools import wraps
  19. from StringIO import StringIO
  20. from os.path import exists, join
  21. from os import unlink, name as os_name
  22. from PIL import Image
  23. from struct import pack, unpack
  24. from zlib import compress, decompress, error
  25. from mctl import MumbleCtlBase
  26. from utils import ObjectInfo
  27. import Ice, IcePy, tempfile
  28. def loadSlice( slicefile ):
  29. """ Load the slice file with the correct include dir set, if possible. """
  30. if hasattr( Ice, "getSliceDir" ):
  31. icepath = Ice.getSliceDir()
  32. else:
  33. icepath = None
  34. # Ice returns '' in getSliceDir() sometimes. (I kid you not.)
  35. if not icepath:
  36. try:
  37. from django.conf import settings
  38. except ImportError:
  39. # CTL is being used independently from MD
  40. icepath = None
  41. else:
  42. icepath = settings.SLICEDIR
  43. if not exists( join( icepath, "Ice", "SliceChecksumDict.ice" ) ):
  44. icepath = None
  45. if not icepath:
  46. # last resort when getSliceDir fails AND settings are wrong/unavailable, won't work for >=1.2.3
  47. Ice.loadSlice( slicefile )
  48. else:
  49. Ice.loadSlice( '', ['-I' + icepath, slicefile ] )
  50. def protectDjangoErrPage( func ):
  51. """ Catch and reraise Ice exceptions to prevent the Django page from failing.
  52. Since I need to "import Murmur", Django would try to read a murmur.py file
  53. which doesn't exist, and thereby produce an IndexError exception. This method
  54. erases the exception's traceback, preventing Django from trying to read any
  55. non-existant files and borking.
  56. """
  57. @wraps(func)
  58. def protection_wrapper( self, *args, **kwargs ):
  59. """ Call the original function and catch Ice exceptions. """
  60. try:
  61. return func( self, *args, **kwargs )
  62. except Ice.Exception, err:
  63. raise err
  64. protection_wrapper.innerfunc = func
  65. return protection_wrapper
  66. @protectDjangoErrPage
  67. def MumbleCtlIce( connstring, slicefile=None, icesecret=None ):
  68. """ Choose the correct Ice handler to use (1.1.8 or 1.2.x), and make sure the
  69. Murmur version matches the slice Version.
  70. Optional parameters are the path to the slice file and the Ice secret
  71. necessary to authenticate to Murmur.
  72. The path can be omitted only if running Murmur 1.2.3 or later, which
  73. exports a getSlice method to retrieve the Slice from.
  74. """
  75. prop = Ice.createProperties([])
  76. prop.setProperty("Ice.ImplicitContext", "Shared")
  77. prop.setProperty("Ice.MessageSizeMax", "65535")
  78. idd = Ice.InitializationData()
  79. idd.properties = prop
  80. ice = Ice.initialize(idd)
  81. if icesecret:
  82. ice.getImplicitContext().put( "secret", icesecret.encode("utf-8") )
  83. prx = ice.stringToProxy( connstring.encode("utf-8") )
  84. try:
  85. prx.ice_ping()
  86. except Ice.Exception:
  87. raise EnvironmentError( "Murmur does not appear to be listening on this address (Ice ping failed)." )
  88. try:
  89. import Murmur
  90. except ImportError:
  91. # Try loading the Slice from Murmur directly via its getSlice method.
  92. # See scripts/testdynamic.py in Mumble's Git repository.
  93. try:
  94. slice = IcePy.Operation( 'getSlice',
  95. Ice.OperationMode.Idempotent, Ice.OperationMode.Idempotent,
  96. True, (), (), (), IcePy._t_string, ()
  97. ).invoke(prx, ((), None))
  98. except (TypeError, Ice.OperationNotExistException):
  99. if not slicefile:
  100. raise EnvironmentError(
  101. "You didn't configure a slice file. Please set the SLICE variable in settings.py." )
  102. if not exists( slicefile ):
  103. raise EnvironmentError(
  104. "The slice file does not exist: '%s' - please check the settings." % slicefile )
  105. if " " in slicefile:
  106. raise EnvironmentError(
  107. "You have a space char in your Slice path. This will confuse Ice, please check." )
  108. if not slicefile.endswith( ".ice" ):
  109. raise EnvironmentError( "The slice file name MUST end with '.ice'." )
  110. try:
  111. loadSlice( slicefile )
  112. except RuntimeError:
  113. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  114. else:
  115. if os_name == "nt":
  116. # It weren't Windows if it didn't need to be treated differently. *sigh*
  117. temppath = join( tempfile.gettempdir(), "Murmur.ice" )
  118. slicetemp = open( temppath, "w+b" )
  119. try:
  120. slicetemp.write( slice )
  121. finally:
  122. slicetemp.close()
  123. try:
  124. loadSlice( temppath )
  125. except RuntimeError:
  126. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  127. finally:
  128. unlink(temppath)
  129. else:
  130. slicetemp = tempfile.NamedTemporaryFile( suffix='.ice' )
  131. try:
  132. slicetemp.write( slice )
  133. slicetemp.flush()
  134. loadSlice( slicetemp.name )
  135. except RuntimeError:
  136. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  137. finally:
  138. slicetemp.close()
  139. import Murmur
  140. meta = Murmur.MetaPrx.checkedCast(prx)
  141. murmurversion = meta.getVersion()[:3]
  142. if murmurversion == (1, 1, 8):
  143. return MumbleCtlIce_118( connstring, meta )
  144. elif murmurversion[:2] == (1, 2):
  145. if murmurversion[2] < 2:
  146. return MumbleCtlIce_120( connstring, meta )
  147. elif murmurversion[2] == 2:
  148. return MumbleCtlIce_122( connstring, meta )
  149. elif murmurversion[2] >= 3:
  150. return MumbleCtlIce_123( connstring, meta )
  151. raise NotImplementedError( "No ctl object available for Murmur version %d.%d.%d" % tuple(murmurversion) )
  152. class MumbleCtlIce_118(MumbleCtlBase):
  153. method = "ICE"
  154. def __init__( self, connstring, meta ):
  155. self.proxy = connstring
  156. self.meta = meta
  157. @protectDjangoErrPage
  158. def _getIceServerObject(self, srvid):
  159. return self.meta.getServer(srvid)
  160. @protectDjangoErrPage
  161. def getBootedServers(self):
  162. ret = []
  163. for x in self.meta.getBootedServers():
  164. ret.append(x.id())
  165. return ret
  166. @protectDjangoErrPage
  167. def getVersion( self ):
  168. return self.meta.getVersion()
  169. @protectDjangoErrPage
  170. def getAllServers(self):
  171. ret = []
  172. for x in self.meta.getAllServers():
  173. ret.append(x.id())
  174. return ret
  175. @protectDjangoErrPage
  176. def getRegisteredPlayers(self, srvid, filter = ''):
  177. users = self._getIceServerObject(srvid).getRegisteredPlayers( filter.encode( "UTF-8" ) )
  178. ret = {}
  179. for user in users:
  180. ret[user.playerid] = ObjectInfo(
  181. userid = int( user.playerid ),
  182. name = unicode( user.name, "utf8" ),
  183. email = unicode( user.email, "utf8" ),
  184. pw = unicode( user.pw, "utf8" )
  185. )
  186. return ret
  187. @protectDjangoErrPage
  188. def getChannels(self, srvid):
  189. return self._getIceServerObject(srvid).getChannels()
  190. @protectDjangoErrPage
  191. def getTree(self, srvid):
  192. return self._getIceServerObject(srvid).getTree()
  193. @protectDjangoErrPage
  194. def getPlayers(self, srvid):
  195. users = self._getIceServerObject(srvid).getPlayers()
  196. ret = {}
  197. for useridx in users:
  198. user = users[useridx]
  199. ret[ user.session ] = ObjectInfo(
  200. session = user.session,
  201. userid = user.playerid,
  202. mute = user.mute,
  203. deaf = user.deaf,
  204. suppress = user.suppressed,
  205. selfMute = user.selfMute,
  206. selfDeaf = user.selfDeaf,
  207. channel = user.channel,
  208. name = user.name,
  209. onlinesecs = user.onlinesecs,
  210. bytespersec = user.bytespersec
  211. )
  212. return ret
  213. @protectDjangoErrPage
  214. def getDefaultConf(self):
  215. return self.setUnicodeFlag(self.meta.getDefaultConf())
  216. @protectDjangoErrPage
  217. def getAllConf(self, srvid):
  218. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  219. info = {}
  220. for key in conf:
  221. if key == "playername":
  222. info['username'] = conf[key]
  223. else:
  224. info[str(key)] = conf[key]
  225. return info
  226. @protectDjangoErrPage
  227. def newServer(self):
  228. return self.meta.newServer().id()
  229. @protectDjangoErrPage
  230. def isBooted( self, srvid ):
  231. return bool( self._getIceServerObject(srvid).isRunning() )
  232. @protectDjangoErrPage
  233. def start( self, srvid ):
  234. self._getIceServerObject(srvid).start()
  235. @protectDjangoErrPage
  236. def stop( self, srvid ):
  237. self._getIceServerObject(srvid).stop()
  238. @protectDjangoErrPage
  239. def deleteServer( self, srvid ):
  240. if self._getIceServerObject(srvid).isRunning():
  241. self._getIceServerObject(srvid).stop()
  242. self._getIceServerObject(srvid).delete()
  243. @protectDjangoErrPage
  244. def setSuperUserPassword(self, srvid, value):
  245. self._getIceServerObject(srvid).setSuperuserPassword( value.encode( "UTF-8" ) )
  246. @protectDjangoErrPage
  247. def getConf(self, srvid, key):
  248. if key == "username":
  249. key = "playername"
  250. return self._getIceServerObject(srvid).getConf( key )
  251. @protectDjangoErrPage
  252. def setConf(self, srvid, key, value):
  253. if key == "username":
  254. key = "playername"
  255. if value is None:
  256. value = ''
  257. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  258. @protectDjangoErrPage
  259. def registerPlayer(self, srvid, name, email, password):
  260. mumbleid = self._getIceServerObject(srvid).registerPlayer( name.encode( "UTF-8" ) )
  261. self.setRegistration( srvid, mumbleid, name, email, password )
  262. return mumbleid
  263. @protectDjangoErrPage
  264. def unregisterPlayer(self, srvid, mumbleid):
  265. self._getIceServerObject(srvid).unregisterPlayer(mumbleid)
  266. @protectDjangoErrPage
  267. def getRegistration(self, srvid, mumbleid):
  268. user = self._getIceServerObject(srvid).getRegistration(mumbleid)
  269. return ObjectInfo(
  270. userid = mumbleid,
  271. name = user.name,
  272. email = user.email,
  273. pw = '',
  274. )
  275. @protectDjangoErrPage
  276. def setRegistration(self, srvid, mumbleid, name, email, password):
  277. import Murmur
  278. user = Murmur.RegisteredPlayer()
  279. user.playerid = mumbleid
  280. user.name = name.encode( "UTF-8" )
  281. user.email = email.encode( "UTF-8" )
  282. user.pw = password.encode( "UTF-8" )
  283. # update*r*egistration r is lowercase...
  284. return self._getIceServerObject(srvid).updateregistration(user)
  285. @protectDjangoErrPage
  286. def getACL(self, srvid, channelid):
  287. # need to convert acls to say "userid" instead of "playerid". meh.
  288. raw_acls, raw_groups, raw_inherit = self._getIceServerObject(srvid).getACL(channelid)
  289. acls = [ ObjectInfo(
  290. applyHere = rule.applyHere,
  291. applySubs = rule.applySubs,
  292. inherited = rule.inherited,
  293. userid = rule.playerid,
  294. group = rule.group,
  295. allow = rule.allow,
  296. deny = rule.deny,
  297. )
  298. for rule in raw_acls
  299. ]
  300. return acls, raw_groups, raw_inherit
  301. @protectDjangoErrPage
  302. def setACL(self, srvid, channelid, acls, groups, inherit):
  303. import Murmur
  304. ice_acls = []
  305. for rule in acls:
  306. ice_rule = Murmur.ACL()
  307. ice_rule.applyHere = rule.applyHere
  308. ice_rule.applySubs = rule.applySubs
  309. ice_rule.inherited = rule.inherited
  310. ice_rule.playerid = rule.userid
  311. ice_rule.group = rule.group
  312. ice_rule.allow = rule.allow
  313. ice_rule.deny = rule.deny
  314. ice_acls.append(ice_rule)
  315. return self._getIceServerObject(srvid).setACL( channelid, ice_acls, groups, inherit )
  316. @protectDjangoErrPage
  317. def getTexture(self, srvid, mumbleid):
  318. texture = self._getIceServerObject(srvid).getTexture(mumbleid)
  319. if len(texture) == 0:
  320. raise ValueError( "No Texture has been set." )
  321. # this returns a list of bytes.
  322. try:
  323. decompressed = decompress( texture )
  324. except error, err:
  325. raise ValueError( err )
  326. # iterate over 4 byte chunks of the string
  327. imgdata = ""
  328. for idx in range( 0, len(decompressed), 4 ):
  329. # read 4 bytes = BGRA and convert to RGBA
  330. # manual wrote getTexture returns "Textures are stored as zlib compress()ed 600x60 32-bit RGBA data."
  331. # http://mumble.sourceforge.net/slice/Murmur/Server.html#getTexture
  332. # but return values BGRA X(
  333. bgra = unpack( "4B", decompressed[idx:idx+4] )
  334. imgdata += pack( "4B", bgra[2], bgra[1], bgra[0], bgra[3] )
  335. # return an 600x60 RGBA image object created from the data
  336. return Image.fromstring( "RGBA", ( 600, 60 ), imgdata )
  337. @protectDjangoErrPage
  338. def setTexture(self, srvid, mumbleid, infile):
  339. # open image, convert to RGBA, and resize to 600x60
  340. img = infile.convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) )
  341. # iterate over the list and pack everything into a string
  342. bgrastring = ""
  343. for ent in list( img.getdata() ):
  344. # ent is in RGBA format, but Murmur wants BGRA (ARGB inverse), so stuff needs
  345. # to be reordered when passed to pack()
  346. bgrastring += pack( "4B", ent[2], ent[1], ent[0], ent[3] )
  347. # compress using zlib
  348. compressed = compress( bgrastring )
  349. # pack the original length in 4 byte big endian, and concat the compressed
  350. # data to it to emulate qCompress().
  351. texture = pack( ">L", len(bgrastring) ) + compressed
  352. # finally call murmur and set the texture
  353. self._getIceServerObject(srvid).setTexture(mumbleid, texture)
  354. @protectDjangoErrPage
  355. def verifyPassword(self, srvid, username, password):
  356. return self._getIceServerObject(srvid).verifyPassword(username, password)
  357. @staticmethod
  358. def setUnicodeFlag(data):
  359. ret = ''
  360. if isinstance(data, tuple) or isinstance(data, list) or isinstance(data, dict):
  361. ret = {}
  362. for key in data.keys():
  363. ret[MumbleCtlIce_118.setUnicodeFlag(key)] = MumbleCtlIce_118.setUnicodeFlag(data[key])
  364. else:
  365. ret = unicode(data, 'utf-8')
  366. return ret
  367. def getUptime(self, srvid):
  368. return None
  369. @protectDjangoErrPage
  370. def getBans( self, srvid ):
  371. return self._getIceServerObject(srvid).getBans()
  372. @protectDjangoErrPage
  373. def getLog( self, srvid, first=0, last=100 ):
  374. return self._getIceServerObject(srvid).getLog( first, last )
  375. @protectDjangoErrPage
  376. def addChannel( self, srvid, name, parentid ):
  377. return self._getIceServerObject(srvid).addChannel( name.encode( "UTF-8" ), parentid )
  378. @protectDjangoErrPage
  379. def removeChannel( self, srvid, channelid ):
  380. return self._getIceServerObject(srvid).removeChannel( channelid )
  381. @protectDjangoErrPage
  382. def renameChannel( self, srvid, channelid, name, description ):
  383. srv = self._getIceServerObject(srvid)
  384. state = srv.getChannelState(channelid)
  385. state.name = name.encode("UTF-8")
  386. srv.setChannelState(state)
  387. @protectDjangoErrPage
  388. def moveChannel(self, srvid, channelid, parentid):
  389. srv = self._getIceServerObject(srvid)
  390. state = srv.getChannelState(channelid)
  391. state.parent = parentid
  392. srv.setChannelState(state)
  393. @protectDjangoErrPage
  394. def moveUser(self, srvid, sessionid, channelid):
  395. srv = self._getIceServerObject(srvid)
  396. state = srv.getState(sessionid)
  397. state.channel = channelid
  398. srv.setState(state)
  399. @protectDjangoErrPage
  400. def muteUser(self, srvid, sessionid, mute=True):
  401. srv = self._getIceServerObject(srvid)
  402. state = srv.getState(sessionid)
  403. state.mute = mute
  404. srv.setState(state)
  405. @protectDjangoErrPage
  406. def deafenUser(self, srvid, sessionid, deaf=True):
  407. srv = self._getIceServerObject(srvid)
  408. state = srv.getState(sessionid)
  409. state.deaf = deaf
  410. srv.setState(state)
  411. @protectDjangoErrPage
  412. def kickUser(self, srvid, userid, reason=""):
  413. return self._getIceServerObject(srvid).kickPlayer( userid, reason.encode("UTF-8") )
  414. @protectDjangoErrPage
  415. def sendMessage(self, srvid, sessionid, message):
  416. return self._getIceServerObject(srvid).sendMessage( sessionid, message.encode( "UTF-8" ) )
  417. @protectDjangoErrPage
  418. def sendMessageChannel(self, srvid, channelid, tree, message):
  419. return self._getIceServerObject(srvid).sendMessageChannel( channelid, tree, message.encode( "UTF-8" ) )
  420. class MumbleCtlIce_120(MumbleCtlIce_118):
  421. @protectDjangoErrPage
  422. def getRegisteredPlayers(self, srvid, filter = ''):
  423. users = self._getIceServerObject( srvid ).getRegisteredUsers( filter.encode( "UTF-8" ) )
  424. ret = {}
  425. for id in users:
  426. ret[id] = ObjectInfo(
  427. userid = id,
  428. name = unicode( users[id], "utf8" ),
  429. email = '',
  430. pw = ''
  431. )
  432. return ret
  433. @protectDjangoErrPage
  434. def getPlayers(self, srvid):
  435. userdata = self._getIceServerObject(srvid).getUsers()
  436. for key in userdata:
  437. if isinstance( userdata[key], str ):
  438. userdata[key] = userdata[key].decode( "UTF-8" )
  439. return userdata
  440. @protectDjangoErrPage
  441. def getState(self, srvid, sessionid):
  442. userdata = self._getIceServerObject(srvid).getState(sessionid)
  443. for key in userdata.__dict__:
  444. attr = getattr( userdata, key )
  445. if isinstance( attr, str ):
  446. setattr( userdata, key, attr.decode( "UTF-8" ) )
  447. return userdata
  448. @protectDjangoErrPage
  449. def registerPlayer(self, srvid, name, email, password):
  450. # To get the real values of these ENUM entries, try
  451. # Murmur.UserInfo.UserX.value
  452. import Murmur
  453. user = {
  454. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  455. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  456. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  457. }
  458. return self._getIceServerObject(srvid).registerUser( user )
  459. @protectDjangoErrPage
  460. def unregisterPlayer(self, srvid, mumbleid):
  461. self._getIceServerObject(srvid).unregisterUser(mumbleid)
  462. @protectDjangoErrPage
  463. def getRegistration(self, srvid, mumbleid):
  464. reg = self._getIceServerObject( srvid ).getRegistration( mumbleid )
  465. user = ObjectInfo( userid=mumbleid, name="", email="", comment="", hash="", pw="" )
  466. import Murmur
  467. if Murmur.UserInfo.UserName in reg: user.name = reg[Murmur.UserInfo.UserName]
  468. if Murmur.UserInfo.UserEmail in reg: user.email = reg[Murmur.UserInfo.UserEmail]
  469. if Murmur.UserInfo.UserComment in reg: user.comment = reg[Murmur.UserInfo.UserComment]
  470. if Murmur.UserInfo.UserHash in reg: user.hash = reg[Murmur.UserInfo.UserHash]
  471. return user
  472. @protectDjangoErrPage
  473. def setRegistration(self, srvid, mumbleid, name, email, password):
  474. import Murmur
  475. user = {
  476. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  477. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  478. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  479. }
  480. return self._getIceServerObject( srvid ).updateRegistration( mumbleid, user )
  481. @protectDjangoErrPage
  482. def getAllConf(self, srvid):
  483. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  484. info = {}
  485. for key in conf:
  486. if key == "playername" and conf[key]:
  487. # Buggy database transition from 1.1.8 -> 1.2.0
  488. # Store username as "username" field and set playername field to empty
  489. info['username'] = conf[key]
  490. self.setConf( srvid, "playername", "" )
  491. self.setConf( srvid, "username", conf[key] )
  492. else:
  493. info[str(key)] = conf[key]
  494. return info
  495. @protectDjangoErrPage
  496. def getConf(self, srvid, key):
  497. return self._getIceServerObject(srvid).getConf( key )
  498. @protectDjangoErrPage
  499. def setConf(self, srvid, key, value):
  500. if value is None:
  501. value = ''
  502. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  503. @protectDjangoErrPage
  504. def getACL(self, srvid, channelid):
  505. return self._getIceServerObject(srvid).getACL(channelid)
  506. @protectDjangoErrPage
  507. def setACL(self, srvid, channelid, acls, groups, inherit):
  508. return self._getIceServerObject(srvid).setACL( channelid, acls, groups, inherit )
  509. @protectDjangoErrPage
  510. def getBans(self, srvid):
  511. return self._getIceServerObject(srvid).getBans()
  512. @protectDjangoErrPage
  513. def setBans(self, srvid, bans):
  514. return self._getIceServerObject(srvid).setBans(bans)
  515. @protectDjangoErrPage
  516. def addBanForSession(self, srvid, sessionid, **kwargs):
  517. session = self.getState(srvid, sessionid)
  518. if "bits" not in kwargs:
  519. kwargs["bits"] = 128
  520. if "start" not in kwargs:
  521. kwargs["start"] = int(time())
  522. if "duration" not in kwargs:
  523. kwargs["duration"] = 3600
  524. return self.addBan(srvid, address=session.address, **kwargs)
  525. @protectDjangoErrPage
  526. def addBan(self, srvid, **kwargs):
  527. for key in kwargs:
  528. if isinstance( kwargs[key], unicode ):
  529. kwargs[key] = kwargs[key].encode("UTF-8")
  530. from Murmur import Ban
  531. srvbans = self.getBans(srvid)
  532. srvbans.append( Ban( **kwargs ) )
  533. return self.setBans(srvid, srvbans)
  534. @protectDjangoErrPage
  535. def removeBan(self, srvid, **kwargs):
  536. return self.setBans(srvid, [
  537. # keep all bans which don't match exactly the one we're looking for
  538. ban for ban in self.getBans(srvid)
  539. # if one of those attr checks fails (-> False), min() is False -> keep the thing
  540. if not min([ getattr(ban, kw) == kwargs[kw] for kw in kwargs ])
  541. ])
  542. @protectDjangoErrPage
  543. def kickUser(self, srvid, userid, reason=""):
  544. return self._getIceServerObject(srvid).kickUser( userid, reason.encode("UTF-8") )
  545. @protectDjangoErrPage
  546. def renameChannel( self, srvid, channelid, name, description ):
  547. srv = self._getIceServerObject(srvid)
  548. state = srv.getChannelState(channelid)
  549. state.name = name.encode("UTF-8")
  550. state.description = description.encode("UTF-8")
  551. srv.setChannelState(state)
  552. @protectDjangoErrPage
  553. def getUptime(self, srvid):
  554. return None
  555. class MumbleCtlIce_122(MumbleCtlIce_120):
  556. @protectDjangoErrPage
  557. def getTexture(self, srvid, mumbleid):
  558. raise ValueError( "This method is buggy in 1.2.2, sorry dude." )
  559. @protectDjangoErrPage
  560. def setTexture(self, srvid, mumbleid, infile):
  561. buf = StringIO()
  562. infile.save( buf, "PNG" )
  563. buf.seek(0)
  564. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  565. @protectDjangoErrPage
  566. def getUptime(self, srvid):
  567. return self._getIceServerObject(srvid).getUptime()
  568. class MumbleCtlIce_123(MumbleCtlIce_120):
  569. @protectDjangoErrPage
  570. def getRawTexture(self, srvid, mumbleid):
  571. return self._getIceServerObject(srvid).getTexture(mumbleid)
  572. @protectDjangoErrPage
  573. def getTexture(self, srvid, mumbleid):
  574. texture = self.getRawTexture(srvid, mumbleid)
  575. if len(texture) == 0:
  576. raise ValueError( "No Texture has been set." )
  577. from StringIO import StringIO
  578. try:
  579. return Image.open( StringIO( texture ) )
  580. except IOError, err:
  581. raise ValueError( err )
  582. @protectDjangoErrPage
  583. def setTexture(self, srvid, mumbleid, infile):
  584. buf = StringIO()
  585. infile.save( buf, "PNG" )
  586. buf.seek(0)
  587. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  588. @protectDjangoErrPage
  589. def getUptime(self, srvid):
  590. return self._getIceServerObject(srvid).getUptime()