mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-07-06 17:14:07 +00:00
Added sync feature
This commit is contained in:
21
lib.py
21
lib.py
@ -8,10 +8,9 @@ logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
datefmt='%d-%m-%Y %H:%M:%S')
|
||||
|
||||
CFG_PATH = '/usr/local/etc/outfleet/config.yaml'
|
||||
|
||||
|
||||
class ServerDict(TypedDict):
|
||||
server_id: str
|
||||
name: str
|
||||
url: str
|
||||
cert: str
|
||||
@ -30,9 +29,12 @@ class Server:
|
||||
url: str,
|
||||
cert: str,
|
||||
comment: str,
|
||||
# read from config. not the same as real server id you can get from api
|
||||
local_server_id: str,
|
||||
):
|
||||
self.client = OutlineVPN(api_url=url, cert_sha256=cert)
|
||||
self.data: ServerDict = {
|
||||
'local_server_id': local_server_id,
|
||||
'name': self.client.get_server_information()["name"],
|
||||
'url': url,
|
||||
'cert': cert,
|
||||
@ -49,8 +51,21 @@ class Server:
|
||||
|
||||
def info(self) -> ServerDict:
|
||||
return self.data
|
||||
|
||||
def check_client(self, name):
|
||||
# Looking for any users with provided name. len(result) != 1 is a problem.
|
||||
result = []
|
||||
for key in self.client.get_keys():
|
||||
if key.name == name:
|
||||
result.append(name)
|
||||
self.log.info(f"check_client found client `{name}` config is correct.")
|
||||
if len(result) != 1:
|
||||
self.log.warning(f"check_client found client `{name}` inconsistent. Found {len(result)} keys.")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def apply_config(self, config):
|
||||
def apply_config(self, config, CFG_PATH):
|
||||
if config.get("name"):
|
||||
self.client.set_server_name(config.get("name"))
|
||||
self.log.info("Changed %s name to '%s'", self.data["server_id"], config.get("name"))
|
||||
|
Reference in New Issue
Block a user