def auth_POST(server, request): try: input = getpostdata(request) userhost = input['userhost'] perm = input['perm'] except KeyError: rlog(0, request.host, 'auth: no port number or name provided') return dumps('no port userhost/permission provided') return dumps(users.allowed(userhost, perm))
def addrecord_POST(server, request): try: input = getpostdata(request) name = input['name'] except KeyError: rlog(5, host, 'addrecord .. no name provided') return dumps('no name provided') rlog(10, 'cloud', 'addrecord request for %s (%s)' % (name, request.ip)) try: if not users.exist(name): users.add(name, ["cloud@%s" % request.ip, ], ['CLOUD', ]) return dumps("%s added" % name) except Exception, ex: pass
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)
def addrecord_POST(server, request): try: input = getpostdata(request) name = input['name'] except KeyError: rlog(5, host, 'addrecord .. no name provided') return dumps('no name provided') rlog(10, 'cloud', 'addrecord request for %s (%s)' % (name, request.ip)) try: if not users.exist(name): users.add(name, [ "cloud@%s" % request.ip, ], [ 'CLOUD', ]) return dumps("%s added" % name) except Exception, ex: pass
def join_POST(server, request): try: (host, port) = request.client_address except: return dumps("can't determine host/port") try: input = getpostdata(request) port = input['port'] name = input['name'] except KeyError: rlog(0, host, 'join: no port number or name provided') return dumps('no port number/name provided') rlog(0, 'cloud', 'join request for %s %s' % (name, port)) #if cloud.byname(name): # rlog(10, host, '%s name already taken' % name) # return dumps('node name already taken') hp = "%s:%s" % (host, port) url = 'http://%s/' % hp cloud.addifping(name, url) cloud.addrecord(cfg.get('name'), url) return dumps('node added')
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)