The web design and pages for my personal website.
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.
 
 
 
 

128 lines
3.6 KiB

  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. # CNET links to the MS-DOS download using semicolon delimiters in the
  44. # query string. Fix that if detected.
  45. query = request.query_string.decode()
  46. if not '&' in query and ';' in query:
  47. url = re.sub(r';|%3b', '&', request.url, flags=re.IGNORECASE)
  48. return redirect(url)
  49. form = request.args
  50. method = form.get("method", "index")
  51. project = form.get("project", "")
  52. filename = form.get("file", "")
  53. root = "/home/kirsle/www/projects"
  54. if project and filename:
  55. # Filter the sections.
  56. project = re.sub(r'[^A-Za-z0-9]', '', project) # Project name is alphanumeric only.
  57. filename = re.sub(r'[^A-Za-z0-9\-_\.]', '', filename)
  58. # Check that all the files exist.
  59. if os.path.isdir(os.path.join(root, project)) and os.path.isfile(os.path.join(root, project, filename)):
  60. # Hit counters.
  61. hits = { "hits": 0 }
  62. db = "data/downloads/{}-{}".format(project, filename)
  63. if JsonDB.exists(db.format(project, filename)):
  64. hits = JsonDB.get(db)
  65. # Actually getting the file?
  66. if method == "get":
  67. # Up the hit counter.
  68. hits["hits"] += 1
  69. JsonDB.commit(db, hits)
  70. g.info["method"] = method
  71. g.info["project"] = project
  72. g.info["file"] = filename
  73. g.info["hits"] = hits["hits"]
  74. return template("download.html")
  75. flash("The file or project wasn't found.")
  76. return redirect(url_for("index"))
  77. @app.route("/<page>.html")
  78. def legacy_url(page):
  79. return redirect("/{}".format(page), code=301)
  80. @app.route("/metacity")
  81. def legacy_metacity():
  82. return redirect("https://github.com/kirsle/linux-themes", code=301)
  83. @app.route("/ssl_test")
  84. @login_required
  85. def ssl_test():
  86. return "<pre>{}</pre>".format(json.dumps({
  87. "SSLify criteria": {
  88. "request.is_secure": request.is_secure,
  89. "app.debug": app.debug,
  90. "X-Forwarded-Proto is http": request.headers.get("X-Forwarded-Proto", "http") == "https",
  91. },
  92. "App Configuration": {
  93. "Session cookies secure": app.config["SESSION_COOKIE_SECURE"],
  94. "config.FORCE_SSL": Config.security.force_ssl,
  95. },
  96. }))