Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created January 8, 2012 17:10
Show Gist options
  • Select an option

  • Save cowboy/1579024 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy/1579024 to your computer and use it in GitHub Desktop.
Python / Mumble: My tweaks to http://0xy.org/http_cvp.py
#!/usr/bin/env python
# -*- coding: utf-8
#
# Copyright (C) 2012 Benjamin Jemlich <pcgod@users.sourceforge.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urlparse
import json
import BaseHTTPServer
# Settings
prxstr = "Meta:tcp -h 127.0.0.1 -p 6502"
serverid = 1
listen_ip = '0.0.0.0'
listen_port = 27800 # 64745
slicefile = "Murmur.ice"
def loadUser(u):
user = {}
user['session'] = u.session
user['userid'] = u.userid
user['mute'] = u.mute
user['deaf'] = u.deaf
user['suppress'] = u.suppress
user['selfMute'] = u.selfMute
user['selfDeaf'] = u.selfDeaf
user['channel'] = u.channel
user['name'] = u.name
user['onlinesecs'] = u.onlinesecs
user['idlesecs'] = u.idlesecs
user['os'] = u.os
user['release'] = u.release
user['bytespersec'] = u.bytespersec
return user
def loadChannel(c):
channel = {}
channel['id'] = c.c.id
channel['name'] = c.c.name
channel['parent'] = c.c.parent
channel['links'] = []
channel['position'] = c.c.position
channel['channels'] = [loadChannel(child) for child in c.children]
channel['users'] = [loadUser(u) for u in c.users]
return channel
import Ice
Ice.loadSlice("", ["-I" + Ice.getSliceDir(), "--checksum", slicefile])
import Murmur
ice = Ice.initialize()
prx = ice.stringToProxy(prxstr)
m = Murmur.MetaPrx.checkedCast(prx)
s = m.getServer(serverid)
class CvpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
parts = urlparse.urlparse(self.path)
if parts.path != "/":
self.send_error(404)
return
tree = s.getTree()
version = m.getVersion()
conf = {}
conf.update(m.getDefaultConf())
conf.update(s.getAllConf())
if not 'registername' in conf:
conf['registername'] = 'Root'
server = {}
server['name'] = conf["registername"]
server['id'] = serverid
server['x_uptime'] = s.getUptime()
server['root'] = loadChannel(tree)
data = json.dumps(server)
query = urlparse.parse_qs(parts.query)
if "callback" in query:
data = "%s(%s);" % (query["callback"][0], data)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", len(data))
self.send_header("Connection", "close")
self.end_headers()
self.wfile.write(data)
server = BaseHTTPServer.HTTPServer((listen_ip, listen_port), CvpHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment