Skip to content

Commit

Permalink
修复OLOrz996分支里端口分流规则模式无法删除的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 26, 2024
1 parent d3ac15f commit 3a1d575
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/yh.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
## iKuai Bypass
通过自定义运营商分流或者端口分流的方式实现非旁路由方式的自动分流,并定时更新规则。实现国内ip或者指定的ip或者指定的域名列表走直连或者经过openwrt等另外处理。
### ip分组和端口分流方式
国内ip直连,非国内ip指定下一条网关到openwrt。openwrt出口流量直连。实现方式
### 自定义运营商分流方式说明:
ikuai 可以通过分流规则 把openwrt或者其他路由作为爱快的上级虚拟运营商,同时作为ikuai的下级路由,再把openwrt的出口流量绑回到爱快实际的运营商,实现无感分流:国内网站访问速度更好、不用单独配置网关、openwrt炸了不影响正常上网、openwrt恢复后网络自愈。[查看具体实现方式](https://dev.leiyanhui.com/route/ikuai-bypass-joyanhui/) 或者查看 [恩山eezz](https://www.right.com.cn/forum/thread-8252571-1-1.html) 或者下文 [分流模式的简单说明](https://github.com/joyanhui/ikuai-bypass?tab=readme-ov-file#%E5%88%86%E6%B5%81%E6%A8%A1%E5%BC%8F%E7%AE%80%E5%8D%95%E8%AF%B4%E6%98%8E)
这种方式比传统用openwrt的作为旁路由的指定网关的方案,或者only openwrt的方案更加稳定,速度更好。 `缺点是 网络top看起来有一些复杂,非开箱即用`
但是因为大家喜闻乐见的分流规则数据可能几万条,在ikuai上维护更新比较麻烦,这个工具就是为了自动从订阅地址更新爱快的分流规则的域名分流和运营商分流。
> 如有问题或建议都可以提[issues](https://github.com/joyanhui/ikuai-bypass/issues),我会尽快处理。给个star我会很开心。
## 分流模式简单说明
#### 分流模式简单说明
通常是爱快+openwrt的双路由方式,ikuai可以是物理机也可以是虚拟机。openwrt同样可以是物理机也可以是虚拟机,也可以是lxc/docker也可以部署到爱快内。
ikuai需要分配3个网口(分别绑定到wan1 wan2 lan1),openwrt需要2个(wan和lan)。可以是物理网卡也可以是虚拟网卡。
<details>
Expand All @@ -22,7 +26,10 @@ ikuai需要分配3个网口(分别绑定到wan1 wan2 lan1),openwrt需要2

## 参数说明
- `-c` : 配置文件路径 默认为`config.yml` 可用相对路径或者绝对路径
- `-m` : 是否启用ip分组和下一跳网关模式,默认为0 不启用,1为启用 v2.0以后版本有效
- `-m` : 是否启用ip分组和下一跳网关模式(端口分流)v2.0以后版本有效
- `ispdomain` : 使用isp和域名分流功能(默认,为了兼容v1.x版本)
- `ipgroup` : 使用ip分组和下一跳网关模式(端口分流)
- `ii` : 同时使用 上面两种模式
- `-r` : 运行模式 默认为`cron`
- `cron` : 先运行一次 而后等待计划任务触发
- `nocron``once``1`: 忽略配置文件的cron定时配置配置 运行一次然后就退出结束
Expand All @@ -36,9 +43,11 @@ ikuai需要分配3个网口(分别绑定到wan1 wan2 lan1),openwrt需要2
- `-login` : ikuai登陆地址和账户密码,优先级比配置文件的优先级更高。格式: `http://10.1.1.1,admin,password` 为空则使用配置文件内地址

## 更新日志
- 2024-05-26 命令行参数增加-login参数,可以覆盖配置文件内的爱快地址和用户名密码
- 2024-03-23 增加域名分流规则导出为爱快兼容的可导入的txt文件 [[5#2016320900]](https://github.com/joyanhui/ikuai-bypass/issues/5#issuecomment-2016320900)
- 2024-03-23 尝试修复列表太多导致爱快处理超时的问题 [[#5]](https://github.com/joyanhui/ikuai-bypass/issues/5)
- 2024-05-26 修复OLOrz996分支里端口分流规则模式无法删除的bug
- 2024-05-26 合并ztc1997的ip分组和下一跳网关功能[[#7]](https://github.com/joyanhui/ikuai-bypass/issues/7) 增加了 `-m`参数
- 2024-05-26 命令行参数增加-login参数,可以覆盖配置文件内的爱快地址和用户名密码
- 2024-03-23 增加域名分流规则导出为爱快兼容的可导入的txt文件 [[5#2016320900]](https://github.com/joyanhui/ikuai-bypass/issues/5#issuecomment-2016320900)
- 2024-03-23 尝试修复列表太多导致爱快处理超时的问题 [[#5]](https://github.com/joyanhui/ikuai-bypass/issues/5)
- 2024-03-07 openwrt服务安装脚本增加无代理环境安装
- 2024-02-25 增加去广告功能演示规则 [[参考]](https://github.com/joyanhui/ikuai-bypass/blob/main/config_example.yml)
- 2024-02-7 添加一个openwrt下开机自动运行 [[参考脚本]](https://github.com/joyanhui/ikuai-bypass/blob/main/script-example/AddOpenwrtService.sh)
Expand All @@ -47,7 +56,6 @@ ikuai需要分配3个网口(分别绑定到wan1 wan2 lan1),openwrt需要2
- 2024-02-1 清理模式增加附加参数`-tag` 可以清理全部备注名包含`IKUAI_BYPASS`的分流规则,或者指定备注名全程或者后缀名的分流规则
- 旧的更新记录没啥价值也未单独记,小工具代码简单,请参考commit记录
## todo list
- ip分组和下一跳网关[[#7]](https://github.com/joyanhui/ikuai-bypass/issues/7)
- 在性能受限制的爱快上域名分流过多导致爱快接口超时,进一步导致ikuai-bypass出错的bug [[#5]](https://github.com/joyanhui/ikuai-bypass/issues/5)
## 简要使用说明
从 Releases [[下载]](https://github.com/joyanhui/ikuai-bypass/releases) 解压后得到一个可执行文件`ikuai-bypass`和一个通用配置文件 `config.yml` [[参考]](https://github.com/joyanhui/ikuai-bypass/blob/main/config_example.yml)
Expand Down
2 changes: 1 addition & 1 deletion api/stream-ipport.go → api/stream_ipport.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (i *IKuai) DelIKuaiBypassStreamIpPort() (err error) {
return
}
id := strings.Join(ids, ",")
err = i.DelStreamDomain(id)
err = i.DelStreamIpPort(id)
if err != nil {
return
}
Expand Down
20 changes: 10 additions & 10 deletions config_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ ip-group: # IP分组 和端口分流配合使用
stream-ipport: # 端口分流,与IP分组组合使用
- type: 0 # 分流方式:0-外网线路,1-下一跳网关
interface: wan2 # 分流线路
src-addr: 192.168.1.100-192.168.1.250 # 分流的源地址
src-addr: 10.1.1.10-10.1.1.254 # 分流的源地址
## 域名列表网址,每行一个,超过1000行会自动分为多个
ip-group: 国内 # 前面填写的IP分组名称,多个用逗号隔开
- type: 1 # 分流方式:0-外网线路,1-下一跳网关
nexthop: 192.168.1.2 # 下一跳网关
src-addr: 192.168.1.100-192.168.1.250
nexthop: 10.1.1.2 # 下一跳网关
src-addr: 10.1.1.10-10.1.1.254
ip-group: Telegram

custom-isp: # 自定义运营商 IP分流
Expand Down Expand Up @@ -50,38 +50,38 @@ custom-isp: # 自定义运营商 IP分流

stream-domain: # 域名分流 可选功能,优先级比ip分流高
#- interface: wan2 # 分流线路
# src-addr: 10.1.1.2-10.1.1.254 # 分流的源地址 多ip段用“,”分开 参考 https://github.com/joyanhui/ikuai-bypass/issues/1#issuecomment-1892763993
# src-addr: 10.1.1.10-10.1.1.254 # 分流的源地址 多ip段用“,”分开 参考 https://github.com/joyanhui/ikuai-bypass/issues/1#issuecomment-1892763993
# ## 域名列表网址,每行一个,超过1000行会自动分为多个
# url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/greatfire.txt
# 下面是强制走wan2的
- interface: wan2
src-addr: 10.1.1.2-10.1.1.254
src-addr: 10.1.1.10-10.1.1.254
url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt
tag: gfw
- interface: wan2
src-addr: 10.1.1.2-10.1.1.254
src-addr: 10.1.1.10-10.1.1.254
# 作者自己维护的自定义的域名列表 强制走代理的域名
url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/joyanhui/ikuai-bypass/main/private/bypass-domain-list.txt
tag: private_bypass
# 下面是自动走wan1直连的,
- interface: wan1
src-addr: 10.1.1.2-10.1.1.254
src-addr: 10.1.1.10-10.1.1.254
# 作者自己维护的自定义的域名列表 主要存放github的镜像网站等国内可以直连的镜像或其他类型域名
url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/joyanhui/ikuai-bypass/main/private/direct-domain-list.txt
tag: private_direct
#- interface: wan1
# src-addr: 10.1.1.2-10.1.1.254
# src-addr: 10.1.1.10-10.1.1.254
# china-list 网址列表较大,不建议启用,在部分ikuai设备上可能会导致维护的时候超时出错。
# url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/china-list.txt
# tag: cn
#- interface: wan1
# src-addr: 10.1.1.2-10.1.1.254
# src-addr: 10.1.1.10-10.1.1.254
# url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt
# tag: apple
# 下面是去广告的
# todo 以后会使用爱快的域名黑名单模式来实现广告过滤,暂时用线路分流功能屏蔽
# wan99是一个不可用或者不通的线路。因为reject-list网址列表较大,如爱快性能不佳不建议启用。
#- interface: wan99
# src-addr: 10.1.1.2-10.1.1.254
# src-addr: 10.1.1.10-10.1.1.254
# url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/reject-list.txt
# tag: adFilter
4 changes: 3 additions & 1 deletion dev_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ go run *.go -r 1 -c /home/yh/workspace/ikuai-bypass/config_example.yml -login



go run *.go -r 1 -m 1 -c /home/yh/workspace/ikuai-bypass/config_example.yml -login http://10.1.1.1,admin,123
go run *.go -r 1 -m ipgroup -c /home/yh/workspace/ikuai-bypass/config_example.yml -login http://10.1.1.1,admin,123


go run *.go -r clean -c /home/yh/workspace/ikuai-bypass/config_example.yml -login http://10.1.1.1,admin,123

git tag -d v2.0.0-beta1
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ func main() {
}

func update() {
if *isAcIpgroup == "1" {
switch *isAcIpgroup {
case "ispdomain":
log.Println("启动 ... 自定义isp和域名分流模式 模式")
updateIspRule()
case "ipgroup":
log.Println("启动 ... ip分组和下一条网关模式")
updateIpgroup()
} else {
case "ii":
log.Println("启动 ... 自定义isp和域名分流模式 模式")
log.Println("启动 ... ip分组和下一条网关模式")

updateIspRule()
updateIpgroup()
}

}
42 changes: 16 additions & 26 deletions runModeClean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,16 @@ package main

import (
"log"

"github.com/joyanhui/ikuai-bypass/api"
"github.com/joyanhui/ikuai-bypass/router"
)

// 清理旧分流规则
func clean() {
err := readConf(*confPath)
iKuai, err := loginToIkuai()
if err != nil {
log.Println("更新配置文件失败:", err)
log.Println("登录爱快失败:", err)
return
}

baseurl := conf.IkuaiURL
if baseurl == "" {
gateway, err := router.GetGateway()
if err != nil {
log.Println("获取默认网关失败:", err)
return
}
baseurl = "http://" + gateway
log.Println("使用默认网关地址:", baseurl)
}

iKuai := api.NewIKuai(baseurl)

err = iKuai.Login(conf.Username, conf.Password)
if err != nil {
log.Println("ikuai 登陆失败:", baseurl, err)
return
} else {
log.Println("ikuai 登录成功", baseurl)
}
//删除旧的自定义运营商
err = iKuai.DelCustomIspAll(*cleanTag)
if err != nil {
Expand All @@ -49,5 +26,18 @@ func clean() {
} else {
log.Println("移除旧的域名分流成功 tag:" + *cleanTag)
}

//删除旧的ip组
err = iKuai.DelIKuaiBypassIpGroup()
if err != nil {
log.Println("移除旧的IP分组失败:", err)
} else {
log.Println("移除旧的IP分组成功")
}
//删除端口分流规则
err = iKuai.DelIKuaiBypassStreamIpPort()
if err != nil {
log.Println("移除旧的端口分流失败:", err)
} else {
log.Println("移除旧的端口分流成功")
}
}

0 comments on commit 3a1d575

Please sign in to comment.