]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
unbound-dhcp-leases-client: A new script to send events to the bridge
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 15:06:23 +0000 (16:06 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 15:06:23 +0000 (16:06 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/rootfiles/common/unbound
config/unbound/unbound-dhcp-leases-client [new file with mode: 0644]
lfs/unbound

index 95dafc4dae6ccbed6194ac67a366de8f89af3abd..6caff464d0690881878d294c84fa6e25a921b871 100644 (file)
@@ -19,6 +19,7 @@ usr/sbin/unbound-checkconf
 usr/sbin/unbound-control
 usr/sbin/unbound-control-setup
 usr/sbin/unbound-dhcp-leases-bridge
+usr/sbin/unbound-dhcp-leases-client
 usr/sbin/unbound-host
 #usr/share/man/man1/unbound-host.1
 #usr/share/man/man3/libunbound.3
diff --git a/config/unbound/unbound-dhcp-leases-client b/config/unbound/unbound-dhcp-leases-client
new file mode 100644 (file)
index 0000000..b1b6291
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2016  Michael Tremer                                          #
+#                                                                             #
+# 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+SOCKET="/var/run/unbound-dhcp-leases-bridge.sock"
+
+main() {
+       local event="${1}"
+       shift
+
+       # Check if we have received an event
+       if [ -z "${event}" ]; then
+               echo "${0}: Missing event" >&2
+               return 2
+       fi
+
+       # Check if the socket exists
+       if [ ! -S "${SOCKET}" ]; then
+               echo "${0}: ${SOCKET} does not exist" >&2
+               return 1
+       fi
+
+       # Connect to the socket
+       coproc NC { nc -U "${SOCKET}"; }
+
+       local arg
+       local response
+
+       # Send the message
+       {
+               # Send the event
+               echo "EVENT=${event}"
+
+               # Send all arguments
+               for arg in $@; do
+                       echo "${arg}"
+               done
+       } >&"${NC[1]}"
+
+       # Close the input part of the connection
+       exec {NC[1]}>&-
+
+       # Capture the response
+       read response <&"${NC[0]}"
+
+       case "${response}" in
+               OK)
+                       return 0
+                       ;;
+
+               *)
+                       echo "${response}" >&2
+                       return 1
+                       ;;
+       esac
+}
+
+main "$@" || exit $?
index f09e76b1b9f1896f923edbdd116500c17d9b9acf..1e5ac9efa417badc2970340a9fb34003b8fda4db 100644 (file)
@@ -99,6 +99,8 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
        # Install DHCP leases bridge
        install -v -m 755 $(DIR_SRC)/config/unbound/unbound-dhcp-leases-bridge \
                /usr/sbin/unbound-dhcp-leases-bridge
+       install -v -m 755 $(DIR_SRC)/config/unbound/unbound-dhcp-leases-client \
+               /usr/sbin/unbound-dhcp-leases-client
 
        # Install key
        -mkdir -pv /var/lib/unbound