Started logging client creation/deletion directly to syslog
This commit is contained in:
parent
4438270e78
commit
5c783d95aa
@ -1,6 +1,7 @@
|
||||
from configparser import ConfigParser
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from syslog import syslog
|
||||
from textwrap import dedent
|
||||
from time import sleep
|
||||
import ipaddress
|
||||
@ -18,11 +19,6 @@ workdir = Path('./work')
|
||||
lockfile = workdir.joinpath('lockfile.lock~')
|
||||
|
||||
|
||||
def log(context_id: str, message) -> None:
|
||||
now = datetime.now()
|
||||
now_string = now.isoformat(' ', 'minutes')
|
||||
print(f'{now_string} - {context_id}: {message}')
|
||||
|
||||
def safe_join(*args) -> Path:
|
||||
'''
|
||||
Similar to flask's own safe_join, but uses Path objects
|
||||
@ -161,6 +157,9 @@ class WireGuard:
|
||||
self.user_name = None
|
||||
self.user_base = None
|
||||
|
||||
def log(self, context_id: str, message) -> None:
|
||||
syslog(f'[{self.tunnel_id}] {context_id}: {message}')
|
||||
|
||||
def set_user(self, user_name: str) -> None:
|
||||
user_base = safe_join(self.configs_base, user_name)
|
||||
if not user_base.exists():
|
||||
@ -272,8 +271,8 @@ class WireGuard:
|
||||
client_pubkey
|
||||
)
|
||||
server_config.write(sf)
|
||||
log(f'{self.user_name}/{config_id}', f'Created new config')
|
||||
log(f'{self.user_name}/{config_id}', f'IP: {client_ip}')
|
||||
self.log(f'{self.user_name}/{config_id}', f'Created new config')
|
||||
self.log(f'{self.user_name}/{config_id}', f'IP: {client_ip}')
|
||||
self.wg_updated = True
|
||||
return client_ip
|
||||
|
||||
@ -316,7 +315,7 @@ class WireGuard:
|
||||
[path.unlink() for path in paths]
|
||||
delete_route(client_ip)
|
||||
|
||||
log(f'{self.user_name}/{config_id}', 'Deleted config')
|
||||
self.log(f'{self.user_name}/{config_id}', 'Deleted config')
|
||||
self.wg_updated = True
|
||||
|
||||
def update(self) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user