A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.3KB

  1. # -*- coding: utf-8 -*-
  2. # Legacy endpoint compatibility from kirsle.net.
  3. from flask import g, request, redirect, url_for, flash
  4. import re
  5. import os
  6. import json
  7. from rophako.settings import Config
  8. from rophako.app import app
  9. from rophako.utils import template, login_required
  10. import rophako.model.blog as Blog
  11. import rophako.jsondb as JsonDB
  12. @app.route("/+")
  13. def google_plus():
  14. return redirect("https://plus.google.com/+NoahPetherbridge/posts")
  15. @app.route("/blog.html")
  16. def ancient_legacy_blog():
  17. post_id = request.args.get("id", None)
  18. if post_id is None:
  19. return redirect(url_for("blog.index"))
  20. # Look up the friendly ID.
  21. post = Blog.get_entry(post_id)
  22. if not post:
  23. flash("That blog entry wasn't found.")
  24. return redirect(url_for("blog.index"))
  25. return redirect(url_for("blog.entry", fid=post["fid"]), code=301)
  26. @app.route("/blog/kirsle/<fid>")
  27. def legacy_blog(fid):
  28. return redirect(url_for("blog.entry", fid=fid), code=301)
  29. @app.route("/rss.cgi")
  30. def legacy_rss():
  31. return redirect(url_for("blog.rss"), code=301)
  32. @app.route("/firered/<page>")
  33. @app.route("/firered")
  34. def legacy_firered(page=""):
  35. g.info["page"] = str(page) or "1"
  36. return template("firered.html")
  37. @app.route("/download", methods=["GET", "POST"])
  38. def legacy_download():
  39. form = None
  40. if request.method == "POST":
  41. form = request.form
  42. else:
  43. form = request.args
  44. method = form.get("method", "index")
  45. project = form.get("project", "")
  46. filename = form.get("file", "")
  47. root = "/home/kirsle/www/projects"
  48. if project and filename:
  49. # Filter the sections.
  50. project = re.sub(r'[^A-Za-z0-9]', '', project) # Project name is alphanumeric only.
  51. filename = re.sub(r'[^A-Za-z0-9\-_\.]', '', filename)
  52. # Check that all the files exist.
  53. if os.path.isdir(os.path.join(root, project)) and os.path.isfile(os.path.join(root, project, filename)):
  54. # Hit counters.
  55. hits = { "hits": 0 }
  56. db = "data/downloads/{}-{}".format(project, filename)
  57. if JsonDB.exists(db.format(project, filename)):
  58. hits = JsonDB.get(db)
  59. # Actually getting the file?
  60. if method == "get":
  61. # Up the hit counter.
  62. hits["hits"] += 1
  63. JsonDB.commit(db, hits)
  64. g.info["method"] = method
  65. g.info["project"] = project
  66. g.info["file"] = filename
  67. g.info["hits"] = hits["hits"]
  68. return template("download.html")
  69. flash("The file or project wasn't found.")
  70. return redirect(url_for("index"))
  71. @app.route("/<page>.html")
  72. def legacy_url(page):
  73. return redirect("/{}".format(page), code=301)
  74. @app.route("/metacity")
  75. def legacy_metacity():
  76. return redirect("https://github.com/kirsle/linux-themes", code=301)
  77. @app.route("/ssl_test")
  78. @login_required
  79. def ssl_test():
  80. return "<pre>{}</pre>".format(json.dumps({
  81. "SSLify criteria": {
  82. "request.is_secure": request.is_secure,
  83. "app.debug": app.debug,
  84. "X-Forwarded-Proto is http": request.headers.get("X-Forwarded-Proto", "http") == "https",
  85. },
  86. "App Configuration": {
  87. "Session cookies secure": app.config["SESSION_COOKIE_SECURE"],
  88. "config.FORCE_SSL": Config.security.force_ssl,
  89. },
  90. }))