luci: optimization code
This commit is contained in:
parent
4f61d13de8
commit
14e6f515a3
@ -2,20 +2,20 @@
|
|||||||
-- Copyright (C) 2021-2022 xiaorouji
|
-- Copyright (C) 2021-2022 xiaorouji
|
||||||
|
|
||||||
module("luci.controller.passwall", package.seeall)
|
module("luci.controller.passwall", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local ucic = luci.model.uci.cursor()
|
local ucic = luci.model.uci.cursor()
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local i18n = require "luci.i18n"
|
local i18n = require "luci.i18n"
|
||||||
local brook = require("luci.model.cbi." .. appname ..".api.brook")
|
local brook = require("luci.passwall.brook")
|
||||||
local v2ray = require("luci.model.cbi." .. appname ..".api.v2ray")
|
local v2ray = require("luci.passwall.v2ray")
|
||||||
local xray = require("luci.model.cbi." .. appname ..".api.xray")
|
local xray = require("luci.passwall.xray")
|
||||||
local trojan_go = require("luci.model.cbi." .. appname ..".api.trojan_go")
|
local trojan_go = require("luci.passwall.trojan_go")
|
||||||
local hysteria = require("luci.model.cbi." .. appname ..".api.hysteria")
|
local hysteria = require("luci.passwall.hysteria")
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
appname = require "luci.model.cbi.passwall.api.api".appname
|
appname = require "luci.passwall.api".appname
|
||||||
entry({"admin", "services", appname}).dependent = true
|
entry({"admin", "services", appname}).dependent = true
|
||||||
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true
|
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true
|
||||||
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
|
entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local has_chnlist = api.fs.access("/usr/share/passwall/rules/chnlist")
|
local has_chnlist = api.fs.access("/usr/share/passwall/rules/chnlist")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local has_v2ray = api.is_finded("v2ray")
|
local has_v2ray = api.is_finded("v2ray")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
|
|
||||||
m = Map(appname)
|
m = Map(appname)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
|
|
||||||
local nodes_table = {}
|
local nodes_table = {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local datatypes = api.datatypes
|
local datatypes = api.datatypes
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local net = require "luci.model.network".init()
|
local net = require "luci.model.network".init()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
|
|
||||||
f = SimpleForm(appname)
|
f = SimpleForm(appname)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local datatypes = api.datatypes
|
local datatypes = api.datatypes
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local has_ss = api.is_finded("ss-redir")
|
local has_ss = api.is_finded("ss-redir")
|
||||||
local has_ss_rust = api.is_finded("sslocal")
|
local has_ss_rust = api.is_finded("sslocal")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local has_ss = api.is_finded("ss-redir")
|
local has_ss = api.is_finded("ss-redir")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local has_v2ray = api.is_finded("v2ray")
|
local has_v2ray = api.is_finded("v2ray")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local has_v2ray = api.is_finded("v2ray")
|
local has_v2ray = api.is_finded("v2ray")
|
||||||
local has_xray = api.is_finded("xray")
|
local has_xray = api.is_finded("xray")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = api.appname
|
local appname = api.appname
|
||||||
local datatypes = api.datatypes
|
local datatypes = api.datatypes
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
module("luci.model.cbi.passwall.server.api.hysteria", package.seeall)
|
|
||||||
function gen_config(user)
|
|
||||||
local config = {
|
|
||||||
listen = ":" .. user.port,
|
|
||||||
protocol = user.protocol or "udp",
|
|
||||||
obfs = user.hysteria_obfs,
|
|
||||||
cert = user.tls_certificateFile,
|
|
||||||
key = user.tls_keyFile,
|
|
||||||
auth = (user.hysteria_auth_type == "string") and {
|
|
||||||
mode = "password",
|
|
||||||
config = {
|
|
||||||
password = user.hysteria_auth_password
|
|
||||||
}
|
|
||||||
} or nil,
|
|
||||||
disable_udp = (user.hysteria_udp == "0") and true or false,
|
|
||||||
alpn = user.hysteria_alpn or nil,
|
|
||||||
up_mbps = tonumber(user.hysteria_up_mbps) or 10,
|
|
||||||
down_mbps = tonumber(user.hysteria_down_mbps) or 50,
|
|
||||||
recv_window_conn = (user.hysteria_recv_window_conn) and tonumber(user.hysteria_recv_window_conn) or nil,
|
|
||||||
recv_window = (user.hysteria_recv_window) and tonumber(user.hysteria_recv_window) or nil,
|
|
||||||
disable_mtu_discovery = (user.hysteria_disable_mtu_discovery) and true or false
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
end
|
|
@ -1,25 +0,0 @@
|
|||||||
module("luci.model.cbi.passwall.server.api.shadowsocks", package.seeall)
|
|
||||||
function gen_config(user)
|
|
||||||
local config = {}
|
|
||||||
config.server_port = tonumber(user.port)
|
|
||||||
config.password = user.password
|
|
||||||
config.timeout = tonumber(user.timeout)
|
|
||||||
config.fast_open = (user.tcp_fast_open and user.tcp_fast_open == "1") and true or false
|
|
||||||
config.method = user.method
|
|
||||||
|
|
||||||
if user.type == "SS-Rust" then
|
|
||||||
config.server = "::"
|
|
||||||
config.mode = "tcp_and_udp"
|
|
||||||
else
|
|
||||||
config.server = {"[::0]", "0.0.0.0"}
|
|
||||||
end
|
|
||||||
|
|
||||||
if user.type == "SSR" then
|
|
||||||
config.protocol = user.protocol
|
|
||||||
config.protocol_param = user.protocol_param
|
|
||||||
config.obfs = user.obfs
|
|
||||||
config.obfs_param = user.obfs_param
|
|
||||||
end
|
|
||||||
|
|
||||||
return config
|
|
||||||
end
|
|
@ -1,61 +0,0 @@
|
|||||||
module("luci.model.cbi.passwall.server.api.trojan", package.seeall)
|
|
||||||
function gen_config(user)
|
|
||||||
local cipher = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
|
|
||||||
local cipher13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
|
|
||||||
local config = {
|
|
||||||
run_type = "server",
|
|
||||||
local_addr = "::",
|
|
||||||
local_port = tonumber(user.port),
|
|
||||||
remote_addr = (user.remote_enable == "1" and user.remote_address) and user.remote_address or nil,
|
|
||||||
remote_port = (user.remote_enable == "1" and user.remote_port) and tonumber(user.remote_port) or nil,
|
|
||||||
password = user.uuid,
|
|
||||||
log_level = (user.log and user.log == "1") and tonumber(user.loglevel) or 5,
|
|
||||||
ssl = {
|
|
||||||
cert = user.tls_certificateFile,
|
|
||||||
key = user.tls_keyFile,
|
|
||||||
key_password = "",
|
|
||||||
cipher = cipher,
|
|
||||||
cipher_tls13 = cipher13,
|
|
||||||
prefer_server_cipher = true,
|
|
||||||
reuse_session = true,
|
|
||||||
session_ticket = (user.tls_sessionTicket == "1") and true or false,
|
|
||||||
session_timeout = 600,
|
|
||||||
plain_http_response = "",
|
|
||||||
curves = "",
|
|
||||||
dhparam = ""
|
|
||||||
},
|
|
||||||
tcp = {
|
|
||||||
prefer_ipv4 = false,
|
|
||||||
no_delay = true,
|
|
||||||
keep_alive = true,
|
|
||||||
reuse_port = false,
|
|
||||||
fast_open = (user.tcp_fast_open and user.tcp_fast_open == "1") and true or false,
|
|
||||||
fast_open_qlen = 20
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if user.type == "Trojan-Go" then
|
|
||||||
config.ssl.cipher = nil
|
|
||||||
config.ssl.cipher_tls13 = nil
|
|
||||||
config.udp_timeout = 60
|
|
||||||
config.disable_http_check = true
|
|
||||||
config.transport_plugin = ((user.tls == nil or user.tls ~= "1") and user.trojan_transport == "original") and {
|
|
||||||
enabled = user.plugin_type ~= nil,
|
|
||||||
type = user.plugin_type or "plaintext",
|
|
||||||
command = user.plugin_type ~= "plaintext" and user.plugin_cmd or nil,
|
|
||||||
option = user.plugin_type ~= "plaintext" and user.plugin_option or nil,
|
|
||||||
arg = user.plugin_type ~= "plaintext" and { user.plugin_arg } or nil,
|
|
||||||
env = {}
|
|
||||||
} or nil
|
|
||||||
config.websocket = (user.trojan_transport == 'ws') and {
|
|
||||||
enabled = true,
|
|
||||||
path = user.ws_path or "/",
|
|
||||||
host = user.ws_host or ""
|
|
||||||
} or nil
|
|
||||||
config.shadowsocks = (user.ss_aead == "1") and {
|
|
||||||
enabled = true,
|
|
||||||
method = user.ss_aead_method or "aes_128_gcm",
|
|
||||||
password = user.ss_aead_pwd or ""
|
|
||||||
} or nil
|
|
||||||
end
|
|
||||||
return config
|
|
||||||
end
|
|
@ -1,242 +0,0 @@
|
|||||||
module("luci.model.cbi.passwall.server.api.xray", package.seeall)
|
|
||||||
local uci = require"luci.model.uci".cursor()
|
|
||||||
|
|
||||||
function gen_config(user)
|
|
||||||
local settings = nil
|
|
||||||
local routing = nil
|
|
||||||
local outbounds = {
|
|
||||||
{protocol = "freedom", tag = "direct"}, {protocol = "blackhole", tag = "blocked"}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.protocol == "vmess" or user.protocol == "vless" then
|
|
||||||
if user.uuid then
|
|
||||||
local clients = {}
|
|
||||||
for i = 1, #user.uuid do
|
|
||||||
clients[i] = {
|
|
||||||
id = user.uuid[i],
|
|
||||||
flow = ("vless" == user.protocol and "1" == user.tls and user.tlsflow) and user.tlsflow or nil
|
|
||||||
}
|
|
||||||
end
|
|
||||||
settings = {
|
|
||||||
clients = clients,
|
|
||||||
decryption = user.decryption or "none"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
elseif user.protocol == "socks" then
|
|
||||||
settings = {
|
|
||||||
udp = ("1" == user.udp_forward) and true or false,
|
|
||||||
auth = ("1" == user.auth) and "password" or "noauth",
|
|
||||||
accounts = ("1" == user.auth) and {
|
|
||||||
{
|
|
||||||
user = user.username,
|
|
||||||
pass = user.password
|
|
||||||
}
|
|
||||||
} or nil
|
|
||||||
}
|
|
||||||
elseif user.protocol == "http" then
|
|
||||||
settings = {
|
|
||||||
allowTransparent = false,
|
|
||||||
accounts = ("1" == user.auth) and {
|
|
||||||
{
|
|
||||||
user = user.username,
|
|
||||||
pass = user.password
|
|
||||||
}
|
|
||||||
} or nil
|
|
||||||
}
|
|
||||||
user.transport = "tcp"
|
|
||||||
user.tcp_guise = "none"
|
|
||||||
elseif user.protocol == "shadowsocks" then
|
|
||||||
settings = {
|
|
||||||
method = user.method,
|
|
||||||
password = user.password,
|
|
||||||
ivCheck = ("1" == user.iv_check) and true or false,
|
|
||||||
network = user.ss_network or "TCP,UDP"
|
|
||||||
}
|
|
||||||
elseif user.protocol == "trojan" then
|
|
||||||
if user.uuid then
|
|
||||||
local clients = {}
|
|
||||||
for i = 1, #user.uuid do
|
|
||||||
clients[i] = {
|
|
||||||
password = user.uuid[i],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
settings = {
|
|
||||||
clients = clients
|
|
||||||
}
|
|
||||||
end
|
|
||||||
elseif user.protocol == "mtproto" then
|
|
||||||
settings = {
|
|
||||||
users = {
|
|
||||||
{
|
|
||||||
secret = (user.password == nil) and "" or user.password
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif user.protocol == "dokodemo-door" then
|
|
||||||
settings = {
|
|
||||||
network = user.d_protocol,
|
|
||||||
address = user.d_address,
|
|
||||||
port = tonumber(user.d_port)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if user.fallback and user.fallback == "1" then
|
|
||||||
local fallbacks = {}
|
|
||||||
for i = 1, #user.fallback_list do
|
|
||||||
local fallbackStr = user.fallback_list[i]
|
|
||||||
if fallbackStr then
|
|
||||||
local tmp = {}
|
|
||||||
string.gsub(fallbackStr, '[^' .. "," .. ']+', function(w)
|
|
||||||
table.insert(tmp, w)
|
|
||||||
end)
|
|
||||||
local dest = tmp[1] or ""
|
|
||||||
local path = tmp[2]
|
|
||||||
if dest:find("%.") then
|
|
||||||
else
|
|
||||||
dest = tonumber(dest)
|
|
||||||
end
|
|
||||||
fallbacks[i] = {
|
|
||||||
path = path,
|
|
||||||
dest = dest,
|
|
||||||
xver = 1
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
settings.fallbacks = fallbacks
|
|
||||||
end
|
|
||||||
|
|
||||||
routing = {
|
|
||||||
domainStrategy = "IPOnDemand",
|
|
||||||
rules = {
|
|
||||||
{
|
|
||||||
type = "field",
|
|
||||||
ip = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"},
|
|
||||||
outboundTag = (user.accept_lan == nil or user.accept_lan == "0") and "blocked" or "direct"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.outbound_node and user.outbound_node ~= "nil" then
|
|
||||||
local outbound = nil
|
|
||||||
if user.outbound_node == "_iface" and user.outbound_node_iface then
|
|
||||||
outbound = {
|
|
||||||
protocol = "freedom",
|
|
||||||
tag = "outbound",
|
|
||||||
streamSettings = {
|
|
||||||
sockopt = {
|
|
||||||
interface = user.outbound_node_iface
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
local outbound_node_t = uci:get_all("passwall", user.outbound_node)
|
|
||||||
if user.outbound_node == "_socks" or user.outbound_node == "_http" then
|
|
||||||
outbound_node_t = {
|
|
||||||
type = user.type,
|
|
||||||
protocol = user.outbound_node:gsub("_", ""),
|
|
||||||
transport = "tcp",
|
|
||||||
address = user.outbound_node_address,
|
|
||||||
port = user.outbound_node_port,
|
|
||||||
username = (user.outbound_node_username and user.outbound_node_username ~= "") and user.outbound_node_username or nil,
|
|
||||||
password = (user.outbound_node_password and user.outbound_node_password ~= "") and user.outbound_node_password or nil,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
outbound = require("luci.model.cbi.passwall.api.util_xray").gen_outbound(nil, outbound_node_t, "outbound")
|
|
||||||
end
|
|
||||||
if outbound then
|
|
||||||
table.insert(outbounds, 1, outbound)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local config = {
|
|
||||||
log = {
|
|
||||||
-- error = "/tmp/etc/passwall_server/log/" .. user[".name"] .. ".log",
|
|
||||||
loglevel = ("1" == user.log) and user.loglevel or "none"
|
|
||||||
},
|
|
||||||
-- 传入连接
|
|
||||||
inbounds = {
|
|
||||||
{
|
|
||||||
listen = (user.bind_local == "1") and "127.0.0.1" or nil,
|
|
||||||
port = tonumber(user.port),
|
|
||||||
protocol = user.protocol,
|
|
||||||
settings = settings,
|
|
||||||
streamSettings = {
|
|
||||||
network = user.transport,
|
|
||||||
security = "none",
|
|
||||||
tlsSettings = ("1" == user.tls) and {
|
|
||||||
disableSystemRoot = false,
|
|
||||||
certificates = {
|
|
||||||
{
|
|
||||||
certificateFile = user.tls_certificateFile,
|
|
||||||
keyFile = user.tls_keyFile
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} or nil,
|
|
||||||
tcpSettings = (user.transport == "tcp") and {
|
|
||||||
acceptProxyProtocol = (user.acceptProxyProtocol and user.acceptProxyProtocol == "1") and true or false,
|
|
||||||
header = {
|
|
||||||
type = user.tcp_guise,
|
|
||||||
request = (user.tcp_guise == "http") and {
|
|
||||||
path = user.tcp_guise_http_path or {"/"},
|
|
||||||
headers = {
|
|
||||||
Host = user.tcp_guise_http_host or {}
|
|
||||||
}
|
|
||||||
} or nil
|
|
||||||
}
|
|
||||||
} or nil,
|
|
||||||
kcpSettings = (user.transport == "mkcp") and {
|
|
||||||
mtu = tonumber(user.mkcp_mtu),
|
|
||||||
tti = tonumber(user.mkcp_tti),
|
|
||||||
uplinkCapacity = tonumber(user.mkcp_uplinkCapacity),
|
|
||||||
downlinkCapacity = tonumber(user.mkcp_downlinkCapacity),
|
|
||||||
congestion = (user.mkcp_congestion == "1") and true or false,
|
|
||||||
readBufferSize = tonumber(user.mkcp_readBufferSize),
|
|
||||||
writeBufferSize = tonumber(user.mkcp_writeBufferSize),
|
|
||||||
seed = (user.mkcp_seed and user.mkcp_seed ~= "") and user.mkcp_seed or nil,
|
|
||||||
header = {type = user.mkcp_guise}
|
|
||||||
} or nil,
|
|
||||||
wsSettings = (user.transport == "ws") and {
|
|
||||||
acceptProxyProtocol = (user.acceptProxyProtocol and user.acceptProxyProtocol == "1") and true or false,
|
|
||||||
headers = (user.ws_host) and {Host = user.ws_host} or nil,
|
|
||||||
path = user.ws_path
|
|
||||||
} or nil,
|
|
||||||
httpSettings = (user.transport == "h2") and {
|
|
||||||
path = user.h2_path, host = user.h2_host
|
|
||||||
} or nil,
|
|
||||||
dsSettings = (user.transport == "ds") and {
|
|
||||||
path = user.ds_path
|
|
||||||
} or nil,
|
|
||||||
quicSettings = (user.transport == "quic") and {
|
|
||||||
security = user.quic_security,
|
|
||||||
key = user.quic_key,
|
|
||||||
header = {type = user.quic_guise}
|
|
||||||
} or nil,
|
|
||||||
grpcSettings = (user.transport == "grpc") and {
|
|
||||||
serviceName = user.grpc_serviceName
|
|
||||||
} or nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
-- 传出连接
|
|
||||||
outbounds = outbounds,
|
|
||||||
routing = routing
|
|
||||||
}
|
|
||||||
|
|
||||||
local alpn = {}
|
|
||||||
if user.alpn then
|
|
||||||
string.gsub(user.alpn, '[^' .. "," .. ']+', function(w)
|
|
||||||
table.insert(alpn, w)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
if alpn and #alpn > 0 then
|
|
||||||
if config.inbounds[1].streamSettings.tlsSettings then
|
|
||||||
config.inbounds[1].streamSettings.tlsSettings.alpn = alpn
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if "1" == user.tls then
|
|
||||||
config.inbounds[1].streamSettings.security = "tls"
|
|
||||||
end
|
|
||||||
|
|
||||||
return config
|
|
||||||
end
|
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
|
|
||||||
m = Map("passwall_server", translate("Server-Side"))
|
m = Map("passwall_server", translate("Server-Side"))
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
|
|
||||||
local ss_encrypt_method_list = {
|
local ss_encrypt_method_list = {
|
||||||
"rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr",
|
"rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr",
|
||||||
|
2
luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua → luci-app-passwall/luasrc/passwall/api.lua
Executable file → Normal file
2
luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua → luci-app-passwall/luasrc/passwall/api.lua
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
module("luci.model.cbi.passwall.api.api", package.seeall)
|
module("luci.passwall.api", package.seeall)
|
||||||
fs = require "nixio.fs"
|
fs = require "nixio.fs"
|
||||||
sys = require "luci.sys"
|
sys = require "luci.sys"
|
||||||
uci = require"luci.model.uci".cursor()
|
uci = require"luci.model.uci".cursor()
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.brook", package.seeall)
|
module("luci.passwall.brook", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local util = api.util
|
local util = api.util
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.hysteria", package.seeall)
|
module("luci.passwall.hysteria", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local util = api.util
|
local util = api.util
|
20
luci-app-passwall/luasrc/model/cbi/passwall/server/api/app.lua → luci-app-passwall/luasrc/passwall/server_app.lua
Executable file → Normal file
20
luci-app-passwall/luasrc/model/cbi/passwall/server/api/app.lua → luci-app-passwall/luasrc/passwall/server_app.lua
Executable file → Normal file
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
local action = arg[1]
|
local action = arg[1]
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local jsonc = api.jsonc
|
local jsonc = api.jsonc
|
||||||
@ -10,7 +10,7 @@ local CONFIG = "passwall_server"
|
|||||||
local CONFIG_PATH = "/tmp/etc/" .. CONFIG
|
local CONFIG_PATH = "/tmp/etc/" .. CONFIG
|
||||||
local LOG_APP_FILE = "/tmp/log/" .. CONFIG .. ".log"
|
local LOG_APP_FILE = "/tmp/log/" .. CONFIG .. ".log"
|
||||||
local TMP_BIN_PATH = CONFIG_PATH .. "/bin"
|
local TMP_BIN_PATH = CONFIG_PATH .. "/bin"
|
||||||
local require_dir = "luci.model.cbi.passwall.server.api."
|
local require_dir = "luci.passwall."
|
||||||
|
|
||||||
local ipt_bin = sys.exec("echo -n $(/usr/share/passwall/iptables.sh get_ipt_bin)")
|
local ipt_bin = sys.exec("echo -n $(/usr/share/passwall/iptables.sh get_ipt_bin)")
|
||||||
local ip6t_bin = sys.exec("echo -n $(/usr/share/passwall/iptables.sh get_ip6t_bin)")
|
local ip6t_bin = sys.exec("echo -n $(/usr/share/passwall/iptables.sh get_ip6t_bin)")
|
||||||
@ -131,7 +131,7 @@ local function start()
|
|||||||
end
|
end
|
||||||
bin = ln_run("/usr/bin/microsocks", "microsocks_" .. id, string.format("-i :: -p %s %s", port, auth), log_path)
|
bin = ln_run("/usr/bin/microsocks", "microsocks_" .. id, string.format("-i :: -p %s %s", port, auth), log_path)
|
||||||
elseif type == "SS" or type == "SSR" then
|
elseif type == "SS" or type == "SSR" then
|
||||||
config = require(require_dir .. "shadowsocks").gen_config(user)
|
config = require(require_dir .. "util_shadowsocks").gen_config_server(user)
|
||||||
local udp_param = ""
|
local udp_param = ""
|
||||||
udp_forward = tonumber(user.udp_forward) or 1
|
udp_forward = tonumber(user.udp_forward) or 1
|
||||||
if udp_forward == 1 then
|
if udp_forward == 1 then
|
||||||
@ -140,22 +140,22 @@ local function start()
|
|||||||
type = type:lower()
|
type = type:lower()
|
||||||
bin = ln_run("/usr/bin/" .. type .. "-server", type .. "-server", "-c " .. config_file .. " " .. udp_param, log_path)
|
bin = ln_run("/usr/bin/" .. type .. "-server", type .. "-server", "-c " .. config_file .. " " .. udp_param, log_path)
|
||||||
elseif type == "SS-Rust" then
|
elseif type == "SS-Rust" then
|
||||||
config = require(require_dir .. "shadowsocks").gen_config(user)
|
config = require(require_dir .. "util_shadowsocks").gen_config_server(user)
|
||||||
bin = ln_run("/usr/bin/ssserver", "ssserver", "-c " .. config_file, log_path)
|
bin = ln_run("/usr/bin/ssserver", "ssserver", "-c " .. config_file, log_path)
|
||||||
elseif type == "V2ray" then
|
elseif type == "V2ray" then
|
||||||
config = require(require_dir .. "xray").gen_config(user)
|
config = require(require_dir .. "util_xray").gen_config_server(user)
|
||||||
bin = ln_run(api.get_v2ray_path(), "v2ray", "run -c " .. config_file, log_path)
|
bin = ln_run(api.get_v2ray_path(), "v2ray", "run -c " .. config_file, log_path)
|
||||||
elseif type == "Xray" then
|
elseif type == "Xray" then
|
||||||
config = require(require_dir .. "xray").gen_config(user)
|
config = require(require_dir .. "util_xray").gen_config_server(user)
|
||||||
bin = ln_run(api.get_xray_path(), "xray", "run -c " .. config_file, log_path)
|
bin = ln_run(api.get_xray_path(), "xray", "run -c " .. config_file, log_path)
|
||||||
elseif type == "Trojan" then
|
elseif type == "Trojan" then
|
||||||
config = require(require_dir .. "trojan").gen_config(user)
|
config = require(require_dir .. "util_trojan").gen_config_server(user)
|
||||||
bin = ln_run("/usr/sbin/trojan", "trojan", "-c " .. config_file, log_path)
|
bin = ln_run("/usr/sbin/trojan", "trojan", "-c " .. config_file, log_path)
|
||||||
elseif type == "Trojan-Plus" then
|
elseif type == "Trojan-Plus" then
|
||||||
config = require(require_dir .. "trojan").gen_config(user)
|
config = require(require_dir .. "util_trojan").gen_config_server(user)
|
||||||
bin = ln_run("/usr/sbin/trojan-plus", "trojan-plus", "-c " .. config_file, log_path)
|
bin = ln_run("/usr/sbin/trojan-plus", "trojan-plus", "-c " .. config_file, log_path)
|
||||||
elseif type == "Trojan-Go" then
|
elseif type == "Trojan-Go" then
|
||||||
config = require(require_dir .. "trojan").gen_config(user)
|
config = require(require_dir .. "util_trojan").gen_config_server(user)
|
||||||
bin = ln_run(api.get_trojan_go_path(), "trojan-go", "-config " .. config_file, log_path)
|
bin = ln_run(api.get_trojan_go_path(), "trojan-go", "-config " .. config_file, log_path)
|
||||||
elseif type == "Brook" then
|
elseif type == "Brook" then
|
||||||
local brook_protocol = user.protocol
|
local brook_protocol = user.protocol
|
||||||
@ -167,7 +167,7 @@ local function start()
|
|||||||
end
|
end
|
||||||
bin = ln_run(api.get_brook_path(), "brook_" .. id, string.format("--debug %s -l :%s -p %s%s", brook_protocol, port, brook_password, brook_path_arg), log_path)
|
bin = ln_run(api.get_brook_path(), "brook_" .. id, string.format("--debug %s -l :%s -p %s%s", brook_protocol, port, brook_password, brook_path_arg), log_path)
|
||||||
elseif type == "Hysteria" then
|
elseif type == "Hysteria" then
|
||||||
config = require(require_dir .. "hysteria").gen_config(user)
|
config = require(require_dir .. "util_hysteria").gen_config_server(user)
|
||||||
bin = ln_run(api.get_hysteria_path(), "hysteria", "-c " .. config_file .. " server", log_path)
|
bin = ln_run(api.get_hysteria_path(), "hysteria", "-c " .. config_file .. " server", log_path)
|
||||||
end
|
end
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.trojan_go", package.seeall)
|
module("luci.passwall.trojan_go", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local util = api.util
|
local util = api.util
|
@ -1,8 +1,33 @@
|
|||||||
module("luci.model.cbi.passwall.api.util_hysteria", package.seeall)
|
module("luci.passwall.util_hysteria", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local jsonc = api.jsonc
|
local jsonc = api.jsonc
|
||||||
|
|
||||||
|
function gen_config_server(node)
|
||||||
|
local config = {
|
||||||
|
listen = ":" .. node.port,
|
||||||
|
protocol = node.protocol or "udp",
|
||||||
|
obfs = node.hysteria_obfs,
|
||||||
|
cert = node.tls_certificateFile,
|
||||||
|
key = node.tls_keyFile,
|
||||||
|
auth = (node.hysteria_auth_type == "string") and {
|
||||||
|
mode = "password",
|
||||||
|
config = {
|
||||||
|
password = node.hysteria_auth_password
|
||||||
|
}
|
||||||
|
} or nil,
|
||||||
|
disable_udp = (node.hysteria_udp == "0") and true or false,
|
||||||
|
alpn = node.hysteria_alpn or nil,
|
||||||
|
up_mbps = tonumber(node.hysteria_up_mbps) or 10,
|
||||||
|
down_mbps = tonumber(node.hysteria_down_mbps) or 50,
|
||||||
|
recv_window_conn = (node.hysteria_recv_window_conn) and tonumber(node.hysteria_recv_window_conn) or nil,
|
||||||
|
recv_window = (node.hysteria_recv_window) and tonumber(node.hysteria_recv_window) or nil,
|
||||||
|
disable_mtu_discovery = (node.hysteria_disable_mtu_discovery) and true or false
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function gen_config(var)
|
function gen_config(var)
|
||||||
local node_id = var["-node"]
|
local node_id = var["-node"]
|
||||||
if not node_id then
|
if not node_id then
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.util_naiveproxy", package.seeall)
|
module("luci.passwall.util_naiveproxy", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local jsonc = api.jsonc
|
local jsonc = api.jsonc
|
||||||
|
|
@ -1,8 +1,33 @@
|
|||||||
module("luci.model.cbi.passwall.api.util_shadowsocks", package.seeall)
|
module("luci.passwall.util_shadowsocks", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local jsonc = api.jsonc
|
local jsonc = api.jsonc
|
||||||
|
|
||||||
|
function gen_config_server(node)
|
||||||
|
local config = {}
|
||||||
|
config.server_port = tonumber(node.port)
|
||||||
|
config.password = node.password
|
||||||
|
config.timeout = tonumber(node.timeout)
|
||||||
|
config.fast_open = (node.tcp_fast_open and node.tcp_fast_open == "1") and true or false
|
||||||
|
config.method = node.method
|
||||||
|
|
||||||
|
if node.type == "SS-Rust" then
|
||||||
|
config.server = "::"
|
||||||
|
config.mode = "tcp_and_udp"
|
||||||
|
else
|
||||||
|
config.server = {"[::0]", "0.0.0.0"}
|
||||||
|
end
|
||||||
|
|
||||||
|
if node.type == "SSR" then
|
||||||
|
config.protocol = node.protocol
|
||||||
|
config.protocol_param = node.protocol_param
|
||||||
|
config.obfs = node.obfs
|
||||||
|
config.obfs_param = node.obfs_param
|
||||||
|
end
|
||||||
|
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
function gen_config(var)
|
function gen_config(var)
|
||||||
local node_id = var["-node"]
|
local node_id = var["-node"]
|
||||||
if not node_id then
|
if not node_id then
|
@ -1,8 +1,69 @@
|
|||||||
module("luci.model.cbi.passwall.api.util_trojan", package.seeall)
|
module("luci.passwall.util_trojan", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local json = api.jsonc
|
local json = api.jsonc
|
||||||
|
|
||||||
|
function gen_config_server(node)
|
||||||
|
local cipher = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
|
||||||
|
local cipher13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
|
||||||
|
local config = {
|
||||||
|
run_type = "server",
|
||||||
|
local_addr = "::",
|
||||||
|
local_port = tonumber(node.port),
|
||||||
|
remote_addr = (node.remote_enable == "1" and node.remote_address) and node.remote_address or nil,
|
||||||
|
remote_port = (node.remote_enable == "1" and node.remote_port) and tonumber(node.remote_port) or nil,
|
||||||
|
password = node.uuid,
|
||||||
|
log_level = (node.log and node.log == "1") and tonumber(node.loglevel) or 5,
|
||||||
|
ssl = {
|
||||||
|
cert = node.tls_certificateFile,
|
||||||
|
key = node.tls_keyFile,
|
||||||
|
key_password = "",
|
||||||
|
cipher = cipher,
|
||||||
|
cipher_tls13 = cipher13,
|
||||||
|
prefer_server_cipher = true,
|
||||||
|
reuse_session = true,
|
||||||
|
session_ticket = (node.tls_sessionTicket == "1") and true or false,
|
||||||
|
session_timeout = 600,
|
||||||
|
plain_http_response = "",
|
||||||
|
curves = "",
|
||||||
|
dhparam = ""
|
||||||
|
},
|
||||||
|
tcp = {
|
||||||
|
prefer_ipv4 = false,
|
||||||
|
no_delay = true,
|
||||||
|
keep_alive = true,
|
||||||
|
reuse_port = false,
|
||||||
|
fast_open = (node.tcp_fast_open and node.tcp_fast_open == "1") and true or false,
|
||||||
|
fast_open_qlen = 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.type == "Trojan-Go" then
|
||||||
|
config.ssl.cipher = nil
|
||||||
|
config.ssl.cipher_tls13 = nil
|
||||||
|
config.udp_timeout = 60
|
||||||
|
config.disable_http_check = true
|
||||||
|
config.transport_plugin = ((node.tls == nil or node.tls ~= "1") and node.trojan_transport == "original") and {
|
||||||
|
enabled = node.plugin_type ~= nil,
|
||||||
|
type = node.plugin_type or "plaintext",
|
||||||
|
command = node.plugin_type ~= "plaintext" and node.plugin_cmd or nil,
|
||||||
|
option = node.plugin_type ~= "plaintext" and node.plugin_option or nil,
|
||||||
|
arg = node.plugin_type ~= "plaintext" and { node.plugin_arg } or nil,
|
||||||
|
env = {}
|
||||||
|
} or nil
|
||||||
|
config.websocket = (node.trojan_transport == 'ws') and {
|
||||||
|
enabled = true,
|
||||||
|
path = node.ws_path or "/",
|
||||||
|
host = node.ws_host or ""
|
||||||
|
} or nil
|
||||||
|
config.shadowsocks = (node.ss_aead == "1") and {
|
||||||
|
enabled = true,
|
||||||
|
method = node.ss_aead_method or "aes_128_gcm",
|
||||||
|
password = node.ss_aead_pwd or ""
|
||||||
|
} or nil
|
||||||
|
end
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
function gen_config(var)
|
function gen_config(var)
|
||||||
local node_id = var["-node"]
|
local node_id = var["-node"]
|
||||||
if not node_id then
|
if not node_id then
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.util_xray", package.seeall)
|
module("luci.passwall.util_xray", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local uci = api.uci
|
local uci = api.uci
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local jsonc = api.jsonc
|
local jsonc = api.jsonc
|
||||||
@ -237,6 +237,246 @@ function gen_outbound(flag, node, tag, proxy_table)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function gen_config_server(node)
|
||||||
|
local settings = nil
|
||||||
|
local routing = nil
|
||||||
|
local outbounds = {
|
||||||
|
{protocol = "freedom", tag = "direct"}, {protocol = "blackhole", tag = "blocked"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if node.protocol == "vmess" or node.protocol == "vless" then
|
||||||
|
if node.uuid then
|
||||||
|
local clients = {}
|
||||||
|
for i = 1, #node.uuid do
|
||||||
|
clients[i] = {
|
||||||
|
id = node.uuid[i],
|
||||||
|
flow = ("vless" == node.protocol and "1" == node.tls and node.tlsflow) and node.tlsflow or nil
|
||||||
|
}
|
||||||
|
end
|
||||||
|
settings = {
|
||||||
|
clients = clients,
|
||||||
|
decryption = node.decryption or "none"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elseif node.protocol == "socks" then
|
||||||
|
settings = {
|
||||||
|
udp = ("1" == node.udp_forward) and true or false,
|
||||||
|
auth = ("1" == node.auth) and "password" or "noauth",
|
||||||
|
accounts = ("1" == node.auth) and {
|
||||||
|
{
|
||||||
|
user = node.username,
|
||||||
|
pass = node.password
|
||||||
|
}
|
||||||
|
} or nil
|
||||||
|
}
|
||||||
|
elseif node.protocol == "http" then
|
||||||
|
settings = {
|
||||||
|
allowTransparent = false,
|
||||||
|
accounts = ("1" == node.auth) and {
|
||||||
|
{
|
||||||
|
user = node.username,
|
||||||
|
pass = node.password
|
||||||
|
}
|
||||||
|
} or nil
|
||||||
|
}
|
||||||
|
node.transport = "tcp"
|
||||||
|
node.tcp_guise = "none"
|
||||||
|
elseif node.protocol == "shadowsocks" then
|
||||||
|
settings = {
|
||||||
|
method = node.method,
|
||||||
|
password = node.password,
|
||||||
|
ivCheck = ("1" == node.iv_check) and true or false,
|
||||||
|
network = node.ss_network or "TCP,UDP"
|
||||||
|
}
|
||||||
|
elseif node.protocol == "trojan" then
|
||||||
|
if node.uuid then
|
||||||
|
local clients = {}
|
||||||
|
for i = 1, #node.uuid do
|
||||||
|
clients[i] = {
|
||||||
|
password = node.uuid[i],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
settings = {
|
||||||
|
clients = clients
|
||||||
|
}
|
||||||
|
end
|
||||||
|
elseif node.protocol == "mtproto" then
|
||||||
|
settings = {
|
||||||
|
users = {
|
||||||
|
{
|
||||||
|
secret = (node.password == nil) and "" or node.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif node.protocol == "dokodemo-door" then
|
||||||
|
settings = {
|
||||||
|
network = node.d_protocol,
|
||||||
|
address = node.d_address,
|
||||||
|
port = tonumber(node.d_port)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
if node.fallback and node.fallback == "1" then
|
||||||
|
local fallbacks = {}
|
||||||
|
for i = 1, #node.fallback_list do
|
||||||
|
local fallbackStr = node.fallback_list[i]
|
||||||
|
if fallbackStr then
|
||||||
|
local tmp = {}
|
||||||
|
string.gsub(fallbackStr, '[^' .. "," .. ']+', function(w)
|
||||||
|
table.insert(tmp, w)
|
||||||
|
end)
|
||||||
|
local dest = tmp[1] or ""
|
||||||
|
local path = tmp[2]
|
||||||
|
if dest:find("%.") then
|
||||||
|
else
|
||||||
|
dest = tonumber(dest)
|
||||||
|
end
|
||||||
|
fallbacks[i] = {
|
||||||
|
path = path,
|
||||||
|
dest = dest,
|
||||||
|
xver = 1
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
settings.fallbacks = fallbacks
|
||||||
|
end
|
||||||
|
|
||||||
|
routing = {
|
||||||
|
domainStrategy = "IPOnDemand",
|
||||||
|
rules = {
|
||||||
|
{
|
||||||
|
type = "field",
|
||||||
|
ip = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"},
|
||||||
|
outboundTag = (node.accept_lan == nil or node.accept_lan == "0") and "blocked" or "direct"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if node.outbound_node and node.outbound_node ~= "nil" then
|
||||||
|
local outbound = nil
|
||||||
|
if node.outbound_node == "_iface" and node.outbound_node_iface then
|
||||||
|
outbound = {
|
||||||
|
protocol = "freedom",
|
||||||
|
tag = "outbound",
|
||||||
|
streamSettings = {
|
||||||
|
sockopt = {
|
||||||
|
interface = node.outbound_node_iface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
local outbound_node_t = uci:get_all("passwall", node.outbound_node)
|
||||||
|
if node.outbound_node == "_socks" or node.outbound_node == "_http" then
|
||||||
|
outbound_node_t = {
|
||||||
|
type = node.type,
|
||||||
|
protocol = node.outbound_node:gsub("_", ""),
|
||||||
|
transport = "tcp",
|
||||||
|
address = node.outbound_node_address,
|
||||||
|
port = node.outbound_node_port,
|
||||||
|
username = (node.outbound_node_username and node.outbound_node_username ~= "") and node.outbound_node_username or nil,
|
||||||
|
password = (node.outbound_node_password and node.outbound_node_password ~= "") and node.outbound_node_password or nil,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
outbound = require("luci.passwall.util_xray").gen_outbound(nil, outbound_node_t, "outbound")
|
||||||
|
end
|
||||||
|
if outbound then
|
||||||
|
table.insert(outbounds, 1, outbound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local config = {
|
||||||
|
log = {
|
||||||
|
-- error = "/tmp/etc/passwall_server/log/" .. user[".name"] .. ".log",
|
||||||
|
loglevel = ("1" == node.log) and node.loglevel or "none"
|
||||||
|
},
|
||||||
|
-- 传入连接
|
||||||
|
inbounds = {
|
||||||
|
{
|
||||||
|
listen = (node.bind_local == "1") and "127.0.0.1" or nil,
|
||||||
|
port = tonumber(node.port),
|
||||||
|
protocol = node.protocol,
|
||||||
|
settings = settings,
|
||||||
|
streamSettings = {
|
||||||
|
network = node.transport,
|
||||||
|
security = "none",
|
||||||
|
tlsSettings = ("1" == node.tls) and {
|
||||||
|
disableSystemRoot = false,
|
||||||
|
certificates = {
|
||||||
|
{
|
||||||
|
certificateFile = node.tls_certificateFile,
|
||||||
|
keyFile = node.tls_keyFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} or nil,
|
||||||
|
tcpSettings = (node.transport == "tcp") and {
|
||||||
|
acceptProxyProtocol = (node.acceptProxyProtocol and node.acceptProxyProtocol == "1") and true or false,
|
||||||
|
header = {
|
||||||
|
type = node.tcp_guise,
|
||||||
|
request = (node.tcp_guise == "http") and {
|
||||||
|
path = node.tcp_guise_http_path or {"/"},
|
||||||
|
headers = {
|
||||||
|
Host = node.tcp_guise_http_host or {}
|
||||||
|
}
|
||||||
|
} or nil
|
||||||
|
}
|
||||||
|
} or nil,
|
||||||
|
kcpSettings = (node.transport == "mkcp") and {
|
||||||
|
mtu = tonumber(node.mkcp_mtu),
|
||||||
|
tti = tonumber(node.mkcp_tti),
|
||||||
|
uplinkCapacity = tonumber(node.mkcp_uplinkCapacity),
|
||||||
|
downlinkCapacity = tonumber(node.mkcp_downlinkCapacity),
|
||||||
|
congestion = (node.mkcp_congestion == "1") and true or false,
|
||||||
|
readBufferSize = tonumber(node.mkcp_readBufferSize),
|
||||||
|
writeBufferSize = tonumber(node.mkcp_writeBufferSize),
|
||||||
|
seed = (node.mkcp_seed and node.mkcp_seed ~= "") and node.mkcp_seed or nil,
|
||||||
|
header = {type = node.mkcp_guise}
|
||||||
|
} or nil,
|
||||||
|
wsSettings = (node.transport == "ws") and {
|
||||||
|
acceptProxyProtocol = (node.acceptProxyProtocol and node.acceptProxyProtocol == "1") and true or false,
|
||||||
|
headers = (node.ws_host) and {Host = node.ws_host} or nil,
|
||||||
|
path = node.ws_path
|
||||||
|
} or nil,
|
||||||
|
httpSettings = (node.transport == "h2") and {
|
||||||
|
path = node.h2_path, host = node.h2_host
|
||||||
|
} or nil,
|
||||||
|
dsSettings = (node.transport == "ds") and {
|
||||||
|
path = node.ds_path
|
||||||
|
} or nil,
|
||||||
|
quicSettings = (node.transport == "quic") and {
|
||||||
|
security = node.quic_security,
|
||||||
|
key = node.quic_key,
|
||||||
|
header = {type = node.quic_guise}
|
||||||
|
} or nil,
|
||||||
|
grpcSettings = (node.transport == "grpc") and {
|
||||||
|
serviceName = node.grpc_serviceName
|
||||||
|
} or nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
-- 传出连接
|
||||||
|
outbounds = outbounds,
|
||||||
|
routing = routing
|
||||||
|
}
|
||||||
|
|
||||||
|
local alpn = {}
|
||||||
|
if node.alpn then
|
||||||
|
string.gsub(node.alpn, '[^' .. "," .. ']+', function(w)
|
||||||
|
table.insert(alpn, w)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
if alpn and #alpn > 0 then
|
||||||
|
if config.inbounds[1].streamSettings.tlsSettings then
|
||||||
|
config.inbounds[1].streamSettings.tlsSettings.alpn = alpn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if "1" == node.tls then
|
||||||
|
config.inbounds[1].streamSettings.security = "tls"
|
||||||
|
end
|
||||||
|
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
function gen_config(var)
|
function gen_config(var)
|
||||||
local flag = var["-flag"]
|
local flag = var["-flag"]
|
||||||
local node_id = var["-node"]
|
local node_id = var["-node"]
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.v2ray", package.seeall)
|
module("luci.passwall.v2ray", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local util = api.util
|
local util = api.util
|
@ -1,5 +1,5 @@
|
|||||||
module("luci.model.cbi.passwall.api.xray", package.seeall)
|
module("luci.passwall.xray", package.seeall)
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = api.fs
|
local fs = api.fs
|
||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
local util = api.util
|
local util = api.util
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local brook_version = api.get_brook_version()
|
local brook_version = api.get_brook_version()
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local hysteria_version = api.get_hysteria_version()
|
local hysteria_version = api.get_hysteria_version()
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local trojan_go_version = api.get_trojan_go_version()
|
local trojan_go_version = api.get_trojan_go_version()
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local v2ray_version = api.get_v2ray_version()
|
local v2ray_version = api.get_v2ray_version()
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local xray_version = api.get_xray_version()
|
local xray_version = api.get_xray_version()
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
<div class="cbi-section cbi-tblsection">
|
<div class="cbi-section cbi-tblsection">
|
||||||
<div id="dns_div">
|
<div id="dns_div">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local auto_switch = api.uci_get_type("auto_switch", "enable", 0)
|
local auto_switch = api.uci_get_type("auto_switch", "enable", 0)
|
||||||
-%>
|
-%>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
local uci = require 'luci.model.uci'.cursor()
|
local uci = require 'luci.model.uci'.cursor()
|
||||||
local mode = 'normal'
|
local mode = 'normal'
|
||||||
@ -64,10 +64,10 @@ https://github.com/pure-css/pure/blob/master/LICENSE.md
|
|||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
.block h4 {
|
.block h4 {
|
||||||
background-image: none;
|
background-image: none;
|
||||||
background-color: #1e1e1e;
|
background-color: #131b33;
|
||||||
}
|
}
|
||||||
.block.pure-g {
|
.block.pure-g {
|
||||||
background: #2d2d2d;
|
background: #0a0f17;
|
||||||
box-shadow: unset;
|
box-shadow: unset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local console_port = api.uci_get_type("global_haproxy", "console_port", "")
|
local console_port = api.uci_get_type("global_haproxy", "console_port", "")
|
||||||
-%>
|
-%>
|
||||||
<p id="_status"></p>
|
<p id="_status"></p>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<%+cbi/valueheader%>
|
<%+cbi/valueheader%>
|
||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
local has_v2ray = api.is_finded("v2ray")
|
local has_v2ray = api.is_finded("v2ray")
|
||||||
local has_xray = api.is_finded("xray")
|
local has_xray = api.is_finded("xray")
|
||||||
-%>
|
-%>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
|
|
||||||
local gfwlist_update = api.uci_get_type("global_rules", "gfwlist_update", "1") == "1" and "checked='checked'" or ""
|
local gfwlist_update = api.uci_get_type("global_rules", "gfwlist_update", "1") == "1" and "checked='checked'" or ""
|
||||||
local chnroute_update = api.uci_get_type("global_rules", "chnroute_update", "1") == "1" and "checked='checked'" or ""
|
local chnroute_update = api.uci_get_type("global_rules", "chnroute_update", "1") == "1" and "checked='checked'" or ""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<%
|
<%
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
-%>
|
-%>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
START=99
|
START=99
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
lua /usr/lib/lua/luci/model/cbi/passwall/server/api/app.lua start
|
lua /usr/lib/lua/luci/passwall/server_app.lua start
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
lua /usr/lib/lua/luci/model/cbi/passwall/server/api/app.lua stop
|
lua /usr/lib/lua/luci/passwall/server_app.lua stop
|
||||||
}
|
}
|
||||||
|
|
||||||
restart() {
|
restart() {
|
||||||
|
@ -31,12 +31,12 @@ PROXY_IPV6_UDP=0
|
|||||||
resolve_dns=0
|
resolve_dns=0
|
||||||
use_tcp_node_resolve_dns=0
|
use_tcp_node_resolve_dns=0
|
||||||
use_udp_node_resolve_dns=0
|
use_udp_node_resolve_dns=0
|
||||||
LUA_API_PATH=/usr/lib/lua/luci/model/cbi/$CONFIG/api
|
LUA_UTIL_PATH=/usr/lib/lua/luci/passwall
|
||||||
UTIL_SS=$LUA_API_PATH/util_shadowsocks.lua
|
UTIL_SS=$LUA_UTIL_PATH/util_shadowsocks.lua
|
||||||
UTIL_XRAY=$LUA_API_PATH/util_xray.lua
|
UTIL_XRAY=$LUA_UTIL_PATH/util_xray.lua
|
||||||
UTIL_TROJAN=$LUA_API_PATH/util_trojan.lua
|
UTIL_TROJAN=$LUA_UTIL_PATH/util_trojan.lua
|
||||||
UTIL_NAIVE=$LUA_API_PATH/util_naiveproxy.lua
|
UTIL_NAIVE=$LUA_UTIL_PATH/util_naiveproxy.lua
|
||||||
UTIL_HYSTERIA=$LUA_API_PATH/util_hysteria.lua
|
UTIL_HYSTERIA=$LUA_UTIL_PATH/util_hysteria.lua
|
||||||
|
|
||||||
echolog() {
|
echolog() {
|
||||||
local d="$(date "+%Y-%m-%d %H:%M:%S")"
|
local d="$(date "+%Y-%m-%d %H:%M:%S")"
|
||||||
@ -263,7 +263,7 @@ lua_api() {
|
|||||||
echo "nil"
|
echo "nil"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
echo $(lua -e "local api = require 'luci.model.cbi.passwall.api.api' print(api.${func})")
|
echo $(lua -e "local api = require 'luci.passwall.api' print(api.${func})")
|
||||||
}
|
}
|
||||||
|
|
||||||
run_ipt2socks() {
|
run_ipt2socks() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
require "luci.sys"
|
require "luci.sys"
|
||||||
local api = require "luci.model.cbi.passwall.api.api"
|
local api = require "luci.passwall.api"
|
||||||
|
|
||||||
local var = api.get_args(arg)
|
local var = api.get_args(arg)
|
||||||
local FLAG = var["-FLAG"]
|
local FLAG = var["-FLAG"]
|
||||||
|
@ -6,7 +6,7 @@ local luci = luci
|
|||||||
local ucic = luci.model.uci.cursor()
|
local ucic = luci.model.uci.cursor()
|
||||||
local jsonc = require "luci.jsonc"
|
local jsonc = require "luci.jsonc"
|
||||||
local name = 'passwall'
|
local name = 'passwall'
|
||||||
local api = require ("luci.model.cbi." .. name .. ".api.api")
|
local api = require ("luci.passwall.api")
|
||||||
local arg1 = arg[1]
|
local arg1 = arg[1]
|
||||||
|
|
||||||
local rule_path = "/usr/share/" .. name .. "/rules"
|
local rule_path = "/usr/share/" .. name .. "/rules"
|
||||||
|
@ -9,7 +9,7 @@ require 'luci.util'
|
|||||||
require 'luci.jsonc'
|
require 'luci.jsonc'
|
||||||
require 'luci.sys'
|
require 'luci.sys'
|
||||||
local appname = 'passwall'
|
local appname = 'passwall'
|
||||||
local api = require ("luci.model.cbi." .. appname .. ".api.api")
|
local api = require ("luci.passwall.api")
|
||||||
local datatypes = require "luci.cbi.datatypes"
|
local datatypes = require "luci.cbi.datatypes"
|
||||||
|
|
||||||
-- these global functions are accessed all the time by the event handler
|
-- these global functions are accessed all the time by the event handler
|
||||||
|
Loading…
Reference in New Issue
Block a user