|
@@ -65,7 +65,7 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
|
# /node/<id>.json - node's data
|
|
|
# /node/<id>/field - return specific field from node's data
|
|
|
- m = re.match(r'node/([a-f0-9]{12})(?P<cmd>\.json|/[a-zA-Z0-9_\-]+)$', path)
|
|
|
+ m = re.match(r'node/([a-f0-9]{12})(?P<cmd>\.json|/[a-zA-Z0-9_\-\.]+)$', path)
|
|
|
if m != None:
|
|
|
cmd = m.group('cmd')
|
|
|
if cmd == '.json':
|
|
@@ -263,13 +263,19 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
self.send_error(404, 'No node with id \'' + nodeid + '\' present.')
|
|
|
return
|
|
|
|
|
|
+ return_count = False
|
|
|
+ if field.endswith('.count'):
|
|
|
+ return_count = True
|
|
|
+ field = field[0:-6]
|
|
|
+
|
|
|
if not field in node:
|
|
|
self.send_error(404, 'The node \'' + nodeid + '\' does not have a field named \'' + str(field) + '\'.')
|
|
|
return
|
|
|
|
|
|
value = node[field]
|
|
|
+ if return_count: value = len(value)
|
|
|
|
|
|
- self.send_headers('text/plain' if isinstance(value, basestring) else 'text/json')
|
|
|
+ self.send_headers('text/plain' if isinstance(value, basestring) or isinstance(value, int) else 'text/json')
|
|
|
self.wfile.write(value if isinstance(value, basestring) else json.dumps(value))
|
|
|
|
|
|
def respond_vpn(self, query):
|