Browse Source

merge alias.json into config.json

Karsten Böddeker 6 years ago
parent
commit
f8557cd7be
5 changed files with 36 additions and 50 deletions
  1. 2 7
      README.md
  2. 0 30
      alias.json.example
  3. 30 2
      config.json.example
  4. 2 2
      lib/nodeinfo.py
  5. 2 9
      lib/respondd.py

+ 2 - 7
README.md

@@ -31,13 +31,8 @@ Copy `config.json.example` to `config.json` and change it to match your server c
  * `fastd_socket` (string) (Optional: needed for uplink-flag)
  * `rate_limit` (integer) (Optional: limit incoming requests per minutes)
  * `rate_limit_burst` (integer) (Optional: allow burst requests)
-
-### alias.json
-Aliases to overwrite the returned server data.
-Copy `alias.json.example` to `alias.json` and input e.g. owner information.
-(`cp alias.json.example alias.json`)
-
-The JSON content matches one block of the nodes.json, which is outputted by e.g. the [HopGlass-Server](https://github.com/hopglass/hopglass-server).
+ * `nodeinfo` (array) (Optional: overwrite the returned server data)
+   The JSON content matches one block of the nodes.json, which is outputted by e.g. the [HopGlass-Server](https://github.com/hopglass/hopglass-server).
 
 ### ext-respondd.service
 Register ext-respondd as a systemd service

+ 0 - 30
alias.json.example

@@ -1,30 +0,0 @@
-{
-  "nodeinfo": {
-    "hostname": "Supernode-001",
-    "node_id": "deadcafe1337",
-    "hardware": {
-      "model": "Raspberry Pi 2 B"
-    },
-    "owner": {
-      "contact": "info@example.org"
-    },
-    "software": {
-      "firmware": {
-        "release": "0.42"
-      }
-    },
-    "system": {
-      "site_code": "ffggrz",
-      "role": "gateway"
-    },
-    "location": {
-      "latitude": 89.10727755551,
-      "longitude": 5.00932562351
-    },
-    "pages": [
-      "http://start.ffggrz/",
-      "http://start.ffggrz.de/"
-    ]
-  },
-  "firstseen": "2015-04-12T15:41:01"
-}

+ 30 - 2
config.json.example

@@ -5,6 +5,34 @@
   "mesh-wlan": [ "ibss0", "mesh0" ],
   "fastd_socket": "/var/run/fastd.mesh_vpn.socket",
   "rate_limit": 30,
-  "rate_limit_burst": 10
-}
+  "rate_limit_burst": 10,
 
+  "nodeinfo": {
+    "hostname": "Supernode-001",
+    "node_id": "deadcafe1337",
+    "hardware": {
+      "model": "Raspberry Pi 2 B"
+    },
+    "owner": {
+      "contact": "info@example.org"
+    },
+    "software": {
+      "firmware": {
+        "release": "0.42"
+      }
+    },
+    "system": {
+      "site_code": "ffggrz",
+      "role": "gateway"
+    },
+    "location": {
+      "latitude": 89.10727755551,
+      "longitude": 5.00932562351
+    },
+    "pages": [
+      "http://start.ffggrz/",
+      "http://start.ffggrz.de/"
+    ]
+  },
+  "firstseen": "2015-04-12T15:41:01"
+}

+ 2 - 2
lib/nodeinfo.py

@@ -129,8 +129,8 @@ class Nodeinfo(Respondd):
       except:
         pass
 
-    if 'nodeinfo' in self._aliasOverlay:
-      return lib.helper.merge(ret, self._aliasOverlay['nodeinfo'])
+    if 'nodeinfo' in self._config:
+      return lib.helper.merge(ret, self._config['nodeinfo'])
     else:
       return ret
 

+ 2 - 9
lib/respondd.py

@@ -8,19 +8,12 @@ import lib.helper
 class Respondd:
   def __init__(self, config):
     self._config = config
-    self._aliasOverlay = {}
     self.__cache = {}
     self.__cacheTime = 0
-    try:
-      with open('alias.json', 'r') as fh: # TODO: prevent loading more then once !
-        self._aliasOverlay = json.load(fh)
-    except IOError:
-      print('can\'t load alias.json!')
-      pass
 
   def getNodeID(self):
-    if 'nodeinfo' in self._aliasOverlay and 'node_id' in self._aliasOverlay['nodeinfo']:
-      return self._aliasOverlay['nodeinfo']['node_id']
+    if 'nodeinfo' in self._config and 'node_id' in self._config['nodeinfo']:
+      return self._config['nodeinfo']['node_id']
     else:
       return lib.helper.getInterfaceMAC(self._config['batman']).replace(':', '')