Commit 410c1c6d authored by Leigh Stoller's avatar Leigh Stoller

Commit some chatroom support that has been hanging around in my devel

tree; still not functional yet. Needs a bit more work, someday.
parent cf971a28
...@@ -13,11 +13,11 @@ include $(OBJDIR)/Makeconf ...@@ -13,11 +13,11 @@ include $(OBJDIR)/Makeconf
SBIN_SCRIPTS = jabbersetup addjabberuser deljabberuser \ SBIN_SCRIPTS = jabbersetup addjabberuser deljabberuser \
modjabberbuddies addjabberchat deljabberchat \ modjabberbuddies addjabberchat deljabberchat \
setchatmembers setchatmembers chatsup.py
LIBEXEC_SCRIPTS = LIBEXEC_SCRIPTS =
CTRL_LIBEXEC_SCRIPTS = CTRL_LIBEXEC_SCRIPTS =
CTRL_LIB_FILES = CTRL_LIB_FILES =
CTRL_SBIN_SCRIPTS = jabberproxy CTRL_SBIN_SCRIPTS = jabberproxy mkchatroom.py
# #
# Force dependencies on the scripts so that they will be rerun through # Force dependencies on the scripts so that they will be rerun through
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group. # Copyright (c) 2005, 2006 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -29,8 +29,7 @@ my $TBOPS = "@TBOPSEMAIL@"; ...@@ -29,8 +29,7 @@ my $TBOPS = "@TBOPSEMAIL@";
my $CONTROL = "@USERNODE@"; my $CONTROL = "@USERNODE@";
my $BOSSNODE = "@BOSSNODE@"; my $BOSSNODE = "@BOSSNODE@";
my $CHATSUPPORT = @CHATSUPPORT@; my $CHATSUPPORT = @CHATSUPPORT@;
my $SSH = "$TB/bin/sshtb"; my $JABBERCHAT = "$TB/sbin/chatsup";
my $JABBERPROXY = "$TB/sbin/jabberproxy";
# #
# Untaint the path # Untaint the path
...@@ -164,15 +163,14 @@ if ($CONTROL ne $BOSSNODE) { ...@@ -164,15 +163,14 @@ if ($CONTROL ne $BOSSNODE) {
TBScriptLock("jabber_update") == 0 or TBScriptLock("jabber_update") == 0 or
fatal("Could not get the lock!"); fatal("Could not get the lock!");
system("echo '$leader $password' | ". system("$JABBERCHAT $chatroom create $password $leader");
"$SSH -host $CONTROL $JABBERPROXY $optarg addchat $chatroom");
my $status = $?; my $status = $?;
TBScriptUnlock(); TBScriptUnlock();
$? = $status; $? = $status;
if ($?) { if ($?) {
fatal("$JABBERPROXY failed on $CONTROL!"); fatal("$JABBERCHAT failed!");
} }
} }
exit(0); exit(0);
......
...@@ -29,7 +29,8 @@ if TBPATH not in sys.path: ...@@ -29,7 +29,8 @@ if TBPATH not in sys.path:
import xmpp import xmpp
# Debugging output. # Debugging output.
debug = 0 debug = False
verbose = False
# Error condition. # Error condition.
server_error = 0 server_error = 0
...@@ -98,7 +99,7 @@ try: ...@@ -98,7 +99,7 @@ try:
jabber_server = val jabber_server = val
pass pass
elif opt in ("-d", "--debug"): elif opt in ("-d", "--debug"):
debug = 1 debug = True
pass pass
pass pass
pass pass
...@@ -126,8 +127,10 @@ admin_jid = admin_user + "@" + jabber_server + "/" + admin_resource ...@@ -126,8 +127,10 @@ admin_jid = admin_user + "@" + jabber_server + "/" + admin_resource
# #
def HandlePresence(session, presence): def HandlePresence(session, presence):
global current_id, server_error global current_id, server_error
print str(presence) if verbose:
print str(presence)
pass
current_id = presence.getID() current_id = presence.getID()
if presence.getType() == 'error': if presence.getType() == 'error':
...@@ -140,7 +143,10 @@ def HandlePresence(session, presence): ...@@ -140,7 +143,10 @@ def HandlePresence(session, presence):
def HandleMessage(session, message): def HandleMessage(session, message):
global current_id, server_error global current_id, server_error
print str(message) if verbose:
print str(message)
pass
current_id = message.getID() current_id = message.getID()
if message.getType() == 'error': if message.getType() == 'error':
errmsg = message.getError() errmsg = message.getError()
...@@ -150,7 +156,11 @@ def HandleMessage(session, message): ...@@ -150,7 +156,11 @@ def HandleMessage(session, message):
def HandleIQ(conn, iq_node): def HandleIQ(conn, iq_node):
global current_id, desired_id global current_id, desired_id
print str(iq_node)
if verbose:
print str(iq_node)
pass
current_id = iq_node.getID() current_id = iq_node.getID()
if current_id == desired_id: if current_id == desired_id:
raise xmpp.protocol.NodeProcessed raise xmpp.protocol.NodeProcessed
...@@ -158,10 +168,14 @@ def HandleIQ(conn, iq_node): ...@@ -158,10 +168,14 @@ def HandleIQ(conn, iq_node):
def HandleIQ_Error(conn, iq_node): def HandleIQ_Error(conn, iq_node):
global current_id, server_error global current_id, server_error
if verbose:
print str(iq_node)
pass
errmsg = iq_node.getError() errmsg = iq_node.getError()
current_id = iq_node.getID() current_id = iq_node.getID()
server_error = 1 server_error = 1
print str(iq_node)
raise xmpp.protocol.NodeProcessed raise xmpp.protocol.NodeProcessed
pass pass
...@@ -170,7 +184,12 @@ def HandleIQ_Error(conn, iq_node): ...@@ -170,7 +184,12 @@ def HandleIQ_Error(conn, iq_node):
# #
def Connect(): def Connect():
jid = xmpp.protocol.JID(admin_jid) jid = xmpp.protocol.JID(admin_jid)
cl = xmpp.Client(jid.getDomain(), debug=['always',]) dbg = []
if debug:
dbg = ['always',]
pass
cl = xmpp.Client(jid.getDomain(), debug=dbg)
cl.connect() cl.connect()
cl.auth(jid.getNode(), admin_password, resource=admin_resource) cl.auth(jid.getNode(), admin_password, resource=admin_resource)
cl.sendInitPresence(requestRoster=0) cl.sendInitPresence(requestRoster=0)
...@@ -296,12 +315,13 @@ def DoChatRoom(client, args): ...@@ -296,12 +315,13 @@ def DoChatRoom(client, args):
# #
# Otherwise creating a room. Must have a password. # Otherwise creating a room. Must have a password.
# #
if len(args) != 2: if len(args) != 3:
usage() usage()
sys.exit(2) sys.exit(2)
pass pass
password = args[1] password = args[1]
leader = args[2]
# Announce presence, which creates room. # Announce presence, which creates room.
p = xmpp.Presence(to = chatroom_jid) p = xmpp.Presence(to = chatroom_jid)
...@@ -361,9 +381,10 @@ def DoChatRoom(client, args): ...@@ -361,9 +381,10 @@ def DoChatRoom(client, args):
print "Chatroom " + chatroom + " did not not properly configure." print "Chatroom " + chatroom + " did not not properly configure."
return -1 return -1
client.Process(timeout=2) client.Process(timeout=1)
return 0 # Now set the admin for the room.
return DoMemberShip(client, [leader, "admin"])
# #
# Add/Remove members from a room # Add/Remove members from a room
...@@ -399,6 +420,9 @@ def DoMemberShip(client, args): ...@@ -399,6 +420,9 @@ def DoMemberShip(client, args):
elif op == "owner": elif op == "owner":
item.setAttr('affiliation', 'owner') item.setAttr('affiliation', 'owner')
pass pass
elif op == "admin":
item.setAttr('affiliation', 'admin')
pass
else: else:
item.setAttr('affiliation', 'none') item.setAttr('affiliation', 'none')
pass pass
......
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group. # Copyright (c) 2005, 2006 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
use English; use English;
...@@ -30,7 +30,7 @@ my $CONTROL = "@USERNODE@"; ...@@ -30,7 +30,7 @@ my $CONTROL = "@USERNODE@";
my $BOSSNODE = "@BOSSNODE@"; my $BOSSNODE = "@BOSSNODE@";
my $CHATSUPPORT = @CHATSUPPORT@; my $CHATSUPPORT = @CHATSUPPORT@;
my $SSH = "$TB/bin/sshtb"; my $SSH = "$TB/bin/sshtb";
my $JABBERPROXY = "$TB/sbin/jabberproxy"; my $JABBERCHAT = "$TB/sbin/chatsup";
# #
# Untaint the path # Untaint the path
...@@ -139,7 +139,7 @@ if ($CONTROL ne $BOSSNODE) { ...@@ -139,7 +139,7 @@ if ($CONTROL ne $BOSSNODE) {
TBScriptLock("jabber_update") == 0 or TBScriptLock("jabber_update") == 0 or
fatal("Could not get the lock!"); fatal("Could not get the lock!");
system("$SSH -host $CONTROL $JABBERPROXY $optarg delchat $chatroom"); system("$JABBERCHAT $chatroom destroy");
my $status = $?; my $status = $?;
TBScriptUnlock(); TBScriptUnlock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment