Skip to content

Commit

Permalink
Merge branch 'develop' for version 0.4.0.
Browse files Browse the repository at this point in the history
0.4.0 with http and https support.
  • Loading branch information
genshen committed Sep 1, 2019
2 parents cc1aa41 + 904d0d4 commit d5934bc
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 45 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
PACKAGE=github.com/genshen/wssocks-plugin-ustb/wssocks-ustb

.PHONY: clean all

# wssocks-ustb:
# go build -o wssocks-ustb

all: wssocks-ustb-linux-amd64 wssocks-ustb-darwin-amd64 wssocks-ustb-windows-amd64.exe
all: wssocks-ustb-linux-amd64 wssocks-ustb-linux-arm64 wssocks-ustb-darwin-amd64 wssocks-ustb-windows-amd64.exe

wssocks-ustb-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o wssocks-ustb-linux-amd64 ${PACKAGE}

wssocks-ustb-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o wssocks-ustb-linux-arm64 ${PACKAGE}

wssocks-ustb-darwin-amd64:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o wssocks-ustb-darwin-amd64 ${PACKAGE}

Expand All @@ -16,4 +21,4 @@ wssocks-ustb-windows-amd64.exe:


clean:
rm -f wssocks-ustb-linux-amd64 wssocks-ustb-darwin-amd64 wssocks-ustb-windows-amd64.exe
rm -f wssocks-ustb-linux-amd64 wssocks-ustb-linux-arm64 wssocks-ustb-darwin-amd64 wssocks-ustb-windows-amd64.exe
65 changes: 65 additions & 0 deletions docs/zh-cn/README-v0.3.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
> 从校外网络访问USTB校内网络
![wssocks-ustb v0.3.0](https://img.shields.io/badge/wssocks--ustb-v0.3.0-orange.svg)

## 使用示例:服务端
在内网的服务端的主机(如地址为`proxy.gensh.me`的主机)上执行:
```bash
# For instance, listener on port 80.
# And make sure your port has been added to the white list of your firewall.
wssocks server --addr :80
```
例如上面的命令,在服务端监听80端口(或者是别的端口,但client端`remote`选项需要和其相一致)。另外,需要确保你监听的端口已经被添加到主机防火墙的白名单列表中。

see more: https://github.com/genshen/wssocks#server-side.

## 使用示例:客户端
1. 打开命令行,执行如下命令,运行客户端:
> 下面命令中, `wssocks-ustb`可执行程序均指代包含`wssocks-plugin-ustb`插件功能的`wssocks`程序.
```bash
wssocks-ustb client --remote=ws://proxy.gensh.me --vpn-enable --vpn-host=vpn4.ustb.edu.cn --vpn-force-logout --vpn-host-encrypt
```
以上命令通过启用`--vpn-enable`选项启用通过vpn连接校内到网络。
随后, 要求输入vpn的用户名和密码登录`n.ustb.edu.cn`以获取其cookie (用户名和密码也可以在命令中通过`--vpn-usernam``--vpn-password`选项指定)。
此外,客户端默认本地监听地址为`:1080`(即0.0.0.0:1080), 服务器端地址为`ws://proxy.gensh.me`

也可以通过`wssocks-ustb client --help`查看更多参数的使用。 其中, 几个主要命令参数如下:
- `--addr` 指定客户端默认本地监听地址,默认为`:1080`(即0.0.0.0:1080);
- `--remote` 指定服务器端地址;
- `--vpn-enable` 是否开启vpn模式;如不开启vpn模式, 将跳过所有以vpn开头的参数;
- `--vpn-host` vpn服务器主机地址;
- `--vpn-username` 登录vpn的用户名;如不在命令参数中指定,将会以交互的方式获取;
- `--vpn-password` 登录vpn的密码; 如不在命令参数中指定,将会以交互的方式获取(为安全起见,不推荐在命令参数中指定);
- `--vpn-force-logout` 如果账号已经在其他设备上登录,强制退出其他设备上的账号;
- `--vpn-host-encrypt` 使用 aes 算法加密代理服务器主机名,默认启用;

2. 设置代理
使用socks代理客户端软件(如mac系统的全局代理功能), 设置代理地址。
![](asserts/mac-proxy.png)
在mac中,勾选**socks代理**选项框, 并填入代理服务器的地址及端口(即wssocks客户端本地监听地址及端口),保存生效。
如果你使用的是windows, 可以使用[Proxifier](https://www.proxifier.com/)软件。
(下图proxifier界面来自于 www.proxifier.com , 以展示添加代理方法。使用wssocks时,图中各个字段(如地址和端口)和选项会有区别。)
![proxifier](https://www.proxifier.com/screenshots/proxy.png)

3. 访问网页
直接在浏览器地址栏输入对应的地址即可访问,即可访问校内网络,不用任何特殊设置。

4. ssh连接(仅macOS)
```bash
ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p' ssh.hpc.gensh.me
```
![](asserts/ssh-example.png)
windows和linux中可直接使用类似的`ssh ssh.hpc.gensh.me`命令。

5. git 命令(仅macOS)
```bash
GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p' " git clone repo_address
```
windows和linux中可直接使用类似的`git clone repo_address`命令。

6. 其他终端操作(仅macOS)
```bash
export all_proxy=socks5://127.0.0.1:1080
git clone repo_address # git clone, 效果同 7.
ssh ssh.hpc.gensh.me # ssh 连接, 效果同6.
```
67 changes: 50 additions & 17 deletions docs/zh-cn/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
> 从校外网络访问USTB校内网络
![wssocks-ustb v0.3.0](https://img.shields.io/badge/wssocks--ustb-v0.3.0-orange.svg)
![wssocks-ustb v0.4.0](https://img.shields.io/badge/wssocks--ustb-v0.4.0-orange.svg)

## 使用示例:服务端
在内网的服务端的主机(如地址为`proxy.gensh.me`的主机)上执行:
Expand All @@ -17,7 +17,7 @@
1. 打开命令行,执行如下命令,运行客户端:
> 下面命令中, `wssocks-ustb`可执行程序均指代包含`wssocks-plugin-ustb`插件功能的`wssocks`程序.
```bash
wssocks-ustb client --remote=ws://proxy.gensh.me --vpn-enable --vpn-host=vpn4.ustb.edu.cn --vpn-force-logout --vpn-host-encrypt
wssocks-ustb client --remote=ws://proxy.gensh.me --http -http-addr=:1086 --vpn-enable --vpn-host=vpn4.ustb.edu.cn --vpn-force-logout --vpn-host-encrypt
```
以上命令通过启用`--vpn-enable`选项启用通过vpn连接校内到网络。
随后, 要求输入vpn的用户名和密码登录`n.ustb.edu.cn`以获取其cookie (用户名和密码也可以在命令中通过`--vpn-usernam``--vpn-password`选项指定)。
Expand All @@ -26,40 +26,73 @@
也可以通过`wssocks-ustb client --help`查看更多参数的使用。 其中, 几个主要命令参数如下:
- `--addr` 指定客户端默认本地监听地址,默认为`:1080`(即0.0.0.0:1080);
- `--remote` 指定服务器端地址;
- `--http` 启用 http 和 https 代理
- `--http-addr` 若启用 http 和 https 代理,该选项指定http代理的本地监听地址及端口(仅http代理地址,https代理的地址和socks5一致),默认 `:1086`
- `--vpn-enable` 是否开启vpn模式;如不开启vpn模式, 将跳过所有以vpn开头的参数;
- `--vpn-host` vpn服务器主机地址;
- `--vpn-username` 登录vpn的用户名;如不在命令参数中指定,将会以交互的方式获取;
- `--vpn-password` 登录vpn的密码; 如不在命令参数中指定,将会以交互的方式获取(为安全起见,不推荐在命令参数中指定);
- `--vpn-force-logout` 如果账号已经在其他设备上登录,强制退出其他设备上的账号;
- `--vpn-host-encrypt` 使用 aes 算法加密代理服务器主机名,默认启用;

2. 设置代理
2. socks5 代理客户端设置
使用socks代理客户端软件(如mac系统的全局代理功能), 设置代理地址。
![](asserts/mac-proxy.png)
在mac中,勾选**socks代理**选项框, 并填入代理服务器的地址及端口(即wssocks客户端本地监听地址及端口),保存生效。
如果你使用的是windows, 可以使用[Proxifier](https://www.proxifier.com/)软件
如果你使用的是windows, 可以使用[Proxifier](https://www.proxifier.com/)软件来设置全局代理
(下图proxifier界面来自于 www.proxifier.com , 以展示添加代理方法。使用wssocks时,图中各个字段(如地址和端口)和选项会有区别。)
![proxifier](https://www.proxifier.com/screenshots/proxy.png)
![proxifier](https://www.proxifier.com/screenshots/proxy.png)
另外,一些软件的设置中也会有socks5代理选项,也可以针对特定软件进行设置,当然这种设置只针对该软件有效。

3. 访问网页
直接在浏览器地址栏输入对应的地址即可访问,即可访问校内网络,不用任何特殊设置。
4. http 与 https 代理客户端设置
在 mac 的系统偏好设置或 windows 的网络设置中,可设置全局的 http 和 https 代理; 部分软件可设置针对该软件有效的http和https代理(如firefox浏览器)。
其中,http代理服务器地址由命令行中的`--http-addr`指定,默认为`:1086`(或`127.0.1.0:1086`),https 代理服务器地址和socks5代理服务器地址一致。

4. ssh连接(仅macOS)
5. 访问网页
如果你已经设置好了 http、 https 代理,或者设置了 socks5 代理,可直接在浏览器地址栏输入对应的地址即可访问,不用任何特殊设置。

6. ssh连接(仅macOS)
```bash
ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p' ssh.hpc.gensh.me
```
![](asserts/ssh-example.png)
windows和linux中可直接使用类似的`ssh ssh.hpc.gensh.me`命令。
windows和linux中可直接使用类似的`ssh ssh.hpcer.dev`命令。

7. git 命令代理
- macOS
```bash
GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p' " git clone repo_address
```
- 通用设置(macOS、windows、linux)
设置 http(s) 代理:
```bash
git config --global http.proxy http://127.0.0.1:1086
git config --global https.proxy http://127.0.0.1:1080
```
设置 socks5 代理:
```bash
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
```
Git 取消代理设置:
```bash
git config --global --unset http.proxy
git config --global --unset https.proxy
```
具体可参考 https://git-scm.com/docs/git-config.

5. git 命令(仅macOS)
8. 其他终端操作(macOS、linux)
终端设置 http(s) 代理(只对当前终端有效):
```bash
GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -x 127.0.0.1:1080 %h %p' " git clone repo_address
export http_proxy=http://127.0.0.1:1086
export https_proxy=http://127.0.0.1:1080
```
windows和linux中可直接使用类似的`git clone repo_address`命令。

6. 其他终端操作(仅macOS)
终端设置 socks5 代理(只对当前终端有效):
```bash
export http_proxy=socks5://127.0.0.1:1080
export https_proxy=socks5://127.0.0.1:1080
```
设置终端中的 wget、curl 等都走 socks5 代理(只对当前终端有效):
```bash
export all_proxy=socks5://127.0.0.1:1080
git clone repo_address # git clone, 效果同 7.
ssh ssh.hpc.gensh.me # ssh 连接, 效果同6.
export ALL_PROXY=socks5://127.0.0.1:1080
```
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.12

require (
github.com/genshen/cmds v0.0.0-20190410131841-986519260a65
github.com/genshen/wssocks v0.2.1
github.com/gorilla/websocket v1.4.0
github.com/genshen/wssocks v0.3.0
github.com/gorilla/websocket v1.4.1
github.com/sirupsen/logrus v1.4.2
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
)
21 changes: 7 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/genshen/cmds v0.0.0-20190410131841-986519260a65 h1:RYKhlk6k5qpQBZVaSi+azOINxxJRujYMGHVAdMstw+o=
github.com/genshen/cmds v0.0.0-20190410131841-986519260a65/go.mod h1:Uo2P6VGNS7t++sjm8vO2AqK/AB2v/favOgOZB984Z3o=
github.com/genshen/wssocks v0.2.1 h1:t9mxkZkor+Ov+tDPmtDZErqZck8PfovR2VP4YVcu2a0=
github.com/genshen/wssocks v0.2.1/go.mod h1:orUdoo8chhH0NNlnvs6eZ7RT0r+qnd3dht3vpN02vYQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/genshen/wssocks v0.3.0 h1:AZwaE0yPU2YAIBLsj0ZfAIVdnBOhZFgesbev3rSInRc=
github.com/genshen/wssocks v0.3.0/go.mod h1:300BjgkBxJxQUXHZ6sPKrA2P+RZ0LJ3mlFIu2M9TbWo=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/segmentio/ksuid v1.0.2 h1:9yBfKyw4ECGTdALaF09Snw3sLJmYIX6AbPJrAy6MrDc=
github.com/segmentio/ksuid v1.0.2/go.mod h1:BXuJDr2byAiHuQaQtSKoXh1J0YmUDurywOXgB2w+OSU=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
32 changes: 32 additions & 0 deletions plugins/ver/version_plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ver

import (
"errors"
"github.com/genshen/wssocks/wss"
log "github.com/sirupsen/logrus"
)

type PluginVersionNeg struct{}

func (v *PluginVersionNeg) OnServerVersion(version wss.VersionNeg) error {
log.WithFields(log.Fields{
"compatible version code": version.CompVersion,
"version code": version.VersionCode,
"wssocks version": version.Version,
}).Info("server version")

if version.CompVersion > wss.VersionCode || wss.VersionCode > version.VersionCode {
log.WithFields(log.Fields{
"version code": wss.VersionCode,
"wssocks version": wss.CoreVersion,
}).Info("client version")
return errors.New("incompatible protocol version of client and server")
}
if version.Version != wss.CoreVersion {
log.WithFields(log.Fields{
"client wssocks version": wss.CoreVersion,
"server wssocks version": version.Version,
}).Warning("different versions of client and server wssocks.")
}
return nil
}
2 changes: 1 addition & 1 deletion vpn_plugin/auto_login.go → plugins/vpn/auto_login.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"regexp"
Expand Down
2 changes: 1 addition & 1 deletion vpn_plugin/host_encrypt.go → plugins/vpn/host_encrypt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"crypto/aes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"encoding/hex"
Expand Down
2 changes: 1 addition & 1 deletion vpn_plugin/vpn.go → plugins/vpn/vpn.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion vpn_plugin/vpn_test.go → plugins/vpn/vpn_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vpn_plugin
package vpn

import (
"net/url"
Expand Down
7 changes: 5 additions & 2 deletions wssocks-ustb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package main

import (
"github.com/genshen/cmds"
"github.com/genshen/wssocks-plugin-ustb/vpn_plugin"
"github.com/genshen/wssocks-plugin-ustb/plugins/ver"
"github.com/genshen/wssocks-plugin-ustb/plugins/vpn"
"github.com/genshen/wssocks/client"
_ "github.com/genshen/wssocks/server"
log "github.com/sirupsen/logrus"
Expand All @@ -12,8 +13,10 @@ import (

// initialize USTB vpn (n.ustb.edu.cn) plugin
func init() {
vpn := vpn_plugin.NewUstbVpn()
vpn := vpn.NewUstbVpn()
ver := ver.PluginVersionNeg{}
client.AddPluginRedirect(vpn)
client.AddPluginVersion(&ver)
}

func main() {
Expand Down
3 changes: 2 additions & 1 deletion wssocks-ustb/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/genshen/wssocks/wss"
)

const VERSION = "0.3.0"
const VERSION = "0.4.0"

var versionCommand = &cmds.Command{
Name: "version",
Expand All @@ -34,6 +34,7 @@ func (v *version) PreRun() error {
func (v *version) Run() error {
fmt.Printf("version\t %s.\n", VERSION)
fmt.Printf("protocol version\t %d\n", wss.VersionCode)
fmt.Printf("wssocks version(core version)\t %s\n", wss.CoreVersion)
fmt.Println("This is a socks5 proxy which allows you to visit internal network in USTB.")
fmt.Println("github https://github.com/genshen/wssocks-plugin-ustb")
fmt.Println("based on https://github.com/genshen/wssocks")
Expand Down

0 comments on commit d5934bc

Please sign in to comment.