From ab39322ebd15f8d629129e78de2b2c1b7a86deba Mon Sep 17 00:00:00 2001 From: Julien VAUBOURG Date: Sun, 26 Apr 2015 21:34:11 +0200 Subject: [PATCH] beta multissid --- TODO | 13 + conf/dhcpdv4.conf.tpl | 47 +++ conf/dhcpdv6.conf.tpl | 23 ++ conf/{hostapd.conf.tpl => hostapd.conf.tpl1} | 10 +- conf/hostapd.conf.tpl2 | 8 + conf/init_ynh-hotspot | 351 ++++++++++--------- scripts/install | 18 +- scripts/remove | 4 +- sources/controller.php | 22 +- sources/views/_ssid.html.php | 23 -- sources/views/settings.html.php | 22 ++ 11 files changed, 322 insertions(+), 219 deletions(-) create mode 100644 conf/dhcpdv4.conf.tpl create mode 100644 conf/dhcpdv6.conf.tpl rename conf/{hostapd.conf.tpl => hostapd.conf.tpl1} (82%) create mode 100644 conf/hostapd.conf.tpl2 diff --git a/TODO b/TODO index 1c5d23a..a335719 100644 --- a/TODO +++ b/TODO @@ -1 +1,14 @@ * Translate PHP interface in French + +* multissid +** WEB: limit to N ssid max depending on the antenna specs +** WEB: add ssid delete feature +** WEB: update is_connected_through_hotspot feature +** WEB: autocomplete ipv4 nat prefix (.242, .243, .244, etc) +** WEB: check if ipv6 delgated prefixes and ipv4 nat prefixes are unique +** WEB: fix the now broken wifiparty button +** INIT: differentiate ipv6 and ipv4 in is_dhcpd_running +** INIT: do not attribute a static mac address +** INIT: use insserv instead of update-rc.d and update service dependencies +** HARD: try with olimex antenna (no multissid enabled) +** MISC: update vpnclient/torclient for enabling the user to choose the correct ssid diff --git a/conf/dhcpdv4.conf.tpl b/conf/dhcpdv4.conf.tpl new file mode 100644 index 0000000..07347cf --- /dev/null +++ b/conf/dhcpdv4.conf.tpl @@ -0,0 +1,47 @@ +# Wifi Hotspot app for YunoHost +# Copyright (C) 2015 Julien Vaubourg +# Contribute at https://github.com/jvaubourg/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 + +# Send DHCPv4 option. +dhcp-option=option:dns-server,, + +# 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, +# whether it has a record of the lease or not. This avoids long timeouts +# when a machine wakes up on a new network. DO NOT enable this if there's +# the slightest chance that you might end up accidentally configuring a DHCP +# server for your campus/company accidentally. The ISC server uses +# the same option, and this URL provides more information: +# http://www.isc.org/files/auth.html +dhcp-authoritative + +# On systems which support it, dnsmasq binds the wildcard address, +# even when it is listening on only some interfaces. It then discards +# requests that it shouldn't reply to. This has the advantage of +# working even when interfaces come and go and change address. If you +# want dnsmasq to really bind only the interfaces it is listening on, +# uncomment this option. About the only time you may need this is when +# running another nameserver on the same machine. +bind-interfaces + +# If this line is uncommented, dnsmasq will read /etc/ethers and act +# on the ethernet-address/IP pairs found there just as if they had +# been given as --dhcp-host options. Useful if you keep +# MAC-address/host mappings there for other purposes. +#read-ethers diff --git a/conf/dhcpdv6.conf.tpl b/conf/dhcpdv6.conf.tpl new file mode 100644 index 0000000..d0edf50 --- /dev/null +++ b/conf/dhcpdv6.conf.tpl @@ -0,0 +1,23 @@ +# Wifi Hotspot app for YunoHost +# Copyright (C) 2015 Julien Vaubourg +# Contribute at https://github.com/jvaubourg/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 + +# Send DHCPv6 option. Note [] around IPv6 addresses. +dhcp-option=option6:dns-server,[],[] diff --git a/conf/hostapd.conf.tpl b/conf/hostapd.conf.tpl1 similarity index 82% rename from conf/hostapd.conf.tpl rename to conf/hostapd.conf.tpl1 index 4246c72..d9e11da 100644 --- a/conf/hostapd.conf.tpl +++ b/conf/hostapd.conf.tpl1 @@ -16,19 +16,11 @@ # along with this program. If not, see . interface= -ssid= - hw_mode=g ieee80211n=1 wmm_enabled=1 - -channel= macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 +channel= -wpa=2 -wpa_passphrase= -wpa_key_mgmt=WPA-PSK -wpa_pairwise=TKIP -rsn_pairwise=CCMP diff --git a/conf/hostapd.conf.tpl2 b/conf/hostapd.conf.tpl2 new file mode 100644 index 0000000..32375c2 --- /dev/null +++ b/conf/hostapd.conf.tpl2 @@ -0,0 +1,8 @@ +bss= +ssid= +wpa=2 +wpa_passphrase= +wpa_key_mgmt=WPA-PSK +wpa_pairwise=TKIP +rsn_pairwise=CCMP + diff --git a/conf/init_ynh-hotspot b/conf/init_ynh-hotspot index 6e9eb78..5b0cfca 100644 --- a/conf/init_ynh-hotspot +++ b/conf/init_ynh-hotspot @@ -34,7 +34,9 @@ has_vpnclient_app() { } has_ip6delegatedprefix() { - [ "${ynh_ip6_net}" != none ] + i=${1} + + [ "${ynh_ip6_net[${i}]}" != none ] } is_nat_set() { @@ -44,11 +46,15 @@ is_nat_set() { } is_ip4nataddr_set() { - ip address show dev "${ynh_wifi_device}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix}.1/24" + i=${1} + + ip address show dev "ssid${i}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix[${i}]}.1/24" } is_ip6addr_set() { - ip address show dev "${ynh_wifi_device}" 2> /dev/null | grep -q "${ynh_ip6_addr}/64" + i=${1} + + ip address show dev "ssid${i}" 2> /dev/null | grep -q "${ynh_ip6_addr[${i}]}/64" } is_forwarding_set() { @@ -58,39 +64,27 @@ is_forwarding_set() { [ "${ip6}" -eq 1 -a "${ip4}" -eq 1 ] } -is_dhcpdv6_set() { - [ -e /etc/dnsmasq.d/dhcpdv6.conf ] -} +is_dhcpd_running() { + i=${1} -is_dhcpdv4_set() { - [ -e /etc/dnsmasq.d/dhcpdv4.conf ] + $(ps aux | grep "dhcpdv.-ssid${i}" | grep -qv grep) } is_hostapd_running() { service hostapd status &> /dev/null - - if [ $? -eq 0 ]; then - - # If the wifi antenna was unplugged - if ip link show dev "${ynh_wifi_device}" | grep -q DOWN; then - service hostapd stop &> /dev/null - return 1 - fi - - return 0 - fi - - return 1 -} - -is_dnsmasq_running() { - service dnsmasq status &> /dev/null } is_running() { - ( has_ip6delegatedprefix && is_ip6addr_set && is_dhcpdv6_set || ! has_ip6delegatedprefix )\ - && is_nat_set "${new_internet_device}" && is_ip4nataddr_set && is_forwarding_set && is_hostapd_running\ - && is_dhcpdv4_set && is_dnsmasq_running + for i in $(seq 0 $((${ynh_multissid} - 1))); do + ( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} || ! has_ip6delegatedprefix ${i} )\ + && is_ip4nataddr_set ${i} && is_dhcpd_running ${i} + + if [ ! $? -eq 0 ]; then + return 1 + fi + done + + is_hostapd_running && is_forwarding_set && is_nat_set "${new_internet_device}" } ## Setters @@ -102,12 +96,16 @@ set_nat() { } set_ip4nataddr() { - ip address add "${ynh_ip4_nat_prefix}.1/24" dev "${ynh_wifi_device}" + i=${1} + + ip address add "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "ssid${i}" } set_ip6addr() { - ip address delete "${ynh_ip6_addr}/64" dev tun0 &> /dev/null - ip address add "${ynh_ip6_addr}/64" dev "${ynh_wifi_device}" + i=${1} + + ip address delete "${ynh_ip6_addr[${i}]}/64" dev tun0 &> /dev/null + ip address add "${ynh_ip6_addr[${i}]}/64" dev "ssid${i}" } set_forwarding() { @@ -115,43 +113,63 @@ set_forwarding() { sysctl -w net.ipv4.conf.all.forwarding=1 > /dev/null } -set_dhcpd() { - if has_ip6delegatedprefix; then - cp /etc/dnsmasq.d.tpl/dhcpdv6.conf.tpl /etc/dnsmasq.d/dhcpdv6.conf +start_dhcpd() { + i=${1} + + rm -f /etc/dnsmasq.dhcpd/dhcpdv?-ssid*.conf + + if has_ip6delegatedprefix ${i}; then + cp /etc/dnsmasq.dhcpdhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf} - sed "s||${ynh_wifi_device}|g" -i /etc/dnsmasq.d/dhcpdv6.conf - sed "s||${ynh_ip6_net}|g" -i /etc/dnsmasq.d/dhcpdv6.conf - sed "s||${ynh_ip6_dns0}|g" -i /etc/dnsmasq.d/dhcpdv6.conf - sed "s||${ynh_ip6_dns1}|g" -i /etc/dnsmasq.d/dhcpdv6.conf + sed "s||ssid${i}|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_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + sed "s||${ynh_ip6_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 fi - cp /etc/dnsmasq.d.tpl/dhcpdv4.conf.tpl /etc/dnsmasq.d/dhcpdv4.conf + cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf} - sed "s||${ynh_ip4_dns0}|g" -i /etc/dnsmasq.d/dhcpdv4.conf - sed "s||${ynh_ip4_dns1}|g" -i /etc/dnsmasq.d/dhcpdv4.conf - sed "s||${ynh_wifi_device}|g" -i /etc/dnsmasq.d/dhcpdv4.conf - sed "s||${ynh_ip4_nat_prefix}|g" -i /etc/dnsmasq.d/dhcpdv4.conf + sed "s||${ynh_ip4_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s||${ynh_ip4_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s||ssid${i}|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 + + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 } start_hostapd() { - cp /etc/hostapd/hostapd.conf{.tpl,} + cp /etc/hostapd/hostapd.conf{.tpl1,} + + ip link set addr 02:42:42:13:37:00 dev "${ynh_wifi_device}" sed "s||${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf - sed "s||${ynh_wifi_ssid}|g" -i /etc/hostapd/hostapd.conf - sed "s||${ynh_wifi_passphrase}|g" -i /etc/hostapd/hostapd.conf sed "s||${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf - if [ "${ynh_wifi_n}" -eq 1 ]; then + iwconfig "${ynh_wifi_device}" | grep -q 'n *ESSID' + if [ $? -eq 0 ]; then sed "s|||g" -i /etc/hostapd/hostapd.conf else sed "s||#|g" -i /etc/hostapd/hostapd.conf fi - if [ "${ynh_wifi_secure}" -eq 1 ]; then - sed "s|||g" -i /etc/hostapd/hostapd.conf - else - sed "s||#|g" -i /etc/hostapd/hostapd.conf - fi + for i in $(seq 0 $((${ynh_multissid} - 1))); do + cp /etc/hostapd/hostapd.conf{.tpl2,.tmp} + + sed "s||ssid${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 + + if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then + sed "s|||g" -i /etc/hostapd/hostapd.conf.tmp + else + sed "s||#|g" -i /etc/hostapd/hostapd.conf.tmp + fi + + cat /etc/hostapd/hostapd.conf.tmp >> /etc/hostapd/hostapd.conf + rm /etc/hostapd/hostapd.conf.tmp + done service hostapd start } @@ -165,15 +183,15 @@ unset_nat() { } unset_ip4nataddr() { - ip address delete "${ynh_ip4_nat_prefix}.1/24" dev "${ynh_wifi_device}" + i=${1} + + ip address delete "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "ssid${i}" } unset_ip6addr() { - ip address delete "${ynh_ip6_addr}/64" dev "${ynh_wifi_device}" -} + i=${1} -unset_dhcpd() { - rm -f /etc/dnsmasq.d/dhcpdv?.conf + ip address delete "${ynh_ip6_addr[${i}]}/64" dev "ssid${i}" } unset_forwarding() { @@ -181,6 +199,11 @@ unset_forwarding() { sysctl -w net.ipv4.conf.all.forwarding=0 > /dev/null } +stop_dhcpd() { + kill $(ps aux | grep 'dhcpdv.-ssid' | grep -v grep | awk '{ print $2 }') + rm -f /etc/dnsmasq.d/dhcpdv?-ssid*.conf +} + stop_hostapd() { service hostapd stop } @@ -239,19 +262,20 @@ if [ "$1" != restart ]; then ynh_service_enabled=$(moulinette_get service_enabled) ynh_wifi_device=$(moulinette_get wifi_device) - ynh_wifi_ssid=$(moulinette_get wifi_ssid) - ynh_wifi_secure=$(moulinette_get wifi_secure) - ynh_wifi_passphrase=$(moulinette_get wifi_passphrase) ynh_wifi_channel=$(moulinette_get wifi_channel) - ynh_wifi_n=$(moulinette_get wifi_n) - ynh_ip6_addr=$(moulinette_get ip6_addr) - ynh_ip6_net=$(moulinette_get ip6_net) - ynh_ip6_dns0=$(moulinette_get ip6_dns0) - ynh_ip6_dns1=$(moulinette_get ip6_dns1) - ynh_ip4_dns0=$(moulinette_get ip4_dns0) - ynh_ip4_dns1=$(moulinette_get ip4_dns1) - ynh_ip4_nat_prefix=$(moulinette_get ip4_nat_prefix) - + ynh_multissid=$(moulinette_get multissid) + + IFS='|' read -a ynh_wifi_ssid <<< "$(moulinette_get wifi_ssid)" + IFS='|' read -a ynh_wifi_secure <<< "$(moulinette_get wifi_secure)" + IFS='|' read -a ynh_wifi_passphrase <<< "$(moulinette_get wifi_passphrase)" + IFS='|' read -a ynh_ip6_addr <<< "$(moulinette_get ip6_addr)" + IFS='|' read -a ynh_ip6_net <<< "$(moulinette_get ip6_net)" + IFS='|' read -a ynh_ip6_dns0 <<< "$(moulinette_get ip6_dns0)" + IFS='|' read -a ynh_ip6_dns1 <<< "$(moulinette_get ip6_dns1)" + IFS='|' read -a ynh_ip4_dns0 <<< "$(moulinette_get ip4_dns0)" + IFS='|' read -a ynh_ip4_dns1 <<< "$(moulinette_get ip4_dns1)" + IFS='|' read -a ynh_ip4_nat_prefix <<< "$(moulinette_get ip4_nat_prefix)" + old_internet_device=$(moulinette_get internet_device) new_internet_device=$(ip route | awk '/default via/ { print $NF; }') @@ -264,21 +288,21 @@ if [ "$1" != restart ]; then echo "OK" # Check IPv6 delegated prefix from vpnclient - vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net) - - if [ ! -z "${vpnclient_ip6_addr}" ]; then - if [ "${ynh_ip6_net}" == none ]; then - ynh_ip6_net=$vpnclient_ip6_net - ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr) - - moulinette_set ip6_net "${ynh_ip6_net}" - moulinette_set ip6_addr "${ynh_ip6_addr}" - else - if [ "${ynh_ip6_net}" != "${vpnclient_ip6_net}" ]; then - echo "[WARN] The IPv6 delegated prefix is different from the vpnclient one" - fi - fi - fi +# vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net) +# +# if [ ! -z "${vpnclient_ip6_addr}" ]; then +# if [ "${ynh_ip6_net}" == none ]; then +# ynh_ip6_net=$vpnclient_ip6_net +# ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr) +# +# moulinette_set ip6_net "${ynh_ip6_net}" +# moulinette_set ip6_addr "${ynh_ip6_addr}" +# else +# if [ "${ynh_ip6_net}" != "${vpnclient_ip6_net}" ]; then +# echo "[WARN] The IPv6 delegated prefix is different from the vpnclient one" +# fi +# fi +# fi fi @@ -313,18 +337,6 @@ case "$1" in set_nat "${new_internet_device}" fi - # Set ipv4 NAT address - if ! is_ip4nataddr_set; then - echo "Set IPv4 NAT address" - set_ip4nataddr - fi - - # Set the ipv6 address - if has_ip6delegatedprefix && ! is_ip6addr_set; then - echo "Set IPv6 address" - set_ip6addr - fi - # Set forwarding for ipv6 and ipv4 if ! is_forwarding_set; then echo "Set forwarding" @@ -334,18 +346,41 @@ case "$1" in # Run hostapd if ! is_hostapd_running; then echo "Run hostapd" - start_hostapd + start_hostapd ${i} + + if [ ! $? -eq 0 ]; then + exit 1 + fi + + i=0; false || while [ $? -ne 0 ]; do + sleep 1 && (( i++ )) + [ ${i} -gt 20 ] && stop_hostapd + [ ${i} -gt 20 ] && exit 1 + ip link show dev ssid0 &> /dev/null + done fi - # Run DHCP servers - if ( has_ip6delegatedprefix && ! is_dhcpdv6_set ) || ! is_dhcpdv4_set; then - echo "Set DHCP servers (dnsmasq)" - set_dhcpd - fi + # For each registred ssid + for i in $(seq 0 $((${ynh_multissid} - 1))); do - # Restart dhcpd - service bind9 stop &> /dev/null - service dnsmasq restart + # Set ipv4 NAT address + if ! is_ip4nataddr_set ${i}; then + echo "Set IPv4 NAT address" + set_ip4nataddr ${i} + fi + + # Set the ipv6 address + if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then + echo "Set IPv6 address" + set_ip6addr ${i} + fi + + # Run DHCP servers + if ! is_dhcpd_running ${i}; then + echo "Set DHCP servers (dnsmasq)" + start_dhcpd ${i} + fi + done # Update dynamic settings moulinette_set internet_device "${new_internet_device}" @@ -360,25 +395,27 @@ case "$1" in unset_nat "${old_internet_device}" fi - if is_ip4nataddr_set; then - echo "Unset IPv4 NAT address" - unset_ip4nataddr - fi - - if has_ip6delegatedprefix && is_ip6addr_set; then - echo "Unset IPv6 address" - unset_ip6addr - fi - if is_forwarding_set; then echo "Unset forwarding" unset_forwarding fi - - if is_dhcpdv6_set || is_dhcpdv4_set; then - echo "Stop DHCP servers" - unset_dhcpd - fi + + for i in $(seq 0 $((${ynh_multissid} - 1))); do + if is_ip4nataddr_set ${i}; then + echo "Unset IPv4 NAT address" + unset_ip4nataddr ${i} + fi + + if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then + echo "Unset IPv6 address" + unset_ip6addr ${i} + fi + + if is_dhcpd_running ${i}; then + echo "Stop DHCP servers" + stop_dhcpd ${i} + fi + done if is_hostapd_running; then echo "Stop hostapd" @@ -388,8 +425,6 @@ case "$1" in if has_vpnclient_app; then service ynh-vpnclient start fi - - service dnsmasq restart ;; restart) $0 stop @@ -405,34 +440,6 @@ case "$1" in echo "[INFO] Autodetected internet interface: ${new_internet_device} (last start: ${old_internet_device})" - if has_ip6delegatedprefix; then - echo "[INFO] IPv6 delegated prefix found" - echo "[INFO] IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}" - - if is_ip6addr_set; then - echo "[OK] IPv6 address set" - else - echo "[ERR] No IPv6 address set" - exitcode=1 - fi - - if is_dhcpdv6_set; then - echo "[OK] SLAAC & DHCPv6 server set" - else - echo "[ERR] No SLAAC & DHCPv6 server set" - exitcode=1 - fi - else - echo "[INFO] No IPv6 delegated prefix found" - fi - - if is_dhcpdv4_set; then - echo "[OK] DHCPv4 server set" - else - echo "[ERR] No DHCPv4 server set" - exitcode=1 - fi - if is_nat_set "${new_internet_device}"; then echo "[OK] IPv4 NAT set" else @@ -440,13 +447,6 @@ case "$1" in exitcode=1 fi - if is_ip4nataddr_set; then - echo "[OK] IPv4 NAT address set" - else - echo "[ERR] No IPv4 NAT address set" - exitcode=1 - fi - if is_forwarding_set; then echo "[OK] IPv6/IPv4 forwarding set" else @@ -454,13 +454,6 @@ case "$1" in exitcode=1 fi - if is_dnsmasq_running; then - echo "[OK] Dnsmasq is running" - else - echo "[ERR] Dnsmasq is not running" - exitcode=1 - fi - if is_hostapd_running; then echo "[OK] Hostapd is running" else @@ -468,6 +461,36 @@ case "$1" in exitcode=1 fi + for i in $(seq 0 $((${ynh_multissid} - 1))); do + if has_ip6delegatedprefix ${i}; then + echo "[INFO] SSID ${i}: IPv6 delegated prefix found" + echo "[INFO] SSID ${i}: IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}" + + if is_ip6addr_set ${i}; then + echo "[OK] SSID ${i}: IPv6 address set" + else + echo "[ERR] SSID ${i}: No IPv6 address set" + exitcode=1 + fi + else + echo "[INFO] SSID ${i}: No IPv6 delegated prefix found" + fi + + if is_dhcpd_running ${i}; then + echo "[OK] SSID ${i}: DHCP servers set" + else + echo "[ERR] SSID ${i}: No DHCP servers set" + exitcode=1 + fi + + if is_ip4nataddr_set ${i}; then + echo "[OK] SSID ${i}: IPv4 NAT address set" + else + echo "[ERR] SSID ${i}: No IPv4 NAT address set" + exitcode=1 + fi + done + exit ${exitcode} ;; *) diff --git a/scripts/install b/scripts/install index 61db479..5ac568e 100644 --- a/scripts/install +++ b/scripts/install @@ -102,26 +102,20 @@ if [ -z "${ip6_net}" ]; then fi wifi_device=$(sudo iwconfig 2>&1 | grep 802.11 | head -n1 | awk '{ print $1 }') -wifi_n=0 if [ -z "${wifi_device}" ]; then echo "ERROR: No wifi interface found" >&2 exit 1 fi -sudo iwconfig "${wifi_device}" | grep -q 'n *ESSID' -if [ $? -eq 0 ]; then - wifi_n=1 -fi - # Save arguments sudo yunohost app setting hotspot service_enabled -v 1 +sudo yunohost app setting hotspot multissid -v 1 sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}" sudo yunohost app setting hotspot wifi_secure -v 1 sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}" sudo yunohost app setting hotspot wifi_device -v "${wifi_device}" sudo yunohost app setting hotspot wifi_channel -v 6 -sudo yunohost app setting hotspot wifi_n -v "${wifi_n}" sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}" sudo yunohost app setting hotspot ip6_net -v "${ip6_net}" sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8 @@ -137,12 +131,12 @@ sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/ # Copy confs sudo mkdir -pm 0755 /var/log/nginx/ -sudo mkdir -pm 0755 /etc/dnsmasq.d.tpl/ -sudo chown root: /etc/dnsmasq.d.tpl/ +sudo mkdir -pm 0755 /etc/dnsmasq.dhcpd/ +sudo chown root: /etc/dnsmasq.dhcpd/ -sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/ -sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.d.tpl/dhcpdv6.conf.tpl -sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.d.tpl/dhcpdv4.conf.tpl +sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/ +sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl +sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf diff --git a/scripts/remove b/scripts/remove index 890b24a..889cd81 100644 --- a/scripts/remove +++ b/scripts/remove @@ -31,8 +31,8 @@ sudo yunohost firewall disallow --ipv6 UDP 547 sudo yunohost firewall disallow UDP 67 # Remove confs -sudo rm -fr /etc/dnsmasq.d.tpl/ -sudo rm -f /etc/hostapd/hostapd.conf{.tpl,} /etc/radvd.conf{.tpl,} /etc/dhcp/dhcpd.conf{.tpl,} +sudo rm -fr /etc/dnsmasq.dhcpd/ +sudo rm -f /etc/hostapd/hostapd.conf{.tpl?,} sudo rm -f /etc/nginx/conf.d/${domain}.d/wifiadmin.conf sudo rm -f /etc/php5/fpm/pool.d/wifiadmin.conf diff --git a/sources/controller.php b/sources/controller.php index c24b78f..6d16419 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -77,12 +77,15 @@ function is_connected_through_hotspot($ip6_net, $ip4_nat_prefix) { } dispatch('/', function() { - exec('sudo iwconfig', $devs); - $wifi_device = moulinette_get('wifi_device'); - $multissid = moulinette_get('multissid'); $ssids = array(); $devs_list = ''; + exec('sudo iwconfig', $devs); + + $wifi_device = moulinette_get('wifi_device'); + $multissid = moulinette_get('multissid'); + $wifi_channel = moulinette_get('wifi_channel'); + foreach($devs AS $dev) { if(preg_match('/802.11/', $dev)) { $dev = explode(' ', $dev); @@ -96,7 +99,6 @@ dispatch('/', function() { $wifi_ssid = getArray(moulinette_get('wifi_ssid')); $wifi_secure = getArray(moulinette_get('wifi_secure')); $wifi_passphrase = getArray(moulinette_get('wifi_passphrase')); - $wifi_channel = getArray(moulinette_get('wifi_channel')); $ip6_net = getArray(moulinette_get('ip6_net')); $ip6_dns0 = getArray(moulinette_get('ip6_dns0')); $ip6_dns1 = getArray(moulinette_get('ip6_dns1')); @@ -110,7 +112,6 @@ dispatch('/', function() { 'wifi_ssid' => noneValue($wifi_ssid[$i]), 'wifi_secure' => noneValue($wifi_secure[$i]), 'wifi_passphrase' => noneValue($wifi_passphrase[$i]), - 'wifi_channel' => noneValue($wifi_channel[$i]), 'ip6_net' => noneValue($ip6_net[$i]), 'ip6_dns0' => noneValue($ip6_dns0[$i]), 'ip6_dns1' => noneValue($ip6_dns1[$i]), @@ -129,6 +130,7 @@ dispatch('/', function() { set('service_enabled', moulinette_get('service_enabled')); set('ssids', $ssids); set('wifi_device', $wifi_device); + set('wifi_channel', $wifi_channel); set('wifi_device_list', $devs_list); set('faststatus', service_faststatus() == 0); set('is_connected_through_hotspot', is_connected_through_hotspot($ip6_net, $ip4_nat_prefix)); @@ -157,8 +159,8 @@ dispatch_put('/settings', function() { $ssid['wifi_passphrase'] = 'none'; } - if(empty($ssid['wifi_ssid']) || empty($ssid['wifi_passphrase']) || empty($ssid['wifi_channel'])) { - throw new Exception(T_('Your Wifi Hotspot needs a name, a password and a channel')); + if(empty($ssid['wifi_ssid']) || empty($ssid['wifi_passphrase'])) { + throw new Exception(T_('Your Wifi Hotspot needs a name and a password')); } if($ssid['wifi_secure'] && (strlen($ssid['wifi_passphrase']) < 8 || strlen($ssid['wifi_passphrase']) > 63)) { @@ -231,7 +233,7 @@ dispatch_put('/settings', function() { } } - //stop_service(); + stop_service(); moulinette_set('service_enabled', $service_enabled); $settings = array(); @@ -244,12 +246,14 @@ dispatch_put('/settings', function() { } moulinette_set('multissid', count($ssids)); + moulinette_set('wifi_device', $_POST['wifi_device']); + moulinette_set('wifi_channel', $_POST['wifi_channel']); foreach($settings as $setting => $value) { moulinette_set($setting, preg_replace('/\|$/', '', $value)); } - //$retcode = start_service(); + $retcode = start_service(); if($retcode == 0) { flash('success', T_('Configuration updated and service successfully reloaded')); diff --git a/sources/views/_ssid.html.php b/sources/views/_ssid.html.php index 0ab93da..826f034 100644 --- a/sources/views/_ssid.html.php +++ b/sources/views/_ssid.html.php @@ -34,29 +34,6 @@ - -
- -
- -
-
diff --git a/sources/views/settings.html.php b/sources/views/settings.html.php index d7af571..8b8f134 100644 --- a/sources/views/settings.html.php +++ b/sources/views/settings.html.php @@ -89,6 +89,28 @@ +
+ +
+ +
+