GithubHelp home page GithubHelp logo

v2scar's Introduction

v2scar

Sidecar For V2ray

go-releaser

视频安装教程

  • 面板视频安装教程: 地址

  • 后端对接视频教程: 地址

  • 隧道对接视频教程: 地址

原理介绍

该项目需要以 sidecar 的形式和 v2ray 部署在一台机器上

他通过grpc接口动态添加/删除V2ray的 Vmess/Trojan 用户, 并统计流量

通过接入 django-sspanel 的api,可以动态调节v2ray的Vmess/Trojan用户

目前实现了以下几个接口:

  • AddInboundUser
  • RemoveInboundUser
  • GetAndResetUserTraffic

使用说明

  • 可以直接以cli的形式运行:

./v2scar --api-endpoint="xxx" --grpc-endpoint="127.0.0.1:8080" --sync-time=60

  • 或者通过配置环境变量来运行:
export V2SCAR_SYNC_TIME=60 # 和django-sspanel同步的时间间隔
export V2SCAR_API_ENDPOINT="xxxx" # 这个是django-sspanel的sync api 地址
export V2SCAR_GRPC_ENDPOINT="127.0.0.1:8080" # 这个是机器上v2ray开放的grpc地址

配置V2ray:

这只是一份参考的配置, 关键的部分在于 stats/api/policy/routing

另外如果需要对接 django-sspanel的话,配置里的inbound的 port/tag/level 必须和面板后台里的配置相同

{
    "stats": {},
    "api": {
        "tag": "api",
        "services": [
            "HandlerService",
            "StatsService"
        ]
    },
    "log": {
        "loglevel": "warning"
    },
    "policy": {
        "levels": {
            "0": {
                "statsUserUplink": true,
                "statsUserDownlink": true
            }
        },
        "system": {
            "statsInboundUplink": true,
            "statsInboundDownlink": true
        }
    },
    "inbounds": [
        {
            "tag": "proxy",
            "port": 10086,
            "protocol": "vmess",
            "settings": {
                "clients": []
            }
        },
        {
            "listen": "127.0.0.1",
            "port": 8080,
            "protocol": "dokodemo-door",
            "settings": {
                "address": "127.0.0.1"
            },
            "tag": "api"
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {}
        }
    ],
    "routing": {
        "settings": {
            "rules": [
                {
                    "inboundTag": [
                        "api"
                    ],
                    "outboundTag": "api",
                    "type": "field"
                }
            ]
        },
        "strategy": "rules"
    }
}

dev

go get v2ray的时候需要 export GONOSUMDB=v2ray.com/core,github.com/v2fly/v2ray-core

v2scar's People

Contributors

ehco1996 avatar gkirito avatar qiqizjl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

v2scar's Issues

Typo in README

README 中的
./v2scar --api-endpoint="xxx" --grpc-endpoint="127.0.0.0:8080" --sync-time=60
应该是
./v2scar --api-endpoint="xxx" --grpc-endpoint="127.0.0.1:8080" --sync-time=60

Handler 无法找到

2020/03/23 18:47:49 services.go:67: [ERROR]: rpc error: code = Unknown desc = v2ray.com/core/app/proxyman/command: failed to get handler: proxy > v2ray.com/core/app/proxyman/inbound: handler not found: proxy
2020/03/23 18:47:49 services.go:67: [ERROR]: rpc error: code = Unknown desc = v2ray.com/core/app/proxyman/command: failed to get handler: proxy > v2ray.com/core/app/proxyman/inbound: handler not found: proxy
2020/03/23 18:47:49 services.go:67: [ERROR]: rpc error: code = Unknown desc = v2ray.com/core/app/proxyman/command: failed to get handler: proxy > v2ray.com/core/app/proxyman/inbound: handler not found: proxy
2020/03/23 18:47:49 tasks.go:148: [INFO] Call syncUserTrafficToServer ONLINE USER COUNT: 0

v2scar 执行后出现这个问题

GRPC连接失败

image

跟随你的视频教程做的,在执行到docker-compose up 这个命令时出现了:
“ v2scar | 2020/03/24 16:13:14 [WARNING]: GRPC连接失败,请检查V2ray是否运行并开放对应grpc端口 当前GRPC地址: v2ray:8080 错误信息: context deadline exceeded

由于是首次设置,我几乎没有改动设置相关。另外,我的系统时间、硬件时间和错误信息上的时间不同,v2ray对时间是有要求的,不知道是不是这方面的原因。
我无法找到错误的原因

请问作者怎么解决的代理问题?

go小白:请问作者怎么解决的代理问题?
django-sspanel和这个新的v2scar好像文档都不太全的样子。
我在go build的时候直接给我整个网络错误出来。
配好七牛的go proxy了,v2ray的源又不能访问,proxychains4也不行。

V2Ray 4.20下使用GPRC连接失败

使用示例配置文件启动V2Ray后无法启动v2scar 提示 “GRPC连接失败,请检查V2ray是否运行并开放对应grpc端口”
查询后发现inboundDetour已在4.0中弃用
v2scar是否暂不支持4.0版本的v2ray?

GRPC连接失败,端口已开放

一切配置正确,运行v2scar出现下面报错:

2019/10/26 02:46:32 [WARNING]: GRPC连接失败,请检查V2ray是否运行并开放对应grpc端口 当前GRPC地址: 127.0.0.1:8080

使用命令为:

./v2scar --api-endpoint="http://xxxx.xxxx/api/user_vmess_config/1/?token=xxxxx" --grpc-endpoint="127.0.0.1:8080" --sync-time=60

使用lsof -i:8080,已出现v2ray:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
v2ray   20064 root    5u  IPv4  66234      0t0  TCP localhost:webcache (LISTEN)

配置文件如下:

{
	"api": {
		"tag": "api",
		"services": [
			"HandlerService",
			"StatsService"
 		]
	},
	"log": {
		"access": "/var/log/v2ray/access.log",
		"error": "/var/log/v2ray/error.log",
		"loglevel": "warning"
	},
	"policy": {
		"levels": {
			"1": {
   				"statsUserUplink": true,
				"statsUserDownlink": true
			}
	},
	"system": {
 		"statsInboundUplink": true,
		"statsInboundDownlink": true
		}
	},
	"inbounds": [
		{
			"tag": "proxy",
			"port": 12345,
			"protocol": "vmess",
			"settings": {
				"clients": [
					{
						"id": "xxxxxxxxx-xxxxxx-xxxxxx-xxxxxx",
						"level": 1,
						"alterId": 233
					}
				]
			},
			"streamSettings": {
				"network": "tcp"
			},
			"sniffing": {
				"enabled": true,
				"destOverride": [
					"http",
					"tls"
				]
			}
		},
		{
			"listen": "127.0.0.1",
			"port": 8080,
			"protocol": "dokodemo-door",
			"settings": {
				"address": "127.0.0.1"
			},
			"tag": "api"
		}
	],
	"outbounds": [
		{
			"protocol": "freedom",
			"settings": {}
		},
		{
			"protocol": "blackhole",
			"settings": {},
			"tag": "blocked"
		},
		{
			"protocol": "freedom",
			"settings": {},
			"tag": "direct"
		},
		{
			"protocol": "mtproto",
			"settings": {},
			"tag": "tg-out"
		}
		//include_out_config
		//
	],
	"dns": {
		"server": [
			"1.1.1.1",
			"1.0.0.1",
			"8.8.8.8",
			"8.8.4.4",
			"localhost"
		]
	},
	"routing": {
		"domainStrategy": "IPOnDemand",	
		"rules": [
			{
				"type": "field",
				"ip": [
					"0.0.0.0/8",
					"10.0.0.0/8",
					"100.64.0.0/10",
					"127.0.0.0/8",
					"169.254.0.0/16",
					"172.16.0.0/12",
					"192.0.0.0/24",
					"192.0.2.0/24",
					"192.168.0.0/16",
					"198.18.0.0/15",
					"198.51.100.0/24",
					"203.0.113.0/24",
					"::1/128",
					"fc00::/7",
					"fe80::/10"
				],
				"outboundTag": "blocked"
			},
			{
				"type": "field",
				"inboundTag": ["tg-in"],
				"outboundTag": "tg-out"
			}
			,
                {
                    "type": "field",
                    "protocol": [
                        "bittorrent"
                    ],
                    "outboundTag": "blocked"
                },
			{
				"inboundTag": [
			  		"api"
				],
				"outboundTag": "api",
				"type": "field"
		  	}
			//include_ban_ad
			//include_rules
			//
		]
	},
	"strategy": "rules",
	"transport": {
		"kcpSettings": {
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": true
        },
		"sockopt": {
			"tcpFastOpen": true
		}
	}
}

使用的是233boy的脚本,自己修改了配置文件。
v2ray版本为:4.21.0,django-sspanel和grpc皆为最新版

panic: runtime error: invalid memory address or nil pointer dereference

错误信息:
v2scar-0 | 2020/11/24 23:45:56 tasks.go:88: [INFO] Call initOrUpdateUser
v2scar-0 | 2020/11/24 23:45:56 tasks.go:162: [INFO] Call syncUserTrafficToServer ONLINE USER COUNT: 0
v2scar-0 | 2020/11/24 23:46:56 tasks.go:88: [INFO] Call initOrUpdateUser
v2scar-0 | 2020/11/24 23:46:56 tasks.go:162: [INFO] Call syncUserTrafficToServer ONLINE USER COUNT: 0
v2scar-0 | 2020/11/24 23:47:56 tasks.go:88: [INFO] Call initOrUpdateUser
v2scar-0 | 2020/11/24 23:47:56 tasks.go:162: [INFO] Call syncUserTrafficToServer ONLINE USER COUNT: 0
v2scar-0 | 2020/11/24 23:48:56 tasks.go:88: [INFO] Call initOrUpdateUser
v2scar-0 | panic: runtime error: invalid memory address or nil pointer dereference
v2scar-0 | [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x9d292f]
v2scar-0 |
v2scar-0 | goroutine 69 [running]:
v2scar-0 | github.com/Ehco1996/v2scar.postJson(0xc0001f3f50, 0xc00003a014, 0x66, 0xa0f8a0, 0xc0001f1760, 0x0, 0x0)
v2scar-0 | /app/requests.go:22 +0x12f
v2scar-0 | github.com/Ehco1996/v2scar.syncUserTrafficToServer(0xc00009da80, 0xbe6440, 0xc0002ba680, 0xc0001f3f50)
v2scar-0 | /app/tasks.go:161 +0x32b
v2scar-0 | github.com/Ehco1996/v2scar.SyncTask(0xc00009da80)
v2scar-0 | /app/tasks.go:83 +0x428
v2scar-0 | created by main.main.func1


config.json
{
"stats": {},
"api": {
"tag": "api",
"services": [
"HandlerService",
"StatsService"
]
},
"log": {
"loglevel": "info"
},
"dns": {},
"policy": {
"system": {
"statsInboundUplink": true,
"statsInboundDownlink": true
}
},
"inbounds": [
{
"tag": "proxy",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "26a29ca2-68d2-4907-99d7-dec44c4ab2c7",
"email": "[email protected]",
"flow": "xtls-rprx-direct",
"user_id": 1,
"enable": true
}
],
"fallbacks": [
{
"dest": 80
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "xtls",
"xtlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"keyFile": "/root/v2ray.key",
"certificateFile": "/root/v2ray.crt"
}
]
}
}
},
{
"tag": "transit",
"port": 8080,
"protocol": "vmess",
"settings": {
"clients": []
},
"streamSettings": {
"network": "ws"
}
},
{
"tag": "api",
"port": "1090",
"listen": "0.0.0.0",
"protocol": "dokodemo-door",
"settings": {
"address": "0.0.0.0"
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
],
"routing": {
"rules": [
{
"type": "field",
"inboundTag": [
"api"
],
"outboundTag": "api"
}
],
"domainStrategy": "IPOnDemand"
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.