def count_files(): if xauth.get_current_user() == None: return 0 user_name = xauth.get_current_user().get("name") # if user_name == "admin": # count = execute("SELECT COUNT(*) as count FROM file WHERE is_deleted = 0 ")[0].get("count") # else: # count = execute("SELECT COUNT(*) as count FROM file WHERE is_deleted = 0 AND groups='%s'" % user_name)[0].get("count") db = xtables.get_file_table() count = db.count("is_deleted = 0 AND groups='%s'" % user_name) if count == 0: return 1 return count
def POST(self): path = xutils.get_argument("path") if not path: path = xconfig.DATA_DIR path = os.path.abspath(path) find_key = xutils.get_argument("find_key", "") find_type = xutils.get_argument("type") mode = xutils.get_argument("mode") if find_key == "" or find_key is None: find_key = xutils.get_argument("key", "") find_key = "*" + find_key + "*" path_name = os.path.join(path, find_key) if find_key == "**": plist = [] elif path == os.path.abspath(xconfig.DATA_DIR) and xconfig.USE_CACHE_SEARCH: # search in cache plist = find_in_cache(find_key) else: plist = xutils.search_path(path, find_key) filelist = FS.process_file_list(plist, path) # TODO max result size tpl = "fs/page/fs.html" if mode == "grid": tpl = "fs/fs_grid.html" return xtemplate.render(tpl, path = path, token = xauth.get_current_user().token, filelist = filelist)
def GET(self): shell_list = [] dirname = "scripts" if os.path.exists(dirname): for fname in os.listdir(dirname): fpath = os.path.join(dirname, fname) if os.path.isfile(fpath) and fpath.endswith(".bat"): shell_list.append(fpath) # 自定义链接 customized_items = [] db = xtables.get_storage_table() config = db.select_one( where=dict(key="tools", user=xauth.get_current_name())) if config is not None: config_list = xutils.parse_config_text(config.value) customized_items = map( lambda x: Storage(name=x.get("key"), link=x.get("value")), config_list) return xtemplate.render("system/system.html", Storage=Storage, os=os, user=xauth.get_current_user(), customized_items=customized_items)
def list_directory(self, path): try: if xutils.is_windows() and path == "/": # return self.list_win_drives() filelist = get_win_drives() else: filelist = list_abs_dir(path) except OSError: return "No permission to list directory" # filelist中路径均不带/ # 排序:文件夹优先,按字母顺序排列 # filelist.sort(key=lambda a: a.lower()) # filelist.sort(key=lambda a: not os.path.isdir(os.path.join(path,a))) filelist = [FileItem(item) for item in filelist] filelist.sort() # SAE上遇到中文出错 # Fix bad filenames,修改不生效 # filelist = list(map(lambda x: xutils.decode_bytes(x.encode("utf-8", errors='surrogateescape')), filelist)) # Fix, some `file` in *nix is not file either directory. os.stat方法报错 path = path.replace("\\", "/") kw = get_filesystem_kw() kw["filelist"] = filelist kw["path"] = path kw["fspathlist"] = xutils.splitpath(path) kw["token"] = xauth.get_current_user().token return xtemplate.render("fs/fs.html", **kw)
def GET(self): shell_list = [] dirname = "scripts" if os.path.exists(dirname): for fname in os.listdir(dirname): fpath = os.path.join(dirname, fname) if os.path.isfile(fpath) and fpath.endswith(".bat"): shell_list.append(fpath) # 自定义链接 customized_items = [] user_config = get_tools_config(xauth.get_current_name()) if user_config is not None: config_list = xutils.parse_config_text(user_config.value) customized_items = map( lambda x: Storage(name=x.get("key"), url=x.get("value")), config_list) return xtemplate.render("system/system.html", show_aside=(xconfig.OPTION_STYLE == "aside"), html_title="系统", Storage=Storage, os=os, user=xauth.get_current_user(), customized_items=customized_items)
def GET(self): user_name = xauth.current_name() menu_list = [] def filter_link_func(link): if link.is_guest: return user_name is None if link.is_user: return user_name != None if link.user is None: return True return link.user == user_name for category in xconfig.MENU_LIST: children = category.children if len(children) == 0: continue children = list(filter(filter_link_func, children)) menu_list.append(Storage(name=category.name, children=children)) return xtemplate.render("system/template/system.html", html_title="系统", Storage=Storage, os=os, user=xauth.get_current_user(), menu_list=menu_list, customized_items=[])
def POST(self): content = xutils.get_argument("content") user = xauth.get_current_user() # chatlist.append(content) db = xtables.get_message_table() ctime = xutils.format_time() db.insert(user=user.get("name"), ctime=ctime, content=content) return dict(code="success", message="", data=dict(user=user.get("name"), content=content, ctime=ctime))
def GET(self): shell_list = [] dirname = "scripts" if os.path.exists(dirname): for fname in os.listdir(dirname): fpath = os.path.join(dirname, fname) if os.path.isfile(fpath) and fpath.endswith(".bat"): shell_list.append(fpath) return xtemplate.render("system/system.html", Storage=Storage, os=os, user=xauth.get_current_user())
def GET(self): shell_list = [] dirname = "scripts" if os.path.exists(dirname): for fname in os.listdir(dirname): fpath = os.path.join(dirname, fname) if os.path.isfile(fpath) and fpath.endswith(".bat"): shell_list.append(fpath) addr = get_server_ip() + ":" + config.get("PORT") return xtemplate.render("system/system.html", addr=addr, os=os, user=xauth.get_current_user())
def GET(self): id = xutils.get_argument("id", "") name = xutils.get_argument("name", "") page = xutils.get_argument("page", 1, type=int) if id == "" and name == "": raise HTTPError(504) if id != "": id = int(id) file = dao.get_by_id(id) elif name is not None: file = dao.get_by_name(name) if file is None: raise web.notfound() if not file.is_public and xauth.get_current_user() is None: return xauth.redirect_to_login() db = xtables.get_file_table() pathlist = dao.get_pathlist(db, file) user_name = xauth.get_current_name() can_edit = (file.creator == user_name) or (user_name == "admin") role = xauth.get_current_role() if role != "admin" and file.groups != '*' and file.groups != role: raise web.seeother("/unauthorized") files = [] amount = 0 if file.type == "group": amount = db.count(where="parent_id=%s AND is_deleted=0" % file.id) files = db.select(where=dict(parent_id=file.id, is_deleted=0), order="priority DESC, sctime DESC", limit=10, offset=(page-1)*10) elif file.type == "post": file.content = file.content.replace(u'\xad', '\n') file.content = file.content.replace("\n", "<br/>") dao.visit_by_id(id) else: dao.visit_by_id(id) return xtemplate.render("file/view.html", file=file, content = file.get_content(), date2str=date2str, can_edit = can_edit, pathlist = pathlist, page_max = math.ceil(amount/10), page = page, page_url = "/file/view?id=%s&page=" % id, files = files)
def GET(self): # 自定义链接 # customized_items = [] # user_config = get_tools_config(xauth.get_current_name()) # if user_config is not None: # config_list = xutils.parse_config_text(user_config.value) # customized_items = map(lambda x: Storage(name=x.get("key"), url=x.get("value")), config_list) return xtemplate.render("system/system.html", show_aside=(xconfig.OPTION_STYLE == "aside"), html_title="系统", Storage=Storage, os=os, user=xauth.get_current_user(), customized_items=[])
def POST(self): path = xutils.get_argument("path") find_key = xutils.get_argument("find_key", "") find_type = xutils.get_argument("type") find_key = "*" + find_key + "*" path_name = os.path.join(path, find_key) if find_key == "": plist = [] else: plist = xutils.search_path(path, find_key) return xtemplate.render( "fs/fs.html", token=xauth.get_current_user().token, fspathlist=xutils.splitpath(path), filelist=[xutils.FileItem(p, path) for p in plist])
def list_directory(self, path): try: if xutils.is_windows() and path == "/": filelist = list_win_drives() else: filelist = list_abs_dir(path) except OSError: return xtemplate.render("fs/fs.html", show_aside=False, path=path, filelist=[], error="No permission to list directory") # filelist中路径均不带/ # 排序:文件夹优先,按字母顺序排列 # filelist.sort(key=lambda a: a.lower()) # filelist.sort(key=lambda a: not os.path.isdir(os.path.join(path,a))) filelist = process_file_list(filelist) # SAE上遇到中文出错 # Fix bad filenames,修改不生效 # filelist = list(map(lambda x: xutils.decode_bytes(x.encode("utf-8", errors='surrogateescape')), filelist)) # Fix, some `file` in *nix is not file either directory. os.stat方法报错 path = path.replace("\\", "/") kw = get_filesystem_kw() kw["filelist"] = filelist kw["path"] = path kw["token"] = xauth.get_current_user().token kw["parent_path"] = get_parent_path(path) kw["search_action"] = "/fs_find" kw["show_aside"] = False kw["show_hidden_files"] = xutils.get_argument("show_hidden_files", False, type=bool) mode = xutils.get_argument("mode", xconfig.FS_VIEW_MODE) kw["fs_mode"] = mode if mode == "grid": return xtemplate.render("fs/fs_grid.html", **kw) elif mode == "shell": return xtemplate.render("fs/fs_shell.html", **kw) elif mode == "sidebar": kw["show_aside"] = False return xtemplate.render("fs/fs_sidebar.html", **kw) else: return xtemplate.render("fs/fs.html", **kw)
def POST(self): path = xutils.get_argument("path") find_key = xutils.get_argument("find_key", "") find_type = xutils.get_argument("type") if find_key == "" or find_key is None: find_key = xutils.get_argument("key", "") find_key = "*" + find_key + "*" path_name = os.path.join(path, find_key) if find_key == "**": plist = [] elif os.path.abspath(path) == os.path.abspath(xconfig.DATA_DIR) and xconfig.USE_CACHE_SEARCH: # search in cache plist = find_in_cache(find_key) else: plist = xutils.search_path(path, find_key) # TODO max result size return xtemplate.render("fs/fs.html", token = xauth.get_current_user().token, filelist = [xutils.FileItem(p, path) for p in plist])
def GET(self): year = xutils.get_argument("year") month = xutils.get_argument("month") if len(month) == 1: month = "0" + month db = xtables.get_file_table() user_name = xauth.get_current_user()["name"] rows = db.query("SELECT id, type, name, creator, ctime, mtime, size FROM file WHERE creator = $creator AND ctime LIKE $ctime AND is_deleted=0" + " ORDER BY ctime DESC", dict(creator=user_name, ctime="%s-%s%%" % (year, month))) result = dict() for row in rows: date = re.match(r"\d+\-\d+", row.ctime).group(0) row.url = "/file/view?id={}".format(row.id); # 优化数据大小 row.content = "" if date not in result: result[date] = [] result[date].append(row) return result
def GET(self): # days = xutils.get_argument("days", 30, type=int) offset = xutils.get_argument("offset", 0, type=int) limit = xutils.get_argument("limit", 20, type=int) db = xtables.get_file_table() # last_month = xutils.days_before(days, format=True) user_name = xauth.get_current_user()["name"] rows = db.query("SELECT id, type, name, creator, ctime, mtime, size FROM file WHERE creator = $creator AND is_deleted=0" + " ORDER BY ctime DESC LIMIT $offset, $limit", dict(creator=user_name, offset=offset, limit=limit)) result = dict() for row in rows: date = re.match(r"\d+\-\d+", row.ctime).group(0) row.url = "/file/view?id={}".format(row.id); # 优化数据大小 row.content = "" if date not in result: result[date] = [] result[date].append(row) return result
def pre_render(kw): """ Main hook for template engine """ kw["math"] = math kw["_is_admin"] = xauth.is_admin() kw["_has_login"] = xauth.has_login() kw["_user"] = xauth.get_current_user() kw["_user_agent"] = get_user_agent() # 处理首页公告 kw["_top_notice"] = None # print(web.ctx.env) # kw["_nav_position"] = web.cookies(nav_position="top").nav_position kw["_nav_position"] = "top" # 用于渲染其他组件 kw["_render"] = render kw["xutils"] = xutils if hasattr(web.ctx, "env"): kw["HOST"] = web.ctx.env.get("HTTP_HOST") # render input _input = web.ctx.get("_xnote.input") if _input is not None: kw.update(_input)