From e3e0c47e2b113b821d2547d87b65bd5fe2c79858 Mon Sep 17 00:00:00 2001 From: mantaohuang Date: Mon, 3 Aug 2020 12:36:29 -0400 Subject: [PATCH] save and load config --- o_manager.py | 14 ++- openvpn.py | 3 + tabler/index.html | 252 +++++----------------------------------------- test.py | 17 +++- 4 files changed, 57 insertions(+), 229 deletions(-) diff --git a/o_manager.py b/o_manager.py index b17ffab..f076df7 100644 --- a/o_manager.py +++ b/o_manager.py @@ -47,6 +47,18 @@ class OManager: self.lb1_pm = ProcessManager(restart_interval=5, loop=self.loop) self.lb2_pm = ProcessManager(restart_interval=5, loop=self.loop) + def load_instance_config(self, instance_config): + """ + [ + ovpn_config + ] + """ + for ovpn_config in instance_config: + self.new_op(ovpn_config) + + def serialize_instance_config(self): + return [i["op"].export_cfg() for i in self.instances] + @property def pids(self): return [self.lb1_pm.pid, self.lb2_pm.pid] @@ -207,7 +219,7 @@ class OManager: if not instance: return instance["op"].start() - instance["weight"] = 1 + instance["weight"] = 0 self.reset_lb() def stop_op(self, idx): diff --git a/openvpn.py b/openvpn.py index e484f1e..6e205b7 100644 --- a/openvpn.py +++ b/openvpn.py @@ -82,6 +82,9 @@ class Openvpn: self.load_cfg(ovpn_config, env_config) def load_cfg(self, ovpn_config, env_config): + self.ovpn_config = ovpn_config + self.env_config = env_config + self.cfg_fp = ovpn_config["cfg_fp"] self.name = ovpn_config["name"] self.additional_cfg = ovpn_config.get("additional_cfg", {}) diff --git a/tabler/index.html b/tabler/index.html index 841c6cf..722235e 100644 --- a/tabler/index.html +++ b/tabler/index.html @@ -13,7 +13,7 @@ - Openvpn Load Balancing Socks5 Server + OLBS Dashboard @@ -37,161 +37,6 @@ -
@@ -200,80 +45,37 @@

- Home + Openvpn Load Balancing Socks5 Server

- - - -
-
-
- - - - - -
-
- 132 Sales -
-
12 waiting payments
-
-
-
-
-
-
-
- - - - - - -
-
- 78 Orders -
-
32 shipped
-
-
-
-
-
-
-
-
-
-
-
-
- 1,352 Members -
-
163 registered today
-
-
-
-
-
+
-
- 132 Comments -
-
16 waiting
+
-
-
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
@@ -344,14 +146,10 @@
-
    -
  • -
  • -
  • -
+
- 2020 +
diff --git a/test.py b/test.py index 3713cb7..4d56212 100644 --- a/test.py +++ b/test.py @@ -4,6 +4,7 @@ import json import argparse import os import subprocess +import logging from o_manager import OManager dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -17,6 +18,15 @@ session_folder = args["session_folder"] interface = args["interface"] om = OManager(session_folder, interface) +root = os.path.dirname(__file__) +instance_config_fp = os.path.join(root, "config/instances.json") + +try: + instance_config = json.load(open(instance_config_fp, "r")) + om.load_instance_config(instance_config) +except Exception as err: + logging.warn(f"Cannot load instances config: {err}") + class MainHandler(tornado.web.RequestHandler): def get(self): @@ -115,7 +125,12 @@ class ClearCacheInstatnceHandler(tornado.web.RequestHandler): om.clear_cache() -root = os.path.dirname(__file__) +class SaveConfig(tornado.web.RequestHandler): + def get(self): + instances = om.serialize_instance_config() + with open(os.path.join(root), instance_config_fp, "w") as f: + f.write(json.dumps(instances)) + self.write("OK") def make_app():