Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/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
3 m = Map("vpnbypass", translate("VPN Bypass Settings"))
4
5 h = m:section(NamedSection, "config", "vpnbypass", translate("Service Status"))
6 local packageName = "vpnbypass"
7 local uci = require "luci.model.uci".cursor()
8 local sys = require "luci.sys"
9 local http = require "luci.http"
10 local dispatcher = require "luci.dispatcher"
11 en = h:option(Button, "__toggle")
12 if enabledFlag ~= "1" then
13         en.title      = translate("Service is disabled/stopped")
14         en.inputtitle = translate("Enable/Start")
15         en.inputstyle = "apply important"
16 else
17         en.title      = translate("Service is enabled/started")
18         en.inputtitle = translate("Stop/Disable")
19         en.inputstyle = "reset important"
20 end
21 function en.write()
22         enabledFlag = enabledFlag == "1" and "0" or "1"
23         uci:set(packageName, "config", "enabled", enabledFlag)
24         uci:save(packageName)
25         uci:commit(packageName)
26         if enabledFlag == "0" then
27                 sys.init.stop(packageName)
28                 sys.init.disable(packageName)
29         else
30                 sys.init.enable(packageName)
31                 sys.init.start(packageName)
32         end
33         http.redirect(dispatcher.build_url("admin/services/" .. packageName))
34 end
35
36 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
37
38 -- Local Ports
39 p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
40 p1.datatype    = "portrange"
41 -- p1.placeholder = "0-65535"
42 p1.addremove = false
43 p1.optional = false
44
45 -- Remote Ports
46 p2 = s:option(DynamicList, "remoteport", translate("Remote Ports to Bypass"), translate("Remote ports to trigger VPN Bypass"))
47 p2.datatype    = "portrange"
48 -- p2.placeholder = "0-65535"
49 p2.addremove = false
50 p2.optional = false
51
52 -- Local Subnets
53 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)"))
54 r1.datatype    = "ip4addr"
55 -- r1.placeholder = ip.new(m.uci:get("network", "lan", "ipaddr"), m.uci:get("network", "lan", "netmask"))
56 r1.addremove = false
57 r1.optional = false
58
59 -- Remote Subnets
60 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)"))
61 r2.datatype    = "ip4addr"
62 -- r2.placeholder = "0.0.0.0/0"
63 r2.addremove = false
64 r2.optional = false
65
66 -- Domains
67 d = Map("dhcp")
68 s4 = d:section(TypedSection, "dnsmasq")
69 s4.anonymous = true
70 di = s4:option(DynamicList, "ipset", translate("Domains to Bypass"),
71     translate("Domains to be accessed directly (outside of the VPN tunnel), see ")
72                 .. [[<a href="]] .. readmeURL .. [[#bypass-domains-formatsyntax" target="_blank">]]
73     .. translate("README") .. [[</a> ]] .. translate("for syntax"))
74 function d.on_after_commit(map)
75     sys.init.restart("dnsmasq")
76 end
77
78 return m, d