Skip to content

Commit

Permalink
use procd init script
Browse files Browse the repository at this point in the history
  • Loading branch information
aa65535 committed May 24, 2022
1 parent b05cc7c commit 6c27dae
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 161 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2016-2021 Jian Chang <[email protected]>
# Copyright (C) 2016-2022 Jian Chang <[email protected]>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
Expand All @@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-shadowsocks
PKG_VERSION:=2.0.4
PKG_VERSION:=2.1.0
PKG_RELEASE:=1

PKG_LICENSE:=GPLv3
Expand Down
14 changes: 4 additions & 10 deletions files/luci/controller/shadowsocks.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2014-2021 Jian Chang <[email protected]>
-- Copyright (C) 2014-2022 Jian Chang <[email protected]>
-- Licensed to the public under the GNU General Public License v3.

module("luci.controller.shadowsocks", package.seeall)
Expand Down Expand Up @@ -56,17 +56,11 @@ function index()
page.acl_depends = { "luci-app-shadowsocks" }
end

local function is_running(name)
return luci.sys.call("pidof %s >/dev/null" %{name}) == 0
end

function action_status()
local util = require "luci.util"
local list = util.ubus("service", "list", {name = "shadowsocks"})
luci.http.prepare_content("application/json")
luci.http.write_json({
ss_redir = (is_running("ss-redir") or is_running("ssr-redir")),
ss_local = (is_running("ss-local") or is_running("ssr-local")),
ss_tunnel = (is_running("ss-tunnel") or is_running("ssr-tunnel"))
})
luci.http.write_json(list)
end

function action_subscribe()
Expand Down
42 changes: 25 additions & 17 deletions files/luci/model/cbi/shadowsocks/general.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2014-2021 Jian Chang <[email protected]>
-- Copyright (C) 2014-2022 Jian Chang <[email protected]>
-- Licensed to the public under the GNU General Public License v3.

local m, s, o
Expand Down Expand Up @@ -28,17 +28,9 @@ if not has_ss_redir and not has_ssr_redir and not has_ss_local and not has_ssr_l
translate("General Settings")}, '<b style="color:red">shadowsocks-libev binary file not found.</b>')
end

local function is_running(name)
return luci.sys.call("pidof %s >/dev/null" %{name}) == 0
end

local function get_status(name)
return (is_running(name %{"ss"}) or is_running(name %{"ssr"})) and translate("RUNNING") or translate("NOT RUNNING")
end

uci:foreach(shadowsocks, "servers", function(s)
if s.server and s.server_port then
servers[#servers+1] = {name = s[".name"], alias = s.alias or "%s:%s" %{s.server, s.server_port}}
servers[#servers+1] = {type = s.type or "ss", name = s[".name"], alias = s.alias or "%s:%s" %{s.server, s.server_port}}
end
end)

Expand All @@ -51,19 +43,19 @@ s.anonymous = true

if has_ss_redir or has_ssr_redir then
o = s:option(DummyValue, "_redir_status", translate("Transparent Proxy"))
o.value = "<span id=\"_redir_status\">%s</span>" %{get_status("%s-redir")}
o.value = "<span id=\"_redir_status\">%s</span>" %{translate("Updating...")}
o.rawhtml = true
end

if has_ss_local or has_ssr_local then
o = s:option(DummyValue, "_local_status", translate("SOCKS5 Proxy"))
o.value = "<span id=\"_local_status\">%s</span>" %{get_status("%s-local")}
o.value = "<span id=\"_local_status\">%s</span>" %{translate("Updating...")}
o.rawhtml = true
end

if has_ss_tunnel or has_ssr_tunnel then
o = s:option(DummyValue, "_tunnel_status", translate("Port Forward"))
o.value = "<span id=\"_tunnel_status\">%s</span>" %{get_status("%s-tunnel")}
o.value = "<span id=\"_tunnel_status\">%s</span>" %{translate("Updating...")}
o.rawhtml = true
end

Expand All @@ -86,15 +78,23 @@ if has_ss_redir or has_ssr_redir then

o = s:option(ListValue, "main_server", translate("Main Server"))
o:value("nil", translate("Disable"))
for _, s in ipairs(servers) do o:value(s.name, s.alias) end
for _, s in ipairs(servers) do
if (has_ss_redir and s.type == "ss") or (has_ssr_redir and s.type == "ssr") then
o:value(s.name, s.alias)
end
end
o.default = "nil"
o.rmempty = false

o = s:option(ListValue, "udp_relay_server", translate("UDP-Relay Server"))
if has_udp_relay() then
o:value("nil", translate("Disable"))
o:value("same", translate("Same as Main Server"))
for _, s in ipairs(servers) do o:value(s.name, s.alias) end
for _, s in ipairs(servers) do
if (has_ss_redir and s.type == "ss") or (has_ssr_redir and s.type == "ssr") then
o:value(s.name, s.alias)
end
end
else
o:value("nil", translate("Unusable - Missing iptables-mod-tproxy or ip"))
end
Expand Down Expand Up @@ -131,7 +131,11 @@ if has_ss_local or has_ssr_local then

o = s:option(ListValue, "server", translate("Server"))
o:value("nil", translate("Disable"))
for _, s in ipairs(servers) do o:value(s.name, s.alias) end
for _, s in ipairs(servers) do
if (has_ss_local and s.type == "ss") or (has_ssr_local and s.type == "ssr") then
o:value(s.name, s.alias)
end
end
o.default = "nil"
o.rmempty = false

Expand Down Expand Up @@ -165,7 +169,11 @@ if has_ss_tunnel or has_ssr_tunnel then

o = s:option(ListValue, "server", translate("Server"))
o:value("nil", translate("Disable"))
for _, s in ipairs(servers) do o:value(s.name, s.alias) end
for _, s in ipairs(servers) do
if (has_ss_tunnel and s.type == "ss") or (has_ssr_tunnel and s.type == "ssr") then
o:value(s.name, s.alias)
end
end
o.default = "nil"
o.rmempty = false

Expand Down
5 changes: 3 additions & 2 deletions files/luci/model/cbi/shadowsocks/servers-details.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ local function has_ssr_bins()
end

local function support_fast_open()
local bit = luci.sys.exec("cat /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null"):trim()
return bit == "1" or bit == "3"
local nixio = require "nixio"
local bit = tonumber(luci.sys.exec("cat /proc/sys/net/ipv4/tcp_fastopen 2>/dev/null"):trim()) or 0
return nixio.bit.band(bit, 1) == 1
end

m = Map(shadowsocks, "%s - %s" %{translate("ShadowSocks"), translate("Edit Server")})
Expand Down
24 changes: 16 additions & 8 deletions files/luci/view/shadowsocks/general.htm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%#
Copyright (C) 2017-2021 Jian Chang <aa65535@live.com>
Copyright (C) 2017-2022 Jian Chang <aa65535@live.com>
Licensed to the public under the GNU General Public License v3.
-%>

Expand All @@ -8,15 +8,23 @@
<script type="text/javascript">//<![CDATA[
(function() {
var elements = {
ss_redir: document.getElementById("_redir_status"),
ss_local: document.getElementById("_local_status"),
ss_tunnel: document.getElementById("_tunnel_status"),
redir: document.getElementById("_redir_status"),
local: document.getElementById("_local_status"),
tunnel: document.getElementById("_tunnel_status"),
};
XHR.poll(5, "<%=luci.dispatcher.build_url("admin", "services", "shadowsocks", "status")%>", null, function(xhr, status) {
if (xhr.status === 200) {
var instances, keys;
XHR.poll(5, "<%=luci.dispatcher.build_url("admin", "services", "shadowsocks", "status")%>", null, function(xhr, data) {
if (xhr.status === 200 && data.shadowsocks && data.shadowsocks.instances) {
keys = {};
instances = data.shadowsocks.instances;
for (var n in instances) {
if (instances.hasOwnProperty(n) && instances[n].running) {
keys[n.split('-')[1]] = true;
}
}
for (var k in elements) {
if (elements[k]) {
elements[k].textContent = status[k] ? "<%:RUNNING%>" : "<%:NOT RUNNING%>";
if (elements.hasOwnProperty(k) && elements[k]) {
elements[k].textContent = keys[k] ? "<%:RUNNING%>" : "<%:NOT RUNNING%>";
}
}
}
Expand Down
Loading

0 comments on commit 6c27dae

Please sign in to comment.