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}'")))
9 if not packageVersion or packageVersion == "" then
11 statusText = packageName .. " " .. translate("is not installed or not found")
13 packageVersion = " [" .. packageName .. " " .. packageVersion .. "]"
16 local serviceRunning, serviceEnabled = false, false
17 if uci:get(packageName, "config", "enabled") == "1" then
20 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
24 if serviceRunning then
25 statusText = translate("Running")
27 statusText = translate("Stopped")
28 if not serviceEnabled then
29 statusText = statusText .. " (" .. translate("disabled") .. ")"
33 m = Map("vpnbypass", translate("VPN Bypass Settings"))
35 h = m:section(NamedSection, "config", packageName, translate("Service Status") .. packageVersion)
36 ss = h:option(DummyValue, "_dummy", translate("Service Status"))
37 ss.template = packageName .. "/status"
39 if packageVersion ~= "" then
40 buttons = h:option(DummyValue, "_dummy")
41 buttons.template = packageName .. "/buttons"
44 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
46 p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
47 p1.datatype = "portrange"
48 -- p1.placeholder = "0-65535"
53 p2 = s:option(DynamicList, "remoteport", translate("Remote Ports to Bypass"), translate("Remote ports to trigger VPN Bypass"))
54 p2.datatype = "portrange"
55 -- p2.placeholder = "0-65535"
60 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)"))
61 r1.datatype = "ip4addr"
62 -- r1.placeholder = ip.new(m.uci:get("network", "lan", "ipaddr"), m.uci:get("network", "lan", "netmask"))
67 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)"))
68 r2.datatype = "ip4addr"
69 -- r2.placeholder = "0.0.0.0/0"
75 s4 = d:section(TypedSection, "dnsmasq")
77 di = s4:option(DynamicList, "ipset", translate("Domains to Bypass"),
78 translate("Domains to be accessed directly (outside of the VPN tunnel), see ")
79 .. [[<a href="]] .. readmeURL .. [[#bypass-domains-formatsyntax" target="_blank">]]
80 .. translate("README") .. [[</a> ]] .. translate("for syntax"))
81 function d.on_after_commit(map)
82 util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1")