1 local readmeURL = "https://github.com/openwrt/packages/blob/master/net/vpnbypass/files/README.md"
2 local uci = require "luci.model.uci".cursor()
3 local sys = require "luci.sys"
4 local util = require "luci.util"
5 local packageName = "vpnbypass"
7 local packageVersion, statusText = nil, nil
8 packageVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'"))) or ""
9 if packageVersion == "" then
10 statusText = translatef("%s is not installed or not found", packageName)
13 local serviceRunning, serviceEnabled = false, false
14 if uci:get(packageName, "config", "enabled") == "1" then
17 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
21 if serviceRunning then
22 statusText = translate("Running")
24 statusText = translate("Stopped")
25 if not serviceEnabled then
26 statusText = translatef("%s (disabled)", statusText)
30 m = Map("vpnbypass", translate("VPN Bypass Settings"))
32 h = m:section(NamedSection, "config", packageName, translatef("Service Status [%s %s]", packageName, packageVersion))
33 ss = h:option(DummyValue, "_dummy", translate("Service Status"))
34 ss.template = packageName .. "/status"
36 if packageVersion ~= "" then
37 buttons = h:option(DummyValue, "_dummy")
38 buttons.template = packageName .. "/buttons"
41 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
43 p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
44 p1.datatype = "portrange"
45 -- p1.placeholder = "0-65535"
50 p2 = s:option(DynamicList, "remoteport", translate("Remote Ports to Bypass"), translate("Remote ports to trigger VPN Bypass"))
51 p2.datatype = "portrange"
52 -- p2.placeholder = "0-65535"
57 r1 = s:option(DynamicList, "localsubnet", translate("Local IP Addresses to Bypass"), translate("Local IP addresses or subnets with direct internet access (outside of the VPN tunnel)"))
58 r1.datatype = "ip4addr"
59 -- r1.placeholder = ip.new(m.uci:get("network", "lan", "ipaddr"), m.uci:get("network", "lan", "netmask"))
64 r2 = s:option(DynamicList, "remotesubnet", translate("Remote IP Addresses to Bypass"), translate("Remote IP addresses or subnets which will be accessed directly (outside of the VPN tunnel)"))
65 r2.datatype = "ip4addr"
66 -- r2.placeholder = "0.0.0.0/0"
72 s4 = d:section(TypedSection, "dnsmasq")
74 di = s4:option(DynamicList, "ipset", translate("Domains to Bypass"),
75 translatef("Domains to be accessed directly (outside of the VPN tunnel), see %sREADME%s for syntax",
76 "<a href=\"" .. readmeURL .. "#bypass-domains-formatsyntax" .. "\" target=\"_blank\">", "</a>"))
77 function d.on_after_commit(map)
78 util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1")