mirror of
https://github.com/openwrt/luci.git
synced 2026-06-01 02:52:02 +08:00
e42b52a348
Maintainer: me Compile tested: x86_64, Dell EMC Edge620, OpenWrt 25.12.1 Run tested: x86_64, Dell EMC Edge620, OpenWrt 25.12.1 Description: update to PKG_RELEASE 5 and status page improvements - Bump PKG_RELEASE from 4 to 5. htdocs/luci-static/resources/https-dns-proxy/status.js: - Remove redundant 'cbi-value-description' class from statusText element. - Remove old README link from instances description. - Restructure instances description to correctly display donate link. - Add a line break element after the instancesText output. po/templates/https-dns-proxy.pot: - Update POT file to reflect changes in status.js. root/usr/libexec/rpcd/luci.https-dns-proxy: - Redirect stderr for is_enabled and is_running functions to /dev/null. - Correctly retrieve service name in `get_init_list` using basename. - Remove extraneous `json_close_array` call from `get_init_status`. - Ensure `ubus_get_ports` uses correct JSON quoting. Signed-off-by: Stan Grishin <stangri@melmac.ca>
199 lines
4.7 KiB
Bash
Executable File
199 lines
4.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Copyright 2023 MOSSDeF, Stan Grishin (stangri@melmac.ca)
|
|
# shellcheck disable=SC1091,SC2039,SC3043
|
|
|
|
# TechRef: https://openwrt.org/docs/techref/rpcd
|
|
|
|
# ubus -v list luci.https-dns-proxy
|
|
# ubus -S call luci.https-dns-proxy getInitList '{"name": "https-dns-proxy" }'
|
|
# ubus -S call luci.https-dns-proxy getInitStatus '{"name": "https-dns-proxy" }'
|
|
# ubus -S call luci.https-dns-proxy getPlatformSupport '{"name": "https-dns-proxy" }'
|
|
# ubus -S call luci.https-dns-proxy getProviders '{"name": "https-dns-proxy" }'
|
|
|
|
readonly packageName="https-dns-proxy"
|
|
readonly providersDir="/usr/share/${packageName}/providers"
|
|
readonly providersJson="/usr/share/${packageName}/providers.json"
|
|
|
|
. "${IPKG_INSTROOT}/lib/functions.sh"
|
|
. "${IPKG_INSTROOT}/usr/share/libubox/jshn.sh"
|
|
|
|
is_enabled() { "/etc/init.d/${1}" enabled >/dev/null 2>&1; }
|
|
is_running() { "/etc/init.d/${1}" running >/dev/null 2>&1; }
|
|
get_version() { /usr/sbin/https-dns-proxy -V | head -1; }
|
|
check_http2() { /usr/sbin/https-dns-proxy -V | grep -q 'nghttp2'; }
|
|
check_http3() { /usr/sbin/https-dns-proxy -V | grep -q 'nghttp3'; }
|
|
ubus_get_ports() { ubus call service list "{\"name\":\"$packageName\"}" | jsonfilter -e "@[\"${packageName}\"].instances.*.data.firewall.*.dest_port"; }
|
|
logger() { /usr/bin/logger -t "$packageName" "$@"; }
|
|
print_json_bool() { json_init; json_add_boolean "$1" "$2"; json_dump; json_cleanup; }
|
|
|
|
get_init_list() {
|
|
local name
|
|
name="$(basename "$1")"
|
|
name="${name:-${packageName}}"
|
|
json_init
|
|
json_add_object "$name"
|
|
if is_enabled "$name"; then
|
|
json_add_boolean 'enabled' '1'
|
|
else
|
|
json_add_boolean 'enabled' '0'
|
|
fi
|
|
if is_running "$name"; then
|
|
json_add_boolean 'running' '1'
|
|
else
|
|
json_add_boolean 'running' '0'
|
|
fi
|
|
json_close_object
|
|
json_dump
|
|
json_cleanup
|
|
}
|
|
|
|
get_init_status() {
|
|
local name
|
|
local i ports
|
|
local version
|
|
name="$(basename "$1")"
|
|
name="${name:-${packageName}}"
|
|
ports="$(ubus_get_ports)"
|
|
[ -z "$version" ] && version="$(get_version "$name")"
|
|
json_init
|
|
json_add_object "$name"
|
|
if is_enabled "$name"; then
|
|
json_add_boolean 'enabled' '1'
|
|
else
|
|
json_add_boolean 'enabled' '0'
|
|
fi
|
|
if is_running "$name"; then
|
|
json_add_boolean 'running' '1'
|
|
else
|
|
json_add_boolean 'running' '0'
|
|
fi
|
|
if [ -n "$ports" ]; then
|
|
json_add_boolean 'force_dns_active' '1'
|
|
json_add_array 'force_dns_ports'
|
|
for i in $ports; do json_add_int '' "$i"; done
|
|
json_close_array
|
|
else
|
|
json_add_boolean 'force_dns_active' '0'
|
|
fi
|
|
json_add_string 'version' "$version"
|
|
json_close_object
|
|
json_dump
|
|
json_cleanup
|
|
}
|
|
|
|
get_platform_support() {
|
|
local name
|
|
name="$(basename "$1")"
|
|
name="${name:-${packageName}}"
|
|
json_init
|
|
json_add_object "$name"
|
|
if check_http2; then
|
|
json_add_boolean 'http2_support' '1'
|
|
else
|
|
json_add_boolean 'http2_support' '0'
|
|
fi
|
|
if check_http3; then
|
|
json_add_boolean 'http3_support' '1'
|
|
else
|
|
json_add_boolean 'http3_support' '0'
|
|
fi
|
|
json_close_object
|
|
json_dump
|
|
json_cleanup
|
|
}
|
|
|
|
get_providers() {
|
|
local f
|
|
echo '{"https-dns-proxy":'
|
|
if [ -s "$providersJson" ]; then
|
|
cat "$providersJson"
|
|
else
|
|
echo '['
|
|
for f in "$providersDir"/*; do
|
|
cat "$f"
|
|
echo ','
|
|
done
|
|
echo ']'
|
|
fi
|
|
echo '}'
|
|
}
|
|
|
|
set_init_action() {
|
|
local action="$2" cmd
|
|
[ "$(basename "$1")" = "$packageName" ] || { print_json_bool 'result' '0'; return 1; }
|
|
case $action in
|
|
enable|disable|start|stop|restart)
|
|
cmd="/etc/init.d/${packageName} ${action}"
|
|
;;
|
|
esac
|
|
if [ -n "$cmd" ] && eval "$cmd" >/dev/null 2>&1; then
|
|
print_json_bool 'result' '1'
|
|
else
|
|
print_json_bool 'result' '0'
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
list)
|
|
json_init
|
|
json_add_object "getInitList"
|
|
json_add_string 'name' "name"
|
|
json_close_object
|
|
json_add_object "getInitStatus"
|
|
json_add_string 'name' 'name'
|
|
json_close_object
|
|
json_add_object "getPlatformSupport"
|
|
json_add_string 'name' 'name'
|
|
json_close_object
|
|
json_add_object "getProviders"
|
|
json_add_string 'name' "name"
|
|
json_close_object
|
|
json_add_object "setInitAction"
|
|
json_add_string 'name' "name"
|
|
json_add_string 'action' "action"
|
|
json_close_object
|
|
json_dump
|
|
json_cleanup
|
|
;;
|
|
call)
|
|
case "$2" in
|
|
getInitList)
|
|
read -r input
|
|
json_load "$input"
|
|
json_get_var name "name"
|
|
json_cleanup
|
|
get_init_list "$name"
|
|
;;
|
|
getInitStatus)
|
|
read -r input
|
|
json_load "$input"
|
|
json_get_var name 'name'
|
|
json_cleanup
|
|
get_init_status "$name"
|
|
;;
|
|
getPlatformSupport)
|
|
read -r input
|
|
json_load "$input"
|
|
json_get_var name 'name'
|
|
json_cleanup
|
|
get_platform_support "$name"
|
|
;;
|
|
getProviders)
|
|
read -r input
|
|
json_load "$input"
|
|
json_get_var name "name"
|
|
json_cleanup
|
|
get_providers "$name"
|
|
;;
|
|
setInitAction)
|
|
read -r input
|
|
json_load "$input"
|
|
json_get_var name "name"
|
|
json_get_var action "action"
|
|
json_cleanup
|
|
set_init_action "$name" "$action"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|