1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

Works with non-multissid devices

This commit is contained in:
Julien VAUBOURG 2015-05-02 14:54:08 +02:00
parent 956440e797
commit b39ab65086
8 changed files with 153 additions and 49 deletions

View file

@ -48,13 +48,25 @@ is_nat_set() {
is_ip4nataddr_set() {
i=${1}
ip address show dev "ssid${i}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix[${i}]}.1/24"
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address show dev "${dev}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix[${i}]}.1/24"
}
is_ip6addr_set() {
i=${1}
ip address show dev "ssid${i}" 2> /dev/null | grep -q "${ynh_ip6_addr[${i}]}/64"
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address show dev "${dev}" 2> /dev/null | grep -q "${ynh_ip6_addr[${i}]}/64"
}
is_forwarding_set() {
@ -98,14 +110,26 @@ set_nat() {
set_ip4nataddr() {
i=${1}
ip address add "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "ssid${i}"
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address add "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}"
}
set_ip6addr() {
i=${1}
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address delete "${ynh_ip6_addr[${i}]}/64" dev tun0 &> /dev/null
ip address add "${ynh_ip6_addr[${i}]}/64" dev "ssid${i}"
ip address add "${ynh_ip6_addr[${i}]}/64" dev "${dev}"
}
set_forwarding() {
@ -116,12 +140,18 @@ set_forwarding() {
start_dhcpd() {
i=${1}
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
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|<TPL:WIFI_DEVICE>|ssid${i}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
sed "s|<TPL:IP6_NET>|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
sed "s|<TPL:IP6_DNS0>|${ynh_ip6_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
sed "s|<TPL:IP6_DNS1>|${ynh_ip6_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
@ -133,7 +163,7 @@ start_dhcpd() {
sed "s|<TPL:IP4_DNS0>|${ynh_ip4_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
sed "s|<TPL:IP4_DNS1>|${ynh_ip4_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
sed "s|<TPL:WIFI_DEVICE>|ssid${i}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
sed "s|<TPL: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
@ -147,18 +177,12 @@ start_hostapd() {
sed "s|<TPL:WIFI_DEVICE>|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf
sed "s|<TPL:WIFI_CHANNEL>|${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf
iwconfig "${ynh_wifi_device}" | grep -q 'n *ESSID'
if [ $? -eq 0 ]; then
sed "s|<TPL:N_COMMENT>||g" -i /etc/hostapd/hostapd.conf
else
sed "s|<TPL:N_COMMENT>|#|g" -i /etc/hostapd/hostapd.conf
fi
sed "s|<TPL: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|<TPL:WIFI_INTERFACE>|ssid${i}|g" -i /etc/hostapd/hostapd.conf.tmp
sed "s|<TPL:WIFI_INTERFACE>|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp
sed "s|<TPL:WIFI_SSID>|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
sed "s|<TPL:WIFI_PASSPHRASE>|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
@ -192,13 +216,25 @@ unset_nat() {
unset_ip4nataddr() {
i=${1}
ip address delete "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "ssid${i}"
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address delete "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}"
}
unset_ip6addr() {
i=${1}
ip address delete "${ynh_ip6_addr[${i}]}/64" dev "ssid${i}"
if [ "${i}" -eq 0 ]; then
dev=${ynh_wifi_device}
else
dev="hotspot${i}"
fi
ip address delete "${ynh_ip6_addr[${i}]}/64" dev "${dev}"
}
unset_forwarding() {
@ -372,19 +408,19 @@ case "$1" in
# Set ipv4 NAT address
if ! is_ip4nataddr_set ${i}; then
echo "SSID ${i}: Set IPv4 NAT address"
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 "SSID ${i}: Set IPv6 address"
echo "Hotspot ${i}: Set IPv6 address"
set_ip6addr ${i}
fi
# Run DHCP servers
if ! is_dhcpd_running ${i}; then
echo "SSID ${i}: Set DHCP servers (dnsmasq)"
echo "Hotspot ${i}: Set DHCP servers (dnsmasq)"
start_dhcpd ${i}
fi
done
@ -409,17 +445,17 @@ case "$1" in
for i in $(seq 0 $((${ynh_multissid} - 1))); do
if is_ip4nataddr_set ${i}; then
echo "SSID ${i}: Unset IPv4 NAT address"
echo "Hotspot ${i}: Unset IPv4 NAT address"
unset_ip4nataddr ${i}
fi
if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
echo "SSID ${i}: Unset IPv6 address"
echo "Hotspot ${i}: Unset IPv6 address"
unset_ip6addr ${i}
fi
if is_dhcpd_running ${i}; then
echo "SSID ${i}: Stop DHCP servers"
echo "Hotspot ${i}: Stop DHCP servers"
stop_dhcpd ${i}
fi
done
@ -470,30 +506,30 @@ case "$1" in
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}"
echo "[INFO] Hotspot ${i}: IPv6 delegated prefix found"
echo "[INFO] Hotspot ${i}: IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}"
if is_ip6addr_set ${i}; then
echo "[OK] SSID ${i}: IPv6 address set"
echo "[OK] Hotspot ${i}: IPv6 address set"
else
echo "[ERR] SSID ${i}: No IPv6 address set"
echo "[ERR] Hotspot ${i}: No IPv6 address set"
exitcode=1
fi
else
echo "[INFO] SSID ${i}: No IPv6 delegated prefix found"
echo "[INFO] Hotspot ${i}: No IPv6 delegated prefix found"
fi
if is_dhcpd_running ${i}; then
echo "[OK] SSID ${i}: DHCP servers set"
echo "[OK] Hotspot ${i}: DHCP servers set"
else
echo "[ERR] SSID ${i}: No DHCP servers set"
echo "[ERR] Hotspot ${i}: No DHCP servers set"
exitcode=1
fi
if is_ip4nataddr_set ${i}; then
echo "[OK] SSID ${i}: IPv4 NAT address set"
echo "[OK] Hotspot ${i}: IPv4 NAT address set"
else
echo "[ERR] SSID ${i}: No IPv4 NAT address set"
echo "[ERR] Hotspot ${i}: No IPv4 NAT address set"
exitcode=1
fi
done

20
conf/iw_devices Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# Wifi Hotspot app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# 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 <http://www.gnu.org/licenses/>.
echo -n $(iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }') | tr ' ' \|

22
conf/iw_multissid Normal file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# Wifi Hotspot app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# 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 <http://www.gnu.org/licenses/>.
phy=$(iw "${1}" info | grep wiphy | awk '{ print $NF }')
iw "phy${phy}" info | grep -A1 'valid interface combinations' | tail -n1 | sed 's/.*{.*AP.*}\s<=\s\(.*\),.*/\1/'

20
conf/iw_ssids Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# Wifi Hotspot app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# 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 <http://www.gnu.org/licenses/>.
echo -n hotspot0 $(iw dev | grep Interface | grep hotspot | awk '{ print $NF }') | tr ' ' \|

View file

@ -56,7 +56,7 @@ if [ ! $? -eq 0 ]; then
fi
# Install packages
packages='php5-fpm sipcalc hostapd iptables wireless-tools dnsmasq'
packages='php5-fpm sipcalc hostapd iptables iw dnsmasq'
export DEBIAN_FRONTEND=noninteractive
# Packaged USB Wireless Device firmwares
@ -101,7 +101,7 @@ if [ -z "${ip6_net}" ]; then
# ip6_addr=$(bash ../conf/ipv6_compressed "${ip6_addr}")
fi
wifi_device=$(sudo iwconfig 2>&1 | grep 802.11 | head -n1 | awk '{ print $1 }')
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
if [ -z "${wifi_device}" ]; then
echo "ERROR: No wifi interface found" >&2
@ -125,7 +125,10 @@ sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
sudo yunohost app setting hotspot vpnclient -v no
# Install IPv6 scripts
# Install custom scripts
sudo install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/

View file

@ -48,9 +48,4 @@ sudo service nginx reload
# Remove sources
sudo rm -rf /var/www/wifiadmin/
# Remove packets
# The yunohost policy is currently to not uninstall packets (dependency problems)
## sudo apt-get --assume-yes --force-yes remove hostapd iptables sipcalc wireless-tools
## sudo apt-get --assume-yes --force-yes remove firmware-atheros atmel-firmware firmware-linux-free firmware-linux-nonfree firmware-realtek firmware-ralink firmware-libertas zd1211-firmware
exit 0

View file

@ -60,12 +60,24 @@ function ipv6_compressed($ip) {
return $output[0];
}
function iw_multissid($nic) {
exec('sudo iw_multissid '.escapeshellarg($nic), $output);
return $output[0];
}
function iw_devices() {
exec('sudo iw_devices', $output);
return getArray($output[0]);
}
function getArray($str) {
return explode('|', $str);
}
function noneValue($str) {
return $str == 'none' ? '' : $str;
return ($str == 'none') ? '' : $str;
}
function is_connected_through_hotspot($ip6_net, $ip4_nat_prefix) {
@ -78,22 +90,18 @@ function is_connected_through_hotspot($ip6_net, $ip4_nat_prefix) {
dispatch('/', function() {
$ssids = array();
$devs = iw_devices();
$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);
$dev = $dev[0];
$dev_multissid = iw_multissid($dev);
$active = ($dev == $wifi_device) ? 'class="active"' : '';
$devs_list .= "<li $active><a href='#'>$dev</a></li>\n";
}
$active = ($dev == $wifi_device) ? 'class="active"' : '';
$devs_list .= "<li $active data-multissid='$dev_multissid'><a href='javascript:'>$dev</a></li>\n";
}
$wifi_ssid = getArray(moulinette_get('wifi_ssid'));

View file

@ -1,6 +1,6 @@
<div class="panel panel-default ssid enabled" <?= $service_enabled == 0 ? 'style="display: none"' : '' ?>>
<div class="panel-heading">
<h3 class="panel-title" data-label="<?= T_("SSID") ?>"><?= T_("SSID") ?> <?= $ssid['id'] + 1 ?></h3>
<h3 class="panel-title" data-label="<?= T_("Hotspot") ?>"><?= T_("Hotspot") ?> <?= $ssid['id'] + 1 ?></h3>
</div>
<ul class="nav nav-tabs nav-justified">