def navigateToURL(self, dimdimID, roomID, sessionID, encodedURL): # navigateToURL is called only from within a page. # so this is always for the 'current' resourceID originalURL = urllib.unquote(encodedURL) page = self.stateEngine.getCurrentPage(dimdimID) currentBaseURL = self.baseURL(page.get('url')) baseURL = self.baseURL(originalURL) if string.find(originalURL, osconfig.serverURL()) >= 0: # some pages don't have base injected (e.g. youtube) # these pages might give out relative links which # assume osconfig.serverURL() as the base URL. originalURL = string.lstrip(originalURL, osconfig.serverURL()) # it is possible that originalURL isn't an absolute link if string.find(originalURL, 'http://') != 0: # the only way originalURL isn't an absolute link is if # it belongs to the existing server. so we can # safely set baseURL to existing currentBaseURL baseURL = currentBaseURL originalURL = urlparse.urljoin(baseURL, originalURL) encodedURL = urllib.quote(originalURL) meeting = self.stateEngine.getMeeting(dimdimID) resourceID = meeting.get('currentResource') resource = self.stateEngine.getCurrentResource(dimdimID) lastPageNum = resource.get('lastPage') currentPageNum = resource.get('currentPage') if (currentPageNum != lastPageNum): self.stateEngine.trimResourceToCurrentPage(dimdimID) resourceType = self.stateEngine.getResourceType(dimdimID, resourceID) currentPageNum = currentPageNum + 1 # just create the page and return its location resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), resourceType), resourceID) pagePath = os.path.join(resourcePath, str(currentPageNum)) presenterPagePath = os.path.join(pagePath, 'presenter') attendeePagePath = os.path.join(pagePath, 'attendee') if not os.path.isdir(presenterPagePath): os.makedirs(presenterPagePath) if not os.path.isdir(attendeePagePath): os.makedirs(attendeePagePath) tempStore = os.path.join(resourcePath, 'temp.html') try: os.remove(tempStore) except: pass retval = self.curlHandle.downloadToFileFromHTTPURL(encodedURL, tempStore) if len(retval) < 3: try: os.remove(tempStore) except: pass try: shutil.rmtree(pagePath) except: pass response = self.jsonObj.encode({'result' : False, 'error' : 7500}) return response.encode() if originalURL != retval: # must be a 302. this is our new URL originalURL = retval baseURL = self.baseURL(originalURL) encodedURL = urllib.quote(originalURL) htmlHandle = open(tempStore, 'r') htmlContent = htmlHandle.read() htmlHandle.close() htmlContent = contentMgr.sanitizeHTML(htmlContent, baseURL) self.prepareHtml(originalURL, htmlContent, presenterPagePath, attendeePagePath) try: os.remove(tempStore) except: pass # add this page to the stateMachine self.stateEngine.registerPage(dimdimID, originalURL) resource = self.stateEngine.getCurrentResource(dimdimID) lastPage = resource.get('lastPage') response = self.jsonObj.encode({'result' : True, 'lastPage' : str(lastPage), 'currentPage' : str(currentPageNum), 'error' : 7200}) return response.encode()
def formSubmit(self, paramDict): dimdimID = paramDict.pop('dimdimsl_dimdimID') roomID = paramDict.pop('dimdimsl_roomID') sessionID = paramDict.pop('dimdimsl_sessionID') method = paramDict.pop('dimdimsl_method') action = paramDict.pop('dimdimsl_action') originalAction = urllib.unquote(action) page = self.stateEngine.getCurrentPage(dimdimID) currentBaseURL = self.baseURL(page.get('url')) baseURL = self.baseURL(originalAction) if string.find(originalAction, osconfig.serverURL()) >= 0: # some pages don't have base injected (e.g. youtube) # these pages might give out relative links which # assume osconfig.serverURL() as the base URL. originalAction = string.lstrip(originalAction, osconfig.serverURL()) # it is possible that originalAction isn't an absolute link if string.find(originalAction, 'http://') != 0: # the only way originalAction isn't an absolute link is if # it belongs to the existing server. so we can # safely set baseURL to existing currentBaseURL baseURL = currentBaseURL originalAction = urlparse.urljoin(baseURL, originalAction) action = urllib.quote(originalAction) meeting = self.stateEngine.getMeeting(dimdimID) resourceID = meeting.get('currentResource') resource = self.stateEngine.getCurrentResource(dimdimID) lastPageNum = resource.get('lastPage') currentPageNum = resource.get('currentPage') if (currentPageNum != lastPageNum): self.stateEngine.trimResourceToCurrentPage(dimdimID) resourceType = self.stateEngine.getResourceType(dimdimID, resourceID) currentPageNum = currentPageNum + 1 # just create the page and return its location resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), resourceType), resourceID) pagePath = os.path.join(resourcePath, str(currentPageNum)) presenterPagePath = os.path.join(pagePath, 'presenter') attendeePagePath = os.path.join(pagePath, 'attendee') if not os.path.isdir(presenterPagePath): os.makedirs(presenterPagePath) if not os.path.isdir(attendeePagePath): os.makedirs(attendeePagePath) tempStore = os.path.join(resourcePath, 'temp.html') try: os.remove(tempStore) except: pass retval = self.curlHandle.downloadToFileFromHTTPFormSubmit(action, method, paramDict, tempStore) if len(retval) < 3: try: os.remove(tempStore) except: pass try: shutil.rmtree(pagePath) except: pass response = self.jsonObj.encode({'result' : False, 'error' : 7500}) return response.encode() if originalAction != retval: # must be a 302. this is our new URL originalAction = retval baseURL = self.baseURL(originalAction) encodedURL = urllib.quote(originalAction) htmlHandle = open(tempStore, 'r') htmlContent = htmlHandle.read() htmlHandle.close() # inject baseURL and jquery.noConflict # TODO - WHAT IF BASE URL IS ALREADY THERE ?? htmlContent = contentMgr.sanitizeHTML(htmlContent, baseURL) self.prepareHtml(originalAction, htmlContent, presenterPagePath, attendeePagePath) try: os.remove(tempStore) except: pass # add this page to the stateMachine self.stateEngine.registerPage(dimdimID, originalAction) resource = self.stateEngine.getCurrentResource(dimdimID) lastPage = resource.get('lastPage') response = self.jsonObj.encode({'result' : True, 'lastPage' : str(lastPage), 'currentPage' : str(currentPageNum), 'error' : 7200}) return response.encode()