From 017c6dec051ac3a7681ccc5caade338abfb0fcd2 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 15 Nov 2021 19:59:24 +0100 Subject: [PATCH 01/15] Improve hostapd debugging --- conf/ynh-hotspot | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 82623a9..2ab7869 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -387,6 +387,7 @@ case "$1" in start_hostapd ${i} if [ ! $? -eq 0 ]; then + journalctl -u hostapd -n 100 --no-hostname --no-pager exit 1 fi From 3ad8d0fa69a2872967e93060a4c4c6497e98b693 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 15 Nov 2021 22:00:52 +0100 Subject: [PATCH 02/15] jpp des tpl --- conf/dnsmasq_dhcpdv4.conf.tpl | 19 ++----------------- conf/dnsmasq_dhcpdv6.conf.tpl | 21 ++------------------- conf/hostapd.conf.tpl1 | 8 ++++---- conf/hostapd.conf.tpl2 | 15 +++++++-------- conf/ynh-hotspot | 32 ++++++++++++++++---------------- 5 files changed, 31 insertions(+), 64 deletions(-) diff --git a/conf/dnsmasq_dhcpdv4.conf.tpl b/conf/dnsmasq_dhcpdv4.conf.tpl index 9070007..9d19f26 100644 --- a/conf/dnsmasq_dhcpdv4.conf.tpl +++ b/conf/dnsmasq_dhcpdv4.conf.tpl @@ -1,25 +1,10 @@ # Wifi Hotspot app for YunoHost -# Copyright (C) 2015 Julien Vaubourg -# Contribute at https://github.com/labriqueinternet/hotspot_ynh -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . # Do DHCP for this subnet. -dhcp-range=interface:,.2,.254,4h +dhcp-range=interface:__WIFI_DEVICE__,__IP4_NAT_PREFIX__.2,__IP4_NAT_PREFIX__.254,4h # Send DHCPv4 option. -dhcp-option=option:dns-server, +dhcp-option=option:dns-server,__IP4_DNS__ # Set the DHCP server to authoritative mode. In this mode it will barge in # and take over the lease for any client which broadcasts on the network, diff --git a/conf/dnsmasq_dhcpdv6.conf.tpl b/conf/dnsmasq_dhcpdv6.conf.tpl index acff7fa..fb3906e 100644 --- a/conf/dnsmasq_dhcpdv6.conf.tpl +++ b/conf/dnsmasq_dhcpdv6.conf.tpl @@ -1,23 +1,6 @@ -# Wifi Hotspot app for YunoHost -# Copyright (C) 2015 Julien Vaubourg -# Contribute at https://github.com/labriqueinternet/hotspot_ynh -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - # Do DHCP and Router Advertisements for this subnet. Set the A bit in the RA # so that clients can use SLAAC addresses as well as DHCP ones. -dhcp-range=interface:,,slaac,64,4h +dhcp-range=interface:__WIFI_DEVICE__,__IP6_NET__,slaac,64,4h # Send DHCPv6 option. Note [] around IPv6 addresses. -dhcp-option=option6:dns-server, +dhcp-option=option6:dns-server,__IP6_DNS__ diff --git a/conf/hostapd.conf.tpl1 b/conf/hostapd.conf.tpl1 index 8de8433..897e93f 100644 --- a/conf/hostapd.conf.tpl1 +++ b/conf/hostapd.conf.tpl1 @@ -15,12 +15,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -interface= +interface=__WIFI_DEVICE__ hw_mode=g -ieee80211n=1 -wmm_enabled=1 +__N_COMMENT__ieee80211n=1 +__N_COMMENT__wmm_enabled=1 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 -channel= +channel=__WIFI_CHANNEL__ diff --git a/conf/hostapd.conf.tpl2 b/conf/hostapd.conf.tpl2 index 47f58d6..a726b1e 100644 --- a/conf/hostapd.conf.tpl2 +++ b/conf/hostapd.conf.tpl2 @@ -1,8 +1,7 @@ -bss= -ssid= -wpa=2 -wpa_passphrase= -wpa_key_mgmt=WPA-PSK -wpa_pairwise=TKIP -rsn_pairwise=CCMP - +__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/ynh-hotspot b/conf/ynh-hotspot index 2ab7869..8c08e17 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -144,9 +144,9 @@ start_dhcpd6() { cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} - sed "s||${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s||${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s||${ynh_ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + sed "s|__IP6_NET__|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + sed "s|__IP6_DNS__|${ynh_ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 } @@ -157,9 +157,9 @@ start_dhcpd4() { cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - sed "s||${ynh_ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s||${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s||${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s|__IP4_DNS__|${ynh_ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s|__IP4_NAT_PREFIX__|${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 } @@ -170,27 +170,27 @@ start_hostapd() { ethaddr=$(ip link show dev "${ynh_wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }') ip link set addr "${ethaddr}" dev "${ynh_wifi_device}" - sed "s||${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf - sed "s||${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf - sed "s|||g" -i /etc/hostapd/hostapd.conf + sed "s|__WIFI_DEVICE__|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf + sed "s|__WIFI_CHANNEL__|${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf + sed "s|__N_COMMENT__||g" -i /etc/hostapd/hostapd.conf for i in $(seq 0 $((${ynh_multissid} - 1))); do cp /etc/hostapd/hostapd.conf{.tpl2,.tmp} - sed "s||hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s||${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s||${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__WIFI_INTERFACE__|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__WIFI_SSID__|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__WIFI_PASSPHRASE__|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then - sed "s|||g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__SEC_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp else - sed "s||#|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__SEC_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp fi if [ "${i}" -eq 0 ]; then - sed "s||#|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__BSS_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp else - sed "s|||g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__BSS_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp fi cat /etc/hostapd/hostapd.conf.tmp >> /etc/hostapd/hostapd.conf From 38f61c775b94e22d5716542c2d7c2b2880ac2d04 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 15 Nov 2021 22:07:24 +0100 Subject: [PATCH 03/15] ynh_setting_get: epic regex is unreadable and breaks syntax highlighting, let's copypasta the official helper... --- conf/ynh-hotspot | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 8c08e17..3f68bef 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -253,11 +253,19 @@ stop_hostapd() { ## Tools ynh_setting_get() { - app=${1} - setting=${2} - grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$// - # '" + APP="$1" KEY="$2" python3 - < Date: Mon, 15 Nov 2021 22:13:35 +0100 Subject: [PATCH 04/15] Unused vpnclient setting ... --- conf/ynh-hotspot | 6 ------ scripts/install | 1 - 2 files changed, 7 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 3f68bef..d2ba1f3 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -364,12 +364,6 @@ case "$1" in echo "[hotspot] Starting..." touch /tmp/.ynh-hotspot-started - if [ "${new_internet_device}" == tun0 ]; then - ynh_setting_set hotspot vpnclient yes - else - ynh_setting_set hotspot vpnclient no - fi - # Check old state of the ipv4 NAT settings if [ ! -z "${old_internet_device}" -a "${new_internet_device}" != "${old_internet_device}" ]\ && is_nat_set "${old_internet_device}"; then diff --git a/scripts/install b/scripts/install index ddf4403..d516f72 100644 --- a/scripts/install +++ b/scripts/install @@ -143,7 +143,6 @@ ynh_app_setting_set --app=$app --key=ip6_firewall --value=1 ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" ynh_app_setting_set --app=$app --key=dns --value="2001:913::8,2001:910:800::12,80.67.188.188,80.67.169.12" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 -ynh_app_setting_set --app=$app --key=vpnclient --value=no if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 From 00fd220f152e76f3260c28e2a8a1903ad4665140 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 15 Nov 2021 23:45:27 +0100 Subject: [PATCH 05/15] Improve templating seds etc --- ...apd.conf.tpl2 => hostapd.accesspoint.conf} | 0 conf/hostapd.base.conf | 8 ++++++ conf/hostapd.conf.tpl1 | 26 ------------------- conf/ynh-hotspot | 26 +++++++------------ 4 files changed, 17 insertions(+), 43 deletions(-) rename conf/{hostapd.conf.tpl2 => hostapd.accesspoint.conf} (100%) create mode 100644 conf/hostapd.base.conf delete mode 100644 conf/hostapd.conf.tpl1 diff --git a/conf/hostapd.conf.tpl2 b/conf/hostapd.accesspoint.conf similarity index 100% rename from conf/hostapd.conf.tpl2 rename to conf/hostapd.accesspoint.conf diff --git a/conf/hostapd.base.conf b/conf/hostapd.base.conf new file mode 100644 index 0000000..8ea3d7d --- /dev/null +++ b/conf/hostapd.base.conf @@ -0,0 +1,8 @@ +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__ diff --git a/conf/hostapd.conf.tpl1 b/conf/hostapd.conf.tpl1 deleted file mode 100644 index 897e93f..0000000 --- a/conf/hostapd.conf.tpl1 +++ /dev/null @@ -1,26 +0,0 @@ -# Wifi Hotspot app for YunoHost -# Copyright (C) 2015 Julien Vaubourg -# Contribute at https://github.com/labriqueinternet/hotspot_ynh -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -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__ - diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index d2ba1f3..6087e43 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -164,40 +164,32 @@ start_dhcpd4() { dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 } -start_hostapd() { - cp /etc/hostapd/hostapd.conf{.tpl1,} +configure_hostapd() { ethaddr=$(ip link show dev "${ynh_wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }') ip link set addr "${ethaddr}" dev "${ynh_wifi_device}" + cp /etc/hostapd/hostapd.base.conf /etc/hostapd/hostapd.conf sed "s|__WIFI_DEVICE__|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf sed "s|__WIFI_CHANNEL__|${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf sed "s|__N_COMMENT__||g" -i /etc/hostapd/hostapd.conf for i in $(seq 0 $((${ynh_multissid} - 1))); do - cp /etc/hostapd/hostapd.conf{.tpl2,.tmp} + + [ "${ynh_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__|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp sed "s|__WIFI_PASSPHRASE__|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - - if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then - sed "s|__SEC_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp - else - sed "s|__SEC_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp - fi - - if [ "${i}" -eq 0 ]; then - sed "s|__BSS_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp - else - sed "s|__BSS_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp - fi + 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 - - systemctl start hostapd } ## Unsetters From 3100538cbc0f1fa681485ffbcef28e25fd3045d4 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:16:13 +0100 Subject: [PATCH 06/15] Misc formatting, var naming etc --- conf/ynh-hotspot | 371 ++++++++++++++++++++++++----------------------- 1 file changed, 188 insertions(+), 183 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 6087e43..8139c0a 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -25,59 +25,59 @@ has_vpnclient_app() { } has_ip6delegatedprefix() { - i=${1} + local i=${1} - [[ -n "${ynh_ip6_net[${i}]}" ]] && [[ "${ynh_ip6_net[${i}]}" != "none" ]] + [[ -n "${ip6_net[${i}]}" ]] && [[ "${ip6_net[${i}]}" != "none" ]] } ip6addrfromdelegatedprefix() { - i=${1} + local i=${1} - echo "${ynh_ip6_net[${i}]}${i}001" + echo "${ip6_net[${i}]}${i}001" } is_nat_set() { - internet_device=${1} + local gateway_interface=${1} - iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${internet_device}" + iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}" } is_ip4nataddr_set() { - i=${1} + local i=${1} dev=$(devfromid "${i}") - ip address show dev "${dev}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix[${i}]}.1/24" + ip address show dev "${dev}" 2> /dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" } is_ip6addr_set() { - i=${1} + local i=${1} dev=$(devfromid "${i}") ip address show dev "${dev}" 2> /dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" } is_ip6firewall_set() { - i=${1} + local i=${1} dev=$(devfromid "${i}") ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}" } is_forwarding_set() { - ip6=$(sysctl net.ipv6.conf.all.forwarding | awk '{ print $NF; }') - ip4=$(sysctl net.ipv4.conf.all.forwarding | awk '{ print $NF; }') + 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 -a "${ip4}" -eq 1 ] } is_dhcpd6_running() { - i=${1} + local i=${1} $(ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep) } is_dhcpd4_running() { - i=${1} + local i=${1} $(ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep) } @@ -87,9 +87,9 @@ is_hostapd_running() { } is_running() { - for i in $(seq 0 $((${ynh_multissid} - 1))); do + for i in $(seq 0 $((${multissid} - 1))); do ( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}\ - && ( [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i} || [ "${ynh_ip6_firewall[${i}]}" -eq 0 ] )\ + && ( [ "${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} @@ -98,35 +98,35 @@ is_running() { fi done - is_hostapd_running && is_forwarding_set && ( [ -z "${new_internet_device}" ] || is_nat_set "${new_internet_device}" ) + is_hostapd_running && is_forwarding_set && ( [ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}" ) } ## Setters set_nat() { - internet_device=${1} + local gateway_interface=${1} - iptables -w -t nat -A POSTROUTING -o "${internet_device}" -j MASQUERADE + iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE } set_ip4nataddr() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address add "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" } set_ip6addr() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &> /dev/null ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" } set_ip6firewall() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") ip6tables -w -A FORWARD -i "${dev}" -j ACCEPT ip6tables -w -A FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT @@ -139,51 +139,51 @@ set_forwarding() { } start_dhcpd6() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") 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_NET__|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s|__IP6_DNS__|${ynh_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 + sed "s|__IP6_DNS__|${ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 } start_dhcpd4() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - sed "s|__IP4_DNS__|${ynh_ip4_dns[${i}]}|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|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s|__IP4_NAT_PREFIX__|${ynh_ip4_nat_prefix[${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 } configure_hostapd() { - ethaddr=$(ip link show dev "${ynh_wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }') - ip link set addr "${ethaddr}" dev "${ynh_wifi_device}" + 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__|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf - sed "s|__WIFI_CHANNEL__|${ynh_wifi_channel}|g" -i /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 $((${ynh_multissid} - 1))); do + for i in $(seq 0 $((${multissid} - 1))); do - [ "${ynh_wifi_secure[${i}]}" -eq 1 ] && local sec_comment="" || local sec_comment="#" + [ "${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__|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - sed "s|__WIFI_PASSPHRASE__|${ynh_wifi_passphrase[${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 @@ -195,28 +195,28 @@ configure_hostapd() { ## Unsetters unset_nat() { - internet_device=${1} + local gateway_interface=${1} - iptables -w -t nat -D POSTROUTING -o "${internet_device}" -j MASQUERADE + iptables -w -t nat -D POSTROUTING -o "${gateway_interface}" -j MASQUERADE } unset_ip4nataddr() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address delete "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" } unset_ip6addr() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" } unset_ip6firewall() { - i=${1} - dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") ip6tables -w -D FORWARD -i "${dev}" -j ACCEPT ip6tables -w -D FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT @@ -283,10 +283,10 @@ EOF } devfromid() { - i=${1} + local i=${1} if [ "${i}" -eq 0 ]; then - echo "${ynh_wifi_device}" + echo "${wifi_device}" else echo "hotspot${i}" fi @@ -298,41 +298,41 @@ if [ "$1" != restart ]; then echo -n "Retrieving Yunohost settings... " - ynh_service_enabled=$(systemctl is-enabled ynh-hotspot) - ynh_wifi_device=$(ynh_setting_get hotspot wifi_device) - ynh_wifi_channel=$(ynh_setting_get hotspot wifi_channel) - ynh_multissid=$(ynh_setting_get hotspot multissid) + service_enabled=$(systemctl is-enabled ynh-hotspot) + wifi_device=$(ynh_setting_get hotspot wifi_device) + wifi_channel=$(ynh_setting_get hotspot wifi_channel) + multissid=$(ynh_setting_get hotspot multissid) - IFS='|' read -a ynh_wifi_ssid <<< "$(ynh_setting_get hotspot wifi_ssid)" - IFS='|' read -a ynh_wifi_secure <<< "$(ynh_setting_get hotspot wifi_secure)" - IFS='|' read -a ynh_wifi_passphrase <<< "$(ynh_setting_get hotspot wifi_passphrase)" - IFS='|' read -a ynh_ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)" - IFS='|' read -a ynh_ip6_net <<< "$(ynh_setting_get hotspot ip6_net)" - IFS='|' read -a ynh_dns <<< "$(ynh_setting_get hotspot dns)" - IFS='|' read -a ynh_ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)" - for i in $(seq 0 $((${ynh_multissid} - 1))); do - ynh_ip6_dns[${i}]="" - ynh_ip4_dns[${i}]="" - for ip in $(echo "${ynh_dns[${i}]}" | tr ',' ' '); do + IFS='|' read -a wifi_ssid <<< "$(ynh_setting_get hotspot wifi_ssid)" + IFS='|' read -a wifi_secure <<< "$(ynh_setting_get hotspot wifi_secure)" + IFS='|' read -a wifi_passphrase <<< "$(ynh_setting_get hotspot wifi_passphrase)" + IFS='|' read -a ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)" + IFS='|' read -a ip6_net <<< "$(ynh_setting_get hotspot ip6_net)" + IFS='|' read -a dns <<< "$(ynh_setting_get hotspot dns)" + IFS='|' read -a ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)" + for i in $(seq 0 $((${multissid} - 1))); do + ip6_dns[${i}]="" + ip4_dns[${i}]="" + for ip in $(echo "${dns[${i}]}" | tr ',' ' '); do if [[ "$ip" == *":"* ]] then - ynh_ip6_dns[${i}]+="[$ip]," + ip6_dns[${i}]+="[$ip]," else - ynh_ip4_dns[${i}]+="$ip," + ip4_dns[${i}]+="$ip," fi done # Remove trailing , - ynh_ip6_dns[${i}]="${ynh_ip6_dns[${i}]%%,}" - ynh_ip4_dns[${i}]="${ynh_ip4_dns[${i}]%%,}" + ip6_dns[${i}]="${ip6_dns[${i}]%%,}" + ip4_dns[${i}]="${ip4_dns[${i}]%%,}" done - old_internet_device=$(ynh_setting_get hotspot internet_device) - new_internet_device=$(ip route get 1.2.3.4 | awk '{ print $5; }') + 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_internet_device=tun0 + new_gateway_interface=tun0 fi echo "OK" @@ -344,105 +344,110 @@ case "$1" in start) if is_running; then echo "Already started" - elif [ "${ynh_service_enabled}" != "enabled" ]; then - echo "Disabled service" - else + exit 0 + elif [ "${service_enabled}" != "enabled" ]; then + echo "Not starting because hotspod service is disabled" + exit 1 + fi - if [ -z "${ynh_wifi_device}" ]; then - echo "[ERR] No wifi device selected. Make sure your wifi antenna is plugged-in / available and select it in the Hotspot admin" - exitcode=1 + 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 + + echo "[hotspot] Starting..." + touch /tmp/.ynh-hotspot-started + + # Check old state of the ipv4 NAT settings + if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ]\ + && is_nat_set "${old_gateway_interface}"; then + + unset_nat "${old_gateway_interface}" + fi + + # Set ipv4 NAT + if [ ! -z "${new_gateway_interface}" ] && ! is_nat_set "${new_gateway_interface}"; then + echo "Set NAT" + set_nat "${new_gateway_interface}" + fi + + # Set forwarding for ipv6 and ipv4 + if ! is_forwarding_set; then + echo "Set forwarding" + set_forwarding + fi + + # Run hostapd + if ! is_hostapd_running; then + echo "Configuring hostapd" + configure_hostapd + + echo "Starting hostapd..." + if ! systemctl start hostapd + journalctl -u hostapd -n 100 --no-hostname --no-pager + exit 1 fi - echo "[hotspot] Starting..." - touch /tmp/.ynh-hotspot-started + sleep 1 - # Check old state of the ipv4 NAT settings - if [ ! -z "${old_internet_device}" -a "${new_internet_device}" != "${old_internet_device}" ]\ - && is_nat_set "${old_internet_device}"; then - - unset_nat "${old_internet_device}" - fi - - # Set ipv4 NAT - if [ ! -z "${new_internet_device}" ] && ! is_nat_set "${new_internet_device}"; then - echo "Set NAT" - set_nat "${new_internet_device}" - fi - - # Set forwarding for ipv6 and ipv4 - if ! is_forwarding_set; then - echo "Set forwarding" - set_forwarding - fi - - # Run hostapd - if ! is_hostapd_running; then - echo "Run hostapd" - start_hostapd ${i} - - if [ ! $? -eq 0 ]; then - journalctl -u hostapd -n 100 --no-hostname --no-pager + i=0; + while ! ip link show dev hotspot1 &> /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 - if [ "${ynh_multissid}" -gt 1 ]; then - i=0; false || while [ $? -ne 0 ]; do - sleep 1 && (( i++ )) - [ ${i} -gt 20 ] && stop_hostapd - [ ${i} -gt 20 ] && exit 1 - ip link show dev hotspot1 &> /dev/null - done - else - sleep 1 - fi + # For each registred ssid + for i in $(seq 0 $((${multissid} - 1))); do + + # Set ipv4 NAT address + if ! is_ip4nataddr_set ${i}; then + echo "hotspot${i}: Set IPv4 NAT address" + set_ip4nataddr ${i} fi - # For each registred ssid - for i in $(seq 0 $((${ynh_multissid} - 1))); do + # Set the ipv6 address + if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then + echo "hotspot${i}: Set IPv6 address" + set_ip6addr ${i} + fi - # Set ipv4 NAT address - if ! is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Set IPv4 NAT address" - set_ip4nataddr ${i} - fi + # Set ipv6 firewalling + if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then + echo "hotspot${i}: Set IPv6 firewalling" + set_ip6firewall ${i} + fi - # Set the ipv6 address - if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then - echo "hotspot${i}: Set IPv6 address" - set_ip6addr ${i} - fi + # Run DHCPv6 server + if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then + echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" + start_dhcpd6 ${i} + fi - # Set ipv6 firewalling - if has_ip6delegatedprefix ${i} && [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then - echo "hotspot${i}: Set IPv6 firewalling" - set_ip6firewall ${i} - fi + # Run DHCPv4 server + if ! is_dhcpd4_running ${i}; then + echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" + start_dhcpd4 ${i} + fi - # Run DHCPv6 server - if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then - echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" - start_dhcpd6 ${i} - fi + done - # Run DHCPv4 server - if ! is_dhcpd4_running ${i}; then - echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" - start_dhcpd4 ${i} - fi - - done - - # Update dynamic settings - ynh_setting_set hotspot internet_device "${new_internet_device}" - fi + # Update dynamic settings + ynh_setting_set hotspot gateway_interface "${new_gateway_interface}" ;; stop) echo "[hotspot] Stopping..." rm -f /tmp/.ynh-hotspot-started - if [ ! -z "${old_internet_device}" ] && is_nat_set "${old_internet_device}"; then + if [ ! -z "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then echo "Unset NAT" - unset_nat "${old_internet_device}" + unset_nat "${old_gateway_interface}" fi if is_forwarding_set; then @@ -450,7 +455,7 @@ case "$1" in unset_forwarding fi - for i in $(seq 0 $((${ynh_multissid} - 1))); do + for i in $(seq 0 $((${multissid} - 1))); do if is_ip4nataddr_set ${i}; then echo "hotspot${i}: Unset IPv4 NAT address" unset_ip4nataddr ${i} @@ -461,7 +466,7 @@ case "$1" in unset_ip6addr ${i} fi - if has_ip6delegatedprefix ${i} && [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then + if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then echo "hotspot${i}: Unset IPv6 firewalling" unset_ip6firewall ${i} fi @@ -494,60 +499,60 @@ case "$1" in status) exitcode=0 - if [ "${ynh_service_enabled}" != "enabled" ]; then - echo "[ERR] Hotspot Service disabled" - exitcode=1 + if [ "${service_enabled}" != "enabled" ]; then + echo "[FAIL] Hotspot Service disabled" + exit 1 fi - if [ -z "${ynh_wifi_device}" ]; then - echo "[ERR] No wifi device selected. Make sure your wifi antenna is plugged-in / available and select it in the Hotspot admin" - exitcode=1 + 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 - echo "[INFO] Autodetected internet interface: ${new_internet_device} (last start: ${old_internet_device})" + echo "[INFO] Autodetected internet interface: ${new_gateway_interface} (last start: ${old_gateway_interface})" - if is_nat_set "${new_internet_device}"; then - echo "[OK] IPv4 NAT set" + if is_nat_set "${new_gateway_interface}"; then + echo "[ OK ] IPv4 NAT set" else - if [ -z "${new_internet_device}" ]; then + if [ -z "${new_gateway_interface}" ]; then echo "[INFO] No IPv4 NAT set (no internet interface)" else - echo "[ERR] No IPv4 NAT set" + echo "[FAIL] No IPv4 NAT set" fi exitcode=1 fi if is_forwarding_set; then - echo "[OK] IPv6/IPv4 forwarding set" + echo "[ OK ] IPv6/IPv4 forwarding set" else - echo "[ERR] No IPv6/IPv4 forwarding set" + echo "[FAIL] No IPv6/IPv4 forwarding set" exitcode=1 fi if is_hostapd_running; then - echo "[OK] Hostapd is running" + echo "[ OK ] Hostapd is running" else - echo "[ERR] Hostapd is not running" + echo "[FAIL] Hostapd is not running" exitcode=1 fi - for i in $(seq 0 $((${ynh_multissid} - 1))); do + 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 is_ip6addr_set ${i}; then - echo "[OK] hotspot${i}: IPv6 address set" + echo "[ OK ] hotspot${i}: IPv6 address set" else - echo "[ERR] hotspot${i}: No IPv6 address set" + echo "[FAIL] hotspot${i}: No IPv6 address set" exitcode=1 fi if is_ip6firewall_set ${i}; then - echo "[OK] hotspot${i}: IPv6 firewalling set" + echo "[ OK ] hotspot${i}: IPv6 firewalling set" else - if [ "${ynh_ip6_firewall[${i}]}" -eq 1 ]; then - echo "[ERR] hotspot${i}: No IPv6 firewalling set" + 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 @@ -555,9 +560,9 @@ case "$1" in fi if is_dhcpd6_running ${i}; then - echo "[OK] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are running" + echo "[ OK ] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are running" else - echo "[ERR] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are not running" + echo "[FAIL] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are not running" exitcode=1 fi else @@ -565,16 +570,16 @@ case "$1" in fi if is_dhcpd4_running ${i}; then - echo "[OK] hotspot${i}: DHCPv4 server (dnsmasq) is running" + echo "[ OK ] hotspot${i}: DHCPv4 server (dnsmasq) is running" else - echo "[ERR] hotspot${i}: DHCPv4 (dnsmasq) is not running" + echo "[FAIL] hotspot${i}: DHCPv4 (dnsmasq) is not running" exitcode=1 fi if is_ip4nataddr_set ${i}; then - echo "[OK] hotspot${i}: IPv4 NAT address set" + echo "[ OK ] hotspot${i}: IPv4 NAT address set" else - echo "[ERR] hotspot${i}: No IPv4 NAT address set" + echo "[FAIL] hotspot${i}: No IPv4 NAT address set" exitcode=1 fi done From 7da1dc5461ac54fab3e69b81035d03042ed2e458 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:20:13 +0100 Subject: [PATCH 07/15] Apply 'shfmt -bn -i 4 -w' on ynh-hotspot --- conf/ynh-hotspot | 581 +++++++++++++++++++++++------------------------ 1 file changed, 289 insertions(+), 292 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 8139c0a..18e498d 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -21,232 +21,232 @@ ## State functions has_vpnclient_app() { - [ -e /tmp/.ynh-vpnclient-started ] + [ -e /tmp/.ynh-vpnclient-started ] } has_ip6delegatedprefix() { - local i=${1} + local i=${1} - [[ -n "${ip6_net[${i}]}" ]] && [[ "${ip6_net[${i}]}" != "none" ]] + [[ -n "${ip6_net[${i}]}" ]] && [[ "${ip6_net[${i}]}" != "none" ]] } ip6addrfromdelegatedprefix() { - local i=${1} + local i=${1} - echo "${ip6_net[${i}]}${i}001" + echo "${ip6_net[${i}]}${i}001" } is_nat_set() { - local gateway_interface=${1} + local gateway_interface=${1} - iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}" + iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${gateway_interface}" } is_ip4nataddr_set() { - local i=${1} - dev=$(devfromid "${i}") + local i=${1} + dev=$(devfromid "${i}") - ip address show dev "${dev}" 2> /dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" + ip address show dev "${dev}" 2>/dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" } is_ip6addr_set() { - local i=${1} - dev=$(devfromid "${i}") + local i=${1} + dev=$(devfromid "${i}") - ip address show dev "${dev}" 2> /dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" + ip address show dev "${dev}" 2>/dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" } is_ip6firewall_set() { - local i=${1} - dev=$(devfromid "${i}") + local i=${1} + dev=$(devfromid "${i}") - ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}" + ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}" } 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; }') + 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 -a "${ip4}" -eq 1 ] + [ "${ip6}" -eq 1 -a "${ip4}" -eq 1 ] } is_dhcpd6_running() { - local i=${1} + local i=${1} - $(ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep) + $(ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep) } is_dhcpd4_running() { - local i=${1} + local i=${1} - $(ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep) + $(ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep) } is_hostapd_running() { - systemctl is-active hostapd &> /dev/null + systemctl is-active hostapd &>/dev/null } 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} + 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 - return 1 - fi - done + if [ ! $? -eq 0 ]; then + return 1 + fi + done - is_hostapd_running && is_forwarding_set && ( [ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}" ) + is_hostapd_running && is_forwarding_set && ([ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}") } ## Setters set_nat() { - local gateway_interface=${1} + local gateway_interface=${1} - iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE + iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE } set_ip4nataddr() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" } set_ip6addr() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &> /dev/null - ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" + ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &>/dev/null + ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" } set_ip6firewall() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - 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 + 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 } set_forwarding() { - sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null - sysctl -w net.ipv4.conf.all.forwarding=1 > /dev/null + sysctl -w net.ipv6.conf.all.forwarding=1 >/dev/null + sysctl -w net.ipv4.conf.all.forwarding=1 >/dev/null } start_dhcpd6() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} + 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_NET__|${ip6_net[${i}]}|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|__WIFI_DEVICE__|${dev}|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 + sed "s|__IP6_DNS__|${ip6_dns[${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 } start_dhcpd4() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} + cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s|__WIFI_DEVICE__|${dev}|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 + sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s|__WIFI_DEVICE__|${dev}|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 } 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}" + 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 + 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 + 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="" + [ "${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 + 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 + 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 + cat /etc/hostapd/hostapd.conf.tmp >>/etc/hostapd/hostapd.conf + rm /etc/hostapd/hostapd.conf.tmp + done } ## Unsetters unset_nat() { - local gateway_interface=${1} + local gateway_interface=${1} - iptables -w -t nat -D POSTROUTING -o "${gateway_interface}" -j MASQUERADE + iptables -w -t nat -D POSTROUTING -o "${gateway_interface}" -j MASQUERADE } unset_ip4nataddr() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" } unset_ip6addr() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" + ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" } unset_ip6firewall() { - local i=${1} - local dev=$(devfromid "${i}") + local i=${1} + local dev=$(devfromid "${i}") - 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 + 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 } unset_forwarding() { - sysctl -w net.ipv6.conf.all.forwarding=0 > /dev/null - sysctl -w net.ipv4.conf.all.forwarding=0 > /dev/null + sysctl -w net.ipv6.conf.all.forwarding=0 >/dev/null + sysctl -w net.ipv4.conf.all.forwarding=0 >/dev/null } stop_dhcpd6() { - kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf + kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') + rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf } stop_dhcpd4() { - kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf + kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') + rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf } stop_hostapd() { - systemctl stop hostapd + systemctl stop hostapd } ## Tools ynh_setting_get() { - APP="$1" KEY="$2" python3 - < /dev/null - if [ "$?" -eq 0 ]; then - new_gateway_interface=tun0 - fi + # 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" + echo "OK" fi # Script case "$1" in - start) +start) if is_running; then - echo "Already started" - exit 0 + echo "Already started" + exit 0 elif [ "${service_enabled}" != "enabled" ]; then - echo "Not starting because hotspod service is disabled" - exit 1 + echo "Not starting because hotspod service is disabled" + exit 1 fi 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 + 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 echo "[hotspot] Starting..." touch /tmp/.ynh-hotspot-started # Check old state of the ipv4 NAT settings - if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ]\ - && is_nat_set "${old_gateway_interface}"; then + if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then - unset_nat "${old_gateway_interface}" + unset_nat "${old_gateway_interface}" fi # Set ipv4 NAT if [ ! -z "${new_gateway_interface}" ] && ! is_nat_set "${new_gateway_interface}"; then - echo "Set NAT" - set_nat "${new_gateway_interface}" + echo "Set NAT" + set_nat "${new_gateway_interface}" fi # Set forwarding for ipv6 and ipv4 if ! is_forwarding_set; then - echo "Set forwarding" - set_forwarding + echo "Set forwarding" + set_forwarding fi # Run hostapd if ! is_hostapd_running; then - echo "Configuring hostapd" - configure_hostapd + echo "Configuring hostapd" + configure_hostapd - echo "Starting hostapd..." - if ! systemctl start hostapd - journalctl -u hostapd -n 100 --no-hostname --no-pager - exit 1 - fi - - sleep 1 - - i=0; - while ! ip link show dev hotspot1 &> /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 + echo "Starting hostapd..." + if ! systemctl start hostapd; then + journalctl -u hostapd -n 100 --no-hostname --no-pager + exit 1 fi - i=$(($i + 1)) - done + + sleep 1 + + i=0 + while ! ip link show dev hotspot1 &>/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 # For each registred ssid for i in $(seq 0 $((${multissid} - 1))); do - # Set ipv4 NAT address - if ! is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Set IPv4 NAT address" - set_ip4nataddr ${i} - fi + # Set ipv4 NAT address + if ! is_ip4nataddr_set ${i}; then + echo "hotspot${i}: Set IPv4 NAT address" + set_ip4nataddr ${i} + fi - # Set the ipv6 address - if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then - echo "hotspot${i}: Set IPv6 address" - set_ip6addr ${i} - fi + # Set the ipv6 address + if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then + echo "hotspot${i}: Set IPv6 address" + set_ip6addr ${i} + fi - # Set ipv6 firewalling - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then - echo "hotspot${i}: Set IPv6 firewalling" - set_ip6firewall ${i} - fi + # Set ipv6 firewalling + if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then + echo "hotspot${i}: Set IPv6 firewalling" + set_ip6firewall ${i} + fi - # Run DHCPv6 server - if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then - echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" - start_dhcpd6 ${i} - fi + # Run DHCPv6 server + if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then + echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" + start_dhcpd6 ${i} + fi - # Run DHCPv4 server - if ! is_dhcpd4_running ${i}; then - echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" - start_dhcpd4 ${i} - fi + # Run DHCPv4 server + if ! is_dhcpd4_running ${i}; then + echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" + start_dhcpd4 ${i} + fi done # Update dynamic settings ynh_setting_set hotspot gateway_interface "${new_gateway_interface}" - ;; - stop) + ;; +stop) echo "[hotspot] Stopping..." rm -f /tmp/.ynh-hotspot-started if [ ! -z "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then - echo "Unset NAT" - unset_nat "${old_gateway_interface}" + echo "Unset NAT" + unset_nat "${old_gateway_interface}" fi if is_forwarding_set; then - echo "Unset forwarding" - unset_forwarding + echo "Unset forwarding" + unset_forwarding fi for i in $(seq 0 $((${multissid} - 1))); do - if is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Unset IPv4 NAT address" - unset_ip4nataddr ${i} - fi + if is_ip4nataddr_set ${i}; then + echo "hotspot${i}: Unset IPv4 NAT address" + unset_ip4nataddr ${i} + fi - if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then - echo "hotspot${i}: Unset IPv6 address" - unset_ip6addr ${i} - fi + if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then + echo "hotspot${i}: Unset IPv6 address" + unset_ip6addr ${i} + fi - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then - echo "hotspot${i}: Unset IPv6 firewalling" - unset_ip6firewall ${i} - fi + if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then + echo "hotspot${i}: Unset IPv6 firewalling" + unset_ip6firewall ${i} + fi - if is_dhcpd6_running ${i}; then - echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" - stop_dhcpd6 ${i} - fi + if is_dhcpd6_running ${i}; then + echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" + stop_dhcpd6 ${i} + fi - if is_dhcpd4_running ${i}; then - echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" - stop_dhcpd4 ${i} - fi + if is_dhcpd4_running ${i}; then + echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" + stop_dhcpd4 ${i} + fi done if is_hostapd_running; then - echo "Stop hostapd" - stop_hostapd + echo "Stop hostapd" + stop_hostapd fi # Fix configuration if has_vpnclient_app; then - ynh-vpnclient start + ynh-vpnclient start fi - ;; - restart) + ;; +restart) $0 stop $0 start - ;; - status) + ;; +status) exitcode=0 if [ "${service_enabled}" != "enabled" ]; then - echo "[FAIL] Hotspot Service disabled" - exit 1 + echo "[FAIL] Hotspot Service disabled" + exit 1 fi 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 + 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 echo "[INFO] Autodetected internet interface: ${new_gateway_interface} (last start: ${old_gateway_interface})" if is_nat_set "${new_gateway_interface}"; then - echo "[ OK ] IPv4 NAT set" + echo "[ OK ] IPv4 NAT set" else - if [ -z "${new_gateway_interface}" ]; then - echo "[INFO] No IPv4 NAT set (no internet interface)" - else - echo "[FAIL] No IPv4 NAT set" - fi - exitcode=1 + if [ -z "${new_gateway_interface}" ]; then + echo "[INFO] No IPv4 NAT set (no internet interface)" + else + echo "[FAIL] No IPv4 NAT set" + fi + exitcode=1 fi if is_forwarding_set; then - echo "[ OK ] IPv6/IPv4 forwarding set" + echo "[ OK ] IPv6/IPv4 forwarding set" else - echo "[FAIL] No IPv6/IPv4 forwarding set" - exitcode=1 + echo "[FAIL] No IPv6/IPv4 forwarding set" + exitcode=1 fi if is_hostapd_running; then - echo "[ OK ] Hostapd is running" + echo "[ OK ] Hostapd is running" else - echo "[FAIL] Hostapd is not running" - exitcode=1 + echo "[FAIL] Hostapd is not running" + 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 ${i}; then + echo "[INFO] hotspot${i}: IPv6 delegated prefix found" + echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: $(ip6addrfromdelegatedprefix $i)" - if is_ip6addr_set ${i}; then - echo "[ OK ] hotspot${i}: IPv6 address set" + 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 else - echo "[FAIL] hotspot${i}: No IPv6 address set" - exitcode=1 + echo "[INFO] hotspot${i}: No IPv6 delegated prefix found" fi - if is_ip6firewall_set ${i}; then - echo "[ OK ] hotspot${i}: IPv6 firewalling set" + if is_dhcpd4_running ${i}; then + echo "[ OK ] hotspot${i}: DHCPv4 server (dnsmasq) is running" 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 + echo "[FAIL] hotspot${i}: DHCPv4 (dnsmasq) is not running" + exitcode=1 fi - if is_dhcpd6_running ${i}; then - echo "[ OK ] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are running" + if is_ip4nataddr_set ${i}; then + echo "[ OK ] hotspot${i}: IPv4 NAT address set" else - echo "[FAIL] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are not running" - exitcode=1 + echo "[FAIL] hotspot${i}: No IPv4 NAT address set" + exitcode=1 fi - 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" - exitcode=1 - fi - - if is_ip4nataddr_set ${i}; then - echo "[ OK ] hotspot${i}: IPv4 NAT address set" - else - echo "[FAIL] hotspot${i}: No IPv4 NAT address set" - exitcode=1 - fi done exit ${exitcode} - ;; - *) + ;; +*) echo "Usage: $0 {start|stop|restart|status}" exit 1 - ;; + ;; esac exit 0 From 7d7eddf98a26e3bd87fa20fa72778906bd414242 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:22:23 +0100 Subject: [PATCH 08/15] ! -z -> -n --- conf/ynh-hotspot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 18e498d..fa09592 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -358,13 +358,13 @@ start) touch /tmp/.ynh-hotspot-started # Check old state of the ipv4 NAT settings - if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then + if [ -n "${old_gateway_interface}" ] && [ "${new_gateway_interface}" != "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then unset_nat "${old_gateway_interface}" fi # Set ipv4 NAT - if [ ! -z "${new_gateway_interface}" ] && ! is_nat_set "${new_gateway_interface}"; then + if [ -n "${new_gateway_interface}" ] && ! is_nat_set "${new_gateway_interface}"; then echo "Set NAT" set_nat "${new_gateway_interface}" fi @@ -442,7 +442,7 @@ stop) echo "[hotspot] Stopping..." rm -f /tmp/.ynh-hotspot-started - if [ ! -z "${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 From e19af5f6b96ffa5873dd22841faaeed25d1ef10b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:29:00 +0100 Subject: [PATCH 09/15] Misc syntax --- conf/ynh-hotspot | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index fa09592..30f0cea 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -67,19 +67,19 @@ 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 -a "${ip4}" -eq 1 ] + [ "${ip6}" -eq 1 ] && [ "${ip4}" -eq 1 ] } is_dhcpd6_running() { local i=${1} - $(ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep) + ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep } is_dhcpd4_running() { local i=${1} - $(ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep) + ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep } is_hostapd_running() { @@ -145,8 +145,8 @@ start_dhcpd6() { 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_NET__|${ip6_net[${i}]}|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 } @@ -157,8 +157,8 @@ start_dhcpd4() { cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-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 From 19d25d4e8b10b00c04665d5881ce1862af5048b5 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:46:09 +0100 Subject: [PATCH 10/15] Try to simplify code readability by merging set/unset ipv4/6 together --- conf/ynh-hotspot | 195 ++++++++++++++++++++--------------------------- 1 file changed, 83 insertions(+), 112 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 30f0cea..7a5e237 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -44,21 +44,21 @@ is_nat_set() { is_ip4nataddr_set() { local i=${1} - dev=$(devfromid "${i}") + local dev=$(devfromid "${i}") ip address show dev "${dev}" 2>/dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" } is_ip6addr_set() { local i=${1} - dev=$(devfromid "${i}") + local dev=$(devfromid "${i}") ip address show dev "${dev}" 2>/dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" } is_ip6firewall_set() { local i=${1} - dev=$(devfromid "${i}") + local dev=$(devfromid "${i}") ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}" } @@ -109,28 +109,34 @@ set_nat() { iptables -w -t nat -A POSTROUTING -o "${gateway_interface}" -j MASQUERADE } -set_ip4nataddr() { +set_ipaddr() { local i=${1} local dev=$(devfromid "${i}") - ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + if ! is_ip4nataddr_set ${i}; then + echo "hotspot${i}: Set IPv4 NAT address" + ip address add "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + 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}" + fi } -set_ip6addr() { +set_ipfirewall() { local i=${1} local dev=$(devfromid "${i}") - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &>/dev/null - ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" -} + # 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 + fi -set_ip6firewall() { - local i=${1} - local dev=$(devfromid "${i}") - - 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 } set_forwarding() { @@ -138,30 +144,35 @@ set_forwarding() { sysctl -w net.ipv4.conf.all.forwarding=1 >/dev/null } -start_dhcpd6() { +start_dhcpd() { local i=${1} local dev=$(devfromid "${i}") - cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} + # Run DHCPv4 server + if ! is_dhcpd4_running ${i}; then + echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" - 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 + cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 -} + 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 -start_dhcpd4() { - local i=${1} - local dev=$(devfromid "${i}") + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 + fi - cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} + # Run DHCPv6 server + if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then + echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" - 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 + cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 + 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 + fi } configure_hostapd() { @@ -200,27 +211,31 @@ unset_nat() { iptables -w -t nat -D POSTROUTING -o "${gateway_interface}" -j MASQUERADE } -unset_ip4nataddr() { +unset_ipaddr() { local i=${1} local dev=$(devfromid "${i}") - ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + if is_ip4nataddr_set ${i}; then + echo "hotspot${i}: Unset IPv4 NAT address" + ip address delete "${ip4_nat_prefix[${i}]}.1/24" dev "${dev}" + fi + + if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then + echo "hotspot${i}: Unset IPv6 address" + ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" + fi } -unset_ip6addr() { +unset_ipfirewall() { local i=${1} local dev=$(devfromid "${i}") - ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" -} - -unset_ip6firewall() { - local i=${1} - local dev=$(devfromid "${i}") - - 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 ${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 + fi } unset_forwarding() { @@ -228,14 +243,23 @@ unset_forwarding() { sysctl -w net.ipv4.conf.all.forwarding=0 >/dev/null } -stop_dhcpd6() { - kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf +stop_dhcpd() { + local i=${1} + + 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 + 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 + fi } stop_dhcpd4() { - kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf } stop_hostapd() { @@ -370,10 +394,8 @@ start) fi # Set forwarding for ipv6 and ipv4 - if ! is_forwarding_set; then - echo "Set forwarding" - set_forwarding - fi + echo "Set forwarding" + set_forwarding # Run hostapd if ! is_hostapd_running; then @@ -402,37 +424,9 @@ start) # For each registred ssid for i in $(seq 0 $((${multissid} - 1))); do - - # Set ipv4 NAT address - if ! is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Set IPv4 NAT address" - set_ip4nataddr ${i} - fi - - # Set the ipv6 address - if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then - echo "hotspot${i}: Set IPv6 address" - set_ip6addr ${i} - fi - - # Set ipv6 firewalling - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then - echo "hotspot${i}: Set IPv6 firewalling" - set_ip6firewall ${i} - fi - - # Run DHCPv6 server - if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then - echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)" - start_dhcpd6 ${i} - fi - - # Run DHCPv4 server - if ! is_dhcpd4_running ${i}; then - echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)" - start_dhcpd4 ${i} - fi - + set_ipaddr ${i} + set_ipfirewall ${i} + start_dhcpd ${i} done # Update dynamic settings @@ -447,36 +441,13 @@ stop) unset_nat "${old_gateway_interface}" fi - if is_forwarding_set; then - echo "Unset forwarding" - unset_forwarding - fi + echo "Unset forwarding" + unset_forwarding for i in $(seq 0 $((${multissid} - 1))); do - if is_ip4nataddr_set ${i}; then - echo "hotspot${i}: Unset IPv4 NAT address" - unset_ip4nataddr ${i} - fi - - if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then - echo "hotspot${i}: Unset IPv6 address" - unset_ip6addr ${i} - fi - - if has_ip6delegatedprefix ${i} && [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then - echo "hotspot${i}: Unset IPv6 firewalling" - unset_ip6firewall ${i} - fi - - if is_dhcpd6_running ${i}; then - echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" - stop_dhcpd6 ${i} - fi - - if is_dhcpd4_running ${i}; then - echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" - stop_dhcpd4 ${i} - fi + unset_ipaddr ${i} + unset_ipfirewall ${i} + stop_dhcpd ${i} done if is_hostapd_running; then From 506fcc14c02f62478130f00cb861a2f4fa018c61 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 16 Nov 2021 00:50:35 +0100 Subject: [PATCH 11/15] Propagate renaming for hostapd conf templates --- scripts/backup | 3 ++- scripts/install | 2 +- scripts/remove | 2 +- scripts/upgrade | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index eb44588..8284b04 100644 --- a/scripts/backup +++ b/scripts/backup @@ -40,10 +40,11 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -for FILE in $(ls /etc/hostapd/hostapd.conf{.tpl?,} 2>/dev/null) +for FILE in $(ls /etc/hostapd/hostapd.*.conf 2>/dev/null) do ynh_backup --src_path="$FILE" done + ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" diff --git a/scripts/install b/scripts/install index d516f72..e9ab243 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.tpl? /etc/hostapd/ +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 diff --git a/scripts/remove b/scripts/remove index 2238e07..4ccfd27 100644 --- a/scripts/remove +++ b/scripts/remove @@ -65,7 +65,7 @@ done # Remove confs ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -for FILE in $(ls /etc/hostapd/hostapd.conf{.tpl?,} 2>/dev/null) +for FILE in $(ls /etc/hostapd/hostapd.*.conf 2>/dev/null) do ynh_secure_remove --file="$FILE" done diff --git a/scripts/upgrade b/scripts/upgrade index d193da8..519721e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -134,7 +134,7 @@ ynh_script_progression --message="Copying configuration..." mkdir -pm 0755 /etc/dnsmasq.dhcpd/ chown root: /etc/dnsmasq.dhcpd/ -install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/ +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 From bc5eb54331b32184f07023779b64abb4ee6c3e83 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Wed, 24 Nov 2021 19:21:14 +0100 Subject: [PATCH 12/15] [fix] Syntax error --- conf/ynh-hotspot | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 7a5e237..23741c4 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -260,6 +260,7 @@ stop_dhcpd() { } stop_dhcpd4() { + : } stop_hostapd() { From f8f73fbe00bb2e2086b64f50e98347612237b107 Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Wed, 24 Nov 2021 19:30:14 +0100 Subject: [PATCH 13/15] [fix] hotspot1 doesn't exist --- conf/ynh-hotspot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 23741c4..1873e55 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -412,7 +412,7 @@ start) sleep 1 i=0 - while ! ip link show dev hotspot1 &>/dev/null; do + while ! ip link show dev "${new_gateway_interface}" &>/dev/null; do sleep 1 if [ ${i} -gt 20 ]; then echo "Failed to see hotspot interface showing up in 'ip a'" From e6f4cddbd9f3b60777bbdd43028c334968c8d60b Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Fri, 26 Nov 2021 02:31:26 +0100 Subject: [PATCH 14/15] [enh] Use instance resolver to let using local services --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index e9ab243..8032f2a 100644 --- a/scripts/install +++ b/scripts/install @@ -141,7 +141,7 @@ 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_net --value="${ip6_net}" -ynh_app_setting_set --app=$app --key=dns --value="2001:913::8,2001:910:800::12,80.67.188.188,80.67.169.12" +ynh_app_setting_set --app=$app --key=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 1acbfc6c66af30d1717036a50843a494d252e726 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 27 Nov 2021 18:41:44 +0100 Subject: [PATCH 15/15] Fix check that hotspot1 is up in multissid context --- conf/ynh-hotspot | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 1873e55..546d283 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -411,16 +411,20 @@ start) sleep 1 - i=0 - while ! ip link show dev "${new_gateway_interface}" &>/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 + # On single SSID, the hotspot interface will be wlan0 (or similar) + # in multissid, we additionally want to make sure that at least hotspot1 started + if [ "${multissid}" -gt 1 ]; then + i=0 + while ! ip link show dev "hotspot1" &>/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