From 3622accc8e5ecc384b4e3ac821698109165aa835 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Fri, 14 Feb 2020 12:56:26 +0800 Subject: [PATCH] luci-app-ssr-plus: add self-signed certificate for v2ray/trojan --- package/lean/luci-app-ssr-plus/Makefile | 2 +- .../model/cbi/shadowsocksr/client-config.lua | 53 ++++++++++++++++++- .../luasrc/view/shadowsocksr/certupload.htm | 4 ++ .../luci-app-ssr-plus/po/zh-cn/ssr-plus.po | 21 ++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 package/lean/luci-app-ssr-plus/luasrc/view/shadowsocksr/certupload.htm diff --git a/package/lean/luci-app-ssr-plus/Makefile b/package/lean/luci-app-ssr-plus/Makefile index 30abf387f..94e6840ec 100644 --- a/package/lean/luci-app-ssr-plus/Makefile +++ b/package/lean/luci-app-ssr-plus/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-ssr-plus -PKG_RELEASE:=139 +PKG_RELEASE:=140 PKG_VERSION:=1 include $(INCLUDE_DIR)/package.mk diff --git a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index 81d25ccec..a4c2008e5 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -8,6 +8,7 @@ local fs = require "nixio.fs" local sys = require "luci.sys" local sid = arg[1] local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid") +local http = require "luci.http" local function isKcptun(file) if not fs.access(file, "rwx", "rx", "rx") then @@ -165,11 +166,11 @@ o.rmempty = true o:depends("type", "ss") -- Shadowsocks Plugin -o = s:option(Value, "plugin", "Plugin") +o = s:option(Value, "plugin", translate("Plugin")) o.rmempty = true o:depends("type", "ss") -o = s:option(Value, "plugin_opts", "Plugin Opts") +o = s:option(Value, "plugin_opts", translate("Plugin Opts")) o.rmempty = true o:depends("type", "ss") @@ -366,6 +367,54 @@ o.rmempty = true o.default = "8" o:depends("mux", "1") +-- [[ Cert ]]-- +o = s:option(Flag, "certificate", translate("Self-signed Certificate")) +o.rmempty = true +o.default = "0" +o:depends("type", "trojan") +o:depends("type", "v2ray") +o.description = translate("If you have a self-signed certificate,please check the box") + +o = s:option(DummyValue, "upload", translate("Upload")) +o.template = "shadowsocksr/certupload" +o:depends("certificate", 1) + +cert_dir = "/etc/ssl/private/" +local path + +http.setfilehandler( + function(meta, chunk, eof) + if not fd then + if (not meta) or (not meta.name) or (not meta.file) then return end + fd = nixio.open(cert_dir .. meta.file, "w") + if not fd then + path = translate("Create upload file error.") + return + end + end + if chunk and fd then + fd:write(chunk) + end + if eof and fd then + fd:close() + fd = nil + path = '/etc/ssl/private/' .. meta.file .. '' + end + end + ) +if luci.http.formvalue("upload") then + local f = luci.http.formvalue("ulfile") + if #f <= 0 then + path = translate("No specify upload file.") + end +end + +o = s:option(Value, "certpath", translate("Current Certificate Path")) +o:depends("certificate", 1) +o:value("/etc/ssl/private/") +o.description = translate("Please confirm the current certificate path") +o.default = "/etc/ssl/private/" + o = s:option(Flag, "fast_open", translate("TCP Fast Open")) o.rmempty = true o.default = "0" diff --git a/package/lean/luci-app-ssr-plus/luasrc/view/shadowsocksr/certupload.htm b/package/lean/luci-app-ssr-plus/luasrc/view/shadowsocksr/certupload.htm new file mode 100644 index 000000000..27ad7ae83 --- /dev/null +++ b/package/lean/luci-app-ssr-plus/luasrc/view/shadowsocksr/certupload.htm @@ -0,0 +1,4 @@ +<%+cbi/valueheader%> + + +<%+cbi/valuefooter%> \ No newline at end of file diff --git a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index 6320e9442..f6bdd2eab 100644 --- a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -546,3 +546,24 @@ msgstr "插件" msgid "Plugin Opts" msgstr "插件参数" + +msgid "Self-signed Certificate" +msgstr "自签证书" + +msgid "If you have a self-signed certificate,please check the box" +msgstr "如果你使用自签证书,请选择" + +msgid "upload" +msgstr "上传" + +msgid "Upload" +msgstr "上传" + +msgid "No specify upload file." +msgstr "没有上传证书" + +msgid "Current Certificate Path" +msgstr "当前证书路径" + +msgid "Please confirm the current certificate path" +msgstr "请选择确认所传证书,证书不正确将无法运行"