-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrv_interface.py
79 lines (65 loc) · 2.46 KB
/
srv_interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from dash import Dash, dcc, html, Input, Output, callback
app = Dash(__name__, title='Jetwork', update_title=None)
from db import *
from status import *
from os import walk
from os import system as sys
from platform import system
from threading import Thread
app.layout = html.Div([ html.Div([
dcc.ConfirmDialog(id='shut_mess', message='Ты совсем гений?'),
html.Button("Выключить клиент", className='off_btn', n_clicks=0, id='off_btn'),
html.Div([], id='our_port', className='our_port'),
html.Div([], id='servers', className='servers'),
html.Div([], id='sites', className='sites'),
dcc.Dropdown(options=[], id='search', placeholder='Поиск...'),
dcc.Interval(id='interval-component', interval=1*1000, n_intervals=0)
], className='main')], className='content')
# Кнопка выключения
@callback(
Output('shut_mess', 'displayed'),
Input('off_btn', 'n_clicks'),
prevent_initial_call=True
)
def shut_btn(n_clicks):
return True
# Обновление нашего порта (зачем?)
@callback(Output('our_port', 'children'),
Input('interval-component', 'n_intervals'))
def update_our_port(n):
return f"Ваш порт: {read()['our_port']}"
# Обновление доступных узлов
@callback(Output('servers', 'children'),
Input('interval-component', 'n_intervals'))
def update_servers(n):
res = []
for i in read()['ports']:
res.append(html.Div([i], className='serv_elem'))
return res
# Обновление доступных сайтов
@callback(Output('sites', 'children'),
Input('interval-component', 'n_intervals'),
Input('search', 'value'))
def update_sites(n, s_val):
# Префикс
base_url = read()['base_url']
# Если есть элемент в поиске
if s_val:
return html.Div([ dcc.Link(children=i, href=f'{base_url}/{s_val}',
target='_blank') ], className='sites_elem')
res = []
for i in next(walk('cached/'), (None, None, []))[1]:
conf = read(f'cached/{i}/config.json')
res.append(html.Div([ dcc.Link(children=i, href=f'http://{i}',
target='_blank') ], className='sites_elem'))
return res
# Обновление доступных сайтов в поиске
@callback(Output('search', 'options'),
Input('interval-component', 'n_intervals'))
def update_search(n):
res = []
for i in next(walk('cached/'), (None, None, []))[1]:
res.append(i)
return res
#app.run(debug=True, port = 5555)
app.run(debug=False, host = '0.0.0.0', port = 5555)