def get(self, path): """ get method """ logging.debug("request to download: %s", path) # If the file is large, we want to abandon downloading # if user cancels the requests. # pylint: disable=attribute-defined-outside-init self.connection_closed = False self.set_header("Content-Disposition", "attachment") if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return if path is None or not os.path.isfile(path): self.write("File %s not found" % path) self.set_status(404) self.finish() return length = int(4 * 1024 * 1024) offset = int(0) while True: data = utils.read_chunk(path, offset=offset, length=length, escape_data=False) if self.connection_closed or 'data' not in data or len(data['data']) < length: break offset += length self.write(data['data']) self.flush() if 'data' in data: self.write(data['data']) self.finish()
async def get(self, path): """ get method """ handler = logging.StreamHandler() handler.setFormatter( anticrlf.LogFormatter('%(levelname)s:%(name)s:%(message)s')) logger = logging.getLogger(__name__) logger.addHandler(handler) logger.setLevel(logging.DEBUG) logger.debug("request to download: %s", path) # If the file is large, we want to abandon downloading # if user cancels the requests. # pylint: disable=attribute-defined-outside-init self.connection_closed = False self.set_header("Content-Disposition", "attachment") if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return if path is None or not os.path.isfile(path): self.write(f"File {path} not found") self.set_status(404) self.finish() return length = int(4 * 1024 * 1024) offset = int(0) while True: data = await utils.read_chunk(path, offset=offset, length=length, escape_data=False) if self.connection_closed or 'data' not in data or len( data['data']) < length: break offset += length self.write(data['data']) self.flush() if 'data' in data: self.write(data['data']) self.finish()
def get(self, path): """ get method """ if path is None: return {} if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return offset = self.get_argument("offset", default=-1) length = self.get_argument("length", default=-1) if not os.path.isfile(path): return {} data = utils.read_chunk(path, offset=offset, length=length, escape_data=True) self.write(json.dumps(data)) self.finish()
def get(self, path): ''' get method ''' path = tornado.escape.url_unescape(path) if not path: path = "." # User should not be able to access anything outside # of the dir that heron-shell is running in. This ensures # sandboxing. So we don't allow absolute paths and parent # accessing. if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return listing = utils.get_listing(path) file_stats = {} for fn in listing: try: is_dir = False formatted_stat = utils.format_prefix(fn, utils.get_stat(path, fn)) if stat.S_ISDIR(utils.get_stat(path, fn).st_mode): is_dir = True file_stats[fn] = { "formatted_stat": formatted_stat, "is_dir": is_dir, "path": tornado.escape.url_escape(os.path.join(path, fn)), } if fn == "..": path_fragments = path.split("/") if not path_fragments: file_stats[fn]["path"] = "." else: file_stats[fn]["path"] = tornado.escape.url_escape( "/".join(path_fragments[:-1])) except: continue self.write(json.dumps(file_stats)) self.finish()
async def get(self, path): """ get method """ t = Template(utils.get_asset("file.html")) if path is None: self.set_status(404) await self.finish("No such file") return if not utils.check_path(path): self.set_status(403) await self.finish("Only relative paths are allowed") return args = dict( filename=path, jquery=utils.get_asset("jquery.js"), pailer=utils.get_asset("jquery.pailer.js"), css=utils.get_asset("bootstrap.css"), ) await self.finish(t.generate(**args)) return
async def get(self, path): ''' get method ''' if not path: path = "." if not utils.check_path(path): self.set_status(403) await self.finish("Only relative paths are allowed") return t = Template(utils.get_asset("browse.html")) args = dict( path=path, listing=utils.get_listing(path), format_prefix=utils.format_prefix, stat=stat, get_stat=utils.get_stat, os=os, css=utils.get_asset("bootstrap.css") ) await self.finish(t.generate(**args))
def get(self, path): """ get method """ t = Template(utils.get_asset("file.html")) if path is None: self.set_status(404) self.write("No such file") self.finish() return if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return args = dict( filename=path, jquery=utils.get_asset("jquery.js"), pailer=utils.get_asset("jquery.pailer.js"), css=utils.get_asset("bootstrap.css"), ) self.write(t.generate(**args)) self.finish()
def get(self, path): ''' get method ''' if not path: path = "." if not utils.check_path(path): self.write("Only relative paths are allowed") self.set_status(403) self.finish() return t = Template(utils.get_asset("browse.html")) args = dict( path=path, listing=utils.get_listing(path), format_prefix=utils.format_prefix, stat=stat, get_stat=utils.get_stat, os=os, css=utils.get_asset("bootstrap.css") ) self.write(t.generate(**args)) self.finish()