luci-app-ssr-libev-server: add package
This commit is contained in:
parent
4d8a3f1c5c
commit
e4b61553ef
18
package/lienol/luci-app-ssr-libev-server/Makefile
Normal file
18
package/lienol/luci-app-ssr-libev-server/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2018-2019 Lienol
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for SSR Libev Server
|
||||
LUCI_DEPENDS:=+libsodium +shadowsocksr-libev-server
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=6-20190704
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
-- Copyright 2018-2019 Lienol <lawlienol@gmail.com>
|
||||
module("luci.controller.ssr_libev_server", package.seeall)
|
||||
local http = require "luci.http"
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/ssr_libev_server") then return end
|
||||
entry({"admin", "vpn"}, firstchild(), "VPN", 45).dependent = false
|
||||
entry({"admin", "vpn", "ssr_libev_server"}, cbi("ssr_libev_server/index"),
|
||||
_("SSR Libev Server"), 2).dependent = true
|
||||
entry({"admin", "vpn", "ssr_libev_server", "config"},
|
||||
cbi("ssr_libev_server/config")).leaf = true
|
||||
|
||||
entry({"admin", "vpn", "ssr_libev_server", "users_status"},
|
||||
call("ssr_libev_users_status")).leaf = true
|
||||
end
|
||||
|
||||
local function http_write_json(content)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(content or {code = 1})
|
||||
end
|
||||
|
||||
function ssr_libev_users_status()
|
||||
local e = {}
|
||||
e.index = luci.http.formvalue("index")
|
||||
e.status = luci.sys.call(
|
||||
"ps -w| grep -v grep | grep '/var/etc/ssr_libev_server/" ..
|
||||
luci.http.formvalue("id") .. "' >/dev/null") == 0
|
||||
http_write_json(e)
|
||||
end
|
||||
@ -0,0 +1,65 @@
|
||||
local i = "ssr_libev_server"
|
||||
local d = require "luci.dispatcher"
|
||||
local a, t, e
|
||||
|
||||
local encrypt_method = {
|
||||
"table", "rc4", "rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb",
|
||||
"aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb",
|
||||
"camellia-192-cfb", "camellia-256-cfb", "cast5-cfb", "des-cfb", "idea-cfb",
|
||||
"rc2-cfb", "seed-cfb", "salsa20", "chacha20", "chacha20-ietf"
|
||||
}
|
||||
|
||||
local protocol = {"origin"}
|
||||
local obfs = {"plain", "http_simple", "http_post"}
|
||||
|
||||
a = Map(i, "ShadowsocksR Libev " .. translate("Server Config"))
|
||||
a.redirect = d.build_url("admin", "vpn", "ssr_libev_server")
|
||||
|
||||
t = a:section(NamedSection, arg[1], "user", "")
|
||||
t.addremove = false
|
||||
t.dynamic = false
|
||||
|
||||
e = t:option(Flag, "enable", translate("Enable"))
|
||||
e.default = "1"
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(Value, "remarks", translate("Remarks"))
|
||||
e.default = translate("Remarks")
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(Value, "port", translate("Port"))
|
||||
e.datatype = "port"
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(Value, "password", translate("Password"))
|
||||
e.password = true
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(ListValue, "method", translate("Encrypt Method"))
|
||||
for a, t in ipairs(encrypt_method) do e:value(t) end
|
||||
|
||||
e = t:option(ListValue, "protocol", translate("Protocol"))
|
||||
for a, t in ipairs(protocol) do e:value(t) end
|
||||
|
||||
e = t:option(Value, "protocol_param", translate("Protocol Param"))
|
||||
|
||||
e = t:option(ListValue, "obfs", translate("Obfs"))
|
||||
for a, t in ipairs(obfs) do e:value(t) end
|
||||
|
||||
e = t:option(Value, "obfs_param", translate("Obfs Param"))
|
||||
|
||||
e = t:option(Value, "timeout", translate("Connection Timeout"))
|
||||
e.datatype = "uinteger"
|
||||
e.default = 300
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(ListValue, "fast_open", translate("Fast Open"))
|
||||
e:value("false")
|
||||
e:value("true")
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(Flag, "udp_forward", translate("UDP Forward"))
|
||||
e.default = "1"
|
||||
e.rmempty = false
|
||||
|
||||
return a
|
||||
@ -0,0 +1,61 @@
|
||||
local o = require "luci.dispatcher"
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local cursor = luci.model.uci.cursor()
|
||||
local appname = "ssr_libev_server"
|
||||
local a, t, e
|
||||
|
||||
a = Map(appname, translate("ShadowsocksR Libev Server"))
|
||||
|
||||
t = a:section(TypedSection, "global", translate("Global Settings"))
|
||||
t.anonymous = true
|
||||
t.addremove = false
|
||||
|
||||
e = t:option(Flag, "enable", translate("Enable"))
|
||||
e.rmempty = false
|
||||
|
||||
t = a:section(TypedSection, "user", translate("Users Manager"))
|
||||
t.anonymous = true
|
||||
t.addremove = true
|
||||
t.template = "cbi/tblsection"
|
||||
t.extedit = o.build_url("admin", "vpn", appname, "config", "%s")
|
||||
|
||||
function t.create(e, t)
|
||||
local e = TypedSection.create(e, t)
|
||||
luci.http.redirect(o.build_url("admin", "vpn", appname, "config", e))
|
||||
end
|
||||
|
||||
function t.remove(t, a)
|
||||
t.map.proceed = true
|
||||
t.map:del(a)
|
||||
luci.http.redirect(o.build_url("admin", "vpn", appname))
|
||||
end
|
||||
|
||||
e = t:option(Flag, "enable", translate("Enable"))
|
||||
e.width = "5%"
|
||||
e.rmempty = false
|
||||
|
||||
e = t:option(DummyValue, "status", translate("Status"))
|
||||
e.template = "ssr_libev_server/users_status"
|
||||
|
||||
e = t:option(DummyValue, "remarks", translate("Remarks"))
|
||||
e.width = "15%"
|
||||
|
||||
e = t:option(DummyValue, "port", translate("Port"))
|
||||
e.width = "10%"
|
||||
|
||||
e = t:option(DummyValue, "password", translate("Password"))
|
||||
e.width = "15%"
|
||||
|
||||
e = t:option(DummyValue, "method", translate("Encrypt Method"))
|
||||
e.width = "15%"
|
||||
|
||||
e = t:option(DummyValue, "protocol", translate("Protocol"))
|
||||
e.width = "15%"
|
||||
|
||||
e = t:option(DummyValue, "obfs", translate("Obfs"))
|
||||
e.width = "15%"
|
||||
|
||||
a:append(Template("ssr_libev_server/users_list_status"))
|
||||
|
||||
return a
|
||||
@ -0,0 +1,23 @@
|
||||
<%
|
||||
local dsp = require "luci.dispatcher"
|
||||
-%>
|
||||
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
var ssr_libev_users_status = document.getElementsByClassName('ssr_libev_users_status');
|
||||
for(var i = 0; i < ssr_libev_users_status.length; i++) {
|
||||
var id = ssr_libev_users_status[i].parentElement.parentElement.parentElement.id;
|
||||
id = id.substr(id.lastIndexOf("-") + 1);
|
||||
XHR.poll(1,'<%=dsp.build_url("admin/vpn/ssr_libev_server/users_status")%>', {
|
||||
index: i,
|
||||
id: id
|
||||
},
|
||||
function(x, result) {
|
||||
ssr_libev_users_status[result.index].setAttribute("style","font-weight:bold;");
|
||||
ssr_libev_users_status[result.index].setAttribute("color",result.status ? "green":"red");
|
||||
ssr_libev_users_status[result.index].innerHTML = (result.status ? '✓' : 'X');
|
||||
}
|
||||
);
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
@ -0,0 +1,3 @@
|
||||
<%+cbi/valueheader%>
|
||||
<font class="ssr_libev_users_status" hint="<%=self:cfgvalue(section)%>">--</font>
|
||||
<%+cbi/valuefooter%>
|
||||
@ -0,0 +1,65 @@
|
||||
msgid "ShadowsocksR Libev Server"
|
||||
msgstr "ShadowsocksR Libev 服务器"
|
||||
|
||||
msgid "SSR Libev Server"
|
||||
msgstr "SSR Libev服务器"
|
||||
|
||||
msgid "Global Settings"
|
||||
msgstr "全局设置"
|
||||
|
||||
msgid "Server Config"
|
||||
msgstr "服务器配置"
|
||||
|
||||
msgid "Users Manager"
|
||||
msgstr "用户管理"
|
||||
|
||||
msgid "Remarks"
|
||||
msgstr "备注"
|
||||
|
||||
msgid "Port"
|
||||
msgstr "端口"
|
||||
|
||||
msgid "Password"
|
||||
msgstr "密码"
|
||||
|
||||
msgid "Encrypt Method"
|
||||
msgstr "加密"
|
||||
|
||||
msgid "Protocol"
|
||||
msgstr "协议"
|
||||
|
||||
msgid "Protocol Param"
|
||||
msgstr "协议参数"
|
||||
|
||||
msgid "Obfs"
|
||||
msgstr "混淆"
|
||||
|
||||
msgid "Obfs Param"
|
||||
msgstr "混淆参数"
|
||||
|
||||
msgid "Connection Timeout"
|
||||
msgstr "连接超时时间"
|
||||
|
||||
msgid "redirect"
|
||||
msgstr "重定向"
|
||||
|
||||
msgid "Fast Open"
|
||||
msgstr "快速打开"
|
||||
|
||||
msgid "UDP Forward"
|
||||
msgstr "UDP转发"
|
||||
|
||||
msgid "Enabled"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Status"
|
||||
msgstr "状态"
|
||||
|
||||
msgid "Current Condition"
|
||||
msgstr "当前状态"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
@ -0,0 +1,16 @@
|
||||
|
||||
config global
|
||||
option enable '0'
|
||||
|
||||
config user
|
||||
option enable '1'
|
||||
option remarks '备注2'
|
||||
option port '10002'
|
||||
option password '123456'
|
||||
option method 'table'
|
||||
option protocol 'origin'
|
||||
option obfs 'plain'
|
||||
option timeout '300'
|
||||
option fast_open 'false'
|
||||
option udp_forward '1'
|
||||
|
||||
74
package/lienol/luci-app-ssr-libev-server/root/etc/init.d/ssr_libev_server
Executable file
74
package/lienol/luci-app-ssr-libev-server/root/etc/init.d/ssr_libev_server
Executable file
@ -0,0 +1,74 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2018-2019 Lienol <lawlienol@gmail.com>
|
||||
|
||||
START=99
|
||||
|
||||
CONFIG=ssr_libev_server
|
||||
CONFIG_PATH=/var/etc/$CONFIG
|
||||
|
||||
gen_ssr_libev_config_file() {
|
||||
config_get enable $1 enable
|
||||
[ "$enable" = "0" ] && return 0
|
||||
config_get remarks $1 remarks
|
||||
config_get port $1 port
|
||||
config_get password $1 password
|
||||
config_get method $1 method
|
||||
config_get protocol $1 protocol
|
||||
config_get protocol_param $1 protocol_param
|
||||
config_get obfs $1 obfs
|
||||
config_get obfs_param $1 obfs_param
|
||||
config_get timeout $1 timeout
|
||||
config_get fast_open $1 fast_open
|
||||
config_get udp_forward $1 udp_forward
|
||||
udp_param=""
|
||||
[ "$udp_forward" = "1" ] && udp_param="-u"
|
||||
|
||||
cat <<-EOF >$CONFIG_PATH/$1.json
|
||||
{
|
||||
"server": ["[::0]", "0.0.0.0"],
|
||||
"server_port": $port,
|
||||
"password": "$password",
|
||||
"timeout": $timeout,
|
||||
"method": "$method",
|
||||
"protocol": "$protocol",
|
||||
"protocol_param": "$protocol_param",
|
||||
"obfs": "$obfs",
|
||||
"obfs_param": "$obfs_param",
|
||||
"fast_open": $fast_open
|
||||
}
|
||||
EOF
|
||||
|
||||
/usr/bin/ssr-server -c $CONFIG_PATH/$1.json $udp_param >/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
start_ssr_libev_server() {
|
||||
config_foreach gen_ssr_libev_config_file "user"
|
||||
fw3 reload
|
||||
}
|
||||
|
||||
stop_ssr_libev_server() {
|
||||
fw3 reload
|
||||
ps -w | grep "$CONFIG_PATH/" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
start() {
|
||||
config_load $CONFIG
|
||||
enable=$(uci get $CONFIG.@global[0].enable)
|
||||
if [ "$enable" = "0" ];then
|
||||
stop_ssr_libev_server
|
||||
else
|
||||
mkdir -p $CONFIG_PATH
|
||||
start_ssr_libev_server
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
stop_ssr_libev_server
|
||||
rm -rf $CONFIG_PATH
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete firewall.ssr_libev_server
|
||||
set firewall.ssr_libev_server=include
|
||||
set firewall.ssr_libev_server.type=script
|
||||
set firewall.ssr_libev_server.path=/usr/share/ssr_libev_server/firewall.include
|
||||
set firewall.ssr_libev_server.reload=1
|
||||
EOF
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@ssr_libev_server[-1]
|
||||
add ucitrack ssr_libev_server
|
||||
set ucitrack.@ssr_libev_server[-1].init=ssr_libev_server
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
chmod a+x /usr/share/ssr_libev_server/* >/dev/null 2>&1
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
||||
@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
. $IPKG_INSTROOT/lib/functions.sh
|
||||
. $IPKG_INSTROOT/lib/functions/service.sh
|
||||
|
||||
gen_user_iptables() {
|
||||
config_get enable $1 enable
|
||||
[ "$enable" = "0" ] && return 0
|
||||
config_get remarks $1 remarks
|
||||
config_get port $1 port
|
||||
config_get udp_forward $1 udp_forward
|
||||
|
||||
iptables -A SSR_LIBEV-SERVER -p tcp --dport $port -m comment --comment "$remarks" -j ACCEPT
|
||||
[ "$udp_forward" = "1" ] && iptables -A SSR_LIBEV-SERVER -p udp --dport $port -m comment --comment "$remarks" -j ACCEPT
|
||||
}
|
||||
|
||||
iptables -F SSR_LIBEV-SERVER 2>/dev/null
|
||||
iptables -D INPUT -j SSR_LIBEV-SERVER 2>/dev/null
|
||||
iptables -X SSR_LIBEV-SERVER 2>/dev/null
|
||||
|
||||
enable=$(uci get ssr_libev_server.@global[0].enable)
|
||||
if [ $enable -eq 1 ]; then
|
||||
iptables -N SSR_LIBEV-SERVER
|
||||
iptables -I INPUT -j SSR_LIBEV-SERVER
|
||||
config_load ssr_libev_server
|
||||
config_foreach gen_user_iptables "user"
|
||||
fi
|
||||
Loading…
Reference in New Issue
Block a user