diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 9857e63..f9dc99d 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -261,50 +261,19 @@ stop_hostapd() { ## Tools -moulinette_get() { - var=${1} - gotcha=0 +ynh_setting_get() { + app=${1} + setting=${2} - while [ "${gotcha}" -eq 0 ]; do - value=$(yunohost app setting hotspot "${var}") - - if [[ "${value}" =~ "An instance is already running" ]]; then - sleep $(($((RANDOM%5)) + 1)) - else - gotcha=1 - fi - done - - echo "${value}" + grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$// } -moulinette_vpnclient_get() { - var=${1} - gotcha=0 +ynh_setting_set() { + app=${1} + setting=${2} + value=${3} - while [ "${gotcha}" -eq 0 ]; do - value=$(yunohost app setting vpnclient "${var}") - - if [[ "${value}" =~ "An instance is already running" ]]; then - sleep $(($((RANDOM%5)) + 1)) - else - gotcha=1 - fi - done - - echo "${value}" -} - -moulinette_set() { - var=${1} - value=${2} - - msg=$(yunohost app setting hotspot "${var}" -v "${value}") - - if [ ! $? -eq 0 ]; then - echo "${msg}" >&2 - exit 1 - fi + yunohost app setting "${app}" "${setting}" -v "${value}" } if [ "$1" != restart ]; then @@ -319,23 +288,23 @@ 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_channel=$(moulinette_get wifi_channel) - ynh_multissid=$(moulinette_get multissid) + ynh_service_enabled=$(ynh_setting_get hotspot service_enabled) + ynh_wifi_device=$(ynh_setting_get hotspot wifi_device) + ynh_wifi_channel=$(ynh_setting_get hotspot wifi_channel) + ynh_multissid=$(ynh_setting_get hotspot multissid) - IFS='|' read -a ynh_wifi_ssid <<< "$(moulinette_get wifi_ssid)" - IFS='|' read -a ynh_wifi_secure <<< "$(moulinette_get wifi_secure)" - IFS='|' read -a ynh_wifi_passphrase <<< "$(moulinette_get wifi_passphrase)" - IFS='|' read -a ynh_ip6_addr <<< "$(moulinette_get ip6_addr)" - IFS='|' read -a ynh_ip6_net <<< "$(moulinette_get ip6_net)" - IFS='|' read -a ynh_ip6_dns0 <<< "$(moulinette_get ip6_dns0)" - IFS='|' read -a ynh_ip6_dns1 <<< "$(moulinette_get ip6_dns1)" - IFS='|' read -a ynh_ip4_dns0 <<< "$(moulinette_get ip4_dns0)" - IFS='|' read -a ynh_ip4_dns1 <<< "$(moulinette_get ip4_dns1)" - IFS='|' read -a ynh_ip4_nat_prefix <<< "$(moulinette_get ip4_nat_prefix)" + IFS='|' read -a ynh_wifi_ssid <<< "$(ynh_setting_get hotspot wifi_ssid)" + IFS='|' read -a ynh_wifi_secure <<< "$(ynh_setting_get hotspot wifi_secure)" + IFS='|' read -a ynh_wifi_passphrase <<< "$(ynh_setting_get hotspot wifi_passphrase)" + IFS='|' read -a ynh_ip6_addr <<< "$(ynh_setting_get hotspot ip6_addr)" + IFS='|' read -a ynh_ip6_net <<< "$(ynh_setting_get hotspot ip6_net)" + IFS='|' read -a ynh_ip6_dns0 <<< "$(ynh_setting_get hotspot ip6_dns0)" + IFS='|' read -a ynh_ip6_dns1 <<< "$(ynh_setting_get hotspot ip6_dns1)" + IFS='|' read -a ynh_ip4_dns0 <<< "$(ynh_setting_get hotspot ip4_dns0)" + IFS='|' read -a ynh_ip4_dns1 <<< "$(ynh_setting_get hotspot ip4_dns1)" + IFS='|' read -a ynh_ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)" - old_internet_device=$(moulinette_get internet_device) + old_internet_device=$(ynh_setting_get hotspot internet_device) new_internet_device=$(ip route | awk '/default via/ { print $NF; }') # Switch the NAT interface if there is a VPN @@ -345,24 +314,6 @@ if [ "$1" != restart ]; then 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 -# if [ "${ynh_ip6_net}" != "${vpnclient_ip6_net}" ]; then -# echo "[WARN] The IPv6 delegated prefix is different from the vpnclient one" -# fi -# fi -# fi - fi # Script @@ -378,9 +329,9 @@ case "$1" in touch /tmp/.ynh-hotspot-started if [ "${new_internet_device}" == tun0 ]; then - moulinette_set vpnclient yes + ynh_setting_set hotspot vpnclient yes else - moulinette_set vpnclient no + ynh_setting_set hotspot vpnclient no fi # Check old state of the ipv4 NAT settings @@ -453,7 +404,7 @@ case "$1" in done # Update dynamic settings - moulinette_set internet_device "${new_internet_device}" + ynh_setting_set hotspot internet_device "${new_internet_device}" fi ;; stop) diff --git a/docs/box-project.png b/docs/box-project.png deleted file mode 100644 index 637b7eb..0000000 Binary files a/docs/box-project.png and /dev/null differ diff --git a/docs/box-project_french.pdf b/docs/box-project_french.pdf deleted file mode 100644 index 7cb9fc6..0000000 Binary files a/docs/box-project_french.pdf and /dev/null differ diff --git a/docs/box-project_french.svg b/docs/box-project_french.svg deleted file mode 100644 index 11f8cd2..0000000 --- a/docs/box-project_french.svg +++ /dev/null @@ -1,6268 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - Boîtier AssoFAI double usage(Rasp./Olimex/etc. + YunoHost + Apps VPN & Hotspot) - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - MachinBox - - - - PortEthernet - - - - PortEthernet - - - - PortEthernet - - - - - WiFi - - - - - ArrivéeInternet - - - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - MAISON - - - - MachinFAI - - - - - AssoFAI - - - - - Quelqu'unsurInternet - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IPv6, IPv4, filtrages - - Autohébergement clé-en-main(mail, jabber, blog, etc.) avec YunoHost,nom de domaine perso ou fourni par l'assoet backups automatiques sur l'infra de l'asso - - Déménagement, passage à BiduleFAI,pose chez un ami, etc, quelque soit leréseau, juste en débranchant/rebranchant - - - - - - Un servicesurInternet - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - SmartPhone - - - - - USB - - - - - - - - 3/4G - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - MAISON - - MachinFAI - - - AssoFAI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IPv6, IPv4, filtrages - - - - - - - - - - - - - - - - - - - - - - MachinFAI - - - - - - - - - - - - - - - - - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - SmartPhone - - - - - USB - - - - - - - - 3/4G - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - MAISON - - - - AssoFAI - - - - - Quelqu'unsurInternet - - - - - - - - - - - - - - - - - - - - - - - - - - IPv6, IPv4, filtrages - - - - - - - - - - - - Un servicesurInternet - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - MachinBox - - - - PortEthernet - - - - PortEthernet - - - - PortEthernet - - - - - WiFi - - - - - - - - - - ArrivéeInternet - - - - - - MAISON - - - MachinFAI - - - - - - - - - - - IPv6, IPv4, filtrages - - - - + Connexion à Internet - - Sans boîtier AssoFAI - Avec boîtier AssoFAI - Autohébergement - - Sans boîtier AssoFAI - Avec boîtier AssoFAI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ... et on pourrait aussi faire : - ... et on pourrait aussi faire : - ... ou bien : - - - - Un servicesurInternet - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - MachinBox - - - - PortEthernet - - - - PortEthernet - - - - PortEthernet - - - - - WiFi - - - - - ArrivéeInternet - - - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - MAISON - - - - MachinFAI - - - - - AssoFAI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IPv6, IPv4, filtrages - - WiFi (avec VPN transparent) clé-en-mainavec IP fixes & publiques quelque soit la MachinBox,avec mises à jour automatiques - - Alimentation en USB (e.g. Raspberry PI),en branchant directement sur la MachinBox ?Mini-panneau solaire ? - - Pourrait aussi être en filaire en proposantd'ajouter un petit switch au boîtier - - - - - - - TrucCloud(+ tous ses amis qui ont un accèslibre aux données hébergées) - - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - MachinBox - - - - PortEthernet - - - - PortEthernet - - - - PortEthernet - - - - - WiFi - - - - - - - - - - ArrivéeInternet - - - - - - MAISON - - - MachinFAI - - - - - Quelqu'unsurInternet - - - - - - - - - - - - IPv6, IPv4, filtrages - - - - - - - - Service lambda d'hébergementde fichiers, de blogs, de mails,de messagerie instantanée, etc. - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - MachinBox - - - - PortEthernet - - - - PortEthernet - - - - PortEthernet - - - - - WiFi - - - - - ArrivéeInternet - - - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - ÉVÉNEMENT PUBLIC LAMBDA - - - - - - - - - - IPv6, IPv4, filtrages - - - - - Un servicesurInternet - - - - - MachinFAI - - - - - AssoFAI - - - - - - - - - - - - - - - - - - - - - - - - - - - - Entreprise ? Renater ? Particulierqui veut bien prêter sa connexionmais qui a peur des trucs illégaux ?Accès filtré ? 3/4G ? - Sans MachinBox de reliée,ça pourrait aussi servirsimplement de PirateBox - - - - - - - - - - - PC - - - - WiFi - - - - - - - - - - - - Modem - - - - - PortEthernet - - - - - - - - ArrivéeInternet - - - - - - - - - - DongleWiFi USB - - - - Alimvia USB - - BoîtierAssoFAI - - - - - - - - - - - - PortEthernet - - - - - - - USB - - - - - MAISON - - - - IPv6, IPv4, filtrages - - - - Un servicesurInternet - - - - - AssoFAI - - - - - Devient une simple box wifi de FAI associatif(toujours en plus de l'autohébergement) - - - ... ou encore : - - - diff --git a/sources/controller.php b/sources/controller.php index a83eac8..a038565 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -18,12 +18,16 @@ * along with this program. If not, see . */ -function moulinette_get($var) { - return htmlspecialchars(exec('sudo yunohost app setting hotspot '.escapeshellarg($var))); +function ynh_setting_get($setting) { + $value = exec("sudo grep \"^$setting:\" /etc/yunohost/apps/hotspot/settings.yml"); + $value = preg_replace('/^[^:]+:\s*["\']?/', '', $value); + $value = preg_replace('/\s*["\']$/', '', $value); + + return htmlspecialchars($value); } -function moulinette_set($var, $value) { - return exec('sudo yunohost app setting hotspot '.escapeshellarg($var).' -v '.escapeshellarg($value)); +function ynh_setting_set($setting, $value) { + return exec('sudo yunohost app setting hotspot '.escapeshellarg($setting).' -v '.escapeshellarg($value)); } function stop_service() { @@ -107,9 +111,9 @@ dispatch('/', function() { $devs = iw_devices(); $devs_list = ''; - $wifi_device = moulinette_get('wifi_device'); - $multissid = moulinette_get('multissid'); - $wifi_channel = moulinette_get('wifi_channel'); + $wifi_device = ynh_setting_get('wifi_device'); + $multissid = ynh_setting_get('multissid'); + $wifi_channel = ynh_setting_get('wifi_channel'); foreach($devs AS $dev) { $dev_multissid = iw_multissid($dev); @@ -118,15 +122,15 @@ dispatch('/', function() { $devs_list .= "
  • $dev
  • \n"; } - $wifi_ssid = getArray(moulinette_get('wifi_ssid')); - $wifi_secure = getArray(moulinette_get('wifi_secure')); - $wifi_passphrase = getArray(moulinette_get('wifi_passphrase')); - $ip6_net = getArray(moulinette_get('ip6_net')); - $ip6_dns0 = getArray(moulinette_get('ip6_dns0')); - $ip6_dns1 = getArray(moulinette_get('ip6_dns1')); - $ip4_nat_prefix = getArray(moulinette_get('ip4_nat_prefix')); - $ip4_dns0 = getArray(moulinette_get('ip4_dns0')); - $ip4_dns1 = getArray(moulinette_get('ip4_dns1')); + $wifi_ssid = getArray(ynh_setting_get('wifi_ssid')); + $wifi_secure = getArray(ynh_setting_get('wifi_secure')); + $wifi_passphrase = getArray(ynh_setting_get('wifi_passphrase')); + $ip6_net = getArray(ynh_setting_get('ip6_net')); + $ip6_dns0 = getArray(ynh_setting_get('ip6_dns0')); + $ip6_dns1 = getArray(ynh_setting_get('ip6_dns1')); + $ip4_nat_prefix = getArray(ynh_setting_get('ip4_nat_prefix')); + $ip4_dns0 = getArray(ynh_setting_get('ip4_dns0')); + $ip4_dns1 = getArray(ynh_setting_get('ip4_dns1')); for($i = 0; $i < $multissid; $i++) { $ssid = [ @@ -145,11 +149,11 @@ dispatch('/', function() { array_push($ssids, $ssid); } - $ip6_net = moulinette_get('ip6_net'); + $ip6_net = ynh_setting_get('ip6_net'); $ip6_net = ($ip6_net == 'none') ? '' : getArray($ip6_net); - $ip4_nat_prefix = getArray(moulinette_get('ip4_nat_prefix')); + $ip4_nat_prefix = getArray(ynh_setting_get('ip4_nat_prefix')); - set('service_enabled', moulinette_get('service_enabled')); + set('service_enabled', ynh_setting_get('service_enabled')); set('ssids', $ssids); set('wifi_device', $wifi_device); set('wifi_channel', $wifi_channel); @@ -278,7 +282,7 @@ dispatch_put('/settings', function() { stop_service(); - moulinette_set('service_enabled', $service_enabled); + ynh_setting_set('service_enabled', $service_enabled); $settings = array(); if($service_enabled == 1) { @@ -288,12 +292,12 @@ dispatch_put('/settings', function() { } } - moulinette_set('multissid', count($ssids)); - moulinette_set('wifi_device', $_POST['wifi_device']); - moulinette_set('wifi_channel', $_POST['wifi_channel']); + ynh_setting_set('multissid', count($ssids)); + ynh_setting_set('wifi_device', $_POST['wifi_device']); + ynh_setting_set('wifi_channel', $_POST['wifi_channel']); foreach($settings as $setting => $value) { - moulinette_set($setting, preg_replace('/\|$/', '', $value)); + ynh_setting_set($setting, preg_replace('/\|$/', '', $value)); } $retcode = start_service();