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.

120 lines
3.3 KiB

# -*- coding: utf-8 -*-
# Legacy endpoint compatibility from kirsle.net.
from flask import g, request, redirect, url_for, flash
import re
import os
import json
from rophako.settings import Config
from rophako.app import app
from rophako.utils import template, login_required
import rophako.model.blog as Blog
import rophako.jsondb as JsonDB
def google_plus():
return redirect("https://plus.google.com/+NoahPetherbridge/posts")
def ancient_legacy_blog():
post_id = request.args.get("id", None)
if post_id is None:
return redirect(url_for("blog.index"))
# Look up the friendly ID.
post = Blog.get_entry(post_id)
if not post:
flash("That blog entry wasn't found.")
return redirect(url_for("blog.index"))
return redirect(url_for("blog.entry", fid=post["fid"]), code=301)
def legacy_blog(fid):
return redirect(url_for("blog.entry", fid=fid), code=301)
def legacy_rss():
return redirect(url_for("blog.rss"), code=301)
def legacy_firered(page=""):
g.info["page"] = str(page) or "1"
return template("firered.html")
@app.route("/download", methods=["GET", "POST"])
def legacy_download():
form = None
if request.method == "POST":
form = request.form
form = request.args
method = form.get("method", "index")
project = form.get("project", "")
filename = form.get("file", "")
root = "/home/kirsle/www/projects"
if project and filename:
# Filter the sections.
project = re.sub(r'[^A-Za-z0-9]', '', project) # Project name is alphanumeric only.
filename = re.sub(r'[^A-Za-z0-9\-_\.]', '', filename)
# Check that all the files exist.
if os.path.isdir(os.path.join(root, project)) and os.path.isfile(os.path.join(root, project, filename)):
# Hit counters.
hits = { "hits": 0 }
db = "data/downloads/{}-{}".format(project, filename)
if JsonDB.exists(db.format(project, filename)):
hits = JsonDB.get(db)
# Actually getting the file?
if method == "get":
# Up the hit counter.
hits["hits"] += 1
JsonDB.commit(db, hits)
g.info["method"] = method
g.info["project"] = project
g.info["file"] = filename
g.info["hits"] = hits["hits"]
return template("download.html")
flash("The file or project wasn't found.")
return redirect(url_for("index"))
def legacy_url(page):
return redirect("/{}".format(page), code=301)
def legacy_metacity():
return redirect("https://github.com/kirsle/linux-themes", code=301)
def ssl_test():
return "<pre>{}</pre>".format(json.dumps({
"SSLify criteria": {
"request.is_secure": request.is_secure,
"app.debug": app.debug,
"X-Forwarded-Proto is http": request.headers.get("X-Forwarded-Proto", "http") == "https",
"App Configuration": {
"Session cookies secure": app.config["SESSION_COOKIE_SECURE"],
"config.FORCE_SSL": Config.security.force_ssl,