Sfoglia il codice sorgente

define the route to create a new key and send information

Sven Czarnian 3 anni fa
parent
commit
848d89a918
1 ha cambiato i file con 24 aggiunte e 1 eliminazioni
  1. 24 1
      aman/app.py

+ 24 - 1
aman/app.py

@@ -2,6 +2,7 @@
 
 import json
 import os
+import subprocess
 
 from flask import Flask, Response, request
 from json import JSONEncoder
@@ -31,7 +32,7 @@ aman = AMAN()
 app = Flask('AMAN')
 version = '0.0.0'
 
-with open(os.environ['AMAN_PATH'] + '\\VERSION') as file:
+with open(os.path.join(os.environ['AMAN_PATH'], 'VERSION')) as file:
     version = file.readline()
 
 if __name__ == '__main__':
@@ -47,6 +48,28 @@ def airports():
     data = json.dumps({ 'version' : version, 'airports' : retval }, ensure_ascii=True)
     return Response(data, status=200, mimetype='application/json')
 
+@app.route('/aman/newuser')
+def newUser():
+    toolpath = os.path.join(os.path.join(os.environ['AMAN_PATH'], 'tools'), 'KeyPairCreator.py')
+    serverKeypath = os.path.join(os.path.join(os.path.join(AMAN.findConfigPath(), 'keys'), 'server'), 'server.key')
+    clientKeypath = os.path.join(os.path.join(AMAN.findConfigPath(), 'keys'), 'clients')
+
+    cmd = ['python', toolpath, '--directory=' + clientKeypath, '--publickey=' + serverKeypath]
+
+    stdout = subprocess.check_output(cmd)
+    keys = stdout.splitlines()
+    server = keys[0].decode('ascii')
+    public = keys[1].decode('ascii')
+    private = keys[2].decode('ascii')
+
+    dictionary = {
+        'server' : server,
+        'public' : public,
+        'private' : private,
+    }
+    data = json.dumps(dictionary, ensure_ascii=True)
+    return Response(data, status=200, mimetype='application/json')
+
 @app.route('/aman/configuration/<icao>')
 def configuration(icao):
     airport = aman.findAirport(icao.upper())