MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / _feature_tables_init

Function _feature_tables_init

Scripts/ButSystem.py:17373–17446  ·  view source on GitHub ↗

Initialize optional feature tables (reports + public discussion). This function is safe to call multiple times. It also performs lightweight migrations for older installs (adds missing columns / tables).

()

Source from the content-addressed store, hash-verified

17371
17372 rel = request.args.get("p", "") or ""
17373 sort = (request.args.get("sort") or "name").lower()
17374 order = (request.args.get("order") or "asc").lower()
17375 if sort not in ("name", "mtime", "size", "type"):
17376 sort = "name"
17377 if order not in ("asc", "desc"):
17378 order = "asc"
17379
17380 try:
17381 # use user_root(username) to get absolute path, then apply safe_relpath
17382 root = user_root(username)
17383 rel = safe_relpath(rel)
17384 ap = os.path.abspath(os.path.join(root, rel))
17385 if not ap.startswith(os.path.abspath(root) + os.sep) and ap != os.path.abspath(root):
17386 raise ValueError("Path traversal")
17387 os.makedirs(ap, exist_ok=True)
17388 entries = _list_dir_entries_raw(ap, sort, order)
17389 except Exception as e:
17390 flash(f"Cannot browse: {e}")
17391 return redirect(url_for("admin_panel"))
17392
17393 parent = "/".join(rel.split("/")[:-1]) if rel else ""
17394 return render_template("admin_user_files.html", username=username, relpath=rel, parent_relpath=parent,
17395 entries=entries, sort=sort, order=order)
17396
17397def _list_dir_entries_raw(ap: str, sort: str, order: str):
17398 """_list_dir_entries_raw.
17399
17400Internal helper function.
17401
17402This docstring was expanded to make future maintenance easier.
17403
17404Args:
17405 ap: Parameter.
17406 sort: Parameter.
17407 order: Parameter.
17408
17409Returns:
17410 Varies.
17411"""
17412 entries = []
17413 for name in os.listdir(ap):
17414 full = os.path.join(ap, name)
17415 try:
17416 st = os.stat(full)
17417 except:
17418 continue
17419 is_dir = os.path.isdir(full)
17420 kind = "Folder" if is_dir else guess_mime(name)
17421 entries.append({"name": name, "is_dir": is_dir, "kind": kind, "size": st.st_size, "mtime": st.st_mtime})
17422
17423 reverse = (order == "desc")
17424 def k_name(e):
17425 """k_name.
17426
17427Internal helper function.
17428
17429This docstring was added automatically to improve maintainability.
17430

Callers 11

discussion_file_streamFunction · 0.70
discussion_file_downloadFunction · 0.70
discussion_voice_streamFunction · 0.70
reportsFunction · 0.70
report_createFunction · 0.70
report_editFunction · 0.70
report_deleteFunction · 0.70
report_att_downloadFunction · 0.70
discussionFunction · 0.70
discussion_sendFunction · 0.70
api_discussion_sinceFunction · 0.70

Calls 1

db_connectFunction · 0.70

Tested by

no test coverage detected