示例#1
0
def handle_dispatch(event):
    """ dispatch web request """
    input = unquote_plus(event.path)
    bot = fleet.getfirstbot()
    ievent = Ircevent()
    try:
        what = input.split('?', 1)[1]
    except IndexError:
        return ["dispatch what ?", ]
    if what.startswith("command="):
        what = what[8:]
    ievent.txt = what
    ievent.nick = 'web'
    ievent.userhost = 'web@web'
    ievent.channel = 'web'
    q = Queue.Queue()
    ievent.queues.append(q)
    ievent.speed = 3
    ievent.bot = bot
    result = []
    if plugins.woulddispatch(bot, ievent):
        start_new_thread(plugins.trydispatch, (bot, ievent))
    else:
        return ["can't dispatch %s" % what, ]
    result = waitforqueue(q, 60)
    if not result:
        return ["can't dispatch %s" % what, ]
    return result
示例#2
0
def handle_dispatch(event):
    """ dispatch web request """
    input = unquote_plus(event.path)
    bot = fleet.getfirstbot()
    ievent = Ircevent()
    try:
        what = input.split('?', 1)[1]
    except IndexError:
        return [
            "dispatch what ?",
        ]
    if what.startswith("command="):
        what = what[8:]
    ievent.txt = what
    ievent.nick = 'web'
    ievent.userhost = 'web@web'
    ievent.channel = 'web'
    q = Queue.Queue()
    ievent.queues.append(q)
    ievent.speed = 3
    ievent.bot = bot
    result = []
    if plugins.woulddispatch(bot, ievent):
        start_new_thread(plugins.trydispatch, (bot, ievent))
    else:
        return [
            "can't dispatch %s" % what,
        ]
    result = waitforqueue(q, 60)
    if not result:
        return [
            "can't dispatch %s" % what,
        ]
    return result
示例#3
0
def handle_json(event):
    """ dispatch web request .. return json """
    input = unquote_plus(event.path)
    bot = fleet.getfirstbot()
    ievent = Ircevent()
    try:
        what = input.split('?', 1)[1]
    except IndexError:
        return ["dispatch what ?", ]
    if what.startswith("command="):
        what = what[8:]
    ievent.txt = what
    ievent.nick = 'web'
    ievent.userhost = 'web@web'
    ievent.channel = 'web'
    q = Queue.Queue()
    ievent.queues.append(q)
    ievent.speed = 3
    ievent.bot = bot
    result = []
    if plugins.woulddispatch(bot, ievent):
        start_new_thread(plugins.trydispatch, (bot, ievent))
    else:
        return ["can't dispatch %s" % ievent.txt, ]
    result = waitforqueue(q, 3)
    rlog(10, 'json', str(result))
    try:
        res = dumps(result)
    except Exception, ex:
        handle_exception()
        res = []
示例#4
0
def dispatch_POST(server, request):
    """ dispatch request into the cloud """
    try:
        (host, port) = request.client_address
    except:
        return [
            "can't determine host/port",
        ]
    try:
        input = getpostdata(request)
        cmnd = input['cmnd']
    except KeyError:
        return dumps([
            'need cmnd value',
        ])
    try:
        channel = input['channel']
    except KeyError:
        channel = "#cloud"
    if not channel:
        channel = '#cloud'
    bot = fleet.getfirstbot()
    ievent = Ircevent()
    ievent.txt = cmnd
    ievent.nick = 'cloud'
    ievent.userhost = "cloud@%s" % host
    ievent.channel = channel
    q = Queue.Queue()
    ievent.queues.append(q)
    ievent.speed = 3
    ievent.bot = bot
    result = []
    if plugins.woulddispatch(bot, ievent):
        start_new_thread(plugins.trydispatch, (bot, ievent))
    else:
        return dumps([
            "can't dispatch %s" % cmnd,
        ])
    result = waitforqueue(q, 10)
    if not result:
        return dumps([
            "no result",
        ])
    res = []
    for item in result:
        res.append(str(item))
    return dumps(res)
示例#5
0
def dispatch_POST(server, request):
    """ dispatch request into the cloud """
    try:
        (host, port) = request.client_address
    except:
        return ["can't determine host/port", ]
    try:
        input = getpostdata(request)
        cmnd = input['cmnd']
    except KeyError:
        return dumps(['need cmnd value', ])
    try:
        channel = input['channel']
    except KeyError:
        channel = "#cloud"
    if not channel:
        channel = '#cloud'
    bot = fleet.getfirstbot()
    ievent = Ircevent()
    ievent.txt = cmnd  
    ievent.nick = 'cloud'
    ievent.userhost = "cloud@%s" % host
    ievent.channel = channel
    q = Queue.Queue()
    ievent.queues.append(q)
    ievent.speed = 3
    ievent.bot = bot
    result = []
    if plugins.woulddispatch(bot, ievent):
        start_new_thread(plugins.trydispatch, (bot, ievent))
    else:
        return dumps(["can't dispatch %s" % cmnd, ])
    result = waitforqueue(q, 10)
    if not result:
        return dumps(["no result", ])
    res = []
    for item in result:
        res.append(str(item))
    return dumps(res)