1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#!/usr/bin/env python
# -*- coding: utf-8
import Ice, sys, sha
from M2Crypto import X509;
Ice.loadSlice('', ['-I' + Ice.getSliceDir(), 'Murmur.ice'])
import Murmur
class MetaCallbackI(Murmur.MetaCallback):
def started(self, s, current=None):
print "started"
serverR=Murmur.ServerCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerCallbackI(server, current.adapter)))
s.addCallback(serverR)
def stopped(self, s, current=None):
print "stopped"
class ServerCallbackI(Murmur.ServerCallback):
def __init__(self, server, adapter):
self.server = server
self.contextR=Murmur.ServerContextCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerContextCallbackI(server)))
def userConnected(self, p, current=None):
print "connected"
print p
self.server.addContextCallback(p.session, "flubber", "Power up the T", self.contextR, Murmur.ContextChannel | Murmur.ContextUser)
if (self.server.hasPermission(p.session, 0, Murmur.PermissionWrite)):
print "Is a global admin"
certlist=self.server.getCertificateList(p.session)
for cert in certlist:
hash = sha.new()
hash.update(cert)
cert = X509.load_cert_der_string(cert)
print cert.get_subject(), "issued by", cert.get_issuer(), "hash", hash.hexdigest()
if current:
print current.ctx
def userDisconnected(self, p, current=None):
print "disconnected"
print p
def userStateChanged(self, p, current=None):
print "stateChanged"
print self.server
print p
def channelCreated(self, c, current=None):
print "created"
print c
def channelRemoved(self, c, current=None):
print "removed"
print c
def channelStateChanged(self, c, current=None):
print "stateChanged"
print c
class ServerContextCallbackI(Murmur.ServerContextCallback):
def __init__(self, server):
self.server = server
def contextAction(self, action, p, session, chanid, current=None):
print "aaand ACTION"
print action
print p
print session
print chanid
if (session != 0):
server.sendMessage(session, "Bouncy")
elif (chanid >= 0):
server.sendMessageChannel(chanid, 0, "Channel Bouncy")
if __name__ == "__main__":
global contextR
prop = Ice.createProperties(sys.argv)
prop.setProperty("Ice.ImplicitContext", "Shared")
idd = Ice.InitializationData()
idd.properties = prop
ice = Ice.initialize(idd)
print "Creating callbacks...",
# If icesecret is set, we need to set it here as well.
ice.getImplicitContext().put("secret", "fourtytwo")
meta = Murmur.MetaPrx.checkedCast(ice.stringToProxy('Meta:tcp -h 127.0.0.1 -p 6502'))
adapter = ice.createObjectAdapterWithEndpoints("Callback.Client", "tcp -h 127.0.0.1")
metaR=Murmur.MetaCallbackPrx.uncheckedCast(adapter.addWithUUID(MetaCallbackI()))
adapter.activate()
meta.addCallback(metaR)
for server in meta.getBootedServers():
serverR=Murmur.ServerCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerCallbackI(server, adapter)))
server.addCallback(serverR)
print "Done"
print 'Script running (press CTRL-C to abort)';
try:
ice.waitForShutdown()
except KeyboardInterrupt:
print 'CTRL-C caught, aborting'
meta.removeCallback(metaR)
ice.shutdown()
print "Goodbye"
|