Example #1
0
 def handlerawmsg(self, msg):
     ''' Helper to invoke handlemsg() using raw (packed) message bytes.
     '''
     hdr = msg[:coreapi.CoreMessage.hdrsiz]
     msgtype, flags, msglen = coreapi.CoreMessage.unpackhdr(hdr)
     msgcls = coreapi.msg_class(msgtype)
     return self.handlemsg(msgcls(flags, hdr, msg[coreapi.CoreMessage.hdrsiz:]))
Example #2
0
 def handlerawmsg(self, msg):
     ''' Helper to invoke handlemsg() using raw (packed) message bytes.
     '''
     hdr = msg[:coreapi.CoreMessage.hdrsiz]
     msgtype, flags, msglen = coreapi.CoreMessage.unpackhdr(hdr)
     msgcls = coreapi.msg_class(msgtype)
     return self.handlemsg(msgcls(flags, hdr, msg[coreapi.CoreMessage.hdrsiz:]))
Example #3
0
    def fixupremotetty(msghdr, msgdata, host):
        ''' When an interactive TTY request comes from the GUI, snoop the reply
            and add an SSH command to the appropriate remote server.
        '''
        msgtype, msgflags, msglen = coreapi.CoreMessage.unpackhdr(msghdr)
        msgcls = coreapi.msg_class(msgtype)
        msg = msgcls(msgflags, msghdr, msgdata)

        nodenum = msg.gettlv(coreapi.CORE_TLV_EXEC_NODE)
        execnum = msg.gettlv(coreapi.CORE_TLV_EXEC_NUM)
        cmd = msg.gettlv(coreapi.CORE_TLV_EXEC_CMD)
        res = msg.gettlv(coreapi.CORE_TLV_EXEC_RESULT)

        tlvdata = b""
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_NODE, nodenum)
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_NUM, execnum)
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_CMD, cmd)
        title = "\\\"CORE: n%s @ %s\\\"" % (nodenum, host)
        res = "ssh -X -f " + host + " xterm -e " + res
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_RESULT, res)

        return coreapi.CoreExecMessage.pack(msgflags, tlvdata)
Example #4
0
    def fixupremotetty(msghdr, msgdata, host):
        ''' When an interactive TTY request comes from the GUI, snoop the reply
            and add an SSH command to the appropriate remote server.
        '''
        msgtype, msgflags, msglen = coreapi.CoreMessage.unpackhdr(msghdr)
        msgcls = coreapi.msg_class(msgtype)
        msg = msgcls(msgflags, msghdr, msgdata)

        nodenum = msg.gettlv(coreapi.CORE_TLV_EXEC_NODE)
        execnum = msg.gettlv(coreapi.CORE_TLV_EXEC_NUM)
        cmd = msg.gettlv(coreapi.CORE_TLV_EXEC_CMD)
        res = msg.gettlv(coreapi.CORE_TLV_EXEC_RESULT)

        tlvdata = ""
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_NODE, nodenum)
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_NUM, execnum)
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_CMD, cmd)
        title = "\\\"CORE: n%s @ %s\\\"" % (nodenum, host)
        res = "ssh -X -f " + host + " xterm -e " + res
        tlvdata += coreapi.CoreExecTlv.pack(coreapi.CORE_TLV_EXEC_RESULT, res)

        return coreapi.CoreExecMessage.pack(msgflags, tlvdata)
Example #5
0
 def decode_message(self, data):
     ''' Retrieve a message from a socket and return the CoreMessage object or
             None upon disconnect. Socket data beyond the first message is dropped.
     '''
     msghdr = data[:coreapi.CoreMessage.hdrsiz]
     if len(msghdr) == 0:
         return None
     msgdata = None
     msgtype, msgflags, msglen = coreapi.CoreMessage.unpackhdr(msghdr)
     if msglen:
         msgdata = data[coreapi.CoreMessage.hdrsiz:]
     try:
         msgcls = coreapi.msg_class(msgtype)
     except KeyError:
         msg = coreapi.CoreMessage(msgflags, msghdr, msgdata)
         msg.msgtype = msgtype
         print("unimplemented CORE message type: %s" % msg.typestr())
         return msg
     if len(data) > msglen + coreapi.CoreMessage.hdrsiz:
         print("received a message of type %d, dropping %d bytes of extra data" \
                     % (msgtype, len(data) - (msglen + coreapi.CoreMessage.hdrsiz)))
     return msgcls(msgflags, msghdr, msgdata)
Example #6
0
def to_msg(raw_msg):
    hdr = raw_msg[:coreapi.CoreMessage.hdrsiz]
    msgtype, flags, msglen = coreapi.CoreMessage.unpackhdr(hdr)
    msgcls = coreapi.msg_class(msgtype)
    return msgcls(flags, hdr, raw_msg[coreapi.CoreMessage.hdrsiz:])