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 function getPackageVersion()
8 local opkgFile = "/usr/lib/opkg/status"
11 for line in io.lines(opkgFile) do
13 return line:match('[%d%.$-]+') or ""
14 elseif line:find("Package: " .. packageName:gsub("%-", "%%%-")) then
21 local packageVersion = getPackageVersion()
22 local statusText = nil
23 if packageVersion == "" then
24 statusText = translatef("%s is not installed or not found", packageName)
27 local serviceRunning, serviceEnabled = false, false
28 if uci:get(packageName, "config", "enabled") == "1" then
31 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
35 if serviceRunning then
36 statusText = translate("Running")
38 statusText = translate("Stopped")
39 if not serviceEnabled then
40 statusText = translatef("%s (disabled)", statusText)
44 m = Map("vpnbypass", translate("VPN Bypass Settings"))
46 h = m:section(NamedSection, "config", packageName, translatef("Service Status [%s %s]", packageName, packageVersion))
47 ss = h:option(DummyValue, "_dummy", translate("Service Status"))
48 ss.template = packageName .. "/status"
50 if packageVersion ~= "" then
51 buttons = h:option(DummyValue, "_dummy")
52 buttons.template = packageName .. "/buttons"
55 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
57 p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
58 p1.datatype = "portrange"
59 -- p1.placeholder = "0-65535"
64 p2 = s:option(DynamicList, "remoteport", translate("Remote Ports to Bypass"), translate("Remote ports to trigger VPN Bypass"))
65 p2.datatype = "portrange"
66 -- p2.placeholder = "0-65535"
71 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)"))
72 r1.datatype = "ip4addr"
73 -- r1.placeholder = ip.new(m.uci:get("network", "lan", "ipaddr"), m.uci:get("network", "lan", "netmask"))
78 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)"))
79 r2.datatype = "ip4addr"
80 -- r2.placeholder = "0.0.0.0/0"
86 s4 = d:section(TypedSection, "dnsmasq")
88 di = s4:option(DynamicList, "ipset", translate("Domains to Bypass"),
89 translatef("Domains to be accessed directly (outside of the VPN tunnel), see %sREADME%s for syntax",
90 "<a href=\"" .. readmeURL .. "#bypass-domains-formatsyntax" .. "\" target=\"_blank\">", "</a>"))
91 function d.on_after_commit(map)
92 util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1")