diff --git a/Makefile b/Makefile index 0f5dd226..81191e1b 100644 --- a/Makefile +++ b/Makefile @@ -284,12 +284,10 @@ run-stage-0: run-build-dev: $(DOCKER) buildx build -t registry.cn-hangzhou.aliyuncs.com/silentwind/kvmd:dev \ - --progress plain \ --platform linux/amd64,linux/arm64,linux/arm/v7 \ -f build/Dockerfile . \ --push $(DOCKER) buildx build -t silentwind0/kvmd:dev \ - --progress plain \ --platform linux/amd64,linux/arm64,linux/arm/v7 \ -f build/Dockerfile . \ --push diff --git a/build/Dockerfile b/build/Dockerfile index 1a969fc3..5ef333e2 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -41,10 +41,10 @@ COPY web/ /usr/share/kvmd/web/ COPY build/platform scripts/kvmd-gencert /usr/share/kvmd/ COPY contrib/keymaps /usr/share/kvmd/keymaps COPY kvmd/ build/init.sh /kvmd/ -COPY configs/kvmd/* /etc/kvmd_backup/ -COPY configs/nginx/* /etc/kvmd_backup/nginx/ -COPY configs/janus/* /etc/kvmd_backup/janus/ -COPY configs/hw_info/* /etc/kvmd_backup/hw_info/ -COPY testenv/js/* /usr/share/janus/javascript/ +COPY configs/kvmd/ /etc/kvmd_backup/ +COPY configs/nginx/ /etc/kvmd_backup/nginx/ +COPY configs/janus/ /etc/kvmd_backup/janus/ +COPY configs/hw_info/ /etc/kvmd_backup/hw_info/ +COPY testenv/js/ /usr/share/janus/javascript/ ENTRYPOINT ["/kvmd/init.sh"] \ No newline at end of file diff --git a/build/init.sh b/build/init.sh index ddd946dc..edbf4b52 100755 --- a/build/init.sh +++ b/build/init.sh @@ -125,7 +125,7 @@ fi #Trying usb_gadget if [ "$OTG" == "1" ]; then echo "Trying OTG Port..." - rm -r /run/kvmd/otg + rm -r /run/kvmd/otg &> /dev/null modprobe libcomposite || echo -e "${RED}Linux libcomposite module modprobe failed.${NC}" python -m kvmd.apps.otg start \ && ln -s /dev/hidg1 /dev/kvmd-hid-mouse \ diff --git a/configs/kvmd/atx.sh b/configs/kvmd/atx.sh new file mode 100755 index 00000000..d074634b --- /dev/null +++ b/configs/kvmd/atx.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +echo $ATX +case $ATX in + GPIO) + CUSTOMATX=gpio + ;; + USBRELAY_HID) + CUSTOMATX=usbrelay_hid + ;; + *) + echo "No thing." + exit -1 +esac + +#$1 option: short long reset +exec /etc/kvmd/custom_atx/$CUSTOMATX.sh $1 \ No newline at end of file diff --git a/configs/kvmd/gpio.sh b/configs/kvmd/custom_atx/gpio.sh similarity index 100% rename from configs/kvmd/gpio.sh rename to configs/kvmd/custom_atx/gpio.sh diff --git a/configs/kvmd/custom_atx/usbrelay_hid.py b/configs/kvmd/custom_atx/usbrelay_hid.py new file mode 100755 index 00000000..2009e5cf --- /dev/null +++ b/configs/kvmd/custom_atx/usbrelay_hid.py @@ -0,0 +1,52 @@ +import sys +import hid + +VENDOR_ID = 0x5131 +PRODUCT_ID = 0x2007 + +def find_usbrelay(): + for device in hid.enumerate(): + if device.get("vendor_id") == VENDOR_ID and device.get("product_id") == PRODUCT_ID: + return device + return None + +def send_command(device_info, channel, onoff): + device = hid.device() + device.open(device_info['vendor_id'], device_info['product_id']) + if device is None: + print("Failed to open device.") + return + + try: + cmd = [0xA0, channel, onoff, 0xA0 + channel + onoff] + device.write(bytearray(cmd)) + finally: + device.close() + +def main(): + if len(sys.argv) != 3: + print("Usage:\n" + "\tpython script.py id on|off") + return + + try: + id = int(sys.argv[1]) + if sys.argv[2].lower() == 'on': + onoff = 1 + elif sys.argv[2].lower() == 'off': + onoff = 0 + else: + raise ValueError + except ValueError: + print("Invalid command, use 'on' or 'off'") + return + + device_info = find_usbrelay() + if device_info is None: + print("USB relay not found") + else: + send_command(device_info, id, onoff) + print(f"Sent command to channel {id}: {'ON' if onoff else 'OFF'}") + +if __name__ == "__main__": + main() diff --git a/configs/kvmd/custom_atx/usbrelay_hid.sh b/configs/kvmd/custom_atx/usbrelay_hid.sh new file mode 100755 index 00000000..63008bff --- /dev/null +++ b/configs/kvmd/custom_atx/usbrelay_hid.sh @@ -0,0 +1,20 @@ +#!/bin/bash +case $1 in + short) + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 on + sleep 1 + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 off + ;; + long) + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 on + sleep 5 + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 1 off + ;; + reset) + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 2 on + sleep 1 + python3 /etc/kvmd/custom_atx/usbrelay_hid.py 2 off + ;; + *) + echo "No thing." +esac \ No newline at end of file diff --git a/configs/kvmd/override.yaml b/configs/kvmd/override.yaml index c23192c3..18157a10 100644 --- a/configs/kvmd/override.yaml +++ b/configs/kvmd/override.yaml @@ -45,6 +45,53 @@ kvmd: - "--h264-bitrate={h264_bitrate}" - "--h264-gop={h264_gop}" - "--slowdown" + gpio: + drivers: + wol_server1: + type: wol + mac: 2c:56:dc:db:7c:1e + short_press: + type: cmd + cmd: [/etc/kvmd/atx.sh, short] + long_press: + type: cmd + cmd: [/etc/kvmd/atx.sh, long] + reset_press: + type: cmd + cmd: [/etc/kvmd/atx.sh, reset] + scheme: + wol_server1: + driver: wol_server1 + pin: 0 + mode: output + switch: false + short_button: + driver: short_press + pin: 0 + mode: output + switch: false + long_button: + driver: long_press + pin: 0 + mode: output + switch: false + reset_button: + driver: reset_press + pin: 0 + mode: output + switch: false + view: + header: + title: 电源管理 + table: + - ["#电源管理"] + - [] + - ["#短按(开/关机):", short_button|按下] + - ["#长按(强制关机):", long_button|按下] + - ["#重启:", reset_button|按下] + - [] + - ["#网络唤醒"] + - ["#被控机设备", wol_server1|网络唤醒] vnc: keymap: /usr/share/kvmd/keymaps/ru diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index 482bcb5e..be8dd4e5 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -140,6 +140,8 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes self.__region = aiotools.AioExclusiveRegion(GpioChannelIsBusyError, notifier) + self.gettext=Languages().gettext + def is_const(self) -> bool: return (not self.__switch and not self.__pulse_delay)