better restart management
This commit is contained in:
parent
28cfae03a8
commit
3cacc9fb00
@ -9,7 +9,7 @@ jQuery(document).ready(function ($) {
|
||||
if (confirm(l.js_sysinfo_restart_confirmation)) {
|
||||
$('body').html(l.js_sysinfo_restart_loading).css({margin:200});
|
||||
$.ajax({
|
||||
url: '/sysinfo/restart',
|
||||
url: '/sysinfo/restart?secret_key='+secret_key,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
data: '',
|
||||
method: 'POST',
|
||||
|
||||
@ -24,6 +24,9 @@ class AuthController(ObController):
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('slideshow_slide_list'))
|
||||
|
||||
if not self._model_store.variable().map().get('auth_enabled').as_bool():
|
||||
return redirect(url_for('slideshow_slide_list'))
|
||||
|
||||
if len(request.form):
|
||||
user = self._model_store.user().get_one_by_username(request.form['username'], enabled=True)
|
||||
if user:
|
||||
@ -42,6 +45,13 @@ class AuthController(ObController):
|
||||
|
||||
def logout(self):
|
||||
logout_user()
|
||||
|
||||
if request.args.get('restart'):
|
||||
return redirect(url_for(
|
||||
'sysinfo_restart',
|
||||
secret_key=self._model_store.config().map().get('secret_key')
|
||||
))
|
||||
|
||||
return redirect(url_for('login'))
|
||||
|
||||
def auth_user_list(self):
|
||||
|
||||
@ -39,7 +39,10 @@ class SettingsController(ObController):
|
||||
if variable.name == 'auth_enabled':
|
||||
self.reload_web_server()
|
||||
if variable.as_bool():
|
||||
return redirect(url_for('logout'))
|
||||
return redirect(url_for(
|
||||
'logout',
|
||||
restart=1
|
||||
))
|
||||
|
||||
if variable.name == 'lang':
|
||||
self._model_store.lang().set_lang(variable.value)
|
||||
|
||||
@ -2,21 +2,23 @@ import os
|
||||
import sys
|
||||
import platform
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
|
||||
from flask import Flask, render_template, jsonify
|
||||
from flask import Flask, render_template, jsonify, request, url_for, redirect
|
||||
from src.manager.VariableManager import VariableManager
|
||||
from src.manager.ConfigManager import ConfigManager
|
||||
from src.service.ModelStore import ModelStore
|
||||
|
||||
from src.interface.ObController import ObController
|
||||
from src.utils import get_ip_address
|
||||
from src.utils import get_ip_address, am_i_in_docker
|
||||
|
||||
|
||||
class SysinfoController(ObController):
|
||||
|
||||
def register(self):
|
||||
self._app.add_url_rule('/sysinfo', 'sysinfo_attribute_list', self._auth(self.sysinfo), methods=['GET'])
|
||||
self._app.add_url_rule('/sysinfo/restart', 'sysinfo_restart', self._auth(self.sysinfo_restart), methods=['POST'])
|
||||
self._app.add_url_rule('/sysinfo/restart', 'sysinfo_restart', self.sysinfo_restart, methods=['GET', 'POST'])
|
||||
self._app.add_url_rule('/sysinfo/restart/needed', 'sysinfo_restart_needed', self._auth(self.sysinfo_restart_needed), methods=['GET'])
|
||||
|
||||
def sysinfo(self):
|
||||
@ -29,20 +31,13 @@ class SysinfoController(ObController):
|
||||
)
|
||||
|
||||
def sysinfo_restart(self):
|
||||
if platform.system().lower() == 'darwin':
|
||||
if self._model_store.config().map().get('debug'):
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
else:
|
||||
try:
|
||||
subprocess.run(["sudo", "systemctl", "restart", 'obscreen'], check=True, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
pass
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
secret = self._model_store.config().map().get('secret_key')
|
||||
challenge = request.args.get('secret_key')
|
||||
thread = threading.Thread(target=self.restart, args=(secret, challenge))
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
return redirect(url_for('manage'))
|
||||
|
||||
def sysinfo_restart_needed(self):
|
||||
var_last_slide_update = self._model_store.variable().get_one_by_name('last_slide_update')
|
||||
@ -53,3 +48,24 @@ class SysinfoController(ObController):
|
||||
|
||||
return jsonify({'status': True})
|
||||
|
||||
def restart(self, secret: str, challenge: str) -> None:
|
||||
time.sleep(1)
|
||||
|
||||
if secret != challenge:
|
||||
return jsonify({'status': 'error'})
|
||||
|
||||
if platform.system().lower() == 'darwin':
|
||||
if self._model_store.config().map().get('debug'):
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
elif am_i_in_docker:
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
else:
|
||||
try:
|
||||
subprocess.run(["sudo", "systemctl", "restart", 'obscreen-manager'], check=True, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
pass
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
@ -25,6 +25,7 @@ class TemplateRenderer:
|
||||
def get_view_globals(self) -> dict:
|
||||
globals = dict(
|
||||
STATIC_PREFIX="/{}/{}/".format(WebDirConstant.FOLDER_STATIC, WebDirConstant.FOLDER_STATIC_WEB_ASSETS),
|
||||
SECRET_KEY=self._model_store.config().map().get('secret_key'),
|
||||
FLEET_ENABLED=self._model_store.variable().map().get('fleet_enabled').as_bool(),
|
||||
AUTH_ENABLED=self._model_store.variable().map().get('auth_enabled').as_bool(),
|
||||
track_created=self._model_store.user().track_user_created,
|
||||
|
||||
@ -113,6 +113,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
<script>
|
||||
var secret_key = '{{ SECRET_KEY }}';
|
||||
var l = {
|
||||
'js_slideshow_slide_delete_confirmation': '{{ l.slideshow_slide_delete_confirmation }}',
|
||||
'js_fleet_screen_delete_confirmation': '{{ l.js_fleet_screen_delete_confirmation }}',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user