verify config values being edited
diff --git a/backend/connections.py b/backend/connections.py
index 977974f..903b645 100644
--- a/backend/connections.py
+++ b/backend/connections.py
@@ -55,7 +55,8 @@
# use key (as hostname:port:session-id) to store the created NETCONF session
key = session.host + ":" + str(session.port) + ":" + session.id
- sessions[user.username][key] = session
+ sessions[user.username][key] = {}
+ sessions[user.username][key]['session'] = session
return(json.dumps({'success': True, 'session-key': key}))
@@ -77,7 +78,7 @@
return(json.dumps({'success': False, 'error-msg': 'Invalid session key.'}))
cpblts = []
- for c in sessions[user.username][key].capabilities:
+ for c in sessions[user.username][key]['session'].capabilities:
cpblts.append(c)
return(json.dumps({'success': True, 'capabilities': cpblts}))
@@ -100,9 +101,8 @@
if not key in sessions[user.username]:
return(json.dumps({'success': False, 'error-msg': 'Invalid session key.'}))
- session = sessions[user.username][key]
try:
- data = session.rpcGet()
+ sessions[user.username][key]['data'] = sessions[user.username][key]['session'].rpcGet()
except nc.ReplyError as e:
reply = {'success': False, 'error': []}
for err in e.args[0]:
@@ -110,9 +110,42 @@
return(json.dumps(reply))
if not 'path' in req:
- return(dataInfoRoots(data, True if req['recursive'] == 'true' else False))
+ return(dataInfoRoots(sessions[user.username][key]['data'], True if req['recursive'] == 'true' else False))
else:
- return(dataInfoSubtree(data, req['path'], True if req['recursive'] == 'true' else False))
+ return(dataInfoSubtree(sessions[user.username][key]['data'], req['path'], True if req['recursive'] == 'true' else False))
+
+
+@auth.required()
+def session_checkvalue():
+ session = auth.lookup(request.headers.get('Authorization', None))
+ user = session['user']
+ req = request.args.to_dict()
+
+ if not 'key' in req:
+ return(json.dumps({'success': False, 'error-msg': 'Missing session key.'}))
+ if not 'path' in req:
+ return(json.dumps({'success': False, 'error-msg': 'Missing path to validate value.'}))
+ if not 'value' in req:
+ return(json.dumps({'success': False, 'error-msg': 'Missing value to validate.'}))
+
+ if not user.username in sessions:
+ sessions[user.username] = {}
+
+ key = req['key']
+ if not key in sessions[user.username]:
+ return(json.dumps({'success': False, 'error-msg': 'Invalid session key.'}))
+
+ search = sessions[user.username][key]['data'].find_path(req['path'])
+ if search.number() != 1:
+ return(json.dumps({'success': False, 'error-msg': 'Invalid data path.'}))
+ node = search.data()[0]
+
+ try:
+ node.validate_value(req['value'])
+ except:
+ return(json.dumps({'success': False, 'error-msg': ly.Error().errmsg()}))
+
+ return(json.dumps({'success': True}))
@auth.required()