From 643d8eaf52c6c54f4bc98c9f1bec7de41bf97213 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 20:23:08 +0200 Subject: [PATCH 01/51] fix dhcp cleanup --- conf/ynh-hotspot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 546d283..f6ba832 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -158,7 +158,7 @@ start_dhcpd() { sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf sed "s|__IP4_NAT_PREFIX__|${ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-ssid${i}.pid fi # Run DHCPv6 server @@ -171,7 +171,7 @@ start_dhcpd() { sed "s|__IP6_DNS__|${ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf sed "s|__IP6_NET__|${ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-ssid${i}.pid fi } @@ -249,13 +249,13 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf + rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf + rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf fi } From c1246b49632d35e8dfb0b1c618399f151896d89f Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 20:35:58 +0200 Subject: [PATCH 02/51] make use of pid files --- conf/ynh-hotspot | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index f6ba832..d3c732b 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -73,13 +73,13 @@ is_forwarding_set() { is_dhcpd6_running() { local i=${1} - ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] } is_dhcpd4_running() { local i=${1} - ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] } is_hostapd_running() { @@ -248,14 +248,14 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" - kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid) + rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" - kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid) + rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf fi } From 2d8b5867942f224453b012fe518e5684c3d22313 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 20:39:02 +0200 Subject: [PATCH 03/51] remove openvpn coupling --- conf/openvpn_90-hotspot | 3 +++ conf/ynh-hotspot | 15 --------------- scripts/backup | 3 +++ scripts/install | 8 ++++++++ scripts/remove | 3 +++ scripts/restore | 3 +++ scripts/upgrade | 7 +++++++ 7 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 conf/openvpn_90-hotspot diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot new file mode 100644 index 0000000..5964ef2 --- /dev/null +++ b/conf/openvpn_90-hotspot @@ -0,0 +1,3 @@ +#!/bin/bash + +systemctl restart ynh-hotspot diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 546d283..26fa6d9 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -20,10 +20,6 @@ # Functions ## State functions -has_vpnclient_app() { - [ -e /tmp/.ynh-vpnclient-started ] -} - has_ip6delegatedprefix() { local i=${1} @@ -353,12 +349,6 @@ if [ "$1" != restart ]; then old_gateway_interface=$(ynh_setting_get hotspot gateway_interface) new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') - # Switch the NAT interface if there is a VPN - ip link show dev tun0 &>/dev/null - if [ "$?" -eq 0 ]; then - new_gateway_interface=tun0 - fi - echo "OK" fi @@ -459,11 +449,6 @@ stop) echo "Stop hostapd" stop_hostapd fi - - # Fix configuration - if has_vpnclient_app; then - ynh-vpnclient start - fi ;; restart) $0 stop diff --git a/scripts/backup b/scripts/backup index 8284b04..8634184 100644 --- a/scripts/backup +++ b/scripts/backup @@ -50,6 +50,9 @@ ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" ynh_backup --src_path="/usr/local/bin/$service_name" +ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-hotspot" +ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-hotspot" + ynh_backup --src_path="/etc/init.d/hostapd" #================================================= diff --git a/scripts/install b/scripts/install index 8032f2a..e82036b 100644 --- a/scripts/install +++ b/scripts/install @@ -165,6 +165,14 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq # Copy init script install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +# Copy openvpn scripts +mkdir -pm 0755 /etc/openvpn/scripts +mkdir -pm 0755 /etc/openvpn/scripts/route-up.d +mkdir -pm 0755 /etc/openvpn/scripts/route-down.d +install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot +install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot + + #================================================= # CONFIGURE HOSTAPD #================================================= diff --git a/scripts/remove b/scripts/remove index 4ccfd27..ae210dd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -54,6 +54,9 @@ ynh_remove_app_dependencies #================================================= ynh_script_progression --message="Removing app main directory..." +ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-hotspot" +ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-hotspot" + # Remove the app directory securely ynh_secure_remove --file="/usr/local/bin/$service_name" diff --git a/scripts/restore b/scripts/restore index fb047d1..ee9580e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -70,6 +70,9 @@ ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" ynh_restore_file --origin_path="/usr/local/bin/$service_name" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-hotspot" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-hotspot" + ynh_restore_file --origin_path="/etc/init.d/hostapd" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 519721e..72a98b4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -141,6 +141,13 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq # Copy init script install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +# Copy openvpn scripts +mkdir -pm 0755 /etc/openvpn/scripts +mkdir -pm 0755 /etc/openvpn/scripts/route-up.d +mkdir -pm 0755 /etc/openvpn/scripts/route-down.d +install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot +install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot + #================================================= # SETUP SYSTEMD #================================================= From dceb955917ed04c7b7a0aa641417b2978478e9ef Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 21:04:42 +0200 Subject: [PATCH 04/51] ensure process from pid is running and remove pid file --- conf/ynh-hotspot | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index d3c732b..8883f2f 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -73,13 +73,13 @@ is_forwarding_set() { is_dhcpd6_running() { local i=${1} - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid") > /dev/null } is_dhcpd4_running() { local i=${1} - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid") > /dev/null } is_hostapd_running() { @@ -249,12 +249,14 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv6-ssid${1}.pid rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv4-ssid${1}.pid rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf fi } From f02097b99ed93a2bf2912cd92635c9667c37fcdc Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 15:22:11 +0200 Subject: [PATCH 05/51] remove multissid --- conf/hostapd.accesspoint.conf | 7 - conf/hostapd.base.conf | 8 +- conf/ynh-hotspot | 432 ++++++++++++---------------------- config_panel.toml | 168 ++----------- scripts/config | 88 ++----- scripts/install | 1 - 6 files changed, 191 insertions(+), 513 deletions(-) delete mode 100644 conf/hostapd.accesspoint.conf diff --git a/conf/hostapd.accesspoint.conf b/conf/hostapd.accesspoint.conf deleted file mode 100644 index a726b1e..0000000 --- a/conf/hostapd.accesspoint.conf +++ /dev/null @@ -1,7 +0,0 @@ -__BSS_COMMENT__bss=__WIFI_INTERFACE__ -ssid=__WIFI_SSID__ -__SEC_COMMENT__wpa=2 -__SEC_COMMENT__wpa_passphrase=__WIFI_PASSPHRASE__ -__SEC_COMMENT__wpa_key_mgmt=WPA-PSK -__SEC_COMMENT__wpa_pairwise=TKIP -__SEC_COMMENT__rsn_pairwise=CCMP diff --git a/conf/hostapd.base.conf b/conf/hostapd.base.conf index 8ea3d7d..64e59eb 100644 --- a/conf/hostapd.base.conf +++ b/conf/hostapd.base.conf @@ -1,8 +1,12 @@ interface=__WIFI_DEVICE__ hw_mode=g -__N_COMMENT__ieee80211n=1 -__N_COMMENT__wmm_enabled=1 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 channel=__WIFI_CHANNEL__ +ssid=__WIFI_SSID__ +__SEC_COMMENT__wpa=2 +__SEC_COMMENT__wpa_passphrase=__WIFI_PASSPHRASE__ +__SEC_COMMENT__wpa_key_mgmt=WPA-PSK +__SEC_COMMENT__wpa_pairwise=TKIP +__SEC_COMMENT__rsn_pairwise=CCMP diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 95eaff3..aaf0b96 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -17,65 +17,49 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +source /usr/share/yunohost/helpers + # Functions ## State functions has_ip6delegatedprefix() { - local i=${1} - - [[ -n "${ip6_net[${i}]}" ]] && [[ "${ip6_net[${i}]}" != "none" ]] + [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]] } ip6addrfromdelegatedprefix() { - local i=${1} - - echo "${ip6_net[${i}]}${i}001" + echo "${ip6_net}1" } is_nat_set() { local gateway_interface=${1} - iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}" } is_ip4nataddr_set() { - local i=${1} - local dev=$(devfromid "${i}") - - ip address show dev "${dev}" 2>/dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" + ip address show dev "${wifi_device}" 2>/dev/null | grep -q "${ip4_nat_prefix}.1/24" } is_ip6addr_set() { - local i=${1} - local dev=$(devfromid "${i}") - - ip address show dev "${dev}" 2>/dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" + ip address show dev "${wifi_device}" 2>/dev/null | grep -q "$(ip6addrfromdelegatedprefix)/64" } is_ip6firewall_set() { - local i=${1} - local dev=$(devfromid "${i}") - - ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}" + ip6tables -w -nvL FORWARD | grep DROP | grep -q "${wifi_device}" } is_forwarding_set() { local ip6=$(sysctl net.ipv6.conf.all.forwarding | awk '{ print $NF; }') local ip4=$(sysctl net.ipv4.conf.all.forwarding | awk '{ print $NF; }') - [ "${ip6}" -eq 1 ] && [ "${ip4}" -eq 1 ] + [[ "${ip6}" -eq 1 ]] && [[ "${ip4}" -eq 1 ]] } is_dhcpd6_running() { - local i=${1} - - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid") > /dev/null + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid") > /dev/null } is_dhcpd4_running() { - local i=${1} - - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid") > /dev/null + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid") > /dev/null } is_hostapd_running() { @@ -83,18 +67,39 @@ is_hostapd_running() { } is_running() { - for i in $(seq 0 $((${multissid} - 1))); do - (has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} \ - && ([ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i} || [ "${ip6_firewall[${i}]}" -eq 0 ]) \ - && is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i}) \ - && is_ip4nataddr_set ${i} && is_dhcpd4_running ${i} - - if [ ! $? -eq 0 ]; then + if has_ip6delegatedprefix; then + if ! is_ip6addr_set; then return 1 fi - done + if [[ "${ip6_firewall}" -eq 1 ]] && ! is_ip6firewall_set; then + return 1 + fi + if ! is_dhcpd6_running; then + return 1 + fi + fi - is_hostapd_running && is_forwarding_set && ([ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}") + if ! is_ip4nataddr_set; then + return 1 + fi + + if ! is_dhcpd4_running; then + return 1 + fi + + if ! is_hostapd_running; then + return 1 + fi + + if ! is_forwarding_set; then + return 1 + fi + + if [[ -n ${new_gateway_interface} ]] && ! is_nat_set "${new_gateway_interface}"; then + return 1 + fi + + return 0 } ## Setters @@ -106,33 +111,26 @@ set_nat() { } set_ipaddr() { - local i=${1} - local dev=$(devfromid "${i}") - - if ! is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Set IPv4 NAT address" - ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + if ! is_ip4nataddr_set; then + echo "hotspot ${wifi_device}: Set IPv4 NAT address" + ip address add "${ip4_nat_prefix}.1/24" dev "${wifi_device}" fi - if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then - echo "hotspot${i}: Set IPv6 address" - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &>/dev/null - ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" + if has_ip6delegatedprefix && ! is_ip6addr_set; then + echo "hotspot ${wifi_device}: Set IPv6 address" + ip address delete "$(ip6addrfromdelegatedprefix)/64" dev tun0 &>/dev/null + ip address add "$(ip6addrfromdelegatedprefix)/64" dev "${wifi_device}" fi } set_ipfirewall() { - local i=${1} - local dev=$(devfromid "${i}") - # Set ipv6 firewalling - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then - echo "hotspot${i}: Set IPv6 firewalling" - ip6tables -w -A FORWARD -i "${dev}" -j ACCEPT - ip6tables -w -A FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - ip6tables -w -A FORWARD -o "${dev}" -j DROP + if has_ip6delegatedprefix && [[ "${ip6_firewall}" -eq 1 ]] && ! is_ip6firewall_set; then + echo "hotspot ${wifi_device}: Set IPv6 firewalling" + ip6tables -w -A FORWARD -i "${wifi_device}" -j ACCEPT + ip6tables -w -A FORWARD -o "${wifi_device}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + ip6tables -w -A FORWARD -o "${wifi_device}" -j DROP fi - } set_forwarding() { @@ -141,62 +139,22 @@ set_forwarding() { } start_dhcpd() { - local i=${1} - local dev=$(devfromid "${i}") - # Run DHCPv4 server - if ! is_dhcpd4_running ${i}; then - echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" - - cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - - sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s|__IP4_NAT_PREFIX__|${ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-ssid${i}.pid + if ! is_dhcpd4_running; then + echo "hotspot ${wifi_device}: Start the DHCPv4 server (dnsmasq)" + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-ssid-${wifi_device}.pid fi # Run DHCPv6 server - if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then - echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" - - cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} - - sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s|__IP6_DNS__|${ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s|__IP6_NET__|${ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-ssid${i}.pid + if has_ip6delegatedprefix && ! is_dhcpd6_running; then + echo "hotspot ${wifi_device}: Start the NDP and DHCPv6 server (dnsmasq)" + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-ssid-${wifi_device}.pid fi } configure_hostapd() { - local ethaddr=$(ip link show dev "${wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }') ip link set addr "${ethaddr}" dev "${wifi_device}" - - cp /etc/hostapd/hostapd.base.conf /etc/hostapd/hostapd.conf - sed "s|__WIFI_DEVICE__|${wifi_device}|g" -i /etc/hostapd/hostapd.conf - sed "s|__WIFI_CHANNEL__|${wifi_channel}|g" -i /etc/hostapd/hostapd.conf - sed "s|__N_COMMENT__||g" -i /etc/hostapd/hostapd.conf - - for i in $(seq 0 $((${multissid} - 1))); do - - [ "${wifi_secure[${i}]}" -eq 1 ] && local sec_comment="" || local sec_comment="#" - [ "${i}" -eq 0 ] && local bss_comment="#" || local bss_comment="" - - cp /etc/hostapd/hostapd.accesspoint.conf /etc/hostapd/hostapd.conf.tmp - - sed "s|__WIFI_INTERFACE__|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s|__WIFI_SSID__|${wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s|__WIFI_PASSPHRASE__|${wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s|__SEC_COMMENT__|${sec_comment}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s|__BSS_COMMENT__|${bss_comment}|g" -i /etc/hostapd/hostapd.conf.tmp - - cat /etc/hostapd/hostapd.conf.tmp >>/etc/hostapd/hostapd.conf - rm /etc/hostapd/hostapd.conf.tmp - done } ## Unsetters @@ -208,29 +166,23 @@ unset_nat() { } unset_ipaddr() { - local i=${1} - local dev=$(devfromid "${i}") - - if is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Unset IPv4 NAT address" - ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + if is_ip4nataddr_set; then + echo "hotspot ${wifi_device}: Unset IPv4 NAT address" + ip address delete "${ip4_nat_prefix}.1/24" dev "${wifi_device}" fi - if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then - echo "hotspot${i}: Unset IPv6 address" - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" + if has_ip6delegatedprefix && is_ip6addr_set; then + echo "hotspot ${wifi_device}: Unset IPv6 address" + ip address delete "$(ip6addrfromdelegatedprefix)/64" dev "${wifi_device}" fi } unset_ipfirewall() { - local i=${1} - local dev=$(devfromid "${i}") - - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then - echo "hotspot${i}: Unset IPv6 firewalling" - ip6tables -w -D FORWARD -i "${dev}" -j ACCEPT - ip6tables -w -D FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - ip6tables -w -D FORWARD -o "${dev}" -j DROP + if has_ip6delegatedprefix && [[ "${ip6_firewall}" -eq 1 ]] && is_ip6firewall_set; then + echo "hotspot ${wifi_device}: Unset IPv6 firewalling" + ip6tables -w -D FORWARD -i "${wifi_device}" -j ACCEPT + ip6tables -w -D FORWARD -o "${wifi_device}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + ip6tables -w -D FORWARD -o "${wifi_device}" -j DROP fi } @@ -240,81 +192,23 @@ unset_forwarding() { } stop_dhcpd() { - local i=${1} - - if is_dhcpd6_running ${i}; then - echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" - kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid) - rm -f /run/dnsmasq/dnsmasq-dhcpdv6-ssid${1}.pid - rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + if is_dhcpd6_running; then + echo "hotspot ${wifi_device}: Stop the NDP and DHCPv6 server (dnsmasq)" + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid fi - if is_dhcpd4_running ${i}; then - echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" - kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid) - rm -f /run/dnsmasq/dnsmasq-dhcpdv4-ssid${1}.pid - rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + if is_dhcpd4_running; then + echo "hotspot ${wifi_device}: Stop the DHCPv4 server (dnsmasq)" + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid fi } -stop_dhcpd4() { - : -} - stop_hostapd() { systemctl stop hostapd } -## Tools - -ynh_setting_get() { - - APP="$1" KEY="$2" python3 - </dev/null; do - sleep 1 - if [ ${i} -gt 20 ]; then - echo "Failed to see hotspot interface showing up in 'ip a'" - stop_hostapd - exit 1 - fi - i=$(($i + 1)) - done - fi fi - # For each registred ssid - for i in $(seq 0 $((${multissid} - 1))); do - set_ipaddr ${i} - set_ipfirewall ${i} - start_dhcpd ${i} - done + set_ipaddr + set_ipfirewall + start_dhcpd # Update dynamic settings - ynh_setting_set hotspot gateway_interface "${new_gateway_interface}" + ynh_app_setting_set hotspot gateway_interface "${new_gateway_interface}" ;; stop) echo "[hotspot] Stopping..." rm -f /tmp/.ynh-hotspot-started - if [ -n "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then + if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then echo "Unset NAT" unset_nat "${old_gateway_interface}" fi @@ -441,11 +313,9 @@ stop) echo "Unset forwarding" unset_forwarding - for i in $(seq 0 $((${multissid} - 1))); do - unset_ipaddr ${i} - unset_ipfirewall ${i} - stop_dhcpd ${i} - done + unset_ipaddr + unset_ipfirewall + stop_dhcpd if is_hostapd_running; then echo "Stop hostapd" @@ -459,12 +329,12 @@ restart) status) exitcode=0 - if [ "${service_enabled}" != "enabled" ]; then + if [[ "${service_enabled}" != "enabled" ]]; then echo "[FAIL] Hotspot Service disabled" exit 1 fi - if [ -z "${wifi_device}" ]; then + if [[ -z "${wifi_device}" ]]; then echo "[FAIL] No wifi device selected. Make sure your wifi antenna is plugged-in / available and select it in the Hotspot admin" exit 1 fi @@ -474,7 +344,7 @@ status) if is_nat_set "${new_gateway_interface}"; then echo "[ OK ] IPv4 NAT set" else - if [ -z "${new_gateway_interface}" ]; then + if [[ -z "${new_gateway_interface}" ]]; then echo "[INFO] No IPv4 NAT set (no internet interface)" else echo "[FAIL] No IPv4 NAT set" @@ -496,53 +366,51 @@ status) exitcode=1 fi - for i in $(seq 0 $((${multissid} - 1))); do - if has_ip6delegatedprefix ${i}; then - echo "[INFO] hotspot${i}: IPv6 delegated prefix found" - echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: $(ip6addrfromdelegatedprefix $i)" + if has_ip6delegatedprefix; then + echo "[INFO] hotspot ${wifi_device}: IPv6 delegated prefix found" + echo "[INFO] hotspot ${wifi_device}: IPv6 address computed from the delegated prefix: $(ip6addrfromdelegatedprefix)" - if is_ip6addr_set ${i}; then - echo "[ OK ] hotspot${i}: IPv6 address set" - else - echo "[FAIL] hotspot${i}: No IPv6 address set" - exitcode=1 - fi - - if is_ip6firewall_set ${i}; then - echo "[ OK ] hotspot${i}: IPv6 firewalling set" - else - if [ "${ip6_firewall[${i}]}" -eq 1 ]; then - echo "[FAIL] hotspot${i}: No IPv6 firewalling set" - else - echo "[INFO] hotspot${i}: No IPv6 firewalling set" - fi - exitcode=1 - fi - - if is_dhcpd6_running ${i}; then - echo "[ OK ] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are running" - else - echo "[FAIL] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are not running" - exitcode=1 - fi + if is_ip6addr_set; then + echo "[ OK ] hotspot ${wifi_device}: IPv6 address set" else - echo "[INFO] hotspot${i}: No IPv6 delegated prefix found" - fi - - if is_dhcpd4_running ${i}; then - echo "[ OK ] hotspot${i}: DHCPv4 server (dnsmasq) is running" - else - echo "[FAIL] hotspot${i}: DHCPv4 (dnsmasq) is not running" + echo "[FAIL] hotspot ${wifi_device}: No IPv6 address set" exitcode=1 fi - if is_ip4nataddr_set ${i}; then - echo "[ OK ] hotspot${i}: IPv4 NAT address set" + if is_ip6firewall_set; then + echo "[ OK ] hotspot ${wifi_device}: IPv6 firewalling set" else - echo "[FAIL] hotspot${i}: No IPv4 NAT address set" + if [[ "${ip6_firewall}" -eq 1 ]]; then + echo "[FAIL] hotspot ${wifi_device}: No IPv6 firewalling set" + else + echo "[INFO] hotspot ${wifi_device}: No IPv6 firewalling set" + fi exitcode=1 fi - done + + if is_dhcpd6_running; then + echo "[ OK ] hotspot ${wifi_device}: NDP and DHCPv6 server (dnsmasq) are running" + else + echo "[FAIL] hotspot ${wifi_device}: NDP and DHCPv6 server (dnsmasq) are not running" + exitcode=1 + fi + else + echo "[INFO] hotspot ${wifi_device}: No IPv6 delegated prefix found" + fi + + if is_dhcpd4_running; then + echo "[ OK ] hotspot ${wifi_device}: DHCPv4 server (dnsmasq) is running" + else + echo "[FAIL] hotspot ${zifi_device}: DHCPv4 (dnsmasq) is not running" + exitcode=1 + fi + + if is_ip4nataddr_set; then + echo "[ OK ] hotspot ${wifi_device}: IPv4 NAT address set" + else + echo "[FAIL] hotspot ${wifi_device}: No IPv4 NAT address set" + exitcode=1 + fi exit ${exitcode} ;; diff --git a/config_panel.toml b/config_panel.toml index 7b11364..71a9384 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -19,7 +19,7 @@ name = "Configuration" visible = "no_antenna" [main.service.status] - ask = "The status of your VPN is unknown." + ask = "The status of your Hotspot is unknown." type = "alert" style = "info" visible = "! no_antenna" @@ -52,194 +52,58 @@ name = "Configuration" visible = "! no_antenna" help = "Changing the channel may help with signal strength depending on neighbour WiFis" - [main.service.multissid] - ask = "Number of hotspots to broadcast" - type = "select" - choices.1 = "1" - choices.2 = "2" - choices.3 = "3" - visible = "! no_antenna" - - [main.hotspot1] - name = "Hotspot 1" + [main.hotspot] + name = "Hotspot" optional = false visible = "! no_antenna" - [main.hotspot1.wifi_ssid__1] + [main.hotspot.wifi_ssid] ask = "Name (SSID)" type = "string" - bind = "array_settings()" pattern.regexp = '^[\w \-]{1,32}$' pattern.error = "SSID in this app are limited to letter, number space, dash and underscores." - [main.hotspot1.wifi_secure__1] + [main.hotspot.wifi_secure] ask = "Secure" type = "boolean" - bind = "array_settings()" - [main.hotspot1.wifi_passphrase__1] + [main.hotspot.wifi_passphrase] ask = "Password (WPA2)" type = "string" - bind = "array_settings()" redact = true optional = true - visible = "wifi_secure__1" + visible = "wifi_secure" pattern.regexp = '^[a-zA-Z0-9]{8,63}$' pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars" - [main.hotspot1.advanced__1] + [main.hotspot.advanced] ask = "Advanced settings" type = "boolean" - bind = "array_settings()" - [main.hotspot1.ip4_nat_prefix__1] + [main.hotspot.ip4_nat_prefix] ask = "IPv4 NAT prefix (/24)" type = "string" - bind = "array_settings()" - visible = "advanced__1" + visible = "advanced" pattern.regexp = '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' pattern.error = "Please provide a private /24 range in the format xxx.xxx.xxx" - [main.hotspot1.ip6_net__1] + [main.hotspot.ip6_net] ask = "IPv6 delegated prefix" type = "string" - bind = "array_settings()" optional = true - visible = "advanced__1" + visible = "advanced" pattern.regexp = '^[0-9a-fA-F:]+$' pattern.error = "Please provide a valid IPv6 Prefix" - [main.hotspot1.ip6_firewall__1] + [main.hotspot.ip6_firewall] ask = "IPv6 firewall" type = "boolean" - bind = "array_settings()" - visible = "advanced__1" + visible = "advanced" - [main.hotspot1.dns__1] + [main.hotspot.dns] ask = "DNS resolvers" type = "tags" - bind = "array_settings()" - visible = "advanced__1" - pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' - pattern.error = "Not an ip" - - [main.hotspot2] - name = "Hotspot 2" - visible = "! no_antenna && multissid >= 2" - - [main.hotspot2.wifi_ssid__2] - ask = "Name (SSID)" - type = "string" - bind = "array_settings()" - pattern.regexp = '^[\w \-]{1,32}$' - pattern.error = "SSID in this app are limited to letter, number space, dash and underscores." - - [main.hotspot2.wifi_secure__2] - ask = "Secure" - type = "boolean" - bind = "array_settings()" - - [main.hotspot2.wifi_passphrase__2] - ask = "Password (WPA2)" - type = "string" - bind = "array_settings()" - redact = true - visible = "wifi_secure__2" - pattern.regexp = '^[a-zA-Z0-9]{8,63}$' - pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars" - - [main.hotspot2.advanced__2] - ask = "Advanced settings" - type = "boolean" - bind = "array_settings()" - - [main.hotspot2.ip4_nat_prefix__2] - ask = "IPv4 NAT prefix (/24)" - type = "string" - bind = "array_settings()" - visible = "advanced__2" - pattern.regexp = '^[0-9.]{7,15}$' - pattern.error = "Please provide a valid IP" - - [main.hotspot2.ip6_net__2] - ask = "IPv6 delegated prefix" - type = "string" - bind = "array_settings()" - visible = "advanced__2" - pattern.regexp = '^[0-9a-fA-F:]+$' - pattern.error = "Please provide a valid IPv6 Prefix" - - [main.hotspot2.ip6_firewall__2] - ask = "IPv6 firewall" - type = "boolean" - bind = "array_settings()" - visible = "advanced__2" - - [main.hotspot2.dns__2] - ask = "DNS resolvers" - type = "tags" - bind = "array_settings()" - visible = "advanced__2" - pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' - pattern.error = "Not an ip" - - [main.hotspot3] - name = "Hotspot 3" - visible = "! no_antenna && multissid >= 3" - - [main.hotspot3.wifi_ssid__3] - ask = "Name (SSID)" - type = "string" - bind = "array_settings()" - pattern.regexp = '^[\w \-]{1,32}$' - pattern.error = "SSID in this app are limited to letter, number space, dash and underscores." - - [main.hotspot3.wifi_secure__3] - ask = "Secure" - type = "boolean" - bind = "array_settings()" - - [main.hotspot3.wifi_passphrase__3] - ask = "Password (WPA2)" - type = "string" - bind = "array_settings()" - redact = true - visible = "wifi_secure__3" - pattern.regexp = '^[a-zA-Z0-9]{8,63}$' - pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars" - - [main.hotspot3.advanced__3] - ask = "Advanced settings" - type = "boolean" - bind = "array_settings()" - - [main.hotspot3.ip4_nat_prefix__3] - ask = "IPv4 NAT prefix (/24)" - type = "string" - bind = "array_settings()" - visible = "advanced__3" - pattern.regexp = '^[0-9.]{7,15}$' - pattern.error = "Please provide a valid IP" - - [main.hotspot3.ip6_net__3] - ask = "IPv6 delegated prefix" - type = "string" - bind = "array_settings()" - visible = "advanced__3" - pattern.regexp = '^[0-9a-fA-F:]+$' - pattern.error = "Please provide a valid IPv6 Prefix" - - [main.hotspot3.ip6_firewall__3] - ask = "IPv6 firewall" - type = "boolean" - bind = "array_settings()" - visible = "advanced__3" - - [main.hotspot3.dns__3] - ask = "DNS resolvers" - type = "tags" - bind = "array_settings()" - visible = "advanced__3" + visible = "advanced" pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' pattern.error = "Not an ip" diff --git a/scripts/config b/scripts/config index 78fa748..e3fb11d 100644 --- a/scripts/config +++ b/scripts/config @@ -92,112 +92,49 @@ EOF echo "value: '$(ynh_app_setting_get $app wifi_device)'" } -get__array_settings() { - local short_setting="${1%%__*}" - local index="${1#*__}" - IFS='|' read -a values <<< "$(ynh_app_setting_get $app $short_setting)" - echo "value: \"${values[$(($index - 1))]:-}\"" -} - #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= -is_unique() { - local short_setting="$1" - local short_setting__1="$1__1" - local short_setting__2="$1__2" - local short_setting__3="$1__3" - if [[ "${!short_setting__1}" == "${!short_setting__2}" ]] - then - return 1 - elif [ "$multissid" -ge "3" ] && [[ "${!short_setting__1}" == "${!short_setting__3}" ]] - then - return 1 - elif [ "$multissid" -ge "3" ] && [[ "${!short_setting__2}" == "${!short_setting__3}" ]] - then - return 1 - fi - return 0 -} + validate__wifi_ssid() { - local wifi_ssid_var="wifi_ssid__$1" - if [ "$multissid" -ge "$1" ] && [[ -z "${!wifi_ssid_var}" ]] + if [[ -z "${wifi_ssid}" ]] then echo 'SSID required' fi - if ! is_unique wifi_ssid - then - echo 'All Wifi names must be unique' - fi } validate__wifi_passphrase() { - local wifi_secure_var="wifi_secure__$1" - local wifi_passphrase_var="wifi_passphrase__$1" - if [ "$multissid" -ge "$1" ] && [[ "${!wifi_secure_var}" == "1" ]] && [[ -z "${!wifi_passphrase_var}" ]] + if [[ "${wifi_secure}" == "1" ]] && [[ -z "${wifi_passphrase}" ]] then echo 'In WPA2 secure mode, you need to provide a passphrase' fi } validate__ip4_nat_prefix() { - local ip4_nat_prefix_var="ip4_nat_prefix__$1" - if [ "$multissid" -ge "$1" ] && [[ -z "${!ip4_nat_prefix_var}" ]] + if [[ -z "${ip4_nat_prefix}" ]] then echo 'Private IPv4 nat prefix required' fi - if ! is_unique ip4_nat_prefix - then - echo 'All IPv4 prefix must be unique' - fi } validate__dns() { - local dns_var="dns__$1" - local ip6_net_var="dns__$1" - if [ "$multissid" -ge "$1" ] && ! echo "${!dns_var}" | grep -q "\." + if ! echo "${dns}" | grep -q "\." then echo 'IPv4 DNS required' fi - if [ "$multissid" -ge "$1" ] && [[ -n "${!ip6_net_var}" ]] && ! echo "${!dns_var}" | grep -q ":" + if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":" then echo 'IPv6 DNS required' fi } -validate__array_settings() { - local short_setting="${1%%__*}" - local index="${1#*__}" - if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null; - then - validate__$short_setting $index - fi -} - #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= -set__array_settings() { - local short_setting="${1%%__*}" - local index="${1#*__}" - local type="${types[$1]}" - local value="${!1}" - if [[ "$type" == "string" ]] && [ "$multissid" -lt "$index" ] - then - value="" - fi - local values="$(ynh_app_setting_get $app $short_setting | awk "BEGIN{FS=OFS=\"|\"} {\$${index}=\"${value}\"}"1)" - ynh_app_setting_set --app=$app --key=$short_setting --value="$values" - ynh_print_info --message="Configuration key '$short_setting' edited in app settings" -} - #================================================= # OVERWRITING VALIDATE STEP #================================================= -ynh_app_config_validate() { - _ynh_app_config_validate -} #================================================= # OVERWRITING APPLY STEP @@ -209,7 +146,20 @@ ynh_app_config_apply() { /usr/local/bin/ynh-hotspot stop _ynh_app_config_apply + + if [ "${wifi_secure}" -eq 1 ]; then + local sec_comment="" + else + local sec_comment="#" + fi + + ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination"/etc/dnsmasq.dhcpdv4-ssid-${wifi_device}.conf" + if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination"/etc/dnsmasq.dhcpdv6-ssid-${wifi_device}.conf" + fi + # Start vpn client ynh_print_info --message="Starting hotspot service if needed" /usr/local/bin/ynh-hotspot start diff --git a/scripts/install b/scripts/install index e82036b..090700b 100644 --- a/scripts/install +++ b/scripts/install @@ -132,7 +132,6 @@ fi hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') -ynh_app_setting_set --app=$app --key=multissid --value=1 ynh_app_setting_set --app=$app --key=ssid_nb --value=1 ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" ynh_app_setting_set --app=$app --key=wifi_secure --value=1 From 1a4030a094057a570a190262c96e49366e2e162a Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 15:38:01 +0200 Subject: [PATCH 06/51] fix syntax error --- scripts/config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/config b/scripts/config index e3fb11d..8655dfd 100644 --- a/scripts/config +++ b/scripts/config @@ -154,10 +154,10 @@ ynh_app_config_apply() { fi ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination"/etc/dnsmasq.dhcpdv4-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpdv4-ssid-${wifi_device}.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination"/etc/dnsmasq.dhcpdv6-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpdv6-ssid-${wifi_device}.conf" fi # Start vpn client From c05667cdbb8515813c9a05dd701c1c152fa777f0 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 16:20:20 +0200 Subject: [PATCH 07/51] fix dns config --- conf/ynh-hotspot | 15 ++------------- config_panel.toml | 1 + scripts/config | 18 ++++++++++++++++++ scripts/install | 3 ++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index aaf0b96..d375730 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -223,21 +223,10 @@ if [ "$1" != restart ]; then wifi_secure=$(ynh_app_setting_get hotspot wifi_secure) wifi_passphrase=$(ynh_app_setting_get hotspot wifi_passphrase) ip6_firewall=$(ynh_app_setting_get hotspot ip6_firewall) + ip6_dns=$(ynh_app_setting_get hotspot ip6_dns) ip6_net=$(ynh_app_setting_get hotspot ip6_net) - dns=$(ynh_app_setting_get hotspot dns) + ip4_dns=$(ynh_app_setting_get hotspot ip4_dns) ip4_nat_prefix=$(ynh_app_setting_get hotspot ip4_nat_prefix) - ip6_dns="" - ip4_dns="" - for ip in $(echo "${dns}" | tr ',' ' '); do - if [[ "$ip" == *":"* ]]; then - ip6_dns+="[$ip]," - else - ip4_dns+="$ip," - fi - done - # Remove trailing , - ip6_dns="${ip6_dns%%,}" - ip4_dns="${ip4_dns%%,}" old_gateway_interface=$(ynh_app_setting_get hotspot gateway_interface) new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') diff --git a/config_panel.toml b/config_panel.toml index 71a9384..ff286d0 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -103,6 +103,7 @@ name = "Configuration" [main.hotspot.dns] ask = "DNS resolvers" type = "tags" + bind = "null" visible = "advanced" pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$' pattern.error = "Not an ip" diff --git a/scripts/config b/scripts/config index 8655dfd..c683ae8 100644 --- a/scripts/config +++ b/scripts/config @@ -132,6 +132,24 @@ validate__dns() { # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= +set__dns() { + ip6_dns="" + ip4_dns="" + for ip in $(echo "${dns}" | tr ',' ' '); do + if [[ "$ip" == *":"* ]]; then + ip6_dns+="[$ip]," + else + ip4_dns+="$ip," + fi + done + # Remove trailing , + ip6_dns="${ip6_dns%%,}" + ip4_dns="${ip4_dns%%,}" + + ynh_app_setting_set $app ip6_dns "${ip6_dns}" + ynh_app_setting_set $app ip4_dns "${ip4_dns}" +} + #================================================= # OVERWRITING VALIDATE STEP #================================================= diff --git a/scripts/install b/scripts/install index 090700b..4fa79f4 100644 --- a/scripts/install +++ b/scripts/install @@ -139,8 +139,9 @@ ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase} ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value=6 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 +ynh_app_setting_set --app=$app --key=ip6_dns --value="" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" -ynh_app_setting_set --app=$app --key=dns --value="10.0.242.1" +ynh_app_setting_set --app=$app --key=ip4_dns --value="10.0.242.1" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 if [[ -z $wifi_device ]]; then From 4e55c614627edc2139193b20651db4479a57ba5e Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 16:31:09 +0200 Subject: [PATCH 08/51] fix dns config getter --- scripts/config | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/config b/scripts/config index c683ae8..61919a0 100644 --- a/scripts/config +++ b/scripts/config @@ -92,6 +92,14 @@ EOF echo "value: '$(ynh_app_setting_get $app wifi_device)'" } +get__dns() { + ip6_dns=$(ynh_app_setting_get $app ip6_dns | tr -d '[' | tr -d ']') + ip4_dns=$(ynh_app_setting_get $app ip4_dns) + + echo "value: ${ip4_dns},${ip6_dns}" +} + + #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= From 982f4ebe3e3521eaa8a8f84f702fdc196128aada Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 16:36:39 +0200 Subject: [PATCH 09/51] fix dnsmasq config --- scripts/config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/config b/scripts/config index 61919a0..11e4f3d 100644 --- a/scripts/config +++ b/scripts/config @@ -180,10 +180,10 @@ ynh_app_config_apply() { fi ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpdv4-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpdv6-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" fi # Start vpn client From 64075f2dd99547277a94da6677fbd5e06bb48f6e Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 17:14:13 +0200 Subject: [PATCH 10/51] handle new dns settings --- scripts/upgrade | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 72a98b4..a27b9b0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -72,6 +72,31 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi +dns=$(ynh_app_setting_get $app dns) +if [[ -n "${dns}" ]]; then + ip6_dns="" + ip4_dns="" + for ip in $(echo "${dns}" | tr ',' ' '); do + if [[ "$ip" == *":"* ]]; then + ip6_dns+="[$ip]," + else + ip4_dns+="$ip," + fi + done + # Remove trailing , + ip6_dns="${ip6_dns%%,}" + ip4_dns="${ip4_dns%%,}" + + if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then + ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" + if + if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then + ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" + if + + ynh_app_setting_delete $app dns +fi + # Old stuff prior to 2.x ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) From 5b4c94c042a105e4b3945df9dc2adc4fdfdd5848 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 18:02:20 +0200 Subject: [PATCH 11/51] convert multissid settings --- scripts/install | 1 - scripts/upgrade | 25 ++++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 4fa79f4..b3fa5fb 100644 --- a/scripts/install +++ b/scripts/install @@ -132,7 +132,6 @@ fi hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') -ynh_app_setting_set --app=$app --key=ssid_nb --value=1 ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" ynh_app_setting_set --app=$app --key=wifi_secure --value=1 ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}" diff --git a/scripts/upgrade b/scripts/upgrade index a27b9b0..93e6690 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -72,7 +72,26 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi -dns=$(ynh_app_setting_get $app dns) +multissid=$(ynh_app_setting_get --app=$app --key=multissid) +if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then + wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid | cut -d'|' -f 1) + wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure | cut -d'|' -f 1) + wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase | cut -d'|' -f 1) + ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix | cut -d'|' -f 1) + ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net | cut -d'|' -f 1) + ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall | cut -d'|' -f 1) + dns=$(ynh_app_setting_get --app=$app --key=dns | cut -d'|' -f 1) + + ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" + ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}" + ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}" + ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" + ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" + ynh_app_setting_set --app=$app --key=ip6_firewall --value="${ip6_firewall}" +else + dns=$(ynh_app_setting_get --app=$app --key=dns) +fi + if [[ -n "${dns}" ]]; then ip6_dns="" ip4_dns="" @@ -97,6 +116,10 @@ if [[ -n "${dns}" ]]; then ynh_app_setting_delete $app dns fi +if [[ -n ${multissid} ]]; then + ynh_app_setting_delete --app=$app --key=multissid +fi + # Old stuff prior to 2.x ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) From c077514062276b317ac80b6bc751c6c67ca0d6f5 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 18:15:58 +0200 Subject: [PATCH 12/51] typo --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 93e6690..a636f93 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -111,7 +111,7 @@ if [[ -n "${dns}" ]]; then if if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" - if + fi ynh_app_setting_delete $app dns fi From 186ec93570df979d0348208ccfa4d6cd4324cc80 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 20 Aug 2023 18:35:02 +0200 Subject: [PATCH 13/51] typo bis --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index a636f93..c6878d4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -108,7 +108,7 @@ if [[ -n "${dns}" ]]; then if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" - if + fi if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" fi From 40534c2ac4b36be88ae1b30148e17aaf55a9d5c1 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 10:51:37 +0200 Subject: [PATCH 14/51] prefill dns settings from nat and ipv6 prefix --- scripts/config | 21 ++++++++++++++++++--- scripts/install | 7 ++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/config b/scripts/config index 11e4f3d..9c73781 100644 --- a/scripts/config +++ b/scripts/config @@ -93,13 +93,20 @@ EOF } get__dns() { - ip6_dns=$(ynh_app_setting_get $app ip6_dns | tr -d '[' | tr -d ']') + ip6_dns=$(ynh_app_setting_get $app ip6_dns | tr -d '[]') ip4_dns=$(ynh_app_setting_get $app ip4_dns) - + + if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + ip6_dns="${ip6_net}1" + fi + + if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + ip4_dns="${ip4_nat_prefix}.1" + fi + echo "value: ${ip4_dns},${ip6_dns}" } - #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= @@ -154,6 +161,14 @@ set__dns() { ip6_dns="${ip6_dns%%,}" ip4_dns="${ip4_dns%%,}" + if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + ip6_dns="${ip6_net}1" + fi + + if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + ip4_dns="${ip4_nat_prefix}.1" + fi + ynh_app_setting_set $app ip6_dns "${ip6_dns}" ynh_app_setting_set $app ip4_dns "${ip4_dns}" } diff --git a/scripts/install b/scripts/install index b3fa5fb..8bc4568 100644 --- a/scripts/install +++ b/scripts/install @@ -117,14 +117,15 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring hotspot..." +ip6_net="" +ip6_dns="" if [[ ! -v ip6_net ]]; then # if ip6_net not set - ip6_net="" - if [[ -e /tmp/.ynh-vpnclient-started ]]; then vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1) if [[ $vpnclient_ip6_net =~ :: ]]; then ip6_net=${vpnclient_ip6_net} + ip6_dns="${ip6_net}1" fi fi fi @@ -138,7 +139,7 @@ ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase} ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value=6 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 -ynh_app_setting_set --app=$app --key=ip6_dns --value="" +ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" ynh_app_setting_set --app=$app --key=ip4_dns --value="10.0.242.1" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 From ee1f3cd176d49e4fcf2ff18908d8679a870fa532 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 10:52:04 +0200 Subject: [PATCH 15/51] fix restore --- scripts/backup | 5 +---- scripts/restore | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/backup b/scripts/backup index 8634184..793ab93 100644 --- a/scripts/backup +++ b/scripts/backup @@ -40,10 +40,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -for FILE in $(ls /etc/hostapd/hostapd.*.conf 2>/dev/null) -do - ynh_backup --src_path="$FILE" -done +ynh_backup --src_path="/etc/hostapd/hostapd.conf" ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" diff --git a/scripts/restore b/scripts/restore index ee9580e..4c4ff7e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -61,10 +61,8 @@ else pkg_dependencies="$pkg_dependencies $free_firmware_packages" fi -for FILE in $(ls /etc/hostapd/hostapd.conf{.tpl?,} 2>/dev/null) -do - ynh_restore_file --origin_path="$FILE" -done +ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf" + ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" From 676e6d973399f1242491d3bc5462692f574df4f2 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 11:04:39 +0200 Subject: [PATCH 16/51] backup, restore & remove config files --- scripts/backup | 5 +++++ scripts/remove | 11 +++++++---- scripts/restore | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index 793ab93..6dfa463 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,9 +42,13 @@ ynh_print_info --message="Declaring files to be backed up..." #================================================= ynh_backup --src_path="/etc/hostapd/hostapd.conf" +ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" + ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" ynh_backup --src_path="/usr/local/bin/$service_name" diff --git a/scripts/remove b/scripts/remove index ae210dd..6510749 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # STANDARD REMOVE @@ -67,11 +68,13 @@ done # Remove confs ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" +ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" + ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -for FILE in $(ls /etc/hostapd/hostapd.*.conf 2>/dev/null) -do - ynh_secure_remove --file="$FILE" -done +ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" + +ynh_secure_remove --file="/etc/hostapd/hostapd.conf" +ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf" #================================================= # CLOSE A PORT diff --git a/scripts/restore b/scripts/restore index 4c4ff7e..b4f5fe8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -62,9 +63,13 @@ else fi ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf" +ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" + ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" ynh_restore_file --origin_path="/usr/local/bin/$service_name" From d6b5dc62c53936a932aa27418130c43f23ba2e54 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 16:17:22 +0200 Subject: [PATCH 17/51] custom systemd config for hostapd to handle multiple instances --- conf/{hostapd.base.conf => hostapd.conf.tpl} | 0 conf/systemd_hostapd.service | 21 ++++++++++++++++++++ conf/ynh-hotspot | 6 +++--- scripts/backup | 2 +- scripts/config | 7 ++++++- scripts/install | 10 +++------- scripts/remove | 2 +- scripts/restore | 2 +- scripts/upgrade | 11 ++++++++++ 9 files changed, 47 insertions(+), 14 deletions(-) rename conf/{hostapd.base.conf => hostapd.conf.tpl} (100%) create mode 100644 conf/systemd_hostapd.service diff --git a/conf/hostapd.base.conf b/conf/hostapd.conf.tpl similarity index 100% rename from conf/hostapd.base.conf rename to conf/hostapd.conf.tpl diff --git a/conf/systemd_hostapd.service b/conf/systemd_hostapd.service new file mode 100644 index 0000000..c2b3146 --- /dev/null +++ b/conf/systemd_hostapd.service @@ -0,0 +1,21 @@ +[Unit] +Documentation=man:systemd-sysv-generator(8) +SourcePath=/etc/init.d/hostapd +Description=LSB: Advanced IEEE 802.11 management daemon +After=remote-fs.target +After=network-online.target +Wants=network-online.target + +[Service] +Type=forking +Restart=no +TimeoutSec=5min +IgnoreSIGPIPE=no +KillMode=process +GuessMainPID=no +RemainAfterExit=yes +SuccessExitStatus=5 6 +Environment=DAEMON_CONF=/etc/hostapd/hostapd-%i.conf +ExecStart=/etc/init.d/hostapd start +ExecStop=/etc/init.d/hostapd stop +ExecReload=/etc/init.d/hostapd reload diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index d375730..adf5194 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -63,7 +63,7 @@ is_dhcpd4_running() { } is_hostapd_running() { - systemctl is-active hostapd &>/dev/null + systemctl is-active "hostapd@${wifi_device}" &>/dev/null } is_running() { @@ -206,7 +206,7 @@ stop_dhcpd() { } stop_hostapd() { - systemctl stop hostapd + systemctl stop "hostapd@${wifi_device}" } if [ "$1" != restart ]; then @@ -275,7 +275,7 @@ start) configure_hostapd echo "Starting hostapd..." - if ! systemctl start hostapd; then + if ! systemctl start "hostapd@${wifi_device}"; then journalctl -u hostapd -n 100 --no-hostname --no-pager exit 1 fi diff --git a/scripts/backup b/scripts/backup index 6dfa463..ba2defc 100644 --- a/scripts/backup +++ b/scripts/backup @@ -41,7 +41,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="/etc/hostapd/hostapd.conf" +ynh_backup --src_path="/etc/hostapd/hostapd.conf.tpl" ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" diff --git a/scripts/config b/scripts/config index 9c73781..34f5794 100644 --- a/scripts/config +++ b/scripts/config @@ -181,6 +181,7 @@ set__dns() { # OVERWRITING APPLY STEP #================================================= ynh_app_config_apply() { + old_wifi_device=$(ynh_app_setting_get $app wifi_device) # Stop vpn client ynh_print_info --message="Stopping hotspot in order to edit files" @@ -194,7 +195,11 @@ ynh_app_config_apply() { local sec_comment="#" fi - ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" + ynh_secure_remove --file="/etc/hostapd/hostapd-${old_wifi_device}.conf" + ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${old_wifi_device}.conf" + ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${old_wifi_device}.conf" + + ynh_add_config --template="/etc/hostapd/hostapd.conf.tpl" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then diff --git a/scripts/install b/scripts/install index 8bc4568..1e9504c 100644 --- a/scripts/install +++ b/scripts/install @@ -158,7 +158,7 @@ ynh_script_progression --message="Copying configuration files..." mkdir -pm 0755 /etc/dnsmasq.dhcpd/ chown root: /etc/dnsmasq.dhcpd/ -install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/ +install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/hostapd.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl @@ -179,14 +179,8 @@ install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/ ynh_script_progression --message="Configuring hostapd..." ## hostapd -ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd ynh_store_file_checksum --file="/etc/init.d/hostapd" -# We also need to put this in /etc/default/hostapd because on some setup -# like RPi, the version of hostapd is different and /etc/init.d/hostapd -# isnt used ... instead the service is "pure systemd" ... -echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd - # Set default inits # The boot order of these services are important, so they are disabled by default # and the ynh-hotspot service handles them. @@ -201,6 +195,8 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name +# Create custom systemd config for hostapd to handle multiple wifi devices +ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" #================================================= # INTEGRATE SERVICE IN YUNOHOST diff --git a/scripts/remove b/scripts/remove index 6510749..408f31a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -73,7 +73,7 @@ ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" -ynh_secure_remove --file="/etc/hostapd/hostapd.conf" +ynh_secure_remove --file="/etc/hostapd/hostapd.conf.tpl" ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf" #================================================= diff --git a/scripts/restore b/scripts/restore index b4f5fe8..e4d982b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -62,7 +62,7 @@ else pkg_dependencies="$pkg_dependencies $free_firmware_packages" fi -ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf" +ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf.tpl" ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" diff --git a/scripts/upgrade b/scripts/upgrade index c6878d4..9ef90ed 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -120,6 +120,15 @@ if [[ -n ${multissid} ]]; then ynh_app_setting_delete --app=$app --key=multissid fi +ynh_secure_remove --file="/etc/hostapd/hostapd.conf" +ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" +ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" + +for FILE in $(ls /etc/dnsmasq.dhcpd/dhcpdv{4,6}-ssid{0..3}.conf 2>/dev/null); do + ynh_secure_remove --file="$FILE" + ynh_secure_remove --file="$FILE" +done + # Old stuff prior to 2.x ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) @@ -203,6 +212,8 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name +# Create custom systemd config for hostapd to handle multiple wifi devices +ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" #================================================= # GENERIC FINALIZATION From 538826b32e88ab3f448e0d8f5df6e7e957dd0e12 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 18:43:20 +0200 Subject: [PATCH 18/51] enable multi instance --- conf/openvpn_90-hotspot | 2 +- conf/systemd.service | 4 +-- conf/systemd_hostapd.service | 15 ++-------- conf/ynh-hotspot | 55 +++++++++++++++++++++--------------- manifest.json | 2 +- scripts/backup | 20 ++++++------- scripts/config | 18 ++++-------- scripts/install | 42 ++++++++++++++++----------- scripts/remove | 29 +++++++++---------- scripts/restore | 23 +++++++-------- scripts/upgrade | 30 +++++++++++--------- 11 files changed, 119 insertions(+), 121 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 5964ef2..98bb699 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -1,3 +1,3 @@ #!/bin/bash -systemctl restart ynh-hotspot +systemctl restart __SERVICE_NAME__ diff --git a/conf/systemd.service b/conf/systemd.service index 6268e69..1537aca 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,8 +6,8 @@ After=network.target [Service] Type=oneshot User=root -ExecStart=/usr/local/bin/ynh-hotspot start -ExecStop=/usr/local/bin/ynh-hotspot stop +ExecStart=/usr/local/bin/__SERVICE_NAME__ start +ExecStop=/usr/local/bin/__SERVICE_NAME__ stop RemainAfterExit=yes [Install] diff --git a/conf/systemd_hostapd.service b/conf/systemd_hostapd.service index c2b3146..14ad3eb 100644 --- a/conf/systemd_hostapd.service +++ b/conf/systemd_hostapd.service @@ -1,21 +1,12 @@ [Unit] -Documentation=man:systemd-sysv-generator(8) -SourcePath=/etc/init.d/hostapd Description=LSB: Advanced IEEE 802.11 management daemon After=remote-fs.target After=network-online.target Wants=network-online.target [Service] -Type=forking +Type=simple Restart=no TimeoutSec=5min -IgnoreSIGPIPE=no -KillMode=process -GuessMainPID=no -RemainAfterExit=yes -SuccessExitStatus=5 6 -Environment=DAEMON_CONF=/etc/hostapd/hostapd-%i.conf -ExecStart=/etc/init.d/hostapd start -ExecStop=/etc/init.d/hostapd stop -ExecReload=/etc/init.d/hostapd reload +ExecStart=/usr/sbin/hostapd /etc/hostapd/__APP__/hostapd.conf +ExecReload=/bin/kill -HEP $MAINPID diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index adf5194..5f3428f 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -63,7 +63,13 @@ is_dhcpd4_running() { } is_hostapd_running() { - systemctl is-active "hostapd@${wifi_device}" &>/dev/null + systemctl is-active "hostapd@${app}" &>/dev/null +} + +is_other_hostapd_running() { + other_hostapd_services=$(systemctl list-units --state=running hostapd@*.service | grep -v "^hostapd@$app.service") + + [[ -n "${other_hostapd_service}" ]] } is_running() { @@ -206,7 +212,7 @@ stop_dhcpd() { } stop_hostapd() { - systemctl stop "hostapd@${wifi_device}" + systemctl stop "hostapd@${app}" } if [ "$1" != restart ]; then @@ -215,20 +221,21 @@ if [ "$1" != restart ]; then echo -n "Retrieving Yunohost settings... " - service_enabled=$(systemctl is-enabled ynh-hotspot) - wifi_device=$(ynh_app_setting_get hotspot wifi_device) - wifi_channel=$(ynh_app_setting_get hotspot wifi_channel) + app=__APP__ + service_enabled=$(ynh_app_setting_get --app=$app --key=service_enabled) + wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) + wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) - wifi_ssid=$(ynh_app_setting_get hotspot wifi_ssid) - wifi_secure=$(ynh_app_setting_get hotspot wifi_secure) - wifi_passphrase=$(ynh_app_setting_get hotspot wifi_passphrase) - ip6_firewall=$(ynh_app_setting_get hotspot ip6_firewall) - ip6_dns=$(ynh_app_setting_get hotspot ip6_dns) - ip6_net=$(ynh_app_setting_get hotspot ip6_net) - ip4_dns=$(ynh_app_setting_get hotspot ip4_dns) - ip4_nat_prefix=$(ynh_app_setting_get hotspot ip4_nat_prefix) + wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) + wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) + wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) + ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) + ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns) + ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) + ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) + ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) - old_gateway_interface=$(ynh_app_setting_get hotspot gateway_interface) + old_gateway_interface=$(ynh_app_setting_get --app=$app --key=gateway_interface) new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') echo "OK" @@ -252,7 +259,7 @@ start) fi echo "[hotspot] Starting..." - touch /tmp/.ynh-hotspot-started + touch /tmp/.${service_name}-started # Check old state of the ipv4 NAT settings if [[ -n "${old_gateway_interface}" ]] && [[ "${new_gateway_interface}" != "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then @@ -275,7 +282,7 @@ start) configure_hostapd echo "Starting hostapd..." - if ! systemctl start "hostapd@${wifi_device}"; then + if ! systemctl start "hostapd@${app}"; then journalctl -u hostapd -n 100 --no-hostname --no-pager exit 1 fi @@ -292,16 +299,18 @@ start) ;; stop) echo "[hotspot] Stopping..." - rm -f /tmp/.ynh-hotspot-started + rm -f /tmp/.${service_name}-started - if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then - echo "Unset NAT" - unset_nat "${old_gateway_interface}" + if ! is_other_hostapd_running; then + if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then + echo "Unset NAT" + unset_nat "${old_gateway_interface}" + fi + + echo "Unset forwarding" + unset_forwarding fi - echo "Unset forwarding" - unset_forwarding - unset_ipaddr unset_ipfirewall stop_dhcpd diff --git a/manifest.json b/manifest.json index f2ecc47..efcda4f 100644 --- a/manifest.json +++ b/manifest.json @@ -21,7 +21,7 @@ "requirements": { "yunohost": ">= 4.3.2" }, - "multi_instance": false, + "multi_instance": true, "services": [], "arguments": { "install" : [ diff --git a/scripts/backup b/scripts/backup index ba2defc..cbf88e1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,21 +40,19 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="/etc/hostapd/hostapd.conf.tpl" -ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf" ynh_backup --src_path="/usr/local/bin/$service_name" -ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-hotspot" - -ynh_backup --src_path="/etc/init.d/hostapd" +ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-$service_name" +ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-$service_name" #================================================= # SPECIFIC BACKUP @@ -64,6 +61,7 @@ ynh_backup --src_path="/etc/init.d/hostapd" #================================================= ynh_backup --src_path="/etc/systemd/system/$service_name.service" +ynh_backup --src_path="/etc/systemd/system/hostapd@$app.service" #================================================= # END OF SCRIPT diff --git a/scripts/config b/scripts/config index 34f5794..4c7c40c 100644 --- a/scripts/config +++ b/scripts/config @@ -181,11 +181,9 @@ set__dns() { # OVERWRITING APPLY STEP #================================================= ynh_app_config_apply() { - old_wifi_device=$(ynh_app_setting_get $app wifi_device) - # Stop vpn client ynh_print_info --message="Stopping hotspot in order to edit files" - /usr/local/bin/ynh-hotspot stop + /usr/local/bin/${service_name} stop _ynh_app_config_apply @@ -195,20 +193,16 @@ ynh_app_config_apply() { local sec_comment="#" fi - ynh_secure_remove --file="/etc/hostapd/hostapd-${old_wifi_device}.conf" - ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${old_wifi_device}.conf" - ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${old_wifi_device}.conf" - - ynh_add_config --template="/etc/hostapd/hostapd.conf.tpl" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" fi - # Start vpn client + # Start hotspot ynh_print_info --message="Starting hotspot service if needed" - /usr/local/bin/ynh-hotspot start + /usr/local/bin/${service_name} start } diff --git a/scripts/install b/scripts/install index 1e9504c..725312f 100644 --- a/scripts/install +++ b/scripts/install @@ -30,7 +30,7 @@ firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE app=$YNH_APP_INSTANCE_NAME # the service name must match the service template files -service_name='ynh-hotspot' +service_name=ynh-$app #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -130,6 +130,13 @@ if [[ ! -v ip6_net ]]; then # if ip6_net not set fi fi +ip4_nat_prefix_index=${app##*__} +if [[ "${ip4_nat_prefix_index}" == "${app}" ]]; then + ip4_nat_prefix_index=0 +fi +ip4_nat_prefix="10.${ip4_nat_prefix_index}.242" +ip4_dns="${ip4_nat_prefix}.1" + hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') @@ -141,8 +148,8 @@ ynh_app_setting_set --app=$app --key=wifi_channel --value=6 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" -ynh_app_setting_set --app=$app --key=ip4_dns --value="10.0.242.1" -ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 +ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" +ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 @@ -155,32 +162,33 @@ fi #================================================= ynh_script_progression --message="Copying configuration files..." -mkdir -pm 0755 /etc/dnsmasq.dhcpd/ -chown root: /etc/dnsmasq.dhcpd/ +mkdir -pm 0755 /etc/hostapd/$app/ +chown root: /etc/hostapd/$app/ -install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/hostapd.conf.tpl -install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl -install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl +mkdir -pm 0755 /etc/dnsmasq.$app/ +chown root: /etc/dnsmasq.$app/ + +install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl # Copy init script -install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" # Copy openvpn scripts mkdir -pm 0755 /etc/openvpn/scripts mkdir -pm 0755 /etc/openvpn/scripts/route-up.d mkdir -pm 0755 /etc/openvpn/scripts/route-down.d -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot - +ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-up.d/90-$service_name" +ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-down.d/90-$service_name" +chmod 0755 "/etc/openvpn/scripts/route-up.d/90-${service_name}" +chmod 0755 "/etc/openvpn/scripts/route-down.d/90-${service_name}" #================================================= # CONFIGURE HOSTAPD #================================================= ynh_script_progression --message="Configuring hostapd..." -## hostapd -ynh_store_file_checksum --file="/etc/init.d/hostapd" - # Set default inits # The boot order of these services are important, so they are disabled by default # and the ynh-hotspot service handles them. @@ -196,14 +204,14 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 408f31a..d3acaa9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # STANDARD REMOVE @@ -27,12 +26,9 @@ wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) -if yunohost service status $service_name >/dev/null 2>&1 -then - ynh_script_progression --message="Removing $app service" - yunohost service stop $service_name - yunohost service remove $service_name -fi +ynh_script_progression --message="Removing $app service" +yunohost service stop $service_name +yunohost service remove $service_name #================================================= # STOP AND REMOVE SERVICE @@ -41,6 +37,7 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config --service=$service_name +ynh_remove_systemd_config --service="hostapd@$app" #================================================= # REMOVE DEPENDENCIES @@ -55,26 +52,26 @@ ynh_remove_app_dependencies #================================================= ynh_script_progression --message="Removing app main directory..." -ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-hotspot" +ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-${service_name}" +ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-${service_name}" # Remove the app directory securely ynh_secure_remove --file="/usr/local/bin/$service_name" -for FILE in $(ls /tmp/.ynh-hotspot-* 2>/dev/null) +for FILE in $(ls /tmp/.${service_name}-* 2>/dev/null) do ynh_secure_remove --file="$FILE" done # Remove confs -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf" -ynh_secure_remove --file="/etc/hostapd/hostapd.conf.tpl" -ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf" #================================================= # CLOSE A PORT diff --git a/scripts/restore b/scripts/restore index e4d982b..0fc6027 100644 --- a/scripts/restore +++ b/scripts/restore @@ -29,7 +29,6 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -62,21 +61,19 @@ else pkg_dependencies="$pkg_dependencies $free_firmware_packages" fi -ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf.tpl" -ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory ynh_restore_file --origin_path="/usr/local/bin/$service_name" -ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-hotspot" - -ynh_restore_file --origin_path="/etc/init.d/hostapd" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-${service_name}" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}" #================================================= # SPECIFIC RESTORATION @@ -94,14 +91,14 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service" -systemctl enable $service_name.service --quiet +ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service" #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 9ef90ed..6a9ce48 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -68,7 +68,7 @@ elif [ $firmware_nonfree = "no" ]; then fi if [ -z $service_name ]; then - service_name="ynh-hotspot" + service_name="ynh-$app" ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi @@ -124,8 +124,7 @@ ynh_secure_remove --file="/etc/hostapd/hostapd.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" -for FILE in $(ls /etc/dnsmasq.dhcpd/dhcpdv{4,6}-ssid{0..3}.conf 2>/dev/null); do - ynh_secure_remove --file="$FILE" +for FILE in $(ls /etc/dnsmasq.dhcpd/*.conf 2>/dev/null); do ynh_secure_remove --file="$FILE" done @@ -188,22 +187,27 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Copying configuration..." -mkdir -pm 0755 /etc/dnsmasq.dhcpd/ -chown root: /etc/dnsmasq.dhcpd/ +mkdir -pm 0755 /etc/hostapd/$app/ +chown root: /etc/hostapd/$app/ -install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/ -install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl -install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl +mkdir -pm 0755 /etc/dnsmasq.$app/ +chown root: /etc/dnsmasq.$app/ + +install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl # Copy init script -install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" # Copy openvpn scripts mkdir -pm 0755 /etc/openvpn/scripts mkdir -pm 0755 /etc/openvpn/scripts/route-up.d mkdir -pm 0755 /etc/openvpn/scripts/route-down.d -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot +ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-up.d/90-$service_name" +ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-down.d/90-$service_name" +chmod 0755 "/etc/openvpn/scripts/route-up.d/90-${service_name}" +chmod 0755 "/etc/openvpn/scripts/route-down.d/90-${service_name}" #================================================= # SETUP SYSTEMD @@ -213,7 +217,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" #================================================= # GENERIC FINALIZATION @@ -222,7 +226,7 @@ ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_ #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE From 35eb80ef4ae55475ed5aeeb4c0a9da6053c30c64 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 19:09:11 +0200 Subject: [PATCH 19/51] remove .service prefix --- scripts/install | 2 +- scripts/upgrade | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 725312f..8ad7e66 100644 --- a/scripts/install +++ b/scripts/install @@ -204,7 +204,7 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_hostapd.service" #================================================= # INTEGRATE SERVICE IN YUNOHOST diff --git a/scripts/upgrade b/scripts/upgrade index 6a9ce48..5989d23 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -217,7 +217,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_hostapd.service" #================================================= # GENERIC FINALIZATION From 8f6da7c103113b5c0395ed154a6316b70e4f1f5b Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 19:16:02 +0200 Subject: [PATCH 20/51] fix cleanup --- scripts/remove | 10 ++-------- scripts/upgrade | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/scripts/remove b/scripts/remove index d3acaa9..e7a0a0f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -64,14 +64,8 @@ do done # Remove confs -ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf" - -ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf" - -ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf.tpl" -ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf" +ynh_secure_remove --file="/etc/dnsmasq.$app/" +ynh_secure_remove --file="/etc/hostapd/$app/" #================================================= # CLOSE A PORT diff --git a/scripts/upgrade b/scripts/upgrade index 5989d23..de98521 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -123,10 +123,7 @@ fi ynh_secure_remove --file="/etc/hostapd/hostapd.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" - -for FILE in $(ls /etc/dnsmasq.dhcpd/*.conf 2>/dev/null); do - ynh_secure_remove --file="$FILE" -done +ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" # Old stuff prior to 2.x From ee19798159db5a1e702ee8141e9c96ee0410642a Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 19:19:24 +0200 Subject: [PATCH 21/51] fix exec permissions --- scripts/install | 1 + scripts/upgrade | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index 8ad7e66..88fe8de 100644 --- a/scripts/install +++ b/scripts/install @@ -174,6 +174,7 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq # Copy init script ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" +chmod 0755 "/usr/local/bin/$service_name" # Copy openvpn scripts mkdir -pm 0755 /etc/openvpn/scripts diff --git a/scripts/upgrade b/scripts/upgrade index de98521..24e0880 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -196,6 +196,7 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq # Copy init script ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" +chmod 0755 "/usr/local/bin/$service_name" # Copy openvpn scripts mkdir -pm 0755 /etc/openvpn/scripts From 4bbf247394b2d8e885c4ecc2a15d7154285608b4 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 19:27:40 +0200 Subject: [PATCH 22/51] fix service enabled --- conf/ynh-hotspot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 5f3428f..ed49234 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -248,8 +248,8 @@ start) if is_running; then echo "Already started" exit 0 - elif [[ "${service_enabled}" != "enabled" ]]; then - echo "Not starting because hotspod service is disabled" + elif [[ "${service_enabled}" -eq 0 ]]; then + echo "Not starting because hotspot service is disabled" exit 1 fi @@ -327,7 +327,7 @@ restart) status) exitcode=0 - if [[ "${service_enabled}" != "enabled" ]]; then + if [[ "${service_enabled}" -eq 0 ]]; then echo "[FAIL] Hotspot Service disabled" exit 1 fi From 5d8ea57e2a90699ab17adf7517b16d27ba471b41 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 19:35:38 +0200 Subject: [PATCH 23/51] fix start dhcp --- conf/ynh-hotspot | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index ed49234..a98d557 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -55,11 +55,11 @@ is_forwarding_set() { } is_dhcpd6_running() { - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid") > /dev/null + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-$app.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-$app.pid") > /dev/null } is_dhcpd4_running() { - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid") > /dev/null + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-$app.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-$app.pid") > /dev/null } is_hostapd_running() { @@ -148,13 +148,13 @@ start_dhcpd() { # Run DHCPv4 server if ! is_dhcpd4_running; then echo "hotspot ${wifi_device}: Start the DHCPv4 server (dnsmasq)" - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-ssid-${wifi_device}.pid + dnsmasq -C /etc/dnsmasq.$app/dhcpdv4.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-$app.pid fi # Run DHCPv6 server if has_ip6delegatedprefix && ! is_dhcpd6_running; then echo "hotspot ${wifi_device}: Start the NDP and DHCPv6 server (dnsmasq)" - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-ssid-${wifi_device}.pid + dnsmasq -C /etc/dnsmasq.$app/dhcpdv6.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-$app.pid fi } @@ -200,14 +200,14 @@ unset_forwarding() { stop_dhcpd() { if is_dhcpd6_running; then echo "hotspot ${wifi_device}: Stop the NDP and DHCPv6 server (dnsmasq)" - kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid) - rm -f /run/dnsmasq/dnsmasq-dhcpdv6-ssid-${wifi_device}.pid + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-$app.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv6-$app.pid fi if is_dhcpd4_running; then echo "hotspot ${wifi_device}: Stop the DHCPv4 server (dnsmasq)" - kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid) - rm -f /run/dnsmasq/dnsmasq-dhcpdv4-ssid-${wifi_device}.pid + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-$app.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv4-$app.pid fi } From eaf7b994b03d91655f0f91b3fdd4a35a44e216ca Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 21:59:27 +0200 Subject: [PATCH 24/51] fix unbound var --- scripts/config | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/config b/scripts/config index 4c7c40c..1c26524 100644 --- a/scripts/config +++ b/scripts/config @@ -93,8 +93,10 @@ EOF } get__dns() { - ip6_dns=$(ynh_app_setting_get $app ip6_dns | tr -d '[]') - ip4_dns=$(ynh_app_setting_get $app ip4_dns) + ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) + ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns | tr -d '[]') + ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) + ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then ip6_dns="${ip6_net}1" From da0c4095a8a119a00e7262eaccc123738b229254 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 22:07:05 +0200 Subject: [PATCH 25/51] run config after install --- scripts/install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 88fe8de..468f5dc 100644 --- a/scripts/install +++ b/scripts/install @@ -223,7 +223,8 @@ ynh_script_progression --message="Starting a systemd service..." if [[ $wifi_device == "" ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 else - ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" + ynh_app_config_run $1 + # ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" fi #================================================= From 9b6ba3ec5a195cfa938dd1a954ea10cf30ed6329 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 22:16:26 +0200 Subject: [PATCH 26/51] fix config run --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 468f5dc..f39d45b 100644 --- a/scripts/install +++ b/scripts/install @@ -223,7 +223,7 @@ ynh_script_progression --message="Starting a systemd service..." if [[ $wifi_device == "" ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 else - ynh_app_config_run $1 + ynh_app_config_run apply # ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" fi From baf3dac35f6286469032e0fc671a72c00672f250 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 22:40:58 +0200 Subject: [PATCH 27/51] apply config during install and upgrade --- scripts/install | 24 ++++++++++++++++++++---- scripts/upgrade | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/scripts/install b/scripts/install index f39d45b..6be322a 100644 --- a/scripts/install +++ b/scripts/install @@ -139,12 +139,14 @@ ip4_dns="${ip4_nat_prefix}.1" hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') +wifi_secure=1 +wifi_channel=6 ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" -ynh_app_setting_set --app=$app --key=wifi_secure --value=1 +ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}" ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" -ynh_app_setting_set --app=$app --key=wifi_channel --value=6 +ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}" ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" @@ -197,6 +199,21 @@ systemctl disable hostapd --quiet 2>&1 systemctl stop hostapd 2>&1 systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ... +if [[ -n ${wifi_device} ]]; then + if [ "${wifi_secure}" -eq 1 ]; then + local sec_comment="" + else + local sec_comment="#" + fi + + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" + + if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" + fi +fi + #================================================= # SETUP SYSTEMD #================================================= @@ -223,8 +240,7 @@ ynh_script_progression --message="Starting a systemd service..." if [[ $wifi_device == "" ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 else - ynh_app_config_run apply - # ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" + ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 24e0880..464a152 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -72,15 +72,24 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi +wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) +wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) +wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) +wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) +ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) +ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) +ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) +dns=$(ynh_app_setting_get --app=$app --key=dns) + multissid=$(ynh_app_setting_get --app=$app --key=multissid) if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then - wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid | cut -d'|' -f 1) - wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure | cut -d'|' -f 1) - wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase | cut -d'|' -f 1) - ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix | cut -d'|' -f 1) - ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net | cut -d'|' -f 1) - ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall | cut -d'|' -f 1) - dns=$(ynh_app_setting_get --app=$app --key=dns | cut -d'|' -f 1) + wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid}) + wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure}) + wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase}) + ip4_nat_prefix=$(cut -d'|' -f 1 <<< ${ip4_nat_prefix}) + ip6_net=$(cut -d'|' -f 1 <<< ${ip6_net}) + ip6_firewall=$(cut -d'|' -f 1 <<< ${ip6_firewall}) + dns=$(cut -d'|' -f 1 <<< ${dns}) ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}" @@ -88,8 +97,6 @@ if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" ynh_app_setting_set --app=$app --key=ip6_firewall --value="${ip6_firewall}" -else - dns=$(ynh_app_setting_get --app=$app --key=dns) fi if [[ -n "${dns}" ]]; then @@ -114,6 +121,9 @@ if [[ -n "${dns}" ]]; then fi ynh_app_setting_delete $app dns +else + ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns) + ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) fi if [[ -n ${multissid} ]]; then @@ -194,6 +204,21 @@ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/ho install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl +if [[ -n ${wifi_device} ]]; then + if [ "${wifi_secure}" -eq 1 ]; then + local sec_comment="" + else + local sec_comment="#" + fi + + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" + + if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" + fi +fi + # Copy init script ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" chmod 0755 "/usr/local/bin/$service_name" From 5b2143d814d41ee111a18bdd8570ac3be84e6526 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 22:46:38 +0200 Subject: [PATCH 28/51] stupid bash syntax --- scripts/install | 4 ++-- scripts/upgrade | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 6be322a..0eea9a7 100644 --- a/scripts/install +++ b/scripts/install @@ -201,9 +201,9 @@ systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd if [[ -n ${wifi_device} ]]; then if [ "${wifi_secure}" -eq 1 ]; then - local sec_comment="" + sec_comment="" else - local sec_comment="#" + sec_comment="#" fi ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" diff --git a/scripts/upgrade b/scripts/upgrade index 464a152..e656456 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -206,9 +206,9 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq if [[ -n ${wifi_device} ]]; then if [ "${wifi_secure}" -eq 1 ]; then - local sec_comment="" + sec_comment="" else - local sec_comment="#" + sec_comment="#" fi ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" From 3e0b11f919777965b6e2a56f2fce58d863c443bc Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 22:55:37 +0200 Subject: [PATCH 29/51] fix backup config --- scripts/backup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/backup b/scripts/backup index cbf88e1..1362ed7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -41,13 +41,13 @@ ynh_print_info --message="Declaring files to be backed up..." #================================================= ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl" -ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" +ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory ynh_backup --src_path="/usr/local/bin/$service_name" From b840bac031bd2e60140753d59bd69486748c9fb0 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 23:12:27 +0200 Subject: [PATCH 30/51] delete legacy files only when multissid detected --- scripts/upgrade | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e656456..c8b1a63 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -128,12 +128,12 @@ fi if [[ -n ${multissid} ]]; then ynh_app_setting_delete --app=$app --key=multissid -fi -ynh_secure_remove --file="/etc/hostapd/hostapd.conf" -ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" -ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" + ynh_secure_remove --file="/etc/hostapd/hostapd.conf" + ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" + ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" + ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" +fi # Old stuff prior to 2.x From 5e89bf7d917b24bc25062cea4299d996489e7fe5 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 23:14:42 +0200 Subject: [PATCH 31/51] scan wifi devices earlier --- scripts/upgrade | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index c8b1a63..670e77c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -194,6 +194,9 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Copying configuration..." +hot_reload_usb_wifi_cards +wifi_device=$(iw_devices | awk -F\| '{ print $1 }') + mkdir -pm 0755 /etc/hostapd/$app/ chown root: /etc/hostapd/$app/ @@ -256,9 +259,6 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point" #================================================= ynh_script_progression --message="Starting the hotspot service..." -hot_reload_usb_wifi_cards -wifi_device=$(iw_devices | awk -F\| '{ print $1 }') - if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 wifi_device="" From 60e2cdd1d76cec00b31484af6f046f418512d515 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 23:24:01 +0200 Subject: [PATCH 32/51] fix check hostapd status --- scripts/config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/config b/scripts/config index 1c26524..7cdcbe5 100644 --- a/scripts/config +++ b/scripts/config @@ -37,9 +37,9 @@ get__no_antenna() { get__status() { local service_enabled=$(ynh_app_setting_get $app service_enabled) - if systemctl is-active hostapd -q + if systemctl is-active hostapd@$app -q then - if [ $service_enabled -eq 1 ] + if [[ $service_enabled -eq 1 ]] then cat << EOF style: success @@ -54,7 +54,7 @@ ask: en: Your Hotspot is running, but it shouldn't ! EOF fi - elif [ $service_enabled -eq 1 ] + elif [[ $service_enabled -eq 1 ]] then cat << EOF style: danger @@ -62,7 +62,7 @@ ask: en: |- Your Hotspot is down ! Here are errors logged in the last 5 minutes \`\`\` -$(journalctl -u hostapd -n10 -o cat | sed 's/^/ /g') +$(journalctl -u hostapd@$app -n10 -o cat | sed 's/^/ /g') \`\`\` EOF else From a4a99e70f689360a2ad778dfecf127172c00827d Mon Sep 17 00:00:00 2001 From: HgO Date: Tue, 22 Aug 2023 09:28:36 +0200 Subject: [PATCH 33/51] fix config panel --- scripts/config | 2 ++ scripts/install | 1 + 2 files changed, 3 insertions(+) diff --git a/scripts/config b/scripts/config index 7cdcbe5..6ce9c2f 100644 --- a/scripts/config +++ b/scripts/config @@ -183,6 +183,8 @@ set__dns() { # OVERWRITING APPLY STEP #================================================= ynh_app_config_apply() { + service_name=$(ynh_app_setting_get --app=$app --key=service_name) + # Stop vpn client ynh_print_info --message="Stopping hotspot in order to edit files" /usr/local/bin/${service_name} stop diff --git a/scripts/install b/scripts/install index 0eea9a7..276885f 100644 --- a/scripts/install +++ b/scripts/install @@ -147,6 +147,7 @@ ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}" ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}" +ynh_app_setting_set --app=$app --key=advanced --value=0 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" From 69478cd6e261ea6c9f864e0eff4c7d24a0e1062a Mon Sep 17 00:00:00 2001 From: HgO Date: Tue, 22 Aug 2023 14:51:13 +0200 Subject: [PATCH 34/51] create functions for configuring hostapd and dhcp --- scripts/_common.sh | 20 ++++++++++++++++++++ scripts/config | 14 ++------------ scripts/install | 14 ++------------ scripts/upgrade | 14 ++------------ 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 0687a14..a39ce75 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -48,6 +48,26 @@ function hot_reload_usb_wifi_cards() done } +function configure_hostapd() +{ + if [[ "${wifi_secure}" -eq 1 ]]; then + sec_comment="" + else + sec_comment="#" + fi + + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" +} + +function configure_dhcp() +{ + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" + + if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" + fi +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/config b/scripts/config index 6ce9c2f..b0013ee 100644 --- a/scripts/config +++ b/scripts/config @@ -191,18 +191,8 @@ ynh_app_config_apply() { _ynh_app_config_apply - if [ "${wifi_secure}" -eq 1 ]; then - local sec_comment="" - else - local sec_comment="#" - fi - - ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" - - if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" - fi + configure_hostapd + configure_dhcp # Start hotspot ynh_print_info --message="Starting hotspot service if needed" diff --git a/scripts/install b/scripts/install index 276885f..eec1e7a 100644 --- a/scripts/install +++ b/scripts/install @@ -201,18 +201,8 @@ systemctl stop hostapd 2>&1 systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ... if [[ -n ${wifi_device} ]]; then - if [ "${wifi_secure}" -eq 1 ]; then - sec_comment="" - else - sec_comment="#" - fi - - ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" - - if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" - fi + configure_hostapd + configure_dhcp fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 670e77c..6ae4e2a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -208,18 +208,8 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl if [[ -n ${wifi_device} ]]; then - if [ "${wifi_secure}" -eq 1 ]; then - sec_comment="" - else - sec_comment="#" - fi - - ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" - - if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" - fi + configure_hostapd + configure_dhcp fi # Copy init script From 2a1aa439544fedc38394afc1eb9f078b1b71691f Mon Sep 17 00:00:00 2001 From: HgO Date: Tue, 22 Aug 2023 15:09:30 +0200 Subject: [PATCH 35/51] setup advanced setting --- scripts/upgrade | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 6ae4e2a..78fc062 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,17 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) +wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) +wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) +wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) +advanced=$(ynh_app_setting_get --app=$app --key=advanced) +ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) +ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) +ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) +dns=$(ynh_app_setting_get --app=$app --key=dns) +multissid=$(ynh_app_setting_get --app=$app --key=multissid) + #================================================= # CHECK VERSION #================================================= @@ -72,20 +83,11 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi -wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) -wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) -wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) -wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) -ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) -ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) -ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) -dns=$(ynh_app_setting_get --app=$app --key=dns) - -multissid=$(ynh_app_setting_get --app=$app --key=multissid) if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid}) wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure}) wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase}) + advanced=$(cut -d'|' -f 1 <<< ${advanced}) ip4_nat_prefix=$(cut -d'|' -f 1 <<< ${ip4_nat_prefix}) ip6_net=$(cut -d'|' -f 1 <<< ${ip6_net}) ip6_firewall=$(cut -d'|' -f 1 <<< ${ip6_firewall}) @@ -135,6 +137,10 @@ if [[ -n ${multissid} ]]; then ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" fi +if [[ -z ${advanced} ]]; then + ynh_app_setting_set --app=$app --key=adanced --value=0 +fi + # Old stuff prior to 2.x ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) From ee04b0449bc7700eaa99dfcd8229f82dd0cc7f4d Mon Sep 17 00:00:00 2001 From: HgO Date: Tue, 22 Aug 2023 15:26:24 +0200 Subject: [PATCH 36/51] fix firewall port warning --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index eec1e7a..d89e519 100644 --- a/scripts/install +++ b/scripts/install @@ -220,7 +220,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index 0fc6027..a892475 100644 --- a/scripts/restore +++ b/scripts/restore @@ -98,7 +98,7 @@ ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 78fc062..47c6ebe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -248,7 +248,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 #================================================= # START SYSTEMD SERVICE From 7803699e667d654bc9979b8f83a59fcdc9a2eee0 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 23 Aug 2023 10:24:43 +0200 Subject: [PATCH 37/51] display unused wifi devices --- scripts/_common.sh | 22 +++++++++++++++++++++- scripts/config | 7 ++++--- scripts/install | 2 +- scripts/restore | 6 +++++- scripts/upgrade | 6 +++++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index a39ce75..b6e0acb 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -14,7 +14,27 @@ free_firmware_packages="firmware-ath9k-htc" function iw_devices() { - echo -n $(/sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }') | tr ' ' '|' + /sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }' +} + +function used_iw_devices() +{ + local app_shortname="${app%%__*}" + local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname) + # Remove this app from hotspot apps list + local other_hotspot_apps=$(grep -F -x -v $app <<< ${hotspot_apps}) + for hotspot_app in ${other_hotspot_apps}; do + hotspot_wifi_device=$(ynh_app_setting_get --app=$hotspot_app --key=wifi_device) + if [[ -n ${hotspot_wifi_device} ]]; then + echo "${hotspot_wifi_device}" + fi + done +} + +function unused_iw_devices() +{ + # Only prints devices that are not in the list of used devices + iw_devices | grep -F -v -f <(used_iw_devices) } function check_armbian_nonfree_conflict() diff --git a/scripts/config b/scripts/config index b0013ee..7ad0dc5 100644 --- a/scripts/config +++ b/scripts/config @@ -27,7 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= get__no_antenna() { - if [[ $(iw_devices) == "" ]] + if [[ $(unused_iw_devices) == "" ]] then echo "value: true" else @@ -76,14 +76,15 @@ EOF } get__wifi_device() { - if [[ $(iw_devices) == "" ]] + local unused_wifi_devices=$(unused_iw_devices) + if [[ -z ${unused_wifi_devices} ]] then echo "choices: []" else cat << EOF choices: EOF - for device in $(iw_devices | sed "s/|/ /g") + for device in $unused_wifi_devices do echo " $device: $device" done diff --git a/scripts/install b/scripts/install index d89e519..8643f91 100644 --- a/scripts/install +++ b/scripts/install @@ -138,7 +138,7 @@ ip4_nat_prefix="10.${ip4_nat_prefix_index}.242" ip4_dns="${ip4_nat_prefix}.1" hot_reload_usb_wifi_cards -wifi_device=$(iw_devices | awk -F\| '{ print $1 }') +wifi_device=$(unused_iw_devices | head -n 1) wifi_secure=1 wifi_channel=6 diff --git a/scripts/restore b/scripts/restore index a892475..0f9f615 100644 --- a/scripts/restore +++ b/scripts/restore @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -106,7 +107,10 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point" ynh_script_progression --message="Starting a systemd service..." hot_reload_usb_wifi_cards -wifi_device=$(iw_devices | awk -F\| '{ print $1 }') +if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then + wifi_device=$(unused_iw_devices | head -n 1) + ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" +fi if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 diff --git a/scripts/upgrade b/scripts/upgrade index 47c6ebe..bfad83b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) +wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) @@ -201,7 +202,10 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Copying configuration..." hot_reload_usb_wifi_cards -wifi_device=$(iw_devices | awk -F\| '{ print $1 }') +if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then + wifi_device=$(unused_iw_devices | head -n 1) + ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" +fi mkdir -pm 0755 /etc/hostapd/$app/ chown root: /etc/hostapd/$app/ From 20cd43340cd438a3f334bab861b371beca8ad589 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 23 Aug 2023 15:46:15 +0200 Subject: [PATCH 38/51] Revert "fix firewall port warning" This reverts commit ee04b0449bc7700eaa99dfcd8229f82dd0cc7f4d. --- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 8643f91..fb494bd 100644 --- a/scripts/install +++ b/scripts/install @@ -220,7 +220,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/restore b/scripts/restore index 0f9f615..6bce614 100644 --- a/scripts/restore +++ b/scripts/restore @@ -99,7 +99,7 @@ ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index bfad83b..cbd43ad 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -252,7 +252,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --needs_exposed_ports 547 67 +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE From 1d5d14162c680a0979169c2f6fb9a89eec9b927e Mon Sep 17 00:00:00 2001 From: HgO Date: Thu, 24 Aug 2023 08:45:34 +0200 Subject: [PATCH 39/51] typo --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index cbd43ad..076da9d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -139,7 +139,7 @@ if [[ -n ${multissid} ]]; then fi if [[ -z ${advanced} ]]; then - ynh_app_setting_set --app=$app --key=adanced --value=0 + ynh_app_setting_set --app=$app --key=advanced --value=0 fi # Old stuff prior to 2.x From fbf6e7acc12b6a6068000e9ba67d33f6f65e17b7 Mon Sep 17 00:00:00 2001 From: HgO Date: Thu, 24 Aug 2023 09:32:03 +0200 Subject: [PATCH 40/51] enable multi instance check --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index aafd852..950622f 100644 --- a/check_process +++ b/check_process @@ -13,7 +13,7 @@ upgrade=1 upgrade=1 from_commit=539a1f26c30ba850455c63746d50ce3d8f33b119 backup_restore=1 - multi_instance=0 + multi_instance=1 change_url=0 ;;; Upgrade options ; commit=539a1f26c30ba850455c63746d50ce3d8f33b119 From 2f0dfecca5e918597a7ab5326f1f439366dbe30b Mon Sep 17 00:00:00 2001 From: HgO Date: Thu, 24 Aug 2023 09:56:08 +0200 Subject: [PATCH 41/51] don't guess ipv6 prefix from vpnclient app --- scripts/install | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/install b/scripts/install index e82036b..a98772b 100644 --- a/scripts/install +++ b/scripts/install @@ -117,18 +117,6 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring hotspot..." -if [[ ! -v ip6_net ]]; then # if ip6_net not set - ip6_net="" - - if [[ -e /tmp/.ynh-vpnclient-started ]]; then - vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1) - - if [[ $vpnclient_ip6_net =~ :: ]]; then - ip6_net=${vpnclient_ip6_net} - fi - fi -fi - hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') From c39e31a92cc7f962906236b50f2fb85401c338af Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 17 Sep 2023 21:57:39 +0200 Subject: [PATCH 42/51] Code review / add quotes around suspicious vars that may be empty --- scripts/_common.sh | 2 +- scripts/config | 16 ++++++++-------- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b6e0acb..94a730a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -25,7 +25,7 @@ function used_iw_devices() local other_hotspot_apps=$(grep -F -x -v $app <<< ${hotspot_apps}) for hotspot_app in ${other_hotspot_apps}; do hotspot_wifi_device=$(ynh_app_setting_get --app=$hotspot_app --key=wifi_device) - if [[ -n ${hotspot_wifi_device} ]]; then + if [[ -n "${hotspot_wifi_device}" ]]; then echo "${hotspot_wifi_device}" fi done diff --git a/scripts/config b/scripts/config index 7ad0dc5..b7c9748 100644 --- a/scripts/config +++ b/scripts/config @@ -27,7 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= get__no_antenna() { - if [[ $(unused_iw_devices) == "" ]] + if [[ "$(unused_iw_devices)" == "" ]] then echo "value: true" else @@ -39,7 +39,7 @@ get__status() { local service_enabled=$(ynh_app_setting_get $app service_enabled) if systemctl is-active hostapd@$app -q then - if [[ $service_enabled -eq 1 ]] + if [[ "$service_enabled" -eq 1 ]] then cat << EOF style: success @@ -54,7 +54,7 @@ ask: en: Your Hotspot is running, but it shouldn't ! EOF fi - elif [[ $service_enabled -eq 1 ]] + elif [[ "$service_enabled" -eq 1 ]] then cat << EOF style: danger @@ -77,7 +77,7 @@ EOF get__wifi_device() { local unused_wifi_devices=$(unused_iw_devices) - if [[ -z ${unused_wifi_devices} ]] + if [[ -z "${unused_wifi_devices}" ]] then echo "choices: []" else @@ -99,11 +99,11 @@ get__dns() { ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) - if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then ip6_dns="${ip6_net}1" fi - if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then ip4_dns="${ip4_nat_prefix}.1" fi @@ -164,11 +164,11 @@ set__dns() { ip6_dns="${ip6_dns%%,}" ip4_dns="${ip4_dns%%,}" - if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then ip6_dns="${ip6_net}1" fi - if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then ip4_dns="${ip4_nat_prefix}.1" fi diff --git a/scripts/install b/scripts/install index fb494bd..a8ebb60 100644 --- a/scripts/install +++ b/scripts/install @@ -200,7 +200,7 @@ systemctl disable hostapd --quiet 2>&1 systemctl stop hostapd 2>&1 systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ... -if [[ -n ${wifi_device} ]]; then +if [[ -n "${wifi_device}" ]]; then configure_hostapd configure_dhcp fi diff --git a/scripts/restore b/scripts/restore index 6bce614..43d912c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -107,7 +107,7 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point" ynh_script_progression --message="Starting a systemd service..." hot_reload_usb_wifi_cards -if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then +if [[ -z "$wifi_device" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then wifi_device=$(unused_iw_devices | head -n 1) ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" fi diff --git a/scripts/upgrade b/scripts/upgrade index 076da9d..ce8da75 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -84,7 +84,7 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi -if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then +if [[ -n "${multissid}" ]] && [[ "${multissid}" -gt 1 ]]; then wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid}) wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure}) wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase}) @@ -129,7 +129,7 @@ else ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) fi -if [[ -n ${multissid} ]]; then +if [[ -n "${multissid}" ]]; then ynh_app_setting_delete --app=$app --key=multissid ynh_secure_remove --file="/etc/hostapd/hostapd.conf" @@ -138,7 +138,7 @@ if [[ -n ${multissid} ]]; then ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" fi -if [[ -z ${advanced} ]]; then +if [[ -z "${advanced}" ]]; then ynh_app_setting_set --app=$app --key=advanced --value=0 fi @@ -202,8 +202,8 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Copying configuration..." hot_reload_usb_wifi_cards -if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then - wifi_device=$(unused_iw_devices | head -n 1) +if [[ -z "$wifi_device" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then + wifi_device="$(unused_iw_devices | head -n 1)" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" fi @@ -217,7 +217,7 @@ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/ho install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl -if [[ -n ${wifi_device} ]]; then +if [[ -n "${wifi_device}" ]]; then configure_hostapd configure_dhcp fi From 6a3cc410e94412c4f9da1302acfd989b6bbed96b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 17 Sep 2023 22:07:49 +0200 Subject: [PATCH 43/51] bump version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index efcda4f..8dff521 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Create and manager wifi networks, share Internet access and use YunoHost apps accross wifi", "fr": "Créer et configurer des réseaux wifi, partager l'accès a Internet et utiliser les applications YunoHost via wifi" }, - "version": "2.0~ynh4", + "version": "2.1~ynh1", "url": "https://github.com/labriqueinternet/hotspot_ynh", "license": "AGPL-3.0", "maintainer": { From fffdf4c5b7b48575cc6613512cf90712ce7ab4ef Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Sun, 17 Sep 2023 20:07:52 +0000 Subject: [PATCH 44/51] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f70b8eb..ee3b6d4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in * Combine with the [VPN Client app](https://github.com/labriqueinternet/vpnclient_ynh) to obtain a VPN-protected WiFi -**Shipped version:** 2.0~ynh4 +**Shipped version:** 2.1~ynh1 ## Screenshots diff --git a/README_fr.md b/README_fr.md index 88c5f61..d19c85b 100644 --- a/README_fr.md +++ b/README_fr.md @@ -20,7 +20,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po * À combiner avec l'[app VPN Client](https://github.com/labriqueinternet/vpnclient_ynh) pour obtenir un accès internet aumatiquement protégé par votre VPN -**Version incluse :** 2.0~ynh4 +**Version incluse :** 2.1~ynh1 ## Captures d’écran From ac6cff8a93ff3d515181e7b3265e2fb47ef07679 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 18 Sep 2023 09:39:50 +0200 Subject: [PATCH 45/51] init ip6_net and ip6_dns vars --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index 924b7ee..a94c79a 100644 --- a/scripts/install +++ b/scripts/install @@ -136,6 +136,8 @@ ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}" ynh_app_setting_set --app=$app --key=advanced --value=0 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 +ynh_app_setting_set --app=$app --key=ip6_net --value="" +ynh_app_setting_set --app=$app --key=ip6_dns --value="" ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" From 52057765510fa0b4e1cd98a3797a43d83191d780 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 18 Sep 2023 10:48:18 +0200 Subject: [PATCH 46/51] declare empty vars for ip6_net and ip6_dns --- scripts/install | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index a94c79a..08e09ee 100644 --- a/scripts/install +++ b/scripts/install @@ -117,6 +117,9 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring hotspot..." +ip6_net="" +ip6_dns="" + ip4_nat_prefix_index=${app##*__} if [[ "${ip4_nat_prefix_index}" == "${app}" ]]; then ip4_nat_prefix_index=0 @@ -136,8 +139,8 @@ ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}" ynh_app_setting_set --app=$app --key=advanced --value=0 ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 -ynh_app_setting_set --app=$app --key=ip6_net --value="" -ynh_app_setting_set --app=$app --key=ip6_dns --value="" +ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" +ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" From 2b60fee9f25d2b74ae72b0c24f3b3bd1be8627ab Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 22 Sep 2023 17:33:14 +0200 Subject: [PATCH 47/51] configure dnsmasq to enable dns resolver on wifi interface --- conf/dnsmasq.conf.tpl | 4 ++++ scripts/_common.sh | 5 +++++ scripts/backup | 3 +++ scripts/config | 1 + scripts/install | 2 ++ scripts/remove | 2 ++ scripts/restore | 3 +++ scripts/upgrade | 2 ++ 8 files changed, 22 insertions(+) create mode 100644 conf/dnsmasq.conf.tpl diff --git a/conf/dnsmasq.conf.tpl b/conf/dnsmasq.conf.tpl new file mode 100644 index 0000000..74b638a --- /dev/null +++ b/conf/dnsmasq.conf.tpl @@ -0,0 +1,4 @@ +# Wifi Hotspot app for YunoHost + +# Enable DNS +interface=__WIFI_DEVICE__ diff --git a/scripts/_common.sh b/scripts/_common.sh index 94a730a..485fed0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -79,6 +79,11 @@ function configure_hostapd() ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" } +function configure_dnsmasq() +{ + ynh_add_config --template="/etc/dnsmasq.$app/dnsmasq.conf.tpl" --destination="/etc/dnsmasq.d/$app.conf" +} + function configure_dhcp() { ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" diff --git a/scripts/backup b/scripts/backup index 1362ed7..de71cba 100644 --- a/scripts/backup +++ b/scripts/backup @@ -43,6 +43,9 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl" ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory +ynh_backup --src_path="/etc/dnsmasq.$app/dnsmasq.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.d/$app.conf" --not_mandatory + ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory diff --git a/scripts/config b/scripts/config index b7c9748..b493dbf 100644 --- a/scripts/config +++ b/scripts/config @@ -193,6 +193,7 @@ ynh_app_config_apply() { _ynh_app_config_apply configure_hostapd + configure_dnsmasq configure_dhcp # Start hotspot diff --git a/scripts/install b/scripts/install index 08e09ee..5dd508d 100644 --- a/scripts/install +++ b/scripts/install @@ -162,6 +162,7 @@ mkdir -pm 0755 /etc/dnsmasq.$app/ chown root: /etc/dnsmasq.$app/ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq.conf.tpl /etc/dnsmasq.$app/dnsmasq.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl @@ -200,6 +201,7 @@ systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd if [[ -n "${wifi_device}" ]]; then configure_hostapd + configure_dnsmasq configure_dhcp fi diff --git a/scripts/remove b/scripts/remove index e7a0a0f..c59fe8e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -64,6 +64,8 @@ do done # Remove confs +ynh_secure_remove --file="/etc/dnsmasq.d/$app.conf" + ynh_secure_remove --file="/etc/dnsmasq.$app/" ynh_secure_remove --file="/etc/hostapd/$app/" diff --git a/scripts/restore b/scripts/restore index 43d912c..afd0c60 100644 --- a/scripts/restore +++ b/scripts/restore @@ -65,6 +65,9 @@ fi ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf.tpl" ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dnsmasq.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.d/$app.conf" --not_mandatory + ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory diff --git a/scripts/upgrade b/scripts/upgrade index 0810b57..dfa7c6d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -214,11 +214,13 @@ mkdir -pm 0755 /etc/dnsmasq.$app/ chown root: /etc/dnsmasq.$app/ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl +install -b -o root -g root -m 0644 ../conf/dnsmasq.conf.tpl /etc/dnsmasq.$app/dnsmasq.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl if [[ -n "${wifi_device}" ]]; then configure_hostapd + configure_dnsmasq configure_dhcp fi From fe15d2e5755b4da2a6d28e4ccd73ccf8a815ace7 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 22 Sep 2023 17:41:44 +0200 Subject: [PATCH 48/51] restart dnsmasq to apply config change --- conf/dnsmasq.conf.tpl | 2 +- scripts/_common.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/dnsmasq.conf.tpl b/conf/dnsmasq.conf.tpl index 74b638a..7af2560 100644 --- a/conf/dnsmasq.conf.tpl +++ b/conf/dnsmasq.conf.tpl @@ -1,4 +1,4 @@ # Wifi Hotspot app for YunoHost -# Enable DNS +# Enable DNS resolution on wifi interface interface=__WIFI_DEVICE__ diff --git a/scripts/_common.sh b/scripts/_common.sh index 485fed0..a7f046f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -82,6 +82,7 @@ function configure_hostapd() function configure_dnsmasq() { ynh_add_config --template="/etc/dnsmasq.$app/dnsmasq.conf.tpl" --destination="/etc/dnsmasq.d/$app.conf" + systemctl restart dnsmasq } function configure_dhcp() From 5d7a9ca16e48745239823f983fb4fda3b5d972f6 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 22 Sep 2023 17:44:27 +0200 Subject: [PATCH 49/51] restart dnsmasq to apply config change --- scripts/remove | 1 + scripts/restore | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/remove b/scripts/remove index c59fe8e..e3f3ea5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -65,6 +65,7 @@ done # Remove confs ynh_secure_remove --file="/etc/dnsmasq.d/$app.conf" +systemctl restart dnsmasq ynh_secure_remove --file="/etc/dnsmasq.$app/" ynh_secure_remove --file="/etc/hostapd/$app/" diff --git a/scripts/restore b/scripts/restore index afd0c60..af9c431 100644 --- a/scripts/restore +++ b/scripts/restore @@ -67,6 +67,7 @@ ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory ynh_restore_file --origin_path="/etc/dnsmasq.$app/dnsmasq.conf.tpl" ynh_restore_file --origin_path="/etc/dnsmasq.d/$app.conf" --not_mandatory +systemctl restart dnsmasq ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory From 92876e023e9366d3b2ded7d88dba92cb2fc77a10 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 22 Sep 2023 18:12:20 +0200 Subject: [PATCH 50/51] add checks before closing dhcp ports --- scripts/_common.sh | 14 +++++++++----- scripts/remove | 22 ++++++++++------------ scripts/restore | 9 +++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index a7f046f..13ceb53 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -12,6 +12,14 @@ free_firmware_packages="firmware-ath9k-htc" # PERSONAL HELPERS #================================================= +function other_hotspot_apps() +{ + local app_shortname="${app%%__*}" + local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname) + # Remove this app from hotspot apps list + grep -F -x -v $app <<< ${hotspot_apps} +} + function iw_devices() { /sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }' @@ -19,11 +27,7 @@ function iw_devices() function used_iw_devices() { - local app_shortname="${app%%__*}" - local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname) - # Remove this app from hotspot apps list - local other_hotspot_apps=$(grep -F -x -v $app <<< ${hotspot_apps}) - for hotspot_app in ${other_hotspot_apps}; do + for hotspot_app in $(other_hotspot_apps); do hotspot_wifi_device=$(ynh_app_setting_get --app=$hotspot_app --key=wifi_device) if [[ -n "${hotspot_wifi_device}" ]]; then echo "${hotspot_wifi_device}" diff --git a/scripts/remove b/scripts/remove index e3f3ea5..7b3d158 100644 --- a/scripts/remove +++ b/scripts/remove @@ -58,8 +58,7 @@ ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-${service_name}" # Remove the app directory securely ynh_secure_remove --file="/usr/local/bin/$service_name" -for FILE in $(ls /tmp/.${service_name}-* 2>/dev/null) -do +for FILE in $(ls /tmp/.${service_name}-* 2>/dev/null); do ynh_secure_remove --file="$FILE" done @@ -74,17 +73,16 @@ ynh_secure_remove --file="/etc/hostapd/$app/" # CLOSE A PORT #================================================= -if yunohost firewall list | grep -q "\- 547$" -then - ynh_script_progression --message="Closing port 547" - ynh_exec_warn_less yunohost firewall disallow TCP 547 -fi +if [[ -z "$(other_hotspot_apps)" ]]; then + if yunohost firewall list | grep -q "\- 547$"; then + ynh_script_progression --message="Closing port 547" + ynh_exec_warn_less yunohost firewall disallow TCP 547 + fi - -if yunohost firewall list | grep -q "\- 67$" -then - ynh_script_progression --message="Closing port 67" - ynh_exec_warn_less yunohost firewall disallow TCP 67 + if yunohost firewall list | grep -q "\- 67$"; then + ynh_script_progression --message="Closing port 67" + ynh_exec_warn_less yunohost firewall disallow TCP 67 + fi fi #================================================= diff --git a/scripts/restore b/scripts/restore index af9c431..679bb30 100644 --- a/scripts/restore +++ b/scripts/restore @@ -36,6 +36,15 @@ wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= ynh_script_progression --message="Validating restoration parameters..." +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Configuring firewall..." + +# Update firewall for DHCP +ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547 +ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67 + # Meh idk where to put this ... On RPi, by default wlan is blocked if test -e /usr/sbin/rfkill && rfkill | grep wlan | grep -q -w 'blocked' then From e3a4f9e34ad88162b2e784e9949d95cd279a91b9 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 22 Sep 2023 18:23:16 +0200 Subject: [PATCH 51/51] remove duplicate config --- scripts/install | 8 -------- scripts/upgrade | 7 ------- 2 files changed, 15 deletions(-) diff --git a/scripts/install b/scripts/install index 5dd508d..5f746d4 100644 --- a/scripts/install +++ b/scripts/install @@ -179,14 +179,6 @@ ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openv chmod 0755 "/etc/openvpn/scripts/route-up.d/90-${service_name}" chmod 0755 "/etc/openvpn/scripts/route-down.d/90-${service_name}" -# Copy openvpn scripts -mkdir -pm 0755 /etc/openvpn/scripts -mkdir -pm 0755 /etc/openvpn/scripts/route-up.d -mkdir -pm 0755 /etc/openvpn/scripts/route-down.d -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot - - #================================================= # CONFIGURE HOSTAPD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index dfa7c6d..1d56a39 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -237,13 +237,6 @@ ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openv chmod 0755 "/etc/openvpn/scripts/route-up.d/90-${service_name}" chmod 0755 "/etc/openvpn/scripts/route-down.d/90-${service_name}" -# Copy openvpn scripts -mkdir -pm 0755 /etc/openvpn/scripts -mkdir -pm 0755 /etc/openvpn/scripts/route-up.d -mkdir -pm 0755 /etc/openvpn/scripts/route-down.d -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot -install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot - #================================================= # SETUP SYSTEMD #=================================================