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

Merge pull request #15 from labriqueinternet/jessie

Debian jessie support
This commit is contained in:
Julien Vaubourg 2015-06-19 11:07:00 +02:00
commit 935c2c94f4
9 changed files with 103 additions and 96 deletions

View file

@ -43,10 +43,5 @@ In this manner, with this example, you can provide 3 access points at the same t
## Prerequisites
This app works with a non-stable version of YunoHost.
Until this version is available (coming soon!) as an official stable release, you need to execute some commands before installing this app:
# service bind9 stop
# update-rc.d bind9 remove
# apt-get install dnsmasq
* Debian Jessie
* YunoHost >= 2.2.0

3
TODO
View file

@ -1,4 +1 @@
* Translate PHP interface in French
* multissid
** INIT: use insserv instead of update-rc.d and update service dependencies

View file

@ -18,5 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
phy=$(iw "${1}" info | grep wiphy | awk '{ print $NF }')
multissid=$(iw "phy${phy}" info | grep -A1 'valid interface combinations' | tail -n1 | sed 's/.*{.*AP.*}\s<=\s\(.*\),.*/\1/')
iw "phy${phy}" info | grep -A1 'valid interface combinations' | tail -n1 | sed 's/.*{.*AP.*}\s<=\s\(.*\),.*/\1/'
if [ -z "${multissid}" ]; then
echo 1
else
echo $multissid
fi

View file

@ -1,28 +1,19 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: ynh-hotspot
# Required-Start: $network $remote_fs $syslog yunohost-api
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set prerequisites for wifi hotspot.
# Description: Set prerequisites for wifi hotspot.
### END INIT INFO
# Wifi Hotspot app for YunoHost
#
# 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/>.
@ -89,13 +80,13 @@ is_dhcpd4_running() {
}
is_hostapd_running() {
service hostapd status &> /dev/null
systemctl is-active hostapd &> /dev/null
}
is_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_dhcpd6_running ${i} && is_dhcpd4_running ${i}
( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} && is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i} )\
&& is_ip4nataddr_set ${i} && is_dhcpd4_running ${i}
if [ ! $? -eq 0 ]; then
return 1
@ -152,9 +143,7 @@ start_dhcpd6() {
dev="hotspot${i}"
fi
rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf
cp /etc/dnsmasq.dhcp/dhcpdv6{.conf.tpl,-ssid${i}.conf}
cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-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
@ -173,8 +162,6 @@ start_dhcpd4() {
dev="hotspot${i}"
fi
rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf
cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf}
sed "s|<TPL:IP4_DNS0>|${ynh_ip4_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
@ -201,7 +188,7 @@ start_hostapd() {
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
if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then
sed "s|<TPL:SEC_COMMENT>||g" -i /etc/hostapd/hostapd.conf.tmp
else
@ -218,7 +205,7 @@ start_hostapd() {
rm /etc/hostapd/hostapd.conf.tmp
done
service hostapd start
systemctl start hostapd
}
## Unsetters
@ -269,33 +256,41 @@ stop_dhcpd4() {
}
stop_hostapd() {
service hostapd stop
systemctl stop hostapd
}
## Tools
moulinette_get() {
var=${1}
gotcha=0
value=$(yunohost app setting hotspot "${var}")
while [ "${gotcha}" -eq 0 ]; do
value=$(yunohost app setting hotspot "${var}")
if [[ "${value}" =~ "An instance is already running" ]]; then
echo "${value}" >&2
exit 1
fi
if [[ "${value}" =~ "An instance is already running" ]]; then
sleep $(($((RANDOM%5)) + 1))
else
gotcha=1
fi
done
echo "${value}"
}
}
moulinette_vpnclient_get() {
var=${1}
gotcha=0
value=$(yunohost app setting vpnclient "${var}")
while [ "${gotcha}" -eq 0 ]; do
value=$(yunohost app setting vpnclient "${var}")
if [[ "${value}" =~ "An instance is already running" ]]; then
echo "${value}" >&2
exit 1
fi
if [[ "${value}" =~ "An instance is already running" ]]; then
sleep $(($((RANDOM%5)) + 1))
else
gotcha=1
fi
done
echo "${value}"
}
@ -317,13 +312,13 @@ if [ "$1" != restart ]; then
# Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
if [ ! -e /tmp/.ynh-hotspot-boot ]; then
touch /tmp/.ynh-hotspot-boot
service php5-fpm restart
systemctl restart php5-fpm
fi
# Variables
echo -n "Retrieving Yunohost settings... "
ynh_service_enabled=$(moulinette_get service_enabled)
ynh_wifi_device=$(moulinette_get wifi_device)
ynh_wifi_channel=$(moulinette_get wifi_channel)
@ -342,23 +337,23 @@ if [ "$1" != restart ]; then
old_internet_device=$(moulinette_get internet_device)
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
# Switch the NAT interface if there is a VPN
ip link show dev tun0 &> /dev/null
if [ "$?" -eq 0 ]; then
new_internet_device=tun0
fi
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
@ -416,12 +411,16 @@ case "$1" in
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 "mon.${ynh_wifi_device}" &> /dev/null
done
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
fi
# For each registred ssid
@ -432,13 +431,13 @@ case "$1" in
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
# Run DHCPv6 server
if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then
echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)"
@ -480,8 +479,8 @@ case "$1" in
if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
echo "hotspot${i}: Unset IPv6 address"
unset_ip6addr ${i}
fi
fi
if is_dhcpd6_running ${i}; then
echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)"
stop_dhcpd6 ${i}
@ -498,8 +497,9 @@ case "$1" in
stop_hostapd
fi
# Fix configuration
if has_vpnclient_app; then
service ynh-vpnclient start
ynh-vpnclient start
fi
;;
restart)
@ -541,7 +541,7 @@ case "$1" in
if has_ip6delegatedprefix ${i}; then
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] hotspot${i}: IPv6 address set"
else
@ -558,14 +558,14 @@ case "$1" in
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 "[ERR] hotspot${i}: NDP and DHCPv4 (dnsmasq) is not running"
exitcode=1
fi
if is_ip4nataddr_set ${i}; then
echo "[OK] hotspot${i}: IPv4 NAT address set"
else

13
conf/ynh-hotspot.service Normal file
View file

@ -0,0 +1,13 @@
[Unit]
Description=YunoHost Wifi Hotspot.
Requires=network.target
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ynh-hotspot start
ExecStop=/usr/local/bin/ynh-hotspot stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View file

@ -39,10 +39,10 @@ if [ "${ynh_version}" -lt 220 ]; then
exit 1
fi
sudo service dnsmasq status &> /dev/null
sudo systemctl is-active dnsmasq &> /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && service dnsmasq start)"
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
exit 1
fi
@ -191,7 +191,8 @@ sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
# Copy init script
sudo install -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
sudo install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/
sudo install -o root -g root -m 0644 ../conf/ynh-hotspot.service /etc/systemd/system/
# Update firewall for DHCP
sudo yunohost firewall allow --no-upnp --ipv6 UDP 547
@ -200,15 +201,13 @@ sudo yunohost firewall allow --no-upnp UDP 67
# Set default inits
# The boot order of these services are important, so they are disabled by default
# and the ynh-hotspot service handles them.
# All services are registred by yunohost in order to prevent conflicts after the uninstall.
sudo yunohost service add hostapd
sudo yunohost service stop hostapd
sudo yunohost service disable hostapd
sudo systemctl disable hostapd
sudo systemctl stop hostapd
sudo yunohost service add php5-fpm
sudo yunohost service enable php5-fpm
sudo systemctl enable php5-fpm
sudo systemctl restart php5-fpm
sudo service nginx reload
sudo systemctl reload nginx
# Remove IPv6 address set if there is a VPN installed
if [ "${ip6_addr}" != none ]; then
@ -218,9 +217,8 @@ if [ "${ip6_addr}" != none ]; then
fi
fi
sudo yunohost service add ynh-hotspot
sudo yunohost service enable ynh-hotspot
sudo service ynh-hotspot start
sudo systemctl enable ynh-hotspot
sudo systemctl start ynh-hotspot
# Update SSO for wifiadmin
sudo yunohost app ssowatconf

View file

@ -21,9 +21,9 @@
domain=$(sudo yunohost app setting hotspot domain)
# The End
sudo service ynh-hotspot stop
sudo yunohost service remove ynh-hotspot
sudo rm -f /etc/init.d/ynh-hotspot
sudo systemctl stop ynh-hotspot
sudo systemctl disable ynh-hotspot
sudo rm -f /etc/systemd/system/ynh-hotspot.service /usr/local/bin/ynh-hotspot
sudo rm -f /tmp/.ynh-hotspot-*
# Update firewall for DHCP
@ -41,9 +41,8 @@ sudo rm -f /lib/firmware/htc-7010.fw
sudo rm -f /lib/firmware/htc-9271.fw
# Restart services
sudo yunohost service stop php5-fpm
sudo yunohost service start php5-fpm
sudo service nginx reload
sudo systemctl restart php5-fpm
sudo systemctl reload nginx
# Remove sources
sudo rm -rf /var/www/wifiadmin/

View file

@ -27,23 +27,23 @@ function moulinette_set($var, $value) {
}
function stop_service() {
exec('sudo service ynh-hotspot stop');
exec('sudo systemctl stop ynh-hotspot');
}
function start_service() {
exec('sudo service ynh-hotspot start', $output, $retcode);
exec('sudo systemctl start ynh-hotspot', $output, $retcode);
return $retcode;
}
function service_status() {
exec('sudo service ynh-hotspot status', $output);
exec('sudo ynh-hotspot status', $output);
return $output;
}
function service_faststatus() {
exec('sudo service hostapd status', $output, $retcode);
exec('sudo systemctl is-active hostapd', $output, $retcode);
return $retcode;
}
@ -146,8 +146,8 @@ dispatch('/', function() {
}
$ip6_net = moulinette_get('ip6_net');
$ip6_net = ($ip6_net == 'none') ? '' : $ip6_net;
$ip4_nat_prefix = moulinette_get('ip4_nat_prefix');
$ip6_net = ($ip6_net == 'none') ? '' : getArray($ip6_net);
$ip4_nat_prefix = getArray(moulinette_get('ip4_nat_prefix'));
set('service_enabled', moulinette_get('service_enabled'));
set('ssids', $ssids);

View file

@ -66,7 +66,7 @@ div#saveconfirmation {
display: none;
padding-right: 15px;
width: 60%;
margin: 0 auto;
margin: 15px auto 0;
}
div#saveconfirmation div#confirm {