def post(self): if not self.server: logging.error("Server '%s' not found" % (self.hostname, )) self.error(403) self.response.out.write("Invalid hostname") return if not self.check_hash(self.request.body): logging.error("Request hash does not match") self.error(403) self.response.out.write("Request hash does not match") return version = self.request.GET.get("version", 0) reader = csv.reader(self.request.body_file) if version >= 1: for id, user, host, level, ts, sender, rcpt, length, msg in reader: if user == "": user = None mapping = model.Mapping.get_by_address(user, host) if not mapping: logging.error("Unable to find mapping for '%s@%s'" % (user, host)) continue level = int(level) model.LogEntry(key_name="_" + id, mapping=mapping, server=self.server, ts=datetime.datetime.utcfromtimestamp( float(ts)), sender=sender, recipient=rcpt, length=int(length), message=msg, is_warning=level >= logging.WARNING, is_error=level >= logging.ERROR).put() else: for id, key, level, ts, sender, rcpt, length, msg in reader: if "@" in key: user, host = key.split("@", 1) else: user = None host = key mapping = model.Mapping.get_by_address(user, host) if not mapping: logging.error("Unable to find mapping for '%s@%s'" % (user, host)) continue level = int(level) model.LogEntry(key_name="_" + id, mapping=mapping, server=self.server, ts=datetime.datetime.utcfromtimestamp( float(ts)), sender=sender, recipient=rcpt, length=int(length), message=msg, is_warning=level >= logging.WARNING, is_error=level >= logging.ERROR).put()
def post(self): state = get_state() if state['user'] is not None: return logging.info("registering user") urop = model.User() cv = self.request.POST.get('cv') logging.info("filename is %s" % cv) urop.name = self.request.get('name') urop.email = self.request.get('email') urop.user_id = users.get_current_user().user_id() urop.statement = self.request.get('statement') urop.kind = 'UROP' urop.put() if (cv is not None) and hasattr(cv, 'filename'): urop.cv = save_cv(urop, cv) urop.put() json_reply(self) d = dict(status='ok') d['urop'] = user_to_dict(urop) self.response.write(to_json(d)) entry = model.LogEntry() entry.patient = urop.key entry.action = 'UROP created' entry.put()
def delete(self, host_id, urop_id): urop = model.User.for_user_id(urop_id) urop.host = None urop.put() entry = model.LogEntry() host = model.User.for_user_id(host_id) entry.agent = host.key entry.patient = urop.key entry.action = 'UROP disclaimed' entry.put()
def post(self): state = get_state() if state['user'] is not None: return host = model.User() data = json.loads(self.request.body) host.name = data['name'] host.email = data['email'] host.research = data['research'] host.user_id = users.get_current_user().user_id() host.approved = False host.kind = 'Host' host.put() json_reply(self) d = dict(status='ok') d['host'] = user_to_dict(host) self.response.write(to_json(d)) entry = model.LogEntry() entry.patient = host.key entry.action = 'Host created' entry.put()
def post(self, host_id, urop_id): json_reply(self) if host_id != "current": d = dict(status='not ok') self.response.write(to_json(d)) return host = get_state()['user'] if not host.approved: d = dict(status='host not approved') self.response.write(to_json(d)) return urop = model.User.for_user_id(urop_id) urop.host = host.key urop.put() d = dict(status='ok') self.response.write(to_json(d)) entry = model.LogEntry() entry.agent = host.key entry.patient = urop.key entry.action = 'UROP claimed' entry.put()
def put(self, host_id): payload = json.loads(self.request.body) logging.info(payload) user = get_state()['user'] host = model.User.for_user_id(host_id) d = dict() if (host is None) or (host.kind != 'Host'): d['status'] = 'invalid host' else: if user.kind == 'Host' and user.approved: d['status'] = 'ok' host.approved = True host.put() entry = model.LogEntry() entry.agent = user.key entry.patient = host.key entry.action = 'Host approved' entry.put() else: d['status'] = 'not permitted' json_reply(self) self.response.write(to_json(d))
def put(self, user_id): user = get_state()['user'] d = {} payload = json.loads(self.request.body) if user.user_id == user_id: d['status'] = 'ok' if 'name' in payload: user.name = payload['name'] if 'email' in payload: user.email = payload['email'] if 'research' in payload: user.research = payload['research'] if 'statement' in payload: user.statement = payload['statement'] user.put() entry = model.LogEntry() entry.agent = user.key entry.patient = user.key entry.action = 'modify' entry.put() else: d['status'] = 'permission denied' json_reply(self) self.response.write(to_json(d))