Browse Source

rebuild clients

master
Robin Thoni 8 years ago
parent
commit
b4796c0858
3 changed files with 21 additions and 10 deletions
  1. 1
    3
      TODO
  2. 9
    6
      vpngen-cli.py
  3. 11
    1
      vpngen.py

+ 1
- 3
TODO View File

1
 Remove client
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 View File

113
         default_variables = config['defaults'].copy()
113
         default_variables = config['defaults'].copy()
114
         default_variables.update(vpng.get_server_variables(vpn_name))
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
 main()
127
 main()

+ 11
- 1
vpngen.py View File

135
         with open(self.get_client_variables_path(vpn_name, client_name), "r") as f:
135
         with open(self.get_client_variables_path(vpn_name, client_name), "r") as f:
136
             return json.load(f)['variables']
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
     def setup_vars(self, vpn_name, variables):
149
     def setup_vars(self, vpn_name, variables):
139
         easyrsadir = self.get_easy_rsa_dir(vpn_name)
150
         easyrsadir = self.get_easy_rsa_dir(vpn_name)
140
 
151
 
283
         files_names = glob.glob("%s%s*" % (client_dir, os.sep))
294
         files_names = glob.glob("%s%s*" % (client_dir, os.sep))
284
         files_names = list(map(lambda file_path: os.path.basename(file_path), files_names))
295
         files_names = list(map(lambda file_path: os.path.basename(file_path), files_names))
285
 
296
 
286
-
287
         call(["tar", "cfj", self.get_client_tarball_path(vpn_name, client_name),
297
         call(["tar", "cfj", self.get_client_tarball_path(vpn_name, client_name),
288
               "-C", client_dir] + files_names)
298
               "-C", client_dir] + files_names)
289
 
299
 

Loading…
Cancel
Save