Kaynağa Gözat

rebuild clients

master
Robin Thoni 8 yıl önce
ebeveyn
işleme
b4796c0858
3 değiştirilmiş dosya ile 21 ekleme ve 10 silme
  1. 1
    3
      TODO
  2. 9
    6
      vpngen-cli.py
  3. 11
    1
      vpngen.py

+ 1
- 3
TODO Dosyayı Görüntüle

@@ -1,5 +1,3 @@
1 1
 Remove client
2 2
 
3
-Check if client has benn revoked
4
-
5
-Rebuild client(s) config(s)
3
+Check if client has benn revoked

+ 9
- 6
vpngen-cli.py Dosyayı Görüntüle

@@ -113,12 +113,15 @@ def main():
113 113
         default_variables = config['defaults'].copy()
114 114
         default_variables.update(vpng.get_server_variables(vpn_name))
115 115
 
116
-        res = vpng.rebuild_clients(vpn_name)
117
-        if res == vpngen.VpnGenError.Success:
118
-            print("Clients configurations rebuilt successfully on VPN %s" % vpn_name)
119
-        else:
120
-            eprint("Failed to rebuild clients configuration on VPN %s: %s" % (vpn_name, res))
121
-            exit(1)
116
+        for client_name in vpng.get_client_list(vpn_name):
117
+            variables = default_variables.copy()
118
+            variables.update(vpng.get_client_variables(vpn_name, client_name))
119
+            res = vpng.rebuild_client(vpn_name, client_name, variables)
120
+            if res == vpngen.VpnGenError.Success:
121
+                print("Client %s configuration rebuilt successfully on VPN %s" % (client_name, vpn_name))
122
+            else:
123
+                eprint("Failed to rebuild client %s configuration on VPN %s: %s" % (client_name, vpn_name, res))
124
+                exit(1)
122 125
 
123 126
 
124 127
 main()

+ 11
- 1
vpngen.py Dosyayı Görüntüle

@@ -135,6 +135,17 @@ class VpnGen:
135 135
         with open(self.get_client_variables_path(vpn_name, client_name), "r") as f:
136 136
             return json.load(f)['variables']
137 137
 
138
+    def get_client_list(self, vpn_name):
139
+        base_dir = self.get_base_dir(vpn_name)
140
+        files_paths = glob.glob("%sclients%s*" % (base_dir, os.sep))
141
+        files_names = list(map(lambda file_path: os.path.basename(file_path), files_paths))
142
+
143
+        clients = []
144
+        for file_name in files_names:
145
+            if file_name != 'client.conf' and not file_name.endswith(".tar.bz2"):
146
+                clients.append(file_name[0:len(file_name) - len(vpn_name) - 1])
147
+        return clients
148
+
138 149
     def setup_vars(self, vpn_name, variables):
139 150
         easyrsadir = self.get_easy_rsa_dir(vpn_name)
140 151
 
@@ -283,7 +294,6 @@ class VpnGen:
283 294
         files_names = glob.glob("%s%s*" % (client_dir, os.sep))
284 295
         files_names = list(map(lambda file_path: os.path.basename(file_path), files_names))
285 296
 
286
-
287 297
         call(["tar", "cfj", self.get_client_tarball_path(vpn_name, client_name),
288 298
               "-C", client_dir] + files_names)
289 299
 

Loading…
İptal
Kaydet