mirror of
https://github.com/YunoHost-Apps/adguardhome_ynh.git
synced 2024-09-03 18:06:23 +02:00
use the same IP config updating in mechanism for all scripts
This commit is contained in:
parent
87c31e7082
commit
68cfa98d49
6 changed files with 17 additions and 31 deletions
|
@ -13,9 +13,7 @@ http_proxy: ""
|
||||||
language: ""
|
language: ""
|
||||||
theme: auto
|
theme: auto
|
||||||
dns:
|
dns:
|
||||||
bind_hosts:
|
bind_hosts: []
|
||||||
__IPV4_ADDR__
|
|
||||||
__IPV6_ADDR__
|
|
||||||
port: 53
|
port: 53
|
||||||
anonymize_client_ip: false
|
anonymize_client_ip: false
|
||||||
ratelimit: 20
|
ratelimit: 20
|
||||||
|
|
|
@ -81,16 +81,7 @@ process_ips(){
|
||||||
if [ "$(is_public_ip "$ip")" == 0 ] && [ "$open_port_53" == "false" ] ; then
|
if [ "$(is_public_ip "$ip")" == 0 ] && [ "$open_port_53" == "false" ] ; then
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
if [ "${after_first_pass:-}" = true ]; then
|
processed_ips+=$(printf "$processed_ips\n%s" "$ip")
|
||||||
processed_ips+=$(printf "$processed_ips\n%s" "/n")
|
|
||||||
fi
|
|
||||||
after_first_pass=true
|
|
||||||
if [[ "${is_install:-}" = true ]]; then
|
|
||||||
# to get a dash before each IP
|
|
||||||
processed_ips+=$(printf "$processed_ips\n%s" "- $ip")
|
|
||||||
else
|
|
||||||
pprocessed_ips+=$(printf "$processed_ips\n%s" "$ip")
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -98,26 +89,22 @@ process_ips(){
|
||||||
echo "${processed_ips:-}"
|
echo "${processed_ips:-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
update_agh_config(){
|
update_agh_ip_config(){
|
||||||
# used to update the IP adresses in the AGHconfig file
|
# used to update the IP adresses in the AGHconfig file
|
||||||
|
|
||||||
python3 -c "import yaml
|
python3 -c "import yaml
|
||||||
with open(\"$install_dir/AdGuardHome.yaml\", 'r') as file:
|
with open(\"$install_dir/AdGuardHome.yaml\", 'r') as file:
|
||||||
conf_file = yaml.safe_load(file)
|
conf_file = yaml.safe_load(file)
|
||||||
|
|
||||||
need_file_update = False
|
|
||||||
|
|
||||||
conf_file[\"dns\"][\"bind_hosts\"] = []
|
conf_file[\"dns\"][\"bind_hosts\"] = []
|
||||||
if \"$ipv4_addr\":
|
|
||||||
conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv4_addr\")
|
for ip in \"$ipv4_addr\":
|
||||||
need_file_update = True
|
conf_file[\"dns\"][\"bind_hosts\"].append(\"ip\")
|
||||||
if \"$ipv6_addr\":
|
for ip in \"$ipv6_addr\":
|
||||||
conf_file[\"dns\"][\"bind_hosts\"].append(\"$ipv6_addr\")
|
conf_file[\"dns\"][\"bind_hosts\"].append(\"ip\")
|
||||||
need_file_update = True
|
|
||||||
|
with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file:
|
||||||
if need_file_update:
|
yaml.dump(conf_file, file)
|
||||||
with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file:
|
|
||||||
yaml.dump(conf_file, file)
|
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ set__open_port_53() {
|
||||||
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
||||||
|
|
||||||
# update the IP adresses in the AGH config file
|
# update the IP adresses in the AGH config file
|
||||||
update_agh_config
|
update_agh_ip_config
|
||||||
|
|
||||||
# save the new setting
|
# save the new setting
|
||||||
ynh_app_setting_set "$app" --key=open_port_53 --value="$open_port_53"
|
ynh_app_setting_set "$app" --key=open_port_53 --value="$open_port_53"
|
||||||
|
|
|
@ -84,8 +84,6 @@ ipv6_interface="$(get_network_interface 6)"
|
||||||
# put the network interface in a dedicated dnsmasq config
|
# put the network interface in a dedicated dnsmasq config
|
||||||
configure_network_interface_dnsmasq "$ipv4_interface" "$ipv6_interface"
|
configure_network_interface_dnsmasq "$ipv4_interface" "$ipv6_interface"
|
||||||
|
|
||||||
# to warn process_ips that we're doing an installation (to get a dash before each IP)
|
|
||||||
is_install=true
|
|
||||||
# get IPv4 for the AGH config file
|
# get IPv4 for the AGH config file
|
||||||
# the 'sed' is used to get rid of the network prefix ('/24' for example) and the router IP
|
# the 'sed' is used to get rid of the network prefix ('/24' for example) and the router IP
|
||||||
ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
||||||
|
@ -94,6 +92,9 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
|
||||||
# the 'sed' is used to get rid of the network prefix ('/64' for example)
|
# the 'sed' is used to get rid of the network prefix ('/64' for example)
|
||||||
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
||||||
|
|
||||||
|
# update the IP adresses in the AGH config file
|
||||||
|
update_agh_ip_config
|
||||||
|
|
||||||
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")
|
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())")
|
||||||
ynh_app_setting_set --app="$app" --key=password --value="$password"
|
ynh_app_setting_set --app="$app" --key=password --value="$password"
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
|
||||||
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
||||||
|
|
||||||
# update the IP adresses in the AGH config file
|
# update the IP adresses in the AGH config file
|
||||||
update_agh_config
|
update_agh_ip_config
|
||||||
|
|
||||||
|
|
||||||
# this will be treated as a security issue.
|
# this will be treated as a security issue.
|
||||||
|
|
|
@ -137,7 +137,7 @@ ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | g
|
||||||
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")
|
||||||
|
|
||||||
# update the IP adresses in the AGH config file
|
# update the IP adresses in the AGH config file
|
||||||
update_agh_config
|
update_agh_ip_config
|
||||||
|
|
||||||
chmod 600 "$install_dir/AdGuardHome.yaml"
|
chmod 600 "$install_dir/AdGuardHome.yaml"
|
||||||
chown -R "$app:$app" "$install_dir/AdGuardHome.yaml"
|
chown -R "$app:$app" "$install_dir/AdGuardHome.yaml"
|
||||||
|
|
Loading…
Add table
Reference in a new issue