From bb2f1b8b13bcadf8d185a8627474d00edc5f879c Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 20 Sep 2021 18:01:28 +0200 Subject: [PATCH] [fix] Config panel --- conf/dhcpdv4.conf.tpl | 2 +- conf/dhcpdv6.conf.tpl | 2 +- conf/dnsmasq_dhcpdv4.conf.tpl | 2 +- conf/dnsmasq_dhcpdv6.conf.tpl | 2 +- conf/ynh-hotspot | 28 +++-- config_panel.toml | 94 ++++++++++++----- scripts/config | 193 ++++++++++++++++++++-------------- scripts/install | 5 +- 8 files changed, 207 insertions(+), 121 deletions(-) diff --git a/conf/dhcpdv4.conf.tpl b/conf/dhcpdv4.conf.tpl index 3ce4b2f..9070007 100644 --- a/conf/dhcpdv4.conf.tpl +++ b/conf/dhcpdv4.conf.tpl @@ -19,7 +19,7 @@ dhcp-range=interface:,.2,.254,4h # Send DHCPv4 option. -dhcp-option=option:dns-server,, +dhcp-option=option:dns-server, # 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, diff --git a/conf/dhcpdv6.conf.tpl b/conf/dhcpdv6.conf.tpl index 5d5834f..acff7fa 100644 --- a/conf/dhcpdv6.conf.tpl +++ b/conf/dhcpdv6.conf.tpl @@ -20,4 +20,4 @@ dhcp-range=interface:,,slaac,64,4h # Send DHCPv6 option. Note [] around IPv6 addresses. -dhcp-option=option6:dns-server,[],[] +dhcp-option=option6:dns-server, diff --git a/conf/dnsmasq_dhcpdv4.conf.tpl b/conf/dnsmasq_dhcpdv4.conf.tpl index 3ce4b2f..9070007 100644 --- a/conf/dnsmasq_dhcpdv4.conf.tpl +++ b/conf/dnsmasq_dhcpdv4.conf.tpl @@ -19,7 +19,7 @@ dhcp-range=interface:,.2,.254,4h # Send DHCPv4 option. -dhcp-option=option:dns-server,, +dhcp-option=option:dns-server, # 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, diff --git a/conf/dnsmasq_dhcpdv6.conf.tpl b/conf/dnsmasq_dhcpdv6.conf.tpl index 5d5834f..acff7fa 100644 --- a/conf/dnsmasq_dhcpdv6.conf.tpl +++ b/conf/dnsmasq_dhcpdv6.conf.tpl @@ -20,4 +20,4 @@ dhcp-range=interface:,,slaac,64,4h # Send DHCPv6 option. Note [] around IPv6 addresses. -dhcp-option=option6:dns-server,[],[] +dhcp-option=option6:dns-server, diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 449a770..f707d98 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -140,8 +140,7 @@ start_dhcpd6() { sed "s||${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf sed "s||${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s||${ynh_ip6_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - sed "s||${ynh_ip6_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf + sed "s||${ynh_ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf 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} - sed "s||${ynh_ip4_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - sed "s||${ynh_ip4_dns1[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf + sed "s||${ynh_ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf sed "s||${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf sed "s||${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf @@ -253,6 +251,7 @@ ynh_setting_get() { setting=${2} grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$// + # '" } ynh_setting_set() { @@ -262,7 +261,7 @@ ynh_setting_set() { # performance reasons (it takes a few second to run every yunohost commands) # and to remove the need for the infamous '--need-lock' option/issue. - app="$1" key="$2" value="${3:-}" python2.7 - </dev/null; + then + validate__$short_setting $index fi } #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= -set__login_user() { - if [ -n "${login_user}" ] +set__array_settings() { + local short_setting="${1%%__*}" + local index="${1#*__}" + local type="${types[$1]}" + local value="${!1}" + if [[ "$type" == "string" ]] && [ "$multissid" -lt "$index" ] then - echo "${login_user}\n${login_passphrase}" > /etc/openvpn/keys/credentials - set_right /etc/openvpn/keys/credentials - else - echo "" > /etc/openvpn/keys/credentials + value="" 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 #================================================= -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 } @@ -157,25 +207,14 @@ ynh_app_config_validate() { ynh_app_config_apply() { # Stop vpn client - ynh_print_info --message="Stopping vpnclient in order to edit files" - touch /tmp/.ynh-vpnclient-stopped - /usr/local/bin/ynh-vpnclient stop + ynh_print_info --message="Stopping hotspot in order to edit files" + /usr/local/bin/ynh-hotspot stop - chown $app:$app /etc/openvpn/keys - chmod go=--- /etc/openvpn/keys - _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 - ynh_print_info --message="Starting vpnclient service if needed" - /usr/local/bin/ynh-vpnclient start - rm -f /tmp/.ynh-vpnclient-stopped + ynh_print_info --message="Starting hotspot service if needed" + /usr/local/bin/ynh-hotspot start } diff --git a/scripts/install b/scripts/install index 0b3de42..5d7dd2b 100644 --- a/scripts/install +++ b/scripts/install @@ -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_firewall --value=1 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=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=dns --value="2001:913::8,2001:910:800::12,80.67.188.188,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=vpnclient --value=no