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.

716 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 getPlayers(self, srvid):
  192. users = self._getIceServerObject(srvid).getPlayers()
  193. ret = {}
  194. for useridx in users:
  195. user = users[useridx]
  196. ret[ user.session ] = ObjectInfo(
  197. session = user.session,
  198. userid = user.playerid,
  199. mute = user.mute,
  200. deaf = user.deaf,
  201. suppress = user.suppressed,
  202. selfMute = user.selfMute,
  203. selfDeaf = user.selfDeaf,
  204. channel = user.channel,
  205. name = user.name,
  206. onlinesecs = user.onlinesecs,
  207. bytespersec = user.bytespersec
  208. )
  209. return ret
  210. @protectDjangoErrPage
  211. def getDefaultConf(self):
  212. return self.setUnicodeFlag(self.meta.getDefaultConf())
  213. @protectDjangoErrPage
  214. def getAllConf(self, srvid):
  215. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  216. info = {}
  217. for key in conf:
  218. if key == "playername":
  219. info['username'] = conf[key]
  220. else:
  221. info[str(key)] = conf[key]
  222. return info
  223. @protectDjangoErrPage
  224. def newServer(self):
  225. return self.meta.newServer().id()
  226. @protectDjangoErrPage
  227. def isBooted( self, srvid ):
  228. return bool( self._getIceServerObject(srvid).isRunning() )
  229. @protectDjangoErrPage
  230. def start( self, srvid ):
  231. self._getIceServerObject(srvid).start()
  232. @protectDjangoErrPage
  233. def stop( self, srvid ):
  234. self._getIceServerObject(srvid).stop()
  235. @protectDjangoErrPage
  236. def deleteServer( self, srvid ):
  237. if self._getIceServerObject(srvid).isRunning():
  238. self._getIceServerObject(srvid).stop()
  239. self._getIceServerObject(srvid).delete()
  240. @protectDjangoErrPage
  241. def setSuperUserPassword(self, srvid, value):
  242. self._getIceServerObject(srvid).setSuperuserPassword( value.encode( "UTF-8" ) )
  243. @protectDjangoErrPage
  244. def getConf(self, srvid, key):
  245. if key == "username":
  246. key = "playername"
  247. return self._getIceServerObject(srvid).getConf( key )
  248. @protectDjangoErrPage
  249. def setConf(self, srvid, key, value):
  250. if key == "username":
  251. key = "playername"
  252. if value is None:
  253. value = ''
  254. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  255. @protectDjangoErrPage
  256. def registerPlayer(self, srvid, name, email, password):
  257. mumbleid = self._getIceServerObject(srvid).registerPlayer( name.encode( "UTF-8" ) )
  258. self.setRegistration( srvid, mumbleid, name, email, password )
  259. return mumbleid
  260. @protectDjangoErrPage
  261. def unregisterPlayer(self, srvid, mumbleid):
  262. self._getIceServerObject(srvid).unregisterPlayer(mumbleid)
  263. @protectDjangoErrPage
  264. def getRegistration(self, srvid, mumbleid):
  265. user = self._getIceServerObject(srvid).getRegistration(mumbleid)
  266. return ObjectInfo(
  267. userid = mumbleid,
  268. name = user.name,
  269. email = user.email,
  270. pw = '',
  271. )
  272. @protectDjangoErrPage
  273. def setRegistration(self, srvid, mumbleid, name, email, password):
  274. import Murmur
  275. user = Murmur.RegisteredPlayer()
  276. user.playerid = mumbleid
  277. user.name = name.encode( "UTF-8" )
  278. user.email = email.encode( "UTF-8" )
  279. user.pw = password.encode( "UTF-8" )
  280. # update*r*egistration r is lowercase...
  281. return self._getIceServerObject(srvid).updateregistration(user)
  282. @protectDjangoErrPage
  283. def getACL(self, srvid, channelid):
  284. # need to convert acls to say "userid" instead of "playerid". meh.
  285. raw_acls, raw_groups, raw_inherit = self._getIceServerObject(srvid).getACL(channelid)
  286. acls = [ ObjectInfo(
  287. applyHere = rule.applyHere,
  288. applySubs = rule.applySubs,
  289. inherited = rule.inherited,
  290. userid = rule.playerid,
  291. group = rule.group,
  292. allow = rule.allow,
  293. deny = rule.deny,
  294. )
  295. for rule in raw_acls
  296. ]
  297. return acls, raw_groups, raw_inherit
  298. @protectDjangoErrPage
  299. def setACL(self, srvid, channelid, acls, groups, inherit):
  300. import Murmur
  301. ice_acls = []
  302. for rule in acls:
  303. ice_rule = Murmur.ACL()
  304. ice_rule.applyHere = rule.applyHere
  305. ice_rule.applySubs = rule.applySubs
  306. ice_rule.inherited = rule.inherited
  307. ice_rule.playerid = rule.userid
  308. ice_rule.group = rule.group
  309. ice_rule.allow = rule.allow
  310. ice_rule.deny = rule.deny
  311. ice_acls.append(ice_rule)
  312. return self._getIceServerObject(srvid).setACL( channelid, ice_acls, groups, inherit )
  313. @protectDjangoErrPage
  314. def getTexture(self, srvid, mumbleid):
  315. texture = self._getIceServerObject(srvid).getTexture(mumbleid)
  316. if len(texture) == 0:
  317. raise ValueError( "No Texture has been set." )
  318. # this returns a list of bytes.
  319. try:
  320. decompressed = decompress( texture )
  321. except error, err:
  322. raise ValueError( err )
  323. # iterate over 4 byte chunks of the string
  324. imgdata = ""
  325. for idx in range( 0, len(decompressed), 4 ):
  326. # read 4 bytes = BGRA and convert to RGBA
  327. # manual wrote getTexture returns "Textures are stored as zlib compress()ed 600x60 32-bit RGBA data."
  328. # http://mumble.sourceforge.net/slice/Murmur/Server.html#getTexture
  329. # but return values BGRA X(
  330. bgra = unpack( "4B", decompressed[idx:idx+4] )
  331. imgdata += pack( "4B", bgra[2], bgra[1], bgra[0], bgra[3] )
  332. # return an 600x60 RGBA image object created from the data
  333. return Image.fromstring( "RGBA", ( 600, 60 ), imgdata )
  334. @protectDjangoErrPage
  335. def setTexture(self, srvid, mumbleid, infile):
  336. # open image, convert to RGBA, and resize to 600x60
  337. img = infile.convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) )
  338. # iterate over the list and pack everything into a string
  339. bgrastring = ""
  340. for ent in list( img.getdata() ):
  341. # ent is in RGBA format, but Murmur wants BGRA (ARGB inverse), so stuff needs
  342. # to be reordered when passed to pack()
  343. bgrastring += pack( "4B", ent[2], ent[1], ent[0], ent[3] )
  344. # compress using zlib
  345. compressed = compress( bgrastring )
  346. # pack the original length in 4 byte big endian, and concat the compressed
  347. # data to it to emulate qCompress().
  348. texture = pack( ">L", len(bgrastring) ) + compressed
  349. # finally call murmur and set the texture
  350. self._getIceServerObject(srvid).setTexture(mumbleid, texture)
  351. @protectDjangoErrPage
  352. def verifyPassword(self, srvid, username, password):
  353. return self._getIceServerObject(srvid).verifyPassword(username, password)
  354. @staticmethod
  355. def setUnicodeFlag(data):
  356. ret = ''
  357. if isinstance(data, tuple) or isinstance(data, list) or isinstance(data, dict):
  358. ret = {}
  359. for key in data.keys():
  360. ret[MumbleCtlIce_118.setUnicodeFlag(key)] = MumbleCtlIce_118.setUnicodeFlag(data[key])
  361. else:
  362. ret = unicode(data, 'utf-8')
  363. return ret
  364. def getUptime(self, srvid):
  365. return None
  366. @protectDjangoErrPage
  367. def getBans( self, srvid ):
  368. return self._getIceServerObject(srvid).getBans()
  369. @protectDjangoErrPage
  370. def getLog( self, srvid, first=0, last=100 ):
  371. return self._getIceServerObject(srvid).getLog( first, last )
  372. @protectDjangoErrPage
  373. def addChannel( self, srvid, name, parentid ):
  374. return self._getIceServerObject(srvid).addChannel( name.encode( "UTF-8" ), parentid )
  375. @protectDjangoErrPage
  376. def removeChannel( self, srvid, channelid ):
  377. return self._getIceServerObject(srvid).removeChannel( channelid )
  378. @protectDjangoErrPage
  379. def renameChannel( self, srvid, channelid, name, description ):
  380. srv = self._getIceServerObject(srvid)
  381. state = srv.getChannelState(channelid)
  382. state.name = name.encode("UTF-8")
  383. srv.setChannelState(state)
  384. @protectDjangoErrPage
  385. def moveChannel(self, srvid, channelid, parentid):
  386. srv = self._getIceServerObject(srvid)
  387. state = srv.getChannelState(channelid)
  388. state.parent = parentid
  389. srv.setChannelState(state)
  390. @protectDjangoErrPage
  391. def moveUser(self, srvid, sessionid, channelid):
  392. srv = self._getIceServerObject(srvid)
  393. state = srv.getState(sessionid)
  394. state.channel = channelid
  395. srv.setState(state)
  396. @protectDjangoErrPage
  397. def muteUser(self, srvid, sessionid, mute=True):
  398. srv = self._getIceServerObject(srvid)
  399. state = srv.getState(sessionid)
  400. state.mute = mute
  401. srv.setState(state)
  402. @protectDjangoErrPage
  403. def deafenUser(self, srvid, sessionid, deaf=True):
  404. srv = self._getIceServerObject(srvid)
  405. state = srv.getState(sessionid)
  406. state.deaf = deaf
  407. srv.setState(state)
  408. @protectDjangoErrPage
  409. def kickUser(self, srvid, userid, reason=""):
  410. return self._getIceServerObject(srvid).kickPlayer( userid, reason.encode("UTF-8") )
  411. @protectDjangoErrPage
  412. def sendMessage(self, srvid, sessionid, message):
  413. return self._getIceServerObject(srvid).sendMessage( sessionid, message.encode( "UTF-8" ) )
  414. @protectDjangoErrPage
  415. def sendMessageChannel(self, srvid, channelid, tree, message):
  416. return self._getIceServerObject(srvid).sendMessageChannel( channelid, tree, message.encode( "UTF-8" ) )
  417. class MumbleCtlIce_120(MumbleCtlIce_118):
  418. @protectDjangoErrPage
  419. def getRegisteredPlayers(self, srvid, filter = ''):
  420. users = self._getIceServerObject( srvid ).getRegisteredUsers( filter.encode( "UTF-8" ) )
  421. ret = {}
  422. for id in users:
  423. ret[id] = ObjectInfo(
  424. userid = id,
  425. name = unicode( users[id], "utf8" ),
  426. email = '',
  427. pw = ''
  428. )
  429. return ret
  430. @protectDjangoErrPage
  431. def getPlayers(self, srvid):
  432. userdata = self._getIceServerObject(srvid).getUsers()
  433. for key in userdata:
  434. if isinstance( userdata[key], str ):
  435. userdata[key] = userdata[key].decode( "UTF-8" )
  436. return userdata
  437. @protectDjangoErrPage
  438. def getState(self, srvid, sessionid):
  439. userdata = self._getIceServerObject(srvid).getState(sessionid)
  440. for key in userdata.__dict__:
  441. attr = getattr( userdata, key )
  442. if isinstance( attr, str ):
  443. setattr( userdata, key, attr.decode( "UTF-8" ) )
  444. return userdata
  445. @protectDjangoErrPage
  446. def registerPlayer(self, srvid, name, email, password):
  447. # To get the real values of these ENUM entries, try
  448. # Murmur.UserInfo.UserX.value
  449. import Murmur
  450. user = {
  451. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  452. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  453. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  454. }
  455. return self._getIceServerObject(srvid).registerUser( user )
  456. @protectDjangoErrPage
  457. def unregisterPlayer(self, srvid, mumbleid):
  458. self._getIceServerObject(srvid).unregisterUser(mumbleid)
  459. @protectDjangoErrPage
  460. def getRegistration(self, srvid, mumbleid):
  461. reg = self._getIceServerObject( srvid ).getRegistration( mumbleid )
  462. user = ObjectInfo( userid=mumbleid, name="", email="", comment="", hash="", pw="" )
  463. import Murmur
  464. if Murmur.UserInfo.UserName in reg: user.name = reg[Murmur.UserInfo.UserName]
  465. if Murmur.UserInfo.UserEmail in reg: user.email = reg[Murmur.UserInfo.UserEmail]
  466. if Murmur.UserInfo.UserComment in reg: user.comment = reg[Murmur.UserInfo.UserComment]
  467. if Murmur.UserInfo.UserHash in reg: user.hash = reg[Murmur.UserInfo.UserHash]
  468. return user
  469. @protectDjangoErrPage
  470. def setRegistration(self, srvid, mumbleid, name, email, password):
  471. import Murmur
  472. user = {
  473. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  474. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  475. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  476. }
  477. return self._getIceServerObject( srvid ).updateRegistration( mumbleid, user )
  478. @protectDjangoErrPage
  479. def getAllConf(self, srvid):
  480. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  481. info = {}
  482. for key in conf:
  483. if key == "playername" and conf[key]:
  484. # Buggy database transition from 1.1.8 -> 1.2.0
  485. # Store username as "username" field and set playername field to empty
  486. info['username'] = conf[key]
  487. self.setConf( srvid, "playername", "" )
  488. self.setConf( srvid, "username", conf[key] )
  489. else:
  490. info[str(key)] = conf[key]
  491. return info
  492. @protectDjangoErrPage
  493. def getConf(self, srvid, key):
  494. return self._getIceServerObject(srvid).getConf( key )
  495. @protectDjangoErrPage
  496. def setConf(self, srvid, key, value):
  497. if value is None:
  498. value = ''
  499. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  500. @protectDjangoErrPage
  501. def getACL(self, srvid, channelid):
  502. return self._getIceServerObject(srvid).getACL(channelid)
  503. @protectDjangoErrPage
  504. def setACL(self, srvid, channelid, acls, groups, inherit):
  505. return self._getIceServerObject(srvid).setACL( channelid, acls, groups, inherit )
  506. @protectDjangoErrPage
  507. def getBans(self, srvid):
  508. return self._getIceServerObject(srvid).getBans()
  509. @protectDjangoErrPage
  510. def setBans(self, srvid, bans):
  511. return self._getIceServerObject(srvid).setBans(bans)
  512. @protectDjangoErrPage
  513. def addBanForSession(self, srvid, sessionid, **kwargs):
  514. session = self.getState(srvid, sessionid)
  515. if "bits" not in kwargs:
  516. kwargs["bits"] = 128
  517. if "start" not in kwargs:
  518. kwargs["start"] = int(time())
  519. if "duration" not in kwargs:
  520. kwargs["duration"] = 3600
  521. return self.addBan(srvid, address=session.address, **kwargs)
  522. @protectDjangoErrPage
  523. def addBan(self, srvid, **kwargs):
  524. for key in kwargs:
  525. if isinstance( kwargs[key], unicode ):
  526. kwargs[key] = kwargs[key].encode("UTF-8")
  527. from Murmur import Ban
  528. srvbans = self.getBans(srvid)
  529. srvbans.append( Ban( **kwargs ) )
  530. return self.setBans(srvid, srvbans)
  531. @protectDjangoErrPage
  532. def removeBan(self, srvid, **kwargs):
  533. return self.setBans(srvid, [
  534. # keep all bans which don't match exactly the one we're looking for
  535. ban for ban in self.getBans(srvid)
  536. # if one of those attr checks fails (-> False), min() is False -> keep the thing
  537. if not min([ getattr(ban, kw) == kwargs[kw] for kw in kwargs ])
  538. ])
  539. @protectDjangoErrPage
  540. def kickUser(self, srvid, userid, reason=""):
  541. return self._getIceServerObject(srvid).kickUser( userid, reason.encode("UTF-8") )
  542. @protectDjangoErrPage
  543. def renameChannel( self, srvid, channelid, name, description ):
  544. srv = self._getIceServerObject(srvid)
  545. state = srv.getChannelState(channelid)
  546. state.name = name.encode("UTF-8")
  547. state.description = description.encode("UTF-8")
  548. srv.setChannelState(state)
  549. @protectDjangoErrPage
  550. def getUptime(self, srvid):
  551. return None
  552. class MumbleCtlIce_122(MumbleCtlIce_120):
  553. @protectDjangoErrPage
  554. def getTexture(self, srvid, mumbleid):
  555. raise ValueError( "This method is buggy in 1.2.2, sorry dude." )
  556. @protectDjangoErrPage
  557. def setTexture(self, srvid, mumbleid, infile):
  558. buf = StringIO()
  559. infile.save( buf, "PNG" )
  560. buf.seek(0)
  561. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  562. @protectDjangoErrPage
  563. def getUptime(self, srvid):
  564. return self._getIceServerObject(srvid).getUptime()
  565. class MumbleCtlIce_123(MumbleCtlIce_120):
  566. @protectDjangoErrPage
  567. def getRawTexture(self, srvid, mumbleid):
  568. return self._getIceServerObject(srvid).getTexture(mumbleid)
  569. @protectDjangoErrPage
  570. def getTexture(self, srvid, mumbleid):
  571. texture = self.getRawTexture(srvid, mumbleid)
  572. if len(texture) == 0:
  573. raise ValueError( "No Texture has been set." )
  574. from StringIO import StringIO
  575. try:
  576. return Image.open( StringIO( texture ) )
  577. except IOError, err:
  578. raise ValueError( err )
  579. @protectDjangoErrPage
  580. def setTexture(self, srvid, mumbleid, infile):
  581. buf = StringIO()
  582. infile.save( buf, "PNG" )
  583. buf.seek(0)
  584. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  585. @protectDjangoErrPage
  586. def getUptime(self, srvid):
  587. return self._getIceServerObject(srvid).getUptime()