A Python port of the Invisible Internet Project (I2P)
1"""Configuration routes — form-based config pages.
2
3Merged from Java's 19 separate config pages into grouped sections.
4
5Ported from net.i2p.router.web.helpers.Config*Helper / Config*Handler.
6"""
7
8from __future__ import annotations
9
10from flask import Blueprint, render_template, request, redirect, url_for, current_app
11
12bp = Blueprint("config", __name__, url_prefix="/config")
13
14_SECTIONS = {"network", "security", "ui", "tunnels", "clients", "logging", "updates", "advanced"}
15
16
17@bp.route("/")
18def config_index():
19 """Configuration overview — links to all sections."""
20 return render_template("config/index.html", sections=sorted(_SECTIONS))
21
22
23@bp.route("/<section>", methods=["GET"])
24def config_section(section: str):
25 """Render a config section page."""
26 if section not in _SECTIONS:
27 return render_template("404.html"), 404
28 ctx = current_app.config["CONSOLE_CONTEXT"]
29 return render_template(
30 f"config/{section}.html",
31 section=section,
32 properties=ctx.get_all_properties(),
33 )
34
35
36@bp.route("/<section>", methods=["POST"])
37def config_save(section: str):
38 """Save configuration changes from a form POST."""
39 if section not in _SECTIONS:
40 return render_template("404.html"), 404
41 ctx = current_app.config["CONSOLE_CONTEXT"]
42 for key, value in request.form.items():
43 ctx.set_property(key, value)
44 return redirect(url_for("config.config_section", section=section))