finished config editor
parent
1b22a993a0
commit
95750b6b3c
|
@ -27,7 +27,7 @@ config_BP = Blueprint('config_BP', __name__)
|
||||||
@config_BP.route('/config/get')
|
@config_BP.route('/config/get')
|
||||||
def get_all_config():
|
def get_all_config():
|
||||||
'''Simply return all configuration as JSON string'''
|
'''Simply return all configuration as JSON string'''
|
||||||
return Response(json.dumps(config.get_config()))
|
return Response(json.dumps(config.get_config(), indent=4, sort_keys=True))
|
||||||
|
|
||||||
@config_BP.route('/config/get/<key>')
|
@config_BP.route('/config/get/<key>')
|
||||||
def get_by_key(key):
|
def get_by_key(key):
|
||||||
|
@ -37,13 +37,13 @@ def get_by_key(key):
|
||||||
@config_BP.route('/config/setall', methods=['POST'])
|
@config_BP.route('/config/setall', methods=['POST'])
|
||||||
def set_all_config():
|
def set_all_config():
|
||||||
'''Overwrite existing JSON config with new JSON string'''
|
'''Overwrite existing JSON config with new JSON string'''
|
||||||
new_config = request.get_json(force=True)
|
|
||||||
try:
|
try:
|
||||||
new_config = json.loads(new_config)
|
new_config = request.get_json(force=True)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
abort(400)
|
abort(400)
|
||||||
else:
|
else:
|
||||||
config.set_config(new_config)
|
config.set_config(new_config)
|
||||||
|
config.save()
|
||||||
return Response('success')
|
return Response('success')
|
||||||
|
|
||||||
@config_BP.route('/config/set/<key>', methods=['POST'])
|
@config_BP.route('/config/set/<key>', methods=['POST'])
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
<details class='configArea'>
|
<details class='configArea'>
|
||||||
<summary><b>Edit Configuration</b></summary>
|
<summary><b>Edit Configuration</b></summary>
|
||||||
<br>
|
<br>
|
||||||
|
<p><em>Warning: </em><b>Some values can be dangerous to change. Use caution.</b></p>
|
||||||
|
<br>
|
||||||
<textarea class='configEditor'></textarea>
|
<textarea class='configEditor'></textarea>
|
||||||
<button class='saveConfig successBtn'>Save Config</button>
|
<button class='saveConfig successBtn'>Save Config</button>
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
/*
|
||||||
|
Onionr - P2P Anonymous Storage Network
|
||||||
|
|
||||||
|
This file is for configuration editing in the web interface
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
var saveBtns = document.getElementsByClassName('saveConfig')
|
var saveBtns = document.getElementsByClassName('saveConfig')
|
||||||
var saveBtn = document.getElementsByClassName('saveConfig')[0]
|
var saveBtn = document.getElementsByClassName('saveConfig')[0]
|
||||||
var configEditor = document.getElementsByClassName('configEditor')[0]
|
var configEditor = document.getElementsByClassName('configEditor')[0]
|
||||||
|
@ -7,12 +26,29 @@ fetch('/config/get', {
|
||||||
headers: {
|
headers: {
|
||||||
"token": webpass
|
"token": webpass
|
||||||
}})
|
}})
|
||||||
.then((resp) => resp.json()) // Transform the data into json
|
.then((resp) => resp.text()) // Transform the data into text
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
config = resp
|
configEditor.value = resp
|
||||||
configEditor.value = JSON.stringify(config)
|
config = JSON.parse(resp) //parse here so we can set the text field to pretty json
|
||||||
})
|
})
|
||||||
|
|
||||||
saveBtn.onclick = function(){
|
saveBtn.onclick = function(){
|
||||||
|
var postData = configEditor.value
|
||||||
|
try {
|
||||||
|
JSON.parse(postData)
|
||||||
|
} catch (e) {
|
||||||
|
alert('Configuration is not valid JSON')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
fetch('/config/setall', {
|
||||||
|
method: 'POST',
|
||||||
|
body: postData,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
"token": webpass
|
||||||
|
}})
|
||||||
|
.then((resp) => resp.text()) // Transform the data into text
|
||||||
|
.then(function(data) {
|
||||||
|
alert('Config saved')
|
||||||
|
})
|
||||||
}
|
}
|
Loading…
Reference in New Issue