-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyserver.py
More file actions
87 lines (67 loc) · 1.95 KB
/
pyserver.py
File metadata and controls
87 lines (67 loc) · 1.95 KB
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
80
81
82
83
84
85
86
87
#JOÃO PEDRO, TI - ATIVA NÁUTICA
#VERSÃO 1.0
from flask import Flask
from flask import request
import os
import sys
import time
import requests
from subprocess import call
app = Flask(__name__)
APP_DEBUG = False
#Utilize '--debug' na linha de comando para iniciar em modo de debug:
if len(sys.argv) > 1 and "--debug" in sys.argv:
print("RODANDO EM MODO DE DEBUG...")
APP_DEBUG = True
ARQUIVO = sys.executable
@app.route("/close")
def fechar_conexao():
func = request.environ.get("werkzeug.server.shutdown")
if func is None:
raise RuntimeError("Server não está rodando")
func()
if APP_DEBUG == True:
os.system(f"start python {__file__}")
else:
os.system("start " + ARQUIVO)
return "Servidor reiniciando..."
@app.route("/ping")
def ping():
try:
ip = request.headers.get('Host')
return "Tudo ok! IP: " + ip
except:
return "Erro na conexão!"
@app.route("/video/<pasta>/<nome>")
def video(pasta, nome):
home = os.path.expanduser("~")
arquivo = home + "\\" + pasta + "\\" + nome
try:
os.system("start " + arquivo)
return "O vídeo " + nome + " está passando!"
except:
return "Houve algum problema na reprodução do vídeo..."
@app.route("/block")
def bloquear():
try:
call("C:/Windows/System32/rundll32.exe user32.dll,LockWorkStation")
return "Sua máquina foi bloqueada!"
except:
return "Houve algum problema..."
@app.route("/shutdown")
def desligar():
try:
call("shutdown -s -t 1")
return "Sua máquina está desligando..."
except:
return "Houve algum problema..."
@app.route("/reboot")
def reiniciar():
try:
call("shutdown -r -t 1")
return "Reiniciando..."
except:
return "Houve algum problema..."
if __name__ == "__main__":
app.run(host='0.0.0.0',threaded=True)
#mete um request pra um webapp que registra a sessão como ativa (IP, porta, etc)