luci-app-vpnbypass: ACL update
[project/luci.git] / applications / luci-app-vpnbypass / luasrc / model / cbi / vpnbypass.lua
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"
6
7 function getPackageVersion()
8 local opkgFile = "/usr/lib/opkg/status"
9 local line
10 local flag = false
11 for line in io.lines(opkgFile) do
12 if flag then
13 return line:match('[%d%.$-]+') or ""
14 elseif line:find("Package: " .. packageName:gsub("%-", "%%%-")) then
15 flag = true
16 end
17 end
18 return ""
19 end
20
21 local packageVersion = getPackageVersion()
22 local statusText = nil
23 if packageVersion == "" then
24 statusText = translatef("%s is not installed or not found", packageName)
25 end
26
27 local serviceRunning, serviceEnabled = false, false
28 if uci:get(packageName, "config", "enabled") == "1" then
29 serviceEnabled = true
30 end
31 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
32 serviceRunning = true
33 end
34
35 if serviceRunning then
36 statusText = translate("Running")
37 else
38 statusText = translate("Stopped")
39 if not serviceEnabled then
40 statusText = translatef("%s (disabled)", statusText)
41 end
42 end
43
44 m = Map("vpnbypass", translate("VPN Bypass Settings"))
45
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"
49 ss.value = statusText
50 if packageVersion ~= "" then
51 buttons = h:option(DummyValue, "_dummy")
52 buttons.template = packageName .. "/buttons"
53 end
54
55 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
56 -- Local Ports
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"
60 p1.addremove = false
61 p1.optional = false
62
63 -- Remote Ports
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"
67 p2.addremove = false
68 p2.optional = false
69
70 -- Local Subnets
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"))
74 r1.addremove = false
75 r1.optional = false
76
77 -- Remote Subnets
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"
81 r2.addremove = false
82 r2.optional = false
83
84 -- Domains
85 d = Map("dhcp")
86 s4 = d:section(TypedSection, "dnsmasq")
87 s4.anonymous = true
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")
93 end
94
95 return m, d