diff options
Diffstat (limited to 'applications/luci-app-vpnbypass/root')
4 files changed, 133 insertions, 28 deletions
diff --git a/applications/luci-app-vpnbypass/root/etc/uci-defaults/40_luci-vpnbypass b/applications/luci-app-vpnbypass/root/etc/uci-defaults/40_luci-vpnbypass index 6df7810334..8e457adce8 100644 --- a/applications/luci-app-vpnbypass/root/etc/uci-defaults/40_luci-vpnbypass +++ b/applications/luci-app-vpnbypass/root/etc/uci-defaults/40_luci-vpnbypass @@ -1,4 +1,5 @@ #!/bin/sh + +/etc/init.d/rpcd reload rm -rf /var/luci-modulecache/; rm -f /var/luci-indexcache; exit 0 - diff --git a/applications/luci-app-vpnbypass/root/usr/libexec/rpcd/luci.vpnbypass b/applications/luci-app-vpnbypass/root/usr/libexec/rpcd/luci.vpnbypass new file mode 100755 index 0000000000..e5eb7c2ca2 --- /dev/null +++ b/applications/luci-app-vpnbypass/root/usr/libexec/rpcd/luci.vpnbypass @@ -0,0 +1,105 @@ +#!/bin/sh +# Copyright 2021 Stan Grishin (stangri@melmac.net) +# shellcheck disable=SC1091,SC2039 + +# TechRef: https://openwrt.org/docs/techref/rpcd + +. /lib/functions.sh +. /usr/share/libubox/jshn.sh + +pkgName="vpnbypass" + +is_enabled() { uci -q get "${1}.config.enabled"; } +is_running() { iptables -t mangle -L | grep -q VPNBYPASS && echo '1' || echo '0'; } +get_version() { grep -A2 -w "Package: $1$" /usr/lib/opkg/status | sed -n 's/Version: //p'; } +print_json_bool() { json_init; json_add_boolean "$1" "$2"; json_dump; json_cleanup; } +print_json_string() { json_init; json_add_string "$1" "$2"; json_dump; json_cleanup; } +logger() { /usr/bin/logger -t "$pkgName" "$@"; } + +get_init_list() { + local name="$1" + json_init + json_add_object "$name" + json_add_boolean 'enabled' "$(is_enabled "$name")" + json_add_boolean 'running' "$(is_running "$name")" + json_close_object + json_dump + json_cleanup +} + +set_init_action() { + local name="$1" action="$2" cmd + if [ ! -f "/etc/init.d/$name" ]; then + print_json_string 'error' 'Init script not found!' + return + fi + case $action in + enable) + cmd="uci -q set ${name}.config.enabled=1 && uci commit $name";; + disable) + cmd="uci -q set ${name}.config.enabled=0 && uci commit $name";; + start|stop|reload|restart) + cmd="/etc/init.d/${name} ${action}";; + esac + if [ -n "$cmd" ] && eval "${cmd}" 1>/dev/null 2>&1; then + print_json_bool "result" '1' + else + print_json_bool "result" '0' + fi +} + +get_init_status() { + local name="$1" + json_init + json_add_object "$name" + json_add_boolean 'enabled' "$(is_enabled "$name")" + json_add_boolean 'running' "$(is_running "$name")" + json_add_string 'version' "$(get_version "$name")" + json_close_object + json_dump + json_cleanup +} + +case "$1" in + list) + json_init + json_add_object "getInitList" + 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_add_object "getInitStatus" + json_add_string 'name' 'name' + 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" + ;; + 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 diff --git a/applications/luci-app-vpnbypass/root/usr/share/luci/menu.d/vpnbypass.json b/applications/luci-app-vpnbypass/root/usr/share/luci/menu.d/vpnbypass.json new file mode 100644 index 0000000000..0a56f9023d --- /dev/null +++ b/applications/luci-app-vpnbypass/root/usr/share/luci/menu.d/vpnbypass.json @@ -0,0 +1,15 @@ +{ + "admin/vpn/vpnbypass": { + "title": "VPN Bypass", + "order": 90, + "action": { + "type": "view", + "path": "vpnbypass/overview" + }, + "depends": { + "acl": [ + "luci-app-vpnbypass" + ] + } + } +} diff --git a/applications/luci-app-vpnbypass/root/usr/share/rpcd/acl.d/luci-app-vpnbypass.json b/applications/luci-app-vpnbypass/root/usr/share/rpcd/acl.d/luci-app-vpnbypass.json index 6dc1cb6a3f..3e3e06745c 100644 --- a/applications/luci-app-vpnbypass/root/usr/share/rpcd/acl.d/luci-app-vpnbypass.json +++ b/applications/luci-app-vpnbypass/root/usr/share/rpcd/acl.d/luci-app-vpnbypass.json @@ -2,39 +2,23 @@ "luci-app-vpnbypass": { "description": "Grant UCI and file access for luci-app-vpnbypass", "read": { - "cgi-io": [ - "exec" - ], - "file": { - "/usr/lib/opkg/status": [ - "read" - ], - "/etc/init.d/vpnbypass *": [ - "exec" - ], - "/etc/init.d/dnsmasq restart *": [ - "exec" - ], - "/usr/bin/grep *": [ - "exec" - ], - "/usr/sbin/grep *": [ - "exec" - ], - "/usr/sbin/iptables *": [ - "exec" + "ubus": { + "luci.vpnbypass": [ + "getInitList", + "getInitStatus" ] }, "uci": [ - "dhcp", - "vpnbypass" + "vpnbypass", + "dnsmasq" ] }, "write": { - "uci": [ - "dhcp", - "vpnbypass" - ] + "ubus": { + "luci.vpnbypass": [ + "setInitAction" + ] + } } } }
\ No newline at end of file |