mirror of
				https://gitea.augustin64.fr/piair/MsRewards-Reborn.git
				synced 2025-11-03 23:23:53 +01:00 
			
		
		
		
	c'est une bien meilleure manière de faire.
This commit is contained in:
		
							
								
								
									
										15
									
								
								Flask/app.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								Flask/app.py
									
									
									
									
									
								
							@@ -10,6 +10,21 @@ import json
 | 
			
		||||
import re
 | 
			
		||||
from requests import get
 | 
			
		||||
 | 
			
		||||
# redis part for live update
 | 
			
		||||
redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
 | 
			
		||||
pubsub = redis_client.pubsub()
 | 
			
		||||
pubsub.subscribe('console')
 | 
			
		||||
 | 
			
		||||
def generate_output():
 | 
			
		||||
    for message in pubsub.listen():
 | 
			
		||||
        if message['type'] == 'message':
 | 
			
		||||
            yield f"data: {message['data'].decode()}\n\n"
 | 
			
		||||
 | 
			
		||||
@app.route('/stream')
 | 
			
		||||
def stream():
 | 
			
		||||
    return Response(generate_output(), content_type='text/event-stream')
 | 
			
		||||
# end
 | 
			
		||||
 | 
			
		||||
global password
 | 
			
		||||
with open("/app/MsRewards-Reborn/user_data/flask.json", "r") as inFile:
 | 
			
		||||
    data = json.load(inFile)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
service grafana-server start
 | 
			
		||||
service nginx start
 | 
			
		||||
gunicorn --reload -w 1 -b 0.0.0.0:6666 'app:app'
 | 
			
		||||
nohup redis-server &
 | 
			
		||||
gunicorn --reload -w 1 --worker-class gevent -b 0.0.0.0:6666 'app:app'
 | 
			
		||||
 
 | 
			
		||||
@@ -7,21 +7,24 @@
 | 
			
		||||
{%if not current_user.is_authenticated %}
 | 
			
		||||
    <button class="unselected" onclick="location.href = '/login';">login</button>
 | 
			
		||||
{% else %}
 | 
			
		||||
    <iframe id="iframe" src="{{url_for('static', filename='logs/dev.txt')}}" width="100%" height="80%"></iframe>
 | 
			
		||||
<table>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td width="20%" height="90%">
 | 
			
		||||
            <div id="console"></div>
 | 
			
		||||
        </td>
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
    <script>
 | 
			
		||||
        var myIframe = document.getElementById('iframe');
 | 
			
		||||
<script>
 | 
			
		||||
    const consoleElement = document.getElementById('console');
 | 
			
		||||
    const eventSource = new EventSource('/stream');
 | 
			
		||||
 | 
			
		||||
        myIframe.addEventListener("load", async () => {
 | 
			
		||||
            myIframe.contentDocument.body.innerHTML = myIframe.contentDocument.body.innerHTML + '<style>html{color:white;}</style>';
 | 
			
		||||
            await delay(2000);
 | 
			
		||||
            document.getElementById('iframe').contentWindow.location.reload();
 | 
			
		||||
        });
 | 
			
		||||
        
 | 
			
		||||
        window.setInterval(function() {
 | 
			
		||||
            document.getElementById('iframe').contentWindow.scrollTo(0, myIframe.contentDocument.body.scrollHeight);
 | 
			
		||||
        }, 500);
 | 
			
		||||
        
 | 
			
		||||
    </script>
 | 
			
		||||
    eventSource.onmessage = (event) => {
 | 
			
		||||
        const newOutput = document.createElement('div');
 | 
			
		||||
        newOutput.textContent = event.data;
 | 
			
		||||
        consoleElement.appendChild(newOutput);
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
</script>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -9,23 +9,26 @@
 | 
			
		||||
{% else %}
 | 
			
		||||
<table>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td width="20%" height="90%"><iframe id="iframe" src="{{url_for('static', filename='logs/custom.txt')}}" width="100%" height="100%"></iframe></td>
 | 
			
		||||
        <td width="80%"><iframe src="/novnc/vnc.html?resize=scale&path=novnc/websockify&autoconnect=true&view_only" width="100%" height="100%" frameborder="0"></iframe></td>
 | 
			
		||||
        <td width="20%" height="90%">
 | 
			
		||||
            <div id="console"></div>
 | 
			
		||||
        </td>
 | 
			
		||||
        <td width="80%">
 | 
			
		||||
            <iframe src="/novnc/vnc.html?resize=scale&path=novnc/websockify&autoconnect=true&view_only" width="100%" height="100%" frameborder="0"></iframe>
 | 
			
		||||
        </td>
 | 
			
		||||
    </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
    var myIframe = document.getElementById('iframe');
 | 
			
		||||
 | 
			
		||||
    myIframe.addEventListener("load", async () => {
 | 
			
		||||
        myIframe.contentDocument.body.innerHTML = myIframe.contentDocument.body.innerHTML + '<style>html{color:white;}</style>';
 | 
			
		||||
        await delay(2000);
 | 
			
		||||
        document.getElementById('iframe').contentWindow.location.reload();
 | 
			
		||||
    });
 | 
			
		||||
    
 | 
			
		||||
    window.setInterval(function() {
 | 
			
		||||
        document.getElementById('iframe').contentWindow.scrollTo(0, myIframe.contentDocument.body.scrollHeight);
 | 
			
		||||
    }, 500);
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
    const consoleElement = document.getElementById('console');
 | 
			
		||||
    const eventSource = new EventSource('/stream');
 | 
			
		||||
 | 
			
		||||
    eventSource.onmessage = (event) => {
 | 
			
		||||
        const newOutput = document.createElement('div');
 | 
			
		||||
        newOutput.textContent = event.data;
 | 
			
		||||
        consoleElement.appendChild(newOutput);
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user