correction de bugs

This commit is contained in:
Vincent BENOIT
2022-11-29 15:51:01 +01:00
parent f2c4939b56
commit 5f32a19f3e

View File

@@ -64,7 +64,7 @@ def refresh_expiring_tokens(response):
except (RuntimeError, KeyError):
return response
def execute_cmd(self, args=""):
def execute_cmd(args=""):
''' Execute system command
'''
out = None
@@ -155,23 +155,24 @@ def current_user():
current_user = get_jwt_identity()
return jsonify(current_user)
@auth.route('/alive', methods=['POST'])
@auth.route('/reboot', methods=['POST'])
@jwt_required()
def isAlive():
def reboot():
''' Handles HTTP requests to URL: /api/configurateur/alive
'''
current_app.logger.info("Reboot du système ...")
current_user = get_jwt_identity()
unset_jwt_cookies(content)
userpath = os.path.join("/tmp", current_app.config['PROJECT'])
if os.path.exists(userpath):
shutil.rmtree(userpath)
reboot_cmd = ['sudo', '/usr/bin/systemctl', 'reboot']
if not self.execute_cmd(reboot_cmd):
abort(status.HTTP_500_INTERNAL_SERVER_ERROR, description='Redémarrage du système impossible')
if not execute_cmd(reboot_cmd):
abort(status.HTTP_500_INTERNAL_SERVER_ERROR,
description='Redémarrage du système impossible')
content = jsonify({'message': 'reboot successful !'})
unset_jwt_cookies(content)
return content, status.HTTP_200_OK
@auth.route('/userConnected', methods=['GET'])