diff --git a/conf/hostapd.conf.tpl b/conf/hostapd.conf.tpl index 8e73836..4246c72 100644 --- a/conf/hostapd.conf.tpl +++ b/conf/hostapd.conf.tpl @@ -27,8 +27,8 @@ macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 -wpa=2 -wpa_passphrase= -wpa_key_mgmt=WPA-PSK -wpa_pairwise=TKIP -rsn_pairwise=CCMP +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 74d3a63..eba1b37 100644 --- a/conf/init_ynh-hotspot +++ b/conf/init_ynh-hotspot @@ -150,6 +150,12 @@ start_hostapd() { 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 + service hostapd start } @@ -235,8 +241,10 @@ if [ "$1" != restart ]; then echo -n "Retrieving Yunohost settings... " + 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) @@ -284,6 +292,8 @@ case "$1" in start) if is_running; then echo "Already started" + elif [ "${ynh_service_enabled}" -eq 0 ]; then + echo "Disabled service" else echo "[hotspot] Starting..." touch /tmp/.ynh-hotspot-started @@ -386,6 +396,11 @@ case "$1" in status) exitcode=0 + if [ "${ynh_service_enabled}" -eq 0 ]; then + echo "[ERR] Hotspot Service disabled" + exitcode=1 + fi + echo "[INFO] Autodetected internet interface: ${new_internet_device} (last start: ${old_internet_device})" if has_ip6delegatedprefix; then diff --git a/manifest.json b/manifest.json index 4b9c6be..1ce9263 100644 --- a/manifest.json +++ b/manifest.json @@ -47,6 +47,15 @@ "fr": "Choisissez un mot de passe wifi (au minimum 8 caractères pour le WPA2)" }, "example": "VhegT8oev0jZI" + }, + { + "name": "firmware_nonfree", + "ask": { + "en": "Install non-free firmwares for the wifi dongle (yes/no)", + "fr": "Installer des firmwares non-libres pour la clé USB wifi (yes/no)" + }, + "example": "yes", + "default": "yes" } ] } diff --git a/manifest.json.options b/manifest.json.options index 576cb45..aa9d696 100644 --- a/manifest.json.options +++ b/manifest.json.options @@ -48,6 +48,15 @@ }, "example": "VhegT8oev0jZI" }, + { + "name": "firmware_nonfree", + "ask": { + "en": "Install non-free firmwares for the wifi dongle (yes/no)", + "fr": "Installer des firmwares non-libres pour la clé USB wifi (yes/no)" + }, + "example": "yes", + "default": "yes" + }, { "name": "ip6_net", "ask": { diff --git a/screenshot.png b/screenshot.png index b038635..138179c 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/scripts/install b/scripts/install index 6402588..9271065 100644 --- a/scripts/install +++ b/scripts/install @@ -22,13 +22,14 @@ domain=${1} url_path=${2} wifi_ssid=${3} wifi_passphrase=${4} +firmware_nonfree=${5} ## ## These arguments are optional but YunoHost is not yet able to handle them with the web installer ## See manifest.json.options ## # -#ip6_net=${5} +#ip6_net=${6} # Check arguments if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then @@ -59,7 +60,11 @@ packages='php5-fpm sipcalc hostapd iptables wireless-tools dnsmasq' # Packaged USB Wireless Device firmwares # Based on https://wiki.debian.org/WiFi#USB_Devices -packages="$packages firmware-atheros atmel-firmware firmware-linux-free firmware-linux-nonfree firmware-realtek firmware-ralink firmware-libertas zd1211-firmware" +if [ "${firmware_nonfree}" == yes ]; then + packages="$packages firmware-atheros atmel-firmware firmware-linux-free firmware-linux-nonfree firmware-realtek firmware-ralink firmware-libertas zd1211-firmware" +else + packages="$packages firmware-linux-free" +fi sudo apt-get --assume-yes --force-yes install ${packages} @@ -109,7 +114,9 @@ if [ $? -eq 0 ]; then fi # Save arguments +sudo yunohost app setting hotspot service_enabled -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 diff --git a/sources/controller.php b/sources/controller.php index f9cb0fc..f8a1700 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -87,7 +87,9 @@ dispatch('/', function() { $ip6_net = ($ip6_net == 'none') ? '' : $ip6_net; $ip4_nat_prefix = moulinette_get('ip4_nat_prefix'); + set('service_enabled', moulinette_get('service_enabled')); set('wifi_ssid', moulinette_get('wifi_ssid')); + set('wifi_secure', moulinette_get('wifi_secure')); set('wifi_passphrase', moulinette_get('wifi_passphrase')); set('wifi_channel', moulinette_get('wifi_channel')); set('wifi_n', moulinette_get('wifi_n')); @@ -111,95 +113,111 @@ dispatch_put('/settings', function() { $ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net']; $ip6_addr = 'none'; + $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; + $wifi_secure = isset($_POST['wifi_secure']) ? 1 : 0; - try { - if(empty($_POST['wifi_ssid']) || empty($_POST['wifi_passphrase']) || empty($_POST['wifi_channel'])) { - throw new Exception(T_('Your Wifi Hotspot needs a name, a password and a channel')); - } - - if(strlen($_POST['wifi_passphrase']) < 8 || strlen($_POST['wifi_passphrase']) > 63) { - throw new Exception(T_('Your password must from 8 to 63 characters (WPA2 passphrase)')); - } - - if(preg_match('/[^[:print:]]/', $_POST['wifi_passphrase'])) { - throw new Exception(T_('Only printable ASCII characters are permitted in your password')); - } - - if(!$wifi_device_exists) { - throw new Exception(T_('The wifi antenna interface seems not exist on the system')); - } - - if($ip6_net != 'none') { - $ip6_net = ipv6_expanded($ip6_net); - - if(empty($ip6_net)) { - throw new Exception(T_('The IPv6 Delegated Prefix format looks bad')); + if($service_enabled == 1) { + try { + if(empty($_POST['wifi_ssid']) || empty($_POST['wifi_passphrase']) || empty($_POST['wifi_channel'])) { + throw new Exception(T_('Your Wifi Hotspot needs a name, a password and a channel')); } - $ip6_blocs = explode(':', $ip6_net); - $ip6_addr = "${ip6_blocs[0]}:${ip6_blocs[1]}:${ip6_blocs[2]}:${ip6_blocs[3]}:${ip6_blocs[4]}:${ip6_blocs[5]}:${ip6_blocs[6]}:42"; + if(strlen($_POST['wifi_passphrase']) < 8 || strlen($_POST['wifi_passphrase']) > 63) { + throw new Exception(T_('Your password must from 8 to 63 characters (WPA2 passphrase)')); + } - $ip6_net = ipv6_compressed($ip6_net); - $ip6_addr = ipv6_compressed($ip6_addr); + if(preg_match('/[^[:print:]]/', $_POST['wifi_passphrase'])) { + throw new Exception(T_('Only printable ASCII characters are permitted in your password')); + } + + if(!$wifi_device_exists) { + throw new Exception(T_('The wifi antenna interface seems not exist on the system')); + } + + if($ip6_net != 'none') { + $ip6_net = ipv6_expanded($ip6_net); + + if(empty($ip6_net)) { + throw new Exception(T_('The IPv6 Delegated Prefix format looks bad')); + } + + $ip6_blocs = explode(':', $ip6_net); + $ip6_addr = "${ip6_blocs[0]}:${ip6_blocs[1]}:${ip6_blocs[2]}:${ip6_blocs[3]}:${ip6_blocs[4]}:${ip6_blocs[5]}:${ip6_blocs[6]}:42"; + + $ip6_net = ipv6_compressed($ip6_net); + $ip6_addr = ipv6_compressed($ip6_addr); + } + + $ip6_dns0 = ipv6_expanded($ip6_dns0); + + if(empty($_POST['ip6_dns0'])) { + throw new Exception(T_('The format of the first IPv6 DNS Resolver looks bad')); + } + + $ip6_dns0 = ipv6_compressed($ip6_dns0); + $ip6_dns1 = ipv6_expanded($ip6_dns1); + + if(empty($_POST['ip6_dns1'])) { + throw new Exception(T_('The format of the second IPv6 DNS Resolver looks bad')); + } + + $ip6_dns1 = ipv6_compressed($ip6_dns1); + + if(inet_pton($_POST['ip4_dns0']) === false) { + throw new Exception(T_('The format of the first IPv4 DNS Resolver looks bad')); + } + + if(inet_pton($_POST['ip4_dns1']) === false) { + throw new Exception(T_('The format of the second IPv4 DNS Resolver looks bad')); + } + + if(inet_pton("${_POST['ip4_nat_prefix']}.0") === false) { + throw new Exception(T_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)')); + } + + if(filter_var("${_POST['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) { + throw new Exception(T_('The IPv4 NAT Prefix must be from a private range')); + } + + } catch(Exception $e) { + flash('error', $e->getMessage().' ('.T_('configuration not updated').').'); + goto redirect; } - - $ip6_dns0 = ipv6_expanded($ip6_dns0); - - if(empty($_POST['ip6_dns0'])) { - throw new Exception(T_('The format of the first IPv6 DNS Resolver looks bad')); - } - - $ip6_dns0 = ipv6_compressed($ip6_dns0); - $ip6_dns1 = ipv6_expanded($ip6_dns1); - - if(empty($_POST['ip6_dns1'])) { - throw new Exception(T_('The format of the second IPv6 DNS Resolver looks bad')); - } - - $ip6_dns1 = ipv6_compressed($ip6_dns1); - - if(inet_pton($_POST['ip4_dns0']) === false) { - throw new Exception(T_('The format of the first IPv4 DNS Resolver looks bad')); - } - - if(inet_pton($_POST['ip4_dns1']) === false) { - throw new Exception(T_('The format of the second IPv4 DNS Resolver looks bad')); - } - - if(inet_pton("${_POST['ip4_nat_prefix']}.0") === false) { - throw new Exception(T_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)')); - } - - if(filter_var("${_POST['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) { - throw new Exception(T_('The IPv4 NAT Prefix must be from a private range')); - } - - } catch(Exception $e) { - flash('error', $e->getMessage().' ('.T_('configuration not updated').').'); - goto redirect; } 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', $ip6_net); - moulinette_set('ip6_addr', $ip6_addr); - 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']); + moulinette_set('service_enabled', $service_enabled); - $retcode = start_service(); + if($service_enabled == 1) { + moulinette_set('wifi_ssid', $_POST['wifi_ssid']); + moulinette_set('wifi_secure', $wifi_secure); + + if($wifi_secure == 1) { + 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', $ip6_net); + moulinette_set('ip6_addr', $ip6_addr); + 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 = start_service(); + + if($retcode == 0) { + flash('success', T_('Configuration updated and service successfully reloaded')); + } else { + flash('error', T_('Configuration updated but service reload failed')); + } - if($retcode == 0) { - flash('success', T_('Configuration updated and service successfully reloaded')); } else { - flash('error', T_('Configuration updated but service reload failed')); + flash('success', T_('Service successfully disabled')); } redirect: diff --git a/sources/public/js/custom.js b/sources/public/js/custom.js index 0e9a8a7..d2a651f 100644 --- a/sources/public/js/custom.js +++ b/sources/public/js/custom.js @@ -101,6 +101,22 @@ $(document).ready(function() { $('#wifiparty_close').click(function() { $('#wifiparty_screen').hide(); }); + + $('#wifi_secure').change(function() { + if($('#wifi_secure').parent().hasClass('off')) { + $('.secure').hide('slow'); + } else { + $('.secure').show('slow'); + } + }); + + $('#service_enabled').change(function() { + if($('#service_enabled').parent().hasClass('off')) { + $('.enabled').hide('slow'); + } else { + $('.enabled').show('slow'); + } + }); }); $(document).keydown(function(e) { diff --git a/sources/views/settings.html.php b/sources/views/settings.html.php index 4e6e0a4..2c6c2ce 100644 --- a/sources/views/settings.html.php +++ b/sources/views/settings.html.php @@ -64,6 +64,23 @@
+
+

+
+ +
+
+ +
"> +
+ /> +
+
+
+
+
+ +
>

@@ -75,8 +92,17 @@
- +
+ +
+
+ /> +
+
+
+ +
>
@@ -107,8 +133,8 @@
-
- +