2014-11-16 23:27:36 +01:00
|
|
|
#!/bin/bash
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Wifi Hotspot app for YunoHost
|
2014-12-26 20:18:03 +01:00
|
|
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
2015-07-22 23:54:56 +02:00
|
|
|
# Contribute at https://github.com/labriqueinternet/hotspot_ynh
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
2014-12-26 20:18:03 +01:00
|
|
|
# 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.
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
2014-12-26 20:18:03 +01:00
|
|
|
# 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.
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
2014-12-26 20:18:03 +01:00
|
|
|
# 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/>.
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2015-07-24 18:43:19 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2014-11-25 21:05:24 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2015-09-29 18:01:10 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
wifi_ssid=$YNH_APP_ARG_WIFI_SSID
|
|
|
|
wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE
|
|
|
|
firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2019-02-10 19:51:12 +01:00
|
|
|
sysuser="${app}"
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-02-10 16:42:40 +01:00
|
|
|
# the service name must match the service template files
|
|
|
|
service_name='ynh-hotspot'
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path "$path_url")
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available "$domain" "$path_url"
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register "$app" "$domain" "$path_url"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" domain "$domain"
|
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
|
|
ynh_app_setting_set "$app" wifi_ssid "$wifi_ssid"
|
|
|
|
ynh_app_setting_set "$app" wifi_passphrase "$wifi_passphrase"
|
|
|
|
ynh_app_setting_set "$app" firmware_nonfree "$firmware_nonfree"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
2019-02-20 19:46:07 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL NONFREE FIRWARE IF REQUESTED
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
# Packaged USB Wireless Device firmwares
|
|
|
|
# Based on https://wiki.debian.org/WiFi#USB_Devices
|
|
|
|
if [[ $firmware_nonfree -eq 1 ]]; then
|
|
|
|
# check if non-free is set on sources.list
|
|
|
|
if ! grep -q non-free /etc/apt/sources.list ; then
|
|
|
|
sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list
|
|
|
|
fi
|
|
|
|
|
|
|
|
packages=$nonfree_packages
|
|
|
|
else
|
|
|
|
packages=$free_packages
|
|
|
|
|
|
|
|
# Extract from http://packages.trisquel.info/toutatis-updates/open-ath9k-htc-firmware
|
|
|
|
# https://www.fsf.org/news/ryf-certification-thinkpenguin-usb-with-atheros-chip
|
|
|
|
# https://wiki.debian.org/ath9k_htc/open_firmware
|
|
|
|
mkdir -p /lib/firmware
|
|
|
|
install -b -o root -g root -m 0644 ../conf/firmware_htc-7010.fw /lib/firmware/htc_7010.fw
|
|
|
|
install -b -o root -g root -m 0644 ../conf/firmware_htc-9271.fw /lib/firmware/htc_9271.fw
|
|
|
|
fi
|
|
|
|
|
|
|
|
ynh_package_update
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-20 19:46:07 +01:00
|
|
|
ynh_install_app_dependencies "$pkg_dependencies" "$packages"
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# RUN PREREQUISITES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source ./prerequisites
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK PARAMETERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Check arguments
|
|
|
|
if [[ -z $wifi_ssid || -z $wifi_passphrase ]]; then
|
|
|
|
ynh_die "Your Wifi Hotspot needs a name and a password"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check passphrase length
|
|
|
|
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
|
|
|
|
if [[ $wifi_passphrase_length -lt 8 || $wifi_passphrase_length -gt 63 ]]; then
|
|
|
|
ynh_die "Your password must from 8 to 63 characters (WPA2 passphrase)"
|
|
|
|
fi
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Check no special characters are present in the passphrase
|
|
|
|
if [[ $wifi_passphrase =~ [^[:print:]] ]]; then
|
|
|
|
ynh_die "Only printable ASCII characters are permitted in your password (WPA2 passphrase)"
|
2014-11-09 22:49:07 +01:00
|
|
|
fi
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK PARAMETERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [[ ! -v ip6_net ]]; then # if ip6_net not set
|
|
|
|
ip6_net=none
|
|
|
|
ip6_addr=none
|
|
|
|
|
|
|
|
if [[ -e /tmp/.ynh-vpnclient-started ]]; then
|
2019-02-15 22:37:31 +01:00
|
|
|
vpnclient_ip6_net=$(yunohost app setting vpnclient ip6_net 2>&1)
|
|
|
|
vpnclient_ip6_addr=$(yunohost app setting vpnclient ip6_addr 2>&1)
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
if [[ $vpnclient_ip6_net =~ :: && $vpnclient_ip6_addr =~ :: ]]; then
|
|
|
|
ip6_net=${vpnclient_ip6_net}
|
|
|
|
ip6_addr=${vpnclient_ip6_addr}
|
2014-12-29 01:18:31 +01:00
|
|
|
fi
|
|
|
|
fi
|
2018-05-04 00:33:01 +02:00
|
|
|
fi
|
2015-07-25 16:33:38 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Save arguments
|
|
|
|
|
|
|
|
if [[ -z $wifi_device ]]; then
|
2019-02-09 11:24:32 +01:00
|
|
|
ynh_app_setting_set $app service_enabled 0
|
2018-05-04 00:33:01 +02:00
|
|
|
wifi_device=none
|
|
|
|
else
|
2019-02-09 11:24:32 +01:00
|
|
|
ynh_app_setting_set $app service_enabled 1
|
2014-11-16 23:27:36 +01:00
|
|
|
fi
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SAVE SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-09 11:24:32 +01:00
|
|
|
ynh_app_setting_set $app multissid 1
|
|
|
|
ynh_app_setting_set $app wifi_ssid "${wifi_ssid}"
|
|
|
|
ynh_app_setting_set $app wifi_secure 1
|
|
|
|
ynh_app_setting_set $app wifi_passphrase "${wifi_passphrase}"
|
|
|
|
ynh_app_setting_set $app wifi_device "${wifi_device}"
|
|
|
|
ynh_app_setting_set $app wifi_channel 6
|
|
|
|
ynh_app_setting_set $app ip6_addr "${ip6_addr}"
|
|
|
|
ynh_app_setting_set $app ip6_firewall 1
|
|
|
|
ynh_app_setting_set $app ip6_net "${ip6_net}"
|
|
|
|
ynh_app_setting_set $app ip6_dns0 2001:913::8
|
|
|
|
ynh_app_setting_set $app ip6_dns1 2001:910:800::12
|
|
|
|
ynh_app_setting_set $app ip4_dns0 80.67.188.188
|
|
|
|
ynh_app_setting_set $app ip4_dns1 80.67.169.12
|
|
|
|
ynh_app_setting_set $app ip4_nat_prefix 10.0.242
|
|
|
|
ynh_app_setting_set $app vpnclient no
|
2019-02-10 16:42:40 +01:00
|
|
|
ynh_app_setting_set $app service_name $service_name
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-02-10 19:51:12 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Ensure the app has its own system user
|
|
|
|
if ! ynh_system_user_exists ${sysuser}
|
|
|
|
then
|
|
|
|
ynh_system_user_create ${sysuser}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure the system user has enough sudo permissions
|
|
|
|
install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_ynh
|
|
|
|
ynh_replace_string "__HOTSPOT_SYSUSER__" "${sysuser}" /etc/sudoers.d/${app}_ynh
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL CUSTOM SCRIPTS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
2014-11-04 23:00:04 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# COPY CONFIGS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
mkdir -pm 0755 /var/log/nginx/
|
|
|
|
mkdir -pm 0755 /etc/dnsmasq.dhcpd/
|
|
|
|
chown root: /etc/dnsmasq.dhcpd/
|
2014-12-26 18:58:58 +01:00
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /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
|
|
|
|
install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# COPY WEB SOURCES
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
mkdir -pm 0755 /var/www/wifiadmin/
|
|
|
|
cp -a ../sources/* /var/www/wifiadmin/
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
chown -R root: /var/www/wifiadmin/
|
|
|
|
chmod -R 0644 /var/www/wifiadmin/*
|
|
|
|
find /var/www/wifiadmin/ -type d -exec chmod +x {} \;
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# FIX CONFIGS
|
|
|
|
#=================================================
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
## hostapd
|
2019-02-09 12:42:19 +01:00
|
|
|
sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
## nginx
|
2019-02-09 12:42:19 +01:00
|
|
|
sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
2014-11-09 22:49:07 +01:00
|
|
|
|
|
|
|
## php-fpm
|
2019-02-10 19:51:12 +01:00
|
|
|
sed "s|<TPL:PHP_NAME>|wifiadmin|g" -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sed "s|<TPL:PHP_USER>|${sysuser}|g" -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sed "s|<TPL:PHP_GROUP>|${sysuser}|g" -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sed "s|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g" -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
2014-11-09 22:49:07 +01:00
|
|
|
|
|
|
|
# Fix sources
|
2019-02-09 12:42:19 +01:00
|
|
|
sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i /var/www/wifiadmin/config.php
|
2014-11-09 22:49:07 +01:00
|
|
|
|
|
|
|
# Copy init script
|
2019-02-10 16:42:40 +01:00
|
|
|
install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
|
2019-02-20 19:46:27 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config $service_name
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-12-26 18:58:58 +01:00
|
|
|
# Update firewall for DHCP
|
2018-05-04 00:33:01 +02:00
|
|
|
yunohost firewall allow --no-upnp --ipv6 UDP 547
|
|
|
|
yunohost firewall allow --no-upnp UDP 67
|
2014-12-26 18:58:58 +01:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Set default inits
|
|
|
|
# The boot order of these services are important, so they are disabled by default
|
|
|
|
# and the ynh-hotspot service handles them.
|
2018-05-04 00:33:01 +02:00
|
|
|
systemctl disable hostapd
|
|
|
|
systemctl stop hostapd
|
|
|
|
systemctl enable php5-fpm
|
|
|
|
systemctl restart php5-fpm
|
2019-02-20 19:46:27 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
systemctl reload nginx
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-11-09 00:40:40 +01:00
|
|
|
# Remove IPv6 address set if there is a VPN installed
|
2018-05-04 00:33:01 +02:00
|
|
|
if [[ $ip6_addr != none ]]; then
|
2019-02-09 12:42:19 +01:00
|
|
|
ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
|
2018-05-04 00:33:01 +02:00
|
|
|
if [[ "$?" -eq 0 ]]; then
|
2019-02-09 12:42:19 +01:00
|
|
|
ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
|
2014-11-10 22:27:59 +01:00
|
|
|
fi
|
2014-11-05 23:41:51 +01:00
|
|
|
fi
|
|
|
|
|
2019-02-10 16:42:40 +01:00
|
|
|
# register the service
|
|
|
|
yunohost service add $service_name --description "creates a Wi-Fi access point"
|
2015-07-24 19:20:19 +02:00
|
|
|
|
2019-02-16 00:42:11 +01:00
|
|
|
# enable and start the service if device is present
|
2018-05-04 00:33:01 +02:00
|
|
|
if [[ $wifi_device == none ]]; then
|
2015-09-15 22:21:27 +02:00
|
|
|
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
2019-02-10 16:42:40 +01:00
|
|
|
else
|
2019-02-16 00:42:11 +01:00
|
|
|
ynh_systemctl enable $service_name
|
2019-02-10 16:42:40 +01:00
|
|
|
ynh_systemctl start $service_name
|
2015-09-15 22:21:27 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Reload SSOwat config
|
|
|
|
yunohost app ssowatconf
|