luci-app-vpnbypass: better service control & buttons styling
[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 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
10 packageVersion = ""
11 statusText = packageName .. " " .. translate("is not installed or not found")
12 else
13 packageVersion = " [" .. packageName .. " " .. packageVersion .. "]"
14 end
15
16 local serviceRunning, serviceEnabled = false, false
17 if uci:get(packageName, "config", "enabled") == "1" then
18 serviceEnabled = true
19 end
20 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
21 serviceRunning = true
22 end
23
24 if serviceRunning then
25 statusText = translate("Running")
26 else
27 statusText = translate("Stopped")
28 if not serviceEnabled then
29 statusText = statusText .. " (" .. translate("disabled") .. ")"
30 end
31 end
32
33 m = Map("vpnbypass", translate("VPN Bypass Settings"))
34
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"
38 ss.value = statusText
39 if packageVersion ~= "" then
40 buttons = h:option(DummyValue, "_dummy")
41 buttons.template = packageName .. "/buttons"
42 end
43
44 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
45 -- Local Ports
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"
49 p1.addremove = false
50 p1.optional = false
51
52 -- Remote Ports
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"
56 p2.addremove = false
57 p2.optional = false
58
59 -- Local Subnets
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"))
63 r1.addremove = false
64 r1.optional = false
65
66 -- Remote Subnets
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"
70 r2.addremove = false
71 r2.optional = false
72
73 -- Domains
74 d = Map("dhcp")
75 s4 = d:section(TypedSection, "dnsmasq")
76 s4.anonymous = true
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")
83 end
84
85 return m, d