From 355986b8d3f26c4db7789c6323688eb7087b7dd0 Mon Sep 17 00:00:00 2001 From: Julien VAUBOURG Date: Mon, 10 Nov 2014 22:27:59 +0100 Subject: [PATCH] Some stuff --- README.md | 6 ++-- conf/init_ynh-hotspot | 64 ++++++++++++++++++--------------- manifest.json | 42 ++-------------------- scripts/install | 36 ++++++++++--------- sources/controller.php | 26 +++++++++++--- sources/views/settings.html.php | 14 ++++++-- 6 files changed, 94 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index f364ed9..4570e42 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,19 @@ **Warning: work in progress** +**Warning: currently, there is no checking on input parameters** + Hotspot wifi app for [YunoHost](http://yunohost.org/). * Broadcast your own Wifi internet access in addition to your self-hosted web services. * Without internet access, it's a [PirateBox](https://en.wikipedia.org/wiki/PirateBox). * With the [VPN Client app for YunoHost](https://github.com/jvaubourg/vpnclient_ynh), it's an encrypted Wifi internet access (eventually with [neutral access](https://en.wikipedia.org/wiki/Net_neutrality), without filters, and with IPv6, depending on your VPN provider). -Small computers like [Olimex](https://www.olimex.com) or [Raspberry PI](http://www.raspberrypi.org/) boxes and an USB Wifi dongle like [this one](https://www.olimex.com/Products/USB-Modules/MOD-WIFI-R5370-ANT/) are perfect for a nomade access with low power consumption. - ## Features * WPA2 encryption -* IPv6 compliant (with a delegated prefix) * 802.11n if your antenna is compliant +* IPv6 compliant (with a delegated prefix) * Automatic clients configuration (IPv6 and IPv4) * Announce DNS resolvers (IPv6 and IPv4) * Set an IPv6 from your delegated prefix (*prefix::1*) on the server, to use for the AAAA records diff --git a/conf/init_ynh-hotspot b/conf/init_ynh-hotspot index 600123c..93a0b4d 100644 --- a/conf/init_ynh-hotspot +++ b/conf/init_ynh-hotspot @@ -12,6 +12,10 @@ # Functions ## State functions +has_ip6delegatedprefix() { + [ "${ynh_ip6_net}" != none ] +} + is_ndproxy_set() { proxy=$(ip -6 neighbour show proxy) [ ! -z "${proxy}" ] @@ -51,9 +55,9 @@ is_dhcpd_running() { } is_running() { - is_ndproxy_set && is_nat_set "${new_internet_device}" && is_ip4nataddr_set\ - && is_ip6addr_set && is_forwarding_set && is_hostapd_running\ - && is_radvd_running && is_dhcpd_running + ( has_ip6delegatedprefix && is_ip6addr_set && is_radvd_running && is_ndproxy_set || ! has_ip6delegatedprefix )\ + && is_nat_set "${new_internet_device}" && is_ip4nataddr_set && is_forwarding_set && is_hostapd_running\ + && is_dhcpd_running } ## Setters @@ -222,7 +226,7 @@ case "$1" in echo "Starting..." # Set NDP proxy - if ! is_ndproxy_set; then + if has_ip6delegatedprefix && ! is_ndproxy_set; then echo "Set NDP proxy" set_ndproxy fi @@ -247,7 +251,7 @@ case "$1" in fi # Set the ipv6 address - if ! is_ip6addr_set; then + if has_ip6delegatedprefix && ! is_ip6addr_set; then echo "Set IPv6 address" set_ip6addr fi @@ -267,7 +271,7 @@ case "$1" in # Run radvd # must be running after hostapd - if ! is_radvd_running; then + if has_ip6delegatedprefix && ! is_radvd_running; then echo "Run radvd" start_radvd fi @@ -286,7 +290,7 @@ case "$1" in stop) echo "Stopping..." - if is_ndproxy_set; then + if has_ip6delegatedprefix && is_ndproxy_set; then echo "Unset NDP proxy" unset_ndproxy fi @@ -301,7 +305,7 @@ case "$1" in unset_ip4nataddr fi - if is_ip6addr_set; then + if has_ip6delegatedprefix && is_ip6addr_set; then echo "Unset IPv6 address" unset_ip6addr fi @@ -316,7 +320,7 @@ case "$1" in stop_hostapd fi - if is_radvd_running; then + if has_ip6delegatedprefix && is_radvd_running; then echo "Stop radvd" stop_radvd fi @@ -328,12 +332,30 @@ case "$1" in ;; status) exitcode=0 - - if is_ndproxy_set; then - echo "NDP proxy is correctly set" + + if has_ip6delegatedprefix; then + if is_ndproxy_set; then + echo "NDP proxy is correctly set" + else + echo "NDP proxy is NOT set" + exitcode=1 + fi + + if is_ip6addr_set; then + echo "IPv6 address is correctly set" + else + echo "IPv6 address is NOT set" + exitcode=1 + fi + + if is_radvd_running; then + echo "Radvd is running" + else + echo "Radvd is NOT running" + exitcode=1 + fi else - echo "NDP proxy is NOT set" - exitcode=1 + echo "No IPv6 delegated prefix" fi if is_nat_set "${new_internet_device}"; then @@ -350,13 +372,6 @@ case "$1" in exitcode=1 fi - if is_ip6addr_set; then - echo "IPv6 address is correctly set" - else - echo "IPv6 address is NOT set" - exitcode=1 - fi - if is_forwarding_set; then echo "Forwarding is correctly set" else @@ -371,13 +386,6 @@ case "$1" in exitcode=1 fi - if is_radvd_running; then - echo "Radvd is running" - else - echo "Radvd is NOT running" - exitcode=1 - fi - if is_dhcpd_running; then echo "Dhcpd is running" else diff --git a/manifest.json b/manifest.json index 527879e..f950616 100644 --- a/manifest.json +++ b/manifest.json @@ -60,46 +60,10 @@ { "name": "ip6_net", "ask": { - "en": "Select your IPv6 delegated prefix (netmask number provided must be lesser or equal to 64)", - "fr": "Sélectionnez votre préfixe IPv6 délégué (le masque de sous-réseau fourni doit être plus petit ou égal à 64)" + "en": "Select your IPv6 delegated prefix (leave empty if your Internet Service Provider does not give you a delegated prefix, but you will not have IPv6)", + "fr": "Sélectionnez votre préfixe IPv6 délégué (laisser vide si votre Fournisseur d'Accès à Internet ne vous donne pas de préfixe délégué, mais vous n'aurez pas d'IPv6)" }, - "example": "2001:db8:42::/48" - }, - { - "name": "ip6_dns0", - "ask": { - "en": "Select a first IPv6 DNS resolver", - "fr": "Sélectionnez un premier serveur DNS IPv6" - }, - "example": "2001:913::8", - "default": "2001:913::8" - }, - { - "name": "ip6_dns1", - "ask": { - "en": "Select a second IPv6 DNS resolver", - "fr": "Sélectionnez un second serveur DNS IPv6" - }, - "example": "2001:910:800::40", - "default": "2001:910:800::40" - }, - { - "name": "ip4_dns0", - "ask": { - "en": "Select a first IPv4 DNS resolver", - "fr": "Sélectionnez un premier serveur DNS IPv4" - }, - "example": "80.67.188.188", - "default": "80.67.188.188" - }, - { - "name": "ip4_dns1", - "ask": { - "en": "Select a second IPv4 DNS resolver", - "fr": "Sélectionnez un second serveur DNS IPv4" - }, - "example": "80.67.169.12", - "default": "80.67.169.12" + "example": "2001:db8:42::" } ] } diff --git a/scripts/install b/scripts/install index ac57669..ff82d85 100644 --- a/scripts/install +++ b/scripts/install @@ -7,10 +7,6 @@ wifi_ssid=${3} wifi_passphrase=${4} wifi_device=${5} ip6_net=${6} -ip6_dns0=${7} -ip6_dns1=${8} -ip4_dns0=${9} -ip4_dns1=${10} # Check arguments # TODO @@ -29,11 +25,15 @@ sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server ipta sudo apt-get --assume-yes --force-yes install sipcalc # Compute extra arguments -ip6_expanded_net=$(sipcalc "${ip6_net}" | grep Expanded | awk '{ print $NF; }') -ip6_net=$(sipcalc "${ip6_net}" | grep Compressed | awk '{ print $NF; }') -ip6_addr=$(echo "$(echo "${ip6_expanded_net}" | cut -d: -f1-7):1") -ip6_addr=$(sipcalc "${ip6_addr}" | grep Compressed | awk '{ print $NF; }') -ip4_nat_prefix=10.0.242 +if [ -z "${ip6_net}" ]; then + ip6_net=none + ip6_addr=none +else + ip6_expanded_net=$(sipcalc "${ip6_net}" | grep Expanded | awk '{ print $NF; }') + ip6_net=$(sipcalc "${ip6_net}" | grep Compressed | awk '{ print $NF; }') + ip6_addr=$(echo "$(echo "${ip6_expanded_net}" | cut -d: -f1-7):1") + ip6_addr=$(sipcalc "${ip6_addr}" | grep Compressed | awk '{ print $NF; }') +fi # Save arguments sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}" @@ -43,11 +43,11 @@ sudo yunohost app setting hotspot wifi_channel -v 6 sudo yunohost app setting hotspot wifi_n -v 0 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 "${ip6_dns0}" -sudo yunohost app setting hotspot ip6_dns1 -v "${ip6_dns1}" -sudo yunohost app setting hotspot ip4_dns0 -v "${ip4_dns0}" -sudo yunohost app setting hotspot ip4_dns1 -v "${ip4_dns1}" -sudo yunohost app setting hotspot ip4_nat_prefix -v "${ip4_nat_prefix}" +sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8 +sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12 +sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188 +sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12 +sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242 # Copy confs sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/ @@ -113,9 +113,11 @@ sudo yunohost service start php5-fpm sudo service nginx reload # Remove IPv6 address set if there is a VPN installed -sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/" -if [ "$?" -eq 0 ]; then - sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null +if [ "${ip6_addr}" != none ]; then + sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/" + if [ "$?" -eq 0 ]; then + sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null + fi fi sudo yunohost service add ynh-hotspot diff --git a/sources/controller.php b/sources/controller.php index e50291c..c3ea133 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -8,8 +8,11 @@ function moulinette_set($var, $value) { return exec("sudo yunohost app setting hotspot ".escapeshellarg($var)." -v ".escapeshellarg($value)); } -function restart_service() { +function stop_service() { exec('sudo service ynh-hotspot stop'); +} + +function start_service() { exec('sudo service ynh-hotspot start', $output, $retcode); return $retcode; @@ -32,13 +35,16 @@ dispatch('/', function() { } } + $ip6_net = moulinette_get('ip6_net'); + $ip6_net = ($ip6_net == 'none') ? '' : $ip6_net; + set('wifi_ssid', moulinette_get('wifi_ssid')); set('wifi_passphrase', moulinette_get('wifi_passphrase')); set('wifi_channel', moulinette_get('wifi_channel')); set('wifi_n', moulinette_get('wifi_n')); set('wifi_device', $wifi_device); set('wifi_device_list', $devs_list); - set('ip6_net', moulinette_get('ip6_net')); + set('ip6_net', $ip6_net); set('ip6_dns0', moulinette_get('ip6_dns0')); set('ip6_dns1', moulinette_get('ip6_dns1')); set('ip4_nat_prefix', moulinette_get('ip4_nat_prefix')); @@ -49,19 +55,31 @@ dispatch('/', function() { }); dispatch_put('/settings', function() { + $ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net']; + + stop_service(); + moulinette_set('wifi_ssid', $_POST['wifi_ssid']); moulinette_set('wifi_passphrase', $_POST['wifi_passphrase']); moulinette_set('wifi_channel', $_POST['wifi_channel']); moulinette_set('wifi_n', isset($_POST['wifi_n']) ? 1 : 0); moulinette_set('wifi_device', $_POST['wifi_device']); - moulinette_set('ip6_net', $_POST['ip6_net']); + moulinette_set('ip6_net', $ip6_net); moulinette_set('ip6_dns0', $_POST['ip6_dns0']); moulinette_set('ip6_dns1', $_POST['ip6_dns1']); moulinette_set('ip4_nat_prefix', $_POST['ip4_nat_prefix']); moulinette_set('ip4_dns0', $_POST['ip4_dns0']); moulinette_set('ip4_dns1', $_POST['ip4_dns1']); - $retcode = restart_service(); + # TODO: format ip6_net + if($ip6_net == 'none') { + moulinette_set('ip6_addr', 'none'); + } else { + $ip6_addr = "${ip6_net}1"; + moulinette_set('ip6_addr', $ip6_addr); + } + + $retcode = start_service(); if($retcode == 0) { flash('success', T_('Configuration updated and service successfully reloaded')); diff --git a/sources/views/settings.html.php b/sources/views/settings.html.php index 4cb52e3..2f93749 100644 --- a/sources/views/settings.html.php +++ b/sources/views/settings.html.php @@ -80,15 +80,23 @@
+ + + +
- +
- +
- +