mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
allow kvmd to edit msd params
This commit is contained in:
@@ -54,6 +54,7 @@ from ..validators.basic import valid_number
|
|||||||
from ..validators.basic import valid_float_f0
|
from ..validators.basic import valid_float_f0
|
||||||
from ..validators.basic import valid_float_f01
|
from ..validators.basic import valid_float_f01
|
||||||
|
|
||||||
|
from ..validators.auth import valid_user
|
||||||
from ..validators.auth import valid_users_list
|
from ..validators.auth import valid_users_list
|
||||||
|
|
||||||
from ..validators.os import valid_abs_path
|
from ..validators.os import valid_abs_path
|
||||||
@@ -249,15 +250,27 @@ def _get_config_scheme() -> Dict:
|
|||||||
},
|
},
|
||||||
|
|
||||||
"otg": {
|
"otg": {
|
||||||
"gadget": Option("kvmd", type=valid_otg_gadget),
|
|
||||||
"vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
|
"vendor_id": Option(0x1D6B, type=valid_otg_id), # Linux Foundation
|
||||||
"product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
|
"product_id": Option(0x0104, type=valid_otg_id), # Multifunction Composite Gadget
|
||||||
"manufacturer": Option("Pi-KVM"),
|
"manufacturer": Option("Pi-KVM"),
|
||||||
"product": Option("Composite KVM Device"),
|
"product": Option("Composite KVM Device"),
|
||||||
"serial_number": Option("CAFEBABE"),
|
"serial": Option("CAFEBABE"),
|
||||||
"udc": Option(""),
|
|
||||||
|
"gadget": Option("kvmd", type=valid_otg_gadget),
|
||||||
|
"udc": Option("", type=(lambda arg: str(arg).strip())),
|
||||||
"init_delay": Option(3.0, type=valid_float_f01),
|
"init_delay": Option(3.0, type=valid_float_f01),
|
||||||
|
|
||||||
|
"msd": {
|
||||||
|
"user": Option("kvmd", type=valid_user),
|
||||||
|
"default": {
|
||||||
|
"stall": Option(False, type=valid_bool),
|
||||||
|
"cdrom": Option(True, type=valid_bool),
|
||||||
|
"rw": Option(False, type=valid_bool),
|
||||||
|
"removable": Option(True, type=valid_bool),
|
||||||
|
"fua": Option(True, type=valid_bool),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
"acm": {
|
"acm": {
|
||||||
"enabled": Option(True, type=valid_bool),
|
"enabled": Option(True, type=valid_bool),
|
||||||
},
|
},
|
||||||
@@ -265,6 +278,13 @@ def _get_config_scheme() -> Dict:
|
|||||||
"drives": {
|
"drives": {
|
||||||
"enabled": Option(False, type=valid_bool),
|
"enabled": Option(False, type=valid_bool),
|
||||||
"count": Option(1, type=(lambda arg: valid_number(arg, min=1))),
|
"count": Option(1, type=(lambda arg: valid_number(arg, min=1))),
|
||||||
|
"default": {
|
||||||
|
"stall": Option(False, type=valid_bool),
|
||||||
|
"cdrom": Option(False, type=valid_bool),
|
||||||
|
"rw": Option(True, type=valid_bool),
|
||||||
|
"removable": Option(True, type=valid_bool),
|
||||||
|
"fua": Option(True, type=valid_bool),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,17 @@ def main(argv: Optional[List[str]]=None) -> None:
|
|||||||
load_hid=True,
|
load_hid=True,
|
||||||
load_atx=True,
|
load_atx=True,
|
||||||
load_msd=True,
|
load_msd=True,
|
||||||
)[2].kvmd
|
)[2]
|
||||||
|
|
||||||
with gpio.bcm():
|
with gpio.bcm():
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
msd_kwargs = config.kvmd.msd._unpack(ignore=["type"])
|
||||||
|
if config.kvmd.msd.type == "otg":
|
||||||
|
msd_kwargs["gadget"] = config.otg.gadget # XXX: Small crutch to pass gadget name to plugin
|
||||||
|
|
||||||
|
config = config.kvmd
|
||||||
|
|
||||||
Server(
|
Server(
|
||||||
auth_manager=AuthManager(
|
auth_manager=AuthManager(
|
||||||
internal_type=config.auth.internal.type,
|
internal_type=config.auth.internal.type,
|
||||||
@@ -67,7 +74,7 @@ def main(argv: Optional[List[str]]=None) -> None:
|
|||||||
|
|
||||||
hid=get_hid_class(config.hid.type)(**config.hid._unpack(ignore=["type"])),
|
hid=get_hid_class(config.hid.type)(**config.hid._unpack(ignore=["type"])),
|
||||||
atx=get_atx_class(config.atx.type)(**config.atx._unpack(ignore=["type"])),
|
atx=get_atx_class(config.atx.type)(**config.atx._unpack(ignore=["type"])),
|
||||||
msd=get_msd_class(config.msd.type)(**config.msd._unpack(ignore=["type"])),
|
msd=get_msd_class(config.msd.type)(**msd_kwargs),
|
||||||
streamer=Streamer(**config.streamer._unpack()),
|
streamer=Streamer(**config.streamer._unpack()),
|
||||||
).run(**config.server._unpack())
|
).run(**config.server._unpack())
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
@@ -49,6 +50,11 @@ def _mkdir(path: str) -> None:
|
|||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
|
|
||||||
|
def _chown(path: str, user: str) -> None:
|
||||||
|
get_logger().info("CHOWN --- %s - %s", user, path)
|
||||||
|
shutil.chown(path, user)
|
||||||
|
|
||||||
|
|
||||||
def _symlink(src: str, dest: str) -> None:
|
def _symlink(src: str, dest: str) -> None:
|
||||||
get_logger().info("SYMLINK - %s --> %s", dest, src)
|
get_logger().info("SYMLINK - %s --> %s", dest, src)
|
||||||
os.symlink(src, dest)
|
os.symlink(src, dest)
|
||||||
@@ -104,7 +110,7 @@ def _create_acm(gadget_path: str, config_path: str) -> None:
|
|||||||
_symlink(func_path, join(config_path, "acm.usb0"))
|
_symlink(func_path, join(config_path, "acm.usb0"))
|
||||||
|
|
||||||
|
|
||||||
def _create_hid(gadget_path: str, config_path: str, hid: Hid, instance: int) -> None:
|
def _create_hid(gadget_path: str, config_path: str, instance: int, hid: Hid) -> None:
|
||||||
func_path = join(gadget_path, f"functions/hid.usb{instance}")
|
func_path = join(gadget_path, f"functions/hid.usb{instance}")
|
||||||
_mkdir(func_path)
|
_mkdir(func_path)
|
||||||
_write(join(func_path, "protocol"), str(hid.protocol))
|
_write(join(func_path, "protocol"), str(hid.protocol))
|
||||||
@@ -114,14 +120,29 @@ def _create_hid(gadget_path: str, config_path: str, hid: Hid, instance: int) ->
|
|||||||
_symlink(func_path, join(config_path, f"hid.usb{instance}"))
|
_symlink(func_path, join(config_path, f"hid.usb{instance}"))
|
||||||
|
|
||||||
|
|
||||||
def _create_msd(gadget_path: str, config_path: str, instance: int, cdrom: bool, rw: bool) -> None:
|
def _create_msd(
|
||||||
|
gadget_path: str,
|
||||||
|
config_path: str,
|
||||||
|
instance: int,
|
||||||
|
user: str,
|
||||||
|
stall: bool,
|
||||||
|
cdrom: bool,
|
||||||
|
rw: bool,
|
||||||
|
removable: bool,
|
||||||
|
fua: bool,
|
||||||
|
) -> None:
|
||||||
|
|
||||||
func_path = join(gadget_path, f"functions/mass_storage.usb{instance}")
|
func_path = join(gadget_path, f"functions/mass_storage.usb{instance}")
|
||||||
_mkdir(func_path)
|
_mkdir(func_path)
|
||||||
_write(join(func_path, "stall"), "0")
|
_write(join(func_path, "stall"), str(int(stall)))
|
||||||
_write(join(func_path, "lun.0/cdrom"), ("1" if cdrom else "0"))
|
_write(join(func_path, "lun.0/cdrom"), str(int(cdrom)))
|
||||||
_write(join(func_path, "lun.0/ro"), ("0" if rw else "1"))
|
_write(join(func_path, "lun.0/ro"), str(int(not rw)))
|
||||||
_write(join(func_path, "lun.0/removable"), "1")
|
_write(join(func_path, "lun.0/removable"), str(int(removable)))
|
||||||
_write(join(func_path, "lun.0/nofua"), "0")
|
_write(join(func_path, "lun.0/nofua"), str(int(not fua)))
|
||||||
|
if user != "root":
|
||||||
|
_chown(join(func_path, "lun.0/cdrom"), user)
|
||||||
|
_chown(join(func_path, "lun.0/ro"), user)
|
||||||
|
_chown(join(func_path, "lun.0/file"), user)
|
||||||
_symlink(func_path, join(config_path, f"mass_storage.usb{instance}"))
|
_symlink(func_path, join(config_path, f"mass_storage.usb{instance}"))
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +169,7 @@ def _cmd_start(config: Section) -> None:
|
|||||||
_mkdir(lang_path)
|
_mkdir(lang_path)
|
||||||
_write(join(lang_path, "manufacturer"), config.otg.manufacturer)
|
_write(join(lang_path, "manufacturer"), config.otg.manufacturer)
|
||||||
_write(join(lang_path, "product"), config.otg.product)
|
_write(join(lang_path, "product"), config.otg.product)
|
||||||
_write(join(lang_path, "serialnumber"), config.otg.serial_number)
|
_write(join(lang_path, "serialnumber"), config.otg.serial)
|
||||||
|
|
||||||
config_path = join(gadget_path, "configs/c.1")
|
config_path = join(gadget_path, "configs/c.1")
|
||||||
_mkdir(config_path)
|
_mkdir(config_path)
|
||||||
@@ -162,16 +183,16 @@ def _cmd_start(config: Section) -> None:
|
|||||||
|
|
||||||
if config.kvmd.hid.type == "otg":
|
if config.kvmd.hid.type == "otg":
|
||||||
logger.info("Required HID")
|
logger.info("Required HID")
|
||||||
_create_hid(gadget_path, config_path, KEYBOARD_HID, 0)
|
_create_hid(gadget_path, config_path, 0, KEYBOARD_HID)
|
||||||
_create_hid(gadget_path, config_path, MOUSE_HID, 1)
|
_create_hid(gadget_path, config_path, 1, MOUSE_HID)
|
||||||
|
|
||||||
if config.kvmd.msd.type == "otg":
|
if config.kvmd.msd.type == "otg":
|
||||||
logger.info("Required MSD")
|
logger.info("Required MSD")
|
||||||
_create_msd(gadget_path, config_path, 0, cdrom=True, rw=False)
|
_create_msd(gadget_path, config_path, 0, config.otg.msd.user, **config.otg.msd.default._unpack()) # pylint: disable=protected-access
|
||||||
if config.otg.drives.enabled:
|
if config.otg.drives.enabled:
|
||||||
logger.info("Required MSD extra drives: %d", config.otg.drives.count)
|
logger.info("Required MSD extra drives: %d", config.otg.drives.count)
|
||||||
for instance in range(config.otg.drives.count):
|
for instance in range(config.otg.drives.count):
|
||||||
_create_msd(gadget_path, config_path, instance + 1, cdrom=False, rw=True)
|
_create_msd(gadget_path, config_path, instance + 1, "root", **config.otg.drives.default._unpack()) # pylint: disable=protected-access
|
||||||
|
|
||||||
logger.info("Enabling the gadget ...")
|
logger.info("Enabling the gadget ...")
|
||||||
_write(join(gadget_path, "UDC"), udc)
|
_write(join(gadget_path, "UDC"), udc)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ def _remount(path: str, rw: bool) -> None:
|
|||||||
|
|
||||||
def _mkdir(path: str) -> None:
|
def _mkdir(path: str) -> None:
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
_log(f"MKDIR {path} ...")
|
_log(f"MKDIR --- {path}")
|
||||||
try:
|
try:
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@@ -82,7 +82,7 @@ def _mkdir(path: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _chown(path: str, user: str) -> None:
|
def _chown(path: str, user: str) -> None:
|
||||||
_log(f"CHOWN {user} {path} ...")
|
_log(f"CHOWN --- {user} - {path}")
|
||||||
try:
|
try:
|
||||||
shutil.chown(path, user)
|
shutil.chown(path, user)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|||||||
Reference in New Issue
Block a user