From ef4d41d315d0b62adb75c6c2b327d2e734fcbf0d Mon Sep 17 00:00:00 2001 From: Ducky Date: Sun, 13 Aug 2023 02:17:17 +0100 Subject: [PATCH] various --- .gitignore | 6 ++++++ usr/local/bin/zio-libvirt-port-forward | 23 +++++++++++++++++++++++ usr/local/libexec/zio-helpers | 1 + 3 files changed, 30 insertions(+) create mode 100644 usr/local/bin/zio-libvirt-port-forward create mode 100644 usr/local/libexec/zio-helpers diff --git a/.gitignore b/.gitignore index bfed0cb..235367d 100644 --- a/.gitignore +++ b/.gitignore @@ -42,5 +42,11 @@ !/usr/local/bin/ /usr/local/bin/* !/usr/local/bin/zio-backup +!/usr/local/bin/zio-libvirt-port-forward !/usr/local/bin/zio-update-caddy !/usr/local/bin/zio-update-rootfs + +# /usr/local/libexec/ +!/usr/local/libexec/ +/usr/local/libexec/* +!/usr/local/libexec/zio-helpers diff --git a/usr/local/bin/zio-libvirt-port-forward b/usr/local/bin/zio-libvirt-port-forward new file mode 100644 index 0000000..f8c89f7 --- /dev/null +++ b/usr/local/bin/zio-libvirt-port-forward @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [[ "$(realpath "$(dirname "$(realpath -s "$0")")/../../../")" == "/" ]]; then + . /usr/local/libexec/zio-helpers +else + . "$(dirname "$(realpath -s "$0")")/../libexec/zio-helpers" +fi + +vm_state="$1" +vm_ip="$2" +vm_port="$3" +vm_proto="$4" +host_port="$5" + +if [ $vm_state == "stopped" ] || [ $vm_state == "reconnect" ]; then + iptables -D FORWARD -o virbr0 -p $vm_proto -d $vm_ip --dport $vm_port -j ACCEPT + iptables -t nat -D PREROUTING -p $vm_proto --dport $host_port -j DNAT --to $vm_ip:$vm_port +fi + +if [ $vm_state == "start" ] || [ $vm_state == "reconnect" ]; then + iptables -I FORWARD -o virbr0 -p $vm_proto -d $vm_ip --dport $vm_port -j ACCEPT + iptables -t nat -I PREROUTING -p $vm_proto --dport $host_port -j DNAT --to $vm_ip:$vm_port +fi \ No newline at end of file diff --git a/usr/local/libexec/zio-helpers b/usr/local/libexec/zio-helpers new file mode 100644 index 0000000..212c4ba --- /dev/null +++ b/usr/local/libexec/zio-helpers @@ -0,0 +1 @@ +#!/usr/bin/env bash \ No newline at end of file