Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
attr0 committed May 1, 2022
0 parents commit 4273a42
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:latest

WORKDIR /

# install soga
COPY install_soga.sh /install_soga.sh
RUN /bin/sh /install_soga.sh

# install software
RUN true \
# install openvpn
&& apk add --no-cache openvpn net-tools openresolv openrc tzdata bash \
# clean cache
&& rm -rf /var/cache/apk/*

# copy start script
COPY start.sh /start.sh
RUN chmod +x /start.sh

ENTRYPOINT [ \
"/bin/sh", "-c", \
"cd / && /usr/sbin/openvpn --config vpn.ovpn --script-security 2 --up /start.sh" \
]
2 changes: 2 additions & 0 deletions build_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
docker build --force-rm -t openvpn-soga .
93 changes: 93 additions & 0 deletions install_soga.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Reference: https://github.com/vaxilu/soga/blob/master/install.sh

red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'

cur_dir=$(pwd)


arch=$(arch)

if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
arch="amd64"
elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
arch="arm64"
else
arch="amd64"
echo -e "${red}检测架构失败,使用默认架构: ${arch}${plain}"
fi

echo "架构: ${arch}"


if [ "$(getconf WORD_BIT)" != '32' ] && [ "$(getconf LONG_BIT)" != '64' ] ; then
echo "本软件不支持 32 位系统(x86),请使用 64 位系统(x86_64),如果检测有误,请联系作者"
exit 2
fi


install_base() {
apk update
apk add --no-cache wget curl tar socat
}


install_soga() {
cd /usr/local/
if [[ -e /usr/local/soga/ ]]; then
rm /usr/local/soga/ -rf
fi

if [ $# == 0 ] ;then
last_version=$(curl -Ls "https://api.github.com/repos/vaxilu/soga/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ ! -n "$last_version" ]]; then
echo -e "${red}检测 soga 版本失败,可能是超出 Github API 限制,请稍后再试,或手动指定 soga 版本安装${plain}"
exit 1
fi
echo -e "检测到 soga 最新版本:${last_version},开始安装"
wget -N --no-check-certificate -O /usr/local/soga.tar.gz https://github.com/vaxilu/soga/releases/download/${last_version}/soga-linux-${arch}.tar.gz
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 soga 失败,请确保你的服务器能够下载 Github 的文件${plain}"
exit 1
fi
else
last_version=$1
url="https://github.com/vaxilu/soga/releases/download/${last_version}/soga-linux-${arch}.tar.gz"
echo -e "开始安装 soga v$1"
wget -N --no-check-certificate -O /usr/local/soga.tar.gz ${url}
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 soga v$1 失败,请确保此版本存在${plain}"
exit 1
fi
fi

tar zxvf soga.tar.gz
rm soga.tar.gz -f
cd soga
chmod +x soga
mkdir /etc/soga/ -p
echo -e "${green}soga v${last_version}${plain} 安装完成"
cp soga.conf /etc/soga/

if [[ ! -f /etc/soga/blockList ]]; then
cp blockList /etc/soga/
fi
if [[ ! -f /etc/soga/dns.yml ]]; then
cp dns.yml /etc/soga/
fi
if [[ ! -f /etc/soga/routes.toml ]]; then
cp routes.toml /etc/soga/
fi
curl -o /usr/bin/soga -Ls https://raw.githubusercontent.com/vaxilu/soga/master/soga.sh
chmod +x /usr/bin/soga
curl -o /usr/bin/soga-tool -Ls https://raw.githubusercontent.com/vaxilu/soga/master/soga-tool-${arch}
chmod +x /usr/bin/soga-tool
}


echo -e "${green}开始安装 soga${plain}"
install_base
install_soga $1
echo -e "${green}安装结束 soga${plain}"
22 changes: 22 additions & 0 deletions node-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"
services:
node-example:
# image
image: openvpn-soga
restart: unless-stopped
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
# configuration
container_name: node-example
ports:
- 49999:49999
volumes:
- ./vpn.ovpn:/vpn.ovpn
- ./vpn.auth:/vpn.auth
- ./soga.conf:/etc/soga/soga.conf
#- ./ssl.key:/ssl.key
#- ./ssl.pem:/ssl.pem
#- ./routes.yml:/etc/soga/routes.yml
#- ./dns.yml:/etc/soga/dns.yml
52 changes: 52 additions & 0 deletions node-example/soga.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 基础配置
type=sspanel-uim
server_type=v2ray
node_id=
soga_key=

# webapi 或 db 对接任选一个
api=webapi

# webapi 对接信息
webapi_url=
webapi_key=

# db 对接信息
db_host=db.domain.com
db_port=3306
db_name=
db_user=root
db_password=

# 手动证书配置
cert_file=/ssl.pem
key_file=/ssl.key

# dns 配置
default_dns=
dns_cache_time=10
dns_strategy=ipv4_first

# v2ray 特殊配置
v2ray_reduce_memory=false
vless=false
vless_flow=

# proxy protocol 中转配置
proxy_protocol=true

# 全局限制用户 IP 数配置
redis_enable=false
redis_addr=
redis_password=
redis_db=0
conn_limit_expiry=60

# 其它杂项
user_conn_limit=0
user_speed_limit=0
node_speed_limit=0
check_interval=60
force_close_ssl=
forbidden_bit_torrent=true
log_level=info
2 changes: 2 additions & 0 deletions node-example/vpn.auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
abcabc
123123
43 changes: 43 additions & 0 deletions node-example/vpn.ovpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
client
dev tun
proto udp
remote node port
resolv-retry infinite
remote-random
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
persist-key
persist-tun
ping 15
ping-restart 0
ping-timer-rem
reneg-sec 0

remote-cert-tls server

auth-user-pass /vpn.auth

#comp-lzo
verb 3
pull
fast-io
cipher AES-256-CBC

auth SHA512

<ca>
-----BEGIN CERTIFICATE-----
EXAMPLE CERT
-----END CERTIFICATE-----
</ca>
key-direction 1
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
EXAMPLE KEY
-----END OpenVPN Static key V1-----
</tls-auth>
145 changes: 145 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# OpenVPN to v2ray Node

Convert OpenVPN to a v2ray node based on docker. Use [soga](https://github.com/vaxilu/soga) as the v2ray backend.



# Usage

## Environment Requirement

- Docker
- Docker Compose



Please prepare them yourself and clone this project into your disk

```bash
git clone https://github.com/attr0/openvpn2soga.git.git openvpn2soga
cd openvpn2soga
```



## Build Image

This will generate a image including the latest soga and openvpn

```bash
chmod +x ./build_container.sh
./build_container.sh
```



The image is called `openvpn-soga`. Use the following command to see.

```
docker image ls
```



## Configuration

**One folder means one node.**

Please copy node-example to your-node.

```bash
cp node-example <your-node>
```



There are four configuration

- `soga.conf`

soga configuration file, please change to yours



- `vpn.ovpn`

openvpn configuration file, please change to yours

If password auth is required, change

```
auth-user-pass
```
To
```
auth-user-pass /vpn.auth
```
- `vpn.auth`
auth file for openvpn. If password auth is required, pleace change it to
```
your_username
your_password
```
- `docker-compose.yml`
controls the name of the container, ports, and file
- change container name to yours (must be unique)
- change ports as you desired (must follow the v2ray configuration)
- change file map if you wish
> !DO NOT CHANGE THE FILE PATH IN THE CONTAINER SIDE (RIGHT OF THE COLON)
## Start
```bash
docker-compose up -d
docker logs <your_container_name>
```

Start up the container, and print the log



In case you need to change your configuration

```bash
docker restart <your_container_name>
```



## Update

1. Rebuild the image

```bash
./build_container.sh
```

2. Recompose

```bash
cd <your_node>
docker-compose up -d
```





Enjoy it.
Loading

0 comments on commit 4273a42

Please sign in to comment.