diff options
author | Yousong Zhou <yszhou4tech@gmail.com> | 2017-07-09 03:18:15 +0800 |
---|---|---|
committer | Yousong Zhou <yszhou4tech@gmail.com> | 2017-07-23 23:40:26 +0800 |
commit | 48b5ccfad54d6d21468f68a2ae8c52c377bc5c5e (patch) | |
tree | c5dd2a8fdcee0a4fe3c1dc49d0929a9a12b70678 /applications/luci-app-shadowsocks-libev/luasrc/model/cbi | |
parent | 90de442347a54400d37ddb36ecb7a99e913d026a (diff) |
luci-app-shadowsocks-libev: rewrite for shadowsocks-libev 3.0.6-2
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Diffstat (limited to 'applications/luci-app-shadowsocks-libev/luasrc/model/cbi')
5 files changed, 266 insertions, 157 deletions
diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev.lua deleted file mode 100644 index 97ce83f771..0000000000 --- a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev.lua +++ /dev/null @@ -1,157 +0,0 @@ --- Copyright 2015 Jian Chang <aa65535@live.com> --- Licensed to the public under the Apache License 2.0. - -local m, s, o, e, a - -if luci.sys.call("pidof ss-redir >/dev/null") == 0 then - m = Map("shadowsocks-libev", translate("ShadowSocks-libev"), translate("ShadowSocks-libev is running")) -else - m = Map("shadowsocks-libev", translate("ShadowSocks-libev"), translate("ShadowSocks-libev is not running")) -end - -e = { - "table", - "rc4", - "rc4-md5", - "aes-128-cfb", - "aes-192-cfb", - "aes-256-cfb", - "bf-cfb", - "camellia-128-cfb", - "camellia-192-cfb", - "camellia-256-cfb", - "cast5-cfb", - "des-cfb", - "idea-cfb", - "rc2-cfb", - "seed-cfb", - "salsa20", - "chacha20", -} - --- Global Setting -s = m:section(TypedSection, "shadowsocks-libev", translate("Global Setting")) -s.anonymous = true - -o = s:option(Flag, "enable", translate("Enable")) -o.default = 1 -o.rmempty = false - -o = s:option(Value, "server", translate("Server Address")) -o.datatype = "ipaddr" -o.rmempty = false - -o = s:option(Value, "server_port", translate("Server Port")) -o.datatype = "port" -o.rmempty = false - -o = s:option(Value, "local_port", translate("Local Port")) -o.datatype = "port" -o.default = 1080 -o.rmempty = false - -o = s:option(Value, "timeout", translate("Connection Timeout")) -o.datatype = "uinteger" -o.default = 60 -o.rmempty = false - -o = s:option(Value, "password", translate("Password")) -o.password = true -o.rmempty = false - -o = s:option(ListValue, "encrypt_method", translate("Encrypt Method")) -for i,v in ipairs(e) do - o:value(v) -end -o.rmempty = false - -o = s:option(Value, "ignore_list", translate("Ignore List")) -o:value("/dev/null", translate("Disabled")) -o.default = "/dev/null" -o.rmempty = false - --- UDP Relay -s = m:section(TypedSection, "shadowsocks-libev", translate("UDP Relay")) -s.anonymous = true - -o = s:option(ListValue, "udp_mode", translate("Relay Mode")) -o:value("0", translate("Disabled")) -o:value("1", translate("Enabled")) -o:value("2", translate("Custom")) -o.default = 0 -o.rmempty = false - -o = s:option(Value, "udp_server", translate("Server Address")) -o.datatype = "ipaddr" -o:depends("udp_mode", 2) - -o = s:option(Value, "udp_server_port", translate("Server Port")) -o.datatype = "port" -o:depends("udp_mode", 2) - -o = s:option(Value, "udp_local_port", translate("Local Port")) -o.datatype = "port" -o.default = 1081 -o:depends("udp_mode", 2) - -o = s:option(Value, "udp_timeout", translate("Connection Timeout")) -o.datatype = "uinteger" -o.default = 60 -o:depends("udp_mode", 2) - -o = s:option(Value, "udp_password", translate("Password")) -o.password = true -o:depends("udp_mode", 2) - -o = s:option(ListValue, "udp_encrypt_method", translate("Encrypt Method")) -for i,v in ipairs(e) do - o:value(v) -end -o:depends("udp_mode", 2) - --- UDP Forward -s = m:section(TypedSection, "shadowsocks-libev", translate("UDP Forward")) -s.anonymous = true - -o = s:option(Flag, "tunnel_enable", translate("Enable")) -o.default = 1 -o.rmempty = false - -o = s:option(Value, "tunnel_port", translate("UDP Local Port")) -o.datatype = "port" -o.default = 5300 - -o = s:option(Value, "tunnel_forward", translate("Forwarding Tunnel")) -o.default = "8.8.4.4:53" - --- Access Control -s = m:section(TypedSection, "shadowsocks-libev", translate("Access Control")) -s.anonymous = true - -s:tab("lan_ac", translate("LAN")) - -o = s:taboption("lan_ac", ListValue, "lan_ac_mode", translate("Access Control")) -o:value("0", translate("Disabled")) -o:value("1", translate("Allow listed only")) -o:value("2", translate("Allow all except listed")) -o.default = 0 -o.rmempty = false - -o = s:taboption("lan_ac", DynamicList, "lan_ac_ip", translate("LAN IP List")) -o.datatype = "ipaddr" - -luci.ip.neighbors({ family = 4 }, function(entry) - if entry.reachable then - o:value(entry.dest:string()) - end -end) - -s:tab("wan_ac", translate("WAN")) - -o = s:taboption("wan_ac", DynamicList, "wan_bp_ip", translate("Bypassed IP")) -o.datatype = "ip4addr" - -o = s:taboption("wan_ac", DynamicList, "wan_fw_ip", translate("Forwarded IP")) -o.datatype = "ip4addr" - -return m diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instance-details.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instance-details.lua new file mode 100644 index 0000000000..d9a61d0bf7 --- /dev/null +++ b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instance-details.lua @@ -0,0 +1,49 @@ +-- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com> +-- Licensed to the public under the Apache License 2.0. + +local ds = require "luci.dispatcher" +local ss = require "luci.model.shadowsocks-libev" + +local sname = arg[1] +local redirect_url = ds.build_url("admin/services/shadowsocks-libev/instances") +local s, o + +local m = Map("shadowsocks-libev") +local sdata = m:get(sname) +if not sdata then + luci.http.redirect(redirect_url) + return +end +local stype = sdata[".type"] +m.redirect = redirect_url +m.title = "shadowsocks-libev - %s - %s" % {stype, sname} + + +s = m:section(NamedSection, sname, stype) +s:tab("general", translate("General Settings")) +s:tab("advanced", translate("Advanced Settings")) +s:taboption("general", Flag, "disabled", translate("Disable")) +ss.option_install_package(s, "general") + +if stype == "ss_server" then + ss.options_server(s, "general") + o = s:taboption("general", Value, "bind_address", + translate("Bind address"), + translate("The address ss-server will initiate connection from")) + o.datatype = "ipaddr" + o.placeholder = "0.0.0.0" + ss.values_ipaddr(o) + o = s:taboption("general", Value, "manager_address", translate("Manager address")) + o.datatype = "hostport" +else + ss.options_client(s, "general") + if stype == "ss_tunnel" then + o = s:taboption("general", Value, "tunnel_address", + translate("Tunnel address"), + translate("The address ss-tunnel will forward traffic to")) + o.datatype = "hostport" + end +end +ss.options_common(s, "advanced") + +return m diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instances.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instances.lua new file mode 100644 index 0000000000..15e57df6bd --- /dev/null +++ b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/instances.lua @@ -0,0 +1,113 @@ +-- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com> +-- Licensed to the public under the Apache License 2.0. + +local ds = require "luci.dispatcher" +local ss = require "luci.model.shadowsocks-libev" +local ut = require "luci.util" +local m, s, o + +m = Map("shadowsocks-libev", + translate("Local Instances"), + translate("Instances of shadowsocks-libev components, e.g. ss-local, \ + ss-redir, ss-tunnel, ss-server, etc. To enable an instance it \ + is required to enable both the instance itself and the remote \ + server it refers to.")) + +local instances = {} +local cfgtypes = { "ss_local", "ss_redir", "ss_server", "ss_tunnel" } +local instances_data = ut.ubus("service", "list", {name = "shadowsocks-libev"})["shadowsocks-libev"] +if instances_data ~= nil then + instances_data = instances_data["instances"] +end + +for sname, sdata in pairs(m:get()) do + local key, value = ss.cfgvalue_overview(sdata) + if key ~= nil then + if instances_data and instances_data[key] and instances_data[key]["running"] then + value["running"] = "yes" + else + value["running"] = "no" + end + instances[key] = value + end +end + +s = m:section(Table, instances) +s.addremove = true +s.template_addremove = "shadowsocks-libev/add_instance" +s.extedit = function(self, section) + local value = instances[section] + if type(value) == "table" then + return ds.build_url(unpack(ds.context.requestpath), + "services/shadowsocks-libev/instances", + value[".name"]) + end +end +s.parse = function(self, ...) + Table.parse(self, ...) + + local crval = REMOVE_PREFIX .. self.config + local name = self.map:formvaluetable(crval) + for k,v in pairs(name) do + local value = instances[k] + local sname = value[".name"] + if type(value) == "table" then + m:del(sname) + instances[k] = nil + for _, oname in ipairs({"redir_tcp", "redir_udp"}) do + local ovalue = m:get("ss_rules", oname) + if ovalue == sname then + m:del("ss_rules", oname) + end + end + end + end + + local stype = m:formvalue("_newinst.type") + local sname = m:formvalue("_newinst.name") + if ut.contains(cfgtypes, stype) then + local created + if sname and #sname > 0 then + created = m:set(sname, nil, stype) + else + created = m:add(stype) + sname = created + end + if created then + m.uci:save("shadowsocks-libev") + luci.http.redirect(ds.build_url( + "admin/services/shadowsocks-libev/instances", sname + )) + end + end +end + +o = s:option(DummyValue, "name", translate("Name")) +o.rawhtml = true +o = s:option(DummyValue, "overview", translate("Overview")) +o.rawhtml = true + +s:option(DummyValue, "running", translate("Running")) + +o = s:option(Button, "disabled", translate("Enable/Disable")) +o.render = function(self, section, scope) + if instances[section].disabled then + self.title = translate("Disabled") + self.inputstyle = "reset" + else + self.title = translate("Enabled") + self.inputstyle = "save" + end + Button.render(self, section, scope) +end +o.write = function(self, section) + local sdata = instances[section] + if type(sdata) == "table" then + local sname = sdata[".name"] + local disabled = not sdata["disabled"] + sdata["disabled"] = disabled + m:set(sname, "disabled", tostring(disabled)) + end +end + +return m diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua new file mode 100644 index 0000000000..fe5f9c31b8 --- /dev/null +++ b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/rules.lua @@ -0,0 +1,73 @@ +-- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com> +-- Licensed to the public under the Apache License 2.0. + +local ss = require("luci.model.shadowsocks-libev") + +local m, s, o + +m = Map("shadowsocks-libev", + translate("Redir Rules"), + translate("On this page you can configure how traffics are to be \ + forwarded to ss-redir instances. \ + If enabled, packets will first have their source ip addresses checked \ + against <em>Src ip bypass</em>, <em>Src ip forward</em>, \ + <em>Src ip checkdst</em> and if none matches <em>Src default</em> \ + will give the default action to be taken. \ + If the prior check results in action <em>checkdst</em>, packets will continue \ + to have their destination addresses checked.")) + + +s = m:section(NamedSection, "ss_rules", "ss-rules") +s:tab("general", translate("General Settings")) +s:tab("srcip", translate("Source Settings")) +s:tab("dstip", translate("Destination Settings")) + +s:taboption('general', Flag, "disabled", translate("Disable")) +ss.option_install_package(s, 'general') + +o = s:taboption('general', ListValue, "redir_tcp", + translate("ss-redir for TCP")) +ss.values_redir(o, 'tcp') +o = s:taboption('general', ListValue, "redir_udp", + translate("ss-redir for UDP")) +ss.values_redir(o, 'udp') + +o = s:taboption('general', ListValue, "local_default", + translate("Local-out default"), + translate("Default action for locally generated packets")) +ss.values_actions(o) +s:taboption('general', Value, "ipt_args", + translate("Extra arguments"), + translate("Passes additional arguments to iptables. Use with care!")) + +s:taboption('srcip', DynamicList, "src_ips_bypass", + translate("Src ip bypass"), + translate("Bypass redir action for packets with source addresses in this list")) +s:taboption('srcip', DynamicList, "src_ips_forward", + translate("Src ip forward"), + translate("Go through redir action for packets with source addresses in this list")) +s:taboption('srcip', DynamicList, "src_ips_checkdst", + translate("Src ip checkdst"), + translate("Continue to have dst address checked for packets with source addresses in this list")) +o = s:taboption('srcip', ListValue, "src_default", + translate("Src default"), + translate("Default action for packets whose source addresses do not match any of the source ip list")) +ss.values_actions(o) + +s:taboption('dstip', DynamicList, "dst_ips_bypass", + translate("Dst ip bypass"), + translate("Bypass redir action for packets with destination addresses in this list")) +s:taboption('dstip', DynamicList, "dst_ips_forward", + translate("Dst ip forward"), + translate("Go through redir action for packets with destination addresses in this list")) + +o = s:taboption('dstip', FileBrowser, "dst_ips_bypass_file", + translate("Dst ip bypass file"), + translate("File containing ip addresses for the purposes as with <em>Dst ip bypass</em>")) +o.datatype = "file" +s:taboption('dstip', FileBrowser, "dst_ips_forward_file", + translate("Dst ip forward file"), + translate("File containing ip addresses for the purposes as with <em>Dst ip forward</em>")) +o.datatype = "file" + +return m diff --git a/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/servers.lua b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/servers.lua new file mode 100644 index 0000000000..71c66562e1 --- /dev/null +++ b/applications/luci-app-shadowsocks-libev/luasrc/model/cbi/shadowsocks-libev/servers.lua @@ -0,0 +1,31 @@ +-- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com> +-- Licensed to the public under the Apache License 2.0. + +local ds = require "luci.dispatcher" +local ss = require("luci.model.shadowsocks-libev") + +local m, s + +m = Map("shadowsocks-libev", + translate("Remote Servers"), + translate("Definition of remote shadowsocks servers. \ + Disable any of them will also disable instances refering to it.")) + +local sname = arg[1] +if sname then + if not m:get(sname) then + luci.http.redirect(ds.build_url("admin/services/shadowsocks-libev/servers")) + return + end + s = m:section(NamedSection, sname, "server") + m.title = m.title .. ' - ' .. sname +else + s = m:section(TypedSection, "server") + s.template = 'cbi/tblsection' + s.addremove = true +end + +s:option(Flag, "disabled", translate("Disable")) +ss.options_server(s) + +return m |