rewrite luci v2ray pro

This commit is contained in:
coolsnowwolf 2018-09-19 22:52:17 +08:00
parent c180aab044
commit 9f1850a540
22 changed files with 226 additions and 295 deletions

View File

@ -1,4 +1,4 @@
src-git packages https://github.com/openwrt/packages.git src-git packages https://github.com/openwrt/packages.git;openwrt-18.06
src-git luci https://github.com/openwrt/luci.git src-git luci https://github.com/openwrt/luci.git;openwrt-18.06
src-git routing https://git.openwrt.org/feed/routing.git;openwrt-18.06 src-git routing https://git.openwrt.org/feed/routing.git;openwrt-18.06
#src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-18.06 #src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-18.06

View File

@ -6,10 +6,10 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for V2Ray (Please select lua-cjson package manually) LUCI_TITLE:=LuCI support for V2Ray (Please select lua-cjson package manually)
LUCI_DEPENDS:=+iptables-mod-tproxy +kmod-ipt-tproxy +ip +ipset-lists +pdnsd-alt +coreutils +coreutils-base64 +coreutils-nohup +dnsmasq-full +ca-certificates +v2ray LUCI_DEPENDS:=+iptables-mod-tproxy +kmod-ipt-tproxy +ip +ipset-lists +pdnsd-alt +coreutils +coreutils-base64 +coreutils-nohup +dnsmasq-full +v2ray
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_VERSION:=1.0 PKG_VERSION:=1.0
PKG_RELEASE:=6 PKG_RELEASE:=8
include $(TOPDIR)/feeds/luci/luci.mk include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -0,0 +1,17 @@
module("luci.controller.v2raypro", package.seeall)
function index()
if not nixio.fs.access("/etc/config/v2raypro") then
return
end
local page
page = entry({"admin", "services", "v2raypro"}, cbi("v2raypro"), _("V2Ray Pro"))
page.dependent = true
entry({"admin","services","v2raypro","status"},call("act_status")).leaf=true
end
function act_status()
local e={}
e.running=luci.sys.call("pgrep v2ray >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -1,3 +1,4 @@
local fs = require "nixio.fs" local fs = require "nixio.fs"
local NXFS = require "nixio.fs" local NXFS = require "nixio.fs"
local WLFS = require "nixio.fs" local WLFS = require "nixio.fs"
@ -9,21 +10,14 @@ local dog = "/tmp/v2raypro.log"
local http = luci.http local http = luci.http
local ucursor = require "luci.model.uci".cursor() local ucursor = require "luci.model.uci".cursor()
local Status m = Map("v2raypro")
if SYS.call("pidof v2ray > /dev/null") == 0 then
Status = translate("<strong><font color=\"green\">V2Ray is Running</font></strong>")
else
Status = translate("<strong><font color=\"red\">V2Ray is Not Running</font></strong>")
end
m = Map("v2ray")
m.title = translate("V2Ray Transparent Proxy") m.title = translate("V2Ray Transparent Proxy")
m.description = translate("A fast secure tunnel proxy that help you get through firewalls on your router") m.description = translate("A fast secure tunnel proxy that help you get through firewalls on your router")
s = m:section(TypedSection, "v2ray") m:section(SimpleSection).template = "v2raypro/v2raypro_status"
s = m:section(TypedSection, "v2raypro")
s.anonymous = true s.anonymous = true
s.description = translate(string.format("%s<br /><br />", Status))
-- --------------------------------------------------- -- ---------------------------------------------------
@ -56,9 +50,6 @@ safe_dns_tcp = s:taboption("basic",Flag, "safe_dns_tcp", translate("DNS uses TCP
safe_dns_tcp.rmempty = false safe_dns_tcp.rmempty = false
-- safe_dns_tcp:depends("more", "1") -- safe_dns_tcp:depends("more", "1")
-- more_opt = s:taboption("basic",Flag, "more", translate("More Options"),
-- translate("Options for advanced users"))
-- timeout = s:taboption("basic",Value, "timeout", translate("Timeout")) -- timeout = s:taboption("basic",Value, "timeout", translate("Timeout"))
-- timeout.datatype = "range(0,10000)" -- timeout.datatype = "range(0,10000)"
-- timeout.placeholder = "60" -- timeout.placeholder = "60"
@ -81,89 +72,22 @@ safe_dns_tcp.rmempty = false
--fast_open =s:taboption("basic",Flag, "fast_open", translate("TCP Fast Open"), --fast_open =s:taboption("basic",Flag, "fast_open", translate("TCP Fast Open"),
-- translate("Enable TCP fast open, only available on kernel > 3.7.0")) -- translate("Enable TCP fast open, only available on kernel > 3.7.0"))
s:tab("main", translate("Server Setting")) s:tab("main", translate("Server Setting"))
use_conf_file = s:taboption("main",Flag, "use_conf_file", translate("Use Config File"))
use_conf_file.rmempty = false
if nixio.fs.access("/usr/bin/v2ray/v2ctl") then
conf_file_type = s:taboption("main",ListValue, "conf_file_type", translate("Config File Type"))
conf_file_type:value("pb","Protobuf")
else
conf_file_type = s:taboption("main",ListValue, "conf_file_type", translate("Config File Type"), translate("Warning: Can't find v2ctl. You can only choose Protobuf."))
end
conf_file_type:value("json","JSON")
conf_file_type:depends("use_conf_file", 1)
conf_file_path = s:taboption("main",Value, "conf_file_path", translate("Config File Path"),
translate("If you choose to upload a new file, please do not modify and this configuration will be overwritten automatically."))
conf_file_path:depends("use_conf_file", 1)
upload_conf = s:taboption("main",FileUpload, "")
upload_conf.template = "cbi/other_upload2"
upload_conf:depends("use_conf_file", 1)
um = s:taboption("main",DummyValue, "", nil)
um.template = "cbi/other_dvalue"
um:depends("use_conf_file", 1)
local conf_dir, fd
conf_dir = "/etc/v2ray/"
nixio.fs.mkdir(conf_dir)
http.setfilehandler(
function(meta, chunk, eof)
if not fd then
if not meta then return end
if meta and chunk then fd = nixio.open(conf_dir .. meta.file, "w") end
if not fd then
um.value = 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
um.value = translate("File saved to") .. ' "/etc/v2ray/' .. meta.file .. '"'
ucursor:set("v2ray","v2ray","conf_file_path","/etc/v2ray/" .. meta.file)
ucursor:commit("v2ray")
end
end
)
if luci.http.formvalue("upload") then
local f = luci.http.formvalue("ulfile")
if #f <= 0 then
um.value = translate("No specify upload file.")
end
end
server = s:taboption("main",Value, "address", translate("Server Address")) server = s:taboption("main",Value, "address", translate("Server Address"))
server.datatype = "host" server.datatype = "host"
server:depends("use_conf_file", 0) server.rmempty = false
server_port = s:taboption("main",Value, "port", translate("Server Port")) server_port = s:taboption("main",Value, "port", translate("Server Port"))
server_port.datatype = "range(0,65535)" server_port.datatype = "range(0,65535)"
server_port:depends("use_conf_file", 0) server_port.rmempty = false
id = s:taboption("main",Value, "id", translate("ID")) id = s:taboption("main",Value, "id", translate("ID"))
id.password = true id.password = true
id:depends("use_conf_file", 0)
alterId = s:taboption("main",Value, "alterId", translate("Alter ID")) alterId = s:taboption("main",Value, "alterId", translate("Alter ID"))
alterId.datatype = "range(1,65535)" alterId.datatype = "range(1,65535)"
alterId:depends("use_conf_file", 0) alterId.rmempty = false
security = s:taboption("main",ListValue, "security", translate("Security")) security = s:taboption("main",ListValue, "security", translate("Security"))
security:value("none") security:value("none")
@ -171,13 +95,11 @@ security:value("auto")
security:value("aes-128-cfb") security:value("aes-128-cfb")
security:value("aes-128-gcm") security:value("aes-128-gcm")
security:value("chacha20-poly1305") security:value("chacha20-poly1305")
security:depends("use_conf_file", 0)
network_type = s:taboption("main",ListValue, "network_type", translate("Network Type")) network_type = s:taboption("main",ListValue, "network_type", translate("Network Type"))
network_type:value("tcp") network_type:value("tcp")
network_type:value("kcp") network_type:value("kcp")
network_type:value("ws") network_type:value("ws")
network_type:depends("use_conf_file", 0)
-- tcp settings -- tcp settings
tcp_obfs = s:taboption("main",ListValue, "tcp_obfs", translate("TCP Obfs")) tcp_obfs = s:taboption("main",ListValue, "tcp_obfs", translate("TCP Obfs"))
@ -238,13 +160,9 @@ ws_headers.datatype = "host"
-- others -- others
tls = s:taboption("main",Flag, "tls", translate("TLS")) tls = s:taboption("main",Flag, "tls", translate("TLS"))
tls.rmempty = false tls.rmempty = false
tls:depends("use_conf_file", 0)
mux = s:taboption("main",Flag, "mux", translate("Mux")) mux = s:taboption("main",Flag, "mux", translate("Mux"))
mux.rmempty = false mux.rmempty = false
mux:depends("use_conf_file", 0)
s:tab("list", translate("User-defined GFW-List")) s:tab("list", translate("User-defined GFW-List"))
gfwlist = s:taboption("list", TextValue, "conf") gfwlist = s:taboption("list", TextValue, "conf")
@ -320,11 +238,4 @@ e:value("disable",translate("No Proxy"))
e:value("global",translate("Global Proxy")) e:value("global",translate("Global Proxy"))
e:value("game",translate("Game Mode")) e:value("game",translate("Game Mode"))
-- ---------------------------------------------------
local apply = luci.http.formvalue("cbi.apply")
if apply then
os.execute("chmod +x /etc/init.d/v2raypro &")
os.execute("/etc/init.d/v2raypro restart >/dev/null 2>&1 &")
end
return m return m

View File

@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[v2raypro]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('v2raypro_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>V2Ray Pro <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>V2Ray Pro <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="v2raypro_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,18 @@
config v2raypro 'v2raypro'
option gfwlist 'china-banned'
option proxy_mode 'M'
option safe_dns_tcp '1'
option cron_mode '1'
option address '4.4.4.4'
option port '443'
option id '00755892-0921-4433-bd92-04242abd92af'
option alterId '64'
option security 'aes-128-gcm'
option network_type 'ws'
option tls '1'
option mux '1'
option ws_path '/v2ray'
option ws_headers 'www.baidu.com'
option enabled '0'

View File

@ -1,27 +1,54 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
#
#
START=99 START=99
# local port is defined in $V2_CONF_GENERATE_LUA STOP=10
SS_REDIR_PORT=7070
SS_REDIR_PIDFILE=/var/run/v2ray-go.pid EXTRA_COMMANDS="reload_rule"
V2RAY_REDIR_PORT=7070
V2RAY_REDIR_PIDFILE=/var/run/v2ray-redir-go.pid
PDNSD_LOCAL_PORT=7453 PDNSD_LOCAL_PORT=7453
SSRCONF=/etc/v2ray/config.json V2RAYCONF=/tmp/config.json
V2_CONF_GENERATE_LUA=/etc/v2ray/gen_config.lua
CRON_FILE=/etc/crontabs/root CRON_FILE=/etc/crontabs/root
CONFIG=v2ray V2_CONF_GENERATE_LUA=/etc/v2ray/gen_config.lua
V2RAY_EXEC_PATH=/usr/bin/v2ray/v2ray CONFIG=v2raypro
KEEP_GFWLIST=Y
vt_np_ipset="china"
get_config()
{
config_get_bool vt_enabled $1 enabled 0
config_get vt_server_addr $1 address
config_get vt_server_port $1 server_port
config_get vt_password $1 password
config_get vt_method $1 method
config_get vt_protocol $1 protocol
config_get vt_protoparam $1 protoparam
config_get vt_obfs $1 obfs
config_get obfs_param $1 obfs_param
config_get vt_proxy_mode $1 proxy_mode
config_get vt_timeout $1 timeout
config_get vt_safe_dns $1 safe_dns
config_get vt_timeout $1 timeout
config_get vt_safe_dns $1 safe_dns
config_get vt_safe_dns_port $1 safe_dns_port
config_get vt_safe_dns_tcp $1 safe_dns_tcp
config_get cron_mode $1 cron_mode 1
}
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# $covered_subnets, $local_addresses are not required
covered_subnets=`uci get v2ray.@v2ray[0].covered_subnets 2>/dev/null`
local_addresses=`uci get v2ray.@v2ray[0].local_addresses 2>/dev/null`
# Get LAN settings as default parameters # Get LAN settings as default parameters
[ -f /lib/functions/network.sh ] && . /lib/functions/network.sh [ -f /lib/functions/network.sh ] && . /lib/functions/network.sh
[ -z "$covered_subnets" ] && network_get_subnet covered_subnets lan network_get_subnet covered_subnets lan
[ -z "$local_addresses" ] && network_get_ipaddr local_addresses lan network_get_ipaddr local_addresses lan
vt_np_ipset="china" # Must be global variable
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
__gfwlist_by_mode() __gfwlist_by_mode()
{ {
@ -31,33 +58,19 @@ __gfwlist_by_mode()
esac esac
} }
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
start() start()
{ {
local vt_enabled=`uci get v2ray.@v2ray[0].enabled 2>/dev/null` config_load v2raypro
local vt_safe_dns=`uci get v2ray.@v2ray[0].safe_dns 2>/dev/null` config_foreach get_config v2raypro
local vt_safe_dns_port=`uci get v2ray.@v2ray[0].safe_dns_port 2>/dev/null`
local vt_safe_dns_tcp=`uci get v2ray.@v2ray[0].safe_dns_tcp 2>/dev/null`
local vt_proxy_mode=`uci get v2ray.@v2ray[0].proxy_mode`
local vt_server_addr=`uci get v2ray.@v2ray[0].address`
local cron_mode=`uci get v2ray.@v2ray[0].cron_mode 2>/dev/null`
local vt_gfwlist=`__gfwlist_by_mode $vt_proxy_mode`
local use_conf_file=`uci get v2ray.@v2ray[0].use_conf_file 2>/dev/null`
local conf_file_path=`uci get v2ray.@v2ray[0].conf_file_path 2>/dev/null`
local conf_file_type=`uci get v2ray.@v2ray[0].conf_file_type 2>/dev/null`
[ -f /etc/init.d/pdnsd ] && /etc/init.d/pdnsd disable 2>/dev/null [ -f /etc/init.d/pdnsd ] && /etc/init.d/pdnsd disable 2>/dev/null
# -----------------------------------------------------------------
if [ "$vt_enabled" = 0 ]; then if [ "$vt_enabled" = 0 ]; then
echo "WARNING: V2Ray is disabled." echo "WARNING: v2ray is disabled."
return 1 exit 0
fi fi
local vt_gfwlist=`__gfwlist_by_mode $vt_proxy_mode`
[ -z "$vt_proxy_mode" ] && vt_proxy_mode=M [ -z "$vt_proxy_mode" ] && vt_proxy_mode=M
[ -z "$vt_method" ] && vt_method=table [ -z "$vt_method" ] && vt_method=table
[ -z "$vt_timeout" ] && vt_timeout=60 [ -z "$vt_timeout" ] && vt_timeout=60
@ -71,24 +84,15 @@ start()
# ----------------------------------------------------------------- # -----------------------------------------------------------------
###### v2ray ###### ###### v2ray ######
/usr/bin/lua $V2_CONF_GENERATE_LUA $CONFIG $V2RAYCONF
/usr/bin/v2ray/v2ray -config=$V2RAYCONF &
echo "V2Ray started"
if [ "$use_conf_file" = 0 ]; then
/usr/bin/lua $V2_CONF_GENERATE_LUA $CONFIG $SSRCONF
$V2RAY_EXEC_PATH -config=$SSRCONF &
else
$V2RAY_EXEC_PATH -config=$conf_file_path -format=$conf_file_type &
fi
sleep 3
if pidof v2ray>/dev/null; then
echo "V2Ray started"
else
return 1
fi
# IPv4 firewall rules # IPv4 firewall rules
add_rule add_rule
# ----------------------------------------------------------------- # -----------------------------------------------------------------
mkdir -p /var/etc/dnsmasq-go.d mkdir -p /var/etc/dnsmasq-go.d
###### Anti-pollution configuration ###### ###### Anti-pollution configuration ######
@ -121,15 +125,15 @@ start()
conf-dir=/var/etc/dnsmasq-go.d conf-dir=/var/etc/dnsmasq-go.d
EOF EOF
/etc/init.d/dnsmasq restart /etc/init.d/dnsmasq restart
fi fi
add_cron add_cron
} }
stop() stop()
{ {
# ----------------------------------------------------------------- # -----------------------------------------------------------------
rm -rf /var/etc/dnsmasq-go.d rm -rf /var/etc/dnsmasq-go.d
if [ -f /tmp/dnsmasq.d/dnsmasq-go.conf ]; then if [ -f /tmp/dnsmasq.d/dnsmasq-go.conf ]; then
@ -141,16 +145,33 @@ stop()
# --STOP IPv4 firewall--------------------------------------------------------------- # --STOP IPv4 firewall---------------------------------------------------------------
del_rule del_rule
# ----------------------------------------------------------------- # -----------------------------------------------------------------
if [ -f $SS_REDIR_PIDFILE ]; then if [ -f $V2RAY_REDIR_PIDFILE ]; then
kill -9 `cat $SS_REDIR_PIDFILE` kill -9 `cat $V2RAY_REDIR_PIDFILE`
rm -f $SS_REDIR_PIDFILE rm -f $V2RAY_REDIR_PIDFILE
fi fi
killall -9 v2ray 2>/dev/null killall -9 v2ray 2>/dev/null
del_cron del_cron
} }
reload_rule()
{
config_load v2raypro
config_foreach get_config v2raypro
local vt_gfwlist=`__gfwlist_by_mode $vt_proxy_mode`
KEEP_GFWLIST=Y
del_rule
add_rule
if [ "$vt_safe_dns_tcp" = 1 ]; then
stop_pdnsd
start_pdnsd
fi
}
restart() restart()
{ {
KEEP_GFWLIST=Y KEEP_GFWLIST=Y
@ -158,23 +179,6 @@ restart()
start start
} }
reload()
{
local vt_enabled=`uci get v2ray.@v2ray[0].enabled 2>/dev/null`
local vt_server_addr=`uci get v2ray.@v2ray[0].address`
local vt_safe_dns=`uci get v2ray.@v2ray[0].safe_dns 2>/dev/null`
local vt_safe_dns_port=`uci get v2ray.@v2ray[0].safe_dns_port 2>/dev/null`
local vt_safe_dns_tcp=`uci get v2ray.@v2ray[0].safe_dns_tcp 2>/dev/null`
local vt_proxy_mode=`uci get v2ray.@v2ray[0].proxy_mode`
local vt_gfwlist=`__gfwlist_by_mode $vt_proxy_mode`
KEEP_GFWLIST=Y
del_rule
add_rule
if [ "$vt_safe_dns_tcp" = 1 ]; then
stop_pdnsd
start_pdnsd
fi
}
# $1: upstream DNS server # $1: upstream DNS server
start_pdnsd() start_pdnsd()
@ -185,14 +189,14 @@ start_pdnsd()
[ -n "$safe_dns" ] && tcp_dns_list="$safe_dns,$tcp_dns_list" [ -n "$safe_dns" ] && tcp_dns_list="$safe_dns,$tcp_dns_list"
#killall -9 pdnsd 2>/dev/null && sleep 1 #killall -9 pdnsd 2>/dev/null && sleep 1
kill -9 $(cat /var/run/pdnsd.pid) >/dev/null 2>&1 kill -9 $(cat /var/run/pdnsd.pid) >/dev/null 2>&1
mkdir -p /var/etc /var/pdnsd mkdir -p /var/etc /var/pdnsd
if ! test -f "/var/pdnsd/pdnsd.cache"; then if ! test -f "/var/pdnsd/pdnsd.cache"; then
dd if=/dev/zero of="/var/pdnsd/pdnsd.cache" bs=1 count=4 2> /dev/null dd if=/dev/zero of="/var/pdnsd/pdnsd.cache" bs=1 count=4 2> /dev/null
chown -R nobody.nogroup /var/pdnsd chown -R nobody.nogroup /var/pdnsd
fi fi
cat > /var/etc/pdnsd.conf <<EOF cat > /var/etc/pdnsd.conf <<EOF
global { global {
perm_cache=10240; perm_cache=10240;
@ -223,10 +227,10 @@ EOF
/usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d /usr/sbin/pdnsd -c /var/etc/pdnsd.conf -d
# Access TCP DNS server through V2Ray tunnel # Access TCP DNS server through v2ray tunnel
if iptables -t nat -N pdnsd_output; then if iptables -t nat -N pdnsd_output; then
iptables -t nat -A pdnsd_output -m set --match-set $vt_np_ipset dst -j RETURN iptables -t nat -A pdnsd_output -m set --match-set $vt_np_ipset dst -j RETURN
iptables -t nat -A pdnsd_output -p tcp -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -A pdnsd_output -p tcp -j REDIRECT --to $V2RAY_REDIR_PORT
fi fi
iptables -t nat -I OUTPUT -p tcp --dport 53 -j pdnsd_output iptables -t nat -I OUTPUT -p tcp --dport 53 -j pdnsd_output
} }
@ -247,7 +251,7 @@ add_cron()
sed -i '/up-gfwlist.sh/d' $CRON_FILE sed -i '/up-gfwlist.sh/d' $CRON_FILE
sed -i '/v2ray_watchdog.log/d' $CRON_FILE sed -i '/v2ray_watchdog.log/d' $CRON_FILE
if [ $cron_mode -eq 1 ]; then if [ $cron_mode -eq 1 ]; then
echo '0 5 * * * /etc/v2ray/up-gfwlist.sh > /tmp/gfwupdate.log 2>&1' >> $CRON_FILE echo '0 5 * * * /etc/v2ray/up-gfwlist.sh > /tmp/gfwupdate.log 2>&1' >> $CRON_FILE
fi fi
echo '0 */1 * * * /etc/v2ray/v2ray-watchdog >> /tmp/v2ray_watchdog.log 2>&1' >> $CRON_FILE echo '0 */1 * * * /etc/v2ray/v2ray-watchdog >> /tmp/v2ray_watchdog.log 2>&1' >> $CRON_FILE
echo '0 1 * * 0 echo "" > /tmp/v2ray_watchdog.log' >> $CRON_FILE echo '0 1 * * 0 echo "" > /tmp/v2ray_watchdog.log' >> $CRON_FILE
@ -277,11 +281,6 @@ uci_get_by_type() {
echo ${ret:=$3} echo ${ret:=$3}
} }
is_ipv6_address()
{
echo "$1" | grep -q ":"
}
add_rule() add_rule()
{ {
iptables -t nat -N v2ray_pre iptables -t nat -N v2ray_pre
@ -294,9 +293,8 @@ add_rule()
iptables -t nat -A v2ray_pre -d 127.0.0.0/8 -j RETURN iptables -t nat -A v2ray_pre -d 127.0.0.0/8 -j RETURN
iptables -t nat -A v2ray_pre -d 224.0.0.0/3 -j RETURN iptables -t nat -A v2ray_pre -d 224.0.0.0/3 -j RETURN
} }
iptables -t nat -A v2ray_pre -d $vt_server_addr -j RETURN iptables -t nat -A v2ray_pre -d $vt_server_addr -j RETURN
iptables -N gameboost -t mangle iptables -N gameboost -t mangle
ipset -! create gameuser hash:ip maxelem 65536 2>/dev/null ipset -! create gameuser hash:ip maxelem 65536 2>/dev/null
ip rule add fwmark 0x01/0x01 table 100 ip rule add fwmark 0x01/0x01 table 100
@ -305,7 +303,7 @@ add_rule()
iptables -t mangle -A gameboost -p udp -m set --match-set china dst -j RETURN iptables -t mangle -A gameboost -p udp -m set --match-set china dst -j RETURN
iptables -t mangle -A gameboost -p udp --dport 53 -j RETURN iptables -t mangle -A gameboost -p udp --dport 53 -j RETURN
iptables -t mangle -A gameboost -p udp -j TPROXY --on-port 7070 --tproxy-mark 0x01/0x01 iptables -t mangle -A gameboost -p udp -j TPROXY --on-port 7070 --tproxy-mark 0x01/0x01
iptables -t mangle -A PREROUTING -m set --match-set gameuser src -j gameboost iptables -t mangle -A PREROUTING -m set --match-set gameuser src -j gameboost
for i in $(seq 0 100) for i in $(seq 0 100)
do do
@ -316,11 +314,11 @@ add_rule()
iptables -t nat -A v2ray_pre -s $ip -j RETURN iptables -t nat -A v2ray_pre -s $ip -j RETURN
;; ;;
global) global)
iptables -t nat -A v2ray_pre -s $ip -p tcp -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -A v2ray_pre -s $ip -p tcp -j REDIRECT --to $V2RAY_REDIR_PORT
iptables -t nat -A v2ray_pre -s $ip -j RETURN iptables -t nat -A v2ray_pre -s $ip -j RETURN
;; ;;
game) game)
iptables -t nat -A v2ray_pre -p tcp -s $ip -m set ! --match-set china dst -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -A v2ray_pre -p tcp -s $ip -m set ! --match-set china dst -j REDIRECT --to $V2RAY_REDIR_PORT
ipset -! add gameuser $ip ipset -! add gameuser $ip
;; ;;
esac esac
@ -330,7 +328,7 @@ add_rule()
G) : ;; G) : ;;
S) S)
iptables -t nat -A v2ray_pre -m set --match-set $vt_np_ipset dst -j RETURN iptables -t nat -A v2ray_pre -m set --match-set $vt_np_ipset dst -j RETURN
iptables -t nat -I OUTPUT -p tcp -m multiport --dports 80,443 -m set ! --match-set $vt_np_ipset dst -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -I OUTPUT -p tcp -m multiport --dports 80,443 -m set ! --match-set $vt_np_ipset dst -j REDIRECT --to $V2RAY_REDIR_PORT
;; ;;
M) M)
ipset -! create $vt_gfwlist hash:ip maxelem 65536 2>/dev/null ipset -! create $vt_gfwlist hash:ip maxelem 65536 2>/dev/null
@ -339,7 +337,7 @@ add_rule()
ipset -! restore < /tmp/addinip.ipset ipset -! restore < /tmp/addinip.ipset
iptables -t nat -A v2ray_pre -m set ! --match-set $vt_gfwlist dst -j RETURN iptables -t nat -A v2ray_pre -m set ! --match-set $vt_gfwlist dst -j RETURN
iptables -t nat -A v2ray_pre -m set --match-set $vt_np_ipset dst -j RETURN iptables -t nat -A v2ray_pre -m set --match-set $vt_np_ipset dst -j RETURN
iptables -t nat -I OUTPUT -p tcp -m multiport --dports 80,443 -m set --match-set $vt_gfwlist dst -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -I OUTPUT -p tcp -m multiport --dports 80,443 -m set --match-set $vt_gfwlist dst -j REDIRECT --to $V2RAY_REDIR_PORT
;; ;;
V) V)
vt_np_ipset="" vt_np_ipset=""
@ -349,7 +347,7 @@ add_rule()
esac esac
local subnet local subnet
for subnet in $covered_subnets; do for subnet in $covered_subnets; do
iptables -t nat -A v2ray_pre -s $subnet -p tcp -j REDIRECT --to $SS_REDIR_PORT iptables -t nat -A v2ray_pre -s $subnet -p tcp -j REDIRECT --to $V2RAY_REDIR_PORT
done done
iptables -t nat -I PREROUTING -p tcp -j v2ray_pre iptables -t nat -I PREROUTING -p tcp -j v2ray_pre
} }
@ -360,12 +358,12 @@ del_rule()
while iptables -t nat -D PREROUTING -p tcp -j v2ray_pre 2>/dev/null; do :; done while iptables -t nat -D PREROUTING -p tcp -j v2ray_pre 2>/dev/null; do :; done
iptables -t nat -X v2ray_pre 2>/dev/null iptables -t nat -X v2ray_pre 2>/dev/null
fi fi
iptables -t nat -D OUTPUT -p tcp -m multiport --dports 80,443 -m set --match-set china-banned dst -j REDIRECT --to $SS_REDIR_PORT 2>/dev/null iptables -t nat -D OUTPUT -p tcp -m multiport --dports 80,443 -m set --match-set china-banned dst -j REDIRECT --to $V2RAY_REDIR_PORT 2>/dev/null
iptables -t nat -D OUTPUT -p tcp -m multiport --dports 80,443 -m set ! --match-set $vt_np_ipset dst -j REDIRECT --to $SS_REDIR_PORT 2>/dev/null iptables -t nat -D OUTPUT -p tcp -m multiport --dports 80,443 -m set ! --match-set $vt_np_ipset dst -j REDIRECT --to $V2RAY_REDIR_PORT 2>/dev/null
ip rule del fwmark 0x01/0x01 table 100 /usr/bin/ip rule del fwmark 0x01/0x01 table 100
ip route del local 0.0.0.0/0 dev lo table 100 /usr/bin/ip route del local 0.0.0.0/0 dev lo table 100
if iptables -t mangle -F gameboost 2>/dev/null; then if iptables -t mangle -F gameboost 2>/dev/null; then
while iptables -t mangle -D PREROUTING -m set --match-set gameuser src -j gameboost 2>/dev/null; do :; done while iptables -t mangle -D PREROUTING -m set --match-set gameuser src -j gameboost 2>/dev/null; do :; done
iptables -t mangle -X gameboost 2>/dev/null iptables -t mangle -X gameboost 2>/dev/null
@ -377,3 +375,4 @@ del_rule()
# ----------------------------------------------------------------- # -----------------------------------------------------------------
[ "$KEEP_GFWLIST" = Y ] || ipset destroy "$vt_gfwlist" 2>/dev/null [ "$KEEP_GFWLIST" = Y ] || ipset destroy "$vt_gfwlist" 2>/dev/null
} }

View File

@ -0,0 +1,20 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@v2raypro[-1]
add ucitrack v2raypro
set ucitrack.@v2raypro[-1].init=v2raypro
commit ucitrack
delete firewall.v2raypro
set firewall.v2raypro=include
set firewall.v2raypro.type=script
set firewall.v2raypro.path=/etc/v2raypro.include
set firewall.v2raypro.reload=1
commit firewall
EOF
/etc/init.d/v2raypro stop
/etc/init.d/v2raypro enable
rm -f /tmp/luci-indexcache
exit 0

View File

@ -4,8 +4,8 @@
]]-- ]]--
local conf_path, json_path = ... local conf_path, json_path = ...
conf_path = conf_path or "v2ray" conf_path = conf_path or "v2raypro"
json_path = json_path or "/etc/v2ray/config.json" json_path = json_path or "/tmp/config.json"
local local_listen_port = 7070 local local_listen_port = 7070
@ -13,7 +13,7 @@ local cjson = require "cjson.safe"
local ucursor = require "luci.model.uci".cursor() local ucursor = require "luci.model.uci".cursor()
local lip = require "luci.ip" local lip = require "luci.ip"
local v2ray_stream_mode = ucursor:get(conf_path, "v2ray", "network_type") -- tcp/kcp/ws local v2ray_stream_mode = ucursor:get(conf_path, "v2raypro", "network_type") -- tcp/kcp/ws
function v2ray_get_conf_list(op) function v2ray_get_conf_list(op)
local t = {} local t = {}
@ -69,25 +69,25 @@ local v2ray = {
settings = { settings = {
vnext = { vnext = {
[1] = { [1] = {
address = ucursor:get(conf_path, "v2ray", "address"), address = ucursor:get(conf_path, "v2raypro", "address"),
port = tonumber(ucursor:get(conf_path, "v2ray", "port")), port = tonumber(ucursor:get(conf_path, "v2raypro", "port")),
users = { users = {
[1] = { [1] = {
id = ucursor:get(conf_path, "v2ray", "id"), id = ucursor:get(conf_path, "v2raypro", "id"),
alterId = tonumber(ucursor:get(conf_path, "v2ray", "alterId")), alterId = tonumber(ucursor:get(conf_path, "v2raypro", "alterId")),
security = ucursor:get(conf_path, "v2ray", "security") security = ucursor:get(conf_path, "v2raypro", "security")
}, },
}, },
}, },
}, },
}, },
streamSettings = { streamSettings = {
network = ucursor:get(conf_path, "v2ray", "network_type"), network = ucursor:get(conf_path, "v2raypro", "network_type"),
security = (ucursor:get(conf_path, "v2ray", "tls") == '1') and "tls" or "none", security = (ucursor:get(conf_path, "v2raypro", "tls") == '1') and "tls" or "none",
tcpSettings = (v2ray_stream_mode == "tcp" and ucursor:get(conf_path, "v2ray", "tcp_obfs") == "http") and { tcpSettings = (v2ray_stream_mode == "tcp" and ucursor:get(conf_path, "v2raypro", "tcp_obfs") == "http") and {
connectionReuse = true, connectionReuse = true,
header = { header = {
type = ucursor:get(conf_path, "v2ray", "tcp_obfs"), type = ucursor:get(conf_path, "v2raypro", "tcp_obfs"),
request = { request = {
version = "1.1", version = "1.1",
method = "GET", method = "GET",
@ -118,28 +118,28 @@ local v2ray = {
} or nil, } or nil,
kcpSettings = (v2ray_stream_mode == "kcp") and { kcpSettings = (v2ray_stream_mode == "kcp") and {
mtu = tonumber(ucursor:get(conf_path, "v2ray", "kcp_mtu")), mtu = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_mtu")),
tti = tonumber(ucursor:get(conf_path, "v2ray", "kcp_tti")), tti = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_tti")),
uplinkCapacity = tonumber(ucursor:get(conf_path, "v2ray", "kcp_uplink")), uplinkCapacity = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_uplink")),
downlinkCapacity = tonumber(ucursor:get(conf_path, "v2ray", "kcp_downlink")), downlinkCapacity = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_downlink")),
congestion = (ucursor:get(conf_path, "v2ray", "kcp_congestion") == "1") and true or false, congestion = (ucursor:get(conf_path, "v2raypro", "kcp_congestion") == "1") and true or false,
readBufferSize = tonumber(ucursor:get(conf_path, "v2ray", "kcp_readbuf")), readBufferSize = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_readbuf")),
writeBufferSize = tonumber(ucursor:get(conf_path, "v2ray", "kcp_writebuf")), writeBufferSize = tonumber(ucursor:get(conf_path, "v2raypro", "kcp_writebuf")),
header = { header = {
type = ucursor:get(conf_path, "v2ray", "kcp_obfs") type = ucursor:get(conf_path, "v2raypro", "kcp_obfs")
} }
} or nil, } or nil,
wsSettings = (v2ray_stream_mode == "ws") and { wsSettings = (v2ray_stream_mode == "ws") and {
connectionReuse = true, connectionReuse = true,
path = ucursor:get(conf_path, "v2ray", "ws_path"), path = ucursor:get(conf_path, "v2raypro", "ws_path"),
headers = (ucursor:get(conf_path, "v2ray", "ws_headers") ~= nil) and { headers = (ucursor:get(conf_path, "v2raypro", "ws_headers") ~= nil) and {
Host = ucursor:get(conf_path, "v2ray", "ws_headers") Host = ucursor:get(conf_path, "v2raypro", "ws_headers")
} or nil, } or nil,
} or nil, } or nil,
}, },
mux = { mux = {
enabled = (ucursor:get(conf_path, "v2ray", "mux") == "1") and true or false enabled = (ucursor:get(conf_path, "v2raypro", "mux") == "1") and true or false
}, },
}, },
dns = { dns = {

View File

@ -0,0 +1,11 @@
#!/bin/sh
v2ray_enable=$(uci get v2raypro.@v2raypro[0].enabled 2>/dev/null)
if [ $v2ray_enable -eq 1 ]; then
if pidof v2ray>/dev/null; then
/etc/init.d/v2raypro reload_rule
else
/etc/init.d/v2raypro restart
fi
fi

View File

@ -1,9 +0,0 @@
module("luci.controller.v2ray", package.seeall)
function index()
if not nixio.fs.access("/etc/config/v2ray") then
return
end
local page
page = entry({"admin", "services", "v2ray"}, cbi("v2ray"), _("V2Ray Pro"))
page.dependent = true
end

View File

@ -1,31 +0,0 @@
config v2ray 'v2ray'
option gfwlist 'china-banned'
option enabled '0'
option proxy_mode 'M'
option safe_dns_tcp '1'
option cron_mode '1'
option address 'test.TEST'
option port '443'
option id '00755892-0921-4433-bd92-04242abd92af'
option alterId '64'
option security 'aes-128-gcm'
option network_type 'ws'
option tls '1'
option mux '1'
option tcp_obfs 'none'
list tcp_path '/'
list tcp_host 'www.baidu.com'
option kcp_obfs 'none'
option kcp_mtu '1350'
option kcp_tti '20'
option kcp_uplink '5'
option kcp_downlink '20'
option kcp_congestion '1'
option kcp_readbuf '2'
option kcp_writebuf '2'
option ws_path '/v2ray'
option ws_headers 'www.baidu.com'

View File

@ -1,16 +0,0 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete firewall.v2ray
set firewall.v2ray=include
set firewall.v2ray.type=script
set firewall.v2ray.path=/etc/v2ray.include
set firewall.v2ray.reload=1
commit firewall
EOF
/etc/init.d/v2raypro stop
/etc/init.d/v2raypro disable
rm -f /tmp/luci-indexcache
exit 0

View File

@ -1,11 +0,0 @@
#!/bin/sh
ssr_enable=$(uci get v2ray.@v2ray[0].enabled 2>/dev/null)
if [ $ssr_enable -eq 1 ]; then
if pidof v2ray>/dev/null; then
/etc/init.d/v2raypro reload
else
/etc/init.d/v2raypro restart
fi
fi

View File

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=v2ray PKG_NAME:=v2ray
PKG_VERSION:=v3.39 PKG_VERSION:=v3.41
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
ifeq ($(ARCH),x86_64) ifeq ($(ARCH),x86_64)