mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-01-18 08:58:48 +00:00
Добавление кнопки выключения (она работает)
This commit is contained in:
parent
e693d8450e
commit
a52fb2679a
@ -7,13 +7,34 @@
|
||||
.main {
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"our_port search"
|
||||
"servers sites"
|
||||
"servers sites";
|
||||
"off_btn search"
|
||||
"our_port sites"
|
||||
"servers sites";
|
||||
grid-template-columns: 1fr 2fr;
|
||||
grid-template-rows: auto auto;
|
||||
}
|
||||
|
||||
|
||||
.off_btn {
|
||||
grid-area: off_btn;
|
||||
background: #ff5a5a;
|
||||
align-content: center;
|
||||
border-radius: 0.4rem;
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
border-style: hidden;
|
||||
font-size: 1rem;
|
||||
width: calc(100% - 0.5rem);
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.off_btn:active {
|
||||
background-color: #c85000;
|
||||
box-shadow: rgba(0, 0, 0, .06) 0 2px 4px;
|
||||
transform: scale(.96);
|
||||
}
|
||||
|
||||
|
||||
.our_port {
|
||||
grid-area: our_port;
|
||||
background: #53f453;
|
||||
@ -22,6 +43,7 @@
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
margin-right: 0.5rem;
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
|
||||
.servers {
|
||||
|
31
interface.py
31
interface.py
@ -2,14 +2,20 @@ 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.Input(className='search', type='search', list=[1,2,3]),
|
||||
dcc.Dropdown(options=[], id='search', placeholder='Поиск...'),
|
||||
|
||||
dcc.Interval(id='interval-component', interval=1*1000, n_intervals=0)
|
||||
@ -17,6 +23,29 @@ dcc.Interval(id='interval-component', interval=1*1000, n_intervals=0)
|
||||
], className='main')], className='content')
|
||||
|
||||
|
||||
# Функция выключения
|
||||
def shutdown():
|
||||
# Задаём код остановки
|
||||
status_set('stop')
|
||||
# Определяем платформу
|
||||
if system() == 'Linux':
|
||||
# вырубаем прокси и скрипты
|
||||
sys('killall bore')
|
||||
sys('killall python')
|
||||
elif system() == 'Windows':
|
||||
sys('taskkill /f /im bore.exe')
|
||||
sys('taskkill /f /im python.exe')
|
||||
|
||||
# Кнопка выключения
|
||||
@callback(
|
||||
Output('shut_mess', 'displayed'),
|
||||
Input('off_btn', 'n_clicks'),
|
||||
prevent_initial_call=True
|
||||
)
|
||||
def shut_btn(n_clicks):
|
||||
th = Thread(target=shutdown)
|
||||
th.start()
|
||||
return True
|
||||
|
||||
# Обновление нашего порта (зачем?)
|
||||
@callback(Output('our_port', 'children'),
|
||||
|
2
main.py
2
main.py
@ -63,7 +63,7 @@ if __name__ == '__main__':
|
||||
p = Process(target=main)
|
||||
p.start()
|
||||
|
||||
status_set(True) # Устанавливаем статус, что программа работает
|
||||
status_set('work') # Устанавливаем статус, что программа работает
|
||||
|
||||
st = status_check()
|
||||
while st:
|
||||
|
10
proxy.py
10
proxy.py
@ -2,6 +2,8 @@ from os import system, name
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
from status import *
|
||||
|
||||
global http_out ; http_out = None
|
||||
def proxy_http(port):
|
||||
global http_out
|
||||
@ -24,13 +26,15 @@ def watch_http(port):
|
||||
run.start()
|
||||
|
||||
global http_out
|
||||
while True:
|
||||
st = status_check()
|
||||
while st:
|
||||
# Если команда вышла
|
||||
if http_out or not run.is_alive():
|
||||
run.join(1)
|
||||
http_out = None
|
||||
run = Thread(target=proxy_http, args=(port,))
|
||||
run.start()
|
||||
st = status_check()
|
||||
sleep(1)
|
||||
|
||||
def watch_serv(port):
|
||||
@ -38,10 +42,12 @@ def watch_serv(port):
|
||||
run.start()
|
||||
|
||||
global serv_out
|
||||
while True:
|
||||
st = status_check()
|
||||
while st:
|
||||
if serv_out or not run.is_alive():
|
||||
run.join(1)
|
||||
serv_out = None
|
||||
run = Thread(target=proxy_serv, args=(port,))
|
||||
run.start()
|
||||
st = status_check()
|
||||
sleep(1)
|
||||
|
Loading…
Reference in New Issue
Block a user