1
0
Fork 0
mirror of https://github.com/Nyr/openvpn-install.git synced 2025-04-04 21:23:31 +03:00

fix init issue

This commit is contained in:
Ben Song 2024-05-16 15:40:37 +08:00
parent 85c5d460a2
commit 6b8ecd875c
5 changed files with 40 additions and 17 deletions

View file

@ -31,7 +31,7 @@ router = APIRouter()
200: {"description": "OK"},
},
tags=["client"],
summary="List all clients",
summary="List all clients and download vpn file with specific name",
response_model_by_alias=True,
)
async def get_client(
@ -40,8 +40,8 @@ async def get_client(
try:
file_path = command.install_dir
if client_name:
client_name = f"{client_name.strip('.ovpn')}.ovpn"
file_location = file_path + client_name
client_name = client_name.strip('.ovpn') + ".ovpn"
file_location = file_path + "/" + client_name
return FileResponse(file_location, filename=client_name,
media_type="application/octet-stream")
else:

View file

@ -28,7 +28,7 @@ router = APIRouter()
200: {"description": "OK"},
},
tags=["openvpn"],
summary="Get OpenVPN configuration",
summary="Get OpenVPN status",
response_model_by_alias=True,
)
async def get_openvpn(

0
openvpn_ui/bin/openvpn-install.sh Normal file → Executable file
View file

View file

@ -2,17 +2,35 @@
Simple web UI to manage OpenVPN users.
swagger ui <> python <> [openvpn-install.sh](https://github.com/Nyr/openvpn-install/blob/master/README.md)
swagger ui <> python <> [openvpn-install.sh](../openvpn-install.sh)
# usage
## prepare python
```
# parepare libs
apt update
apt install wget curl unzip build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev -y
- run server
# install python
wget -c https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
tar -xvf Python-3.10.0.tar.xz
cd Python-3.10.0
sudo ./configure --enable-optimizations
make altinstall # install Python 3.10 into /usr/local/bin
python3.10 --version
# install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
```
## run server
```commandline
Install python3.10
cd project-path
pip install -r -i https://mirrors.aliyun.com/pypi/simple/ requirements.txt
wget -c https://github.com/Song2017/openvpn-install-ui/archive/refs/heads/master.zip
unzip master.zip
cd openvpn-install-ui-master
pip install -r openvpn_ui/requirements.txt
openvpn_ui/bin/run_http_server.sh
```
@ -22,7 +40,7 @@ openvpn_ui/bin/run_http_server.sh
http://0.0.0.0:8080/api/docs
```
# develop
## develop
```commandline
docker run -it -v /Users/songgs/_git/openvpn-install:/app -p 8080:8080 --cap-add=NET_ADMIN python:3.10.14-bullseye bash
@ -32,7 +50,7 @@ sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
```
```commandline
!! comment this line in openvpn-install.sh
!! comment this line in ./bin/openvpn-install.sh
# Discard stdin. Needed when running from an one-liner which includes a newline
read -N 999999 -t 0.001
```

View file

@ -8,8 +8,7 @@ from typing import Union
class VpnCommand:
@cached_property
def install_dir(self) -> str:
return os.path.dirname(__file__).replace("openvpn-ui/http_server/vpn", "").replace(
r"openvpn-ui\\http_server\\vpn", "")
return os.path.dirname(__file__).rstrip("/vpn")
@cached_property
def install_file(self) -> str:
@ -21,14 +20,17 @@ class VpnCommand:
return f"Please install OpenVPN: {self.install_file}"
def install_vpn(self) -> str:
return self.create_client("default")
return self.create_client("init")
def create_client(self, name) -> str:
result = self.install_cmd(name, "1")
if isinstance(result, str):
return result
if result:
new_client = f"~/{name.strip('.ovpn')}.ovpn"
if not name.startswith('/'):
new_client = f"/root/{name.strip('.ovpn')}.ovpn"
else:
new_client = name
# move vpn file
if os.path.exists(new_client):
shutil.copy(new_client, self.install_dir)
@ -49,7 +51,8 @@ class VpnCommand:
def install_cmd(self, name: str, option: str,
file_path="/etc/openvpn/server/server.conf") -> Union[bool, str]:
if self.get_vpn_status(file_path) != "OpenVPN has been installed":
if (self.get_vpn_status(file_path) != "OpenVPN has been installed"
and name != "init"):
return "Please install OpenVPN"
name = name.strip('.ovpn')
@ -76,4 +79,6 @@ class VpnCommand:
# 输出脚本执行结果和状态
print("shell output: ", new_client, stdout_data, stderr_data,
process.returncode, process.stderr)
if self.get_vpn_status(file_path) != "OpenVPN has been installed":
return stdout_data
return True