From c03cdcb3b900c349bc852ed545a44893e2f626f6 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Fri, 18 Oct 2024 11:33:43 +0800 Subject: [PATCH] v2raya: add package --- net/v2raya/Makefile | 87 +++++++++++ net/v2raya/files/v2raya.config | 44 ++++++ net/v2raya/files/v2raya.init | 75 +++++++++ net/v2raya/test.sh | 3 + net/xray-core/Makefile | 89 +++++++++++ net/xray-core/files/config.json.example | 144 ++++++++++++++++++ net/xray-core/files/vpoint_socks_vmess.json | 25 +++ net/xray-core/files/vpoint_vmess_freedom.json | 31 ++++ net/xray-core/files/xray.conf | 11 ++ net/xray-core/files/xray.init | 58 +++++++ net/xray-core/test.sh | 7 + 11 files changed, 574 insertions(+) create mode 100644 net/v2raya/Makefile create mode 100644 net/v2raya/files/v2raya.config create mode 100755 net/v2raya/files/v2raya.init create mode 100644 net/v2raya/test.sh create mode 100644 net/xray-core/Makefile create mode 100644 net/xray-core/files/config.json.example create mode 100644 net/xray-core/files/vpoint_socks_vmess.json create mode 100644 net/xray-core/files/vpoint_vmess_freedom.json create mode 100644 net/xray-core/files/xray.conf create mode 100755 net/xray-core/files/xray.init create mode 100644 net/xray-core/test.sh diff --git a/net/v2raya/Makefile b/net/v2raya/Makefile new file mode 100644 index 00000000..ea2e2d26 --- /dev/null +++ b/net/v2raya/Makefile @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: GPL-3.0-only +# +# Copyright (C) 2021 ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_NAME:=v2rayA +PKG_VERSION:=2.2.6 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/v2rayA/v2rayA/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=2d52b8cc6fbd7264e53704684dd8ee56955852dbff324a45360d6ed1c923d8ba +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)/service + +PKG_LICENSE:=AGPL-3.0-only +PKG_LICENSE_FILES:=LICENSE +PKG_MAINTAINER:=Tianling Shen + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_BUILD_FLAGS:=no-mips16 + +GO_PKG:=github.com/v2rayA/v2rayA +GO_PKG_LDFLAGS_X:= \ + $(GO_PKG)/conf.Version=$(PKG_VERSION) \ + $(GO_PKG)/core/iptables.TproxyNotSkipBr=true + +include $(INCLUDE_DIR)/package.mk +include ../../lang/golang/golang-package.mk + +TAR_OPTIONS+= --strip-components 1 +TAR_CMD=$(HOST_TAR) -C $(1)/.. $(TAR_OPTIONS) + +define Package/v2raya + TITLE:=A Linux web GUI client of Project V + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + DEPENDS:=$(GO_ARCH_DEPENDS) \ + +ca-bundle \ + +kmod-nft-tproxy \ + +xray-core + URL:=https://v2raya.org +endef + +define Package/v2raya/description + v2rayA is a V2Ray Linux client supporting global transparent proxy, + compatible with SS, SSR, Trojan(trojan-go), PingTunnel protocols. +endef + +define Package/v2raya/conffiles +/etc/v2raya/ +/etc/config/v2raya +endef + +WEB_FILE:=$(PKG_NAME)-web-$(PKG_VERSION).tar.gz +define Download/v2raya-web + URL:=https://github.com/v2rayA/v2rayA/releases/download/v$(PKG_VERSION)/ + URL_FILE:=web.tar.gz + FILE:=$(WEB_FILE) + HASH:=123123d3d6d393c065348355b47db45aa6c6af10c60d6320f564883cd93c556a +endef + +define Build/Prepare + $(call Build/Prepare/Default) + + ( \ + mkdir -p $(PKG_BUILD_DIR)/server/router/web ; \ + gzip -dc $(DL_DIR)/$(WEB_FILE) | $(HOST_TAR) -C $(PKG_BUILD_DIR)/server/router/web $(TAR_OPTIONS) ; \ + ) +endef + +define Package/v2raya/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + $(INSTALL_DIR) $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/v2rayA $(1)/usr/bin/v2raya + + $(INSTALL_DIR) $(1)/etc/config/ + $(INSTALL_CONF) $(CURDIR)/files/v2raya.config $(1)/etc/config/v2raya + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) $(CURDIR)/files/v2raya.init $(1)/etc/init.d/v2raya +endef + +$(eval $(call Download,v2raya-web)) +$(eval $(call GoBinPackage,v2raya)) +$(eval $(call BuildPackage,v2raya)) diff --git a/net/v2raya/files/v2raya.config b/net/v2raya/files/v2raya.config new file mode 100644 index 00000000..66b66b24 --- /dev/null +++ b/net/v2raya/files/v2raya.config @@ -0,0 +1,44 @@ + +config v2raya 'config' + option enabled '0' + + # Listening address + option address '0.0.0.0:2017' + + # Make sure your IPv6 network works fine before you turn it on. + # Optional values: auto, on, off. + option ipv6_support 'auto' + + # Experimental feature. Make sure you have installed nftables. + # Optional values: auto, on, off. + option nftables_support 'auto' + + # Optional values: trace, debug, info, warn or error + option log_level 'info' + + # Maximum number of days to keep log files + option log_max_days '3' + + option log_disable_color '1' + + option log_disable_timestamp '0' + + # Executable v2ray binary path. Auto-detect if put it empty + option v2ray_bin '' + + # Additional v2ray config directory, files in it will be combined with config generated by v2rayA + option v2ray_confdir '' + + # The executable file to run in the transparent proxy life-cycle. + # v2rayA will pass in the --transparent-type (tproxy, redirect) + # and --stage (pre-start, post-start, pre-stop, post-stop) arguments. + option transparent_hook '' + + # The executable file to run in the v2ray-core life-cycle. + # v2rayA will pass in the --stage (pre-start, post-start, pre-stop, post-stop) argument. + option core_hook '' + + # The executable file to run in the v2ray-core life-cycle. + # v2rayA will pass in the --stage (pre-start, post-start, pre-stop, post-stop) argument. + option plugin_manager '' + diff --git a/net/v2raya/files/v2raya.init b/net/v2raya/files/v2raya.init new file mode 100755 index 00000000..1e55a187 --- /dev/null +++ b/net/v2raya/files/v2raya.init @@ -0,0 +1,75 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2021 Tianling Shen + +USE_PROCD=1 +START=99 + +CONF="v2raya" +PROG="/usr/bin/v2raya" + +is_enabled() { + local enabled + config_get_bool enabled "$1" "$2" "${3:-0}" + if [ "$enabled" -eq "1" ]; then + return 0 + else + return 1 + fi +} + +append_env() { + procd_append_param env "V2RAYA_$(echo "$1" | tr "[a-z]" "[A-Z]")"="$2" +} + +append_env_arg() { + local value + config_get value "$1" "$2" $3 + [ -n "$value" ] && append_env "$2" "$value" +} + +append_env_bool() { + is_enabled "$1" "$2" && append_env "$2" "true" +} + +start_service() { + config_load "$CONF" + + is_enabled "config" "enabled" || return 1 + + procd_open_instance "$CONF" + procd_set_param command "$PROG" + procd_set_param env XDG_DATA_HOME="/usr/share" + + append_env "config" "/etc/v2raya" + append_env "log_file" "/var/log/v2raya/v2raya.log" + + append_env_arg "config" "address" "0.0.0.0:2017" + append_env_arg "config" "ipv6_support" "auto" + append_env_arg "config" "nftables_support" "auto" + append_env_arg "config" "log_level" "info" + append_env_arg "config" "log_max_days" "3" + append_env_arg "config" "v2ray_bin" + append_env_arg "config" "v2ray_confdir" + append_env_arg "config" "transparent_hook" + append_env_arg "config" "core_hook" + append_env_arg "config" "plugin_manager" + append_env_bool "config" "log_disable_color" + append_env_bool "config" "log_disable_timestamp" + + procd_set_param limits core="unlimited" + procd_set_param limits nofile="1000000 1000000" + procd_set_param respawn + procd_set_param stdout 1 + procd_set_param stderr 1 + + procd_close_instance +} + +reload_service() { + stop + start +} + +service_triggers() { + procd_add_reload_trigger "$CONF" +} diff --git a/net/v2raya/test.sh b/net/v2raya/test.sh new file mode 100644 index 00000000..2c53d5fe --- /dev/null +++ b/net/v2raya/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +v2raya --version | grep "$PKG_VERSION" diff --git a/net/xray-core/Makefile b/net/xray-core/Makefile new file mode 100644 index 00000000..01ee70be --- /dev/null +++ b/net/xray-core/Makefile @@ -0,0 +1,89 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=xray-core +PKG_VERSION:=24.9.30 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/XTLS/Xray-core/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=0771120ddbf866fba44f2e8978bcc20f3843663f5726bd8db9e03e1a27e1212a + +PKG_MAINTAINER:=Tianling Shen +PKG_LICENSE:=MPL-2.0 +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_DIR:=$(BUILD_DIR)/Xray-core-$(PKG_VERSION) +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_BUILD_FLAGS:=no-mips16 + +GO_PKG:=github.com/xtls/xray-core +GO_PKG_BUILD_PKG:=github.com/xtls/xray-core/main +GO_PKG_LDFLAGS_X:= \ + $(GO_PKG)/core.build=OpenWrt \ + $(GO_PKG)/core.version=$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk +include ../../lang/golang/golang-package.mk + +define Package/xray/template + TITLE:=A platform for building proxies to bypass network restrictions + SECTION:=net + CATEGORY:=Network + URL:=https://xtls.github.io +endef + +define Package/xray-core + $(call Package/xray/template) + DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle +endef + +define Package/xray-example + $(call Package/xray/template) + TITLE+= (example configs) + DEPENDS:=xray-core + PKGARCH:=all +endef + +define Package/xray/description + Xray, Penetrates Everything. It helps you to build your own computer network. + It secures your network connections and thus protects your privacy. +endef + +define Package/xray-core/description + $(call Package/xray/description) +endef + +define Package/xray-example/description + $(call Package/xray/description) + + This includes example configuration files for xray-core. +endef + +define Package/xray-core/conffiles +/etc/xray/ +/etc/config/xray +endef + +define Package/xray-core/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + $(INSTALL_DIR) $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/main $(1)/usr/bin/xray + + $(INSTALL_DIR) $(1)/etc/xray/ + $(INSTALL_DATA) $(CURDIR)/files/config.json.example $(1)/etc/xray/ + + $(INSTALL_DIR) $(1)/etc/config/ + $(INSTALL_CONF) $(CURDIR)/files/xray.conf $(1)/etc/config/xray + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) $(CURDIR)/files/xray.init $(1)/etc/init.d/xray +endef + +define Package/xray-example/install + $(INSTALL_DIR) $(1)/etc/xray/ + $(INSTALL_DATA) $(CURDIR)/files/vpoint_socks_vmess.json $(1)/etc/xray/ + $(INSTALL_DATA) $(CURDIR)/files/vpoint_vmess_freedom.json $(1)/etc/xray/ +endef + +$(eval $(call BuildPackage,xray-core)) +$(eval $(call BuildPackage,xray-example)) diff --git a/net/xray-core/files/config.json.example b/net/xray-core/files/config.json.example new file mode 100644 index 00000000..710bb1be --- /dev/null +++ b/net/xray-core/files/config.json.example @@ -0,0 +1,144 @@ +// Config file of Xray. This file follows standard JSON format, with comments support. +// Uncomment entries below to satisfy your needs. Also read our manual for more detail at +// https://xtls.github.io/en/config/ +{ + "log": { + // By default, Xray writes access log to stdout. + // "access": "/path/to/access/log/file", + + // By default, Xray write error log to stdout. + // "error": "/path/to/error/log/file", + + // Log level, one of "debug", "info", "warning", "error", "none" + "loglevel": "warning" + }, + // List of inbound proxy configurations. + "inbounds": [{ + // Port to listen on. You may need root access if the value is less than 1024. + "port": 1080, + + // IP address to listen on. Change to "0.0.0.0" to listen on all network interfaces. + "listen": "127.0.0.1", + + // Tag of the inbound proxy. May be used for routing. + "tag": "socks-inbound", + + // Protocol name of inbound proxy. + "protocol": "socks", + + // Settings of the protocol. Varies based on protocol. + "settings": { + "auth": "noauth", + "udp": false, + "ip": "127.0.0.1" + }, + + // Enable sniffing on TCP connection. + "sniffing": { + "enabled": true, + // Target domain will be overriden to the one carried by the connection, if the connection is HTTP or HTTPS. + "destOverride": ["http", "tls"] + } + }], + // List of outbound proxy configurations. + "outbounds": [{ + // Protocol name of the outbound proxy. + "protocol": "freedom", + + // Settings of the protocol. Varies based on protocol. + "settings": {}, + + // Tag of the outbound. May be used for routing. + "tag": "direct" + },{ + "protocol": "blackhole", + "settings": {}, + "tag": "blocked" + }], + + // Transport is for global transport settings. If you have multiple transports with same settings + // (say mKCP), you may put it here, instead of in each individual inbound/outbounds. + //"transport": {}, + + // Routing controls how traffic from inbounds are sent to outbounds. + "routing": { + "domainStrategy": "IPOnDemand", + "rules":[ + { + // Blocks access to private IPs. Remove this if you want to access your router. + "type": "field", + "ip": ["geoip:private"], + "outboundTag": "blocked" + }, + { + // Blocks major ads. + "type": "field", + "domain": ["geosite:category-ads"], + "outboundTag": "blocked" + } + ] + }, + + // Dns settings for domain resolution. + "dns": { + // Static hosts, similar to hosts file. + "hosts": { + // Match v2ray.com to another domain on CloudFlare. This domain will be used when querying IPs for v2ray.com. + "domain:v2ray.com": "www.vicemc.net", + + // The following settings help to eliminate DNS poisoning in mainland China. + // It is safe to comment these out if this is not the case for you. + "domain:github.io": "pages.github.com", + "domain:wikipedia.org": "www.wikimedia.org", + "domain:shadowsocks.org": "electronicsrealm.com" + }, + "servers": [ + "1.1.1.1", + { + "address": "114.114.114.114", + "port": 53, + // List of domains that use this DNS first. + "domains": [ + "geosite:cn" + ] + }, + "8.8.8.8", + "localhost" + ] + }, + + // Policy controls some internal behavior of how Xray handles connections. + // It may be on connection level by user levels in 'levels', or global settings in 'system.' + "policy": { + // Connection policys by user levels + "levels": { + "0": { + "uplinkOnly": 0, + "downlinkOnly": 0 + } + }, + "system": { + "statsInboundUplink": false, + "statsInboundDownlink": false, + "statsOutboundUplink": false, + "statsOutboundDownlink": false + } + }, + + // Stats enables internal stats counter. + // This setting can be used together with Policy and Api. + //"stats":{}, + + // Api enables gRPC APIs for external programs to communicate with Xray instance. + //"api": { + //"tag": "api", + //"services": [ + // "HandlerService", + // "LoggerService", + // "StatsService" + //] + //}, + + // You may add other entries to the configuration, but they will not be recognized by Xray. + "other": {} +} diff --git a/net/xray-core/files/vpoint_socks_vmess.json b/net/xray-core/files/vpoint_socks_vmess.json new file mode 100644 index 00000000..789cd270 --- /dev/null +++ b/net/xray-core/files/vpoint_socks_vmess.json @@ -0,0 +1,25 @@ +{ + "log": { + "loglevel": "warning" + }, + "inbounds": [{ + "port": 1080, + "listen": "127.0.0.1", + "protocol": "socks", + "settings": { + "auth": "noauth", + "udp": false, + "ip": "127.0.0.1" + } + }], + "outbounds": [{ + "protocol": "freedom", + "settings": {}, + "tag": "direct" + }], + "policy": { + "levels": { + "0": {"uplinkOnly": 0} + } + } +} diff --git a/net/xray-core/files/vpoint_vmess_freedom.json b/net/xray-core/files/vpoint_vmess_freedom.json new file mode 100644 index 00000000..41c7e30f --- /dev/null +++ b/net/xray-core/files/vpoint_vmess_freedom.json @@ -0,0 +1,31 @@ +{ + "inbounds": [{ + "port": 10086, + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "23ad6b10-8d1a-40f7-8ad0-e3e35cd38297", + "level": 1 + } + ] + } + }], + "outbounds": [{ + "protocol": "freedom", + "settings": {} + },{ + "protocol": "blackhole", + "settings": {}, + "tag": "blocked" + }], + "routing": { + "rules": [ + { + "type": "field", + "ip": ["geoip:private"], + "outboundTag": "blocked" + } + ] + } +} diff --git a/net/xray-core/files/xray.conf b/net/xray-core/files/xray.conf new file mode 100644 index 00000000..362fbac0 --- /dev/null +++ b/net/xray-core/files/xray.conf @@ -0,0 +1,11 @@ + +config xray 'enabled' + option enabled '0' + +config xray 'config' + option confdir '/etc/xray' + list conffiles '/etc/xray/config.json' + option datadir '/usr/share/v2ray' + option dialer '' + option format 'json' + diff --git a/net/xray-core/files/xray.init b/net/xray-core/files/xray.init new file mode 100755 index 00000000..7e4b8a7d --- /dev/null +++ b/net/xray-core/files/xray.init @@ -0,0 +1,58 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=99 + +CONF="xray" +PROG="/usr/bin/xray" + +start_service() { + config_load "$CONF" + + local enabled + config_get_bool enabled "enabled" "enabled" "0" + [ "$enabled" -eq "1" ] || return 1 + + local confdir + local conffiles + local datadir + local dialer + local format + + config_get confdir "config" "confdir" + config_get conffiles "config" "conffiles" + config_get datadir "config" "datadir" "/usr/share/xray" + config_get dialer "config" "dialer" + config_get format "config" "format" "json" + + procd_open_instance "$CONF" + procd_set_param command "$PROG" run + [ -n "$confdir" ] && procd_append_param command -confdir "$confdir" + [ -n "$conffiles" ] && { + for i in $conffiles + do + procd_append_param command -config "$i" + done + } + [ -n "$format" ] && procd_append_param command -format "$format" + [ -n "$dialer" ] && procd_set_param env XRAY_BROWSER_DIALER="$dialer" + procd_set_param env XRAY_LOCATION_ASSET="$datadir" + procd_set_param file $conffiles + + procd_set_param limits core="unlimited" + procd_set_param limits nofile="1000000 1000000" + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param respawn + + procd_close_instance +} + +reload_service() { + stop + start +} + +service_triggers() { + procd_add_reload_trigger "$CONF" +} diff --git a/net/xray-core/test.sh b/net/xray-core/test.sh new file mode 100644 index 00000000..8fcce26f --- /dev/null +++ b/net/xray-core/test.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +case "$1" in + "xray-core") + xray version 2>&1 | grep "${2#*v}" + ;; +esac