mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
moved lua crutch to kvmd
This commit is contained in:
parent
51dd9a7428
commit
9762c82d0a
9
Makefile
9
Makefile
@ -4,10 +4,8 @@ TESTENV_VIDEO ?= /dev/video0
|
||||
TESTENV_LOOP ?= /dev/loop7
|
||||
TESTENV_CMD ?= /bin/bash -c " \
|
||||
(socat PTY,link=$(TESTENV_HID) PTY,link=/dev/ttyS11 &) \
|
||||
&& rm -rf /etc/nginx/* \
|
||||
&& cp -r /usr/share/kvmd/configs/nginx/* /etc/nginx \
|
||||
&& mkdir -p /etc/kvmd \
|
||||
&& cp /usr/share/kvmd/configs/kvmd/*.yaml /etc/kvmd \
|
||||
&& cp -r /usr/share/kvmd/configs.default/nginx/* /etc/nginx \
|
||||
&& cp /usr/share/kvmd/configs.default/kvmd/*.yaml /etc/kvmd \
|
||||
&& cp /testenv/kvmd.yaml /etc/kvmd \
|
||||
&& nginx -c /etc/nginx/nginx.conf \
|
||||
&& ln -s $(TESTENV_VIDEO) /dev/kvmd-streamer \
|
||||
@ -33,7 +31,8 @@ run: _testenv
|
||||
- docker run --rm \
|
||||
--volume `pwd`/kvmd:/kvmd:ro \
|
||||
--volume `pwd`/web:/usr/share/kvmd/web:ro \
|
||||
--volume `pwd`/configs:/usr/share/kvmd/configs:ro \
|
||||
--volume `pwd`/extras:/usr/share/kvmd/extras:ro \
|
||||
--volume `pwd`/configs:/usr/share/kvmd/configs.default:ro \
|
||||
--volume `pwd`/testenv:/testenv:ro \
|
||||
--device $(TESTENV_LOOP):/dev/kvmd-msd \
|
||||
--device $(TESTENV_VIDEO):$(TESTENV_VIDEO) \
|
||||
|
||||
3
PKGBUILD
3
PKGBUILD
@ -42,6 +42,7 @@ package() {
|
||||
mkdir -p "$pkgdir/usr/share/kvmd"
|
||||
mkdir -p "$pkgdir/etc/kvmd"
|
||||
cp -r web "$pkgdir/usr/share/kvmd"
|
||||
cp -r configs "$pkgdir/usr/share/kvmd"
|
||||
cp -r extras "$pkgdir/usr/share/kvmd"
|
||||
cp -r configs "$pkgdir/usr/share/kvmd/configs.default"
|
||||
find "$pkgdir" -name ".gitignore" -delete
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Don't touch this file otherwise your device may stop working.
|
||||
# You can find a workable configuration in /usr/share/kvmd/configs/kvmd.
|
||||
# You can find a working configuration in /usr/share/kvmd/configs.default/kvmd.
|
||||
|
||||
kvmd:
|
||||
server:
|
||||
@ -9,6 +9,7 @@ kvmd:
|
||||
|
||||
info:
|
||||
meta: /etc/kvmd/meta.yaml
|
||||
extras: /usr/share/kvmd/extras
|
||||
|
||||
hid:
|
||||
pinout:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Don't touch this file otherwise your device may stop working.
|
||||
# You can find a workable configuration in /usr/share/kvmd/configs/kvmd.
|
||||
# You can find a workable configuration in /usr/share/kvmd/configs.default/kvmd.
|
||||
|
||||
kvmd:
|
||||
server:
|
||||
@ -9,6 +9,7 @@ kvmd:
|
||||
|
||||
info:
|
||||
meta: /etc/kvmd/meta.yaml
|
||||
extras: /usr/share/kvmd/extras
|
||||
|
||||
hid:
|
||||
pinout:
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
{
|
||||
"name": "KVM",
|
||||
"description": "Open KVM session in a web browser",
|
||||
"icon": "/svg/kvm.svg",
|
||||
"path": "/kvm.html",
|
||||
"place": 0,
|
||||
"keyboard_cap": true
|
||||
}
|
||||
@ -6,7 +6,7 @@ worker_processes 4;
|
||||
# error_log /tmp/nginx.error.log;
|
||||
error_log stderr;
|
||||
|
||||
include /etc/nginx/apps/*/main-ctx.conf;
|
||||
include /usr/share/kvmd/extras/*/nginx.main-ctx.conf;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
@ -40,26 +40,12 @@ http {
|
||||
server 127.0.0.1:8082 fail_timeout=0s max_fails=0;
|
||||
}
|
||||
|
||||
include /etc/nginx/apps/*/http-ctx.conf;
|
||||
include /usr/share/kvmd/extras/*/nginx.http-ctx.conf;
|
||||
|
||||
lua_shared_dict WS_TOKENS 10m;
|
||||
init_by_lua_block {
|
||||
WS_TOKEN_EXPIRES = 10;
|
||||
|
||||
local cjson = require("cjson");
|
||||
local io = require("io");
|
||||
|
||||
local apps = {};
|
||||
local apps_dir_path = "/etc/nginx/apps";
|
||||
for app in io.popen("ls " .. apps_dir_path):lines() do
|
||||
local manifest_file = assert(io.open(apps_dir_path .. "/" .. app .. "/manifest.json", "r"));
|
||||
local manifest = cjson.decode(manifest_file:read("*all"));
|
||||
manifest_file:close();
|
||||
apps[app] = manifest;
|
||||
end
|
||||
|
||||
APPS_JSON = cjson.encode(apps);
|
||||
}
|
||||
#PROD lua_shared_dict WS_TOKENS 10m;
|
||||
#PROD init_by_lua_block {
|
||||
#PROD WS_TOKEN_EXPIRES = 10;
|
||||
#PROD }
|
||||
|
||||
#PROD server {
|
||||
#PROD listen 80;
|
||||
@ -98,13 +84,6 @@ http {
|
||||
}
|
||||
}
|
||||
|
||||
location /get_apps {
|
||||
default_type "application/json";
|
||||
content_by_lua_block {
|
||||
ngx.say(APPS_JSON);
|
||||
}
|
||||
}
|
||||
|
||||
location /kvmd/ws {
|
||||
#PROD auth_basic off;
|
||||
#PROD access_by_lua_block {
|
||||
@ -165,6 +144,6 @@ http {
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
}
|
||||
|
||||
include /etc/nginx/apps/*/server-ctx.conf;
|
||||
include /usr/share/kvmd/extras/*/nginx.server-ctx.conf;
|
||||
}
|
||||
}
|
||||
|
||||
6
extras/kvm/manifest.yaml
Normal file
6
extras/kvm/manifest.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
name: KVM
|
||||
description: Open KVM session in a web browser
|
||||
icon: /svg/kvm.svg
|
||||
keyboard_cap: true
|
||||
daemon: kvmd
|
||||
place: 0
|
||||
@ -8,6 +8,7 @@ from ...logging import Log
|
||||
|
||||
from ... import gpio
|
||||
|
||||
from .info import InfoManager
|
||||
from .hid import Hid
|
||||
from .atx import Atx
|
||||
from .msd import MassStorageDevice
|
||||
@ -24,6 +25,12 @@ def main() -> None:
|
||||
|
||||
log = Log(loop)
|
||||
|
||||
info_manager = InfoManager(
|
||||
meta_path=str(config["info"]["meta"]),
|
||||
extras_path=str(config["info"]["extras"]),
|
||||
loop=loop,
|
||||
)
|
||||
|
||||
hid = Hid(
|
||||
reset=int(config["hid"]["pinout"]["reset"]),
|
||||
device_path=str(config["hid"]["device"]),
|
||||
@ -77,12 +84,13 @@ def main() -> None:
|
||||
|
||||
Server(
|
||||
log=log,
|
||||
info_manager=info_manager,
|
||||
|
||||
hid=hid,
|
||||
atx=atx,
|
||||
msd=msd,
|
||||
streamer=streamer,
|
||||
|
||||
meta_path=str(config["info"]["meta"]),
|
||||
heartbeat=float(config["server"]["heartbeat"]),
|
||||
streamer_shutdown_delay=float(config["streamer"]["shutdown_delay"]),
|
||||
msd_chunk_size=int(config["msd"]["chunk_size"]),
|
||||
|
||||
51
kvmd/apps/kvmd/info.py
Normal file
51
kvmd/apps/kvmd/info.py
Normal file
@ -0,0 +1,51 @@
|
||||
import os
|
||||
import asyncio
|
||||
|
||||
from typing import Dict
|
||||
|
||||
import dbus # pylint: disable=import-error
|
||||
import dbus.exceptions # pylint: disable=import-error
|
||||
|
||||
from ...yaml import load_yaml_file
|
||||
|
||||
|
||||
# =====
|
||||
class InfoManager:
|
||||
def __init__(
|
||||
self,
|
||||
meta_path: str,
|
||||
extras_path: str,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
) -> None:
|
||||
|
||||
self.__meta_path = meta_path
|
||||
self.__extras_path = extras_path
|
||||
|
||||
self.__loop = loop
|
||||
|
||||
async def get_meta(self) -> Dict:
|
||||
return (await self.__loop.run_in_executor(None, load_yaml_file, self.__meta_path))
|
||||
|
||||
async def get_extras(self) -> Dict:
|
||||
return (await self.__loop.run_in_executor(None, self.__sync_get_extras))
|
||||
|
||||
def __sync_get_extras(self) -> Dict:
|
||||
try:
|
||||
bus = dbus.SystemBus()
|
||||
|
||||
def is_enabled(daemon: str) -> bool:
|
||||
obj = bus.get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
|
||||
get_unit_state = obj.get_dbus_method("GetUnitFileState", "org.freedesktop.systemd1.Manager")
|
||||
return (get_unit_state(daemon + ".service") in ["enabled", "enabled-runtime", "static", "indirect", "generated"])
|
||||
|
||||
except dbus.exceptions.DBusException:
|
||||
is_enabled = (lambda daemon: True)
|
||||
|
||||
extras: Dict[str, Dict] = {}
|
||||
for app in os.listdir(self.__extras_path):
|
||||
if app[0] != "." and os.path.isdir(os.path.join(self.__extras_path, app)):
|
||||
extras[app] = load_yaml_file(os.path.join(self.__extras_path, app, "manifest.yaml"))
|
||||
daemon = extras[app].get("daemon", "")
|
||||
if isinstance(daemon, str) and daemon.strip():
|
||||
extras[app]["enabled"] = is_enabled(daemon.strip())
|
||||
return extras
|
||||
@ -18,10 +18,10 @@ from ...logging import Log
|
||||
|
||||
from ...aioregion import RegionIsBusyError
|
||||
|
||||
from ...yaml import load_yaml_file
|
||||
|
||||
from ... import __version__
|
||||
|
||||
from .info import InfoManager
|
||||
|
||||
from .hid import Hid
|
||||
|
||||
from .atx import Atx
|
||||
@ -108,12 +108,13 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||
def __init__( # pylint: disable=too-many-arguments
|
||||
self,
|
||||
log: Log,
|
||||
info_manager: InfoManager,
|
||||
|
||||
hid: Hid,
|
||||
atx: Atx,
|
||||
msd: MassStorageDevice,
|
||||
streamer: Streamer,
|
||||
|
||||
meta_path: str,
|
||||
heartbeat: float,
|
||||
streamer_shutdown_delay: float,
|
||||
msd_chunk_size: int,
|
||||
@ -122,12 +123,13 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||
) -> None:
|
||||
|
||||
self.__log = log
|
||||
self.__info_manager = info_manager
|
||||
|
||||
self.__hid = hid
|
||||
self.__atx = atx
|
||||
self.__msd = msd
|
||||
self.__streamer = streamer
|
||||
|
||||
self.__meta_path = meta_path
|
||||
self.__heartbeat = heartbeat
|
||||
self.__streamer_shutdown_delay = streamer_shutdown_delay
|
||||
self.__msd_chunk_size = msd_chunk_size
|
||||
@ -190,7 +192,8 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||
"streamer": await self.__streamer.get_version(),
|
||||
},
|
||||
"streamer": self.__streamer.get_app(),
|
||||
"meta": load_yaml_file(self.__meta_path),
|
||||
"meta": await self.__info_manager.get_meta(),
|
||||
"extras": await self.__info_manager.get_extras(),
|
||||
})
|
||||
|
||||
@_wrap_exceptions_for_web("Log error")
|
||||
|
||||
@ -6,3 +6,4 @@ pyyaml
|
||||
pyserial
|
||||
setproctitle
|
||||
systemd-python
|
||||
dbus-python
|
||||
|
||||
@ -43,8 +43,8 @@ RUN pacman -Syy \
|
||||
python \
|
||||
python-pip \
|
||||
python-systemd \
|
||||
python-dbus \
|
||||
nginx-mainline \
|
||||
lua51-cjson \
|
||||
ustreamer \
|
||||
socat \
|
||||
htmlhint \
|
||||
@ -56,4 +56,7 @@ RUN pacman -Syy \
|
||||
COPY testenv/requirements.txt requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN rm -rf /etc/nginx/* \
|
||||
&& mkdir /etc/kvmd
|
||||
|
||||
CMD /bin/bash
|
||||
|
||||
@ -6,6 +6,7 @@ kvmd:
|
||||
|
||||
info:
|
||||
meta: /etc/kvmd/meta.yaml
|
||||
extras: /usr/share/kvmd/extras
|
||||
|
||||
hid:
|
||||
pinout:
|
||||
|
||||
@ -6,4 +6,5 @@ pyyaml
|
||||
pyserial
|
||||
setproctitle
|
||||
systemd-python
|
||||
dbus-python
|
||||
tox
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user