94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
import sys
|
|
import Ice
|
|
import MumbleServer
|
|
import re
|
|
|
|
HOST = "172.16.10.3" # VM IP
|
|
INTERNAL = "172.19.0.2" # container IP
|
|
|
|
def fix_proxy(prx, communicator):
|
|
s = communicator.proxyToString(prx)
|
|
# Match any IP address pattern after "-h " and replace it
|
|
s = re.sub(r'-h (\d{1,3}\.){3}\d{1,3}', f'-h {HOST}', s)
|
|
return communicator.stringToProxy(s)
|
|
|
|
def main():
|
|
with Ice.initialize(sys.argv) as communicator:
|
|
base = communicator.stringToProxy(f"Meta:tcp -h {HOST} -p 6502 -t 60000")
|
|
meta = MumbleServer.MetaPrx.checkedCast(base)
|
|
|
|
assert meta is not None
|
|
|
|
context = {"secret": "password"}
|
|
|
|
# We just assume the server we want to modify has ID 1
|
|
server = meta.getServer(1, context)
|
|
print("Server:", server)
|
|
|
|
server = MumbleServer.ServerPrx.uncheckedCast(fix_proxy(server, communicator))
|
|
print("Running:", server)
|
|
assert server is not None
|
|
users = server.getUsers(context)
|
|
|
|
# Python 3 uses .items(), not .iteritems()
|
|
for session_id, user in users.items():
|
|
print(session_id, user.name)
|
|
|
|
# Not providing the context with the correct password would make this
|
|
# request fail with an InvalidSecretException
|
|
server.setSuperuserPassword("Strong password", context)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
|
|
|
|
# import Ice
|
|
# import MumbleServer
|
|
|
|
# HOST = "172.16.10.123" # external VM IP
|
|
# PORT = 6502
|
|
# ICE_SECRET = "password"
|
|
# SERVER_ID = 1
|
|
# INTERNAL = "172.19.0.2" # container IP to replace
|
|
|
|
# props = Ice.createProperties()
|
|
# props.setProperty("Ice.ImplicitContext", "Shared")
|
|
|
|
# init = Ice.InitializationData()
|
|
# init.properties = props
|
|
|
|
# def fix_proxy(prx, communicator):
|
|
# """Replace internal container IP with external VM IP in proxy string."""
|
|
# s = communicator.proxyToString(prx)
|
|
# s = s.replace(INTERNAL, HOST)
|
|
# return communicator.stringToProxy(s)
|
|
|
|
# with Ice.initialize(initData=init) as communicator:
|
|
# communicator.getImplicitContext().put("secret", ICE_SECRET)
|
|
|
|
# proxy = communicator.stringToProxy(f"Meta:tcp -h {HOST} -p {PORT} -t 10000")
|
|
# meta = MumbleServer.MetaPrx.uncheckedCast(proxy)
|
|
|
|
# try:
|
|
# version = meta.getVersion()
|
|
# print("Connected! Version:", version)
|
|
|
|
# # Fix the server proxy endpoint before using it
|
|
# raw_server = meta.getServer(SERVER_ID)
|
|
# fixed = fix_proxy(raw_server, communicator)
|
|
# server = MumbleServer.ServerPrx.uncheckedCast(fixed)
|
|
|
|
# print("Running:", server.isRunning())
|
|
|
|
# for cid, ch in server.getChannels().items():
|
|
# print(f" [{cid}] {ch.name}")
|
|
|
|
# users = server.getUsers()
|
|
# print("Online users:", len(users))
|
|
# for sid, u in users.items():
|
|
# print(f" [{sid}] {u.name}")
|
|
|
|
# except Exception as e:
|
|
# print("Error:", type(e).__name__, e) |