Translated using Weblate (Japanese)
[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 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}'"))) or ""
9 if packageVersion == "" then
10         statusText = translatef("%s is not installed or not found", packageName)
11 end
12
13 local serviceRunning, serviceEnabled = false, false
14 if uci:get(packageName, "config", "enabled") == "1" then
15         serviceEnabled = true
16 end
17 if sys.call("iptables -t mangle -L | grep -q " .. packageName:upper()) == 0 then
18         serviceRunning = true
19 end
20
21 if serviceRunning then
22         statusText = translate("Running")
23 else
24         statusText = translate("Stopped")
25         if not serviceEnabled then
26                 statusText = translatef("%s (disabled)", statusText)
27         end
28 end
29
30 m = Map("vpnbypass", translate("VPN Bypass Settings"))
31
32 h = m:section(NamedSection, "config", packageName, translatef("Service Status [%s %s]", packageName, packageVersion))
33 ss = h:option(DummyValue, "_dummy", translate("Service Status"))
34 ss.template = packageName .. "/status"
35 ss.value = statusText
36 if packageVersion ~= "" then
37         buttons = h:option(DummyValue, "_dummy")
38         buttons.template = packageName .. "/buttons"
39 end
40
41 s = m:section(NamedSection, "config", "vpnbypass", translate("VPN Bypass Rules"))
42 -- Local Ports
43 p1 = s:option(DynamicList, "localport", translate("Local Ports to Bypass"), translate("Local ports to trigger VPN Bypass"))
44 p1.datatype    = "portrange"
45 -- p1.placeholder = "0-65535"
46 p1.addremove = false
47 p1.optional = false
48
49 -- Remote Ports
50 p2 = s:option(DynamicList, "remoteport", translate("Remote Ports to Bypass"), translate("Remote ports to trigger VPN Bypass"))
51 p2.datatype    = "portrange"
52 -- p2.placeholder = "0-65535"
53 p2.addremove = false
54 p2.optional = false
55
56 -- Local Subnets
57 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)"))
58 r1.datatype    = "ip4addr"
59 -- r1.placeholder = ip.new(m.uci:get("network", "lan", "ipaddr"), m.uci:get("network", "lan", "netmask"))
60 r1.addremove = false
61 r1.optional = false
62
63 -- Remote Subnets
64 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)"))
65 r2.datatype    = "ip4addr"
66 -- r2.placeholder = "0.0.0.0/0"
67 r2.addremove = false
68 r2.optional = false
69
70 -- Domains
71 d = Map("dhcp")
72 s4 = d:section(TypedSection, "dnsmasq")
73 s4.anonymous = true
74 di = s4:option(DynamicList, "ipset", translate("Domains to Bypass"),
75                 translatef("Domains to be accessed directly (outside of the VPN tunnel), see %sREADME%s for syntax", 
76                 "<a href=\"" .. readmeURL   .. "#bypass-domains-formatsyntax" .. "\" target=\"_blank\">", "</a>"))
77 function d.on_after_commit(map)
78         util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1")
79 end
80
81 return m, d