Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0cbe092

Browse files
committed
added password authentication
1 parent 51d96b8 commit 0cbe092

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎modules/server.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import errno
44
import socket
55
import select
6+
import config
67

78
class Server():
89
def __init__(self, config, worker):
@@ -12,9 +13,10 @@ def __init__(self, config, worker):
1213
self.host = config['host']
1314
self.inputs = []
1415
self.outputs = []
16+
self.authorized = []
1517
self.BUFFER_SIZE = 1024
1618
self.worker = worker
17-
self.hello = "### Python Manager\nHello !\n#> "
19+
self.hello = "### Python Manager\nHello !\n(password)\n#>"
1820
self.socket = None
1921

2022
def start(self):
@@ -35,11 +37,19 @@ def start(self):
3537
self.inputs.append(client)
3638
client.send(self.hello.encode())
3739
else:
38-
try:
40+
try:
3941
data = sock.recv(self.BUFFER_SIZE)
4042
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)
4353
sock.send(output.encode()+b"\n#> ")
4454
else:
4555
if sock in self.outputs:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /