fix init issue
This commit is contained in:
parent
85c5d460a2
commit
6b8ecd875c
@ -31,7 +31,7 @@ router = APIRouter()
|
|||||||
200: {"description": "OK"},
|
200: {"description": "OK"},
|
||||||
},
|
},
|
||||||
tags=["client"],
|
tags=["client"],
|
||||||
summary="List all clients",
|
summary="List all clients and download vpn file with specific name",
|
||||||
response_model_by_alias=True,
|
response_model_by_alias=True,
|
||||||
)
|
)
|
||||||
async def get_client(
|
async def get_client(
|
||||||
@ -40,8 +40,8 @@ async def get_client(
|
|||||||
try:
|
try:
|
||||||
file_path = command.install_dir
|
file_path = command.install_dir
|
||||||
if client_name:
|
if client_name:
|
||||||
client_name = f"{client_name.strip('.ovpn')}.ovpn"
|
client_name = client_name.strip('.ovpn') + ".ovpn"
|
||||||
file_location = file_path + client_name
|
file_location = file_path + "/" + client_name
|
||||||
return FileResponse(file_location, filename=client_name,
|
return FileResponse(file_location, filename=client_name,
|
||||||
media_type="application/octet-stream")
|
media_type="application/octet-stream")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -28,7 +28,7 @@ router = APIRouter()
|
|||||||
200: {"description": "OK"},
|
200: {"description": "OK"},
|
||||||
},
|
},
|
||||||
tags=["openvpn"],
|
tags=["openvpn"],
|
||||||
summary="Get OpenVPN configuration",
|
summary="Get OpenVPN status",
|
||||||
response_model_by_alias=True,
|
response_model_by_alias=True,
|
||||||
)
|
)
|
||||||
async def get_openvpn(
|
async def get_openvpn(
|
||||||
|
|||||||
0
openvpn_ui/bin/openvpn-install.sh
Normal file → Executable file
0
openvpn_ui/bin/openvpn-install.sh
Normal file → Executable file
@ -2,17 +2,35 @@
|
|||||||
|
|
||||||
Simple web UI to manage OpenVPN users.
|
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
|
# 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
|
```commandline
|
||||||
Install python3.10
|
wget -c https://github.com/Song2017/openvpn-install-ui/archive/refs/heads/master.zip
|
||||||
|
unzip master.zip
|
||||||
cd project-path
|
cd openvpn-install-ui-master
|
||||||
pip install -r -i https://mirrors.aliyun.com/pypi/simple/ requirements.txt
|
pip install -r openvpn_ui/requirements.txt
|
||||||
openvpn_ui/bin/run_http_server.sh
|
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
|
http://0.0.0.0:8080/api/docs
|
||||||
```
|
```
|
||||||
|
|
||||||
# develop
|
## develop
|
||||||
|
|
||||||
```commandline
|
```commandline
|
||||||
docker run -it -v /Users/songgs/_git/openvpn-install:/app -p 8080:8080 --cap-add=NET_ADMIN python:3.10.14-bullseye bash
|
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
|
```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
|
# Discard stdin. Needed when running from an one-liner which includes a newline
|
||||||
read -N 999999 -t 0.001
|
read -N 999999 -t 0.001
|
||||||
```
|
```
|
||||||
@ -8,8 +8,7 @@ from typing import Union
|
|||||||
class VpnCommand:
|
class VpnCommand:
|
||||||
@cached_property
|
@cached_property
|
||||||
def install_dir(self) -> str:
|
def install_dir(self) -> str:
|
||||||
return os.path.dirname(__file__).replace("openvpn-ui/http_server/vpn", "").replace(
|
return os.path.dirname(__file__).rstrip("/vpn")
|
||||||
r"openvpn-ui\\http_server\\vpn", "")
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def install_file(self) -> str:
|
def install_file(self) -> str:
|
||||||
@ -21,14 +20,17 @@ class VpnCommand:
|
|||||||
return f"Please install OpenVPN: {self.install_file}"
|
return f"Please install OpenVPN: {self.install_file}"
|
||||||
|
|
||||||
def install_vpn(self) -> str:
|
def install_vpn(self) -> str:
|
||||||
return self.create_client("default")
|
return self.create_client("init")
|
||||||
|
|
||||||
def create_client(self, name) -> str:
|
def create_client(self, name) -> str:
|
||||||
result = self.install_cmd(name, "1")
|
result = self.install_cmd(name, "1")
|
||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
return result
|
return result
|
||||||
if 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
|
# move vpn file
|
||||||
if os.path.exists(new_client):
|
if os.path.exists(new_client):
|
||||||
shutil.copy(new_client, self.install_dir)
|
shutil.copy(new_client, self.install_dir)
|
||||||
@ -49,7 +51,8 @@ class VpnCommand:
|
|||||||
|
|
||||||
def install_cmd(self, name: str, option: str,
|
def install_cmd(self, name: str, option: str,
|
||||||
file_path="/etc/openvpn/server/server.conf") -> Union[bool, 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"
|
return "Please install OpenVPN"
|
||||||
|
|
||||||
name = name.strip('.ovpn')
|
name = name.strip('.ovpn')
|
||||||
@ -76,4 +79,6 @@ class VpnCommand:
|
|||||||
# 输出脚本执行结果和状态
|
# 输出脚本执行结果和状态
|
||||||
print("shell output: ", new_client, stdout_data, stderr_data,
|
print("shell output: ", new_client, stdout_data, stderr_data,
|
||||||
process.returncode, process.stderr)
|
process.returncode, process.stderr)
|
||||||
|
if self.get_vpn_status(file_path) != "OpenVPN has been installed":
|
||||||
|
return stdout_data
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user