3
3
import errno
4
4
import socket
5
5
import select
6
+ import config
6
7
7
8
class Server ():
8
9
def __init__ (self , config , worker ):
@@ -12,9 +13,10 @@ def __init__(self, config, worker):
12
13
self .host = config ['host' ]
13
14
self .inputs = []
14
15
self .outputs = []
16
+ self .authorized = []
15
17
self .BUFFER_SIZE = 1024
16
18
self .worker = worker
17
- self .hello = "### Python Manager\n Hello !\n #> "
19
+ self .hello = "### Python Manager\n Hello !\n (password) \n #> "
18
20
self .socket = None
19
21
20
22
def start (self ):
@@ -35,11 +37,19 @@ def start(self):
35
37
self .inputs .append (client )
36
38
client .send (self .hello .encode ())
37
39
else :
38
- try :
40
+ try :
39
41
data = sock .recv (self .BUFFER_SIZE )
40
42
if data :
41
- command = data .decode ("UTF-8" )
42
- success , output = handle_input (command , self .worker , self )
43
+ if sock not in self .authorized :
44
+ pwd = data .decode ("UTF-8" ).strip ()
45
+ if pwd != config .daemon ['password' ]:
46
+ output = "Invalid password.\n (password)"
47
+ else :
48
+ self .authorized .append (sock )
49
+ output = "OK"
50
+ else :
51
+ command = data .decode ("UTF-8" )
52
+ success , output = handle_input (command , self .worker , self )
43
53
sock .send (output .encode ()+ b"\n #> " )
44
54
else :
45
55
if sock in self .outputs :
0 commit comments