genv2rayconfig.lua 2.2 KB
Newer Older
1 2 3 4
local ucursor = require "luci.model.uci".cursor()
local json = require "luci.jsonc"
local server_section = arg[1]
local server = ucursor:get_all("v2ray_server", server_section)
C
coolsnowwolf 已提交
5

6 7 8 9 10 11 12 13 14
local proset

if server.protocol == "vmess" then
    proset = {
			clients = {
				{
					id = server.VMess_id,
					alterId = tonumber(server.VMess_alterId),
					level = tonumber(server.VMess_level)
15 16
				}
			}
17
		}
18 19 20 21 22
elseif server.protocol == "http" then
	proset = {
			allowTransparent = false,
			accounts = {
				{
23 24
					user = (server.Http_user == nil) and "" or server.Http_user,
					pass = (server.Http_pass == nil) and "" or server.Http_pass
25 26 27
				}
			}
		}
28 29
else
    proset = {
30
			auth =  (server.Socks_user == nil) and "noauth" or "password",
31 32
			accounts = {
				{
33 34
					user = (server.Socks_user == nil) and "" or server.Socks_user,
					pass = (server.Socks_pass == nil) and "" or server.Socks_pass
C
coolsnowwolf 已提交
35 36
				}
			}
37 38 39 40 41 42 43 44 45
		}
end


local v2ray = {
	log = {
		--error = "/var/log/v2ray.log",
		loglevel = "warning"
	},
46
	-- 传入连接
47 48 49 50
	inbound = {
		port = tonumber(server.port),
		protocol = server.protocol,
		settings = proset,
51
		-- 底层传输配置
52 53 54 55 56 57 58 59 60 61 62 63 64
		streamSettings = {
			network = server.transport,
			security = (server.tls == '1') and "tls" or "none",
			kcpSettings = (server.transport == "mkcp") and {
				mtu = tonumber(server.mkcp_mtu),
				tti = tonumber(server.mkcp_tti),
				uplinkCapacity = tonumber(server.mkcp_uplinkCapacity),
				downlinkCapacity = tonumber(server.mkcp_downlinkCapacity),
				congestion = (server.mkcp_congestion == "1") and true or false,
				readBufferSize = tonumber(server.mkcp_readBufferSize),
				writeBufferSize = tonumber(server.mkcp_writeBufferSize),
				header = {
					type = server.mkcp_guise
C
coolsnowwolf 已提交
65
				}
66 67 68 69 70 71 72 73 74 75
			} or nil,
			httpSettings = (server.transport == "h2") and {
				path = server.h2_path,
				host = server.h2_host,
			} or nil,
			quicSettings = (server.transport == "quic") and {
				security = server.quic_security,
				key = server.quic_key,
				header = {
					type = server.quic_guise
76
				}
77 78 79
			} or nil
		}
	},
80
	-- 传出连接
81 82 83
	outbound = {
		protocol = "freedom"
	},
84
	-- 额外传出连接
85 86 87 88
	outboundDetour = {
		{
			protocol = "blackhole",
			tag = "blocked"
C
coolsnowwolf 已提交
89
		}
90
	}
C
coolsnowwolf 已提交
91
}
92
print(json.stringify(v2ray,1))