mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
[fix] Config panel
This commit is contained in:
parent
e0fe74fbbe
commit
bb2f1b8b13
8 changed files with 207 additions and 121 deletions
|
@ -19,7 +19,7 @@
|
||||||
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP4_NAT_PREFIX>.2,<TPL:IP4_NAT_PREFIX>.254,4h
|
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP4_NAT_PREFIX>.2,<TPL:IP4_NAT_PREFIX>.254,4h
|
||||||
|
|
||||||
# Send DHCPv4 option.
|
# Send DHCPv4 option.
|
||||||
dhcp-option=option:dns-server,<TPL:IP4_DNS0>,<TPL:IP4_DNS1>
|
dhcp-option=option:dns-server,<TPL:IP4_DNS>
|
||||||
|
|
||||||
# Set the DHCP server to authoritative mode. In this mode it will barge in
|
# Set the DHCP server to authoritative mode. In this mode it will barge in
|
||||||
# and take over the lease for any client which broadcasts on the network,
|
# and take over the lease for any client which broadcasts on the network,
|
||||||
|
|
|
@ -20,4 +20,4 @@
|
||||||
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP6_NET>,slaac,64,4h
|
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP6_NET>,slaac,64,4h
|
||||||
|
|
||||||
# Send DHCPv6 option. Note [] around IPv6 addresses.
|
# Send DHCPv6 option. Note [] around IPv6 addresses.
|
||||||
dhcp-option=option6:dns-server,[<TPL:IP6_DNS0>],[<TPL:IP6_DNS1>]
|
dhcp-option=option6:dns-server,<TPL:IP6_DNS>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP4_NAT_PREFIX>.2,<TPL:IP4_NAT_PREFIX>.254,4h
|
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP4_NAT_PREFIX>.2,<TPL:IP4_NAT_PREFIX>.254,4h
|
||||||
|
|
||||||
# Send DHCPv4 option.
|
# Send DHCPv4 option.
|
||||||
dhcp-option=option:dns-server,<TPL:IP4_DNS0>,<TPL:IP4_DNS1>
|
dhcp-option=option:dns-server,<TPL:IP4_DNS>
|
||||||
|
|
||||||
# Set the DHCP server to authoritative mode. In this mode it will barge in
|
# Set the DHCP server to authoritative mode. In this mode it will barge in
|
||||||
# and take over the lease for any client which broadcasts on the network,
|
# and take over the lease for any client which broadcasts on the network,
|
||||||
|
|
|
@ -20,4 +20,4 @@
|
||||||
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP6_NET>,slaac,64,4h
|
dhcp-range=interface:<TPL:WIFI_DEVICE>,<TPL:IP6_NET>,slaac,64,4h
|
||||||
|
|
||||||
# Send DHCPv6 option. Note [] around IPv6 addresses.
|
# Send DHCPv6 option. Note [] around IPv6 addresses.
|
||||||
dhcp-option=option6:dns-server,[<TPL:IP6_DNS0>],[<TPL:IP6_DNS1>]
|
dhcp-option=option6:dns-server,<TPL:IP6_DNS>
|
||||||
|
|
|
@ -140,8 +140,7 @@ start_dhcpd6() {
|
||||||
|
|
||||||
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-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
|
sed "s|<TPL:IP6_NET>|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
||||||
sed "s|<TPL:IP6_DNS0>|${ynh_ip6_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
sed "s|<TPL:IP6_DNS>|${ynh_ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
||||||
sed "s|<TPL:IP6_DNS1>|${ynh_ip6_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
|
||||||
|
|
||||||
dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0
|
dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0
|
||||||
}
|
}
|
||||||
|
@ -152,8 +151,7 @@ start_dhcpd4() {
|
||||||
|
|
||||||
cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.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
|
sed "s|<TPL:IP4_DNS>|${ynh_ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
||||||
sed "s|<TPL:IP4_DNS1>|${ynh_ip4_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
|
||||||
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
||||||
sed "s|<TPL:IP4_NAT_PREFIX>|${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
sed "s|<TPL:IP4_NAT_PREFIX>|${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
||||||
|
|
||||||
|
@ -253,6 +251,7 @@ ynh_setting_get() {
|
||||||
setting=${2}
|
setting=${2}
|
||||||
|
|
||||||
grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
|
grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
|
||||||
|
# '"
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_setting_set() {
|
ynh_setting_set() {
|
||||||
|
@ -262,7 +261,7 @@ ynh_setting_set() {
|
||||||
# performance reasons (it takes a few second to run every yunohost commands)
|
# performance reasons (it takes a few second to run every yunohost commands)
|
||||||
# and to remove the need for the infamous '--need-lock' option/issue.
|
# and to remove the need for the infamous '--need-lock' option/issue.
|
||||||
|
|
||||||
app="$1" key="$2" value="${3:-}" python2.7 - <<EOF
|
app="$1" key="$2" value="${3:-}" python3 - <<EOF
|
||||||
import os, yaml, sys
|
import os, yaml, sys
|
||||||
app = os.environ['app']
|
app = os.environ['app']
|
||||||
key, value = os.environ['key'], os.environ.get('value', None)
|
key, value = os.environ['key'], os.environ.get('value', None)
|
||||||
|
@ -304,11 +303,22 @@ if [ "$1" != restart ]; then
|
||||||
IFS='|' read -a ynh_ip6_addr <<< "$(ynh_setting_get hotspot ip6_addr)"
|
IFS='|' read -a ynh_ip6_addr <<< "$(ynh_setting_get hotspot ip6_addr)"
|
||||||
IFS='|' read -a ynh_ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)"
|
IFS='|' read -a ynh_ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)"
|
||||||
IFS='|' read -a ynh_ip6_net <<< "$(ynh_setting_get hotspot ip6_net)"
|
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_dns <<< "$(ynh_setting_get hotspot dns)"
|
||||||
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)"
|
IFS='|' read -a ynh_ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)"
|
||||||
|
for i in $(seq 0 $((${ynh_multissid} - 1))); do
|
||||||
|
ynh_ip6_dns[${i}]=""
|
||||||
|
ynh_ip4_dns[${i}]=""
|
||||||
|
for ip in ; do
|
||||||
|
if [[ "$ip" == *":"* ]]
|
||||||
|
then
|
||||||
|
ynh_ip6_dns[${i}]+="[$ip],"
|
||||||
|
else
|
||||||
|
ynh_ip4_dns[${i}]+="$ip,"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
ynh_ip6_dns[${i}]="${ynh_ip6_dns[${i}]%%*,}"
|
||||||
|
ynh_ip4_dns[${i}]="${ynh_ip4_dns[${i}]%%*,}"
|
||||||
|
done
|
||||||
|
|
||||||
old_internet_device=$(ynh_setting_get hotspot internet_device)
|
old_internet_device=$(ynh_setting_get hotspot internet_device)
|
||||||
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
|
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
|
||||||
|
|
|
@ -7,24 +7,28 @@ name = "Auto-configuration"
|
||||||
name = "Service"
|
name = "Service"
|
||||||
optional = false
|
optional = false
|
||||||
|
|
||||||
|
[main.service.no_antenna]
|
||||||
|
ask = "No wifi antenna has been detected! If you use a wifi USB dongle and that this one is not listed here, try to unplug and replug it, then reload this page."
|
||||||
|
type = "alert"
|
||||||
|
style = "danger"
|
||||||
|
visible = "no_antenna"
|
||||||
|
|
||||||
[main.service.status]
|
[main.service.status]
|
||||||
ask = "The status of your VPN is unknown."
|
ask = "The status of your VPN is unknown."
|
||||||
type = "alert"
|
type = "alert"
|
||||||
style = "info"
|
style = "info"
|
||||||
|
visible = "! no_antenna"
|
||||||
|
|
||||||
[main.service.service_enabled]
|
[main.service.service_enabled]
|
||||||
ask = "Enable Hotspot"
|
ask = "Enable Hotspot"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
visible = "! no_antenna"
|
||||||
[main.service.doc]
|
|
||||||
ask = "You need to select a wifi antenna interface. If you use a wifi USB dongle and that this one is not listed here, try to unplug and replug it, then reload this page."
|
|
||||||
type = "alert"
|
|
||||||
style = "warning"
|
|
||||||
|
|
||||||
[main.service.wifi_device]
|
[main.service.wifi_device]
|
||||||
ask = "Device"
|
ask = "Device"
|
||||||
type = "select"
|
type = "select"
|
||||||
choices.wlan0 = "wlan0"
|
choices.wlan0 = "wlan0"
|
||||||
|
visible = "! no_antenna"
|
||||||
|
|
||||||
[main.service.wifi_channel]
|
[main.service.wifi_channel]
|
||||||
ask = "Channel"
|
ask = "Channel"
|
||||||
|
@ -40,160 +44,196 @@ name = "Auto-configuration"
|
||||||
choices.9 = "9"
|
choices.9 = "9"
|
||||||
choices.10 = "10"
|
choices.10 = "10"
|
||||||
choices.11 = "11"
|
choices.11 = "11"
|
||||||
|
visible = "! no_antenna"
|
||||||
|
|
||||||
[main.service.ssid_nb]
|
[main.service.multissid]
|
||||||
ask = "Hotspot number"
|
ask = "Hotspot number"
|
||||||
type = "number"
|
type = "select"
|
||||||
min = 1
|
choices.1 = "1"
|
||||||
max = 3
|
choices.2 = "2"
|
||||||
|
choices.3 = "3"
|
||||||
|
visible = "! no_antenna"
|
||||||
|
|
||||||
[main.hotspot1]
|
[main.hotspot1]
|
||||||
name = "Hotspot 1"
|
name = "Hotspot 1"
|
||||||
optional = false
|
optional = false
|
||||||
|
visible = "! no_antenna"
|
||||||
|
|
||||||
[main.hotspot1.wifi_ssid__1]
|
[main.hotspot1.wifi_ssid__1]
|
||||||
ask = "Name (SSID)"
|
ask = "Name (SSID)"
|
||||||
type = "string"
|
type = "string"
|
||||||
pattern.regexp = '^[\w \-]{1,32}$"
|
bind = "array_settings()"
|
||||||
pattern.error = 'SSID in this app are limited to letter, number space, dash and underscores."
|
pattern.regexp = '^[\w \-]{1,32}$'
|
||||||
|
pattern.error = "SSID in this app are limited to letter, number space, dash and underscores."
|
||||||
|
|
||||||
[main.hotspot1.wifi_secure__1]
|
[main.hotspot1.wifi_secure__1]
|
||||||
ask = "Secure"
|
ask = "Secure"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot1.wifi_passphrase__1]
|
[main.hotspot1.wifi_passphrase__1]
|
||||||
ask = "Password (WPA2)"
|
ask = "Password (WPA2)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
redact = true
|
redact = true
|
||||||
|
optional = true
|
||||||
visible = "wifi_secure__1"
|
visible = "wifi_secure__1"
|
||||||
|
pattern.regexp = '^[a-zA-Z0-9]{8,63}$'
|
||||||
|
pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars"
|
||||||
|
|
||||||
[main.hotspot1.advanced__1]
|
[main.hotspot1.advanced__1]
|
||||||
ask = "Advanced settings"
|
ask = "Advanced settings"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot1.ip4_nat_prefix__1]
|
[main.hotspot1.ip4_nat_prefix__1]
|
||||||
ask = "IPv4 NAT prefix (/24)"
|
ask = "IPv4 NAT prefix (/24)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__1"
|
visible = "advanced__1"
|
||||||
pattern.regexp = "^[0-9.]{7,15}$"
|
pattern.regexp = '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
|
||||||
pattern.error = "Please provide a valid IP"
|
pattern.error = "Please provide a private /24 range in the format xxx.xxx.xxx"
|
||||||
|
|
||||||
[main.hotspot1.ip6_net__1]
|
[main.hotspot1.ip6_net__1]
|
||||||
ask = "IPv6 delegated prefix"
|
ask = "IPv6 delegated prefix"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
|
optional = "true"
|
||||||
visible = "advanced__1"
|
visible = "advanced__1"
|
||||||
pattern.regexp = "^[0-9a-fA-F:]+$"
|
pattern.regexp = '^[0-9a-fA-F:]+$'
|
||||||
pattern.error = "Please provide a valid IPv6 Prefix"
|
pattern.error = "Please provide a valid IPv6 Prefix"
|
||||||
|
|
||||||
[main.hotspot1.ip6_firewall__1]
|
[main.hotspot1.ip6_firewall__1]
|
||||||
ask = "IPv6 firewall"
|
ask = "IPv6 firewall"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__1"
|
visible = "advanced__1"
|
||||||
|
|
||||||
[main.hotspot1.dns__1]
|
[main.hotspot1.dns__1]
|
||||||
ask = "DNS resolvers"
|
ask = "DNS resolvers"
|
||||||
type = "tags"
|
type = "tags"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__1"
|
visible = "advanced__1"
|
||||||
pattern.regexp = "^([0-9.]{7,15}|[0-9a-fA-F:]+)$"
|
pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$'
|
||||||
pattern.error = "Not an ip"
|
pattern.error = "Not an ip"
|
||||||
|
|
||||||
[main.hotspot2]
|
[main.hotspot2]
|
||||||
name = "Hotspot 2"
|
name = "Hotspot 2"
|
||||||
visible = "ssid_nb >= 2"
|
visible = "! no_antenna && multissid >= 2"
|
||||||
|
|
||||||
[main.hotspot2.wifi_ssid__2]
|
[main.hotspot2.wifi_ssid__2]
|
||||||
ask = "Name (SSID)"
|
ask = "Name (SSID)"
|
||||||
type = "string"
|
type = "string"
|
||||||
pattern.regexp = '^[\w \-]{1,32}$"
|
bind = "array_settings()"
|
||||||
pattern.error = 'SSID in this app are limited to letter, number space, dash and underscores."
|
pattern.regexp = '^[\w \-]{1,32}$'
|
||||||
|
pattern.error = "SSID in this app are limited to letter, number space, dash and underscores."
|
||||||
|
|
||||||
[main.hotspot2.wifi_secure__2]
|
[main.hotspot2.wifi_secure__2]
|
||||||
ask = "Secure"
|
ask = "Secure"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot2.wifi_passphrase__2]
|
[main.hotspot2.wifi_passphrase__2]
|
||||||
ask = "Password (WPA2)"
|
ask = "Password (WPA2)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
redact = true
|
redact = true
|
||||||
visible = "wifi_secure__2"
|
visible = "wifi_secure__2"
|
||||||
|
pattern.regexp = '^[a-zA-Z0-9]{8,63}$'
|
||||||
|
pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars"
|
||||||
|
|
||||||
[main.hotspot2.advanced__2]
|
[main.hotspot2.advanced__2]
|
||||||
ask = "Advanced settings"
|
ask = "Advanced settings"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot2.ip4_nat_prefix__2]
|
[main.hotspot2.ip4_nat_prefix__2]
|
||||||
ask = "IPv4 NAT prefix (/24)"
|
ask = "IPv4 NAT prefix (/24)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__2"
|
visible = "advanced__2"
|
||||||
pattern.regexp = "^[0-9.]{7,15}$"
|
pattern.regexp = '^[0-9.]{7,15}$'
|
||||||
pattern.error = "Please provide a valid IP"
|
pattern.error = "Please provide a valid IP"
|
||||||
|
|
||||||
[main.hotspot2.ip6_net__2]
|
[main.hotspot2.ip6_net__2]
|
||||||
ask = "IPv6 delegated prefix"
|
ask = "IPv6 delegated prefix"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__2"
|
visible = "advanced__2"
|
||||||
pattern.regexp = "^[0-9a-fA-F:]+$"
|
pattern.regexp = '^[0-9a-fA-F:]+$'
|
||||||
pattern.error = "Please provide a valid IPv6 Prefix"
|
pattern.error = "Please provide a valid IPv6 Prefix"
|
||||||
|
|
||||||
[main.hotspot2.ip6_firewall__2]
|
[main.hotspot2.ip6_firewall__2]
|
||||||
ask = "IPv6 firewall"
|
ask = "IPv6 firewall"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__2"
|
visible = "advanced__2"
|
||||||
|
|
||||||
[main.hotspot2.dns__2]
|
[main.hotspot2.dns__2]
|
||||||
ask = "DNS resolvers"
|
ask = "DNS resolvers"
|
||||||
type = "tags"
|
type = "tags"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__2"
|
visible = "advanced__2"
|
||||||
pattern.regexp = "^([0-9.]{7,15}|[0-9a-fA-F:]+)$"
|
pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$'
|
||||||
pattern.error = "Not an ip"
|
pattern.error = "Not an ip"
|
||||||
|
|
||||||
[main.hotspot3]
|
[main.hotspot3]
|
||||||
name = "Hotspot 3"
|
name = "Hotspot 3"
|
||||||
visible = "ssid_nb >= 3"
|
visible = "! no_antenna && multissid >= 3"
|
||||||
|
|
||||||
[main.hotspot3.wifi_ssid__3]
|
[main.hotspot3.wifi_ssid__3]
|
||||||
ask = "Name (SSID)"
|
ask = "Name (SSID)"
|
||||||
type = "string"
|
type = "string"
|
||||||
pattern.regexp = '^[\w \-]{1,32}$"
|
bind = "array_settings()"
|
||||||
pattern.error = 'SSID in this app are limited to letter, number space, dash and underscores."
|
pattern.regexp = '^[\w \-]{1,32}$'
|
||||||
|
pattern.error = "SSID in this app are limited to letter, number space, dash and underscores."
|
||||||
|
|
||||||
[main.hotspot3.wifi_secure__3]
|
[main.hotspot3.wifi_secure__3]
|
||||||
ask = "Secure"
|
ask = "Secure"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot3.wifi_passphrase__3]
|
[main.hotspot3.wifi_passphrase__3]
|
||||||
ask = "Password (WPA2)"
|
ask = "Password (WPA2)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
redact = true
|
redact = true
|
||||||
visible = "wifi_secure__3"
|
visible = "wifi_secure__3"
|
||||||
|
pattern.regexp = '^[a-zA-Z0-9]{8,63}$'
|
||||||
|
pattern.error = "Only printable alphanumeric characters are permitted in your password. Maximal size 63 chars"
|
||||||
|
|
||||||
[main.hotspot3.advanced__3]
|
[main.hotspot3.advanced__3]
|
||||||
ask = "Advanced settings"
|
ask = "Advanced settings"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
|
|
||||||
[main.hotspot3.ip4_nat_prefix__3]
|
[main.hotspot3.ip4_nat_prefix__3]
|
||||||
ask = "IPv4 NAT prefix (/24)"
|
ask = "IPv4 NAT prefix (/24)"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__3"
|
visible = "advanced__3"
|
||||||
pattern.regexp = "^[0-9.]{7,15}$"
|
pattern.regexp = '^[0-9.]{7,15}$'
|
||||||
pattern.error = "Please provide a valid IP"
|
pattern.error = "Please provide a valid IP"
|
||||||
|
|
||||||
[main.hotspot3.ip6_net__3]
|
[main.hotspot3.ip6_net__3]
|
||||||
ask = "IPv6 delegated prefix"
|
ask = "IPv6 delegated prefix"
|
||||||
type = "string"
|
type = "string"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__3"
|
visible = "advanced__3"
|
||||||
pattern.regexp = "^[0-9a-fA-F:]+$"
|
pattern.regexp = '^[0-9a-fA-F:]+$'
|
||||||
pattern.error = "Please provide a valid IPv6 Prefix"
|
pattern.error = "Please provide a valid IPv6 Prefix"
|
||||||
|
|
||||||
[main.hotspot3.ip6_firewall__3]
|
[main.hotspot3.ip6_firewall__3]
|
||||||
ask = "IPv6 firewall"
|
ask = "IPv6 firewall"
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__3"
|
visible = "advanced__3"
|
||||||
|
|
||||||
[main.hotspot3.dns__3]
|
[main.hotspot3.dns__3]
|
||||||
ask = "DNS resolvers"
|
ask = "DNS resolvers"
|
||||||
type = "tags"
|
type = "tags"
|
||||||
|
bind = "array_settings()"
|
||||||
visible = "advanced__3"
|
visible = "advanced__3"
|
||||||
pattern.regexp = "^([0-9.]{7,15}|[0-9a-fA-F:]+)$"
|
pattern.regexp = '^([0-9.]{7,15}|[0-9a-fA-F:]+)$'
|
||||||
pattern.error = "Not an ip"
|
pattern.error = "Not an ip"
|
||||||
|
|
||||||
|
|
193
scripts/config
193
scripts/config
|
@ -22,21 +22,26 @@ ynh_abort_if_errors
|
||||||
|
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
set_right() {
|
|
||||||
if [ -f $1 ]
|
|
||||||
then
|
|
||||||
chown $app:$app $1
|
|
||||||
chmod go=--- $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
get__no_antenna() {
|
||||||
|
if [[ $(iw_devices) == "" ]]
|
||||||
|
then
|
||||||
|
echo "value: false"
|
||||||
|
else
|
||||||
|
cat << EOF
|
||||||
|
value: false
|
||||||
|
ask: Wifi antenna correctly detected
|
||||||
|
style: info
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
get__status() {
|
get__status() {
|
||||||
local service_enabled=$(ynh_app_setting_get $app service_enabled)
|
local service_enabled=$(ynh_app_setting_get $app service_enabled)
|
||||||
if ip route get 1.2.3.4 | grep -q tun0
|
if systemctl is-active hostapd -q
|
||||||
then
|
then
|
||||||
if [ $service_enabled -eq 1 ]
|
if [ $service_enabled -eq 1 ]
|
||||||
then
|
then
|
||||||
|
@ -44,16 +49,13 @@ get__status() {
|
||||||
style: success
|
style: success
|
||||||
ask:
|
ask:
|
||||||
en: |-
|
en: |-
|
||||||
Your VPN is running :)
|
Your Hotspot is running :)
|
||||||
|
|
||||||
**IPv4:** \`$(curl https://ip.yunohost.org --silent)\`
|
|
||||||
**IPv6:** \`$(curl https://ip6.yunohost.org --silent)\`
|
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
cat << EOF
|
cat << EOF
|
||||||
style: warning
|
style: warning
|
||||||
ask:
|
ask:
|
||||||
en: Your VPN is running, but it shouldn't !
|
en: Your Hotspot is running, but it shouldn't !
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
elif [ $service_enabled -eq 1 ]
|
elif [ $service_enabled -eq 1 ]
|
||||||
|
@ -62,91 +64,139 @@ EOF
|
||||||
style: danger
|
style: danger
|
||||||
ask:
|
ask:
|
||||||
en: |-
|
en: |-
|
||||||
Your VPN is down ! Here are errors logged in the last 5 minutes
|
Your Hotspot is down ! Here are errors logged in the last 5 minutes
|
||||||
\`\`\`
|
\`\`\`
|
||||||
$(journalctl -u openvpn@client -p0..3 --since "- 20 minutes" -o cat | sed 's/^/ /g' | tail -n 15)
|
$(journalctl -u hostapd -n10 -o cat | sed 's/^/ /g')
|
||||||
\`\`\`
|
\`\`\`
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
cat << EOF
|
cat << EOF
|
||||||
style: info
|
style: info
|
||||||
ask:
|
ask:
|
||||||
en: Your VPN is down has expected.
|
en: Your Hotspot is down has expected.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get__login_user() {
|
get__wifi_device() {
|
||||||
if [ -s /etc/openvpn/keys/credentials ]
|
if [[ $(iw_devices) == "" ]]
|
||||||
then
|
then
|
||||||
echo "$(sed -n 1p /etc/openvpn/keys/credentials)"
|
echo "choices: []"
|
||||||
else
|
else
|
||||||
echo ""
|
cat << EOF
|
||||||
|
choices:
|
||||||
|
EOF
|
||||||
|
for device in $(iw_devices)
|
||||||
|
do
|
||||||
|
echo " $device: $device"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get__login_passphrase() {
|
get__array_settings() {
|
||||||
if [ -s /etc/openvpn/keys/credentials ]
|
local short_setting="${1%%__*}"
|
||||||
then
|
local index="${1#*__}"
|
||||||
echo "$(sed -n 2p /etc/openvpn/keys/credentials)"
|
IFS='|' read -a values <<< "$(ynh_app_setting_get $app $short_setting)"
|
||||||
else
|
echo "value: \"${values[$(($index - 1))]:-}\""
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||||
#=================================================
|
#=================================================
|
||||||
validate__login_user() {
|
is_unique() {
|
||||||
|
local short_setting="$1"
|
||||||
if grep -q '^\s*auth-user-pass' ${config_file}
|
local short_setting__1="$1__1"
|
||||||
|
local short_setting__2="$1__2"
|
||||||
|
local short_setting__3="$1__3"
|
||||||
|
if [[ "${!short_setting__1}" == "${!short_setting__2}" ]]
|
||||||
then
|
then
|
||||||
if [[ -z "${login_user}" ]]
|
return 1
|
||||||
then
|
elif [ "$multissid" -ge "3" ] && [[ "${!short_setting__1}" == "${!short_setting__3}" ]]
|
||||||
echo 'A Username is needed with this configuration file'
|
then
|
||||||
fi
|
return 1
|
||||||
|
elif [ "$multissid" -ge "3" ] && [[ "${!short_setting__2}" == "${!short_setting__3}" ]]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
validate__wifi_ssid() {
|
||||||
|
local wifi_ssid_var="wifi_ssid__$1"
|
||||||
|
if [ "$multissid" -ge "$1" ] && [[ -z "${!wifi_ssid_var}" ]]
|
||||||
|
then
|
||||||
|
echo 'SSID required'
|
||||||
|
fi
|
||||||
|
if ! is_unique wifi_ssid
|
||||||
|
then
|
||||||
|
echo 'All Wifi names must be unique'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
validate__wifi_passphrase() {
|
||||||
|
local wifi_secure_var="wifi_secure__$1"
|
||||||
|
local wifi_passphrase_var="wifi_passphrase__$1"
|
||||||
|
if [ "$multissid" -ge "$1" ] && [[ "${!wifi_secure_var}" == "1" ]] && [[ -z "${!wifi_passphrase_var}" ]]
|
||||||
|
then
|
||||||
|
echo 'In WPA2 secure mode, you need to provide a passphrase'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
validate__ip4_nat_prefix() {
|
||||||
|
local ip4_nat_prefix_var="ip4_nat_prefix__$1"
|
||||||
|
if [ "$multissid" -ge "$1" ] && [[ -z "${!ip4_nat_prefix_var}" ]]
|
||||||
|
then
|
||||||
|
echo 'Private IPv4 nat prefix required'
|
||||||
|
fi
|
||||||
|
if ! is_unique ip4_nat_prefix
|
||||||
|
then
|
||||||
|
echo 'All IPv4 prefix must be unique'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
validate__dns() {
|
||||||
|
local dns_var="dns__$1"
|
||||||
|
local ip6_net_var="dns__$1"
|
||||||
|
if [ "$multissid" -ge "$1" ] && ! echo "${!dns_var}" | grep -q "\."
|
||||||
|
then
|
||||||
|
echo 'IPv4 DNS required'
|
||||||
|
fi
|
||||||
|
if [ "$multissid" -ge "$1" ] && [[ -n "${!ip6_net_var}" ]] && ! echo "${!dns_var}" | grep -q ":"
|
||||||
|
then
|
||||||
|
echo 'IPv6 DNS required'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
validate__array_settings() {
|
||||||
|
local short_setting="${1%%__*}"
|
||||||
|
local index="${1#*__}"
|
||||||
|
if type -t validate__$short_setting | grep -q '^function$' 2>/dev/null;
|
||||||
|
then
|
||||||
|
validate__$short_setting $index
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||||
#=================================================
|
#=================================================
|
||||||
set__login_user() {
|
set__array_settings() {
|
||||||
if [ -n "${login_user}" ]
|
local short_setting="${1%%__*}"
|
||||||
|
local index="${1#*__}"
|
||||||
|
local type="${types[$1]}"
|
||||||
|
local value="${!1}"
|
||||||
|
if [[ "$type" == "string" ]] && [ "$multissid" -lt "$index" ]
|
||||||
then
|
then
|
||||||
echo "${login_user}\n${login_passphrase}" > /etc/openvpn/keys/credentials
|
value=""
|
||||||
set_right /etc/openvpn/keys/credentials
|
|
||||||
else
|
|
||||||
echo "" > /etc/openvpn/keys/credentials
|
|
||||||
fi
|
fi
|
||||||
|
local values="$(ynh_app_setting_get $app $short_setting | awk 'BEGIN{FS=OFS="|"} {$'$index'="'${!1}'"}'1)"
|
||||||
|
ynh_app_setting_set --app=$app --key=$short_setting --value="$values"
|
||||||
|
ynh_print_info --message="Configuration key '$short_setting' edited in app settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
set__login_passphrase() {
|
|
||||||
:
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# OVERWRITING VALIDATE STEP
|
# OVERWRITING VALIDATE STEP
|
||||||
#=================================================
|
#=================================================
|
||||||
read_cube() {
|
|
||||||
tmp_dir=$(dirname "$1")
|
|
||||||
setting_value="$(jq --raw-output ".$2" "$1")"
|
|
||||||
if [[ "$setting_value" == "null" ]]
|
|
||||||
then
|
|
||||||
setting_value=''
|
|
||||||
# Save file in tmp dir
|
|
||||||
elif [[ "$2" == "crt_"* ]]
|
|
||||||
then
|
|
||||||
if [ -n "${setting_value}" ]
|
|
||||||
then
|
|
||||||
echo "${setting_value}" | sed 's/|/\n/g' > $tmp_dir/$2
|
|
||||||
setting_value="$tmp_dir/$2"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo $setting_value
|
|
||||||
}
|
|
||||||
ynh_app_config_validate() {
|
ynh_app_config_validate() {
|
||||||
_ynh_app_config_validate
|
_ynh_app_config_validate
|
||||||
}
|
}
|
||||||
|
@ -157,25 +207,14 @@ ynh_app_config_validate() {
|
||||||
ynh_app_config_apply() {
|
ynh_app_config_apply() {
|
||||||
|
|
||||||
# Stop vpn client
|
# Stop vpn client
|
||||||
ynh_print_info --message="Stopping vpnclient in order to edit files"
|
ynh_print_info --message="Stopping hotspot in order to edit files"
|
||||||
touch /tmp/.ynh-vpnclient-stopped
|
/usr/local/bin/ynh-hotspot stop
|
||||||
/usr/local/bin/ynh-vpnclient stop
|
|
||||||
|
|
||||||
chown $app:$app /etc/openvpn/keys
|
|
||||||
chmod go=--- /etc/openvpn/keys
|
|
||||||
|
|
||||||
_ynh_app_config_apply
|
_ynh_app_config_apply
|
||||||
|
|
||||||
set_right /etc/openvpn/client.conf
|
|
||||||
set_right /etc/openvpn/keys/ca-server.crt
|
|
||||||
set_right /etc/openvpn/keys/user.crt
|
|
||||||
set_right /etc/openvpn/keys/user.key
|
|
||||||
set_right /etc/openvpn/keys/user_ta.key
|
|
||||||
|
|
||||||
# Start vpn client
|
# Start vpn client
|
||||||
ynh_print_info --message="Starting vpnclient service if needed"
|
ynh_print_info --message="Starting hotspot service if needed"
|
||||||
/usr/local/bin/ynh-vpnclient start
|
/usr/local/bin/ynh-hotspot start
|
||||||
rm -f /tmp/.ynh-vpnclient-stopped
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,10 +180,7 @@ ynh_app_setting_set --app=$app --key=wifi_channel --value=6
|
||||||
ynh_app_setting_set --app=$app --key=ip6_addr --value="${ip6_addr}"
|
ynh_app_setting_set --app=$app --key=ip6_addr --value="${ip6_addr}"
|
||||||
ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
|
ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
|
||||||
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
|
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
|
||||||
ynh_app_setting_set --app=$app --key=ip6_dns0 --value=2001:913::8
|
ynh_app_setting_set --app=$app --key=dns --value="2001:913::8,2001:910:800::12,80.67.188.188,80.67.169.12"
|
||||||
ynh_app_setting_set --app=$app --key=ip6_dns1 --value=2001:910:800::12
|
|
||||||
ynh_app_setting_set --app=$app --key=ip4_dns0 --value=80.67.188.188
|
|
||||||
ynh_app_setting_set --app=$app --key=ip4_dns1 --value=80.67.169.12
|
|
||||||
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
|
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
|
||||||
ynh_app_setting_set --app=$app --key=vpnclient --value=no
|
ynh_app_setting_set --app=$app --key=vpnclient --value=no
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue