Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added disconnect_client method #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion openvpn_api/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import re
import socket
from enum import Enum
from typing import Optional, Generator
from typing import Optional, Generator, Union

import openvpn_status
from openvpn_status.models import Status
from openvpn_status.utils import PeerAddress

from openvpn_api.models.state import State
from openvpn_api.models.stats import ServerStats
Expand Down Expand Up @@ -192,3 +193,17 @@ def get_status(self) -> Status:
"""
raw = self.send_command("status 1")
return openvpn_status.parse_status(raw)

def disconnect_client(self, client: Union[PeerAddress, str]) -> None:
"""Disconnect a given client from VPN
"""
if isinstance(client, PeerAddress):
host = client.host.compressed
port = client.port
command = f"kill {host}:{port}"
self.send_command(command)
elif isinstance(client, str):
command = f"client-kill {client}"
self.send_command(command)
else:
raise ValueError(f"Invalid value {client} for client.")