summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-02-03 16:11:34 +0200
committerMaxim Devaev <[email protected]>2024-02-03 16:13:45 +0200
commit8d702f8cc26e5a0665ce2f0f0ea403e8d0d4ad79 (patch)
tree07ae5354a22564335de652e8a02e1ce059955bb4 /kvmd
parent272e3bf5e95ed9ad8e304f51c3f62ada53faaa63 (diff)
kvmd-nginx-mkconf: Render nginx config with kvmd settings
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py10
-rw-r--r--kvmd/apps/ngxmkconf/__init__.py68
-rw-r--r--kvmd/apps/ngxmkconf/__main__.py24
3 files changed, 102 insertions, 0 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 8e504ed1..88e31ef7 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -742,6 +742,16 @@ def _get_config_scheme() -> dict:
},
},
+ "nginx": {
+ "http": {
+ "port": Option(80, type=valid_port),
+ },
+ "https": {
+ "enabled": Option(True, type=valid_bool),
+ "port": Option(443, type=valid_port),
+ },
+ },
+
"janus": {
"stun": {
"host": Option("stun.l.google.com", type=valid_ip_or_host, unpack_as="stun_host"),
diff --git a/kvmd/apps/ngxmkconf/__init__.py b/kvmd/apps/ngxmkconf/__init__.py
new file mode 100644
index 00000000..6f7ed17a
--- /dev/null
+++ b/kvmd/apps/ngxmkconf/__init__.py
@@ -0,0 +1,68 @@
+# ========================================================================== #
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2023 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+import os
+import argparse
+
+import mako.template
+
+from ... import network
+
+from .. import init
+
+
+# =====
+def main(argv: (list[str] | None)=None) -> None:
+ (parent_parser, argv, config) = init(
+ add_help=False,
+ argv=argv,
+ )
+ parser = argparse.ArgumentParser(
+ prog="kvmd-nginx-mkconf",
+ description="Generate KVMD-Nginx config",
+ parents=[parent_parser],
+ )
+ parser.add_argument("-p", "--print", action="store_true", help="Print the result to stdout besides the output file")
+ parser.add_argument("input", help="Input Mako template")
+ parser.add_argument("output", help="Output Nginx config")
+ options = parser.parse_args(argv[1:])
+
+ with open(options.input, "r") as in_file:
+ template = in_file.read()
+
+ rendered = mako.template.Template(template).render(
+ http_port=config.nginx.http.port,
+ https_enabled=config.nginx.https.enabled,
+ https_port=config.nginx.https.port,
+ ipv6_enabled=network.is_ipv6_enabled(),
+ )
+
+ if options.print:
+ print(rendered)
+
+ try:
+ os.remove(options.output)
+ except FileNotFoundError:
+ pass
+
+ with open(options.output, "w") as out_file:
+ out_file.write(rendered)
diff --git a/kvmd/apps/ngxmkconf/__main__.py b/kvmd/apps/ngxmkconf/__main__.py
new file mode 100644
index 00000000..73bb60b3
--- /dev/null
+++ b/kvmd/apps/ngxmkconf/__main__.py
@@ -0,0 +1,24 @@
+# ========================================================================== #
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2023 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+from . import main
+main()