Beispiel #1
2
def getIdFromUrl(url):
	if stringutils.isEmpty(url):
		return None
	url = urlsplit(url)
	path = url.path if stringutils.isNotEmpty(url.path) else "/" 
	# normalize referrers down to a path (get rid of query+fragment)
	seed = "%s://%s%s" % (url.scheme, url.netloc, path)
	return hashlib.md5(seed).hexdigest()
Beispiel #2
0
	def onApiRequest(self):
		id = self.param(settings.CHATROOM_ID_PARAM)
		token = self.param(settings.TOKEN_PARAM)
		name = self.param(settings.CHATROOM_NAME_PARAM, "", settings.ROOM_NAME_CHARACTER_LIMIT, True)
		participants = 0
		chatroom = None
		
		if stringutils.isNotEmpty(id):
			chatroom = chatroomservice.getChatroom(id)
			if chatroom is None: # check for bad IDs
				id = None
		if stringutils.isEmpty(id):
			id = chatroomservice.getIdFromUrl(self.request.referrer)
		
		if stringutils.isNotEmpty(id):
			chatroom = chatroomservice.getChatroom(id)
			if chatroom is None:
				chatroom = Chatroom(id, name)
				chatroomservice.cacheAndEnqueueSave(chatroom)
			elif len(name) > 0 and (name != chatroom.getName()):
				chatroom.setName(name)
				chatroomservice.cacheAndEnqueueSave(chatroom)
			if channelservice.isValidToken(id, token):
				participants = channelservice.activateToken(id, token)
			else:
				token, participants = channelservice.createToken(id)
			channelservice.updateParticipantCount(id, token)
			self.sendApiResponse({
				'token': token,
				'chatroom': chatroom.asLiteral(),
				'participants': participants,
				'settings': settings.getClientSettings()
			})
		else:
			self.sendApiError('invalid or missing referrer', 401)
Beispiel #3
0
	def param(self, key, default="", size=0, sanitize=False):
		value = self.request.get(key).strip()
		if stringutils.isEmpty(value):
			value = default
		if size > 0:
			value = value[0:size]
		if sanitize:
			value = htmlutils.escape(value)	
		return value
Beispiel #4
0
	def serveAsset(self, path, timeout=settings.ASSET_CACHE_WINDOW):
		cacheKey = self.getCacheKey(path, self.assetVersion)
		asset = memcache.get(cacheKey)
		if stringutils.isEmpty(asset) or not settings.CACHE_ASSETS:
			if os.path.exists(path):
				asset = open(path).read()
				if stringutils.isNotEmpty(asset):
					memcache.set(cacheKey, asset, timeout)
				else:
					return self.send("Empty Asset - %s" % path, 409)
			else:
				return self.send("Missing Asset - %s" % path, 404)
		self.send(asset)